Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxdefi-466 #405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions migrations/wxdefi-466-release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/txs
.env*
pnpm-lock.yaml
97 changes: 97 additions & 0 deletions migrations/wxdefi-466-release/index.mjs
Original file line number Diff line number Diff line change
@@ -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.`)
13 changes: 13 additions & 0 deletions migrations/wxdefi-466-release/package.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
14 changes: 13 additions & 1 deletion ride/factory_v2.ride
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#------------------------
Expand Down Expand Up @@ -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
)
Expand Down
Loading