Skip to content

Commit

Permalink
Add wallets and ABI types fixes (#180)
Browse files Browse the repository at this point in the history
* Create separate ABI for ethers and viem

* Add changeset

* Add exports

* Remove unncessary import
  • Loading branch information
besated authored May 28, 2024
1 parent 48fd533 commit 93ea230
Show file tree
Hide file tree
Showing 14 changed files with 278 additions and 146 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-plants-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sei-js/evm": patch
---

Add wallets and ABI types fixes
46 changes: 27 additions & 19 deletions packages/evm/src/precompiles/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type AddressPrecompileContract = ethers.Contract & AddressPrecompileFunct
export const ADDRESS_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001004';

/**
* The ABI for the precompile contract which can be used for interoperability between the EVM and Cosmos.
* The ABI for the address precompile contract which can be used for interoperability between the EVM and Cosmos.
* It can be used to get the associated EVM address for a given Cosmos address and vice versa.
*
* @example
Expand All @@ -79,25 +79,9 @@ export const ADDRESS_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000
* const associatedSeiAddress = useReadContract({ abi: ADDRESS_PRECOMPILE_ABI, address: ADDRESS_PRECOMPILE_ADDRESS, functionName: 'getSeiAddr', args: [address] });
* ```
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the associated Cosmos address for the connected account.
* ```tsx
* import { ADDRESS_PRECOMPILE_ADDRESS, AddressPrecompileContract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const accounts = await provider.send('eth_requestAccounts', []);
*
* const addressPrecompileContract = new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ADDRESS_PRECOMPILE_ABI, signer) as AddressPrecompileContract;
*
* const associatedSeiAddress = await addressPrecompileContract.getSeiAddr(accounts[0]);
* ```
*
* @category Cosmos Interoperability
*/
export const ADDRESS_PRECOMPILE_ABI: Abi & InterfaceAbi = [
export const ADDRESS_PRECOMPILE_ABI: Abi = [
{
inputs: [{ internalType: 'string', name: 'addr', type: 'string' }],
name: 'getEvmAddr',
Expand All @@ -114,6 +98,30 @@ export const ADDRESS_PRECOMPILE_ABI: Abi & InterfaceAbi = [
}
];

/**
* The ABI for the address precompile contract which can be used for interoperability between the EVM and Cosmos.
* It can be used to get the associated EVM address for a given Cosmos address and vice versa.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the associated Cosmos address for the connected account.
* ```tsx
* import { ADDRESS_PRECOMPILE_ADDRESS, AddressPrecompileContract, ETHERS_ADDRESS_PRECOMPILE_ABI } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const accounts = await provider.send('eth_requestAccounts', []);
*
* const addressPrecompileContract = new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ETHERS_ADDRESS_PRECOMPILE_ABI, signer) as AddressPrecompileContract;
*
* const associatedSeiAddress = await addressPrecompileContract.getSeiAddr(accounts[0]);
* ```
*
* @category Cosmos Interoperability
*/
export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_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.
* It can be used to get the associated EVM address for a given Cosmos address and vice versa.
Expand All @@ -138,5 +146,5 @@ export const ADDRESS_PRECOMPILE_ABI: Abi & InterfaceAbi = [
* @category Cosmos Interoperability
*/
export function getAddressPrecompileEthersV6Contract(runner: ContractRunner): AddressPrecompileContract {
return new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ADDRESS_PRECOMPILE_ABI, runner) as AddressPrecompileContract;
return new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ETHERS_ADDRESS_PRECOMPILE_ABI, runner) as AddressPrecompileContract;
}
46 changes: 27 additions & 19 deletions packages/evm/src/precompiles/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type BankPrecompileContract = ethers.Contract & BankPrecompileFunctions;
export const BANK_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001001';

/**
* The ABI for the precompile contract, which can be used for interoperability between the EVM and Cosmos.
* The ABI for the bank precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* Wagmi: Use the `useReadContract` hook to read the balance of the connected account.
Expand All @@ -132,25 +132,9 @@ export const BANK_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000000
* console.log({ balance: data.balance });
* ```
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the balance of the connected account.
* ```tsx
* import { BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, BankPrecompileContract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const accounts = await provider.send('eth_requestAccounts', []);
*
* const bankPrecompileContract = new ethers.Contract(BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, signer) as BankPrecompileContract;
*
* const balance = await bankPrecompileContract.balance(accounts[0], 'usei');
* ```
*
* @category Cosmos Interoperability
*/
export const BANK_PRECOMPILE_ABI: Abi & InterfaceAbi = [
export const BANK_PRECOMPILE_ABI: Abi = [
{
inputs: [{ internalType: 'address', name: 'acc', type: 'address' }],
name: 'all_balances',
Expand Down Expand Up @@ -227,6 +211,30 @@ export const BANK_PRECOMPILE_ABI: Abi & InterfaceAbi = [
}
];

/**
* The ABI for the bank precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the balance of the connected account.
* ```tsx
* import { BANK_PRECOMPILE_ADDRESS, ETHERS_BANK_PRECOMPILE_ABI, BankPrecompileContract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const accounts = await provider.send('eth_requestAccounts', []);
*
* const bankPrecompileContract = new ethers.Contract(BANK_PRECOMPILE_ADDRESS, ETHERS_BANK_PRECOMPILE_ABI, signer) as BankPrecompileContract;
*
* const balance = await bankPrecompileContract.balance(accounts[0], 'usei');
* ```
*
*
* @category Cosmos Interoperability
*/
export const ETHERS_BANK_PRECOMPILE_ABI = BANK_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.
*
Expand All @@ -250,5 +258,5 @@ export const BANK_PRECOMPILE_ABI: Abi & InterfaceAbi = [
* @category Cosmos Interoperability
*/
export const getBankPrecompileEthersV6Contract = (runner: ContractRunner): BankPrecompileContract => {
return new ethers.Contract(BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, runner) as BankPrecompileContract;
return new ethers.Contract(BANK_PRECOMPILE_ADDRESS, ETHERS_BANK_PRECOMPILE_ABI, runner) as BankPrecompileContract;
};
41 changes: 24 additions & 17 deletions packages/evm/src/precompiles/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export type DistributionPrecompileContract = ethers.Contract & DistributionPreco
export const DISTRIBUTION_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001007';

/**
* The ABI for the precompile contract, which can be used for interoperability between the EVM and Cosmos.
* The ABI for the distribution precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* Wagmi: Use the `useWriteContract` hook to set the withdrawal address for rewards for the connected account.
Expand All @@ -96,23 +96,9 @@ export const DISTRIBUTION_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000
* console.log({ hash, isConfirming, isConfirmed });
* ```
*
* @example
* ethers v6: Use the `ethers` library and precompiles to set the withdrawal address for rewards for the connected account.
* ```tsx
* import { DISTRIBUTION_PRECOMPILE_ADDRESS, DISTRIBUTION_PRECOMPILE_ABI, DistributionPrecompileContract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const contract = new ethers.Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, DISTRIBUTION_PRECOMPILE_ABI, signer) as DistributionPrecompileContract;
*
* const response = await contract.setWithdrawAddress('0xADDRESS');
* ```
*
* @category Cosmos Interoperability
*/
export const DISTRIBUTION_PRECOMPILE_ABI: Abi & InterfaceAbi = [
export const DISTRIBUTION_PRECOMPILE_ABI: Abi = [
{
inputs: [{ internalType: 'address', name: 'withdrawAddr', type: 'address' }],
name: 'setWithdrawAddress',
Expand All @@ -129,6 +115,27 @@ export const DISTRIBUTION_PRECOMPILE_ABI: Abi & InterfaceAbi = [
}
];

/**
* The ABI for the distribution precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to set the withdrawal address for rewards for the connected account.
* ```tsx
* import { DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, DistributionPrecompileContract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const contract = new ethers.Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, signer) as DistributionPrecompileContract;
*
* const response = await contract.setWithdrawAddress('0xADDRESS');
* ```
*
* @category Cosmos Interoperability
*/
export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_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.
*
Expand All @@ -150,5 +157,5 @@ export const DISTRIBUTION_PRECOMPILE_ABI: Abi & InterfaceAbi = [
* @category Cosmos Interoperability
*/
export const getDistributionPrecompileEthersV6Contract = (runner: ContractRunner): DistributionPrecompileContract => {
return new ethers.Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, DISTRIBUTION_PRECOMPILE_ABI, runner) as DistributionPrecompileContract;
return new ethers.Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, runner) as DistributionPrecompileContract;
};
40 changes: 24 additions & 16 deletions packages/evm/src/precompiles/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type GovernancePrecompileContract = ethers.Contract & GovernancePrecompil
export const GOVERNANCE_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001006';

/**
* The ABI for the precompile contract, which can be used for interoperability between the EVM and Cosmos.
* The ABI for the governance precompile contract, which can be used for interoperability between the EVM and Cosmos.
*
* @example
* Wagmi
Expand All @@ -80,22 +80,9 @@ export const GOVERNANCE_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000
* );
* ```
*
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, GOVERNANCE_PRECOMPILE_ADDRESS, 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, GOVERNANCE_PRECOMPILE_ABI, signer) as GovernancePrecompileContract;
*
* const depositResponse = await governancePrecompileContract.connect().deposit('PROPOSAL_ID', { value: parseSei(1) });
* ```
* @category Cosmos Interoperability
* */
export const GOVERNANCE_PRECOMPILE_ABI: Abi & InterfaceAbi = [
export const GOVERNANCE_PRECOMPILE_ABI: Abi = [
{
inputs: [{ internalType: 'uint64', name: 'proposalID', type: 'uint64' }],
name: 'deposit',
Expand All @@ -115,6 +102,27 @@ export const GOVERNANCE_PRECOMPILE_ABI: Abi & InterfaceAbi = [
}
];

/**
* 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.
*
Expand All @@ -137,5 +145,5 @@ export const GOVERNANCE_PRECOMPILE_ABI: Abi & InterfaceAbi = [
* @category Cosmos Interoperability
*/
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner) => {
return new ethers.Contract(GOVERNANCE_PRECOMPILE_ADDRESS, GOVERNANCE_PRECOMPILE_ABI, runner) as GovernancePrecompileContract;
return new ethers.Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, runner) as GovernancePrecompileContract;
};
39 changes: 23 additions & 16 deletions packages/evm/src/precompiles/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,9 @@ export const IBC_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000000000000
* const isSuccessful = useReadContract({ abi: IBC_PRECOMPILE_ABI, address: IBC_PRECOMPILE_ADDRESS, functionName: 'transfer', args: [COSMOS_ADDRESS, PORT, ... ] });
* ```
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the associated Cosmos address for the connected account.
* ```tsx
* import { IBC_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(IBC_PRECOMPILE_ADDRESS, signer);
*
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* @category Cosmos Interoperability
*/
export const IBC_PRECOMPILE_ABI: Abi & InterfaceAbi = [
export const IBC_PRECOMPILE_ABI: Abi = [
{
inputs: [
{ internalType: 'string', name: 'toAddress', type: 'string' },
Expand Down Expand Up @@ -151,6 +137,27 @@ export const IBC_PRECOMPILE_ABI: Abi & InterfaceAbi = [
}
];

/**
* The ABI for the IBC precompile contract.
*
* @example
* ethers v6: Use the `ethers` library and precompiles to read the associated Cosmos address for the connected account.
* ```tsx
* import { IBC_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
* const signer = await provider.getSigner();
*
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(IBC_PRECOMPILE_ADDRESS, signer);
*
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* @category Cosmos Interoperability
*/
export const ETHERS_IBC_PRECOMPILE_ABI = IBC_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.
*
Expand All @@ -173,5 +180,5 @@ export const IBC_PRECOMPILE_ABI: Abi & InterfaceAbi = [
* @category Cosmos Interoperability
*/
export const getIbcPrecompileEthersV6Contract = (runner: ContractRunner): IbcPrecompileContract => {
return new ethers.Contract(IBC_PRECOMPILE_ADDRESS, IBC_PRECOMPILE_ABI, runner) as IbcPrecompileContract;
return new ethers.Contract(IBC_PRECOMPILE_ADDRESS, ETHERS_IBC_PRECOMPILE_ABI, runner) as IbcPrecompileContract;
};
3 changes: 3 additions & 0 deletions packages/evm/src/precompiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export * from './distribution';
export * from './governance';
export * from './ibc';
export * from './json';
export * from './oracle';
export * from './pointer';
export * from './pointerview';
export * from './staking';
export * from './wasm';
Loading

0 comments on commit 93ea230

Please sign in to comment.