UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

61 lines (60 loc) 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseAppAddedEvent = exports.parseAllocationVoteCastEvent = exports.parseRoundStartedEvent = exports.getEventName = exports.decodeEvent = exports.decodeEvents = exports.filterEventsByName = void 0; const deploy_1 = require("./deploy"); const filterEventsByName = (events, eventName) => { return events.filter(event => event.fragment && event.fragment.name === eventName); }; exports.filterEventsByName = filterEventsByName; const decodeEvents = (contract, events) => { return events.map(event => { return (0, exports.decodeEvent)(event, contract); }); }; exports.decodeEvents = decodeEvents; const decodeEvent = (event, contract) => { return contract.interface.parseLog({ topics: event.topics, data: event.data, }); }; exports.decodeEvent = decodeEvent; const getEventName = (receipt, contract) => { const event = receipt?.logs[0]; const decodedLogs = contract.interface.parseLog({ topics: [...event?.topics], data: event ? event.data : "", }); return decodedLogs?.name; }; exports.getEventName = getEventName; const parseRoundStartedEvent = (event, xAllocationVoting) => { const decoded = (0, exports.decodeEvent)(event, xAllocationVoting); return { roundId: parseInt(decoded?.args[0].toString()), proposer: decoded?.args[1], voteStart: decoded?.args[2], voteEnd: decoded?.args[3], appsIds: decoded?.args[4], }; }; exports.parseRoundStartedEvent = parseRoundStartedEvent; const parseAllocationVoteCastEvent = (event, xAllocationVoting) => { const decoded = (0, exports.decodeEvent)(event, xAllocationVoting); return { voter: decoded?.args[0], roundId: decoded?.args[1], apps: decoded?.args[2], voteWeights: decoded?.args[3], }; }; exports.parseAllocationVoteCastEvent = parseAllocationVoteCastEvent; const parseAppAddedEvent = async (event) => { const { x2EarnApps } = await (0, deploy_1.getOrDeployContractInstances)({ forceDeploy: false }); const decoded = (0, exports.decodeEvent)(event, x2EarnApps); return { id: decoded?.args[0], address: decoded?.args[1], }; }; exports.parseAppAddedEvent = parseAppAddedEvent;