1 | | - | # no script |
---|
| 1 | + | {-# STDLIB_VERSION 6 #-} |
---|
| 2 | + | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
| 3 | + | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | let free_to_borrom = addressFromStringValue("3PG7CHvBatHpChwm8reH74wfEwk1PHc8Rqy") |
---|
| 5 | + | |
---|
| 6 | + | let USDN_ASSET_ID = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' |
---|
| 7 | + | |
---|
| 8 | + | let boss = addressFromStringValue("3PRE5KH9oPGfFPs7fGnQcJ4wNshEDUPGj1t") |
---|
| 9 | + | |
---|
| 10 | + | let adminPublicKey = base58'Cr1ybL2JGg9GwJHA2JwqxBPfSW6Q7Jg4HvNrsEiCsHu6' |
---|
| 11 | + | |
---|
| 12 | + | let WX_SWAP_DAPP = Address(base58'3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93') |
---|
| 13 | + | |
---|
| 14 | + | let assets_in = ["DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"] |
---|
| 15 | + | |
---|
| 16 | + | func getBalance (assetId) = match assetId { |
---|
| 17 | + | case b: ByteVector => |
---|
| 18 | + | assetBalance(this, b) |
---|
| 19 | + | case _ => |
---|
| 20 | + | wavesBalance(this).available |
---|
| 21 | + | } |
---|
| 22 | + | |
---|
| 23 | + | |
---|
| 24 | + | func getBase1 (data) = { |
---|
| 25 | + | let p_data = split_4C(data, "_") |
---|
| 26 | + | let a = p_data[0] |
---|
| 27 | + | let a2 = p_data[1] |
---|
| 28 | + | let assetIn = assets_in[value(parseInt(p_data[2]))] |
---|
| 29 | + | let amountIn = p_data[3] |
---|
| 30 | + | $Tuple4(a, a2, assetIn, amountIn) |
---|
| 31 | + | } |
---|
| 32 | + | |
---|
| 33 | + | |
---|
| 34 | + | func getBase2 (data) = { |
---|
| 35 | + | let p_data = split(data, "_") |
---|
| 36 | + | let p1 = p_data[0] |
---|
| 37 | + | let t = p_data[1] |
---|
| 38 | + | $Tuple2(p1, t) |
---|
| 39 | + | } |
---|
| 40 | + | |
---|
| 41 | + | |
---|
| 42 | + | func getAssetBytes (assetId) = if ((assetId == "WAVES")) |
---|
| 43 | + | then unit |
---|
| 44 | + | else fromBase58String(assetId) |
---|
| 45 | + | |
---|
| 46 | + | |
---|
| 47 | + | func swap_wx (p,asset,amount,a) = { |
---|
| 48 | + | let call = invoke(WX_SWAP_DAPP, "swap", [1, a, toString(this)], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
| 49 | + | if ((call == call)) |
---|
| 50 | + | then nil |
---|
| 51 | + | else throw("Strict value is not equal to itself.") |
---|
| 52 | + | } |
---|
| 53 | + | |
---|
| 54 | + | |
---|
| 55 | + | func swap_swop (p,asset,amount) = { |
---|
| 56 | + | let swap = invoke(Address(fromBase58String(p)), "exchange", [1], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
| 57 | + | if ((swap == swap)) |
---|
| 58 | + | then nil |
---|
| 59 | + | else throw("Strict value is not equal to itself.") |
---|
| 60 | + | } |
---|
| 61 | + | |
---|
| 62 | + | |
---|
| 63 | + | func swap_puzzle (p,asset,amount,assetOut) = { |
---|
| 64 | + | let swap = invoke(Address(fromBase58String(p)), "swap", [assetOut, 1], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
| 65 | + | if ((swap == swap)) |
---|
| 66 | + | then nil |
---|
| 67 | + | else throw("Strict value is not equal to itself.") |
---|
| 68 | + | } |
---|
| 69 | + | |
---|
| 70 | + | |
---|
| 71 | + | @Callable(i) |
---|
| 72 | + | func borrow (amnt) = if (!(containsElement([free_to_borrom, boss, this], i.caller))) |
---|
| 73 | + | then throw("you are not allowed to borrow!") |
---|
| 74 | + | else { |
---|
| 75 | + | let currentBal = getBalance(USDN_ASSET_ID) |
---|
| 76 | + | if ((amnt > currentBal)) |
---|
| 77 | + | then throw("You cannnot borrow that much") |
---|
| 78 | + | else [ScriptTransfer(i.caller, amnt, USDN_ASSET_ID)] |
---|
| 79 | + | } |
---|
| 80 | + | |
---|
| 81 | + | |
---|
| 82 | + | |
---|
| 83 | + | @Callable(i) |
---|
| 84 | + | func setTreshold (amnt) = if (!(containsElement([free_to_borrom, boss, this], i.caller))) |
---|
| 85 | + | then throw("you are not allowed to do that!") |
---|
| 86 | + | else [IntegerEntry("treshold", amnt)] |
---|
| 87 | + | |
---|
| 88 | + | |
---|
| 89 | + | |
---|
| 90 | + | @Callable(i) |
---|
| 91 | + | func y (data) = if (if ((i.caller != this)) |
---|
| 92 | + | then (i.caller != boss) |
---|
| 93 | + | else false) |
---|
| 94 | + | then throw("you are not allowed to arb!") |
---|
| 95 | + | else { |
---|
| 96 | + | let data_array = split_4C(data, "|") |
---|
| 97 | + | let $t027512807 = getBase1(data_array[0]) |
---|
| 98 | + | let a = $t027512807._1 |
---|
| 99 | + | let a2 = $t027512807._2 |
---|
| 100 | + | let assetIn = $t027512807._3 |
---|
| 101 | + | let amountIn = $t027512807._4 |
---|
| 102 | + | let $t028122850 = getBase2(data_array[1]) |
---|
| 103 | + | let p1 = $t028122850._1 |
---|
| 104 | + | let t1 = $t028122850._2 |
---|
| 105 | + | let $t028552893 = getBase2(data_array[2]) |
---|
| 106 | + | let p2 = $t028552893._1 |
---|
| 107 | + | let t2 = $t028552893._2 |
---|
| 108 | + | let $t028982936 = getBase2(data_array[3]) |
---|
| 109 | + | let p3 = $t028982936._1 |
---|
| 110 | + | let t3 = $t028982936._2 |
---|
| 111 | + | let idu = if ((size(data_array[4]) > 1)) |
---|
| 112 | + | then split(data_array[4], "-") |
---|
| 113 | + | else nil |
---|
| 114 | + | if (if ((size(idu) > 0)) |
---|
| 115 | + | then true |
---|
| 116 | + | else (1 >= size(data_array[4]))) |
---|
| 117 | + | then { |
---|
| 118 | + | let amount_bef_assetIn = getBalance(getAssetBytes(assetIn)) |
---|
| 119 | + | if ((amount_bef_assetIn == amount_bef_assetIn)) |
---|
| 120 | + | then { |
---|
| 121 | + | let new_amountIn = if ((value(parseInt(amountIn)) > amount_bef_assetIn)) |
---|
| 122 | + | then amount_bef_assetIn |
---|
| 123 | + | else value(parseInt(amountIn)) |
---|
| 124 | + | if ((new_amountIn == new_amountIn)) |
---|
| 125 | + | then { |
---|
| 126 | + | let amount_bef_asset1 = getBalance(getAssetBytes(a)) |
---|
| 127 | + | if ((amount_bef_asset1 == amount_bef_asset1)) |
---|
| 128 | + | then { |
---|
| 129 | + | let swap1 = if ((t1 == "W")) |
---|
| 130 | + | then swap_wx(p1, assetIn, new_amountIn, a) |
---|
| 131 | + | else if ((t1 == "S")) |
---|
| 132 | + | then swap_swop(p1, assetIn, new_amountIn) |
---|
| 133 | + | else swap_puzzle(p1, assetIn, new_amountIn, a) |
---|
| 134 | + | if ((swap1 == swap1)) |
---|
| 135 | + | then { |
---|
| 136 | + | let nb = (getBalance(getAssetBytes(a)) - amount_bef_asset1) |
---|
| 137 | + | if ((nb == nb)) |
---|
| 138 | + | then { |
---|
| 139 | + | let amount_bef_asset2 = getBalance(getAssetBytes(a2)) |
---|
| 140 | + | if ((amount_bef_asset2 == amount_bef_asset2)) |
---|
| 141 | + | then { |
---|
| 142 | + | let swap2 = if ((t2 == "W")) |
---|
| 143 | + | then swap_wx(p2, a, nb, a2) |
---|
| 144 | + | else if ((t2 == "S")) |
---|
| 145 | + | then swap_swop(p2, a, nb) |
---|
| 146 | + | else swap_puzzle(p2, a, nb, a2) |
---|
| 147 | + | if ((swap2 == swap2)) |
---|
| 148 | + | then { |
---|
| 149 | + | let nb2 = (getBalance(getAssetBytes(a2)) - amount_bef_asset2) |
---|
| 150 | + | if ((nb2 == nb2)) |
---|
| 151 | + | then { |
---|
| 152 | + | let amount_bef_base_asset = getBalance(getAssetBytes(assetIn)) |
---|
| 153 | + | if ((amount_bef_base_asset == amount_bef_base_asset)) |
---|
| 154 | + | then { |
---|
| 155 | + | let swap3 = if ((t3 == "W")) |
---|
| 156 | + | then swap_wx(p3, a2, nb2, assetIn) |
---|
| 157 | + | else if ((t3 == "S")) |
---|
| 158 | + | then swap_swop(p3, a2, nb2) |
---|
| 159 | + | else swap_puzzle(p3, a2, nb2, assetIn) |
---|
| 160 | + | if ((swap3 == swap3)) |
---|
| 161 | + | then { |
---|
| 162 | + | let nb3 = (getBalance(getAssetBytes(assetIn)) - amount_bef_base_asset) |
---|
| 163 | + | if ((nb3 == nb3)) |
---|
| 164 | + | then { |
---|
| 165 | + | let treshold = valueOrElse(getInteger(this, "treshold"), 150000) |
---|
| 166 | + | if ((nb3 > (new_amountIn + treshold))) |
---|
| 167 | + | then [ScriptTransfer(i.caller, (nb3 - new_amountIn), getAssetBytes(assetIn))] |
---|
| 168 | + | else throw(((((((((("origin amountIn = " + amountIn) + ", new_amountIn = ") + toString(new_amountIn)) + ", newBal_1: ") + toString(nb)) + ", newBal_2: ") + toString(nb2)) + ", newBal_3: ") + toString(nb3))) |
---|
| 169 | + | } |
---|
| 170 | + | else throw("Strict value is not equal to itself.") |
---|
| 171 | + | } |
---|
| 172 | + | else throw("Strict value is not equal to itself.") |
---|
| 173 | + | } |
---|
| 174 | + | else throw("Strict value is not equal to itself.") |
---|
| 175 | + | } |
---|
| 176 | + | else throw("Strict value is not equal to itself.") |
---|
| 177 | + | } |
---|
| 178 | + | else throw("Strict value is not equal to itself.") |
---|
| 179 | + | } |
---|
| 180 | + | else throw("Strict value is not equal to itself.") |
---|
| 181 | + | } |
---|
| 182 | + | else throw("Strict value is not equal to itself.") |
---|
| 183 | + | } |
---|
| 184 | + | else throw("Strict value is not equal to itself.") |
---|
| 185 | + | } |
---|
| 186 | + | else throw("Strict value is not equal to itself.") |
---|
| 187 | + | } |
---|
| 188 | + | else throw("Strict value is not equal to itself.") |
---|
| 189 | + | } |
---|
| 190 | + | else throw("Strict value is not equal to itself.") |
---|
| 191 | + | } |
---|
| 192 | + | else nil |
---|
| 193 | + | } |
---|
| 194 | + | |
---|
| 195 | + | |
---|
| 196 | + | @Verifier(tx) |
---|
| 197 | + | func verify () = if (sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
| 198 | + | then true |
---|
| 199 | + | else sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], adminPublicKey) |
---|
| 200 | + | |
---|