2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let owner = base58'3NBmj1eEDJmrQ16GJkmVU1p31MTURgoV38r' |
---|
5 | | - | |
---|
6 | | - | let LiquidAssetId = base58'GhAFhXzwCYfvcXQ3GHFaQFnCzAuYCT156qFqiYyzfkzv' |
---|
7 | | - | |
---|
8 | | - | let WAVESID = unit |
---|
9 | | - | |
---|
10 | | - | @Callable(contextObj) |
---|
11 | | - | func uniswap (comission,minTokenRecieve) = if (if ((0 > comission)) |
---|
12 | | - | then true |
---|
13 | | - | else (comission > 100)) |
---|
14 | | - | then throw("incorrect comission value") |
---|
15 | | - | else { |
---|
16 | | - | let wavesAmount = getIntegerValue(this, "wavesAmount") |
---|
17 | | - | let liquidAmount = getIntegerValue(this, "liquidAmount") |
---|
18 | | - | let payment = match contextObj.payment { |
---|
19 | | - | case p: AttachedPayment => |
---|
20 | | - | p |
---|
21 | | - | case _ => |
---|
22 | | - | throw("Payment not attached") |
---|
23 | | - | } |
---|
24 | | - | let assetIdReceived = payment.assetId |
---|
25 | | - | let tokenReceiveAmount = payment.amount |
---|
26 | | - | if ((assetIdReceived == unit)) |
---|
27 | | - | then { |
---|
28 | | - | let tokenSendAmount = ((fraction(liquidAmount, tokenReceiveAmount, (tokenReceiveAmount + wavesAmount)) * (100 - comission)) / 100) |
---|
29 | | - | if ((minTokenRecieve > tokenSendAmount)) |
---|
30 | | - | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") |
---|
31 | | - | else { |
---|
32 | | - | let assetIdSent = LiquidAssetId |
---|
33 | | - | ScriptResult(WriteSet([DataEntry("liquidAmount", (liquidAmount - tokenSendAmount)), DataEntry("wavesAmount", (wavesAmount + tokenReceiveAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) |
---|
34 | | - | } |
---|
35 | | - | } |
---|
36 | | - | else if ((assetIdReceived == LiquidAssetId)) |
---|
37 | | - | then { |
---|
38 | | - | let tokenSendAmount = ((fraction(wavesAmount, tokenReceiveAmount, (tokenReceiveAmount + liquidAmount)) * (100 - comission)) / 100) |
---|
39 | | - | if ((minTokenRecieve > tokenSendAmount)) |
---|
40 | | - | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") |
---|
41 | | - | else { |
---|
42 | | - | let assetIdSent = unit |
---|
43 | | - | ScriptResult(WriteSet([DataEntry("liquidAmount", (liquidAmount + tokenReceiveAmount)), DataEntry("wavesAmount", (wavesAmount - tokenSendAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) |
---|
44 | | - | } |
---|
45 | | - | } |
---|
46 | | - | else throw("Asset is not allowed") |
---|
47 | | - | } |
---|
48 | | - | |
---|
49 | | - | |
---|
50 | | - | |
---|
51 | | - | @Callable(contextObj) |
---|
52 | | - | func withdraw () = { |
---|
53 | | - | let LiquidBalance = assetBalance(this, LiquidAssetId) |
---|
54 | | - | let WavesBalance = wavesBalance(this) |
---|
55 | | - | if ((contextObj.caller.bytes == owner)) |
---|
56 | | - | then ScriptResult(WriteSet([DataEntry("liquidAmount", "withdrawn"), DataEntry("wavesAmount", "withdrawn")]), TransferSet([ScriptTransfer(contextObj.caller, LiquidBalance, LiquidAssetId), ScriptTransfer(contextObj.caller, WavesBalance, unit)])) |
---|
57 | | - | else throw("You are not exchanger's owner") |
---|
58 | | - | } |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | @Verifier(contextObj) |
---|
62 | | - | func verify () = true |
---|
63 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey = base58'3NBmj1eEDJmrQ16GJkmVU1p31MTURgoV38r' |
---|
| 4 | + | sigVerify(tx.bodyBytes, tx.proofs[0], PubKey) |
---|