Skip to content

Commit

Permalink
chore: release candidate (failing tests) (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase authored Sep 27, 2024
1 parent ed2f662 commit 815d446
Show file tree
Hide file tree
Showing 17 changed files with 407 additions and 265 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;
}
6 changes: 3 additions & 3 deletions js/src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const DECIMALS = 0;
const SOURCE_TOKEN_ACCOUNT = new PublicKey('');

/** Amount to give per schedule */
const AMOUNT_PER_SCHEDULE = 0;
const LOCKED_AMOUNT = 0;

/** Your RPC connection */
const connection = new Connection('');
Expand Down Expand Up @@ -64,10 +64,10 @@ const lock = async () => {
const schedule: Schedule = new Schedule(
/** Has to be in seconds */
// @ts-ignore
new Numberu64(DATE.getTime() / 1_000),
new Numberu64(60),
/** Don't forget to add decimals */
// @ts-ignore
new Numberu64(AMOUNT_PER_SCHEDULE * Math.pow(10, DECIMALS)),
new Numberu64(LOCKED_AMOUNT * Math.pow(10, DECIMALS)),
);
const seed = generateRandomSeed();

Expand Down
21 changes: 13 additions & 8 deletions js/src/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PublicKey, SYSVAR_RENT_PUBKEY, TransactionInstruction } from '@solana/web3.js';
import {
PublicKey,
SYSVAR_RENT_PUBKEY,
TransactionInstruction,
} from '@solana/web3.js';
import { Schedule } from './state';
import { Numberu32 } from './utils';

Expand All @@ -12,12 +16,9 @@ export function createInitInstruction(
vestingProgramId: PublicKey,
payerKey: PublicKey,
vestingAccountKey: PublicKey,
seeds: Array<Buffer | Uint8Array>
seeds: Array<Buffer | Uint8Array>,
): TransactionInstruction {
let buffers = [
Buffer.from(Int8Array.from([0]).buffer),
Buffer.concat(seeds),
];
let buffers = [Buffer.from(Int8Array.from([0]).buffer), Buffer.concat(seeds)];

const data = Buffer.concat(buffers);
const keys = [
Expand Down Expand Up @@ -53,11 +54,11 @@ export function createInitInstruction(
export function createCreateInstruction(
vestingProgramId: PublicKey,
tokenProgramId: PublicKey,
clockSysvarId: PublicKey,
vestingAccountKey: PublicKey,
vestingTokenAccountKey: PublicKey,
sourceTokenAccountOwnerKey: PublicKey,
sourceTokenAccountKey: PublicKey,
destinationTokenAccountKey: PublicKey,
mintAddress: PublicKey,
schedule: Schedule,
seeds: Array<Buffer | Uint8Array>,
Expand All @@ -66,7 +67,6 @@ export function createCreateInstruction(
Buffer.from(Int8Array.from([1]).buffer),
Buffer.concat(seeds),
mintAddress.toBuffer(),
destinationTokenAccountKey.toBuffer(),
];

buffers.push(schedule.toBuffer());
Expand All @@ -78,6 +78,11 @@ export function createCreateInstruction(
isSigner: false,
isWritable: false,
},
{
pubkey: clockSysvarId,
isSigner: false,
isWritable: false,
},
{
pubkey: vestingAccountKey,
isSigner: false,
Expand Down
6 changes: 3 additions & 3 deletions js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function create(
programId,
payer,
vestingAccountKey,
[seedWord]
[seedWord],
),
createAssociatedTokenAccountInstruction(
payer,
Expand All @@ -104,11 +104,11 @@ export async function create(
createCreateInstruction(
programId,
TOKEN_PROGRAM_ID,
SYSVAR_CLOCK_PUBKEY,
vestingAccountKey,
vestingTokenAccountKey,
sourceTokenOwner,
possibleSourceTokenPubkey,
destinationTokenPubkey,
mintAddress,
schedule,
[seedWord],
Expand Down Expand Up @@ -228,4 +228,4 @@ export async function getContractInfo(
throw new Error('Vesting contract account is not initialized');
}
return info!;
}
}
12 changes: 6 additions & 6 deletions js/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { Numberu64 } from './utils';

export class Schedule {
// Release time in unix timestamp
releaseTime!: Numberu64;
timeDelta!: Numberu64;
amount!: Numberu64;

constructor(releaseTime: Numberu64, amount: Numberu64) {
this.releaseTime = releaseTime;
constructor(timeDelta: Numberu64, amount: Numberu64) {
this.timeDelta = timeDelta;
this.amount = amount;
}

public toBuffer(): Buffer {
return Buffer.concat([this.releaseTime.toBuffer(), this.amount.toBuffer()]);
return Buffer.concat([this.timeDelta.toBuffer(), this.amount.toBuffer()]);
}

static fromBuffer(buf: Buffer): Schedule {
const releaseTime: Numberu64 = Numberu64.fromBuffer(buf.slice(0, 8));
const timeDelta: Numberu64 = Numberu64.fromBuffer(buf.slice(0, 8));
const amount: Numberu64 = Numberu64.fromBuffer(buf.slice(8, 16));
return new Schedule(releaseTime, amount);
return new Schedule(timeDelta, amount);
}
}

Expand Down
Loading

0 comments on commit 815d446

Please sign in to comment.