tx · Bvw6u6GTGPf6eG5b2vv3CR4nqVRUFBtTj1xeXpTFn4ib

3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk:  -0.05000000 Waves

2022.07.13 18:44 [2138155] smart account 3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk > SELF 0.00000000 Waves

{ "type": 13, "id": "Bvw6u6GTGPf6eG5b2vv3CR4nqVRUFBtTj1xeXpTFn4ib", "fee": 5000000, "feeAssetId": null, "timestamp": 1657727189655, "version": 2, "chainId": 84, "sender": "3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk", "senderPublicKey": "8ZzMCsQ15BKiHk944146A5WQ8eSFd8vaff4xaktCKSBK", "proofs": [ "5Ei1zjNGjNYPzkdaWX3dqHnFzemmcdLyikJnSZRmk3iXRJfKbVHV4Kv5ErjLNuoATZXjzBKUdcZnSiefHxBRkR9d" ], "script": "base64:BgIMCAISABIAEgQKAggIEAAJc2VwYXJhdG9yAgFfAQ1nZXRQYWlyTGVuZ3RoAAkBC3ZhbHVlT3JFbHNlAgkAmggCBQR0aGlzAgpwYWlyTGVuZ3RoAAABDXNldFBhaXJMZW5naHQBCW5ld0xlbmd0aAkBDEludGVnZXJFbnRyeQICCnBhaXJMZW5ndGgFCW5ld0xlbmd0aAEKZ2V0UGFpcktleQIGdG9rZW4wBnRva2VuMQQIdG9rZW4wQlYJALEJAQkA2QQBBQZ0b2tlbjAECHRva2VuMUJWCQCxCQEJANkEAQUGdG9rZW4xAwkAZgIFCHRva2VuMUJWBQh0b2tlbjBCVgkAuQkCCQDMCAIFBnRva2VuMAkAzAgCBQZ0b2tlbjEFA25pbAUJc2VwYXJhdG9yCQC5CQIJAMwIAgUGdG9rZW4xCQDMCAIFBnRva2VuMAUDbmlsBQlzZXBhcmF0b3IBDmdldFBhaXJUb2tlbklkAgZ0b2tlbjAGdG9rZW4xCQERQGV4dHJOYXRpdmUoMTA1MykCBQR0aGlzCQEKZ2V0UGFpcktleQIFBnRva2Vu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haXICBQZ0b2tlbjAFBnRva2VuMQMJAQIhPQIFBnRva2VuMAUGdG9rZW4xAwMJAQ1pc1Rva2VuRXhpc3RzAQUGdG9rZW4wCQENaXNUb2tlbkV4aXN0cwEFBnRva2VuMQcECG5ld1Rva2VuCQDCCAUJANgEAQkAyQECCAUBaQ10cmFuc2FjdGlvbklkAAoCAAAAAAAGBAdpc3N1ZUlkCQDYBAEJALgIAQUIbmV3VG9rZW4EEGN1cnJlbnRQYWlySW5kZXgJAQ1nZXRQYWlyTGVuZ3RoAAkAzAgCBQhuZXdUb2tlbgkAzAgCCQELU3RyaW5nRW50cnkCCQCkAwEFEGN1cnJlbnRQYWlySW5kZXgFB2lzc3VlSWQJAMwIAgkBDXNldFBhaXJMZW5naHQBCQBkAgUQY3VycmVudFBhaXJJbmRleAABCQDMCAIJAQ5zZXRQYWlyVG9rZW5JZAMFBnRva2VuMAUGdG9rZW4xBQdpc3N1ZUlkCQDMCAIJAQ5zZXRQYWlyRGV0YWlscwUFB2lzc3VlSWQFBnRva2VuMAUGdG9rZW4xAAAAAAUDbmlsCQACAQIMV3JvbmcgdG9rZW5zCQACAQIMRXF1YWwgdG9rZW5zCQACAQITUGFpciBhbHJlYWR5IGV4aXN0cwAkZbmA", "height": 2138155, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Gv1U45NncsM3aiCmtw837WHdw4xS1MzpJcqFe15PC6oe Next: B2DDZ8w6q11WQ1tef5ojtMWJHdTZNMYaDdu83GS7t6iZ 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
4848 func isTokenExists (tokenId) = true
4949
5050
5151 let maxx = 1000000000000
5252
5353 let zeroAddr = value(addressFromString("3M4qwDomRabJKLZxuXhwfqLApQkU592nWxF"))
5454
5555 let MINIMUM_LIQUIDITY = 100000
5656
5757 @Callable(i)
5858 func mint () = {
5959 let token0 = toBase58String(value(i.payments[0].assetId))
6060 let token1 = toBase58String(value(i.payments[1].assetId))
6161 let lpToken = getPairTokenId(token0, token1)
6262 let amount0 = value(i.payments[0].amount)
6363 let amount1 = value(i.payments[1].amount)
6464 let $t023722454 = getPairDetails(lpToken)
6565 let pairToken0 = $t023722454._1
6666 let pairToken1 = $t023722454._2
6767 let pairReserve0 = $t023722454._3
6868 let pairReserve1 = $t023722454._4
6969 let totalSupply = getPairTotalSupply(lpToken)
7070 if ((totalSupply == 0))
7171 then {
7272 let liquidity = (sqrt((amount0 * amount1), 0, 0, DOWN) - MINIMUM_LIQUIDITY)
7373 [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))]
7474 }
7575 else {
7676 let liquidity = min([((amount0 * totalSupply) / pairReserve0), ((amount1 * totalSupply) / pairReserve1)])
7777 [Reissue(fromBase58String(lpToken), liquidity, true), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, liquidity), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))]
7878 }
7979 }
8080
8181
8282
8383 @Callable(i)
8484 func burn () = {
8585 let amountlp = value(i.payments[0].amount)
8686 let assetIdLp = value(i.payments[0].assetId)
8787 let $t035473647 = getPairDetails(toBase58String(assetIdLp))
8888 let pairToken0 = $t035473647._1
8989 let pairToken1 = $t035473647._2
9090 let pairReserve0 = $t035473647._3
9191 let pairReserve1 = $t035473647._4
9292 let lpToken = getPairTokenId(pairToken0, pairToken1)
9393 let totalSupply = getPairTotalSupply(lpToken)
9494 let share = ((amountlp * maxx) / totalSupply)
9595 let amount0 = ((share * pairReserve0) / maxx)
9696 let amount1 = ((share * pairReserve1) / maxx)
9797 [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))]
9898 }
9999
100100
101101
102102 @Callable(i)
103103 func addLiquidityPool (token0,token1) = if (isNewPair(token0, token1))
104104 then if ((token0 != token1))
105105 then if (if (isTokenExists(token0))
106106 then isTokenExists(token1)
107107 else false)
108108 then {
109109 let newToken = Issue(toBase58String(take(i.transactionId, 10)), "", 0, 0, true)
110110 let issueId = toBase58String(calculateAssetId(newToken))
111111 let currentPairIndex = getPairLength()
112112 [newToken, StringEntry(toString(currentPairIndex), issueId), setPairLenght((currentPairIndex + 1)), setPairTokenId(token0, token1, issueId), setPairDetails(issueId, token0, token1, 0, 0)]
113113 }
114114 else throw("Wrong tokens")
115115 else throw("Equal tokens")
116116 else throw("Pair already exists")
117117
118118

github/deemru/w8io/169f3d6 
38.72 ms