UNPKG

@ajna-finance/sdk

Version:

A typescript SDK that can be used to create Dapps in Ajna ecosystem.

178 lines 7.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GrantFund = void 0; const tslib_1 = require("tslib"); const common_1 = require("../constants/common"); const grant_fund_1 = require("../contracts/grant-fund"); const types_1 = require("../types"); const Config_1 = require("./Config"); const ContractBase_1 = require("./ContractBase"); const DistributionPeriod_1 = require("./DistributionPeriod"); const Proposal_1 = require("./Proposal"); /** * Class used to iteract with grants fund contract. */ class GrantFund extends ContractBase_1.ContractBase { constructor(signerOrProvider) { super(signerOrProvider); } /** * Get total token supply. * @returns BigNumber */ getTotalSupply() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, grant_fund_1.getTotalSupply)(this.getProvider()); }); } /** * Delegates vote to the given delegatee. * @param signer vote delegator * @param delegatee address of the delegateee * @returns promise to transaction */ delegateVote(signer, delegatee) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, grant_fund_1.delegateVote)(signer, delegatee); }); } /** * Get the address account is currently delegating to. * @param address delegator * @returns address */ getDelegates(address) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, grant_fund_1.getDelegates)(this.getProvider(), address); }); } /** * Starts a new distribution period, ensuring the treasury is funded. * @param signer transaction signer * @returns promise to transaction */ startNewDistributionPeriod(signer) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if ((yield (0, grant_fund_1.getTreasury)(signer)).isZero()) { throw new types_1.SdkError('Unfunded treasury'); } return (0, grant_fund_1.startNewDistributionPeriod)(signer); }); } /** * Gets the current treasury balance. * @returns BigNumber */ getTreasury() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, grant_fund_1.getTreasury)(this.getProvider()); }); } /** * Gets details of the distribution period. * @param signer caller * @param distributionId id of the distrituion period * @returns DistributionPeriod */ getDistributionPeriod(distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const provider = this.getProvider(); const [_distributionId, startBlockNumber, endBlockNumber, fundsAvailable, fundingVotePowerCast, fundedSlateHash,] = yield (0, grant_fund_1.getDistributionPeriod)(provider, distributionId); const [startBlock, endBlock] = yield Promise.all([ provider.getBlock(startBlockNumber), provider.getBlock(endBlockNumber), ]); const startDate = startBlock.timestamp * 1000; return new DistributionPeriod_1.DistributionPeriod(provider, distributionId, endBlock === null, startBlockNumber, startDate, endBlockNumber, endBlock ? endBlock.timestamp * 1000 : startDate + common_1.DISTRIBUTION_PERIOD_DURATION, fundsAvailable, fundingVotePowerCast, fundedSlateHash); }); } /** * Gets details of the currently active distribution period. * @param signer caller * @returns DistributionPeriod */ getActiveDistributionPeriod() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const provider = this.getProvider(); const distributionId = yield (0, grant_fund_1.getCurrentDistributionId)(provider); if (distributionId === 0) { return undefined; } const currentDistributionPeriod = yield this.getDistributionPeriod(distributionId); if (!currentDistributionPeriod.isActive) { return undefined; } return currentDistributionPeriod; }); } /** * Creates a proposal in the current distribution period. * @param signer caller * @param params ProposalParams object * @returns promise to transaction */ createProposal(signer, params) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, grant_fund_1.createProposal)(signer, params); }); } /** * Gets a proposal object with the given proposalId. * @param proposalId BigNumber * @returns Proposal object */ getProposal(proposalId) { return new Proposal_1.Proposal(this.getProvider(), proposalId); } /** * Distributes delegate reward based on delegatee Vote share. * @param distributionId_ Id of distribution from which delegatee wants to claim their reward. * @return rewardClaimed_ amount of reward claimed by delegatee. */ claimDelegateReward(signer, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, grant_fund_1.claimDelegateReward)(signer, distributionId); }); } /** * Retrieve the delegate reward accrued to a voter in a given distribution period. * @param distributionId_ The distributionId to calculate rewards for. * @param voter_ the address of the voter to calculate rewards for. * @return rewards_ the rewards earned by the voter for voting in that distribution period. */ getDelegateReward(distributionId, voter) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, grant_fund_1.getDelegateReward)(this.getProvider(), distributionId, voter); }); } /** * Get the reward claim status of an account in a given distribution period. * @param distributionId_ The distributionId of the distribution period to check. * @param voter_ the address of the voter to check. * @return rewards_ the reward claim status of the account in the distribution period. */ getHasClaimedRewards(distributionId, voter) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, grant_fund_1.getHasClaimedRewards)(this.getProvider(), distributionId, voter); }); } /** * Execute a proposal that has been approved by the community. Only proposals in the finalized top slate slate at the end of the challenge period can be executed. * @param targets_ list of contracts the proposal calldata will interact with. Should be the Ajna token contract for all proposals. * @param values_ list of values to be sent with the proposal calldata. Should be 0 for all proposals. * @param calldatas_ list of calldata to be executed. Should be the transfer() method. * @param descriptionHash_ hash of proposal's description string. * @return proposalId_ the id of the executed proposal. */ executeProposal(signer_1, _a) { return tslib_1.__awaiter(this, arguments, void 0, function* (signer, { params, description }) { const descriptionHash = yield (0, grant_fund_1.getDescriptionHash)(this.getProvider(), description); const targets = params.map(() => Config_1.Config.ajnaToken); const values = params.map(() => 0); const calldata = params.map(({ calldata }) => calldata); return yield (0, grant_fund_1.executeProposal)(signer, targets, values, calldata, descriptionHash); }); } } exports.GrantFund = GrantFund; //# sourceMappingURL=GrantFund.js.map