Skip to content

Commit

Permalink
add --round-address optino
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Apr 3, 2024
1 parent 214e395 commit 8e3a1a2
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions contracts/tasks/runners/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,63 @@ import { EContracts } from '../../utils/types'
import { ContractStorage } from '../helpers/ContractStorage'

task('claim', 'Claim funnds for test recipients')
.addOptionalParam('roundAddress', 'Funding round contract address')
.addParam(
'recipient',
'The recipient index in the tally file',
undefined,
types.int
)
.addParam('tallyFile', 'The tally file')
.setAction(async ({ tallyFile, recipient }, { ethers, network }) => {
if (!isPathExist(tallyFile)) {
throw new Error(`Path ${tallyFile} does not exist`)
}
.setAction(
async ({ tallyFile, recipient, roundAddress }, { ethers, network }) => {
if (!isPathExist(tallyFile)) {
throw new Error(`Path ${tallyFile} does not exist`)
}

if (recipient <= 0) {
throw new Error('Recipient must be greater than 0')
}
if (recipient <= 0) {
throw new Error('Recipient must be greater than 0')
}

const storage = ContractStorage.getInstance()
const fundingRound = storage.mustGetAddress(
EContracts.FundingRound,
network.name
)
const storage = ContractStorage.getInstance()
const fundingRound =
roundAddress ??
storage.mustGetAddress(EContracts.FundingRound, network.name)

const tally = JSONFile.read(tallyFile)
const tally = JSONFile.read(tallyFile)

const fundingRoundContract = await ethers.getContractAt(
EContracts.FundingRound,
fundingRound
)
const fundingRoundContract = await ethers.getContractAt(
EContracts.FundingRound,
fundingRound
)

const recipientStatus = await fundingRoundContract.recipients(recipient)
if (recipientStatus.fundsClaimed) {
throw new Error(`Recipient already claimed funds`)
}
const recipientStatus = await fundingRoundContract.recipients(recipient)
if (recipientStatus.fundsClaimed) {
throw new Error(`Recipient already claimed funds`)
}

const pollAddress = await fundingRoundContract.poll()
console.log('pollAddress', pollAddress)
const pollAddress = await fundingRoundContract.poll()
console.log('pollAddress', pollAddress)

const poll = await ethers.getContractAt(EContracts.Poll, pollAddress)
const treeDepths = await poll.treeDepths()
const recipientTreeDepth = getNumber(treeDepths.voteOptionTreeDepth)
const poll = await ethers.getContractAt(EContracts.Poll, pollAddress)
const treeDepths = await poll.treeDepths()
const recipientTreeDepth = getNumber(treeDepths.voteOptionTreeDepth)

// Claim funds
const recipientClaimData = getRecipientClaimData(
recipient,
recipientTreeDepth,
tally
)
const claimTx = await fundingRoundContract.claimFunds(...recipientClaimData)
const claimedAmount = await getEventArg(
claimTx,
fundingRoundContract,
'FundsClaimed',
'_amount'
)
console.log(`Recipient ${recipient} claimed ${claimedAmount} tokens.`)
})
// Claim funds
const recipientClaimData = getRecipientClaimData(
recipient,
recipientTreeDepth,
tally
)
const claimTx = await fundingRoundContract.claimFunds(
...recipientClaimData
)
const claimedAmount = await getEventArg(
claimTx,
fundingRoundContract,
'FundsClaimed',
'_amount'
)
console.log(`Recipient ${recipient} claimed ${claimedAmount} tokens.`)
}
)

0 comments on commit 8e3a1a2

Please sign in to comment.