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

Asset Conversion pallet #12984

Merged
merged 232 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
e8b13b6
Add pallet dex
jsidorenko Aug 2, 2022
afc2836
Fmt
jsidorenko Aug 2, 2022
1205c76
Add RPC endpoint
jsidorenko Aug 2, 2022
ceff65c
Fix RPC
jsidorenko Aug 2, 2022
8a9e330
Fix the build
jsidorenko Aug 2, 2022
cc98057
Some more fixes
jsidorenko Aug 3, 2022
bdbcfec
Add a method to topup pallet's account
jsidorenko Aug 3, 2022
106bfab
Add support for multi-currency into Uniques
jsidorenko Aug 3, 2022
0fd70fb
Fix the build
jsidorenko Aug 3, 2022
b9491ee
Add [transactional] + setup() + fix balances
jsidorenko Aug 3, 2022
f5e71e9
Improve tests
jsidorenko Aug 3, 2022
04ea005
Fix price quotation
jsidorenko Aug 3, 2022
7124090
Code clean up
jsidorenko Aug 3, 2022
e5d8a4d
Validate swaps
jsidorenko Aug 3, 2022
94cabb4
Fmt
jsidorenko Aug 3, 2022
3c8fb00
Update README
jsidorenko Aug 3, 2022
00a09b7
add test
gilescope Nov 8, 2022
99c18ec
mint LP assets in a different instance
gilescope Nov 8, 2022
0883485
remove transactional as now the default
gilescope Nov 9, 2022
ab04ad3
Merge pull request #1 from paritytech/giles-more
Nov 11, 2022
1b28af3
merge master
gilescope Nov 11, 2022
0aabfef
Merge pull request #2 from paritytech/giles-more
Nov 14, 2022
69b21d6
Revert "Merge master"
Nov 14, 2022
b4f6ea9
Merge pull request #4 from jsidorenko/revert-2-giles-more
Nov 14, 2022
2b4696c
Merge branch 'master' into update-master
gilescope Nov 21, 2022
eac18b3
Merge pull request #5 from paritytech/update-master
Nov 22, 2022
f406417
fix tests post merge.
gilescope Nov 22, 2022
a969f85
Merge pull request #6 from paritytech/giles-fix-tests
Nov 22, 2022
ccd34ad
attempt to set create origin
gilescope Nov 22, 2022
7c704ad
Internally allocate lp asset id.
gilescope Nov 23, 2022
279327f
Merge pull request #7 from paritytech/giles-set-create-origin
Nov 23, 2022
6bc91c8
Simplify
gilescope Nov 23, 2022
d73137f
Merge pull request #8 from paritytech/giles-set-create-origin
Nov 24, 2022
0289b6d
Merge remote-tracking branch 'origin/master' into giles-set-create-or…
gilescope Nov 25, 2022
5ebb52d
Bump to be in line
gilescope Nov 25, 2022
7700b25
additional bumps to make compile
gilescope Nov 25, 2022
fabb0fd
fix compile
gilescope Nov 25, 2022
21a2ac1
Merge pull request #9 from paritytech/giles-set-create-origin
Nov 25, 2022
e829cf4
Merge branch 'paritytech:master' into master
jsidorenko Nov 25, 2022
a6618f1
less bounds
gilescope Dec 5, 2022
aadad92
Merge pull request #10 from jsidorenko/giles-less-bounds
Dec 5, 2022
ac650c8
use fungible crates
gilescope Dec 7, 2022
eec3dd5
Merge pull request #11 from jsidorenko/giles-currency-to-fungable
Dec 8, 2022
3872184
multiasset enum
gilescope Dec 10, 2022
97936d6
only allow native currency pairs
gilescope Dec 10, 2022
68251e9
added slippage tests
gilescope Dec 11, 2022
0a17ab5
transfer into separate method
gilescope Dec 12, 2022
6d78fef
Merge pull request #13 from jsidorenko/giles-multi-asset-enum
Dec 12, 2022
f8ee5cc
Add benchmarks + weights
jsidorenko Dec 12, 2022
b6b860d
Typos
jsidorenko Dec 12, 2022
a97e46a
Clean up
jsidorenko Dec 12, 2022
ac091f7
Merge pull request #14 from jsidorenko/js-add-benchmarks
jsidorenko Dec 12, 2022
3cf6239
More tests,
gilescope Dec 12, 2022
236bef4
tighten up naming
gilescope Dec 13, 2022
20ccea2
Merge pull request #15 from jsidorenko/giles-more-tests
Dec 13, 2022
7800d10
Default, zero, square root traits not needed
gilescope Dec 13, 2022
4cebb9b
Merge pull request #16 from jsidorenko/giles-more-tests
Dec 14, 2022
9ec3871
add keep-alive param
gilescope Dec 14, 2022
36f830f
add insufficient liquidity test
gilescope Dec 14, 2022
a482298
Merge pull request #17 from jsidorenko/keep-alive
Dec 15, 2022
5b98910
Fix quote() to support u64
jsidorenko Dec 15, 2022
514332d
Avoid recording balances twice
gilescope Dec 15, 2022
a25f989
cargo fmt
gilescope Dec 15, 2022
1685cfc
Didn't mean to change error type
gilescope Dec 15, 2022
2d29613
temp
gilescope Dec 15, 2022
899045e
Less
gilescope Dec 15, 2022
b11b5f5
Rework get_amount_in/get_amount_out
jsidorenko Dec 15, 2022
abcc619
Convert other places
jsidorenko Dec 15, 2022
2e93e69
Rework the last piece
jsidorenko Dec 15, 2022
7009fc1
Merge pull request #18 from jsidorenko/js-check-u64
jsidorenko Dec 15, 2022
a386c58
Merge branch 'master' into giles-remove-balances
jsidorenko Dec 16, 2022
d6e5ee3
Merge pull request #19 from jsidorenko/giles-remove-balances
Dec 16, 2022
45099c9
Typo
jsidorenko Dec 16, 2022
22dcf91
Fix benchmarks
jsidorenko Dec 16, 2022
38498a9
use hash trait
gilescope Dec 16, 2022
a9a291c
Extract a native asset check into the runtime setting
jsidorenko Dec 16, 2022
34c9adf
Don't set the metadata
jsidorenko Dec 16, 2022
5d959ba
Merge pull request #22 from jsidorenko/js-extract-native-asset-check
jsidorenko Dec 16, 2022
7b0d909
Merge pull request #23 from jsidorenko/js-remove-metadata-creation
jsidorenko Dec 16, 2022
e154075
Merge pull request #21 from jsidorenko/giles-hash-trait
Dec 16, 2022
b4b99b3
Merge pull request #20 from jsidorenko/js-fix-benchmarks
Dec 16, 2022
9c8bd5e
Remove spec file
jsidorenko Dec 16, 2022
bb12ad6
Enable multi-assets swaps by default
jsidorenko Dec 16, 2022
a4704ee
Refactor conversion into u128
jsidorenko Dec 16, 2022
027c7a5
Merge pull request #25 from jsidorenko/js-improve-u128-support
jsidorenko Dec 16, 2022
0c6a515
Merge pull request #24 from jsidorenko/js-enable-multi-assets-swaps
jsidorenko Dec 16, 2022
dbcacff
Add path param to swap_token_for_exact_tokens
jsidorenko Dec 18, 2022
1e5a054
Fix typo + a bit of refactoring
jsidorenko Dec 19, 2022
9df535e
Implement path param for swap_exact_tokens_for_tokens()
jsidorenko Dec 19, 2022
66f27f0
Deref
jsidorenko Dec 19, 2022
f4ef006
Minor fixes
jsidorenko Dec 19, 2022
b7fb31d
Add test with sensible scale values
gilescope Dec 19, 2022
759eb91
Use .windows()
jsidorenko Dec 19, 2022
dbf9f12
Fix benchmarks
jsidorenko Dec 19, 2022
b974f23
update docs
gilescope Dec 19, 2022
c6061b3
Merge pull request #28 from jsidorenko/giles-update-docs
Dec 20, 2022
49ca641
Merge pull request #27 from jsidorenko/add-realistic-test
Dec 20, 2022
fe926c4
Fix everything :)
jsidorenko Dec 20, 2022
72c238a
Merge branch 'master' into js-multi-swaps
jsidorenko Dec 20, 2022
92f5486
Chore
jsidorenko Dec 20, 2022
9cb0779
Revert
jsidorenko Dec 20, 2022
318d488
Merge pull request #26 from jsidorenko/js-multi-swaps
jsidorenko Dec 20, 2022
6958800
Chore
jsidorenko Dec 20, 2022
e79d443
prev way of creating sub accounts lead to collisions
gilescope Dec 20, 2022
b7608cf
Update frame/dex/src/lib.rs
Dec 20, 2022
d9c3d99
Update frame/dex/src/lib.rs
Dec 20, 2022
c1ab888
Merge pull request #29 from jsidorenko/giles-truncated
Dec 20, 2022
09e1dbc
Chore
jsidorenko Dec 20, 2022
15a6969
Fmt fix on Uniques
jsidorenko Dec 20, 2022
a4ac2d4
Merge remote-tracking branch 'jeger/master' into dex-pallet
gilescope Dec 20, 2022
331c4e9
add call_index
gilescope Dec 20, 2022
4e146ca
revert readme changes
gilescope Dec 20, 2022
7a2e142
add cr
gilescope Dec 20, 2022
f984658
revert uniques changes
gilescope Dec 20, 2022
23866c5
reducing noise
gilescope Dec 20, 2022
20f1672
no need for deadline (#12990)
gilescope Dec 21, 2022
d75b442
fix kitchen sink (#12991)
gilescope Dec 21, 2022
d7ad301
add BenchmarkHelper for second instance (#12998)
gilescope Dec 22, 2022
9bd3d21
update mock to latest master
gilescope Dec 22, 2022
97a0992
less indirections (#13012)
gilescope Dec 23, 2022
e8c2c4f
remove dex PR's custom RPC (#13050)
gilescope Jan 3, 2023
5dfcb56
no longer a need to upgrade rpc version (#13053)
gilescope Jan 3, 2023
b00004a
Merge branch 'master' into dex-pallet
gilescope Jan 16, 2023
cd41d6b
add CallbackHadle
gilescope Jan 20, 2023
5a8da1e
quote bugfix (#13191)
gilescope Jan 21, 2023
8db89ab
Merge branch 'master' into dex-pallet
gilescope Jan 22, 2023
9fc0a35
merging in dex specific changes due to pay by dex
gilescope Feb 13, 2023
fed34ba
update lock file
gilescope Feb 13, 2023
1b64115
merging in kitchen sink changes
gilescope Feb 13, 2023
121ee7d
Merge remote-tracking branch 'origin/master' into dex-pallet
Mar 6, 2023
fcbbd34
Merge branch 'master' into dex-pallet
gilescope Mar 9, 2023
81f0e38
Merge remote-tracking branch 'origin/master' into dex-pallet
Mar 16, 2023
8ff6179
Add get_reserves() api method
jsidorenko Mar 17, 2023
3cdc595
Partial updating of the benchmarks
gilescope Mar 20, 2023
ffe2953
Merge branch 'dex-pallet' of github.com:paritytech/substrate into dex…
gilescope Mar 20, 2023
47d3537
Merge branch 'master' into dex-pallet
jsidorenko Mar 21, 2023
bbe81ba
Fix tests
jsidorenko Mar 22, 2023
a1edec0
clippy
jsidorenko Mar 22, 2023
67711a7
Temp fix weights
jsidorenko Mar 22, 2023
63add87
Fix benchmarks
jsidorenko Mar 22, 2023
0c78cfe
Add pool setup fee
jsidorenko Mar 22, 2023
386e424
Money upfront
jsidorenko Mar 22, 2023
80602cc
Address some comments
jsidorenko Mar 22, 2023
458eda8
Use u128 in mock
jsidorenko Mar 23, 2023
f325993
Fix benchmarks
jsidorenko Mar 23, 2023
d84ac9a
Change error message
jsidorenko Mar 24, 2023
3adf116
Update comments
jsidorenko Mar 24, 2023
d06ce8a
Change error names
jsidorenko Mar 24, 2023
437392c
Implement PartialOrd for NativeOrAssetId
jsidorenko Mar 24, 2023
e2e24a2
add note
jsidorenko Mar 24, 2023
923193b
Update errors
jsidorenko Mar 24, 2023
4c7ee70
More tests for assets sorting
jsidorenko Mar 24, 2023
f8b7a85
Merge branch 'master' of https://github.com/paritytech/substrate into…
Mar 24, 2023
c657b58
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_dex
Mar 24, 2023
73daaa2
Change the way we generate pool accounts
jsidorenko Mar 27, 2023
cf0f790
Improve the liquidity removal method
jsidorenko Mar 27, 2023
3023cc3
Extract MintMinLiquidity to config, rework all tests
jsidorenko Mar 29, 2023
9229802
Add comments
jsidorenko Mar 29, 2023
89e1e41
Validate provided amount
jsidorenko Mar 30, 2023
c8c5aa6
Rename to asset-conversion
jsidorenko Mar 30, 2023
ca3b8d6
Validate ED
jsidorenko Mar 30, 2023
6828602
Improve handling the ED related errors
jsidorenko Mar 30, 2023
cfc9b30
typos
jsidorenko Mar 30, 2023
edf4b12
Try to fix benchmarks
jsidorenko Mar 30, 2023
c79eb8d
Merge branch 'master' into dex-pallet
jsidorenko Mar 30, 2023
60e1707
Another try
jsidorenko Mar 30, 2023
852f297
Another day, another try
jsidorenko Mar 31, 2023
74f26e1
Fix benchmarks
jsidorenko Mar 31, 2023
69fcf71
Expose fee related params
jsidorenko Apr 4, 2023
f553104
Validate token's minimal amount the same way as ED
jsidorenko Apr 7, 2023
a93f6d6
fix typo
gilescope Apr 11, 2023
8d48599
Merge branch 'master' into dex-pallet
gilescope Apr 12, 2023
7a1638a
Use longer path for swaps in benchmarks
jsidorenko Apr 18, 2023
c2220b5
Merge branch 'dex-pallet' of https://github.com/paritytech/substrate …
gilescope Apr 19, 2023
305a7eb
need to ref sp_std's vec.
gilescope Apr 19, 2023
732df43
Remove From<u32> requirement when benchmarking
gilescope Apr 19, 2023
bbf7d41
impl BenchmarkHelper for ()
gilescope Apr 20, 2023
fb5a946
only for runtime benchmarks
gilescope Apr 21, 2023
e608d9c
MultiLocation: !MaybeDisplay
gilescope Apr 21, 2023
82f6be6
Update frame/asset-conversion/src/lib.rs
gilescope Apr 21, 2023
ccccaa8
Update frame/asset-conversion/src/lib.rs
gilescope Apr 21, 2023
b4f7a63
Merge branch 'master' into dex-pallet
gilescope Apr 21, 2023
e4e6844
Add documentation links
gilescope Apr 21, 2023
bb84701
add collision test
gilescope Apr 21, 2023
bcd826c
Revert "[Enhancement] Throw an error when there are too many pallets …
gilescope Apr 25, 2023
70bdfae
[Enhancement] Throw an error when there are too many pallets (#13763)
ruseinov Mar 30, 2023
f1efb7d
Merge branch 'master' into dex-pallet
gilescope Apr 25, 2023
a51e6da
add benchmark helper
gilescope Apr 25, 2023
9bcaacf
cargo fmt
gilescope Apr 25, 2023
cdf673a
Fix adding liquidity to non-empty pool
jsidorenko Apr 25, 2023
a2870a7
Fix compilation error
jsidorenko Apr 25, 2023
661075b
Fix params ordering issue
jsidorenko Apr 25, 2023
5a2d97d
additional docs
gilescope Apr 25, 2023
18db17f
The swap path elements should be unique
jsidorenko Apr 25, 2023
17aff58
Fix account collision
gilescope Apr 25, 2023
f263147
Merge branch 'dex-pallet' of https://github.com/paritytech/substrate …
gilescope Apr 25, 2023
fa22694
Validate all the pool in a swap path are unique
jsidorenko Apr 26, 2023
1d60e4e
Merge branch 'master' into dex-pallet
gilescope Apr 26, 2023
c7c9422
Change the way we add liquidity to empty pools
jsidorenko Apr 26, 2023
96f4872
Merge branch 'master' into dex-pallet
gilescope Apr 26, 2023
270647a
Merge branch 'master' into dex-pallet
gilescope Apr 26, 2023
a467107
Improve docs
gilescope Apr 27, 2023
ef01a2b
remove unnessisary Display impl
gilescope Apr 27, 2023
dcee96a
cargo fmt
gilescope Apr 27, 2023
fb52368
remove unused imports
gilescope Apr 27, 2023
68ae5d2
Make api consistent
jsidorenko Apr 27, 2023
c5f8acd
Chore
jsidorenko Apr 27, 2023
c8b7e28
Merge remote-tracking branch 'origin/master' into dex-pallet
May 8, 2023
5f74237
Touch the pool account so it could hold the pair tokens
jsidorenko May 8, 2023
82b925c
Check the balance before touching the pool's account
jsidorenko May 8, 2023
2937574
Introduce liquidity provision fee
jsidorenko May 9, 2023
4004628
Touch the pool acc one more time
jsidorenko May 9, 2023
ffcf6b0
Merge remote-tracking branch 'origin/master' into dex-pallet
May 11, 2023
419b9be
Apply suggestions from code review
jsidorenko May 11, 2023
d9cf0ae
Update frame/asset-conversion/README.md
jsidorenko May 11, 2023
4df34e2
Use ContainsPair instead of the balance checker
jsidorenko May 15, 2023
5456e3f
Merge branch 'master' into dex-pallet
gilescope May 16, 2023
ae6a18c
Remove old Currency trait
jsidorenko May 17, 2023
5c486c1
Add liquidity withdrawal fee
jsidorenko May 22, 2023
4ae0d1b
Update docs
jsidorenko May 22, 2023
9577f67
Use 0 withdrawal fee in mock
jsidorenko May 22, 2023
41b07e7
Rename vars
jsidorenko May 22, 2023
124c84b
Merge branch 'master' into dex-pallet
gilescope May 24, 2023
7ec75e0
Merge branch 'master' into dex-pallet
gilescope May 24, 2023
d9b0296
asset id not clone
gilescope May 24, 2023
6bf0efd
fix: shadow var was being used
gilescope May 24, 2023
12472e1
correct tests
gilescope May 25, 2023
e261f11
fix benches
gilescope May 25, 2023
bbe2de8
Merge branch 'master' into dex-pallet
gilescope May 25, 2023
602c976
merge master
gilescope May 25, 2023
ac1812f
neater
gilescope May 25, 2023
eceafb8
Merge branch 'master' into dex-pallet
gilescope May 25, 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
36 changes: 36 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ members = [
"client/transaction-pool/api",
"client/utils",
"frame/alliance",
"frame/asset-conversion",
"frame/assets",
"frame/atomic-swap",
"frame/aura",
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sc-storage-monitor = { version = "0.1.0", path = "../../../client/storage-monito
frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
frame-system-rpc-runtime-api = { version = "4.0.0-dev", path = "../../../frame/system/rpc/runtime-api" }
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
pallet-asset-conversion = { version = "4.0.0-dev", path = "../../../frame/asset-conversion" }
pallet-assets = { version = "4.0.0-dev", path = "../../../frame/assets/" }
pallet-asset-tx-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment/asset-tx-payment/" }
pallet-im-online = { version = "4.0.0-dev", default-features = false, path = "../../../frame/im-online" }
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ pub fn testnet_genesis(
assets: vec![(9, get_account_id_from_seed::<sr25519::Public>("Alice"), true, 1)],
..Default::default()
},
pool_assets: Default::default(),
transaction_storage: Default::default(),
transaction_payment: Default::default(),
alliance: Default::default(),
Expand Down
7 changes: 7 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ scale-info = { version = "2.5.0", default-features = false, features = ["derive"
static_assertions = "1.1.0"
log = { version = "0.4.17", default-features = false }

# pallet-asset-conversion: turn on "num-traits" feature
primitive-types = { version = "0.12.0", default-features = false, features = ["codec", "scale-info", "num-traits"] }

# primitives
sp-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/authority-discovery" }
sp-consensus-babe = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/consensus/babe" }
Expand Down Expand Up @@ -54,6 +57,7 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
frame-try-runtime = { version = "0.10.0-dev", default-features = false, path = "../../../frame/try-runtime", optional = true }
pallet-alliance = { version = "4.0.0-dev", default-features = false, path = "../../../frame/alliance" }
pallet-asset-conversion = { version = "4.0.0-dev", default-features = false, path = "../../../frame/asset-conversion" }
pallet-asset-rate = { version = "4.0.0-dev", default-features = false, path = "../../../frame/asset-rate" }
pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets" }
pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authority-discovery" }
Expand Down Expand Up @@ -137,6 +141,7 @@ std = [
"frame-system-benchmarking?/std",
"frame-election-provider-support/std",
"sp-authority-discovery/std",
"pallet-asset-conversion/std",
"pallet-assets/std",
"pallet-authority-discovery/std",
"pallet-authorship/std",
Expand Down Expand Up @@ -236,6 +241,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-alliance/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
Expand Down Expand Up @@ -297,6 +303,7 @@ try-runtime = [
"frame-system/try-runtime",
"frame-support/try-runtime",
"pallet-alliance/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets/try-runtime",
"pallet-authority-discovery/try-runtime",
"pallet-authorship/try-runtime",
Expand Down
100 changes: 93 additions & 7 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use frame_election_provider_support::{
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
instances::{Instance1, Instance2},
ord_parameter_types,
pallet_prelude::Get,
parameter_types,
traits::{
Expand All @@ -48,10 +50,11 @@ use frame_support::{
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureRootWithSuccess, EnsureSigned, EnsureWithSuccess,
EnsureRoot, EnsureRootWithSuccess, EnsureSigned, EnsureSignedBy, EnsureWithSuccess,
};
pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter};
use pallet_election_provider_multi_phase::SolutionAccuracyOf;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
Expand All @@ -69,8 +72,8 @@ use sp_runtime::{
curve::PiecewiseLinear,
generic, impl_opaque_keys,
traits::{
self, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor, OpaqueKeys,
SaturatedConversion, StaticLookup,
self, AccountIdConversion, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor,
OpaqueKeys, SaturatedConversion, StaticLookup,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill,
Expand Down Expand Up @@ -482,7 +485,7 @@ impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Fungibles = Assets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto, Instance1>,
CreditToBlockAuthor,
>;
}
Expand Down Expand Up @@ -1473,7 +1476,7 @@ parameter_types! {
pub const MetadataDepositPerByte: Balance = 1 * DOLLARS;
}

impl pallet_assets::Config for Runtime {
impl pallet_assets::Config<Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = u128;
type AssetId = u32;
Expand All @@ -1496,6 +1499,66 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = ();
}

ord_parameter_types! {
pub const AssetConversionOrigin: AccountId = AccountIdConversion::<AccountId>::into_account_truncating(&AssetConversionPalletId::get());
}

impl pallet_assets::Config<Instance2> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = u128;
type AssetId = u32;
type AssetIdParameter = codec::Compact<u32>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type AssetDeposit = AssetDeposit;
type AssetAccountDeposit = ConstU128<DOLLARS>;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = StringLimit;
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
type RemoveItemsLimit = ConstU32<1000>;
type CallbackHandle = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub AllowMultiAssetPools: bool = true;
pub const PoolSetupFee: Balance = 1 * DOLLARS; // should be more or equal to the existential deposit
pub const MintMinLiquidity: Balance = 100; // 100 is good enough when the main currency has 10-12 decimals.
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0); // should be non-zero if AllowMultiAssetPools is true, otherwise can be zero.
}

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type AssetBalance = <Self as pallet_balances::Config>::Balance;
type HigherPrecisionBalance = sp_core::U256;
type Assets = Assets;
type Balance = u128;
type PoolAssets = PoolAssets;
type AssetId = <Self as pallet_assets::Config<Instance1>>::AssetId;
type MultiAssetId = NativeOrAssetId<u32>;
type PoolAssetId = <Self as pallet_assets::Config<Instance2>>::AssetId;
type PalletId = AssetConversionPalletId;
type LPFee = ConstU32<3>; // means 0.3%
type PoolSetupFee = PoolSetupFee;
type PoolSetupFeeReceiver = AssetConversionOrigin;
type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
type WeightInfo = pallet_asset_conversion::weights::SubstrateWeight<Runtime>;
type AllowMultiAssetPools = AllowMultiAssetPools;
type MaxSwapPathLength = ConstU32<4>;
type MintMinLiquidity = MintMinLiquidity;
type MultiAssetIdConverter = NativeOrAssetIdConverter<u32>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

parameter_types! {
pub const QueueCount: u32 = 300;
pub const MaxQueueLen: u32 = 1000;
Expand Down Expand Up @@ -1617,7 +1680,7 @@ impl pallet_nft_fractionalization::Config for Runtime {
type NftCollectionId = <Self as pallet_nfts::Config>::CollectionId;
type NftId = <Self as pallet_nfts::Config>::ItemId;
type AssetBalance = <Self as pallet_balances::Config>::Balance;
type AssetId = <Self as pallet_assets::Config>::AssetId;
type AssetId = <Self as pallet_assets::Config<Instance1>>::AssetId;
type Assets = Assets;
type Nfts = Nfts;
type PalletId = NftFractionalizationPalletId;
Expand Down Expand Up @@ -1838,7 +1901,8 @@ construct_runtime!(
Multisig: pallet_multisig,
Bounties: pallet_bounties,
Tips: pallet_tips,
Assets: pallet_assets,
Assets: pallet_assets::<Instance1>,
PoolAssets: pallet_assets::<Instance2>,
Mmr: pallet_mmr,
Lottery: pallet_lottery,
Nis: pallet_nis,
Expand All @@ -1861,6 +1925,7 @@ construct_runtime!(
NominationPools: pallet_nomination_pools,
RankedPolls: pallet_referenda::<Instance2>,
RankedCollective: pallet_ranked_collective,
AssetConversion: pallet_asset_conversion,
FastUnstake: pallet_fast_unstake,
MessageQueue: pallet_message_queue,
Pov: frame_benchmarking_pallet_pov,
Expand Down Expand Up @@ -1951,6 +2016,7 @@ mod benches {
[pallet_contracts, Contracts]
[pallet_core_fellowship, CoreFellowship]
[pallet_democracy, Democracy]
[pallet_asset_conversion, AssetConversion]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
[pallet_elections_phragmen, Elections]
Expand Down Expand Up @@ -2288,6 +2354,26 @@ impl_runtime_apis! {
}
}

impl pallet_asset_conversion::AssetConversionApi<
Block,
Balance,
u128,
NativeOrAssetId<u32>
> for Runtime
{
fn quote_price_exact_tokens_for_tokens(asset1: NativeOrAssetId<u32>, asset2: NativeOrAssetId<u32>, amount: u128, include_fee: bool) -> Option<Balance> {
AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
}

fn quote_price_tokens_for_exact_tokens(asset1: NativeOrAssetId<u32>, asset2: NativeOrAssetId<u32>, amount: u128, include_fee: bool) -> Option<Balance> {
AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
}

fn get_reserves(asset1: NativeOrAssetId<u32>, asset2: NativeOrAssetId<u32>) -> Option<(Balance, Balance)> {
AssetConversion::get_reserves(&asset1, &asset2).ok()
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
for Runtime
{
Expand Down
1 change: 1 addition & 0 deletions bin/node/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
node-executor = { version = "3.0.0-dev", path = "../executor" }
node-primitives = { version = "2.0.0", path = "../primitives" }
kitchensink-runtime = { version = "3.0.0-dev", path = "../runtime" }
pallet-asset-conversion = { version = "4.0.0-dev", path = "../../../frame/asset-conversion" }
pallet-assets = { version = "4.0.0-dev", path = "../../../frame/assets" }
pallet-asset-tx-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment/asset-tx-payment" }
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
Expand Down
1 change: 1 addition & 0 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
society: SocietyConfig { members: vec![alice(), bob()], pot: 0, max_members: 999 },
vesting: Default::default(),
assets: AssetsConfig { assets: vec![(9, alice(), true, 1)], ..Default::default() },
pool_assets: Default::default(),
transaction_storage: Default::default(),
transaction_payment: Default::default(),
alliance: Default::default(),
Expand Down
52 changes: 52 additions & 0 deletions frame/asset-conversion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "pallet-asset-conversion"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME asset conversion pallet"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-arithmetic = { version = "6.0.0", default-features = false, path = "../../primitives/arithmetic" }

[dev-dependencies]
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
pallet-assets = { version = "4.0.0-dev", path = "../assets" }
primitive-types = { version = "0.12.0", default-features = false, features = ["codec", "scale-info", "num-traits"] }
sp-std = { version = "5.0.0", path = "../../primitives/std" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-io = { version = "7.0.0", path = "../../primitives/io" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-std/std",
"sp-runtime/std",
"sp-arithmetic/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
Loading