Skip to content

Commit

Permalink
feat: fixing JS package (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase authored Sep 27, 2024
1 parent 6bfed17 commit e19022e
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ js/lib

/node_modules

js/dist
**/wallet.json
4 changes: 4 additions & 0 deletions js/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './instructions';
export * from './main';
export * from './state';
export * from './utils';
1 change: 1 addition & 0 deletions js/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions js/dist/instructions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="node" />
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
import { Schedule } from './state';
export declare enum Instruction {
Init = 0,
Create = 1
}
export declare function createInitInstruction(systemProgramId: PublicKey, vestingProgramId: PublicKey, payerKey: PublicKey, vestingAccountKey: PublicKey, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;
export declare function createCreateInstruction(vestingProgramId: PublicKey, tokenProgramId: PublicKey, clockSysvarId: PublicKey, vestingAccountKey: PublicKey, vestingTokenAccountKey: PublicKey, sourceTokenAccountOwnerKey: PublicKey, sourceTokenAccountKey: PublicKey, mintAddress: PublicKey, schedule: Schedule, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;
export declare function createUnlockInstruction(vestingProgramId: PublicKey, tokenProgramId: PublicKey, clockSysvarId: PublicKey, vestingAccountKey: PublicKey, vestingTokenAccountKey: PublicKey, destinationTokenAccountKey: PublicKey, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;
export declare function createInitializeUnlockInstruction(vestingProgramId: PublicKey, tokenProgramId: PublicKey, clockSysvarId: PublicKey, vestingAccountKey: PublicKey, vestingTokenAccountKey: PublicKey, destinationTokenAccountKey: PublicKey, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;
46 changes: 46 additions & 0 deletions js/dist/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/// <reference types="node" />
import { PublicKey, TransactionInstruction, Connection } from '@solana/web3.js';
import { ContractInfo, Schedule } from './state';
/**
* The vesting schedule program ID on mainnet
*/
export declare const TOKEN_VESTING_PROGRAM_ID: PublicKey;
/**
* This function can be used to lock tokens
* @param connection The Solana RPC connection object
* @param programId The token vesting program ID
* @param seedWord Seed words used to derive the vesting account
* @param payer The fee payer of the transaction
* @param sourceTokenOwner The owner of the source token account (i.e where locked tokens are originating from)
* @param possibleSourceTokenPubkey The source token account (i.e where locked tokens are originating from), if null it defaults to the ATA
* @param destinationTokenPubkey The destination token account i.e where unlocked tokens will be transfered
* @param mintAddress The mint of the tokens being vested
* @param schedule The vesting schedule
* @returns An array of `TransactionInstruction`
*/
export declare function create(connection: Connection, programId: PublicKey, seedWord: Buffer | Uint8Array, payer: PublicKey, sourceTokenOwner: PublicKey, possibleSourceTokenPubkey: PublicKey | null, destinationTokenPubkey: PublicKey, mintAddress: PublicKey, schedule: Schedule): Promise<Array<TransactionInstruction>>;
/**
* This function can be used to unlock vested tokens
* @param connection The Solana RPC connection object
* @param programId The token vesting program ID
* @param seedWord Seed words used to derive the vesting account
* @param mintAddress The mint of the vested tokens
* @returns An array of `TransactionInstruction`
*/
export declare function unlock(connection: Connection, programId: PublicKey, seedWord: Buffer | Uint8Array, mintAddress: PublicKey): Promise<Array<TransactionInstruction>>;
/**
* This function can be used to initialize the unlock of vested tokens
* @param connection The Solana RPC connection object
* @param programId The token vesting program ID
* @param seedWord Seed words used to derive the vesting account
* @param mintAddress The mint of the vested tokens
* @returns An array of `TransactionInstruction`
*/
export declare function initializeUnlock(connection: Connection, programId: PublicKey, seedWord: Buffer | Uint8Array, mintAddress: PublicKey): Promise<Array<TransactionInstruction>>;
/**
* This function can be used retrieve information about a vesting account
* @param connection The Solana RPC connection object
* @param vestingAccountKey The vesting account public key
* @returns A `ContractInfo` object
*/
export declare function getContractInfo(connection: Connection, vestingAccountKey: PublicKey): Promise<ContractInfo>;
24 changes: 24 additions & 0 deletions js/dist/state.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference types="node" />
import { PublicKey } from '@solana/web3.js';
import { Numberu64 } from './utils';
export declare class Schedule {
timeDelta: Numberu64;
amount: Numberu64;
constructor(timeDelta: Numberu64, amount: Numberu64);
toBuffer(): Buffer;
static fromBuffer(buf: Buffer): Schedule;
}
export declare class VestingScheduleHeader {
destinationAddress: PublicKey;
mintAddress: PublicKey;
isInitialized: boolean;
constructor(destinationAddress: PublicKey, mintAddress: PublicKey, isInitialized: boolean);
static fromBuffer(buf: Buffer): VestingScheduleHeader;
}
export declare class ContractInfo {
destinationAddress: PublicKey;
mintAddress: PublicKey;
schedules: Array<Schedule>;
constructor(destinationAddress: PublicKey, mintAddress: PublicKey, schedules: Array<Schedule>);
static fromBuffer(buf: Buffer): ContractInfo | undefined;
}
23 changes: 23 additions & 0 deletions js/dist/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference types="node" />
import BN from 'bn.js';
export declare const generateRandomSeed: () => string;
export declare class Numberu64 extends BN {
/**
* Convert to Buffer representation
*/
toBuffer(): Buffer;
/**
* Construct a Numberu64 from Buffer representation
*/
static fromBuffer(buffer: any): any;
}
export declare class Numberu32 extends BN {
/**
* Convert to Buffer representation
*/
toBuffer(): Buffer;
/**
* Construct a Numberu32 from Buffer representation
*/
static fromBuffer(buffer: any): any;
}
2 changes: 0 additions & 2 deletions js/src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export function createCreateInstruction(
vestingTokenAccountKey: PublicKey,
sourceTokenAccountOwnerKey: PublicKey,
sourceTokenAccountKey: PublicKey,
destinationTokenAccountKey: PublicKey,
mintAddress: PublicKey,
schedule: Schedule,
seeds: Array<Buffer | Uint8Array>,
Expand All @@ -68,7 +67,6 @@ export function createCreateInstruction(
Buffer.from(Int8Array.from([1]).buffer),
Buffer.concat(seeds),
mintAddress.toBuffer(),
destinationTokenAccountKey.toBuffer(),
];

buffers.push(schedule.toBuffer());
Expand Down
1 change: 0 additions & 1 deletion js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export async function create(
vestingTokenAccountKey,
sourceTokenOwner,
possibleSourceTokenPubkey,
destinationTokenPubkey,
mintAddress,
schedule,
[seedWord],
Expand Down
2 changes: 1 addition & 1 deletion program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Processor {
release_time = clock.unix_timestamp as u64 + schedule.time_delta;
}
_ => {
msg!("Unsupported time delta");
msg!("Unsupported time delta: {}", schedule.time_delta);
return Err(ProgramError::InvalidInstructionData);
}
}
Expand Down

0 comments on commit e19022e

Please sign in to comment.