@intent-engine/client 0.1.23 → 0.1.27
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/src/accounts.d.ts +6 -0
- package/dist/src/accounts.js +15 -1
- package/dist/src/accounts.js.map +1 -1
- package/dist/src/budget.d.ts +6 -4
- package/dist/src/budget.js +24 -9
- package/dist/src/budget.js.map +1 -1
- package/dist/src/client-committee.d.ts +8 -0
- package/dist/src/client-committee.js +34 -0
- package/dist/src/client-committee.js.map +1 -0
- package/dist/src/client-errors.d.ts +33 -0
- package/dist/src/client-errors.js +65 -0
- package/dist/src/client-errors.js.map +1 -0
- package/dist/src/client-intents.d.ts +12 -0
- package/dist/src/client-intents.js +140 -0
- package/dist/src/client-intents.js.map +1 -0
- package/dist/src/client-reads.d.ts +7 -0
- package/dist/src/client-reads.js +61 -0
- package/dist/src/client-reads.js.map +1 -0
- package/dist/src/client-settle.d.ts +7 -0
- package/dist/src/client-settle.js +180 -0
- package/dist/src/client-settle.js.map +1 -0
- package/dist/src/client-types.d.ts +192 -0
- package/dist/src/client-types.js +9 -0
- package/dist/src/client-types.js.map +1 -0
- package/dist/src/client-watch.d.ts +4 -0
- package/dist/src/client-watch.js +97 -0
- package/dist/src/client-watch.js.map +1 -0
- package/dist/src/client.d.ts +5 -140
- package/dist/src/client.js +28 -309
- package/dist/src/client.js.map +1 -1
- package/dist/src/confirmation.d.ts +11 -0
- package/dist/src/confirmation.js +94 -0
- package/dist/src/confirmation.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/intent-notifications.d.ts +13 -0
- package/dist/src/intent-notifications.js +106 -0
- package/dist/src/intent-notifications.js.map +1 -0
- package/dist/src/job-deliveries.d.ts +40 -0
- package/dist/src/job-deliveries.js +92 -0
- package/dist/src/job-deliveries.js.map +1 -0
- package/dist/src/job-memos.d.ts +17 -0
- package/dist/src/job-memos.js +64 -0
- package/dist/src/job-memos.js.map +1 -0
- package/dist/src/job-origins.d.ts +30 -0
- package/dist/src/job-origins.js +53 -0
- package/dist/src/job-origins.js.map +1 -0
- package/dist/src/job-proofs.d.ts +17 -0
- package/dist/src/job-proofs.js +54 -0
- package/dist/src/job-proofs.js.map +1 -0
- package/dist/src/job-scan.d.ts +20 -0
- package/dist/src/job-scan.js +70 -0
- package/dist/src/job-scan.js.map +1 -0
- package/dist/src/job-specs.d.ts +40 -0
- package/dist/src/job-specs.js +107 -0
- package/dist/src/job-specs.js.map +1 -0
- package/dist/src/jobs.d.ts +6 -77
- package/dist/src/jobs.js +6 -186
- package/dist/src/jobs.js.map +1 -1
- package/dist/src/memoized-transport.d.ts +4 -0
- package/dist/src/memoized-transport.js +66 -0
- package/dist/src/memoized-transport.js.map +1 -0
- package/dist/src/reputation.d.ts +53 -0
- package/dist/src/reputation.js +176 -0
- package/dist/src/reputation.js.map +1 -0
- package/dist/src/rpc-retry.d.ts +16 -0
- package/dist/src/rpc-retry.js +62 -0
- package/dist/src/rpc-retry.js.map +1 -0
- package/dist/src/rpc-shapes.d.ts +230 -0
- package/dist/src/rpc-shapes.js +2 -0
- package/dist/src/rpc-shapes.js.map +1 -0
- package/dist/src/rpc-transport.d.ts +6 -0
- package/dist/src/rpc-transport.js +236 -0
- package/dist/src/rpc-transport.js.map +1 -0
- package/dist/src/simple-orders.d.ts +24 -0
- package/dist/src/simple-orders.js +101 -0
- package/dist/src/simple-orders.js.map +1 -0
- package/dist/src/simple-tokens.d.ts +19 -0
- package/dist/src/simple-tokens.js +84 -0
- package/dist/src/simple-tokens.js.map +1 -0
- package/dist/src/simple-types.d.ts +111 -0
- package/dist/src/simple-types.js +2 -0
- package/dist/src/simple-types.js.map +1 -0
- package/dist/src/simple-work.d.ts +12 -0
- package/dist/src/simple-work.js +69 -0
- package/dist/src/simple-work.js.map +1 -0
- package/dist/src/simple.d.ts +6 -0
- package/dist/src/simple.js +53 -0
- package/dist/src/simple.js.map +1 -0
- package/dist/src/svm.js +83 -27
- package/dist/src/svm.js.map +1 -1
- package/dist/src/transaction-keys.d.ts +6 -0
- package/dist/src/transaction-keys.js +19 -0
- package/dist/src/transaction-keys.js.map +1 -0
- package/dist/src/transport.d.ts +7 -223
- package/dist/src/transport.js +6 -467
- package/dist/src/transport.js.map +1 -1
- package/package.json +17 -6
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { getTransferSolInstruction } from "@solana-program/system";
|
|
2
|
+
import { decodeEvent, feedbackMemo, DELIVERY_MEMO_PREFIX, FILL_ATTESTED_SPLIT_COMMITTEE_DISCRIMINATOR, FILL_ATTESTED_SPLIT_DISCRIMINATOR, findAssociatedTokenAddress, getFillAttestedSplitCommitteeInstructionDataDecoder, getFillAttestedSplitInstructionDataDecoder, parseDeliveryMemo, parseFeedbackMemo, splitN, } from "@intent-engine/core";
|
|
3
|
+
import { mintOf } from "./accounts.js";
|
|
4
|
+
import { loadCommittee } from "./client-committee.js";
|
|
5
|
+
import { HISTORY_LIMIT } from "./client-types.js";
|
|
6
|
+
import { memoInstruction, recordedDelivery } from "./job-memos.js";
|
|
7
|
+
import { NotSettleable } from "./client-errors.js";
|
|
8
|
+
import { engineCalls } from "./job-origins.js";
|
|
9
|
+
import { DELIVERY_PAGES, MEMOS_PER_TRANSACTION, scan } from "./job-scan.js";
|
|
10
|
+
const SPLIT_INTENT_ACCOUNT = 2;
|
|
11
|
+
const startsWith = (data, head) => data.length >= head.length && Array.from(head).every((b, i) => data[i] === b);
|
|
12
|
+
function splitClaim(release, intent) {
|
|
13
|
+
for (const { data, accounts } of engineCalls(release)) {
|
|
14
|
+
if (accounts?.[SPLIT_INTENT_ACCOUNT] !== intent) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
if (startsWith(data, FILL_ATTESTED_SPLIT_DISCRIMINATOR)) {
|
|
19
|
+
return getFillAttestedSplitInstructionDataDecoder().decode(data).claim;
|
|
20
|
+
}
|
|
21
|
+
if (startsWith(data, FILL_ATTESTED_SPLIT_COMMITTEE_DISCRIMINATOR)) {
|
|
22
|
+
return getFillAttestedSplitCommitteeInstructionDataDecoder().decode(data).claim;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function announcedBy(wallet, transactions) {
|
|
32
|
+
const found = new Map();
|
|
33
|
+
for (const { signature, slot, blockTime, failed, memos, feePayer } of transactions) {
|
|
34
|
+
if (failed || feePayer !== wallet) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
for (const memo of (memos ?? []).slice(0, MEMOS_PER_TRANSACTION).map(parseDeliveryMemo)) {
|
|
38
|
+
if (memo === null) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const key = `${memo.intent}:${memo.sha256}`;
|
|
42
|
+
const held = found.get(key);
|
|
43
|
+
if (held === undefined || slot < held.slot || (slot === held.slot && signature < held.announced)) {
|
|
44
|
+
found.set(key, { intent: memo.intent, sha256: memo.sha256, announced: signature, slot, blockTime });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...found.values()];
|
|
49
|
+
}
|
|
50
|
+
function eventsOf(transactions, intent) {
|
|
51
|
+
return transactions
|
|
52
|
+
.filter(({ failed }) => !failed)
|
|
53
|
+
.flatMap((transaction) => transaction.emitted
|
|
54
|
+
.map((data) => decodeEvent(data))
|
|
55
|
+
.filter((event) => event !== null && "intent" in event.fields && event.fields.intent === intent)
|
|
56
|
+
.map((event) => ({ event, transaction })));
|
|
57
|
+
}
|
|
58
|
+
function feedbackOf(transactions, intent, owner) {
|
|
59
|
+
const ordered = [...transactions].filter(({ failed }) => !failed).sort((a, b) => (a.slot < b.slot ? -1 : a.slot > b.slot ? 1 : 0));
|
|
60
|
+
for (const { memos, memoSigners } of ordered) {
|
|
61
|
+
for (const [i, text] of (memos ?? []).entries()) {
|
|
62
|
+
const memo = parseFeedbackMemo(text);
|
|
63
|
+
if (memo !== null && memo.intent === intent && memoSigners?.[i]?.includes(owner) === true) {
|
|
64
|
+
return memo.score;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
async function judgeOf(transport, attestor) {
|
|
71
|
+
const committee = await loadCommittee(transport, attestor);
|
|
72
|
+
return committee === null ? undefined : [...committee.members];
|
|
73
|
+
}
|
|
74
|
+
async function recordOf(transport, wallet, work, history) {
|
|
75
|
+
const transactions = await transport.engineTransactions(history, work.intent);
|
|
76
|
+
const events = eventsOf(transactions, work.intent);
|
|
77
|
+
const created = events.find(({ event }) => event.name === "IntentCreated")?.event;
|
|
78
|
+
const released = events.find(({ event }) => event.name === "IntentAttested" || event.name === "IntentSplit");
|
|
79
|
+
const refunded = events.some(({ event }) => event.name === "IntentCancelled" || event.name === "IntentExpired");
|
|
80
|
+
const complete = created !== undefined || transactions.length < history;
|
|
81
|
+
const base = { ...work, selfDealt: false };
|
|
82
|
+
const owner = created?.name === "IntentCreated" ? created.fields.owner : released?.event.name === "IntentAttested" || released?.event.name === "IntentSplit" ? released.event.fields.owner : undefined;
|
|
83
|
+
const mint = created?.name === "IntentCreated" ? created.fields.inputMint : undefined;
|
|
84
|
+
if (released === undefined || (released.event.name !== "IntentAttested" && released.event.name !== "IntentSplit")) {
|
|
85
|
+
const outcome = refunded ? "refunded" : "open";
|
|
86
|
+
return { complete, record: { ...base, outcome, ...(owner === undefined ? {} : { owner }), ...(mint === undefined ? {} : { mint }) } };
|
|
87
|
+
}
|
|
88
|
+
const { event, transaction } = released;
|
|
89
|
+
const attestor = event.fields.attestor;
|
|
90
|
+
const committee = await judgeOf(transport, attestor);
|
|
91
|
+
const selfDealt = event.fields.owner === wallet ||
|
|
92
|
+
attestor === wallet ||
|
|
93
|
+
event.fields.owner === attestor ||
|
|
94
|
+
(committee !== undefined && (committee.includes(wallet) || committee.includes(event.fields.owner)));
|
|
95
|
+
const recorded = recordedDelivery(transactions, transaction, attestor);
|
|
96
|
+
const common = {
|
|
97
|
+
...base,
|
|
98
|
+
owner: event.fields.owner,
|
|
99
|
+
attestor,
|
|
100
|
+
...(committee === undefined ? {} : { committee }),
|
|
101
|
+
...(mint === undefined ? {} : { mint }),
|
|
102
|
+
release: transaction.signature,
|
|
103
|
+
selfDealt,
|
|
104
|
+
};
|
|
105
|
+
if (recorded !== work.sha256) {
|
|
106
|
+
return { complete, record: { ...common, outcome: "paid-other" } };
|
|
107
|
+
}
|
|
108
|
+
let earned;
|
|
109
|
+
if (event.name === "IntentAttested") {
|
|
110
|
+
if (mint === undefined) {
|
|
111
|
+
return { complete: false, record: { ...common, outcome: "unknown" } };
|
|
112
|
+
}
|
|
113
|
+
const { tokenProgram } = await mintOf(transport, mint);
|
|
114
|
+
const own = await findAssociatedTokenAddress({ owner: wallet, mint, tokenProgram });
|
|
115
|
+
earned = event.fields.payee === own ? event.fields.net : undefined;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const claim = splitClaim(transaction, work.intent);
|
|
119
|
+
const at = claim?.recipients.indexOf(wallet) ?? -1;
|
|
120
|
+
earned = claim === null || at < 0 ? undefined : splitN(event.fields.net, claim.weights)[at];
|
|
121
|
+
}
|
|
122
|
+
if (earned === undefined) {
|
|
123
|
+
return { complete, record: { ...common, outcome: "paid-other" } };
|
|
124
|
+
}
|
|
125
|
+
const feedback = feedbackOf(transactions, work.intent, event.fields.owner);
|
|
126
|
+
return { complete, record: { ...common, outcome: "paid", earned, ...(feedback === undefined ? {} : { feedback }) } };
|
|
127
|
+
}
|
|
128
|
+
export async function reputationOf(transport, wallet, options = {}) {
|
|
129
|
+
const { firstAvailableSlot } = transport;
|
|
130
|
+
const fullLedger = async () => firstAvailableSlot !== undefined && (await firstAvailableSlot.call(transport)) === 0n;
|
|
131
|
+
const scanned = await scan(transport, wallet, { memo: DELIVERY_MEMO_PREFIX, pages: options.pages ?? DELIVERY_PAGES, covered: fullLedger });
|
|
132
|
+
const works = announcedBy(wallet, scanned.transactions);
|
|
133
|
+
const read = await Promise.all(works.map((work) => recordOf(transport, wallet, work, options.history ?? HISTORY_LIMIT)));
|
|
134
|
+
const records = read.map(({ record }) => record).sort((a, b) => (a.slot < b.slot ? -1 : a.slot > b.slot ? 1 : 0));
|
|
135
|
+
const fair = records.filter((r) => r.outcome === "paid" && !r.selfDealt);
|
|
136
|
+
const earned = new Map();
|
|
137
|
+
for (const r of fair) {
|
|
138
|
+
if (r.mint !== undefined && r.earned !== undefined) {
|
|
139
|
+
earned.set(r.mint, (earned.get(r.mint) ?? 0n) + r.earned);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const scores = fair.flatMap((r) => (r.feedback === undefined ? [] : [r.feedback]));
|
|
143
|
+
const times = records.flatMap((r) => (r.blockTime === null ? [] : [r.blockTime]));
|
|
144
|
+
return {
|
|
145
|
+
wallet,
|
|
146
|
+
complete: scanned.complete && read.every(({ complete }) => complete),
|
|
147
|
+
announced: records.length,
|
|
148
|
+
paid: fair.length,
|
|
149
|
+
selfDealt: records.filter((r) => r.outcome === "paid" && r.selfDealt).length,
|
|
150
|
+
payers: new Set(fair.map((r) => r.owner)).size,
|
|
151
|
+
judges: new Set(fair.map((r) => r.attestor)).size,
|
|
152
|
+
committeeJudged: fair.filter((r) => r.committee !== undefined).length,
|
|
153
|
+
earned: [...earned].map(([mint, amount]) => ({ mint, amount })),
|
|
154
|
+
feedback: { count: scores.length, average: scores.length === 0 ? null : scores.reduce((a, b) => a + b, 0) / scores.length },
|
|
155
|
+
first: times.length === 0 ? null : times.reduce((a, b) => (a < b ? a : b)),
|
|
156
|
+
last: times.length === 0 ? null : times.reduce((a, b) => (a > b ? a : b)),
|
|
157
|
+
records,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export async function feedbackInstructions(transport, input, history = HISTORY_LIMIT) {
|
|
161
|
+
const memo = feedbackMemo({ intent: input.intent, score: input.score, ...(input.note === undefined ? {} : { note: input.note }) });
|
|
162
|
+
const transactions = await transport.engineTransactions(history, input.intent);
|
|
163
|
+
const events = eventsOf(transactions, input.intent);
|
|
164
|
+
const released = events.find(({ event }) => event.name === "IntentAttested" || event.name === "IntentSplit")?.event;
|
|
165
|
+
if (released === undefined || (released.name !== "IntentAttested" && released.name !== "IntentSplit")) {
|
|
166
|
+
throw new NotSettleable(input.intent, "has no release among its recent transactions, so there is no work to give feedback on");
|
|
167
|
+
}
|
|
168
|
+
if (released.fields.owner !== input.owner.address) {
|
|
169
|
+
throw new NotSettleable(input.intent, `was paid for by ${released.fields.owner}, and only that owner gives feedback on it`);
|
|
170
|
+
}
|
|
171
|
+
if (feedbackOf(transactions, input.intent, input.owner.address) !== undefined) {
|
|
172
|
+
throw new NotSettleable(input.intent, "already has its owner's feedback; the first one counts");
|
|
173
|
+
}
|
|
174
|
+
return [memoInstruction(input.owner, memo), getTransferSolInstruction({ source: input.owner, destination: input.intent, amount: 0n })];
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=reputation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reputation.js","sourceRoot":"","sources":["../../src/reputation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,oBAAoB,EAEpB,2CAA2C,EAC3C,iCAAiC,EACjC,0BAA0B,EAC1B,mDAAmD,EACnD,0CAA0C,EAC1C,iBAAiB,EACjB,iBAAiB,EACjB,MAAM,GACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,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C,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;QAC9E,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,wDAAwD,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,yBAAyB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACzI,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const POLL_MS = 500;
|
|
2
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
3
|
+
export declare const RATE_LIMIT_ATTEMPTS = 6;
|
|
4
|
+
export declare function rateLimited(error: unknown): boolean;
|
|
5
|
+
export declare const MIN_CONTEXT_SLOT_NOT_REACHED = -32016;
|
|
6
|
+
export declare function behindMinSlot(error: unknown): boolean;
|
|
7
|
+
export declare function patiently<T>(call: () => Promise<T>, wait?: (ms: number) => Promise<void>): Promise<T>;
|
|
8
|
+
export declare class Charged extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class FailedOnChain extends Charged {
|
|
12
|
+
}
|
|
13
|
+
export declare class BlockhashExpired extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare const neverLanded: (error: unknown) => boolean;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isSolanaError, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR } from "@solana/kit";
|
|
2
|
+
export const POLL_MS = 500;
|
|
3
|
+
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
+
export const RATE_LIMIT_ATTEMPTS = 6;
|
|
5
|
+
const CAUSE_DEPTH = 8;
|
|
6
|
+
function causes(error) {
|
|
7
|
+
const chain = [];
|
|
8
|
+
for (let link = error; link instanceof Error && chain.length < CAUSE_DEPTH; link = link.cause) {
|
|
9
|
+
chain.push(link);
|
|
10
|
+
}
|
|
11
|
+
return chain;
|
|
12
|
+
}
|
|
13
|
+
const said = (chain, text) => chain.some((link) => !isSolanaError(link) && text.test(link.message));
|
|
14
|
+
export function rateLimited(error) {
|
|
15
|
+
if (!(error instanceof Error) || error instanceof Charged) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const chain = causes(error);
|
|
19
|
+
for (const link of chain) {
|
|
20
|
+
if (isSolanaError(link, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR)) {
|
|
21
|
+
return link.context.statusCode === 429;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return said(chain, /\b429\b/);
|
|
25
|
+
}
|
|
26
|
+
export const MIN_CONTEXT_SLOT_NOT_REACHED = -32016;
|
|
27
|
+
export function behindMinSlot(error) {
|
|
28
|
+
if (!(error instanceof Error) || error instanceof Charged) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const chain = causes(error);
|
|
32
|
+
return chain.some((link) => isSolanaError(link, MIN_CONTEXT_SLOT_NOT_REACHED)) || said(chain, /-32016\b|minimum context slot/i);
|
|
33
|
+
}
|
|
34
|
+
export async function patiently(call, wait = sleep) {
|
|
35
|
+
for (let attempt = 1;; attempt++) {
|
|
36
|
+
try {
|
|
37
|
+
return await call();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (!(rateLimited(error) || behindMinSlot(error)) || attempt >= RATE_LIMIT_ATTEMPTS) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
await wait(POLL_MS * 2 ** attempt);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class Charged extends Error {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "Charged";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class FailedOnChain extends Charged {
|
|
54
|
+
}
|
|
55
|
+
export class BlockhashExpired extends Error {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = "BlockhashExpired";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export const neverLanded = (error) => error instanceof FailedOnChain || error instanceof BlockhashExpired;
|
|
62
|
+
//# sourceMappingURL=rpc-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-retry.js","sourceRoot":"","sources":["../../src/rpc-retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,uCAAuC,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAE3B,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE7F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,SAAS,MAAM,CAAC,KAAc;IAC5B,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,IAAI,YAAY,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9F,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,IAAI,GAAG,CAAC,KAAuB,EAAE,IAAY,EAAW,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,C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C,CAAC,IAAI,OAAO,IAAI,mBAAmB,EAAE,CAAC;gBACpF,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,OAAO,OAAQ,SAAQ,KAAK;IAChC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,OAAO;CAAG;AAE7C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,KAAK,YAAY,aAAa,IAAI,KAAK,YAAY,gBAAgB,CAAC"}
|
|
@@ -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 @@
|
|
|
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;
|