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:AAIFAAAAAAAAAAgIAhIECgIIAQAAAAcAAAAACXNlcGFyYXRvcgIAAAABXwEAAAAOam9pblBhaXJTdHJ1Y3QAAAAEAAAABnRva2VuMAAAAAZ0b2tlbjEAAAAIcmVzZXJ2ZTAAAAAIcmVzZXJ2ZTEJAAS5AAAAAgkABEwAAAACBQAAAAZ0b2tlbjAJAARMAAAAAgUAAAAGdG9rZW4xCQAETAAAAAIJAAGkAAAAAQUAAAAIcmVzZXJ2ZTAJAARMAAAAAgkAAaQAAAABBQAAAAhyZXNlcnZlMQUAAAADbmlsBQAAAAlzZXBhcmF0b3IBAAAADnNldFBhaXJEZXRhaWxzAAAABQAAAAlscFRva2VuSWQAAAAGdG9rZW4wAAAABnRva2VuMQAAAAhyZXNlcnZlMAAAAAhyZXNlcnZlMQkBAAAAC1N0cmluZ0VudHJ5AAAAAgUAAAAJbHBUb2tlbklkCQEAAAAOam9pblBhaXJTdHJ1Y3QAAAAEBQAAAAZ0b2tlbjAFAAAABnRva2VuMQUAAAAIcmVzZXJ2ZTAFAAAACHJlc2VydmUxAQAAAA1jYWxjQW1vd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QEAAAACWFtb3VudE91dAkBAAAADWNhbGNBbW91bnRPdXQAAAADBQAAAAhhbW91bnRJbgUAAAAMcGFpclJlc2VydmUwBQAAAAxwYWlyUmVzZXJ2ZTEDCQAAZgAAAAIFAAAADGFtb3VudE91dE1pbgUAAAAJYW1vdW50T3V0CQAAAgAAAAECAAAAGkluc3VmZmljaWVudCBvdXRwdXQgYW1vdW50CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAJYW1vdW50T3V0CQACWQAAAAEFAAAACnBhaXJUb2tlbjEJAARMAAAAAgkBAAAADnNldFBhaXJEZXRhaWxzAAAABQUAAAAHbHBUb2tlbgUAAAAHdG9rZW5JbgUAAAAIdG9rZW5PdXQJAABkAAAAAgUAAAAMcGFpclJlc2VydmUwBQAAAAhhbW91bnRJbgkAAGUAAAACBQAAAAxwYWlyUmVzZXJ2ZTEFAAAACWFtb3VudE91dAUAAAADbmlsAAAAAOaRgMs=", "height": 2342789, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: HnJ2tEckyXM14p72xHyUs35Tamy5xDzsDruqozRxjR6F Next: XY6hGBKpNyBmSgpdyHEkELsYa1mxqM7Gk9RKq32XTzm Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let separator = "_"
55
66 func joinPairStruct (token0,token1,reserve0,reserve1) = makeString([token0, token1, toString(reserve0), toString(reserve1)], separator)
77
88
99 func setPairDetails (lpTokenId,token0,token1,reserve0,reserve1) = StringEntry(lpTokenId, joinPairStruct(token0, token1, reserve0, reserve1))
1010
1111
1212 func calcAmountOut (amountIn,reserveIn,reserveOut) = {
1313 let amountInWithFee = (amountIn * 970)
1414 let numerator = (amountInWithFee * reserveOut)
1515 let denominator = ((reserveIn * 1000) + amountInWithFee)
1616 fraction(1, numerator, denominator, HALFEVEN)
1717 }
1818
1919
2020 func getPairKey (token0,token1) = {
2121 let token0BV = toInt(fromBase58String(token0))
2222 let token1BV = toInt(fromBase58String(token1))
2323 if ((token1BV > token0BV))
2424 then makeString([token0, token1], separator)
2525 else makeString([token1, token0], separator)
2626 }
2727
2828
2929 func getPairTokenId (token0,token1) = valueOrErrorMessage(getString(this, getPairKey(token0, token1)), "Pair doesn`t exist")
3030
3131
3232 func getPairDetails (lpTokenId) = {
3333 let details = split(valueOrElse(getString(this, lpTokenId), "assetId0_assetId1_0_0"), separator)
3434 $Tuple4(details[0], details[1], parseIntValue(details[2]), parseIntValue(details[3]))
3535 }
3636
3737
3838 @Callable(i)
3939 func swap (tokenOut,amountOutMin) = {
4040 let $t014441548 = $Tuple2(toBase58String(value(i.payments[0].assetId)), value(i.payments[0].amount))
4141 let tokenIn = $t014441548._1
4242 let amountIn = $t014441548._2
4343 let lpToken = getPairTokenId(tokenIn, tokenOut)
4444 let $t016011683 = getPairDetails(lpToken)
4545 let pairToken0 = $t016011683._1
4646 let pairToken1 = $t016011683._2
4747 let pairReserve0 = $t016011683._3
4848 let pairReserve1 = $t016011683._4
4949 let amountOut = calcAmountOut(amountIn, pairReserve0, pairReserve1)
5050 if ((amountOutMin > amountOut))
5151 then throw("Insufficient output amount")
5252 else [ScriptTransfer(i.caller, amountOut, fromBase58String(pairToken1)), setPairDetails(lpToken, tokenIn, tokenOut, (pairReserve0 + amountIn), (pairReserve1 - amountOut))]
5353 }
5454
5555

github/deemru/w8io/169f3d6 
25.27 ms