Skip to content

Commit 41e78ac

Browse files
authored
add ETH and WBTC.e asset specs (#1710)
* add ETH and WBTC.e assets * review fixes
1 parent d03d79d commit 41e78ac

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

app-libs/assets-map/src/lib.rs

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use itp_types::{
3232
parentchain::{Hash, ParentchainAssetIdNative},
3333
xcm::{
3434
Junction::{AccountKey20, GlobalConsensus},
35-
Junctions::X2,
35+
Junctions::{X1, X2},
3636
Location,
3737
NetworkId::Ethereum,
3838
},
@@ -57,23 +57,33 @@ use serde::{Deserialize, Serialize};
5757
#[repr(u32)]
5858
#[allow(non_camel_case_types)]
5959
pub enum AssetId {
60+
// Tether tokens
6061
/// USDT Tether, minted natively
6162
USDT = 10,
6263
/// USDT Tether, minted on Ethereum
6364
USDT_E = 11,
65+
66+
// Circle tokens
6467
/// USDC Circle, minted natively
6568
USDC = 20,
6669
/// USDC Circle, minted on Ethereum
6770
USDC_E = 21,
71+
72+
// protocol-issued tokens, wrapped or not
6873
/// Ethereum ETH,
6974
ETH = 30,
70-
/// wrapped ETH
75+
/// wrapped ETH ERC20
7176
WETH = 31,
77+
/// Bitcoin. just reserving the index. no bridge exists yet
78+
BTC = 36,
79+
/// ethereum-wrapped Bitcoin
80+
WBTC_E = 37,
7281
}
7382

7483
const USDC_E_MAINNET_CONTRACT_ADDRESS: [u8; 20] = hex!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
7584
const USDT_E_MAINNET_CONTRACT_ADDRESS: [u8; 20] = hex!("dac17f958d2ee523a2206206994597c13d831ec7");
7685
const WETH_SEPOLIA_CONTRACT_ADDRESS: [u8; 20] = hex!("fff9976782d46cc05630d1f6ebab18b2324d6b14");
86+
const WBTC_E_MAINNET_CONTRACT_ADDRESS: [u8; 20] = hex!("2260fac5e5542a773aa44fbcfedf7c193bc2c599");
7787

7888
/// The AssetId type we use on L2 to map all possible locations/instances
7989
/// This type must contain unique definitions for any token we may want to shield on any shielding target
@@ -88,6 +98,8 @@ impl std::fmt::Display for AssetId {
8898
AssetId::USDC_E => write!(f, "USDC.e"),
8999
AssetId::ETH => write!(f, "ETH"),
90100
AssetId::WETH => write!(f, "WETH"),
101+
AssetId::BTC => write!(f, "BTC"),
102+
AssetId::WBTC_E => write!(f, "WBTC.e"),
91103
}
92104
}
93105
}
@@ -104,6 +116,7 @@ impl TryFrom<&str> for AssetId {
104116
"USDC.e" => Ok(AssetId::USDC_E),
105117
"ETH" => Ok(AssetId::ETH),
106118
"WETH" => Ok(AssetId::WETH),
119+
"WBTC.e" => Ok(AssetId::WBTC_E),
107120
_ => Err(()),
108121
}
109122
}
@@ -128,6 +141,8 @@ impl AssetId {
128141
AssetId::USDC_E => Some(FOREIGN_ASSETS),
129142
AssetId::ETH => Some(FOREIGN_ASSETS),
130143
AssetId::WETH => Some(FOREIGN_ASSETS),
144+
AssetId::BTC => None,
145+
AssetId::WBTC_E => Some(FOREIGN_ASSETS),
131146
}
132147
}
133148

@@ -139,6 +154,8 @@ impl AssetId {
139154
AssetId::USDC_E => 1_000_000, // 6 decimals
140155
AssetId::ETH => 1_000_000_000_000_000_000, // 18 decimals
141156
AssetId::WETH => 1_000_000_000_000_000_000, // 18 decimals
157+
AssetId::BTC => 100_000_000, // 8 decimals
158+
AssetId::WBTC_E => 100_000_000, // 8 decimals
142159
}
143160
}
144161

@@ -157,16 +174,11 @@ impl AssetId {
157174
AssetId::USDC_E,
158175
AssetId::WETH,
159176
AssetId::ETH,
177+
AssetId::WBTC_E,
160178
],
161-
ASSET_HUB_PASEO_GENESIS_HASH_HEX => vec![
162-
AssetId::USDT,
163-
AssetId::USDT_E,
164-
AssetId::USDC,
165-
AssetId::USDC_E,
166-
AssetId::WETH,
167-
AssetId::ETH,
168-
],
169-
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX => vec![AssetId::USDT_E, AssetId::USDC_E],
179+
ASSET_HUB_PASEO_GENESIS_HASH_HEX => vec![AssetId::USDT, AssetId::USDC, AssetId::WETH],
180+
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX =>
181+
vec![AssetId::USDT_E, AssetId::USDC_E, AssetId::ETH, AssetId::WBTC_E],
170182
_ => vec![],
171183
}
172184
}
@@ -206,6 +218,21 @@ impl AssetTranslation for AssetId {
206218
} else {
207219
None
208220
},
221+
AssetId::WBTC_E =>
222+
if matches!(
223+
genesis_hash.into(),
224+
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX | ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
225+
) {
226+
Some(Location {
227+
parents: 2,
228+
interior: X2(Arc::new([
229+
GlobalConsensus(Ethereum { chain_id: ETHEREUM_MAINNET_CHAIN_ID }),
230+
AccountKey20 { key: WBTC_E_MAINNET_CONTRACT_ADDRESS, network: None },
231+
])),
232+
})
233+
} else {
234+
None
235+
},
209236
AssetId::WETH =>
210237
if matches!(
211238
genesis_hash.into(),
@@ -221,6 +248,20 @@ impl AssetTranslation for AssetId {
221248
} else {
222249
None
223250
},
251+
AssetId::ETH =>
252+
if matches!(
253+
genesis_hash.into(),
254+
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX | ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
255+
) {
256+
Some(Location {
257+
parents: 2,
258+
interior: X1(Arc::new([GlobalConsensus(Ethereum {
259+
chain_id: ETHEREUM_MAINNET_CHAIN_ID,
260+
})])),
261+
})
262+
} else {
263+
None
264+
},
224265
_ => None,
225266
}
226267
}
@@ -274,6 +315,14 @@ impl AssetTranslation for AssetId {
274315
| ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
275316
) =>
276317
Some(AssetId::USDT_E),
318+
[GlobalConsensus(Ethereum { chain_id: ETHEREUM_MAINNET_CHAIN_ID }), AccountKey20 { key: contract, network: None }]
319+
if *contract == WBTC_E_MAINNET_CONTRACT_ADDRESS
320+
&& matches!(
321+
genesis_hash.into(),
322+
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX
323+
| ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
324+
) =>
325+
Some(AssetId::WBTC_E),
277326
[GlobalConsensus(Ethereum { chain_id: ETHEREUM_SEPOLIA_CHAIN_ID }), AccountKey20 { key: contract, network: None }]
278327
if *contract == WETH_SEPOLIA_CONTRACT_ADDRESS
279328
&& matches!(
@@ -282,6 +331,13 @@ impl AssetTranslation for AssetId {
282331
| ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
283332
) =>
284333
Some(AssetId::WETH),
334+
[GlobalConsensus(Ethereum { chain_id: ETHEREUM_MAINNET_CHAIN_ID })]
335+
if matches!(
336+
genesis_hash.into(),
337+
ASSET_HUB_POLKADOT_GENESIS_HASH_HEX
338+
| ASSET_HUB_LOCAL_TEST_GENESIS_HASH_HEX
339+
) =>
340+
Some(AssetId::ETH),
285341
_ => None,
286342
}
287343
} else {

0 commit comments

Comments
 (0)