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

feat: vault top up #20

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
582 changes: 286 additions & 296 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
[package]
name = "core-mx-life-bonding-sc"
version = "2.0.0"
version = "3.0.0"
authors = ["Bucur David - Itheum"]
edition = "2021"
publish = false

[lib]
path = "src/lib.rs"

[dependencies]
core-mx-liveliness-stake = {git ="https://github.com/Itheum/core-mx-liveliness-stake.git",branch = "main"}

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


[dev-dependencies.multiversx-sc-scenario]
version = "0.51.0"

Expand Down
43 changes: 40 additions & 3 deletions interaction/devnet.snippets.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROXY=https://devnet-gateway.multiversx.com
CHAIN_ID="D"

WALLET="./wallet.pem"
WALLET="../wallet_dev.pem"
USER="./wallet2.pem"

ADDRESS=$(mxpy data load --key=address-devnet)
Expand All @@ -16,7 +16,7 @@ TOKEN_HEX="0x$(echo -n ${TOKEN} | xxd -p -u | tr -d '\n')"
# --bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \
deploy(){
mxpy --verbose contract deploy \
--bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \
--bytecode output/core-mx-life-bonding-sc.wasm \
--outfile deployOutput \
--metadata-not-readable \
--metadata-payable-by-sc \
Expand All @@ -42,7 +42,7 @@ deploy(){
# in below code example we added --metadata-payable to add PAYABLE to the prop of the SC and removed --metadata-not-readable to make it READABLE
upgrade(){
mxpy --verbose contract upgrade ${ADDRESS} \
--bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \
--bytecode output/core-mx-life-bonding-sc.wasm \
--metadata-not-readable \
--metadata-payable-by-sc \
--pem ${WALLET} \
Expand Down Expand Up @@ -294,3 +294,40 @@ initiateBond() {
--chain ${CHAIN_ID} \
--send || return
}


setLivelinessStakeAddress(){

# $1 = address

address="0x$(mxpy wallet bech32 --decode ${1})"

mxpy --verbose contract call ${ADDRESS} \
--recall-nonce \
--pem=${WALLET} \
--gas-limit=6000000 \
--function "setLivelinessStakeAddress" \
--arguments $address \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--send || return

}


setTopUpAdministrator(){

# $1 = address

address="0x$(mxpy wallet bech32 --decode ${1})"

mxpy --verbose contract call ${ADDRESS} \
--recall-nonce \
--pem=${WALLET} \
--gas-limit=6000000 \
--function "setTopUpAdministrator" \
--arguments $address \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--send || return
}
22 changes: 21 additions & 1 deletion src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
ERR_COMPENSATION_NOT_FOUND, ERR_INVALID_PENALTY_VALUE, ERR_INVALID_TIMESTAMP,
ERR_INVALID_TOKEN_IDENTIFIER, ERR_NOT_IN_STORAGE, ERR_NOT_PRIVILEGED,
},
events, only_privileged,
events, only_privileged, proxy_contracts,
storage::{self, PenaltyType},
};

Expand Down Expand Up @@ -132,6 +132,12 @@ pub trait AdminModule:
let mut bond_cache = BondCache::new(self, bond_id);
let mut compensation_cache = CompensationCache::new(self, compensation_id);

self.tx()
.to(self.liveliness_stake_address().get())
.typed(proxy_contracts::liveliness_stake_proxy::CoreMxLivelinessStakeProxy)
.generate_rewards()
.sync_call();

let penalty = match penalty {
PenaltyType::Minimum => self.minimum_penalty().get(),
PenaltyType::Custom => {
Expand Down Expand Up @@ -296,4 +302,18 @@ pub trait AdminModule:
self.withdraw_penalty_event(penalty);
self.withdraw_penalty().set(penalty);
}

#[endpoint(setLivelinessStakeAddress)]
fn set_liveliness_stake_address(&self, address: ManagedAddress) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.set_liveliness_stake_address_event(&address);
self.liveliness_stake_address().set(address);
}

#[endpoint(setTopUpAdministrator)]
fn set_top_up_administrator(&self, address: ManagedAddress) {
only_privileged!(self, ERR_NOT_PRIVILEGED);
self.set_top_up_administrator_event(&address);
self.top_up_administrator().set(address);
}
}
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ pub trait ConfigModule: storage::StorageModule + events::EventsModule {
if self.lock_periods().is_empty() {
is_ready = false;
}

if self.liveliness_stake_address().is_empty() {
is_ready = false;
}

if self.top_up_administrator().is_empty() {
is_ready = false;
}
is_ready
}

Expand All @@ -89,6 +97,10 @@ pub trait ConfigModule: storage::StorageModule + events::EventsModule {
#[storage_mapper("administrator")]
fn administrator(&self) -> SingleValueMapper<ManagedAddress>;

#[view(getTopUpAdministrator)]
#[storage_mapper("top_up_administrator")]
fn top_up_administrator(&self) -> SingleValueMapper<ManagedAddress>;

#[view(getAcceptedCallers)]
#[storage_mapper("accepted_callers")]
fn accepted_callers(&self) -> UnorderedSetMapper<ManagedAddress>;
Expand Down
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pub const ERR_ALREADY_IN_STORAGE: &str = "Already in storage";
pub const ERR_NOT_IN_STORAGE: &str = "Not in storage";
pub const ERR_ALREADY_ACTIVE: &str = "Already active";
pub const ERR_ALREADY_INACTIVE: &str = "Already inactive";
pub const ERR_VAULT_NONCE_NOT_SET: &str = "Vault nonce not set";
6 changes: 6 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ pub trait EventsModule {

#[event("set_administrator_event")]
fn set_administrator_event(&self, #[indexed] administrator: &ManagedAddress);

#[event("set_liveliness_stake_address")]
fn set_liveliness_stake_address_event(&self, #[indexed] address: &ManagedAddress);

#[event("set_top_up_administrator_event")]
fn set_top_up_administrator_event(&self, #[indexed] top_up_administrator: &ManagedAddress);
}
Loading
Loading