var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=3&rec=1&url=https://docs.warp.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

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

  1. Create a Warp account. Accounts are smart contracts that only you and your Warp jobs have permission to access.

  2. Add Luna to your account.

  3. 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.

  4. 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).

  5. 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.

  6. Now onto the keeper side of things. The keepers scan the transaction pool and see which transactions have conditions that resolve to true.

  7. Once swapping 1 Luna yields you at least 9500 $Astro, the keeper sees that your job condition is now valid.

  8. 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.

Query

_28
{
_28
"wasm": {
_28
"smart": {
_28
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_28
"msg": {
_28
"simulate_swap_operations": {
_28
"offer_amount": "1000000",
_28
"operations": [
_28
{
_28
"astro_swap": {
_28
"ask_asset_info": {
_28
"token": {
_28
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_28
}
_28
},
_28
"offer_asset_info": {
_28
"native_token": {
_28
"denom": "uluna"
_28
}
_28
}
_28
}
_28
}
_28
]
_28
}
_28
}
_28
}
_28
}
_28
}

terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64 is the Astroport Router address for the Pisco Testnet.

Query

_28
{
_28
"wasm": {
_28
"smart": {
_28
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_28
"msg": {
_28
"simulate_swap_operations": {
_28
"offer_amount": "1000000",
_28
"operations": [
_28
{
_28
"astro_swap": {
_28
"ask_asset_info": {
_28
"token": {
_28
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_28
}
_28
},
_28
"offer_asset_info": {
_28
"native_token": {
_28
"denom": "uluna"
_28
}
_28
}
_28
}
_28
}
_28
]
_28
}
_28
}
_28
}
_28
}
_28
}

Query

_28
{
_28
"wasm": {
_28
"smart": {
_28
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_28
"msg": {
_28
"simulate_swap_operations": {
_28
"offer_amount": "1000000",
_28
"operations": [
_28
{
_28
"astro_swap": {
_28
"ask_asset_info": {
_28
"token": {
_28
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_28
}
_28
},
_28
"offer_asset_info": {
_28
"native_token": {
_28
"denom": "uluna"
_28
}
_28
}
_28
}
_28
}
_28
]
_28
}
_28
}
_28
}
_28
}
_28
}

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

_28
{
_28
"wasm": {
_28
"smart": {
_28
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_28
"msg": {
_28
"simulate_swap_operations": {
_28
"offer_amount": "1000000",
_28
"operations": [
_28
{
_28
"astro_swap": {
_28
"ask_asset_info": {
_28
"token": {
_28
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_28
}
_28
},
_28
"offer_asset_info": {
_28
"native_token": {
_28
"denom": "uluna"
_28
}
_28
}
_28
}
_28
}
_28
]
_28
}
_28
}
_28
}
_28
}
_28
}

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:

Response

_10
{
_10
"amount": "9400000000"
_10
}

Response

_10
{
_10
"amount": "9400000000"
_10
}

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.

Response

_10
{
_10
"amount": "9400000000"
_10
}

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.

Job

_30
{
_30
"wasm": {
_30
"execute": {
_30
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_30
"msg": {
_30
"execute_swap_operations": {
_30
"max_spread": "0.15",
_30
"minimum_receive": "9500000000",
_30
"operations": [
_30
{
_30
"astro_swap": {
_30
"ask_asset_info": {
_30
"token": {
_30
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_30
}
_30
},
_30
"offer_asset_info": {
_30
"native_token": {
_30
"denom": "uluna"
_30
}
_30
}
_30
}
_30
}
_30
]
_30
}
_30
},
_30
"funds": [{"denom":"uluna","amount":"1000000"}]
_30
}
_30
}
_30
}

We specify that we would like to send 1000000 uLuna (1 Luna) for the swap in the funds portion.

Job

_30
{
_30
"wasm": {
_30
"execute": {
_30
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_30
"msg": {
_30
"execute_swap_operations": {
_30
"max_spread": "0.15",
_30
"minimum_receive": "9500000000",
_30
"operations": [
_30
{
_30
"astro_swap": {
_30
"ask_asset_info": {
_30
"token": {
_30
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_30
}
_30
},
_30
"offer_asset_info": {
_30
"native_token": {
_30
"denom": "uluna"
_30
}
_30
}
_30
}
_30
}
_30
]
_30
}
_30
},
_30
"funds": [{"denom":"uluna","amount":"1000000"}]
_30
}
_30
}
_30
}

We specify that the minimum uAstro received should be 9500000000, or 9500 $Astro tokens. terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv is the $Astro token address.

Job

_30
{
_30
"wasm": {
_30
"execute": {
_30
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_30
"msg": {
_30
"execute_swap_operations": {
_30
"max_spread": "0.15",
_30
"minimum_receive": "9500000000",
_30
"operations": [
_30
{
_30
"astro_swap": {
_30
"ask_asset_info": {
_30
"token": {
_30
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_30
}
_30
},
_30
"offer_asset_info": {
_30
"native_token": {
_30
"denom": "uluna"
_30
}
_30
}
_30
}
_30
}
_30
]
_30
}
_30
},
_30
"funds": [{"denom":"uluna","amount":"1000000"}]
_30
}
_30
}
_30
}

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.

Job

_30
{
_30
"wasm": {
_30
"execute": {
_30
"contract_addr": "terra1na348k6rvwxje9jj6ftpsapfeyaejxjeq6tuzdmzysps20l6z23smnlv64",
_30
"msg": {
_30
"execute_swap_operations": {
_30
"max_spread": "0.15",
_30
"minimum_receive": "9500000000",
_30
"operations": [
_30
{
_30
"astro_swap": {
_30
"ask_asset_info": {
_30
"token": {
_30
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
_30
}
_30
},
_30
"offer_asset_info": {
_30
"native_token": {
_30
"denom": "uluna"
_30
}
_30
}
_30
}
_30
}
_30
]
_30
}
_30
},
_30
"funds": [{"denom":"uluna","amount":"1000000"}]
_30
}
_30
}
_30
}

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.

  1. Select Expression from the interface. On the Left side, select Query and input the query message.

  2. The selector will be $.amount, which specifies that the part of the query response you want to evaluate is the amount field.

  3. The operator will be GTE (greater than or equal to).

  4. On the right side of the expression, input 9500000000, which is the minimum amount of $Astro you want to receive.

  5. 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 to 9500000000. If the condition is met, they can execute the job message and collect their reward.

  6. Upon successful execution of your job, you will receive 9500 $Astro in your account.

Congratulations! You just made a limit swap using Warp!