| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | $min_bid_amnt = 100000; |
| 29 | $fee = 10000; |
| 30 | $seed_amnt = 10000; |
| 31 | $commission = var['commisson'] otherwise 0; |
| 32 | $commission_address = 'B7KF2F5AP6BZLXOE2EGHH6BKZWVNIKWF'; |
| 33 | $commission_payout_threshold = 10000; |
| 34 | $bot_address = '4H2FOFBP7ST6BLYWHZ3GUV5PHY626AM4'; |
| 35 | |
| 36 | |
| 37 | |
| 38 | $game_status = var['game_status'] otherwise 'not started'; |
| 39 | $bid_amnt = trigger.output[[asset=base]]; |
| 40 | |
| 41 | $game_finished = ($bot_address == trigger.initial_address); |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | $bid_status = ($bid_amnt >= $min_bid_amnt) otherwise false; |
| 48 | if ($bid_status == false AND trigger.initial_address != $bot_address) |
| 49 | bounce('Your bid is too small and will be returned to you - fees'); |
| 50 | }", |
| 51 | "messages": [ |
| 52 | { |
| 53 | "app": "payment", |
| 54 | "if": "{$game_finished}", |
| 55 | "payload": { |
| 56 | "asset": "base", |
| 57 | "outputs": [ |
| 58 | { |
| 59 | "address": "{ var['leader'] }", |
| 60 | "amount": "{ var['winnings'] }" |
| 61 | }, |
| 62 | { |
| 63 | "address": "{ var['author'] }", |
| 64 | "amount": "{ var['winnings'] }" |
| 65 | } |
| 66 | ] |
| 67 | } |
| 68 | }, |
| 69 | { |
| 70 | "app": "payment", |
| 71 | "if": "{ $commission >= $commission_payout_threshold }", |
| 72 | "payload": { |
| 73 | "asset": "base", |
| 74 | "outputs": [ |
| 75 | { |
| 76 | "address": "{ $commission_address }", |
| 77 | "amount": "{ var['commission'] }" |
| 78 | } |
| 79 | ] |
| 80 | } |
| 81 | }, |
| 82 | { |
| 83 | "app": "state", |
| 84 | "state": "{ |
| 85 | |
| 86 | if ($bid_status AND $game_status == 'not started') { |
| 87 | var['stack_amnt'] = $bid_amnt - $fee; |
| 88 | var['winnings'] = var['stack_amnt'] / 2; |
| 89 | var['author'] = trigger.initial_address; |
| 90 | var['leader'] = trigger.initial_address; |
| 91 | var['game_status'] = 'running'; |
| 92 | response['message'] = 'Thank you for playing 1st'; |
| 93 | } |
| 94 | |
| 95 | if ($bid_status == true AND $game_status == 'running') { |
| 96 | var['stack_amnt'] += ($bid_amnt - $fee); |
| 97 | var['winnings'] = var['stack_amnt'] / 2; |
| 98 | var['leader'] = trigger.initial_address; |
| 99 | var['game_status'] = 'running'; |
| 100 | response['message'] = 'Thank you for playing'; |
| 101 | } |
| 102 | |
| 103 | if ($game_finished) { |
| 104 | var['commission'] = balance[base] - $seed_amnt; |
| 105 | |
| 106 | |
| 107 | |
| 108 | var['game_status'] = 'not started'; |
| 109 | response['message'] = 'Game finished'; |
| 110 | } |
| 111 | }" |
| 112 | } |
| 113 | ] |
| 114 | } |
| 115 | ] |