Limit order Job example
This example will walk you through creating a basic Warp job and condition without using a premade template. For general information on how Warp works, visit the Overview page. For a tutorial on how to use the Warp App, visit the Get started page.
The workflow
-
Create a Warp account. Accounts are smart contracts that only you and your Warp jobs have permission to access.
-
Add Luna to your account.
-
Create a job with the swap parameters such as price per unit, how much Luna you're willing to spend, etc. For this example, suppose that you want to spend 1 Luna to receive a minimum of 9500 Astro. You can see the job message in the example below.
-
Using a query message, Create the condition, where you specify that for your 1 Luna, you want to receive at least 9500 Astro Luna (~0.00010526 Luna per unit).
-
Submit the job, which includes your transaction, condition, and a reward. The reward is the amount that you will pay the keeper for executing your transaction on your behalf when the price is right. The reward will likely be equal to the gas cost for executing your job plus a little extra for the keeper’s effort.
-
Now onto the keeper side of things. The keepers scan the transaction pool and see which transactions have conditions that resolve to true.
-
Once swapping 1 Luna yields you at least 9500 $Astro, the keeper sees that your job condition is now valid.
-
At this point, the keeper (which can be anyone, including yourself) executes the transaction, swapping the tokens. Now the Astro is in your Warp account, which you can access and withdraw.
The specifics
The Query
This example will use Astroport's Testnet Router to execute the job's swap. The Router allows you to use a single contract for multiple assets instead of having to keep track of pool addresses. For more information on queries, visit the Query page.
The following code is the query for the Astroport Router.
terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64
is the Astroport Router address for the Pisco Testnet.
1000000
uLuna (1 Luna) is the amount to be swapped.
The following code is the query for the Astroport Router.
terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64
is the Astroport Router address for the Pisco Testnet.
1000000
uLuna (1 Luna) is the amount to be swapped.
Query Response
Once you compose the query, you must be aware of the format of its corresponding response:
The following is an example response from the above query:
The selector $.amount
will give you the value inside the response, which is 9400000000
.
The following is an example response from the above query:
The selector $.amount
will give you the value inside the response, which is 9400000000
.
The Job message
The job message for the swap is as follows. For more information on jobs, visit the Overview page
As you can see, the transaction for the Router is very similar to the simulation query.
We specify that we would like to send 1000000
uLuna (1 Luna) for the swap in the funds portion.
We specify that the minimum uAstro received should be 9500000000
, or 9500 $Astro tokens. terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv
is the $Astro token address.
The job message for the swap is as follows. For more information on jobs, visit the Overview page
As you can see, the transaction for the Router is very similar to the simulation query.
We specify that we would like to send 1000000
uLuna (1 Luna) for the swap in the funds portion.
We specify that the minimum uAstro received should be 9500000000
, or 9500 $Astro tokens. terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv
is the $Astro token address.
The Condition
You want to swap 1 Luna to get 9500 Astro.
Your condition is:
if the swap query returns at least 9500 $Astro for 1 Luna, execute the job message. That way, you will receive no less than 9500 $Astro tokens.
To specify this condition using the interface, create a simple expression. For more information on conditions, visit the Conditions page.
-
Select Expression from the interface. On the Left side, select Query and input the query message.
-
The selector will be
$.amount
, which specifies that the part of the query response you want to evaluate is theamount
field. -
The operator will be GTE (greater than or equal to).
-
On the right side of the expression, input
9500000000
, which is the minimum amount of $Astro you want to receive. -
When the keeper evaluates the condition, they will run the query to see if the
amount
portion of the response is greater than or equal to9500000000
. If the condition is met, they can execute the job message and collect their reward. -
Upon successful execution of your job, you will receive 9500 $Astro in your account.
Congratulations! You just made a limit swap using Warp!