diff --git a/.changeset/fair-emus-complain.md b/.changeset/fair-emus-complain.md new file mode 100644 index 00000000..e130faee --- /dev/null +++ b/.changeset/fair-emus-complain.md @@ -0,0 +1,5 @@ +--- +"@sei-js/evm": minor +--- + +Adding new functions to distribution and staking precompiles diff --git a/packages/evm/README.md b/packages/evm/README.md index ca6a1b5c..08b8d421 100644 --- a/packages/evm/README.md +++ b/packages/evm/README.md @@ -145,11 +145,12 @@ The Distribution precompile contract facilitates operations related to rewards w #### Functions -| Function Name | Input Parameters | Return Value | Description | -|--------------------------------------------------------------------------------------------------|------------------------------|------------------------|-----------------------------------------------------| -| [`setWithdrawAddress`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#setWithdrawAddress) | `withdrawAddress: ` `string` | `{ success: boolean }` | Sets the withdrawal address for rewards. | -| [`withdrawDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawDelegationRewards) | `validator: ` `string` | `{ success: boolean }` | Withdraws delegation rewards for a given validator. | -| [`withdrawMultipleDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawMultipleDelegationRewards) | `validators: ` `string[]` | `{ success: boolean }` | Withdraws delegation rewards for given validators. | +| Function Name | Input Parameters | Return Value | Description | +|-------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`setWithdrawAddress`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#setWithdrawAddress) | `withdrawAddress: ` `string` | `{ success: boolean }` | Sets the withdrawal address for rewards. | +| [`withdrawDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawDelegationRewards) | `validator: ` `string` | `{ success: boolean }` | Withdraws delegation rewards for a given validator. | +| [`withdrawMultipleDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawMultipleDelegationRewards) | `validators: ` `string[]` | `{ success: boolean }` | Withdraws delegation rewards for given validators. | +| [`rewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#rewards) | `delegatorAddress: ` `address` | `{ rewards: Rewards }` | Queries rewards available for a given delegator address. Rewards are usually returned as decimals. To calculate the actual amount, divide the amount by decimals. | #### Precompile Addresses 0x0000000000000000000000000000000000001007 @@ -196,11 +197,12 @@ The Staking precompile contract provides functions for delegation, re-delegation #### Functions -| Function Name | Input Parameters | Return Value | Description | -|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------|------------------------|----------------------------------------------------------------------------| -| [`delegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#delegate) | `valAddress: ` `string` | `{ success: boolean }` | Delegates tokens to the specified validator. | -| [`redelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#redelegate) | `srcAddress: ` `string`, `dstAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Redelegates tokens from the source validator to the destination validator. | -| [`undelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#undelegate) | `valAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Undelegates tokens from the specified validator. | +| Function Name | Input Parameters | Return Value | Description | +|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`delegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#delegate) | `valAddress: ` `string` | `{ success: boolean }` | Delegates tokens to the specified validator. | +| [`redelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#redelegate) | `srcAddress: ` `string`, `dstAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Redelegates tokens from the source validator to the destination validator. | +| [`undelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#undelegate) | `valAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Undelegates tokens from the specified validator. | +| [`delegation`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#delegation) | `delegator`: `address`, `valAddress: ` `string` | `{ delegation: Delegation }` | Queries delegation by delegator and validator address. Shares in DelegationDetails are usually returned as decimals. To calculate the actual amount, divide the shares by decimals. | #### Precompile Addresses 0x0000000000000000000000000000000000001005 diff --git a/packages/evm/src/precompiles/distribution.ts b/packages/evm/src/precompiles/distribution.ts index 58e8043d..19e725a5 100644 --- a/packages/evm/src/precompiles/distribution.ts +++ b/packages/evm/src/precompiles/distribution.ts @@ -9,25 +9,60 @@ export const DISTRIBUTION_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000 * @category Cosmos Interoperability */ export const DISTRIBUTION_PRECOMPILE_ABI = [ - { - inputs: [{ internalType: 'address', name: 'withdrawAddr', type: 'address' }], - name: 'setWithdrawAddress', - outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], - stateMutability: 'nonpayable', - type: 'function' - }, - { - inputs: [{ internalType: 'string', name: 'validator', type: 'string' }], - name: 'withdrawDelegationRewards', - outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], - stateMutability: 'nonpayable', - type: 'function' - }, - { - inputs: [{ internalType: 'string[]', name: 'validators', type: 'string[]' }], - name: 'withdrawMultipleDelegationRewards', - outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], - stateMutability: 'nonpayable', - type: 'function' - } + { + inputs: [{ internalType: 'address', name: 'withdrawAddr', type: 'address' }], + name: 'setWithdrawAddress', + outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [{ internalType: 'string', name: 'validator', type: 'string' }], + name: 'withdrawDelegationRewards', + outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [{ internalType: 'string[]', name: 'validators', type: 'string[]' }], + name: 'withdrawMultipleDelegationRewards', + outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [{ internalType: 'address', name: 'delegatorAddress', type: 'address' }], + name: 'rewards', + outputs: [ + { + components: [ + { + components: [ + { + components: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'decimals', type: 'uint256' }, + { internalType: 'string', name: 'denom', type: 'string' } + ], + internalType: 'struct Coin[]', name: 'coins', type: 'tuple[]' + }, + { internalType: 'string', name: 'validator_address', type: 'string' } + ], + internalType: 'struct Reward[]', name: 'rewards', type: 'tuple[]' + }, + { + components: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'decimals', type: 'uint256' }, + { internalType: 'string', name: 'denom', type: 'string' } + ], + internalType: 'struct Coin[]', name: 'total', type: 'tuple[]' + } + ], + internalType: 'struct Rewards', name: 'rewards', type: 'tuple' + } + ], + stateMutability: 'view', + type: 'function' + } ] as const; diff --git a/packages/evm/src/precompiles/staking.ts b/packages/evm/src/precompiles/staking.ts index f2041f30..454bb3b0 100644 --- a/packages/evm/src/precompiles/staking.ts +++ b/packages/evm/src/precompiles/staking.ts @@ -9,32 +9,64 @@ export const STAKING_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000 * @category Cosmos Interoperability */ export const STAKING_PRECOMPILE_ABI = [ - { - inputs: [{ internalType: 'string', name: 'valAddress', type: 'string' }], - name: 'delegate', - outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], - stateMutability: 'payable', - type: 'function' - }, - { - inputs: [ - { internalType: 'string', name: 'srcAddress', type: 'string' }, - { internalType: 'string', name: 'dstAddress', type: 'string' }, - { internalType: 'uint256', name: 'amount', type: 'uint256' } - ], - name: 'redelegate', - outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], - stateMutability: 'nonpayable', - type: 'function' - }, - { - inputs: [ - { internalType: 'string', name: 'valAddress', type: 'string' }, - { internalType: 'uint256', name: 'amount', type: 'uint256' } - ], - name: 'undelegate', - outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], - stateMutability: 'nonpayable', - type: 'function' - } + { + inputs: [{ internalType: 'string', name: 'valAddress', type: 'string' }], + name: 'delegate', + outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], + stateMutability: 'payable', + type: 'function' + }, + { + inputs: [ + { internalType: 'string', name: 'srcAddress', type: 'string' }, + { internalType: 'string', name: 'dstAddress', type: 'string' }, + { internalType: 'uint256', name: 'amount', type: 'uint256' } + ], + name: 'redelegate', + outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'string', name: 'valAddress', type: 'string' }, + { internalType: 'uint256', name: 'amount', type: 'uint256' } + ], + name: 'undelegate', + outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { internalType: 'address', name: 'delegator', type: 'address' }, + { internalType: 'string', name: 'valAddress', type: 'string' } + ], + name: 'delegation', + outputs: [ + { + components: [ + { + components: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'string', name: 'denom', type: 'string' } + ], + internalType: 'struct Balance', name: 'balance', type: 'tuple' + }, + { + components: [ + { internalType: 'string', name: 'delegator_address', type: 'string' }, + { internalType: 'uint256', name: 'shares', type: 'uint256' }, + { internalType: 'uint256', name: 'decimals', type: 'uint256' }, + { internalType: 'string', name: 'validator_address', type: 'string' } + ], + internalType: 'struct DelegationDetails', name: 'delegation', type: 'tuple' + } + ], + internalType: 'struct Delegation', name: 'delegation', type: 'tuple' + } + ], + stateMutability: 'view', + type: 'function' + } ] as const;