1 | | - | {-# STDLIB_VERSION 3 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let wEUR = base58'8kKP8hCaoSa3vNN4e2e3bboKfnw3arz7kLhQeCBWauQH' |
---|
5 | | - | |
---|
6 | | - | @Callable(i) |
---|
7 | | - | func deposit () = { |
---|
8 | | - | let pmt = extract(i.payment) |
---|
9 | | - | if ((pmt.assetId != wEUR)) |
---|
10 | | - | then throw("wEUR - 8kKP8hCaoSa3vNN4e2e3bboKfnw3arz7kLhQeCBWauQH only tokens") |
---|
11 | | - | else { |
---|
12 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
13 | | - | let currentAmount = match getInteger(this, currentKey) { |
---|
14 | | - | case a: Int => |
---|
15 | | - | a |
---|
16 | | - | case _ => |
---|
17 | | - | 0 |
---|
18 | | - | } |
---|
19 | | - | let newAmount = (currentAmount + pmt.amount) |
---|
20 | | - | WriteSet([DataEntry(currentKey, newAmount)]) |
---|
21 | | - | } |
---|
22 | | - | } |
---|
23 | | - | |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | @Callable(i) |
---|
27 | | - | func withdraw (amount) = { |
---|
28 | | - | let currentKey = toBase58String(i.caller.bytes) |
---|
29 | | - | let currentAmount = match getInteger(this, currentKey) { |
---|
30 | | - | case a: Int => |
---|
31 | | - | a |
---|
32 | | - | case _ => |
---|
33 | | - | 0 |
---|
34 | | - | } |
---|
35 | | - | let newAmount = (currentAmount - amount) |
---|
36 | | - | if ((0 > amount)) |
---|
37 | | - | then throw("Can't withdraw negative amount") |
---|
38 | | - | else if ((0 > newAmount)) |
---|
39 | | - | then throw("Not enough balance") |
---|
40 | | - | else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, wEUR)])) |
---|
41 | | - | } |
---|
42 | | - | |
---|
43 | | - | |
---|
| 1 | + | {-# STDLIB_VERSION 2 #-} |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let issuer = Address(base58'3issuerAddress') |
---|
| 4 | + | let assetId = base58'ThisAsset1d' |
---|
| 5 | + | match tx { |
---|
| 6 | + | case ex: ExchangeTransaction => |
---|
| 7 | + | let pair = AssetPair(assetId, unit) |
---|
| 8 | + | let rate = extract(getInteger(issuer, "exchangeRate")) |
---|
| 9 | + | let rateDiff = (rate - fraction(100000000, ex.price, ex.amount)) |
---|
| 10 | + | if (if ((ex.buyOrder.assetPair == pair)) |
---|
| 11 | + | then (rateDiff > -100) |
---|
| 12 | + | else false) |
---|
| 13 | + | then (100 > rateDiff) |
---|
| 14 | + | else false |
---|
| 15 | + | case _ => |
---|
| 16 | + | true |
---|
| 17 | + | } |
---|