Integration Guide
How to integrate the Orion Protocol SDK into your UI.
Last updated
How to integrate the Orion Protocol SDK into your UI.
Last updated
Let's consider integration of Orion Protocol with your UI.
Orion Protocol's SDK operate with OrionUnit — a chain-in-environment abstraction such as "Ethereum-in-production", "bsc-in-production", "fantom-in-testing", etc.
When your UI connects to a wallet (through Metamask or Wallet Connect, for example), you should get access to a signer. The signer is the API's entity that allows to sign transactions.
Currently, the SDK requires the . Possibly, in the future, we will consider adding a common signer interface.
For example, you can access the signer through Metamask:
That's all. You can easily get tradeable assets this way:
Orion Protocol charges you only with available fee assets. You can get the fee assets list:
If you choose ORN as fee asset, you will pay 0.2% of your order's amount (quoted in ORN).
If you choose BNB as fee asset, you will pay 0.3% of your order's amount (quoted in BNB).
If you choose USDT as fee asset, you will pay 0.3% of your order's amount (quoted in USDT).
You can swap one asset for another in two ways:
You can specify how much funds you want to spend (exact spend)
You can specify how much funds you want to receive (exact receive)
Each time when the user changes form inputs, you should get the swap info:
When you call the getSwapInfo
method, the SDK internally makes a request to service, deciding the execution route from either of the two: "pool" or "aggregator".
When you get "pool", that means you just need to call the method on the exchange contract to make the swap (DEX only swap execution). When you get "aggregator", that means you need to send the order to the aggregator and wait for execution (the aggregator can execute order on CEX's and DEX's)
If you don't want to deposit funds to the exchange contract, you can set "poolOnly" option to true.
The SDK has multiple ways to make a swap:
Orion Protocol requires a method to transfer your funds from you. When you swap tokens (not coins on their native chains i.e. ETH on Ethereum for example), we use "approve" to reach this goal. But approve is not always possible. For example, if you want to swap BNB for ORN, you can't approve BNB because BNB is not a token. BNB is the native currency of Binance Smart Chain. So, in a case when the native currency is the desired asset AND the route is "aggregator", you should funds (native cryptocurrency) to the exchange contract.
Call orionUnit.exchange.swapMarket
. This is the simplest way to swap. All inclusive method.
Call orionUnit.orionAggregator.placeOrder
. This is a method used to place an order to the aggregator. More verbose.
Call the method swapThroughOrionPool
on the exchange contract. This is a method to swap tokens through pool.