From 93ea2303b6652049820b95907423c72295678be4 Mon Sep 17 00:00:00 2001 From: bt <99624770+besated@users.noreply.github.com> Date: Mon, 27 May 2024 17:44:01 -0700 Subject: [PATCH] Add wallets and ABI types fixes (#180) * Create separate ABI for ethers and viem * Add changeset * Add exports * Remove unncessary import --- .changeset/rude-plants-enjoy.md | 5 +++ packages/evm/src/precompiles/address.ts | 46 ++++++++++++-------- packages/evm/src/precompiles/bank.ts | 46 ++++++++++++-------- packages/evm/src/precompiles/distribution.ts | 41 +++++++++-------- packages/evm/src/precompiles/governance.ts | 40 ++++++++++------- packages/evm/src/precompiles/ibc.ts | 39 ++++++++++------- packages/evm/src/precompiles/index.ts | 3 ++ packages/evm/src/precompiles/json.ts | 41 +++++++++-------- packages/evm/src/precompiles/oracle.ts | 41 +++++++++-------- packages/evm/src/precompiles/pointer.ts | 26 ++++++++++- packages/evm/src/precompiles/pointerview.ts | 28 ++++++++++-- packages/evm/src/precompiles/staking.ts | 38 +++++++++------- packages/evm/src/precompiles/wasm.ts | 6 ++- packages/evm/src/providers/wagmi.ts | 24 ++++++++-- 14 files changed, 278 insertions(+), 146 deletions(-) create mode 100644 .changeset/rude-plants-enjoy.md diff --git a/.changeset/rude-plants-enjoy.md b/.changeset/rude-plants-enjoy.md new file mode 100644 index 00000000..b67ceedf --- /dev/null +++ b/.changeset/rude-plants-enjoy.md @@ -0,0 +1,5 @@ +--- +"@sei-js/evm": patch +--- + +Add wallets and ABI types fixes diff --git a/packages/evm/src/precompiles/address.ts b/packages/evm/src/precompiles/address.ts index 73df3fb6..1f6f8569 100644 --- a/packages/evm/src/precompiles/address.ts +++ b/packages/evm/src/precompiles/address.ts @@ -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 @@ -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', @@ -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. @@ -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; } diff --git a/packages/evm/src/precompiles/bank.ts b/packages/evm/src/precompiles/bank.ts index 8c64bd61..4675a5af 100644 --- a/packages/evm/src/precompiles/bank.ts +++ b/packages/evm/src/precompiles/bank.ts @@ -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. @@ -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', @@ -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. * @@ -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; }; diff --git a/packages/evm/src/precompiles/distribution.ts b/packages/evm/src/precompiles/distribution.ts index 5bd83dc0..a7772c86 100644 --- a/packages/evm/src/precompiles/distribution.ts +++ b/packages/evm/src/precompiles/distribution.ts @@ -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. @@ -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', @@ -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. * @@ -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; }; diff --git a/packages/evm/src/precompiles/governance.ts b/packages/evm/src/precompiles/governance.ts index c3c53ff1..34e6aeaa 100644 --- a/packages/evm/src/precompiles/governance.ts +++ b/packages/evm/src/precompiles/governance.ts @@ -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 @@ -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', @@ -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. * @@ -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; }; diff --git a/packages/evm/src/precompiles/ibc.ts b/packages/evm/src/precompiles/ibc.ts index 12563721..d17be645 100644 --- a/packages/evm/src/precompiles/ibc.ts +++ b/packages/evm/src/precompiles/ibc.ts @@ -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' }, @@ -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. * @@ -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; }; diff --git a/packages/evm/src/precompiles/index.ts b/packages/evm/src/precompiles/index.ts index 69d7462e..4d0951ad 100644 --- a/packages/evm/src/precompiles/index.ts +++ b/packages/evm/src/precompiles/index.ts @@ -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'; diff --git a/packages/evm/src/precompiles/json.ts b/packages/evm/src/precompiles/json.ts index a91d765c..59154616 100644 --- a/packages/evm/src/precompiles/json.ts +++ b/packages/evm/src/precompiles/json.ts @@ -74,7 +74,7 @@ export type JSONPrecompileContract = ethers.Contract & JSONPrecompileFunctions; export const JSON_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001003'; /** - * The ABI for the precompile contract, which can be used for interoperability between the EVM and Cosmos. + * The ABI for the JSON precompile contract, which can be used for interoperability between the EVM and Cosmos. * * @example * Wagmi: Use the `useReadContract` hook to read the associated Cosmos address for the connected account. @@ -88,23 +88,9 @@ export const JSON_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000000 * const extractedBytes = useReadContract({ abi: JSON_PRECOMPILE_ABI, address: JSON_PRECOMPILE_ADDRESS, functionName: 'extractAsBytes', args: ['0xINPUT', 'KEY'] }); * ``` * - * @example - * ethers v6 - * ```tsx - * import { JSON_PRECOMPILE_ADDRESS, JSON_PRECOMPILE_ABI, JSONPrecompileContract } 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 jsonPrecompileContract = new ethers.Contract(JSON_PRECOMPILE_ADDRESS, JSON_PRECOMPILE_ABI, signer) as JSONPrecompileContract; - * - * const response = await jsonPrecompileContract.connect().extractAsBytes('0xINPUT', 'KEY'); - * ``` - * * @category Cosmos Interoperability */ -export const JSON_PRECOMPILE_ABI: Abi & InterfaceAbi = [ +export const JSON_PRECOMPILE_ABI: Abi = [ { inputs: [ { internalType: 'bytes', name: 'input', type: 'bytes' }, @@ -137,6 +123,27 @@ export const JSON_PRECOMPILE_ABI: Abi & InterfaceAbi = [ } ]; +/** + * The ABI for the JSON precompile contract, which can be used for interoperability between the EVM and Cosmos. + * + * @example + * ethers v6 + * ```tsx + * import { JSON_PRECOMPILE_ADDRESS, ETHERS_JSON_PRECOMPILE_ABI, JSONPrecompileContract } 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 jsonPrecompileContract = new ethers.Contract(JSON_PRECOMPILE_ADDRESS, ETHERS_JSON_PRECOMPILE_ABI, signer) as JSONPrecompileContract; + * + * const response = await jsonPrecompileContract.connect().extractAsBytes('0xINPUT', 'KEY'); + * ``` + * + * @category Cosmos Interoperability + */ +export const ETHERS_JSON_PRECOMPILE_ABI = JSON_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. * @@ -159,5 +166,5 @@ export const JSON_PRECOMPILE_ABI: Abi & InterfaceAbi = [ * @category Cosmos Interoperability */ export const getJSONPrecompileEthersV6Contract = (runner: ContractRunner): JSONPrecompileContract => { - return new ethers.Contract(JSON_PRECOMPILE_ADDRESS, JSON_PRECOMPILE_ABI, runner) as JSONPrecompileContract; + return new ethers.Contract(JSON_PRECOMPILE_ADDRESS, ETHERS_JSON_PRECOMPILE_ABI, runner) as JSONPrecompileContract; }; diff --git a/packages/evm/src/precompiles/oracle.ts b/packages/evm/src/precompiles/oracle.ts index 5362bc3e..efb30b7f 100644 --- a/packages/evm/src/precompiles/oracle.ts +++ b/packages/evm/src/precompiles/oracle.ts @@ -100,24 +100,9 @@ export const ORACLE_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000000000 * console.log(data); * ``` * - * @example - * ethers v6: Use the `ethers` library and precompiles to read the exchange rates. - * ```tsx - * import { ORACLE_PRECOMPILE_ADDRESS, ORACLE_PRECOMPILE_ABI, OraclePrecompileContract } 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 oraclePrecompileContract = new ethers.Contract(ORACLE_PRECOMPILE_ADDRESS, ORACLE_PRECOMPILE_ABI, signer) as OraclePrecompileContract; - * - * const exchangeRates = await oraclePrecompileContract.getExchangeRates(); - * console.log(exchangeRates); - * ``` - * * @category Cosmos Interoperability */ -export const ORACLE_PRECOMPILE_ABI: Abi & InterfaceAbi = [ +export const ORACLE_PRECOMPILE_ABI: Abi = [ { inputs: [], name: 'getExchangeRates', @@ -164,6 +149,28 @@ export const ORACLE_PRECOMPILE_ABI: Abi & InterfaceAbi = [ } ]; +/** + * The ABI for the Oracle 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 exchange rates. + * ```tsx + * import { ORACLE_PRECOMPILE_ADDRESS, ETHERS_ORACLE_PRECOMPILE_ABI, OraclePrecompileContract } 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 oraclePrecompileContract = new ethers.Contract(ORACLE_PRECOMPILE_ADDRESS, ETHERS_ORACLE_PRECOMPILE_ABI, signer) as OraclePrecompileContract; + * + * const exchangeRates = await oraclePrecompileContract.getExchangeRates(); + * console.log(exchangeRates); + * ``` + * + * @category Cosmos Interoperability + */ +export const ETHERS_ORACLE_PRECOMPILE_ABI = ORACLE_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. * @@ -186,5 +193,5 @@ export const ORACLE_PRECOMPILE_ABI: Abi & InterfaceAbi = [ * @category Cosmos Interoperability */ export const getOraclePrecompileEthersV6Contract = (runner: ContractRunner): OraclePrecompileContract => { - return new ethers.Contract(ORACLE_PRECOMPILE_ADDRESS, ORACLE_PRECOMPILE_ABI, runner) as OraclePrecompileContract; + return new ethers.Contract(ORACLE_PRECOMPILE_ADDRESS, ETHERS_ORACLE_PRECOMPILE_ABI, runner) as OraclePrecompileContract; }; diff --git a/packages/evm/src/precompiles/pointer.ts b/packages/evm/src/precompiles/pointer.ts index f27cbde2..afee5ceb 100644 --- a/packages/evm/src/precompiles/pointer.ts +++ b/packages/evm/src/precompiles/pointer.ts @@ -115,7 +115,7 @@ export const POINTER_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000 * * @category Cosmos Interoperability */ -export const POINTER_PRECOMPILE_ABI: Abi & InterfaceAbi = [ +export const POINTER_PRECOMPILE_ABI: Abi = [ { inputs: [{ internalType: 'string', name: 'cwAddr', type: 'string' }], name: 'addCW20Pointer', @@ -139,6 +139,28 @@ export const POINTER_PRECOMPILE_ABI: Abi & InterfaceAbi = [ } ]; +/** + * The ABI for the Pointer precompile contract, which can be used for interoperability between the EVM and Cosmos. + * + * @example + * ethers v6: Use the `ethers` library and precompiles to add a CW20 pointer. + * ```tsx + * import { POINTER_PRECOMPILE_ADDRESS, ETHERS_POINTER_PRECOMPILE_ABI, PointerPrecompileContract } 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 pointerPrecompileContract = new ethers.Contract(POINTER_PRECOMPILE_ADDRESS, ETHERS_POINTER_PRECOMPILE_ABI, signer) as PointerPrecompileContract; + * + * const tx = await pointerPrecompileContract.addCW20Pointer('CW20_CONTRACT_ADDRESS', { value: ethers.utils.parseEther('0.01') }); + * console.log(tx); + * ``` + * + * @category Cosmos Interoperability + */ +export const ETHERS_POINTER_PRECOMPILE_ABI = POINTER_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. * @@ -161,5 +183,5 @@ export const POINTER_PRECOMPILE_ABI: Abi & InterfaceAbi = [ * @category Cosmos Interoperability */ export const getPointerPrecompileEthersV6Contract = (runner: ContractRunner): PointerPrecompileContract => { - return new ethers.Contract(POINTER_PRECOMPILE_ADDRESS, POINTER_PRECOMPILE_ABI, runner) as PointerPrecompileContract; + return new ethers.Contract(POINTER_PRECOMPILE_ADDRESS, ETHERS_POINTER_PRECOMPILE_ABI, runner) as PointerPrecompileContract; }; diff --git a/packages/evm/src/precompiles/pointerview.ts b/packages/evm/src/precompiles/pointerview.ts index 9e12a80d..f0a5d7f6 100644 --- a/packages/evm/src/precompiles/pointerview.ts +++ b/packages/evm/src/precompiles/pointerview.ts @@ -77,7 +77,7 @@ export type PointerviewPrecompileContract = ethers.Contract & PointerviewPrecomp export const POINTERVIEW_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000000000000000000000000100A'; /** - * The ABI for the precompile contract, which can be used for interoperability between the EVM and Cosmos. + * The ABI for the pointerview precompile contract, which can be used for interoperability between the EVM and Cosmos. * * @example * Wagmi: Use the `useReadContract` hook to read the pointer of a CW20 contract. @@ -113,7 +113,7 @@ export const POINTERVIEW_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000 * * @category Cosmos Interoperability */ -export const POINTERVIEW_PRECOMPILE_ABI: Abi & InterfaceAbi = [ +export const POINTERVIEW_PRECOMPILE_ABI: Abi = [ { inputs: [{ internalType: 'string', name: 'cwAddr', type: 'string' }], name: 'getCW20Pointer', @@ -149,6 +149,28 @@ export const POINTERVIEW_PRECOMPILE_ABI: Abi & InterfaceAbi = [ } ]; +/** + * The ABI for the pointerview 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 pointer of a CW20 contract. + * ```tsx + * import { POINTERVIEW_PRECOMPILE_ADDRESS, ETHERS_POINTERVIEW_PRECOMPILE_ABI, PointerviewPrecompileContract } 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 pointerviewPrecompileContract = new ethers.Contract(POINTERVIEW_PRECOMPILE_ADDRESS, ETHERS_POINTERVIEW_PRECOMPILE_ABI, signer) as PointerviewPrecompileContract; + * + * const pointer = await pointerviewPrecompileContract.getCW20Pointer('CW20_CONTRACT_ADDRESS'); + * console.log(pointer); + * ``` + * + * @category Cosmos Interoperability + */ +export const ETHERS_POINTERVIEW_PRECOMPILE_ABI = POINTERVIEW_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. * @@ -171,5 +193,5 @@ export const POINTERVIEW_PRECOMPILE_ABI: Abi & InterfaceAbi = [ * @category Cosmos Interoperability */ export const getPointerviewPrecompileEthersV6Contract = (runner: ContractRunner): PointerviewPrecompileContract => { - return new ethers.Contract(POINTERVIEW_PRECOMPILE_ADDRESS, POINTERVIEW_PRECOMPILE_ABI, runner) as PointerviewPrecompileContract; + return new ethers.Contract(POINTERVIEW_PRECOMPILE_ADDRESS, ETHERS_POINTERVIEW_PRECOMPILE_ABI, runner) as PointerviewPrecompileContract; }; diff --git a/packages/evm/src/precompiles/staking.ts b/packages/evm/src/precompiles/staking.ts index 12fa7a82..5ab92c09 100644 --- a/packages/evm/src/precompiles/staking.ts +++ b/packages/evm/src/precompiles/staking.ts @@ -84,7 +84,7 @@ export type StakingPrecompileContract = ethers.Contract & StakingPrecompileFunct export const STAKING_PRECOMPILE_ADDRESS: `0x${string}` = '0x0000000000000000000000000000000000001005'; /** - * The ABI for the precompile contract, which can be used for interoperability between the EVM and Cosmos. + * The ABI for the staking 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. @@ -108,21 +108,9 @@ export const STAKING_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000 * console.log({ hash, isConfirming, isConfirmed }); * ``` * - * @example - * ```tsx - * import { STAKING_PRECOMPILE_ADDRESS, STAKING_PRECOMPILE_ABI, StakingPrecompileContract } 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(STAKING_PRECOMPILE_ADDRESS, STAKING_PRECOMPILE_ABI, signer) as StakingPrecompileContract; - * - * const response = await contract.connect().delegate('0xVALIDATOR_ADDRESS', parseSei(1)); - * ``` * @category Cosmos Interoperability */ -export const STAKING_PRECOMPILE_ABI: Abi & InterfaceAbi = [ +export const STAKING_PRECOMPILE_ABI: Abi = [ { inputs: [{ internalType: 'string', name: 'valAddress', type: 'string' }], name: 'delegate', @@ -153,6 +141,26 @@ export const STAKING_PRECOMPILE_ABI: Abi & InterfaceAbi = [ } ]; +/** + * The ABI for the staking precompile contract, which can be used for interoperability between the EVM and Cosmos. + * + * @example + * ```tsx + * import { STAKING_PRECOMPILE_ADDRESS, ETHERS_STAKING_PRECOMPILE_ABI, StakingPrecompileContract } 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(STAKING_PRECOMPILE_ADDRESS, ETHERS_STAKING_PRECOMPILE_ABI, signer) as StakingPrecompileContract; + * + * const response = await contract.connect().delegate('0xVALIDATOR_ADDRESS', parseSei(1)); + * ``` + * + * @category Cosmos Interoperability + */ +export const ETHERS_STAKING_PRECOMPILE_ABI = STAKING_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. * @@ -175,5 +183,5 @@ export const STAKING_PRECOMPILE_ABI: Abi & InterfaceAbi = [ * @category Cosmos Interoperability */ export const getStakingPrecompileEthersV6Contract = (runner: ContractRunner): StakingPrecompileContract => { - return new ethers.Contract(STAKING_PRECOMPILE_ADDRESS, STAKING_PRECOMPILE_ABI, runner) as StakingPrecompileContract; + return new ethers.Contract(STAKING_PRECOMPILE_ADDRESS, ETHERS_STAKING_PRECOMPILE_ABI, runner) as StakingPrecompileContract; }; diff --git a/packages/evm/src/precompiles/wasm.ts b/packages/evm/src/precompiles/wasm.ts index c50b41a9..fa065d66 100644 --- a/packages/evm/src/precompiles/wasm.ts +++ b/packages/evm/src/precompiles/wasm.ts @@ -99,7 +99,7 @@ export const WASM_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000000 * * @category Cosmos Interoperability */ -export const WASM_PRECOMPILE_ABI: Abi & InterfaceAbi = [ +export const WASM_PRECOMPILE_ABI: Abi = [ { inputs: [ { internalType: 'string', name: 'contractAddress', type: 'string' }, @@ -157,6 +157,8 @@ export const WASM_PRECOMPILE_ABI: Abi & InterfaceAbi = [ } ]; +export const ETHERS_WASM_PRECOMPILE_ABI = WASM_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. * @@ -179,5 +181,5 @@ export const WASM_PRECOMPILE_ABI: Abi & InterfaceAbi = [ * @category Cosmos Interoperability */ export const getWasmPrecompileEthersV6Contract = (runner: ContractRunner) => { - return new ethers.Contract(WASM_PRECOMPILE_ADDRESS, WASM_PRECOMPILE_ABI, runner) as WasmPrecompileContract; + return new ethers.Contract(WASM_PRECOMPILE_ADDRESS, ETHERS_WASM_PRECOMPILE_ABI, runner) as WasmPrecompileContract; }; diff --git a/packages/evm/src/providers/wagmi.ts b/packages/evm/src/providers/wagmi.ts index 3bbaed55..2aec0bc3 100644 --- a/packages/evm/src/providers/wagmi.ts +++ b/packages/evm/src/providers/wagmi.ts @@ -1,6 +1,23 @@ import { Chain, createClient, http } from 'viem'; import { Config, createConfig, CreateConnectorFn, injected } from '@wagmi/core'; +/** + * The default wallet connectors used in `getBaseSeiWagmiConfig`. + * @category Wagmi + */ +const DEFAULT_WALLETS: CreateConnectorFn[] = [ + injected({ + target: { + id: 'compassWalletProvider', + name: 'Compass', + provider: window['compassEvm'], + icon: 'https://cdn.sei.io/sei-app/wallets/compass-icon.png' + } + }), + injected({ target: 'metaMask' }), + injected({ target: 'coinbaseWallet' }) +]; + /** * Creates and returns a Wagmi config for the passed in Viem chain. This config includes the injected connector for MetaMask and Compass. If you need to add additional parameters it is recommended that you extend the object returned from this function. * @@ -23,15 +40,16 @@ import { Config, createConfig, CreateConnectorFn, injected } from '@wagmi/core'; * ``` * @returns Helper function to create a wagmi config given a Viem Chain. * @param chains - An array of Chains from 'viem'. - * @param additionalConnectors - A list of additional connectors to add to the Wagmi config for other wallets + * @param connectors - A list of connectors to add to the Wagmi config for wallets * @category Wagmi */ -export const getBaseSeiWagmiConfig = (chains: [Chain], additionalConnectors: CreateConnectorFn[] = []): Config => { +export const getBaseSeiWagmiConfig = (chains: [Chain], connectors: CreateConnectorFn[] = DEFAULT_WALLETS): Config => { return createConfig({ chains: chains, client({ chain }) { return createClient({ chain, transport: http() }); }, - connectors: [...additionalConnectors, injected({ target: 'metaMask' })] + multiInjectedProviderDiscovery: false, + connectors }); };