@5ive-tech/sdk 1.1.7 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FiveSDK.d.ts +17 -0
- package/dist/FiveSDK.js +11 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +5 -5
- package/dist/config/ProgramIdResolver.d.ts +1 -1
- package/dist/config/ProgramIdResolver.js +1 -1
- package/dist/crypto/index.js +2 -10
- package/dist/modules/admin.d.ts +121 -0
- package/dist/modules/admin.js +327 -0
- package/dist/modules/deploy.d.ts +17 -0
- package/dist/modules/deploy.js +294 -241
- package/dist/modules/execute.d.ts +4 -0
- package/dist/modules/execute.js +104 -94
- package/dist/modules/fees.d.ts +2 -0
- package/dist/modules/fees.js +21 -19
- package/dist/modules/vm-state.d.ts +4 -0
- package/dist/modules/vm-state.js +9 -2
- package/dist/testing/AccountTestFixture.js +3 -3
- package/dist/testing/TestDiscovery.d.ts +6 -0
- package/dist/testing/TestDiscovery.js +62 -57
- package/dist/testing/TestRunner.d.ts +1 -1
- package/dist/testing/TestRunner.js +62 -41
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/package.json +2 -1
- package/dist/assets/vm/dummy.file +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.js +0 -3307
package/dist/FiveSDK.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { FiveSDKConfig, FiveScriptSource, FiveBytecode, CompilationOptions, CompilationResult, DeploymentOptions, SerializedDeployment, SerializedExecution, FiveCompiledFile, FunctionNameEntry, FeeInformation } from "./types.js";
|
|
5
5
|
import { ScriptMetadata } from "./metadata/index.js";
|
|
6
6
|
import * as Namespaces from "./modules/namespaces.js";
|
|
7
|
+
import * as Admin from "./modules/admin.js";
|
|
7
8
|
/**
|
|
8
9
|
* Main Five SDK class - entry point for all Five VM interactions
|
|
9
10
|
*/
|
|
@@ -14,6 +15,16 @@ export declare class FiveSDK {
|
|
|
14
15
|
private fiveVMProgramId?;
|
|
15
16
|
private debug;
|
|
16
17
|
private network?;
|
|
18
|
+
static admin: {
|
|
19
|
+
generateInitializeVmStateInstruction: typeof Admin.generateInitializeVmStateInstruction;
|
|
20
|
+
generateSetFeesInstruction: typeof Admin.generateSetFeesInstruction;
|
|
21
|
+
generateInitFeeVaultInstruction: typeof Admin.generateInitFeeVaultInstruction;
|
|
22
|
+
generateWithdrawScriptFeesInstruction: typeof Admin.generateWithdrawScriptFeesInstruction;
|
|
23
|
+
initializeVmStateOnSolana: typeof Admin.initializeVmStateOnSolana;
|
|
24
|
+
setFeesOnSolana: typeof Admin.setFeesOnSolana;
|
|
25
|
+
initFeeVaultOnSolana: typeof Admin.initFeeVaultOnSolana;
|
|
26
|
+
withdrawScriptFeesOnSolana: typeof Admin.withdrawScriptFeesOnSolana;
|
|
27
|
+
};
|
|
17
28
|
constructor(config?: FiveSDKConfig);
|
|
18
29
|
getConfig(): FiveSDKConfig & {
|
|
19
30
|
network?: string;
|
|
@@ -168,11 +179,17 @@ export declare class FiveSDK {
|
|
|
168
179
|
static getVMState(connection: any, fiveVMProgramId?: string): Promise<{
|
|
169
180
|
authority: string;
|
|
170
181
|
scriptCount: number;
|
|
182
|
+
deployFeeLamports: number;
|
|
183
|
+
executeFeeLamports: number;
|
|
171
184
|
deployFeeBps: number;
|
|
172
185
|
executeFeeBps: number;
|
|
186
|
+
feeVaultShardCount: number;
|
|
187
|
+
vmStateBump: number;
|
|
173
188
|
isInitialized: boolean;
|
|
174
189
|
}>;
|
|
175
190
|
static getFees(connection: any, fiveVMProgramId?: string): Promise<{
|
|
191
|
+
deployFeeLamports: number;
|
|
192
|
+
executeFeeLamports: number;
|
|
176
193
|
deployFeeBps: number;
|
|
177
194
|
executeFeeBps: number;
|
|
178
195
|
adminAccount: string | null;
|
package/dist/FiveSDK.js
CHANGED
|
@@ -15,6 +15,7 @@ import * as VMState from "./modules/vm-state.js";
|
|
|
15
15
|
import * as Accounts from "./modules/accounts.js";
|
|
16
16
|
import * as StateDiff from "./modules/state-diff.js";
|
|
17
17
|
import * as Namespaces from "./modules/namespaces.js";
|
|
18
|
+
import * as Admin from "./modules/admin.js";
|
|
18
19
|
/**
|
|
19
20
|
* Main Five SDK class - entry point for all Five VM interactions
|
|
20
21
|
*/
|
|
@@ -389,6 +390,16 @@ export class FiveSDK {
|
|
|
389
390
|
FiveSDK.compiler = null;
|
|
390
391
|
FiveSDK.parameterEncoder = null;
|
|
391
392
|
FiveSDK.metadataCache = new MetadataCache();
|
|
393
|
+
FiveSDK.admin = {
|
|
394
|
+
generateInitializeVmStateInstruction: Admin.generateInitializeVmStateInstruction,
|
|
395
|
+
generateSetFeesInstruction: Admin.generateSetFeesInstruction,
|
|
396
|
+
generateInitFeeVaultInstruction: Admin.generateInitFeeVaultInstruction,
|
|
397
|
+
generateWithdrawScriptFeesInstruction: Admin.generateWithdrawScriptFeesInstruction,
|
|
398
|
+
initializeVmStateOnSolana: Admin.initializeVmStateOnSolana,
|
|
399
|
+
setFeesOnSolana: Admin.setFeesOnSolana,
|
|
400
|
+
initFeeVaultOnSolana: Admin.initFeeVaultOnSolana,
|
|
401
|
+
withdrawScriptFeesOnSolana: Admin.withdrawScriptFeesOnSolana,
|
|
402
|
+
};
|
|
392
403
|
// Export helper functions
|
|
393
404
|
export const createFiveSDK = (config) => new FiveSDK(config);
|
|
394
405
|
// Export default
|
|
Binary file
|
|
@@ -227,19 +227,19 @@ export const bytecodeencoder_encoded_size_u32: (a: number) => number;
|
|
|
227
227
|
export const bytecodeencoder_encoded_size_u16: (a: number) => number;
|
|
228
228
|
export const parameterencoder_encode_execute: (a: number, b: number, c: number) => void;
|
|
229
229
|
export const get_wasm_compiler_info: () => number;
|
|
230
|
-
export const __wbg_set_wasmsuggestion_confidence: (a: number, b: number) => void;
|
|
231
|
-
export const __wbg_set_wasmenhancedcompilationresult_compilation_time: (a: number, b: number) => void;
|
|
232
|
-
export const __wbg_set_wasmcompilationwithmetrics_compilation_time: (a: number, b: number) => void;
|
|
233
|
-
export const __wbg_set_wasmcompilationresult_compilation_time: (a: number, b: number) => void;
|
|
234
230
|
export const __wbg_get_wasmsuggestion_confidence: (a: number) => number;
|
|
235
231
|
export const __wbg_get_wasmenhancedcompilationresult_compilation_time: (a: number) => number;
|
|
236
232
|
export const __wbg_get_wasmcompilationwithmetrics_compilation_time: (a: number) => number;
|
|
237
233
|
export const __wbg_get_wasmcompilationresult_compilation_time: (a: number) => number;
|
|
238
234
|
export const __wbg_set_wasmenhancedcompilationresult_success: (a: number, b: number) => void;
|
|
239
235
|
export const __wbg_get_wasmenhancedcompilationresult_success: (a: number) => number;
|
|
236
|
+
export const __wbg_set_wasmsuggestion_confidence: (a: number, b: number) => void;
|
|
237
|
+
export const __wbg_set_wasmenhancedcompilationresult_compilation_time: (a: number, b: number) => void;
|
|
238
|
+
export const __wbg_set_wasmcompilationwithmetrics_compilation_time: (a: number, b: number) => void;
|
|
239
|
+
export const __wbg_set_wasmcompilationresult_compilation_time: (a: number, b: number) => void;
|
|
240
240
|
export const __wbg_wasmfivecompiler_free: (a: number, b: number) => void;
|
|
241
|
-
export const __wbg_bytecodeencoder_free: (a: number, b: number) => void;
|
|
242
241
|
export const __wbg_parameterencoder_free: (a: number, b: number) => void;
|
|
242
|
+
export const __wbg_bytecodeencoder_free: (a: number, b: number) => void;
|
|
243
243
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
244
244
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
245
245
|
export const __wbindgen_export3: (a: number) => void;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Baked program ID injected at release time (set by scripts/set-default-program-id.sh)
|
|
7
7
|
* Empty string by default; overridden in npm published packages.
|
|
8
8
|
*/
|
|
9
|
-
export declare const FIVE_BAKED_PROGRAM_ID = "";
|
|
9
|
+
export declare const FIVE_BAKED_PROGRAM_ID = "4Qxf3pbCse2veUgZVMiAm3nWqJrYo2pT4suxHKMJdK1d";
|
|
10
10
|
/**
|
|
11
11
|
* Centralized resolver for program IDs across all SDK operations.
|
|
12
12
|
* Ensures consistent validation and error messaging.
|
|
@@ -7,7 +7,7 @@ import { validator } from '../validation/index.js';
|
|
|
7
7
|
* Baked program ID injected at release time (set by scripts/set-default-program-id.sh)
|
|
8
8
|
* Empty string by default; overridden in npm published packages.
|
|
9
9
|
*/
|
|
10
|
-
export const FIVE_BAKED_PROGRAM_ID = '';
|
|
10
|
+
export const FIVE_BAKED_PROGRAM_ID = '4Qxf3pbCse2veUgZVMiAm3nWqJrYo2pT4suxHKMJdK1d';
|
|
11
11
|
/**
|
|
12
12
|
* Centralized resolver for program IDs across all SDK operations.
|
|
13
13
|
* Ensures consistent validation and error messaging.
|
package/dist/crypto/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Five SDK crypto utilities.
|
|
3
3
|
*/
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
|
-
import { Point } from '@noble/ed25519';
|
|
6
5
|
import { randomBytes } from 'crypto';
|
|
6
|
+
import { PublicKey } from '@solana/web3.js';
|
|
7
7
|
/**
|
|
8
8
|
* Program Derived Address (PDA) utilities - pure implementation
|
|
9
9
|
*/
|
|
@@ -65,15 +65,7 @@ export class PDAUtils {
|
|
|
65
65
|
* Check if hash is off the Ed25519 curve (valid PDA)
|
|
66
66
|
*/
|
|
67
67
|
static isOffCurve(hash) {
|
|
68
|
-
|
|
69
|
-
// If point conversion succeeds, it's ON the curve
|
|
70
|
-
Point.fromHex(hash.toString('hex'));
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
// If point conversion fails, it's OFF the curve (valid PDA)
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
68
|
+
return !PublicKey.isOnCurve(hash);
|
|
77
69
|
}
|
|
78
70
|
/**
|
|
79
71
|
* Derive metadata account PDA for script
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export declare function generateInitializeVmStateInstruction(authority: string, options?: {
|
|
2
|
+
fiveVMProgramId?: string;
|
|
3
|
+
payer?: string;
|
|
4
|
+
vmStateAccount?: string;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
programId: string;
|
|
7
|
+
vmStateAccount: string;
|
|
8
|
+
bump: number;
|
|
9
|
+
instruction: {
|
|
10
|
+
programId: string;
|
|
11
|
+
accounts: Array<{
|
|
12
|
+
pubkey: string;
|
|
13
|
+
isSigner: boolean;
|
|
14
|
+
isWritable: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
data: string;
|
|
17
|
+
};
|
|
18
|
+
requiredSigners: string[];
|
|
19
|
+
}>;
|
|
20
|
+
export declare function generateSetFeesInstruction(authority: string, deployFeeLamports: number, executeFeeLamports: number, options?: {
|
|
21
|
+
fiveVMProgramId?: string;
|
|
22
|
+
vmStateAccount?: string;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
programId: string;
|
|
25
|
+
vmStateAccount: string;
|
|
26
|
+
instruction: {
|
|
27
|
+
programId: string;
|
|
28
|
+
accounts: Array<{
|
|
29
|
+
pubkey: string;
|
|
30
|
+
isSigner: boolean;
|
|
31
|
+
isWritable: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
data: string;
|
|
34
|
+
};
|
|
35
|
+
requiredSigners: string[];
|
|
36
|
+
}>;
|
|
37
|
+
export declare function generateInitFeeVaultInstruction(payer: string, shardIndex: number, options?: {
|
|
38
|
+
fiveVMProgramId?: string;
|
|
39
|
+
vmStateAccount?: string;
|
|
40
|
+
feeVaultAccount?: string;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
programId: string;
|
|
43
|
+
vmStateAccount: string;
|
|
44
|
+
feeVaultAccount: string;
|
|
45
|
+
bump: number;
|
|
46
|
+
instruction: {
|
|
47
|
+
programId: string;
|
|
48
|
+
accounts: Array<{
|
|
49
|
+
pubkey: string;
|
|
50
|
+
isSigner: boolean;
|
|
51
|
+
isWritable: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
data: string;
|
|
54
|
+
};
|
|
55
|
+
requiredSigners: string[];
|
|
56
|
+
}>;
|
|
57
|
+
export declare function generateWithdrawScriptFeesInstruction(authority: string, recipient: string, scriptAccount: string, shardIndex: number, lamports: number, options?: {
|
|
58
|
+
fiveVMProgramId?: string;
|
|
59
|
+
vmStateAccount?: string;
|
|
60
|
+
feeVaultAccount?: string;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
programId: string;
|
|
63
|
+
vmStateAccount: string;
|
|
64
|
+
feeVaultAccount: string;
|
|
65
|
+
instruction: {
|
|
66
|
+
programId: string;
|
|
67
|
+
accounts: Array<{
|
|
68
|
+
pubkey: string;
|
|
69
|
+
isSigner: boolean;
|
|
70
|
+
isWritable: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
data: string;
|
|
73
|
+
};
|
|
74
|
+
requiredSigners: string[];
|
|
75
|
+
}>;
|
|
76
|
+
export declare function initializeVmStateOnSolana(connection: any, authorityKeypair: any, options?: {
|
|
77
|
+
fiveVMProgramId?: string;
|
|
78
|
+
payerKeypair?: any;
|
|
79
|
+
vmStateAccount?: string;
|
|
80
|
+
maxRetries?: number;
|
|
81
|
+
debug?: boolean;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
success: boolean;
|
|
84
|
+
transactionId?: string;
|
|
85
|
+
vmStateAccount?: string;
|
|
86
|
+
error?: string;
|
|
87
|
+
}>;
|
|
88
|
+
export declare function setFeesOnSolana(connection: any, authorityKeypair: any, deployFeeLamports: number, executeFeeLamports: number, options?: {
|
|
89
|
+
fiveVMProgramId?: string;
|
|
90
|
+
vmStateAccount?: string;
|
|
91
|
+
maxRetries?: number;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
success: boolean;
|
|
94
|
+
transactionId?: string;
|
|
95
|
+
vmStateAccount?: string;
|
|
96
|
+
error?: string;
|
|
97
|
+
}>;
|
|
98
|
+
export declare function initFeeVaultOnSolana(connection: any, payerKeypair: any, shardIndex: number, options?: {
|
|
99
|
+
fiveVMProgramId?: string;
|
|
100
|
+
vmStateAccount?: string;
|
|
101
|
+
feeVaultAccount?: string;
|
|
102
|
+
maxRetries?: number;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
success: boolean;
|
|
105
|
+
transactionId?: string;
|
|
106
|
+
vmStateAccount?: string;
|
|
107
|
+
feeVaultAccount?: string;
|
|
108
|
+
error?: string;
|
|
109
|
+
}>;
|
|
110
|
+
export declare function withdrawScriptFeesOnSolana(connection: any, authorityKeypair: any, recipient: string, scriptAccount: string, shardIndex: number, lamports: number, options?: {
|
|
111
|
+
fiveVMProgramId?: string;
|
|
112
|
+
vmStateAccount?: string;
|
|
113
|
+
feeVaultAccount?: string;
|
|
114
|
+
maxRetries?: number;
|
|
115
|
+
}): Promise<{
|
|
116
|
+
success: boolean;
|
|
117
|
+
transactionId?: string;
|
|
118
|
+
vmStateAccount?: string;
|
|
119
|
+
feeVaultAccount?: string;
|
|
120
|
+
error?: string;
|
|
121
|
+
}>;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { validator } from "../validation/index.js";
|
|
2
|
+
import { ProgramIdResolver } from "../config/ProgramIdResolver.js";
|
|
3
|
+
import bs58 from "bs58";
|
|
4
|
+
const VM_STATE_SEED = Buffer.from("vm_state", "utf8");
|
|
5
|
+
const FEE_VAULT_NAMESPACE_SEED = Buffer.from([
|
|
6
|
+
0xff, 0x66, 0x69, 0x76, 0x65, 0x5f, 0x76, 0x6d, 0x5f, 0x66, 0x65, 0x65,
|
|
7
|
+
0x5f, 0x76, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x76, 0x31,
|
|
8
|
+
]);
|
|
9
|
+
async function deriveCanonicalVmState(programId) {
|
|
10
|
+
const { PublicKey } = await import("@solana/web3.js");
|
|
11
|
+
const [pda, bump] = PublicKey.findProgramAddressSync([VM_STATE_SEED], new PublicKey(programId));
|
|
12
|
+
return { address: pda.toBase58(), bump };
|
|
13
|
+
}
|
|
14
|
+
async function deriveFeeVault(programId, shardIndex) {
|
|
15
|
+
const { PublicKey } = await import("@solana/web3.js");
|
|
16
|
+
const [pda, bump] = PublicKey.findProgramAddressSync([FEE_VAULT_NAMESPACE_SEED, Buffer.from([shardIndex & 0xff])], new PublicKey(programId));
|
|
17
|
+
return { address: pda.toBase58(), bump };
|
|
18
|
+
}
|
|
19
|
+
function encodeInitializeVmState(bump) {
|
|
20
|
+
return Uint8Array.from([0, bump & 0xff]);
|
|
21
|
+
}
|
|
22
|
+
function encodeSetFees(deployFeeLamports, executeFeeLamports) {
|
|
23
|
+
const out = new Uint8Array(9);
|
|
24
|
+
out[0] = 6;
|
|
25
|
+
const view = new DataView(out.buffer);
|
|
26
|
+
view.setUint32(1, deployFeeLamports >>> 0, true);
|
|
27
|
+
view.setUint32(5, executeFeeLamports >>> 0, true);
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
function encodeInitFeeVault(shardIndex, bump) {
|
|
31
|
+
return Uint8Array.from([11, shardIndex & 0xff, bump & 0xff]);
|
|
32
|
+
}
|
|
33
|
+
function encodeWithdrawScriptFees(scriptAccount, shardIndex, lamports) {
|
|
34
|
+
const out = new Uint8Array(42);
|
|
35
|
+
out[0] = 12;
|
|
36
|
+
const scriptBytes = bs58.decode(scriptAccount);
|
|
37
|
+
if (scriptBytes.length !== 32) {
|
|
38
|
+
throw new Error("scriptAccount must decode to 32 bytes");
|
|
39
|
+
}
|
|
40
|
+
out.set(scriptBytes, 1);
|
|
41
|
+
out[33] = shardIndex & 0xff;
|
|
42
|
+
const view = new DataView(out.buffer);
|
|
43
|
+
view.setBigUint64(34, BigInt(lamports), true);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function requireU32(name, value) {
|
|
47
|
+
validator.validateNumber(value, name);
|
|
48
|
+
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
|
|
49
|
+
throw new Error(`${name} must be a u32 integer`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function requireU64(name, value) {
|
|
53
|
+
validator.validateNumber(value, name);
|
|
54
|
+
if (!Number.isInteger(value) || value < 0 || value > Number.MAX_SAFE_INTEGER) {
|
|
55
|
+
throw new Error(`${name} must be a non-negative safe integer`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function requireShardIndex(shardIndex) {
|
|
59
|
+
validator.validateNumber(shardIndex, "shardIndex");
|
|
60
|
+
if (!Number.isInteger(shardIndex) || shardIndex < 0 || shardIndex > 255) {
|
|
61
|
+
throw new Error("shardIndex must be in range 0..255");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export async function generateInitializeVmStateInstruction(authority, options = {}) {
|
|
65
|
+
validator.validateBase58Address(authority, "authority");
|
|
66
|
+
const payer = options.payer || authority;
|
|
67
|
+
validator.validateBase58Address(payer, "payer");
|
|
68
|
+
const programId = ProgramIdResolver.resolve(options.fiveVMProgramId);
|
|
69
|
+
const canonical = await deriveCanonicalVmState(programId);
|
|
70
|
+
if (options.vmStateAccount && options.vmStateAccount !== canonical.address) {
|
|
71
|
+
throw new Error(`vmStateAccount must be canonical PDA ${canonical.address}; got ${options.vmStateAccount}`);
|
|
72
|
+
}
|
|
73
|
+
const accounts = [
|
|
74
|
+
{ pubkey: canonical.address, isSigner: false, isWritable: true },
|
|
75
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
76
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
77
|
+
{ pubkey: "11111111111111111111111111111111", isSigner: false, isWritable: false },
|
|
78
|
+
];
|
|
79
|
+
return {
|
|
80
|
+
programId,
|
|
81
|
+
vmStateAccount: canonical.address,
|
|
82
|
+
bump: canonical.bump,
|
|
83
|
+
instruction: {
|
|
84
|
+
programId,
|
|
85
|
+
accounts,
|
|
86
|
+
data: Buffer.from(encodeInitializeVmState(canonical.bump)).toString("base64"),
|
|
87
|
+
},
|
|
88
|
+
requiredSigners: Array.from(new Set([authority, payer])),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export async function generateSetFeesInstruction(authority, deployFeeLamports, executeFeeLamports, options = {}) {
|
|
92
|
+
validator.validateBase58Address(authority, "authority");
|
|
93
|
+
requireU32("deployFeeLamports", deployFeeLamports);
|
|
94
|
+
requireU32("executeFeeLamports", executeFeeLamports);
|
|
95
|
+
const programId = ProgramIdResolver.resolve(options.fiveVMProgramId);
|
|
96
|
+
const canonical = await deriveCanonicalVmState(programId);
|
|
97
|
+
if (options.vmStateAccount && options.vmStateAccount !== canonical.address) {
|
|
98
|
+
throw new Error(`vmStateAccount must be canonical PDA ${canonical.address}; got ${options.vmStateAccount}`);
|
|
99
|
+
}
|
|
100
|
+
const accounts = [
|
|
101
|
+
{ pubkey: canonical.address, isSigner: false, isWritable: true },
|
|
102
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
103
|
+
];
|
|
104
|
+
return {
|
|
105
|
+
programId,
|
|
106
|
+
vmStateAccount: canonical.address,
|
|
107
|
+
instruction: {
|
|
108
|
+
programId,
|
|
109
|
+
accounts,
|
|
110
|
+
data: Buffer.from(encodeSetFees(deployFeeLamports, executeFeeLamports)).toString("base64"),
|
|
111
|
+
},
|
|
112
|
+
requiredSigners: [authority],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export async function generateInitFeeVaultInstruction(payer, shardIndex, options = {}) {
|
|
116
|
+
validator.validateBase58Address(payer, "payer");
|
|
117
|
+
requireShardIndex(shardIndex);
|
|
118
|
+
const programId = ProgramIdResolver.resolve(options.fiveVMProgramId);
|
|
119
|
+
const canonical = await deriveCanonicalVmState(programId);
|
|
120
|
+
const feeVault = await deriveFeeVault(programId, shardIndex);
|
|
121
|
+
if (options.vmStateAccount && options.vmStateAccount !== canonical.address) {
|
|
122
|
+
throw new Error(`vmStateAccount must be canonical PDA ${canonical.address}; got ${options.vmStateAccount}`);
|
|
123
|
+
}
|
|
124
|
+
if (options.feeVaultAccount && options.feeVaultAccount !== feeVault.address) {
|
|
125
|
+
throw new Error(`feeVaultAccount must be canonical PDA ${feeVault.address}; got ${options.feeVaultAccount}`);
|
|
126
|
+
}
|
|
127
|
+
const accounts = [
|
|
128
|
+
{ pubkey: canonical.address, isSigner: false, isWritable: false },
|
|
129
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
130
|
+
{ pubkey: feeVault.address, isSigner: false, isWritable: true },
|
|
131
|
+
{ pubkey: "11111111111111111111111111111111", isSigner: false, isWritable: false },
|
|
132
|
+
];
|
|
133
|
+
return {
|
|
134
|
+
programId,
|
|
135
|
+
vmStateAccount: canonical.address,
|
|
136
|
+
feeVaultAccount: feeVault.address,
|
|
137
|
+
bump: feeVault.bump,
|
|
138
|
+
instruction: {
|
|
139
|
+
programId,
|
|
140
|
+
accounts,
|
|
141
|
+
data: Buffer.from(encodeInitFeeVault(shardIndex, feeVault.bump)).toString("base64"),
|
|
142
|
+
},
|
|
143
|
+
requiredSigners: [payer],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export async function generateWithdrawScriptFeesInstruction(authority, recipient, scriptAccount, shardIndex, lamports, options = {}) {
|
|
147
|
+
validator.validateBase58Address(authority, "authority");
|
|
148
|
+
validator.validateBase58Address(recipient, "recipient");
|
|
149
|
+
validator.validateBase58Address(scriptAccount, "scriptAccount");
|
|
150
|
+
requireShardIndex(shardIndex);
|
|
151
|
+
requireU64("lamports", lamports);
|
|
152
|
+
const programId = ProgramIdResolver.resolve(options.fiveVMProgramId);
|
|
153
|
+
const canonical = await deriveCanonicalVmState(programId);
|
|
154
|
+
const feeVault = await deriveFeeVault(programId, shardIndex);
|
|
155
|
+
if (options.vmStateAccount && options.vmStateAccount !== canonical.address) {
|
|
156
|
+
throw new Error(`vmStateAccount must be canonical PDA ${canonical.address}; got ${options.vmStateAccount}`);
|
|
157
|
+
}
|
|
158
|
+
if (options.feeVaultAccount && options.feeVaultAccount !== feeVault.address) {
|
|
159
|
+
throw new Error(`feeVaultAccount must be canonical PDA ${feeVault.address}; got ${options.feeVaultAccount}`);
|
|
160
|
+
}
|
|
161
|
+
const accounts = [
|
|
162
|
+
{ pubkey: canonical.address, isSigner: false, isWritable: false },
|
|
163
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
164
|
+
{ pubkey: feeVault.address, isSigner: false, isWritable: true },
|
|
165
|
+
{ pubkey: recipient, isSigner: false, isWritable: true },
|
|
166
|
+
];
|
|
167
|
+
return {
|
|
168
|
+
programId,
|
|
169
|
+
vmStateAccount: canonical.address,
|
|
170
|
+
feeVaultAccount: feeVault.address,
|
|
171
|
+
instruction: {
|
|
172
|
+
programId,
|
|
173
|
+
accounts,
|
|
174
|
+
data: Buffer.from(encodeWithdrawScriptFees(scriptAccount, shardIndex, lamports)).toString("base64"),
|
|
175
|
+
},
|
|
176
|
+
requiredSigners: [authority],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export async function initializeVmStateOnSolana(connection, authorityKeypair, options = {}) {
|
|
180
|
+
const { PublicKey, Transaction, TransactionInstruction } = await import("@solana/web3.js");
|
|
181
|
+
const payerKeypair = options.payerKeypair || authorityKeypair;
|
|
182
|
+
const generated = await generateInitializeVmStateInstruction(authorityKeypair.publicKey.toBase58(), {
|
|
183
|
+
fiveVMProgramId: options.fiveVMProgramId,
|
|
184
|
+
payer: payerKeypair.publicKey.toBase58(),
|
|
185
|
+
vmStateAccount: options.vmStateAccount,
|
|
186
|
+
});
|
|
187
|
+
const tx = new Transaction().add(new TransactionInstruction({
|
|
188
|
+
keys: generated.instruction.accounts.map((a) => ({
|
|
189
|
+
pubkey: new PublicKey(a.pubkey),
|
|
190
|
+
isSigner: a.isSigner,
|
|
191
|
+
isWritable: a.isWritable,
|
|
192
|
+
})),
|
|
193
|
+
programId: new PublicKey(generated.instruction.programId),
|
|
194
|
+
data: Buffer.from(generated.instruction.data, "base64"),
|
|
195
|
+
}));
|
|
196
|
+
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
197
|
+
tx.recentBlockhash = blockhash;
|
|
198
|
+
tx.feePayer = payerKeypair.publicKey;
|
|
199
|
+
tx.partialSign(payerKeypair);
|
|
200
|
+
if (authorityKeypair.publicKey.toBase58() !== payerKeypair.publicKey.toBase58()) {
|
|
201
|
+
tx.partialSign(authorityKeypair);
|
|
202
|
+
}
|
|
203
|
+
const signature = await connection.sendRawTransaction(tx.serialize(), {
|
|
204
|
+
skipPreflight: false,
|
|
205
|
+
preflightCommitment: "confirmed",
|
|
206
|
+
maxRetries: options.maxRetries || 3,
|
|
207
|
+
});
|
|
208
|
+
const confirmation = await connection.confirmTransaction(signature, "confirmed");
|
|
209
|
+
if (confirmation?.value?.err) {
|
|
210
|
+
return { success: false, transactionId: signature, vmStateAccount: generated.vmStateAccount, error: JSON.stringify(confirmation.value.err) };
|
|
211
|
+
}
|
|
212
|
+
return { success: true, transactionId: signature, vmStateAccount: generated.vmStateAccount };
|
|
213
|
+
}
|
|
214
|
+
export async function setFeesOnSolana(connection, authorityKeypair, deployFeeLamports, executeFeeLamports, options = {}) {
|
|
215
|
+
const { PublicKey, Transaction, TransactionInstruction } = await import("@solana/web3.js");
|
|
216
|
+
const generated = await generateSetFeesInstruction(authorityKeypair.publicKey.toBase58(), deployFeeLamports, executeFeeLamports, {
|
|
217
|
+
fiveVMProgramId: options.fiveVMProgramId,
|
|
218
|
+
vmStateAccount: options.vmStateAccount,
|
|
219
|
+
});
|
|
220
|
+
const tx = new Transaction().add(new TransactionInstruction({
|
|
221
|
+
keys: generated.instruction.accounts.map((a) => ({
|
|
222
|
+
pubkey: new PublicKey(a.pubkey),
|
|
223
|
+
isSigner: a.isSigner,
|
|
224
|
+
isWritable: a.isWritable,
|
|
225
|
+
})),
|
|
226
|
+
programId: new PublicKey(generated.instruction.programId),
|
|
227
|
+
data: Buffer.from(generated.instruction.data, "base64"),
|
|
228
|
+
}));
|
|
229
|
+
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
230
|
+
tx.recentBlockhash = blockhash;
|
|
231
|
+
tx.feePayer = authorityKeypair.publicKey;
|
|
232
|
+
tx.partialSign(authorityKeypair);
|
|
233
|
+
const signature = await connection.sendRawTransaction(tx.serialize(), {
|
|
234
|
+
skipPreflight: false,
|
|
235
|
+
preflightCommitment: "confirmed",
|
|
236
|
+
maxRetries: options.maxRetries || 3,
|
|
237
|
+
});
|
|
238
|
+
const confirmation = await connection.confirmTransaction(signature, "confirmed");
|
|
239
|
+
if (confirmation?.value?.err) {
|
|
240
|
+
return { success: false, transactionId: signature, vmStateAccount: generated.vmStateAccount, error: JSON.stringify(confirmation.value.err) };
|
|
241
|
+
}
|
|
242
|
+
return { success: true, transactionId: signature, vmStateAccount: generated.vmStateAccount };
|
|
243
|
+
}
|
|
244
|
+
export async function initFeeVaultOnSolana(connection, payerKeypair, shardIndex, options = {}) {
|
|
245
|
+
const { PublicKey, Transaction, TransactionInstruction } = await import("@solana/web3.js");
|
|
246
|
+
const generated = await generateInitFeeVaultInstruction(payerKeypair.publicKey.toBase58(), shardIndex, {
|
|
247
|
+
fiveVMProgramId: options.fiveVMProgramId,
|
|
248
|
+
vmStateAccount: options.vmStateAccount,
|
|
249
|
+
feeVaultAccount: options.feeVaultAccount,
|
|
250
|
+
});
|
|
251
|
+
const tx = new Transaction().add(new TransactionInstruction({
|
|
252
|
+
keys: generated.instruction.accounts.map((a) => ({
|
|
253
|
+
pubkey: new PublicKey(a.pubkey),
|
|
254
|
+
isSigner: a.isSigner,
|
|
255
|
+
isWritable: a.isWritable,
|
|
256
|
+
})),
|
|
257
|
+
programId: new PublicKey(generated.instruction.programId),
|
|
258
|
+
data: Buffer.from(generated.instruction.data, "base64"),
|
|
259
|
+
}));
|
|
260
|
+
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
261
|
+
tx.recentBlockhash = blockhash;
|
|
262
|
+
tx.feePayer = payerKeypair.publicKey;
|
|
263
|
+
tx.partialSign(payerKeypair);
|
|
264
|
+
const signature = await connection.sendRawTransaction(tx.serialize(), {
|
|
265
|
+
skipPreflight: false,
|
|
266
|
+
preflightCommitment: "confirmed",
|
|
267
|
+
maxRetries: options.maxRetries || 3,
|
|
268
|
+
});
|
|
269
|
+
const confirmation = await connection.confirmTransaction(signature, "confirmed");
|
|
270
|
+
if (confirmation?.value?.err) {
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
transactionId: signature,
|
|
274
|
+
vmStateAccount: generated.vmStateAccount,
|
|
275
|
+
feeVaultAccount: generated.feeVaultAccount,
|
|
276
|
+
error: JSON.stringify(confirmation.value.err),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
success: true,
|
|
281
|
+
transactionId: signature,
|
|
282
|
+
vmStateAccount: generated.vmStateAccount,
|
|
283
|
+
feeVaultAccount: generated.feeVaultAccount,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
export async function withdrawScriptFeesOnSolana(connection, authorityKeypair, recipient, scriptAccount, shardIndex, lamports, options = {}) {
|
|
287
|
+
const { PublicKey, Transaction, TransactionInstruction } = await import("@solana/web3.js");
|
|
288
|
+
const generated = await generateWithdrawScriptFeesInstruction(authorityKeypair.publicKey.toBase58(), recipient, scriptAccount, shardIndex, lamports, {
|
|
289
|
+
fiveVMProgramId: options.fiveVMProgramId,
|
|
290
|
+
vmStateAccount: options.vmStateAccount,
|
|
291
|
+
feeVaultAccount: options.feeVaultAccount,
|
|
292
|
+
});
|
|
293
|
+
const tx = new Transaction().add(new TransactionInstruction({
|
|
294
|
+
keys: generated.instruction.accounts.map((a) => ({
|
|
295
|
+
pubkey: new PublicKey(a.pubkey),
|
|
296
|
+
isSigner: a.isSigner,
|
|
297
|
+
isWritable: a.isWritable,
|
|
298
|
+
})),
|
|
299
|
+
programId: new PublicKey(generated.instruction.programId),
|
|
300
|
+
data: Buffer.from(generated.instruction.data, "base64"),
|
|
301
|
+
}));
|
|
302
|
+
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
303
|
+
tx.recentBlockhash = blockhash;
|
|
304
|
+
tx.feePayer = authorityKeypair.publicKey;
|
|
305
|
+
tx.partialSign(authorityKeypair);
|
|
306
|
+
const signature = await connection.sendRawTransaction(tx.serialize(), {
|
|
307
|
+
skipPreflight: false,
|
|
308
|
+
preflightCommitment: "confirmed",
|
|
309
|
+
maxRetries: options.maxRetries || 3,
|
|
310
|
+
});
|
|
311
|
+
const confirmation = await connection.confirmTransaction(signature, "confirmed");
|
|
312
|
+
if (confirmation?.value?.err) {
|
|
313
|
+
return {
|
|
314
|
+
success: false,
|
|
315
|
+
transactionId: signature,
|
|
316
|
+
vmStateAccount: generated.vmStateAccount,
|
|
317
|
+
feeVaultAccount: generated.feeVaultAccount,
|
|
318
|
+
error: JSON.stringify(confirmation.value.err),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
success: true,
|
|
323
|
+
transactionId: signature,
|
|
324
|
+
vmStateAccount: generated.vmStateAccount,
|
|
325
|
+
feeVaultAccount: generated.feeVaultAccount,
|
|
326
|
+
};
|
|
327
|
+
}
|
package/dist/modules/deploy.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ options?: {
|
|
|
32
32
|
maxRetries?: number;
|
|
33
33
|
fiveVMProgramId?: string;
|
|
34
34
|
vmStateAccount?: string;
|
|
35
|
+
adminAccount?: string;
|
|
35
36
|
exportMetadata?: ExportMetadataInput;
|
|
36
37
|
}): Promise<{
|
|
37
38
|
success: boolean;
|
|
@@ -52,6 +53,8 @@ options?: {
|
|
|
52
53
|
fiveVMProgramId?: string;
|
|
53
54
|
progressCallback?: (chunk: number, total: number) => void;
|
|
54
55
|
vmStateAccount?: string;
|
|
56
|
+
adminAccount?: string;
|
|
57
|
+
forceChunkedSmallProgram?: boolean;
|
|
55
58
|
}): Promise<{
|
|
56
59
|
success: boolean;
|
|
57
60
|
scriptAccount?: string;
|
|
@@ -71,7 +74,11 @@ options?: {
|
|
|
71
74
|
network?: string;
|
|
72
75
|
maxRetries?: number;
|
|
73
76
|
fiveVMProgramId?: string;
|
|
77
|
+
vmStateAccount?: string;
|
|
78
|
+
adminAccount?: string;
|
|
79
|
+
exportMetadata?: ExportMetadataInput;
|
|
74
80
|
progressCallback?: (transaction: number, total: number) => void;
|
|
81
|
+
forceChunkedSmallProgram?: boolean;
|
|
75
82
|
}): Promise<{
|
|
76
83
|
success: boolean;
|
|
77
84
|
scriptAccount?: string;
|
|
@@ -87,4 +94,14 @@ options?: {
|
|
|
87
94
|
error?: string;
|
|
88
95
|
logs?: string[];
|
|
89
96
|
}>;
|
|
97
|
+
declare function buildInitializeVmStateInstructionData(bump?: number): Buffer;
|
|
98
|
+
declare function createInitLargeProgramInstructionData(expectedSize: number, firstChunk?: Uint8Array): Buffer;
|
|
99
|
+
declare function createAppendBytecodeInstructionData(chunk: Uint8Array): Buffer;
|
|
100
|
+
declare function createFinalizeScriptInstructionData(): Buffer;
|
|
101
|
+
export declare const __deployTestUtils: {
|
|
102
|
+
buildInitializeVmStateInstructionData: typeof buildInitializeVmStateInstructionData;
|
|
103
|
+
createInitLargeProgramInstructionData: typeof createInitLargeProgramInstructionData;
|
|
104
|
+
createAppendBytecodeInstructionData: typeof createAppendBytecodeInstructionData;
|
|
105
|
+
createFinalizeScriptInstructionData: typeof createFinalizeScriptInstructionData;
|
|
106
|
+
};
|
|
90
107
|
export {};
|