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

Liquid staking sc #121

Draft
wants to merge 18 commits into
base: feat/beta
Choose a base branch
from
Draft

Liquid staking sc #121

wants to merge 18 commits into from

Conversation

andreiblt1304
Copy link
Contributor

No description provided.

Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
@@ -0,0 +1,4 @@
use multiversx_sc::imports::*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this

{
#[init]
fn init(&self, delegation_address: ManagedAddress) {
require!(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better extract this into a function / endpoint add_delegation_contract. In the future you might have this contract working with more than 1 delegation contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, in this case I will make the storage mapper to a UnorderedSetMapper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, this won't work, I created a SingleValueMapper with an index as contract_name

Comment on lines 55 to 70
#[callback]
fn stake_callback(
&self,
caller: &ManagedAddress,
egld_amount: &BigUint,
#[call_result] result: ManagedAsyncCallResult<()>,
) {
match result {
ManagedAsyncCallResult::Ok(()) => {
self.delegated_value(caller.clone()).set(egld_amount);
self.egld_token_supply()
.update(|value| *value += egld_amount)
}
_ => sc_panic!("There was an error at delegating"),
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small advice to ease code reading: put every callback after the endpoint that calls it

let current_epoch = self.blockchain().get_block_epoch();
let total_egld_deposit = self.delegated_value(caller.clone()).get();
let delegation_contract_address = self.delegation_address().get();
let undelegate_endpoint = ManagedBuffer::from("unDelegate");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a pub const out of this


let mut args: ManagedArgBuffer<Self::Api> = ManagedArgBuffer::new();
args.push_arg(&egld_amount_to_unstake);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it is way better to make a check here if caller has something to unstake, by checking that the amount to unstake is available in delegated_value

in this way you will not call undelegate if you already know that the caller hasn't enough to unstake

"tx": {
"from": "address:owner",
"contractCode": "mxsc:../output/liquid-staking.mxsc.json",
"arguments": [],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you forgot the init args

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no init args at the moment

Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Copy link

github-actions bot commented Sep 13, 2024

Coverage Summary

Totals

Count Covered %
Lines 3092 269 8.70
Regions 1040 53 5.10
Functions 387 31 8.01
Instantiations 1636 50 3.06

Files

Expand
File Lines Regions Functions Instantiations
/chain-config/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/chain-config/src/bridge.rs 0.00% 0.00% 0.00% 0.00%
/chain-config/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/chain-config/src/validator_rules.rs 0.00% 0.00% 0.00% 0.00%
/chain-factory/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/chain-factory/src/factory.rs 0.00% 0.00% 0.00% 0.00%
/chain-factory/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/chain-factory/src/slash.rs 0.00% 0.00% 0.00% 0.00%
/common/bls-signature/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/max-bridged-amount-module/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/setup-phase/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/token-whitelist/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/transaction/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/transaction/src/transaction_status.rs 0.00% 0.00% 0.00% 0.00%
/common/tx-batch-module/src/batch_status.rs 0.00% 0.00% 0.00% 0.00%
/common/tx-batch-module/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/tx-batch-module/src/tx_batch_mapper.rs 0.00% 0.00% 0.00% 0.00%
/common/utils/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/from_sovereign/events.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/from_sovereign/refund.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/from_sovereign/token_mapping.rs 1.47% 3.03% 7.69% 1.67%
/enshrine-esdt-safe/src/from_sovereign/transfer_tokens.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/lib.rs 25.00% 57.14% 40.00% 10.42%
/enshrine-esdt-safe/src/to_sovereign/create_tx.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/to_sovereign/events.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/to_sovereign/refund.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/src/to_sovereign/set_tx_status.rs 0.00% 0.00% 0.00% 0.00%
/enshrine-esdt-safe/tests/enshrine_esdt_safe_scenario_go_test.rs 100.00% 100.00% 100.00% 100.00%
/enshrine-esdt-safe/tests/enshrine_esdt_safe_scenario_rs_test.rs 100.00% 100.00% 100.00% 100.00%
/esdt-safe/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/esdt_safe_proxy.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/from_sovereign/events.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/from_sovereign/token_mapping.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/from_sovereign/transfer_tokens.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/to_sovereign/create_tx.rs 0.00% 0.00% 0.00% 0.00%
/esdt-safe/src/to_sovereign/events.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/enable_fee.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/fee_common.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/fee_market_proxy.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/fee_type.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/price_aggregator.rs 0.00% 0.00% 0.00% 0.00%
/fee-market/src/subtract_fee.rs 0.00% 0.00% 0.00% 0.00%
/header-verifier/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/header-verifier/src/header_verifier_proxy.rs 0.00% 0.00% 0.00% 0.00%
/header-verifier/src/lib.rs 61.11% 66.67% 62.50% 21.13%
/header-verifier/tests/header_verifier_blackbox_test.rs 83.70% 83.33% 83.33% 83.33%
/liquid-staking/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/liquid-staking/src/common/storage.rs 100.00% 33.33% 100.00% 2.94%
/liquid-staking/src/delegation.rs 0.00% 0.00% 0.00% 0.00%
/liquid-staking/src/lib.rs 100.00% 100.00% 100.00% 20.00%
/liquid-staking/src/liquid_staking_proxy.rs 25.00% 30.00% 30.00% 28.57%
/liquid-staking/src/liquidity_pools.rs 0.00% 0.00% 0.00% 0.00%
/liquid-staking/tests/liquid_staking_blackbox_tests.rs 100.00% 100.00% 100.00% 100.00%

Copy link

github-actions bot commented Sep 13, 2024

Contract comparison - from ae4bca4 to 5f25329
⚠️ Warning: Could not download the report for the base branch. Displaying only the report for the current branch. ⚠️

Path                                                                                             size                  has-allocator                     has-format
mx-sovereign-sc
- chain-config/chain-config.wasm 5457 No No
- chain-factory/chain-factory.wasm 5560 No No
- enshrine-esdt-safe
- - enshrine-esdt-safe.wasm 37032 No No
- - enshrine-esdt-safe-full.wasm 37032 No No
- - enshrine-esdt-safe-view.wasm 626 No No
- esdt-safe
- - esdt-safe.wasm 32399 No No
- - esdt-safe-full.wasm 32401 No No
- - esdt-safe-view.wasm 626 No No
- fee-market
- - fee-marker-full.wasm 11184 No No
- - fee-market.wasm 11184 No No
- - multisig-view.wasm 626 No No
- header-verifier
- - header-verifier.wasm 5365 No No
- - header-verifier-full.wasm 5365 No No
- - multisig-view.wasm 626 No No
- liquid-staking
- - liquid-staking.wasm 6740 No No
- - liquid-staking-full.wasm 6740 No No
- - liquid-staking-view.wasm 626 No No

andreiblt1304 and others added 4 commits September 15, 2024 15:26
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants