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

Dex offchain rebalance swap #2219

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

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

15 changes: 15 additions & 0 deletions modules/aggregated-dex/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ ord_parameter_types! {

parameter_types! {
pub const DEXPalletId: PalletId = PalletId(*b"aca/dexm");
pub const TreasuryPalletId: PalletId = PalletId(*b"aca/trea");
pub const GetExchangeFee: (u32, u32) = (0, 100);
pub EnabledTradingPairs: Vec<TradingPair> = vec![];
}
Expand All @@ -115,7 +116,11 @@ impl module_dex::Config for Runtime {
type Currency = Tokens;
type GetExchangeFee = GetExchangeFee;
type TradingPathLimit = ConstU32<4>;
type SingleTokenTradingLimit = ConstU32<10>;
type TradingKeysUpdateFrequency = ConstU64<1>;
type UnsignedPriority = ConstU64<1048576>; // 1 << 20
type PalletId = DEXPalletId;
type TreasuryPallet = TreasuryPalletId;
type Erc20InfoMapping = ();
type DEXIncentives = ();
type WeightInfo = ();
Expand Down Expand Up @@ -222,6 +227,16 @@ frame_support::construct_runtime!(
}
);

pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Runtime
where
Call: From<LocalCall>,
{
type OverarchingCall = Call;
type Extrinsic = Extrinsic;
}

pub struct ExtBuilder {
balances: Vec<(AccountId, CurrencyId, Balance)>,
}
Expand Down
1 change: 0 additions & 1 deletion modules/auction-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ impl<T: Config> Pallet<T> {
let lock_expiration = Duration::from_millis(LOCK_DURATION);
let mut lock = StorageLock::<'_, Time>::with_deadline(OFFCHAIN_WORKER_LOCK, lock_expiration);
let mut guard = lock.try_lock().map_err(|_| OffchainErr::OffchainLock)?;

let mut to_be_continue = StorageValueRef::persistent(OFFCHAIN_WORKER_DATA);

// get to_be_continue record,
Expand Down
5 changes: 5 additions & 0 deletions modules/auction-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl PriceProvider<CurrencyId> for MockPriceSource {

parameter_types! {
pub const DEXPalletId: PalletId = PalletId(*b"aca/dexm");
pub const TreasuryPalletId: PalletId = PalletId(*b"aca/trea");
pub const GetExchangeFee: (u32, u32) = (0, 100);
pub EnabledTradingPairs: Vec<TradingPair> = vec![
TradingPair::from_currency_ids(AUSD, BTC).unwrap(),
Expand All @@ -175,7 +176,11 @@ impl module_dex::Config for Runtime {
type Currency = Tokens;
type GetExchangeFee = GetExchangeFee;
type TradingPathLimit = ConstU32<4>;
type SingleTokenTradingLimit = ConstU32<10>;
type TradingKeysUpdateFrequency = ConstU64<1>;
type UnsignedPriority = ConstU64<1048576>; // 1 << 20
type PalletId = DEXPalletId;
type TreasuryPallet = TreasuryPalletId;
type Erc20InfoMapping = ();
type DEXIncentives = ();
type WeightInfo = ();
Expand Down
4 changes: 4 additions & 0 deletions modules/cdp-engine/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ impl cdp_treasury::Config for Runtime {

parameter_types! {
pub const DEXPalletId: PalletId = PalletId(*b"aca/dexm");
pub const TreasuryPalletId: PalletId = PalletId(*b"aca/trea");
pub const GetExchangeFee: (u32, u32) = (0, 100);
pub EnabledTradingPairs: Vec<TradingPair> = vec![
TradingPair::from_currency_ids(AUSD, BTC).unwrap(),
Expand All @@ -257,7 +258,10 @@ impl dex::Config for Runtime {
type Currency = Currencies;
type GetExchangeFee = GetExchangeFee;
type TradingPathLimit = ConstU32<4>;
type SingleTokenTradingLimit = ConstU32<10>;
type TradingKeysUpdateFrequency = ConstU64<1>;
type PalletId = DEXPalletId;
type TreasuryPallet = TreasuryPalletId;
type Erc20InfoMapping = ();
type DEXIncentives = ();
type WeightInfo = ();
Expand Down
15 changes: 15 additions & 0 deletions modules/cdp-treasury/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,19 @@ parameter_types! {
TradingPair::from_currency_ids(BTC, DOT).unwrap(),
];
pub const DEXPalletId: PalletId = PalletId(*b"aca/dexm");
pub const TreasuryPalletId: PalletId = PalletId(*b"aca/trea");
}

impl module_dex::Config for Runtime {
type Event = Event;
type Currency = Currencies;
type GetExchangeFee = GetExchangeFee;
type TradingPathLimit = ConstU32<4>;
type SingleTokenTradingLimit = ConstU32<10>;
type TradingKeysUpdateFrequency = ConstU64<1>;
type UnsignedPriority = ConstU64<1048576>; // 1 << 20
type PalletId = DEXPalletId;
type TreasuryPallet = TreasuryPalletId;
type Erc20InfoMapping = ();
type DEXIncentives = ();
type WeightInfo = ();
Expand Down Expand Up @@ -239,6 +244,16 @@ construct_runtime!(
}
);

pub type Extrinsic = sp_runtime::testing::TestXt<Call, ()>;

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Runtime
where
Call: From<LocalCall>,
{
type OverarchingCall = Call;
type Extrinsic = Extrinsic;
}

pub struct ExtBuilder {
balances: Vec<(AccountId, CurrencyId, Balance)>,
}
Expand Down
15 changes: 11 additions & 4 deletions modules/dex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,39 @@ edition = "2021"
serde = { version = "1.0.136", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] }
scale-info = { version = "2.1", default-features = false, features = ["derive"] }

sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

orml-traits = { path = "../../orml/traits", default-features = false }
orml-utilities = { path = "../../orml/utilities", default-features = false }

support = { package = "module-support", path = "../support", default-features = false }
primitives = { package = "acala-primitives", path = "../../primitives", default-features = false }

[dev-dependencies]
orml-tokens = { path = "../../orml/tokens" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
parking_lot = { version = "0.12.0" }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"scale-info/std",
"sp-io/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"sp-std/std",
"orml-traits/std",
"orml-utilities/std",
"support/std",
"primitives/std",
]
Expand Down
Loading