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

Update staking precompile method #1425

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions precompile/metadata/abi/staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@
"type": "uint256"
},
{
"internalType": "uint8[]",
"internalType": "uint16[]",
"name": "depositIds",
"type": "uint8[]"
"type": "uint16[]"
}
],
"name": "restake",
Expand Down Expand Up @@ -136,9 +136,9 @@
"type": "uint256"
},
{
"internalType": "uint8[]",
"internalType": "uint16[]",
"name": "depositIds",
"type": "uint8[]"
"type": "uint16[]"
}
],
"name": "stake",
Expand Down Expand Up @@ -167,9 +167,9 @@
"type": "uint256"
},
{
"internalType": "uint8[]",
"internalType": "uint16[]",
"name": "depositIds",
"type": "uint8[]"
"type": "uint16[]"
}
],
"name": "unstake",
Expand Down Expand Up @@ -242,7 +242,7 @@
"_0": "returns true on success, false otherwise."
}
},
"restake(uint256,uint8[])":
"restake(uint256,uint16[])":
{
"details": "Re-stake the unstaking assets immediately.",
"params":
Expand All @@ -255,7 +255,7 @@
"_0": "true on success, false otherwise."
}
},
"stake(uint256,uint256,uint8[])":
"stake(uint256,uint256,uint16[])":
{
"details": "Add stakes to the staking pool.",
"params":
Expand All @@ -269,7 +269,7 @@
"_0": "returns true on success, false otherwise."
}
},
"unstake(uint256,uint256,uint8[])":
"unstake(uint256,uint256,uint16[])":
{
"details": "Withdraw stakes to the staking pool.",
"params":
Expand All @@ -294,9 +294,9 @@
"collect(uint32)": "10a66536",
"nominate(address)": "b332180b",
"payout(address)": "0b7e9c44",
"restake(uint256,uint8[])": "6dbcd550",
"stake(uint256,uint256,uint8[])": "757f9b3b",
"unstake(uint256,uint256,uint8[])": "ef20fcb3"
"restake(uint256,uint16[])": "1ed0818e",
"stake(uint256,uint256,uint16[])": "98e9fb50",
"unstake(uint256,uint256,uint16[])": "632efe00"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions precompile/metadata/sol/staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface Staking {
function stake(
uint256 ringAmount,
uint256 ktonAmount,
uint8[] memory depositIds
uint16[] memory depositIds
) external returns (bool);

/// @dev Withdraw stakes to the staking pool.
Expand All @@ -46,7 +46,7 @@ interface Staking {
function unstake(
uint256 ringAmount,
uint256 ktonAmount,
uint8[] memory depositIds
uint16[] memory depositIds
) external returns (bool);

/// @dev Re-stake the unstaking assets immediately.
Expand All @@ -55,7 +55,7 @@ interface Staking {
/// @return true on success, false otherwise.
function restake(
uint256 ringAmount,
uint8[] memory depositIds
uint16[] memory depositIds
) external returns (bool);

/// @dev Claim the stakes from the pallet/contract account.
Expand Down
14 changes: 7 additions & 7 deletions precompile/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ where
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
<Runtime as frame_system::Config>::AccountId: From<H160>,
<<Runtime as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin: OriginTrait,
<<Runtime as darwinia_staking::Config>::Deposit as Stake>::Item: From<u8>,
<<Runtime as darwinia_staking::Config>::Deposit as Stake>::Item: From<u16>,
{
#[precompile::public("stake(uint256,uint256,uint8[])")]
#[precompile::public("stake(uint256,uint256,uint16[])")]
fn stake(
handle: &mut impl PrecompileHandle,
ring_amount: U256,
kton_amount: U256,
deposits: Vec<u8>,
deposits: Vec<u16>,
) -> EvmResult<bool> {
let origin = handle.context().caller.into();
let deposits = deposits.into_iter().map(|i| i.into()).collect();
Expand All @@ -75,12 +75,12 @@ where
Ok(true)
}

#[precompile::public("unstake(uint256,uint256,uint8[])")]
#[precompile::public("unstake(uint256,uint256,uint16[])")]
fn unstake(
handle: &mut impl PrecompileHandle,
ring_amount: U256,
kton_amount: U256,
deposits: Vec<u8>,
deposits: Vec<u16>,
) -> EvmResult<bool> {
let origin = handle.context().caller.into();
let deposits = deposits.into_iter().map(|i| i.into()).collect();
Expand All @@ -97,11 +97,11 @@ where
Ok(true)
}

#[precompile::public("restake(uint256,uint8[])")]
#[precompile::public("restake(uint256,uint16[])")]
fn restake(
handle: &mut impl PrecompileHandle,
ring_amount: U256,
deposits: Vec<u8>,
deposits: Vec<u16>,
) -> EvmResult<bool> {
let origin = handle.context().caller.into();
let deposits = deposits.into_iter().map(|i| i.into()).collect();
Expand Down
2 changes: 1 addition & 1 deletion precompile/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl darwinia_deposit::SimpleAsset for KtonMinting {

impl darwinia_deposit::Config for Runtime {
type Kton = KtonMinting;
type MaxDeposits = frame_support::traits::ConstU32<16>;
type MaxDeposits = frame_support::traits::ConstU32<512>;
type MinLockingAmount = frame_support::traits::ConstU128<100>;
type Ring = Balances;
type RuntimeEvent = RuntimeEvent;
Expand Down
6 changes: 3 additions & 3 deletions precompile/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fn precompiles() -> TestPrecompiles<Runtime> {

#[test]
fn selectors() {
assert!(PCall::stake_selectors().contains(&0x757f9b3b));
assert!(PCall::unstake_selectors().contains(&0xef20fcb3));
assert!(PCall::restake_selectors().contains(&0x6dbcd550));
assert!(PCall::stake_selectors().contains(&0x98e9fb50));
assert!(PCall::unstake_selectors().contains(&0x632efe00));
assert!(PCall::restake_selectors().contains(&0x1ed0818e));
assert!(PCall::claim_selectors().contains(&0x4e71d92d));
assert!(PCall::nominate_selectors().contains(&0xb332180b));
assert!(PCall::collect_selectors().contains(&0x10a66536));
Expand Down