Safle Swaps
Safle enables decentralised swaps via the in house built swaps SDK. The SDK exposes set of functionalities required to execute a swap. Currently 1inch DEX is integrated on safle swaps.
The SDK has a modular architecture where a dedicated controller for each DEX can be plugged in with just a few lines of code
Step by step description
1. Installation, import & initialisation
npm install @getsafle/safle-swaps-v2
const Swap = require('@getsafle/safle-swaps-v2');
const swap = new Swap({ dex, rpcURL,chain });
dex
- The name of DEX using which you want to swap tokens.rpcURL
- The rpc url to connect to a blockchain node.chain
- The chain name of the blockchain. Supported for now -ethereum
2. User Flow
User selects chain, wallet, source token, destination token and source token amount
Get Supported Tokens: This method returns list of tokens supported on the dex to be populated.
const supportedToken = await swap.getSupportedTokens();
Get Exchange Rates: This method returns exchange rates for a token pair
await swap.getExchangeRates({ toContractAddress, toContractDecimal, fromContractAddress, fromContractDecimal, fromQuantity, slippageTolerance });
Exchange rates, estimated slippage and estimated gas fees is displayed to user
Get Estimated Gas: This method returns estimated gas for the swap transaction
await swap.getEstimatedGas({ toContractAddress, toContractDecimal, fromContractAddress, fromContractDecimal, fromQuantity, slippageTolerance })
User confirms exchange rates
Get Raw Transaction: This method returns the raw transaction
await swap.getRawTransaction({ walletAddress, toContractAddress, toContractDecimal, fromContractAddress, fromContractDecimal, fromQuantity, toQuantity, slippageTolerance })
User continues to sign transaction. Enters vault pin to proceed
Application calls vault method to sign raw transaction and enters pin
const signedTransaction = await vault.signTransaction(rawTx, pin, chain);
Returns the signed transaction string
chain
- The chain for which the transaction is to be signed.rawTx
- The raw transaction object to be signedpin
- The pin to access the vault's private functions.
Signed transaction broadcasted by client application
Last updated