tx · 7NXY6k4e2uyrY1u2DJBfpoDuHgpPZArA2R5uTSP7nBTy 3N1ytAUyhtig9X6F2hHHs1jbzYxr47Yp8Fr: -0.00600000 Waves 2024.10.14 09:22 [3326149] smart account 3N1ytAUyhtig9X6F2hHHs1jbzYxr47Yp8Fr > SELF 0.00000000 Waves
{ "type": 13, "id": "7NXY6k4e2uyrY1u2DJBfpoDuHgpPZArA2R5uTSP7nBTy", "fee": 600000, "feeAssetId": null, "timestamp": 1728886997980, "version": 2, "chainId": 84, "sender": "3N1ytAUyhtig9X6F2hHHs1jbzYxr47Yp8Fr", "senderPublicKey": "jXCTQV8PjX2uC9UHBFveupYy9cjhY7stHbzE9cptymw", "proofs": [ "5evdTnTWdNc3fp1Bgc5HFJn2vcfbh1ZdQT8iR6ECqBJ8DsTbH1qSxPKJ6u4h6wVm7VMX3Kx3KmUpFwhL18zC5VQv" ], "script": "base64:BwIZCAISAwoBCBIECgICGBIECgICGBIECgICGCYACXNlcGFyYXRvcgICX18AC3dhdmVzU3RyaW5nAgVXQVZFUwAQY29udHJhY3RGaWxlbmFtZQIXbWVtZV9pbV9jYWxjdWxhdG9yLnJpZGUABW11bHQ4AIDC1y8BB3dyYXBFcnIBAXMJAKwCAgkArAICBRBjb250cmFjdEZpbGVuYW1lAgI6IAUBcwEIdGhyb3dFcnIBAXMJAAIBCQEHd3JhcEVycgEFAXMBD3ZhbGlkYXRlQWRkcmVzcwEHYWRkcmVzcwkBCWlzRGVmaW5lZAEJAKYIAQUHYWRkcmVzcwAMU1RBVFVTX0VNUFRZAAAADFNUQVRVU19SRUFEWQABAAlrU2h1dGRvd24CDnNodXRkb3duX19mbGFnAAtrUHJpY2VBc3NldAIMcHJpY2VfX2Fzc2V0AA5rTGlzdGluZ1ZvbHVtZQIPbGlzdGluZ19fdm9sdW1lAAxrQ3JlYXRpb25GZWUCEnNldHVwX19jcmVhdGlvbkZlZQAMa0N1cnZlVGFyZ2V0AhJzZXR1cF9fY3VydmVUYXJnZXQAE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QEVa1Bvb2xJbmRleEZyb21BZGRyZXNzAQULcG9vbEFkZHJlc3MECW5ld1N0YXR1cwkBDXBhcnNlSW50VmFsdWUBCQCRAwIFBGFyZ3MAAAQOZmFjdG9yeUFjdGlvbnMJAMwIAgkA/AcEBQ5mYWN0b3J5QWRkcmVzcwIMaW50ZWdlckVudHJ5CQDMCAIJAQtrUG9vbFN0YXR1cwEFCXBvb2xJbmRleAkAzAgCBQluZXdTdGF0dXMFA25pbAUDbmlsBQNuaWwJAJQKAgUDbmlsBQ5mYWN0b3J5QWN0aW9ucwkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgC7QfUo", "height": 3326149, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7HhGoX2KGrwQJWc9LaBuDMmvHpLNsCrLd6o8dnoh7w5s Next: ErZh2Cy8xigxkf5jGfEeqexNvWmNJNJKxdWptzDCJWfy Diff:
Old | New | Differences | |
---|---|---|---|
27 | 27 | let kPriceAsset = "price__asset" | |
28 | 28 | ||
29 | 29 | let kListingVolume = "listing__volume" | |
30 | + | ||
31 | + | let kCreationFee = "setup__creationFee" | |
32 | + | ||
33 | + | let kCurveTarget = "setup__curveTarget" | |
34 | + | ||
35 | + | let kVirtualLiquidity = "setup__virtualLiquidity" | |
30 | 36 | ||
31 | 37 | let kPoolContractHash = "pool__contract__hash" | |
32 | 38 | ||
67 | 73 | ||
68 | 74 | let listingVolume = valueOrElse(getInteger(factoryAddress, kListingVolume), 0) | |
69 | 75 | ||
76 | + | let creationFee = valueOrElse(getInteger(factoryAddress, kCreationFee), 0) | |
77 | + | ||
78 | + | let poolContractHash = value(getBinary(factoryAddress, kPoolContractHash)) | |
79 | + | ||
70 | 80 | func parseAssetId (input) = if ((input == wavesString)) | |
71 | 81 | then unit | |
72 | 82 | else fromBase58String(input) | |
88 | 98 | func mustFactory (caller) = mustAddress(caller, factoryAddress) | |
89 | 99 | ||
90 | 100 | ||
91 | - | func poolContractHash () = valueOrErrorMessage(getBinary(factoryAddress, kPoolContractHash), wrapErr("pool contract script hash is not set")) | |
101 | + | func checkContractHash (address) = match poolContractHash { | |
102 | + | case h: ByteVector => | |
103 | + | (scriptHash(address) == h) | |
104 | + | case _ => | |
105 | + | true | |
106 | + | } | |
92 | 107 | ||
93 | 108 | ||
94 | 109 | func isPoolExists (poolAddress) = isDefined(getInteger(factoryAddress, kPoolIndexFromAddress(poolAddress))) | |
110 | 125 | let newPoolIndex = (lastEmptyIndex + 1) | |
111 | 126 | let checks = [if (!(shutdown)) | |
112 | 127 | then true | |
113 | - | else throwErr("not allowed (shutdown)"), if (!(isPoolExists(newPoolAddress))) | |
128 | + | else throwErr("not allowed (shutdown)"), if (checkContractHash(newPoolAddress)) | |
129 | + | then true | |
130 | + | else throwErr("pool script hash is not allowed"), if (!(isPoolExists(newPoolAddress))) | |
114 | 131 | then true | |
115 | 132 | else throwErr("pool address is already registered")] | |
116 | 133 | if ((checks == checks)) | |
125 | 142 | ||
126 | 143 | @Callable(i) | |
127 | 144 | func createPool (callerPublicKey,args) = { | |
145 | + | let minPayment = (listingVolume + creationFee) | |
128 | 146 | let checks = [if (!(shutdown)) | |
129 | 147 | then true | |
130 | 148 | else throwErr("not allowed (shutdown)"), mustFactory(i.caller), if (((lastEmptyIndex - firstEmptyIndex) > 0)) | |
131 | 149 | then true | |
132 | 150 | else throwErr("no empty pools available"), if ((i.payments[0].assetId == unit)) | |
133 | 151 | then true | |
134 | - | else throwErr("payment should be in WAVES"), if ((i.payments[0].amount > | |
152 | + | else throwErr("payment should be in WAVES"), if ((i.payments[0].amount >= minPayment)) | |
135 | 153 | then true | |
136 | - | else throwErr("payment amount should be greater than | |
154 | + | else throwErr(("payment amount should be greater than " + toString(minPayment))), if (isDefined(args[0])) | |
137 | 155 | then true | |
138 | 156 | else throwErr("tokenName is not provided"), if (isDefined(args[1])) | |
139 | 157 | then true |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 7 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "__" | |
5 | 5 | ||
6 | 6 | let wavesString = "WAVES" | |
7 | 7 | ||
8 | 8 | let contractFilename = "meme_im_calculator.ride" | |
9 | 9 | ||
10 | 10 | let mult8 = 100000000 | |
11 | 11 | ||
12 | 12 | func wrapErr (s) = ((contractFilename + ": ") + s) | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func throwErr (s) = throw(wrapErr(s)) | |
16 | 16 | ||
17 | 17 | ||
18 | 18 | func validateAddress (address) = isDefined(addressFromString(address)) | |
19 | 19 | ||
20 | 20 | ||
21 | 21 | let STATUS_EMPTY = 0 | |
22 | 22 | ||
23 | 23 | let STATUS_READY = 1 | |
24 | 24 | ||
25 | 25 | let kShutdown = "shutdown__flag" | |
26 | 26 | ||
27 | 27 | let kPriceAsset = "price__asset" | |
28 | 28 | ||
29 | 29 | let kListingVolume = "listing__volume" | |
30 | + | ||
31 | + | let kCreationFee = "setup__creationFee" | |
32 | + | ||
33 | + | let kCurveTarget = "setup__curveTarget" | |
34 | + | ||
35 | + | let kVirtualLiquidity = "setup__virtualLiquidity" | |
30 | 36 | ||
31 | 37 | let kPoolContractHash = "pool__contract__hash" | |
32 | 38 | ||
33 | 39 | let kLastEmptyPoolIndex = "last__empty_pool__index" | |
34 | 40 | ||
35 | 41 | let kFirstEmptyPoolIndex = "first__empty__pool__index" | |
36 | 42 | ||
37 | 43 | func kPoolAddressFromIndex (index) = makeString(["pool", toString(index)], separator) | |
38 | 44 | ||
39 | 45 | ||
40 | 46 | func kPoolIndexFromAddress (address) = makeString(["pool", toString(address)], separator) | |
41 | 47 | ||
42 | 48 | ||
43 | 49 | func kPoolAsset (address) = makeString(["asset", toString(address)], separator) | |
44 | 50 | ||
45 | 51 | ||
46 | 52 | func kPoolStatus (index) = makeString(["pool", "status", toString(index)], separator) | |
47 | 53 | ||
48 | 54 | ||
49 | 55 | let kFactoryAddress = "factory__address" | |
50 | 56 | ||
51 | 57 | let factoryAddressOption = match getString(this, kFactoryAddress) { | |
52 | 58 | case s: String => | |
53 | 59 | addressFromString(s) | |
54 | 60 | case _: Unit => | |
55 | 61 | unit | |
56 | 62 | case _ => | |
57 | 63 | throw("Match error") | |
58 | 64 | } | |
59 | 65 | ||
60 | 66 | let factoryAddress = valueOrErrorMessage(factoryAddressOption, wrapErr("invalid factory address")) | |
61 | 67 | ||
62 | 68 | let shutdown = valueOrElse(getBoolean(factoryAddress, kShutdown), false) | |
63 | 69 | ||
64 | 70 | let lastEmptyIndex = valueOrElse(getInteger(factoryAddress, kLastEmptyPoolIndex), 0) | |
65 | 71 | ||
66 | 72 | let firstEmptyIndex = valueOrElse(getInteger(factoryAddress, kFirstEmptyPoolIndex), 0) | |
67 | 73 | ||
68 | 74 | let listingVolume = valueOrElse(getInteger(factoryAddress, kListingVolume), 0) | |
69 | 75 | ||
76 | + | let creationFee = valueOrElse(getInteger(factoryAddress, kCreationFee), 0) | |
77 | + | ||
78 | + | let poolContractHash = value(getBinary(factoryAddress, kPoolContractHash)) | |
79 | + | ||
70 | 80 | func parseAssetId (input) = if ((input == wavesString)) | |
71 | 81 | then unit | |
72 | 82 | else fromBase58String(input) | |
73 | 83 | ||
74 | 84 | ||
75 | 85 | func assetIdToString (input) = if ((input == unit)) | |
76 | 86 | then wavesString | |
77 | 87 | else toBase58String(value(input)) | |
78 | 88 | ||
79 | 89 | ||
80 | 90 | func mustAddress (caller,address) = if ((caller == address)) | |
81 | 91 | then true | |
82 | 92 | else throwErr("permission denied") | |
83 | 93 | ||
84 | 94 | ||
85 | 95 | func mustThis (caller) = mustAddress(caller, this) | |
86 | 96 | ||
87 | 97 | ||
88 | 98 | func mustFactory (caller) = mustAddress(caller, factoryAddress) | |
89 | 99 | ||
90 | 100 | ||
91 | - | func poolContractHash () = valueOrErrorMessage(getBinary(factoryAddress, kPoolContractHash), wrapErr("pool contract script hash is not set")) | |
101 | + | func checkContractHash (address) = match poolContractHash { | |
102 | + | case h: ByteVector => | |
103 | + | (scriptHash(address) == h) | |
104 | + | case _ => | |
105 | + | true | |
106 | + | } | |
92 | 107 | ||
93 | 108 | ||
94 | 109 | func isPoolExists (poolAddress) = isDefined(getInteger(factoryAddress, kPoolIndexFromAddress(poolAddress))) | |
95 | 110 | ||
96 | 111 | ||
97 | 112 | @Callable(i) | |
98 | 113 | func init (factoryAddressStr) = { | |
99 | 114 | let checkCaller = mustThis(i.caller) | |
100 | 115 | if ((checkCaller == checkCaller)) | |
101 | 116 | then [StringEntry(kFactoryAddress, factoryAddressStr)] | |
102 | 117 | else throw("Strict value is not equal to itself.") | |
103 | 118 | } | |
104 | 119 | ||
105 | 120 | ||
106 | 121 | ||
107 | 122 | @Callable(i) | |
108 | 123 | func addEmptyPool (callerPublicKey,args) = { | |
109 | 124 | let newPoolAddress = addressFromPublicKey(callerPublicKey) | |
110 | 125 | let newPoolIndex = (lastEmptyIndex + 1) | |
111 | 126 | let checks = [if (!(shutdown)) | |
112 | 127 | then true | |
113 | - | else throwErr("not allowed (shutdown)"), if (!(isPoolExists(newPoolAddress))) | |
128 | + | else throwErr("not allowed (shutdown)"), if (checkContractHash(newPoolAddress)) | |
129 | + | then true | |
130 | + | else throwErr("pool script hash is not allowed"), if (!(isPoolExists(newPoolAddress))) | |
114 | 131 | then true | |
115 | 132 | else throwErr("pool address is already registered")] | |
116 | 133 | if ((checks == checks)) | |
117 | 134 | then { | |
118 | 135 | let factoryActions = [invoke(factoryAddress, "integerEntry", [kLastEmptyPoolIndex, newPoolIndex], nil), invoke(factoryAddress, "stringEntry", [kPoolAddressFromIndex(newPoolIndex), toString(newPoolAddress)], nil), invoke(factoryAddress, "integerEntry", [kPoolIndexFromAddress(newPoolAddress), newPoolIndex], nil), invoke(factoryAddress, "integerEntry", [kPoolStatus(newPoolIndex), STATUS_EMPTY], nil)] | |
119 | 136 | $Tuple2(nil, factoryActions) | |
120 | 137 | } | |
121 | 138 | else throw("Strict value is not equal to itself.") | |
122 | 139 | } | |
123 | 140 | ||
124 | 141 | ||
125 | 142 | ||
126 | 143 | @Callable(i) | |
127 | 144 | func createPool (callerPublicKey,args) = { | |
145 | + | let minPayment = (listingVolume + creationFee) | |
128 | 146 | let checks = [if (!(shutdown)) | |
129 | 147 | then true | |
130 | 148 | else throwErr("not allowed (shutdown)"), mustFactory(i.caller), if (((lastEmptyIndex - firstEmptyIndex) > 0)) | |
131 | 149 | then true | |
132 | 150 | else throwErr("no empty pools available"), if ((i.payments[0].assetId == unit)) | |
133 | 151 | then true | |
134 | - | else throwErr("payment should be in WAVES"), if ((i.payments[0].amount > | |
152 | + | else throwErr("payment should be in WAVES"), if ((i.payments[0].amount >= minPayment)) | |
135 | 153 | then true | |
136 | - | else throwErr("payment amount should be greater than | |
154 | + | else throwErr(("payment amount should be greater than " + toString(minPayment))), if (isDefined(args[0])) | |
137 | 155 | then true | |
138 | 156 | else throwErr("tokenName is not provided"), if (isDefined(args[1])) | |
139 | 157 | then true | |
140 | 158 | else throwErr("tokenDescription is not provided"), if (isDefined(args[2])) | |
141 | 159 | then true | |
142 | 160 | else throwErr("tokenQuantity is not provided")] | |
143 | 161 | if ((checks == checks)) | |
144 | 162 | then { | |
145 | 163 | let poolIndex = (firstEmptyIndex + 1) | |
146 | 164 | let poolAddressString = getStringValue(factoryAddress, kPoolAddressFromIndex(poolIndex)) | |
147 | 165 | let poolAddress = addressFromStringValue(poolAddressString) | |
148 | 166 | let callerAddress = addressFromPublicKey(callerPublicKey) | |
149 | 167 | let poolDomain = take(poolAddressString, 8) | |
150 | 168 | let poolOwner = toString(callerAddress) | |
151 | 169 | let tokenName = args[0] | |
152 | 170 | let tokenDesc = args[1] | |
153 | 171 | let tokenQuantity = args[2] | |
154 | 172 | let initPoolInvoke = invoke(factoryAddress, "initPoolInvoke", [poolAddressString, [poolDomain, poolOwner, tokenName, tokenDesc, tokenQuantity]], [AttachedPayment(i.payments[0].assetId, i.payments[0].amount)]) | |
155 | 173 | if ((initPoolInvoke == initPoolInvoke)) | |
156 | 174 | then { | |
157 | 175 | let factoryActions = [invoke(factoryAddress, "integerEntry", [kFirstEmptyPoolIndex, poolIndex], nil), invoke(factoryAddress, "integerEntry", [kPoolStatus(poolIndex), STATUS_READY], nil)] | |
158 | 176 | $Tuple2(nil, factoryActions) | |
159 | 177 | } | |
160 | 178 | else throw("Strict value is not equal to itself.") | |
161 | 179 | } | |
162 | 180 | else throw("Strict value is not equal to itself.") | |
163 | 181 | } | |
164 | 182 | ||
165 | 183 | ||
166 | 184 | ||
167 | 185 | @Callable(i) | |
168 | 186 | func notifyStatusUpdate (callerPublicKey,args) = { | |
169 | 187 | let poolAddress = addressFromPublicKey(callerPublicKey) | |
170 | 188 | let checks = [if (isPoolExists(poolAddress)) | |
171 | 189 | then true | |
172 | 190 | else throwErr("pool not found")] | |
173 | 191 | if ((checks == checks)) | |
174 | 192 | then { | |
175 | 193 | let poolIndex = getIntegerValue(factoryAddress, kPoolIndexFromAddress(poolAddress)) | |
176 | 194 | let newStatus = parseIntValue(args[0]) | |
177 | 195 | let factoryActions = [invoke(factoryAddress, "integerEntry", [kPoolStatus(poolIndex), newStatus], nil)] | |
178 | 196 | $Tuple2(nil, factoryActions) | |
179 | 197 | } | |
180 | 198 | else throw("Strict value is not equal to itself.") | |
181 | 199 | } | |
182 | 200 | ||
183 | 201 |
github/deemru/w8io/169f3d6 47.26 ms ◑