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 106 commits into
base: feat/beta
Choose a base branch
from
Draft

Liquid staking sc #121

wants to merge 106 commits into from

Conversation

andreiblt1304
Copy link
Contributor

No description provided.

@@ -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

Copy link

github-actions bot commented Sep 13, 2024

Coverage Summary

Totals

Count Covered %
Lines 3978 1069 26.87
Regions 1182 178 15.06
Functions 475 106 22.32
Instantiations 1906 164 8.60

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%
/delegation-mock/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/delegation-mock/src/delegation_proxy.rs 0.00% 0.00% 0.00% 0.00%
/delegation-mock/src/lib.rs 66.13% 67.74% 69.23% 23.08%
/delegation-mock/tests/delegation_mock_scenario_go_test.rs 100.00% 100.00% 100.00% 100.00%
/delegation-mock/tests/delegation_mock_scenario_rs_test.rs 100.00% 100.00% 100.00% 100.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% 71.43% 100.00% 15.15%
/liquid-staking/src/delegation.rs 90.57% 77.14% 85.71% 30.38%
/liquid-staking/src/delegation_proxy.rs 71.70% 71.43% 71.43% 46.15%
/liquid-staking/src/lib.rs 70.37% 66.67% 80.00% 21.57%
/liquid-staking/src/liquid_staking_proxy.rs 48.85% 45.00% 45.00% 39.39%
/liquid-staking/src/liquidity_pools.rs 100.00% 66.67% 100.00% 10.00%
/liquid-staking/tests/liquid_staking_tests.rs 100.00% 100.00% 100.00% 100.00%

Copy link

github-actions bot commented Sep 13, 2024

Contract comparison - from ae4bca4 to a0874cf

Path                                                                                             size                  has-allocator                     has-format
chain-config-dbg.wasm 15246 false without message
chain-config.wasm 5457 false without message
enshrine-esdt-safe-full.wasm 37031 false without message
enshrine-esdt-safe-view.wasm 626 false none
enshrine-esdt-safe-dbg.wasm 90836 false without message
enshrine-esdt-safe.wasm 37031 false without message
enshrine-esdt-safe-view-dbg.wasm 1616 false none
enshrine-esdt-safe-full-dbg.wasm 90841 false without message
esdt-safe.wasm 32399 false without message
esdt-safe-full-dbg.wasm 83218 false without message
esdt-safe-dbg.wasm 83213 false without message
esdt-safe-view.wasm 626 false none
esdt-safe-full.wasm 32400 false without message
esdt-safe-view-dbg.wasm 1607 false none
fee-marker-full.wasm 11184 false without message
fee-market.wasm 11184 false without message
fee-market-dbg.wasm 32053 false without message
fee-marker-full-dbg.wasm 32058 false without message
multisig-view-dbg.wasm 1606 false none
multisig-view.wasm 626 false none
liquid-staking.wasm 8059 false without message
liquid-staking-view.wasm 626 false none
liquid-staking-full-dbg.wasm 23375 false without message
liquid-staking-dbg.wasm 23370 false without message
liquid-staking-full.wasm 8059 false without message
liquid-staking-view-dbg.wasm 1612 false none
delegation-mock-view.wasm 626 false none
delegation-mock.wasm 2900 false none
delegation-mock-dbg.wasm 9362 false none
delegation-mock-full-dbg.wasm 9367 false none
delegation-mock-view-dbg.wasm 1613 false none
delegation-mock-full.wasm 2900 false none
chain-factory-dbg.wasm 16274 false none
chain-factory.wasm 5560 false none
header-verifier-full-dbg.wasm 17194 false without message
header-verifier-full.wasm 5365 false without message
header-verifier-dbg.wasm 17189 false without message
header-verifier.wasm 5365 false without message
multisig-view-dbg.wasm 1606 false none
multisig-view.wasm 626 false none

⚠️ Could not download the report for the base branch. Displaying only the report for the current branch. ⚠️

andreiblt1304 and others added 13 commits September 15, 2024 15:26
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
andreiblt1304 and others added 30 commits October 4, 2024 09:17
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Liquid Staking upgrade to 0.53.1
Signed-off-by: Andrei Baltariu <[email protected]>
Signed-off-by: Andrei Baltariu <[email protected]>
Liquid-Staking fixes after review
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.

5 participants