Skip to content

Commit

Permalink
Allow passing the redeem flag (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Jan 17, 2025
1 parent 73c4a82 commit 2ff1d4e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion docs/pages/developers/polkadot/token-gateway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Assets can also be updated in the same way by dispatching `update_erc6160_asset`

Asset precision is used to note the precision an asset is configured with on a remote chain, this allows the pallet to handle balance conversions correctly.
To update or set the precision of an asset on dispatch `update_asset_precision` with the values that need to be set.
The precision for ERC6160 assets deployed on EVM should always be set to 18.

## Teleporting assets

Expand All @@ -187,7 +188,9 @@ pub struct TeleportParams<AssetId, Balance> {
/// Relayer fee
pub relayer_fee: Balance,
/// Optional call data
pub call_data: Option<Vec<u8>>
pub call_data: Option<Vec<u8>>,
/// Redeem erc20 tokens
pub redeem: bool
}
```
Let's explore what each parameter holds:
Expand All @@ -199,5 +202,7 @@ Let's explore what each parameter holds:
- `timeout`: The request timeout, this is the time after which the request cannot be delivered to the destination. It should represent the cumulative time for finalization on the source chain and hyperbridge with some additional buffer.<br/>
- `token_gateway`: The address of the token gateway module on the destination chain.<br/>
- `relayer_fee`: The amount to be paid to relayers for delivering the request, a value of zero means the dispatcher is responsible for relaying the request.<br/>
- `redeem`: This value should be set to true if bridging an asset that has an ERC20 deployment on the destination, it should be false in any other case.<br/>


Funds from undelivered requests can be recovered by submitting a timeout message for the request through `pallet-ismp`.
4 changes: 4 additions & 0 deletions modules/pallets/testsuite/src/tests/pallet_token_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn should_teleport_asset_correctly() {
token_gateway: H160::zero().0.to_vec(),
relayer_fee: Default::default(),
call_data: None,
redeem: false,
};

TokenGateway::teleport(RuntimeOrigin::signed(ALICE), params).unwrap();
Expand All @@ -59,6 +60,7 @@ fn should_receive_asset_correctly() {
token_gateway: H160::zero().0.to_vec(),
relayer_fee: Default::default(),
call_data: None,
redeem: false,
};

TokenGateway::teleport(RuntimeOrigin::signed(ALICE), params).unwrap();
Expand Down Expand Up @@ -113,6 +115,7 @@ fn should_timeout_request_correctly() {
token_gateway: H160::zero().0.to_vec(),
relayer_fee: Default::default(),
call_data: None,
redeem: false,
};

TokenGateway::teleport(RuntimeOrigin::signed(ALICE), params).unwrap();
Expand Down Expand Up @@ -339,6 +342,7 @@ fn should_receive_asset_with_call_correctly() {
token_gateway: H160::zero().0.to_vec(),
relayer_fee: Default::default(),
call_data: None,
redeem: false,
};

TokenGateway::teleport(RuntimeOrigin::signed(ALICE), params).unwrap();
Expand Down
1 change: 1 addition & 0 deletions modules/pallets/token-gateway/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mod benches {
token_gateway: vec![1, 2, 3, 4, 5],
relayer_fee: 0u128.into(),
call_data: None,
redeem: false
};

#[extrinsic_call]
Expand Down
4 changes: 2 additions & 2 deletions modules/pallets/token-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub mod pallet {
alloy_primitives::U256::from_be_bytes(bytes)
},
asset_id: asset_id.0.into(),
redeem: false,
redeem: params.redeem,
from: from.into(),
to: to.into(),
data: data.into(),
Expand All @@ -339,7 +339,7 @@ pub mod pallet {
alloy_primitives::U256::from_be_bytes(bytes)
},
asset_id: asset_id.0.into(),
redeem: false,
redeem: params.redeem,
from: from.into(),
to: to.into(),
};
Expand Down
2 changes: 2 additions & 0 deletions modules/pallets/token-gateway/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub struct TeleportParams<AssetId, Balance> {
pub relayer_fee: Balance,
/// Optional call data to be executed on the destination chain
pub call_data: Option<Vec<u8>>,
/// Redeem native erc20 assets
pub redeem: bool,
}

/// Local asset Id and its corresponding token gateway asset id
Expand Down

0 comments on commit 2ff1d4e

Please sign in to comment.