UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

36 lines (35 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.claimVoterRewards = void 0; const typechain_types_1 = require("../../typechain-types"); const sdk_core_1 = require("@vechain/sdk-core"); const utils_1 = require("@repo/utils"); const chunk_1 = require("./chunk"); const config_1 = require("@repo/config"); const sdk_network_1 = require("@vechain/sdk-network"); const thorClient = sdk_network_1.ThorClient.at((0, config_1.getConfig)().nodeUrl); const claimVoterRewards = async (voterRewards, roundId, signingAcct, accounts, ignoreErrors = false) => { console.log("Claiming voter rewards..."); const contractAddress = await voterRewards.getAddress(); const accountChunks = (0, chunk_1.chunk)(accounts, 50); for (const accountChunk of accountChunks) { try { const clauses = []; accountChunk.forEach(account => { clauses.push(sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(contractAddress), sdk_core_1.ABIContract.ofAbi(typechain_types_1.VoterRewards__factory.abi).getFunction("claimReward"), [roundId, account.key.address.toString()])); }); await utils_1.TransactionUtils.sendTx(thorClient, clauses, signingAcct.pk); console.log(`Rewards claimed for chunk starting with account ${accountChunk[0]?.key.address.toString()}`); } catch (e) { if (ignoreErrors) { console.error(`Error claiming rewards for chunk starting with account ${accountChunk[0]?.key.address.toString()}:`, e); } else { throw e; } } } console.log("Finished attempting to claim voter rewards."); }; exports.claimVoterRewards = claimVoterRewards;