UNPKG

@swaptoshi/governance-module

Version:

Klayr governance on-chain module

87 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProposalStore = void 0; const schema_1 = require("../schema"); const types_1 = require("../types"); const utils_1 = require("@swaptoshi/utils"); const base_1 = require("./base"); const instances_1 = require("./instances"); class ProposalStore extends base_1.BaseStoreWithInstance { constructor() { super(...arguments); this.schema = schema_1.proposalStoreSchema; this.default = { title: '', summary: '', deposited: BigInt(0), author: Buffer.alloc(0), turnout: { for: BigInt(0), against: BigInt(0), abstain: BigInt(0) }, parameters: { createdHeight: 0, startHeight: 0, quorumHeight: 0, endHeight: 0, executionHeight: 0, boostFactor: 1, maxBoostDuration: 0, enableBoosting: false, enableTurnoutBias: false, quorumMode: types_1.QuorumMode.FOR_AGAINST_ABSTAIN, quorumTreshold: '0', }, voteSummary: { for: BigInt(0), against: BigInt(0), abstain: BigInt(0) }, status: types_1.ProposalStatus.EXECUTED_WITH_ERROR, actions: [], attributes: [], }; } async verifyCreateProposal(ctx, params) { this._checkDependencies(); const proposal = new instances_1.Proposal(this.stores, this.events, this.config, this.genesisConfig, this.moduleName, this.governableConfigRegistry, undefined, Buffer.alloc(0)); proposal.addImmutableDependencies({ context: ctx, tokenMethod: this.tokenMethod, internalMethod: this.internalMethod, }); await proposal.verifyCreate(params); } async createProposal(ctx, params, verify = true) { this._checkDependencies(); const proposal = new instances_1.Proposal(this.stores, this.events, this.config, this.genesisConfig, this.moduleName, this.governableConfigRegistry, undefined, Buffer.alloc(0)); proposal.addMutableDependencies({ context: ctx, tokenMethod: this.tokenMethod, internalMethod: this.internalMethod, }); await proposal.create(params, verify); } async getMutableProposal(ctx, proposalId) { this._checkDependencies(); const key = this.getKey(proposalId); const proposalData = await this.get(ctx.context, key); const proposal = new instances_1.Proposal(this.stores, this.events, this.config, this.genesisConfig, this.moduleName, this.governableConfigRegistry, proposalData, key); proposal.addMutableDependencies({ context: ctx, tokenMethod: this.tokenMethod, internalMethod: this.internalMethod, }); return proposal; } async getImmutableProposal(ctx, proposalId) { this._checkDependencies(); const key = this.getKey(proposalId); const proposalData = await this.get(ctx.context, key); const proposal = new instances_1.Proposal(this.stores, this.events, this.config, this.genesisConfig, this.moduleName, this.governableConfigRegistry, proposalData, key); proposal.addImmutableDependencies({ context: ctx, tokenMethod: this.tokenMethod, internalMethod: this.internalMethod, }); return proposal; } getKey(proposalId) { return utils_1.bytes.numberToBytes(proposalId); } } exports.ProposalStore = ProposalStore; //# sourceMappingURL=proposal.js.map