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

  1. User selects chain, wallet, source token, destination token and source token amount

    1. Get Supported Tokens: This method returns list of tokens supported on the dex to be populated.

      const supportedToken = await swap.getSupportedTokens();
    2. Get Exchange Rates: This method returns exchange rates for a token pair

      await swap.getExchangeRates({ toContractAddress, toContractDecimal, fromContractAddress, fromContractDecimal, fromQuantity, slippageTolerance });
  2. Exchange rates, estimated slippage and estimated gas fees is displayed to user

    1. Get Estimated Gas: This method returns estimated gas for the swap transaction

      await swap.getEstimatedGas({ toContractAddress, toContractDecimal, fromContractAddress, fromContractDecimal, fromQuantity, slippageTolerance })
  3. User confirms exchange rates

    1. Get Raw Transaction: This method returns the raw transaction

      await swap.getRawTransaction({ walletAddress, toContractAddress, toContractDecimal, fromContractAddress, fromContractDecimal, fromQuantity, toQuantity, slippageTolerance })
  4. User continues to sign transaction. Enters vault pin to proceed

    1. 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 signed

      • pin - The pin to access the vault's private functions.

  5. Signed transaction broadcasted by client application

Last updated