-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic_usage.rs
More file actions
69 lines (59 loc) · 1.91 KB
/
basic_usage.rs
File metadata and controls
69 lines (59 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use vertex_sdk::math::{to_i128_x18, to_u128_x18, to_u128_x6};
use vertex_sdk::prelude::*;
use vertex_sdk::utils::private_key::private_key;
#[tokio::main]
async fn main() {
// paste private key or set RUST_SDK_PRIVATE_KEY in .env file
let private_key = private_key();
let client = VertexClient::new(ClientMode::SepoliaTest)
.with_signer(private_key)
.await
.unwrap();
// product_id for USDC
const USDC: u32 = 0;
// deposit 1_000 USDC
client
.deposit_collateral_builder()
.product_id(USDC)
.amount(to_u128_x6(1000)) // scale by token decimals (USDC has 6 decimals)
.mints_tokens(true) // testnet only (mints specified amount of token before depositing)
.erc20_sleep_secs(1)
.gas_price(100_000_000)
.deposit_and_await_balance() // waits for change in balance
.await
.unwrap();
const BTC: u32 = 0;
// deposit 1 BTC
let deposit_collateral_params = client
.deposit_collateral_builder()
.product_id(BTC)
.amount(to_u128_x18(1)) // scale by token decimals (BTC has 18, etc)
.mints_tokens(true) // testnet only (mints specified amount of token before depositing)
.build()
.unwrap();
// every builder can build a struct which can be used by the client, or it can execute directly
// with .execute()
client
.deposit_collateral(deposit_collateral_params)
.await
.unwrap();
// product_id for BTC_PERP
const BTC_PERP: u32 = 2;
// buy 1 BTC_PERP
client
.place_order_builder()
.product_id(BTC_PERP)
.amount(to_i128_x18(1))
.price_x18(to_i128_x18(35_000))
.execute()
.await
.unwrap();
// withdraw 100 USDC
client
.withdraw_collateral_builder()
.product_id(USDC)
.amount(to_u128_x6(100))
.execute()
.await
.unwrap();
}