DEX Limit Orders

Let's say you want to enable users to create limit orders. With AMMs, this is complicate and is an area of active research. With Supercool, you can add limit order capabilities to any standard DEX.
Consider a limit order to buy ETH at 1000 DAI. If you approve the relayer account to spend 1000 DAI, then you can set up a limit order rule that will monitor Uniswap for the spot price and make a buy transaction when the ETH price in the ETH <> DAI pool crosses 1000 DAI.
And if you prefer not to approve the relayer to make token transfers, you can set a DAI approval on the On-chain Policy Engine, which constrains the types of transactions the relayer can make. In this case, you could approve the Policy Engine to only make calls to Uniswap that swap DAI for ETH.
Assuming you set up your ERC-20 approvals, here's a code example for the above limit order:
import { AutomationClient, jobdefs } from '@supercoolxyz/automation-client'
const apiKey = '...'
const apiSecret = '...'
const client = new AutomationClient({apiKey, apiSecret})
// Create payment job to send payments out every day.
// Your relayer blockchain account will be automatically connected to the job
// and will run the job execution.
const jobConfig = {
display_name: 'eth-limit-buy-order',
runType: {
type: 'per_block',
},
definition: jobdefs.UniswapLimitOrder({
// The chain to run the job on
chain: 'ethereum',
// The DAI address
tokenSrcAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
// WETH address
tokenDstAddress: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
// Supercool will check the `decimals` method on the destination contract.
// Use "priceRaw" if you want to enter the price in the smallest underlying
// units or if the ERC-20 contract does not implement `decimals`.
pricePretty: "1000",
// The owner of the DAI we are spending
from: "0xdeadbeef...",
// Where the resulting WETH should be sent
to: "0xbadfeed..."
})
}
const job = await client.createJob(jobConfig)
console.log(`Started job "${job.display_name}" with ID: ${job.id}`)