-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathget_balance_allowance.rs
More file actions
41 lines (34 loc) · 1.25 KB
/
get_balance_allowance.rs
File metadata and controls
41 lines (34 loc) · 1.25 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
#![allow(
clippy::print_stdout,
reason = "Examples print their results to stdout"
)]
//! Fetch the collateral balance and allowance for the authenticated account.
use std::str::FromStr as _;
use alloy::signers::Signer as _;
use alloy::signers::local::LocalSigner;
use polymarket_client_sdk_v2::clob::types::AssetType;
use polymarket_client_sdk_v2::clob::types::request::BalanceAllowanceRequest;
use polymarket_client_sdk_v2::clob::{Client, Config};
use polymarket_client_sdk_v2::{POLYGON, PRIVATE_KEY_VAR};
use polymarket_client_sdk_v2::CLOB_HOST;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let host =
std::env::var("CLOB_API_URL").unwrap_or_else(|_| CLOB_HOST.into());
let signer =
LocalSigner::from_str(&std::env::var(PRIVATE_KEY_VAR)?)?.with_chain_id(Some(POLYGON));
let client = Client::new(&host, Config::default())?
.authentication_builder(&signer)
.authenticate()
.await?;
let resp = client
.balance_allowance(
BalanceAllowanceRequest::builder()
.asset_type(AssetType::Collateral)
.build(),
)
.await?;
println!("balance: {}", resp.balance);
println!("allowances: {} contract(s)", resp.allowances.len());
Ok(())
}