@thru/programs 0.2.25 → 0.2.28
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/multicall/index.cjs +166 -24
- package/dist/multicall/index.cjs.map +1 -1
- package/dist/multicall/index.d.cts +39 -3
- package/dist/multicall/index.d.ts +39 -3
- package/dist/multicall/index.js +166 -25
- package/dist/multicall/index.js.map +1 -1
- package/dist/passkey-manager/index.cjs +1235 -345
- package/dist/passkey-manager/index.cjs.map +1 -1
- package/dist/passkey-manager/index.d.cts +45 -11
- package/dist/passkey-manager/index.d.ts +45 -11
- package/dist/passkey-manager/index.js +1225 -346
- package/dist/passkey-manager/index.js.map +1 -1
- package/package.json +2 -2
- package/src/multicall/abi/thru/common/primitives/types.ts +14 -9
- package/src/multicall/abi/thru/program/multicall/types.ts +136 -4
- package/src/multicall/index.ts +6 -17
- package/src/passkey-manager/abi/thru/blockchain/state_proof/types.ts +11 -6
- package/src/passkey-manager/abi/thru/common/primitives/types.ts +19 -14
- package/src/passkey-manager/abi/thru/program/passkey_manager/types.ts +1069 -271
- package/src/passkey-manager/accounts.ts +79 -40
- package/src/passkey-manager/constants.ts +10 -1
- package/src/passkey-manager/index.ts +18 -2
- package/src/passkey-manager/instructions/add-authority.ts +31 -3
- package/src/passkey-manager/instructions/create.ts +106 -11
- package/src/passkey-manager/instructions/invoke.ts +9 -0
- package/src/passkey-manager/instructions/shared.ts +15 -0
- package/src/passkey-manager/instructions/transfer.ts +1 -1
- package/src/passkey-manager/instructions/validate.ts +13 -43
- package/src/passkey-manager/types.ts +7 -2
- package/src/passkey-manager/validate.test.ts +71 -3
|
@@ -2,12 +2,13 @@ type __TnValidateResult$1 = {
|
|
|
2
2
|
ok: boolean;
|
|
3
3
|
code?: string;
|
|
4
4
|
consumed?: bigint;
|
|
5
|
+
params?: Record<string, bigint>;
|
|
5
6
|
};
|
|
6
|
-
type __TnBuilderLike = {
|
|
7
|
+
type __TnBuilderLike$1 = {
|
|
7
8
|
build(): Uint8Array;
|
|
8
9
|
};
|
|
9
10
|
type __TnFamWriterResult<Parent> = {
|
|
10
|
-
write(payload: Uint8Array | __TnBuilderLike): {
|
|
11
|
+
write(payload: Uint8Array | __TnBuilderLike$1): {
|
|
11
12
|
finish(): Parent;
|
|
12
13
|
};
|
|
13
14
|
finish(): Parent;
|
|
@@ -124,6 +125,17 @@ type __TnValidateResult = {
|
|
|
124
125
|
ok: boolean;
|
|
125
126
|
code?: string;
|
|
126
127
|
consumed?: bigint;
|
|
128
|
+
params?: Record<string, bigint>;
|
|
129
|
+
};
|
|
130
|
+
type __TnBuilderLike = {
|
|
131
|
+
build(): Uint8Array;
|
|
132
|
+
};
|
|
133
|
+
type __TnStructFieldInput = Uint8Array | __TnBuilderLike | {
|
|
134
|
+
buffer?: Uint8Array;
|
|
135
|
+
} | {
|
|
136
|
+
asUint8Array?: () => Uint8Array;
|
|
137
|
+
} | {
|
|
138
|
+
bytes?: () => Uint8Array;
|
|
127
139
|
};
|
|
128
140
|
declare class MulticallArgs {
|
|
129
141
|
private buffer;
|
|
@@ -138,6 +150,8 @@ declare class MulticallArgs {
|
|
|
138
150
|
dynamicParams(): MulticallArgs.Params;
|
|
139
151
|
withFieldContext(context: Record<string, number | bigint>): this;
|
|
140
152
|
private __tnResolveFieldRef;
|
|
153
|
+
static builder(): MulticallArgsBuilder;
|
|
154
|
+
static fromBuilder(builder: MulticallArgsBuilder): MulticallArgs | null;
|
|
141
155
|
private static __tnExtractParams;
|
|
142
156
|
get_calls_count(): number;
|
|
143
157
|
set_calls_count(value: number): void;
|
|
@@ -203,6 +217,28 @@ declare namespace MulticallArgs {
|
|
|
203
217
|
calls_calls_count: number | bigint;
|
|
204
218
|
}): Params;
|
|
205
219
|
}
|
|
220
|
+
declare class MulticallArgsBuilder {
|
|
221
|
+
private buffer;
|
|
222
|
+
private view;
|
|
223
|
+
private __tnJagged_calls;
|
|
224
|
+
private __tnCachedParams;
|
|
225
|
+
private __tnLastBuffer;
|
|
226
|
+
private __tnLastParams;
|
|
227
|
+
constructor();
|
|
228
|
+
private __tnInvalidate;
|
|
229
|
+
set_calls_count(value: number): this;
|
|
230
|
+
set_calls(values: readonly (InstructionData | __TnStructFieldInput)[]): this;
|
|
231
|
+
build(): Uint8Array;
|
|
232
|
+
buildInto(target: Uint8Array, offset?: number): Uint8Array;
|
|
233
|
+
finish(): MulticallArgs;
|
|
234
|
+
finishView(): MulticallArgs;
|
|
235
|
+
dynamicParams(): MulticallArgs.Params;
|
|
236
|
+
private __tnComputeParams;
|
|
237
|
+
private __tnCollectFragments;
|
|
238
|
+
private __tnComputeSize;
|
|
239
|
+
private __tnWriteInto;
|
|
240
|
+
private __tnValidateOrThrow;
|
|
241
|
+
}
|
|
206
242
|
declare class MulticallError {
|
|
207
243
|
private buffer;
|
|
208
244
|
private view;
|
|
@@ -250,4 +286,4 @@ declare const MULTICALL_PROGRAM_PUBKEY: Uint8Array<ArrayBuffer>;
|
|
|
250
286
|
declare const MULTICALL_PROGRAM_ADDRESS: string;
|
|
251
287
|
declare function buildMulticallInstruction(calls: MulticallCall[]): Uint8Array;
|
|
252
288
|
|
|
253
|
-
export { InstructionData, InstructionDataBuilder, MULTICALL_PROGRAM_ADDRESS, MULTICALL_PROGRAM_PUBKEY, MulticallArgs, type MulticallCall, MulticallError, buildMulticallInstruction };
|
|
289
|
+
export { InstructionData, InstructionDataBuilder, MULTICALL_PROGRAM_ADDRESS, MULTICALL_PROGRAM_PUBKEY, MulticallArgs, MulticallArgsBuilder, type MulticallCall, MulticallError, buildMulticallInstruction };
|
|
@@ -2,12 +2,13 @@ type __TnValidateResult$1 = {
|
|
|
2
2
|
ok: boolean;
|
|
3
3
|
code?: string;
|
|
4
4
|
consumed?: bigint;
|
|
5
|
+
params?: Record<string, bigint>;
|
|
5
6
|
};
|
|
6
|
-
type __TnBuilderLike = {
|
|
7
|
+
type __TnBuilderLike$1 = {
|
|
7
8
|
build(): Uint8Array;
|
|
8
9
|
};
|
|
9
10
|
type __TnFamWriterResult<Parent> = {
|
|
10
|
-
write(payload: Uint8Array | __TnBuilderLike): {
|
|
11
|
+
write(payload: Uint8Array | __TnBuilderLike$1): {
|
|
11
12
|
finish(): Parent;
|
|
12
13
|
};
|
|
13
14
|
finish(): Parent;
|
|
@@ -124,6 +125,17 @@ type __TnValidateResult = {
|
|
|
124
125
|
ok: boolean;
|
|
125
126
|
code?: string;
|
|
126
127
|
consumed?: bigint;
|
|
128
|
+
params?: Record<string, bigint>;
|
|
129
|
+
};
|
|
130
|
+
type __TnBuilderLike = {
|
|
131
|
+
build(): Uint8Array;
|
|
132
|
+
};
|
|
133
|
+
type __TnStructFieldInput = Uint8Array | __TnBuilderLike | {
|
|
134
|
+
buffer?: Uint8Array;
|
|
135
|
+
} | {
|
|
136
|
+
asUint8Array?: () => Uint8Array;
|
|
137
|
+
} | {
|
|
138
|
+
bytes?: () => Uint8Array;
|
|
127
139
|
};
|
|
128
140
|
declare class MulticallArgs {
|
|
129
141
|
private buffer;
|
|
@@ -138,6 +150,8 @@ declare class MulticallArgs {
|
|
|
138
150
|
dynamicParams(): MulticallArgs.Params;
|
|
139
151
|
withFieldContext(context: Record<string, number | bigint>): this;
|
|
140
152
|
private __tnResolveFieldRef;
|
|
153
|
+
static builder(): MulticallArgsBuilder;
|
|
154
|
+
static fromBuilder(builder: MulticallArgsBuilder): MulticallArgs | null;
|
|
141
155
|
private static __tnExtractParams;
|
|
142
156
|
get_calls_count(): number;
|
|
143
157
|
set_calls_count(value: number): void;
|
|
@@ -203,6 +217,28 @@ declare namespace MulticallArgs {
|
|
|
203
217
|
calls_calls_count: number | bigint;
|
|
204
218
|
}): Params;
|
|
205
219
|
}
|
|
220
|
+
declare class MulticallArgsBuilder {
|
|
221
|
+
private buffer;
|
|
222
|
+
private view;
|
|
223
|
+
private __tnJagged_calls;
|
|
224
|
+
private __tnCachedParams;
|
|
225
|
+
private __tnLastBuffer;
|
|
226
|
+
private __tnLastParams;
|
|
227
|
+
constructor();
|
|
228
|
+
private __tnInvalidate;
|
|
229
|
+
set_calls_count(value: number): this;
|
|
230
|
+
set_calls(values: readonly (InstructionData | __TnStructFieldInput)[]): this;
|
|
231
|
+
build(): Uint8Array;
|
|
232
|
+
buildInto(target: Uint8Array, offset?: number): Uint8Array;
|
|
233
|
+
finish(): MulticallArgs;
|
|
234
|
+
finishView(): MulticallArgs;
|
|
235
|
+
dynamicParams(): MulticallArgs.Params;
|
|
236
|
+
private __tnComputeParams;
|
|
237
|
+
private __tnCollectFragments;
|
|
238
|
+
private __tnComputeSize;
|
|
239
|
+
private __tnWriteInto;
|
|
240
|
+
private __tnValidateOrThrow;
|
|
241
|
+
}
|
|
206
242
|
declare class MulticallError {
|
|
207
243
|
private buffer;
|
|
208
244
|
private view;
|
|
@@ -250,4 +286,4 @@ declare const MULTICALL_PROGRAM_PUBKEY: Uint8Array<ArrayBuffer>;
|
|
|
250
286
|
declare const MULTICALL_PROGRAM_ADDRESS: string;
|
|
251
287
|
declare function buildMulticallInstruction(calls: MulticallCall[]): Uint8Array;
|
|
252
288
|
|
|
253
|
-
export { InstructionData, InstructionDataBuilder, MULTICALL_PROGRAM_ADDRESS, MULTICALL_PROGRAM_PUBKEY, MulticallArgs, type MulticallCall, MulticallError, buildMulticallInstruction };
|
|
289
|
+
export { InstructionData, InstructionDataBuilder, MULTICALL_PROGRAM_ADDRESS, MULTICALL_PROGRAM_PUBKEY, MulticallArgs, MulticallArgsBuilder, type MulticallCall, MulticallError, buildMulticallInstruction };
|
package/dist/multicall/index.js
CHANGED
|
@@ -621,7 +621,8 @@ __tnRegisterFootprint("Date", (params) => Date.__tnInvokeFootprint(params));
|
|
|
621
621
|
__tnRegisterValidate("Date", (buffer, params) => Date.__tnInvokeValidate(buffer, params));
|
|
622
622
|
__tnRegisterDynamicValidate("Date", (buffer) => {
|
|
623
623
|
const result = Date.validate(buffer);
|
|
624
|
-
|
|
624
|
+
const params = result.params;
|
|
625
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
625
626
|
});
|
|
626
627
|
var __tn_ir_Duration = {
|
|
627
628
|
typeName: "Duration",
|
|
@@ -749,7 +750,8 @@ __tnRegisterFootprint("Duration", (params) => Duration.__tnInvokeFootprint(param
|
|
|
749
750
|
__tnRegisterValidate("Duration", (buffer, params) => Duration.__tnInvokeValidate(buffer, params));
|
|
750
751
|
__tnRegisterDynamicValidate("Duration", (buffer) => {
|
|
751
752
|
const result = Duration.validate(buffer);
|
|
752
|
-
|
|
753
|
+
const params = result.params;
|
|
754
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
753
755
|
});
|
|
754
756
|
var __tn_ir_FixedPoint = {
|
|
755
757
|
typeName: "FixedPoint",
|
|
@@ -877,7 +879,8 @@ __tnRegisterFootprint("FixedPoint", (params) => FixedPoint.__tnInvokeFootprint(p
|
|
|
877
879
|
__tnRegisterValidate("FixedPoint", (buffer, params) => FixedPoint.__tnInvokeValidate(buffer, params));
|
|
878
880
|
__tnRegisterDynamicValidate("FixedPoint", (buffer) => {
|
|
879
881
|
const result = FixedPoint.validate(buffer);
|
|
880
|
-
|
|
882
|
+
const params = result.params;
|
|
883
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
881
884
|
});
|
|
882
885
|
var __tn_ir_Hash = {
|
|
883
886
|
typeName: "Hash",
|
|
@@ -992,7 +995,8 @@ __tnRegisterFootprint("Hash", (params) => Hash.__tnInvokeFootprint(params));
|
|
|
992
995
|
__tnRegisterValidate("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
|
|
993
996
|
__tnRegisterDynamicValidate("Hash", (buffer) => {
|
|
994
997
|
const result = Hash.validate(buffer);
|
|
995
|
-
|
|
998
|
+
const params = result.params;
|
|
999
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
996
1000
|
});
|
|
997
1001
|
var __tn_ir_InstructionData = {
|
|
998
1002
|
typeName: "InstructionData",
|
|
@@ -1332,7 +1336,8 @@ __tnRegisterFootprint("InstructionData", (params) => InstructionData.__tnInvokeF
|
|
|
1332
1336
|
__tnRegisterValidate("InstructionData", (buffer, params) => InstructionData.__tnInvokeValidate(buffer, params));
|
|
1333
1337
|
__tnRegisterDynamicValidate("InstructionData", (buffer) => {
|
|
1334
1338
|
const result = InstructionData.validate(buffer);
|
|
1335
|
-
|
|
1339
|
+
const params = result.params;
|
|
1340
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
1336
1341
|
});
|
|
1337
1342
|
var __tn_ir_Pubkey = {
|
|
1338
1343
|
typeName: "Pubkey",
|
|
@@ -1447,7 +1452,8 @@ __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
|
|
|
1447
1452
|
__tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
|
|
1448
1453
|
__tnRegisterDynamicValidate("Pubkey", (buffer) => {
|
|
1449
1454
|
const result = Pubkey.validate(buffer);
|
|
1450
|
-
|
|
1455
|
+
const params = result.params;
|
|
1456
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
1451
1457
|
});
|
|
1452
1458
|
var __tn_ir_Signature = {
|
|
1453
1459
|
typeName: "Signature",
|
|
@@ -1562,7 +1568,8 @@ __tnRegisterFootprint("Signature", (params) => Signature.__tnInvokeFootprint(par
|
|
|
1562
1568
|
__tnRegisterValidate("Signature", (buffer, params) => Signature.__tnInvokeValidate(buffer, params));
|
|
1563
1569
|
__tnRegisterDynamicValidate("Signature", (buffer) => {
|
|
1564
1570
|
const result = Signature.validate(buffer);
|
|
1565
|
-
|
|
1571
|
+
const params = result.params;
|
|
1572
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
1566
1573
|
});
|
|
1567
1574
|
var __tn_ir_Timestamp = {
|
|
1568
1575
|
typeName: "Timestamp",
|
|
@@ -1671,7 +1678,8 @@ __tnRegisterFootprint("Timestamp", (params) => Timestamp.__tnInvokeFootprint(par
|
|
|
1671
1678
|
__tnRegisterValidate("Timestamp", (buffer, params) => Timestamp.__tnInvokeValidate(buffer, params));
|
|
1672
1679
|
__tnRegisterDynamicValidate("Timestamp", (buffer) => {
|
|
1673
1680
|
const result = Timestamp.validate(buffer);
|
|
1674
|
-
|
|
1681
|
+
const params = result.params;
|
|
1682
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
|
|
1675
1683
|
});
|
|
1676
1684
|
|
|
1677
1685
|
// src/multicall/abi/thru/program/multicall/types.ts
|
|
@@ -1690,6 +1698,36 @@ function __tnWarnOnce2(message) {
|
|
|
1690
1698
|
__tnLogWarn2(message);
|
|
1691
1699
|
}
|
|
1692
1700
|
}
|
|
1701
|
+
function __tnResolveBuilderInput2(input, context) {
|
|
1702
|
+
if (input instanceof Uint8Array) {
|
|
1703
|
+
return new Uint8Array(input);
|
|
1704
|
+
}
|
|
1705
|
+
if (input && typeof input.build === "function") {
|
|
1706
|
+
const built = input.build();
|
|
1707
|
+
if (!(built instanceof Uint8Array)) {
|
|
1708
|
+
throw new Error(`${context}: builder did not return Uint8Array`);
|
|
1709
|
+
}
|
|
1710
|
+
return new Uint8Array(built);
|
|
1711
|
+
}
|
|
1712
|
+
throw new Error(`${context}: expected Uint8Array or builder`);
|
|
1713
|
+
}
|
|
1714
|
+
function __tnResolveStructFieldInput(input, context) {
|
|
1715
|
+
if (input instanceof Uint8Array || input && typeof input.build === "function") {
|
|
1716
|
+
return __tnResolveBuilderInput2(input, context);
|
|
1717
|
+
}
|
|
1718
|
+
if (input && typeof input.asUint8Array === "function") {
|
|
1719
|
+
const bytes = input.asUint8Array();
|
|
1720
|
+
return new Uint8Array(bytes);
|
|
1721
|
+
}
|
|
1722
|
+
if (input && typeof input.bytes === "function") {
|
|
1723
|
+
const bytes = input.bytes();
|
|
1724
|
+
return new Uint8Array(bytes);
|
|
1725
|
+
}
|
|
1726
|
+
if (input && input.buffer instanceof Uint8Array) {
|
|
1727
|
+
return new Uint8Array(input.buffer);
|
|
1728
|
+
}
|
|
1729
|
+
throw new Error(`${context}: expected Uint8Array, builder, or view-like value`);
|
|
1730
|
+
}
|
|
1693
1731
|
var __tnMask322 = __tnHasNativeBigInt2 ? (BigInt(1) << BigInt(32)) - BigInt(1) : 4294967295;
|
|
1694
1732
|
var __tnSignBit322 = __tnHasNativeBigInt2 ? BigInt(1) << BigInt(31) : 2147483648;
|
|
1695
1733
|
function __tnToBigInt2(value) {
|
|
@@ -2113,7 +2151,8 @@ __tnRegisterFootprint2("InstructionData", (params) => InstructionData.__tnInvoke
|
|
|
2113
2151
|
__tnRegisterValidate2("InstructionData", (buffer, params) => InstructionData.__tnInvokeValidate(buffer, params));
|
|
2114
2152
|
__tnRegisterDynamicValidate2("InstructionData", (buffer) => {
|
|
2115
2153
|
const result = InstructionData.validate(buffer);
|
|
2116
|
-
|
|
2154
|
+
const params = result.params;
|
|
2155
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
|
|
2117
2156
|
});
|
|
2118
2157
|
var __tn_ir_MulticallArgs = {
|
|
2119
2158
|
typeName: "MulticallArgs",
|
|
@@ -2167,6 +2206,14 @@ var MulticallArgs = class _MulticallArgs {
|
|
|
2167
2206
|
}
|
|
2168
2207
|
throw new Error("MulticallArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
|
|
2169
2208
|
}
|
|
2209
|
+
static builder() {
|
|
2210
|
+
return new MulticallArgsBuilder();
|
|
2211
|
+
}
|
|
2212
|
+
static fromBuilder(builder) {
|
|
2213
|
+
const buffer = builder.build();
|
|
2214
|
+
const params = builder.dynamicParams();
|
|
2215
|
+
return _MulticallArgs.from_array(buffer, { params });
|
|
2216
|
+
}
|
|
2170
2217
|
static __tnExtractParams(view, buffer) {
|
|
2171
2218
|
if (buffer.length < 2) {
|
|
2172
2219
|
return null;
|
|
@@ -2370,11 +2417,116 @@ var MulticallArgs = class _MulticallArgs {
|
|
|
2370
2417
|
}
|
|
2371
2418
|
MulticallArgs2.params = params;
|
|
2372
2419
|
})(MulticallArgs || (MulticallArgs = {}));
|
|
2420
|
+
var MulticallArgsBuilder = class {
|
|
2421
|
+
constructor() {
|
|
2422
|
+
this.__tnJagged_calls = null;
|
|
2423
|
+
this.__tnCachedParams = null;
|
|
2424
|
+
this.__tnLastBuffer = null;
|
|
2425
|
+
this.__tnLastParams = null;
|
|
2426
|
+
this.buffer = new Uint8Array(2);
|
|
2427
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2428
|
+
}
|
|
2429
|
+
__tnInvalidate() {
|
|
2430
|
+
this.__tnCachedParams = null;
|
|
2431
|
+
this.__tnLastBuffer = null;
|
|
2432
|
+
this.__tnLastParams = null;
|
|
2433
|
+
}
|
|
2434
|
+
set_calls_count(value) {
|
|
2435
|
+
this.view.setUint16(0, value, true);
|
|
2436
|
+
this.__tnInvalidate();
|
|
2437
|
+
return this;
|
|
2438
|
+
}
|
|
2439
|
+
set_calls(values) {
|
|
2440
|
+
const fragments = [];
|
|
2441
|
+
for (let i = 0; i < values.length; i++) {
|
|
2442
|
+
const bytes = __tnResolveStructFieldInput(values[i], "MulticallArgsBuilder::calls[" + i + "]");
|
|
2443
|
+
const validation = __tnInvokeDynamicValidate2("InstructionData", bytes);
|
|
2444
|
+
if (!validation.ok || validation.consumed === void 0) throw new Error("MulticallArgsBuilder: field 'calls' element failed validation");
|
|
2445
|
+
if (__tnBigIntToNumber2(validation.consumed, "MulticallArgsBuilder::calls") !== bytes.length) throw new Error("MulticallArgsBuilder: field 'calls' element validation did not consume the full buffer");
|
|
2446
|
+
fragments.push(bytes);
|
|
2447
|
+
}
|
|
2448
|
+
this.__tnJagged_calls = fragments;
|
|
2449
|
+
this.set_calls_count(fragments.length);
|
|
2450
|
+
this.__tnInvalidate();
|
|
2451
|
+
return this;
|
|
2452
|
+
}
|
|
2453
|
+
build() {
|
|
2454
|
+
const params = this.__tnComputeParams();
|
|
2455
|
+
const fragments = this.__tnCollectFragments();
|
|
2456
|
+
const size = this.__tnComputeSize(fragments);
|
|
2457
|
+
const buffer = new Uint8Array(size);
|
|
2458
|
+
this.__tnWriteInto(buffer, fragments);
|
|
2459
|
+
this.__tnValidateOrThrow(buffer, params);
|
|
2460
|
+
return buffer;
|
|
2461
|
+
}
|
|
2462
|
+
buildInto(target, offset = 0) {
|
|
2463
|
+
const params = this.__tnComputeParams();
|
|
2464
|
+
const fragments = this.__tnCollectFragments();
|
|
2465
|
+
const size = this.__tnComputeSize(fragments);
|
|
2466
|
+
if (target.length - offset < size) throw new Error("MulticallArgsBuilder: target buffer too small");
|
|
2467
|
+
const slice = target.subarray(offset, offset + size);
|
|
2468
|
+
this.__tnWriteInto(slice, fragments);
|
|
2469
|
+
this.__tnValidateOrThrow(slice, params);
|
|
2470
|
+
return target;
|
|
2471
|
+
}
|
|
2472
|
+
finish() {
|
|
2473
|
+
const buffer = this.build();
|
|
2474
|
+
const params = this.__tnLastParams ?? this.__tnComputeParams();
|
|
2475
|
+
const view = MulticallArgs.from_array(buffer, { params });
|
|
2476
|
+
if (!view) throw new Error("MulticallArgsBuilder: failed to finalize view");
|
|
2477
|
+
return view;
|
|
2478
|
+
}
|
|
2479
|
+
finishView() {
|
|
2480
|
+
return this.finish();
|
|
2481
|
+
}
|
|
2482
|
+
dynamicParams() {
|
|
2483
|
+
return this.__tnComputeParams();
|
|
2484
|
+
}
|
|
2485
|
+
__tnComputeParams() {
|
|
2486
|
+
if (this.__tnCachedParams) return this.__tnCachedParams;
|
|
2487
|
+
const params = MulticallArgs.Params.fromValues({
|
|
2488
|
+
calls_calls_count: (() => {
|
|
2489
|
+
const fragments = this.__tnJagged_calls;
|
|
2490
|
+
if (!fragments) throw new Error("MulticallArgsBuilder: field 'calls' must be written before computing params");
|
|
2491
|
+
return __tnToBigInt2(fragments.length);
|
|
2492
|
+
})()
|
|
2493
|
+
});
|
|
2494
|
+
this.__tnCachedParams = params;
|
|
2495
|
+
return params;
|
|
2496
|
+
}
|
|
2497
|
+
__tnCollectFragments() {
|
|
2498
|
+
const fragments = this.__tnJagged_calls;
|
|
2499
|
+
if (!fragments) throw new Error("MulticallArgsBuilder: field 'calls' must be written before build");
|
|
2500
|
+
return fragments;
|
|
2501
|
+
}
|
|
2502
|
+
__tnComputeSize(fragments) {
|
|
2503
|
+
let total = this.buffer.length;
|
|
2504
|
+
for (const fragment of fragments) total += fragment.length;
|
|
2505
|
+
return total;
|
|
2506
|
+
}
|
|
2507
|
+
__tnWriteInto(target, fragments) {
|
|
2508
|
+
target.set(this.buffer, 0);
|
|
2509
|
+
let cursor = this.buffer.length;
|
|
2510
|
+
for (const fragment of fragments) {
|
|
2511
|
+
target.set(fragment, cursor);
|
|
2512
|
+
cursor += fragment.length;
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
__tnValidateOrThrow(buffer, params) {
|
|
2516
|
+
const result = MulticallArgs.validate(buffer, { params });
|
|
2517
|
+
if (!result.ok) {
|
|
2518
|
+
throw new Error(`${MulticallArgs}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
|
|
2519
|
+
}
|
|
2520
|
+
this.__tnLastParams = result.params ?? params;
|
|
2521
|
+
this.__tnLastBuffer = buffer;
|
|
2522
|
+
}
|
|
2523
|
+
};
|
|
2373
2524
|
__tnRegisterFootprint2("MulticallArgs", (params) => MulticallArgs.__tnInvokeFootprint(params));
|
|
2374
2525
|
__tnRegisterValidate2("MulticallArgs", (buffer, params) => MulticallArgs.__tnInvokeValidate(buffer, params));
|
|
2375
2526
|
__tnRegisterDynamicValidate2("MulticallArgs", (buffer) => {
|
|
2376
2527
|
const result = MulticallArgs.validate(buffer);
|
|
2377
|
-
|
|
2528
|
+
const params = result.params;
|
|
2529
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
|
|
2378
2530
|
});
|
|
2379
2531
|
var __tn_ir_MulticallError = {
|
|
2380
2532
|
typeName: "MulticallError",
|
|
@@ -2483,7 +2635,8 @@ __tnRegisterFootprint2("MulticallError", (params) => MulticallError.__tnInvokeFo
|
|
|
2483
2635
|
__tnRegisterValidate2("MulticallError", (buffer, params) => MulticallError.__tnInvokeValidate(buffer, params));
|
|
2484
2636
|
__tnRegisterDynamicValidate2("MulticallError", (buffer) => {
|
|
2485
2637
|
const result = MulticallError.validate(buffer);
|
|
2486
|
-
|
|
2638
|
+
const params = result.params;
|
|
2639
|
+
return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt2(result.consumed), params };
|
|
2487
2640
|
});
|
|
2488
2641
|
|
|
2489
2642
|
// src/multicall/index.ts
|
|
@@ -2522,10 +2675,6 @@ var MULTICALL_PROGRAM_PUBKEY = new Uint8Array([
|
|
|
2522
2675
|
9
|
|
2523
2676
|
]);
|
|
2524
2677
|
var MULTICALL_PROGRAM_ADDRESS = encodeAddress(MULTICALL_PROGRAM_PUBKEY);
|
|
2525
|
-
function writeU16LE(target, offset, value) {
|
|
2526
|
-
target[offset] = value & 255;
|
|
2527
|
-
target[offset + 1] = value >> 8 & 255;
|
|
2528
|
-
}
|
|
2529
2678
|
function assertProgramIdx(programIdx) {
|
|
2530
2679
|
if (!Number.isInteger(programIdx) || programIdx < 0 || programIdx > 65535) {
|
|
2531
2680
|
throw new Error("programIdx must be 0-65535");
|
|
@@ -2550,15 +2699,7 @@ function buildMulticallInstruction(calls) {
|
|
|
2550
2699
|
if (!Array.isArray(calls)) throw new Error("calls must be an array");
|
|
2551
2700
|
if (calls.length > 65535) throw new Error("calls length must be 0-65535");
|
|
2552
2701
|
const encodedCalls = calls.map(buildInstructionData);
|
|
2553
|
-
const
|
|
2554
|
-
const output = new Uint8Array(totalLength);
|
|
2555
|
-
let offset = 0;
|
|
2556
|
-
writeU16LE(output, offset, calls.length);
|
|
2557
|
-
offset += 2;
|
|
2558
|
-
for (const call of encodedCalls) {
|
|
2559
|
-
output.set(call, offset);
|
|
2560
|
-
offset += call.length;
|
|
2561
|
-
}
|
|
2702
|
+
const output = new MulticallArgsBuilder().set_calls(encodedCalls).build();
|
|
2562
2703
|
const validation = MulticallArgs.validate(output);
|
|
2563
2704
|
if (!validation.ok || validation.consumed !== output.length) {
|
|
2564
2705
|
throw new Error(
|
|
@@ -2568,6 +2709,6 @@ function buildMulticallInstruction(calls) {
|
|
|
2568
2709
|
return output;
|
|
2569
2710
|
}
|
|
2570
2711
|
|
|
2571
|
-
export { InstructionData, InstructionDataBuilder, MULTICALL_PROGRAM_ADDRESS, MULTICALL_PROGRAM_PUBKEY, MulticallArgs, MulticallError, buildMulticallInstruction };
|
|
2712
|
+
export { InstructionData, InstructionDataBuilder, MULTICALL_PROGRAM_ADDRESS, MULTICALL_PROGRAM_PUBKEY, MulticallArgs, MulticallArgsBuilder, MulticallError, buildMulticallInstruction };
|
|
2572
2713
|
//# sourceMappingURL=index.js.map
|
|
2573
2714
|
//# sourceMappingURL=index.js.map
|