From 302bf39fb31d1ad9742e953f9b2de218766aa002 Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 14 Jun 2023 13:07:43 -0300 Subject: [PATCH 01/33] Implemented initial draft code for the conversion between ZenlinkAssetId and Spacewalk assets. --- runtime/foucoco/Cargo.toml | 38 +++++++++--------- runtime/foucoco/src/zenlink.rs | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 19 deletions(-) diff --git a/runtime/foucoco/Cargo.toml b/runtime/foucoco/Cargo.toml index 68aed8b0a..de9c2ae71 100644 --- a/runtime/foucoco/Cargo.toml +++ b/runtime/foucoco/Cargo.toml @@ -26,25 +26,25 @@ smallvec = "1.9.0" runtime-common = { path = "../common", default-features = false } # custom libraries from spacewalk -currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} - -module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} + +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} # Substrate frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.37" } diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 9491c0c0e..9bacf0dd5 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -6,6 +6,8 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; +use spacewalk_primitives::CurrencyId; + use zenlink_protocol::{ AssetId, AssetIdConverter, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, NATIVE, @@ -124,6 +126,77 @@ where } } +fn discriminant(currency: &CurrencyId) -> u8 { + match currency { + CurrencyId::Native => 0, + CurrencyId::XCM(_) => 1, + CurrencyId::Stellar(_) => 2, + CurrencyId::ZenlinkLPToken(_, _, _, _) => 6, + } +} + +impl TryFrom for ZenlinkAssetId { + type Error = (); + + fn try_from(currency: CurrencyId) -> Result { + let disc = discriminant(¤cy); + match currency { + CurrencyId::Native => Ok(ZenlinkAssetId { + chain_id: PARA_CHAIN_ID, + asset_type: NATIVE, + asset_index: 0 as u64, + }), + CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { + chain_id: PARA_CHAIN_ID, + asset_type: LOCAL, + asset_index: (disc << 8) + token_id, + }), + CurrencyId::Stellar => Ok(ZenlinkAssetId { + chain_id: PARA_CHAIN_ID, + asset_type: LOCAL, + asset_index: (disc << 8) + 1, + }), + CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { + let _index = (disc << 8) + + ((token1_id as u64) << 16) + + ((token1_type as u64) << 24) + + ((token2_id as u64) << 32) + + ((token2_type as u64) << 40); + Ok(ZenlinkAssetId { + chain_id: PARA_CHAIN_ID, + asset_type: LOCAL, + asset_index: _index, + }) + }, + } + } +} + +impl TryFrom for CurrencyId { + type Error = (); + + fn try_from(asset: ZenlinkAssetId) -> Result { + let _index = asset.asset_index; + let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; + let symbol = ((_index & 0x0000_0000_0000_00ff) as u8); + match disc { + 0 => Ok(CurrencyId::Native), + 1 => Ok(CurrencyId::XCM(symbol)), + // 2 => Ok(CurrencyId::Stellar()), + 6 => { + let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; + let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 20) as u8; + + let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; + let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; + + Ok(CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type)) + }, + _ => Err(()), + } + } +} + fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { let para_chain_id: u32 = ParachainInfo::parachain_id().into(); if asset_id.chain_id != para_chain_id { From 9988ad4152174db636089ba070d42e2f10273fcd Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 14 Jun 2023 14:13:34 -0300 Subject: [PATCH 02/33] added PARA_CHAIN_ID constant --- runtime/foucoco/src/zenlink.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 9bacf0dd5..297bef48e 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -126,6 +126,8 @@ where } } +pub const PARA_CHAIN_ID: u32 = ParachainInfo::parachain_id().into(); + fn discriminant(currency: &CurrencyId) -> u8 { match currency { CurrencyId::Native => 0, From d9f5b0336279b8ac64bab7e91710e42a6cfd7fd0 Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 14 Jun 2023 14:34:03 -0300 Subject: [PATCH 03/33] Fixed shifting issue --- runtime/foucoco/src/zenlink.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 297bef48e..2454494ac 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -187,7 +187,7 @@ impl TryFrom for CurrencyId { // 2 => Ok(CurrencyId::Stellar()), 6 => { let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; - let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 20) as u8; + let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; From c003c2bd929352b28c90da6390b6184f76c745d9 Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 14 Jun 2023 15:41:53 -0300 Subject: [PATCH 04/33] Improved format and added hard-coded values for Stellar assets --- runtime/foucoco/src/zenlink.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 2454494ac..5d2437b93 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -153,11 +153,19 @@ impl TryFrom for ZenlinkAssetId { asset_type: LOCAL, asset_index: (disc << 8) + token_id, }), - CurrencyId::Stellar => Ok(ZenlinkAssetId { - chain_id: PARA_CHAIN_ID, - asset_type: LOCAL, - asset_index: (disc << 8) + 1, - }), + CurrencyId::Stellar(Asset::AlphaNum4 { code, .. }) => { + let _id = match code { + b"USDC" => 0u8, + b"TZS\0" => 1u8, + b"BRL\0" => 2u8, + b"XLM\0" => 3u8, + }; + Ok(ZenlinkAssetId { + chain_id: PARA_CHAIN_ID, + asset_type: LOCAL, + asset_index: (disc << 8) + _id, + }) + }, CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { let _index = (disc << 8) + ((token1_id as u64) << 16) + @@ -184,7 +192,16 @@ impl TryFrom for CurrencyId { match disc { 0 => Ok(CurrencyId::Native), 1 => Ok(CurrencyId::XCM(symbol)), - // 2 => Ok(CurrencyId::Stellar()), + 2 => { + let code = match symbol { + 0 => *b"USDC", + 1 => *b"TZS\0", + 2 => *b"BRL\0", + 3 => *b"XLM\0", + }; + let issuer = 0x00; // Should we hard-code the issuer? + Ok(CurrencyId::Stellar(Asset { code, issuer })) + }, 6 => { let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; From fe5b292877e5eab54b5fa40e9682b701f7fc00de Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 15 Jun 2023 13:06:50 -0300 Subject: [PATCH 05/33] Added BRL, TZS and USDC issuers --- runtime/foucoco/src/zenlink.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 5d2437b93..27ee2e179 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -128,6 +128,21 @@ where pub const PARA_CHAIN_ID: u32 = ParachainInfo::parachain_id().into(); +pub const USDC_ISSUER: [u8; 32] = [ + 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, + 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, +]; + +pub const BRL_ISSUER: [u8; 32] = [ + 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, + 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, +]; + +pub const TZS_ISSUER: [u8; 32] = [ + 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, + 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, +]; + fn discriminant(currency: &CurrencyId) -> u8 { match currency { CurrencyId::Native => 0, @@ -193,13 +208,12 @@ impl TryFrom for CurrencyId { 0 => Ok(CurrencyId::Native), 1 => Ok(CurrencyId::XCM(symbol)), 2 => { - let code = match symbol { - 0 => *b"USDC", - 1 => *b"TZS\0", - 2 => *b"BRL\0", - 3 => *b"XLM\0", + let (code, issuer) = match symbol { + 0 => (*b"USDC", USDC_ISSUER), + 1 => (*b"TZS\0", TZS_ISSUER), + 2 => (*b"BRL\0", BRL_ISSUER), + 3 => (*b"XLM\0", [0u8; 32]), }; - let issuer = 0x00; // Should we hard-code the issuer? Ok(CurrencyId::Stellar(Asset { code, issuer })) }, 6 => { From 94282f4bad089a7dfbe9cbabbf9fd2447711ab67 Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 15 Jun 2023 13:54:18 -0300 Subject: [PATCH 06/33] Added StellarNative --- runtime/foucoco/src/zenlink.rs | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 27ee2e179..8992020eb 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -168,12 +168,15 @@ impl TryFrom for ZenlinkAssetId { asset_type: LOCAL, asset_index: (disc << 8) + token_id, }), - CurrencyId::Stellar(Asset::AlphaNum4 { code, .. }) => { - let _id = match code { - b"USDC" => 0u8, - b"TZS\0" => 1u8, - b"BRL\0" => 2u8, - b"XLM\0" => 3u8, + CurrencyId::Stellar(asset) => { + let _id = match asset { + Asset::StellarNative => 0u8, + Asset::AlphaNum4 { code, .. } => match code { + b"USDC" => 1u8, + b"TZS\0" => 2u8, + b"BRL\0" => 3u8, + }, + _ => return Err(()), }; Ok(ZenlinkAssetId { chain_id: PARA_CHAIN_ID, @@ -208,13 +211,21 @@ impl TryFrom for CurrencyId { 0 => Ok(CurrencyId::Native), 1 => Ok(CurrencyId::XCM(symbol)), 2 => { - let (code, issuer) = match symbol { - 0 => (*b"USDC", USDC_ISSUER), - 1 => (*b"TZS\0", TZS_ISSUER), - 2 => (*b"BRL\0", BRL_ISSUER), - 3 => (*b"XLM\0", [0u8; 32]), + match symbol { + 0 => Ok(CurrencyId::Stellar::Native), + 1 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"USDC", + issuer: USDC_ISSUER, + })), + 2 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + code: b"TZS\0", + issuer: TZS_ISSUER, + })), + 3 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + code: b"BRL\0", + issuer: BRL_ISSUER, + })), }; - Ok(CurrencyId::Stellar(Asset { code, issuer })) }, 6 => { let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; From 81fa6333127ae22a85c474e0257a3ec84eda3a06 Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 15 Jun 2023 15:40:43 -0300 Subject: [PATCH 07/33] Added Err(()) return to match statement --- runtime/amplitude/Cargo.toml | 36 +++++++++++++++++----------------- runtime/foucoco/src/zenlink.rs | 1 + 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/runtime/amplitude/Cargo.toml b/runtime/amplitude/Cargo.toml index 1803bec2e..004b33449 100644 --- a/runtime/amplitude/Cargo.toml +++ b/runtime/amplitude/Cargo.toml @@ -26,24 +26,24 @@ smallvec = "1.9.0" runtime-common = { path = "../common", default-features = false } # Custom libraries for Spacewalk -currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } -module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3" } +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } # Substrate frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.37" } diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 8992020eb..08bc2da49 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -225,6 +225,7 @@ impl TryFrom for CurrencyId { code: b"BRL\0", issuer: BRL_ISSUER, })), + _ => return Err(()), }; }, 6 => { From 6f1ff801aeafc32e1c06df3ed273951497641d0d Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 15 Jun 2023 17:22:39 -0300 Subject: [PATCH 08/33] Fixed type issues --- runtime/foucoco/src/zenlink.rs | 76 +++++++++++++++++----------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 08bc2da49..7c0a11c81 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -6,11 +6,11 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; -use spacewalk_primitives::CurrencyId; +use spacewalk_primitives::{CurrencyId, Asset}; use zenlink_protocol::{ - AssetId, AssetIdConverter, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, - ZenlinkMultiAssets, LOCAL, NATIVE, + AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, + NATIVE, }; pub type ZenlinkAssetId = zenlink_protocol::AssetId; @@ -28,9 +28,6 @@ impl ZenlinkConfig for Runtime { type LpGenerate = PairLpGenerate; type TargetChains = ZenlinkRegisteredParaChains; type SelfParaId = SelfParaId; - type AccountIdConverter = (); - type AssetIdConverter = AssetIdConverter; - type XcmExecutor = (); type WeightInfo = (); } @@ -126,8 +123,6 @@ where } } -pub const PARA_CHAIN_ID: u32 = ParachainInfo::parachain_id().into(); - pub const USDC_ISSUER: [u8; 32] = [ 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, @@ -152,46 +147,51 @@ fn discriminant(currency: &CurrencyId) -> u8 { } } -impl TryFrom for ZenlinkAssetId { +struct WrappedCurrencyId(CurrencyId); + +impl TryFrom for ZenlinkAssetId { type Error = (); - fn try_from(currency: CurrencyId) -> Result { - let disc = discriminant(¤cy); + fn try_from(wrapped_currency: WrappedCurrencyId) -> Result { + let disc = discriminant(&wrapped_currency.0) as u64; + let currency = wrapped_currency.0; + let parachain_id: u32 = ParachainInfo::parachain_id().into(); match currency { CurrencyId::Native => Ok(ZenlinkAssetId { - chain_id: PARA_CHAIN_ID, + chain_id: parachain_id, asset_type: NATIVE, asset_index: 0 as u64, }), CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { - chain_id: PARA_CHAIN_ID, + chain_id: parachain_id, asset_type: LOCAL, - asset_index: (disc << 8) + token_id, + asset_index: ((disc << 8) + token_id as u64) as u64, }), CurrencyId::Stellar(asset) => { let _id = match asset { - Asset::StellarNative => 0u8, - Asset::AlphaNum4 { code, .. } => match code { - b"USDC" => 1u8, - b"TZS\0" => 2u8, - b"BRL\0" => 3u8, + Asset::StellarNative => 0u64, + Asset::AlphaNum4 { code, .. } => match &code { + b"USDC" => 1u64, + b"TZS\0" => 2u64, + b"BRL\0" => 3u64, + _ => return Err(()) }, _ => return Err(()), }; Ok(ZenlinkAssetId { - chain_id: PARA_CHAIN_ID, + chain_id: parachain_id, asset_type: LOCAL, - asset_index: (disc << 8) + _id, + asset_index: ((disc << 8) + _id) as u64, }) }, CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { - let _index = (disc << 8) + + let _index = ((disc as u64) << 8) + ((token1_id as u64) << 16) + ((token1_type as u64) << 24) + ((token2_id as u64) << 32) + ((token2_type as u64) << 40); Ok(ZenlinkAssetId { - chain_id: PARA_CHAIN_ID, + chain_id: parachain_id, asset_type: LOCAL, asset_index: _index, }) @@ -200,33 +200,33 @@ impl TryFrom for ZenlinkAssetId { } } -impl TryFrom for CurrencyId { +impl TryFrom for WrappedCurrencyId { type Error = (); fn try_from(asset: ZenlinkAssetId) -> Result { let _index = asset.asset_index; let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; - let symbol = ((_index & 0x0000_0000_0000_00ff) as u8); + let symbol = (_index & 0x0000_0000_0000_00ff) as u8; match disc { - 0 => Ok(CurrencyId::Native), - 1 => Ok(CurrencyId::XCM(symbol)), + 0 => Ok(WrappedCurrencyId(CurrencyId::Native)), + 1 => Ok(WrappedCurrencyId(CurrencyId::XCM(symbol))), 2 => { match symbol { - 0 => Ok(CurrencyId::Stellar::Native), - 1 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + 0 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::StellarNative))), + 1 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"USDC", issuer: USDC_ISSUER, - })), - 2 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { - code: b"TZS\0", + }))), + 2 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"TZS\0", issuer: TZS_ISSUER, - })), - 3 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { - code: b"BRL\0", + }))), + 3 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"BRL\0", issuer: BRL_ISSUER, - })), + }))), _ => return Err(()), - }; + } }, 6 => { let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; @@ -235,7 +235,7 @@ impl TryFrom for CurrencyId { let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; - Ok(CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type)) + Ok(WrappedCurrencyId(CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type))) }, _ => Err(()), } From b63df99cb59e6db3908f52f61761295723c7589d Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 16 Jun 2023 08:59:14 -0300 Subject: [PATCH 09/33] Added TryFrom for WrappedCurrency to CurrencyId. Improved format --- runtime/foucoco/src/zenlink.rs | 51 +++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 7c0a11c81..f772e9f5b 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -6,7 +6,7 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; -use spacewalk_primitives::{CurrencyId, Asset}; +use spacewalk_primitives::{Asset, CurrencyId}; use zenlink_protocol::{ AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, @@ -174,7 +174,7 @@ impl TryFrom for ZenlinkAssetId { b"USDC" => 1u64, b"TZS\0" => 2u64, b"BRL\0" => 3u64, - _ => return Err(()) + _ => return Err(()), }, _ => return Err(()), }; @@ -210,23 +210,21 @@ impl TryFrom for WrappedCurrencyId { match disc { 0 => Ok(WrappedCurrencyId(CurrencyId::Native)), 1 => Ok(WrappedCurrencyId(CurrencyId::XCM(symbol))), - 2 => { - match symbol { - 0 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::StellarNative))), - 1 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"USDC", - issuer: USDC_ISSUER, - }))), - 2 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"TZS\0", - issuer: TZS_ISSUER, - }))), - 3 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"BRL\0", - issuer: BRL_ISSUER, - }))), - _ => return Err(()), - } + 2 => match symbol { + 0 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::StellarNative))), + 1 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"USDC", + issuer: USDC_ISSUER, + }))), + 2 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"TZS\0", + issuer: TZS_ISSUER, + }))), + 3 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"BRL\0", + issuer: BRL_ISSUER, + }))), + _ => return Err(()), }, 6 => { let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; @@ -235,13 +233,26 @@ impl TryFrom for WrappedCurrencyId { let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; - Ok(WrappedCurrencyId(CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type))) + Ok(WrappedCurrencyId(CurrencyId::ZenlinkLPToken( + token1_id, + token1_type, + token2_id, + token2_type, + ))) }, _ => Err(()), } } } +impl TryFrom for CurrencyId { + type Error = (); + + fn try_from(wrapped_currency: WrappedCurrencyId) -> Result { + Ok(wrapped_currency.0) + } +} + fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { let para_chain_id: u32 = ParachainInfo::parachain_id().into(); if asset_id.chain_id != para_chain_id { From 82cb9781e5a8a5e483bddbfed334dcf800da821c Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 16 Jun 2023 11:16:00 -0300 Subject: [PATCH 10/33] changed 'zenlink_id_to_currency_id' function --- runtime/foucoco/src/zenlink.rs | 42 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index f772e9f5b..e50450bfb 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -40,7 +40,8 @@ where Local: MultiCurrency, { fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + let currency: Result = zenlink_id_to_currency_id(asset_id); + if let Ok(currency_id) = currency { return TryInto::::try_into(Local::free_balance(currency_id, &who)) .unwrap_or_default() } @@ -48,7 +49,8 @@ where } fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + let currency: Result = zenlink_id_to_currency_id(asset_id); + if let Ok(currency_id) = currency { return TryInto::::try_into(Local::total_issuance(currency_id)) .unwrap_or_default() } @@ -56,7 +58,8 @@ where } fn local_is_exists(asset_id: ZenlinkAssetId) -> bool { - match zenlink_id_to_currency_id(asset_id) { + let currency: Result = zenlink_id_to_currency_id(asset_id); + match currency { Ok(_) => true, Err(_) => false, } @@ -68,7 +71,8 @@ where target: &AccountId, amount: AssetBalance, ) -> DispatchResult { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + let currency: Result = zenlink_id_to_currency_id(asset_id); + if let Ok(currency_id) = currency { Local::transfer( currency_id, &origin, @@ -87,7 +91,8 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + let currency: Result = zenlink_id_to_currency_id(asset_id); + if let Ok(currency_id) = currency { Local::deposit( currency_id, &origin, @@ -107,7 +112,8 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + let currency: Result = zenlink_id_to_currency_id(asset_id); + if let Ok(currency_id) = currency { Local::withdraw( currency_id, &origin, @@ -254,25 +260,9 @@ impl TryFrom for CurrencyId { } fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { - let para_chain_id: u32 = ParachainInfo::parachain_id().into(); - if asset_id.chain_id != para_chain_id { - log::error!("Asset Chain Id {} not compatibile with the Parachain Id.", asset_id.chain_id); - return Err(()) - } - - match asset_id.asset_type { - NATIVE => Ok(CurrencyId::Native), - LOCAL => { - let foreign_id: u8 = asset_id.asset_index.try_into().map_err(|_| { - log::error!("{} has no Foreign Currency Id match.", asset_id.asset_index); - () - })?; - - Ok(XCM(foreign_id)) - }, - other => { - log::error!("Unsupported asset type index:{other}"); - Err(()) - }, + let wrapped_currency: Result = asset_id.try_into(); + match wrapped_currency { + Ok(WrappedCurrencyId(currency)) => Ok(currency), + _ => Err(()), } } From aaa621d5a735532b01e74f7963ee547654d589ff Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 16 Jun 2023 18:24:46 -0300 Subject: [PATCH 11/33] Added unit tests for the conversion functions --- runtime/foucoco/src/zenlink.rs | 147 +++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index e50450bfb..8dceaceb5 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -153,6 +153,20 @@ fn discriminant(currency: &CurrencyId) -> u8 { } } +#[derive( + Debug, + Encode, + Decode, + Eq, + Hash, + PartialEq, + Copy, + Clone, + PartialOrd, + Ord, + TypeInfo, + MaxEncodedLen, +)] struct WrappedCurrencyId(CurrencyId); impl TryFrom for ZenlinkAssetId { @@ -266,3 +280,136 @@ fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result _ => Err(()), } } + +#[cfg(test)] +mod zenlink_tests { + use super::*; + use core::convert::TryFrom; + + #[test] + fn convert_zenlink_native_to_native_currency() { + // Native ZenlinkAsset index = 0x0000_0000_0000_0000 + let _index = 0 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::Native))); + } + + #[test] + fn convert_zenlink_xcm_to_xcm_currency() { + // XCM(0) ZenlinkAsset index = 0x0000_0000_0000_0100 + let _index = 0x0100 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: _index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::XCM(0)))); + } + + fn get_stellar_asset(selector: u8) -> spacewalk_primitives::CurrencyId { + match selector { + 0 => CurrencyId::Stellar(Asset::StellarNative), + 1 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"USDC", issuer: USDC_ISSUER }), + 2 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"TZS\0", issuer: TZS_ISSUER }), + 3 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"BRL\0", issuer: BRL_ISSUER }), + _ => CurrencyId::Stellar(Asset::StellarNative), + } + } + + #[test] + fn convert_zenlink_stellar_to_stellar_currency() { + // Stellar Native ZenlinkAsset index = 0x0000_0000_0000_0200 + let stellar_native_index = 0x0200 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: stellar_native_index, + }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(0u8)))); + + // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 + let usdc_index = 0x0201 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(1u8)))); + + // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 + let tzs_index = 0x0202 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(2u8)))); + + // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 + let brl_index = 0x0203 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(3u8)))); + } + + #[test] + fn convert_zenlink_lp_token_to_lp_token_currency() { + // Native and XCM(0) LP token Zenlink index = 0x0000_0100_0000_0600 + let native_xcm_lp_token_index = 0x0000_0100_0000_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: native_xcm_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 0, 0, 1)); + assert_eq!(currency, Ok(expected_currency)); + + // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 + let xcm0_xcm1_lp_token_index = 0x0000_0101_0100_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: xcm0_xcm1_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 1)); + assert_eq!(currency, Ok(expected_currency)); + + // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 + let xcm0_stellar_native_lp_token_index = 0x0000_0200_0100_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: xcm0_stellar_native_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 0, 2)); + assert_eq!(currency, Ok(expected_currency)); + + // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 + let xcm0_stellar_usdc_lp_token_index = 0x0000_0201_0100_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: xcm0_stellar_usdc_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 2)); + assert_eq!(currency, Ok(expected_currency)); + + // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 + let stellar_native_stellar_usdc_lp_token_index = 0x0000_0201_0200_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: stellar_native_stellar_usdc_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 2, 1, 2)); + assert_eq!(currency, Ok(expected_currency)); + } +} From 73c7e81731eec78ddde69cc23b72355ceb0981d8 Mon Sep 17 00:00:00 2001 From: adelarja Date: Mon, 19 Jun 2023 15:31:54 -0300 Subject: [PATCH 12/33] Abstracted methods into separate file --- runtime/common/Cargo.toml | 17 +- runtime/common/src/lib.rs | 1 + runtime/common/src/zenlink.rs | 321 ++++++++++++++++++++++++++++++++++ 3 files changed, 334 insertions(+), 5 deletions(-) create mode 100644 runtime/common/src/zenlink.rs diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 49a38a385..cc56854ad 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -14,11 +14,16 @@ targets = ["x86_64-unknown-linux-gnu"] # Substrate parity-scale-codec = {version = "3.1.5", default-features = false, features = ["derive"]} scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" } -sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" } -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "befd6fe8de903407e212902956398df25b50e8f3"} -dia-oracle = { git = "https://github.com/pendulum-chain/oracle-pallet", default-features = false, branch = "polkadot-v0.9.37" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +dia-oracle = { git = "https://github.com/pendulum-chain/oracle-pallet", default-features = false, branch = "polkadot-v0.9.40" } +zenlink-protocol = { git = "https://github.com/pendulum-chain/Zenlink-DEX-Module", default-features = false, branch = "polkadot-v0.9.40-protocol" } + +# Open Runtime Module Library +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.40" } [features] default = [ @@ -29,10 +34,12 @@ std = [ "sp-consensus-aura/std", "sp-runtime/std", "sp-core/std", + "sp-std/std", "spacewalk-primitives/std", "parity-scale-codec/std", "scale-info/std", "dia-oracle/std", + "zenlink-protocol/std", ] runtime-benchmarks = [ diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index e35e39193..c94902bb6 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -6,6 +6,7 @@ use sp_runtime::{ }; pub mod chain_ext; +pub mod zenlink; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = MultiSignature; diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs new file mode 100644 index 000000000..aa0c5efd3 --- /dev/null +++ b/runtime/common/src/zenlink.rs @@ -0,0 +1,321 @@ +use core::convert::TryInto; + +use super::*; + +use orml_traits::MultiCurrency; + +use sp_runtime::{DispatchError, DispatchResult}; +use sp_std::marker::PhantomData; +use sp_core::{Encode, Decode, MaxEncodedLen}; + +use scale_info::TypeInfo; + +use spacewalk_primitives::{Asset, CurrencyId}; + +use zenlink_protocol::{ + AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, + NATIVE, +}; +pub type ZenlinkAssetId = zenlink_protocol::AssetId; + +pub mod zenlink { + // use core::convert::TryInto; + + use super::*; + + // use orml_traits::MultiCurrency; + + // use sp_runtime::{DispatchError, DispatchResult}; + // use sp_std::marker::PhantomData; + // use sp_core::{Encode, Decode, MaxEncodedLen}; + + // use scale_info::TypeInfo; + + // use spacewalk_primitives::{Asset, CurrencyId}; + + // use zenlink_protocol::{ + // AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, + // NATIVE, + // }; + // pub type ZenlinkAssetId = zenlink_protocol::AssetId; + + pub const USDC_ISSUER: [u8; 32] = [ + 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, + 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, + ]; + + pub const BRL_ISSUER: [u8; 32] = [ + 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, + 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, + ]; + + pub const TZS_ISSUER: [u8; 32] = [ + 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, + 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, + ]; + + fn discriminant(currency: &CurrencyId) -> u8 { + match currency { + CurrencyId::Native => 0, + CurrencyId::XCM(_) => 1, + CurrencyId::Stellar(_) => 2, + CurrencyId::ZenlinkLPToken(_, _, _, _) => 6, + } + } + + #[derive( + Debug, + Encode, + Decode, + Eq, + Hash, + PartialEq, + Copy, + Clone, + PartialOrd, + Ord, + TypeInfo, + MaxEncodedLen, + )] + pub struct WrappedCurrencyId(pub CurrencyId); + + impl TryFrom for WrappedCurrencyId { + type Error = (); + + fn try_from(asset: ZenlinkAssetId) -> Result { + let _index = asset.asset_index; + let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; + let symbol = (_index & 0x0000_0000_0000_00ff) as u8; + match disc { + 0 => Ok(WrappedCurrencyId(CurrencyId::Native)), + 1 => Ok(WrappedCurrencyId(CurrencyId::XCM(symbol))), + 2 => match symbol { + 0 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::StellarNative))), + 1 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"USDC", + issuer: USDC_ISSUER, + }))), + 2 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"TZS\0", + issuer: TZS_ISSUER, + }))), + 3 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"BRL\0", + issuer: BRL_ISSUER, + }))), + _ => return Err(()), + }, + 6 => { + let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; + let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; + + let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; + let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; + + Ok(WrappedCurrencyId(CurrencyId::ZenlinkLPToken( + token1_id, + token1_type, + token2_id, + token2_type, + ))) + }, + _ => Err(()), + } + } + } + + impl TryFrom for CurrencyId { + type Error = (); + + fn try_from(wrapped_currency: WrappedCurrencyId) -> Result { + Ok(wrapped_currency.0) + } + } + + pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { + let wrapped_currency: Result = asset_id.try_into(); + match wrapped_currency { + Ok(WrappedCurrencyId(currency)) => Ok(currency), + _ => Err(()), + } + } + + pub fn currency_id_to_zenlink_id(currency_id: CurrencyId, parachain_id: u32) -> Result { + let disc = discriminant(¤cy_id) as u64; + match currency_id { + CurrencyId::Native => Ok(ZenlinkAssetId { + chain_id: parachain_id, + asset_type: NATIVE, + asset_index: 0 as u64, + }), + CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { + chain_id: parachain_id, + asset_type: LOCAL, + asset_index: ((disc << 8) + token_id as u64) as u64, + }), + CurrencyId::Stellar(asset) => { + let _id = match asset { + Asset::StellarNative => 0u64, + Asset::AlphaNum4 { code, .. } => match &code { + b"USDC" => 1u64, + b"TZS\0" => 2u64, + b"BRL\0" => 3u64, + _ => return Err(()), + }, + _ => return Err(()), + }; + Ok(ZenlinkAssetId { + chain_id: parachain_id, + asset_type: LOCAL, + asset_index: ((disc << 8) + _id) as u64, + }) + }, + CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { + let _index = ((disc as u64) << 8) + + ((token1_id as u64) << 16) + + ((token1_type as u64) << 24) + + ((token2_id as u64) << 32) + + ((token2_type as u64) << 40); + Ok(ZenlinkAssetId { + chain_id: parachain_id, + asset_type: LOCAL, + asset_index: _index, + }) + }, + } + } +} + +#[cfg(test)] +mod zenlink_tests { + use super::*; + use crate::zenlink::zenlink::*; + use core::convert::TryFrom; + + #[test] + fn convert_zenlink_native_to_native_currency() { + // Native ZenlinkAsset index = 0x0000_0000_0000_0000 + let _index = 0 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::Native))); + } + + #[test] + fn convert_zenlink_xcm_to_xcm_currency() { + // XCM(0) ZenlinkAsset index = 0x0000_0000_0000_0100 + let _index = 0x0100 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: _index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::XCM(0)))); + } + + fn get_stellar_asset(selector: u8) -> spacewalk_primitives::CurrencyId { + match selector { + 0 => CurrencyId::Stellar(Asset::StellarNative), + 1 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"USDC", issuer: USDC_ISSUER }), + 2 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"TZS\0", issuer: TZS_ISSUER }), + 3 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"BRL\0", issuer: BRL_ISSUER }), + _ => CurrencyId::Stellar(Asset::StellarNative), + } + } + + #[test] + fn convert_zenlink_stellar_to_stellar_currency() { + // Stellar Native ZenlinkAsset index = 0x0000_0000_0000_0200 + let stellar_native_index = 0x0200 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: stellar_native_index, + }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(0u8)))); + + // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 + let usdc_index = 0x0201 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(1u8)))); + + // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 + let tzs_index = 0x0202 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(2u8)))); + + // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 + let brl_index = 0x0203 as u64; + let fake_native_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; + let currency: Result = fake_native_asset.try_into(); + assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(3u8)))); + } + + #[test] + fn convert_zenlink_lp_token_to_lp_token_currency() { + // Native and XCM(0) LP token Zenlink index = 0x0000_0100_0000_0600 + let native_xcm_lp_token_index = 0x0000_0100_0000_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: native_xcm_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 0, 0, 1)); + assert_eq!(currency, Ok(expected_currency)); + + // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 + let xcm0_xcm1_lp_token_index = 0x0000_0101_0100_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: xcm0_xcm1_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 1)); + assert_eq!(currency, Ok(expected_currency)); + + // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 + let xcm0_stellar_native_lp_token_index = 0x0000_0200_0100_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: xcm0_stellar_native_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 0, 2)); + assert_eq!(currency, Ok(expected_currency)); + + // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 + let xcm0_stellar_usdc_lp_token_index = 0x0000_0201_0100_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: xcm0_stellar_usdc_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 2)); + assert_eq!(currency, Ok(expected_currency)); + + // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 + let stellar_native_stellar_usdc_lp_token_index = 0x0000_0201_0200_0600 as u64; + let fake_native_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: stellar_native_stellar_usdc_lp_token_index, + }; + let currency: Result = fake_native_asset.try_into(); + let expected_currency: WrappedCurrencyId = + WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 2, 1, 2)); + assert_eq!(currency, Ok(expected_currency)); + } +} From 5bf9a435b76915a6d7672b5b21ee8b0d56240197 Mon Sep 17 00:00:00 2001 From: adelarja Date: Mon, 19 Jun 2023 16:23:02 -0300 Subject: [PATCH 13/33] Changed module --- runtime/common/src/zenlink.rs | 331 +++++++++++++--------------------- 1 file changed, 129 insertions(+), 202 deletions(-) diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index aa0c5efd3..fccc93a13 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -1,196 +1,123 @@ -use core::convert::TryInto; - -use super::*; - -use orml_traits::MultiCurrency; - -use sp_runtime::{DispatchError, DispatchResult}; -use sp_std::marker::PhantomData; -use sp_core::{Encode, Decode, MaxEncodedLen}; - -use scale_info::TypeInfo; - use spacewalk_primitives::{Asset, CurrencyId}; -use zenlink_protocol::{ - AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, - NATIVE, -}; +use zenlink_protocol::{LOCAL, NATIVE}; pub type ZenlinkAssetId = zenlink_protocol::AssetId; -pub mod zenlink { - // use core::convert::TryInto; - - use super::*; - - // use orml_traits::MultiCurrency; - - // use sp_runtime::{DispatchError, DispatchResult}; - // use sp_std::marker::PhantomData; - // use sp_core::{Encode, Decode, MaxEncodedLen}; - - // use scale_info::TypeInfo; - - // use spacewalk_primitives::{Asset, CurrencyId}; - - // use zenlink_protocol::{ - // AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, - // NATIVE, - // }; - // pub type ZenlinkAssetId = zenlink_protocol::AssetId; - - pub const USDC_ISSUER: [u8; 32] = [ - 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, - 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, - ]; - - pub const BRL_ISSUER: [u8; 32] = [ - 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, - 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, - ]; - - pub const TZS_ISSUER: [u8; 32] = [ - 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, - 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, - ]; - - fn discriminant(currency: &CurrencyId) -> u8 { - match currency { - CurrencyId::Native => 0, - CurrencyId::XCM(_) => 1, - CurrencyId::Stellar(_) => 2, - CurrencyId::ZenlinkLPToken(_, _, _, _) => 6, - } - } - - #[derive( - Debug, - Encode, - Decode, - Eq, - Hash, - PartialEq, - Copy, - Clone, - PartialOrd, - Ord, - TypeInfo, - MaxEncodedLen, - )] - pub struct WrappedCurrencyId(pub CurrencyId); - - impl TryFrom for WrappedCurrencyId { - type Error = (); - - fn try_from(asset: ZenlinkAssetId) -> Result { - let _index = asset.asset_index; - let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; - let symbol = (_index & 0x0000_0000_0000_00ff) as u8; - match disc { - 0 => Ok(WrappedCurrencyId(CurrencyId::Native)), - 1 => Ok(WrappedCurrencyId(CurrencyId::XCM(symbol))), - 2 => match symbol { - 0 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::StellarNative))), - 1 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"USDC", - issuer: USDC_ISSUER, - }))), - 2 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"TZS\0", - issuer: TZS_ISSUER, - }))), - 3 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"BRL\0", - issuer: BRL_ISSUER, - }))), - _ => return Err(()), - }, - 6 => { - let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; - let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; - - let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; - let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; - - Ok(WrappedCurrencyId(CurrencyId::ZenlinkLPToken( - token1_id, - token1_type, - token2_id, - token2_type, - ))) - }, - _ => Err(()), - } - } - } - - impl TryFrom for CurrencyId { - type Error = (); - - fn try_from(wrapped_currency: WrappedCurrencyId) -> Result { - Ok(wrapped_currency.0) - } +pub const USDC_ISSUER: [u8; 32] = [ + 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, + 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, +]; + +pub const BRL_ISSUER: [u8; 32] = [ + 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, + 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, +]; + +pub const TZS_ISSUER: [u8; 32] = [ + 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, + 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, +]; + +fn discriminant(currency: &CurrencyId) -> u8 { + match currency { + CurrencyId::Native => 0, + CurrencyId::XCM(_) => 1, + CurrencyId::Stellar(_) => 2, + CurrencyId::ZenlinkLPToken(_, _, _, _) => 6, } +} - pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { - let wrapped_currency: Result = asset_id.try_into(); - match wrapped_currency { - Ok(WrappedCurrencyId(currency)) => Ok(currency), +pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { + + let _index = asset_id.asset_index; + let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; + let symbol = (_index & 0x0000_0000_0000_00ff) as u8; + match disc { + 0 => Ok(CurrencyId::Native), + 1 => Ok(CurrencyId::XCM(symbol)), + 2 => match symbol { + 0 => Ok(CurrencyId::Stellar(Asset::StellarNative)), + 1 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"USDC", + issuer: USDC_ISSUER, + })), + 2 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"TZS\0", + issuer: TZS_ISSUER, + })), + 3 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { + code: *b"BRL\0", + issuer: BRL_ISSUER, + })), + _ => return Err(()), + }, + 6 => { + let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; + let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; + + let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; + let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; + + Ok(CurrencyId::ZenlinkLPToken( + token1_id, + token1_type, + token2_id, + token2_type, + )) + }, _ => Err(()), } - } +} - pub fn currency_id_to_zenlink_id(currency_id: CurrencyId, parachain_id: u32) -> Result { - let disc = discriminant(¤cy_id) as u64; - match currency_id { - CurrencyId::Native => Ok(ZenlinkAssetId { +pub fn currency_id_to_zenlink_id(currency_id: CurrencyId, parachain_id: u32) -> Result { + let disc = discriminant(¤cy_id) as u64; + match currency_id { + CurrencyId::Native => Ok(ZenlinkAssetId { + chain_id: parachain_id, + asset_type: NATIVE, + asset_index: 0 as u64, + }), + CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { + chain_id: parachain_id, + asset_type: LOCAL, + asset_index: ((disc << 8) + token_id as u64) as u64, + }), + CurrencyId::Stellar(asset) => { + let _id = match asset { + Asset::StellarNative => 0u64, + Asset::AlphaNum4 { code, .. } => match &code { + b"USDC" => 1u64, + b"TZS\0" => 2u64, + b"BRL\0" => 3u64, + _ => return Err(()), + }, + _ => return Err(()), + }; + Ok(ZenlinkAssetId { chain_id: parachain_id, - asset_type: NATIVE, - asset_index: 0 as u64, - }), - CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { + asset_type: LOCAL, + asset_index: ((disc << 8) + _id) as u64, + }) + }, + CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { + let _index = ((disc as u64) << 8) + + ((token1_id as u64) << 16) + + ((token1_type as u64) << 24) + + ((token2_id as u64) << 32) + + ((token2_type as u64) << 40); + Ok(ZenlinkAssetId { chain_id: parachain_id, asset_type: LOCAL, - asset_index: ((disc << 8) + token_id as u64) as u64, - }), - CurrencyId::Stellar(asset) => { - let _id = match asset { - Asset::StellarNative => 0u64, - Asset::AlphaNum4 { code, .. } => match &code { - b"USDC" => 1u64, - b"TZS\0" => 2u64, - b"BRL\0" => 3u64, - _ => return Err(()), - }, - _ => return Err(()), - }; - Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: LOCAL, - asset_index: ((disc << 8) + _id) as u64, - }) - }, - CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { - let _index = ((disc as u64) << 8) + - ((token1_id as u64) << 16) + - ((token1_type as u64) << 24) + - ((token2_id as u64) << 32) + - ((token2_type as u64) << 40); - Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: LOCAL, - asset_index: _index, - }) - }, - } + asset_index: _index, + }) + }, } } + #[cfg(test)] mod zenlink_tests { use super::*; - use crate::zenlink::zenlink::*; - use core::convert::TryFrom; #[test] fn convert_zenlink_native_to_native_currency() { @@ -198,8 +125,8 @@ mod zenlink_tests { let _index = 0 as u64; let fake_native_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::Native))); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + assert_eq!(currency, Ok(CurrencyId::Native)); } #[test] @@ -208,8 +135,8 @@ mod zenlink_tests { let _index = 0x0100 as u64; let fake_native_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: _index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::XCM(0)))); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + assert_eq!(currency, Ok(CurrencyId::XCM(0))); } fn get_stellar_asset(selector: u8) -> spacewalk_primitives::CurrencyId { @@ -231,29 +158,29 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: stellar_native_index, }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(0u8)))); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + assert_eq!(currency, Ok(get_stellar_asset(0u8))); // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 let usdc_index = 0x0201 as u64; let fake_native_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(1u8)))); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + assert_eq!(currency, Ok(get_stellar_asset(1u8))); // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 let tzs_index = 0x0202 as u64; let fake_native_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(2u8)))); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + assert_eq!(currency, Ok(get_stellar_asset(2u8))); // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 let brl_index = 0x0203 as u64; let fake_native_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(3u8)))); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + assert_eq!(currency, Ok(get_stellar_asset(3u8))); } #[test] @@ -265,9 +192,9 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: native_xcm_lp_token_index, }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 0, 0, 1)); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let expected_currency: CurrencyId = + CurrencyId::ZenlinkLPToken(0, 0, 0, 1); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 @@ -277,9 +204,9 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: xcm0_xcm1_lp_token_index, }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 1)); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let expected_currency: CurrencyId = + CurrencyId::ZenlinkLPToken(0, 1, 1, 1); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 @@ -289,9 +216,9 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: xcm0_stellar_native_lp_token_index, }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 0, 2)); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let expected_currency: CurrencyId = + CurrencyId::ZenlinkLPToken(0, 1, 0, 2); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 @@ -301,9 +228,9 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: xcm0_stellar_usdc_lp_token_index, }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 2)); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let expected_currency: CurrencyId = + CurrencyId::ZenlinkLPToken(0, 1, 1, 2); assert_eq!(currency, Ok(expected_currency)); // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 @@ -313,9 +240,9 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: stellar_native_stellar_usdc_lp_token_index, }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 2, 1, 2)); + let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let expected_currency: CurrencyId = + CurrencyId::ZenlinkLPToken(0, 2, 1, 2); assert_eq!(currency, Ok(expected_currency)); } } From a5564d3fd8ba842d692d5d422d28fb77bb165ead Mon Sep 17 00:00:00 2001 From: adelarja Date: Mon, 19 Jun 2023 16:25:19 -0300 Subject: [PATCH 14/33] Refactored runtime configuration of zenlink --- runtime/foucoco/src/zenlink.rs | 305 +-------------------------------- 1 file changed, 8 insertions(+), 297 deletions(-) diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 8dceaceb5..8eb3c6192 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -14,6 +14,8 @@ use zenlink_protocol::{ }; pub type ZenlinkAssetId = zenlink_protocol::AssetId; +use runtime_common::zenlink::*; + parameter_types! { pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); @@ -40,8 +42,7 @@ where Local: MultiCurrency, { fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { - let currency: Result = zenlink_id_to_currency_id(asset_id); - if let Ok(currency_id) = currency { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { return TryInto::::try_into(Local::free_balance(currency_id, &who)) .unwrap_or_default() } @@ -49,8 +50,7 @@ where } fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { - let currency: Result = zenlink_id_to_currency_id(asset_id); - if let Ok(currency_id) = currency { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { return TryInto::::try_into(Local::total_issuance(currency_id)) .unwrap_or_default() } @@ -58,8 +58,7 @@ where } fn local_is_exists(asset_id: ZenlinkAssetId) -> bool { - let currency: Result = zenlink_id_to_currency_id(asset_id); - match currency { + match zenlink_id_to_currency_id(asset_id) { Ok(_) => true, Err(_) => false, } @@ -71,8 +70,7 @@ where target: &AccountId, amount: AssetBalance, ) -> DispatchResult { - let currency: Result = zenlink_id_to_currency_id(asset_id); - if let Ok(currency_id) = currency { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { Local::transfer( currency_id, &origin, @@ -91,8 +89,7 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - let currency: Result = zenlink_id_to_currency_id(asset_id); - if let Ok(currency_id) = currency { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { Local::deposit( currency_id, &origin, @@ -112,8 +109,7 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - let currency: Result = zenlink_id_to_currency_id(asset_id); - if let Ok(currency_id) = currency { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { Local::withdraw( currency_id, &origin, @@ -128,288 +124,3 @@ where Ok(amount) } } - -pub const USDC_ISSUER: [u8; 32] = [ - 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, - 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, -]; - -pub const BRL_ISSUER: [u8; 32] = [ - 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, - 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, -]; - -pub const TZS_ISSUER: [u8; 32] = [ - 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, - 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, -]; - -fn discriminant(currency: &CurrencyId) -> u8 { - match currency { - CurrencyId::Native => 0, - CurrencyId::XCM(_) => 1, - CurrencyId::Stellar(_) => 2, - CurrencyId::ZenlinkLPToken(_, _, _, _) => 6, - } -} - -#[derive( - Debug, - Encode, - Decode, - Eq, - Hash, - PartialEq, - Copy, - Clone, - PartialOrd, - Ord, - TypeInfo, - MaxEncodedLen, -)] -struct WrappedCurrencyId(CurrencyId); - -impl TryFrom for ZenlinkAssetId { - type Error = (); - - fn try_from(wrapped_currency: WrappedCurrencyId) -> Result { - let disc = discriminant(&wrapped_currency.0) as u64; - let currency = wrapped_currency.0; - let parachain_id: u32 = ParachainInfo::parachain_id().into(); - match currency { - CurrencyId::Native => Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: NATIVE, - asset_index: 0 as u64, - }), - CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: LOCAL, - asset_index: ((disc << 8) + token_id as u64) as u64, - }), - CurrencyId::Stellar(asset) => { - let _id = match asset { - Asset::StellarNative => 0u64, - Asset::AlphaNum4 { code, .. } => match &code { - b"USDC" => 1u64, - b"TZS\0" => 2u64, - b"BRL\0" => 3u64, - _ => return Err(()), - }, - _ => return Err(()), - }; - Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: LOCAL, - asset_index: ((disc << 8) + _id) as u64, - }) - }, - CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type) => { - let _index = ((disc as u64) << 8) + - ((token1_id as u64) << 16) + - ((token1_type as u64) << 24) + - ((token2_id as u64) << 32) + - ((token2_type as u64) << 40); - Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: LOCAL, - asset_index: _index, - }) - }, - } - } -} - -impl TryFrom for WrappedCurrencyId { - type Error = (); - - fn try_from(asset: ZenlinkAssetId) -> Result { - let _index = asset.asset_index; - let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; - let symbol = (_index & 0x0000_0000_0000_00ff) as u8; - match disc { - 0 => Ok(WrappedCurrencyId(CurrencyId::Native)), - 1 => Ok(WrappedCurrencyId(CurrencyId::XCM(symbol))), - 2 => match symbol { - 0 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::StellarNative))), - 1 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"USDC", - issuer: USDC_ISSUER, - }))), - 2 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"TZS\0", - issuer: TZS_ISSUER, - }))), - 3 => Ok(WrappedCurrencyId(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"BRL\0", - issuer: BRL_ISSUER, - }))), - _ => return Err(()), - }, - 6 => { - let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; - let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; - - let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; - let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; - - Ok(WrappedCurrencyId(CurrencyId::ZenlinkLPToken( - token1_id, - token1_type, - token2_id, - token2_type, - ))) - }, - _ => Err(()), - } - } -} - -impl TryFrom for CurrencyId { - type Error = (); - - fn try_from(wrapped_currency: WrappedCurrencyId) -> Result { - Ok(wrapped_currency.0) - } -} - -fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { - let wrapped_currency: Result = asset_id.try_into(); - match wrapped_currency { - Ok(WrappedCurrencyId(currency)) => Ok(currency), - _ => Err(()), - } -} - -#[cfg(test)] -mod zenlink_tests { - use super::*; - use core::convert::TryFrom; - - #[test] - fn convert_zenlink_native_to_native_currency() { - // Native ZenlinkAsset index = 0x0000_0000_0000_0000 - let _index = 0 as u64; - let fake_native_asset = - ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::Native))); - } - - #[test] - fn convert_zenlink_xcm_to_xcm_currency() { - // XCM(0) ZenlinkAsset index = 0x0000_0000_0000_0100 - let _index = 0x0100 as u64; - let fake_native_asset = - ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: _index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(CurrencyId::XCM(0)))); - } - - fn get_stellar_asset(selector: u8) -> spacewalk_primitives::CurrencyId { - match selector { - 0 => CurrencyId::Stellar(Asset::StellarNative), - 1 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"USDC", issuer: USDC_ISSUER }), - 2 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"TZS\0", issuer: TZS_ISSUER }), - 3 => CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"BRL\0", issuer: BRL_ISSUER }), - _ => CurrencyId::Stellar(Asset::StellarNative), - } - } - - #[test] - fn convert_zenlink_stellar_to_stellar_currency() { - // Stellar Native ZenlinkAsset index = 0x0000_0000_0000_0200 - let stellar_native_index = 0x0200 as u64; - let fake_native_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: stellar_native_index, - }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(0u8)))); - - // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 - let usdc_index = 0x0201 as u64; - let fake_native_asset = - ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(1u8)))); - - // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 - let tzs_index = 0x0202 as u64; - let fake_native_asset = - ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(2u8)))); - - // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 - let brl_index = 0x0203 as u64; - let fake_native_asset = - ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; - let currency: Result = fake_native_asset.try_into(); - assert_eq!(currency, Ok(WrappedCurrencyId(get_stellar_asset(3u8)))); - } - - #[test] - fn convert_zenlink_lp_token_to_lp_token_currency() { - // Native and XCM(0) LP token Zenlink index = 0x0000_0100_0000_0600 - let native_xcm_lp_token_index = 0x0000_0100_0000_0600 as u64; - let fake_native_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: native_xcm_lp_token_index, - }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 0, 0, 1)); - assert_eq!(currency, Ok(expected_currency)); - - // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 - let xcm0_xcm1_lp_token_index = 0x0000_0101_0100_0600 as u64; - let fake_native_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: xcm0_xcm1_lp_token_index, - }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 1)); - assert_eq!(currency, Ok(expected_currency)); - - // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 - let xcm0_stellar_native_lp_token_index = 0x0000_0200_0100_0600 as u64; - let fake_native_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: xcm0_stellar_native_lp_token_index, - }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 0, 2)); - assert_eq!(currency, Ok(expected_currency)); - - // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 - let xcm0_stellar_usdc_lp_token_index = 0x0000_0201_0100_0600 as u64; - let fake_native_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: xcm0_stellar_usdc_lp_token_index, - }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 1, 1, 2)); - assert_eq!(currency, Ok(expected_currency)); - - // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 - let stellar_native_stellar_usdc_lp_token_index = 0x0000_0201_0200_0600 as u64; - let fake_native_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: stellar_native_stellar_usdc_lp_token_index, - }; - let currency: Result = fake_native_asset.try_into(); - let expected_currency: WrappedCurrencyId = - WrappedCurrencyId(CurrencyId::ZenlinkLPToken(0, 2, 1, 2)); - assert_eq!(currency, Ok(expected_currency)); - } -} From 19abbdef270afc2846005ba4e681f83f79145b34 Mon Sep 17 00:00:00 2001 From: adelarja Date: Tue, 20 Jun 2023 09:39:56 -0300 Subject: [PATCH 15/33] Improved code format. Added unit tests --- runtime/common/src/zenlink.rs | 129 ++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index fccc93a13..56756f300 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -28,55 +28,40 @@ fn discriminant(currency: &CurrencyId) -> u8 { } pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { - let _index = asset_id.asset_index; - let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; - let symbol = (_index & 0x0000_0000_0000_00ff) as u8; - match disc { - 0 => Ok(CurrencyId::Native), - 1 => Ok(CurrencyId::XCM(symbol)), - 2 => match symbol { - 0 => Ok(CurrencyId::Stellar(Asset::StellarNative)), - 1 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"USDC", - issuer: USDC_ISSUER, - })), - 2 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"TZS\0", - issuer: TZS_ISSUER, - })), - 3 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { - code: *b"BRL\0", - issuer: BRL_ISSUER, - })), - _ => return Err(()), - }, - 6 => { - let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; - let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; - - let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; - let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; - - Ok(CurrencyId::ZenlinkLPToken( - token1_id, - token1_type, - token2_id, - token2_type, - )) - }, - _ => Err(()), - } + let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; + let symbol = (_index & 0x0000_0000_0000_00ff) as u8; + match disc { + 0 => Ok(CurrencyId::Native), + 1 => Ok(CurrencyId::XCM(symbol)), + 2 => match symbol { + 0 => Ok(CurrencyId::Stellar(Asset::StellarNative)), + 1 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"USDC", issuer: USDC_ISSUER })), + 2 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"TZS\0", issuer: TZS_ISSUER })), + 3 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"BRL\0", issuer: BRL_ISSUER })), + _ => return Err(()), + }, + 6 => { + let token1_id = ((_index & 0x0000_0000_00FF_0000) >> 16) as u8; + let token1_type = ((_index & 0x0000_0000_FF00_0000) >> 24) as u8; + + let token2_id = ((_index & 0x0000_00FF_0000_0000) >> 32) as u8; + let token2_type = ((_index & 0x0000_FF00_0000_0000) >> 40) as u8; + + Ok(CurrencyId::ZenlinkLPToken(token1_id, token1_type, token2_id, token2_type)) + }, + _ => Err(()), + } } -pub fn currency_id_to_zenlink_id(currency_id: CurrencyId, parachain_id: u32) -> Result { +pub fn currency_id_to_zenlink_id( + currency_id: CurrencyId, + parachain_id: u32, +) -> Result { let disc = discriminant(¤cy_id) as u64; match currency_id { - CurrencyId::Native => Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: NATIVE, - asset_index: 0 as u64, - }), + CurrencyId::Native => + Ok(ZenlinkAssetId { chain_id: parachain_id, asset_type: NATIVE, asset_index: 0 as u64 }), CurrencyId::XCM(token_id) => Ok(ZenlinkAssetId { chain_id: parachain_id, asset_type: LOCAL, @@ -105,16 +90,11 @@ pub fn currency_id_to_zenlink_id(currency_id: CurrencyId, parachain_id: u32) -> ((token1_type as u64) << 24) + ((token2_id as u64) << 32) + ((token2_type as u64) << 40); - Ok(ZenlinkAssetId { - chain_id: parachain_id, - asset_type: LOCAL, - asset_index: _index, - }) + Ok(ZenlinkAssetId { chain_id: parachain_id, asset_type: LOCAL, asset_index: _index }) }, } } - #[cfg(test)] mod zenlink_tests { use super::*; @@ -193,8 +173,7 @@ mod zenlink_tests { asset_index: native_xcm_lp_token_index, }; let currency: Result = zenlink_id_to_currency_id(fake_native_asset); - let expected_currency: CurrencyId = - CurrencyId::ZenlinkLPToken(0, 0, 0, 1); + let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 0, 0, 1); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 @@ -205,8 +184,7 @@ mod zenlink_tests { asset_index: xcm0_xcm1_lp_token_index, }; let currency: Result = zenlink_id_to_currency_id(fake_native_asset); - let expected_currency: CurrencyId = - CurrencyId::ZenlinkLPToken(0, 1, 1, 1); + let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 1); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 @@ -217,8 +195,7 @@ mod zenlink_tests { asset_index: xcm0_stellar_native_lp_token_index, }; let currency: Result = zenlink_id_to_currency_id(fake_native_asset); - let expected_currency: CurrencyId = - CurrencyId::ZenlinkLPToken(0, 1, 0, 2); + let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 0, 2); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 @@ -229,8 +206,7 @@ mod zenlink_tests { asset_index: xcm0_stellar_usdc_lp_token_index, }; let currency: Result = zenlink_id_to_currency_id(fake_native_asset); - let expected_currency: CurrencyId = - CurrencyId::ZenlinkLPToken(0, 1, 1, 2); + let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 2); assert_eq!(currency, Ok(expected_currency)); // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 @@ -241,8 +217,41 @@ mod zenlink_tests { asset_index: stellar_native_stellar_usdc_lp_token_index, }; let currency: Result = zenlink_id_to_currency_id(fake_native_asset); - let expected_currency: CurrencyId = - CurrencyId::ZenlinkLPToken(0, 2, 1, 2); + let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 2, 1, 2); assert_eq!(currency, Ok(expected_currency)); } + + #[test] + fn convert_native_currency_to_zenlink_stellar() { + let fake_currency_id = CurrencyId::Native; + let expected_zenlink_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0u64 }; + assert_eq!(currency_id_to_zenlink_id(fake_currency_id, 1000), Ok(expected_zenlink_asset)); + } + + #[test] + fn convert_xcm_currency_to_zenlink_xcm() { + let fake_currency_id = CurrencyId::XCM(0); + let expected_zenlink_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: 0x0100 as u64 }; + assert_eq!(currency_id_to_zenlink_id(fake_currency_id, 1000), Ok(expected_zenlink_asset)); + } + + #[test] + fn convert_stellar_currency_to_stellar_zenlink() { + let stellar_assets_indexes: [u64; 4] = [0x0200u64, 0x0201u64, 0x0202u64, 0x0203u64]; + + for i in 0..=3usize { + let fake_currency_id = get_stellar_asset(i as u8); + let expected_zenlink_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: stellar_assets_indexes[i], + }; + assert_eq!( + currency_id_to_zenlink_id(fake_currency_id, 1000), + Ok(expected_zenlink_asset) + ); + } + } } From e573c15ce405fae2b2c72ae042d8b0f64a6e4bfe Mon Sep 17 00:00:00 2001 From: Adel Arja Date: Tue, 20 Jun 2023 12:25:19 -0300 Subject: [PATCH 16/33] Update Cargo.toml deleted unnecessary dependencies. --- runtime/common/Cargo.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index cc56854ad..cdd754193 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -17,14 +17,10 @@ scale-info = {version = "2.1.1", default-features = false, features = ["derive"] sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} dia-oracle = { git = "https://github.com/pendulum-chain/oracle-pallet", default-features = false, branch = "polkadot-v0.9.40" } zenlink-protocol = { git = "https://github.com/pendulum-chain/Zenlink-DEX-Module", default-features = false, branch = "polkadot-v0.9.40-protocol" } -# Open Runtime Module Library -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.40" } - [features] default = [ "std", @@ -34,7 +30,6 @@ std = [ "sp-consensus-aura/std", "sp-runtime/std", "sp-core/std", - "sp-std/std", "spacewalk-primitives/std", "parity-scale-codec/std", "scale-info/std", From d8c0655afae99d444764a700d38ee8ebbcc652b7 Mon Sep 17 00:00:00 2001 From: Adel Arja Date: Tue, 20 Jun 2023 12:45:21 -0300 Subject: [PATCH 17/33] Update Cargo.toml Updated spacewalk dependencies. --- node/Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index cbb62fc75..f6ed8f31e 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -15,13 +15,13 @@ codec = { package = "parity-scale-codec", version = "3.0.0" } serde = { version = "1.0.145", features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server"] } -module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "befd6fe8de903407e212902956398df25b50e8f3"} -module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "befd6fe8de903407e212902956398df25b50e8f3"} +module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "befd6fe8de903407e212902956398df25b50e8f3"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} # Local amplitude-runtime = {path = "../runtime/amplitude"} From 901d3c43e90c31b0428804c0ee81f753b7090561 Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 21 Jun 2023 08:06:14 -0300 Subject: [PATCH 18/33] Extended statement to check also the issuer in the match of conversion function for stellar assets. --- runtime/common/src/zenlink.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index 56756f300..385227ff1 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -70,10 +70,10 @@ pub fn currency_id_to_zenlink_id( CurrencyId::Stellar(asset) => { let _id = match asset { Asset::StellarNative => 0u64, - Asset::AlphaNum4 { code, .. } => match &code { - b"USDC" => 1u64, - b"TZS\0" => 2u64, - b"BRL\0" => 3u64, + Asset::AlphaNum4 { code, issuer } => match (&code, &issuer) { + (b"USDC", &USDC_ISSUER) => 1u64, + (b"TZS\0", &TZS_ISSUER) => 2u64, + (b"BRL\0", &BRL_ISSUER) => 3u64, _ => return Err(()), }, _ => return Err(()), From db97794821bdf894dace79a0523424cf80235775 Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 21 Jun 2023 10:56:12 -0300 Subject: [PATCH 19/33] Renamed test varible and test name. --- runtime/common/src/zenlink.rs | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index 385227ff1..7d56251bb 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -103,9 +103,9 @@ mod zenlink_tests { fn convert_zenlink_native_to_native_currency() { // Native ZenlinkAsset index = 0x0000_0000_0000_0000 let _index = 0 as u64; - let fake_native_asset = + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); assert_eq!(currency, Ok(CurrencyId::Native)); } @@ -113,9 +113,9 @@ mod zenlink_tests { fn convert_zenlink_xcm_to_xcm_currency() { // XCM(0) ZenlinkAsset index = 0x0000_0000_0000_0100 let _index = 0x0100 as u64; - let fake_native_asset = + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: _index }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); assert_eq!(currency, Ok(CurrencyId::XCM(0))); } @@ -133,33 +133,33 @@ mod zenlink_tests { fn convert_zenlink_stellar_to_stellar_currency() { // Stellar Native ZenlinkAsset index = 0x0000_0000_0000_0200 let stellar_native_index = 0x0200 as u64; - let fake_native_asset = ZenlinkAssetId { + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: stellar_native_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); assert_eq!(currency, Ok(get_stellar_asset(0u8))); // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 let usdc_index = 0x0201 as u64; - let fake_native_asset = + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); assert_eq!(currency, Ok(get_stellar_asset(1u8))); // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 let tzs_index = 0x0202 as u64; - let fake_native_asset = + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); assert_eq!(currency, Ok(get_stellar_asset(2u8))); // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 let brl_index = 0x0203 as u64; - let fake_native_asset = + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); assert_eq!(currency, Ok(get_stellar_asset(3u8))); } @@ -167,62 +167,62 @@ mod zenlink_tests { fn convert_zenlink_lp_token_to_lp_token_currency() { // Native and XCM(0) LP token Zenlink index = 0x0000_0100_0000_0600 let native_xcm_lp_token_index = 0x0000_0100_0000_0600 as u64; - let fake_native_asset = ZenlinkAssetId { + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: native_xcm_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 0, 0, 1); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 let xcm0_xcm1_lp_token_index = 0x0000_0101_0100_0600 as u64; - let fake_native_asset = ZenlinkAssetId { + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: xcm0_xcm1_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 1); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 let xcm0_stellar_native_lp_token_index = 0x0000_0200_0100_0600 as u64; - let fake_native_asset = ZenlinkAssetId { + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: xcm0_stellar_native_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 0, 2); assert_eq!(currency, Ok(expected_currency)); // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 let xcm0_stellar_usdc_lp_token_index = 0x0000_0201_0100_0600 as u64; - let fake_native_asset = ZenlinkAssetId { + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: xcm0_stellar_usdc_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 2); assert_eq!(currency, Ok(expected_currency)); // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 let stellar_native_stellar_usdc_lp_token_index = 0x0000_0201_0200_0600 as u64; - let fake_native_asset = ZenlinkAssetId { + let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: stellar_native_stellar_usdc_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_native_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 2, 1, 2); assert_eq!(currency, Ok(expected_currency)); } #[test] - fn convert_native_currency_to_zenlink_stellar() { + fn convert_native_currency_to_zenlink_native() { let fake_currency_id = CurrencyId::Native; let expected_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0u64 }; From 1239e987503532390712d458fadf52088cf5a26a Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 21 Jun 2023 13:44:47 -0300 Subject: [PATCH 20/33] Refactored zenlink_id_to_currency_id function. Now it checks that the asset chain_id and the parachain_id are the same. --- runtime/common/src/zenlink.rs | 28 ++++++++++++++++------------ runtime/foucoco/src/zenlink.rs | 12 ++++++------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index 7d56251bb..d8dd2c1f5 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -27,7 +27,11 @@ fn discriminant(currency: &CurrencyId) -> u8 { } } -pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { +pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId, parachain_id: u32) -> Result { + if asset_id.chain_id != parachain_id { + return Err(()) + } + let _index = asset_id.asset_index; let disc = ((_index & 0x0000_0000_0000_ff00) >> 8) as u8; let symbol = (_index & 0x0000_0000_0000_00ff) as u8; @@ -105,7 +109,7 @@ mod zenlink_tests { let _index = 0 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(CurrencyId::Native)); } @@ -115,7 +119,7 @@ mod zenlink_tests { let _index = 0x0100 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: _index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(CurrencyId::XCM(0))); } @@ -138,28 +142,28 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: stellar_native_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(0u8))); // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 let usdc_index = 0x0201 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(1u8))); // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 let tzs_index = 0x0202 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(2u8))); // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 let brl_index = 0x0203 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(3u8))); } @@ -172,7 +176,7 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: native_xcm_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 0, 0, 1); assert_eq!(currency, Ok(expected_currency)); @@ -183,7 +187,7 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: xcm0_xcm1_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 1); assert_eq!(currency, Ok(expected_currency)); @@ -194,7 +198,7 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: xcm0_stellar_native_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 0, 2); assert_eq!(currency, Ok(expected_currency)); @@ -205,7 +209,7 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: xcm0_stellar_usdc_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 2); assert_eq!(currency, Ok(expected_currency)); @@ -216,7 +220,7 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: stellar_native_stellar_usdc_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset); + let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 2, 1, 2); assert_eq!(currency, Ok(expected_currency)); } diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 8eb3c6192..818fcd9c9 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -42,7 +42,7 @@ where Local: MultiCurrency, { fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { return TryInto::::try_into(Local::free_balance(currency_id, &who)) .unwrap_or_default() } @@ -50,7 +50,7 @@ where } fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { return TryInto::::try_into(Local::total_issuance(currency_id)) .unwrap_or_default() } @@ -58,7 +58,7 @@ where } fn local_is_exists(asset_id: ZenlinkAssetId) -> bool { - match zenlink_id_to_currency_id(asset_id) { + match zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { Ok(_) => true, Err(_) => false, } @@ -70,7 +70,7 @@ where target: &AccountId, amount: AssetBalance, ) -> DispatchResult { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { Local::transfer( currency_id, &origin, @@ -89,7 +89,7 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { Local::deposit( currency_id, &origin, @@ -109,7 +109,7 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { Local::withdraw( currency_id, &origin, From c8ce574e5f314a91ef9b5b19d7e7c8b89d927c16 Mon Sep 17 00:00:00 2001 From: adelarja Date: Wed, 21 Jun 2023 13:50:11 -0300 Subject: [PATCH 21/33] Added unit test for Err result when converting between zenlink asset and spacewalk asset. --- runtime/common/src/zenlink.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index d8dd2c1f5..e0a6cabca 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -225,6 +225,17 @@ mod zenlink_tests { assert_eq!(currency, Ok(expected_currency)); } + #[test] + fn convert_zenlink_id_to_currency_id_error() { + let fake_zenlink_asset = ZenlinkAssetId { + chain_id: 1000u32, + asset_type: LOCAL, + asset_index: 0u64, + }; + // We pass a parachain_id different than the asset chain_id + assert_eq!(zenlink_id_to_currency_id(fake_zenlink_asset, 1001u32), Err(())); + } + #[test] fn convert_native_currency_to_zenlink_native() { let fake_currency_id = CurrencyId::Native; From 7f45510ad29cb693e6f4e4969e79c586a35c8c0e Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 6 Jul 2023 11:55:42 -0300 Subject: [PATCH 22/33] Added stellar module with issuer definitions. --- runtime/common/src/lib.rs | 1 + runtime/common/src/stellar.rs | 14 ++++++++++++++ runtime/common/src/zenlink.rs | 16 +--------------- 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 runtime/common/src/stellar.rs diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index c94902bb6..33c92567f 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -6,6 +6,7 @@ use sp_runtime::{ }; pub mod chain_ext; +pub mod stellar; pub mod zenlink; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. diff --git a/runtime/common/src/stellar.rs b/runtime/common/src/stellar.rs new file mode 100644 index 000000000..b32ab4ca9 --- /dev/null +++ b/runtime/common/src/stellar.rs @@ -0,0 +1,14 @@ +pub const USDC_ISSUER: [u8; 32] = [ + 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, + 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, +]; + +pub const BRL_ISSUER: [u8; 32] = [ + 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, + 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, +]; + +pub const TZS_ISSUER: [u8; 32] = [ + 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, + 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, +]; \ No newline at end of file diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index 2c11d0955..d9ff251db 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -1,23 +1,9 @@ use spacewalk_primitives::{Asset, CurrencyId}; +use crate::stellar::{USDC_ISSUER, TZS_ISSUER, BRL_ISSUER}; use zenlink_protocol::{LOCAL, NATIVE}; pub type ZenlinkAssetId = zenlink_protocol::AssetId; -pub const USDC_ISSUER: [u8; 32] = [ - 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, - 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, -]; - -pub const BRL_ISSUER: [u8; 32] = [ - 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, - 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, -]; - -pub const TZS_ISSUER: [u8; 32] = [ - 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, - 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, -]; - fn discriminant(currency: &CurrencyId) -> u8 { match currency { CurrencyId::Native => 0, From ee098abb9a9441a218bb3067766ef89d1cda0b28 Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 6 Jul 2023 14:29:00 -0300 Subject: [PATCH 23/33] Changed spacewalk dependency commit hash --- runtime/amplitude/Cargo.toml | 36 ++++++++++++++++++------------------ runtime/common/Cargo.toml | 2 +- runtime/foucoco/Cargo.toml | 36 ++++++++++++++++++------------------ 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/runtime/amplitude/Cargo.toml b/runtime/amplitude/Cargo.toml index 1e5ec63ce..f55650806 100644 --- a/runtime/amplitude/Cargo.toml +++ b/runtime/amplitude/Cargo.toml @@ -26,24 +26,24 @@ smallvec = "1.9.0" runtime-common = { path = "../common", default-features = false } # Custom libraries for Spacewalk -currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } -module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905" } +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } # Substrate frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40" } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index d8984f929..b0b63a309 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -18,7 +18,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} dia-oracle = { git = "https://github.com/pendulum-chain/oracle-pallet", default-features = false, branch = "polkadot-v0.9.40" } zenlink-protocol = { git = "https://github.com/pendulum-chain/Zenlink-DEX-Module", default-features = false, branch = "polkadot-v0.9.40-protocol" } diff --git a/runtime/foucoco/Cargo.toml b/runtime/foucoco/Cargo.toml index ee43dce62..3db1af6da 100644 --- a/runtime/foucoco/Cargo.toml +++ b/runtime/foucoco/Cargo.toml @@ -26,25 +26,25 @@ smallvec = "1.9.0" runtime-common = { path = "../common", default-features = false } # custom libraries from spacewalk -currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} # Substrate frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40" } From b4733f562f54b36bf2b417d03cf9ad4ef2f2d6b5 Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 6 Jul 2023 22:47:00 -0300 Subject: [PATCH 24/33] Fixed spacewalk dependencies in node --- node/Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index c997a85a2..59f8ee501 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -15,13 +15,13 @@ codec = { package = "parity-scale-codec", version = "3.0.0" } serde = { version = "1.0.145", features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server"] } -module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} -module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "d1188915d10735f5ff32f0301705f0aa091cd905"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} # Local amplitude-runtime = {path = "../runtime/amplitude"} From 6d3df88166af8ba0ee2600327cc833d6b724b739 Mon Sep 17 00:00:00 2001 From: adelarja Date: Mon, 10 Jul 2023 09:09:52 -0300 Subject: [PATCH 25/33] Implemented GenerateLpAssetId to change the generate_lp_asset_id function, allowing us to use a discriminant of 3 for the Zenlink LP token. --- runtime/common/src/stellar.rs | 2 +- runtime/common/src/zenlink.rs | 90 +++++++++++++++++++++------------- runtime/foucoco/src/zenlink.rs | 38 ++++++++++---- 3 files changed, 87 insertions(+), 43 deletions(-) diff --git a/runtime/common/src/stellar.rs b/runtime/common/src/stellar.rs index b32ab4ca9..abd8c5bff 100644 --- a/runtime/common/src/stellar.rs +++ b/runtime/common/src/stellar.rs @@ -11,4 +11,4 @@ pub const BRL_ISSUER: [u8; 32] = [ pub const TZS_ISSUER: [u8; 32] = [ 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186, -]; \ No newline at end of file +]; diff --git a/runtime/common/src/zenlink.rs b/runtime/common/src/zenlink.rs index d9ff251db..c2ee377b2 100644 --- a/runtime/common/src/zenlink.rs +++ b/runtime/common/src/zenlink.rs @@ -1,5 +1,5 @@ +use crate::stellar::{BRL_ISSUER, TZS_ISSUER, USDC_ISSUER}; use spacewalk_primitives::{Asset, CurrencyId}; -use crate::stellar::{USDC_ISSUER, TZS_ISSUER, BRL_ISSUER}; use zenlink_protocol::{LOCAL, NATIVE}; pub type ZenlinkAssetId = zenlink_protocol::AssetId; @@ -9,12 +9,27 @@ fn discriminant(currency: &CurrencyId) -> u8 { CurrencyId::Native => 0, CurrencyId::XCM(_) => 1, CurrencyId::Stellar(_) => 2, - CurrencyId::ZenlinkLPToken(_, _, _, _) => 6, + CurrencyId::ZenlinkLPToken(_, _, _, _) => 3, } } -pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId, parachain_id: u32) -> Result { - if asset_id.chain_id != parachain_id { +pub fn generate_lp_asset_id( + asset_0: ZenlinkAssetId, + asset_1: ZenlinkAssetId, + parachain_id: u32, +) -> Option { + let currency_0 = (asset_0.asset_index & 0x0000_0000_0000_ffff) << 16; + let currency_1 = (asset_1.asset_index & 0x0000_0000_0000_ffff) << 32; + let discr = 3u64 << 8; + let index = currency_0 + currency_1 + discr; + Some(ZenlinkAssetId { chain_id: parachain_id, asset_type: LOCAL, asset_index: index }) +} + +pub fn zenlink_id_to_currency_id( + asset_id: ZenlinkAssetId, + parachain_id: u32, +) -> Result { + if asset_id.chain_id != parachain_id { return Err(()) } @@ -32,7 +47,7 @@ pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId, parachain_id: u32) -> 3 => Ok(CurrencyId::Stellar(Asset::AlphaNum4 { code: *b"BRL\0", issuer: BRL_ISSUER })), _ => return Err(()), }, - (6, LOCAL) => { + (3, LOCAL) => { let token1_id = ((index & 0x0000_0000_00FF_0000) >> 16) as u8; let token1_type = ((index & 0x0000_0000_FF00_0000) >> 24) as u8; @@ -95,7 +110,8 @@ mod zenlink_tests { // Native ZenlinkAsset index = 0x0000_0000_0000_0000 let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: NATIVE, asset_index: 0 as u64 }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(CurrencyId::Native)); } @@ -105,7 +121,8 @@ mod zenlink_tests { let index = 0x0100 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(CurrencyId::XCM(0))); } @@ -128,105 +145,112 @@ mod zenlink_tests { asset_type: LOCAL, asset_index: stellar_native_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(0u8))); // Stellar USDC ZenlinkAsset index = 0x0000_0000_0000_0201 let usdc_index = 0x0201 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: usdc_index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(1u8))); // Stellar TZS ZenlinkAsset index = 0x0000_0000_0000_0202 let tzs_index = 0x0202 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: tzs_index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(2u8))); // Stellar BRL ZenlinkAsset index = 0x0000_0000_0000_0203 let brl_index = 0x0203 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: brl_index }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Ok(get_stellar_asset(3u8))); } #[test] fn convert_zenlink_lp_token_to_lp_token_currency() { - // Native and XCM(0) LP token Zenlink index = 0x0000_0100_0000_0600 - let native_xcm_lp_token_index = 0x0000_0100_0000_0600 as u64; + // Native and XCM(0) LP token Zenlink index = 0x0000_0100_0000_0300 + let native_xcm_lp_token_index = 0x0000_0100_0000_0300 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: native_xcm_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 0, 0, 1); assert_eq!(currency, Ok(expected_currency)); - // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0600 - let xcm0_xcm1_lp_token_index = 0x0000_0101_0100_0600 as u64; + // XCM(0) and XCM(1) LP token Zenlink index = 0x0000_0101_0100_0300 + let xcm0_xcm1_lp_token_index = 0x0000_0101_0100_0300 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: xcm0_xcm1_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 1); assert_eq!(currency, Ok(expected_currency)); - // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0600 - let xcm0_stellar_native_lp_token_index = 0x0000_0200_0100_0600 as u64; + // XCM(0) and Stellar Native LP Token Zenlink index = 0x0000_0200_0100_0300 + let xcm0_stellar_native_lp_token_index = 0x0000_0200_0100_0300 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: xcm0_stellar_native_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 0, 2); assert_eq!(currency, Ok(expected_currency)); - // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0600 - let xcm0_stellar_usdc_lp_token_index = 0x0000_0201_0100_0600 as u64; + // XCM(0) and Stellar USDC LP Token Zenlink index = 0x0000_0201_0100_0300 + let xcm0_stellar_usdc_lp_token_index = 0x0000_0201_0100_0300 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: xcm0_stellar_usdc_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 1, 1, 2); assert_eq!(currency, Ok(expected_currency)); - // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0600 - let stellar_native_stellar_usdc_lp_token_index = 0x0000_0201_0200_0600 as u64; + // Stellar Native and Stellar USDC LP Token Zenlink index = 0x0000_0201_0200_0300 + let stellar_native_stellar_usdc_lp_token_index = 0x0000_0201_0200_0300 as u64; let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: stellar_native_stellar_usdc_lp_token_index, }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); let expected_currency: CurrencyId = CurrencyId::ZenlinkLPToken(0, 2, 1, 2); assert_eq!(currency, Ok(expected_currency)); } - #[test] + #[test] fn convert_fake_zenlink_native_to_currency_id_error() { // Native ZenlinkAsset index = 0x0000_0000_0000_0000 let fake_zenlink_asset = ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: 0 as u64 }; - let currency: Result = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); + let currency: Result = + zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32); assert_eq!(currency, Err(())); } #[test] fn convert_zenlink_id_to_currency_id_error() { - let fake_zenlink_asset = ZenlinkAssetId { - chain_id: 1000u32, - asset_type: LOCAL, - asset_index: 0u64, - }; + let fake_zenlink_asset = + ZenlinkAssetId { chain_id: 1000u32, asset_type: LOCAL, asset_index: 0u64 }; // We pass a parachain_id different than the asset chain_id assert_eq!(zenlink_id_to_currency_id(fake_zenlink_asset, 1001u32), Err(())); } diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 818fcd9c9..cea923e1d 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -9,12 +9,12 @@ use sp_std::marker::PhantomData; use spacewalk_primitives::{Asset, CurrencyId}; use zenlink_protocol::{ - AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, - NATIVE, + AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, + LOCAL, NATIVE, }; pub type ZenlinkAssetId = zenlink_protocol::AssetId; -use runtime_common::zenlink::*; +use runtime_common::{zenlink, zenlink::*}; parameter_types! { pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); @@ -27,7 +27,7 @@ impl ZenlinkConfig for Runtime { type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; type AssetId = AssetId; - type LpGenerate = PairLpGenerate; + type LpGenerate = SpacewalkPairLPGenerate; type TargetChains = ZenlinkRegisteredParaChains; type SelfParaId = SelfParaId; type WeightInfo = (); @@ -37,12 +37,24 @@ type MultiAssets = ZenlinkMultiAssets(PhantomData); +pub struct SpacewalkPairLPGenerate(PhantomData); +impl GenerateLpAssetId for SpacewalkPairLPGenerate { + fn generate_lp_asset_id( + asset_0: ZenlinkAssetId, + asset_1: ZenlinkAssetId, + ) -> Option { + zenlink::generate_lp_asset_id(asset_0, asset_1, ParachainInfo::parachain_id().into()) + } +} + impl LocalAssetHandler for LocalAssetAdaptor where Local: MultiCurrency, { fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { return TryInto::::try_into(Local::free_balance(currency_id, &who)) .unwrap_or_default() } @@ -50,7 +62,9 @@ where } fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { return TryInto::::try_into(Local::total_issuance(currency_id)) .unwrap_or_default() } @@ -70,7 +84,9 @@ where target: &AccountId, amount: AssetBalance, ) -> DispatchResult { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::transfer( currency_id, &origin, @@ -89,7 +105,9 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::deposit( currency_id, &origin, @@ -109,7 +127,9 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::withdraw( currency_id, &origin, From b58616fb38a94ab4afa23a659e9dfafeed60f729 Mon Sep 17 00:00:00 2001 From: adelarja Date: Tue, 11 Jul 2023 14:37:05 -0300 Subject: [PATCH 26/33] Refactored zenlink stuffs in runtime common. Added zenlink configuration to amplitude. --- runtime/amplitude/src/zenlink.rs | 68 ++++++++++++++++---------------- runtime/foucoco/src/zenlink.rs | 26 ++++++------ 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/runtime/amplitude/src/zenlink.rs b/runtime/amplitude/src/zenlink.rs index 08f61c9a9..7fa9aee30 100644 --- a/runtime/amplitude/src/zenlink.rs +++ b/runtime/amplitude/src/zenlink.rs @@ -6,24 +6,36 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; +use spacewalk_primitives::{CurrencyId}; + use zenlink_protocol::{ - AssetId, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, LOCAL, NATIVE, + AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, }; +pub type ZenlinkAssetId = zenlink_protocol::AssetId; -pub type ZenlinkAssetId = AssetId; +use runtime_common::{zenlink, zenlink::*}; + +pub struct ZenlinkLPGenerate(PhantomData); +impl GenerateLpAssetId for ZenlinkLPGenerate { + fn generate_lp_asset_id( + asset_0: ZenlinkAssetId, + asset_1: ZenlinkAssetId, + ) -> Option { + zenlink::generate_lp_asset_id(asset_0, asset_1, ParachainInfo::parachain_id().into()) + } +} parameter_types! { pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); pub ZenlinkRegisteredParaChains: Vec<(MultiLocation, u128)> = vec![]; } - -impl zenlink_protocol::Config for Runtime { +impl ZenlinkConfig for Runtime { type RuntimeEvent = super::RuntimeEvent; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; type AssetId = AssetId; - type LpGenerate = PairLpGenerate; + type LpGenerate = ZenlinkLPGenerate; type TargetChains = ZenlinkRegisteredParaChains; type SelfParaId = SelfParaId; type WeightInfo = (); @@ -38,7 +50,9 @@ where Local: MultiCurrency, { fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { return TryInto::::try_into(Local::free_balance(currency_id, &who)) .unwrap_or_default() } @@ -46,7 +60,9 @@ where } fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { return TryInto::::try_into(Local::total_issuance(currency_id)) .unwrap_or_default() } @@ -54,7 +70,7 @@ where } fn local_is_exists(asset_id: ZenlinkAssetId) -> bool { - match zenlink_id_to_currency_id(asset_id) { + match zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { Ok(_) => true, Err(_) => false, } @@ -66,7 +82,9 @@ where target: &AccountId, amount: AssetBalance, ) -> DispatchResult { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::transfer( currency_id, &origin, @@ -85,7 +103,9 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::deposit( currency_id, &origin, @@ -105,7 +125,9 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::withdraw( currency_id, &origin, @@ -120,27 +142,3 @@ where Ok(amount) } } - -fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { - let para_chain_id: u32 = ParachainInfo::parachain_id().into(); - if asset_id.chain_id != para_chain_id { - log::error!("Asset Chain Id {} not compatibile with the Parachain Id.", asset_id.chain_id); - return Err(()) - } - - match asset_id.asset_type { - NATIVE => Ok(CurrencyId::Native), - LOCAL => { - let foreign_id = asset_id.asset_index.try_into().map_err(|_| { - log::error!("{} has no Foreign Currency Id match.", asset_id.asset_index); - () - })?; - - Ok(XCM(foreign_id)) - }, - other => { - log::error!("Unsupported asset type index:{other}"); - Err(()) - }, - } -} diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index cea923e1d..7fa9aee30 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -6,28 +6,36 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; -use spacewalk_primitives::{Asset, CurrencyId}; +use spacewalk_primitives::{CurrencyId}; use zenlink_protocol::{ AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, - LOCAL, NATIVE, }; pub type ZenlinkAssetId = zenlink_protocol::AssetId; use runtime_common::{zenlink, zenlink::*}; +pub struct ZenlinkLPGenerate(PhantomData); +impl GenerateLpAssetId for ZenlinkLPGenerate { + fn generate_lp_asset_id( + asset_0: ZenlinkAssetId, + asset_1: ZenlinkAssetId, + ) -> Option { + zenlink::generate_lp_asset_id(asset_0, asset_1, ParachainInfo::parachain_id().into()) + } +} + parameter_types! { pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); pub ZenlinkRegisteredParaChains: Vec<(MultiLocation, u128)> = vec![]; } - impl ZenlinkConfig for Runtime { type RuntimeEvent = super::RuntimeEvent; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; type AssetId = AssetId; - type LpGenerate = SpacewalkPairLPGenerate; + type LpGenerate = ZenlinkLPGenerate; type TargetChains = ZenlinkRegisteredParaChains; type SelfParaId = SelfParaId; type WeightInfo = (); @@ -37,16 +45,6 @@ type MultiAssets = ZenlinkMultiAssets(PhantomData); -pub struct SpacewalkPairLPGenerate(PhantomData); -impl GenerateLpAssetId for SpacewalkPairLPGenerate { - fn generate_lp_asset_id( - asset_0: ZenlinkAssetId, - asset_1: ZenlinkAssetId, - ) -> Option { - zenlink::generate_lp_asset_id(asset_0, asset_1, ParachainInfo::parachain_id().into()) - } -} - impl LocalAssetHandler for LocalAssetAdaptor where Local: MultiCurrency, From 190f2e84af9fb591b1b7e282bff4c55fffb12458 Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 14 Jul 2023 15:15:48 -0300 Subject: [PATCH 27/33] Added zenlink protocol runtime api configuration for pendulum. Signed-off-by: adelarja --- runtime/amplitude/src/zenlink.rs | 2 +- runtime/foucoco/src/zenlink.rs | 2 +- runtime/pendulum/src/zenlink.rs | 47 +++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/runtime/amplitude/src/zenlink.rs b/runtime/amplitude/src/zenlink.rs index 7fa9aee30..141b90c27 100644 --- a/runtime/amplitude/src/zenlink.rs +++ b/runtime/amplitude/src/zenlink.rs @@ -6,7 +6,7 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; -use spacewalk_primitives::{CurrencyId}; +use spacewalk_primitives::CurrencyId; use zenlink_protocol::{ AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, diff --git a/runtime/foucoco/src/zenlink.rs b/runtime/foucoco/src/zenlink.rs index 7fa9aee30..141b90c27 100644 --- a/runtime/foucoco/src/zenlink.rs +++ b/runtime/foucoco/src/zenlink.rs @@ -6,7 +6,7 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; -use spacewalk_primitives::{CurrencyId}; +use spacewalk_primitives::CurrencyId; use zenlink_protocol::{ AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, diff --git a/runtime/pendulum/src/zenlink.rs b/runtime/pendulum/src/zenlink.rs index 69798954d..0d904de86 100644 --- a/runtime/pendulum/src/zenlink.rs +++ b/runtime/pendulum/src/zenlink.rs @@ -7,22 +7,33 @@ use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; use zenlink_protocol::{ - AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, + AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, }; -pub type ZenlinkAssetId = AssetId; +pub type ZenlinkAssetId = zenlink_protocol::AssetId; + +use runtime_common::{zenlink, zenlink::*}; + +pub struct ZenlinkLPGenerate(PhantomData); +impl GenerateLpAssetId for ZenlinkLPGenerate { + fn generate_lp_asset_id( + asset_0: ZenlinkAssetId, + asset_1: ZenlinkAssetId, + ) -> Option { + zenlink::generate_lp_asset_id(asset_0, asset_1, ParachainInfo::parachain_id().into()) + } +} parameter_types! { pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); pub ZenlinkRegisteredParaChains: Vec<(MultiLocation, u128)> = vec![]; } - impl ZenlinkConfig for Runtime { type RuntimeEvent = super::RuntimeEvent; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; type AssetId = AssetId; - type LpGenerate = PairLpGenerate; + type LpGenerate = ZenlinkLPGenerate; type TargetChains = ZenlinkRegisteredParaChains; type SelfParaId = SelfParaId; type WeightInfo = (); @@ -37,7 +48,9 @@ where Local: MultiCurrency, { fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { return TryInto::::try_into(Local::free_balance(currency_id, &who)) .unwrap_or_default() } @@ -45,7 +58,9 @@ where } fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { return TryInto::::try_into(Local::total_issuance(currency_id)) .unwrap_or_default() } @@ -53,8 +68,7 @@ where } fn local_is_exists(asset_id: ZenlinkAssetId) -> bool { - let currency_id: Result = zenlink_id_to_currency_id(asset_id); - match currency_id { + match zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) { Ok(_) => true, Err(_) => false, } @@ -66,7 +80,9 @@ where target: &AccountId, amount: AssetBalance, ) -> DispatchResult { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::transfer( currency_id, &origin, @@ -85,7 +101,9 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::deposit( currency_id, &origin, @@ -105,7 +123,9 @@ where origin: &AccountId, amount: AssetBalance, ) -> Result { - if let Ok(currency_id) = zenlink_id_to_currency_id(asset_id) { + if let Ok(currency_id) = + zenlink_id_to_currency_id(asset_id, ParachainInfo::parachain_id().into()) + { Local::withdraw( currency_id, &origin, @@ -120,8 +140,3 @@ where Ok(amount) } } - -// This will be replaced with PR 241 -pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result { - Ok(CurrencyId::Native) -} From 51ff2d67137774b6b0254da4cd1d950a6befbda4 Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 14 Jul 2023 17:06:31 -0300 Subject: [PATCH 28/33] Fixed primite issue --- runtime/pendulum/src/zenlink.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/pendulum/src/zenlink.rs b/runtime/pendulum/src/zenlink.rs index 0d904de86..7fa9aee30 100644 --- a/runtime/pendulum/src/zenlink.rs +++ b/runtime/pendulum/src/zenlink.rs @@ -6,6 +6,8 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; +use spacewalk_primitives::{CurrencyId}; + use zenlink_protocol::{ AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, }; From 6817a126f210a4b0aa0f0ca6f73370832d8e309b Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 14 Jul 2023 17:07:16 -0300 Subject: [PATCH 29/33] Deleted unnecessary brackets --- runtime/pendulum/src/zenlink.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/pendulum/src/zenlink.rs b/runtime/pendulum/src/zenlink.rs index 7fa9aee30..141b90c27 100644 --- a/runtime/pendulum/src/zenlink.rs +++ b/runtime/pendulum/src/zenlink.rs @@ -6,7 +6,7 @@ use orml_traits::MultiCurrency; use sp_runtime::{DispatchError, DispatchResult}; use sp_std::marker::PhantomData; -use spacewalk_primitives::{CurrencyId}; +use spacewalk_primitives::CurrencyId; use zenlink_protocol::{ AssetId, Config as ZenlinkConfig, GenerateLpAssetId, LocalAssetHandler, ZenlinkMultiAssets, From c57c37c4914d1380620b5ec9190d95caf3d52ec5 Mon Sep 17 00:00:00 2001 From: adelarja Date: Fri, 14 Jul 2023 17:12:16 -0300 Subject: [PATCH 30/33] Updated spacewalk dependencies hash --- node/Cargo.toml | 12 ++++++------ runtime/amplitude/Cargo.toml | 36 ++++++++++++++++++------------------ runtime/common/Cargo.toml | 2 +- runtime/foucoco/Cargo.toml | 36 ++++++++++++++++++------------------ runtime/pendulum/Cargo.toml | 2 +- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index 59f8ee501..79c35930c 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -15,13 +15,13 @@ codec = { package = "parity-scale-codec", version = "3.0.0" } serde = { version = "1.0.145", features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server"] } -module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} # Local amplitude-runtime = {path = "../runtime/amplitude"} diff --git a/runtime/amplitude/Cargo.toml b/runtime/amplitude/Cargo.toml index f55650806..aa7288ec5 100644 --- a/runtime/amplitude/Cargo.toml +++ b/runtime/amplitude/Cargo.toml @@ -26,24 +26,24 @@ smallvec = "1.9.0" runtime-common = { path = "../common", default-features = false } # Custom libraries for Spacewalk -currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } -module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63" } +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3" } # Substrate frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40" } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index b0b63a309..6c8030dd3 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -18,7 +18,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} dia-oracle = { git = "https://github.com/pendulum-chain/oracle-pallet", default-features = false, branch = "polkadot-v0.9.40" } zenlink-protocol = { git = "https://github.com/pendulum-chain/Zenlink-DEX-Module", default-features = false, branch = "polkadot-v0.9.40-protocol" } diff --git a/runtime/foucoco/Cargo.toml b/runtime/foucoco/Cargo.toml index 3db1af6da..ca5f57a8d 100644 --- a/runtime/foucoco/Cargo.toml +++ b/runtime/foucoco/Cargo.toml @@ -26,25 +26,25 @@ smallvec = "1.9.0" runtime-common = { path = "../common", default-features = false } # custom libraries from spacewalk -currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} -module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} -module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "daf395f6201a834629f6abad77e062d8aa554f63"} +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} # Substrate frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40" } diff --git a/runtime/pendulum/Cargo.toml b/runtime/pendulum/Cargo.toml index 51a5f06e2..64b290175 100644 --- a/runtime/pendulum/Cargo.toml +++ b/runtime/pendulum/Cargo.toml @@ -26,7 +26,7 @@ smallvec = "1.9.0" runtime-common = {path = "../common", default-features = false} # Spacewalk libraries -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"} +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"} # Substrate frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40"} From 6cf7d2ecf1a007712b89c33292aa41b199e5dd99 Mon Sep 17 00:00:00 2001 From: Adel Arja Date: Mon, 17 Jul 2023 06:57:21 -0300 Subject: [PATCH 31/33] Added comment with USDC issuer address. Co-authored-by: Marcel Ebert --- runtime/common/src/stellar.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/common/src/stellar.rs b/runtime/common/src/stellar.rs index abd8c5bff..9aa6700b2 100644 --- a/runtime/common/src/stellar.rs +++ b/runtime/common/src/stellar.rs @@ -1,3 +1,4 @@ +// GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN pub const USDC_ISSUER: [u8; 32] = [ 59, 153, 17, 56, 14, 254, 152, 139, 160, 168, 144, 14, 177, 207, 228, 79, 54, 111, 125, 190, 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, From e0717eff04f906abc96a912fc3285dd07bfb6e51 Mon Sep 17 00:00:00 2001 From: Adel Arja Date: Mon, 17 Jul 2023 06:57:44 -0300 Subject: [PATCH 32/33] Added comment with BRL issuer address. Co-authored-by: Marcel Ebert --- runtime/common/src/stellar.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/common/src/stellar.rs b/runtime/common/src/stellar.rs index 9aa6700b2..f458427f9 100644 --- a/runtime/common/src/stellar.rs +++ b/runtime/common/src/stellar.rs @@ -4,6 +4,7 @@ pub const USDC_ISSUER: [u8; 32] = [ 148, 107, 237, 7, 114, 64, 247, 246, 36, 223, 21, 197, ]; +// GDVKY2GU2DRXWTBEYJJWSFXIGBZV6AZNBVVSUHEPZI54LIS6BA7DVVSP pub const BRL_ISSUER: [u8; 32] = [ 234, 172, 104, 212, 208, 227, 123, 76, 36, 194, 83, 105, 22, 232, 48, 115, 95, 3, 45, 13, 107, 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, From 55a8a150248aa413ed109b2a3fc65992c3c4de5b Mon Sep 17 00:00:00 2001 From: Adel Arja Date: Mon, 17 Jul 2023 06:58:15 -0300 Subject: [PATCH 33/33] Added comment with TZS issuer address. Co-authored-by: Marcel Ebert --- runtime/common/src/stellar.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/common/src/stellar.rs b/runtime/common/src/stellar.rs index f458427f9..490576b4b 100644 --- a/runtime/common/src/stellar.rs +++ b/runtime/common/src/stellar.rs @@ -10,6 +10,7 @@ pub const BRL_ISSUER: [u8; 32] = [ 42, 28, 143, 202, 59, 197, 162, 94, 8, 62, 58, ]; +// GA2MSSZKJOU6RNL3EJKH3S5TB5CDYTFQFWRYFGUJVIN5I6AOIRTLUHTO pub const TZS_ISSUER: [u8; 32] = [ 52, 201, 75, 42, 75, 169, 232, 181, 123, 34, 84, 125, 203, 179, 15, 68, 60, 76, 176, 45, 163, 130, 154, 137, 170, 27, 212, 120, 14, 68, 102, 186,