-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
mod support; | ||
use anyhow::{Error, Result}; | ||
use bigdecimal::num_bigint::BigInt; | ||
use dydx::config::ClientConfig; | ||
use dydx::node::{BigIntExt, NodeClient, Wallet}; | ||
use support::constants::TEST_MNEMONIC; | ||
use tokio::time::{sleep, Duration}; | ||
|
||
pub struct MegaVaulter { | ||
client: NodeClient, | ||
wallet: Wallet, | ||
} | ||
|
||
impl MegaVaulter { | ||
pub async fn connect() -> Result<Self> { | ||
let config = ClientConfig::from_file("client/tests/testnet.toml").await?; | ||
let client = NodeClient::connect(config.node).await?; | ||
let wallet = Wallet::from_mnemonic(TEST_MNEMONIC)?; | ||
Ok(Self { client, wallet }) | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
tracing_subscriber::fmt().try_init().map_err(Error::msg)?; | ||
#[cfg(feature = "telemetry")] | ||
support::telemetry::metrics_dashboard().await?; | ||
|
||
let mut vaulter = MegaVaulter::connect().await?; | ||
let mut account = vaulter.wallet.account(0, &mut vaulter.client).await?; | ||
let address = account.address().clone(); | ||
let subaccount = account.subaccount(0)?; | ||
|
||
// Deposit 1 USDC into the MegaVault | ||
let tx_hash = vaulter | ||
.client | ||
.megavault() | ||
.deposit(&mut account, subaccount.clone(), 1) | ||
.await?; | ||
tracing::info!("Deposit transaction hash: {:?}", tx_hash); | ||
|
||
sleep(Duration::from_secs(2)).await; | ||
|
||
// Withdraw 1 share from the MegaVault | ||
let number_of_shares: BigInt = 1.into(); | ||
let tx_hash = vaulter | ||
.client | ||
.megavault() | ||
.withdraw(&mut account, subaccount, 0, Some(&number_of_shares)) | ||
.await?; | ||
tracing::info!("Withdraw transaction hash: {:?}", tx_hash); | ||
|
||
// Query methods | ||
|
||
let owner_shares = vaulter | ||
.client | ||
.megavault() | ||
.get_owner_shares(&address) | ||
.await?; | ||
tracing::info!("Get owner shares: {owner_shares:?}"); | ||
|
||
// Convert serialized integer into an integer (`BigIntExt` trait) | ||
if let Some(shares) = owner_shares.shares { | ||
let nshares = BigInt::from_serializable_int(&shares.num_shares)?; | ||
tracing::info!("Number of owned shares: {}", nshares); | ||
} | ||
|
||
let withdrawal_info = vaulter | ||
.client | ||
.megavault() | ||
.get_withdrawal_info(&number_of_shares) | ||
.await?; | ||
tracing::info!("Get withdrawal info: {withdrawal_info:?}"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters