tx · G8ThLkwZBdn2Msaejm82aH2rv7uGkT9F4SLFoUq8hsbf 3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx: -0.01000000 Waves 2022.12.02 16:31 [2342789] smart account 3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx > SELF 0.00000000 Waves
{ "type": 13, "id": "G8ThLkwZBdn2Msaejm82aH2rv7uGkT9F4SLFoUq8hsbf", "fee": 1000000, "feeAssetId": null, "timestamp": 1669987885433, "version": 2, "chainId": 84, "sender": "3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx", "senderPublicKey": "EKZmHJ5bK3qKKgRdq8rAamt9qrDbVMLARzRqXoQW258v", "proofs": [ "2xFaTw2816UzGR7QVfKMKzpGHvQGVswUrRUEWw1u9LN2wJgF7bsnhHWJE3DrCuvUMDyLDadUSEVc13GKYaVdfwx8" ], "script": "base64:AAIFAAAAAAAAAAgIAhIECgIIAQAAAAcAAAAACXNlcGFyYXRvcgIAAAABXwEAAAAOam9pblBhaXJTdHJ1Y3QAAAAEAAAABnRva2VuMAAAAAZ0b2tlbjEAAAAIcmVzZXJ2ZTAAAAAIcmVzZXJ2ZTEJAAS5AAAAAgkABEwAAAACBQAAAAZ0b2tlbjAJAARMAAAAAgUAAAAGdG9rZW4xCQAETAAAAAIJAAGkAAAAAQUAAAAIcmVzZXJ2ZTAJAARMAAAAAgkAAaQAAAABBQAAAAhyZXNlcnZlMQUAAAADbmlsBQAAAAlzZXBhcmF0b3IBAAAADnNldFBhaXJEZXRhaWxzAAAABQAAAAlscFRva2VuSWQAAAAGdG9rZW4wAAAABnRva2VuMQAAAAhyZXNlcnZlMAAAAAhyZXNlcnZlMQkBAAAAC1N0cmluZ0VudHJ5AAAAAgUAAAAJbHBUb2tlbklkCQEAAAAOam9pblBhaXJTdHJ1Y3QAAAAEBQAAAAZ0b2tlbjAFAAAABnRva2VuMQUAAAAIcmVzZXJ2ZTAFAAAACHJlc2VydmUxAQAAAA1jYWxjQW1vdW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EAAAACWFtb3VudE91dAkBAAAADWNhbGNBbW91bnRPdXQAAAADBQAAAAhhbW91bnRJbgUAAAAMcGFpclJlc2VydmUwBQAAAAxwYWlyUmVzZXJ2ZTEDCQAAZgAAAAIFAAAADGFtb3VudE91dE1pbgUAAAAJYW1vdW50T3V0CQAAAgAAAAECAAAAGkluc3VmZmljaWVudCBvdXRwdXQgYW1vdW50CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAJYW1vdW50T3V0CQACWQAAAAEFAAAACnBhaXJUb2tlbjEJAARMAAAAAgkBAAAADnNldFBhaXJEZXRhaWxzAAAABQUAAAAHbHBUb2tlbgUAAAAHdG9rZW5JbgUAAAAIdG9rZW5PdXQJAABkAAAAAgUAAAAMcGFpclJlc2VydmUwBQAAAAhhbW91bnRJbgkAAGUAAAACBQAAAAxwYWlyUmVzZXJ2ZTEFAAAACWFtb3VudE91dAUAAAADbmlsAAAAAOaRgMs=", "height": 2342789, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: HnJ2tEckyXM14p72xHyUs35Tamy5xDzsDruqozRxjR6F Next: XY6hGBKpNyBmSgpdyHEkELsYa1mxqM7Gk9RKq32XTzm Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "_" | |
5 | 5 | ||
6 | 6 | func joinPairStruct (token0,token1,reserve0,reserve1) = makeString([token0, token1, toString(reserve0), toString(reserve1)], separator) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func setPairDetails (lpTokenId,token0,token1,reserve0,reserve1) = StringEntry(lpTokenId, joinPairStruct(token0, token1, reserve0, reserve1)) | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func calcAmountOut (amountIn,reserveIn,reserveOut) = { | |
13 | 13 | let amountInWithFee = (amountIn * 970) | |
14 | 14 | let numerator = (amountInWithFee * reserveOut) | |
15 | 15 | let denominator = ((reserveIn * 1000) + amountInWithFee) | |
16 | 16 | fraction(1, numerator, denominator, HALFEVEN) | |
17 | 17 | } | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func getPairKey (token0,token1) = { | |
21 | 21 | let token0BV = toInt(fromBase58String(token0)) | |
22 | 22 | let token1BV = toInt(fromBase58String(token1)) | |
23 | 23 | if ((token1BV > token0BV)) | |
24 | 24 | then makeString([token0, token1], separator) | |
25 | 25 | else makeString([token1, token0], separator) | |
26 | 26 | } | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func getPairTokenId (token0,token1) = valueOrErrorMessage(getString(this, getPairKey(token0, token1)), "Pair doesn`t exist") | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func getPairDetails (lpTokenId) = { | |
33 | 33 | let details = split(valueOrElse(getString(this, lpTokenId), "assetId0_assetId1_0_0"), separator) | |
34 | 34 | $Tuple4(details[0], details[1], parseIntValue(details[2]), parseIntValue(details[3])) | |
35 | 35 | } | |
36 | 36 | ||
37 | 37 | ||
38 | 38 | @Callable(i) | |
39 | 39 | func swap (tokenOut,amountOutMin) = { | |
40 | 40 | let $t014441548 = $Tuple2(toBase58String(value(i.payments[0].assetId)), value(i.payments[0].amount)) | |
41 | 41 | let tokenIn = $t014441548._1 | |
42 | 42 | let amountIn = $t014441548._2 | |
43 | 43 | let lpToken = getPairTokenId(tokenIn, tokenOut) | |
44 | 44 | let $t016011683 = getPairDetails(lpToken) | |
45 | 45 | let pairToken0 = $t016011683._1 | |
46 | 46 | let pairToken1 = $t016011683._2 | |
47 | 47 | let pairReserve0 = $t016011683._3 | |
48 | 48 | let pairReserve1 = $t016011683._4 | |
49 | 49 | let amountOut = calcAmountOut(amountIn, pairReserve0, pairReserve1) | |
50 | 50 | if ((amountOutMin > amountOut)) | |
51 | 51 | then throw("Insufficient output amount") | |
52 | 52 | else [ScriptTransfer(i.caller, amountOut, fromBase58String(pairToken1)), setPairDetails(lpToken, tokenIn, tokenOut, (pairReserve0 + amountIn), (pairReserve1 - amountOut))] | |
53 | 53 | } | |
54 | 54 | ||
55 | 55 |
github/deemru/w8io/169f3d6 25.27 ms ◑