Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Add support for vesting contract #4786

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion crates/aptos/src/stake/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::common::types::{
CliCommand, CliResult, CliTypedResult, TransactionOptions, TransactionSummary,
};
use crate::common::utils::prompt_yes_with_override;
use aptos_types::account_address::{default_stake_pool_address, AccountAddress};
use aptos_types::account_address::{
create_vesting_contract_address, default_stake_pool_address, AccountAddress,
};
use async_trait::async_trait;
use cached_packages::aptos_stdlib;
use clap::Parser;
Expand All @@ -22,6 +24,8 @@ pub enum StakeTool {
InitializeStakeOwner(InitializeStakeOwner),
SetOperator(SetOperator),
SetDelegatedVoter(SetDelegatedVoter),
UnlockVestedCoins(UnlockVestedCoins),
DistributeVestedCoins(DistributeVestedCoins),
}

impl StakeTool {
Expand All @@ -36,6 +40,8 @@ impl StakeTool {
InitializeStakeOwner(tool) => tool.execute_serialized().await,
SetOperator(tool) => tool.execute_serialized().await,
SetDelegatedVoter(tool) => tool.execute_serialized().await,
UnlockVestedCoins(tool) => tool.execute_serialized().await,
DistributeVestedCoins(tool) => tool.execute_serialized().await,
}
}
}
Expand Down Expand Up @@ -297,3 +303,65 @@ impl CliCommand<TransactionSummary> for CreateStakingContract {
.map(|inner| inner.into())
}
}

/// Distribute any fully unlocked tokens (rewards and/or vested tokens) from the vesting contract
/// to shareholders.
#[derive(Parser)]
pub struct DistributeVestedCoins {
/// Address of the vesting contract's admin.
///
/// Defaults to the profile's address if not set.
#[clap(long, parse(try_from_str=crate::common::types::load_account_arg))]
pub admin_address: AccountAddress,

#[clap(flatten)]
pub(crate) txn_options: TransactionOptions,
}

#[async_trait]
impl CliCommand<TransactionSummary> for DistributeVestedCoins {
fn command_name(&self) -> &'static str {
"DistributeVestedCoins"
}

async fn execute(mut self) -> CliTypedResult<TransactionSummary> {
let vesting_contract_address = create_vesting_contract_address(self.admin_address, 0, &[]);
self.txn_options
.submit_transaction(aptos_stdlib::vesting_distribute(vesting_contract_address))
.await
.map(|inner| inner.into())
}
}

/// Unlock any vesting tokens according to the vesting contract's schedule.
/// This also unlock any accumulated staking rewards and pays commission to the operator of the
/// vesting contract's stake pool first.
///
/// The unlocked vested tokens and staking rewards are still subject to the staking lockup and
/// cannot be withdrawn until after the lockup expires.
#[derive(Parser)]
pub struct UnlockVestedCoins {
/// Address of the vesting contract's admin.
///
/// Defaults to the profile's address if not set.
#[clap(long, parse(try_from_str=crate::common::types::load_account_arg))]
pub admin_address: AccountAddress,

#[clap(flatten)]
pub(crate) txn_options: TransactionOptions,
}

#[async_trait]
impl CliCommand<TransactionSummary> for UnlockVestedCoins {
fn command_name(&self) -> &'static str {
"UnlockVestedCoins"
}

async fn execute(mut self) -> CliTypedResult<TransactionSummary> {
let vesting_contract_address = create_vesting_contract_address(self.admin_address, 0, &[]);
self.txn_options
.submit_transaction(aptos_stdlib::vesting_vest(vesting_contract_address))
.await
.map(|inner| inner.into())
}
}