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