symbiosis-sdk v2.3.1
symbiosis-sdk
Installation
npm i symbiosis-sdk
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).
import { Symbiosis } from 'symbiosis-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
})
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
)
// 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)
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-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()
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago