tx · D464jY3gKNHcn73ZA1uGyao3JxZEXFjsjaY66355MHJm 3Mty9tvj2nMt3mudiJFGKqKh8Mai1o8oGCA: -0.01000000 Waves 2022.02.15 12:17 [1924553] smart account 3Mty9tvj2nMt3mudiJFGKqKh8Mai1o8oGCA > SELF 0.00000000 Waves
{ "type": 13, "id": "D464jY3gKNHcn73ZA1uGyao3JxZEXFjsjaY66355MHJm", "fee": 1000000, "feeAssetId": null, "timestamp": 1644916645892, "version": 2, "chainId": 84, "sender": "3Mty9tvj2nMt3mudiJFGKqKh8Mai1o8oGCA", "senderPublicKey": "D5AsfVE6mgvKZXPLeW3vHDhcVwbypV8qcT64Kmn4UQ3D", "proofs": [ "4NFhMwG55UVc1YboDYDq3w7PeeN9xTrXaXtPysRVTV4Vn2mMEYr9zbQftzD1b9yTDFGq5qakvpLJR9Bn1WrwxHx1" ], "script": "base64:AAIFAAAAAAAAAAkIAhIFCgMBCAgAAAACAAAAAARVU0ROAQAAACAiZD8evmBG6RFqExPcpjP+Fn4H+Xfps/IV/JlJKjAKNwAAAAAObG9hbkZlZVBlcmNlbnQJAABpAAAAAgAAAAAAAAAACQAAAAAAAAAAZAAAAAEAAAABaQEAAAAJZmxhc2hsb2FuAAAAAwAAAAZhbW91bnQAAAAIY2FsbGJhY2sAAAAIYm9ycm93ZXIEAAAADHN0YXJ0QmFsYW5jZQkAA/AAAAACBQAAAAR0aGlzBQAAAARVU0ROAwkAAAAAAAACBQAAAAxzdGFydEJhbGFuY2UFAAAADHN0YXJ0QmFsYW5jZQQAAAABcgkAA/wAAAAECQEAAAAHQWRkcmVzcwAAAAEJAAJZAAAAAQUAAAAIYm9ycm93ZXIFAAAACGNhbGxiYWNrCQAETAAAAAIICAUAAAABaQAAAAZjYWxsZXIAAAAFYnl0ZXMFAAAAA25pbAkABEwAAAACCQEAAAAPQXR0YWNoZWRQYXltZW50AAAAAgUAAAAEVVNETgUAAAAGYW1vdW50BQAAAANuaWwDCQAAAAAAAAIFAAAAAXIFAAAAAXIEAAAAC2JhbGFuY2VEaWZmCQAAZQAAAAIJAAPwAAAAAgUAAAAEdGhpcwUAAAAEVVNETgUAAAAMc3RhcnRCYWxhbmNlBAAAAAZwcm9maXQJAABrAAAAAwUAAAAGYW1vdW50BQAAAA5sb2FuRmVlUGVyY2VudAAAAAAAAAAAZAMJAABmAAAAAgUAAAAGcHJvZml0BQAAAAtiYWxhbmNlRGlmZgkAAAIAAAABCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAB5EZWJ0IG5vdCBwYWlkLCBiZWNhdXNlIGRpZmYgPSAJAAGkAAAAAQUAAAALYmFsYW5jZURpZmYCAAAAEi4gRXhwZWN0ZWQgZGlmZiA9IAkAAaQAAAABBQAAAAZwcm9maXQFAAAAA25pbAkAAAIAAAABAgAAACRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4JAAACAAAAAQIAAAAkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAAAAAGIUh8Y=", "height": 1924553, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8jgseVAPKgesxBqQ75AK1wtmESPTQKW11Sr3pks8mPjX Next: DKKp19fKQVPVZqyZtE2aJ4KWjAWk42AzwMV1zYSRcn9L Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let USDN = base58'3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC' | |
5 | + | ||
4 | 6 | let loanFeePercent = (9 / 100) | |
5 | 7 | ||
6 | - | let USDN = base58'3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC' | |
7 | - | ||
8 | - | let WAVES = base58'WAVES' | |
9 | - | ||
10 | - | let exchangerUSDNtoWavesAddress = Address(base58'3My9M3PdtDPdsvHwX4t1epYFJjhLDrQFP49') | |
11 | - | ||
12 | - | let exchangerWavesToUSDNAddress = Address(base58'3NAAEeRUgAj7D4pTPGR7n4yPCX2JGF3vUXm') | |
13 | - | ||
14 | - | let loanerAddress = Address(base58'3Mty9tvj2nMt3mudiJFGKqKh8Mai1o8oGCA') | |
15 | - | ||
16 | 8 | @Callable(i) | |
17 | - | func trade (borrower) = { | |
18 | - | let loanAmount = if ((i.payments[0].assetId == USDN)) | |
19 | - | then i.payments[0].amount | |
20 | - | else throw("Unexpected payment asset") | |
21 | - | let startBalanceWAVES = assetBalance(this, WAVES) | |
22 | - | if ((startBalanceWAVES == startBalanceWAVES)) | |
9 | + | func flashloan (amount,callback,borrower) = { | |
10 | + | let startBalance = assetBalance(this, USDN) | |
11 | + | if ((startBalance == startBalance)) | |
23 | 12 | then { | |
24 | - | let | |
25 | - | if (( | |
13 | + | let r = invoke(Address(fromBase58String(borrower)), callback, [i.caller.bytes], [AttachedPayment(USDN, amount)]) | |
14 | + | if ((r == r)) | |
26 | 15 | then { | |
27 | - | let diffWAVES = (assetBalance(this, WAVES) - startBalanceWAVES) | |
28 | - | if ((diffWAVES == diffWAVES)) | |
29 | - | then { | |
30 | - | let r2 = invoke(exchangerWavesToUSDNAddress, "exchangeWAVEStoUSDN", nil, [AttachedPayment(WAVES, diffWAVES)]) | |
31 | - | if ((r2 == r2)) | |
32 | - | then { | |
33 | - | let debt = fraction(loanAmount, (100 + loanFeePercent), 100) | |
34 | - | let profit = (assetBalance(this, USDN) - debt) | |
35 | - | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(loanerAddress, debt, USDN)] | |
36 | - | } | |
37 | - | else throw("Strict value is not equal to itself.") | |
38 | - | } | |
39 | - | else throw("Strict value is not equal to itself.") | |
16 | + | let balanceDiff = (assetBalance(this, USDN) - startBalance) | |
17 | + | let profit = fraction(amount, loanFeePercent, 100) | |
18 | + | if ((profit > balanceDiff)) | |
19 | + | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) | |
20 | + | else nil | |
40 | 21 | } | |
41 | 22 | else throw("Strict value is not equal to itself.") | |
42 | 23 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let USDN = base58'3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC' | |
5 | + | ||
4 | 6 | let loanFeePercent = (9 / 100) | |
5 | 7 | ||
6 | - | let USDN = base58'3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC' | |
7 | - | ||
8 | - | let WAVES = base58'WAVES' | |
9 | - | ||
10 | - | let exchangerUSDNtoWavesAddress = Address(base58'3My9M3PdtDPdsvHwX4t1epYFJjhLDrQFP49') | |
11 | - | ||
12 | - | let exchangerWavesToUSDNAddress = Address(base58'3NAAEeRUgAj7D4pTPGR7n4yPCX2JGF3vUXm') | |
13 | - | ||
14 | - | let loanerAddress = Address(base58'3Mty9tvj2nMt3mudiJFGKqKh8Mai1o8oGCA') | |
15 | - | ||
16 | 8 | @Callable(i) | |
17 | - | func trade (borrower) = { | |
18 | - | let loanAmount = if ((i.payments[0].assetId == USDN)) | |
19 | - | then i.payments[0].amount | |
20 | - | else throw("Unexpected payment asset") | |
21 | - | let startBalanceWAVES = assetBalance(this, WAVES) | |
22 | - | if ((startBalanceWAVES == startBalanceWAVES)) | |
9 | + | func flashloan (amount,callback,borrower) = { | |
10 | + | let startBalance = assetBalance(this, USDN) | |
11 | + | if ((startBalance == startBalance)) | |
23 | 12 | then { | |
24 | - | let | |
25 | - | if (( | |
13 | + | let r = invoke(Address(fromBase58String(borrower)), callback, [i.caller.bytes], [AttachedPayment(USDN, amount)]) | |
14 | + | if ((r == r)) | |
26 | 15 | then { | |
27 | - | let diffWAVES = (assetBalance(this, WAVES) - startBalanceWAVES) | |
28 | - | if ((diffWAVES == diffWAVES)) | |
29 | - | then { | |
30 | - | let r2 = invoke(exchangerWavesToUSDNAddress, "exchangeWAVEStoUSDN", nil, [AttachedPayment(WAVES, diffWAVES)]) | |
31 | - | if ((r2 == r2)) | |
32 | - | then { | |
33 | - | let debt = fraction(loanAmount, (100 + loanFeePercent), 100) | |
34 | - | let profit = (assetBalance(this, USDN) - debt) | |
35 | - | [ScriptTransfer(Address(borrower), profit, USDN), ScriptTransfer(loanerAddress, debt, USDN)] | |
36 | - | } | |
37 | - | else throw("Strict value is not equal to itself.") | |
38 | - | } | |
39 | - | else throw("Strict value is not equal to itself.") | |
16 | + | let balanceDiff = (assetBalance(this, USDN) - startBalance) | |
17 | + | let profit = fraction(amount, loanFeePercent, 100) | |
18 | + | if ((profit > balanceDiff)) | |
19 | + | then throw(((("Debt not paid, because diff = " + toString(balanceDiff)) + ". Expected diff = ") + toString(profit))) | |
20 | + | else nil | |
40 | 21 | } | |
41 | 22 | else throw("Strict value is not equal to itself.") | |
42 | 23 | } | |
43 | 24 | else throw("Strict value is not equal to itself.") | |
44 | 25 | } | |
45 | 26 | ||
46 | 27 |
github/deemru/w8io/169f3d6 36.18 ms ◑