Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
302bf39
Implemented initial draft code for the conversion between ZenlinkAsse…
adelarja Jun 14, 2023
9988ad4
added PARA_CHAIN_ID constant
adelarja Jun 14, 2023
d9f5b03
Fixed shifting issue
adelarja Jun 14, 2023
c003c2b
Improved format and added hard-coded values for Stellar assets
adelarja Jun 14, 2023
fe5b292
Added BRL, TZS and USDC issuers
adelarja Jun 15, 2023
94282f4
Added StellarNative
adelarja Jun 15, 2023
81fa633
Added Err(()) return to match statement
adelarja Jun 15, 2023
6f1ff80
Fixed type issues
adelarja Jun 15, 2023
b63df99
Added TryFrom for WrappedCurrency to CurrencyId. Improved format
adelarja Jun 16, 2023
82cb978
changed 'zenlink_id_to_currency_id' function
adelarja Jun 16, 2023
aaa621d
Added unit tests for the conversion functions
adelarja Jun 16, 2023
73c7e81
Abstracted methods into separate file
adelarja Jun 19, 2023
5bf9a43
Changed module
adelarja Jun 19, 2023
a5564d3
Refactored runtime configuration of zenlink
adelarja Jun 19, 2023
19abbde
Improved code format. Added unit tests
adelarja Jun 20, 2023
e573c15
Update Cargo.toml
adelarja Jun 20, 2023
d8c0655
Update Cargo.toml
adelarja Jun 20, 2023
901d3c4
Extended statement to check also the issuer in the match of conversio…
adelarja Jun 21, 2023
2a53682
Merge branch '241-update-spacewalk-dependencies-and-configure-the-lp-…
adelarja Jun 21, 2023
db97794
Renamed test varible and test name.
adelarja Jun 21, 2023
1239e98
Refactored zenlink_id_to_currency_id function. Now it checks that the…
adelarja Jun 21, 2023
c8ce574
Added unit test for Err result when converting between zenlink asset …
adelarja Jun 21, 2023
c34634e
Asset type is checked now. renamed variables
adelarja Jul 6, 2023
7f45510
Added stellar module with issuer definitions.
adelarja Jul 6, 2023
ee098ab
Changed spacewalk dependency commit hash
adelarja Jul 6, 2023
b4733f5
Fixed spacewalk dependencies in node
adelarja Jul 7, 2023
6d3df88
Implemented GenerateLpAssetId to change the generate_lp_asset_id func…
adelarja Jul 10, 2023
b58616f
Refactored zenlink stuffs in runtime common. Added zenlink configurat…
adelarja Jul 11, 2023
8aa58dd
Merge branch 'main' of github.com:pendulum-chain/pendulum into 241-up…
adelarja Jul 14, 2023
190f2e8
Added zenlink protocol runtime api configuration for pendulum.
adelarja Jul 14, 2023
51ff2d6
Fixed primite issue
adelarja Jul 14, 2023
6817a12
Deleted unnecessary brackets
adelarja Jul 14, 2023
c57c37c
Updated spacewalk dependencies hash
adelarja Jul 14, 2023
6cf7d2e
Added comment with USDC issuer address.
adelarja Jul 17, 2023
e0717ef
Added comment with BRL issuer address.
adelarja Jul 17, 2023
55a8a15
Added comment with TZS issuer address.
adelarja Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored zenlink_id_to_currency_id function. Now it checks that the…
… asset chain_id and the parachain_id are the same.
  • Loading branch information
adelarja committed Jun 21, 2023
commit 1239e987503532390712d458fadf52088cf5a26a
28 changes: 16 additions & 12 deletions runtime/common/src/zenlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ fn discriminant(currency: &CurrencyId) -> u8 {
}
}

pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result<CurrencyId, ()> {
pub fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId, parachain_id: u32) -> Result<CurrencyId, ()> {
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;
Expand Down Expand Up @@ -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<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32);
assert_eq!(currency, Ok(CurrencyId::Native));
}

Expand All @@ -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<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32);
assert_eq!(currency, Ok(CurrencyId::XCM(0)));
}

Expand All @@ -138,28 +142,28 @@ mod zenlink_tests {
asset_type: LOCAL,
asset_index: stellar_native_index,
};
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset, 1000u32);
assert_eq!(currency, Ok(get_stellar_asset(3u8)));
}

Expand All @@ -172,7 +176,7 @@ mod zenlink_tests {
asset_type: LOCAL,
asset_index: native_xcm_lp_token_index,
};
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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));

Expand All @@ -183,7 +187,7 @@ mod zenlink_tests {
asset_type: LOCAL,
asset_index: xcm0_xcm1_lp_token_index,
};
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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));

Expand All @@ -194,7 +198,7 @@ mod zenlink_tests {
asset_type: LOCAL,
asset_index: xcm0_stellar_native_lp_token_index,
};
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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));

Expand All @@ -205,7 +209,7 @@ mod zenlink_tests {
asset_type: LOCAL,
asset_index: xcm0_stellar_usdc_lp_token_index,
};
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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));

Expand All @@ -216,7 +220,7 @@ mod zenlink_tests {
asset_type: LOCAL,
asset_index: stellar_native_stellar_usdc_lp_token_index,
};
let currency: Result<CurrencyId, _> = zenlink_id_to_currency_id(fake_zenlink_asset);
let currency: Result<CurrencyId, _> = 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));
}
Expand Down
12 changes: 6 additions & 6 deletions runtime/foucoco/src/zenlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ where
Local: MultiCurrency<AccountId, CurrencyId = CurrencyId>,
{
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::<AssetBalance>::try_into(Local::free_balance(currency_id, &who))
.unwrap_or_default()
}
AssetBalance::default()
}

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::<AssetBalance>::try_into(Local::total_issuance(currency_id))
.unwrap_or_default()
}
AssetBalance::default()
}

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,
}
Expand All @@ -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,
Expand All @@ -89,7 +89,7 @@ where
origin: &AccountId,
amount: AssetBalance,
) -> Result<AssetBalance, DispatchError> {
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,
Expand All @@ -109,7 +109,7 @@ where
origin: &AccountId,
amount: AssetBalance,
) -> Result<AssetBalance, DispatchError> {
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,
Expand Down