tx · EVK7g52TfiX2eSMaZeAxPGCEDV6M7g3untjQGkxf4XSu 3Mwm6wcc5SBiMzF2dMWpTJpFFobA236iAZ7: -0.00300000 Waves 2022.09.01 12:30 [2209889] smart account 3Mwm6wcc5SBiMzF2dMWpTJpFFobA236iAZ7 > SELF 0.00000000 Waves
{ "type": 13, "id": "EVK7g52TfiX2eSMaZeAxPGCEDV6M7g3untjQGkxf4XSu", "fee": 300000, "feeAssetId": null, "timestamp": 1662024674274, "version": 2, "chainId": 84, "sender": "3Mwm6wcc5SBiMzF2dMWpTJpFFobA236iAZ7", "senderPublicKey": "BpvXf9toCinzcKiB63evew28WyjAZX5mTYcnAcRGMAH6", "proofs": [ "BY8qh2q16CenLTwjancPHM3zzm7WjxpiLpJNgQW9S6auBYYbJ4Znxbg8DHKnYFg6fA3R8h84cSqhKn43nBakQJq" ], "script": "base64:AAIFAAAAAAAAAB0IAhIFCgMBAgISBQoDAQICEgUKAwIBAhIECgIBCAAAAAcAAAAADGV4Y2hhbmdlUmF0ZQAAAAAAAAAACgAAAAAXZXhjaGFuZ2VSYXRlRGlmZlBlcmNlbnQAAAAAAAAAAAoAAAAAD1VTRE50b1dBVkVTcmF0ZQkAAGsAAAADBQAAAAxleGNoYW5nZVJhdGUJAABlAAAAAgAAAAAAAAAAZAUAAAAXZXhjaGFuZ2VSYXRlRGlmZlBlcmNlbnQAAAAAAAAAAGQAAAAABFVTRE4BAAAAIA/yHBKs5MQ8muxGGqslqLDsugcrRsxtiHLwteKSSQG0AAAAAAVXQVZFUwEAAAAAAAAAAA9VU0ROdG9XQVZFU1JhdGUAAAAAAAAAAAoAAAAADmxvYW5GZWVQZXJjZW50AAAAAAAAAAABAAAABAAAAAFpAQAAABNleGNoYW5nZVdBVkVTdG9VU0ROAAAAAwAAAAZhbW91bnQAAAAHYXNzZXRJZAAAAAZjYWxsZXIDCQAAAAAAAAIFAAAAB2Fzc2V0SWQFAAAABVdBVkVTCQAETAAAAAIJAQAAAA5TY3JpcHRUc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AAAAA25pbAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AAAAADieWRw==", "height": 2209889, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3kKQa3X1twvpZtjrLc1EEWkcsLerQHrLjsoL8Ss65LQj Next: none Diff:
Old | New | Differences | |
---|---|---|---|
7 | 7 | ||
8 | 8 | let USDNtoWAVESrate = fraction(exchangeRate, (100 - exchangeRateDiffPercent), 100) | |
9 | 9 | ||
10 | - | let USDN = base58' | |
10 | + | let USDN = base58'25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT' | |
11 | 11 | ||
12 | 12 | let WAVES = base58'' | |
13 | 13 | ||
15 | 15 | ||
16 | 16 | let loanFeePercent = 1 | |
17 | 17 | ||
18 | + | @Callable(i) | |
18 | 19 | func exchangeWAVEStoUSDN (amount,assetId,caller) = if ((assetId == WAVES)) | |
19 | - | then [ScriptTransfer(Address(caller), (amount | |
20 | + | then [ScriptTransfer(Address(caller), fraction(amount, (USDNtoWAVESrate - 1), 100), USDN), IntegerEntry("WAVEStoUSDN", amount)] | |
20 | 21 | else throw("Unexpected Token") | |
21 | 22 | ||
22 | 23 | ||
24 | + | ||
25 | + | @Callable(i) | |
23 | 26 | func exchangeUSDNtoWAVES (amount,assetId,caller) = if ((assetId == USDN)) | |
24 | - | then [ScriptTransfer(Address(caller), (amount * USDNtoWAVESRate), | |
27 | + | then [ScriptTransfer(Address(caller), (amount * USDNtoWAVESRate), unit), IntegerEntry("USDNtoWAVES", amount)] | |
25 | 28 | else throw("Unexpected Token") | |
26 | 29 | ||
27 | 30 | ||
31 | + | ||
32 | + | @Callable(i) | |
28 | 33 | func trade (borrower,amount,assetId) = { | |
29 | 34 | let loanAmount = if ((assetId == USDN)) | |
30 | 35 | then amount | |
31 | 36 | else throw("Unexpected payment asset") | |
32 | - | let startBalanceWAVES = assetBalance(this, WAVES) | |
33 | - | if ((startBalanceWAVES == startBalanceWAVES)) | |
37 | + | let startBalanceWAVES = wavesBalance(this).regular | |
38 | + | let r1 = reentrantInvoke(Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8'), "exchangeUSDNtoWAVES", [amount, USDN, borrower], nil) | |
39 | + | if ((r1 == r1)) | |
34 | 40 | then { | |
35 | - | let r1 = exchangeUSDNtoWAVES(amount, assetId, borrower) | |
36 | - | if ((r1 == r1)) | |
37 | - | then { | |
38 | - | let diffWAVES = (assetBalance(this, WAVES) - startBalanceWAVES) | |
39 | - | if ((diffWAVES == diffWAVES)) | |
40 | - | then { | |
41 | - | let r2 = exchangeWAVEStoUSDN(amount, WAVES, borrower) | |
42 | - | if ((r2 == r2)) | |
43 | - | then { | |
44 | - | let debt = fraction(loanAmount, (100 + loanFeePercent), 100) | |
45 | - | let profit = (assetBalance(this, USDN) - debt) | |
46 | - | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(this, debt, USDN)] | |
47 | - | } | |
48 | - | else throw("Strict value is not equal to itself.") | |
49 | - | } | |
50 | - | else throw("Strict value is not equal to itself.") | |
51 | - | } | |
41 | + | let diffWAVES = wavesBalance(this).regular | |
42 | + | let diffWAVES2 = (diffWAVES - startBalanceWAVES) | |
43 | + | let r2 = reentrantInvoke(Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8'), "exchangeWAVEStoUSDN", [amount, WAVES, borrower], nil) | |
44 | + | if ((r2 == r2)) | |
45 | + | then [IntegerEntry("STARTBALANCEWAVES", startBalanceWAVES), IntegerEntry("diffWAVES", diffWAVES), IntegerEntry("loanAmount", loanAmount), ScriptTransfer(Address(borrower), amount, USDN)] | |
52 | 46 | else throw("Strict value is not equal to itself.") | |
53 | 47 | } | |
54 | 48 | else throw("Strict value is not equal to itself.") | |
55 | 49 | } | |
56 | 50 | ||
57 | 51 | ||
52 | + | ||
58 | 53 | @Callable(i) | |
59 | 54 | func flashloan (amount,borr) = { | |
60 | 55 | let startBalance = assetBalance(this, USDN) | |
61 | - | if ((startBalance == startBalance)) | |
56 | + | let borrower = borr | |
57 | + | let test = reentrantInvoke(Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8'), "trade", [fromBase58String(borr), amount, USDN], nil) | |
58 | + | if ((test == test)) | |
62 | 59 | then { | |
63 | - | let borrower = borr | |
64 | - | let test = trade(fromBase58String(borr), amount, USDN) | |
65 | - | if ((test == test)) | |
66 | - | then { | |
67 | - | let balanceDiff = (assetBalance(this, USDN) - startBalance) | |
68 | - | let profit = fraction(amount, loanFeePercent, 100) | |
69 | - | if ((profit > balanceDiff)) | |
70 | - | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) | |
71 | - | else nil | |
72 | - | } | |
73 | - | else throw("Strict value is not equal to itself.") | |
60 | + | let balanceDiff = assetBalance(this, USDN) | |
61 | + | let balanceDiff2 = (balanceDiff - startBalance) | |
62 | + | let profit = fraction(amount, loanFeePercent, 100) | |
63 | + | if ((profit > balanceDiff2)) | |
64 | + | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) | |
65 | + | else [IntegerEntry("startBalance", startBalance), IntegerEntry("balanceDiff", balanceDiff2), StringEntry("this", toString(this)), ScriptTransfer(Address(fromBase58String(borr)), profit, USDN)] | |
74 | 66 | } | |
75 | 67 | else throw("Strict value is not equal to itself.") | |
76 | 68 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let exchangeRate = 10 | |
5 | 5 | ||
6 | 6 | let exchangeRateDiffPercent = 10 | |
7 | 7 | ||
8 | 8 | let USDNtoWAVESrate = fraction(exchangeRate, (100 - exchangeRateDiffPercent), 100) | |
9 | 9 | ||
10 | - | let USDN = base58' | |
10 | + | let USDN = base58'25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT' | |
11 | 11 | ||
12 | 12 | let WAVES = base58'' | |
13 | 13 | ||
14 | 14 | let USDNtoWAVESRate = 10 | |
15 | 15 | ||
16 | 16 | let loanFeePercent = 1 | |
17 | 17 | ||
18 | + | @Callable(i) | |
18 | 19 | func exchangeWAVEStoUSDN (amount,assetId,caller) = if ((assetId == WAVES)) | |
19 | - | then [ScriptTransfer(Address(caller), (amount | |
20 | + | then [ScriptTransfer(Address(caller), fraction(amount, (USDNtoWAVESrate - 1), 100), USDN), IntegerEntry("WAVEStoUSDN", amount)] | |
20 | 21 | else throw("Unexpected Token") | |
21 | 22 | ||
22 | 23 | ||
24 | + | ||
25 | + | @Callable(i) | |
23 | 26 | func exchangeUSDNtoWAVES (amount,assetId,caller) = if ((assetId == USDN)) | |
24 | - | then [ScriptTransfer(Address(caller), (amount * USDNtoWAVESRate), | |
27 | + | then [ScriptTransfer(Address(caller), (amount * USDNtoWAVESRate), unit), IntegerEntry("USDNtoWAVES", amount)] | |
25 | 28 | else throw("Unexpected Token") | |
26 | 29 | ||
27 | 30 | ||
31 | + | ||
32 | + | @Callable(i) | |
28 | 33 | func trade (borrower,amount,assetId) = { | |
29 | 34 | let loanAmount = if ((assetId == USDN)) | |
30 | 35 | then amount | |
31 | 36 | else throw("Unexpected payment asset") | |
32 | - | let startBalanceWAVES = assetBalance(this, WAVES) | |
33 | - | if ((startBalanceWAVES == startBalanceWAVES)) | |
37 | + | let startBalanceWAVES = wavesBalance(this).regular | |
38 | + | let r1 = reentrantInvoke(Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8'), "exchangeUSDNtoWAVES", [amount, USDN, borrower], nil) | |
39 | + | if ((r1 == r1)) | |
34 | 40 | then { | |
35 | - | let r1 = exchangeUSDNtoWAVES(amount, assetId, borrower) | |
36 | - | if ((r1 == r1)) | |
37 | - | then { | |
38 | - | let diffWAVES = (assetBalance(this, WAVES) - startBalanceWAVES) | |
39 | - | if ((diffWAVES == diffWAVES)) | |
40 | - | then { | |
41 | - | let r2 = exchangeWAVEStoUSDN(amount, WAVES, borrower) | |
42 | - | if ((r2 == r2)) | |
43 | - | then { | |
44 | - | let debt = fraction(loanAmount, (100 + loanFeePercent), 100) | |
45 | - | let profit = (assetBalance(this, USDN) - debt) | |
46 | - | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(this, debt, USDN)] | |
47 | - | } | |
48 | - | else throw("Strict value is not equal to itself.") | |
49 | - | } | |
50 | - | else throw("Strict value is not equal to itself.") | |
51 | - | } | |
41 | + | let diffWAVES = wavesBalance(this).regular | |
42 | + | let diffWAVES2 = (diffWAVES - startBalanceWAVES) | |
43 | + | let r2 = reentrantInvoke(Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8'), "exchangeWAVEStoUSDN", [amount, WAVES, borrower], nil) | |
44 | + | if ((r2 == r2)) | |
45 | + | then [IntegerEntry("STARTBALANCEWAVES", startBalanceWAVES), IntegerEntry("diffWAVES", diffWAVES), IntegerEntry("loanAmount", loanAmount), ScriptTransfer(Address(borrower), amount, USDN)] | |
52 | 46 | else throw("Strict value is not equal to itself.") | |
53 | 47 | } | |
54 | 48 | else throw("Strict value is not equal to itself.") | |
55 | 49 | } | |
56 | 50 | ||
57 | 51 | ||
52 | + | ||
58 | 53 | @Callable(i) | |
59 | 54 | func flashloan (amount,borr) = { | |
60 | 55 | let startBalance = assetBalance(this, USDN) | |
61 | - | if ((startBalance == startBalance)) | |
56 | + | let borrower = borr | |
57 | + | let test = reentrantInvoke(Address(base58'3Mw2biLQi5ygMk7zexboNGrnMYuaSfrziY8'), "trade", [fromBase58String(borr), amount, USDN], nil) | |
58 | + | if ((test == test)) | |
62 | 59 | then { | |
63 | - | let borrower = borr | |
64 | - | let test = trade(fromBase58String(borr), amount, USDN) | |
65 | - | if ((test == test)) | |
66 | - | then { | |
67 | - | let balanceDiff = (assetBalance(this, USDN) - startBalance) | |
68 | - | let profit = fraction(amount, loanFeePercent, 100) | |
69 | - | if ((profit > balanceDiff)) | |
70 | - | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) | |
71 | - | else nil | |
72 | - | } | |
73 | - | else throw("Strict value is not equal to itself.") | |
60 | + | let balanceDiff = assetBalance(this, USDN) | |
61 | + | let balanceDiff2 = (balanceDiff - startBalance) | |
62 | + | let profit = fraction(amount, loanFeePercent, 100) | |
63 | + | if ((profit > balanceDiff2)) | |
64 | + | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) | |
65 | + | else [IntegerEntry("startBalance", startBalance), IntegerEntry("balanceDiff", balanceDiff2), StringEntry("this", toString(this)), ScriptTransfer(Address(fromBase58String(borr)), profit, USDN)] | |
74 | 66 | } | |
75 | 67 | else throw("Strict value is not equal to itself.") | |
76 | 68 | } | |
77 | 69 | ||
78 | 70 |
github/deemru/w8io/026f985 26.99 ms ◑