| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "messages": [ |
| 5 | { |
| 6 | "app": "payment", |
| 7 | "payload": { |
| 8 | "asset": "base", |
| 9 | "outputs": [ |
| 10 | { |
| 11 | "address": "{$addr}", |
| 12 | "amount": "{$withdraw_asset ? $base_inp : ($withdraw_amount + $base_inp)}" |
| 13 | } |
| 14 | ] |
| 15 | } |
| 16 | }, |
| 17 | { |
| 18 | "app": "payment", |
| 19 | "payload": { |
| 20 | "asset": "{$asset_ct}", |
| 21 | "outputs": [ |
| 22 | { |
| 23 | "address": "{$addr}", |
| 24 | "amount": "{$withdraw_amount}" |
| 25 | } |
| 26 | ] |
| 27 | }, |
| 28 | "if": "{$withdraw_asset}" |
| 29 | }, |
| 30 | { |
| 31 | "app": "state", |
| 32 | "state": "{var[$w_total_key] -= $withdraw_amount;if(var[$w_total_key] == 0)var[$w_total_key] = false;var[$withdraw_key] -= $withdraw_amount;if(var[$withdraw_key] == 0)var[$withdraw_key] = false;var[$key] -= $withdraw_asset ? ($withdraw_amount * $ratio) : ($withdraw_amount / $ratio);if(var[$key] == 0)var[$key] = false;response['message'] = 'withdrawn exchanged amount ('||$withdraw_asset ? 'assets': 'bytes' ||') at '||$ratio||' bytes per token';}" |
| 33 | } |
| 34 | ], |
| 35 | "init": "{$asset_ct = 'U0rLnB4lXupOc1u1woZzzrr0xscmOc50wvrpXAMWq3Q=';if(!var['-Last price'] and !trigger.data.price){bounce('Price must be defined before first exchange');}if(trigger.data.price){$ratio = round(trigger.data.price);if($ratio <= 0){bounce('Price not allowed');}}else{$ratio = var['-Last price'];}$addr = trigger.address;$base_inp = trigger.output[[asset=base]] - 700;if(trigger.output[[asset!=base]].asset != 'none')$asset = trigger.output[[asset!=base]].asset;if($asset){if($asset == 'ambiguous')bounce('Only 1 asset per tx');if($asset != $asset_ct)bounce('Asset not allowed, please send ' || $asset_ct);$asset_inp = (trigger.output[[asset!=base]] != 0) ? trigger.output[[asset!=base]] : bounce('Zero asset tx');}$base_key = $addr || $ratio || 'b';$asset_key = $addr || $ratio;$total_key = 'b' || $ratio;$total_asset_key = 'a' || $ratio;$exch_key = 'b_' || $ratio ;$exch_asset_key = 'a_' || $ratio ;$max_b_to_exchange = var[$total_key] - var[$exch_key];$max_a_to_exchange = var[$total_asset_key] - var[$exch_asset_key];$base_inp_round = ($base_inp - ($base_inp % $ratio));$base_inp_in_asset = $base_inp_round/$ratio;$asset_inp_in_bytes = $asset_inp*$ratio;$withdraw_asset = var[$exch_asset_key] and var[$base_key] and var[$exch_asset_key] > 0 and var[$base_key] > 0;$withdraw_base = var[$exch_key] and var[$asset_key] and var[$exch_key] > 0 and var[$asset_key] > 0;$exchange_asset = $asset and $byte_amount and !var[$base_key];$exchange_base = !$asset and $asset_amount and !var[$asset_key];$cancel_asset = trigger.data.cancel and var[$asset_key] and var[$asset_key] > 0;$cancel_base = trigger.data.cancel and var[$base_key] and var[$base_key] > 0;}" |
| 36 | } |
| 37 | ] |