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