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

fix lp vesting vulnerability NTRN-118 #218

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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
68 changes: 59 additions & 9 deletions src/testcases/run_in_band/tge.auction_migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'auctionVesting',
'auctionLockdrop',
'auctionLockdropVesting',
'claimVestingBeforeMigration',
]) {
tgeWallets[v] = new cosmosWrapper.WalletWrapper(
neutronChain,
Expand Down Expand Up @@ -274,6 +275,11 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
tgeWallets['airdropAuctionVesting'].wallet.address.toString(),
amount: '1000000',
},
{
address:
tgeWallets['claimVestingBeforeMigration'].wallet.address.toString(),
amount: '1000000',
},
];
tgeMain.times.airdropStart = tge.getTimestamp(0);
tgeMain.times.airdropVestingStart = tge.getTimestamp(300);
Expand Down Expand Up @@ -302,6 +308,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'airdropAuctionVesting',
'airdropAuctionLockdrop',
'airdropAuctionLockdropVesting',
'claimVestingBeforeMigration',
]) {
const address = tgeWallets[v].wallet.address.toString();
const amount =
Expand Down Expand Up @@ -387,6 +394,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'auctionVesting',
'auctionLockdrop',
'auctionLockdropVesting',
'claimVestingBeforeMigration',
]) {
const res2 = await tgeWallets[v].executeContract(
tgeMain.contracts.auction,
Expand Down Expand Up @@ -460,6 +468,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'auctionVesting',
'auctionLockdrop',
'auctionLockdropVesting',
'claimVestingBeforeMigration',
]) {
const res2 = await tgeWallets[v].executeContract(
tgeMain.contracts.auction,
Expand Down Expand Up @@ -1001,9 +1010,16 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
}),
);
expect(res.code).toEqual(0);
res = await tgeWallets.airdropOnly.executeContract(
tgeMain.contracts.auction,
JSON.stringify({
migrate_to_vesting: {},
}),
);
expect(res.code).toEqual(0);
tgeMain.times.vestTimestamp = Date.now();
});
it('should not vest LP all 7 users have been migrated', async () => {
it('should not vest LP all 8 users have been migrated', async () => {
await expect(
cmInstantiator.executeContract(
tgeMain.contracts.auction,
Expand Down Expand Up @@ -1067,14 +1083,14 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {

expect(
parseInt(vestingInfoAtom.info.schedules[0].end_point.amount),
).toBeCloseTo(89394, -1);
).toBeCloseTo(75706, -1);
claimAtomLP = parseInt(
vestingInfoAtom.info.schedules[0].end_point.amount,
);

expect(
parseInt(vestingInfoUsdc.info.schedules[0].end_point.amount),
).toBeCloseTo(18087, -1);
).toBeCloseTo(14197, -1);
claimUsdcLP = parseInt(
vestingInfoUsdc.info.schedules[0].end_point.amount,
);
Expand Down Expand Up @@ -1165,6 +1181,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'auctionVesting',
'auctionLockdrop',
'auctionLockdropVesting',
'claimVestingBeforeMigration',
]) {
const member = new dao.DaoMember(tgeWallets[v], daoMain);
expect((await member.queryVotingPower()).power | 0).toBe(0);
Expand Down Expand Up @@ -1214,6 +1231,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'airdropOnly',
'airdropAuctionVesting',
'auctionVesting',
'claimVestingBeforeMigration',
]) {
const member = new dao.DaoMember(tgeWallets[v], daoMain);
expect((await member.queryVotingPower()).power | 0).toBe(0);
Expand Down Expand Up @@ -1252,6 +1270,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'airdropAuctionLockdropVesting',
'auctionLockdrop',
'auctionLockdropVesting',
'claimVestingBeforeMigration',
]) {
const member = new dao.DaoMember(tgeWallets[v], daoMain);
vp[v] = (await member.queryVotingPower()).power | 0;
Expand All @@ -1266,7 +1285,11 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
const tvpNew = await daoMain.queryTotalVotingPower();
expect(tvpNew.power | 0).toBeGreaterThan(tvp.power | 0);
// vesting participants get(increase) the voting power
for (const v of ['airdropAuctionVesting', 'auctionVesting']) {
for (const v of [
'airdropAuctionVesting',
'auctionVesting',
'claimVestingBeforeMigration',
]) {
const member = new dao.DaoMember(tgeWallets[v], daoMain);
expect((await member.queryVotingPower()).power | 0).toBeGreaterThan(
vp[v] | 0,
Expand Down Expand Up @@ -1306,6 +1329,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
'auctionLockdrop',
'auctionLockdropVesting',
'auctionVesting',
'claimVestingBeforeMigration',
]) {
const member = new dao.DaoMember(tgeWallets[v], daoMain);
vp[v] = (await member.queryVotingPower()).power | 0;
Expand Down Expand Up @@ -1401,7 +1425,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
rewardsStateAfterClaim.balanceNtrn +
FEE_SIZE -
rewardsStateBeforeClaim.balanceNtrn,
).toEqual(120515); // lockdrop rewards share for the user
).toEqual(125980); // lockdrop rewards share for the user
const expectedGeneratorRewards = +(
(
rewardsStateBeforeClaim.userInfo.lockup_infos.find(
Expand Down Expand Up @@ -1475,6 +1499,26 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
let vestingLpVaultForClAddr: string;

describe('Migration of pairs', () => {
it('should claim from last wallet in map', async () => {
const resAtom = await tgeWallets[
'claimVestingBeforeMigration'
].executeContract(
tgeMain.contracts.vestingAtomLp,
JSON.stringify({
claim: {},
}),
);
expect(resAtom.code).toEqual(0);
const resUsdc = await tgeWallets[
'claimVestingBeforeMigration'
].executeContract(
tgeMain.contracts.vestingUsdcLp,
JSON.stringify({
claim: {},
}),
);
expect(resUsdc.code).toEqual(0);
});
it('should unregister old pairs', async () => {
{
const res = await tge.executeDeregisterPair(
Expand Down Expand Up @@ -1783,19 +1827,18 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {

expect(
parseInt(vestingInfoAtom.info.schedules[0].end_point.amount),
).toBeCloseTo(89394, -1);
).toBeCloseTo(75706, -1);
claimAtomLP = parseInt(
vestingInfoAtom.info.schedules[0].end_point.amount,
);

expect(
parseInt(vestingInfoUsdc.info.schedules[0].end_point.amount),
).toBeCloseTo(18087, -1);
).toBeCloseTo(14197, -1);
claimUsdcLP = parseInt(
vestingInfoUsdc.info.schedules[0].end_point.amount,
);
});

it('should migrate ATOM LP vesing to V2', async () => {
const res = await cmInstantiator.migrateContract(
tgeMain.contracts.vestingAtomLp,
Expand Down Expand Up @@ -1866,6 +1909,13 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
}),
);
expect(resAtom.code).toEqual(0);
resAtom = await cmInstantiator.executeContract(
tgeMain.contracts.vestingAtomLp,
JSON.stringify({
migrate_liquidity: {},
}),
);
expect(resAtom.code).toEqual(0);
await expect(
cmInstantiator.executeContract(
tgeMain.contracts.vestingAtomLp,
Expand Down Expand Up @@ -2642,7 +2692,7 @@ describe('Neutron / TGE / Auction / Lockdrop migration', () => {
rewardsStateAfterClaim.balanceNtrn +
FEE_SIZE -
rewardsStateBeforeClaim.balanceNtrn,
).toBeCloseTo(120212, -3); // lockdrop rewards share for the user
).toBeCloseTo(125978, -3); // lockdrop rewards share for the user

const expectedGeneratorRewards = +(
(
Expand Down