@intent-engine/client 0.1.23 → 0.1.26

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.
Files changed (72) hide show
  1. package/dist/src/budget.d.ts +6 -4
  2. package/dist/src/budget.js +24 -9
  3. package/dist/src/budget.js.map +1 -1
  4. package/dist/src/client-errors.d.ts +28 -0
  5. package/dist/src/client-errors.js +55 -0
  6. package/dist/src/client-errors.js.map +1 -0
  7. package/dist/src/client-intents.d.ts +12 -0
  8. package/dist/src/client-intents.js +133 -0
  9. package/dist/src/client-intents.js.map +1 -0
  10. package/dist/src/client-reads.d.ts +7 -0
  11. package/dist/src/client-reads.js +61 -0
  12. package/dist/src/client-reads.js.map +1 -0
  13. package/dist/src/client-settle.d.ts +2 -0
  14. package/dist/src/client-settle.js +84 -0
  15. package/dist/src/client-settle.js.map +1 -0
  16. package/dist/src/client-types.d.ts +145 -0
  17. package/dist/src/client-types.js +9 -0
  18. package/dist/src/client-types.js.map +1 -0
  19. package/dist/src/client-watch.d.ts +4 -0
  20. package/dist/src/client-watch.js +97 -0
  21. package/dist/src/client-watch.js.map +1 -0
  22. package/dist/src/client.d.ts +4 -140
  23. package/dist/src/client.js +16 -309
  24. package/dist/src/client.js.map +1 -1
  25. package/dist/src/confirmation.d.ts +11 -0
  26. package/dist/src/confirmation.js +94 -0
  27. package/dist/src/confirmation.js.map +1 -0
  28. package/dist/src/intent-notifications.d.ts +13 -0
  29. package/dist/src/intent-notifications.js +106 -0
  30. package/dist/src/intent-notifications.js.map +1 -0
  31. package/dist/src/job-deliveries.d.ts +40 -0
  32. package/dist/src/job-deliveries.js +92 -0
  33. package/dist/src/job-deliveries.js.map +1 -0
  34. package/dist/src/job-memos.d.ts +16 -0
  35. package/dist/src/job-memos.js +51 -0
  36. package/dist/src/job-memos.js.map +1 -0
  37. package/dist/src/job-origins.d.ts +30 -0
  38. package/dist/src/job-origins.js +53 -0
  39. package/dist/src/job-origins.js.map +1 -0
  40. package/dist/src/job-proofs.d.ts +17 -0
  41. package/dist/src/job-proofs.js +54 -0
  42. package/dist/src/job-proofs.js.map +1 -0
  43. package/dist/src/job-scan.d.ts +20 -0
  44. package/dist/src/job-scan.js +70 -0
  45. package/dist/src/job-scan.js.map +1 -0
  46. package/dist/src/job-specs.d.ts +40 -0
  47. package/dist/src/job-specs.js +107 -0
  48. package/dist/src/job-specs.js.map +1 -0
  49. package/dist/src/jobs.d.ts +6 -77
  50. package/dist/src/jobs.js +6 -186
  51. package/dist/src/jobs.js.map +1 -1
  52. package/dist/src/memoized-transport.d.ts +4 -0
  53. package/dist/src/memoized-transport.js +66 -0
  54. package/dist/src/memoized-transport.js.map +1 -0
  55. package/dist/src/rpc-retry.d.ts +16 -0
  56. package/dist/src/rpc-retry.js +62 -0
  57. package/dist/src/rpc-retry.js.map +1 -0
  58. package/dist/src/rpc-shapes.d.ts +230 -0
  59. package/dist/src/rpc-shapes.js +2 -0
  60. package/dist/src/rpc-shapes.js.map +1 -0
  61. package/dist/src/rpc-transport.d.ts +6 -0
  62. package/dist/src/rpc-transport.js +236 -0
  63. package/dist/src/rpc-transport.js.map +1 -0
  64. package/dist/src/svm.js +83 -27
  65. package/dist/src/svm.js.map +1 -1
  66. package/dist/src/transaction-keys.d.ts +6 -0
  67. package/dist/src/transaction-keys.js +19 -0
  68. package/dist/src/transaction-keys.js.map +1 -0
  69. package/dist/src/transport.d.ts +7 -223
  70. package/dist/src/transport.js +6 -467
  71. package/dist/src/transport.js.map +1 -1
  72. package/package.json +16 -5
@@ -0,0 +1,230 @@
1
+ import type { Address, Base64EncodedWireTransaction, Blockhash, Instruction, Signature, TransactionSigner } from "@solana/kit";
2
+ export type AccountView = {
3
+ owner: Address;
4
+ data: Uint8Array;
5
+ lamports: bigint;
6
+ executable?: boolean;
7
+ };
8
+ export type ProgramAccount = {
9
+ address: Address;
10
+ data: Uint8Array;
11
+ };
12
+ export type TokenHolding = {
13
+ account: Address;
14
+ mint: Address;
15
+ owner?: Address;
16
+ };
17
+ export type EngineTransaction = {
18
+ signature: string;
19
+ slot: bigint;
20
+ blockTime: bigint | null;
21
+ failed: boolean;
22
+ emitted: Uint8Array[];
23
+ emittedAccounts?: Address[][];
24
+ memos?: string[];
25
+ memoSigners?: Address[][];
26
+ feePayer?: Address;
27
+ called?: Uint8Array[];
28
+ calledAccounts?: Address[][];
29
+ tokens?: TokenHolding[];
30
+ unread?: true;
31
+ };
32
+ export type ListedSignature = {
33
+ signature: string;
34
+ slot: bigint;
35
+ blockTime: bigint | null;
36
+ failed: boolean;
37
+ memo: string | null;
38
+ };
39
+ export type Latest = {
40
+ blockhash: Blockhash;
41
+ lastValidBlockHeight: bigint;
42
+ };
43
+ export type IntentRead = {
44
+ minContextSlot?: bigint;
45
+ onSlot?: (slot: bigint) => void;
46
+ };
47
+ export type LookupTables = Readonly<Record<Address, Address[]>>;
48
+ export type Simulation = {
49
+ err: string | null;
50
+ logs: string[];
51
+ unitsConsumed: bigint | null;
52
+ accounts: (Uint8Array | null)[];
53
+ };
54
+ export interface Transport {
55
+ getAccount(address: Address): Promise<AccountView | null>;
56
+ getAccounts(addresses: readonly Address[]): Promise<(AccountView | null)[]>;
57
+ warm?(addresses: readonly Address[]): Promise<void>;
58
+ send(instructions: readonly Instruction[], payer: TransactionSigner): Promise<string>;
59
+ latestBlockhash(): Promise<Latest>;
60
+ sendWire(wire: Base64EncodedWireTransaction, latest: Latest): Promise<string>;
61
+ submitWire(wire: Base64EncodedWireTransaction): Promise<string>;
62
+ simulate(wire: Base64EncodedWireTransaction, watch?: readonly Address[]): Promise<Simulation>;
63
+ genesisHash(): Promise<string>;
64
+ intents(owner?: Address, read?: IntentRead): Promise<ProgramAccount[]>;
65
+ engineTransactions(limit: number, of?: Address, memo?: string): Promise<EngineTransaction[]>;
66
+ signaturesOf?(of: Address, limit: number, before?: string): Promise<ListedSignature[]>;
67
+ transactionsOf?(listed: readonly ListedSignature[]): Promise<EngineTransaction[]>;
68
+ transactionOf?(signature: string): Promise<EngineTransaction | null>;
69
+ firstAvailableSlot?(): Promise<bigint>;
70
+ recentFees(accounts: readonly Address[]): Promise<bigint[]>;
71
+ budget(instructions: readonly Instruction[], feePayer: Address, tables?: LookupTables): Promise<Instruction[]>;
72
+ airdrop(address: Address, lamports: bigint): Promise<string>;
73
+ }
74
+ export type Pending<T> = {
75
+ send(): Promise<T>;
76
+ };
77
+ export type RawAccount = {
78
+ owner: Address;
79
+ data: readonly [string, string];
80
+ lamports: bigint;
81
+ executable: boolean;
82
+ };
83
+ export type AtLeast = {
84
+ minContextSlot?: bigint;
85
+ };
86
+ export type ProgramEntry = {
87
+ pubkey: Address;
88
+ account: {
89
+ data: readonly [string, string];
90
+ };
91
+ };
92
+ export type Status = {
93
+ err: unknown;
94
+ confirmationStatus: string | null;
95
+ slot?: bigint;
96
+ };
97
+ export type RpcLike = {
98
+ getMultipleAccounts(addresses: Address[], config: {
99
+ encoding: "base64";
100
+ } & AtLeast): Pending<{
101
+ value: (RawAccount | null)[];
102
+ }>;
103
+ getAccountInfo(address: Address, config: {
104
+ encoding: "base64";
105
+ } & AtLeast): Pending<{
106
+ value: {
107
+ owner: Address;
108
+ data: readonly [string, string];
109
+ lamports: bigint;
110
+ executable: boolean;
111
+ } | null;
112
+ }>;
113
+ getLatestBlockhash(): Pending<{
114
+ value: {
115
+ blockhash: Blockhash;
116
+ lastValidBlockHeight: bigint;
117
+ };
118
+ }>;
119
+ sendTransaction(wire: Base64EncodedWireTransaction, config: {
120
+ encoding: "base64";
121
+ skipPreflight?: boolean;
122
+ }): Pending<Signature>;
123
+ simulateTransaction(wire: Base64EncodedWireTransaction, config: {
124
+ encoding: "base64";
125
+ sigVerify: false;
126
+ replaceRecentBlockhash: true;
127
+ accounts?: {
128
+ addresses: Address[];
129
+ encoding: "base64";
130
+ };
131
+ }): Pending<{
132
+ value: {
133
+ err: unknown;
134
+ logs: readonly string[] | null;
135
+ unitsConsumed?: bigint | undefined;
136
+ accounts?: readonly ({
137
+ data: readonly [string, string];
138
+ } | null)[] | null;
139
+ };
140
+ }>;
141
+ getSignatureStatuses(signatures: Signature[], config?: {
142
+ searchTransactionHistory: boolean;
143
+ }): Pending<{
144
+ context: {
145
+ slot: bigint;
146
+ };
147
+ value: readonly (Status | null)[];
148
+ }>;
149
+ getEpochInfo(): Pending<{
150
+ blockHeight: bigint;
151
+ absoluteSlot: bigint;
152
+ }>;
153
+ getFirstAvailableBlock?(): Pending<bigint>;
154
+ requestAirdrop(address: Address, lamports: bigint): Pending<Signature>;
155
+ getRecentPrioritizationFees(addresses: readonly Address[]): Pending<readonly {
156
+ prioritizationFee: bigint;
157
+ }[]>;
158
+ getGenesisHash(): Pending<string>;
159
+ getProgramAccounts(program: Address, config: {
160
+ encoding: "base64";
161
+ commitment: "confirmed";
162
+ filters: readonly ({
163
+ dataSize: bigint;
164
+ } | {
165
+ memcmp: {
166
+ offset: bigint;
167
+ bytes: string;
168
+ encoding: "base58";
169
+ };
170
+ })[];
171
+ withContext?: true;
172
+ } & AtLeast): Pending<readonly ProgramEntry[] | {
173
+ context: {
174
+ slot: bigint;
175
+ };
176
+ value: readonly ProgramEntry[];
177
+ }>;
178
+ getSignaturesForAddress(address: Address, config: {
179
+ limit: number;
180
+ before?: Signature;
181
+ } & AtLeast): Pending<readonly {
182
+ signature: Signature;
183
+ slot: bigint;
184
+ blockTime: bigint | null;
185
+ err: unknown;
186
+ memo?: string | null;
187
+ }[]>;
188
+ getTransaction(signature: Signature, config: {
189
+ encoding: "json";
190
+ maxSupportedTransactionVersion: 0;
191
+ commitment: "confirmed";
192
+ }): Pending<{
193
+ slot?: bigint;
194
+ blockTime?: bigint | null;
195
+ transaction: {
196
+ message: {
197
+ accountKeys: readonly Address[];
198
+ header?: {
199
+ numRequiredSignatures: number;
200
+ };
201
+ instructions?: readonly {
202
+ programIdIndex: number;
203
+ accounts?: readonly number[];
204
+ data: string;
205
+ }[];
206
+ };
207
+ };
208
+ meta: {
209
+ err?: unknown;
210
+ loadedAddresses?: {
211
+ writable: readonly Address[];
212
+ readonly: readonly Address[];
213
+ };
214
+ innerInstructions?: readonly {
215
+ instructions: readonly {
216
+ programIdIndex: number;
217
+ accounts?: readonly number[];
218
+ data: string;
219
+ }[];
220
+ }[] | null;
221
+ preTokenBalances?: readonly TokenBalance[] | null;
222
+ postTokenBalances?: readonly TokenBalance[] | null;
223
+ } | null;
224
+ } | null>;
225
+ };
226
+ export type TokenBalance = {
227
+ accountIndex: number;
228
+ mint: string;
229
+ owner?: string;
230
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rpc-shapes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-shapes.js","sourceRoot":"","sources":["../../src/rpc-shapes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { type SignatureWatch } from "./confirmation.js";
2
+ import type { RpcLike, Transport } from "./rpc-shapes.js";
3
+ export declare const MULTIPLE_ACCOUNTS_LIMIT = 100;
4
+ export declare const TRANSACTION_FETCHES = 4;
5
+ export declare const KEPT_TRANSACTIONS = 256;
6
+ export declare function rpcTransport(rpc: RpcLike, wait?: (ms: number) => Promise<void>, watch?: SignatureWatch): Transport;
@@ -0,0 +1,236 @@
1
+ import { inspect } from "node:util";
2
+ import { appendTransactionMessageInstructions, createTransactionMessage, getBase64EncodedWireTransaction, pipe, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signTransactionMessageWithSigners, getBase58Decoder, getBase58Encoder, } from "@solana/kit";
3
+ import { getIntentDiscriminatorBytes, getIntentSize, INTENT_ENGINE_PROGRAM_ADDRESS } from "@intent-engine/core";
4
+ import { confirmSent } from "./confirmation.js";
5
+ import { patiently } from "./rpc-retry.js";
6
+ import { holdingsOf, keysAt, MEMO_PROGRAM_ADDRESS, signersAmong } from "./transaction-keys.js";
7
+ const INTENT_OWNER_OFFSET = 8n;
8
+ const withoutMark = ({ complete: _, ...found }) => found;
9
+ export const MULTIPLE_ACCOUNTS_LIMIT = 100;
10
+ function viewOf(value) {
11
+ return value === null
12
+ ? null
13
+ : { owner: value.owner, data: new Uint8Array(Buffer.from(value.data[0], "base64")), lamports: value.lamports, executable: value.executable };
14
+ }
15
+ export const TRANSACTION_FETCHES = 4;
16
+ export const KEPT_TRANSACTIONS = 256;
17
+ export function rpcTransport(rpc, wait, watch) {
18
+ const fetched = new Map();
19
+ let reached;
20
+ const atLeast = (floor) => {
21
+ const slot = floor === undefined || (reached !== undefined && reached > floor) ? reached : floor;
22
+ return slot === undefined ? {} : { minContextSlot: slot };
23
+ };
24
+ const confirmed = async (signature, lastValidBlockHeight) => {
25
+ const { slot } = await confirmSent(rpc, signature, lastValidBlockHeight, wait, watch);
26
+ if (slot !== undefined && (reached === undefined || slot > reached)) {
27
+ reached = slot;
28
+ }
29
+ return signature;
30
+ };
31
+ const read = (signature) => patiently(() => rpc
32
+ .getTransaction(signature, {
33
+ encoding: "json",
34
+ maxSupportedTransactionVersion: 0,
35
+ commitment: "confirmed",
36
+ })
37
+ .send(), wait);
38
+ const parsed = (entry, tx) => {
39
+ const keys = [
40
+ ...(tx?.transaction.message.accountKeys ?? []),
41
+ ...(tx?.meta?.loadedAddresses?.writable ?? []),
42
+ ...(tx?.meta?.loadedAddresses?.readonly ?? []),
43
+ ];
44
+ const inner = (tx?.meta?.innerInstructions ?? []).flatMap((group) => group.instructions).filter((ix) => keys[ix.programIdIndex] === INTENT_ENGINE_PROGRAM_ADDRESS);
45
+ const emitted = inner.map((ix) => Uint8Array.from(getBase58Encoder().encode(ix.data)));
46
+ const signing = tx?.transaction.message.header?.numRequiredSignatures ?? 0;
47
+ const memoInstructions = (tx?.transaction.message.instructions ?? []).filter((ix) => keys[ix.programIdIndex] === MEMO_PROGRAM_ADDRESS);
48
+ const memos = memoInstructions.map((ix) => new TextDecoder().decode(Uint8Array.from(getBase58Encoder().encode(ix.data))));
49
+ const memoSigners = memoInstructions.map((ix) => signersAmong(keys, ix.accounts ?? [], signing));
50
+ const feePayer = tx?.transaction.message.accountKeys[0];
51
+ const engineCalls = (tx?.transaction.message.instructions ?? []).filter((ix) => keys[ix.programIdIndex] === INTENT_ENGINE_PROGRAM_ADDRESS);
52
+ const called = engineCalls.map((ix) => Uint8Array.from(getBase58Encoder().encode(ix.data)));
53
+ const tokens = holdingsOf(keys, [...(tx?.meta?.preTokenBalances ?? []), ...(tx?.meta?.postTokenBalances ?? [])]);
54
+ return {
55
+ signature: entry.signature,
56
+ slot: entry.slot,
57
+ blockTime: entry.blockTime,
58
+ failed: entry.failed,
59
+ emitted,
60
+ ...(inner.length === 0 ? {} : { emittedAccounts: inner.map((ix) => keysAt(keys, ix.accounts ?? [])) }),
61
+ ...(memos.length === 0 ? {} : { memos, memoSigners }),
62
+ ...(feePayer === undefined ? {} : { feePayer }),
63
+ ...(called.length === 0 ? {} : { called, calledAccounts: engineCalls.map((ix) => keysAt(keys, ix.accounts ?? [])) }),
64
+ ...(tokens.length === 0 ? {} : { tokens }),
65
+ ...(tx?.meta === null || tx?.meta === undefined ? { unread: true } : {}),
66
+ complete: tx?.meta !== null && tx?.meta !== undefined && entry.blockTime !== null,
67
+ };
68
+ };
69
+ const load = async (entry) => parsed(entry, await read(entry.signature));
70
+ const fetchOne = (entry) => {
71
+ const known = fetched.get(entry.signature);
72
+ if (known !== undefined) {
73
+ fetched.delete(entry.signature);
74
+ fetched.set(entry.signature, known);
75
+ return known.then(withoutMark);
76
+ }
77
+ const pending = load(entry);
78
+ fetched.set(entry.signature, pending);
79
+ pending.then((found) => {
80
+ if (!found.complete && fetched.get(entry.signature) === pending) {
81
+ fetched.delete(entry.signature);
82
+ }
83
+ }, () => {
84
+ if (fetched.get(entry.signature) === pending) {
85
+ fetched.delete(entry.signature);
86
+ }
87
+ });
88
+ return pending.then(withoutMark);
89
+ };
90
+ const fetchAll = async (listed) => {
91
+ const found = [];
92
+ for (let i = 0; i < listed.length; i += TRANSACTION_FETCHES) {
93
+ found.push(...(await Promise.all(listed.slice(i, i + TRANSACTION_FETCHES).map(fetchOne))));
94
+ }
95
+ for (const old of fetched.keys()) {
96
+ if (fetched.size <= KEPT_TRANSACTIONS) {
97
+ break;
98
+ }
99
+ fetched.delete(old);
100
+ }
101
+ return found;
102
+ };
103
+ const firstBlock = rpc.getFirstAvailableBlock?.bind(rpc);
104
+ const listSignatures = async (of, limit, before) => {
105
+ const listed = await patiently(() => rpc.getSignaturesForAddress(of, { limit, ...(before === undefined ? {} : { before: before }), ...atLeast() }).send(), wait);
106
+ return listed.map((entry) => ({
107
+ signature: entry.signature,
108
+ slot: entry.slot,
109
+ blockTime: entry.blockTime,
110
+ failed: entry.err !== null,
111
+ memo: entry.memo ?? null,
112
+ }));
113
+ };
114
+ return {
115
+ async getAccount(address) {
116
+ const { value } = await patiently(() => rpc.getAccountInfo(address, { encoding: "base64", ...atLeast() }).send(), wait);
117
+ return viewOf(value);
118
+ },
119
+ async getAccounts(addresses) {
120
+ const found = [];
121
+ for (let at = 0; at < addresses.length; at += MULTIPLE_ACCOUNTS_LIMIT) {
122
+ const chunk = addresses.slice(at, at + MULTIPLE_ACCOUNTS_LIMIT);
123
+ const { value } = await patiently(() => rpc.getMultipleAccounts([...chunk], { encoding: "base64", ...atLeast() }).send(), wait);
124
+ found.push(...chunk.map((_, i) => viewOf(value[i] ?? null)));
125
+ }
126
+ return found;
127
+ },
128
+ async send(instructions, payer) {
129
+ const { value: latest } = await patiently(() => rpc.getLatestBlockhash().send(), wait);
130
+ const message = pipe(createTransactionMessage({ version: 0 }), (m) => setTransactionMessageFeePayerSigner(payer, m), (m) => setTransactionMessageLifetimeUsingBlockhash(latest, m), (m) => appendTransactionMessageInstructions(instructions, m));
131
+ const signed = await signTransactionMessageWithSigners(message);
132
+ const wire = getBase64EncodedWireTransaction(signed);
133
+ const signature = await patiently(() => rpc.sendTransaction(wire, { encoding: "base64" }).send(), wait);
134
+ return confirmed(signature, latest.lastValidBlockHeight);
135
+ },
136
+ async airdrop(address, lamports) {
137
+ const { value: latest } = await patiently(() => rpc.getLatestBlockhash().send(), wait);
138
+ const signature = await patiently(() => rpc.requestAirdrop(address, lamports).send(), wait);
139
+ return confirmed(signature, latest.lastValidBlockHeight);
140
+ },
141
+ async latestBlockhash() {
142
+ const { value } = await patiently(() => rpc.getLatestBlockhash().send(), wait);
143
+ return value;
144
+ },
145
+ async sendWire(wire, latest) {
146
+ const signature = await patiently(() => rpc.sendTransaction(wire, { encoding: "base64" }).send(), wait);
147
+ return confirmed(signature, latest.lastValidBlockHeight);
148
+ },
149
+ async submitWire(wire) {
150
+ return patiently(() => rpc.sendTransaction(wire, { encoding: "base64", skipPreflight: true }).send(), wait);
151
+ },
152
+ async simulate(wire, watch = []) {
153
+ const { value } = await patiently(() => rpc
154
+ .simulateTransaction(wire, {
155
+ encoding: "base64",
156
+ sigVerify: false,
157
+ replaceRecentBlockhash: true,
158
+ ...(watch.length === 0 ? {} : { accounts: { addresses: [...watch], encoding: "base64" } }),
159
+ })
160
+ .send(), wait);
161
+ return {
162
+ err: value.err === null ? null : inspect(value.err, { depth: null, breakLength: Infinity }),
163
+ logs: [...(value.logs ?? [])],
164
+ unitsConsumed: value.unitsConsumed ?? null,
165
+ accounts: watch.map((_, i) => {
166
+ const found = value.accounts?.[i];
167
+ return found === null || found === undefined ? null : new Uint8Array(Buffer.from(found.data[0], "base64"));
168
+ }),
169
+ };
170
+ },
171
+ async genesisHash() {
172
+ return patiently(() => rpc.getGenesisHash().send(), wait);
173
+ },
174
+ async recentFees(accounts) {
175
+ const fees = await patiently(() => rpc.getRecentPrioritizationFees(accounts).send(), wait);
176
+ return fees.map((f) => f.prioritizationFee);
177
+ },
178
+ async budget(instructions) {
179
+ return [...instructions];
180
+ },
181
+ async engineTransactions(limit, of, memo) {
182
+ const listed = await listSignatures(of ?? INTENT_ENGINE_PROGRAM_ADDRESS, limit);
183
+ return fetchAll(memo === undefined ? listed : listed.filter((entry) => (entry.memo ?? "").includes(memo)));
184
+ },
185
+ signaturesOf: (of, limit, before) => listSignatures(of, limit, before),
186
+ transactionsOf: (listed) => fetchAll(listed),
187
+ async transactionOf(signature) {
188
+ const tx = await read(signature);
189
+ if (tx === null) {
190
+ return null;
191
+ }
192
+ const failed = tx.meta !== null && tx.meta.err !== undefined && tx.meta.err !== null;
193
+ return withoutMark(parsed({ signature, slot: tx.slot ?? 0n, blockTime: tx.blockTime ?? null, failed, memo: null }, tx));
194
+ },
195
+ ...(firstBlock === undefined ? {} : { firstAvailableSlot: () => patiently(() => firstBlock().send(), wait) }),
196
+ async intents(owner, read) {
197
+ const least = atLeast(read?.minContextSlot);
198
+ const found = await patiently(async () => {
199
+ const response = await rpc
200
+ .getProgramAccounts(INTENT_ENGINE_PROGRAM_ADDRESS, {
201
+ encoding: "base64",
202
+ commitment: "confirmed",
203
+ filters: [
204
+ { dataSize: BigInt(getIntentSize()) },
205
+ {
206
+ memcmp: {
207
+ offset: 0n,
208
+ bytes: getBase58Decoder().decode(getIntentDiscriminatorBytes()),
209
+ encoding: "base58",
210
+ },
211
+ },
212
+ ...(owner === undefined
213
+ ? []
214
+ : [{ memcmp: { offset: INTENT_OWNER_OFFSET, bytes: owner, encoding: "base58" } }]),
215
+ ],
216
+ ...least,
217
+ ...(read === undefined ? {} : { withContext: true }),
218
+ })
219
+ .send();
220
+ if (!("context" in response)) {
221
+ return response;
222
+ }
223
+ if (least.minContextSlot !== undefined && response.context.slot < least.minContextSlot) {
224
+ throw new Error(`Minimum context slot has not been reached: the node read at slot ${response.context.slot}, below ${least.minContextSlot}`);
225
+ }
226
+ read?.onSlot?.(response.context.slot);
227
+ return response.value;
228
+ }, wait);
229
+ return found.map(({ pubkey, account }) => ({
230
+ address: pubkey,
231
+ data: new Uint8Array(Buffer.from(account.data[0], "base64")),
232
+ }));
233
+ },
234
+ };
235
+ }
236
+ //# sourceMappingURL=rpc-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-transport.js","sourceRoot":"","sources":["../../src/rpc-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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M,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;gBACzC,OAAO,EAAE,MAAM;gBACf,IAAI,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;aAC7D,CAAC,CAAC,CAAC;QACN,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/src/svm.js CHANGED
@@ -1,8 +1,12 @@
1
- import { appendTransactionMessageInstructions, createTransactionMessage, getBase64Encoder, getCompiledTransactionMessageDecoder, getSignatureFromTransaction, getTransactionDecoder, lamports, pipe, setTransactionMessageFeePayerSigner, signTransactionMessageWithSigners, } from "@solana/kit";
1
+ import { appendTransactionMessageInstructions, createTransactionMessage, getBase64Encoder, getCompiledTransactionMessageDecoder, getCompiledTransactionMessageEncoder, getAddressDecoder, getSignatureFromTransaction, getTransactionDecoder, lamports, pipe, setTransactionMessageFeePayerSigner, signTransactionMessageWithSigners, } from "@solana/kit";
2
2
  import { getIntentDecoder, getIntentDiscriminatorBytes, INTENT_ENGINE_PROGRAM_ADDRESS } from "@intent-engine/core";
3
3
  import { FailedTransactionMetadata } from "litesvm";
4
- import { MEMO_PROGRAM_ADDRESS } from "./transport.js";
4
+ import { TOKEN_PROGRAMS } from "./accounts.js";
5
+ import { keysAt, MEMO_PROGRAM_ADDRESS, signersAmong, } from "./transport.js";
6
+ const TOKEN_HEAD = 64;
7
+ const LOOKUP_TABLE_HEAD = 56;
5
8
  export const SVM_GENESIS_HASH = "11111111111111111111111111111111";
9
+ const sigverifyOf = (svm) => svm.inner?.getSigverify?.() ?? true;
6
10
  const decodeWire = (wire) => getTransactionDecoder().decode(getBase64Encoder().encode(wire));
7
11
  export function svmTransport(svm, options = {}) {
8
12
  const seen = new Set();
@@ -12,13 +16,39 @@ export function svmTransport(svm, options = {}) {
12
16
  return account.exists && account.programAddress === INTENT_ENGINE_PROGRAM_ADDRESS ? new Uint8Array(account.data) : null;
13
17
  };
14
18
  const history = [];
19
+ const byId = new Map();
20
+ const holdings = (keys) => keys.flatMap((account) => {
21
+ const held = svm.getAccount(account);
22
+ if (!held.exists || !TOKEN_PROGRAMS.includes(held.programAddress) || held.data.length < TOKEN_HEAD) {
23
+ return [];
24
+ }
25
+ const decoder = getAddressDecoder();
26
+ return [{ account, mint: decoder.decode(held.data.subarray(0, 32)), owner: decoder.decode(held.data.subarray(32, TOKEN_HEAD)) }];
27
+ });
28
+ const tableAddresses = (table) => {
29
+ const held = svm.getAccount(table);
30
+ if (!held.exists || held.data.length < LOOKUP_TABLE_HEAD) {
31
+ return [];
32
+ }
33
+ const decoder = getAddressDecoder();
34
+ return Array.from({ length: Math.floor((held.data.length - LOOKUP_TABLE_HEAD) / 32) }, (_, i) => decoder.decode(held.data.subarray(LOOKUP_TABLE_HEAD + i * 32, LOOKUP_TABLE_HEAD + (i + 1) * 32)));
35
+ };
36
+ const loaded = (compiled) => {
37
+ const lookups = "addressTableLookups" in compiled ? (compiled.addressTableLookups ?? []) : [];
38
+ const tables = lookups.map(({ lookupTableAddress }) => tableAddresses(lookupTableAddress));
39
+ const pick = (indexes) => lookups.flatMap((lookup, i) => indexes(lookup).flatMap((index) => tables[i]?.[index] ?? []));
40
+ return [...compiled.staticAccounts, ...pick(({ writableIndexes }) => writableIndexes), ...pick(({ readonlyIndexes }) => readonlyIndexes)];
41
+ };
15
42
  const landed = (tx) => {
43
+ const compiled = getCompiledTransactionMessageDecoder().decode(tx.messageBytes);
44
+ const keys = loaded(compiled);
45
+ const before = holdings(keys);
16
46
  const result = svm.sendTransaction(tx);
17
47
  if (result instanceof FailedTransactionMetadata) {
18
48
  throw new Error(`${String(result.err())}\n${result.meta().logs().join("\n")}`);
19
49
  }
20
- const compiled = getCompiledTransactionMessageDecoder().decode(tx.messageBytes);
21
- const keys = compiled.staticAccounts;
50
+ const after = holdings(keys).filter((held) => !before.some(({ account }) => account === held.account));
51
+ const tokens = [...before, ...after];
22
52
  for (const address of keys) {
23
53
  const data = engineData(address);
24
54
  if (data !== null && tag.every((b, i) => data[i] === b)) {
@@ -27,27 +57,31 @@ export function svmTransport(svm, options = {}) {
27
57
  }
28
58
  const signature = getSignatureFromTransaction(tx);
29
59
  const clock = svm.getClock();
30
- const memos = ("instructions" in compiled ? compiled.instructions : [])
31
- .filter((ix) => keys[ix.programAddressIndex] === MEMO_PROGRAM_ADDRESS)
32
- .map((ix) => new TextDecoder().decode(Uint8Array.from(ix.data ?? [])));
60
+ const memoInstructions = ("instructions" in compiled ? compiled.instructions : []).filter((ix) => keys[ix.programAddressIndex] === MEMO_PROGRAM_ADDRESS);
61
+ const memos = memoInstructions.map((ix) => new TextDecoder().decode(Uint8Array.from(ix.data ?? [])));
62
+ const memoSigners = memoInstructions.map((ix) => signersAmong(keys, ix.accountIndices ?? [], compiled.header.numSignerAccounts));
33
63
  const feePayer = keys[0];
34
- history.unshift({
35
- touched: new Set(keys),
36
- found: {
37
- signature,
38
- slot: clock.slot,
39
- blockTime: clock.unixTimestamp,
40
- failed: false,
41
- emitted: result
42
- .innerInstructions()
43
- .flat()
44
- .map((inner) => inner.instruction())
45
- .filter((ix) => keys[ix.programIdIndex()] === INTENT_ENGINE_PROGRAM_ADDRESS)
46
- .map((ix) => new Uint8Array(ix.data())),
47
- ...(memos.length === 0 ? {} : { memos }),
48
- ...(feePayer === undefined ? {} : { feePayer }),
49
- },
50
- });
64
+ const engineCalls = ("instructions" in compiled ? compiled.instructions : []).filter((ix) => keys[ix.programAddressIndex] === INTENT_ENGINE_PROGRAM_ADDRESS);
65
+ const called = engineCalls.map((ix) => Uint8Array.from(ix.data ?? []));
66
+ const inner = result
67
+ .innerInstructions()
68
+ .flat()
69
+ .map((ix) => ix.instruction())
70
+ .filter((ix) => keys[ix.programIdIndex()] === INTENT_ENGINE_PROGRAM_ADDRESS);
71
+ const found = {
72
+ signature,
73
+ slot: clock.slot,
74
+ blockTime: clock.unixTimestamp,
75
+ failed: false,
76
+ emitted: inner.map((ix) => new Uint8Array(ix.data())),
77
+ ...(inner.length === 0 ? {} : { emittedAccounts: inner.map((ix) => keysAt(keys, ix.accounts())) }),
78
+ ...(memos.length === 0 ? {} : { memos, memoSigners }),
79
+ ...(feePayer === undefined ? {} : { feePayer }),
80
+ ...(called.length === 0 ? {} : { called, calledAccounts: engineCalls.map((ix) => keysAt(keys, ix.accountIndices ?? [])) }),
81
+ ...(tokens.length === 0 ? {} : { tokens }),
82
+ };
83
+ history.unshift({ touched: new Set(keys), found });
84
+ byId.set(signature, found);
51
85
  return signature;
52
86
  };
53
87
  const getAccount = async (address) => {
@@ -69,10 +103,18 @@ export function svmTransport(svm, options = {}) {
69
103
  submitWire: async (wire) => landed(decodeWire(wire)),
70
104
  simulate: async (wire, watch = []) => {
71
105
  const tx = decodeWire(wire);
106
+ const compiled = getCompiledTransactionMessageDecoder().decode(tx.messageBytes);
107
+ const messageBytes = getCompiledTransactionMessageEncoder().encode({ ...compiled, lifetimeToken: svm.latestBlockhash() });
72
108
  const unsigned = Object.fromEntries(Object.entries(tx.signatures).map(([signer, signature]) => [signer, signature ?? new Uint8Array(64)]));
73
- svm.withSigverify(false).withBlockhashCheck(false);
74
- const result = svm.simulateTransaction({ ...tx, signatures: unsigned });
75
- svm.withSigverify(true).withBlockhashCheck(true);
109
+ const verifying = sigverifyOf(svm);
110
+ svm.withSigverify(false);
111
+ let result;
112
+ try {
113
+ result = svm.simulateTransaction({ messageBytes, signatures: unsigned });
114
+ }
115
+ finally {
116
+ svm.withSigverify(verifying);
117
+ }
76
118
  const meta = result.meta();
77
119
  return {
78
120
  err: result instanceof FailedTransactionMetadata ? String(result.err()) : null,
@@ -97,6 +139,20 @@ export function svmTransport(svm, options = {}) {
97
139
  .slice(0, limit)
98
140
  .map(({ found }) => found)
99
141
  .filter(({ memos }) => memo === undefined || (memos ?? []).some((text) => text.includes(memo))),
142
+ signaturesOf: async (of, limit, before) => {
143
+ const touching = history.filter(({ touched }) => touched.has(of));
144
+ const start = before === undefined ? 0 : touching.findIndex(({ found }) => found.signature === before) + 1;
145
+ return (start === 0 && before !== undefined ? [] : touching.slice(start, start + limit)).map(({ found }) => ({
146
+ signature: found.signature,
147
+ slot: found.slot,
148
+ blockTime: found.blockTime,
149
+ failed: found.failed,
150
+ memo: found.memos === undefined ? null : found.memos.map((text) => `[${text.length}] ${text}`).join("; "),
151
+ }));
152
+ },
153
+ transactionsOf: async (listed) => listed.flatMap(({ signature }) => byId.get(signature) ?? []),
154
+ transactionOf: async (signature) => byId.get(signature) ?? null,
155
+ firstAvailableSlot: async () => 0n,
100
156
  recentFees: async () => [],
101
157
  budget: async (instructions) => [...instructions],
102
158
  airdrop: async (address, amount) => {