tx · 9aoRaPpF9qKuMtm2i4xrpGnFF5uWWPvAQLttZ4awfqdq
3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8: -0.01000000 Waves
2022.03.14 21:45 [1964010] smart account 3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8 > SELF 0.00000000 Waves
{
"type": 13,
"id": "9aoRaPpF9qKuMtm2i4xrpGnFF5uWWPvAQLttZ4awfqdq",
"fee": 1000000,
"feeAssetId": null,
"timestamp": 1647283522276,
"version": 2,
"chainId": 84,
"sender": "3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8",
"senderPublicKey": "7KdKmjfPuTXGRNZv4VEz9mZiC2qb9JPzuji5z6jszZyo",
"proofs": [
"4NzARdfuRyPxhiKtxfoAsUB5BpFj4oAtiNcCHaCNw747Pux7SBcmZLjEVYNdUH2UJsSiLTecRCGH1jwqXXyxVsHC"
],
"script": "base64:AAIFAAAAAAAAAAoIAhIGCgQBCAICAAAACgAAAAAMZXhjaGFuZ2VSYXRlAAAAAAAAAAAKAAAAABdleGNoYW5nZVJhdGVEaWZmUGVyY2VudAAAAAAAAAAAFAAAAAAPVVNETnRvV0FWRVNyYXRlCQAAawAAAAMFAAAADGV4Y2hhbmdlUmF0ZQkAAGUAAAACAAAAAAAAAABkBQAAABdleGNoYW5nZVJhdGVEaWZmUGVyY2VudAAAAAAAAAAAZAAAAAAEVVNETgEAAAAgImQ/Hr5gRukRahMT3KYz/hZ+B/l36bPyFfyZSSowCjcAAAAABVdBVkVTAQAAAAQTq9kzAAAAAA9VU0ROdG9XQVZFU1JhdGUAAAAAAAAAAAUAAAAADmxvYW5GZWVQZXJjZW50CQAAaQAAAAIAAAAAAAAAAAkAAAAAAAAAAGQBAAAAE2V4Y2hhbmdlV0FWRVN0b1VTRE4AAAADAAAABmFtb3VudAAAAAdhc3NldElkAAAABmNhbGxlcgMJAAAAAAAAAgUAAAAHYXNzZXRJZAUAAAAFV0FWRVMJAARMAAAAAgkBAAAADlNjcmlwdF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AABHRlc3QFAAAABHRlc3QEAAAAC2JhbGFuY2VEaWZmCQAAZQAAAAIJAAPwAAAAAgUAAAAEdGhpcwUAAAAEVVNETgUAAAAMc3RhcnRCYWxhbmNlBAAAAAZwcm9maXQJAABrAAAAAwUAAAAGYW1vdW50BQAAAA5sb2FuRmVlUGVyY2VudAAAAAAAAAAAZAMJAABmAAAAAgUAAAAGcHJvZml0BQAAAAtiYWxhbmNlRGlmZgkAAAIAAAABCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAB5EZWJ0IG5vdCBwYWlkLCBiZWNhdXNlIGRpZmYgPSAJAAGkAAAAAQUAAAALYmFsYW5jZURpZmYCAAAAEi4gRXhwZWN0ZWQgZGlmZiA9IAkAAaQAAAABBQAAAAZwcm9maXQFAAAAA25pbAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAAAAAJhQFrI=",
"height": 1964010,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: SaccSsukgB19YRm7ZiP7NJxuRxTwvnBGRA3dL6sN1bi
Next: DCEqFhc7FHgYtHouoTq1SG1y4KYuMyZXeUdVvRn8rBwZ
Diff:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 5 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let exchangeRate = 5 |
---|
| 4 | + | let exchangeRate = 10 |
---|
5 | 5 | | |
---|
6 | 6 | | let exchangeRateDiffPercent = 20 |
---|
7 | 7 | | |
---|
|
15 | 15 | | |
---|
16 | 16 | | let loanFeePercent = (9 / 100) |
---|
17 | 17 | | |
---|
18 | | - | let exchangerUSDNtoWavesAddress = Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8') |
---|
| 18 | + | func exchangeWAVEStoUSDN (amount,assetId,caller) = if ((assetId == WAVES)) |
---|
| 19 | + | then [ScriptTransfer(Address(caller), (amount / USDNtoWAVESrate), USDN)] |
---|
| 20 | + | else throw("Unexpected Token") |
---|
19 | 21 | | |
---|
20 | | - | let exchangerWavesToUSDNAddress = Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8') |
---|
21 | 22 | | |
---|
22 | | - | let loanerAddress = Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8') |
---|
| 23 | + | func exchangeUSDNtoWAVES (amount,assetId,caller) = if ((assetId == USDN)) |
---|
| 24 | + | then [ScriptTransfer(Address(caller), (amount * USDNtoWAVESRate), WAVES)] |
---|
| 25 | + | else throw("Unexpected Token") |
---|
23 | 26 | | |
---|
24 | | - | @Callable(i) |
---|
25 | | - | func trade (borrower) = { |
---|
26 | | - | let loanAmount = if ((i.payments[0].assetId == USDN)) |
---|
27 | | - | then i.payments[0].amount |
---|
| 27 | + | |
---|
| 28 | + | func trade (borrower,amount,assetId) = { |
---|
| 29 | + | let loanAmount = if ((assetId == USDN)) |
---|
| 30 | + | then amount |
---|
28 | 31 | | else throw("Unexpected payment asset") |
---|
29 | 32 | | let startBalanceWAVES = assetBalance(this, WAVES) |
---|
30 | 33 | | if ((startBalanceWAVES == startBalanceWAVES)) |
---|
31 | 34 | | then { |
---|
32 | | - | let r1 = invoke(exchangerUSDNtoWavesAddress, "exchangeUSDNtoWAVES", nil, [AttachedPayment(USDN, loanAmount)]) |
---|
| 35 | + | let r1 = exchangeUSDNtoWAVES(amount, assetId, borrower) |
---|
33 | 36 | | if ((r1 == r1)) |
---|
34 | 37 | | then { |
---|
35 | 38 | | let diffWAVES = (assetBalance(this, WAVES) - startBalanceWAVES) |
---|
36 | 39 | | if ((diffWAVES == diffWAVES)) |
---|
37 | 40 | | then { |
---|
38 | | - | let r2 = invoke(exchangerWavesToUSDNAddress, "exchangeWAVEStoUSDN", nil, [AttachedPayment(WAVES, diffWAVES)]) |
---|
| 41 | + | let r2 = exchangeWAVEStoUSDN(amount, assetId, borrower) |
---|
39 | 42 | | if ((r2 == r2)) |
---|
40 | 43 | | then { |
---|
41 | 44 | | let debt = fraction(loanAmount, (100 + loanFeePercent), 100) |
---|
42 | 45 | | let profit = (assetBalance(this, USDN) - debt) |
---|
43 | | - | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(loanerAddress, debt, USDN)] |
---|
| 46 | + | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(this, debt, USDN)] |
---|
44 | 47 | | } |
---|
45 | 48 | | else throw("Strict value is not equal to itself.") |
---|
46 | 49 | | } |
---|
|
52 | 55 | | } |
---|
53 | 56 | | |
---|
54 | 57 | | |
---|
55 | | - | |
---|
56 | 58 | | @Callable(i) |
---|
57 | | - | func exchangeWAVEStoUSDN () = if ((i.payments[0].assetId == WAVES)) |
---|
58 | | - | then [ScriptTransfer(i.caller, (i.payments[0].amount / USDNtoWAVESrate), USDN)] |
---|
59 | | - | else throw("Unexpected Token") |
---|
60 | | - | |
---|
61 | | - | |
---|
62 | | - | |
---|
63 | | - | @Callable(i) |
---|
64 | | - | func exchangeUSDNtoWAVES () = if ((i.payments[0].assetId == USDN)) |
---|
65 | | - | then [ScriptTransfer(i.caller, (i.payments[0].amount * USDNtoWAVESRate), WAVES)] |
---|
66 | | - | else throw("Unexpected Token") |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | @Callable(i) |
---|
71 | | - | func flashloan (amount,callback,borrower) = { |
---|
| 59 | + | func flashloan (amount,callback,borrower,assetId) = { |
---|
72 | 60 | | let startBalance = assetBalance(this, USDN) |
---|
73 | 61 | | if ((startBalance == startBalance)) |
---|
74 | 62 | | then { |
---|
75 | | - | let r = invoke(Address(fromBase58String(borrower)), callback, [i.caller.bytes], [AttachedPayment(USDN, amount)]) |
---|
76 | | - | if ((r == r)) |
---|
| 63 | + | let test = trade(borrower, amount, assetId) |
---|
| 64 | + | if ((test == test)) |
---|
77 | 65 | | then { |
---|
78 | 66 | | let balanceDiff = (assetBalance(this, USDN) - startBalance) |
---|
79 | 67 | | let profit = fraction(amount, loanFeePercent, 100) |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 5 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let exchangeRate = 5 |
---|
| 4 | + | let exchangeRate = 10 |
---|
5 | 5 | | |
---|
6 | 6 | | let exchangeRateDiffPercent = 20 |
---|
7 | 7 | | |
---|
8 | 8 | | let USDNtoWAVESrate = fraction(exchangeRate, (100 - exchangeRateDiffPercent), 100) |
---|
9 | 9 | | |
---|
10 | 10 | | let USDN = base58'3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC' |
---|
11 | 11 | | |
---|
12 | 12 | | let WAVES = base58'WAVES' |
---|
13 | 13 | | |
---|
14 | 14 | | let USDNtoWAVESRate = 5 |
---|
15 | 15 | | |
---|
16 | 16 | | let loanFeePercent = (9 / 100) |
---|
17 | 17 | | |
---|
18 | | - | let exchangerUSDNtoWavesAddress = Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8') |
---|
| 18 | + | func exchangeWAVEStoUSDN (amount,assetId,caller) = if ((assetId == WAVES)) |
---|
| 19 | + | then [ScriptTransfer(Address(caller), (amount / USDNtoWAVESrate), USDN)] |
---|
| 20 | + | else throw("Unexpected Token") |
---|
19 | 21 | | |
---|
20 | | - | let exchangerWavesToUSDNAddress = Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8') |
---|
21 | 22 | | |
---|
22 | | - | let loanerAddress = Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8') |
---|
| 23 | + | func exchangeUSDNtoWAVES (amount,assetId,caller) = if ((assetId == USDN)) |
---|
| 24 | + | then [ScriptTransfer(Address(caller), (amount * USDNtoWAVESRate), WAVES)] |
---|
| 25 | + | else throw("Unexpected Token") |
---|
23 | 26 | | |
---|
24 | | - | @Callable(i) |
---|
25 | | - | func trade (borrower) = { |
---|
26 | | - | let loanAmount = if ((i.payments[0].assetId == USDN)) |
---|
27 | | - | then i.payments[0].amount |
---|
| 27 | + | |
---|
| 28 | + | func trade (borrower,amount,assetId) = { |
---|
| 29 | + | let loanAmount = if ((assetId == USDN)) |
---|
| 30 | + | then amount |
---|
28 | 31 | | else throw("Unexpected payment asset") |
---|
29 | 32 | | let startBalanceWAVES = assetBalance(this, WAVES) |
---|
30 | 33 | | if ((startBalanceWAVES == startBalanceWAVES)) |
---|
31 | 34 | | then { |
---|
32 | | - | let r1 = invoke(exchangerUSDNtoWavesAddress, "exchangeUSDNtoWAVES", nil, [AttachedPayment(USDN, loanAmount)]) |
---|
| 35 | + | let r1 = exchangeUSDNtoWAVES(amount, assetId, borrower) |
---|
33 | 36 | | if ((r1 == r1)) |
---|
34 | 37 | | then { |
---|
35 | 38 | | let diffWAVES = (assetBalance(this, WAVES) - startBalanceWAVES) |
---|
36 | 39 | | if ((diffWAVES == diffWAVES)) |
---|
37 | 40 | | then { |
---|
38 | | - | let r2 = invoke(exchangerWavesToUSDNAddress, "exchangeWAVEStoUSDN", nil, [AttachedPayment(WAVES, diffWAVES)]) |
---|
| 41 | + | let r2 = exchangeWAVEStoUSDN(amount, assetId, borrower) |
---|
39 | 42 | | if ((r2 == r2)) |
---|
40 | 43 | | then { |
---|
41 | 44 | | let debt = fraction(loanAmount, (100 + loanFeePercent), 100) |
---|
42 | 45 | | let profit = (assetBalance(this, USDN) - debt) |
---|
43 | | - | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(loanerAddress, debt, USDN)] |
---|
| 46 | + | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(this, debt, USDN)] |
---|
44 | 47 | | } |
---|
45 | 48 | | else throw("Strict value is not equal to itself.") |
---|
46 | 49 | | } |
---|
47 | 50 | | else throw("Strict value is not equal to itself.") |
---|
48 | 51 | | } |
---|
49 | 52 | | else throw("Strict value is not equal to itself.") |
---|
50 | 53 | | } |
---|
51 | 54 | | else throw("Strict value is not equal to itself.") |
---|
52 | 55 | | } |
---|
53 | 56 | | |
---|
54 | 57 | | |
---|
55 | | - | |
---|
56 | 58 | | @Callable(i) |
---|
57 | | - | func exchangeWAVEStoUSDN () = if ((i.payments[0].assetId == WAVES)) |
---|
58 | | - | then [ScriptTransfer(i.caller, (i.payments[0].amount / USDNtoWAVESrate), USDN)] |
---|
59 | | - | else throw("Unexpected Token") |
---|
60 | | - | |
---|
61 | | - | |
---|
62 | | - | |
---|
63 | | - | @Callable(i) |
---|
64 | | - | func exchangeUSDNtoWAVES () = if ((i.payments[0].assetId == USDN)) |
---|
65 | | - | then [ScriptTransfer(i.caller, (i.payments[0].amount * USDNtoWAVESRate), WAVES)] |
---|
66 | | - | else throw("Unexpected Token") |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | @Callable(i) |
---|
71 | | - | func flashloan (amount,callback,borrower) = { |
---|
| 59 | + | func flashloan (amount,callback,borrower,assetId) = { |
---|
72 | 60 | | let startBalance = assetBalance(this, USDN) |
---|
73 | 61 | | if ((startBalance == startBalance)) |
---|
74 | 62 | | then { |
---|
75 | | - | let r = invoke(Address(fromBase58String(borrower)), callback, [i.caller.bytes], [AttachedPayment(USDN, amount)]) |
---|
76 | | - | if ((r == r)) |
---|
| 63 | + | let test = trade(borrower, amount, assetId) |
---|
| 64 | + | if ((test == test)) |
---|
77 | 65 | | then { |
---|
78 | 66 | | let balanceDiff = (assetBalance(this, USDN) - startBalance) |
---|
79 | 67 | | let profit = fraction(amount, loanFeePercent, 100) |
---|
80 | 68 | | if ((profit > balanceDiff)) |
---|
81 | 69 | | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) |
---|
82 | 70 | | else nil |
---|
83 | 71 | | } |
---|
84 | 72 | | else throw("Strict value is not equal to itself.") |
---|
85 | 73 | | } |
---|
86 | 74 | | else throw("Strict value is not equal to itself.") |
---|
87 | 75 | | } |
---|
88 | 76 | | |
---|
89 | 77 | | |
---|