UNPKG

@broxus/js-core

Version:

MobX-based JavaScript Core library

56 lines (55 loc) 2.92 kB
import { DEFAULT_NATIVE_CURRENCY_DECIMALS } from '../../constants'; import { voteEscrowDaoRootContract } from '../../models/vote-escrow-dao-root/contacts'; import { getFullContractState, toInt } from '../../utils'; export class VoteEscrowDaoRootUtils { static async propose(provider, daoRootAddress, params, args) { return voteEscrowDaoRootContract(provider, daoRootAddress) .methods.propose({ answerId: 0, description: params.description, ethActions: params.evmActions ?? [], tonActions: params.tvmActions ?? [], }) .sendDelayed({ amount: toInt(0.5, DEFAULT_NATIVE_CURRENCY_DECIMALS), ...args, }); } static async calcTvmActionsValue(connection, daoRootAddress, params, cachedState) { const cache = cachedState || (await getFullContractState(connection, daoRootAddress)); const result = await voteEscrowDaoRootContract(connection, daoRootAddress) .methods.calcTonActionsValue({ actions: params.actions }) .call({ cachedState: cache }); return result.totalValue; } static async getVoteEscrowRoot(connection, daoRootAddress, cachedState) { const cache = cachedState || (await getFullContractState(connection, daoRootAddress)); const result = await voteEscrowDaoRootContract(connection, daoRootAddress) .methods.getVoteEscrowRoot({ answerId: 0 }) .call({ cachedState: cache, responsible: true }); return result.value0; } static async expectedProposalAddress(connection, daoRootAddress, proposalId, cachedState) { const cache = cachedState || (await getFullContractState(connection, daoRootAddress)); const result = await voteEscrowDaoRootContract(connection, daoRootAddress) .methods.expectedProposalAddress({ answerId: 0, proposalId }) .call({ cachedState: cache, responsible: true }); return result.value0; } static async proposalConfiguration(connection, daoRootAddress, cachedState) { const cache = cachedState || (await getFullContractState(connection, daoRootAddress)); const result = await voteEscrowDaoRootContract(connection, daoRootAddress) .methods.proposalConfiguration() .call({ cachedState: cache }); return result.proposalConfiguration; } static decodeEvent(connection, daoRootAddress, args) { return voteEscrowDaoRootContract(connection, daoRootAddress).decodeEvent(args); } static decodeTransaction(connection, daoRootAddress, args) { return voteEscrowDaoRootContract(connection, daoRootAddress).decodeTransaction(args); } static decodeTransactionEvents(connection, daoRootAddress, transaction) { return voteEscrowDaoRootContract(connection, daoRootAddress).decodeTransactionEvents({ transaction }); } }