-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathgovernance.ts
149 lines (143 loc) · 5.43 KB
/
governance.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { ContractRunner, ethers, InterfaceAbi } from 'ethers';
import { Abi } from 'viem';
/**
* Represents the functions available in the Governance precompile contract,
* facilitating interoperability between the EVM and Cosmos.
* @category Cosmos Interoperability
*/
export interface GovernancePrecompileFunctions {
/**
* Deposits funds into a governance proposal.
* @param proposalID The ID of the proposal to deposit funds into.
* @returns A Promise resolving to an object indicating the success of the transaction.
* @category Cosmos Interoperability
*/
deposit(proposalID: ethers.BigNumberish): Promise<{ success: boolean }>;
/**
* Votes on a governance proposal.
* @param proposalID The ID of the proposal to vote on.
* @param option The option to vote for.
* @returns A Promise resolving to an object indicating the success of the transaction.
* @category Cosmos Interoperability
*/
vote(proposalID: ethers.BigNumberish, option: ethers.BigNumberish): Promise<{ success: boolean }>;
}
/** Represents the typed contract instance for the GOVERNANCE precompile contract.
* @category Cosmos Interoperability
* */
export type GovernancePrecompileContract = ethers.Contract & GovernancePrecompileFunctions;
/**
* The address of the GOVERNANCE precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* Wagmi
* ```tsx
* import { GOVERNANCE_PRECOMPILE_ADDRESS, GOVERNANCE_PRECOMPILE_ABI } from '@sei-js/evm';
* import { useReadContract } from 'wagmi';
**
* const depositResponse = useContractFunction(
* GOVERNANCE_PRECOMPILE_ADDRESS,
* GOVERNANCE_PRECOMPILE_ABI,
* 'deposit'
* );
* ```
*
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, GOVERNANCE_PRECOMPILE_ADDRESS, parseSei } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const governancePrecompileContract = getGovernancePrecompileEthersV6Contract(GOVERNANCE_PRECOMPILE_ADDRESS, signer);
*
* //Surround with try/catch for detailed errors
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseSei(1) });
* ```
*
* @category Cosmos Interoperability
* */
export const GOVERNANCE_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001006';
/**
* The ABI for the governance precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* Wagmi
* ```tsx
* import { GOVERNANCE_PRECOMPILE_ADDRESS, GOVERNANCE_PRECOMPILE_ABI } from '@sei-js/evm';
* import { useContractFunction } from '@wagmi/core';
*
* const depositResponse = useContractFunction(
* GOVERNANCE_PRECOMPILE_ADDRESS,
* GOVERNANCE_PRECOMPILE_ABI,
* 'deposit'
* );
* ```
*
* @category Cosmos Interoperability
* */
export const GOVERNANCE_PRECOMPILE_ABI: Abi = [
{
inputs: [{ internalType: 'uint64', name: 'proposalID', type: 'uint64' }],
name: 'deposit',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'payable',
type: 'function'
},
{
inputs: [
{ internalType: 'uint64', name: 'proposalID', type: 'uint64' },
{ internalType: 'int32', name: 'option', type: 'int32' }
],
name: 'vote',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
}
];
/**
* The ABI for the governance precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, parseSei } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const governancePrecompileContract = new ethers.Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, signer) as GovernancePrecompileContract;
*
* const depositResponse = await governancePrecompileContract.connect().deposit('PROPOSAL_ID', { value: parseSei(1) });
* ```
*
* @category Cosmos Interoperability
*/
export const ETHERS_GOVERNANCE_PRECOMPILE_ABI = GOVERNANCE_PRECOMPILE_ABI as InterfaceAbi;
/**
* Creates and returns an ethers v6 contract instance with the provided signer, for use in interoperability between the EVM and Cosmos.
*
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, parseSei } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const governancePrecompileContract = getGovernancePrecompileEthersV6Contract(signer);
*
* //Surround with try/catch for detailed errors
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseSei(1) });
* ```
* @param runner a [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance allowing interaction with the precompile contract.
* @category Cosmos Interoperability
*/
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner) => {
return new ethers.Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, runner) as GovernancePrecompileContract;
};