Skip to content

Commit e694227

Browse files
authored
feat(auth): add funds transfer functionality (#186)
Introduce funds transfer between teams in auth module. Includes new CLI command, GraphQL query, and bigint support.
1 parent 1ebbaac commit e694227

File tree

11 files changed

+3226
-639
lines changed

11 files changed

+3226
-639
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
torii.toml
33
katana.toml
4+
.envrc

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ serde_json = "1.0.133"
2222
thiserror = "1.0.32"
2323
url = "2.2.2"
2424
starknet = "0.12.0"
25+
num-bigint = "0.4.3"

cli/src/command/auth/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use self::{email::EmailArgs, info::InfoArgs, login::LoginArgs};
22
use crate::command::auth::billing::BillingArgs;
33
use crate::command::auth::fund::FundArgs;
4+
use crate::command::auth::transfer::TransferArgs;
45
use anyhow::Result;
56
use clap::Subcommand;
67

@@ -10,6 +11,7 @@ mod fund;
1011
mod info;
1112
mod login;
1213
mod session;
14+
mod transfer;
1315

1416
#[derive(Subcommand, Debug)]
1517
pub enum Auth {
@@ -28,6 +30,9 @@ pub enum Auth {
2830
#[command(about = "Fund the authenticated user's account.")]
2931
Fund(FundArgs),
3032

33+
#[command(about = "Transfer funds to a slot team.")]
34+
Transfer(TransferArgs),
35+
3136
// Mostly for testing purposes, will eventually turn it into a library call from `sozo`.
3237
#[command(hide = true)]
3338
CreateSession(session::CreateSession),
@@ -42,6 +47,7 @@ impl Auth {
4247
Auth::SetEmail(args) => args.run().await,
4348
Auth::EnableSlotBilling(args) => args.run().await,
4449
Auth::Fund(args) => args.run().await,
50+
Auth::Transfer(args) => args.run().await,
4551
}
4652
}
4753
}

cli/src/command/auth/transfer.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use anyhow::Result;
2+
use clap::Args;
3+
use slot::graphql::auth::{transfer::*, Transfer};
4+
use slot::graphql::GraphQLQuery;
5+
use slot::{api::Client, credential::Credentials};
6+
7+
#[derive(Debug, Args)]
8+
#[command(next_help_heading = "Transfer")]
9+
pub struct TransferArgs {
10+
#[arg(help = "The team name to transfer funds to.", value_name = "team")]
11+
pub team: String,
12+
13+
#[arg(help = "The amount to transfer.", value_name = "amount")]
14+
pub amount: f64,
15+
}
16+
17+
impl TransferArgs {
18+
pub async fn run(&self) -> Result<()> {
19+
let credentials = Credentials::load()?;
20+
let client = Client::new_with_token(credentials.access_token);
21+
22+
let request_body = Transfer::build_query(Variables {
23+
transfer: TransferInput {
24+
amount: self.amount,
25+
team: self.team.clone(),
26+
},
27+
});
28+
let res: ResponseData = client.query(&request_body).await?;
29+
30+
println!("Transferred ${} to {}", self.amount, self.team);
31+
println!(
32+
"User balance: ${} -> ${}",
33+
res.transfer.account_before, res.transfer.account_after
34+
);
35+
println!(
36+
"Team balance: ${} -> ${}",
37+
res.transfer.team_before, res.transfer.team_after
38+
);
39+
40+
Ok(())
41+
}
42+
}

slot/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ hyper.workspace = true
2929

3030
account_sdk = { git = "https://github.com/cartridge-gg/controller", rev = "61d2fd0" }
3131
base64 = "0.22.1"
32+
num-bigint = "0.4.6"
3233

3334
[dev-dependencies]
3435
assert_matches = "1.5.0"

0 commit comments

Comments
 (0)