UNPKG

@ajna-finance/sdk

Version:

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

239 lines 11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGrantsFundContract = void 0; exports.getTotalSupply = getTotalSupply; exports.delegateVote = delegateVote; exports.getDelegates = getDelegates; exports.getCurrentDistributionId = getCurrentDistributionId; exports.startNewDistributionPeriod = startNewDistributionPeriod; exports.getDistributionPeriod = getDistributionPeriod; exports.getTreasury = getTreasury; exports.getStage = getStage; exports.createProposal = createProposal; exports.getProposalIdFromReceipt = getProposalIdFromReceipt; exports.getProposalInfo = getProposalInfo; exports.getProposalState = getProposalState; exports.getDescriptionHash = getDescriptionHash; exports.executeProposal = executeProposal; exports.getTopTenProposals = getTopTenProposals; exports.getVotesScreening = getVotesScreening; exports.getVotesFunding = getVotesFunding; exports.getVoterInfo = getVoterInfo; exports.getScreeningVotesCast = getScreeningVotesCast; exports.getFundingVotesCast = getFundingVotesCast; exports.screeningVote = screeningVote; exports.fundingVote = fundingVote; exports.updateSlate = updateSlate; exports.getFundedProposalSlate = getFundedProposalSlate; exports.claimDelegateReward = claimDelegateReward; exports.getDelegateReward = getDelegateReward; exports.getHasClaimedRewards = getHasClaimedRewards; const tslib_1 = require("tslib"); const ethers_1 = require("ethers"); const GrantFund_json_1 = tslib_1.__importDefault(require("../abis/GrantFund.json")); const AjnaToken_json_1 = tslib_1.__importDefault(require("../abis/AjnaToken.json")); const Config_1 = require("../classes/Config"); const common_1 = require("./common"); const checksum_address_1 = tslib_1.__importDefault(require("../utils/checksum-address")); const transactions_1 = require("../utils/transactions"); const getGrantsFundContract = (provider) => { return new ethers_1.ethers.Contract((0, checksum_address_1.default)(Config_1.Config.grantFund), GrantFund_json_1.default, provider); }; exports.getGrantsFundContract = getGrantsFundContract; function getTotalSupply(provider) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, common_1.getAjnaTokenContract)(provider); return yield contractInstance.totalSupply(); }); } // Delegate function delegateVote(signer, delegatee) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, common_1.getAjnaTokenContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'delegate', args: [delegatee], }); }); } function getDelegates(provider, account) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, common_1.getAjnaTokenContract)(provider); return yield contractInstance.delegates(account); }); } // Distribution period function getCurrentDistributionId(provider) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getDistributionId(); }); } function startNewDistributionPeriod(signer) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'startNewDistributionPeriod', args: [], }); }); } function getDistributionPeriod(provider, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getDistributionPeriodInfo(distributionId); }); } function getTreasury(provider) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.treasury(); }); } function getStage(provider) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getStage(); }); } // Proposals function createProposal(signer, _a) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var { recipientAddresses } = _a, rest = tslib_1.__rest(_a, ["recipientAddresses"]); const iface = new ethers_1.ethers.utils.Interface(AjnaToken_json_1.default); const encodedTransferCalls = recipientAddresses.map(({ address, amount }) => iface.encodeFunctionData('transfer', [address, ethers_1.ethers.utils.parseEther(amount)])); const contractInstance = (0, exports.getGrantsFundContract)(signer); const description = JSON.stringify(rest); // targets and values are the same for every recipient const targets = recipientAddresses.map(() => Config_1.Config.ajnaToken); const values = recipientAddresses.map(() => 0); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'propose', args: [targets, values, encodedTransferCalls, description], }); }); } function getProposalIdFromReceipt(receipt) { const iface = new ethers_1.ethers.utils.Interface(GrantFund_json_1.default); const logDescription = iface.parseLog(receipt.logs[0]); return logDescription.args[0]; } function getProposalInfo(provider, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getProposalInfo(distributionId); }); } function getProposalState(provider, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.state(distributionId); }); } function getDescriptionHash(provider, description) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getDescriptionHash(description); }); } function executeProposal(signer, targets, values, calldata, descriptionHash) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'execute', args: [targets, values, calldata, descriptionHash], }); }); } function getTopTenProposals(provider, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getTopTenProposals(distributionId); }); } // Voting function getVotesScreening(provider, distributionId, account) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getVotesScreening(distributionId, account); }); } function getVotesFunding(provider, distributionId, account) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getVotesFunding(distributionId, account); }); } function getVoterInfo(provider, distributionId, account) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getVoterInfo(distributionId, account); }); } function getScreeningVotesCast(provider, distributionId, account) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getScreeningVotesCast(distributionId, account); }); } function getFundingVotesCast(provider, distributionId, account) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getFundingVotesCast(distributionId, account); }); } function screeningVote(signer, votes) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'screeningVote', args: [votes], }); }); } function fundingVote(signer, votes) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'fundingVote', args: [votes], }); }); } function updateSlate(signer, proposalIds, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'updateSlate', args: [proposalIds, distributionId], }); }); } function getFundedProposalSlate(provider, slateHash) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getFundedProposalSlate(slateHash); }); } function claimDelegateReward(signer, distributionId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(signer); return yield (0, transactions_1.createTransaction)(contractInstance, { methodName: 'claimDelegateReward', args: [distributionId], }); }); } function getDelegateReward(provider, distributionId, voter) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getDelegateReward(distributionId, voter); }); } function getHasClaimedRewards(provider, distributionId, voter) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractInstance = (0, exports.getGrantsFundContract)(provider); return yield contractInstance.getHasClaimedRewards(distributionId, voter); }); } //# sourceMappingURL=grant-fund.js.map