Skip to content

Commit

Permalink
Add pacific-1 evm chain config (#178)
Browse files Browse the repository at this point in the history
* Add pacific-1 evm chain config

* Remove precompile addresses from ethers contract helper and merge Abi types

* Add changeset
  • Loading branch information
besated authored May 27, 2024
1 parent c216b2a commit cbb2a4d
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-games-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sei-js/evm": patch
---

Add pacific-1 EVM chain config
6 changes: 3 additions & 3 deletions packages/evm/src/chainInfo/__tests__/chainInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// config.test.ts
import { SeiChainInfo } from '../chainInfo';
import { SEI_CHAIN_INFO } from '../chainInfo';

describe('arctic-1 tests', () => {
test('CHAIN ID should be correct', () => {
expect(SeiChainInfo.devnet.chainId).toBe(713715);
expect(SEI_CHAIN_INFO.devnet.chainId).toBe(713715);
});

test('EVM RPC should be correct', () => {
expect(SeiChainInfo.devnet.defaultRpc).toBe('https://evm-rpc-arctic-1.sei-apis.com');
expect(SEI_CHAIN_INFO.devnet.defaultRpc).toBe('https://evm-rpc-arctic-1.sei-apis.com');
});
});
6 changes: 5 additions & 1 deletion packages/evm/src/chainInfo/chainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
* The static chain information to be used in various wallet providers, tools, and libraries.
* @category Chain Constants
*/
export const SeiChainInfo = {
export const SEI_CHAIN_INFO = {
devnet: {
chainId: 713715,
defaultRpc: 'https://evm-rpc-arctic-1.sei-apis.com'
},
testnet: {
chainId: 1328,
defaultRpc: 'https://evm-rpc-testnet.sei-apis.com/'
},
mainnet: {
chainId: 1329,
defaultRpc: 'https://evm-rpc.sei-apis.com/'
}
};
11 changes: 5 additions & 6 deletions packages/evm/src/precompiles/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const ADDRESS_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000
*
* @category Cosmos Interoperability
*/
export const ADDRESS_PRECOMPILE_ABI: Abi = [
export const ADDRESS_PRECOMPILE_ABI: Abi & InterfaceAbi = [
{
inputs: [{ internalType: 'string', name: 'addr', type: 'string' }],
name: 'getEvmAddr',
Expand All @@ -121,23 +121,22 @@ export const ADDRESS_PRECOMPILE_ABI: Abi = [
* @example
* ethers v6: Use the `ethers` library and precompiles to read the associated Cosmos address for the connected account.
* ```tsx
* import { ADDRESS_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { getAddressPrecompileEthersV6Contract } 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 = getAddressPrecompileEthersV6Contract(ADDRESS_PRECOMPILE_ADDRESS, signer);
* const addressPrecompileContract = getAddressPrecompileEthersV6Contract(signer);
*
* const associatedSeiAddress = await addressPrecompileContract.connect().getSeiAddr(accounts[0]);
* ```
* @param precompileAddress The 0X address of the precompile contract.
* @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 ADDRESS precompile contract.
* @category Cosmos Interoperability
*/
export function getAddressPrecompileEthersV6Contract(precompileAddress: `0x${string}`, runner: ContractRunner): AddressPrecompileContract {
return new ethers.Contract(precompileAddress, ADDRESS_PRECOMPILE_ABI as InterfaceAbi, runner) as AddressPrecompileContract;
export function getAddressPrecompileEthersV6Contract(runner: ContractRunner): AddressPrecompileContract {
return new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ADDRESS_PRECOMPILE_ABI, runner) as AddressPrecompileContract;
}
11 changes: 5 additions & 6 deletions packages/evm/src/precompiles/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const BANK_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000000
*
* @category Cosmos Interoperability
*/
export const BANK_PRECOMPILE_ABI: Abi = [
export const BANK_PRECOMPILE_ABI: Abi & InterfaceAbi = [
{
inputs: [{ internalType: 'address', name: 'acc', type: 'address' }],
name: 'all_balances',
Expand Down Expand Up @@ -232,24 +232,23 @@ export const BANK_PRECOMPILE_ABI: Abi = [
*
* @example
* ```tsx
* import { BANK_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { getBankPrecompileEthersV6Contract } 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 = getBankPrecompileEthersV6Contract(BANK_PRECOMPILE_ADDRESS, signer);
* const bankPrecompileContract = getBankPrecompileEthersV6Contract(signer);
*
* const balance = await bankPrecompileContract.balance(accounts[0], 'usei');
* ```
*
* @param precompileAddress The 0X address of the precompile contract.
* @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 getBankPrecompileEthersV6Contract = (precompileAddress: `0x${string}`, runner: ContractRunner): BankPrecompileContract => {
return new ethers.Contract(precompileAddress, BANK_PRECOMPILE_ABI as InterfaceAbi, runner) as BankPrecompileContract;
export const getBankPrecompileEthersV6Contract = (runner: ContractRunner): BankPrecompileContract => {
return new ethers.Contract(BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, runner) as BankPrecompileContract;
};
11 changes: 5 additions & 6 deletions packages/evm/src/precompiles/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const DISTRIBUTION_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000
*
* @category Cosmos Interoperability
*/
export const DISTRIBUTION_PRECOMPILE_ABI: Abi = [
export const DISTRIBUTION_PRECOMPILE_ABI: Abi & InterfaceAbi = [
{
inputs: [{ internalType: 'address', name: 'withdrawAddr', type: 'address' }],
name: 'setWithdrawAddress',
Expand All @@ -135,21 +135,20 @@ export const DISTRIBUTION_PRECOMPILE_ABI: Abi = [
* @example
* ethers v6: Use the `ethers` library and precompiles to set the withdrawal address for rewards for the connected account.
* ```tsx
* import { getDistributionPrecompileEthersV6Contract, DISTRIBUTION_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { getDistributionPrecompileEthersV6Contract } from '@sei-js/evm';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const contract = getDistributionPrecompileEthersV6Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, signer);
* const contract = getDistributionPrecompileEthersV6Contract(signer);
*
* const response = await contract.setWithdrawAddress('0xADDRESS');
* ```
* @param precompileAddress The 0X address of the precompile contract.
* @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 getDistributionPrecompileEthersV6Contract = (precompileAddress: `0x${string}`, runner: ContractRunner): DistributionPrecompileContract => {
return new ethers.Contract(precompileAddress, DISTRIBUTION_PRECOMPILE_ABI as InterfaceAbi, runner) as DistributionPrecompileContract;
export const getDistributionPrecompileEthersV6Contract = (runner: ContractRunner): DistributionPrecompileContract => {
return new ethers.Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, DISTRIBUTION_PRECOMPILE_ABI, runner) as DistributionPrecompileContract;
};
11 changes: 5 additions & 6 deletions packages/evm/src/precompiles/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const GOVERNANCE_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000
* ```
* @category Cosmos Interoperability
* */
export const GOVERNANCE_PRECOMPILE_ABI: Abi = [
export const GOVERNANCE_PRECOMPILE_ABI: Abi & InterfaceAbi = [
{
inputs: [{ internalType: 'uint64', name: 'proposalID', type: 'uint64' }],
name: 'deposit',
Expand All @@ -121,22 +121,21 @@ export const GOVERNANCE_PRECOMPILE_ABI: Abi = [
* @example
* ethers v6
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, GOVERNANCE_PRECOMPILE_ADDRESS, parseSei } from '@sei-js/evm';
* 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(GOVERNANCE_PRECOMPILE_ADDRESS, signer);
* const governancePrecompileContract = getGovernancePrecompileEthersV6Contract(signer);
*
* //Surround with try/catch for detailed errors
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseSei(1) });
* ```
* @param precompileAddress The 0X address of the precompile contract.
* @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 = (precompileAddress: `0x${string}`, runner: ContractRunner) => {
return new ethers.Contract(precompileAddress, GOVERNANCE_PRECOMPILE_ABI as InterfaceAbi, runner) as GovernancePrecompileContract;
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner) => {
return new ethers.Contract(GOVERNANCE_PRECOMPILE_ADDRESS, GOVERNANCE_PRECOMPILE_ABI, runner) as GovernancePrecompileContract;
};
108 changes: 60 additions & 48 deletions packages/evm/src/precompiles/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,47 @@ import { Abi } from 'viem';
*/
export interface IbcPrecompileFunctions {
/**
* Transfers tokens from the caller's address to another on a different (IBC compatible) chain.
* @param toAddress The recipient's address on the other chain
* @param port IBC port in source chain (e.g. 'transfer')
* @param channel IBC channel in source chain (e.g. 'channel-0')
* @param denom The denomination of the tokens to send
* @param amount The amount of tokens to send
* @param revisionNumber The revision number of the source chain
* @param revisionHeight The revision height of the source chain
* @param timeoutTimestamp The timeout timestamp of the source chain
* @param memo The memo to include in the transaction, if no memo is needed, pass an empty string
*/
transfer(toAddress: string, port: string, channel: string, denom: string, amount: ethers.BigNumberish,
revisionNumber: BigInt, revisionHeight: BigInt, timeoutTimestamp: BigInt, memo: string): Promise<{ success: boolean }>;

/**
* Transfers tokens from the caller's address to another on a different (IBC compatible) chain.
* Calculates the timeout height/timestamp based on the current block timestamp.
* @param toAddress The recipient's address on the other chain
* @param port IBC port in source chain (e.g. 'transfer')
* @param channel IBC channel in source chain (e.g. 'channel-0')
* @param denom The denomination of the tokens to send
* @param amount The amount of tokens to send
* @param memo The memo to include in the transaction, if no memo is needed, pass an empty string
*/
transferWithDefaultTimeout(toAddress: string, port: string, channel: string, denom: string,
amount: ethers.BigNumberish, memo: string): Promise<{ success: boolean }>;
* Transfers tokens from the caller's address to another on a different (IBC compatible) chain.
* @param toAddress The recipient's address on the other chain
* @param port IBC port in source chain (e.g. 'transfer')
* @param channel IBC channel in source chain (e.g. 'channel-0')
* @param denom The denomination of the tokens to send
* @param amount The amount of tokens to send
* @param revisionNumber The revision number of the source chain
* @param revisionHeight The revision height of the source chain
* @param timeoutTimestamp The timeout timestamp of the source chain
* @param memo The memo to include in the transaction, if no memo is needed, pass an empty string
*/
transfer(
toAddress: string,
port: string,
channel: string,
denom: string,
amount: ethers.BigNumberish,
revisionNumber: BigInt,
revisionHeight: BigInt,
timeoutTimestamp: BigInt,
memo: string
): Promise<{ success: boolean }>;

/**
* Transfers tokens from the caller's address to another on a different (IBC compatible) chain.
* Calculates the timeout height/timestamp based on the current block timestamp.
* @param toAddress The recipient's address on the other chain
* @param port IBC port in source chain (e.g. 'transfer')
* @param channel IBC channel in source chain (e.g. 'channel-0')
* @param denom The denomination of the tokens to send
* @param amount The amount of tokens to send
* @param memo The memo to include in the transaction, if no memo is needed, pass an empty string
*/
transferWithDefaultTimeout(
toAddress: string,
port: string,
channel: string,
denom: string,
amount: ethers.BigNumberish,
memo: string
): Promise<{ success: boolean }>;
}

/**
Expand Down Expand Up @@ -103,7 +117,7 @@ export const IBC_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000000000000
*
* @category Cosmos Interoperability
*/
export const IBC_PRECOMPILE_ABI: Abi = [
export const IBC_PRECOMPILE_ABI: Abi & InterfaceAbi = [
{
inputs: [
{ internalType: 'string', name: 'toAddress', type: 'string' },
Expand All @@ -114,52 +128,50 @@ export const IBC_PRECOMPILE_ABI: Abi = [
{ internalType: 'uint64', name: 'revisionNumber', type: 'uint64' },
{ internalType: 'uint64', name: 'revisionHeight', type: 'uint64' },
{ internalType: 'uint64', name: 'timeoutTimestamp', type: 'uint64' },
{ internalType: 'string', name: 'memo', type: 'string' },
{ internalType: 'string', name: 'memo', type: 'string' }
],
name: 'transfer',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'payable',
type: 'function'
},
{
inputs: [
{ internalType: 'string', name: 'toAddress', type: 'string' },
{ internalType: 'string', name: 'port', type: 'string' },
{ internalType: 'string', name: 'channel', type: 'string' },
{ internalType: 'string', name: 'denom', type: 'string' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'string', name: 'memo', type: 'string' },
],
name: 'transferWithDefaultTimeout',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'payable',
type: 'function'
},

{
inputs: [
{ internalType: 'string', name: 'toAddress', type: 'string' },
{ internalType: 'string', name: 'port', type: 'string' },
{ internalType: 'string', name: 'channel', type: 'string' },
{ internalType: 'string', name: 'denom', type: 'string' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'string', name: 'memo', type: 'string' }
],
name: 'transferWithDefaultTimeout',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'payable',
type: 'function'
}
];

/**
* Creates and returns an ethers v6 contract instance with the provided signer, for use in interoperability between the EVM and Cosmos.
*
* @example
* ```tsx
* import { IBC_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { getIbcPrecompileEthersV6Contract } 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 ibcPrecompileContract = getIbcPrecompileEthersV6Contract(signer);
* const cosmosAddress = 'cosmos1...';
*
* const bool = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* @param precompileAddress The 0X address of the precompile contract.
* @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 getIbcPrecompileEthersV6Contract = (precompileAddress: `0x${string}`, runner: ContractRunner): IbcPrecompileContract => {
return new ethers.Contract(precompileAddress, IBC_PRECOMPILE_ABI as InterfaceAbi, runner) as IbcPrecompileContract;
export const getIbcPrecompileEthersV6Contract = (runner: ContractRunner): IbcPrecompileContract => {
return new ethers.Contract(IBC_PRECOMPILE_ADDRESS, IBC_PRECOMPILE_ABI, runner) as IbcPrecompileContract;
};
11 changes: 5 additions & 6 deletions packages/evm/src/precompiles/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const JSON_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000000
*
* @category Cosmos Interoperability
*/
export const JSON_PRECOMPILE_ABI: Abi = [
export const JSON_PRECOMPILE_ABI: Abi & InterfaceAbi = [
{
inputs: [
{ internalType: 'bytes', name: 'input', type: 'bytes' },
Expand Down Expand Up @@ -142,23 +142,22 @@ export const JSON_PRECOMPILE_ABI: Abi = [
*
* @example
* ```tsx
* import { JSON_PRECOMPILE_ADDRESS } from '@sei-js/evm';
* import { getJSONPrecompileEthersV6Contract } 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 jsonPrecompileContract = getJSONPrecompileEthersV6Contract(JSON_PRECOMPILE_ADDRESS, signer);
* const jsonPrecompileContract = getJSONPrecompileEthersV6Contract(signer);
*
* const response = await jsonPrecompileContract.connect().extractAsBytes('0xINPUT', 'KEY');
* ```
* @param precompileAddress The 0X address of the precompile contract.
* @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 getJSONPrecompileEthersV6Contract = (precompileAddress: `0x${string}`, runner: ContractRunner): JSONPrecompileContract => {
return new ethers.Contract(precompileAddress, JSON_PRECOMPILE_ABI as InterfaceAbi, runner) as JSONPrecompileContract;
export const getJSONPrecompileEthersV6Contract = (runner: ContractRunner): JSONPrecompileContract => {
return new ethers.Contract(JSON_PRECOMPILE_ADDRESS, JSON_PRECOMPILE_ABI, runner) as JSONPrecompileContract;
};
Loading

0 comments on commit cbb2a4d

Please sign in to comment.