3️⃣Trade calculation
Before trade calculation you should Set up SDK first.
Swaps in our SDK separated to two different type of swaps:
On-chain swaps- Since Rubic aggregates several DEXs, users can execute On-Chain Swaps and Bridges on Ethereum, BNB Smart Chain, Polygon, Harmony, Avalanche, Fantom, Moonriver, Solana, Arbitrum, Aurora, NEAR, and Telos other networks. By also utilizing external DEXs, users are ensured the best possible rates.
Cross-chain swaps: Rubic's protocol offers easy trading for more than 15,000+ assets across Polygon, BNB Smart Chain, Ethereum, Avalanche, MoonRiver, Fantom, Solana, Harmony, Arbitrum, Aurora, NEAR, Telos and other networks, using our custom and unique Cross-Chain Protocol. We utilize liquidity pools and our own smart contracts, Rubic provides an extremely easy-to-use Cross-Chain solution to all traders. Cross-Chain swaps are available between 80+ major networks right now
On Chain trade calculation
To use on-chain swaps and calculate them, you need an instantTrades
object located in the SDK instance. Inside the object is the calculateTrade
method, which takes the input token, the input swap amount, the output token address, and the transaction parameters.
The method returns an array of calculated DEX which can be represented as OnChainTrade
object or OnChainTradeError
object. Both contains DEX type, but first contains the trade and the second contains error reason. Example:
Done!
Cross Chain trade calculation
To use cross-chain swaps and calculate them, you need a crossChain
object, located in the SDK instance. Inside the object is the calculateTrade
method, which takes the input token, the input swap amount, the output token, and the transaction parameters.
It returns WrappedCrossChainTrade
object.
Using example:
What is next?
In this step, you get the real trade object. You have one last step left - execute a swap.
Last updated