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

feat!: Set Transaction Fee Asset on New Account #476

Merged
merged 22 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be45ed3
set fee currency on new account (and remove on account deletion)
apopiak Jun 7, 2022
4e5d889
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
apopiak Jun 7, 2022
fd374df
fix compile issues (warehouse deps, testing runtime etc.)
apopiak Jun 7, 2022
ef137eb
add integration test for automatic fee currency
apopiak Jun 7, 2022
b2e3071
add integration test for automatic fee currency on xcm transfer
apopiak Jun 7, 2022
1c104df
formatting
apopiak Jun 7, 2022
f844b7e
add use for basilisk_runtime types
apopiak Jun 10, 2022
fd2f2cb
bump spec_version
apopiak Jun 10, 2022
1ab3526
Merge branch 'master' into apopiak/set-tx-fee-asset-on-new-account
apopiak Jun 10, 2022
22498c6
fix whitespace
apopiak Jun 10, 2022
a0ae425
update orml-tokens weights
enthusiastmartin Jun 11, 2022
21b7c2b
bump spec_version
apopiak Jun 13, 2022
caf3389
point warehouse pallets to specific revision
apopiak Jun 14, 2022
6d83043
bump spec_version
apopiak Jun 14, 2022
62c51b2
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
apopiak Jun 14, 2022
161886c
integrate new multi tx payment pallet (fee receiver etc.)
apopiak Jun 14, 2022
dd12d78
bump spec_version
apopiak Jun 14, 2022
e1ce54b
Merge branch 'master' into apopiak/set-tx-fee-asset-on-new-account
enthusiastmartin Jun 16, 2022
981e3f4
bump pallet versions due to orml-token update
enthusiastmartin Jun 16, 2022
052ed50
bump versions - again
enthusiastmartin Jun 16, 2022
0ebdb1b
update lock file
enthusiastmartin Jun 16, 2022
e18d351
Merge branch 'master' into apopiak/set-tx-fee-asset-on-new-account
enthusiastmartin Jun 16, 2022
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
40 changes: 20 additions & 20 deletions Cargo.lock

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

22 changes: 17 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,20 @@ cumulus-relay-chain-interface = { git = "https://github.com/paritytech//cumulus"
cumulus-relay-chain-local = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" }

[patch."https://github.com/galacticcouncil/warehouse"]
pallet-price-oracle = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1"}
pallet-relaychain-info = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1"}
pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1"}
pallet-asset-registry= { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1"}
hydradx-traits = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1"}
pallet-price-oracle = { git = "https://github.com/galacticcouncil//warehouse", branch = "apopiak/set-tx-fee-asset-on-new-account"}
pallet-relaychain-info = { git = "https://github.com/galacticcouncil//warehouse", branch = "apopiak/set-tx-fee-asset-on-new-account"}
pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil//warehouse", branch = "apopiak/set-tx-fee-asset-on-new-account"}
pallet-asset-registry= { git = "https://github.com/galacticcouncil//warehouse", branch = "apopiak/set-tx-fee-asset-on-new-account"}
hydradx-traits = { git = "https://github.com/galacticcouncil//warehouse", branch = "apopiak/set-tx-fee-asset-on-new-account"}
apopiak marked this conversation as resolved.
Show resolved Hide resolved

[patch."https://github.com/open-web3-stack/open-runtime-module-library"]
orml-currencies = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-tokens = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-traits = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-vesting = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-benchmarking = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17", optional = true }
orml-xtokens = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-xcm-support = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-unknown-tokens = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-xcm = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
orml-utilities = { git = "https://github.com/apopiak/open-runtime-module-library", branch = "apopiak/on-new-account-9-17" }
62 changes: 62 additions & 0 deletions integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ fn transfer_from_hydra() {
);
});
}

#[test]
fn transfer_insufficient_amount_should_fail() {
TestNet::reset();
Expand Down Expand Up @@ -182,3 +183,64 @@ fn transfer_insufficient_amount_should_fail() {
);
});
}

#[test]
fn fee_currency_set_on_xcm_transfer() {
TestNet::reset();

const HITCHHIKER: [u8; 32] = [42u8; 32];

let transfer_amount = 100 * BSX;

Basilisk::execute_with(|| {
assert_ok!(basilisk_runtime::AssetRegistry::set_location(
basilisk_runtime::Origin::root(),
1,
basilisk_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(3000), GeneralIndex(0))))
));

// fee currency is not set before XCM transfer
assert_eq!(
basilisk_runtime::MultiTransactionPayment::get_currency(&AccountId::from(HITCHHIKER)),
None
);
});

Hydra::execute_with(|| {
assert_ok!(basilisk_runtime::XTokens::transfer(
basilisk_runtime::Origin::signed(ALICE.into()),
0,
transfer_amount,
Box::new(
MultiLocation::new(
1,
X2(
Junction::Parachain(2000),
Junction::AccountId32 {
id: HITCHHIKER,
network: NetworkId::Any,
}
)
)
.into()
),
399_600_000_000
));
assert_eq!(
basilisk_runtime::Balances::free_balance(&AccountId::from(ALICE)),
200 * BSX - transfer_amount
);
});

Basilisk::execute_with(|| {
assert_eq!(
basilisk_runtime::Tokens::free_balance(1, &AccountId::from(HITCHHIKER)),
transfer_amount
);
// fee currency is set after XCM transfer
assert_eq!(
basilisk_runtime::MultiTransactionPayment::get_currency(&AccountId::from(HITCHHIKER)),
Some(1)
);
});
}
66 changes: 58 additions & 8 deletions integration-tests/src/non_native_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ fn non_native_fee_payment_works() {
assert_eq!(dave_balance, bob_balance + expected_diff);

expect_basilisk_events(vec![
pallet_transaction_multi_payment::Event::FeeWithdrawn(
DAVE.into(),
1,
462_676_500_000,
265_222_898_276,
FALLBACK.into(),
)
pallet_transaction_multi_payment::Event::FeeWithdrawn {
account_id: DAVE.into(),
asset_id: 1,
native_fee_amount: 462_676_500_000,
non_native_fee_amount: 265_222_898_276,
destination_account_id: FALLBACK.into(),
}
.into(),
pallet_transaction_multi_payment::Event::CurrencySet {
account_id: DAVE.into(),
asset_id: 1,
}
.into(),
pallet_transaction_multi_payment::Event::CurrencySet(DAVE.into(), 1).into(),
]);

basilisk_run_to_block(11);
Expand All @@ -140,3 +144,49 @@ fn non_native_fee_payment_works() {
);
});
}

#[test]
fn fee_currency_on_account_lifecycle() {
TestNet::reset();

const HITCHHIKER: [u8; 32] = [42u8; 32];

Basilisk::execute_with(|| {
use basilisk_runtime::{Currencies, MultiTransactionPayment, Origin, Tokens};

assert_eq!(
MultiTransactionPayment::get_currency(&AccountId::from(HITCHHIKER)),
None
);

// ------------ set on create ------------
assert_ok!(Currencies::transfer(
Origin::signed(BOB.into()),
HITCHHIKER.into(),
1,
50_000_000_000_000,
));

assert_eq!(
Tokens::free_balance(1, &AccountId::from(HITCHHIKER)),
50_000_000_000_000
);
assert_eq!(
MultiTransactionPayment::get_currency(&AccountId::from(HITCHHIKER)),
Some(1)
);

// ------------ remove on delete ------------
assert_ok!(Tokens::transfer_all(
Origin::signed(HITCHHIKER.into()),
BOB.into(),
1,
false,
));

assert_eq!(
MultiTransactionPayment::get_currency(&AccountId::from(HITCHHIKER)),
None
);
});
}
2 changes: 2 additions & 0 deletions pallets/duster/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl orml_tokens::Config for Test {
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = Nothing;
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}

impl orml_currencies::Config for Test {
Expand Down
2 changes: 1 addition & 1 deletion pallets/exchange/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-li
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "aac79b3b31953381669a2ffa9b3e9bfe48e87f38", default-features = false }

# HydraDX dependencies
pallet-asset-registry = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
hydra-dx-math = { default-features = false, version = "4.1.1" }

Expand Down
2 changes: 1 addition & 1 deletion pallets/exchange/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-li
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "aac79b3b31953381669a2ffa9b3e9bfe48e87f38", default-features = false }

# HydraDX dependencies
pallet-asset-registry = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }

# Substrate dependencies
Expand Down
2 changes: 2 additions & 0 deletions pallets/exchange/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ impl orml_tokens::Config for Test {
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = Everything;
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}

pub struct AssetPairAccountIdTest();
Expand Down
2 changes: 2 additions & 0 deletions pallets/exchange/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl orml_tokens::Config for Test {
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = Nothing;
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}

pub struct AssetPairAccountIdTest();
Expand Down
2 changes: 2 additions & 0 deletions pallets/lbp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl orml_tokens::Config for Test {
type OnDust = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = Nothing;
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}

pub struct AssetPairAccountIdTest();
Expand Down
2 changes: 1 addition & 1 deletion pallets/liquidity-mining/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pallet-liquidity-mining = { path = "../../liquidity-mining", default-features =
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "aac79b3b31953381669a2ffa9b3e9bfe48e87f38", default-features = false }

# HydraDX dependencies
pallet-asset-registry = { git = "https://github.com/galacticcouncil//warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }
hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev="e428fd81f84781c4508df72f095e7bed6bb58ea1", default-features = false }

primitives = { path = "../../../primitives", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions pallets/liquidity-mining/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ impl orml_tokens::Config for Test {
type OnDust = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = Nothing;
type OnNewTokenAccount = ();
type OnKilledTokenAccount = ();
}

pub struct ExtBuilder {
Expand Down
Loading