SaSi is a protocol that enables the exchange of CDBCs (ERC20s) that already run on the Ripple EVM Sidechain for Bonds (ERC1155s).
Contract | Address | Network |
---|---|---|
SaSiFactory | 0xC6FCCF8Aaa53Ec976483a23388aea068BD7eBcAb | XRPL EVM Sidechain |
SaSiRouter | 0xB2F3994FD5B2CCf1Dc63FC05E01B06d376170F3f | XRPL EVM Sidechain |
SaSiPair (CDBC/Bond) | 0x9bfaadc96d3f0ac268716fc9fe5489a5348e47e4 | XRPL EVM Sidechain |
CDBC | 0x8fF97eCEaf1d5e455e7C3C2dB16e5eF90FfE265c | XRPL EVM Sidechain |
Bond | 0x2136F6805Ec91231eb0527884adE475cb9C50c37 | XRPL EVM Sidechain |
SaSiRouter | 0xB2F3994FD5B2CCf1Dc63FC05E01B06d376170F3f | XRPL EVM Sidechain |
In order to make a swap using the SaSi protocol of our team, do the following: 0. Connect your metamask wallet to the sidechain and get some faucets as described here Ripple Sidechain EVM
- Mint an amount of a CDBC for yourself using the function
mint
in the contract CDBC. - Mint an amount of a bond for yourself using the function
mint
in the contract Bond. - Use the function
swapERC1155TokensForERC20Tokens
or the functionswapERC20TokensForERC1155Tokens
in the contract SaSiRouter, according to your wish.
- Connect to the Ripple EVM Sidechain on Metamask
- Deploy the smart contracts of the SaSi protocol.
- Deploy the tokens that will be exchanged in the pool.
- The pool is created in the SaSiFactory.sol
- The deployer of the contracts gives authorization to an account to add liquidity of the tokens in a pool.
- The authorized entity adds liquidity to the pool.
- An account with some tokens of either token in a certain pool can swap its tokens, in an exchange from CDBCs per bonds or vice-versa.
- Follow the steps here Get Started EVM Sidechain to load your Metamask wallet with XRP.
- Clone this repository.
- Navigate to the the
smartcontracts
repository by
$ cd/sasi/smartcontracts
- Install the
remixd
package inside the current directory
$ npm install -g @remix-project/remixd
- Once installed, run the following in the current directory
remixd
- Go to Remix IDE
- Follow the steps here Remix - Connect to Localhost to connect the Remix IDE to your current environment (localhost).
- In the Remix IDE:
- select
SaSiFactory
atsrc/core/SasiFactory.sol
- select the compiler version
0.8.23
- under
Solidity compiler
tab and underAdvanced Configurations
, enable the optimization with 200 runs.
- select
- In the deploy tab, deploy the
SaSiFactory
contract with the following params:_feeToSetter
: the address to which the fees on the swaps go to._govBr
: the government wallet address that will have control over the protocol by being the only one allowed to create pools and deciding the entities who are able to addLiquidity to the different pools created.
- Deploy the CDBCs (ERC20) and bonds (ERC1155) to the Ripple sidechain.
- We used the
MockToken.sol
contract to represent both the CDBCs and the bonds. - Deploy the
mockERC20Token
contract to represent the CDBC. - Deploy the
mockERC1155Token
contract to represent the bonds.
- We used the
- Once the deployed tokens have been deployed, make sure the
entity
allowed toaddLiquidity
to the pool has received these tokens as well, by either direct transfer of the tokens to theentity
or by theentity
itself minting for itself the tokens. - By using the function
createPair
, the_govBr
account must create a pair for two tokens: one that is a CDBC and another that is the bond. The other parameters are explained as follows:tokenA
token in the pool.tokenB
token in the pool.amount0
initialPrice of token. It's not deterministic for the pair address creation.amount1
initialPrice of token. It's not deterministic for the pair address creation.id
id of the bond (ERC1155) in the pool. The order of the tokens is not important when determining which one istokenA
andtokenB
. The contract has thesortTokens
function that will always regard thetoken0
as the ERC20 andtoken1
as the ERC1155. Also, theamount0
andamount1
variables were created thinking on SaSi version 2, where these amounts will determine the initial price between the bond and the CDBC in the pool, making it so that theentity
that adds liquidity to the pool can only add liquidity in the proportion determined by the_govBr
, solving therefore the problem of determining initial prices for a pair of CDBC and a particular bond.
- Deploy the
SaSiRouter
contract with the following params:_factory
: address of the factory that has been deployed on step 9._govBr
: the address of the entity that will be able to create the pools and that will be able to give power to accounts to addLiquidity to the pools. Usually, this one should be equal to the second parameter os theSaSiFactory
.wNative
: the address of the wrapped token that represents the XRP token in the Ripple EVM-compatible sidechain.
- Once the
SaSiRouter
has been deployed, the_govBr
must use the functionaddEntity
to add power to the account which has the tokens and willaddLiquidity
to the pool. - Once the the right entities have been granted permission to be
entities
in theSaSiRouter
contract, theentity
can call theaddLiquidity
function, wherein each of the params mean:address tokenA
one of the tokensaddress tokenB
one of the tokensuint id
id of the bond tokenuint amountADesired
amount of liquidity desired to be added for tokenAuint amountBDesired
amount of liquidity desired to be added for tokenBuint amountAMin
minimum of liquidity to be added for tokenAuint amountBMin
minimum of liquidity to be added for tokenBaddress to
address for which the LP tokens of the pool will be given foruint deadline
the deadline till which the tx may happen
- Once liquidity has been added to a pair pool of a particular CDBC and bond, anyone willing to exchange their CDBC or bonds by the other token in the pool can call one of the two functions below in the pool:
swapERC20TokensForERC1155Tokens
: swap CDBC per bond.swapERC1155TokensForERC20Tokens
: swap bond per CDBC. The params for these functions are defined as below:uint amountIn
the amount of tokens you want to exchange in the pair pool.uint amountOutMin
the minimum amount of tokens you want to get back, determining therefore the allowed slippage amount.address[] calldata path
the tokens to be exchanged. The first element must be the token you are giving in and the second must be the token you are getting out of the pool.uint id
the id of the bond token.address to
the address to which the swap will happen to.uint deadline
the timestamp till which your tx might be executed.