/* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ import { Address, Contract, ContractState, TestContractResult, HexString, ContractFactory, EventSubscribeOptions, EventSubscription, CallContractParams, CallContractResult, TestContractParams, ContractEvent, subscribeContractEvent, subscribeContractEvents, testMethod, callMethod, multicallMethods, fetchContractState, Asset, ContractInstance, getContractEventsCurrentCount, TestContractParamsWithoutMaps, TestContractResultWithoutMaps, SignExecuteContractMethodParams, SignExecuteScriptTxResult, signExecuteMethod, addStdIdToFields, encodeContractFields, Narrow, } from "@alephium/web3"; import { default as GovernanceDemoContractJson } from "../examples/GovernanceDemo.ral.json"; import { getContractByCodeHash, registerContract } from "./contracts"; import * as types from "./types"; import { RalphMap } from "@alephium/web3"; // Custom types for the contract export namespace GovernanceDemoTypes { export type Fields = { xalphStakeVault: HexString; proposalOptions: [bigint, bigint, bigint, bigint]; owner: Address; totalVotedAmount: bigint; votingStartTime: bigint; votingEndTime: bigint; }; export type State = ContractState; export type VotingStartedEvent = ContractEvent<{ votingStartTime: bigint }>; export type VoteCastEvent = ContractEvent<{ voter: Address; proposalVoted: bigint; amount: bigint; }>; export type VotingEndedEvent = ContractEvent<{ votingEndTime: bigint }>; export interface CallMethodTable { onStake: { params: CallContractParams<{ user: Address; addedAmount: bigint }>; result: CallContractResult; }; onUnstake: { params: CallContractParams<{ user: Address; removedAmount: bigint }>; result: CallContractResult; }; startVoting: { params: Omit, "args">; result: CallContractResult; }; endVoting: { params: Omit, "args">; result: CallContractResult; }; getProposalOptions: { params: Omit, "args">; result: CallContractResult<[bigint, bigint, bigint, bigint]>; }; getUserVote: { params: CallContractParams<{ user: Address }>; result: CallContractResult; }; getProposalVotes: { params: CallContractParams<{ proposal: bigint }>; result: CallContractResult; }; getTotalVotedAmount: { params: Omit, "args">; result: CallContractResult; }; vote: { params: CallContractParams<{ proposal: bigint }>; result: CallContractResult; }; isVotingStarted: { params: Omit, "args">; result: CallContractResult; }; isVotingEnded: { params: Omit, "args">; result: CallContractResult; }; isVotingActive: { params: Omit, "args">; result: CallContractResult; }; } export type CallMethodParams = CallMethodTable[T]["params"]; export type CallMethodResult = CallMethodTable[T]["result"]; export type MultiCallParams = Partial<{ [Name in keyof CallMethodTable]: CallMethodTable[Name]["params"]; }>; export type MultiCallResults = { [MaybeName in keyof T]: MaybeName extends keyof CallMethodTable ? CallMethodTable[MaybeName]["result"] : undefined; }; export type MulticallReturnType = { [index in keyof Callss]: MultiCallResults; }; export interface SignExecuteMethodTable { onStake: { params: SignExecuteContractMethodParams<{ user: Address; addedAmount: bigint; }>; result: SignExecuteScriptTxResult; }; onUnstake: { params: SignExecuteContractMethodParams<{ user: Address; removedAmount: bigint; }>; result: SignExecuteScriptTxResult; }; startVoting: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; endVoting: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; getProposalOptions: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; getUserVote: { params: SignExecuteContractMethodParams<{ user: Address }>; result: SignExecuteScriptTxResult; }; getProposalVotes: { params: SignExecuteContractMethodParams<{ proposal: bigint }>; result: SignExecuteScriptTxResult; }; getTotalVotedAmount: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; vote: { params: SignExecuteContractMethodParams<{ proposal: bigint }>; result: SignExecuteScriptTxResult; }; isVotingStarted: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; isVotingEnded: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; isVotingActive: { params: Omit, "args">; result: SignExecuteScriptTxResult; }; } export type SignExecuteMethodParams = SignExecuteMethodTable[T]["params"]; export type SignExecuteMethodResult = SignExecuteMethodTable[T]["result"]; export type Maps = { userVotes?: Map; proposalVotes?: Map; }; } class Factory extends ContractFactory< GovernanceDemoInstance, GovernanceDemoTypes.Fields > { encodeFields(fields: GovernanceDemoTypes.Fields) { return encodeContractFields( addStdIdToFields(this.contract, fields), this.contract.fieldsSig, types.AllStructs ); } eventIndex = { VotingStarted: 0, VoteCast: 1, VotingEnded: 2 }; consts = { ErrorCodes: { AssetAddressCallerOnly: BigInt("0"), UserNotStaked: BigInt("1"), InvalidVoteProposal: BigInt("2"), VotingNotStarted: BigInt("3"), VotingAlreadyStarted: BigInt("4"), VotingAlreadyEnded: BigInt("5"), AlreadyVoted: BigInt("6"), OwnerOnly: BigInt("7"), StakeVaultCallerOnly: BigInt("8"), }, }; at(address: string): GovernanceDemoInstance { return new GovernanceDemoInstance(address); } tests = { onStake: async ( params: TestContractParams< GovernanceDemoTypes.Fields, { user: Address; addedAmount: bigint }, GovernanceDemoTypes.Maps > ): Promise> => { return testMethod(this, "onStake", params, getContractByCodeHash); }, onUnstake: async ( params: TestContractParams< GovernanceDemoTypes.Fields, { user: Address; removedAmount: bigint }, GovernanceDemoTypes.Maps > ): Promise> => { return testMethod(this, "onUnstake", params, getContractByCodeHash); }, startVoting: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise> => { return testMethod(this, "startVoting", params, getContractByCodeHash); }, endVoting: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise> => { return testMethod(this, "endVoting", params, getContractByCodeHash); }, getProposalOptions: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise< TestContractResult< [bigint, bigint, bigint, bigint], GovernanceDemoTypes.Maps > > => { return testMethod( this, "getProposalOptions", params, getContractByCodeHash ); }, getUserVote: async ( params: TestContractParams< GovernanceDemoTypes.Fields, { user: Address }, GovernanceDemoTypes.Maps > ): Promise< TestContractResult > => { return testMethod(this, "getUserVote", params, getContractByCodeHash); }, getProposalVotes: async ( params: TestContractParams< GovernanceDemoTypes.Fields, { proposal: bigint }, GovernanceDemoTypes.Maps > ): Promise> => { return testMethod( this, "getProposalVotes", params, getContractByCodeHash ); }, getTotalVotedAmount: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise> => { return testMethod( this, "getTotalVotedAmount", params, getContractByCodeHash ); }, vote: async ( params: TestContractParams< GovernanceDemoTypes.Fields, { proposal: bigint }, GovernanceDemoTypes.Maps > ): Promise> => { return testMethod(this, "vote", params, getContractByCodeHash); }, isVotingStarted: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise> => { return testMethod(this, "isVotingStarted", params, getContractByCodeHash); }, isVotingEnded: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise> => { return testMethod(this, "isVotingEnded", params, getContractByCodeHash); }, isVotingActive: async ( params: Omit< TestContractParams< GovernanceDemoTypes.Fields, never, GovernanceDemoTypes.Maps >, "args" > ): Promise> => { return testMethod(this, "isVotingActive", params, getContractByCodeHash); }, }; stateForTest( initFields: GovernanceDemoTypes.Fields, asset?: Asset, address?: string, maps?: GovernanceDemoTypes.Maps ) { return this.stateForTest_(initFields, asset, address, maps); } } // Use this object to test and deploy the contract export const GovernanceDemo = new Factory( Contract.fromJson( GovernanceDemoContractJson, "=6-2+e2=2+c=1-5=2-2=1-3+0=3-1+2=2-1+7=4+7=1+2f1=1-2=1+ff=2-1+c=3-1+d=3-2+e343f3=13-1+a=339-1+b=34+7a7e0214696e73657274206174206d617020706174683a2000=26-2+60=353-1+b=38+7a7e021472656d6f7665206174206d617020706174683a2000=19-1+5=91-1+6=48+7a7e0214696e73657274206174206d617020706174683a2000=25-1+6=878", "551e89bdda9d4514effbfebcd14d1383bcfb9a8e1c10b78fda75c33aca894624", types.AllStructs ) ); registerContract(GovernanceDemo); // Use this class to interact with the blockchain export class GovernanceDemoInstance extends ContractInstance { constructor(address: Address) { super(address); } maps = { userVotes: new RalphMap( GovernanceDemo.contract, this.contractId, "userVotes" ), proposalVotes: new RalphMap( GovernanceDemo.contract, this.contractId, "proposalVotes" ), }; async fetchState(): Promise { return fetchContractState(GovernanceDemo, this); } async getContractEventsCurrentCount(): Promise { return getContractEventsCurrentCount(this.address); } subscribeVotingStartedEvent( options: EventSubscribeOptions, fromCount?: number ): EventSubscription { return subscribeContractEvent( GovernanceDemo.contract, this, options, "VotingStarted", fromCount ); } subscribeVoteCastEvent( options: EventSubscribeOptions, fromCount?: number ): EventSubscription { return subscribeContractEvent( GovernanceDemo.contract, this, options, "VoteCast", fromCount ); } subscribeVotingEndedEvent( options: EventSubscribeOptions, fromCount?: number ): EventSubscription { return subscribeContractEvent( GovernanceDemo.contract, this, options, "VotingEnded", fromCount ); } subscribeAllEvents( options: EventSubscribeOptions< | GovernanceDemoTypes.VotingStartedEvent | GovernanceDemoTypes.VoteCastEvent | GovernanceDemoTypes.VotingEndedEvent >, fromCount?: number ): EventSubscription { return subscribeContractEvents( GovernanceDemo.contract, this, options, fromCount ); } view = { onStake: async ( params: GovernanceDemoTypes.CallMethodParams<"onStake"> ): Promise> => { return callMethod( GovernanceDemo, this, "onStake", params, getContractByCodeHash ); }, onUnstake: async ( params: GovernanceDemoTypes.CallMethodParams<"onUnstake"> ): Promise> => { return callMethod( GovernanceDemo, this, "onUnstake", params, getContractByCodeHash ); }, startVoting: async ( params?: GovernanceDemoTypes.CallMethodParams<"startVoting"> ): Promise> => { return callMethod( GovernanceDemo, this, "startVoting", params === undefined ? {} : params, getContractByCodeHash ); }, endVoting: async ( params?: GovernanceDemoTypes.CallMethodParams<"endVoting"> ): Promise> => { return callMethod( GovernanceDemo, this, "endVoting", params === undefined ? {} : params, getContractByCodeHash ); }, getProposalOptions: async ( params?: GovernanceDemoTypes.CallMethodParams<"getProposalOptions"> ): Promise> => { return callMethod( GovernanceDemo, this, "getProposalOptions", params === undefined ? {} : params, getContractByCodeHash ); }, getUserVote: async ( params: GovernanceDemoTypes.CallMethodParams<"getUserVote"> ): Promise> => { return callMethod( GovernanceDemo, this, "getUserVote", params, getContractByCodeHash ); }, getProposalVotes: async ( params: GovernanceDemoTypes.CallMethodParams<"getProposalVotes"> ): Promise> => { return callMethod( GovernanceDemo, this, "getProposalVotes", params, getContractByCodeHash ); }, getTotalVotedAmount: async ( params?: GovernanceDemoTypes.CallMethodParams<"getTotalVotedAmount"> ): Promise> => { return callMethod( GovernanceDemo, this, "getTotalVotedAmount", params === undefined ? {} : params, getContractByCodeHash ); }, vote: async ( params: GovernanceDemoTypes.CallMethodParams<"vote"> ): Promise> => { return callMethod( GovernanceDemo, this, "vote", params, getContractByCodeHash ); }, isVotingStarted: async ( params?: GovernanceDemoTypes.CallMethodParams<"isVotingStarted"> ): Promise> => { return callMethod( GovernanceDemo, this, "isVotingStarted", params === undefined ? {} : params, getContractByCodeHash ); }, isVotingEnded: async ( params?: GovernanceDemoTypes.CallMethodParams<"isVotingEnded"> ): Promise> => { return callMethod( GovernanceDemo, this, "isVotingEnded", params === undefined ? {} : params, getContractByCodeHash ); }, isVotingActive: async ( params?: GovernanceDemoTypes.CallMethodParams<"isVotingActive"> ): Promise> => { return callMethod( GovernanceDemo, this, "isVotingActive", params === undefined ? {} : params, getContractByCodeHash ); }, }; transact = { onStake: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"onStake"> ): Promise> => { return signExecuteMethod(GovernanceDemo, this, "onStake", params); }, onUnstake: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"onUnstake"> ): Promise> => { return signExecuteMethod(GovernanceDemo, this, "onUnstake", params); }, startVoting: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"startVoting"> ): Promise> => { return signExecuteMethod(GovernanceDemo, this, "startVoting", params); }, endVoting: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"endVoting"> ): Promise> => { return signExecuteMethod(GovernanceDemo, this, "endVoting", params); }, getProposalOptions: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"getProposalOptions"> ): Promise< GovernanceDemoTypes.SignExecuteMethodResult<"getProposalOptions"> > => { return signExecuteMethod( GovernanceDemo, this, "getProposalOptions", params ); }, getUserVote: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"getUserVote"> ): Promise> => { return signExecuteMethod(GovernanceDemo, this, "getUserVote", params); }, getProposalVotes: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"getProposalVotes"> ): Promise< GovernanceDemoTypes.SignExecuteMethodResult<"getProposalVotes"> > => { return signExecuteMethod( GovernanceDemo, this, "getProposalVotes", params ); }, getTotalVotedAmount: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"getTotalVotedAmount"> ): Promise< GovernanceDemoTypes.SignExecuteMethodResult<"getTotalVotedAmount"> > => { return signExecuteMethod( GovernanceDemo, this, "getTotalVotedAmount", params ); }, vote: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"vote"> ): Promise> => { return signExecuteMethod(GovernanceDemo, this, "vote", params); }, isVotingStarted: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"isVotingStarted"> ): Promise< GovernanceDemoTypes.SignExecuteMethodResult<"isVotingStarted"> > => { return signExecuteMethod(GovernanceDemo, this, "isVotingStarted", params); }, isVotingEnded: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"isVotingEnded"> ): Promise< GovernanceDemoTypes.SignExecuteMethodResult<"isVotingEnded"> > => { return signExecuteMethod(GovernanceDemo, this, "isVotingEnded", params); }, isVotingActive: async ( params: GovernanceDemoTypes.SignExecuteMethodParams<"isVotingActive"> ): Promise< GovernanceDemoTypes.SignExecuteMethodResult<"isVotingActive"> > => { return signExecuteMethod(GovernanceDemo, this, "isVotingActive", params); }, }; async multicall( calls: Calls ): Promise>; async multicall( callss: Narrow ): Promise>; async multicall< Callss extends | GovernanceDemoTypes.MultiCallParams | GovernanceDemoTypes.MultiCallParams[] >(callss: Callss): Promise { return await multicallMethods( GovernanceDemo, this, callss, getContractByCodeHash ); } }