Skip to content

Commit

Permalink
fix: updating js scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Oct 6, 2024
1 parent 8d1225c commit 9094e72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 40 deletions.
7 changes: 1 addition & 6 deletions js/src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ export function createCreateInstruction(
vestingTokenAccountKey: PublicKey,
sourceTokenAccountOwnerKey: PublicKey,
sourceTokenAccountKey: PublicKey,
mintAddress: PublicKey,
schedule: CreateSchedule,
seeds: Array<Buffer | Uint8Array>,
): TransactionInstruction {
let buffers = [
Buffer.from(Int8Array.from([1]).buffer),
Buffer.concat(seeds),
mintAddress.toBuffer(),
];
let buffers = [Buffer.from(Int8Array.from([1]).buffer), Buffer.concat(seeds)];

buffers.push(schedule.toBuffer());

Expand Down
20 changes: 10 additions & 10 deletions js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import bs58 from 'bs58';
* TODO: replace with mainnet ID
*/
export const TOKEN_VESTING_PROGRAM_ID = new PublicKey(
'3F15CLnQjHqMCHLn2g7vuDULiRuJDiEMSZQXMoVVUGtA',
'HGhyAuNiYRa6oN55eGGP1MYGVve7epwT8WX6qbWxgYxM',
);

export const TOKEN_MINT = new PublicKey(
'EWMA3o2kHLpsVYvmjtvYRywHrXD84sLxFb42seUShxAD',
);

/**
Expand All @@ -46,13 +50,12 @@ export async function create(
seedWord: Buffer | Uint8Array,
payer: PublicKey,
possibleSourceTokenPubkey: PublicKey | null,
mintAddress: PublicKey,
schedule: CreateSchedule,
): Promise<Array<TransactionInstruction>> {
// If no source token account was given, use the associated source account
if (possibleSourceTokenPubkey == null) {
possibleSourceTokenPubkey = await getAssociatedTokenAddress(
mintAddress,
TOKEN_MINT,
payer,
true,
);
Expand All @@ -66,7 +69,7 @@ export async function create(
);

const vestingTokenAccountKey = await getAssociatedTokenAddress(
mintAddress,
TOKEN_MINT,
vestingAccountKey,
true,
);
Expand Down Expand Up @@ -97,7 +100,7 @@ export async function create(
payer,
vestingTokenAccountKey,
vestingAccountKey,
mintAddress,
TOKEN_MINT,
),
createCreateInstruction(
programId,
Expand All @@ -107,7 +110,6 @@ export async function create(
vestingTokenAccountKey,
payer,
possibleSourceTokenPubkey,
mintAddress,
schedule,
[seedWord],
),
Expand All @@ -127,7 +129,6 @@ export async function unlock(
connection: Connection,
programId: PublicKey,
seedWord: Buffer | Uint8Array,
mintAddress: PublicKey,
): Promise<Array<TransactionInstruction>> {
seedWord = seedWord.slice(0, 31);
const [vestingAccountKey, bump] = await PublicKey.findProgramAddress(
Expand All @@ -137,7 +138,7 @@ export async function unlock(
seedWord = Buffer.from(seedWord.toString('hex') + bump.toString(16), 'hex');

const vestingTokenAccountKey = await getAssociatedTokenAddress(
mintAddress,
TOKEN_MINT,
vestingAccountKey,
true,
);
Expand Down Expand Up @@ -171,7 +172,6 @@ export async function initializeUnlock(
connection: Connection,
programId: PublicKey,
seedWord: Buffer | Uint8Array,
mintAddress: PublicKey,
): Promise<Array<TransactionInstruction>> {
seedWord = seedWord.slice(0, 31);
const [vestingAccountKey, bump] = await PublicKey.findProgramAddress(
Expand All @@ -181,7 +181,7 @@ export async function initializeUnlock(
seedWord = Buffer.from(seedWord.toString('hex') + bump.toString(16), 'hex');

const vestingTokenAccountKey = await getAssociatedTokenAddress(
mintAddress,
TOKEN_MINT,
vestingAccountKey,
true,
);
Expand Down
30 changes: 6 additions & 24 deletions js/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,18 @@ export class Schedule {

export class VestingScheduleHeader {
destinationAddress!: PublicKey;
mintAddress!: PublicKey;
isInitialized!: boolean;

constructor(
destinationAddress: PublicKey,
mintAddress: PublicKey,
isInitialized: boolean,
) {
constructor(destinationAddress: PublicKey, isInitialized: boolean) {
this.destinationAddress = destinationAddress;
this.mintAddress = mintAddress;
this.isInitialized = isInitialized;
}

static fromBuffer(buf: Buffer): VestingScheduleHeader {
const destinationAddress = new PublicKey(buf.slice(0, 32));
const mintAddress = new PublicKey(buf.slice(32, 64));
const isInitialized = buf[64] == 1;
const isInitialized = buf[32] == 1;
const header: VestingScheduleHeader = {
destinationAddress,
mintAddress,
isInitialized,
};
return header;
Expand All @@ -73,29 +65,19 @@ export class VestingScheduleHeader {

export class ContractInfo {
destinationAddress!: PublicKey;
mintAddress!: PublicKey;
schedule!: Schedule;

constructor(
destinationAddress: PublicKey,
mintAddress: PublicKey,
schedule: Schedule,
) {
constructor(destinationAddress: PublicKey, schedule: Schedule) {
this.destinationAddress = destinationAddress;
this.mintAddress = mintAddress;
this.schedule = schedule;
}

static fromBuffer(buf: Buffer): ContractInfo | undefined {
const header = VestingScheduleHeader.fromBuffer(buf.slice(0, 65));
const header = VestingScheduleHeader.fromBuffer(buf.slice(0, 33));
if (!header.isInitialized) {
return undefined;
}
const schedule = Schedule.fromBuffer(buf.slice(65, 81));
return new ContractInfo(
header.destinationAddress,
header.mintAddress,
schedule,
);
const schedule = Schedule.fromBuffer(buf.slice(33, 49));
return new ContractInfo(header.destinationAddress, schedule);
}
}

0 comments on commit 9094e72

Please sign in to comment.