From 0faa6107017c87dc4c0b988bf1283d91cb78c8a8 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Fri, 4 Mar 2022 12:58:27 +0200 Subject: [PATCH 1/9] keep vote nft after redeem --- dex/governance/src/config.rs | 35 ++++++++----------------------- dex/governance/src/contract.rs | 13 ++++++++---- dex/governance/src/errors.rs | 4 ++++ dex/governance/src/vote.rs | 16 +++++++++++++- dex/governance/tests/gov_tests.rs | 10 +++++++-- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/dex/governance/src/config.rs b/dex/governance/src/config.rs index 34d54c0c9..cfb96a787 100644 --- a/dex/governance/src/config.rs +++ b/dex/governance/src/config.rs @@ -1,5 +1,6 @@ elrond_wasm::imports!(); +use crate::errors::*; use crate::proposal::*; #[elrond_wasm::module] @@ -36,67 +37,49 @@ pub trait Config { let caller = self.blockchain().get_caller(); let sc_address = self.blockchain().get_sc_address(); - require!( - caller == sc_address, - "Only the SC itself may call this function" - ); + require!(caller == sc_address, INVALID_CALLER_NOT_SELF); } fn try_change_mex_token_id(&self, token_id: TokenIdentifier) { - require!( - token_id.is_esdt(), - "Invalid ESDT token ID provided for vote_nft" - ); + require!(token_id.is_esdt(), INVALID_ESDT); self.mex_token_id().set(&token_id); } fn try_change_vote_nft_id(&self, token_id: TokenIdentifier) { - require!( - token_id.is_esdt(), - "Invalid ESDT token ID provided for vote_nft" - ); + require!(token_id.is_esdt(), INVALID_ESDT); self.vote_nft_id().set(&token_id); } fn try_change_governance_token_ids(&self, token_ids: ManagedVec) { for token_id in token_ids.iter() { - require!( - token_id.is_esdt(), - "Invalid ESDT token ID provided for token_ids" - ); + require!(token_id.is_esdt(), INVALID_ESDT); } self.governance_token_ids().set(&token_ids); } fn try_change_quorum(&self, new_value: BigUint) { - require!(new_value != 0u64, "Quorum can't be set to 0"); + require!(new_value != 0u64, ZERO_VALUE); self.quorum().set(&new_value); } fn try_change_min_weight_for_proposal(&self, new_value: BigUint) { - require!( - new_value != 0u64, - "Min token balance for proposing can't be set to 0" - ); + require!(new_value != 0u64, ZERO_VALUE); self.min_weight_for_proposal().set(&new_value); } fn try_change_voting_delay_in_blocks(&self, new_value: u64) { - require!(new_value != 0, "Voting delay in blocks can't be set to 0"); + require!(new_value != 0, ZERO_VALUE); self.voting_delay_in_blocks().set(&new_value); } fn try_change_voting_period_in_blocks(&self, new_value: u64) { - require!( - new_value != 0, - "Voting period (in blocks) can't be set to 0" - ); + require!(new_value != 0, ZERO_VALUE); self.voting_period_in_blocks().set(&new_value); } diff --git a/dex/governance/src/contract.rs b/dex/governance/src/contract.rs index 202b3b6ee..c5d068c6d 100644 --- a/dex/governance/src/contract.rs +++ b/dex/governance/src/contract.rs @@ -118,14 +118,19 @@ pub trait Governance: let vote_nft_id = self.vote_nft_id().get(); require!(payment.token_identifier == vote_nft_id, BAD_TOKEN_ID); - let attr = self.get_vote_attr(&payment); - let proposal = self.proposal(attr.proposal_id).get(); + let mut attr = self.get_vote_attr(&payment); + require!(!attr.was_redeemed, ALREADY_REDEEMED); + let proposal = self.proposal(attr.proposal_id).get(); let pstat = self.get_proposal_status(&proposal); + match pstat { ProposalStatus::Defeated | ProposalStatus::Executed => { - self.send_back(attr.payment); - self.burn_vote_nft(payment); + attr.was_redeemed = true; + self.update_vote_nft_attributes(&vote_nft_id, payment.token_nonce, &attr); + + self.send_back(attr.payment.clone()); + self.send_back(payment); } ProposalStatus::Succeeded => { sc_panic!(PROPOSAL_NEEDS_TO_BE_EXECUTED) diff --git a/dex/governance/src/errors.rs b/dex/governance/src/errors.rs index 4c48817b0..050117217 100644 --- a/dex/governance/src/errors.rs +++ b/dex/governance/src/errors.rs @@ -5,3 +5,7 @@ pub const PROPOSAL_NOT_FOUND: &[u8] = b"proposal not found"; pub const NOT_ENOUGH_FUNDS_TO_PROPOSE: &[u8] = b"not enough funds to propose"; pub const VOTING_PERIOD_NOT_ENDED: &[u8] = b"voting period not ended"; pub const PROPOSAL_NEEDS_TO_BE_EXECUTED: &[u8] = b"successful proposal needs to be executed"; +pub const ZERO_VALUE: &[u8] = b"value cannot be zero"; +pub const INVALID_ESDT: &[u8] = b"invalid esdt"; +pub const INVALID_CALLER_NOT_SELF: &[u8] = b"caller should be self"; +pub const ALREADY_REDEEMED: &[u8] = b"already redeemed"; diff --git a/dex/governance/src/vote.rs b/dex/governance/src/vote.rs index 2722b8a81..2fc0c7c05 100644 --- a/dex/governance/src/vote.rs +++ b/dex/governance/src/vote.rs @@ -11,9 +11,11 @@ pub enum VoteType { #[derive(TypeAbi, TopEncode, TopDecode, PartialEq, Debug)] pub struct VoteNFTAttributes { + pub was_redeemed: bool, pub proposal_id: u64, pub vote_type: VoteType, pub vote_weight: BigUint, + pub voter: ManagedAddress, pub payment: EsdtTokenPayment, } @@ -29,10 +31,12 @@ pub trait VoteHelper: config::Config { let big_one = BigUint::from(1u64); let vote_nft_id = self.vote_nft_id().get(); let attr = VoteNFTAttributes { - payment, + was_redeemed: false, proposal_id, vote_type, vote_weight, + voter: self.blockchain().get_caller(), + payment, }; let nonce = self.send().esdt_nft_create( @@ -48,6 +52,16 @@ pub trait VoteHelper: config::Config { EsdtTokenPayment::new(vote_nft_id, nonce, big_one) } + fn update_vote_nft_attributes( + &self, + vote_nft_id: &TokenIdentifier, + nonce: u64, + new_attr: &VoteNFTAttributes, + ) { + self.send() + .nft_update_attributes(&vote_nft_id, nonce, &new_attr); + } + fn get_vote_attr(&self, payment: &EsdtTokenPayment) -> VoteNFTAttributes { self.blockchain() .get_esdt_token_data( diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index 759c0a7be..19b137fce 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -60,7 +60,11 @@ where }) .assert_ok(); - let vote_nft_roles = [EsdtLocalRole::NftCreate, EsdtLocalRole::NftBurn]; + let vote_nft_roles = [ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftBurn, + EsdtLocalRole::NftUpdateAttributes, + ]; blockchain_wrapper.set_esdt_local_roles( gov_wrapper.address_ref(), VOTE_NFT_ID, @@ -169,6 +173,7 @@ fn test_basic_propose() { .assert_ok(); // Owner has to have its Vote NFT + let owner_address = gov_setup.owner_address.clone(); gov_setup .blockchain_wrapper .execute_in_managed_environment(|| { @@ -178,9 +183,11 @@ fn test_basic_propose() { 1, &rust_biguint!(1), &VoteNFTAttributes:: { + was_redeemed: false, proposal_id: 0, vote_type: VoteType::Upvote, vote_weight: managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), + voter: managed_address!(&owner_address), payment: EsdtTokenPayment::new( managed_token_id!(MEX_TOKEN_ID), 0, @@ -191,7 +198,6 @@ fn test_basic_propose() { }); // SC Storage for proposal should be set correctly - let owner_address = gov_setup.owner_address.clone(); gov_setup .blockchain_wrapper .execute_query(&gov_setup.gov_wrapper, |sc| { From e8d564188f0eda5c8cd7cf60b8a75836458717a0 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Fri, 4 Mar 2022 13:29:24 +0200 Subject: [PATCH 2/9] upgrade to 0.29 --- dex/governance/Cargo.toml | 4 ++-- dex/governance/meta/Cargo.toml | 4 ++-- dex/governance/src/validation.rs | 20 ++------------------ dex/governance/wasm/Cargo.toml | 4 ++-- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/dex/governance/Cargo.toml b/dex/governance/Cargo.toml index 37ef08e1e..7e9375869 100644 --- a/dex/governance/Cargo.toml +++ b/dex/governance/Cargo.toml @@ -9,10 +9,10 @@ publish = false path = "src/contract.rs" [dependencies.elrond-wasm] -version = "0.28" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28" +version = "0.29" [dev-dependencies] num-bigint = "0.4.2" diff --git a/dex/governance/meta/Cargo.toml b/dex/governance/meta/Cargo.toml index 7df96e650..f5c791b45 100644 --- a/dex/governance/meta/Cargo.toml +++ b/dex/governance/meta/Cargo.toml @@ -11,7 +11,7 @@ authors = [ "you",] path = ".." [dependencies.elrond-wasm] -version = "0.28" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28" +version = "0.29" diff --git a/dex/governance/src/validation.rs b/dex/governance/src/validation.rs index 0688c60f3..81186df89 100644 --- a/dex/governance/src/validation.rs +++ b/dex/governance/src/validation.rs @@ -7,29 +7,13 @@ use crate::errors::*; pub trait Validation: config::Config { fn require_is_accepted_payment_for_proposal(&self, payment: &EsdtTokenPayment) { let governance_token_ids = self.governance_token_ids().get(); - - let mut found = false; - for token in governance_token_ids.iter() { - if *token == payment.token_identifier { - found = true; - break; - } - } - + let found = governance_token_ids.contains(&payment.token_identifier); require!(found, BAD_TOKEN_ID); } fn require_is_accepted_payment_for_voting(&self, payment: &EsdtTokenPayment) { let governance_token_ids = self.governance_token_ids().get(); - - let mut found = false; - for token in governance_token_ids.iter() { - if *token == payment.token_identifier { - found = true; - break; - } - } - + let found = governance_token_ids.contains(&payment.token_identifier); require!(found, BAD_TOKEN_ID); } } diff --git a/dex/governance/wasm/Cargo.toml b/dex/governance/wasm/Cargo.toml index a21c479b5..0f11a4d7c 100644 --- a/dex/governance/wasm/Cargo.toml +++ b/dex/governance/wasm/Cargo.toml @@ -24,8 +24,8 @@ panic = "abort" path = ".." [dependencies.elrond-wasm-node] -version = "0.28" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28" +version = "0.29" features = [ "wasm-output-mode",] From 436d1c52338b4ea26c8e59335a4c4b4d35d1022c Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Mon, 7 Mar 2022 11:44:26 +0200 Subject: [PATCH 3/9] redeem when successful --- dex/governance/src/contract.rs | 7 ++----- dex/governance/src/errors.rs | 1 - dex/governance/src/vote.rs | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/dex/governance/src/contract.rs b/dex/governance/src/contract.rs index c5d068c6d..b669c53fd 100644 --- a/dex/governance/src/contract.rs +++ b/dex/governance/src/contract.rs @@ -125,16 +125,13 @@ pub trait Governance: let pstat = self.get_proposal_status(&proposal); match pstat { - ProposalStatus::Defeated | ProposalStatus::Executed => { + ProposalStatus::Succeeded | ProposalStatus::Defeated | ProposalStatus::Executed => { attr.was_redeemed = true; self.update_vote_nft_attributes(&vote_nft_id, payment.token_nonce, &attr); - self.send_back(attr.payment.clone()); + self.send_back(attr.payment); self.send_back(payment); } - ProposalStatus::Succeeded => { - sc_panic!(PROPOSAL_NEEDS_TO_BE_EXECUTED) - } ProposalStatus::Active | ProposalStatus::Pending => { sc_panic!(VOTING_PERIOD_NOT_ENDED) } diff --git a/dex/governance/src/errors.rs b/dex/governance/src/errors.rs index 050117217..5a739b002 100644 --- a/dex/governance/src/errors.rs +++ b/dex/governance/src/errors.rs @@ -4,7 +4,6 @@ pub const PROPOSAL_NOT_SUCCEEDED: &[u8] = b"proposal not succeeded"; pub const PROPOSAL_NOT_FOUND: &[u8] = b"proposal not found"; pub const NOT_ENOUGH_FUNDS_TO_PROPOSE: &[u8] = b"not enough funds to propose"; pub const VOTING_PERIOD_NOT_ENDED: &[u8] = b"voting period not ended"; -pub const PROPOSAL_NEEDS_TO_BE_EXECUTED: &[u8] = b"successful proposal needs to be executed"; pub const ZERO_VALUE: &[u8] = b"value cannot be zero"; pub const INVALID_ESDT: &[u8] = b"invalid esdt"; pub const INVALID_CALLER_NOT_SELF: &[u8] = b"caller should be self"; diff --git a/dex/governance/src/vote.rs b/dex/governance/src/vote.rs index 2fc0c7c05..7c1334302 100644 --- a/dex/governance/src/vote.rs +++ b/dex/governance/src/vote.rs @@ -59,7 +59,7 @@ pub trait VoteHelper: config::Config { new_attr: &VoteNFTAttributes, ) { self.send() - .nft_update_attributes(&vote_nft_id, nonce, &new_attr); + .nft_update_attributes(vote_nft_id, nonce, new_attr); } fn get_vote_attr(&self, payment: &EsdtTokenPayment) -> VoteNFTAttributes { From c60d74c2e74572cbaddc510162613ba14cc43eb7 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Mon, 7 Mar 2022 18:28:34 +0200 Subject: [PATCH 4/9] multiple tokens --- dex/governance/src/config.rs | 47 +++++++++++++++++++++++++++++-- dex/governance/src/contract.rs | 6 ++++ dex/governance/src/lib.rs | 42 +++++++++++++++++++++++++-- dex/governance/src/validation.rs | 16 +++++++---- dex/governance/tests/gov_tests.rs | 2 ++ dex/governance/wasm/src/lib.rs | 2 ++ 6 files changed, 104 insertions(+), 11 deletions(-) diff --git a/dex/governance/src/config.rs b/dex/governance/src/config.rs index cfb96a787..18a961177 100644 --- a/dex/governance/src/config.rs +++ b/dex/governance/src/config.rs @@ -33,6 +33,25 @@ pub trait Config { self.try_change_voting_period_in_blocks(new_value); } + #[endpoint(changeGovernanceTokenIds)] + fn change_governance_token_ids(&self, token_ids: ManagedVec) { + self.require_caller_self(); + + self.try_change_governance_token_ids(token_ids); + } + + #[endpoint(changePriceProviders)] + fn change_price_providers( + &self, + #[var_args] price_providers: MultiValueEncoded< + MultiValue2, + >, + ) { + self.require_caller_self(); + + self.try_change_price_providers(price_providers); + } + fn require_caller_self(&self) { let caller = self.blockchain().get_caller(); let sc_address = self.blockchain().get_sc_address(); @@ -53,11 +72,30 @@ pub trait Config { } fn try_change_governance_token_ids(&self, token_ids: ManagedVec) { - for token_id in token_ids.iter() { + self.governance_token_ids().clear(); + + for token_id in token_ids.into_iter() { require!(token_id.is_esdt(), INVALID_ESDT); + + self.governance_token_ids().insert(token_id); } + } + + fn try_change_price_providers( + &self, + #[var_args] price_providers: MultiValueEncoded< + MultiValue2, + >, + ) { + self.price_providers().clear(); - self.governance_token_ids().set(&token_ids); + for provider in price_providers.into_iter() { + let tuple = provider.into_tuple(); + require!(tuple.0.is_esdt(), INVALID_ESDT); + require!(!tuple.1.is_zero(), ZERO_VALUE); + + self.price_providers().insert(tuple.0, tuple.1); + } } fn try_change_quorum(&self, new_value: BigUint) { @@ -86,7 +124,7 @@ pub trait Config { #[view(getGovernanceTokenId)] #[storage_mapper("governanceTokenIds")] - fn governance_token_ids(&self) -> SingleValueMapper>; + fn governance_token_ids(&self) -> SetMapper; #[view(getQuorum)] #[storage_mapper("quorum")] @@ -119,4 +157,7 @@ pub trait Config { #[view(getMexTokenId)] #[storage_mapper("mexTokenId")] fn mex_token_id(&self) -> SingleValueMapper; + + #[storage_mapper("price_providers")] + fn price_providers(&self) -> MapMapper; } diff --git a/dex/governance/src/contract.rs b/dex/governance/src/contract.rs index b669c53fd..a59abb577 100644 --- a/dex/governance/src/contract.rs +++ b/dex/governance/src/contract.rs @@ -31,6 +31,9 @@ pub trait Governance: mex_token_id: TokenIdentifier, min_weight_for_proposal: BigUint, governance_token_ids: ManagedVec, + #[var_args] price_providers: MultiValueEncoded< + MultiValue2, + >, ) { self.try_change_quorum(quorum); self.try_change_vote_nft_id(vote_nft_id); @@ -39,6 +42,7 @@ pub trait Governance: self.try_change_voting_delay_in_blocks(voting_delay_in_blocks); self.try_change_voting_period_in_blocks(voting_period_in_blocks); self.try_change_min_weight_for_proposal(min_weight_for_proposal); + self.try_change_price_providers(price_providers); } #[payable("*")] @@ -99,6 +103,8 @@ pub trait Governance: self.require_is_accepted_payment_for_voting(&payment); let vote_weight = self.get_vote_weight(&payment); + require!(vote_weight != 0, ZERO_VALUE); + match vote_type { VoteType::Upvote => proposal.num_upvotes += &vote_weight, VoteType::DownVote => proposal.num_downvotes += &vote_weight, diff --git a/dex/governance/src/lib.rs b/dex/governance/src/lib.rs index bd98b1ec1..1b51210bc 100644 --- a/dex/governance/src/lib.rs +++ b/dex/governance/src/lib.rs @@ -1,9 +1,44 @@ elrond_wasm::imports!(); +use crate::config; + +mod price_provider_proxy { + elrond_wasm::imports!(); + + #[elrond_wasm::proxy] + pub trait PriceProvider { + #[endpoint(updateAndGetTokensForGivenPositionWithSafePrice)] + fn update_and_get_tokens_for_given_position_with_safe_price( + &self, + liquidity: BigUint, + ) -> MultiValue2, EsdtTokenPayment>; + } +} + #[elrond_wasm::module] -pub trait Lib { +pub trait Lib: config::Config { fn get_vote_weight(&self, payment: &EsdtTokenPayment) -> BigUint { - payment.amount.clone() + if payment.token_identifier == self.mex_token_id().get() { + return payment.amount.clone(); + } + + if let Some(provider) = self.price_providers().get(&payment.token_identifier) { + let (token1, token2) = self + .price_provider_proxy(provider) + .update_and_get_tokens_for_given_position_with_safe_price(payment.amount.clone()) + .execute_on_dest_context_custom_range(|_, after| (after - 2, after)) + .into_tuple(); + + if payment.token_identifier == token1.token_identifier { + return token1.amount; + } + + if payment.token_identifier == token2.token_identifier { + return token2.amount; + } + } + + BigUint::zero() } fn send_back(&self, payment: EsdtTokenPayment) { @@ -15,4 +50,7 @@ pub trait Lib { &[], ); } + + #[proxy] + fn price_provider_proxy(&self, to: ManagedAddress) -> price_provider_proxy::Proxy; } diff --git a/dex/governance/src/validation.rs b/dex/governance/src/validation.rs index 81186df89..ce0a2c08d 100644 --- a/dex/governance/src/validation.rs +++ b/dex/governance/src/validation.rs @@ -6,14 +6,18 @@ use crate::errors::*; #[elrond_wasm::module] pub trait Validation: config::Config { fn require_is_accepted_payment_for_proposal(&self, payment: &EsdtTokenPayment) { - let governance_token_ids = self.governance_token_ids().get(); - let found = governance_token_ids.contains(&payment.token_identifier); - require!(found, BAD_TOKEN_ID); + require!( + self.governance_token_ids() + .contains(&payment.token_identifier), + BAD_TOKEN_ID + ); } fn require_is_accepted_payment_for_voting(&self, payment: &EsdtTokenPayment) { - let governance_token_ids = self.governance_token_ids().get(); - let found = governance_token_ids.contains(&payment.token_identifier); - require!(found, BAD_TOKEN_ID); + require!( + self.governance_token_ids() + .contains(&payment.token_identifier), + BAD_TOKEN_ID + ); } } diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index 19b137fce..6a3cb8080 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -1,3 +1,4 @@ +use elrond_wasm::types::MultiValueEncoded; use elrond_wasm::types::{Address, EsdtLocalRole, EsdtTokenPayment, ManagedVec}; use elrond_wasm_debug::{ managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, @@ -56,6 +57,7 @@ where managed_token_id!(MEX_TOKEN_ID), managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), ManagedVec::from(vec![managed_token_id!(MEX_TOKEN_ID)]), + MultiValueEncoded::new(), ); }) .assert_ok(); diff --git a/dex/governance/wasm/src/lib.rs b/dex/governance/wasm/src/lib.rs index c256da15f..83f3f35ef 100644 --- a/dex/governance/wasm/src/lib.rs +++ b/dex/governance/wasm/src/lib.rs @@ -7,7 +7,9 @@ elrond_wasm_node::wasm_endpoints! { governance ( + changeGovernanceTokenIds changeMinTokenBalanceForProposing + changePriceProviders changeQuorum changeVotingDelayInBlocks changeVotingPeriodInBlocks From 611669af5479d287f140937415113fc8bbb30754 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Tue, 8 Mar 2022 16:29:19 +0200 Subject: [PATCH 5/9] upgrade to 0.29 --- common/common_errors/Cargo.toml | 2 +- common/common_structs/Cargo.toml | 2 +- common/modules/farm/config/Cargo.toml | 2 +- common/modules/farm/contexts/Cargo.toml | 2 +- common/modules/farm/events/Cargo.toml | 2 +- common/modules/farm/farm_token/Cargo.toml | 2 +- .../farm/migration_from_v1_2/Cargo.toml | 2 +- common/modules/farm/rewards/Cargo.toml | 2 +- common/modules/token_merge/Cargo.toml | 2 +- common/modules/token_send/Cargo.toml | 2 +- dex/Cargo.toml | 4 +- dex/farm-staking-proxy/Cargo.toml | 4 +- dex/farm-staking-proxy/meta/Cargo.toml | 4 +- dex/farm-staking-proxy/src/lib.rs | 4 +- dex/farm-staking-proxy/wasm/Cargo.toml | 4 +- dex/farm-staking/Cargo.toml | 5 +- dex/farm-staking/meta/Cargo.toml | 4 +- dex/farm-staking/wasm/Cargo.toml | 4 +- dex/farm/Cargo.toml | 5 +- dex/farm/meta/Cargo.toml | 4 +- dex/farm/wasm/Cargo.toml | 4 +- dex/farm_v1_2_mock/Cargo.toml | 4 +- dex/farm_v1_2_mock/meta/Cargo.toml | 4 +- dex/farm_v1_2_mock/wasm/Cargo.toml | 4 +- dex/farm_with_lock/Cargo.toml | 5 +- dex/farm_with_lock/meta/Cargo.toml | 4 +- dex/farm_with_lock/wasm/Cargo.toml | 4 +- dex/fuzz/Cargo.toml | 4 +- dex/governance/Cargo.toml | 3 + dex/governance/tests/gov_tests.rs | 66 +++++++++++++++---- dex/pair/Cargo.toml | 4 +- dex/pair/meta/Cargo.toml | 4 +- dex/pair/src/fee.rs | 14 ++-- dex/pair/wasm/Cargo.toml | 4 +- dex/router/Cargo.toml | 5 +- dex/router/meta/Cargo.toml | 4 +- dex/router/src/contract.rs | 2 +- dex/router/src/factory.rs | 14 ++-- dex/router/src/lib.rs | 2 +- dex/router/wasm/Cargo.toml | 4 +- .../farm_with_lock_review_distribution.rs | 4 +- dex/tests/router_test.rs | 4 +- integration-test-lib/Cargo.toml | 4 +- locked-asset/Cargo.toml | 4 +- locked-asset/distribution/Cargo.toml | 4 +- locked-asset/distribution/meta/Cargo.toml | 4 +- locked-asset/distribution/src/lib.rs | 6 +- locked-asset/distribution/wasm/Cargo.toml | 4 +- locked-asset/factory/Cargo.toml | 5 +- locked-asset/factory/meta/Cargo.toml | 4 +- locked-asset/factory/src/lib.rs | 10 +-- locked-asset/factory/wasm/Cargo.toml | 4 +- locked-asset/proxy_dex/Cargo.toml | 5 +- locked-asset/proxy_dex/meta/Cargo.toml | 4 +- locked-asset/proxy_dex/src/lib.rs | 2 +- locked-asset/proxy_dex/src/proxy_common.rs | 8 +-- locked-asset/proxy_dex/wasm/Cargo.toml | 4 +- pair-mock/Cargo.toml | 4 +- pair-mock/meta/Cargo.toml | 4 +- pair-mock/wasm/Cargo.toml | 4 +- price-discovery/Cargo.toml | 5 +- price-discovery/meta/Cargo.toml | 4 +- price-discovery/wasm/Cargo.toml | 4 +- 63 files changed, 180 insertions(+), 146 deletions(-) diff --git a/common/common_errors/Cargo.toml b/common/common_errors/Cargo.toml index 94070b2b9..6435a5a50 100644 --- a/common/common_errors/Cargo.toml +++ b/common/common_errors/Cargo.toml @@ -8,5 +8,5 @@ edition = "2018" path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/common_structs/Cargo.toml b/common/common_structs/Cargo.toml index ec5e10212..1c8b35256 100644 --- a/common/common_structs/Cargo.toml +++ b/common/common_structs/Cargo.toml @@ -8,5 +8,5 @@ edition = "2018" path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/farm/config/Cargo.toml b/common/modules/farm/config/Cargo.toml index 35c035062..c37f1f6e0 100644 --- a/common/modules/farm/config/Cargo.toml +++ b/common/modules/farm/config/Cargo.toml @@ -17,4 +17,4 @@ path = "../../../common_errors" path = "../../token_send" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/farm/contexts/Cargo.toml b/common/modules/farm/contexts/Cargo.toml index 50a3905a1..b520664d3 100644 --- a/common/modules/farm/contexts/Cargo.toml +++ b/common/modules/farm/contexts/Cargo.toml @@ -29,4 +29,4 @@ path = "../../token_merge" path = "../config" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/farm/events/Cargo.toml b/common/modules/farm/events/Cargo.toml index 4b4f4ddae..4364f8102 100644 --- a/common/modules/farm/events/Cargo.toml +++ b/common/modules/farm/events/Cargo.toml @@ -14,4 +14,4 @@ path = "../../../common_structs" path = "../contexts" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/farm/farm_token/Cargo.toml b/common/modules/farm/farm_token/Cargo.toml index 69defedcf..0c3c1293a 100644 --- a/common/modules/farm/farm_token/Cargo.toml +++ b/common/modules/farm/farm_token/Cargo.toml @@ -20,4 +20,4 @@ path = "../config" path = "../../token_send" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/farm/migration_from_v1_2/Cargo.toml b/common/modules/farm/migration_from_v1_2/Cargo.toml index e2ad5e90c..2ace9e3d8 100644 --- a/common/modules/farm/migration_from_v1_2/Cargo.toml +++ b/common/modules/farm/migration_from_v1_2/Cargo.toml @@ -26,4 +26,4 @@ path = "../../token_send" path = "../rewards" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/farm/rewards/Cargo.toml b/common/modules/farm/rewards/Cargo.toml index 76448416d..039290499 100644 --- a/common/modules/farm/rewards/Cargo.toml +++ b/common/modules/farm/rewards/Cargo.toml @@ -23,4 +23,4 @@ path = "../farm_token" path = "../../token_send" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/token_merge/Cargo.toml b/common/modules/token_merge/Cargo.toml index f8f25e3fb..0d2d59530 100644 --- a/common/modules/token_merge/Cargo.toml +++ b/common/modules/token_merge/Cargo.toml @@ -14,4 +14,4 @@ path = "../../common_structs" path = "../../common_errors" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/common/modules/token_send/Cargo.toml b/common/modules/token_send/Cargo.toml index ca8a96682..d737bf4b2 100644 --- a/common/modules/token_send/Cargo.toml +++ b/common/modules/token_send/Cargo.toml @@ -14,4 +14,4 @@ path = "../../common_structs" path = "../../common_errors" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" diff --git a/dex/Cargo.toml b/dex/Cargo.toml index 130baecd8..bf8a0a8f9 100644 --- a/dex/Cargo.toml +++ b/dex/Cargo.toml @@ -5,10 +5,10 @@ edition = "2018" publish = false [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dev-dependencies] num-bigint = "0.4.2" diff --git a/dex/farm-staking-proxy/Cargo.toml b/dex/farm-staking-proxy/Cargo.toml index d3c05a7c1..7b1aae2e3 100644 --- a/dex/farm-staking-proxy/Cargo.toml +++ b/dex/farm-staking-proxy/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies] hex-literal = "0.3.1" @@ -30,7 +30,7 @@ path = "../../common/modules/token_merge" path = "../../common/common_structs" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dev-dependencies] num-bigint = "0.4.2" diff --git a/dex/farm-staking-proxy/meta/Cargo.toml b/dex/farm-staking-proxy/meta/Cargo.toml index cffae0132..71cf5077d 100644 --- a/dex/farm-staking-proxy/meta/Cargo.toml +++ b/dex/farm-staking-proxy/meta/Cargo.toml @@ -11,7 +11,7 @@ authors = [ "you",] path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm-staking-proxy/src/lib.rs b/dex/farm-staking-proxy/src/lib.rs index fc884e48e..7b77fd311 100644 --- a/dex/farm-staking-proxy/src/lib.rs +++ b/dex/farm-staking-proxy/src/lib.rs @@ -8,8 +8,8 @@ pub mod lp_farm_token; pub mod result_types; pub type StakeResult = EsdtTokenPayment; -pub type ClaimDualYieldResult = ManagedMultiResultVec>; -pub type UnstakeResult = ManagedMultiResultVec>; +pub type ClaimDualYieldResult = MultiValueEncoded>; +pub type UnstakeResult = MultiValueEncoded>; #[elrond_wasm::contract] pub trait FarmStakingProxy: diff --git a/dex/farm-staking-proxy/wasm/Cargo.toml b/dex/farm-staking-proxy/wasm/Cargo.toml index 9033fd030..490d2d288 100644 --- a/dex/farm-staking-proxy/wasm/Cargo.toml +++ b/dex/farm-staking-proxy/wasm/Cargo.toml @@ -24,9 +24,9 @@ panic = "abort" path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" features = [ "vm-validate-token-identifier" ] [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = [ "wasm-output-mode",] diff --git a/dex/farm-staking/Cargo.toml b/dex/farm-staking/Cargo.toml index cea35f130..013640fcc 100644 --- a/dex/farm-staking/Cargo.toml +++ b/dex/farm-staking/Cargo.toml @@ -36,11 +36,10 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dev-dependencies] num-bigint = "0.4.2" diff --git a/dex/farm-staking/meta/Cargo.toml b/dex/farm-staking/meta/Cargo.toml index 53ddbf2d3..a60f67c0f 100644 --- a/dex/farm-staking/meta/Cargo.toml +++ b/dex/farm-staking/meta/Cargo.toml @@ -10,7 +10,7 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm-staking/wasm/Cargo.toml b/dex/farm-staking/wasm/Cargo.toml index 3e1e046a0..f8d988a7e 100644 --- a/dex/farm-staking/wasm/Cargo.toml +++ b/dex/farm-staking/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index 4f668f65b..9d7051f6c 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -45,8 +45,7 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm/meta/Cargo.toml b/dex/farm/meta/Cargo.toml index 4159e9bfa..c2cc0a764 100644 --- a/dex/farm/meta/Cargo.toml +++ b/dex/farm/meta/Cargo.toml @@ -10,7 +10,7 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm/wasm/Cargo.toml b/dex/farm/wasm/Cargo.toml index 102fe7b59..e8e9ad77e 100644 --- a/dex/farm/wasm/Cargo.toml +++ b/dex/farm/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/dex/farm_v1_2_mock/Cargo.toml b/dex/farm_v1_2_mock/Cargo.toml index 4b46bf4f7..dd64adb8e 100644 --- a/dex/farm_v1_2_mock/Cargo.toml +++ b/dex/farm_v1_2_mock/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm_v1_2_mock/meta/Cargo.toml b/dex/farm_v1_2_mock/meta/Cargo.toml index a7de8be4c..5398d6208 100644 --- a/dex/farm_v1_2_mock/meta/Cargo.toml +++ b/dex/farm_v1_2_mock/meta/Cargo.toml @@ -10,7 +10,7 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm_v1_2_mock/wasm/Cargo.toml b/dex/farm_v1_2_mock/wasm/Cargo.toml index 1732b07a4..83e97c069 100644 --- a/dex/farm_v1_2_mock/wasm/Cargo.toml +++ b/dex/farm_v1_2_mock/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/dex/farm_with_lock/Cargo.toml b/dex/farm_with_lock/Cargo.toml index 499cb290a..2f2401839 100644 --- a/dex/farm_with_lock/Cargo.toml +++ b/dex/farm_with_lock/Cargo.toml @@ -45,8 +45,7 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm_with_lock/meta/Cargo.toml b/dex/farm_with_lock/meta/Cargo.toml index 61873ed97..316a4f724 100644 --- a/dex/farm_with_lock/meta/Cargo.toml +++ b/dex/farm_with_lock/meta/Cargo.toml @@ -10,7 +10,7 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/farm_with_lock/wasm/Cargo.toml b/dex/farm_with_lock/wasm/Cargo.toml index c76489aa7..33069e43d 100644 --- a/dex/farm_with_lock/wasm/Cargo.toml +++ b/dex/farm_with_lock/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/dex/fuzz/Cargo.toml b/dex/fuzz/Cargo.toml index c52f6b113..6317aee74 100644 --- a/dex/fuzz/Cargo.toml +++ b/dex/fuzz/Cargo.toml @@ -8,10 +8,10 @@ edition = "2018" path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies.config] path = "../../common/modules/farm/config" diff --git a/dex/governance/Cargo.toml b/dex/governance/Cargo.toml index 7e9375869..1e83ccf8d 100644 --- a/dex/governance/Cargo.toml +++ b/dex/governance/Cargo.toml @@ -16,3 +16,6 @@ version = "0.29" [dev-dependencies] num-bigint = "0.4.2" + +[dev-dependencies.pair-mock] +path = "../../pair-mock" diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index 6a3cb8080..df36d7b40 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -1,3 +1,4 @@ +use elrond_wasm::elrond_codec::multi_types::{MultiValue2, OptionalValue}; use elrond_wasm::types::MultiValueEncoded; use elrond_wasm::types::{Address, EsdtLocalRole, EsdtTokenPayment, ManagedVec}; use elrond_wasm_debug::{ @@ -11,31 +12,40 @@ use governance::proposal::*; use governance::vote::*; use governance::*; +use pair_mock::*; + pub const GOVERNANCE_WASM_PATH: &'static str = "governance/output/governance.wasm"; +pub const PAIR_MOCK_WASM_PATH: &'static str = "pair-mock/output/pair-mock.wasm"; pub const VOTE_NFT_ID: &[u8] = b"VOTE-abcdef"; pub const FAKE_TOKEN_ID: &[u8] = b"FAKE-abcdef"; pub const MEX_TOKEN_ID: &[u8] = b"MEX-abcdef"; +pub const LPMEX_TOKEN_ID: &[u8] = b"LPMEX-abcdef"; +pub const WUSDC_TOKEN_ID: &[u8] = b"WUSDC-abcdef"; pub const USER_TOTAL_MEX_TOKENS: u64 = 5_000_000_000; pub const QUORUM: u64 = 1_000_000_000; pub const VOTING_DELAY_IN_BLOCKS: u64 = 1; pub const VOTING_PERIOD_IN_BLOCKS: u64 = 1; pub const MIN_WEIGHT_FOR_PROPOSAL: u64 = 1_000_000; -pub struct GovernanceSetup +pub struct GovernanceSetup where GovernanceObjBuilder: 'static + Copy + Fn() -> governance::ContractObj, + PairMockObjBuilder: 'static + Copy + Fn() -> pair_mock::ContractObj, { pub blockchain_wrapper: BlockchainStateWrapper, pub owner_address: Address, pub user_address: Address, pub gov_wrapper: ContractObjWrapper, GovernanceObjBuilder>, + pub pair_wrapper: ContractObjWrapper, PairMockObjBuilder>, } -pub fn setup_gov( +pub fn setup_gov( gov_builder: GovernanceObjBuilder, -) -> GovernanceSetup + pair_builder: PairMockObjBuilder, +) -> GovernanceSetup where GovernanceObjBuilder: 'static + Copy + Fn() -> governance::ContractObj, + PairMockObjBuilder: 'static + Copy + Fn() -> pair_mock::ContractObj, { let rust_zero = rust_biguint!(0u64); let mut blockchain_wrapper = BlockchainStateWrapper::new(); @@ -47,8 +57,36 @@ where GOVERNANCE_WASM_PATH, ); + let pair_wrapper = blockchain_wrapper.create_sc_account( + &rust_zero, + Some(&owner_addr), + pair_builder, + PAIR_MOCK_WASM_PATH, + ); + + // init DEX mock + blockchain_wrapper + .execute_tx(&owner_addr, &pair_wrapper, &rust_zero, |sc| { + sc.init( + OptionalValue::Some(managed_token_id!(MEX_TOKEN_ID)), + OptionalValue::Some(managed_token_id!(WUSDC_TOKEN_ID)), + OptionalValue::None, + OptionalValue::None, + OptionalValue::None, + OptionalValue::None, + OptionalValue::None, + ); + }) + .assert_ok(); + blockchain_wrapper .execute_tx(&owner_addr, &gov_wrapper, &rust_zero, |sc| { + let mut price_providers = MultiValueEncoded::new(); + price_providers.push(MultiValue2::from(( + managed_token_id!(LPMEX_TOKEN_ID), + managed_address!(pair_wrapper.address_ref()), + ))); + sc.init( managed_biguint!(QUORUM), VOTING_DELAY_IN_BLOCKS, @@ -56,8 +94,11 @@ where managed_token_id!(VOTE_NFT_ID), managed_token_id!(MEX_TOKEN_ID), managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), - ManagedVec::from(vec![managed_token_id!(MEX_TOKEN_ID)]), - MultiValueEncoded::new(), + ManagedVec::from(vec![ + managed_token_id!(MEX_TOKEN_ID), + managed_token_id!(LPMEX_TOKEN_ID), + ]), + price_providers, ); }) .assert_ok(); @@ -100,17 +141,18 @@ where owner_address: owner_addr, user_address: user_addr, gov_wrapper, + pair_wrapper, } } #[test] fn test_gov_setup() { - let _ = setup_gov(governance::contract_obj); + let _ = setup_gov(governance::contract_obj, pair_mock::contract_obj); } #[test] fn test_propose_bad_token() { - let mut gov_setup = setup_gov(governance::contract_obj); + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); gov_setup .blockchain_wrapper @@ -132,7 +174,7 @@ fn test_propose_bad_token() { #[test] fn test_propose_bad_amount() { - let mut gov_setup = setup_gov(governance::contract_obj); + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); gov_setup .blockchain_wrapper @@ -154,7 +196,7 @@ fn test_propose_bad_amount() { #[test] fn test_basic_propose() { - let mut gov_setup = setup_gov(governance::contract_obj); + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); // User makes a basic proposal gov_setup @@ -224,7 +266,7 @@ fn test_basic_propose() { #[test] fn test_proposal_status_change() { - let mut gov_setup = setup_gov(governance::contract_obj); + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); gov_setup.blockchain_wrapper.set_block_nonce(0); @@ -337,7 +379,7 @@ fn test_proposal_status_change() { #[test] fn test_basic_reclaim() { - let mut gov_setup = setup_gov(governance::contract_obj); + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); gov_setup .blockchain_wrapper @@ -398,7 +440,7 @@ fn test_basic_reclaim() { #[test] fn test_vote() { - let mut gov_setup = setup_gov(governance::contract_obj); + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); gov_setup.blockchain_wrapper.set_block_nonce(0); diff --git a/dex/pair/Cargo.toml b/dex/pair/Cargo.toml index 478634acf..27131dc4d 100644 --- a/dex/pair/Cargo.toml +++ b/dex/pair/Cargo.toml @@ -16,10 +16,10 @@ version = "0.10.1" default-features = false [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies.common_structs] path = "../../common/common_structs" diff --git a/dex/pair/meta/Cargo.toml b/dex/pair/meta/Cargo.toml index a4adeba2f..88de13ad7 100644 --- a/dex/pair/meta/Cargo.toml +++ b/dex/pair/meta/Cargo.toml @@ -10,8 +10,8 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/pair/src/fee.rs b/dex/pair/src/fee.rs index d28dbe52e..a6df16362 100644 --- a/dex/pair/src/fee.rs +++ b/dex/pair/src/fee.rs @@ -315,8 +315,8 @@ pub trait FeeModule: } #[view(getFeeDestinations)] - fn get_fee_destinations(&self) -> ManagedMultiResultVec<(ManagedAddress, TokenIdentifier)> { - let mut result = ManagedMultiResultVec::new(); + fn get_fee_destinations(&self) -> MultiValueEncoded<(ManagedAddress, TokenIdentifier)> { + let mut result = MultiValueEncoded::new(); for pair in self.destination_map().iter() { result.push((pair.0, pair.1)) } @@ -324,10 +324,8 @@ pub trait FeeModule: } #[view(getTrustedSwapPairs)] - fn get_trusted_swap_pairs( - &self, - ) -> ManagedMultiResultVec<(TokenPair, ManagedAddress)> { - let mut result = ManagedMultiResultVec::new(); + fn get_trusted_swap_pairs(&self) -> MultiValueEncoded<(TokenPair, ManagedAddress)> { + let mut result = MultiValueEncoded::new(); for pair in self.trusted_swap_pair().iter() { result.push((pair.0, pair.1)) } @@ -335,8 +333,8 @@ pub trait FeeModule: } #[view(getWhitelistedManagedAddresses)] - fn get_whitelisted_managed_addresses(&self) -> ManagedMultiResultVec { - let mut result = ManagedMultiResultVec::new(); + fn get_whitelisted_managed_addresses(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); for pair in self.whitelist().iter() { result.push(pair); } diff --git a/dex/pair/wasm/Cargo.toml b/dex/pair/wasm/Cargo.toml index df98d271b..d22331507 100644 --- a/dex/pair/wasm/Cargo.toml +++ b/dex/pair/wasm/Cargo.toml @@ -24,8 +24,8 @@ panic = "abort" path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/dex/router/Cargo.toml b/dex/router/Cargo.toml index e6ffc359f..e2148fd6f 100644 --- a/dex/router/Cargo.toml +++ b/dex/router/Cargo.toml @@ -12,11 +12,10 @@ path = "src/contract.rs" path = "../../common/modules/token_send" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies.pair] path = "../pair" diff --git a/dex/router/meta/Cargo.toml b/dex/router/meta/Cargo.toml index f78f03948..7c968ab2c 100644 --- a/dex/router/meta/Cargo.toml +++ b/dex/router/meta/Cargo.toml @@ -10,7 +10,7 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/dex/router/src/contract.rs b/dex/router/src/contract.rs index f4aa7b130..f7d98f453 100644 --- a/dex/router/src/contract.rs +++ b/dex/router/src/contract.rs @@ -253,7 +253,7 @@ pub trait Router: &self, token: TokenIdentifier, address: ManagedAddress, - #[var_args] roles: ManagedVarArgs, + #[var_args] roles: MultiValueEncoded, ) { require!(self.is_active(), "Not active"); diff --git a/dex/router/src/factory.rs b/dex/router/src/factory.rs index d490b2498..6ceb8e9d3 100644 --- a/dex/router/src/factory.rs +++ b/dex/router/src/factory.rs @@ -104,8 +104,8 @@ pub trait FactoryModule { fn pair_map(&self) -> MapMapper, ManagedAddress>; #[view(getAllPairsManagedAddresses)] - fn get_all_pairs_addresses(&self) -> ManagedMultiResultVec { - let mut result = ManagedMultiResultVec::new(); + fn get_all_pairs_addresses(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); for pair in self.pair_map().values() { result.push(pair); } @@ -113,8 +113,8 @@ pub trait FactoryModule { } #[view(getAllPairTokens)] - fn get_all_token_pairs(&self) -> ManagedMultiResultVec> { - let mut result = ManagedMultiResultVec::new(); + fn get_all_token_pairs(&self) -> MultiValueEncoded> { + let mut result = MultiValueEncoded::new(); for pair in self.pair_map().keys() { result.push(pair); } @@ -122,10 +122,8 @@ pub trait FactoryModule { } #[view(getAllPairContractMetadata)] - fn get_all_pair_contract_metadata( - &self, - ) -> ManagedMultiResultVec> { - let mut result = ManagedMultiResultVec::new(); + fn get_all_pair_contract_metadata(&self) -> MultiValueEncoded> { + let mut result = MultiValueEncoded::new(); for (k, v) in self.pair_map().iter() { let pair_metadata = PairContractMetadata { first_token_id: k.first_token_id, diff --git a/dex/router/src/lib.rs b/dex/router/src/lib.rs index 7b7f2bbdc..ac54896c7 100644 --- a/dex/router/src/lib.rs +++ b/dex/router/src/lib.rs @@ -20,7 +20,7 @@ pub trait Lib: factory::FactoryModule + token_send::TokenSendModule { #[payment_token] token_id: TokenIdentifier, #[payment_amount] amount: BigUint, #[payment_nonce] nonce: u64, - swap_operations: ManagedMultiResultVec>, + swap_operations: MultiValueEncoded>, #[var_args] opt_accept_funds_func: OptionalValue, ) { require!(nonce == 0, "Invalid nonce. Should be zero"); diff --git a/dex/router/wasm/Cargo.toml b/dex/router/wasm/Cargo.toml index 8390fd27f..d4f1f1e6b 100644 --- a/dex/router/wasm/Cargo.toml +++ b/dex/router/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/dex/tests/farm_with_lock_review_distribution.rs b/dex/tests/farm_with_lock_review_distribution.rs index 452ab3c90..b3129a391 100644 --- a/dex/tests/farm_with_lock_review_distribution.rs +++ b/dex/tests/farm_with_lock_review_distribution.rs @@ -5,7 +5,7 @@ use common_structs::{ }; use elrond_wasm::{ elrond_codec::multi_types::OptionalValue, - types::{Address, BigUint, EsdtLocalRole, ManagedAddress, ManagedMultiResultVec, ManagedVec}, + types::{Address, BigUint, EsdtLocalRole, ManagedAddress, ManagedVec, MultiValueEncoded}, }; use elrond_wasm_debug::{ managed_address, managed_biguint, managed_token_id, rust_biguint, @@ -65,7 +65,7 @@ where blockchain_wrapper .execute_tx(&owner_addr, &factory_wrapper, &rust_biguint!(0), |sc| { let asset_token_id = managed_token_id!(LKMEX_TOKEN_ID); - let default_unlock_period = ManagedMultiResultVec::from(ManagedVec::from(vec![ + let default_unlock_period = MultiValueEncoded::from(ManagedVec::from(vec![ UnlockMilestone { unlock_epoch: 20, unlock_percent: 50, diff --git a/dex/tests/router_test.rs b/dex/tests/router_test.rs index e5960d416..03e2923e5 100644 --- a/dex/tests/router_test.rs +++ b/dex/tests/router_test.rs @@ -1,5 +1,5 @@ use elrond_wasm::elrond_codec::multi_types::{MultiValue4, OptionalValue}; -use elrond_wasm::types::{Address, EsdtLocalRole, ManagedMultiResultVec}; +use elrond_wasm::types::{Address, EsdtLocalRole, MultiValueEncoded}; use elrond_wasm_debug::tx_mock::TxInputESDT; use elrond_wasm_debug::{ managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, @@ -272,7 +272,7 @@ fn multi_pair_swap( 0, &payment_amount_big, |sc| { - let mut swap_operations = ManagedMultiResultVec::new(); + let mut swap_operations = MultiValueEncoded::new(); for x in args.iter() { swap_operations.push(MultiValue4::from(( managed_address!(&x.0), diff --git a/integration-test-lib/Cargo.toml b/integration-test-lib/Cargo.toml index c933e8316..31d602153 100644 --- a/integration-test-lib/Cargo.toml +++ b/integration-test-lib/Cargo.toml @@ -9,10 +9,10 @@ edition = "2018" num-bigint = "0.4.2" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies.proxy_dex] path = "../locked-asset/proxy_dex" diff --git a/locked-asset/Cargo.toml b/locked-asset/Cargo.toml index 5c509f473..4c63c9a20 100644 --- a/locked-asset/Cargo.toml +++ b/locked-asset/Cargo.toml @@ -5,10 +5,10 @@ edition = "2018" publish = false [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies.farm] path = "../dex/farm" diff --git a/locked-asset/distribution/Cargo.toml b/locked-asset/distribution/Cargo.toml index 6abae605e..d2d922b6b 100644 --- a/locked-asset/distribution/Cargo.toml +++ b/locked-asset/distribution/Cargo.toml @@ -14,7 +14,7 @@ path = "../../common/common_structs" path = "../factory" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/locked-asset/distribution/meta/Cargo.toml b/locked-asset/distribution/meta/Cargo.toml index 1010d4300..ffafbac29 100644 --- a/locked-asset/distribution/meta/Cargo.toml +++ b/locked-asset/distribution/meta/Cargo.toml @@ -10,8 +10,8 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/locked-asset/distribution/src/lib.rs b/locked-asset/distribution/src/lib.rs index e6db67bab..5fec83837 100644 --- a/locked-asset/distribution/src/lib.rs +++ b/locked-asset/distribution/src/lib.rs @@ -79,7 +79,7 @@ pub trait Distribution: global_op::GlobalOperationModule { fn set_per_user_distributed_locked_assets( &self, spread_epoch: u64, - #[var_args] user_locked_assets: ManagedVarArgs>, + #[var_args] user_locked_assets: MultiValueEncoded>, ) { self.require_global_op_ongoing(); self.require_community_distribution_list_not_empty(); @@ -150,7 +150,7 @@ pub trait Distribution: global_op::GlobalOperationModule { #[only_owner] #[endpoint(setUnlockPeriod)] - fn set_unlock_period(&self, #[var_args] milestones: ManagedVarArgs) { + fn set_unlock_period(&self, #[var_args] milestones: MultiValueEncoded) { let unlock_milestones = milestones.to_vec(); self.validate_unlock_milestones(&unlock_milestones); self.unlock_period() @@ -195,7 +195,7 @@ pub trait Distribution: global_op::GlobalOperationModule { fn add_all_user_assets_to_map( &self, spread_epoch: u64, - user_assets: ManagedVarArgs>, + user_assets: MultiValueEncoded>, ) { let mut last_community_distrib = self .community_distribution_list() diff --git a/locked-asset/distribution/wasm/Cargo.toml b/locked-asset/distribution/wasm/Cargo.toml index f267009f1..69d7c6203 100644 --- a/locked-asset/distribution/wasm/Cargo.toml +++ b/locked-asset/distribution/wasm/Cargo.toml @@ -25,9 +25,9 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/locked-asset/factory/Cargo.toml b/locked-asset/factory/Cargo.toml index 4d7204be9..0515560f5 100644 --- a/locked-asset/factory/Cargo.toml +++ b/locked-asset/factory/Cargo.toml @@ -24,11 +24,10 @@ path = "../../common/modules/token_send" path = "../../common/modules/token_merge" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies] wee_alloc = "0.4" diff --git a/locked-asset/factory/meta/Cargo.toml b/locked-asset/factory/meta/Cargo.toml index 807878d4f..db16ea257 100644 --- a/locked-asset/factory/meta/Cargo.toml +++ b/locked-asset/factory/meta/Cargo.toml @@ -10,9 +10,9 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/locked-asset/factory/src/lib.rs b/locked-asset/factory/src/lib.rs index 8e5c11099..b62b781d8 100644 --- a/locked-asset/factory/src/lib.rs +++ b/locked-asset/factory/src/lib.rs @@ -35,7 +35,7 @@ pub trait LockedAssetFactory: fn init( &self, asset_token_id: TokenIdentifier, - #[var_args] default_unlock_period: ManagedVarArgs, + #[var_args] default_unlock_period: MultiValueEncoded, ) { require!( asset_token_id.is_esdt(), @@ -248,7 +248,7 @@ pub trait LockedAssetFactory: #[only_owner] #[endpoint(setUnlockPeriod)] - fn set_unlock_period(&self, #[var_args] milestones: ManagedVarArgs) { + fn set_unlock_period(&self, #[var_args] milestones: MultiValueEncoded) { let unlock_milestones = milestones.to_vec(); self.validate_unlock_milestones(&unlock_milestones); self.default_unlock_period() @@ -371,7 +371,7 @@ pub trait LockedAssetFactory: fn set_local_roles_locked_asset_token( &self, address: ManagedAddress, - #[var_args] roles: ManagedVarArgs, + #[var_args] roles: MultiValueEncoded, ) { require!( !self.locked_asset_token_id().is_empty(), @@ -437,8 +437,8 @@ pub trait LockedAssetFactory: fn whitelisted_contracts(&self) -> SetMapper; #[view(getWhitelistedContracts)] - fn get_whitelisted_contracts(&self) -> ManagedMultiResultVec { - let mut result = ManagedMultiResultVec::new(); + fn get_whitelisted_contracts(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); for pair in self.whitelisted_contracts().iter() { result.push(pair); } diff --git a/locked-asset/factory/wasm/Cargo.toml b/locked-asset/factory/wasm/Cargo.toml index 26e250ccb..7a5f961dd 100644 --- a/locked-asset/factory/wasm/Cargo.toml +++ b/locked-asset/factory/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/locked-asset/proxy_dex/Cargo.toml b/locked-asset/proxy_dex/Cargo.toml index c066aadb2..2141b866e 100644 --- a/locked-asset/proxy_dex/Cargo.toml +++ b/locked-asset/proxy_dex/Cargo.toml @@ -30,8 +30,7 @@ path = "../../common/modules/token_merge" path = "../../common/modules/token_send" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/locked-asset/proxy_dex/meta/Cargo.toml b/locked-asset/proxy_dex/meta/Cargo.toml index 877d998db..befaaa2d3 100644 --- a/locked-asset/proxy_dex/meta/Cargo.toml +++ b/locked-asset/proxy_dex/meta/Cargo.toml @@ -10,7 +10,7 @@ publish = false path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/locked-asset/proxy_dex/src/lib.rs b/locked-asset/proxy_dex/src/lib.rs index d7e73dbee..6a7fc76c2 100644 --- a/locked-asset/proxy_dex/src/lib.rs +++ b/locked-asset/proxy_dex/src/lib.rs @@ -177,7 +177,7 @@ pub trait ProxyDexImpl: &self, token: TokenIdentifier, address: ManagedAddress, - #[var_args] roles: ManagedVarArgs, + #[var_args] roles: MultiValueEncoded, ) { self.send() .esdt_system_sc_proxy() diff --git a/locked-asset/proxy_dex/src/proxy_common.rs b/locked-asset/proxy_dex/src/proxy_common.rs index cdb10c79e..e1ef89ef1 100644 --- a/locked-asset/proxy_dex/src/proxy_common.rs +++ b/locked-asset/proxy_dex/src/proxy_common.rs @@ -73,8 +73,8 @@ pub trait ProxyCommonModule: token_send::TokenSendModule { fn intermediated_farms(&self) -> SetMapper; #[view(getIntermediatedFarms)] - fn get_intermediated_farms(&self) -> ManagedMultiResultVec { - let mut result = ManagedMultiResultVec::new(); + fn get_intermediated_farms(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); for pair in self.intermediated_farms().iter() { result.push(pair); } @@ -85,8 +85,8 @@ pub trait ProxyCommonModule: token_send::TokenSendModule { fn intermediated_pairs(&self) -> SetMapper; #[view(getIntermediatedPairs)] - fn get_intermediated_pairs(&self) -> ManagedMultiResultVec { - let mut result = ManagedMultiResultVec::new(); + fn get_intermediated_pairs(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); for pair in self.intermediated_pairs().iter() { result.push(pair); } diff --git a/locked-asset/proxy_dex/wasm/Cargo.toml b/locked-asset/proxy_dex/wasm/Cargo.toml index a3dbb3161..5c49cd7ec 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.toml +++ b/locked-asset/proxy_dex/wasm/Cargo.toml @@ -25,8 +25,8 @@ default-features = false path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = ["wasm-output-mode"] diff --git a/pair-mock/Cargo.toml b/pair-mock/Cargo.toml index 4ab888522..07b2ad650 100644 --- a/pair-mock/Cargo.toml +++ b/pair-mock/Cargo.toml @@ -12,10 +12,10 @@ path = "src/pair.rs" path = "../common/common_errors" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dependencies.itertools] version = "0.10.1" diff --git a/pair-mock/meta/Cargo.toml b/pair-mock/meta/Cargo.toml index 9791cc612..ed3604ad0 100644 --- a/pair-mock/meta/Cargo.toml +++ b/pair-mock/meta/Cargo.toml @@ -11,7 +11,7 @@ authors = [ "you",] path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/pair-mock/wasm/Cargo.toml b/pair-mock/wasm/Cargo.toml index 72f801955..8c90e2f0b 100644 --- a/pair-mock/wasm/Cargo.toml +++ b/pair-mock/wasm/Cargo.toml @@ -24,8 +24,8 @@ panic = "abort" path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = [ "wasm-output-mode",] diff --git a/price-discovery/Cargo.toml b/price-discovery/Cargo.toml index e17d981b5..42a2e3458 100644 --- a/price-discovery/Cargo.toml +++ b/price-discovery/Cargo.toml @@ -9,8 +9,7 @@ publish = false path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" -features = ["cb_closure_managed_deser"] +version = "0.29" [dependencies] hex-literal = "0.3.1" @@ -22,7 +21,7 @@ path = "../dex/pair" path = "../common/modules/token_merge" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" [dev-dependencies] num-bigint = "0.4.2" diff --git a/price-discovery/meta/Cargo.toml b/price-discovery/meta/Cargo.toml index 35d3e3d09..bf48019f0 100644 --- a/price-discovery/meta/Cargo.toml +++ b/price-discovery/meta/Cargo.toml @@ -9,7 +9,7 @@ authors = [ "Dorin Iancu " ] path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29" diff --git a/price-discovery/wasm/Cargo.toml b/price-discovery/wasm/Cargo.toml index 60fa30d0c..5cc9ae470 100644 --- a/price-discovery/wasm/Cargo.toml +++ b/price-discovery/wasm/Cargo.toml @@ -24,8 +24,8 @@ panic = "abort" path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29" features = [ "wasm-output-mode",] From c0d6dc876a5791f153398d91a2e022fc8a734308 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Tue, 8 Mar 2022 16:38:55 +0200 Subject: [PATCH 6/9] added test for multitoken --- dex/governance/src/lib.rs | 6 ++- dex/governance/tests/gov_tests.rs | 80 +++++++++++++++++++++++++++++++ pair-mock/src/pair.rs | 11 +++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/dex/governance/src/lib.rs b/dex/governance/src/lib.rs index 1b51210bc..c731369a6 100644 --- a/dex/governance/src/lib.rs +++ b/dex/governance/src/lib.rs @@ -18,6 +18,8 @@ mod price_provider_proxy { #[elrond_wasm::module] pub trait Lib: config::Config { fn get_vote_weight(&self, payment: &EsdtTokenPayment) -> BigUint { + let mex_token_id = self.mex_token_id().get(); + if payment.token_identifier == self.mex_token_id().get() { return payment.amount.clone(); } @@ -29,11 +31,11 @@ pub trait Lib: config::Config { .execute_on_dest_context_custom_range(|_, after| (after - 2, after)) .into_tuple(); - if payment.token_identifier == token1.token_identifier { + if token1.token_identifier == mex_token_id { return token1.amount; } - if payment.token_identifier == token2.token_identifier { + if token2.token_identifier == mex_token_id { return token2.amount; } } diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index df36d7b40..80ef16830 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -125,6 +125,16 @@ where MEX_TOKEN_ID, &rust_biguint!(USER_TOTAL_MEX_TOKENS), ); + blockchain_wrapper.set_esdt_balance( + &user_addr, + LPMEX_TOKEN_ID, + &rust_biguint!(USER_TOTAL_MEX_TOKENS), + ); + blockchain_wrapper.set_esdt_balance( + &owner_addr, + LPMEX_TOKEN_ID, + &rust_biguint!(USER_TOTAL_MEX_TOKENS), + ); blockchain_wrapper.set_esdt_balance( &user_addr, FAKE_TOKEN_ID, @@ -599,3 +609,73 @@ fn test_vote() { ) .assert_ok(); } + +#[test] +fn test_basic_propose_with_lpmex() { + let mut gov_setup = setup_gov(governance::contract_obj, pair_mock::contract_obj); + + // User makes a basic proposal + gov_setup + .blockchain_wrapper + .execute_esdt_transfer( + &gov_setup.owner_address, + &gov_setup.gov_wrapper, + LPMEX_TOKEN_ID, + 0, + &rust_biguint!(MIN_WEIGHT_FOR_PROPOSAL * 2), + |sc| { + sc.propose(ProposalCreationArgs { + description: managed_buffer!(&b""[..]), + actions: ManagedVec::from(Vec::>::new()), + }); + }, + ) + .assert_ok(); + + // Owner has to have its Vote NFT + let owner_address = gov_setup.owner_address.clone(); + gov_setup + .blockchain_wrapper + .execute_in_managed_environment(|| { + gov_setup.blockchain_wrapper.check_nft_balance( + &gov_setup.owner_address, + VOTE_NFT_ID, + 1, + &rust_biguint!(1), + &VoteNFTAttributes:: { + was_redeemed: false, + proposal_id: 0, + vote_type: VoteType::Upvote, + vote_weight: managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), + voter: managed_address!(&owner_address), + payment: EsdtTokenPayment::new( + managed_token_id!(LPMEX_TOKEN_ID), + 0, + managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL * 2), + ), + }, + ); + }); + + // SC Storage for proposal should be set correctly + gov_setup + .blockchain_wrapper + .execute_query(&gov_setup.gov_wrapper, |sc| { + let proposal = sc.proposal(0).get(); + + assert_eq!(0, proposal.id,); + assert_eq!(0, proposal.creation_block); + assert_eq!(managed_address!(&owner_address), proposal.proposer); + assert_eq!(0, proposal.description.len()); + assert_eq!(false, proposal.was_executed); + assert_eq!(0, proposal.actions.len()); + assert_eq!( + managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), + proposal.num_upvotes, + ); + assert_eq!(managed_biguint!(0), proposal.num_downvotes); + + assert_eq!(1, sc.proposal_id_counter().get()); + }) + .assert_ok(); +} diff --git a/pair-mock/src/pair.rs b/pair-mock/src/pair.rs index 328f081e7..ba7a4c45c 100644 --- a/pair-mock/src/pair.rs +++ b/pair-mock/src/pair.rs @@ -138,6 +138,17 @@ pub trait PairMock { )) } + #[endpoint(updateAndGetTokensForGivenPositionWithSafePrice)] + fn update_and_get_tokens_for_given_position_with_safe_price( + &self, + liquidity: BigUint, + ) -> MultiValue2, EsdtTokenPayment> { + MultiValue2::from(( + EsdtTokenPayment::new(self.first_token_id().get(), 0, liquidity.clone() / 2u64), + EsdtTokenPayment::new(self.second_token_id().get(), 0, liquidity.clone() / 2u64), + )) + } + #[storage_mapper("first_token_id")] fn first_token_id(&self) -> SingleValueMapper; From 0192b03686a27121b445533af20139fafd93c708 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Tue, 8 Mar 2022 16:58:01 +0200 Subject: [PATCH 7/9] fix build --- dex/farm-staking-contracts/metabonding-staking/Cargo.toml | 6 +++--- .../metabonding-staking/meta/Cargo.toml | 4 ++-- dex/farm-staking-contracts/metabonding-staking/src/lib.rs | 4 ++-- .../metabonding-staking/wasm/Cargo.toml | 4 ++-- dex/governance/src/contract.rs | 1 + pair-mock/src/pair.rs | 2 +- pair-mock/wasm/src/lib.rs | 1 + 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dex/farm-staking-contracts/metabonding-staking/Cargo.toml b/dex/farm-staking-contracts/metabonding-staking/Cargo.toml index b8ca05bfe..8ed9e262c 100644 --- a/dex/farm-staking-contracts/metabonding-staking/Cargo.toml +++ b/dex/farm-staking-contracts/metabonding-staking/Cargo.toml @@ -9,16 +9,16 @@ publish = false path = "src/lib.rs" [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29.0" [dependencies.elrond-wasm-modules] -version = "0.28.0" +version = "0.29.0" [dependencies.factory] path = "../../../locked-asset/factory" [dev-dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29.0" [dev-dependencies] num-bigint = "0.4.2" diff --git a/dex/farm-staking-contracts/metabonding-staking/meta/Cargo.toml b/dex/farm-staking-contracts/metabonding-staking/meta/Cargo.toml index 158e0b7ca..d430483b6 100644 --- a/dex/farm-staking-contracts/metabonding-staking/meta/Cargo.toml +++ b/dex/farm-staking-contracts/metabonding-staking/meta/Cargo.toml @@ -11,7 +11,7 @@ authors = [ "you",] path = ".." [dependencies.elrond-wasm] -version = "0.28.0" +version = "0.29.0" [dependencies.elrond-wasm-debug] -version = "0.28.0" +version = "0.29.0" diff --git a/dex/farm-staking-contracts/metabonding-staking/src/lib.rs b/dex/farm-staking-contracts/metabonding-staking/src/lib.rs index 0941eb28f..e7532f390 100644 --- a/dex/farm-staking-contracts/metabonding-staking/src/lib.rs +++ b/dex/farm-staking-contracts/metabonding-staking/src/lib.rs @@ -101,8 +101,8 @@ pub trait MetabondingStaking: locked_asset_token::LockedAssetTokenModule { } #[view(getSnapshot)] - fn get_snapshot(&self) -> ManagedMultiResultVec> { - let mut result = ManagedMultiResultVec::new(); + fn get_snapshot(&self) -> MultiValueEncoded> { + let mut result = MultiValueEncoded::new(); for user_address in self.user_list().iter() { let entry: StakingEntry = self.staking_entry_for_user(&user_address).get(); diff --git a/dex/farm-staking-contracts/metabonding-staking/wasm/Cargo.toml b/dex/farm-staking-contracts/metabonding-staking/wasm/Cargo.toml index f0121fab7..d0f816ed2 100644 --- a/dex/farm-staking-contracts/metabonding-staking/wasm/Cargo.toml +++ b/dex/farm-staking-contracts/metabonding-staking/wasm/Cargo.toml @@ -24,8 +24,8 @@ panic = "abort" path = ".." [dependencies.elrond-wasm-node] -version = "0.28.0" +version = "0.29.0" [dependencies.elrond-wasm-output] -version = "0.28.0" +version = "0.29.0" features = [ "wasm-output-mode",] diff --git a/dex/governance/src/contract.rs b/dex/governance/src/contract.rs index a59abb577..d268c9002 100644 --- a/dex/governance/src/contract.rs +++ b/dex/governance/src/contract.rs @@ -1,4 +1,5 @@ #![no_std] +#![allow(clippy::type_complexity)] #![feature(generic_associated_types)] use proposal::ProposalCreationArgs; diff --git a/pair-mock/src/pair.rs b/pair-mock/src/pair.rs index ba7a4c45c..704c191f1 100644 --- a/pair-mock/src/pair.rs +++ b/pair-mock/src/pair.rs @@ -145,7 +145,7 @@ pub trait PairMock { ) -> MultiValue2, EsdtTokenPayment> { MultiValue2::from(( EsdtTokenPayment::new(self.first_token_id().get(), 0, liquidity.clone() / 2u64), - EsdtTokenPayment::new(self.second_token_id().get(), 0, liquidity.clone() / 2u64), + EsdtTokenPayment::new(self.second_token_id().get(), 0, liquidity / 2u64), )) } diff --git a/pair-mock/wasm/src/lib.rs b/pair-mock/wasm/src/lib.rs index 4646342ec..708f36cf6 100644 --- a/pair-mock/wasm/src/lib.rs +++ b/pair-mock/wasm/src/lib.rs @@ -8,6 +8,7 @@ elrond_wasm_node::wasm_endpoints! { pair_mock ( addInitialLiquidity + updateAndGetTokensForGivenPositionWithSafePrice ) } From 98075b9ac13668331220a2aa72660fbc737bba46 Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Tue, 8 Mar 2022 17:50:40 +0200 Subject: [PATCH 8/9] burn vote nft --- dex/governance/src/contract.rs | 9 ++------- dex/governance/src/vote.rs | 12 ------------ dex/governance/tests/gov_tests.rs | 2 -- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/dex/governance/src/contract.rs b/dex/governance/src/contract.rs index d268c9002..be68b9ef6 100644 --- a/dex/governance/src/contract.rs +++ b/dex/governance/src/contract.rs @@ -125,19 +125,14 @@ pub trait Governance: let vote_nft_id = self.vote_nft_id().get(); require!(payment.token_identifier == vote_nft_id, BAD_TOKEN_ID); - let mut attr = self.get_vote_attr(&payment); - require!(!attr.was_redeemed, ALREADY_REDEEMED); - + let attr = self.get_vote_attr(&payment); let proposal = self.proposal(attr.proposal_id).get(); let pstat = self.get_proposal_status(&proposal); match pstat { ProposalStatus::Succeeded | ProposalStatus::Defeated | ProposalStatus::Executed => { - attr.was_redeemed = true; - self.update_vote_nft_attributes(&vote_nft_id, payment.token_nonce, &attr); - self.send_back(attr.payment); - self.send_back(payment); + self.burn_vote_nft(payment); } ProposalStatus::Active | ProposalStatus::Pending => { sc_panic!(VOTING_PERIOD_NOT_ENDED) diff --git a/dex/governance/src/vote.rs b/dex/governance/src/vote.rs index 7c1334302..2c9b3f396 100644 --- a/dex/governance/src/vote.rs +++ b/dex/governance/src/vote.rs @@ -11,7 +11,6 @@ pub enum VoteType { #[derive(TypeAbi, TopEncode, TopDecode, PartialEq, Debug)] pub struct VoteNFTAttributes { - pub was_redeemed: bool, pub proposal_id: u64, pub vote_type: VoteType, pub vote_weight: BigUint, @@ -31,7 +30,6 @@ pub trait VoteHelper: config::Config { let big_one = BigUint::from(1u64); let vote_nft_id = self.vote_nft_id().get(); let attr = VoteNFTAttributes { - was_redeemed: false, proposal_id, vote_type, vote_weight, @@ -52,16 +50,6 @@ pub trait VoteHelper: config::Config { EsdtTokenPayment::new(vote_nft_id, nonce, big_one) } - fn update_vote_nft_attributes( - &self, - vote_nft_id: &TokenIdentifier, - nonce: u64, - new_attr: &VoteNFTAttributes, - ) { - self.send() - .nft_update_attributes(vote_nft_id, nonce, new_attr); - } - fn get_vote_attr(&self, payment: &EsdtTokenPayment) -> VoteNFTAttributes { self.blockchain() .get_esdt_token_data( diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index 80ef16830..7b92c2e8e 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -237,7 +237,6 @@ fn test_basic_propose() { 1, &rust_biguint!(1), &VoteNFTAttributes:: { - was_redeemed: false, proposal_id: 0, vote_type: VoteType::Upvote, vote_weight: managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), @@ -643,7 +642,6 @@ fn test_basic_propose_with_lpmex() { 1, &rust_biguint!(1), &VoteNFTAttributes:: { - was_redeemed: false, proposal_id: 0, vote_type: VoteType::Upvote, vote_weight: managed_biguint!(MIN_WEIGHT_FOR_PROPOSAL), From cb914cb79c82b0f657a9201fef63be181e5573be Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Wed, 9 Mar 2022 10:58:39 +0200 Subject: [PATCH 9/9] fix after review --- dex/governance/src/config.rs | 10 +++++----- dex/governance/src/contract.rs | 8 ++++---- dex/governance/src/errors.rs | 6 +++--- dex/governance/src/validation.rs | 12 ++---------- dex/governance/tests/gov_tests.rs | 2 +- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/dex/governance/src/config.rs b/dex/governance/src/config.rs index 18a961177..410a07709 100644 --- a/dex/governance/src/config.rs +++ b/dex/governance/src/config.rs @@ -92,32 +92,32 @@ pub trait Config { for provider in price_providers.into_iter() { let tuple = provider.into_tuple(); require!(tuple.0.is_esdt(), INVALID_ESDT); - require!(!tuple.1.is_zero(), ZERO_VALUE); + require!(!tuple.1.is_zero(), ERROR_ZERO_VALUE); self.price_providers().insert(tuple.0, tuple.1); } } fn try_change_quorum(&self, new_value: BigUint) { - require!(new_value != 0u64, ZERO_VALUE); + require!(new_value != 0u64, ERROR_ZERO_VALUE); self.quorum().set(&new_value); } fn try_change_min_weight_for_proposal(&self, new_value: BigUint) { - require!(new_value != 0u64, ZERO_VALUE); + require!(new_value != 0u64, ERROR_ZERO_VALUE); self.min_weight_for_proposal().set(&new_value); } fn try_change_voting_delay_in_blocks(&self, new_value: u64) { - require!(new_value != 0, ZERO_VALUE); + require!(new_value != 0, ERROR_ZERO_VALUE); self.voting_delay_in_blocks().set(&new_value); } fn try_change_voting_period_in_blocks(&self, new_value: u64) { - require!(new_value != 0, ZERO_VALUE); + require!(new_value != 0, ERROR_ZERO_VALUE); self.voting_period_in_blocks().set(&new_value); } diff --git a/dex/governance/src/contract.rs b/dex/governance/src/contract.rs index be68b9ef6..b58fe7ab2 100644 --- a/dex/governance/src/contract.rs +++ b/dex/governance/src/contract.rs @@ -50,7 +50,7 @@ pub trait Governance: #[endpoint] fn propose(&self, args: ProposalCreationArgs) -> u64 { let payment = self.call_value().payment(); - self.require_is_accepted_payment_for_proposal(&payment); + self.require_is_accepted_payment(&payment); let vote_weight = self.get_vote_weight(&payment); let min_weight = self.min_weight_for_proposal().get(); @@ -101,10 +101,10 @@ pub trait Governance: require!(pstat == ProposalStatus::Active, PROPOSAL_NOT_ACTIVE); let payment = self.call_value().payment(); - self.require_is_accepted_payment_for_voting(&payment); + self.require_is_accepted_payment(&payment); let vote_weight = self.get_vote_weight(&payment); - require!(vote_weight != 0, ZERO_VALUE); + require!(vote_weight != 0, ERROR_ZERO_VALUE); match vote_type { VoteType::Upvote => proposal.num_upvotes += &vote_weight, @@ -123,7 +123,7 @@ pub trait Governance: let payment = self.call_value().payment(); let vote_nft_id = self.vote_nft_id().get(); - require!(payment.token_identifier == vote_nft_id, BAD_TOKEN_ID); + require!(payment.token_identifier == vote_nft_id, BAD_PAYMENT_TOKEN); let attr = self.get_vote_attr(&payment); let proposal = self.proposal(attr.proposal_id).get(); diff --git a/dex/governance/src/errors.rs b/dex/governance/src/errors.rs index 5a739b002..13fd2d97c 100644 --- a/dex/governance/src/errors.rs +++ b/dex/governance/src/errors.rs @@ -1,10 +1,10 @@ -pub const BAD_TOKEN_ID: &[u8] = b"bad payment token id"; +pub const BAD_PAYMENT_TOKEN: &[u8] = b"wrong token used as payment"; +pub const UNREGISTERED_TOKEN_ID: &[u8] = b"unregistered payment token id"; pub const PROPOSAL_NOT_ACTIVE: &[u8] = b"proposal not active"; pub const PROPOSAL_NOT_SUCCEEDED: &[u8] = b"proposal not succeeded"; pub const PROPOSAL_NOT_FOUND: &[u8] = b"proposal not found"; pub const NOT_ENOUGH_FUNDS_TO_PROPOSE: &[u8] = b"not enough funds to propose"; pub const VOTING_PERIOD_NOT_ENDED: &[u8] = b"voting period not ended"; -pub const ZERO_VALUE: &[u8] = b"value cannot be zero"; +pub const ERROR_ZERO_VALUE: &[u8] = b"value cannot be zero"; pub const INVALID_ESDT: &[u8] = b"invalid esdt"; pub const INVALID_CALLER_NOT_SELF: &[u8] = b"caller should be self"; -pub const ALREADY_REDEEMED: &[u8] = b"already redeemed"; diff --git a/dex/governance/src/validation.rs b/dex/governance/src/validation.rs index ce0a2c08d..947f57b78 100644 --- a/dex/governance/src/validation.rs +++ b/dex/governance/src/validation.rs @@ -5,19 +5,11 @@ use crate::errors::*; #[elrond_wasm::module] pub trait Validation: config::Config { - fn require_is_accepted_payment_for_proposal(&self, payment: &EsdtTokenPayment) { + fn require_is_accepted_payment(&self, payment: &EsdtTokenPayment) { require!( self.governance_token_ids() .contains(&payment.token_identifier), - BAD_TOKEN_ID - ); - } - - fn require_is_accepted_payment_for_voting(&self, payment: &EsdtTokenPayment) { - require!( - self.governance_token_ids() - .contains(&payment.token_identifier), - BAD_TOKEN_ID + UNREGISTERED_TOKEN_ID ); } } diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index 7b92c2e8e..fd8ef9c87 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -179,7 +179,7 @@ fn test_propose_bad_token() { }); }, ) - .assert_user_error(&String::from_utf8(BAD_TOKEN_ID.to_vec()).unwrap()); + .assert_user_error(&String::from_utf8(UNREGISTERED_TOKEN_ID.to_vec()).unwrap()); } #[test]