tx · 9UhDN4m4W8Z4nMWTsQpUhBmiY4Bm5yhsPjNrL8RjgCku 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq: -0.01000000 Waves 2024.03.04 11:19 [3003007] smart account 3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq > SELF 0.00000000 Waves
{ "type": 13, "id": "9UhDN4m4W8Z4nMWTsQpUhBmiY4Bm5yhsPjNrL8RjgCku", "fee": 1000000, "feeAssetId": null, "timestamp": 1709540365336, "version": 2, "chainId": 84, "sender": "3N61RYWc9QuqKUwLvowpZZLpgUnqpQSFwLq", "senderPublicKey": "HdwFH8HPYu3HG27yK6bszu1CdR4uik4HgzyTimeSfcYf", "proofs": [ "4WB4PPLLtyJd3S9wU2paWLZHbgmvFAKxFX4nYvg2x3yZhT3etxVBoxx5qMdaiCncX16iMKBDoSUnQXjrfp87GbLN" ], "script": "base64:BgIECAISAA8AEGFtb3VudEFzc2V0SWRLZXkCDWFtb3VudEFzc2V0SWQAD3ByaWNlQXNzZXRJZEtleQIMcHJpY2VBc3NldElkAApmZWVSYXRlS2V5AgdmZWVSYXRlAQpnZXRBc3NldElkAQ1hc3NldElkU3RyaW5nAwkAAAIFDWFzc2V0SWRTdHJpbmcCBVdBVkVTBQR1bml0CQDZBAEFDWFzc2V0SWRTdHJpbmcBD2dldEFzc2V0QmFsYW5jZQEHYXNzZXRJZAQHJG1hdGNoMAUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgpCeXRlVmVjdG9yBAJpZAUHJG1hdGNoMAkA8AcCBQR0aGlzBQJpZAgJAO8HAQUEdGhpcwlhdmFpbGFibGUAE2Ftb3VudEFzc2V0SWRTdHJpbmcJARFAZXh0ck5hdGl2ZSgxMDUzKQIFBHRoaXMFEGFtb3VudEFzc2V0SWRLZXkADWFtb3VudEFzc2V0SWQJAQpnZXRBc3NldElkAQUTYW1vdW50QXNzZXRJZFN0cmluZwASYW1vdW50QXNzZXRCYWxhbmNlCQEPZ2V0QXNzZXRCY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EgBQNuaWwDCQAAAgUGY2hlY2tzBQZjaGVja3MEDXBheW1lbnRBbW91bnQICQCRAwIIBQFpCHBheW1lbnRzAAAGYW1vdW50BAlpbml0QW1CYWwFEmFtb3VudEFzc2V0QmFsYW5jZQQJaW5pdFByQmFsCQBlAgURcHJpY2VBc3NldEJhbGFuY2UFDXBheW1lbnRBbW91bnQAAAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgEBaQEDZm9vAAkAlAoCBQNuaWwAAAAPmd05", "height": 3003007, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9SHEDhoBRCdwgSTXA3kKdPAyqUEDTd3V68UMryvY6Rht Next: 5pdCPCDyatDLkfxt8mLnER4YMzvntECsNYP3WBDqMhRD Diff:
Old | New | Differences | |
---|---|---|---|
37 | 37 | let feeRate = valueOrElse(getInteger(this, feeRateKey), 1000000) | |
38 | 38 | ||
39 | 39 | func calcSendAmount (initAmBal,initPrBal,paymentAmount) = { | |
40 | - | let | |
41 | - | let newAmBal = (initAmBal - | |
40 | + | let sendAmount = (initAmBal - fraction((initAmBal * initPrBal), SCALE8, (initPrBal * SCALE8))) | |
41 | + | let newAmBal = (initAmBal - sendAmount) | |
42 | 42 | let newPrBal = (initPrBal + paymentAmount) | |
43 | 43 | let oldK = (initAmBal * initPrBal) | |
44 | 44 | let newK = (newAmBal * newPrBal) | |
45 | - | $ | |
45 | + | $Tuple7(sendAmount, initAmBal, initPrBal, oldK, newAmBal, newPrBal, newK) | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let amountAssetIdKey = "amountAssetId" | |
5 | 5 | ||
6 | 6 | let priceAssetIdKey = "priceAssetId" | |
7 | 7 | ||
8 | 8 | let feeRateKey = "feeRate" | |
9 | 9 | ||
10 | 10 | func getAssetId (assetIdString) = if ((assetIdString == "WAVES")) | |
11 | 11 | then unit | |
12 | 12 | else fromBase58String(assetIdString) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func getAssetBalance (assetId) = match assetId { | |
16 | 16 | case id: ByteVector => | |
17 | 17 | assetBalance(this, id) | |
18 | 18 | case _ => | |
19 | 19 | wavesBalance(this).available | |
20 | 20 | } | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | let amountAssetIdString = getStringValue(this, amountAssetIdKey) | |
24 | 24 | ||
25 | 25 | let amountAssetId = getAssetId(amountAssetIdString) | |
26 | 26 | ||
27 | 27 | let amountAssetBalance = getAssetBalance(amountAssetId) | |
28 | 28 | ||
29 | 29 | let priceAssetIdString = getStringValue(this, priceAssetIdKey) | |
30 | 30 | ||
31 | 31 | let priceAssetId = getAssetId(priceAssetIdString) | |
32 | 32 | ||
33 | 33 | let priceAssetBalance = getAssetBalance(priceAssetId) | |
34 | 34 | ||
35 | 35 | let SCALE8 = 100000000 | |
36 | 36 | ||
37 | 37 | let feeRate = valueOrElse(getInteger(this, feeRateKey), 1000000) | |
38 | 38 | ||
39 | 39 | func calcSendAmount (initAmBal,initPrBal,paymentAmount) = { | |
40 | - | let | |
41 | - | let newAmBal = (initAmBal - | |
40 | + | let sendAmount = (initAmBal - fraction((initAmBal * initPrBal), SCALE8, (initPrBal * SCALE8))) | |
41 | + | let newAmBal = (initAmBal - sendAmount) | |
42 | 42 | let newPrBal = (initPrBal + paymentAmount) | |
43 | 43 | let oldK = (initAmBal * initPrBal) | |
44 | 44 | let newK = (newAmBal * newPrBal) | |
45 | - | $ | |
45 | + | $Tuple7(sendAmount, initAmBal, initPrBal, oldK, newAmBal, newPrBal, newK) | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func swap (i) = { | |
50 | 50 | let checks = [if ((size(i.payments) > 0)) | |
51 | 51 | then true | |
52 | 52 | else throw("should be with 1 payment"), if ((i.payments[0].assetId == priceAssetId)) | |
53 | 53 | then true | |
54 | 54 | else throw(makeString(["payment assetId should be: ", priceAssetIdString], " "))] | |
55 | 55 | if ((checks == checks)) | |
56 | 56 | then { | |
57 | 57 | let paymentAmount = i.payments[0].amount | |
58 | 58 | let initAmBal = amountAssetBalance | |
59 | 59 | let initPrBal = (priceAssetBalance - paymentAmount) | |
60 | 60 | 0 | |
61 | 61 | } | |
62 | 62 | else throw("Strict value is not equal to itself.") | |
63 | 63 | } | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | @Callable(i) | |
67 | 67 | func foo () = $Tuple2(nil, 0) | |
68 | 68 | ||
69 | 69 |
github/deemru/w8io/169f3d6 31.48 ms ◑