diff --git a/migrations/wxdefi-466-release/.gitignore b/migrations/wxdefi-466-release/.gitignore new file mode 100644 index 00000000..92d0d10e --- /dev/null +++ b/migrations/wxdefi-466-release/.gitignore @@ -0,0 +1,3 @@ +/txs +.env* +pnpm-lock.yaml diff --git a/migrations/wxdefi-466-release/index.mjs b/migrations/wxdefi-466-release/index.mjs new file mode 100644 index 00000000..2cb1e437 --- /dev/null +++ b/migrations/wxdefi-466-release/index.mjs @@ -0,0 +1,97 @@ +import { create } from '@waves/node-api-js'; +import { data } from '@waves/waves-transactions'; +import fs from 'fs/promises'; +import path from 'path'; +import { address } from '@waves/ts-lib-crypto'; + +const separator = '__'; +const scriptedSenderFee = 4e5; + +const { + NODE_URL, + CHAIN_ID, + TXS_PATH, + FACTORY_PUBLIC_KEY, + PROFIT_INCREASE, + STEP_SIZE, + ORDERS_NUMBER, +} = process.env; + +const api = create(NODE_URL); + +const factoryAddress = address( + { publicKey: FACTORY_PUBLIC_KEY }, + CHAIN_ID +); + +const keyPoolProfitIncrease = (poolAddress) => '%s%s__profitIncrease__' + poolAddress +const keyPoolStepSize = (poolAddress) => '%s%s__stepSize__' + poolAddress +const keyPoolOrdersNumber = (poolAddress) => '%s%s__ordersNumber__' + poolAddress + +const actions = await api.addresses.data(factoryAddress, { + matches: encodeURIComponent( + '%s%s%s__.+__mappings__poolContract2PoolAssets' + ), +}).then((res) => res.reduce((acc, { key }) => { + const poolAddress = key.split(separator)[1]; + return [ + ...acc, + { + key: keyPoolProfitIncrease(poolAddress), + type: 'integer', + value: PROFIT_INCREASE, + }, + { + key: keyPoolStepSize(poolAddress), + type: 'integer', + value: STEP_SIZE, + }, + { + key: keyPoolOrdersNumber(poolAddress), + type: 'integer', + value: ORDERS_NUMBER, + }, + ] +}, [])); + +const chunkSize = 100; +const actionsChunks = Array.from( + { length: Math.ceil(actions.length / chunkSize) }, + () => [] +); +for (const i in actions) { + const chunkIndex = Math.floor(i / chunkSize); + actionsChunks[chunkIndex].push(actions[i]); +} +const dataTxs = actionsChunks.map((changes) => + data({ + data: changes, + chainId: CHAIN_ID, + senderPublicKey: FACTORY_PUBLIC_KEY, + additionalFee: scriptedSenderFee, + }) +); + +const txs = []; + +for (const tx of dataTxs) { + const name = 'data'; + txs.push({ tx, name }); +} + +await fs.mkdir(TXS_PATH, { recursive: true }); +const files = await fs.readdir(TXS_PATH); +await Promise.all( + files.map(async (name) => { + return fs.unlink(path.join(TXS_PATH, name)); + }) +); +await Promise.all( + txs.map(async ({ tx, name }, idx) => { + await fs.writeFile( + path.join(TXS_PATH, `${[idx, name.replace(/\s/g, '_')].join('_')}.json`), + JSON.stringify(tx, null, 2) + ); + }) +); +console.log(`Done. ${txs.length} txs created.`) diff --git a/migrations/wxdefi-466-release/package.json b/migrations/wxdefi-466-release/package.json new file mode 100644 index 00000000..de323e24 --- /dev/null +++ b/migrations/wxdefi-466-release/package.json @@ -0,0 +1,13 @@ +{ + "name": "2022_12_27_lp_staking_pools_release", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": {} +} diff --git a/ride/factory_v2.ride b/ride/factory_v2.ride index bc857a08..eb8c86f1 100644 --- a/ride/factory_v2.ride +++ b/ride/factory_v2.ride @@ -176,6 +176,15 @@ func keyMinBalance(poolAddress: String, assetId: String) func keyMinBalanceDefault(assetId: String) = makeString(["%s%s", "minBalanceDefault", assetId], SEP) +let profitIncreaseDefault = 10000000 +func keyPoolProfitIncrease(poolAddress: String) = "%s%s__profitIncrease__" + poolAddress + +let stepSizeDefault = 100000 +func keyPoolStepSize(poolAddress: String) = "%s%s__stepSize__" + poolAddress + +let ordersNumberDefault = 100 +func keyPoolOrdersNumber(poolAddress: String) = "%s%s__ordersNumber__" + poolAddress + func keyAddressWhitelisted(address: Address) = makeString(["%s%s", "whitelisted", address.toString()], SEP) #------------------------ @@ -663,7 +672,10 @@ func activateNewPool(poolAddress: String, amountAssetStr: String, priceAssetStr: StringEntry(keyMappingPoolLPAssetToPoolContractAddress(lpAssetIdStr), poolAddress), StringEntry(keyMappingPoolContractToLPAsset(poolAddress), lpAssetIdStr), IntegerEntry(keyPoolToWeight(poolAddress),poolWeight), - IntegerEntry(keyPoolSpread(poolAddress),defaultSpread) + IntegerEntry(keyPoolSpread(poolAddress),defaultSpread), + IntegerEntry(keyPoolProfitIncrease(poolAddress), profitIncreaseDefault), + IntegerEntry(keyPoolStepSize(poolAddress), stepSizeDefault), + IntegerEntry(keyPoolOrdersNumber(poolAddress), ordersNumberDefault) ] , lpAssetIdStr )