diff --git a/.github/workflows/integration_test_manta.yml b/.github/workflows/integration_test_manta.yml index d03f069b8..1cb44f56d 100644 --- a/.github/workflows/integration_test_manta.yml +++ b/.github/workflows/integration_test_manta.yml @@ -91,7 +91,7 @@ jobs: if: contains(github.event.pull_request.labels.*.name, 'A-manta') needs: [build-node-current] runs-on: runtime-integration-test - timeout-minutes: 240 + timeout-minutes: 420 container: image: ubuntu:20.04 strategy: diff --git a/.github/workflows/run_linters.yml b/.github/workflows/run_linters.yml index f31a36fd3..9664c5316 100644 --- a/.github/workflows/run_linters.yml +++ b/.github/workflows/run_linters.yml @@ -53,9 +53,9 @@ jobs: protoc --version curl -s https://sh.rustup.rs -sSf | sh -s -- -y source ${HOME}/.cargo/env - rustup toolchain install nightly-2023-03-13 - rustup default nightly-2023-03-13 - cargo install taplo-cli + rustup toolchain install nightly-2023-03-03 + rustup default nightly-2023-03-03 + cargo install taplo-cli --locked - name: cache cargo uses: Swatinem/rust-cache@v2 - name: Check Formatting diff --git a/Cargo.lock b/Cargo.lock index f48c82e40..43df6d392 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6387,7 +6387,7 @@ dependencies = [ [[package]] name = "orml-traits" version = "0.4.1-dev" -source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#ed87ba5bb12c756b3973b3f59a430bab22fc0cc9" +source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#9a1b0f1cf1835225b638311971eba5f30a1187c8" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -6405,7 +6405,7 @@ dependencies = [ [[package]] name = "orml-utilities" version = "0.4.1-dev" -source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#ed87ba5bb12c756b3973b3f59a430bab22fc0cc9" +source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#9a1b0f1cf1835225b638311971eba5f30a1187c8" dependencies = [ "frame-support", "parity-scale-codec", @@ -6419,7 +6419,7 @@ dependencies = [ [[package]] name = "orml-xcm-support" version = "0.4.1-dev" -source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#ed87ba5bb12c756b3973b3f59a430bab22fc0cc9" +source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#9a1b0f1cf1835225b638311971eba5f30a1187c8" dependencies = [ "frame-support", "orml-traits", @@ -6433,7 +6433,7 @@ dependencies = [ [[package]] name = "orml-xtokens" version = "0.4.1-dev" -source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#ed87ba5bb12c756b3973b3f59a430bab22fc0cc9" +source = "git+https://github.com/manta-network/open-runtime-module-library.git?branch=polkadot-v0.9.37#9a1b0f1cf1835225b638311971eba5f30a1187c8" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -15010,7 +15010,7 @@ dependencies = [ [[package]] name = "zenlink-protocol" version = "0.4.4" -source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#c2acc36bea02e6c2aa38f3b290e255dfd5c164dd" +source = "git+https://github.com/manta-network/Zenlink?branch=ghzlatarev/v0937#c581a0b7a1aa38451465bbb4ff82eb93f05348f2" dependencies = [ "frame-benchmarking", "frame-support", @@ -15030,7 +15030,7 @@ dependencies = [ [[package]] name = "zenlink-protocol-rpc" version = "0.4.4" -source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#c2acc36bea02e6c2aa38f3b290e255dfd5c164dd" +source = "git+https://github.com/manta-network/Zenlink?branch=ghzlatarev/v0937#c581a0b7a1aa38451465bbb4ff82eb93f05348f2" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -15045,7 +15045,7 @@ dependencies = [ [[package]] name = "zenlink-protocol-runtime-api" version = "0.4.4" -source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#c2acc36bea02e6c2aa38f3b290e255dfd5c164dd" +source = "git+https://github.com/manta-network/Zenlink?branch=ghzlatarev/v0937#c581a0b7a1aa38451465bbb4ff82eb93f05348f2" dependencies = [ "parity-scale-codec", "sp-api", diff --git a/node/Cargo.toml b/node/Cargo.toml index 52ee47a1c..7d9d511bb 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -38,9 +38,9 @@ sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate.git", pallet-farming-rpc-api = { path = "../pallets/farming/rpc" } pallet-farming-rpc-runtime-api = { path = "../pallets/farming/rpc/runtime-api" } -zenlink-protocol = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37" } -zenlink-protocol-rpc = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37" } -zenlink-protocol-runtime-api = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37" } +zenlink-protocol = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937" } +zenlink-protocol-rpc = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937" } +zenlink-protocol-runtime-api = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937" } # Substrate client dependencies sc-basic-authorship = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.37" } diff --git a/pallets/asset-manager/Cargo.toml b/pallets/asset-manager/Cargo.toml index a9be6f607..2f1e516f2 100644 --- a/pallets/asset-manager/Cargo.toml +++ b/pallets/asset-manager/Cargo.toml @@ -21,7 +21,7 @@ sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkad xcm = { git = "https://github.com/paritytech/polkadot.git", default-features = false, branch = "release-v0.9.37" } # 3rd party dependencies -orml-traits = { git = "https://github.com/manta-network/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.37" } +orml-traits = { git = "https://github.com/manta-network/open-runtime-module-library.git", branch = "polkadot-v0.9.37", default-features = false } [dev-dependencies] pallet-assets = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" } diff --git a/runtime/calamari/Cargo.toml b/runtime/calamari/Cargo.toml index d6cf61286..f4caac5b5 100644 --- a/runtime/calamari/Cargo.toml +++ b/runtime/calamari/Cargo.toml @@ -107,11 +107,11 @@ runtime-common = { path = '../common', default-features = false } session-key-primitives = { path = '../../primitives/session-keys', default-features = false } # Third party (vendored) dependencies -orml-traits = { git = 'https://github.com/manta-network/open-runtime-module-library.git', default-features = false, branch = "polkadot-v0.9.37" } -orml-xtokens = { git = 'https://github.com/manta-network/open-runtime-module-library.git', default-features = false, branch = "polkadot-v0.9.37" } +orml-traits = { git = 'https://github.com/manta-network/open-runtime-module-library.git', branch = "polkadot-v0.9.37", default-features = false } +orml-xtokens = { git = 'https://github.com/manta-network/open-runtime-module-library.git', branch = "polkadot-v0.9.37", default-features = false } -zenlink-protocol = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37", default-features = false } -zenlink-protocol-runtime-api = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37", default-features = false } +zenlink-protocol = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937", default-features = false } +zenlink-protocol-runtime-api = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937", default-features = false } [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] diff --git a/runtime/calamari/src/diff_tx_fees.rs b/runtime/calamari/src/diff_tx_fees.rs index 86cc09aeb..e75f7de79 100644 --- a/runtime/calamari/src/diff_tx_fees.rs +++ b/runtime/calamari/src/diff_tx_fees.rs @@ -2923,7 +2923,7 @@ fn calculate_all_current_extrinsic_tx_fee() -> ( use zenlink_protocol::AssetId as ZenlinkAssetId; assert_eq!( crate::RuntimeCall::get_call_names("ZenlinkProtocol").len(), - 16, + 17, "Please update new extrinsic here." ); // set_fee_receiver @@ -3167,6 +3167,20 @@ fn calculate_all_current_extrinsic_tx_fee() -> ( dispatch_info, call_len, )); + + // set_native_swap_fee_factor + let call = crate::RuntimeCall::ZenlinkProtocol( + zenlink_protocol::Call::set_native_swap_fee_factor { + native_swap_fees_factor: 200u128, + }, + ); + let (dispatch_info, call_len) = get_call_details(&call); + calamari_runtime_calls.push(( + "zenlink_protocol", + "set_native_swap_fee_factor", + dispatch_info, + call_len, + )); } (calamari_runtime_calls, t) diff --git a/runtime/calamari/src/zenlink.rs b/runtime/calamari/src/zenlink.rs index d6f80977f..5824dac26 100644 --- a/runtime/calamari/src/zenlink.rs +++ b/runtime/calamari/src/zenlink.rs @@ -30,6 +30,7 @@ use zenlink_protocol::{ // Normal Coin AMM parameter_types! { pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); + pub const NativeSwapFeesPotId: PalletId = PalletId(*b"/swappot"); pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); pub MantaNativeAssetId: CalamariAssetId = 1; pub ZenlinkNativeAssetId: u64 = 0; @@ -41,6 +42,7 @@ impl zenlink_protocol::Config for Runtime { type RuntimeEvent = RuntimeEvent; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; + type NativeSwapFeesPotId = NativeSwapFeesPotId; type SelfParaId = SelfParaId; type AssetId = ZenlinkAssetId; #[cfg(not(feature = "runtime-benchmarks"))] diff --git a/runtime/manta/Cargo.toml b/runtime/manta/Cargo.toml index 0b88d3b3f..576f2380a 100644 --- a/runtime/manta/Cargo.toml +++ b/runtime/manta/Cargo.toml @@ -85,11 +85,11 @@ xcm-builder = { git = 'https://github.com/paritytech/polkadot.git', default-feat xcm-executor = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.37" } # Third party (vendored) dependencies -orml-traits = { git = 'https://github.com/manta-network/open-runtime-module-library.git', default-features = false, branch = "polkadot-v0.9.37" } -orml-xtokens = { git = 'https://github.com/manta-network/open-runtime-module-library.git', default-features = false, branch = "polkadot-v0.9.37" } +orml-traits = { git = 'https://github.com/manta-network/open-runtime-module-library.git', branch = "polkadot-v0.9.37", default-features = false } +orml-xtokens = { git = 'https://github.com/manta-network/open-runtime-module-library.git', branch = "polkadot-v0.9.37", default-features = false } -zenlink-protocol = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37", default-features = false } -zenlink-protocol-runtime-api = { git = 'https://github.com/manta-network/Zenlink', branch = "polkadot-v0.9.37", default-features = false } +zenlink-protocol = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937", default-features = false } +zenlink-protocol-runtime-api = { git = 'https://github.com/manta-network/Zenlink', branch = "ghzlatarev/v0937", default-features = false } # Self dependencies manta-collator-selection = { path = '../../pallets/collator-selection', default-features = false } diff --git a/runtime/manta/src/diff_tx_fees.rs b/runtime/manta/src/diff_tx_fees.rs index 9a97ebbc7..8c9f9b4aa 100644 --- a/runtime/manta/src/diff_tx_fees.rs +++ b/runtime/manta/src/diff_tx_fees.rs @@ -2910,7 +2910,7 @@ fn calculate_all_current_extrinsic_tx_fee() -> ( use zenlink_protocol::AssetId as ZenlinkAssetId; assert_eq!( crate::RuntimeCall::get_call_names("ZenlinkProtocol").len(), - 16, + 17, "Please update new extrinsic here." ); // set_fee_receiver @@ -3154,6 +3154,20 @@ fn calculate_all_current_extrinsic_tx_fee() -> ( dispatch_info, call_len, )); + + // set_native_swap_fee_factor + let call = crate::RuntimeCall::ZenlinkProtocol( + zenlink_protocol::Call::set_native_swap_fee_factor { + native_swap_fees_factor: 200u128, + }, + ); + let (dispatch_info, call_len) = get_call_details(&call); + calamari_runtime_calls.push(( + "zenlink_protocol", + "set_native_swap_fee_factor", + dispatch_info, + call_len, + )); } (calamari_runtime_calls, t) diff --git a/runtime/manta/src/zenlink.rs b/runtime/manta/src/zenlink.rs index b59065d1a..229180169 100644 --- a/runtime/manta/src/zenlink.rs +++ b/runtime/manta/src/zenlink.rs @@ -30,6 +30,7 @@ use zenlink_protocol::{ // Normal Coin AMM parameter_types! { pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); + pub const NativeSwapFeesPotId: PalletId = PalletId(*b"/swappot"); pub SelfParaId: u32 = ParachainInfo::parachain_id().into(); pub MantaNativeAssetId: MantaAssetId = 1; pub ZenlinkNativeAssetId: u64 = 0; @@ -41,6 +42,7 @@ impl zenlink_protocol::Config for Runtime { type RuntimeEvent = RuntimeEvent; type MultiAssetsHandler = MultiAssets; type PalletId = ZenlinkPalletId; + type NativeSwapFeesPotId = NativeSwapFeesPotId; type SelfParaId = SelfParaId; type AssetId = ZenlinkAssetId; #[cfg(not(feature = "runtime-benchmarks"))] diff --git a/tests/constants.ts b/tests/constants.ts index 67ad95a23..1a89c5b86 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -2,6 +2,8 @@ import {BN} from "@polkadot/util"; export const MANTA_1B = "1000000000000000000000000000"; export const MANTA_1K = new BN("1000000000000000000000"); +export const MANTA_1M = new BN("1000000000000000000000000"); +export const MANTA_10M = new BN("10000000000000000000000000"); export const LP_1K = "1000000000000000"; export const LP_2K = "2000000000000000"; export const USDT_10M = new BN("10000000000000"); @@ -89,4 +91,15 @@ export const LP_USDT_USDC_METADATA = { }, minBalance: 1, isSufficient: true +}; + +export const LP_NATIVE_USDT_METADATA = { + metadata: { + name: "LP-NATIVE-USDT", + symbol: "LP", + decimals: 12, + isFrozen: false + }, + minBalance: 1, + isSufficient: true }; \ No newline at end of file diff --git a/tests/tests/test-dex.ts b/tests/tests/test-dex.ts index 0cdacdca3..73cc4aa5c 100644 --- a/tests/tests/test-dex.ts +++ b/tests/tests/test-dex.ts @@ -4,7 +4,8 @@ import {describeWithManta, executeTx, remark} from "./util"; import '@polkadot/api-augment'; import { LP_1K, LP_2K, - LP_USDT_USDC_METADATA, MANTA_1K, USDC_10M, USDC_20M, + LP_USDT_USDC_METADATA, LP_NATIVE_USDT_METADATA, + MANTA_1K, MANTA_1M, MANTA_10M, USDC_10M, USDC_20M, USDC_LOCATION, USDC_METADATA, USDT_10M, USDT_20M, @@ -12,6 +13,7 @@ import { USDT_METADATA } from "../constants"; import {BN} from "@polkadot/util"; +import { delay } from "../test-util"; describeWithManta("Manta RPC (Dex)", (context) => { step("dex add liquidity should work", async function () { @@ -81,5 +83,29 @@ describeWithManta("Manta RPC (Dex)", (context) => { state = await api.query.assets.account(10, alice); expect(JSON.parse(JSON.stringify(state))).to.equal(null); + + let fees_factor = 200; // 0.5% + callData = api.tx.zenlinkProtocol.setNativeSwapFeeFactor(fees_factor); + await executeTx(context, callData, true); + + callData = api.tx.assetManager.registerLpAsset(1, 8, LP_NATIVE_USDT_METADATA); + await executeTx(context, callData, true); + + await new Promise((res) => setTimeout(res, 2000)); + + callData = api.tx.zenlinkProtocol.createPair([parachainId,0,0], [parachainId,2,8]); + await executeTx(context, callData, true); + + callData = api.tx.zenlinkProtocol.addLiquidity([parachainId,0,0], [parachainId,2,8], + MANTA_10M, USDT_10M, MANTA_10M, USDT_10M, 1000); + await executeTx(context, callData); + + callData = api.tx.zenlinkProtocol.swapExactAssetsForAssets(MANTA_1M,100,[[parachainId,0,0],[parachainId,2,8]],alice,1000); + await executeTx(context, callData); + + const expectedSwapFee = new BN("5000000000000000000000"); + const swapFeesBalance = (await api.query.system.account("dfZ2W8UP6LNgBri4nYSZaXXLUpXbvZM6KhpxPQnFJiKkdVvZi")).data.free.toString(); + console.log("Swap fees pot balance: ", swapFeesBalance); + expect(swapFeesBalance).to.equal(expectedSwapFee.toString()) }); }); \ No newline at end of file