Skip to content

Commit

Permalink
feat: apply code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshvarma committed Dec 12, 2023
1 parent 3c11d5b commit c9f1447
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 166 deletions.
2 changes: 1 addition & 1 deletion precompiles/assets-erc20/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ parameter_types! {
pub WeightPerGas: Weight = Weight::from_parts(1, 0);
}

pub type PCall = Erc20AssetsPrecompileSetCall<Runtime, ()>;
pub type PrecompileCall = Erc20AssetsPrecompileSetCall<Runtime, ()>;

impl pallet_evm::Config for Runtime {
type FeeCalculator = ();
Expand Down
138 changes: 75 additions & 63 deletions precompiles/assets-erc20/src/tests.rs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions precompiles/dapps-staking/DappsStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ interface DappsStaking {

/// @notice Register is root origin only and not allowed via evm precompile.
/// This should always fail.
function register(address) external;
function register(address) external returns (bool);

/// @notice Stake provided amount on the contract.
function bond_and_stake(address, uint128) external;
function bond_and_stake(address, uint128) external returns (bool);

/// @notice Start unbonding process and unstake balance from the contract.
function unbond_and_unstake(address, uint128) external;
function unbond_and_unstake(address, uint128) external returns (bool);

/// @notice Withdraw all funds that have completed the unbonding process.
function withdraw_unbonded() external;
function withdraw_unbonded() external returns (bool);

/// @notice Claim earned staker rewards for the oldest unclaimed era.
/// In order to claim multiple eras, this call has to be called multiple times.
/// Staker account is derived from the caller address.
/// @param smart_contract: The smart contract address used for staking
function claim_staker(address smart_contract) external;
function claim_staker(address smart_contract) external returns (bool);

/// @notice Claim one era of unclaimed dapp rewards for the specified contract and era.
/// @param smart_contract: The smart contract address used for staking
/// @param era: The era to be claimed
function claim_dapp(address smart_contract, uint128 era) external;
function claim_dapp(address smart_contract, uint128 era) external returns (bool);

/// Instruction how to handle reward payout for staker.
/// `FreeBalance` - Reward will be paid out to the staker (free balance).
Expand All @@ -76,15 +76,15 @@ interface DappsStaking {

/// @notice Set reward destination for staker rewards
/// @param reward_destination: The instruction on how the reward payout should be handled
function set_reward_destination(RewardDestination reward_destination) external;
function set_reward_destination(RewardDestination reward_destination) external returns (bool);

/// @notice Withdraw staked funds from an unregistered contract.
/// @param smart_contract: The smart contract address used for staking
function withdraw_from_unregistered(address smart_contract) external;
function withdraw_from_unregistered(address smart_contract) external returns (bool);

/// @notice Transfer part or entire nomination from origin smart contract to target smart contract
/// @param origin_smart_contract: The origin smart contract address
/// @param amount: The amount to transfer from origin to target
/// @param target_smart_contract: The target smart contract address
function nomination_transfer(address origin_smart_contract, uint128 amount, address target_smart_contract) external;
function nomination_transfer(address origin_smart_contract, uint128 amount, address target_smart_contract) external returns (bool);
}
34 changes: 17 additions & 17 deletions precompiles/dapps-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ where
/// Register contract with the dapp-staking pallet
/// Register is root origin only. This should always fail when called via evm precompile.
#[precompile::public("register(address)")]
fn register(_: &mut impl PrecompileHandle, _address: Address) -> EvmResult {
fn register(_: &mut impl PrecompileHandle, _address: Address) -> EvmResult<bool> {
// register is root-origin call. it should always fail when called via evm precompiles.
Err(RevertReason::custom("register via evm precompile is not allowed").into())
}
Expand All @@ -227,7 +227,7 @@ where
handle: &mut impl PrecompileHandle,
contract_h160: Address,
value: u128,
) -> EvmResult {
) -> EvmResult<bool> {
// parse contract's address
let contract_id = Self::decode_smart_contract(contract_h160.into())?;

Expand All @@ -239,7 +239,7 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Start unbonding process and unstake balance from the contract.
Expand All @@ -248,7 +248,7 @@ where
handle: &mut impl PrecompileHandle,
contract_h160: Address,
value: u128,
) -> EvmResult {
) -> EvmResult<bool> {
// parse contract's address
let contract_id = Self::decode_smart_contract(contract_h160.into())?;

Expand All @@ -260,19 +260,19 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Start unbonding process and unstake balance from the contract.
#[precompile::public("withdraw_unbonded()")]
fn withdraw_unbonded(handle: &mut impl PrecompileHandle) -> EvmResult {
fn withdraw_unbonded(handle: &mut impl PrecompileHandle) -> EvmResult<bool> {
// Build call with origin.
let origin = R::AddressMapping::into_account_id(handle.context().caller);
let call = pallet_dapps_staking::Call::<R>::withdraw_unbonded {};

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Claim rewards for the contract in the dapps-staking pallet
Expand All @@ -281,7 +281,7 @@ where
handle: &mut impl PrecompileHandle,
contract_h160: Address,
era: u128,
) -> EvmResult {
) -> EvmResult<bool> {
// parse contract's address
let contract_id = Self::decode_smart_contract(contract_h160.into())?;

Expand All @@ -299,12 +299,12 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Claim rewards for the contract in the dapps-staking pallet
#[precompile::public("claim_staker(address)")]
fn claim_staker(handle: &mut impl PrecompileHandle, contract_h160: Address) -> EvmResult {
fn claim_staker(handle: &mut impl PrecompileHandle, contract_h160: Address) -> EvmResult<bool> {
// parse contract's address
let contract_id = Self::decode_smart_contract(contract_h160.into())?;
log::trace!(target: "ds-precompile", "claim_staker {:?}", contract_id);
Expand All @@ -315,15 +315,15 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Set claim reward destination for the caller
#[precompile::public("set_reward_destination(uint8)")]
fn set_reward_destination(
handle: &mut impl PrecompileHandle,
reward_destination_raw: u8,
) -> EvmResult {
) -> EvmResult<bool> {
// Transform raw value into dapps staking enum
let reward_destination = if reward_destination_raw == 0 {
RewardDestination::FreeBalance
Expand All @@ -341,15 +341,15 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Withdraw staked funds from the unregistered contract
#[precompile::public("withdraw_from_unregistered(address)")]
fn withdraw_from_unregistered(
handle: &mut impl PrecompileHandle,
contract_h160: Address,
) -> EvmResult {
) -> EvmResult<bool> {
// parse contract's address
let contract_id = Self::decode_smart_contract(contract_h160.into())?;
log::trace!(target: "ds-precompile", "withdraw_from_unregistered {:?}", contract_id);
Expand All @@ -360,7 +360,7 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Claim rewards for the contract in the dapps-staking pallet
Expand All @@ -370,7 +370,7 @@ where
origin_contract_h160: Address,
value: u128,
target_contract_h160: Address,
) -> EvmResult {
) -> EvmResult<bool> {
// parse origin contract's address
let origin_contract_id = Self::decode_smart_contract(origin_contract_h160.into())?;

Expand All @@ -389,7 +389,7 @@ where

RuntimeHelper::<R>::try_dispatch(handle, Some(origin).into(), call)?;

Ok(())
Ok(true)
}

/// Helper method to decode type SmartContract enum
Expand Down
2 changes: 1 addition & 1 deletion precompiles/dapps-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
}
}

pub type PCall = DappsStakingWrapperCall<TestRuntime>;
pub type PrecompileCall = DappsStakingWrapperCall<TestRuntime>;

parameter_types! {
pub PrecompilesValue: DappPrecompile<TestRuntime> = DappPrecompile(Default::default());
Expand Down
Loading

0 comments on commit c9f1447

Please sign in to comment.