tx · B2DDZ8w6q11WQ1tef5ojtMWJHdTZNMYaDdu83GS7t6iZ 3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk: -1.00500000 Waves 2022.07.14 08:31 [2138972] smart account 3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk > SELF 0.00000000 Waves
{ "type": 13, "id": "B2DDZ8w6q11WQ1tef5ojtMWJHdTZNMYaDdu83GS7t6iZ", "fee": 100500000, "feeAssetId": null, "timestamp": 1657776664792, "version": 2, "chainId": 84, "sender": "3N2j6yXv5aLx1DTVGpwUmJHKZb5XwMfWZhk", "senderPublicKey": "8ZzMCsQ15BKiHk944146A5WQ8eSFd8vaff4xaktCKSBK", "proofs": [ "3QdWk4bnPvpwauMLjEtMX5NLQZLs9e1aoH7SGRtJ2R61r3cehcxbeYDk9rZBKdvoWzyv4Fe9DfMovDetAVg5C55z" ], "script": "base64:BgIMCAISABIAEgQKAggIEAAJc2VwYXJhdG9yAgFfAQ1nZXRQYWlyTGVuZ3RoAAkBC3ZhbHVlT3JFbHNlAgkAmggCBQR0aGlzAgpwYWlyTGVuZ3RoAAABDXNldFBhaXJMZW5naHQBCW5ld0xlbmd0aAkBDEludGVnZXJFbnRyeQICCnBhaXJMZW5ndGgFCW5ld0xlbmd0aAEKZ2V0UGFpcktleQIGdG9rZW4wBnRva2VuMQQIdG9rZW4wQlYJALEJAQkA2QQBBQZ0b2tlbjAECHRva2VuMUJWCQCxCQEJANkEAQUGdG9rZW4xAwkAZgIFCHRva2VuMUJWBQh0b2tlbjBCVgkAuQkCCQDMCAIFBnRva2VuMAkAzAgCBQZ0b2tlbjEFA25pbAUJc2VwYXJhdG9yCQC5CQIJAMwIAgUGdG9rZW4xCQDMCAIFBnRva2VuMAUDbmlsBQlzZXBhcmF0b3IBDmdldFBhaXJUb2tlbklkAgZ0b2tlbjAGdG9rZW4xCQERQGV4dHJOYXRpdmUoMTA1MykCBQR0aGlzCQEKZ2V0UGFpcktleQIFBnRva2VuMAUGd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QZ0b2tlbjAFBnRva2VuMQMJAQIhPQIFBnRva2VuMAUGdG9rZW4xAwMJAQ1pc1Rva2VuRXhpc3RzAQUGdG9rZW4wCQENaXNUb2tlbkV4aXN0cwEFBnRva2VuMQcECG5ld1Rva2VuCQDCCAUJANgEAQkAyQECCAUBaQ10cmFuc2FjdGlvbklkAAoCAAAAAAAGBAdpc3N1ZUlkCQDYBAEJALgIAQUIbmV3VG9rZW4EEGN1cnJlbnRQYWlySW5kZXgJAQ1nZXRQYWlyTGVuZ3RoAAkAzAgCBQhuZXdUb2tlbgkAzAgCCQELU3RyaW5nRW50cnkCCQCkAwEFEGN1cnJlbnRQYWlySW5kZXgFB2lzc3VlSWQJAMwIAgkBDXNldFBhaXJMZW5naHQBCQBkAgUQY3VycmVudFBhaXJJbmRleAABCQDMCAIJAQ5zZXRQYWlyVG9rZW5JZAMFBnRva2VuMAUGdG9rZW4xBQdpc3N1ZUlkCQDMCAIJAQ5zZXRQYWlyRGV0YWlscwUFB2lzc3VlSWQFBnRva2VuMAUGdG9rZW4xAAAAAAUDbmlsCQACAQIMV3JvbmcgdG9rZW5zCQACAQIMRXF1YWwgdG9rZW5zCQACAQITUGFpciBhbHJlYWR5IGV4aXN0cwAkZbmA", "height": 2138972, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Bvw6u6GTGPf6eG5b2vv3CR4nqVRUFBtTj1xeXpTFn4ib Next: GYWtBGQttGYZQtM4hE6jPmscwjcChrrp5SbKeXEytTzY Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "_" | |
5 | 5 | ||
6 | 6 | func getPairLength () = valueOrElse(getInteger(this, "pairLength"), 0) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func setPairLenght (newLength) = IntegerEntry("pairLength", newLength) | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func getPairKey (token0,token1) = { | |
13 | 13 | let token0BV = toInt(fromBase58String(token0)) | |
14 | 14 | let token1BV = toInt(fromBase58String(token1)) | |
15 | 15 | if ((token1BV > token0BV)) | |
16 | 16 | then makeString([token0, token1], separator) | |
17 | 17 | else makeString([token1, token0], separator) | |
18 | 18 | } | |
19 | 19 | ||
20 | 20 | ||
21 | 21 | func getPairTokenId (token0,token1) = getStringValue(this, getPairKey(token0, token1)) | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func setPairTokenId (token0,token1,issueId) = StringEntry(getPairKey(token0, token1), issueId) | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func joinPairStruct (token0,token1,reserve0,reserve1) = makeString([token0, token1, toString(reserve0), toString(reserve1)], separator) | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | func getPairDetails (lpTokenId) = { | |
31 | 31 | let details = split(valueOrElse(getString(this, lpTokenId), "assetId0_assetId1_0_0"), separator) | |
32 | 32 | $Tuple4(details[0], details[1], parseIntValue(details[2]), parseIntValue(details[3])) | |
33 | 33 | } | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func setPairDetails (lpTokenId,token0,token1,reserve0,reserve1) = StringEntry(lpTokenId, joinPairStruct(token0, token1, reserve0, reserve1)) | |
37 | 37 | ||
38 | 38 | ||
39 | 39 | func getPairTotalSupply (lpTokenId) = valueOrElse(getInteger(this, (("totalSupply" + separator) + lpTokenId)), 0) | |
40 | 40 | ||
41 | 41 | ||
42 | 42 | func setPairTotalSupply (lpTokenId,newTotalSupply) = IntegerEntry((("totalSupply" + separator) + lpTokenId), newTotalSupply) | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | func isNewPair (token0,token1) = !(isDefined(getString(getPairKey(token0, token1)))) | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func isTokenExists (tokenId) = true | |
49 | 49 | ||
50 | 50 | ||
51 | 51 | let maxx = 1000000000000 | |
52 | 52 | ||
53 | 53 | let zeroAddr = value(addressFromString("3M4qwDomRabJKLZxuXhwfqLApQkU592nWxF")) | |
54 | 54 | ||
55 | 55 | let MINIMUM_LIQUIDITY = 100000 | |
56 | 56 | ||
57 | 57 | @Callable(i) | |
58 | 58 | func mint () = { | |
59 | 59 | let token0 = toBase58String(value(i.payments[0].assetId)) | |
60 | 60 | let token1 = toBase58String(value(i.payments[1].assetId)) | |
61 | 61 | let lpToken = getPairTokenId(token0, token1) | |
62 | 62 | let amount0 = value(i.payments[0].amount) | |
63 | 63 | let amount1 = value(i.payments[1].amount) | |
64 | 64 | let $t023722454 = getPairDetails(lpToken) | |
65 | 65 | let pairToken0 = $t023722454._1 | |
66 | 66 | let pairToken1 = $t023722454._2 | |
67 | 67 | let pairReserve0 = $t023722454._3 | |
68 | 68 | let pairReserve1 = $t023722454._4 | |
69 | 69 | let totalSupply = getPairTotalSupply(lpToken) | |
70 | 70 | if ((totalSupply == 0)) | |
71 | 71 | then { | |
72 | 72 | let liquidity = (sqrt((amount0 * amount1), 0, 0, DOWN) - MINIMUM_LIQUIDITY) | |
73 | 73 | [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))] | |
74 | 74 | } | |
75 | 75 | else { | |
76 | 76 | let liquidity = min([((amount0 * totalSupply) / pairReserve0), ((amount1 * totalSupply) / pairReserve1)]) | |
77 | 77 | [Reissue(fromBase58String(lpToken), liquidity, true), ScriptTransfer(i.caller, liquidity, fromBase58String(lpToken)), setPairTotalSupply(lpToken, liquidity), setPairDetails(lpToken, token0, token1, (pairReserve0 + amount0), (pairReserve1 + amount1))] | |
78 | 78 | } | |
79 | 79 | } | |
80 | 80 | ||
81 | 81 | ||
82 | 82 | ||
83 | 83 | @Callable(i) | |
84 | 84 | func burn () = { | |
85 | 85 | let amountlp = value(i.payments[0].amount) | |
86 | 86 | let assetIdLp = value(i.payments[0].assetId) | |
87 | 87 | let $t035473647 = getPairDetails(toBase58String(assetIdLp)) | |
88 | 88 | let pairToken0 = $t035473647._1 | |
89 | 89 | let pairToken1 = $t035473647._2 | |
90 | 90 | let pairReserve0 = $t035473647._3 | |
91 | 91 | let pairReserve1 = $t035473647._4 | |
92 | 92 | let lpToken = getPairTokenId(pairToken0, pairToken1) | |
93 | 93 | let totalSupply = getPairTotalSupply(lpToken) | |
94 | 94 | let share = ((amountlp * maxx) / totalSupply) | |
95 | 95 | let amount0 = ((share * pairReserve0) / maxx) | |
96 | 96 | let amount1 = ((share * pairReserve1) / maxx) | |
97 | 97 | [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))] | |
98 | 98 | } | |
99 | 99 | ||
100 | 100 | ||
101 | 101 | ||
102 | 102 | @Callable(i) | |
103 | 103 | func addLiquidityPool (token0,token1) = if (isNewPair(token0, token1)) | |
104 | 104 | then if ((token0 != token1)) | |
105 | 105 | then if (if (isTokenExists(token0)) | |
106 | 106 | then isTokenExists(token1) | |
107 | 107 | else false) | |
108 | 108 | then { | |
109 | 109 | let newToken = Issue(toBase58String(take(i.transactionId, 10)), "", 0, 0, true) | |
110 | 110 | let issueId = toBase58String(calculateAssetId(newToken)) | |
111 | 111 | let currentPairIndex = getPairLength() | |
112 | 112 | [newToken, StringEntry(toString(currentPairIndex), issueId), setPairLenght((currentPairIndex + 1)), setPairTokenId(token0, token1, issueId), setPairDetails(issueId, token0, token1, 0, 0)] | |
113 | 113 | } | |
114 | 114 | else throw("Wrong tokens") | |
115 | 115 | else throw("Equal tokens") | |
116 | 116 | else throw("Pair already exists") | |
117 | 117 | ||
118 | 118 |
github/deemru/w8io/169f3d6 27.26 ms ◑