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