Skip to main content

canic_core/cdk/spec/standards/icrc/
icrc2.rs

1//! Module: cdk::spec::standards::icrc::icrc2
2//!
3//! Responsibility: ICRC-2 Candid DTOs used by Canic callers.
4//! Does not own: allowance policy, ledger behavior, or transfer workflows.
5//! Boundary: mirrors the external ICRC-2 surface with the Canic account type.
6
7use crate::cdk::spec::prelude::*;
8
9//
10// Allowance
11//
12
13#[derive(CandidType, Deserialize)]
14pub struct Allowance {
15    pub allowance: u64,
16    pub expires_at: Option<u64>,
17}
18
19//
20// AllowanceArgs
21// wrapped to use the Canic Account
22//
23
24#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
25pub struct AllowanceArgs {
26    pub account: Account,
27    pub spender: Account,
28}
29
30//
31// TransferFromArgs
32// transfer_from() arguments
33//
34
35#[derive(CandidType, Serialize)]
36pub struct TransferFromArgs {
37    pub from: Account,
38    pub to: Account,
39    pub amount: u64,
40    pub memo: Option<Vec<u8>>,
41    pub created_at_time: Option<u64>,
42}
43
44//
45// TransferFromResult
46//
47
48#[derive(CandidType, Deserialize)]
49pub enum TransferFromResult {
50    #[serde(rename = "Ok")]
51    Ok(u64), // Transaction index
52    #[serde(rename = "Err")]
53    Err(TransferFromError),
54}
55
56//
57// TransferFromError
58//
59
60#[derive(CandidType, Debug, Deserialize)]
61pub enum TransferFromError {
62    BadFee { expected_fee: u64 },
63    BadBurn { min_burn_amount: u64 },
64    InsufficientFunds { balance: u64 },
65    InsufficientAllowance { allowance: u64 },
66    TooOld,
67    CreatedInFuture { ledger_time: u64 },
68    Duplicate { duplicate_of: u64 },
69    TemporarilyUnavailable,
70    GenericError { error_code: u64, message: String },
71}