tx · 6SXoeWqQf8bx81nzHafoynzZ9VGPorntBDAZ5HHNqUSq

3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk:  -1.00500000 Waves

2022.07.14 10:47 [2139111] smart account 3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk > SELF 0.00000000 Waves

{ "type": 13, "id": "6SXoeWqQf8bx81nzHafoynzZ9VGPorntBDAZ5HHNqUSq", "fee": 100500000, "feeAssetId": null, "timestamp": 1657784930833, "version": 2, "chainId": 84, "sender": "3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk", "senderPublicKey": "8ZzMCsQ15BKiHk944146A5WQ8eSFd8vaff4xaktCKSBK", "proofs": [ "Yix9sAH7JJRiTnusxT2KifnW2WDzAac5G6LkJc2mYnCtXQtZVMoAiLRzTVuK2cyruPNR8ofj2AB3tDoB2DvTBm7" ], "script": "base64:BgIRCAISAwoBCBIAEgASBAoCCAgRAAlzZXBhcmF0b3ICAV8BDWdldFBhaXJMZW5ndGgACQELdmFsdWVPckVsc2UCCQCaCAIFBHRoaXMCCnBhaXJMZW5ndGgAAAENc2V0UGFpckxlbmdodAEJbmV3TGVuZ3RoCQEMSW50ZWdlckVudHJ5AgIKcGFpckxlbmd0aAUJbmV3TGVuZ3RoAQpnZXRQYWlyS2V5AgZ0b2tlbjAGdG9rZW4xBAh0b2tlbjBCVgkAsQkBCQDZBAEFBnRva2VuMAQIdG9rZW4xQlYJALEJAQkA2QQBBQZ0b2tlbjEDCQBmAgUIdG9rZW4xQlYFCHRva2VuMEJWCQC5CQIJAMwIAgUGdG9rZW4wCQDMCAIFBnRva2VuMQUDbmlsBQlzZXBhcmF0b3IJALkJAgkAzAgCBQZ0b2tlbjEJAMwIAgUGdG9rZW4wBQNuaWwFCXNlcGFyYXRvcgEOZ2V0UGFpclRva2VuSWQCBnRva2VuMAZ0b2tlbjEJARFAZXh0ck5hdGl2ZSgxMDUzKQIFBHRoaXMJAQpnZXRQYWlyS2V5AgUGdG9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XJSZXNlcnZlMQUHYW1vdW50MQUDbmlsAWkBEGFkZExpcXVpZGl0eVBvb2wCBnRva2VuMAZ0b2tlbjEDCQEJaXNOZXdQYWlyAgUGdG9rZW4wBQZ0b2tlbjEDCQECIT0CBQZ0b2tlbjAFBnRva2VuMQMDCQENaXNUb2tlbkV4aXN0cwEFBnRva2VuMAkBDWlzVG9rZW5FeGlzdHMBBQZ0b2tlbjEHBAhuZXdUb2tlbgkAwggFCQDYBAEJAMkBAggFAWkNdHJhbnNhY3Rpb25JZAAKAgAAAAAABgQHaXNzdWVJZAkA2AQBCQC4CAEFCG5ld1Rva2VuBBBjdXJyZW50UGFpckluZGV4CQENZ2V0UGFpckxlbmd0aAAJAMwIAgUIbmV3VG9rZW4JAMwIAgkBC1N0cmluZ0VudHJ5AgkApAMBBRBjdXJyZW50UGFpckluZGV4BQdpc3N1ZUlkCQDMCAIJAQ1zZXRQYWlyTGVuZ2h0AQkAZAIFEGN1cnJlbnRQYWlySW5kZXgAAQkAzAgCCQEOc2V0UGFpclRva2VuSWQDBQZ0b2tlbjAFBnRva2VuMQUHaXNzdWVJZAkAzAgCCQEOc2V0UGFpckRldGFpbHMFBQdpc3N1ZUlkBQZ0b2tlbjAFBnRva2VuMQAAAAAFA25pbAkAAgECDFdyb25nIHRva2VucwkAAgECDEVxdWFsIHRva2VucwkAAgECE1BhaXIgYWxyZWFkeSBleGlzdHMAv+pZLQ==", "height": 2139111, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GYWtBGQttGYZQtM4hE6jPmscwjcChrrp5SbKeXEytTzY Next: 3T2LbSdMzfMKBjUfxnNod9JeCwsCS5VG2WknH2jnbs7v Diff:
OldNewDifferences
4545 func isNewPair (token0,token1) = !(isDefined(getString(getPairKey(token0, token1))))
4646
4747
48-func isTokenExists (tokenId) = true
48+func isTokenExists (tokenId) = match assetInfo(fromBase58String(tokenId)) {
49+ case a: Asset =>
50+ true
51+ case _ =>
52+ throw("Bad situation")
53+}
4954
5055
51-let maxx = 1000000000000
56+let maxx = 100000000
5257
5358 let zeroAddr = value(addressFromString("3M4qwDomRabJKLZxuXhwfqLApQkU592nWxF"))
5459
5560 let MINIMUM_LIQUIDITY = 100000
61+
62+func calcAmountOut (amountIn,reserveIn,reserveOut) = {
63+ let amountInWithFee = (amountIn * 997)
64+ let numerator = (amountInWithFee * reserveOut)
65+ let denominator = ((reserveIn * 1000) + amountInWithFee)
66+ (numerator / denominator)
67+ }
68+
69+
70+@Callable(i)
71+func swap (tokenOut) = {
72+ let amountIn = value(i.payments[0].amount)
73+ let tokenIn = toBase58String(value(i.payments[0].assetId))
74+ let lpToken = getPairTokenId(tokenIn, tokenOut)
75+ let $t026392721 = getPairDetails(lpToken)
76+ let pairToken0 = $t026392721._1
77+ let pairToken1 = $t026392721._2
78+ let pairReserve0 = $t026392721._3
79+ let pairReserve1 = $t026392721._4
80+ let amountOut = calcAmountOut(amountIn, pairReserve0, pairReserve1)
81+[ScriptTransfer(i.caller, amountOut, fromBase58String(pairToken1)), setPairDetails(lpToken, tokenIn, tokenOut, (pairReserve0 + amountIn), (pairReserve1 - amountOut))]
82+ }
83+
84+
5685
5786 @Callable(i)
5887 func mint () = {
6190 let lpToken = getPairTokenId(token0, token1)
6291 let amount0 = value(i.payments[0].amount)
6392 let amount1 = value(i.payments[1].amount)
64- let $t023722454 = getPairDetails(lpToken)
65- let pairToken0 = $t023722454._1
66- let pairToken1 = $t023722454._2
67- let pairReserve0 = $t023722454._3
68- let pairReserve1 = $t023722454._4
93+ let $t032693351 = getPairDetails(lpToken)
94+ let pairToken0 = $t032693351._1
95+ let pairToken1 = $t032693351._2
96+ let pairReserve0 = $t032693351._3
97+ let pairReserve1 = $t032693351._4
6998 let totalSupply = getPairTotalSupply(lpToken)
7099 if ((totalSupply == 0))
71100 then {
74103 }
75104 else {
76105 let liquidity = min([((amount0 * totalSupply) / pairReserve0), ((amount1 * totalSupply) / pairReserve1)])
77-[Reissue(fromBase58String(lpToken), liquidity, true), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, liquidity), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))]
106+[Reissue(fromBase58String(lpToken), liquidity, true), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, (totalSupply + liquidity)), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))]
78107 }
79108 }
80109
84113 func burn () = {
85114 let amountlp = value(i.payments[0].amount)
86115 let assetIdLp = value(i.payments[0].assetId)
87- let $t035473647 = getPairDetails(toBase58String(assetIdLp))
88- let pairToken0 = $t035473647._1
89- let pairToken1 = $t035473647._2
90- let pairReserve0 = $t035473647._3
91- let pairReserve1 = $t035473647._4
116+ let $t044584558 = getPairDetails(toBase58String(assetIdLp))
117+ let pairToken0 = $t044584558._1
118+ let pairToken1 = $t044584558._2
119+ let pairReserve0 = $t044584558._3
120+ let pairReserve1 = $t044584558._4
92121 let lpToken = getPairTokenId(pairToken0, pairToken1)
93122 let totalSupply = getPairTotalSupply(lpToken)
94123 let share = ((amountlp * maxx) / totalSupply)
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let separator = "_"
55
66 func getPairLength () = valueOrElse(getInteger(this, "pairLength"), 0)
77
88
99 func setPairLenght (newLength) = IntegerEntry("pairLength", newLength)
1010
1111
1212 func getPairKey (token0,token1) = {
1313 let token0BV = toInt(fromBase58String(token0))
1414 let token1BV = toInt(fromBase58String(token1))
1515 if ((token1BV > token0BV))
1616 then makeString([token0, token1], separator)
1717 else makeString([token1, token0], separator)
1818 }
1919
2020
2121 func getPairTokenId (token0,token1) = getStringValue(this, getPairKey(token0, token1))
2222
2323
2424 func setPairTokenId (token0,token1,issueId) = StringEntry(getPairKey(token0, token1), issueId)
2525
2626
2727 func joinPairStruct (token0,token1,reserve0,reserve1) = makeString([token0, token1, toString(reserve0), toString(reserve1)], separator)
2828
2929
3030 func getPairDetails (lpTokenId) = {
3131 let details = split(valueOrElse(getString(this, lpTokenId), "assetId0_assetId1_0_0"), separator)
3232 $Tuple4(details[0], details[1], parseIntValue(details[2]), parseIntValue(details[3]))
3333 }
3434
3535
3636 func setPairDetails (lpTokenId,token0,token1,reserve0,reserve1) = StringEntry(lpTokenId, joinPairStruct(token0, token1, reserve0, reserve1))
3737
3838
3939 func getPairTotalSupply (lpTokenId) = valueOrElse(getInteger(this, (("totalSupply" + separator) + lpTokenId)), 0)
4040
4141
4242 func setPairTotalSupply (lpTokenId,newTotalSupply) = IntegerEntry((("totalSupply" + separator) + lpTokenId), newTotalSupply)
4343
4444
4545 func isNewPair (token0,token1) = !(isDefined(getString(getPairKey(token0, token1))))
4646
4747
48-func isTokenExists (tokenId) = true
48+func isTokenExists (tokenId) = match assetInfo(fromBase58String(tokenId)) {
49+ case a: Asset =>
50+ true
51+ case _ =>
52+ throw("Bad situation")
53+}
4954
5055
51-let maxx = 1000000000000
56+let maxx = 100000000
5257
5358 let zeroAddr = value(addressFromString("3M4qwDomRabJKLZxuXhwfqLApQkU592nWxF"))
5459
5560 let MINIMUM_LIQUIDITY = 100000
61+
62+func calcAmountOut (amountIn,reserveIn,reserveOut) = {
63+ let amountInWithFee = (amountIn * 997)
64+ let numerator = (amountInWithFee * reserveOut)
65+ let denominator = ((reserveIn * 1000) + amountInWithFee)
66+ (numerator / denominator)
67+ }
68+
69+
70+@Callable(i)
71+func swap (tokenOut) = {
72+ let amountIn = value(i.payments[0].amount)
73+ let tokenIn = toBase58String(value(i.payments[0].assetId))
74+ let lpToken = getPairTokenId(tokenIn, tokenOut)
75+ let $t026392721 = getPairDetails(lpToken)
76+ let pairToken0 = $t026392721._1
77+ let pairToken1 = $t026392721._2
78+ let pairReserve0 = $t026392721._3
79+ let pairReserve1 = $t026392721._4
80+ let amountOut = calcAmountOut(amountIn, pairReserve0, pairReserve1)
81+[ScriptTransfer(i.caller, amountOut, fromBase58String(pairToken1)), setPairDetails(lpToken, tokenIn, tokenOut, (pairReserve0 + amountIn), (pairReserve1 - amountOut))]
82+ }
83+
84+
5685
5786 @Callable(i)
5887 func mint () = {
5988 let token0 = toBase58String(value(i.payments[0].assetId))
6089 let token1 = toBase58String(value(i.payments[1].assetId))
6190 let lpToken = getPairTokenId(token0, token1)
6291 let amount0 = value(i.payments[0].amount)
6392 let amount1 = value(i.payments[1].amount)
64- let $t023722454 = getPairDetails(lpToken)
65- let pairToken0 = $t023722454._1
66- let pairToken1 = $t023722454._2
67- let pairReserve0 = $t023722454._3
68- let pairReserve1 = $t023722454._4
93+ let $t032693351 = getPairDetails(lpToken)
94+ let pairToken0 = $t032693351._1
95+ let pairToken1 = $t032693351._2
96+ let pairReserve0 = $t032693351._3
97+ let pairReserve1 = $t032693351._4
6998 let totalSupply = getPairTotalSupply(lpToken)
7099 if ((totalSupply == 0))
71100 then {
72101 let liquidity = (sqrt((amount0 * amount1), 0, 0, DOWN) - MINIMUM_LIQUIDITY)
73102 [Reissue(fromBase58String(lpToken), (liquidity + MINIMUM_LIQUIDITY), true), ScriptTransfer(zeroAddr, MINIMUM_LIQUIDITY, fromBase58String(lpToken)), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, (liquidity + MINIMUM_LIQUIDITY)), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))]
74103 }
75104 else {
76105 let liquidity = min([((amount0 * totalSupply) / pairReserve0), ((amount1 * totalSupply) / pairReserve1)])
77-[Reissue(fromBase58String(lpToken), liquidity, true), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, liquidity), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))]
106+[Reissue(fromBase58String(lpToken), liquidity, true), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, (totalSupply + liquidity)), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))]
78107 }
79108 }
80109
81110
82111
83112 @Callable(i)
84113 func burn () = {
85114 let amountlp = value(i.payments[0].amount)
86115 let assetIdLp = value(i.payments[0].assetId)
87- let $t035473647 = getPairDetails(toBase58String(assetIdLp))
88- let pairToken0 = $t035473647._1
89- let pairToken1 = $t035473647._2
90- let pairReserve0 = $t035473647._3
91- let pairReserve1 = $t035473647._4
116+ let $t044584558 = getPairDetails(toBase58String(assetIdLp))
117+ let pairToken0 = $t044584558._1
118+ let pairToken1 = $t044584558._2
119+ let pairReserve0 = $t044584558._3
120+ let pairReserve1 = $t044584558._4
92121 let lpToken = getPairTokenId(pairToken0, pairToken1)
93122 let totalSupply = getPairTotalSupply(lpToken)
94123 let share = ((amountlp * maxx) / totalSupply)
95124 let amount0 = ((share * pairReserve0) / maxx)
96125 let amount1 = ((share * pairReserve1) / maxx)
97126 [Burn(fromBase58String(lpToken), amountlp), ScriptTransfer(i.caller, amount0, fromBase58String(pairToken0)), ScriptTransfer(i.caller, amount1, fromBase58String(pairToken1)), setPairTotalSupply(lpToken, (totalSupply - amountlp)), setPairDetails(lpToken, pairToken0, pairToken1, (pairReserve0 - amount0), (pairReserve1 - amount1))]
98127 }
99128
100129
101130
102131 @Callable(i)
103132 func addLiquidityPool (token0,token1) = if (isNewPair(token0, token1))
104133 then if ((token0 != token1))
105134 then if (if (isTokenExists(token0))
106135 then isTokenExists(token1)
107136 else false)
108137 then {
109138 let newToken = Issue(toBase58String(take(i.transactionId, 10)), "", 0, 0, true)
110139 let issueId = toBase58String(calculateAssetId(newToken))
111140 let currentPairIndex = getPairLength()
112141 [newToken, StringEntry(toString(currentPairIndex), issueId), setPairLenght((currentPairIndex + 1)), setPairTokenId(token0, token1, issueId), setPairDetails(issueId, token0, token1, 0, 0)]
113142 }
114143 else throw("Wrong tokens")
115144 else throw("Equal tokens")
116145 else throw("Pair already exists")
117146
118147

github/deemru/w8io/026f985 
36.29 ms