1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let SCALE8 = 8 |
---|
5 | 5 | | |
---|
6 | 6 | | let MULT8 = 100000000 |
---|
7 | 7 | | |
---|
8 | 8 | | let SCALE18 = 18 |
---|
9 | 9 | | |
---|
10 | 10 | | let MULT18 = toBigInt(1000000000000000000) |
---|
11 | 11 | | |
---|
12 | 12 | | let POOLWEIGHTMULT = MULT8 |
---|
13 | 13 | | |
---|
14 | 14 | | let GWXvirtualPOOL = "GWXvirtualPOOL" |
---|
15 | 15 | | |
---|
16 | 16 | | let labelPoolsLp = "POOLS_LP" |
---|
17 | 17 | | |
---|
18 | 18 | | let defaultSpread = 2000000 |
---|
19 | 19 | | |
---|
20 | 20 | | let wavesString = "WAVES" |
---|
21 | 21 | | |
---|
22 | 22 | | let decimalsMultPrice = ((100 * 1000) * 1000) |
---|
23 | 23 | | |
---|
24 | 24 | | let SEP = "__" |
---|
25 | 25 | | |
---|
26 | 26 | | let EMPTY = "" |
---|
27 | 27 | | |
---|
28 | 28 | | let PoolActive = 1 |
---|
29 | 29 | | |
---|
30 | 30 | | let PoolPutDisabled = 2 |
---|
31 | 31 | | |
---|
32 | 32 | | let PoolMatcherDisabled = 3 |
---|
33 | 33 | | |
---|
34 | 34 | | let PoolShutdown = 4 |
---|
35 | 35 | | |
---|
36 | 36 | | let idxInternalAssetId = 1 |
---|
37 | 37 | | |
---|
38 | 38 | | let idxResutActions = 2 |
---|
39 | 39 | | |
---|
40 | 40 | | let idxIfAssetIdCalculationPerformed = 3 |
---|
41 | 41 | | |
---|
42 | 42 | | let idxPoolAddress = 1 |
---|
43 | 43 | | |
---|
44 | 44 | | let idxPoolStatus = 2 |
---|
45 | 45 | | |
---|
46 | 46 | | let idxPoolLPAssetId = 3 |
---|
47 | 47 | | |
---|
48 | 48 | | let idxAmtAssetId = 4 |
---|
49 | 49 | | |
---|
50 | 50 | | let idxPriceAssetId = 5 |
---|
51 | 51 | | |
---|
52 | 52 | | let idxAmtAssetDcm = 6 |
---|
53 | 53 | | |
---|
54 | 54 | | let idxPriceAssetDcm = 7 |
---|
55 | 55 | | |
---|
56 | 56 | | let idxIAmtAssetId = 8 |
---|
57 | 57 | | |
---|
58 | 58 | | let idxIPriceAssetId = 9 |
---|
59 | 59 | | |
---|
60 | 60 | | let idxLPAssetDcm = 10 |
---|
61 | 61 | | |
---|
62 | 62 | | let idxPoolType = 11 |
---|
63 | 63 | | |
---|
64 | 64 | | let poolLabelWxEmission = "WX_EMISSION" |
---|
65 | 65 | | |
---|
66 | 66 | | let validPoolLabels = [poolLabelWxEmission] |
---|
67 | 67 | | |
---|
68 | 68 | | func keyAllowedLpScriptHash () = "%s__allowedLpScriptHash" |
---|
69 | 69 | | |
---|
70 | 70 | | |
---|
71 | 71 | | func keyAllowedLpStableScriptHash () = "%s__allowedLpStableScriptHash" |
---|
72 | 72 | | |
---|
73 | 73 | | |
---|
74 | 74 | | func keyAllowedLpStableAddonScriptHash () = "%s__allowedLpStableAddonScriptHash" |
---|
75 | 75 | | |
---|
76 | 76 | | |
---|
77 | 77 | | func swapContract () = "%s__swapContract" |
---|
78 | 78 | | |
---|
79 | 79 | | |
---|
80 | 80 | | func keyFactoryConfig () = "%s__factoryConfig" |
---|
81 | 81 | | |
---|
82 | 82 | | |
---|
83 | 83 | | func keyLpTokensList () = "%s__lpTokensList" |
---|
84 | 84 | | |
---|
85 | 85 | | |
---|
86 | 86 | | func keyPoolScriptHash () = "%s%s__pool__scriptHash" |
---|
87 | 87 | | |
---|
88 | 88 | | |
---|
89 | 89 | | func keyMatcherPub () = "%s%s__matcher__publicKey" |
---|
90 | 90 | | |
---|
91 | 91 | | |
---|
92 | 92 | | func keyLegacyFactoryContract () = "%s__legacyFactoryContract" |
---|
93 | 93 | | |
---|
94 | 94 | | |
---|
95 | 95 | | func keyLegacyPools () = "%s__legacyPools" |
---|
96 | 96 | | |
---|
97 | 97 | | |
---|
98 | 98 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
99 | 99 | | |
---|
100 | 100 | | |
---|
101 | 101 | | func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey" |
---|
102 | 102 | | |
---|
103 | 103 | | |
---|
104 | 104 | | func keyAdminPubKeys () = "%s__adminPubKeys" |
---|
105 | 105 | | |
---|
106 | 106 | | |
---|
107 | 107 | | func keyAssetsStoreContract () = "%s__assetsStoreContract" |
---|
108 | 108 | | |
---|
109 | 109 | | |
---|
110 | 110 | | func keyVotingEmissionContract () = "%s__votingEmissionContract" |
---|
111 | 111 | | |
---|
112 | 112 | | |
---|
113 | 113 | | func keyPriceAssets () = makeString(["%s", "priceAssets"], SEP) |
---|
114 | 114 | | |
---|
115 | 115 | | |
---|
116 | 116 | | func keyPriceDecimals () = "%s__priceDecimals" |
---|
117 | 117 | | |
---|
118 | 118 | | |
---|
119 | 119 | | func keyAllPoolsShutdown () = "%s__shutdown" |
---|
120 | 120 | | |
---|
121 | 121 | | |
---|
122 | 122 | | func keyNextInternalAssetId () = "%s__nextInternalAssetId" |
---|
123 | 123 | | |
---|
124 | 124 | | |
---|
125 | 125 | | func keyPoolToWeight (poolAddress) = ("%s%s__poolWeight__" + poolAddress) |
---|
126 | 126 | | |
---|
127 | 127 | | |
---|
128 | 128 | | func keyPoolToWeightHistory (poolAddress,num) = ((("%s%s__poolWeight__" + poolAddress) + "__") + toString(num)) |
---|
129 | 129 | | |
---|
130 | 130 | | |
---|
131 | 131 | | func keyMappingsInternal2baseAssetId (internalBaseAsset) = ("%s%s%d__mappings__internal2baseAssetId__" + toString(internalBaseAsset)) |
---|
132 | 132 | | |
---|
133 | 133 | | |
---|
134 | 134 | | func keyMappingsBaseAsset2internalId (baseAssetStr) = ("%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr) |
---|
135 | 135 | | |
---|
136 | 136 | | |
---|
137 | 137 | | func keyPoolConfig (amountAssetInternal,priceAssetInternal) = (((("%d%d%s__" + amountAssetInternal) + "__") + priceAssetInternal) + "__config") |
---|
138 | 138 | | |
---|
139 | 139 | | |
---|
140 | 140 | | func keyPoolOneTokenOperationsDisabled (assetsInternal) = { |
---|
141 | 141 | | let $t037263788 = assetsInternal |
---|
142 | 142 | | let amountAssetInternal = $t037263788._1 |
---|
143 | 143 | | let priceAssetInternal = $t037263788._2 |
---|
144 | 144 | | makeString(["%d%d%s", toString(amountAssetInternal), toString(priceAssetInternal), "oneTokenOperationsDisabled"], SEP) |
---|
145 | 145 | | } |
---|
146 | 146 | | |
---|
147 | 147 | | |
---|
148 | 148 | | func keyAllPoolsOneTokenOperationsDisabled () = makeString(["%s", "oneTokenOperationsDisabled"], SEP) |
---|
149 | 149 | | |
---|
150 | 150 | | |
---|
151 | 151 | | func keyMappingLpAssetToPoolAssets (lpAssetStr) = (("%s%s%s__" + lpAssetStr) + "__mappings__lpAsset2Pool") |
---|
152 | 152 | | |
---|
153 | 153 | | |
---|
154 | 154 | | func keyMappingPoolAssetsToLpasset (internalAmountAssetIdStr,internalPriceAssetIdStr) = (((("%d%d%s%s__" + internalAmountAssetIdStr) + "__") + internalPriceAssetIdStr) + "__mappings__PoolAssets2LpAsset") |
---|
155 | 155 | | |
---|
156 | 156 | | |
---|
157 | 157 | | func keyPoolSpread (poolAddress) = ("%s%s__spread__" + poolAddress) |
---|
158 | 158 | | |
---|
159 | 159 | | |
---|
160 | 160 | | func keyMappingPoolContractAddressToPoolAssets (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2PoolAssets") |
---|
161 | 161 | | |
---|
162 | 162 | | |
---|
163 | 163 | | func keyMappingPoolAssetsToPoolContractAddress (internalAmountAssetIdStr,internalPriceAssetIdStr) = (((("%d%d%s%s__" + toString(internalAmountAssetIdStr)) + "__") + toString(internalPriceAssetIdStr)) + "__mappings__poolAssets2PoolContract") |
---|
164 | 164 | | |
---|
165 | 165 | | |
---|
166 | 166 | | func keyMappingPoolContractToLPAsset (poolContractAddress) = (("%s%s%s__" + poolContractAddress) + "__mappings__poolContract2LpAsset") |
---|
167 | 167 | | |
---|
168 | 168 | | |
---|
169 | 169 | | func keyMappingPoolLPAssetToPoolContractAddress (lpAssetStr) = (("%s%s%s__" + lpAssetStr) + "__mappings__lpAsset2PoolContract") |
---|
170 | 170 | | |
---|
171 | 171 | | |
---|
172 | 172 | | func keyWxEmission (amountAssetId,priceAssetId) = ((("%s%s%s__wxEmission__" + amountAssetId) + "__") + priceAssetId) |
---|
173 | 173 | | |
---|
174 | 174 | | |
---|
175 | 175 | | func keyInFee (poolAddress) = ("%s%s__inFee__" + poolAddress) |
---|
176 | 176 | | |
---|
177 | 177 | | |
---|
178 | 178 | | func keyInFeeDefault () = "%s__inFeeDefault" |
---|
179 | 179 | | |
---|
180 | 180 | | |
---|
181 | 181 | | func keyOutFee (poolAddress) = ("%s%s__outFee__" + poolAddress) |
---|
182 | 182 | | |
---|
183 | 183 | | |
---|
184 | 184 | | func keyOutFeeDefault () = "%s__outFeeDefault" |
---|
185 | 185 | | |
---|
186 | 186 | | |
---|
187 | 187 | | func keySkipOrderValidation (poolAddress) = ("%s%s__skipOrderValidation__" + poolAddress) |
---|
188 | 188 | | |
---|
189 | 189 | | |
---|
190 | 190 | | func keyChangeAmpDelay (poolAddress) = ("%s%s__changeAmpDelay__" + poolAddress) |
---|
191 | 191 | | |
---|
192 | 192 | | |
---|
193 | 193 | | func keyChangeAmpDelta (poolAddress) = ("%s%s__changeAmpDelta__" + poolAddress) |
---|
194 | 194 | | |
---|
195 | 195 | | |
---|
196 | 196 | | func keyChangeAmpTarget (poolAddress) = ("%s%s__changeAmpTarget__" + poolAddress) |
---|
197 | 197 | | |
---|
198 | 198 | | |
---|
199 | 199 | | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key)) |
---|
200 | 200 | | |
---|
201 | 201 | | |
---|
202 | 202 | | func getBooleanOrFail (key) = valueOrErrorMessage(getBoolean(this, key), ("No data for this.key=" + key)) |
---|
203 | 203 | | |
---|
204 | 204 | | |
---|
205 | 205 | | func getIntOrFail (key) = valueOrErrorMessage(getInteger(this, key), ("No data for this.key=" + key)) |
---|
206 | 206 | | |
---|
207 | 207 | | |
---|
208 | 208 | | func parseAssetId (input) = if ((input == wavesString)) |
---|
209 | 209 | | then unit |
---|
210 | 210 | | else fromBase58String(input) |
---|
211 | 211 | | |
---|
212 | 212 | | |
---|
213 | 213 | | let IdxFactoryCfgStakingDapp = 1 |
---|
214 | 214 | | |
---|
215 | 215 | | let IdxFactoryCfgBoostingDapp = 2 |
---|
216 | 216 | | |
---|
217 | 217 | | let IdxFactoryCfgIdoDapp = 3 |
---|
218 | 218 | | |
---|
219 | 219 | | let IdxFactoryCfgTeamDapp = 4 |
---|
220 | 220 | | |
---|
221 | 221 | | let IdxFactoryCfgEmissionDapp = 5 |
---|
222 | 222 | | |
---|
223 | 223 | | let IdxFactoryCfgRestDapp = 6 |
---|
224 | 224 | | |
---|
225 | 225 | | let IdxFactoryCfgSlippageDapp = 7 |
---|
226 | 226 | | |
---|
227 | 227 | | let IdxFactoryCfgDaoDapp = 8 |
---|
228 | 228 | | |
---|
229 | 229 | | let IdxFactoryCfgMarketingDapp = 9 |
---|
230 | 230 | | |
---|
231 | 231 | | let IdxFactoryCfgGwxRewardDapp = 10 |
---|
232 | 232 | | |
---|
233 | 233 | | let IdxFactoryCfgBirdsDapp = 11 |
---|
234 | 234 | | |
---|
235 | 235 | | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) |
---|
236 | 236 | | |
---|
237 | 237 | | |
---|
238 | 238 | | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) |
---|
239 | 239 | | |
---|
240 | 240 | | |
---|
241 | 241 | | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) |
---|
242 | 242 | | |
---|
243 | 243 | | |
---|
244 | 244 | | func getGwxRewardAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgGwxRewardDapp]) |
---|
245 | 245 | | |
---|
246 | 246 | | |
---|
247 | 247 | | func getPriceAssets () = match getString(keyPriceAssets()) { |
---|
248 | 248 | | case s: String => |
---|
249 | 249 | | if ((size(s) == 0)) |
---|
250 | 250 | | then nil |
---|
251 | 251 | | else split(s, SEP) |
---|
252 | 252 | | case _ => |
---|
253 | 253 | | nil |
---|
254 | 254 | | } |
---|
255 | 255 | | |
---|
256 | 256 | | |
---|
257 | 257 | | func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) { |
---|
258 | 258 | | case s: String => |
---|
259 | 259 | | fromBase58String(s) |
---|
260 | 260 | | case _: Unit => |
---|
261 | 261 | | unit |
---|
262 | 262 | | case _ => |
---|
263 | 263 | | throw("Match error") |
---|
264 | 264 | | } |
---|
265 | 265 | | |
---|
266 | 266 | | |
---|
267 | 267 | | func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) { |
---|
268 | 268 | | case s: String => |
---|
269 | 269 | | fromBase58String(s) |
---|
270 | 270 | | case _: Unit => |
---|
271 | 271 | | unit |
---|
272 | 272 | | case _ => |
---|
273 | 273 | | throw("Match error") |
---|
274 | 274 | | } |
---|
275 | 275 | | |
---|
276 | 276 | | |
---|
277 | 277 | | let permissionDeniedError = throw("Permission denied") |
---|
278 | 278 | | |
---|
279 | 279 | | let testError = throw("Test error here") |
---|
280 | 280 | | |
---|
281 | 281 | | func mustThis (i) = if ((i.caller == this)) |
---|
282 | 282 | | then true |
---|
283 | 283 | | else permissionDeniedError |
---|
284 | 284 | | |
---|
285 | 285 | | |
---|
286 | 286 | | func mustManager (i) = match managerPublicKeyOrUnit() { |
---|
287 | 287 | | case pk: ByteVector => |
---|
288 | 288 | | if ((i.callerPublicKey == pk)) |
---|
289 | 289 | | then true |
---|
290 | 290 | | else permissionDeniedError |
---|
291 | 291 | | case _: Unit => |
---|
292 | 292 | | mustThis(i) |
---|
293 | 293 | | case _ => |
---|
294 | 294 | | throw("Match error") |
---|
295 | 295 | | } |
---|
296 | 296 | | |
---|
297 | 297 | | |
---|
298 | 298 | | func dataFactoryCfgV3 (stakingAddress,boostingAddress,idoContract,teamContract,emissionContract,restContract,slippageContract,daoContract,marketingContract,gwxRewardsContract,birdsContract) = makeString(["%s%s%s%s%s%s%s%s%s%s%s", stakingAddress, boostingAddress, idoContract, teamContract, emissionContract, restContract, slippageContract, daoContract, marketingContract, gwxRewardsContract, birdsContract], SEP) |
---|
299 | 299 | | |
---|
300 | 300 | | |
---|
301 | 301 | | func dataFactoryCfg (stakingAddress,boostingAddress,idoContract,teamContract,emissionContract,restContract,slippageContract) = makeString(["%s%s%s%s%s%s", stakingAddress, boostingAddress, idoContract, teamContract, emissionContract, restContract, slippageContract], SEP) |
---|
302 | 302 | | |
---|
303 | 303 | | |
---|
304 | 304 | | func dataPoolCfg (poolAddress,poolStatus,lpAssetId,amountAssetStr,priceAssetStr,amountAssetDecimals,priceAssetDecimals,amountAssetInternalId,priceAssetInternalId,lpAssetDecimals,poolType) = makeString(["%s%d%s%s%s%d%d%d%d%d%s", poolAddress, poolStatus, lpAssetId, amountAssetStr, priceAssetStr, toString(amountAssetDecimals), toString(priceAssetDecimals), toString(amountAssetInternalId), toString(priceAssetInternalId), toString(lpAssetDecimals), poolType], SEP) |
---|
305 | 305 | | |
---|
306 | 306 | | |
---|
307 | 307 | | func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP) |
---|
308 | 308 | | |
---|
309 | 309 | | |
---|
310 | 310 | | func getPoolConfig (poolAddress) = { |
---|
311 | 311 | | let poolAssets = split(getStringOrFail(keyMappingPoolContractAddressToPoolAssets(poolAddress)), SEP) |
---|
312 | 312 | | let amountAssetInternal = poolAssets[1] |
---|
313 | 313 | | let priceAssetInternal = poolAssets[2] |
---|
314 | 314 | | split(getStringOrFail(keyPoolConfig(amountAssetInternal, priceAssetInternal)), SEP) |
---|
315 | 315 | | } |
---|
316 | 316 | | |
---|
317 | 317 | | |
---|
318 | 318 | | func getInternalAssetIdOrCreate (assetIdStr,incrementor) = { |
---|
319 | 319 | | let internalAssetId = valueOrElse(getInteger(this, keyMappingsBaseAsset2internalId(assetIdStr)), 0) |
---|
320 | 320 | | let currentIndexOfInternalId = valueOrElse(getInteger(this, keyNextInternalAssetId()), 0) |
---|
321 | 321 | | let result = if ((internalAssetId == 0)) |
---|
322 | 322 | | then { |
---|
323 | 323 | | let newInternalAssetId = (currentIndexOfInternalId + incrementor) |
---|
324 | 324 | | $Tuple3(newInternalAssetId, [IntegerEntry(keyNextInternalAssetId(), newInternalAssetId), IntegerEntry(keyMappingsBaseAsset2internalId(assetIdStr), newInternalAssetId), StringEntry(keyMappingsInternal2baseAssetId(newInternalAssetId), assetIdStr)], true) |
---|
325 | 325 | | } |
---|
326 | 326 | | else $Tuple3(internalAssetId, nil, false) |
---|
327 | 327 | | result |
---|
328 | 328 | | } |
---|
329 | 329 | | |
---|
330 | 330 | | |
---|
331 | 331 | | func mustAdmin (i) = { |
---|
332 | 332 | | let adminPKs = split(valueOrElse(getString(keyAdminPubKeys()), EMPTY), SEP) |
---|
333 | 333 | | if (containsElement(adminPKs, toBase58String(i.callerPublicKey))) |
---|
334 | 334 | | then true |
---|
335 | 335 | | else { |
---|
336 | 336 | | let isManager = mustManager(i) |
---|
337 | 337 | | if ((isManager == isManager)) |
---|
338 | 338 | | then true |
---|
339 | 339 | | else throw("Strict value is not equal to itself.") |
---|
340 | 340 | | } |
---|
341 | 341 | | } |
---|
342 | 342 | | |
---|
343 | 343 | | |
---|
344 | 344 | | func intOrDefaultOrFallback (key,keyDefault,valueFallback) = valueOrElse(getInteger(this, key), valueOrElse(getInteger(this, keyDefault), valueFallback)) |
---|
345 | 345 | | |
---|
346 | 346 | | |
---|
347 | 347 | | func poolExistsInternal (amountAssetId,priceAssetId) = { |
---|
348 | 348 | | let amountAssetInternal = getInteger(keyMappingsBaseAsset2internalId(amountAssetId)) |
---|
349 | 349 | | let priceAssetInternal = getInteger(keyMappingsBaseAsset2internalId(priceAssetId)) |
---|
350 | 350 | | if (if ((amountAssetInternal == unit)) |
---|
351 | 351 | | then true |
---|
352 | 352 | | else (priceAssetInternal == unit)) |
---|
353 | 353 | | then false |
---|
354 | 354 | | else { |
---|
355 | 355 | | let amAs = toString(value(amountAssetInternal)) |
---|
356 | 356 | | let prAs = toString(value(priceAssetInternal)) |
---|
357 | 357 | | let cfg = getString(keyPoolConfig(amAs, prAs)) |
---|
358 | 358 | | let cfgReverse = getString(keyPoolConfig(prAs, amAs)) |
---|
359 | 359 | | let exists = if ((cfg != unit)) |
---|
360 | 360 | | then true |
---|
361 | 361 | | else (cfgReverse != unit) |
---|
362 | 362 | | exists |
---|
363 | 363 | | } |
---|
364 | 364 | | } |
---|
365 | 365 | | |
---|
366 | 366 | | |
---|
367 | 367 | | @Callable(i) |
---|
368 | 368 | | func getSwapContractREADONLY () = $Tuple2(nil, getStringOrFail(swapContract())) |
---|
369 | 369 | | |
---|
370 | 370 | | |
---|
371 | 371 | | |
---|
372 | 372 | | @Callable(i) |
---|
373 | 373 | | func getLpAssetFromPoolAssetsREADONLY (asset1,asset2) = if (if ((asset1 == "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS")) |
---|
374 | 374 | | then (asset2 == "WAVES") |
---|
375 | 375 | | else false) |
---|
376 | 376 | | then $Tuple2(nil, unit) |
---|
377 | 377 | | else { |
---|
378 | 378 | | let assetNum1 = value(getInteger(this, keyMappingsBaseAsset2internalId(asset1))) |
---|
379 | 379 | | let assetNum2 = value(getInteger(this, keyMappingsBaseAsset2internalId(asset2))) |
---|
380 | 380 | | let ee = getString(this, keyMappingPoolAssetsToLpasset(toString(assetNum1), toString(assetNum2))) |
---|
381 | 381 | | let res = if ((ee == unit)) |
---|
382 | 382 | | then unit |
---|
383 | 383 | | else drop(value(ee), 4) |
---|
384 | 384 | | $Tuple2(nil, res) |
---|
385 | 385 | | } |
---|
386 | 386 | | |
---|
387 | 387 | | |
---|
388 | 388 | | |
---|
389 | 389 | | @Callable(i) |
---|
390 | 390 | | func getPoolAddressFromLpAssetREADONLY (lp) = $Tuple2(nil, valueOrElse(getString(this, keyMappingPoolLPAssetToPoolContractAddress(lp)), "")) |
---|
391 | 391 | | |
---|
392 | 392 | | |
---|
393 | 393 | | |
---|
394 | 394 | | @Callable(i) |
---|
395 | 395 | | func constructor (stakingContract,boostingContract,idoContract,teamContract,emissionContract,restContract,slpipageContract,priceDecimals) = { |
---|
396 | 396 | | let checkCaller = mustManager(i) |
---|
397 | 397 | | if ((checkCaller == checkCaller)) |
---|
398 | 398 | | then [StringEntry(keyFactoryConfig(), dataFactoryCfg(stakingContract, boostingContract, idoContract, teamContract, emissionContract, restContract, slpipageContract)), IntegerEntry(keyPriceDecimals(), priceDecimals)] |
---|
399 | 399 | | else throw("Strict value is not equal to itself.") |
---|
400 | 400 | | } |
---|
401 | 401 | | |
---|
402 | 402 | | |
---|
403 | 403 | | |
---|
404 | 404 | | @Callable(i) |
---|
405 | 405 | | func constructorV2 (mathcherPub58Str) = { |
---|
406 | 406 | | let checkCaller = mustManager(i) |
---|
407 | 407 | | if ((checkCaller == checkCaller)) |
---|
408 | 408 | | then { |
---|
409 | 409 | | let mathcerPub = addressFromPublicKey(fromBase58String(mathcherPub58Str)) |
---|
410 | 410 | | if ((mathcerPub == mathcerPub)) |
---|
411 | 411 | | then [StringEntry(keyMatcherPub(), mathcherPub58Str)] |
---|
412 | 412 | | else throw("Strict value is not equal to itself.") |
---|
413 | 413 | | } |
---|
414 | 414 | | else throw("Strict value is not equal to itself.") |
---|
415 | 415 | | } |
---|
416 | 416 | | |
---|
417 | 417 | | |
---|
418 | 418 | | |
---|
419 | 419 | | @Callable(i) |
---|
420 | 420 | | func constructorV3 (daoContract,marketingContract,gwxRewardsContract,birdsContract) = { |
---|
421 | 421 | | let checkCaller = mustManager(i) |
---|
422 | 422 | | if ((checkCaller == checkCaller)) |
---|
423 | 423 | | then { |
---|
424 | 424 | | let factoryCfg = split(getStringOrFail(keyFactoryConfig()), SEP) |
---|
425 | 425 | | [StringEntry(keyFactoryConfig(), dataFactoryCfgV3(factoryCfg[1], factoryCfg[2], factoryCfg[3], factoryCfg[4], factoryCfg[5], factoryCfg[6], factoryCfg[7], daoContract, marketingContract, gwxRewardsContract, birdsContract))] |
---|
426 | 426 | | } |
---|
427 | 427 | | else throw("Strict value is not equal to itself.") |
---|
428 | 428 | | } |
---|
429 | 429 | | |
---|
430 | 430 | | |
---|
431 | 431 | | |
---|
432 | 432 | | @Callable(i) |
---|
433 | 433 | | func constructorV4 (legacyFactoryContract,legacyPools) = { |
---|
434 | 434 | | let checkCaller = mustManager(i) |
---|
435 | 435 | | if ((checkCaller == checkCaller)) |
---|
436 | 436 | | then [StringEntry(keyLegacyFactoryContract(), legacyFactoryContract), StringEntry(keyLegacyPools(), makeString(legacyPools, SEP))] |
---|
437 | 437 | | else throw("Strict value is not equal to itself.") |
---|
438 | 438 | | } |
---|
439 | 439 | | |
---|
440 | 440 | | |
---|
441 | 441 | | |
---|
442 | 442 | | @Callable(i) |
---|
443 | 443 | | func constructorV5 (assetsStoreContract) = { |
---|
444 | 444 | | let checkCaller = mustManager(i) |
---|
445 | 445 | | if ((checkCaller == checkCaller)) |
---|
446 | 446 | | then [StringEntry(keyAssetsStoreContract(), assetsStoreContract)] |
---|
447 | 447 | | else throw("Strict value is not equal to itself.") |
---|
448 | 448 | | } |
---|
449 | 449 | | |
---|
450 | 450 | | |
---|
451 | 451 | | |
---|
452 | 452 | | @Callable(i) |
---|
453 | 453 | | func constructorV6 (votingEmissionContract,priceAssets) = { |
---|
454 | 454 | | let cheks = [mustManager(i), if ((addressFromString(votingEmissionContract) != unit)) |
---|
455 | 455 | | then true |
---|
456 | 456 | | else "invalid voting emission contract address"] |
---|
457 | 457 | | if ((cheks == cheks)) |
---|
458 | 458 | | then [StringEntry(keyVotingEmissionContract(), votingEmissionContract), StringEntry(keyPriceAssets(), makeString(priceAssets, SEP))] |
---|
459 | 459 | | else throw("Strict value is not equal to itself.") |
---|
460 | 460 | | } |
---|
461 | 461 | | |
---|
462 | 462 | | |
---|
463 | 463 | | |
---|
464 | 464 | | @Callable(i) |
---|
465 | 465 | | func setManager (pendingManagerPublicKey) = { |
---|
466 | 466 | | let checkCaller = mustManager(i) |
---|
467 | 467 | | if ((checkCaller == checkCaller)) |
---|
468 | 468 | | then { |
---|
469 | 469 | | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) |
---|
470 | 470 | | if ((checkManagerPublicKey == checkManagerPublicKey)) |
---|
471 | 471 | | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] |
---|
472 | 472 | | else throw("Strict value is not equal to itself.") |
---|
473 | 473 | | } |
---|
474 | 474 | | else throw("Strict value is not equal to itself.") |
---|
475 | 475 | | } |
---|
476 | 476 | | |
---|
477 | 477 | | |
---|
478 | 478 | | |
---|
479 | 479 | | @Callable(i) |
---|
480 | 480 | | func confirmManager () = { |
---|
481 | 481 | | let pm = pendingManagerPublicKeyOrUnit() |
---|
482 | 482 | | let hasPM = if (isDefined(pm)) |
---|
483 | 483 | | then true |
---|
484 | 484 | | else throw("No pending manager") |
---|
485 | 485 | | if ((hasPM == hasPM)) |
---|
486 | 486 | | then { |
---|
487 | 487 | | let checkPM = if ((i.callerPublicKey == value(pm))) |
---|
488 | 488 | | then true |
---|
489 | 489 | | else throw("You are not pending manager") |
---|
490 | 490 | | if ((checkPM == checkPM)) |
---|
491 | 491 | | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] |
---|
492 | 492 | | else throw("Strict value is not equal to itself.") |
---|
493 | 493 | | } |
---|
494 | 494 | | else throw("Strict value is not equal to itself.") |
---|
495 | 495 | | } |
---|
496 | 496 | | |
---|
497 | 497 | | |
---|
498 | 498 | | |
---|
499 | 499 | | @Callable(i) |
---|
500 | 500 | | func setAdmins (adminPubKeys) = { |
---|
501 | 501 | | let checkCaller = mustManager(i) |
---|
502 | 502 | | if ((checkCaller == checkCaller)) |
---|
503 | 503 | | then [StringEntry(keyAdminPubKeys(), makeString(adminPubKeys, SEP))] |
---|
504 | 504 | | else throw("Strict value is not equal to itself.") |
---|
505 | 505 | | } |
---|
506 | 506 | | |
---|
507 | 507 | | |
---|
508 | 508 | | |
---|
509 | 509 | | @Callable(i) |
---|
510 | 510 | | func activateNewPool (poolAddress,amountAssetStr,priceAssetStr,lpAssetName,lpAssetDescr,poolWeight,poolType,logo) = { |
---|
511 | 511 | | let checkCaller = mustAdmin(i) |
---|
512 | 512 | | if ((checkCaller == checkCaller)) |
---|
513 | 513 | | then if (isDefined(getString(keyMappingPoolContractAddressToPoolAssets(poolAddress)))) |
---|
514 | 514 | | then throw((("Pool address " + poolAddress) + " already registered.")) |
---|
515 | 515 | | else { |
---|
516 | 516 | | let internalAmountAssetData = getInternalAssetIdOrCreate(amountAssetStr, 1) |
---|
517 | 517 | | let internalAmountAssetId = internalAmountAssetData._1 |
---|
518 | 518 | | let internalPriceAssetData = getInternalAssetIdOrCreate(priceAssetStr, if (internalAmountAssetData._3) |
---|
519 | 519 | | then 2 |
---|
520 | 520 | | else 1) |
---|
521 | 521 | | let internalPriceAssetId = internalPriceAssetData._1 |
---|
522 | 522 | | let poolAccountScriptHash = valueOrErrorMessage(scriptHash(addressFromStringValue(poolAddress)), ("No script has been found on pool account " + poolAddress)) |
---|
523 | 523 | | let ethalonPoolAccountScriptHash = getBinaryValue(keyPoolScriptHash()) |
---|
524 | 524 | | let poolExists = poolExistsInternal(amountAssetStr, priceAssetStr) |
---|
525 | 525 | | if (poolExists) |
---|
526 | 526 | | then throw((((("Pool " + amountAssetStr) + "/") + priceAssetStr) + " has already been activated.")) |
---|
527 | 527 | | else { |
---|
528 | 528 | | let poolConfigValue = value(getString(this, keyPoolConfig(toString(internalAmountAssetId), toString(internalPriceAssetId)))) |
---|
529 | 529 | | let amountAssetsDecimals = if ((amountAssetStr == "WAVES")) |
---|
530 | 530 | | then decimalsMultPrice |
---|
531 | 531 | | else pow(10, 0, value(assetInfo(fromBase58String(amountAssetStr))).decimals, 0, 0, DOWN) |
---|
532 | 532 | | let priceAssetsDecimals = if ((priceAssetStr == "WAVES")) |
---|
533 | 533 | | then decimalsMultPrice |
---|
534 | 534 | | else pow(10, 0, value(assetInfo(fromBase58String(priceAssetStr))).decimals, 0, 0, DOWN) |
---|
535 | 535 | | let lpAssetIssueAction = Issue(lpAssetName, lpAssetDescr, 1, 8, true) |
---|
536 | 536 | | let lpAssetId = calculateAssetId(lpAssetIssueAction) |
---|
537 | 537 | | let lpAssetIdStr = toBase58String(lpAssetId) |
---|
538 | 538 | | let poolActivateInvokeResult = invoke(addressFromStringValue(poolAddress), "activate", [amountAssetStr, priceAssetStr], nil) |
---|
539 | 539 | | if ((poolActivateInvokeResult == poolActivateInvokeResult)) |
---|
540 | 540 | | then if ((poolActivateInvokeResult != "success")) |
---|
541 | 541 | | then throw("Pool initialisation error happened.") |
---|
542 | 542 | | else { |
---|
543 | 543 | | let assetsStoreContract = addressFromStringValue(getStringOrFail(keyAssetsStoreContract())) |
---|
544 | 544 | | let createOrUpdateLpAssetInv = invoke(assetsStoreContract, "createOrUpdate", [lpAssetIdStr, lpAssetName, false], nil) |
---|
545 | 545 | | if ((createOrUpdateLpAssetInv == createOrUpdateLpAssetInv)) |
---|
546 | 546 | | then { |
---|
547 | 547 | | let addPoolsLpLabelInv = invoke(assetsStoreContract, "addLabel", [lpAssetIdStr, labelPoolsLp], nil) |
---|
548 | 548 | | if ((addPoolsLpLabelInv == addPoolsLpLabelInv)) |
---|
549 | 549 | | then { |
---|
550 | 550 | | let setLogoInv = invoke(assetsStoreContract, "setLogo", [lpAssetIdStr, logo], nil) |
---|
551 | 551 | | if ((setLogoInv == setLogoInv)) |
---|
552 | 552 | | then { |
---|
553 | 553 | | let addAssetsLinkInv = invoke(assetsStoreContract, "addAssetsLink", [amountAssetStr, priceAssetStr, lpAssetIdStr], nil) |
---|
554 | 554 | | if ((addAssetsLinkInv == addAssetsLinkInv)) |
---|
555 | 555 | | then { |
---|
556 | 556 | | let increaseAssetPoolsNumberInv = invoke(assetsStoreContract, "increaseAssetPoolsNumber", [amountAssetStr], nil) |
---|
557 | 557 | | if ((increaseAssetPoolsNumberInv == increaseAssetPoolsNumberInv)) |
---|
558 | 558 | | then $Tuple2(((internalAmountAssetData._2 ++ internalPriceAssetData._2) ++ [lpAssetIssueAction, Burn(lpAssetId, 1), StringEntry(keyPoolConfig(toString(internalAmountAssetId), toString(internalPriceAssetId)), dataPoolCfg(poolAddress, toString(PoolActive), lpAssetIdStr, amountAssetStr, priceAssetStr, amountAssetsDecimals, priceAssetsDecimals, internalAmountAssetId, internalPriceAssetId, decimalsMultPrice, poolType)), StringEntry(keyMappingLpAssetToPoolAssets(lpAssetIdStr), dataMappingPoolAssets(internalAmountAssetId, internalPriceAssetId)), StringEntry(keyMappingPoolAssetsToLpasset(toString(internalAmountAssetId), toString(internalPriceAssetId)), ("%s__" + lpAssetIdStr)), StringEntry(keyMappingPoolContractAddressToPoolAssets(poolAddress), dataMappingPoolAssets(internalAmountAssetId, internalPriceAssetId)), StringEntry(keyMappingPoolAssetsToPoolContractAddress(internalAmountAssetId, internalPriceAssetId), poolAddress), StringEntry(keyMappingPoolLPAssetToPoolContractAddress(lpAssetIdStr), poolAddress), StringEntry(keyMappingPoolContractToLPAsset(poolAddress), lpAssetIdStr), IntegerEntry(keyPoolToWeight(poolAddress), poolWeight), IntegerEntry(keyPoolSpread(poolAddress), defaultSpread)]), lpAssetIdStr) |
---|
559 | 559 | | else throw("Strict value is not equal to itself.") |
---|
560 | 560 | | } |
---|
561 | 561 | | else throw("Strict value is not equal to itself.") |
---|
562 | 562 | | } |
---|
563 | 563 | | else throw("Strict value is not equal to itself.") |
---|
564 | 564 | | } |
---|
565 | 565 | | else throw("Strict value is not equal to itself.") |
---|
566 | 566 | | } |
---|
567 | 567 | | else throw("Strict value is not equal to itself.") |
---|
568 | 568 | | } |
---|
569 | 569 | | else throw("Strict value is not equal to itself.") |
---|
570 | 570 | | } |
---|
571 | 571 | | } |
---|
572 | 572 | | else throw("Strict value is not equal to itself.") |
---|
573 | 573 | | } |
---|
574 | 574 | | |
---|
575 | 575 | | |
---|
576 | 576 | | |
---|
577 | 577 | | @Callable(i) |
---|
578 | 578 | | func managePool (poolAddress,newStatus) = { |
---|
579 | 579 | | let checkCaller = mustManager(i) |
---|
580 | 580 | | if ((checkCaller == checkCaller)) |
---|
581 | 581 | | then { |
---|
582 | 582 | | let poolConfig = getPoolConfig(poolAddress) |
---|
583 | 583 | | let poolStatus = poolConfig[idxPoolStatus] |
---|
584 | 584 | | let lpAssetIdStr = poolConfig[idxPoolLPAssetId] |
---|
585 | 585 | | let amountAssetStr = poolConfig[idxAmtAssetId] |
---|
586 | 586 | | let priceAssetStr = poolConfig[idxPriceAssetId] |
---|
587 | 587 | | let amountAssetsDecimals = parseIntValue(poolConfig[idxAmtAssetDcm]) |
---|
588 | 588 | | let priceAssetsDecimals = parseIntValue(poolConfig[idxPriceAssetDcm]) |
---|
589 | 589 | | let internalAmountAssetId = parseIntValue(poolConfig[idxIAmtAssetId]) |
---|
590 | 590 | | let internalPriceAssetId = parseIntValue(poolConfig[idxIPriceAssetId]) |
---|
591 | 591 | | let lpAssetDcm = parseIntValue(poolConfig[idxLPAssetDcm]) |
---|
592 | 592 | | let poolType = poolConfig[idxPoolType] |
---|
593 | 593 | | [StringEntry(keyPoolConfig(toString(internalAmountAssetId), toString(internalPriceAssetId)), dataPoolCfg(poolAddress, toString(newStatus), lpAssetIdStr, amountAssetStr, priceAssetStr, amountAssetsDecimals, priceAssetsDecimals, internalAmountAssetId, internalPriceAssetId, lpAssetDcm, poolType))] |
---|
594 | 594 | | } |
---|
595 | 595 | | else throw("Strict value is not equal to itself.") |
---|
596 | 596 | | } |
---|
597 | 597 | | |
---|
598 | 598 | | |
---|
599 | 599 | | |
---|
600 | 600 | | @Callable(i) |
---|
601 | 601 | | func emit (amountToEmit) = { |
---|
602 | 602 | | let caller = i.caller |
---|
603 | 603 | | let originCaller = i.originCaller |
---|
604 | 604 | | let lpAssetRequested = valueOrErrorMessage(getString(keyMappingPoolContractToLPAsset(toString(caller))), "Invalid LP address called me.") |
---|
605 | 605 | | let lpAsset = fromBase58String(lpAssetRequested) |
---|
606 | 606 | | let legacyPools = split(valueOrElse(getString(keyLegacyPools()), EMPTY), SEP) |
---|
607 | 607 | | let legacyFactoryContract = addressFromStringValue(valueOrErrorMessage(getString(keyLegacyFactoryContract()), "Legacy factory contract does not exists.")) |
---|
608 | 608 | | if ((0 >= amountToEmit)) |
---|
609 | 609 | | then nil |
---|
610 | 610 | | else if (containsElement(legacyPools, toString(caller))) |
---|
611 | 611 | | then $Tuple2(nil, legacyFactoryContract) |
---|
612 | 612 | | else $Tuple2([Reissue(lpAsset, amountToEmit, true), ScriptTransfer(i.caller, amountToEmit, lpAsset)], "success") |
---|
613 | 613 | | } |
---|
614 | 614 | | |
---|
615 | 615 | | |
---|
616 | 616 | | |
---|
617 | 617 | | @Callable(i) |
---|
618 | 618 | | func burn (amountToBurn) = { |
---|
619 | 619 | | let caller = i.caller |
---|
620 | 620 | | let originCaller = i.originCaller |
---|
621 | 621 | | let payment = value(i.payments[0]) |
---|
622 | 622 | | let paymentAmount = value(payment.amount) |
---|
623 | 623 | | let inAmountAssetId = toBase58String(value(payment.assetId)) |
---|
624 | 624 | | let lpAssetRequestedForBurning = valueOrErrorMessage(getString(keyMappingPoolContractToLPAsset(toString(caller))), "Invalid LP address called me.") |
---|
625 | 625 | | if ((inAmountAssetId != lpAssetRequestedForBurning)) |
---|
626 | 626 | | then throw("Invalid asset passed.") |
---|
627 | 627 | | else if ((amountToBurn != paymentAmount)) |
---|
628 | 628 | | then throw("Invalid amount passed.") |
---|
629 | 629 | | else { |
---|
630 | 630 | | let lpAsset = fromBase58String(lpAssetRequestedForBurning) |
---|
631 | 631 | | $Tuple2([Burn(lpAsset, amountToBurn)], "success") |
---|
632 | 632 | | } |
---|
633 | 633 | | } |
---|
634 | 634 | | |
---|
635 | 635 | | |
---|
636 | 636 | | |
---|
637 | 637 | | @Callable(i) |
---|
638 | 638 | | func modifyWeight (lpAssetId,share) = { |
---|
639 | 639 | | let checkCaller = if ((toBase58String(i.caller.bytes) == valueOrElse(getString(this, keyVotingEmissionContract()), ""))) |
---|
640 | 640 | | then true |
---|
641 | 641 | | else mustManager(i) |
---|
642 | 642 | | if ((checkCaller == checkCaller)) |
---|
643 | 643 | | then { |
---|
644 | 644 | | let poolContractAddress = getStringOrFail(keyMappingPoolLPAssetToPoolContractAddress(lpAssetId)) |
---|
645 | 645 | | let poolWeightKey = keyPoolToWeight(poolContractAddress) |
---|
646 | 646 | | let gwxWeightKey = keyPoolToWeight(GWXvirtualPOOL) |
---|
647 | 647 | | let gwxWeight = valueOrElse(getInteger(gwxWeightKey), 0) |
---|
648 | 648 | | let poolWeight = valueOrElse(getInteger(poolWeightKey), 0) |
---|
649 | 649 | | let poolWeightNew = share |
---|
650 | 650 | | let factoryCfg = split(getStringOrFail(keyFactoryConfig()), SEP) |
---|
651 | 651 | | let stakingContract = getStakingAddressOrFail(factoryCfg) |
---|
652 | 652 | | let onModifyWeightInv = invoke(stakingContract, "onModifyWeight", [lpAssetId, poolContractAddress], nil) |
---|
653 | 653 | | if ((onModifyWeightInv == onModifyWeightInv)) |
---|
654 | 654 | | then { |
---|
655 | 655 | | let gwxVirtualPoolActions = if ((gwxWeight == 0)) |
---|
656 | 656 | | then nil |
---|
657 | 657 | | else [IntegerEntry(gwxWeightKey, 0)] |
---|
658 | 658 | | let poolWeightHistoryKey = keyPoolToWeightHistory(poolContractAddress, 0) |
---|
659 | 659 | | let poolWeightHistoryOrUnit = getInteger(poolWeightHistoryKey) |
---|
660 | 660 | | let poolWeightHistoryActions = if ((poolWeightHistoryOrUnit == unit)) |
---|
661 | 661 | | then nil |
---|
662 | 662 | | else [DeleteEntry(poolWeightHistoryKey)] |
---|
663 | 663 | | (([IntegerEntry(poolWeightKey, poolWeightNew)] ++ gwxVirtualPoolActions) ++ poolWeightHistoryActions) |
---|
664 | 664 | | } |
---|
665 | 665 | | else throw("Strict value is not equal to itself.") |
---|
666 | 666 | | } |
---|
667 | 667 | | else throw("Strict value is not equal to itself.") |
---|
668 | 668 | | } |
---|
669 | 669 | | |
---|
670 | 670 | | |
---|
671 | 671 | | |
---|
672 | 672 | | @Callable(i) |
---|
673 | 673 | | func modifyWeights (btcPoolAddress,ethPoolAddress,ethBtcPoolAddress,usdcUsdtPoolAddress) = { |
---|
674 | 674 | | let checkCaller = mustManager(i) |
---|
675 | 675 | | if ((checkCaller == checkCaller)) |
---|
676 | 676 | | then { |
---|
677 | 677 | | let ethBtcWeightNew = ((5 * POOLWEIGHTMULT) / 100) |
---|
678 | 678 | | let usdcUsdtWeightNew = ((5 * POOLWEIGHTMULT) / 100) |
---|
679 | 679 | | let weightDecrement = ((5 * POOLWEIGHTMULT) / 100) |
---|
680 | 680 | | let factoryCfg = split(getStringOrFail(keyFactoryConfig()), SEP) |
---|
681 | 681 | | let stakingDapp = getStakingAddressOrFail(factoryCfg) |
---|
682 | 682 | | let gwxRewardDapp = getGwxRewardAddressOrFail(factoryCfg) |
---|
683 | 683 | | let btcWeightKEY = keyPoolToWeight(btcPoolAddress) |
---|
684 | 684 | | let ethWeightKEY = keyPoolToWeight(ethPoolAddress) |
---|
685 | 685 | | let ethBtcWeightKEY = keyPoolToWeight(ethBtcPoolAddress) |
---|
686 | 686 | | let usdcUsdtWeightKEY = keyPoolToWeight(usdcUsdtPoolAddress) |
---|
687 | 687 | | let btcWeight = getIntOrFail(btcWeightKEY) |
---|
688 | 688 | | let ethWeight = getIntOrFail(ethWeightKEY) |
---|
689 | 689 | | let btcWeightNew = (btcWeight - weightDecrement) |
---|
690 | 690 | | let ethWeightNew = (ethWeight - weightDecrement) |
---|
691 | 691 | | if ((0 >= btcWeightNew)) |
---|
692 | 692 | | then throw(("invalid btcWeightNew: " + toString(btcWeightNew))) |
---|
693 | 693 | | else if ((0 >= ethWeightNew)) |
---|
694 | 694 | | then throw(("invalid ethWeightNew: " + toString(ethWeightNew))) |
---|
695 | 695 | | else { |
---|
696 | 696 | | let btcLpAssetIdStr = getStringOrFail(keyMappingPoolContractToLPAsset(btcPoolAddress)) |
---|
697 | 697 | | let ethLpAssetIdStr = getStringOrFail(keyMappingPoolContractToLPAsset(ethPoolAddress)) |
---|
698 | 698 | | let ethBtcLpAssetIdStr = getStringOrFail(keyMappingPoolContractToLPAsset(ethBtcPoolAddress)) |
---|
699 | 699 | | let usdcUsdtLpAssetIdStr = getStringOrFail(keyMappingPoolContractToLPAsset(usdcUsdtPoolAddress)) |
---|
700 | 700 | | let onModifyWeightBtc = invoke(stakingDapp, "onModifyWeight", [btcLpAssetIdStr, btcPoolAddress], nil) |
---|
701 | 701 | | if ((onModifyWeightBtc == onModifyWeightBtc)) |
---|
702 | 702 | | then { |
---|
703 | 703 | | let onModifyWeightEth = invoke(stakingDapp, "onModifyWeight", [ethLpAssetIdStr, ethPoolAddress], nil) |
---|
704 | 704 | | if ((onModifyWeightEth == onModifyWeightEth)) |
---|
705 | 705 | | then { |
---|
706 | 706 | | let onModifyWeightEthBtc = invoke(stakingDapp, "onModifyWeight", [ethBtcLpAssetIdStr, ethBtcPoolAddress], nil) |
---|
707 | 707 | | if ((onModifyWeightEthBtc == onModifyWeightEthBtc)) |
---|
708 | 708 | | then { |
---|
709 | 709 | | let onModifyWeightUsdcUsdt = invoke(stakingDapp, "onModifyWeight", [usdcUsdtLpAssetIdStr, usdcUsdtPoolAddress], nil) |
---|
710 | 710 | | if ((onModifyWeightUsdcUsdt == onModifyWeightUsdcUsdt)) |
---|
711 | 711 | | then [IntegerEntry(btcWeightKEY, btcWeightNew), IntegerEntry(ethWeightKEY, ethWeightNew), IntegerEntry(ethBtcWeightKEY, ethBtcWeightNew), IntegerEntry(usdcUsdtWeightKEY, usdcUsdtWeightNew), IntegerEntry(keyPoolToWeightHistory(btcPoolAddress, 0), btcWeight), IntegerEntry(keyPoolToWeightHistory(ethPoolAddress, 0), ethWeight), IntegerEntry(keyPoolToWeightHistory(ethBtcPoolAddress, 0), ethBtcWeightNew), IntegerEntry(keyPoolToWeightHistory(usdcUsdtPoolAddress, 0), usdcUsdtWeightNew)] |
---|
712 | 712 | | else throw("Strict value is not equal to itself.") |
---|
713 | 713 | | } |
---|
714 | 714 | | else throw("Strict value is not equal to itself.") |
---|
715 | 715 | | } |
---|
716 | 716 | | else throw("Strict value is not equal to itself.") |
---|
717 | 717 | | } |
---|
718 | 718 | | else throw("Strict value is not equal to itself.") |
---|
719 | 719 | | } |
---|
720 | 720 | | } |
---|
721 | 721 | | else throw("Strict value is not equal to itself.") |
---|
722 | 722 | | } |
---|
723 | 723 | | |
---|
724 | 724 | | |
---|
725 | 725 | | |
---|
726 | 726 | | @Callable(i) |
---|
727 | 727 | | func checkWxEmissionPoolLabel (amountAssetId,priceAssetId) = { |
---|
728 | 728 | | let haveLabel = match getBoolean(keyWxEmission(amountAssetId, priceAssetId)) { |
---|
729 | 729 | | case b: Boolean => |
---|
730 | 730 | | b |
---|
731 | 731 | | case _ => |
---|
732 | 732 | | false |
---|
733 | 733 | | } |
---|
734 | 734 | | $Tuple2(nil, haveLabel) |
---|
735 | 735 | | } |
---|
736 | 736 | | |
---|
737 | 737 | | |
---|
738 | 738 | | |
---|
739 | 739 | | @Callable(i) |
---|
740 | 740 | | func setWxEmissionPoolLabel (amountAssetId,priceAssetId) = { |
---|
741 | 741 | | let checkCaller = mustAdmin(i) |
---|
742 | 742 | | if ((checkCaller == checkCaller)) |
---|
743 | 743 | | then $Tuple2([BooleanEntry(keyWxEmission(amountAssetId, priceAssetId), true)], unit) |
---|
744 | 744 | | else throw("Strict value is not equal to itself.") |
---|
745 | 745 | | } |
---|
746 | 746 | | |
---|
747 | 747 | | |
---|
748 | 748 | | |
---|
749 | 749 | | @Callable(i) |
---|
750 | 750 | | func deleteWxEmissionPoolLabel (amountAssetId,priceAssetId) = { |
---|
751 | 751 | | let checkCaller = if (mustThis(i)) |
---|
752 | 752 | | then true |
---|
753 | 753 | | else mustAdmin(i) |
---|
754 | 754 | | if ((checkCaller == checkCaller)) |
---|
755 | 755 | | then $Tuple2([DeleteEntry(keyWxEmission(amountAssetId, priceAssetId))], unit) |
---|
756 | 756 | | else throw("Strict value is not equal to itself.") |
---|
757 | 757 | | } |
---|
758 | 758 | | |
---|
759 | 759 | | |
---|
760 | 760 | | |
---|
761 | 761 | | @Callable(i) |
---|
762 | 762 | | func onVerificationLoss (assetId) = { |
---|
763 | 763 | | let checkCaller = if ((toBase58String(i.caller.bytes) == valueOrElse(getString(this, keyAssetsStoreContract()), ""))) |
---|
764 | 764 | | then true |
---|
765 | 765 | | else mustManager(i) |
---|
766 | 766 | | if ((checkCaller == checkCaller)) |
---|
767 | 767 | | then { |
---|
768 | 768 | | let priceAssets = getPriceAssets() |
---|
769 | 769 | | let checkPriceAssetsSize = if ((size(priceAssets) > 0)) |
---|
770 | 770 | | then true |
---|
771 | 771 | | else throw("invalid price assets") |
---|
772 | 772 | | if ((checkPriceAssetsSize == checkPriceAssetsSize)) |
---|
773 | 773 | | then { |
---|
774 | 774 | | func cb (acc,priceAsset) = { |
---|
775 | 775 | | let r = invoke(this, "deleteWxEmissionPoolLabel", [assetId, priceAsset], nil) |
---|
776 | 776 | | if ((r == r)) |
---|
777 | 777 | | then unit |
---|
778 | 778 | | else throw("Strict value is not equal to itself.") |
---|
779 | 779 | | } |
---|
780 | 780 | | |
---|
781 | 781 | | let actions = { |
---|
782 | 782 | | let $l = priceAssets |
---|
783 | 783 | | let $s = size($l) |
---|
784 | 784 | | let $acc0 = unit |
---|
785 | 785 | | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
786 | 786 | | then $a |
---|
787 | 787 | | else cb($a, $l[$i]) |
---|
788 | 788 | | |
---|
789 | 789 | | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
790 | 790 | | then $a |
---|
791 | 791 | | else throw("List size exceeds 2") |
---|
792 | 792 | | |
---|
793 | 793 | | $f0_2($f0_1($f0_1($acc0, 0), 1), 2) |
---|
794 | 794 | | } |
---|
795 | 795 | | if ((actions == actions)) |
---|
796 | 796 | | then $Tuple2(nil, unit) |
---|
797 | 797 | | else throw("Strict value is not equal to itself.") |
---|
798 | 798 | | } |
---|
799 | 799 | | else throw("Strict value is not equal to itself.") |
---|
800 | 800 | | } |
---|
801 | 801 | | else throw("Strict value is not equal to itself.") |
---|
802 | 802 | | } |
---|
803 | 803 | | |
---|
804 | 804 | | |
---|
805 | 805 | | |
---|
806 | 806 | | @Callable(i) |
---|
807 | 807 | | func isPoolOneTokenOperationsDisabledREADONLY (poolAddress) = { |
---|
808 | 808 | | let poolConfig = getPoolConfig(poolAddress) |
---|
809 | 809 | | let assetsInternal = $Tuple2(parseIntValue(poolConfig[idxIAmtAssetId]), parseIntValue(poolConfig[idxIPriceAssetId])) |
---|
810 | 810 | | let poolOneTokenOperationsDisabled = valueOrElse(getBoolean(keyPoolOneTokenOperationsDisabled(assetsInternal)), false) |
---|
811 | 811 | | let allPoolsOneTokenOperationsDisabled = valueOrElse(getBoolean(keyAllPoolsOneTokenOperationsDisabled()), false) |
---|
812 | 812 | | $Tuple2(nil, if (allPoolsOneTokenOperationsDisabled) |
---|
813 | 813 | | then true |
---|
814 | 814 | | else poolOneTokenOperationsDisabled) |
---|
815 | 815 | | } |
---|
816 | 816 | | |
---|
817 | 817 | | |
---|
818 | 818 | | |
---|
819 | 819 | | @Callable(i) |
---|
820 | 820 | | func getInFeeREADONLY (poolAddress) = { |
---|
821 | 821 | | let fee = intOrDefaultOrFallback(keyInFee(poolAddress), keyInFeeDefault(), 0) |
---|
822 | 822 | | $Tuple2(nil, fee) |
---|
823 | 823 | | } |
---|
824 | 824 | | |
---|
825 | 825 | | |
---|
826 | 826 | | |
---|
827 | 827 | | @Callable(i) |
---|
828 | 828 | | func getOutFeeREADONLY (poolAddress) = { |
---|
829 | 829 | | let fee = intOrDefaultOrFallback(keyOutFee(poolAddress), keyOutFeeDefault(), fraction(10, MULT8, 10000)) |
---|
830 | 830 | | $Tuple2(nil, fee) |
---|
831 | 831 | | } |
---|
832 | 832 | | |
---|
833 | 833 | | |
---|
834 | 834 | | |
---|
835 | 835 | | @Callable(i) |
---|
836 | 836 | | func poolInfoREADONLY (amountAssetIdStr,priceAssetIdStr) = { |
---|
837 | 837 | | let amountAssetInternalIdOption = getInteger(this, keyMappingsBaseAsset2internalId(amountAssetIdStr)) |
---|
838 | 838 | | let priceAssetInternalIdOption = getInteger(this, keyMappingsBaseAsset2internalId(priceAssetIdStr)) |
---|
839 | 839 | | let poolContractAddressOption = getString(this, keyMappingPoolAssetsToPoolContractAddress(value(amountAssetInternalIdOption), value(priceAssetInternalIdOption))) |
---|
840 | 840 | | let lpAssetIdOption = getString(this, keyMappingPoolContractToLPAsset(value(poolContractAddressOption))) |
---|
841 | 841 | | let poolExists = if (if (isDefined(amountAssetInternalIdOption)) |
---|
842 | 842 | | then isDefined(priceAssetInternalIdOption) |
---|
843 | 843 | | else false) |
---|
844 | 844 | | then isDefined(poolContractAddressOption) |
---|
845 | 845 | | else false |
---|
846 | 846 | | let poolInfo = if (poolExists) |
---|
847 | 847 | | then $Tuple2(addressFromStringValue(value(poolContractAddressOption)), parseAssetId(value(lpAssetIdOption))) |
---|
848 | 848 | | else unit |
---|
849 | 849 | | $Tuple2(nil, poolInfo) |
---|
850 | 850 | | } |
---|
851 | 851 | | |
---|
852 | 852 | | |
---|
853 | 853 | | |
---|
854 | 854 | | @Callable(i) |
---|
855 | 855 | | func getPoolStatusREADONLY (poolAddress) = { |
---|
856 | 856 | | let poolAssets = split(getStringOrFail(keyMappingPoolContractAddressToPoolAssets(poolAddress)), SEP) |
---|
857 | 857 | | let amountAssetInternal = poolAssets[1] |
---|
858 | 858 | | let priceAssetInternal = poolAssets[2] |
---|
859 | 859 | | let cfg = split(getStringOrFail(keyPoolConfig(amountAssetInternal, priceAssetInternal)), SEP) |
---|
860 | 860 | | $Tuple2(nil, parseIntValue(cfg[idxPoolStatus])) |
---|
861 | 861 | | } |
---|
862 | 862 | | |
---|
863 | 863 | | |
---|
864 | 864 | | |
---|
865 | 865 | | @Callable(i) |
---|
866 | 866 | | func getPoolConfigREADONLY (poolAddress) = { |
---|
867 | 867 | | let poolAssets = split(getStringOrFail(keyMappingPoolContractAddressToPoolAssets(poolAddress)), SEP) |
---|
868 | 868 | | let amountAssetInternal = poolAssets[1] |
---|
869 | 869 | | let priceAssetInternal = poolAssets[2] |
---|
870 | 870 | | let cfg = split(getStringOrFail(keyPoolConfig(amountAssetInternal, priceAssetInternal)), SEP) |
---|
871 | 871 | | $Tuple2(nil, cfg) |
---|
872 | 872 | | } |
---|
873 | 873 | | |
---|
874 | 874 | | |
---|
875 | 875 | | |
---|
876 | 876 | | @Callable(i) |
---|
877 | 877 | | func getPoolConfigByLpAssetId (lpAssetIdStr) = { |
---|
878 | 878 | | let poolAssets = split(getStringOrFail(keyMappingLpAssetToPoolAssets(lpAssetIdStr)), SEP) |
---|
879 | 879 | | let amountAssetInternal = poolAssets[1] |
---|
880 | 880 | | let priceAssetInternal = poolAssets[2] |
---|
881 | 881 | | let cfg = split(getStringOrFail(keyPoolConfig(amountAssetInternal, priceAssetInternal)), SEP) |
---|
882 | 882 | | $Tuple2(nil, cfg) |
---|
883 | 883 | | } |
---|
884 | 884 | | |
---|
885 | 885 | | |
---|
886 | 886 | | |
---|
887 | 887 | | @Callable(i) |
---|
888 | 888 | | func poolExistsREADONLY (amountAssetId,priceAssetId) = $Tuple2(nil, poolExistsInternal(amountAssetId, priceAssetId)) |
---|
889 | 889 | | |
---|
890 | 890 | | |
---|
891 | 891 | | |
---|
892 | 892 | | @Callable(i) |
---|
893 | 893 | | func skipOrderValidationREADONLY (poolAddress) = $Tuple2(nil, valueOrElse(getBoolean(keySkipOrderValidation(poolAddress)), false)) |
---|
894 | 894 | | |
---|
895 | 895 | | |
---|
896 | 896 | | |
---|
897 | 897 | | @Callable(i) |
---|
898 | 898 | | func getChangeAmpConfigREADONLY (poolAddress) = { |
---|
899 | 899 | | let delay = getIntegerValue(keyChangeAmpDelay(poolAddress)) |
---|