From 895906e6181ccd60cc7b047df9f9fdaa07bde717 Mon Sep 17 00:00:00 2001 From: SilkovAlexander Date: Mon, 2 Nov 2020 18:45:04 +0300 Subject: [PATCH 1/4] Updated functionality to work with the last depool contract --- src/config.rs | 15 +++++ src/depool.rs | 72 +++++++++++++---------- src/depool_abi.rs | 143 +++++++++++++++++++++++++--------------------- src/main.rs | 6 +- 4 files changed, 138 insertions(+), 98 deletions(-) diff --git a/src/config.rs b/src/config.rs index 7d97de4e..2200cddf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,10 @@ fn default_retries() -> u8 { 5 } +fn default_depool_fee() -> f32 { + 0.5 +} + fn default_timeout() -> u32 { 60000 } @@ -45,6 +49,8 @@ pub struct Config { pub timeout: u32, #[serde(default = "default_false")] pub is_json: bool, + #[serde(default = "default_depool_fee")] + pub depool_fee: f32, } impl Config { @@ -59,6 +65,7 @@ impl Config { retries: default_retries(), timeout: default_timeout(), is_json: default_false(), + depool_fee: default_depool_fee(), } } @@ -80,6 +87,7 @@ pub fn set_config( wc: Option<&str>, retries: Option<&str>, timeout: Option<&str>, + depool_fee: Option<&str>, ) -> Result<(), String> { if let Some(s) = url { conf.url = s.to_string(); @@ -108,6 +116,13 @@ pub fn set_config( conf.wc = i32::from_str_radix(wc, 10) .map_err(|e| format!(r#"failed to parse "workchain id": {}"#, e))?; } + if let Some(depool_fee) = depool_fee { + conf.depool_fee = depool_fee.parse::() + .map_err(|e| format!(r#"failed to parse "depool_fee": {}"#, e))?; + } + if conf.depool_fee < 0.5 { + return Err("Minimal value for depool fee is 0.5".to_string()); + } let conf_str = serde_json::to_string(&conf) .map_err(|_| "failed to serialize config object".to_string())?; diff --git a/src/depool.rs b/src/depool.rs index 3488aeb1..306f6220 100644 --- a/src/depool.rs +++ b/src/depool.rs @@ -32,7 +32,7 @@ pub fn create_depool_command<'a, 'b>() -> App<'a, 'b> { .takes_value(true) .long("--value") .short("-v") - .help("Stake value."); + .help("Value in tons."); let keys_arg = Arg::with_name("SIGN") .takes_value(true) .long("--sign") @@ -53,9 +53,6 @@ pub fn create_depool_command<'a, 'b>() -> App<'a, 'b> { .long("--beneficiary") .short("-b") .help("Smart contract address which will own lock stake rewards."); - let reinvest_arg = Arg::with_name("AUTORESUME") - .long("--autoresume-off") - .help("Disables autoresume flag for participant. In this case stake will be invested only to one round."); let dest_arg = Arg::with_name("DEST") .takes_value(true) .long("--dest") @@ -76,8 +73,7 @@ pub fn create_depool_command<'a, 'b>() -> App<'a, 'b> { .setting(AppSettings::AllowLeadingHyphen) .arg(wallet_arg.clone()) .arg(value_arg.clone()) - .arg(keys_arg.clone()) - .arg(reinvest_arg)) + .arg(keys_arg.clone())) .subcommand(SubCommand::with_name("vesting") .about("Deposits vesting stake in depool from multisignature wallet.") .setting(AppSettings::AllowLeadingHyphen) @@ -150,12 +146,14 @@ struct CommandData<'a> { wallet: String, keys: String, stake: &'a str, + depool_fee: String, } impl<'a> CommandData<'a> { pub fn from_matches_and_conf(m: &'a ArgMatches, conf: Config, depool: String) -> Result { let (wallet, stake, keys) = parse_stake_data(m, &conf)?; - Ok(CommandData {conf, depool, wallet, stake, keys}) + let depool_fee = conf.depool_fee.clone().to_string(); + Ok(CommandData {conf, depool, wallet, stake, keys, depool_fee}) } } @@ -331,11 +329,9 @@ fn ordinary_stake_command<'a>( m: &ArgMatches, cmd: CommandData ) -> Result<(), String> { - let disable_reinvest = m.is_present("AUTORESUME"); - let autoresume = Some(if disable_reinvest { "false" } else { "true" }); let (depool, wallet, stake, keys) = (Some(&cmd.depool), Some(&cmd.wallet), Some(cmd.stake), Some(&cmd.keys)); - print_args!(m, depool, wallet, stake, keys, autoresume); - add_ordinary_stake(cmd, !disable_reinvest) + print_args!(m, depool, wallet, stake, keys); + add_ordinary_stake(cmd) } fn replenish_command<'a>( @@ -421,12 +417,16 @@ fn set_withdraw_command( set_withdraw(conf, depool.unwrap(), wallet.unwrap(), keys.unwrap(), enable) } -fn add_ordinary_stake( +fn add_ordinary_stake( cmd: CommandData, - autoresume: bool, ) -> Result<(), String> { - let body = encode_add_ordinary_stake(autoresume)?; - send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, cmd.stake, &cmd.keys, &body) + let stake = u64::from_str_radix(&convert::convert_token(cmd.stake)?, 10) + .map_err(|e| format!(r#"failed to parse stake value: {}"#, e))?; + let body = encode_add_ordinary_stake(stake)?; + let fee = u64::from_str_radix(&convert::convert_token(&cmd.depool_fee)?, 10) + .map_err(|e| format!(r#"failed to parse depool fee value: {}"#, e))?; + let value = (fee + stake) as f64 * 1.0 / 1e9; + send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, &format!("{}", value), &cmd.keys, &body) } fn replenish_stake( @@ -444,12 +444,17 @@ fn add_exotic_stake( is_vesting: bool, ) -> Result<(), String> { load_ton_address(beneficiary)?; + let stake = u64::from_str_radix(&convert::convert_token(cmd.stake)?, 10) + .map_err(|e| format!(r#"failed to parse stake value: {}"#, e))?; let body = if is_vesting { - encode_add_vesting_stake(beneficiary, tp, wp)? + encode_add_vesting_stake(stake, beneficiary, tp, wp)? } else { - encode_add_lock_stake(beneficiary, tp, wp)? + encode_add_lock_stake(stake, beneficiary, tp, wp)? }; - send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, cmd.stake, &cmd.keys, &body) + let fee = u64::from_str_radix(&convert::convert_token(&cmd.depool_fee)?, 10) + .map_err(|e| format!(r#"failed to parse depool fee value: {}"#, e))?; + let value = (fee + stake) as f64 * 1.0 / 1e9; + send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, &format!("{}", value), &cmd.keys, &body) } fn remove_stake( @@ -459,7 +464,7 @@ fn remove_stake( &convert::convert_token(cmd.stake)?, 10, ).unwrap(); let body = encode_remove_stake(stake)?; - send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, "0.05", &cmd.keys, &body) + send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, &cmd.depool_fee, &cmd.keys, &body) } fn withdraw_stake( @@ -469,7 +474,7 @@ fn withdraw_stake( &convert::convert_token(cmd.stake)?, 10, ).unwrap(); let body = encode_withdraw_stake(stake)?; - send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, "0.05", &cmd.keys, &body) + send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, &cmd.depool_fee, &cmd.keys, &body) } fn transfer_stake(cmd: CommandData, dest: &str) -> Result<(), String> { @@ -478,7 +483,7 @@ fn transfer_stake(cmd: CommandData, dest: &str) -> Result<(), String> { &convert::convert_token(cmd.stake)?, 10, ).unwrap(); let body = encode_transfer_stake(dest, stake)?; - send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, "0.135", &cmd.keys, &body) + send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, &cmd.depool_fee, &cmd.keys, &body) } fn set_withdraw( @@ -489,7 +494,8 @@ fn set_withdraw( enable: bool, ) -> Result<(), String> { let body = encode_set_withdraw(enable)?; - send_with_body(conf, wallet, depool, "0.03", keys, &body) + let value = conf.depool_fee.clone().to_string(); + send_with_body(conf, wallet, depool, &value, keys, &body) } fn encode_body(func: &str, params: serde_json::Value) -> Result { @@ -514,14 +520,16 @@ fn encode_body(func: &str, params: serde_json::Value) -> Result } fn encode_set_withdraw(flag: bool) -> Result { - encode_body("withdrawAllAfterCompleting", json!({ - "doWithdrawAll": flag - })) + if flag { + encode_body("withdrawAll", json!({})) + } else { + encode_body("cancelWithdrawal", json!({})) + } } -fn encode_add_ordinary_stake(reinvest: bool) -> Result { +fn encode_add_ordinary_stake(stake: u64) -> Result { encode_body("addOrdinaryStake", json!({ - "reinvest": reinvest + "stake": stake })) } @@ -530,16 +538,18 @@ fn encode_replenish_stake() -> Result { })) } -fn encode_add_vesting_stake(beneficiary: &str, tperiod: u32, wperiod: u32) -> Result { +fn encode_add_vesting_stake(stake: u64, beneficiary: &str, tperiod: u32, wperiod: u32) -> Result { encode_body("addVestingStake", json!({ + "stake": stake, "beneficiary": beneficiary, "withdrawalPeriod": wperiod, "totalPeriod": tperiod })) } -fn encode_add_lock_stake(beneficiary: &str, tperiod: u32, wperiod: u32) -> Result { +fn encode_add_lock_stake(stake: u64, beneficiary: &str, tperiod: u32, wperiod: u32) -> Result { encode_body("addLockStake", json!({ + "stake": stake, "beneficiary": beneficiary, "withdrawalPeriod": wperiod, "totalPeriod": tperiod @@ -547,13 +557,13 @@ fn encode_add_lock_stake(beneficiary: &str, tperiod: u32, wperiod: u32) -> Resul } fn encode_remove_stake(target_value: u64) -> Result { - encode_body("removeOrdinaryStake", json!({ + encode_body("withdrawFromPoolingRound", json!({ "withdrawValue": target_value })) } fn encode_withdraw_stake(target_value: u64) -> Result { - encode_body("withdrawPartAfterCompleting", json!({ + encode_body("withdrawPart", json!({ "withdrawValue": target_value })) } diff --git a/src/depool_abi.rs b/src/depool_abi.rs index 7947d70b..2f5ca34a 100644 --- a/src/depool_abi.rs +++ b/src/depool_abi.rs @@ -19,74 +19,28 @@ { "name": "constructor", "inputs": [ - {"name":"minRoundStake","type":"uint64"}, - {"name":"proxy0","type":"address"}, - {"name":"proxy1","type":"address"}, - {"name":"validatorWallet","type":"address"}, - {"name":"minStake","type":"uint64"} - ], - "outputs": [ - ] - }, - { - "name": "getParticipantInfo", - "inputs": [ - {"name":"addr","type":"address"} - ], - "outputs": [ - {"name":"total","type":"uint64"}, - {"name":"withdrawValue","type":"uint64"}, - {"name":"reinvest","type":"bool"}, - {"name":"reward","type":"uint64"}, - {"name":"stakes","type":"map(uint64,uint64)"}, - {"components":[{"name":"isActive","type":"bool"},{"name":"amount","type":"uint64"},{"name":"lastWithdrawalTime","type":"uint64"},{"name":"withdrawalPeriod","type":"uint32"},{"name":"withdrawalValue","type":"uint64"},{"name":"owner","type":"address"}],"name":"vestings","type":"map(uint64,tuple)"}, - {"components":[{"name":"isActive","type":"bool"},{"name":"amount","type":"uint64"},{"name":"lastWithdrawalTime","type":"uint64"},{"name":"withdrawalPeriod","type":"uint32"},{"name":"withdrawalValue","type":"uint64"},{"name":"owner","type":"address"}],"name":"locks","type":"map(uint64,tuple)"} - ] - }, - { - "name": "getDePoolInfo", - "inputs": [ - ], - "outputs": [ {"name":"minStake","type":"uint64"}, - {"name":"minRoundStake","type":"uint64"}, - {"name":"minValidatorStake","type":"uint64"}, + {"name":"validatorAssurance","type":"uint64"}, + {"name":"proxyCode","type":"cell"}, {"name":"validatorWallet","type":"address"}, - {"name":"proxies","type":"address[]"}, - {"name":"poolClosed","type":"bool"}, - {"name":"interest","type":"uint64"}, - {"name":"addStakeFee","type":"uint64"}, - {"name":"addVestingOrLockFee","type":"uint64"}, - {"name":"removeOrdinaryStakeFee","type":"uint64"}, - {"name":"withdrawPartAfterCompletingFee","type":"uint64"}, - {"name":"withdrawAllAfterCompletingFee","type":"uint64"}, - {"name":"transferStakeFee","type":"uint64"}, - {"name":"retOrReinvFee","type":"uint64"}, - {"name":"answerMsgFee","type":"uint64"}, - {"name":"proxyFee","type":"uint64"}, - {"name":"participantFraction","type":"uint64"}, - {"name":"validatorFraction","type":"uint64"}, - {"name":"validatorWalletMinStake","type":"uint64"} - ] - }, - { - "name": "getParticipants", - "inputs": [ + {"name":"association","type":"address"}, + {"name":"participantRewardFraction","type":"uint8"}, + {"name":"validatorRewardFraction","type":"uint8"}, + {"name":"balanceThreshold","type":"uint64"} ], "outputs": [ - {"name":"participants","type":"address[]"} ] }, { "name": "addOrdinaryStake", "inputs": [ - {"name":"reinvest","type":"bool"} + {"name":"stake","type":"uint64"} ], "outputs": [ ] }, { - "name": "removeOrdinaryStake", + "name": "withdrawFromPoolingRound", "inputs": [ {"name":"withdrawValue","type":"uint64"} ], @@ -96,6 +50,7 @@ { "name": "addVestingStake", "inputs": [ + {"name":"stake","type":"uint64"}, {"name":"beneficiary","type":"address"}, {"name":"withdrawalPeriod","type":"uint32"}, {"name":"totalPeriod","type":"uint32"} @@ -106,6 +61,7 @@ { "name": "addLockStake", "inputs": [ + {"name":"stake","type":"uint64"}, {"name":"beneficiary","type":"address"}, {"name":"withdrawalPeriod","type":"uint32"}, {"name":"totalPeriod","type":"uint32"} @@ -114,7 +70,7 @@ ] }, { - "name": "withdrawPartAfterCompleting", + "name": "withdrawPart", "inputs": [ {"name":"withdrawValue","type":"uint64"} ], @@ -122,9 +78,15 @@ ] }, { - "name": "withdrawAllAfterCompleting", + "name": "withdrawAll", + "inputs": [ + ], + "outputs": [ + ] + }, + { + "name": "cancelWithdrawal", "inputs": [ - {"name":"doWithdrawAll","type":"bool"} ], "outputs": [ ] @@ -229,12 +191,55 @@ "outputs": [ ] }, + { + "name": "getParticipantInfo", + "inputs": [ + {"name":"addr","type":"address"} + ], + "outputs": [ + {"name":"total","type":"uint64"}, + {"name":"withdrawValue","type":"uint64"}, + {"name":"reinvest","type":"bool"}, + {"name":"reward","type":"uint64"}, + {"name":"stakes","type":"map(uint64,uint64)"}, + {"components":[{"name":"amount","type":"uint64"},{"name":"lastWithdrawalTime","type":"uint64"},{"name":"withdrawalPeriod","type":"uint32"},{"name":"withdrawalValue","type":"uint64"},{"name":"owner","type":"address"}],"name":"vestings","type":"map(uint64,tuple)"}, + {"components":[{"name":"amount","type":"uint64"},{"name":"lastWithdrawalTime","type":"uint64"},{"name":"withdrawalPeriod","type":"uint32"},{"name":"withdrawalValue","type":"uint64"},{"name":"owner","type":"address"}],"name":"locks","type":"map(uint64,tuple)"} + ] + }, + { + "name": "getDePoolInfo", + "inputs": [ + ], + "outputs": [ + {"name":"poolClosed","type":"bool"}, + {"name":"minStake","type":"uint64"}, + {"name":"validatorAssurance","type":"uint64"}, + {"name":"participantRewardFraction","type":"uint8"}, + {"name":"validatorRewardFraction","type":"uint8"}, + {"name":"associationRewardFraction","type":"uint8"}, + {"name":"association","type":"address"}, + {"name":"balanceThreshold","type":"uint64"}, + {"name":"validatorWallet","type":"address"}, + {"name":"proxies","type":"address[]"}, + {"name":"stakeFee","type":"uint64"}, + {"name":"retOrReinvFee","type":"uint64"}, + {"name":"proxyFee","type":"uint64"} + ] + }, + { + "name": "getParticipants", + "inputs": [ + ], + "outputs": [ + {"name":"participants","type":"address[]"} + ] + }, { "name": "getRounds", "inputs": [ ], "outputs": [ - {"components":[{"name":"id","type":"uint64"},{"name":"supposedElectedAt","type":"uint32"},{"name":"unfreeze","type":"uint32"},{"name":"step","type":"uint8"},{"name":"completionReason","type":"uint8"},{"name":"participantQty","type":"uint32"},{"name":"stake","type":"uint64"},{"name":"rewards","type":"uint64"},{"name":"unused","type":"uint64"},{"name":"start","type":"uint64"},{"name":"end","type":"uint64"},{"name":"vsetHash","type":"uint256"}],"name":"rounds","type":"map(uint64,tuple)"} + {"components":[{"name":"id","type":"uint64"},{"name":"supposedElectedAt","type":"uint32"},{"name":"unfreeze","type":"uint32"},{"name":"stakeHeldFor","type":"uint32"},{"name":"vsetHashInElectionPhase","type":"uint256"},{"name":"step","type":"uint8"},{"name":"completionReason","type":"uint8"},{"name":"stake","type":"uint64"},{"name":"recoveredStake","type":"uint64"},{"name":"unused","type":"uint64"},{"name":"isValidatorStakeCompleted","type":"bool"},{"name":"rewards","type":"uint64"},{"name":"participantQty","type":"uint32"},{"name":"validatorStake","type":"uint64"},{"name":"validatorRemainingStake","type":"uint64"},{"name":"handledStakesAndRewards","type":"uint64"}],"name":"rounds","type":"map(uint64,tuple)"} ] } ], @@ -242,14 +247,14 @@ ], "events": [ { - "name": "dePoolPoolClosed", + "name": "DePoolClosed", "inputs": [ ], "outputs": [ ] }, { - "name": "roundStakeIsAccepted", + "name": "RoundStakeIsAccepted", "inputs": [ {"name":"queryId","type":"uint64"}, {"name":"comment","type":"uint32"} @@ -258,7 +263,7 @@ ] }, { - "name": "roundStakeIsRejected", + "name": "RoundStakeIsRejected", "inputs": [ {"name":"queryId","type":"uint64"}, {"name":"comment","type":"uint32"} @@ -267,7 +272,7 @@ ] }, { - "name": "proxyHasRejectedTheStake", + "name": "ProxyHasRejectedTheStake", "inputs": [ {"name":"queryId","type":"uint64"} ], @@ -275,7 +280,7 @@ ] }, { - "name": "proxyHasRejectedRecoverRequest", + "name": "ProxyHasRejectedRecoverRequest", "inputs": [ {"name":"roundId","type":"uint64"} ], @@ -285,19 +290,27 @@ { "name": "RoundCompleted", "inputs": [ - {"components":[{"name":"id","type":"uint64"},{"name":"supposedElectedAt","type":"uint32"},{"name":"unfreeze","type":"uint32"},{"name":"step","type":"uint8"},{"name":"completionReason","type":"uint8"},{"name":"participantQty","type":"uint32"},{"name":"stake","type":"uint64"},{"name":"rewards","type":"uint64"},{"name":"unused","type":"uint64"},{"name":"start","type":"uint64"},{"name":"end","type":"uint64"},{"name":"vsetHash","type":"uint256"}],"name":"round","type":"tuple"} + {"components":[{"name":"id","type":"uint64"},{"name":"supposedElectedAt","type":"uint32"},{"name":"unfreeze","type":"uint32"},{"name":"stakeHeldFor","type":"uint32"},{"name":"vsetHashInElectionPhase","type":"uint256"},{"name":"step","type":"uint8"},{"name":"completionReason","type":"uint8"},{"name":"stake","type":"uint64"},{"name":"recoveredStake","type":"uint64"},{"name":"unused","type":"uint64"},{"name":"isValidatorStakeCompleted","type":"bool"},{"name":"rewards","type":"uint64"},{"name":"participantQty","type":"uint32"},{"name":"validatorStake","type":"uint64"},{"name":"validatorRemainingStake","type":"uint64"},{"name":"handledStakesAndRewards","type":"uint64"}],"name":"round","type":"tuple"} ], "outputs": [ ] }, { - "name": "stakeSigningRequested", + "name": "StakeSigningRequested", "inputs": [ {"name":"electionId","type":"uint32"}, {"name":"proxy","type":"address"} ], "outputs": [ ] + }, + { + "name": "TooLowDePoolBalance", + "inputs": [ + {"name":"replenishment","type":"uint256"} + ], + "outputs": [ + ] } ] } diff --git a/src/main.rs b/src/main.rs index 124aca57..6a96a8ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -249,6 +249,7 @@ fn main_internal() -> Result <(), String> { (@arg RETRIES: --retries +takes_value "Number of attempts to call smart contract function if previous attempt was unsuccessful.") (@arg TIMEOUT: --timeout +takes_value "Contract call timeout in ms.") (@arg LIST: --list conflicts_with[URL ABI KEYS ADDR RETRIES TIMEOUT WC] "Prints all config parameters.") + (@arg DEPOOL_FEE: --depool_fee +takes_value "Value added to message sent to depool to cover it's fees (change will be returned).") ) (@subcommand account => (@setting AllowLeadingHyphen) @@ -609,8 +610,9 @@ fn config_command(matches: &ArgMatches, config: Config) -> Result<(), String> { let wc = matches.value_of("WC"); let retries = matches.value_of("RETRIES"); let timeout = matches.value_of("TIMEOUT"); - print_args!(matches, url, address, wallet, keys, abi, wc, retries, timeout); - set_config(config, "tonlabs-cli.conf.json", url, address, wallet, abi, keys, wc, retries, timeout) + let depool_fee = matches.value_of("DEPOOL_FEE"); + print_args!(matches, url, address, wallet, keys, abi, wc, retries, timeout, depool_fee); + set_config(config, "tonlabs-cli.conf.json", url, address, wallet, abi, keys, wc, retries, timeout, depool_fee) } } From 4735d7cb88be59dedc4ff2fcdf507dfeba7bebdd Mon Sep 17 00:00:00 2001 From: SilkovAlexander Date: Mon, 2 Nov 2020 18:51:40 +0300 Subject: [PATCH 2/4] Increased version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2b687492..ba45eff0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" license = "Apache-2.0" keywords = ["TON", "SDK", "smart contract", "tonlabs", "solidity"] edition = "2018" -version = "0.1.24" +version = "0.1.25" [dependencies] base64 = "0.10.1" From 19d5d086d4200b899592fe27eb4be0e942486d8b Mon Sep 17 00:00:00 2001 From: SilkovAlexander Date: Wed, 4 Nov 2020 15:49:00 +0300 Subject: [PATCH 3/4] Updated depool abi --- src/depool_abi.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/depool_abi.rs b/src/depool_abi.rs index 2f5ca34a..459ad7e2 100644 --- a/src/depool_abi.rs +++ b/src/depool_abi.rs @@ -23,9 +23,7 @@ {"name":"validatorAssurance","type":"uint64"}, {"name":"proxyCode","type":"cell"}, {"name":"validatorWallet","type":"address"}, - {"name":"association","type":"address"}, {"name":"participantRewardFraction","type":"uint8"}, - {"name":"validatorRewardFraction","type":"uint8"}, {"name":"balanceThreshold","type":"uint64"} ], "outputs": [ @@ -191,6 +189,13 @@ "outputs": [ ] }, + { + "name": "getLastRoundInfo", + "inputs": [ + ], + "outputs": [ + ] + }, { "name": "getParticipantInfo", "inputs": [ @@ -216,8 +221,6 @@ {"name":"validatorAssurance","type":"uint64"}, {"name":"participantRewardFraction","type":"uint8"}, {"name":"validatorRewardFraction","type":"uint8"}, - {"name":"associationRewardFraction","type":"uint8"}, - {"name":"association","type":"address"}, {"name":"balanceThreshold","type":"uint64"}, {"name":"validatorWallet","type":"address"}, {"name":"proxies","type":"address[]"}, From 36233d3181f6eefb6b0d0d38c1f237e4e0797636 Mon Sep 17 00:00:00 2001 From: SilkovAlexander Date: Thu, 5 Nov 2020 13:33:09 +0300 Subject: [PATCH 4/4] Added ticktock subcommand to call depools function --- src/depool.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/depool.rs b/src/depool.rs index 306f6220..dd4282b5 100644 --- a/src/depool.rs +++ b/src/depool.rs @@ -117,6 +117,11 @@ pub fn create_depool_command<'a, 'b>() -> App<'a, 'b> { .arg(wallet_arg.clone()) .arg(value_arg.clone()) .arg(keys_arg.clone())) + .subcommand(SubCommand::with_name("ticktock") + .about("Call DePool 'ticktock()' function to update its state. 1 ton is attached to this call (change will be returned).") + .setting(AppSettings::AllowLeadingHyphen) + .arg(wallet_arg.clone()) + .arg(keys_arg.clone())) .subcommand(SubCommand::with_name("withdraw") .about("Allows to disable auto investment of the stake into next round and withdraw all the stakes after round completion.") .setting(AppSettings::AllowLeadingHyphen) @@ -236,6 +241,10 @@ pub fn depool_command(m: &ArgMatches, conf: Config) -> Result<(), String> { CommandData::from_matches_and_conf(m, conf, depool)?, ); } + if let Some(m) = m.subcommand_matches("ticktock") { + let (wallet, keys) = parse_wallet_data(&m, &conf)?; + return ticktock_command(m, conf, &depool, &wallet, &keys); + } Err("unknown depool command".to_owned()) } @@ -343,6 +352,18 @@ fn replenish_command<'a>( replenish_stake(cmd) } +fn ticktock_command<'a>( + m: &ArgMatches, + conf: Config, + depool: &str, + wallet: &str, + keys: &str, +) -> Result<(), String> { + let (depool, wallet, keys) = (Some(depool), Some(wallet), Some(keys)); + print_args!(m, depool, wallet, keys); + call_ticktock(conf, depool.unwrap(), wallet.unwrap(), keys.unwrap()) +} + fn transfer_stake_command<'a>( m: &ArgMatches, cmd: CommandData @@ -436,6 +457,16 @@ fn replenish_stake( send_with_body(cmd.conf, &cmd.wallet, &cmd.depool, cmd.stake, &cmd.keys, &body) } +fn call_ticktock( + conf: Config, + depool: &str, + wallet: &str, + keys: &str, +) -> Result<(), String> { + let body = encode_ticktock()?; + send_with_body(conf, wallet, depool, "1", keys, &body) +} + fn add_exotic_stake( cmd: CommandData, beneficiary: &str, @@ -538,6 +569,11 @@ fn encode_replenish_stake() -> Result { })) } +fn encode_ticktock() -> Result { + encode_body("ticktock", json!({ + })) +} + fn encode_add_vesting_stake(stake: u64, beneficiary: &str, tperiod: u32, wperiod: u32) -> Result { encode_body("addVestingStake", json!({ "stake": stake,