2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let owner = base58'3N3LWiYdT9n8o6ecwFZGy6MCehhq6sLUFFL' |
---|
5 | | - | |
---|
6 | | - | let assetIdTokenA = base58'9Jsnot7RWQmTsfXtezQN7igoS2q1QF1jsotaxwh8Fxp4' |
---|
7 | | - | |
---|
8 | | - | let assetIdTokenB = unit |
---|
9 | | - | |
---|
10 | | - | let comission = 0 |
---|
11 | | - | |
---|
12 | | - | @Callable(contextObj) |
---|
13 | | - | func fund () = { |
---|
14 | | - | let payment = match contextObj.payment { |
---|
15 | | - | case p: AttachedPayment => |
---|
16 | | - | p |
---|
17 | | - | case _ => |
---|
18 | | - | throw("Payment not attached") |
---|
19 | | - | } |
---|
20 | | - | let assetIdReceived = payment.assetId |
---|
21 | | - | let tokenReceiveAmount = payment.amount |
---|
22 | | - | if (if ((assetIdReceived == assetIdTokenA)) |
---|
23 | | - | then !(isDefined(getString(this, "fundA"))) |
---|
24 | | - | else false) |
---|
25 | | - | then WriteSet([DataEntry("amountTokenA", tokenReceiveAmount), DataEntry("fundA", "funded")]) |
---|
26 | | - | else if (if ((assetIdReceived == assetIdTokenB)) |
---|
27 | | - | then !(isDefined(getString(this, "fundB"))) |
---|
28 | | - | else false) |
---|
29 | | - | then WriteSet([DataEntry("amountTokenB", tokenReceiveAmount), DataEntry("fundB", "funded")]) |
---|
30 | | - | else throw("already funded or you try to fund with incorrect asset") |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | |
---|
35 | | - | @Callable(contextObj) |
---|
36 | | - | func replenishment () = { |
---|
37 | | - | let payment = match contextObj.payment { |
---|
38 | | - | case p: AttachedPayment => |
---|
39 | | - | p |
---|
40 | | - | case _ => |
---|
41 | | - | throw("Payment not attached") |
---|
42 | | - | } |
---|
43 | | - | let assetIdReceived = payment.assetId |
---|
44 | | - | let tokenReceiveAmount = payment.amount |
---|
45 | | - | if (if ((assetIdReceived == assetIdTokenA)) |
---|
46 | | - | then !(isDefined(getString(this, "fundA"))) |
---|
47 | | - | else false) |
---|
48 | | - | then { |
---|
49 | | - | let amountTokenA = getIntegerValue(this, "amountTokenA") |
---|
50 | | - | WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount))]) |
---|
51 | | - | } |
---|
52 | | - | else if (if ((assetIdReceived == assetIdTokenB)) |
---|
53 | | - | then !(isDefined(getString(this, "fundB"))) |
---|
54 | | - | else false) |
---|
55 | | - | then { |
---|
56 | | - | let amountTokenB = getIntegerValue(this, "amountTokenB") |
---|
57 | | - | WriteSet([DataEntry("amountTokenA", (amountTokenB + tokenReceiveAmount))]) |
---|
58 | | - | } |
---|
59 | | - | else throw("there was an error in the replenishment") |
---|
60 | | - | } |
---|
61 | | - | |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | @Callable(contextObj) |
---|
65 | | - | func exchanger (minTokenRecieve) = if (if ((0 > comission)) |
---|
66 | | - | then true |
---|
67 | | - | else (comission > 100)) |
---|
68 | | - | then throw("incorrect comission value") |
---|
69 | | - | else { |
---|
70 | | - | let amountTokenB = getIntegerValue(this, "amountTokenB") |
---|
71 | | - | let amountTokenA = getIntegerValue(this, "amountTokenA") |
---|
72 | | - | let payment = match contextObj.payment { |
---|
73 | | - | case p: AttachedPayment => |
---|
74 | | - | p |
---|
75 | | - | case _ => |
---|
76 | | - | throw("Payment not attached") |
---|
77 | | - | } |
---|
78 | | - | let assetIdReceived = payment.assetId |
---|
79 | | - | let tokenReceiveAmount = payment.amount |
---|
80 | | - | if ((assetIdReceived == assetIdTokenB)) |
---|
81 | | - | then { |
---|
82 | | - | let tokenSendAmount = ((fraction(amountTokenA, tokenReceiveAmount, (tokenReceiveAmount + amountTokenB)) * (100 - comission)) / 100) |
---|
83 | | - | if ((minTokenRecieve > tokenSendAmount)) |
---|
84 | | - | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") |
---|
85 | | - | else { |
---|
86 | | - | let assetIdSent = assetIdTokenA |
---|
87 | | - | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA - tokenSendAmount)), DataEntry("amountTokenB", (amountTokenB + tokenReceiveAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) |
---|
88 | | - | } |
---|
89 | | - | } |
---|
90 | | - | else if ((assetIdReceived == assetIdTokenA)) |
---|
91 | | - | then { |
---|
92 | | - | let tokenSendAmount = ((fraction(amountTokenB, tokenReceiveAmount, (tokenReceiveAmount + amountTokenA)) * (100 - comission)) / 100) |
---|
93 | | - | if ((minTokenRecieve > tokenSendAmount)) |
---|
94 | | - | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") |
---|
95 | | - | else { |
---|
96 | | - | let assetIdSent = assetIdTokenB |
---|
97 | | - | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), DataEntry("amountTokenB", (amountTokenB - tokenSendAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) |
---|
98 | | - | } |
---|
99 | | - | } |
---|
100 | | - | else throw("Asset is not allowed") |
---|
101 | | - | } |
---|
102 | | - | |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | @Callable(contextObj) |
---|
106 | | - | func withdraw () = { |
---|
107 | | - | let BalanceTokenA = assetBalance(this, assetIdTokenA) |
---|
108 | | - | let BalanceTokenB = assetBalance(this, assetIdTokenB) |
---|
109 | | - | if ((contextObj.caller.bytes == owner)) |
---|
110 | | - | then ScriptResult(WriteSet([DataEntry("amountTokenA", "withdrawn"), DataEntry("amountTokenB", "withdrawn")]), TransferSet([ScriptTransfer(contextObj.caller, BalanceTokenA, assetIdTokenA), ScriptTransfer(contextObj.caller, BalanceTokenB, assetIdTokenB)])) |
---|
111 | | - | else throw("You are not exchanger's owner") |
---|
112 | | - | } |
---|
113 | | - | |
---|
114 | | - | |
---|
115 | | - | @Verifier(contextObj) |
---|
116 | | - | func verify () = true |
---|
117 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|