Safle
  • SafleID
    • About SafleID
      • Core Technical Components (1/3)
      • Core Technical Concepts (2/3)
      • Core Technical Concepts (3/3)
    • What SafleID does?
    • For Chains
      • Technical Breakdown (1/2)
      • Technical Breakdown (2/2)
    • For dApps
    • For Wallet Providers (Exchanges and independent wallets)
      • Why Integrate SafleID (1/2)
      • Why Integrate SafleID (2/2)
    • SafleID's Technology
      • Data Flow and Interactions
      • Resolving Functionalities (RegistrarMain Contract)
      • Auction Functionalities (Auction Contract)
    • Conclusion
    • Terminology
    • Technical Documentation
  • Safle Wallet
    • Onboarding
    • Buy Crypto with Fiat enabled via Transak
    • Safle Swaps
    • Transaction processing on multiple Chains
    • Annexure: Encryption Sequence
  • Safle Vault
    • Features
    • Blockchains Supported
    • Installation & Initialisation
    • Encryption/Decryption Module
    • Controllers
Powered by GitBook
On this page
  1. Safle Wallet

Safle Swaps

PreviousBuy Crypto with Fiat enabled via TransakNextTransaction processing on multiple Chains

Last updated 10 months ago

Safle enables decentralised swaps via the in house built swaps SDK. The SDK exposes set of functionalities required to execute a swap. Currently 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

1inch