Skip to content

Commit

Permalink
Merge pull request #17 from multiversx/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
alyn509 authored Dec 3, 2024
2 parents 0752251 + ce02a3c commit 7c663d2
Show file tree
Hide file tree
Showing 29 changed files with 823 additions and 669 deletions.
35 changes: 12 additions & 23 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ members = [
"liquid-staking/meta",
"liquid-staking/interactor",
"delegation-mock",
"delegation-mock/meta"
"delegation-mock/meta",
]
4 changes: 0 additions & 4 deletions delegation-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@ path = "src/delegation.rs"
[dependencies.multiversx-sc]
version = "0.54.4"

[dependencies.itertools]
version = "0.10.1"
default-features = false

[dev-dependencies.multiversx-sc-scenario]
version = "0.54.4"
16 changes: 0 additions & 16 deletions delegation-mock/wasm/Cargo.lock

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

4 changes: 0 additions & 4 deletions liquid-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ publish = false
[lib]
path = "src/lib.rs"

[dependencies.itertools]
version = "0.10.1"
default-features = false

[dependencies.multiversx-sc]
version = "0.54.4"

Expand Down
144 changes: 72 additions & 72 deletions liquid-staking/interactor/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,70 +81,6 @@ where
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn add_liquidity(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("addLiquidity")
.original_result()
}

pub fn remove_liquidity(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("removeLiquidity")
.original_result()
}

pub fn unbond_tokens(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("unbondTokens")
.original_result()
}

pub fn withdraw_all<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
delegation_contract: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("withdrawAll")
.argument(&delegation_contract)
.original_result()
}

pub fn claim_rewards(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("claimRewards")
.original_result()
}

pub fn recompute_token_reserve(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("recomputeTokenReserve")
.original_result()
}

pub fn delegate_rewards(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("delegateRewards")
.original_result()
}

pub fn get_ls_value_for_position<
Arg0: ProxyArg<BigUint<Env::Api>>,
>(
Expand Down Expand Up @@ -430,17 +366,74 @@ where
.argument(&contract_address)
.original_result()
}
}

#[type_abi]
#[derive(TopEncode, TopDecode, PartialEq, Eq, Copy, Clone, Debug)]
pub enum State {
Inactive,
Active,
pub fn claim_rewards(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("claimRewards")
.original_result()
}

pub fn delegate_rewards(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("delegateRewards")
.original_result()
}

pub fn recompute_token_reserve(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("recomputeTokenReserve")
.original_result()
}

pub fn unbond_tokens(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("unbondTokens")
.original_result()
}

pub fn withdraw_all<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
delegation_contract: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("withdrawAll")
.argument(&delegation_contract)
.original_result()
}

pub fn add_liquidity(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("addLiquidity")
.original_result()
}

pub fn remove_liquidity(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("removeLiquidity")
.original_result()
}
}

#[type_abi]
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, PartialEq, Eq, Clone)]
#[derive(TopEncode)]
pub struct AddLiquidityEvent<Api>
where
Api: ManagedTypeApi,
Expand All @@ -457,7 +450,7 @@ where
}

#[type_abi]
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, PartialEq, Eq, Clone)]
#[derive(TopEncode)]
pub struct RemoveLiquidityEvent<Api>
where
Api: ManagedTypeApi,
Expand All @@ -475,6 +468,13 @@ where
pub timestamp: u64,
}

#[type_abi]
#[derive(TopEncode, TopDecode, PartialEq, Eq, Copy, Clone, Debug)]
pub enum State {
Inactive,
Active,
}

#[type_abi]
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, PartialEq, Eq, Clone)]
pub enum ClaimStatusType {
Expand Down
2 changes: 1 addition & 1 deletion liquid-staking/meta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "liquid-staking-abi"
name = "liquid-staking-meta"
version = "0.0.0"
authors = ["Sorin Petreasca <sorin.petreasca@multiversx.com>"]
edition = "2021"
Expand Down
18 changes: 18 additions & 0 deletions liquid-staking/src/basics/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub type GasLimit = u64;
pub type Blocks = u64;

pub const DEFAULT_MIN_GAS_TO_SAVE_PROGRESS: GasLimit = 30_000_000;
pub const DEFAULT_GAS_TO_CLAIM_REWARDS: GasLimit = 6_000_000;
pub const MIN_GAS_FOR_ASYNC_CALL: GasLimit = 12_000_000;
pub const MIN_GAS_FOR_CALLBACK: GasLimit = 12_000_000;
pub const MIN_GAS_FINISH_EXEC: GasLimit = 20_000_000;

pub const MIN_BLOCKS_BEFORE_CLEAR_ONGOING_OP: Blocks = 10;
pub const RECOMPUTE_BLOCK_OFFSET: Blocks = 10;

pub const MIN_EGLD_TO_DELEGATE: u64 = 1_000_000_000_000_000_000; // 1 EGLD
pub const EGLD_TO_WHITELIST: u64 = 1_000_000_000_000_000_000; // 1 EGLD

pub const MINIMUM_LIQUIDITY: u64 = 1_000;

pub const MAX_DELEGATION_ADDRESSES: usize = 20;
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pub static ERROR_ACTIVE: &[u8] = b"Active state";
pub static ERROR_NOT_ACTIVE: &[u8] = b"Not active";
pub static ERROR_LS_TOKEN_NOT_ISSUED: &[u8] = b"LS token not issued";
pub static ERROR_DELEGATION_CONTRACT_NOT_INITIALIZED: &[u8] =
b"Delegation contract was not initialized yet";
pub static ERROR_INSUFFICIENT_GAS: &[u8] = b"Insufficient gas remaining for the callback";

pub static ERROR_CLAIM_START: &[u8] = b"Claim operation must be new or pending";
pub static ERROR_CLAIM_IN_PROGRESS: &[u8] = b"Claim operation is already in progress";
pub static ERROR_OLD_CLAIM_START: &[u8] =
b"Previous claimed rewards must be redelegated or lesser than 1 EGLD";
Expand All @@ -19,13 +17,9 @@ pub static ERROR_BAD_PAYMENT_TOKEN: &[u8] = b"Bad payment token";
pub static ERROR_BAD_PAYMENT_AMOUNT: &[u8] = b"Insufficient delegated amount";
pub static ERROR_BAD_WHITELIST_FEE: &[u8] = b"Whitelisting contracts costs 1 EGLD";
pub static ERROR_INSUFFICIENT_UNSTAKE_AMOUNT: &[u8] = b"Insufficient unstake amount";
pub static ERROR_INSUFFICIENT_UNBONDED_AMOUNT: &[u8] = b"Insufficient incoming withdraw amount";
pub static ERROR_INSUFFICIENT_LIQUIDITY: &[u8] = b"Insufficient liquidity minted";
pub static ERROR_INSUFFICIENT_LIQ_BURNED: &[u8] = b"Insufficient liquidity burned";

pub static ERROR_NOT_ENOUGH_RESERVE: &[u8] = b"Not enough reserve";
pub static ERROR_NOT_ENOUGH_LP: &[u8] = b"Not enough LP token supply";

pub static ERROR_BAD_DELEGATION_ADDRESS: &[u8] = b"No delegation contract available";
pub static ERROR_BAD_DELEGATION_AMOUNT: &[u8] = b"Delegation amount must be at least 1 EGLD";
pub static ERROR_NO_DELEGATION_CONTRACTS: &[u8] = b"There are no delegation contracts whitelisted";
Expand All @@ -36,4 +30,3 @@ pub static ERROR_DELEGATION_CAP: &[u8] =
b"Delegation cap must be higher than the total staked amount";
pub static ERROR_ONLY_DELEGATION_ADMIN: &[u8] =
b"Only the admin of the delegation contract can change the status";
pub static ERROR_NOTHING_TO_UNBOND: &[u8] = b"Nothing to unbond";
Loading

0 comments on commit 7c663d2

Please sign in to comment.