Skip to content

Commit

Permalink
Adding memo support for IBC precompile (#176)
Browse files Browse the repository at this point in the history
* memo support

* change set
  • Loading branch information
dssei authored May 17, 2024
1 parent 1543bf9 commit 3873d2e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-eels-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sei-js/evm": minor
---

adding memo support for IBC precompile
8 changes: 4 additions & 4 deletions packages/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ The WASM precompile contract facilitates execution, instantiation, and querying
The IBC precompile contract facilitates messages exchange between Sei and other IBC compatible blockchains.
#### Functions

| Function Name | Input Parameters | Return Value | Description |
|------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`transfer`](/sei-js/docs/interfaces/evm.IbcPrecompileFunctions.html#transfer) | `toAddress: ` `string`, `port: ` `string`, `channel: ` `string`, `denom: ` `string`, `amount: ` `ethers.BigNumberish`, `revisionNumber: ` `BigInt`, `revisionHeight: ` `BigInt`, `timeoutTimestamp: ` `BigInt` | `{ success: boolean }` | Transfers tokens from the caller's address to another on a different (IBC compatible) chain. |
| [`transferWithDefaultTimeout`](/sei-js/docs/interfaces/evm.IbcPrecompileFunctions.html#transferWithDefaultTimeout) | `toAddress: ` `string`, `port: ` `string`, `channel: ` `string`, `denom: ` `string`, `amount: ` `ethers.BigNumberish`| `{ success: boolean }` | Transfers tokens from the caller's address to another on a different (IBC compatible) chain. Calculates default timeout height as opposed to `transfer` function |
| Function Name | Input Parameters | Return Value | Description |
|------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`transfer`](/sei-js/docs/interfaces/evm.IbcPrecompileFunctions.html#transfer) | `toAddress: ` `string`, `port: ` `string`, `channel: ` `string`, `denom: ` `string`, `amount: ` `ethers.BigNumberish`, `revisionNumber: ` `BigInt`, `revisionHeight: ` `BigInt`, `timeoutTimestamp: ` `BigInt`, `memo: ` `String` | `{ success: boolean }` | Transfers tokens from the caller's address to another on a different (IBC compatible) chain. |
| [`transferWithDefaultTimeout`](/sei-js/docs/interfaces/evm.IbcPrecompileFunctions.html#transferWithDefaultTimeout) | `toAddress: ` `string`, `port: ` `string`, `channel: ` `string`, `denom: ` `string`, `amount: ` `ethers.BigNumberish`, `memo: ` `String` | `{ success: boolean }` | Transfers tokens from the caller's address to another on a different (IBC compatible) chain. Calculates default timeout height as opposed to `transfer` function |

#### Precompile Addresses
0x0000000000000000000000000000000000001009
Expand Down
36 changes: 20 additions & 16 deletions packages/evm/src/precompiles/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ 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
*/
* 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): Promise<{ success: boolean }>;
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.
Expand All @@ -29,9 +30,10 @@ export interface IbcPrecompileFunctions {
* @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): Promise<{ success: boolean }>;
amount: ethers.BigNumberish, memo: string): Promise<{ success: boolean }>;

}

Expand Down Expand Up @@ -65,7 +67,7 @@ export type IbcPrecompileContract = ethers.Contract & IbcPrecompileFunctions;
*
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(IBC_PRECOMPILE_ADDRESS, signer);
*
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n);
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* @category Cosmos Interoperability
Expand Down Expand Up @@ -96,7 +98,7 @@ export const IBC_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000000000000
*
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(IBC_PRECOMPILE_ADDRESS, signer);
*
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n);
* const queryResponse = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* @category Cosmos Interoperability
Expand All @@ -111,7 +113,8 @@ export const IBC_PRECOMPILE_ABI: Abi = [
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'uint64', name: 'revisionNumber', type: 'uint64' },
{ internalType: 'uint64', name: 'revisionHeight', type: 'uint64' },
{ internalType: 'uint64', name: 'timeoutTimestamp', type: 'uint64' }
{ internalType: 'uint64', name: 'timeoutTimestamp', type: 'uint64' },
{ internalType: 'string', name: 'memo', type: 'string' },
],
name: 'transfer',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
Expand All @@ -125,6 +128,7 @@ export const IBC_PRECOMPILE_ABI: Abi = [
{ 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' }],
Expand All @@ -148,7 +152,7 @@ export const IBC_PRECOMPILE_ABI: Abi = [
* const ibcPrecompileContract = getIbcPrecompileEthersV6Contract(IBC_PRECOMPILE_ADDRESS, signer);
* const cosmosAddress = 'cosmos1...';
*
* const bool = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n);
* const bool = await ibcPrecompileContract.transfer(cosmosAddress, 'transfer', 'channel-0', 'usei', 100, 1n, 1n, 1n, 'memo');
* ```
*
* @param precompileAddress The 0X address of the precompile contract.
Expand Down

0 comments on commit 3873d2e

Please sign in to comment.