Processing Limit Orders
The following page provides an overview of how we process a limit order on the Kromatika dapp.
This is an example created when we were in the beta phase of our deployment. In the meantime, we have successfully launched yet the example remains clear and valuable for explaining the mechanisms behind our protocol.
Process limit order
Let's try and create a BUY limit order on Uniswap V3 (on Kovan) for pairs DAI / LINK. The current market price is 14.5691 DAI per LINK We would like to buy LINK tokens with 0.01 DAI at a target price of 14.352 DAI per LINK. Note: this is close to the market price. For demo purposes, we need to make it closer so that it can get executed quickly enough
We need to create a buy limit order (using our dapp) and send 0.01 DAI to the smart contracts, along with the target price range.
The smart contracts are responsible for managing the buy limit orders and will automatically open a position on Uniswap V3, resulting in the following position being created:
As you can see, our target price range is just outside of the current market price. Let’s try to lower the current/market price towards the min price of 14.266 DAI per LINK, so that Uniswap V3 will start buying LINK with our DAI automatically. We will lower the market price if there are users swapping LINK for DAI (they are selling LINK and getting DAI). Let’s do a similar swap on Uniswap V3 (we will do a huge swap to reduce the price extensively for testing purposes).
Perform upkeep for limit orders
The processed buy limit order DAI/LINK can now be automatically closed by the Chainlink Keeper. Let’s go back and check our Chainlink Keeper details:
The Chainlink Keeper has automatically performed an upkeep, closing our buy limit order in the process and charging us 0.23 LINK tokens for it.
As seen on Uniswap v3, the buy limit order was successfully closed during the Chainlink Upkeep.
We bought 0.0007009 LINK tokens with our 0.01 DAI, with an average price of 14.26 DAI per LINK. That’s much better than our initial target price (14.352 DAI per LINK). Plus, we also earned swap fees paid by the users that are performing the swaps.
As seen in the previous steps, when performing upkeeps on Chainlink, we are being charged LINK tokens (0.23 LINK) which is deducted from the Keepers balance for upkeep. The automatic replenishment of Chainlink Keepers is done through charging a maintenance fee to the Kromatika dapp users for processing their limit orders, so that there is no extra step of manually adding LINK funds to Chainlink Keepers.
This automatic replenishment of Chainlink Keepers is done by charging maintenance fees to the users for processing their limit orders.
E.g. during our testing on mainnet, we have obtained the following numbers:
perform upkeep with 20 limit orders on UniV3 at 60 GWEI gasPrice —
gasUsed: 2105557 x gasPrice: 60 GWEI = 0.12633342 ETH = 18.52 LINK + 20% Chainlink premium = 22.22 LINK per upkeep
22.22 LINK divided among 20 limit or -> 1.1 LINK per limit order ~ $28.
The end user will be charged a maintenance fee per limit order = $28. Imagine this on Arbitrum ONE where gas price is 1 gwei, resulting in 60 times lower fees ~ $0.50 maintenance fee per limit order.