Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

241 update spacewalk dependencies and configure the lp token for use with the zenlink pallet #246

Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"}
module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"}
module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"}
module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"}
module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"}
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 = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae"}
spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", rev = "ae95aa32f3cff47c5ff26d27af81540569bf81d3"}

# Local
amplitude-runtime = {path = "../runtime/amplitude"}
Expand Down
36 changes: 18 additions & 18 deletions runtime/amplitude/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
reward = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
replace = { 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 = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "06873f16c4a7ab884e4759d98b7b86c712e0c0ae" }
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" }
Expand Down
68 changes: 33 additions & 35 deletions runtime/amplitude/src/zenlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(PhantomData<T>);
impl<T: ZenlinkConfig> GenerateLpAssetId<ZenlinkAssetId> for ZenlinkLPGenerate<T> {
fn generate_lp_asset_id(
asset_0: ZenlinkAssetId,
asset_1: ZenlinkAssetId,
) -> Option<ZenlinkAssetId> {
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<Self>;
type LpGenerate = ZenlinkLPGenerate<Self>;
type TargetChains = ZenlinkRegisteredParaChains;
type SelfParaId = SelfParaId;
type WeightInfo = ();
Expand All @@ -38,23 +50,27 @@ 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 @@ -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,
Expand All @@ -85,7 +103,9 @@ 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 @@ -105,7 +125,9 @@ 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 All @@ -120,27 +142,3 @@ where
Ok(amount)
}
}

fn zenlink_id_to_currency_id(asset_id: ZenlinkAssetId) -> Result<CurrencyId, ()> {
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(())
},
}
}
5 changes: 4 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +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" }
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"}
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" }

[features]
default = [
Expand All @@ -33,6 +35,7 @@ std = [
"parity-scale-codec/std",
"scale-info/std",
"dia-oracle/std",
"zenlink-protocol/std",
]

runtime-benchmarks = [
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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.
pub type Signature = MultiSignature;
Expand Down
17 changes: 17 additions & 0 deletions runtime/common/src/stellar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN
pub const USDC_ISSUER: [u8; 32] = [
adelarja marked this conversation as resolved.
Show resolved Hide resolved
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,
];

// GDVKY2GU2DRXWTBEYJJWSFXIGBZV6AZNBVVSUHEPZI54LIS6BA7DVVSP
pub const BRL_ISSUER: [u8; 32] = [
adelarja marked this conversation as resolved.
Show resolved Hide resolved
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,
];

// GA2MSSZKJOU6RNL3EJKH3S5TB5CDYTFQFWRYFGUJVIN5I6AOIRTLUHTO
pub const TZS_ISSUER: [u8; 32] = [
adelarja marked this conversation as resolved.
Show resolved Hide resolved
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,
];
Loading