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