Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap backend #447

Open
1 task
Tracked by #440
joel-medicala-yral opened this issue Nov 6, 2024 · 0 comments · May be fixed by #448
Open
1 task
Tracked by #440

Swap backend #447

joel-medicala-yral opened this issue Nov 6, 2024 · 0 comments · May be fixed by #448

Comments

@joel-medicala-yral
Copy link
Contributor

joel-medicala-yral commented Nov 6, 2024

  • Users should be able to send a swap request to a token creator
  • Swap request can be accepted or declined by a token creator
  • Request is valid for a week
  • Token creator can accept or decline the swap request
  • If accepted swap each other's tokens
  • Check if the swap requester's token has a value in the market and update the token creator's price
  • Swap requester can cancel their request whenever they want to

Overview

flowchart TD
   
   Buyer[Buyer] --> |1.Allocate 1ETH for buyer to be spent by the Owner Canister|icrc2_approve_to --> |2.1ETH -> 10CDAO|Owner[Owner]--> |3.The Owner has two optiond to accept the swap request or to decline it|AcceptOrDecline{AcceptOrDecline}
   AcceptOrDecline --> |4..Owner accepts the request|Accept[Accept]
   AcceptOrDecline --> |4.The Owner declined the swap request|Decline[Decline]

   Accept -->|5.Do the swap|Buyer --> |6.Transfer tokens from buyer to owner|Owner --> |7.Transfer tokens from Owner to Buyer|Buyer--> |8.Check if the token thats being given inplace of the Owner's token has a value or not|get_token_price{get_token_price}
   get_token_price --> |9.If the token is priced|Priced --> |10.Update Owner latest_swap_price for that token|Update --> |11.Update the Owner's canister data|Owner
   get_token_price --> |9.The token is not priced|NotPriced


Loading

Caller Callee Flow

flowchart TD
    Requester[Requester Principal] --> swap_request --> Creator[Creator Canister]

    CreatorPrincipal[Creator Principal] --> swap_request_action --> Creator

    Requester --> cancel_swap_request --> Creator
Loading

swap_request

flowchart TD
    swap_request[token_a --> token_b] --> token_a
    swap_request --> token_b
    token_a --> |1.Check if the token has icrc2 support|is_icrc2_supported_token
    token_b --> |2.Check if the token has icrc2 support|is_icrc2_supported_token --> |3.Check if this canister is the token owner|is_token_creator

    token_b --> is_token_creator --> |4.Allocate token_a with expiry 1wk|icrc2_approve
    token_a --> icrc2_approve
Loading

swap_request_action

  • Swapping is the transfer of token_a from requester_princiapl to the caller and token_b from caller to requester_principal
flowchart TD
    Caller[Caller = token_creator] --> swap_request_action{SwapRequestActions} --> Accept
    Accept --> token_a
    Accept --> token_b
    Accept --> requester_principal

    token_a --> Swap
    token_b --> Swap
    requester_principal --> Swap

    swap_request_action --> Decline

    Swap --> get_token_prices{get_token_prices} --> Priced -->UpdateLastSwappedPrice[Update Last Swap Price]
    get_token_prices --> NotPriced

Loading

get_token_price

flowchart TD
   Caller[token_ledger] -->
   get_ledger_controllers[Get Controllers] --> filter_canister_ids[Filter Canister IDs]
   
   filter_canister_ids --> |Verifies token ownership by calling deployed_cdao for each ID| IsTokenOwner{Is Token Owner?}
   
   IsTokenOwner --> |Not Owner| NotOwner[Error: Not Owner] --> error[Error]
   IsTokenOwner --> |Owner Verified| Owner[Owner] --> check_price_field[Check Price Field] --> return[Return Token Price]

Loading

cancel_swap_request

flowchart TD
    Caller[Caller = requester_principal] -->
    token_a --> |Deallocate by calling icrc2_approve again and setting the amount to 0|icrc2_approve

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant