-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: feat/beta
Are you sure you want to change the base?
Liquid staking sc #121
Conversation
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::*; |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
liquid-staking/src/delegation.rs
Outdated
#[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"), | ||
} | ||
} |
There was a problem hiding this comment.
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
liquid-staking/src/delegation.rs
Outdated
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"); |
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
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": [], |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
Coverage SummaryTotals
FilesExpand
|
Contract comparison - from ae4bca4 to 5f25329
|
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Signed-off-by: Andrei Baltariu <andreibaltariu1304@gmail.com>
Liquid staking unit tests setup
No description provided.