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: Initialize Vault with VRT mint vanity address #200

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion cli/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ Creating a vault requires:
- `<WITHDRAWAL_FEE_BPS>`: Fee for withdrawing ST
- `<REWARD_FEE_BPS>`: Fee taken when ST rewards are sent to the vault
- `<DECIMALS>`: Decimals of the newly created VRT. ( 9 is Recommended )
- `<INITIALIZE_TOKEN_AMOUNT>`: The amount of tokens to initialize the vault with ( in the smallest unit )
- `<VRT_MINT_ADDRESS_FILE_PATH>`: The file path of VRT mint address (**Optional**)

```bash
jito-restaking-cli --rpc-url <RPC_URL> vault vault initialize <TOKEN_MINT> <DEPOSIT_FEE_BPS> <WITHDRAWAL_FEE_BPS> <REWARD_FEE_BPS> <DECIMALS>
jito-restaking-cli --rpc-url <RPC_URL> vault vault initialize <TOKEN_MINT> <DEPOSIT_FEE_BPS> <WITHDRAWAL_FEE_BPS> <REWARD_FEE_BPS> <DECIMALS> <INITIALIZE_TOKEN_AMOUNT>
```

Note the resulting Vault Pubkey.
Expand Down
6 changes: 6 additions & 0 deletions cli/src/vault.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use clap::{command, Subcommand};
use solana_program::pubkey::Pubkey;

Expand Down Expand Up @@ -46,6 +48,10 @@ pub enum VaultActions {
reward_fee_bps: u16,
/// The decimals of the token
decimals: u8,
/// The amount of tokens to initialize the vault with ( in the smallest unit )
initialize_token_amount: u64,
/// The file path of VRT mint address
vrt_mint_address_file_path: Option<PathBuf>,
},
/// Creates token metadata for the vault's LRT token
CreateTokenMetadata {
Expand Down
56 changes: 49 additions & 7 deletions cli/src/vault_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use anyhow::{anyhow, Result};
use jito_bytemuck::{AccountDeserialize, Discriminator};
Expand All @@ -15,7 +15,8 @@ use jito_vault_client::{
types::WithdrawalAllocationMethod,
};
use jito_vault_core::{
config::Config, vault::Vault, vault_operator_delegation::VaultOperatorDelegation,
burn_vault::BurnVault, config::Config, vault::Vault,
vault_operator_delegation::VaultOperatorDelegation,
vault_staker_withdrawal_ticket::VaultStakerWithdrawalTicket,
vault_update_state_tracker::VaultUpdateStateTracker,
};
Expand All @@ -29,7 +30,7 @@ use solana_rpc_client_api::{
filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
};
use solana_sdk::{
signature::{Keypair, Signer},
signature::{read_keypair_file, Keypair, Signer},
transaction::Transaction,
};
use spl_associated_token_account::{
Expand Down Expand Up @@ -90,6 +91,8 @@ impl VaultCliHandler {
withdrawal_fee_bps,
reward_fee_bps,
decimals,
initialize_token_amount,
vrt_mint_address_file_path,
},
} => {
self.initialize_vault(
Expand All @@ -98,6 +101,8 @@ impl VaultCliHandler {
withdrawal_fee_bps,
reward_fee_bps,
decimals,
initialize_token_amount,
vrt_mint_address_file_path,
)
.await
}
Expand Down Expand Up @@ -221,13 +226,16 @@ impl VaultCliHandler {
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub async fn initialize_vault(
&self,
token_mint: String,
deposit_fee_bps: u16,
withdrawal_fee_bps: u16,
reward_fee_bps: u16,
decimals: u8,
initialize_token_amount: u64,
vrt_mint_address_file_path: Option<PathBuf>,
) -> Result<()> {
let token_mint = Pubkey::from_str(&token_mint)?;
let keypair = self
Expand All @@ -240,24 +248,58 @@ impl VaultCliHandler {
let base = Keypair::new();
let vault = Vault::find_program_address(&self.vault_program_id, &base.pubkey()).0;

let vrt_mint = Keypair::new();
let admin = keypair.pubkey();

let vrt_mint = match vrt_mint_address_file_path {
Some(file_path) => {
let keypair = read_keypair_file(file_path)
.map_err(|e| anyhow!("Could not read VRT mint address file path: {e}"))?;
info!("Found VRT mint address: {}", keypair.pubkey());
keypair
}
None => Keypair::new(),
};

let admin_st_token_account = get_associated_token_address(&admin, &token_mint);
let vault_st_token_account = get_associated_token_address(&vault, &token_mint);

let burn_vault = BurnVault::find_program_address(&self.vault_program_id, &base.pubkey()).0;

let burn_vault_vrt_token_account =
get_associated_token_address(&burn_vault, &vrt_mint.pubkey());

let mut ix_builder = InitializeVaultBuilder::new();
ix_builder
.config(Config::find_program_address(&self.vault_program_id).0)
.vault(vault)
.vrt_mint(vrt_mint.pubkey())
.st_mint(token_mint)
.admin(keypair.pubkey())
.admin(admin)
.base(base.pubkey())
.admin_st_token_account(admin_st_token_account)
.vault_st_token_account(vault_st_token_account)
.burn_vault(burn_vault)
.burn_vault_vrt_token_account(burn_vault_vrt_token_account)
.associated_token_program(spl_associated_token_account::id())
.deposit_fee_bps(deposit_fee_bps)
.withdrawal_fee_bps(withdrawal_fee_bps)
.reward_fee_bps(reward_fee_bps)
.decimals(decimals);
.decimals(decimals)
.initialize_token_amount(initialize_token_amount);

let admin_st_token_account_ix =
create_associated_token_account_idempotent(&admin, &admin, &token_mint, &spl_token::ID);

let vault_st_token_account_ix =
create_associated_token_account_idempotent(&admin, &vault, &token_mint, &spl_token::ID);

let blockhash = rpc_client.get_latest_blockhash().await?;
let tx = Transaction::new_signed_with_payer(
&[ix_builder.instruction()],
&[
admin_st_token_account_ix,
vault_st_token_account_ix,
ix_builder.instruction(),
],
Some(&keypair.pubkey()),
&[keypair, &base, &vrt_mint],
blockhash,
Expand Down
4 changes: 3 additions & 1 deletion docs/_tools/00_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Vault commands

Creates a new vault

**Usage:** `jito-restaking-cli vault vault initialize <TOKEN_MINT> <DEPOSIT_FEE_BPS> <WITHDRAWAL_FEE_BPS> <REWARD_FEE_BPS> <DECIMALS>`
**Usage:** `jito-restaking-cli vault vault initialize <TOKEN_MINT> <DEPOSIT_FEE_BPS> <WITHDRAWAL_FEE_BPS> <REWARD_FEE_BPS> <DECIMALS> <INITIALIZE_TOKEN_AMOUNT> [VRT_MINT_ADDRESS_FILE_PATH]`

###### **Arguments:**

Expand All @@ -299,6 +299,8 @@ Creates a new vault
* `<WITHDRAWAL_FEE_BPS>` — The withdrawal fee in bips
* `<REWARD_FEE_BPS>` — The reward fee in bips
* `<DECIMALS>` — The decimals of the token
* `<INITIALIZE_TOKEN_AMOUNT>` — The amount of tokens to initialize the vault with ( in the smallest unit )
* `<VRT_MINT_ADDRESS_FILE_PATH>` — The file path of VRT mint address



Expand Down
Loading