@broxus/js-core
Version:
MobX-based JavaScript Core library
99 lines (98 loc) • 5.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VoteEscrowProposalUtils = exports.VoteEscrowProposalState = void 0;
const constants_1 = require("../../constants");
const contracts_1 = require("../../models/vote-escrow-proposal/contracts");
const utils_1 = require("../../utils");
var VoteEscrowProposalState;
(function (VoteEscrowProposalState) {
VoteEscrowProposalState[VoteEscrowProposalState["Pending"] = 0] = "Pending";
VoteEscrowProposalState[VoteEscrowProposalState["Active"] = 1] = "Active";
VoteEscrowProposalState[VoteEscrowProposalState["Canceled"] = 2] = "Canceled";
VoteEscrowProposalState[VoteEscrowProposalState["Failed"] = 3] = "Failed";
VoteEscrowProposalState[VoteEscrowProposalState["Succeeded"] = 4] = "Succeeded";
VoteEscrowProposalState[VoteEscrowProposalState["Expired"] = 5] = "Expired";
VoteEscrowProposalState[VoteEscrowProposalState["Queued"] = 6] = "Queued";
VoteEscrowProposalState[VoteEscrowProposalState["Executed"] = 7] = "Executed";
})(VoteEscrowProposalState || (exports.VoteEscrowProposalState = VoteEscrowProposalState = {}));
class VoteEscrowProposalUtils {
static async cancel(provider, proposalAddress, args) {
return (0, contracts_1.voteEscrowProposalContract)(provider, proposalAddress)
.methods.cancel()
.sendDelayed({
amount: (0, utils_1.toInt)(2, constants_1.DEFAULT_NATIVE_CURRENCY_DECIMALS),
...args,
});
}
static async queue(provider, proposalAddress, args) {
return (0, contracts_1.voteEscrowProposalContract)(provider, proposalAddress)
.methods.queue()
.sendExternalDelayed(args);
}
static async execute(provider, proposalAddress, args) {
return (0, contracts_1.voteEscrowProposalContract)(provider, proposalAddress)
.methods.execute()
.sendExternalDelayed(args);
}
static async getOverview(connection, proposalAddress, cachedState) {
const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, proposalAddress);
const result = await (0, contracts_1.voteEscrowProposalContract)(connection, proposalAddress)
.methods.getOverview({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
againstVotes: result.againstVotes_,
description: result.description_,
endTime: Number(result.endTime_),
executionTime: Number(result.executionTime_),
forVotes: result.forVotes_,
proposer: result.proposer_,
quorumVotes: result.quorumVotes_,
startTime: Number(result.startTime_),
state: Number(result.state_),
};
}
static async getConfig(connection, proposalAddress, cachedState) {
const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, proposalAddress);
const result = await (0, contracts_1.voteEscrowProposalContract)(connection, proposalAddress)
.methods.getConfig({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
gracePeriod: Number(result.value0.gracePeriod),
quorumVotes: result.value0.quorumVotes,
threshold: result.value0.threshold,
timeLock: Number(result.value0.timeLock),
votingDelay: Number(result.value0.votingDelay),
votingPeriod: Number(result.value0.votingPeriod),
};
}
static async getActions(connection, proposalAddress, cachedState) {
const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, proposalAddress);
const result = await (0, contracts_1.voteEscrowProposalContract)(connection, proposalAddress)
.methods.getActions({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
evmActions: result.value1.map(item => ({
callData: item.callData,
chainId: item.chainId,
signature: item.signature,
target: item.target,
value: item.value,
})),
tvmActions: result.value0.map(item => ({
payload: item.payload,
target: item.target,
value: item.value,
})),
};
}
static decodeEvent(connection, daoRootAddress, args) {
return (0, contracts_1.voteEscrowProposalContract)(connection, daoRootAddress).decodeEvent(args);
}
static decodeTransaction(connection, daoRootAddress, args) {
return (0, contracts_1.voteEscrowProposalContract)(connection, daoRootAddress).decodeTransaction(args);
}
static decodeTransactionEvents(connection, daoRootAddress, transaction) {
return (0, contracts_1.voteEscrowProposalContract)(connection, daoRootAddress).decodeTransactionEvents({ transaction });
}
}
exports.VoteEscrowProposalUtils = VoteEscrowProposalUtils;