Skip to main content

canic_core/dto/
icp_refill.rs

1use crate::{cdk::types::Cycles, dto::prelude::*};
2
3///
4/// IcpRefillMode
5///
6
7#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
8#[remain::sorted]
9pub enum IcpRefillMode {
10    Canister,
11    Fabricate,
12}
13
14///
15/// IcpRefillStatus
16///
17
18#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
19#[remain::sorted]
20pub enum IcpRefillStatus {
21    Completed,
22    Failed,
23    InvalidTransaction,
24    NotifyProcessing,
25    Refunded,
26    Requested,
27    TransactionTooOld,
28    Transferred,
29}
30
31///
32/// IcpRefillErrorCode
33///
34
35#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
36#[remain::sorted]
37pub enum IcpRefillErrorCode {
38    BadFee,
39    Duplicate,
40    FabricationUnavailable,
41    InvalidLedgerBlockIndex,
42    InvalidTransaction,
43    LedgerTransferFailed,
44    NotifyFailed,
45    NotifyMaxAttempts,
46    Processing,
47    RateGateDenied,
48    Refunded,
49    RequestDenied,
50    TransactionTooOld,
51    TransferWindowStale,
52}
53
54///
55/// IcpRefillRequest
56///
57
58#[derive(CandidType, Clone, Debug, Deserialize)]
59pub struct IcpRefillRequest {
60    pub operation_id: [u8; 32],
61    pub source_canister: Principal,
62    pub source_subaccount: Option<[u8; 32]>,
63    pub target_canister: Principal,
64    pub amount_e8s: u64,
65    pub dry_run: bool,
66    pub mode: IcpRefillMode,
67}
68
69///
70/// IcpRefillResponse
71///
72
73#[derive(CandidType, Clone, Debug, Deserialize)]
74pub struct IcpRefillResponse {
75    pub operation_id: [u8; 32],
76    pub status: IcpRefillStatus,
77    pub ledger_block_index: Option<u64>,
78    pub cycles_sent: Option<Nat>,
79    pub error_code: Option<IcpRefillErrorCode>,
80    pub error_message: Option<String>,
81}
82
83///
84/// IcpRefillDryRun
85///
86
87#[derive(CandidType, Clone, Debug, Deserialize)]
88pub struct IcpRefillDryRun {
89    pub operation_id: [u8; 32],
90    pub mode: IcpRefillMode,
91    pub amount_e8s: u64,
92    pub fee_e8s: u64,
93    pub xdr_permyriad_per_icp: Option<u64>,
94    pub estimated_cycles: Option<Cycles>,
95    pub message: Option<String>,
96}
97
98///
99/// IcpRefillEndpointResponse
100///
101
102#[derive(CandidType, Clone, Debug, Deserialize)]
103#[remain::sorted]
104pub enum IcpRefillEndpointResponse {
105    DryRun(IcpRefillDryRun),
106    Refill(IcpRefillResponse),
107}