Skip to content

Commit 815d446

Browse files
authored
chore: release candidate (failing tests) (#9)
1 parent ed2f662 commit 815d446

File tree

17 files changed

+407
-265
lines changed

17 files changed

+407
-265
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ js/lib
77

88
/node_modules
99

10-
js/dist
1110
**/wallet.json

js/dist/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './instructions';
2+
export * from './main';
3+
export * from './state';
4+
export * from './utils';

js/dist/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/instructions.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="node" />
2+
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
3+
import { Schedule } from './state';
4+
export declare enum Instruction {
5+
Init = 0,
6+
Create = 1
7+
}
8+
export declare function createInitInstruction(systemProgramId: PublicKey, vestingProgramId: PublicKey, payerKey: PublicKey, vestingAccountKey: PublicKey, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;
9+
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;
10+
export declare function createUnlockInstruction(vestingProgramId: PublicKey, tokenProgramId: PublicKey, clockSysvarId: PublicKey, vestingAccountKey: PublicKey, vestingTokenAccountKey: PublicKey, destinationTokenAccountKey: PublicKey, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;
11+
export declare function createInitializeUnlockInstruction(vestingProgramId: PublicKey, tokenProgramId: PublicKey, clockSysvarId: PublicKey, vestingAccountKey: PublicKey, vestingTokenAccountKey: PublicKey, destinationTokenAccountKey: PublicKey, seeds: Array<Buffer | Uint8Array>): TransactionInstruction;

js/dist/main.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// <reference types="node" />
2+
import { PublicKey, TransactionInstruction, Connection } from '@solana/web3.js';
3+
import { ContractInfo, Schedule } from './state';
4+
/**
5+
* The vesting schedule program ID on mainnet
6+
*/
7+
export declare const TOKEN_VESTING_PROGRAM_ID: PublicKey;
8+
/**
9+
* This function can be used to lock tokens
10+
* @param connection The Solana RPC connection object
11+
* @param programId The token vesting program ID
12+
* @param seedWord Seed words used to derive the vesting account
13+
* @param payer The fee payer of the transaction
14+
* @param sourceTokenOwner The owner of the source token account (i.e where locked tokens are originating from)
15+
* @param possibleSourceTokenPubkey The source token account (i.e where locked tokens are originating from), if null it defaults to the ATA
16+
* @param destinationTokenPubkey The destination token account i.e where unlocked tokens will be transfered
17+
* @param mintAddress The mint of the tokens being vested
18+
* @param schedule The vesting schedule
19+
* @returns An array of `TransactionInstruction`
20+
*/
21+
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>>;
22+
/**
23+
* This function can be used to unlock vested tokens
24+
* @param connection The Solana RPC connection object
25+
* @param programId The token vesting program ID
26+
* @param seedWord Seed words used to derive the vesting account
27+
* @param mintAddress The mint of the vested tokens
28+
* @returns An array of `TransactionInstruction`
29+
*/
30+
export declare function unlock(connection: Connection, programId: PublicKey, seedWord: Buffer | Uint8Array, mintAddress: PublicKey): Promise<Array<TransactionInstruction>>;
31+
/**
32+
* This function can be used to initialize the unlock of vested tokens
33+
* @param connection The Solana RPC connection object
34+
* @param programId The token vesting program ID
35+
* @param seedWord Seed words used to derive the vesting account
36+
* @param mintAddress The mint of the vested tokens
37+
* @returns An array of `TransactionInstruction`
38+
*/
39+
export declare function initializeUnlock(connection: Connection, programId: PublicKey, seedWord: Buffer | Uint8Array, mintAddress: PublicKey): Promise<Array<TransactionInstruction>>;
40+
/**
41+
* This function can be used retrieve information about a vesting account
42+
* @param connection The Solana RPC connection object
43+
* @param vestingAccountKey The vesting account public key
44+
* @returns A `ContractInfo` object
45+
*/
46+
export declare function getContractInfo(connection: Connection, vestingAccountKey: PublicKey): Promise<ContractInfo>;

js/dist/state.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference types="node" />
2+
import { PublicKey } from '@solana/web3.js';
3+
import { Numberu64 } from './utils';
4+
export declare class Schedule {
5+
timeDelta: Numberu64;
6+
amount: Numberu64;
7+
constructor(timeDelta: Numberu64, amount: Numberu64);
8+
toBuffer(): Buffer;
9+
static fromBuffer(buf: Buffer): Schedule;
10+
}
11+
export declare class VestingScheduleHeader {
12+
destinationAddress: PublicKey;
13+
mintAddress: PublicKey;
14+
isInitialized: boolean;
15+
constructor(destinationAddress: PublicKey, mintAddress: PublicKey, isInitialized: boolean);
16+
static fromBuffer(buf: Buffer): VestingScheduleHeader;
17+
}
18+
export declare class ContractInfo {
19+
destinationAddress: PublicKey;
20+
mintAddress: PublicKey;
21+
schedules: Array<Schedule>;
22+
constructor(destinationAddress: PublicKey, mintAddress: PublicKey, schedules: Array<Schedule>);
23+
static fromBuffer(buf: Buffer): ContractInfo | undefined;
24+
}

js/dist/utils.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference types="node" />
2+
import BN from 'bn.js';
3+
export declare const generateRandomSeed: () => string;
4+
export declare class Numberu64 extends BN {
5+
/**
6+
* Convert to Buffer representation
7+
*/
8+
toBuffer(): Buffer;
9+
/**
10+
* Construct a Numberu64 from Buffer representation
11+
*/
12+
static fromBuffer(buffer: any): any;
13+
}
14+
export declare class Numberu32 extends BN {
15+
/**
16+
* Convert to Buffer representation
17+
*/
18+
toBuffer(): Buffer;
19+
/**
20+
* Construct a Numberu32 from Buffer representation
21+
*/
22+
static fromBuffer(buffer: any): any;
23+
}

js/src/example.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const DECIMALS = 0;
3434
const SOURCE_TOKEN_ACCOUNT = new PublicKey('');
3535

3636
/** Amount to give per schedule */
37-
const AMOUNT_PER_SCHEDULE = 0;
37+
const LOCKED_AMOUNT = 0;
3838

3939
/** Your RPC connection */
4040
const connection = new Connection('');
@@ -64,10 +64,10 @@ const lock = async () => {
6464
const schedule: Schedule = new Schedule(
6565
/** Has to be in seconds */
6666
// @ts-ignore
67-
new Numberu64(DATE.getTime() / 1_000),
67+
new Numberu64(60),
6868
/** Don't forget to add decimals */
6969
// @ts-ignore
70-
new Numberu64(AMOUNT_PER_SCHEDULE * Math.pow(10, DECIMALS)),
70+
new Numberu64(LOCKED_AMOUNT * Math.pow(10, DECIMALS)),
7171
);
7272
const seed = generateRandomSeed();
7373

js/src/instructions.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { PublicKey, SYSVAR_RENT_PUBKEY, TransactionInstruction } from '@solana/web3.js';
1+
import {
2+
PublicKey,
3+
SYSVAR_RENT_PUBKEY,
4+
TransactionInstruction,
5+
} from '@solana/web3.js';
26
import { Schedule } from './state';
37
import { Numberu32 } from './utils';
48

@@ -12,12 +16,9 @@ export function createInitInstruction(
1216
vestingProgramId: PublicKey,
1317
payerKey: PublicKey,
1418
vestingAccountKey: PublicKey,
15-
seeds: Array<Buffer | Uint8Array>
19+
seeds: Array<Buffer | Uint8Array>,
1620
): TransactionInstruction {
17-
let buffers = [
18-
Buffer.from(Int8Array.from([0]).buffer),
19-
Buffer.concat(seeds),
20-
];
21+
let buffers = [Buffer.from(Int8Array.from([0]).buffer), Buffer.concat(seeds)];
2122

2223
const data = Buffer.concat(buffers);
2324
const keys = [
@@ -53,11 +54,11 @@ export function createInitInstruction(
5354
export function createCreateInstruction(
5455
vestingProgramId: PublicKey,
5556
tokenProgramId: PublicKey,
57+
clockSysvarId: PublicKey,
5658
vestingAccountKey: PublicKey,
5759
vestingTokenAccountKey: PublicKey,
5860
sourceTokenAccountOwnerKey: PublicKey,
5961
sourceTokenAccountKey: PublicKey,
60-
destinationTokenAccountKey: PublicKey,
6162
mintAddress: PublicKey,
6263
schedule: Schedule,
6364
seeds: Array<Buffer | Uint8Array>,
@@ -66,7 +67,6 @@ export function createCreateInstruction(
6667
Buffer.from(Int8Array.from([1]).buffer),
6768
Buffer.concat(seeds),
6869
mintAddress.toBuffer(),
69-
destinationTokenAccountKey.toBuffer(),
7070
];
7171

7272
buffers.push(schedule.toBuffer());
@@ -78,6 +78,11 @@ export function createCreateInstruction(
7878
isSigner: false,
7979
isWritable: false,
8080
},
81+
{
82+
pubkey: clockSysvarId,
83+
isSigner: false,
84+
isWritable: false,
85+
},
8186
{
8287
pubkey: vestingAccountKey,
8388
isSigner: false,

js/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function create(
9393
programId,
9494
payer,
9595
vestingAccountKey,
96-
[seedWord]
96+
[seedWord],
9797
),
9898
createAssociatedTokenAccountInstruction(
9999
payer,
@@ -104,11 +104,11 @@ export async function create(
104104
createCreateInstruction(
105105
programId,
106106
TOKEN_PROGRAM_ID,
107+
SYSVAR_CLOCK_PUBKEY,
107108
vestingAccountKey,
108109
vestingTokenAccountKey,
109110
sourceTokenOwner,
110111
possibleSourceTokenPubkey,
111-
destinationTokenPubkey,
112112
mintAddress,
113113
schedule,
114114
[seedWord],
@@ -228,4 +228,4 @@ export async function getContractInfo(
228228
throw new Error('Vesting contract account is not initialized');
229229
}
230230
return info!;
231-
}
231+
}

js/src/state.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { Numberu64 } from './utils';
33

44
export class Schedule {
55
// Release time in unix timestamp
6-
releaseTime!: Numberu64;
6+
timeDelta!: Numberu64;
77
amount!: Numberu64;
88

9-
constructor(releaseTime: Numberu64, amount: Numberu64) {
10-
this.releaseTime = releaseTime;
9+
constructor(timeDelta: Numberu64, amount: Numberu64) {
10+
this.timeDelta = timeDelta;
1111
this.amount = amount;
1212
}
1313

1414
public toBuffer(): Buffer {
15-
return Buffer.concat([this.releaseTime.toBuffer(), this.amount.toBuffer()]);
15+
return Buffer.concat([this.timeDelta.toBuffer(), this.amount.toBuffer()]);
1616
}
1717

1818
static fromBuffer(buf: Buffer): Schedule {
19-
const releaseTime: Numberu64 = Numberu64.fromBuffer(buf.slice(0, 8));
19+
const timeDelta: Numberu64 = Numberu64.fromBuffer(buf.slice(0, 8));
2020
const amount: Numberu64 = Numberu64.fromBuffer(buf.slice(8, 16));
21-
return new Schedule(releaseTime, amount);
21+
return new Schedule(timeDelta, amount);
2222
}
2323
}
2424

0 commit comments

Comments
 (0)