generated from multiversx/mx-template-sc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from multiversx/chain-config
Chain config
- Loading branch information
Showing
19 changed files
with
584 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
*/target/ | ||
|
||
# The mxpy output | ||
/output*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "chain-config" | ||
version = "0.0.0" | ||
authors = [ "you",] | ||
edition = "2018" | ||
publish = false | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dev-dependencies] | ||
num-bigint = "0.4.2" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "=0.43.5" | ||
|
||
[dependencies.multiversx-sc-modules] | ||
version = "=0.43.5" | ||
|
||
[dev-dependencies.multiversx-sc-scenario] | ||
version = "=0.43.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "chain-config-meta" | ||
version = "0.0.0" | ||
edition = "2018" | ||
publish = false | ||
authors = [ "you",] | ||
|
||
[dev-dependencies] | ||
|
||
[dependencies.chain-config] | ||
path = ".." | ||
|
||
[dependencies.multiversx-sc-meta] | ||
version = "=0.43.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
multiversx_sc_meta::cli_main::<chain_config::AbiProvider>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"language": "rust" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
multiversx_sc::imports!(); | ||
|
||
mod bridge_proxy { | ||
multiversx_sc::imports!(); | ||
|
||
#[multiversx_sc::proxy] | ||
pub trait BridgeProxy { | ||
#[init] | ||
fn init(&self, min_valid_signers: u32, signers: MultiValueEncoded<ManagedAddress>); | ||
} | ||
} | ||
|
||
#[multiversx_sc::module] | ||
pub trait BridgeModule { | ||
#[only_owner] | ||
#[endpoint(deployBridge)] | ||
fn deploy_bridge( | ||
&self, | ||
code: ManagedBuffer, | ||
min_valid_signers: u32, | ||
signers: MultiValueEncoded<ManagedAddress>, | ||
) { | ||
require!(self.bridge_address().is_empty(), "Bridge already deployed"); | ||
|
||
let metadata = | ||
CodeMetadata::PAYABLE_BY_SC | CodeMetadata::UPGRADEABLE | CodeMetadata::READABLE; | ||
let (sc_address, _) = self | ||
.bridge_proxy() | ||
.init(min_valid_signers, signers) | ||
.deploy_contract::<IgnoreValue>(&code, metadata); | ||
|
||
self.bridge_address().set(sc_address); | ||
} | ||
|
||
#[proxy] | ||
fn bridge_proxy(&self) -> bridge_proxy::Proxy<Self::Api>; | ||
|
||
#[storage_mapper("bridgeAddress")] | ||
fn bridge_address(&self) -> SingleValueMapper<ManagedAddress>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#![no_std] | ||
|
||
use validator_rules::TokenIdAmountPair; | ||
|
||
multiversx_sc::imports!(); | ||
|
||
pub mod bridge; | ||
pub mod validator_rules; | ||
|
||
pub type StakeMultiArg<M> = MultiValue2<TokenIdentifier<M>, BigUint<M>>; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait ChainConfigContract: | ||
bridge::BridgeModule | ||
+ validator_rules::ValidatorRulesModule | ||
+ multiversx_sc_modules::only_admin::OnlyAdminModule | ||
{ | ||
#[init] | ||
fn init( | ||
&self, | ||
min_validators: usize, | ||
max_validators: usize, | ||
min_stake: BigUint, | ||
admin: ManagedAddress, | ||
additional_stake_required: MultiValueEncoded<StakeMultiArg<Self::Api>>, | ||
) { | ||
require!( | ||
min_validators <= max_validators, | ||
"Invalid min/max validator numbers" | ||
); | ||
|
||
let mut additional_stake_vec = ManagedVec::new(); | ||
for multi_value in additional_stake_required { | ||
let (token_id, amount) = multi_value.into_tuple(); | ||
let value = TokenIdAmountPair { token_id, amount }; | ||
|
||
additional_stake_vec.push(value); | ||
} | ||
|
||
self.min_validators().set(min_validators); | ||
self.max_validators().set(max_validators); | ||
self.min_stake().set(min_stake); | ||
self.add_admin(admin); | ||
self.additional_stake_required().set(additional_stake_vec); | ||
} | ||
|
||
#[endpoint] | ||
fn upgrade(&self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
multiversx_sc::imports!(); | ||
multiversx_sc::derive_imports!(); | ||
|
||
// TODO: What to fill here? | ||
pub enum SlashableOffenses {} | ||
|
||
#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem)] | ||
pub struct TokenIdAmountPair<M: ManagedTypeApi> { | ||
pub token_id: TokenIdentifier<M>, | ||
pub amount: BigUint<M>, | ||
} | ||
|
||
#[multiversx_sc::module] | ||
pub trait ValidatorRulesModule { | ||
#[view(getMinValidators)] | ||
#[storage_mapper("minValidators")] | ||
fn min_validators(&self) -> SingleValueMapper<usize>; | ||
|
||
#[view(getMaxValidators)] | ||
#[storage_mapper("maxValidators")] | ||
fn max_validators(&self) -> SingleValueMapper<usize>; | ||
|
||
// TODO: Read user stake and verify | ||
#[view(getMinStake)] | ||
#[storage_mapper("minStake")] | ||
fn min_stake(&self) -> SingleValueMapper<BigUint>; | ||
|
||
// TODO: Read user stake and verify | ||
#[view(getAdditionalStakeRequired)] | ||
#[storage_mapper("additionalStakeRequired")] | ||
fn additional_stake_required( | ||
&self, | ||
) -> SingleValueMapper<ManagedVec<TokenIdAmountPair<Self::Api>>>; | ||
|
||
#[view(wasPreviouslySlashed)] | ||
#[storage_mapper("wasPreviouslySlashed")] | ||
fn was_previously_slashed(&self, validator: &ManagedAddress) -> SingleValueMapper<bool>; | ||
} |
Oops, something went wrong.