terra-money/warp-contracts

Feature Request: Adding if-else Condition Support for Job Creations

0x7183 opened this issue · 9 comments

0x7183 commented

BIG Labs is interested in contributing to Warp Contracts by adding the ability to use if-else conditions when creating jobs.
We would like to discuss the technical aspects and implementation details with the Warp Contracts development team.

@0x7183 can you give a job example of using if else?

0x7183 commented

@llllllluc following some examples:

  1. A Grid bot using warp
  2. Most of the trading strategies
  3. Handling of errors in sub messages

@llllllluc following some examples:

  1. A Grid bot using warp
  2. Most of the trading strategies
  3. Handling of errors in sub messages

sorry i mean job example where the condition needs if else, can you write some sudo code to help me better understand? the more detail the better maybe use grid bot as example

0x7183 commented

With a grid bot we need to buy or sell an asset based on the price.

Right now there isn't a way to implement it using only warp.

We'll require a job for the buy message with the buy condition and a job with for the sell message with the sell condition.
Also when a job is triggered we have to delete the other one and create a new buy and sell message updating the parameters based on the last message.

What we need is something like that in pseudo code:

If buy:
buy msg
else if sell:
sell msg
else:
pass

Sorry for the formatting, but I'm from phone and is pretty late here.

If this isn't enough I'll provide more details tomorrow!

I see, this is a nice feature we should support, it's like having 2 condition field and 2 msgs fields, if cond 1 resolves to true, then execute msgs 1, if cond 2 resolves to true, then execute msgs 2, if both resolves to false, then do nothing, but what if both resolve to true? I'm trying to think of an elegant way to implement this. Maybe you can bring this up in warp telegram, and let @vladjdk and @simke9445 chime in.

when a job is triggered we have to delete the other one and create a new buy and sell message updating the parameters based on the last message.

I think this is already supported by the recurring job, where you can update var every time it executes (recurring job is after you execute, it will create a new one)

0x7183 commented

@vladjdk told us to open an issue on Github and discuss there the implementation details, if you're ok with it we can start working at it and make a PR at the end.

Just what is the main branch?

awesome! the pre release branch is in #67, looking forward to the PR!

Cool idea, me and @vladjdk were discussing this on several occasions, and its great that you guys took a hand of it.

Ideally this would work very similar to a switch statement.

Job would look like this:

  • cA && tA
  • cB && tB
  • cC && tC
    • c - condition
    • t - set of transactions

in your case:

  • cA = buy condition
  • tA = buy tx
  • cB = sell condition
  • tB = sell tx
  • cA and cB can be simple static var conditions, aka "state" == "buy" | "sell", where state var is kept in job's memory.