Skip to content

Commit

Permalink
Mainnet Runtime version: 358 (#961)
Browse files Browse the repository at this point in the history
## Describe your changes

1. Direct Deposit/Withdrawal
2. OCEX bug fixes

## Checklist before requesting a review
- [x] I have performed a self-review of my code.
- [ ] If it is a core feature, I have added thorough tests.
- [x] I removed all Clippy and Formatting Warnings. 
- [x] I added required Copyrights.
  • Loading branch information
Gauthamastro authored May 30, 2024
2 parents 59461e2 + f915583 commit 7c5b5f4
Show file tree
Hide file tree
Showing 50 changed files with 2,412 additions and 744 deletions.
300 changes: 187 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 2 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,10 @@ members = [
"pallets/xcm-helper",
"misc/load-testing",
"misc/crowdloan-verifier",
"polkadex-xcm-simulator",
]
exclude = ["scripts/check-off-on-deviation"]
default-members = [
"client",
"nodes/mainnet",
"nodes/parachain",
"runtimes/mainnet",
"runtimes/parachain",
"pallets/pdex-migration",
"pallets/pdex-migration",
"pallets/ocex",
"pallets/ocex/rpc",
"pallets/liquidity-mining",
"pallets/ocex/rpc/runtime-api",
"pallets/rewards",
"primitives/orderbook",
"primitives/polkadex",
"primitives/thea",
"primitives/bls",
"pallets/thea",
"pallets/thea-executor",
"pallets/rewards/rpc",
"pallets/rewards/rpc/runtime-api",
"rpc/swap",
]


[workspace.dependencies]
log = { version = "0.4.8", default-features = false }
Expand Down Expand Up @@ -133,7 +112,6 @@ pallet-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-staking-reward-curve = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
#pallet-randomness-collective-flip = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-election-provider-multi-phase = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-statement = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion check-all-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ cargo build --features try-runtime || exit
cargo build --features runtime-benchmarks || exit
./target/debug/polkadex-node benchmark pallet --pallet "*" --extrinsic "*" --steps 2 --repeat 1 || exit
cargo clippy -- -D warnings || exit
RUSTFLAGS="-D warnings" cargo test || exit
RUSTFLAGS="-D warnings" cargo test --workspace || exit
1 change: 1 addition & 0 deletions pallets/liquidity-mining/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl ocex::Config for Test {
type CrowdSourceLiqudityMining = LiqudityMining;
type OBWithdrawalLimit = OBWithdrawalLimit;
type WeightInfo = ocex::weights::WeightInfo<Test>;
type CrossChainGadget = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/ocex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ sp-io = { workspace = true }
pallet-lmp = { path = "../liquidity-mining", default-features = false }
lazy_static = "1.4.0"
sequential-test = "0.2.4"
hex = "0.4.3"

[features]
default = ["std"]
Expand Down
14 changes: 6 additions & 8 deletions pallets/ocex/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,9 @@ benchmarks! {
let proxy = account::<T::AccountId>("proxy", x, 0);
Ocex::<T>::register_main_account(RawOrigin::Signed(user.clone()).into(), proxy)?;
let call = Call::<T>::deposit { asset, amount };
let id = H160::zero();
}: { call.dispatch_bypass_filter(RawOrigin::Signed(user.clone()).into())? }
verify {
assert_last_event::<T>(Event::DepositSuccessful {
user,
asset,
amount
}.into());
}


remove_proxy_account {
let x in 1 .. 255; // should not overflow u8
Expand Down Expand Up @@ -285,12 +280,13 @@ benchmarks! {
let mut vec_withdrawals = Vec::with_capacity(1);
let fees = Decimal::new(100, 5);
vec_withdrawals.push(Withdrawal {
id: Default::default(),
amount: Decimal::new(x.into(), 0),
stid:0,
asset,
main_account: main.clone(),
fees,
});
destination: None,});
let mut wm = sp_std::collections::btree_map::BTreeMap::new();
wm.insert(main.clone(), vec_withdrawals.clone());
<Withdrawals<T>>::insert(x as u64, wm);
Expand Down Expand Up @@ -580,11 +576,13 @@ fn get_dummy_snapshot<T: Config>() -> SnapshotSummary<T::AccountId> {
);
for _ in 0..50 {
withdrawals.push(Withdrawal {
id: Default::default(),
main_account: T::AccountId::decode(&mut &[0u8; 32][..]).unwrap(),
amount: Decimal::one(),
asset: AssetId::Polkadex,
fees: Decimal::one(),
stid: 1,
destination: None,
});
}
SnapshotSummary {
Expand Down
78 changes: 13 additions & 65 deletions pallets/ocex/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use rust_decimal::Decimal;
use sequential_test::sequential;
use sp_core::crypto::AccountId32;
use sp_core::sr25519::Signature;
use sp_core::{Pair, H256};
use sp_core::{Pair, H160, H256};
use sp_runtime::offchain::storage::StorageValueRef;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -84,66 +84,6 @@ fn test_run_on_chain_validation_trades_happy_path() {
});
}

#[test]
#[sequential]
fn test_lmp_complete_flow() {
new_test_ext().execute_with(|| {
set_lmp_config();
push_trade_user_actions(1, 1, 4768084);
assert_ok!(OCEX::run_on_chain_validation(1));
let snapshot_id: u64 = 1;
let mut key = LAST_PROCESSED_SNAPSHOT.to_vec();
key.append(&mut snapshot_id.encode());
let summay_ref = StorageValueRef::persistent(&key);
match summay_ref
.get::<(SnapshotSummary<AccountId32>, crate::sr25519::AuthoritySignature, u16)>()
{
Ok(Some((summary, signature, index))) => {
println!("Summary {:?}", summary);
assert_eq!(summary.snapshot_id, 1);
assert_eq!(summary.state_change_id, 1);
assert_eq!(summary.last_processed_blk, 4768084);
assert_ok!(OCEX::submit_snapshot(RuntimeOrigin::none(), summary, Vec::new()));
},
_ => panic!("Snapshot not found"),
};
OCEX::start_new_epoch(2);
push_trade_user_actions(2, 1, 4768085);
let s_info = StorageValueRef::persistent(&WORKER_STATUS);
s_info.set(&false);
assert_ok!(OCEX::run_on_chain_validation(2));
let snapshot_id: u64 = 2;
let mut key = LAST_PROCESSED_SNAPSHOT.to_vec();
key.append(&mut snapshot_id.encode());
let summay_ref = StorageValueRef::persistent(&key);
match summay_ref
.get::<(SnapshotSummary<AccountId32>, crate::sr25519::AuthoritySignature, u16)>()
{
Ok(Some((summary, signature, index))) => {
println!("Summary {:?}", summary);
assert_eq!(summary.snapshot_id, 2);
assert_eq!(summary.state_change_id, 2);
assert_eq!(summary.last_processed_blk, 4768085);
assert_ok!(OCEX::submit_snapshot(RuntimeOrigin::none(), summary, Vec::new()));
},
_ => panic!("Snapshot not found"),
};
OCEX::start_new_epoch(3);
let (maker_account, taker_account) = get_maker_and_taker_account();
let trading_pair = TradingPair { base: AssetId::Polkadex, quote: AssetId::Asset(1) };
assert_ok!(OCEX::claim_lmp_rewards(
RuntimeOrigin::signed(maker_account.clone()),
1,
trading_pair
));
assert_ok!(OCEX::claim_lmp_rewards(
RuntimeOrigin::signed(taker_account.clone()),
1,
trading_pair
));
})
}

#[test]
#[sequential]
fn test_on_chain_validation_with_auction() {
Expand Down Expand Up @@ -321,10 +261,18 @@ fn push_trade_user_actions(stid: u64, snapshot_id: u64, block_no: u64) {
fn get_block_import(block_no: u64) -> u64 {
let block_no = block_no;
let (maker_account, taker_account) = get_maker_and_taker_account();
let maker_ingress_message =
IngressMessages::Deposit(maker_account, AssetId::Asset(1), Decimal::from(100));
let taker_ingress_message =
IngressMessages::Deposit(taker_account, AssetId::Polkadex, Decimal::from(100));
let maker_ingress_message = IngressMessages::Deposit(
H160::zero(),
maker_account,
AssetId::Asset(1),
Decimal::from(100),
);
let taker_ingress_message = IngressMessages::Deposit(
H160::zero(),
taker_account,
AssetId::Polkadex,
Decimal::from(100),
);
<IngressMessagesStorage<Test>>::insert(
block_no,
vec![maker_ingress_message, taker_ingress_message],
Expand Down
Loading

0 comments on commit 7c5b5f4

Please sign in to comment.