Skip to content

Commit

Permalink
KTON Staking Part.1 (#1409)
Browse files Browse the repository at this point in the history
* KTON Staking Part.1

* More tests

* Format

* Fix staking precompile test

* Test

* Transfer back

* Optimize curve

* Complete staking notify hook (#1410)

* Add notify impl

* Polish the implementation

* Add to field

* Add first params

* Add comment

* Code optimization

Signed-off-by: Xavier Lau <[email protected]>

* Fix the call input

* Fix

* Fix compile

* Fix runtime benchmarks

* Rename

* Format

* Revert curve algorithm

* Lower gas limit

* Correct addresses

---------

Signed-off-by: Xavier Lau <[email protected]>
Co-authored-by: bear <[email protected]>
Co-authored-by: fisher <[email protected]>
  • Loading branch information
3 people authored Feb 23, 2024
1 parent 5fac456 commit 64ee376
Show file tree
Hide file tree
Showing 18 changed files with 315 additions and 188 deletions.
35 changes: 8 additions & 27 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ impl darwinia_staking::Config for Runtime {
type Deposit = Deposit;
type IssuingManager = ();
type Kton = Dummy;
type KtonRewardDistributionContract = ();
type KtonStakerNotifier = ();
type MaxDeposits = ();
type MaxUnstakings = ();
type MigrationCurve = ();
type MinStakingDuration = ();
type Ring = Dummy;
type RuntimeEvent = RuntimeEvent;
Expand Down
3 changes: 0 additions & 3 deletions pallet/message-transact/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ frame_support::parameter_types! {
pub const BlockGasLimit: sp_core::U256 = sp_core::U256::MAX;
pub const WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(20_000, 0);
}

pub struct FixedGasPrice;
impl fp_evm::FeeCalculator for FixedGasPrice {
fn min_gas_price() -> (sp_core::U256, frame_support::weights::Weight) {
(sp_core::U256::from(5), frame_support::weights::Weight::zero())
}
}

impl pallet_evm::Config for Runtime {
type AddressMapping = pallet_evm::IdentityAddressMapping;
type BlockGasLimit = BlockGasLimit;
Expand All @@ -129,7 +127,6 @@ impl pallet_evm::Config for Runtime {
frame_support::parameter_types! {
pub const PostBlockAndTxnHashes: pallet_ethereum::PostLogContent = pallet_ethereum::PostLogContent::BlockAndTxnHashes;
}

impl pallet_ethereum::Config for Runtime {
type ExtraDataLength = ();
type PostLogContent = PostBlockAndTxnHashes;
Expand Down
18 changes: 14 additions & 4 deletions pallet/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ version.workspace = true
[dependencies]
# crates.io
codec = { workspace = true, package = "parity-scale-codec" }
ethabi = { version = "18.0", default-features = false }
ethereum = { workspace = true }
log = { workspace = true }
scale-info = { workspace = true }

# darwinia
darwinia-staking-traits = { workspace = true }
dc-types = { workspace = true }
darwinia-message-transact = { workspace = true }
darwinia-staking-traits = { workspace = true }
dc-types = { workspace = true }
# darwinia optional
darwinia-deposit = { workspace = true, optional = true }

Expand All @@ -23,14 +26,15 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-authorship = { workspace = true }
pallet-session = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
# substrate optional
frame-benchmarking = { workspace = true, optional = true }

[dev-dependencies]
# crates.io
pretty_env_logger = { version = "0.4" }
pretty_env_logger = { version = "0.5" }

# darwinia
darwinia-deposit = { workspace = true, features = ["std"] }
Expand All @@ -42,7 +46,6 @@ pallet-balances = { workspace = true, features = ["std"] }
pallet-session = { workspace = true, features = ["std"] }
pallet-timestamp = { workspace = true, features = ["std"] }
pallet-treasury = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }
substrate-test-utils = { workspace = true }

Expand All @@ -51,10 +54,13 @@ default = ["std"]
std = [
# crates.io
"codec/std",
"ethabi/std",
"ethereum/std",
"log/std",
"scale-info/std",

# darwinia
"darwinia-message-transact/std",
"darwinia-staking-traits/std",
# darwinia optional
"darwinia-deposit?/std",
Expand All @@ -65,6 +71,7 @@ std = [
"pallet-authorship/std",
"pallet-balances/std",
"pallet-session/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
# substrate optional
Expand All @@ -74,6 +81,7 @@ std = [
runtime-benchmarks = [
# darwinia
"darwinia-deposit",
"darwinia-message-transact/runtime-benchmarks",
"darwinia-staking-traits/runtime-benchmarks",

# substrate
Expand All @@ -85,6 +93,8 @@ runtime-benchmarks = [
]

try-runtime = [
# darwinia
"darwinia-message-transact/try-runtime",
# substrate
"frame-support/try-runtime",
"frame-system/try-runtime",
Expand Down
2 changes: 1 addition & 1 deletion pallet/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod benchmarks {
//
// The total number of deposit items has reached `Config::MaxUnstakings`.
#[extrinsic_call]
_(RawOrigin::Signed(a), UNIT, UNIT, deposits);
_(RawOrigin::Signed(a), UNIT, deposits);
}

#[benchmark]
Expand Down
Loading

0 comments on commit 64ee376

Please sign in to comment.