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 integration #440

Open
3 tasks
harshita-srivastava-yral opened this issue Oct 30, 2024 · 21 comments
Open
3 tasks

Swap backend integration #440

harshita-srivastava-yral opened this issue Oct 30, 2024 · 21 comments
Assignees

Comments

@harshita-srivastava-yral
Copy link

harshita-srivastava-yral commented Oct 30, 2024

  • Swap backend #447
  • In app section for viewing the notification (Bell Icon)
  • PNs implementation
flowchart TD
   
   Buyer[Buyer] --> |1.Allocate 1ETH for buyer to be spent by the Owner Canister|icrc2_approve_to --> |2.1ETH -> 10CDAO|PushNotifs[Push Notifications] --> |3.Send push notification to the Token Owner|Owner[Owner]--> |4.The Owner has two optiond to accept the swap request or to decline it|AcceptOrDecline{AcceptOrDecline}
   AcceptOrDecline --> |5.Owner accepts the request|Accept[Accept]
   AcceptOrDecline --> |5.The Owner declined the swap request|Decline[Decline]-->|6.Send a push notification for the buyer|PushNotifs

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




Loading
@harshita-srivastava-yral
Copy link
Author

  • Post call discussion required to understand the implementation

@harshita-srivastava-yral
Copy link
Author

  • Finished writing the mermaid diagram
  • To be reviewed today

@harshita-srivastava-yral
Copy link
Author

harshita-srivastava-yral commented Nov 5, 2024

  • Add a Pending request "Cancel" CTA for users sending swap request in notifications
  • Price of tokens to be stored in the SNS canisters and figure out the canister owner
  • Have 1 field which is last traded price, historical data storage is not required as of now
  • One probable solution is to add fields to ICP ICRC metadata however this might not be possible

@harshita-srivastava-yral
Copy link
Author

  • Wrote few tests
  • PNs to be triggered from the backend and not frontend for implementation

@harshita-srivastava-yral
Copy link
Author

  • Tests won't work as WASM files are ICRC-1 Compliant and not ICRC-2.
  • Once @ravi-sawlani-yral updates the canisters the above issue should be recolved
  • While Swap need to get prices of USDC and BTC which will be discussed today

@harshita-srivastava-yral
Copy link
Author

harshita-srivastava-yral commented Nov 7, 2024

  • Research on internal oracle service (XRC) which helps us fetch the price of the tokens. @joel-medicala-yral to do. We can get BTC and USDC

@harshita-srivastava-yral
Copy link
Author

harshita-srivastava-yral commented Nov 8, 2024

  • Cost estimation of canisters- insights to be shared today
  • Function call happens only for BTC USDC and NNS tokens
  • Initially we will have liquidity only through these tokens hence its ok to move ahead with them for now
  • Individual canisters will make the call to the server function and help derive the cost of the token.
  • When swap is requested, last traded prices will be calculated basis this function
  • Pending: Price to be retrieved for DOLR tokens and we are currently not supporting ICP as of now.
  • Figure out way to list ICP in the wallet.
  • List ETH as well in the wallet
  • Validation to have only principal in the fields (We only support ck variant of everything for now)
  • Total of 5 ICP tokens we will be supporting in the wallet of YRAL for now
  • 4 Useful links for figuring out the traded price: icptokens.net , icpcoins , https://www.coingecko.com/ , https://coinmarketcap.com/currencies/dogecoin/

@harshita-srivastava-yral
Copy link
Author

harshita-srivastava-yral commented Nov 11, 2024

  • When we were trying to integrate the sonic swap we faced the problem, we need to query the price with respect to ICP and then the token price is retrieved.
  • We will use icpswap for now.
  • We are accessing this from backend... !
  • Try to update the last traded price via server function instead of using the canisters.
  • Canisters will only be for data storage and not use for any compute. We would want to go in this direction

@harshita-srivastava-yral
Copy link
Author

  • Swap backend is facing few challenges. We will discuss the details today

@harshita-srivastava-yral
Copy link
Author

  • Price fetching from offchain has been written and now writing it on server

@harshita-srivastava-yral
Copy link
Author

  • Backend is to be merged
  • Server function to be done again post refactor
  • Frontend to be done

@harshita-srivastava-yral
Copy link
Author

  • For the Swap we found few issues - Approval logic can't be on backend canister as it requires caller to approve the request
  • It happens at individual user canister
  • Solution - We can use leptos server function

@harshita-srivastava-yral
Copy link
Author

  • Need to rewrite the code and move a part of it to leptos server function

@harshita-srivastava-yral
Copy link
Author

  • Backend code has been written for this
  • Need to check with @saikatdas0790 if we need to create a separate workspace price fetching part. It was supposed to be on cloudfare

@saikatdas0790
Copy link
Contributor

Let's do as much on cloudflare as much as possible. Any compute that is actor based which ideally was executed by individual user canisters, all of that goes to the durable object worker for the individual user now. Makes sense?
@harshita-srivastava-yral @joel-medicala-yral

@harshita-srivastava-yral
Copy link
Author

@saikatdas0790
Copy link
Contributor

Created and shared over DM

@siyara-m-yral
Copy link

  • Should be merged today

@siyara-m-yral
Copy link

  • Price fetching should be done in 1-2 days
  • Backend 1 day
  • FE 1-2 days

@siyara-m-yral
Copy link

  • Price fetching logic is done
  • Need to implement caching logic on Cloudfare

@siyara-m-yral
Copy link

  • Caching done (to confirm efficient implementation)
  • Need to update mermaid charts and docs

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

No branches or pull requests

4 participants