Repository navigation
Expand file tree
/
Copy pathstate.ts
More file actions
83 lines (73 loc) · 2.19 KB
/
Copy pathstate.ts
File metadata and controls
83 lines (73 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { PublicKey } from '@solana/web3.js';
import { Numberu64 } from './utils';
export class Schedule {
// Release time in unix timestamp
releaseTime!: Numberu64;
amount!: Numberu64;
constructor(releaseTime: Numberu64, amount: Numberu64) {
this.releaseTime = releaseTime;
this.amount = amount;
}
public toBuffer(): Buffer {
return Buffer.concat([this.releaseTime.toBuffer(), this.amount.toBuffer()]);
}
static fromBuffer(buf: Buffer): Schedule {
const releaseTime: Numberu64 = Numberu64.fromBuffer(buf.slice(0, 8));
const amount: Numberu64 = Numberu64.fromBuffer(buf.slice(8, 16));
return new Schedule(releaseTime, amount);
}
}
export class VestingScheduleHeader {
destinationAddress!: PublicKey;
mintAddress!: PublicKey;
isInitialized!: boolean;
constructor(
destinationAddress: PublicKey,
mintAddress: 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 header: VestingScheduleHeader = {
destinationAddress,
mintAddress,
isInitialized,
};
return header;
}
}
export class ContractInfo {
destinationAddress!: PublicKey;
mintAddress!: PublicKey;
schedules!: Array<Schedule>;
constructor(
destinationAddress: PublicKey,
mintAddress: PublicKey,
schedules: Array<Schedule>,
) {
this.destinationAddress = destinationAddress;
this.mintAddress = mintAddress;
this.schedules = schedules;
}
static fromBuffer(buf: Buffer): ContractInfo | undefined {
const header = VestingScheduleHeader.fromBuffer(buf.slice(0, 65));
if (!header.isInitialized) {
return undefined;
}
const schedules: Array<Schedule> = [];
for (let i = 65; i < buf.length; i += 16) {
schedules.push(Schedule.fromBuffer(buf.slice(i, i + 16)));
}
return new ContractInfo(
header.destinationAddress,
header.mintAddress,
schedules,
);
}
}