symbiosis-js-sdk
    TypeScript icon, indicating that this package has built-in type declarations

    2.7.12 • Public • Published

    symbiosis-js-sdk

    Build Status

    Installation

    npm i symbiosis-js-sdk@2.6.3

    Install dependencies

    npm i

    Run tests

    npm run test

    Upgrade version

    For upgrade versions should be use npm versions command. Version will upgrade automatically.

    npm version major|minor|patch

    How To Use

    The current implementation use ethers to interact with the Ethereum like blockchains.

    Init Symbiosis SDK

    To work with Symbiosis SDK you should init Symbiosis instance with config (check Config type) and your CLIENT_ID.

    import { Symbiosis } from 'symbiosis-js-sdk'
    import { CONFIG } from '@app/lib/config'
    
    export const symbiosis = new Symbiosis(
      {
        chains: [{ ... }], // array of used rpc and contract addresses on that chains
        advisor: { url: 'https://...' }, // url of advisor service
        maxSwapAmountInUsd: ..., // max amount of swap in USD
        minSwapAmountInUsd: ..., // min amount of swap in USD
      }, 
      'CLIENT_ID'
    )

    Bridging

    Bridging allows you to swap stable tokens between chains.

    // Create new Bridging instance
    const bridging = symbiosis.newBridging()
    
    // Calculates fee for bridging and get execute function
    const { execute, fee, tokenAmountOut } = await bridging.exactIn(
        tokenAmountIn, // TokenAmount object
        tokenOut, // Token object
        to, // to account address
        revertableAddress // account who can revert stucked transaction
    )
    
    // Execute transaction
    const { response, waitForMined } = await execute(
        signer // ethers Signer instance to sign transaction
    )
    
    // Wait for transaction to be mined
    const { receipt, waitForComplete } = await waitForMined()
    
    // Wait for transaction to be completed on recipient chain
    const log = await waitForComplete()

    Send bridging transaction manually

    const bridging = symbiosis.newBridging()
    
    // transactionRequest contains everything you need to send a transaction by yourself
    const { transactionRequest } = await bridging.exactIn(...)
    
    // Send transaction or get receipt
    const receipt = ...
    
    // Wait for transaction to be completed on recipient chain
    const log = await bridging.waitForComplete(receipt)

    Swapping

    A combination of uniswap and bridging allowing you to swap any supported tokens between networks.

    // Create new Swapping instance
    const swapping = symbiosis.newSwapping()
    
    // Calculates fee for bridging between networks and get execute function
    const { execute, fee, tokenAmountOut, route, priceImpact } = await swapping.exactIn(
        tokenAmountIn, // TokenAmount object
        tokenOut, // Token object
        from, // from account address
        to, // to account address
        revertableAddress, // account who can revert stucked transaction
        slippage, // slippage
        deadline, // deadline date in seconds
        use1Inch // boolean (use 1inch router for swaps)
    )
    
    // Execute transaction
    const { response, waitForMined } = await execute(
        signer // ethers Signer instance to sign transaction
    )
    
    // Wait for transaction to be mined
    const { receipt, waitForComplete } = await waitForMined()
    
    // Wait for transaction to be completed on recipient chain
    const log = await waitForComplete()

    Send swapping transaction manually

    const swapping = symbiosis.newSwapping()
    
    // transactionRequest contains everything you need to send a transaction by yourself
    const { transactionRequest } = await swapping.exactIn(...)
    
    // Send transaction or get receipt
    const receipt = ...
    
    // Wait for transaction to be completed on recipient chain
    const log = await swapping.waitForComplete(receipt)

    Zapping to Symbiosis

    Cross-chain zaps automate liquidity adding to the Symbiosis stable pools, DeFi protocols, NFT, etc.

    // Create new Swapping instance
    const swapping = symbiosis.newZapping()
    
    // Calculates fee for bridging between networks and get execute function
    const { execute, fee, tokenAmountOut, route, priceImpact } = await swapping.exactIn(
        tokenAmountIn, // TokenAmount object
        poolAddress, // Stable pool address 
        poolChainId, // Stable pool chain id 
        from, // from account address
        to, // to account address
        revertableAddress, // account who can revert stucked transaction
        slippage, // slippage
        deadline, // deadline date in seconds
        use1Inch // boolean (use 1inch router for swaps)
    )

    All next steps as in swapping example

    Zapping to Aave/Cream

    Cross-chain zaps automate liquidity adding to the Symbiosis stable pools, DeFi protocols, NFT, etc.

    // Create new Swapping instance
    const swapping = symbiosis.newZappingAave()
    `or`
    const swapping = symbiosis.newZappingCream()
    
    // Calculates fee for bridging between networks and get execute function
    const { execute, fee, tokenAmountOut, route, priceImpact } = await swapping.exactIn(
        tokenAmountIn, // TokenAmount object
        tokenOut, // Token object
        from, // from account address
        to, // to account address
        revertableAddress, // account who can revert stucked transaction
        slippage, // slippage
        deadline, // deadline date in seconds
        use1Inch // boolean (use 1inch router for swaps)
    )

    All next steps as in swapping example

    Get stuck (pending) transactions and revert them

    Sometimes relayers are unable to process your request for bridging. This could happen if you set the small/wrong fee or send the invalid calldata.

    These requests can be found and cancelled.

    Find stuck transactions:

    import { getPendingRequests } from 'symbiosis-js-sdk'
    
    // Get get all pending requests from all chains
    const pendingRequests = await symbiosis.getPendingRequests(
        address // Account address
    )

    Revert stucked transaction:

    // Create RevertPending instance
    const revertPending = symbiosis.newRevertPending(
        request // PendingRequest object
    )
    
    // Calculates fee for revert and get execute function
    const { fee, execute } = await revertPending.revert()
    
    // Execute transaction using signer
    const { waitForMined } = await execute(signer)
    
    // Wait for transaction to be mined
    const { receipt, waitForComplete } = await waitForMined()
    
    // Wait for transaction to be fully reverted on original sender chain
    const log = await waitForComplete()

    Send revert transaction manually

    const revertPending = symbiosis.newRevertPending(request)
    
    // transactionRequest contains everything you need to send a transaction by yourself
    const { transactionRequest } = await revertPending.revert()
    
    ... // Send transaction
    
    // Wait for transaction to be completed on recipient chain
    const log = await revertPending.waitForComplete()

    Keywords

    none

    Install

    npm i symbiosis-js-sdk

    DownloadsWeekly Downloads

    379

    Version

    2.7.12

    License

    MIT

    Unpacked Size

    5.8 MB

    Total Files

    93

    Last publish

    Collaborators

    • symbiosis