Skip to content

Commit e9e01f1

Browse files
Merge pull request #2115 from multiversx/governance-interactor
Governance interactor
2 parents 1410be3 + e6b584c commit e9e01f1

24 files changed

+1033
-56
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ members = [
2525
# "tools/plotter",
2626
"tools/interactor-system-func-calls/",
2727
"tools/interactor-delegation-func-calls/",
28+
"tools/interactor-governance-func-calls/",
2829
"tools/gas-schedule-generator",
2930

3031
"contracts/modules",

contracts/feature-tests/payable-features/interactor/src/payable_interactor.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ pub async fn payable_features_cli() {
1616

1717
let config = Config::load_config();
1818

19-
let mut basic_interact = PayableInteract::new(config).await;
19+
let mut payable_interact = PayableInteract::new(config).await;
2020

2121
let cli = payable_interactor_cli::InteractCli::parse();
2222
match &cli.command {
2323
Some(payable_interactor_cli::InteractCliCommand::Deploy) => {
24-
basic_interact.deploy().await;
24+
payable_interact.deploy().await;
2525
}
2626
Some(payable_interactor_cli::InteractCliCommand::AllTransfers) => {
27-
basic_interact.check_all_transfers().await;
27+
payable_interact.check_all_transfers().await;
2828
}
2929
Some(payable_interactor_cli::InteractCliCommand::MultiTransferWithOneEGLD) => {
30-
basic_interact
30+
payable_interact
3131
.check_multi_transfer_only_egld_transfer()
3232
.await;
3333
}
@@ -48,6 +48,9 @@ impl PayableInteract {
4848
.await
4949
.use_chain_simulator(config.use_chain_simulator());
5050

51+
interactor
52+
.set_current_dir_from_workspace("contracts/feature-tests/payable-features/interactor");
53+
5154
let sc_owner_address = interactor.register_wallet(test_wallets::heidi()).await;
5255
let wallet_address = interactor.register_wallet(test_wallets::ivan()).await;
5356

@@ -70,6 +73,7 @@ impl PayableInteract {
7073
.typed(payable_features_proxy::PayableFeaturesProxy)
7174
.init()
7275
.code(CODE_PATH)
76+
.code_metadata(CodeMetadata::UPGRADEABLE)
7377
.returns(ReturnsNewBech32Address)
7478
.run()
7579
.await;

framework/base/src/types/interaction/annotated/annotated_impl_big_uint.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ where
9292
}
9393
}
9494

95+
impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for u128
96+
where
97+
Env: TxEnv,
98+
{
99+
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
100+
BigUint::from(*self).to_display()
101+
}
102+
103+
fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
104+
BigUint::from(*self)
105+
}
106+
}
107+
95108
impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for i32
96109
where
97110
Env: TxEnv,

framework/base/src/types/interaction/markers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod governance_sc_address;
55
mod system_sc_address;
66
mod to_caller;
77
mod to_self;
8+
mod validator_sc_address;
89

910
pub use delegation_manager_address::DelegationManagerSCAddress;
1011
pub use esdt_system_sc_address::ESDTSystemSCAddress;
@@ -13,3 +14,4 @@ pub use governance_sc_address::GovernanceSystemSCAddress;
1314
pub use system_sc_address::SystemSCAddress;
1415
pub use to_caller::ToCaller;
1516
pub use to_self::ToSelf;
17+
pub use validator_sc_address::ValidatorSystemSCAddress;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use hex_literal::hex;
2+
use multiversx_chain_core::types::Address;
3+
use multiversx_sc_codec::{EncodeErrorHandler, TopEncode, TopEncodeOutput};
4+
5+
use crate::{
6+
abi::TypeAbiFrom,
7+
api::ManagedTypeApi,
8+
types::{AnnotatedValue, ManagedAddress, ManagedBuffer, TxEnv, TxTo, TxToSpecified},
9+
};
10+
11+
/// Address of the validator system smart contract.
12+
const VALIDATOR_SC_ADDRESS_BYTES: [u8; 32] =
13+
hex!("000000000000000000010000000000000000000000000000000000000001ffff");
14+
const VALIDATOR_SC_ADDRESS_BECH32: &str =
15+
"erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l";
16+
const VALIDATOR_SC_ADDRESS_ANNOTATION: &str =
17+
"bech32:erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l";
18+
19+
/// Indicates the system SC address, which is the same on any MultiversX blockchain.
20+
pub struct ValidatorSystemSCAddress;
21+
22+
impl ValidatorSystemSCAddress {
23+
pub fn to_managed_address<Api>(self) -> ManagedAddress<Api>
24+
where
25+
Api: ManagedTypeApi,
26+
{
27+
ManagedAddress::from(VALIDATOR_SC_ADDRESS_BYTES)
28+
}
29+
30+
pub fn to_address(&self) -> Address {
31+
VALIDATOR_SC_ADDRESS_BYTES.into()
32+
}
33+
34+
pub fn to_bech32_str(&self) -> &str {
35+
VALIDATOR_SC_ADDRESS_BECH32
36+
}
37+
38+
pub fn to_bech32_string(&self) -> alloc::string::String {
39+
VALIDATOR_SC_ADDRESS_BECH32.into()
40+
}
41+
}
42+
43+
impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for ValidatorSystemSCAddress
44+
where
45+
Env: TxEnv,
46+
{
47+
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
48+
ManagedBuffer::from(VALIDATOR_SC_ADDRESS_ANNOTATION)
49+
}
50+
51+
fn to_value(&self, _env: &Env) -> ManagedAddress<Env::Api> {
52+
ValidatorSystemSCAddress.to_managed_address()
53+
}
54+
}
55+
56+
impl<Env> TxTo<Env> for ValidatorSystemSCAddress where Env: TxEnv {}
57+
impl<Env> TxToSpecified<Env> for ValidatorSystemSCAddress where Env: TxEnv {}
58+
59+
impl TopEncode for ValidatorSystemSCAddress {
60+
fn top_encode_or_handle_err<O, H>(&self, output: O, h: H) -> Result<(), H::HandledErr>
61+
where
62+
O: TopEncodeOutput,
63+
H: EncodeErrorHandler,
64+
{
65+
VALIDATOR_SC_ADDRESS_BYTES.top_encode_or_handle_err(output, h)
66+
}
67+
}
68+
69+
impl<M> TypeAbiFrom<ValidatorSystemSCAddress> for ManagedAddress<M> where M: ManagedTypeApi {}
70+
71+
impl core::fmt::Display for ValidatorSystemSCAddress {
72+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73+
f.write_str(VALIDATOR_SC_ADDRESS_BECH32)
74+
}
75+
}

framework/base/src/types/interaction/system_proxy.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ mod governance_sc_proxy;
66
mod legacy_system_sc_proxy;
77
pub(crate) mod token_properties;
88
mod token_properties_result;
9+
mod validator_sc_proxy;
910

1011
pub use builtin_func_proxy::*;
1112
pub use delegation_manager_sc_proxy::*;
1213
pub use delegation_sc_proxy::*;
1314
pub use esdt_system_sc_proxy::{ESDTSystemSCProxy, ESDTSystemSCProxyMethods, IssueCall};
14-
pub use governance_sc_proxy::*;
15+
pub use governance_sc_proxy::{
16+
governance_config_result::GovernanceConfigResult, proposal_view_result::ProposalViewResult,
17+
GovernanceSCProxy, GovernanceSCProxyMethods,
18+
};
1519
pub use legacy_system_sc_proxy::ESDTSystemSmartContractProxy;
1620
pub use token_properties::*;
1721
pub use token_properties_result::TokenPropertiesResult;
22+
pub use validator_sc_proxy::*;

framework/base/src/types/interaction/system_proxy/delegation_manager_sc_proxy.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::types::{
2-
BigUint, EgldPayment, ManagedAddress, ManagedVec, NotPayable, ProxyArg, Tx, TxEnv, TxFrom,
3-
TxGas, TxProxyTrait, TxTo, TxTypedCall,
2+
BigUint, Egld, ManagedAddress, ManagedVec, NotPayable, ProxyArg, Tx, TxEgldValue, TxEnv,
3+
TxFrom, TxGas, TxProxyTrait, TxTo, TxTypedCall,
44
};
55

66
/// Proxy for the Delegation Manager smart contract.
@@ -39,17 +39,20 @@ where
3939
To: TxTo<Env>,
4040
Gas: TxGas<Env>,
4141
{
42+
/// Field "amount" requires at least 1250 EGLD.
4243
pub fn create_new_delegation_contract<
4344
Arg0: ProxyArg<BigUint<Env::Api>>,
4445
Arg1: ProxyArg<BigUint<Env::Api>>,
46+
EgldValue: TxEgldValue<Env>,
4547
>(
4648
self,
4749
total_delegation_cap: Arg0,
4850
service_fee: Arg1,
49-
) -> TxTypedCall<Env, From, To, EgldPayment<<Env as TxEnv>::Api>, Gas, ()> {
51+
amount: EgldValue,
52+
) -> TxTypedCall<Env, From, To, Egld<EgldValue>, Gas, ()> {
5053
self.wrapped_tx
5154
.raw_call("createNewDelegationContract")
52-
.egld(BigUint::from(1250000000000000000000u128))
55+
.egld(amount)
5356
.argument(&total_delegation_cap)
5457
.argument(&service_fee)
5558
.original_result()

framework/base/src/types/interaction/system_proxy/governance_sc_proxy.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
pub(super) mod governance_config_result;
2+
pub(super) mod proposal_view_result;
3+
14
use crate::types::{
2-
BigUint, ManagedAddress, ManagedBuffer, MultiValueEncoded, NotPayable, ProxyArg, Tx, TxEnv,
3-
TxFrom, TxGas, TxProxyTrait, TxTo, TxTypedCall,
5+
BigUint, EgldPayment, ManagedAddress, ManagedBuffer, MultiValueEncoded, NotPayable, ProxyArg,
6+
Tx, TxEnv, TxFrom, TxGas, TxProxyTrait, TxTo, TxTypedCall,
47
};
8+
use governance_config_result::GovernanceConfigResult;
9+
use proposal_view_result::ProposalViewResult;
510

611
/// Proxy for the Governance system smart contract.
712
pub struct GovernanceSCProxy;
@@ -38,13 +43,6 @@ where
3843
To: TxTo<Env>,
3944
Gas: TxGas<Env>,
4045
{
41-
pub fn init_v2(self) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
42-
self.wrapped_tx
43-
.payment(NotPayable)
44-
.raw_call("initV2")
45-
.original_result()
46-
}
47-
4846
pub fn proposal<
4947
Arg0: ProxyArg<ManagedBuffer<Env::Api>>,
5048
Arg1: ProxyArg<BigUint<Env::Api>>,
@@ -54,20 +52,17 @@ where
5452
commit_hash: Arg0,
5553
start_vote_epoch: Arg1,
5654
end_vote_epoch: Arg2,
57-
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
55+
) -> TxTypedCall<Env, From, To, EgldPayment<<Env as TxEnv>::Api>, Gas, ()> {
5856
self.wrapped_tx
59-
.payment(NotPayable)
6057
.raw_call("proposal")
6158
.argument(&commit_hash)
6259
.argument(&start_vote_epoch)
6360
.argument(&end_vote_epoch)
61+
.egld(BigUint::from(1_000_000_000_000_000_000_000u128))
6462
.original_result()
6563
}
6664

67-
pub fn vote<
68-
Arg0: ProxyArg<ManagedBuffer<Env::Api>>,
69-
Arg1: ProxyArg<ManagedBuffer<Env::Api>>,
70-
>(
65+
pub fn vote<Arg0: ProxyArg<BigUint<Env::Api>>, Arg1: ProxyArg<ManagedBuffer<Env::Api>>>(
7166
self,
7267
proposal_to_vote: Arg0,
7368
vote: Arg1,
@@ -81,7 +76,7 @@ where
8176
}
8277

8378
pub fn delegate_vote<
84-
Arg0: ProxyArg<ManagedBuffer<Env::Api>>,
79+
Arg0: ProxyArg<u64>,
8580
Arg1: ProxyArg<ManagedBuffer<Env::Api>>,
8681
Arg2: ProxyArg<ManagedAddress<Env::Api>>,
8782
Arg3: ProxyArg<BigUint<Env::Api>>,
@@ -162,7 +157,10 @@ where
162157
.original_result()
163158
}
164159

165-
pub fn view_config(self) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
160+
/// Note: values are returned as strings (base 10 representation).
161+
pub fn view_config(
162+
self,
163+
) -> TxTypedCall<Env, From, To, NotPayable, Gas, GovernanceConfigResult> {
166164
self.wrapped_tx
167165
.payment(NotPayable)
168166
.raw_call("viewConfig")
@@ -188,7 +186,7 @@ where
188186
pub fn view_proposal<Arg0: ProxyArg<BigUint<Env::Api>>>(
189187
self,
190188
nonce: Arg0,
191-
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
189+
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ProposalViewResult<Env::Api>> {
192190
self.wrapped_tx
193191
.payment(NotPayable)
194192
.raw_call("viewProposal")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use alloc::string::String;
2+
3+
use multiversx_sc_codec::{DecodeErrorHandler, TopDecodeMulti, TopDecodeMultiInput};
4+
5+
#[derive(Debug, Clone, Default)]
6+
pub struct GovernanceConfigResult {
7+
pub proposal_fee: String,
8+
pub lost_proposal_fee: String,
9+
pub min_quorum: String,
10+
pub min_veto_threshold: String,
11+
pub min_pass_threshold: String,
12+
pub last_proposal_nonce: u64,
13+
}
14+
15+
impl TopDecodeMulti for GovernanceConfigResult {
16+
fn multi_decode_or_handle_err<I, H>(input: &mut I, h: H) -> Result<Self, H::HandledErr>
17+
where
18+
I: TopDecodeMultiInput,
19+
H: DecodeErrorHandler,
20+
{
21+
let proposal_fee = String::multi_decode_or_handle_err(input, h)?;
22+
let lost_proposal_fee = String::multi_decode_or_handle_err(input, h)?;
23+
let min_quorum = String::multi_decode_or_handle_err(input, h)?;
24+
let min_veto_threshold = String::multi_decode_or_handle_err(input, h)?;
25+
let min_pass_threshold = String::multi_decode_or_handle_err(input, h)?;
26+
let last_proposal_nonce = u64::multi_decode_or_handle_err(input, h)?;
27+
Ok(GovernanceConfigResult {
28+
proposal_fee,
29+
lost_proposal_fee,
30+
min_quorum,
31+
min_veto_threshold,
32+
min_pass_threshold,
33+
last_proposal_nonce,
34+
})
35+
}
36+
}

0 commit comments

Comments
 (0)