You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swap requester can cancel their request whenever they want to
Overview
flowchart TD
%% Initiation by the requester
A[Requester initiates swap via Frontend] --> B[Leptos Server Function]
%% Approval process from requester to token creator canister
B --> C[Send icrc2 approve call to Token Creator Canister, e.g. approve 20 USDC]
%% Token creator side checks and setup
C --> D[Token Creator Canister verifies allocation and token details, last swap price, etc.]
%% For tokens that require external price data (BTC, DOLR, etc.)
B --> L[Check if token requires external pricing]
L -- Yes --> M[Invoke External CF Worker]
M --> N[CF Worker fetches and caches price from Binance, Coinbase, Kongswap]
N --> D
%% Swap request action in the token creator canister
D --> E[Invoke swap_request_action with swap details]
%% Outcome decision point
E --> F{Swap Outcome?}
%% Accepted swap flow
F -- "Accepted" --> G[Execute swap: Exchange tokens and update last swap price, e.g. DOG token new price = 2 USD]
%% Requester cancels swap flow
F -- "Requester Cancels" --> H[Requester cancels the swap]
H --> I[Trigger icrc2 approve call with amount = 0, reset/revoke approval]
%% Token creator rejects swap flow
F -- "Token Creator Rejects" --> J[Token Creator rejects swap request]
J --> K[Notify requester, approval reset to 0 on notification]
flowchart TD
D{"Is Token Owner? (Call deployed_cdao for each ID)"} -- Not Owner --> E["Error: Not Owner"]
E --> F["Abort Process"]
J{"Token Type"} -- DOLR or BTC --> K["Check KV Cache for Price"]
K -- Cached Price Found --> L["Return Cached Price"]
K -- No Cached Price --> M{"Token Type"}
M -- BTC --> N["Fetch Price from Coinbase & Binance, Calculate Average"]
M -- DOLR --> O["Fetch Price from Kong Swap"]
N --> P["Store Fetched Price in KV Cache"]
O --> P
P --> Q["Return Fetched Price"]
J -- "Other Token (e.g. ABC)" --> R["Obtain Token Creator via sns_init Params"]
R --> S@{ label: "Call Token Creator's Canister to Retrieve Price" }
S --> T@{ label: "Return Token Price from Token Creator's Canister" }
D --> J
S@{ shape: rect}
T@{ shape: rect}
Loading
cancel_swap_request (Server Function Side)
flowchart TD
Caller[Caller = requester_principal] -->
token_a --> |Deallocate by calling icrc2_approve again and setting the amount to 0|icrc2_approve
Loading
The text was updated successfully, but these errors were encountered:
Overview
Caller Callee Flow
swap_request_action(Canister side)
get_token_price (CF Worker)
cancel_swap_request (Server Function Side)
The text was updated successfully, but these errors were encountered: