@dydxfoundation/governance
Version:
dYdX governance smart contracts
50 lines (49 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExecutorVotingData = exports.getStrategyVotingSupplyForProposal = exports.getProposalDataAndStateById = void 0;
const GovernanceReturnTypes_1 = require("../types/GovernanceReturnTypes");
const STRATEGY_VOTING_SUPPLY_AT_BLOCK_CACHE = {};
const EXECUTOR_VOTING_DATA_CACHE = {};
async function getProposalDataAndStateById(governance, proposalId) {
const [proposal, proposalState,] = await Promise.all([
governance.getProposalById(proposalId),
governance.getProposalState(proposalId),
]);
return {
proposal,
proposalState: Object.values(GovernanceReturnTypes_1.ProposalState)[proposalState],
};
}
exports.getProposalDataAndStateById = getProposalDataAndStateById;
async function getStrategyVotingSupplyForProposal(strategy, startBlock) {
if (!STRATEGY_VOTING_SUPPLY_AT_BLOCK_CACHE[strategy.address]) {
// cache strategy address so we can enter 2nd if statement without null pointer
STRATEGY_VOTING_SUPPLY_AT_BLOCK_CACHE[strategy.address] = {};
}
if (!STRATEGY_VOTING_SUPPLY_AT_BLOCK_CACHE[strategy.address][startBlock]) {
// cache voting supply for this block
const votingSupply = await strategy.getTotalVotingSupplyAt(startBlock);
STRATEGY_VOTING_SUPPLY_AT_BLOCK_CACHE[strategy.address][startBlock] = votingSupply;
}
return STRATEGY_VOTING_SUPPLY_AT_BLOCK_CACHE[strategy.address][startBlock];
}
exports.getStrategyVotingSupplyForProposal = getStrategyVotingSupplyForProposal;
async function getExecutorVotingData(executor) {
if (!EXECUTOR_VOTING_DATA_CACHE[executor.address]) {
// cache executor voting data
const [minimumQuorum, voteDifferential, executorVotingPrecision, gracePeriod,] = await Promise.all([
executor.MINIMUM_QUORUM(),
executor.VOTE_DIFFERENTIAL(),
executor.ONE_HUNDRED_WITH_PRECISION(),
executor.GRACE_PERIOD(),
]);
EXECUTOR_VOTING_DATA_CACHE[executor.address] = {
minimumQuorum,
executorVotingPrecision,
voteDifferential,
gracePeriod,
};
}
return EXECUTOR_VOTING_DATA_CACHE[executor.address];
}
exports.getExecutorVotingData = getExecutorVotingData;