Skip to content

Commit

Permalink
feat: migrate msig
Browse files Browse the repository at this point in the history
  • Loading branch information
theblockstalk committed Sep 16, 2024
1 parent 92add6b commit 255bcfe
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/cli/msig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { addAuth } from './addAuth';
import { deployContract } from './deployContract';
import { addEosioCode } from './addEosioCode';
import { printCliHelp } from '..';
import { vestingMigrate } from './vestingMigrateAllocate';

const eosioMsigContract = EosioMsigContract.Instance;

Expand Down Expand Up @@ -149,6 +150,17 @@ export default async function msig(args: string[]) {
test,
}
);
} else if (proposalType === 'vesting-migrate') {
await vestingMigrate(
{},
{
proposer,
proposalName,
privateKey,
requested: newGovernanceAccounts,
test,
}
);
} else if (proposalType === 'vesting-bulk') {
const csvFilePath = '/home/dev/Downloads/allocate.csv';

Expand Down
108 changes: 108 additions & 0 deletions src/cli/msig/vestingMigrateAllocate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { NameType } from '@wharfkit/antelope';
import { StandardProposalOptions, createProposal, executeProposal } from '.';
import { ActionData, assetToAmount, VestingContract } from '../../sdk/services/blockchain';

// @ts-expect-error args unused
export async function vestingMigrate(args: {}, options: StandardProposalOptions) {
const migrateAccounts = [''];

const actions: ActionData[] = [];

for (const account of migrateAccounts) {
const accountActions = await createAccountActions(account);

actions.push(...accountActions);
}

const proposalHash = await createProposal(
options.proposer,
options.proposalName,
actions,
options.privateKey,
options.requested
);

if (options.test) await executeProposal(options.proposer, options.proposalName, proposalHash);
}

async function createAccountActions(account: NameType): Promise<ActionData[]> {
const allocations = await VestingContract.Instance.getAllocations(account);

const actions: ActionData[] = [];

for (const allocation of allocations) {
const oldCategory = allocation.vesting_category_type;

let newCategory = 8;
let newAmount = 0;

if (oldCategory === 1 || oldCategory === 2) {
if (oldCategory === 1) {
const oldLeosPrice = 0.002;
const newLeosPrice = 0.0005;
const amount = assetToAmount(allocation.tokens_allocated);

newAmount = (amount * oldLeosPrice) / newLeosPrice;
} else {
const oldLeosPrice = 0.004;
const newLeosPrice = 0.001;
const amount = assetToAmount(allocation.tokens_allocated);

newAmount = (amount * oldLeosPrice) / newLeosPrice;

newCategory = 9;
}

const oldAmount = allocation.tokens_allocated;
const newAsset = `${newAmount.toFixed(6)} LEOS`;

actions.push(
createMigrateAction(
'coinsale.tmy',
account.toString(),
allocation.id,
oldAmount,
newAsset,
oldCategory,
newCategory
)
);
}
}

return actions;
}

function createMigrateAction(
sender: string,
holder: string,
allocationId: number,
oldAmount: string,
newAmount: string,
oldCategoryId: number,
newCategoryId: number
) {
return {
account: 'vesting.tmy',
name: 'migratealloc',
authorization: [
{
actor: sender,
permission: 'owner',
},
{
actor: 'vesting.tmy',
permission: 'active',
},
],
data: {
sender,
holder,
allocation_id: allocationId,
old_amount: oldAmount,
new_amount: newAmount,
old_category_id: oldCategoryId,
new_category_id: newCategoryId,
},
};
}
4 changes: 4 additions & 0 deletions src/sdk/services/blockchain/contracts/EosioTokenContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { getSettings } from '../../../util';

const CONTRACT_NAME = 'eosio.token';

export function assetToAmount(asset: string): number {
return parseFloat(asset.split(' ')[0]);
}

class EosioTokenContract {
static singletonInstande: EosioTokenContract;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Authority,
EosioTokenContract,
Signer,
assetToAmount,
createKeyManagerSigner,
createSigner,
getTonomyOperationsKey,
Expand All @@ -22,10 +23,6 @@ const vestingContract = VestingContract.Instance;
const eosioTokenContract = EosioTokenContract.Instance;
const signer = createSigner(getTonomyOperationsKey());

function assetToAmount(asset: string): number {
return parseFloat(asset.split(' ')[0]);
}

describe('VestingContract class', () => {
jest.setTimeout(60000);
let saleStartDate: Date;
Expand Down

0 comments on commit 255bcfe

Please sign in to comment.