Swap-ERC20 token for ERC20 token using smartcontract

We are working on creating an ERC20 smart contract using the below tutorial code on the Caspers-labs network with Rust. https://github.com/casper-ecosystem/erc20/blob/master/contract/src/main.rs

We have created two tokens, one token as "SDC" and another one as "CDS".

Looking for some help to add a function on the smart contract to swap the token between each other.

Ex: If an account holder has 100 SDC tokens on their account address they can be able to swap their SDC token with a CDS token with the same amount (100 SDC = 100 CDS tokens).

In another network, there is some default function that is available for swapping the token. We will call those functions for our contract and do the swap between the two tokens.
Sample contract for using near-sdk: https://github.com/ref-finance/ref-contracts/blob/main/ref-exchange/src/pool.rs#:~:text=returns%20received%20amount.-,pub%20fn%20swap

Can you please provide some pointers and help us know if that is achievable?

Appreciate the assistance in advance. Thanks!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.