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-435 #382

Draft
wants to merge 98 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
4f42382
unlock draft + some total gwx changes
ridev6 Jul 13, 2023
84a5c83
Auto-merge 'main' -> 'wxdefi-435-wx-unlock'
github-actions[bot] Jul 13, 2023
bb2acb1
lockedGwxAmount draft
ridev6 Jul 13, 2023
800b7c6
Merge remote-tracking branch 'origin/wxdefi-435-wx-unlock' into wxdef…
ridev6 Jul 13, 2023
b6062d0
getLockedGwxAmount draft update
ridev6 Jul 13, 2023
bd8e3b8
boosting_v2.ride
ridev6 Jul 14, 2023
af1af0f
refactor
ridev6 Jul 14, 2023
f9223f5
wip
ridev6 Jul 17, 2023
2d2d910
fix keyUserGwxAmountTotal
ridev6 Jul 18, 2023
edbdbeb
update gwx amount in lock/unlock
ridev6 Jul 18, 2023
a029b06
fix HistoryEntry
ridev6 Jul 18, 2023
814bdfa
remove calcGwxAmountStart
ridev6 Jul 18, 2023
206ad3d
use maxLockDuration from config
ridev6 Jul 18, 2023
77f64ed
fix gwxBurned
ridev6 Jul 18, 2023
5c1c938
fix lock param indeces
ridev6 Jul 18, 2023
ba5db25
wxClaimed and gwxAmount in unlock
ridev6 Jul 18, 2023
857303b
remove getUserGwxAmountTotal todo comment
ridev6 Jul 18, 2023
e63fef7
remove calcGwxParamsREADONLY usage
ridev6 Jul 19, 2023
32b4c76
fix getUserGwxAmountAtHeightREADONLY
ridev6 Jul 19, 2023
add5b85
fix userMaxDurationREADONLY
ridev6 Jul 19, 2023
5b9bf95
remove todo
ridev6 Jul 19, 2023
2fee117
remove period
ridev6 Jul 19, 2023
a13eec6
Auto-merge 'main' -> 'wxdefi-435-wx-unlock'
github-actions[bot] Jul 19, 2023
0ea9ae7
lock duration
ridev6 Jul 19, 2023
410cddb
proposal getLockedGwxAmount
ridev6 Jul 21, 2023
a88e4fa
Auto-merge 'main' -> 'wxdefi-435-wx-unlock'
github-actions[bot] Jul 21, 2023
77f91fd
updateActiveVotingListActions + test
ridev6 Jul 25, 2023
873e587
Merge remote-tracking branch 'origin/main' into wxdefi-435-wx-unlock
ridev6 Jul 26, 2023
2a3c92d
Merge remote-tracking branch 'origin/main' into wxdefi-435-wx-unlock
ridev6 Jul 28, 2023
0711bad
remove locked gwx amount from proposal
ridev6 Jul 28, 2023
e49ca51
fix getLockedGwxAmount draft
ridev6 Jul 28, 2023
7771ce6
voting emission rate getLockedGwxAmount
ridev6 Aug 1, 2023
d29bd48
voting emission getLockedGwxAmount
ridev6 Aug 1, 2023
7605e2b
boosting_v2 getLockedGwxAmount fix
ridev6 Aug 1, 2023
76dfa2c
migration script
ridev6 Aug 2, 2023
c0ad597
Auto-merge 'main' -> 'wxdefi-435-wx-unlock'
github-actions[bot] Aug 2, 2023
a6d8931
remove unused imports
ridev6 Aug 3, 2023
b60819f
Merge remote-tracking branch 'origin/wxdefi-435-wx-unlock' into wxdef…
ridev6 Aug 3, 2023
966fa24
remove usersListTraversal
ridev6 Aug 3, 2023
3d542a2
gwx reward update draft
ridev6 Aug 3, 2023
5301693
refreshRewardPerGwxIntegral draft
ridev6 Aug 4, 2023
0ad2b85
refreshUserReward draft
ridev6 Aug 4, 2023
5832b71
voting emission remove deposit call
ridev6 Aug 7, 2023
1778379
gwx reward refreshUserReward
ridev6 Aug 7, 2023
b1b596c
refreshUserReward in lock/unlock + increase precision
ridev6 Aug 7, 2023
2f3a4cd
fix claimReward
ridev6 Aug 7, 2023
37a10e5
rename + info in migration
ridev6 Aug 8, 2023
ca2e8ef
Merge remote-tracking branch 'origin/main' into wxdefi-435-wx-unlock
ridev6 Aug 8, 2023
9eb8c77
fix migration
ridev6 Aug 8, 2023
0a142ef
fix unlock
ridev6 Aug 8, 2023
678d3ab
fix unlock
ridev6 Aug 8, 2023
64cc272
fix unlock
ridev6 Aug 8, 2023
5ca0bdc
fix migration
ridev6 Aug 8, 2023
7a60e3f
reentrantInvoke in unlock
ridev6 Aug 8, 2023
ba15a1b
fix refreshRewardPerGwxIntegral
ridev6 Aug 8, 2023
899e4a5
fix unlock
ridev6 Aug 8, 2023
cb90e53
fix commonClaimReward
ridev6 Aug 9, 2023
90ff061
fix commonClaimReward
ridev6 Aug 9, 2023
04eb5cc
reentantInvoke in lockActions
ridev6 Aug 9, 2023
40457b3
fix unlock
ridev6 Aug 9, 2023
a8de7ed
blocks in period variable
ridev6 Aug 10, 2023
b7d0c82
fix unlock
ridev6 Aug 10, 2023
b919904
fix getWxWithdrawable
ridev6 Aug 10, 2023
1258336
fix unlock
ridev6 Aug 10, 2023
6eab405
unlock all
ridev6 Aug 10, 2023
6e6c2e9
refactor
ridev6 Aug 11, 2023
fc54675
fix formatLockParamsRecord
ridev6 Aug 14, 2023
7579475
remove unused keys
ridev6 Aug 14, 2023
515a52a
fix userMaxDurationREADONLY
ridev6 Aug 15, 2023
4cb21b1
move duration check in lockActions
ridev6 Aug 15, 2023
5cf3e17
fix
ridev6 Aug 15, 2023
d741c48
remove some tests
ridev6 Aug 15, 2023
ac797b2
remove some tests
ridev6 Aug 15, 2023
f89f1c1
Auto-merge 'main' -> 'wxdefi-435-wx-unlock'
github-actions[bot] Aug 15, 2023
bc23ae7
Merge remote-tracking branch 'origin/main' into wxdefi-435-wx-unlock
ridev6 Aug 16, 2023
48fa023
fix unlock
ridev6 Aug 17, 2023
7f3c567
gwx reward test draft + replace invokes
ridev6 Aug 17, 2023
e09e718
Merge remote-tracking branch 'origin/main' into wxdefi-435-wx-unlock
ridev6 Aug 18, 2023
02cf726
boosting unlock fix
ridev6 Aug 18, 2023
40d614c
remove reentrantInvoke
ridev6 Aug 21, 2023
c42952c
fix existing boosting tests
ridev6 Aug 21, 2023
55f4e06
lock test
ridev6 Aug 21, 2023
c349b88
lock test fix, unlock test
ridev6 Aug 21, 2023
cd4df15
unlock gwx burned check
ridev6 Aug 22, 2023
f62f340
decay constant
ridev6 Aug 22, 2023
e43f0c9
tests update
ridev6 Aug 22, 2023
6c1b564
gwx claim reward test draft
ridev6 Aug 22, 2023
9225b8f
gwx reward claim test math
ridev6 Aug 23, 2023
daadff8
claimReward 2 locks
ridev6 Aug 23, 2023
645c8b1
claim reward test refactor
ridev6 Aug 23, 2023
2c7dbd5
gwx claim reward for 2 parts
ridev6 Aug 23, 2023
9ed69d7
boosting unlock all test
ridev6 Aug 24, 2023
9dcf83d
update tests
ridev6 Aug 25, 2023
c06125a
fix getWxWithdrawable
ridev6 Aug 30, 2023
141c8d2
suspend
ridev6 Aug 31, 2023
efc2e47
fix gwx burned math and unlock test
ridev6 Aug 31, 2023
53fa89d
fix migration
ridev6 Sep 4, 2023
86ecdd6
fix migration
ridev6 Sep 5, 2023
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-435-release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/txs
.env*
pnpm-lock.yaml
209 changes: 209 additions & 0 deletions migrations/wxdefi-435-release/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
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,
GWX_REWARD_PUBLIC_KEY,
BOOSTING_PUBLIC_KEY,
WX_ASSET_ID,
MIN_LOCK_AMOUNT,
MIN_LOCK_DURATION,
MAX_LOCK_DURATION,
BLOCKS_IN_PERIOD,
LOCK_STEP_BLOCKS,
UNLOCK_START_HEIGHT,
} = process.env;
const api = create(NODE_URL);

const boostingAddress = address(
{ publicKey: BOOSTING_PUBLIC_KEY },
CHAIN_ID
);

const gwxRewardAddress = address(
{ publicKey: GWX_REWARD_PUBLIC_KEY },
CHAIN_ID
);

const keyLockParamsRecord = (userAddress, txId) =>
`%s%s%s__lock__${userAddress}__${txId}`;

const keyUserGwxAmountTotal = (userAddress) =>
`%s%s__gwxAmountTotal__${userAddress}`;

const lockParamsRecord = ({
amount,
start,
duration,
timestamp,
gwxAmount,
wxClaimed,
}) => [
'%d%d%d%d%d%d%d',
amount.toString(),
start.toString(),
duration.toString(),
timestamp.toString(),
gwxAmount.toString(),
wxClaimed.toString(),
].join(separator);

const lockParamsData = await api.addresses.data(boostingAddress, {
matches: encodeURIComponent(
`%s%s__lock__[^_]+`
),
});
let locks = {
empty: 0,
nonEmpty: 0,
unlocked: 0,
};
const actions = [];
let gwxAmountTotal = 0n;
for (const { key, value } of lockParamsData) {
const [
/* meta */,
/* 'lock' */,
userAddress
] = key.split(separator);

const [
/* meta */,
/* userNum */,
lockAmountStr,
lockStartStr,
lockDurationStr,
/* paramK */,
/* paramB */,
lockTimestampStr, // last update timestamp
/* gwxAmount */
] = value.split(separator)
const lockAmount = Number(lockAmountStr);
const lockStart = Number(lockStartStr);
const lockDuration = Number(lockDurationStr);
const lockTimestamp = Number(lockTimestampStr);

if (lockAmount <= 0) {
locks.unlocked += 1;
continue;
}
const lockEnd = lockStart + lockDuration;
let gwxAmount = 0, duration = lockDuration, start = lockStart;
if (lockEnd > Number(UNLOCK_START_HEIGHT)) {
start = Number(UNLOCK_START_HEIGHT);
duration = lockEnd - start;
gwxAmount = Math.floor((lockAmount * duration) / Number(MAX_LOCK_DURATION));
}

if (gwxAmount > 0) {
locks.nonEmpty += 1;
} else {
locks.empty += 1;
}
gwxAmountTotal += BigInt(gwxAmount);
actions.push(
{
key: keyLockParamsRecord(userAddress, 'legacy'),
type: 'string',
value: lockParamsRecord({
amount: lockAmount,
start,
duration,
timestamp: lockTimestamp,
gwxAmount,
wxClaimed: 0,
}),
},
{
key: keyUserGwxAmountTotal(userAddress),
type: 'integer',
value: parseInt(gwxAmount),
},
);
}
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: BOOSTING_PUBLIC_KEY,
additionalFee: scriptedSenderFee,
})
);

const txs = [];

// restart the script after boosting lock/unlock freeze?
txs.push({
name: 'restart the script',
tx: {},
});

txs.push({
name: 'boosting data',
tx: data({
data: [
{
key: '%s%s__gwx__total',
type: 'integer',
value: gwxAmountTotal.toString(),
},
{
key: '%s__config',
type: 'string',
value: [
'%s%d%d%d%s%d',
WX_ASSET_ID,
MIN_LOCK_AMOUNT,
MIN_LOCK_DURATION,
MAX_LOCK_DURATION,
gwxRewardAddress,
BLOCKS_IN_PERIOD,
LOCK_STEP_BLOCKS,
].join(separator),
}
],
senderPublicKey: BOOSTING_PUBLIC_KEY,
additionalFee: scriptedSenderFee,
chainId: CHAIN_ID,
}),
});

for (const tx of dataTxs) {
const name = 'lock params';
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.`)
console.log({ locks });
13 changes: 13 additions & 0 deletions migrations/wxdefi-435-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": {}
}
Loading
Loading