Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Karura integration #139

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ The XCM implemented includes assets transferring between Parachains and Relaycha

* Transfers from Relaychain to Parachain happens with `reserveTransferAssets`.
* XCM teleport and executions are currently disabled.
* Supports PONT and KSM tokens.
* Supports Pontem (PONT), Kusama (KSM), Karura (KAR, KUSD, LKSM) tokens.

**Dev Relaychain**

Expand Down
5 changes: 5 additions & 0 deletions constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ repository = 'https://github.com/pontem-network/pontem/'
version = '3.0.0'

[dependencies]
smallvec = "1.4.0"
primitives = { path = "../primitives", default-features = false }
frame-support = { default-features = false, git = 'http://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.11' }
sp-runtime = { default-features = false, git = 'http://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.11' }

[features]
default = ['std']
std = [
"primitives/std",
"frame-support/std",
"sp-runtime/std",
]
22 changes: 18 additions & 4 deletions constants/src/currency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Currencies constants.
use primitives::Balance;
use primitives::{Balance, currency::CurrencyId};

/// Decimals.
pub const DECIMALS: u32 = 10;
Expand All @@ -10,6 +10,20 @@ pub const UNIT: Balance = PONT;
pub const MILLIUNIT: Balance = UNIT / 1_000;
pub const MICROUNIT: Balance = MILLIUNIT / 1_000;

/// Essential Deposits.
pub const PONT_EXISTENTIAL_DEPOSIT: Balance = 100;
pub const KSM_EXISTENTIAL_DEPOSIT: Balance = 100000;
/// Get existential deposit for currency, in Pontem runtime.
pub fn get_exist_deposit(currency_id: &CurrencyId) -> Balance {
match currency_id {
CurrencyId::PONT => 100,
_ => 100000,
}
}

#[test]
/// Test `get_exist_deposit` func.
fn test_get_exist_deposit() {
assert_eq!(get_exist_deposit(&CurrencyId::PONT), 100);
assert_eq!(get_exist_deposit(&CurrencyId::KSM), 100000);
assert_eq!(get_exist_deposit(&CurrencyId::KAR), 100000);
assert_eq!(get_exist_deposit(&CurrencyId::KUSD), 100000);
assert_eq!(get_exist_deposit(&CurrencyId::LKSM), 100000);
}
3 changes: 3 additions & 0 deletions constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ pub mod time;

/// Module contains currency constants.
pub mod currency;

/// Parachains.
pub mod parachains;
65 changes: 65 additions & 0 deletions constants/src/parachains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/// Karura chain specs.
pub mod karura {
use primitives::currency::CurrencyId;
use smallvec::smallvec;
use sp_runtime::Perbill;
use frame_support::weights::{
constants::{ExtrinsicBaseWeight, WEIGHT_PER_SECOND},
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};

/// Karura chain id.
pub const CHAIN_ID: u32 = 2000;

/// Karura balance type.
pub type KaruraBalance = u128;

/// Get 1 dollar of currency.
pub fn dollar(currency_id: &CurrencyId) -> KaruraBalance {
10u128.saturating_pow(currency_id.decimals() as u32)
}

/// Get 1 cent of currency.
pub fn cent(currency_id: &CurrencyId) -> KaruraBalance {
dollar(currency_id) / 100
}

/// Copy from Acala runtime.
fn base_tx_in_kar() -> KaruraBalance {
cent(&CurrencyId::KAR) / 10
}

pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = KaruraBalance;

fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Karura, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = base_tx_in_kar();
let q = Self::Balance::from(ExtrinsicBaseWeight::get());

smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}

pub fn kar_per_second() -> u128 {
let base_weight = KaruraBalance::from(ExtrinsicBaseWeight::get());
let base_tx_per_second = (WEIGHT_PER_SECOND as u128) / base_weight;
base_tx_per_second * base_tx_in_kar()
}

pub fn ksm_per_second() -> u128 {
kar_per_second() / 50
}

#[test]
fn test_karura_chain_id() {
// Should be always 2000.
assert_eq!(CHAIN_ID, 2000);
}
}
2 changes: 1 addition & 1 deletion node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {

fetch(FetchConfig {
git_repo: "https://github.com/pontem-network/move-stdlib.git",
rev: Some("e9bd26720c06705d2e222833a496fda7c67c8e32"),
rev: Some("c53d57d3993b9ee4b9dc63defc26527bf3942d74"),
path_to_clone: "./move/stdlib",
build_with_dove: true,
})
Expand Down
44 changes: 32 additions & 12 deletions pallets/sp-mvm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ benchmarks! {
VMStorage::<T>::insert(module_access_core(name), module);
}
let caller: T::AccountId = whitelisted_caller();
let module = include_bytes!("../tests/benchmark_assets/artifacts/modules/52_StdImport.mv").to_vec();
let module = include_bytes!("../tests/benchmark_assets/artifacts/modules/56_StdImport.mv").to_vec();
}: publish_module(RawOrigin::Signed(caller), module, 100_000_000)
verify {
assert!(VMStorage::<T>::contains_key(module_access("StdImport")));
Expand Down Expand Up @@ -231,6 +231,10 @@ pub fn stdlib() -> Vec<(&'static str, Vec<u8>)> {
"DualAttestation",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/22_DualAttestation.mv").to_vec()
),
(
"DiemId",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/23_DiemId.mv").to_vec()
),
(
"DesignatedDealer",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/24_DesignatedDealer.mv").to_vec()
Expand All @@ -255,14 +259,14 @@ pub fn stdlib() -> Vec<(&'static str, Vec<u8>)> {
"SharedEd25519PublicKey",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/29_SharedEd25519PublicKey.mv").to_vec()
),
(
"RecoveryAddress",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/30_RecoveryAddress.mv").to_vec()
),
(
"Errors",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/2_Errors.mv").to_vec()
),
(
"RecoveryAddress",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/30_RecoveryAddress.mv").to_vec()
),
(
"AccountAdministrationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/31_AccountAdministrationScripts.mv").to_vec()
Expand Down Expand Up @@ -299,33 +303,49 @@ pub fn stdlib() -> Vec<(&'static str, Vec<u8>)> {
"DiemVersion",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/39_DiemVersion.mv").to_vec()
),
(
"CoreAddresses",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/3_CoreAddresses.mv").to_vec()
),
(
"TransactionFee",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/40_TransactionFee.mv").to_vec()
),
(
"CoreAddresses",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/3_CoreAddresses.mv").to_vec()
"LKSM",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/41_LKSM.mv").to_vec()
),
(
"KUSD",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/42_KUSD.mv").to_vec()
),
(
"KSM",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/43_KSM.mv").to_vec()
),
(
"KAR",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/44_KAR.mv").to_vec()
),
(
"Genesis",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/41_Genesis.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/45_Genesis.mv").to_vec()
),
(
"PaymentScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/42_PaymentScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/46_PaymentScripts.mv").to_vec()
),
(
"SystemAdministrationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/43_SystemAdministrationScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/47_SystemAdministrationScripts.mv").to_vec()
),
(
"TreasuryComplianceScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/44_TreasuryComplianceScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/48_TreasuryComplianceScripts.mv").to_vec()
),
(
"ValidatorAdministrationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/45_ValidatorAdministrationScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/49_ValidatorAdministrationScripts.mv").to_vec()
),
(
"DiemTimestamp",
Expand Down
2 changes: 1 addition & 1 deletion pallets/sp-mvm/tests/assets/build_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rm -rf ./stdlib
git clone https://github.com/pontem-network/move-stdlib.git ./stdlib
pushd ./stdlib
git checkout e9bd26720c06705d2e222833a496fda7c67c8e32
git checkout c53d57d3993b9ee4b9dc63defc26527bf3942d74
dove build --package
popd

Expand Down
2 changes: 1 addition & 1 deletion pallets/sp-mvm/tests/assets/root/Dove.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ account_address = "0x1" # std
# account_address = "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" # Bob

dependencies = [
{ git = "https://github.com/pontem-network/move-stdlib.git", rev = "e9bd26720c06705d2e222833a496fda7c67c8e32" },
{ git = "https://github.com/pontem-network/move-stdlib.git", rev = "c53d57d3993b9ee4b9dc63defc26527bf3942d74" },
]
2 changes: 1 addition & 1 deletion pallets/sp-mvm/tests/assets/user/Dove.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ account_address = "gkNW9pAcCHxZrnoVkhLkEQtsLsW5NWTC75cdAdxAMs9LNYCYg" # Bob
# account_address = "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" # Bob

dependencies = [
{ git = "https://github.com/pontem-network/move-stdlib.git", rev = "e9bd26720c06705d2e222833a496fda7c67c8e32" }
{ git = "https://github.com/pontem-network/move-stdlib.git", rev = "c53d57d3993b9ee4b9dc63defc26527bf3942d74" }
]
2 changes: 1 addition & 1 deletion pallets/sp-mvm/tests/benchmark_assets/Dove.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ dialect = "pont"
dove_version = ">=1.3.3"

dependencies = [
{ git = "https://github.com/pontem-network/move-stdlib.git", rev = "e9bd26720c06705d2e222833a496fda7c67c8e32" }
{ git = "https://github.com/pontem-network/move-stdlib.git", rev = "c53d57d3993b9ee4b9dc63defc26527bf3942d74" }
]
2 changes: 1 addition & 1 deletion pallets/sp-mvm/tests/benchmark_assets/build_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rm -rf ./stdlib
git clone https://github.com/pontem-network/move-stdlib.git ./stdlib
pushd ./stdlib
git checkout e9bd26720c06705d2e222833a496fda7c67c8e32
git checkout c53d57d3993b9ee4b9dc63defc26527bf3942d74
dove build
popd

Expand Down
4 changes: 2 additions & 2 deletions pallets/sp-mvm/tests/common/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub mod modules {
Asset::new("Store", "tests/assets/user/artifacts/modules/2_Store.mv");
pub static EVENT_PROXY: Asset = Asset::new(
"EventProxy",
"tests/assets/user/artifacts/modules/49_EventProxy.mv",
"tests/assets/user/artifacts/modules/52_EventProxy.mv",
);
pub static BANK: Asset =
Asset::new("Bank", "tests/assets/user/artifacts/modules/48_Bank.mv");
Asset::new("Bank", "tests/assets/user/artifacts/modules/51_Bank.mv");
}
}

Expand Down
1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ std = [
"scale-info/std",
"sp-core/std",
"sp-std/std",
"sp-runtime/std",
]
Loading