@intent-engine/solver 0.1.36 → 0.1.38
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/bundle.d.ts +28 -0
- package/dist/src/bundle.js +49 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/flights.d.ts +26 -0
- package/dist/src/flights.js +48 -0
- package/dist/src/flights.js.map +1 -0
- package/dist/src/holds.d.ts +13 -0
- package/dist/src/holds.js +30 -0
- package/dist/src/holds.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/inventory.d.ts +11 -0
- package/dist/src/inventory.js +33 -0
- package/dist/src/inventory.js.map +1 -0
- package/dist/src/jupiter.js +7 -1
- package/dist/src/jupiter.js.map +1 -1
- package/dist/src/market.d.ts +3 -0
- package/dist/src/market.js +13 -1
- package/dist/src/market.js.map +1 -1
- package/dist/src/net.d.ts +8 -0
- package/dist/src/net.js +24 -0
- package/dist/src/net.js.map +1 -0
- package/dist/src/plan.d.ts +10 -0
- package/dist/src/plan.js +16 -0
- package/dist/src/plan.js.map +1 -1
- package/dist/src/quote-cache.d.ts +19 -0
- package/dist/src/quote-cache.js +46 -0
- package/dist/src/quote-cache.js.map +1 -0
- package/dist/src/remember.d.ts +7 -0
- package/dist/src/remember.js +80 -0
- package/dist/src/remember.js.map +1 -0
- package/dist/src/solver.d.ts +16 -19
- package/dist/src/solver.js +303 -222
- package/dist/src/solver.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const CONFIG_TTL_MS = 30_000;
|
|
2
|
+
export const BLOCKHASH_TTL_MS = 20_000;
|
|
3
|
+
function fresh(ttl, clock, load) {
|
|
4
|
+
let held = null;
|
|
5
|
+
return {
|
|
6
|
+
get: () => {
|
|
7
|
+
if (held === null || clock() - held.at > ttl) {
|
|
8
|
+
const value = load();
|
|
9
|
+
const entry = { at: clock(), value };
|
|
10
|
+
held = entry;
|
|
11
|
+
value.catch(() => {
|
|
12
|
+
if (held === entry) {
|
|
13
|
+
held = null;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return held.value;
|
|
18
|
+
},
|
|
19
|
+
clear: () => {
|
|
20
|
+
held = null;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function remembering(chain, clock = Date.now) {
|
|
25
|
+
const programs = new Map();
|
|
26
|
+
const mints = new Map();
|
|
27
|
+
const existing = new Set();
|
|
28
|
+
const config = fresh(CONFIG_TTL_MS, clock, () => chain.config());
|
|
29
|
+
const blockhash = fresh(BLOCKHASH_TTL_MS, clock, () => chain.blockhash());
|
|
30
|
+
return {
|
|
31
|
+
...chain,
|
|
32
|
+
config: () => config.get(),
|
|
33
|
+
blockhash: () => blockhash.get(),
|
|
34
|
+
tokenProgram: (mint) => {
|
|
35
|
+
const known = programs.get(mint);
|
|
36
|
+
if (known !== undefined) {
|
|
37
|
+
return known;
|
|
38
|
+
}
|
|
39
|
+
const loaded = chain.tokenProgram(mint);
|
|
40
|
+
programs.set(mint, loaded);
|
|
41
|
+
loaded.catch(() => programs.delete(mint));
|
|
42
|
+
return loaded;
|
|
43
|
+
},
|
|
44
|
+
...(chain.mintData === undefined
|
|
45
|
+
? {}
|
|
46
|
+
: {
|
|
47
|
+
mintData: (mint) => {
|
|
48
|
+
const known = mints.get(mint);
|
|
49
|
+
if (known !== undefined) {
|
|
50
|
+
return known;
|
|
51
|
+
}
|
|
52
|
+
const loaded = chain.mintData?.(mint) ?? Promise.resolve(null);
|
|
53
|
+
mints.set(mint, loaded);
|
|
54
|
+
loaded.then((data) => {
|
|
55
|
+
if (data === null) {
|
|
56
|
+
mints.delete(mint);
|
|
57
|
+
}
|
|
58
|
+
}, () => mints.delete(mint));
|
|
59
|
+
return loaded;
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
exists: async (address) => {
|
|
63
|
+
if (existing.has(address)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const found = await chain.exists(address);
|
|
67
|
+
if (found) {
|
|
68
|
+
existing.add(address);
|
|
69
|
+
}
|
|
70
|
+
return found;
|
|
71
|
+
},
|
|
72
|
+
forget: () => {
|
|
73
|
+
programs.clear();
|
|
74
|
+
existing.clear();
|
|
75
|
+
config.clear();
|
|
76
|
+
blockhash.clear();
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=remember.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remember.js","sourceRoot":"","sources":["../../src/remember.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAEpC,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAIvC,SAAS,KAAK,CAAI,GAAW,EAAE,KAAmB,EAAE,IAAsB;IACxE,IAAI,IAAI,GAA6C,IAAI,CAAC;IAC1D,OAAO;QACL,GAAG,EAAE,GAAG,EAAE;YACR,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC;gBAC7C,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC;gBACrB,MAAM,KAAK,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC;gBACrC,IAAI,GAAG,KAAK,CAAC;gBACb,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;oBACf,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;wBACnB,IAAI,GAAG,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,GAAG,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AA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AAC,IAAI,CAAC,CAAC;oBAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;wBACxB,OAAO,KAAK,CAAC;oBACf,CAAC;oBACD,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;oBAC/D,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;oBACxB,MAAM,CAAC,IAAI,CACT,CAAC,IAAI,EAAE,EAAE;wBACP,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;4BAClB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;wBACrB,CAAC;oBACH,CAAC,EACD,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CACzB,CAAC;oBACF,OAAO,MAAM,CAAC;gBAChB,CAAC;aACF,CAAC;QACN,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,KAAK,EAAE,CAAC;gBACV,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,EAAE,GAAG,EAAE;YACX,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/src/solver.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { type Config, type Intent } from "@intent-engine/core";
|
|
|
3
3
|
import { type Backoff } from "./backoff.js";
|
|
4
4
|
import { type Tip } from "./build.js";
|
|
5
5
|
import type { Pricer } from "./market.js";
|
|
6
|
-
import { type Strategy } from "./plan.js";
|
|
6
|
+
import { type Plan, type Strategy } from "./plan.js";
|
|
7
|
+
import { type Hold } from "./holds.js";
|
|
7
8
|
export { BACKOFF_MAX_INTERVALS, type Backoff, backingOff, backoff } from "./backoff.js";
|
|
8
9
|
export { createdRent, DEFAULT_MAX_RENT, DEFAULT_MAX_SOL_COST, LAMPORTS_PER_SIGNATURE, MICRO_LAMPORTS_PER_LAMPORT, mintExtensions, rentExempt, type SolCost, signaturesOf, solCost, TOKEN_2022_ACCOUNT_SPACE, TOKEN_2022_PROGRAM, TOKEN_ACCOUNT_SPACE, tokenAccountSpace, tooCostly, tooMuchRent, } from "./costs.js";
|
|
9
10
|
export type Chain = {
|
|
@@ -42,22 +43,30 @@ export type SolverOptions = {
|
|
|
42
43
|
maxSolCost?: bigint;
|
|
43
44
|
maxRent?: bigint;
|
|
44
45
|
backoff?: Backoff;
|
|
46
|
+
concurrency?: number;
|
|
47
|
+
planned?(intent: Address): void;
|
|
48
|
+
held?(account: Address): bigint;
|
|
45
49
|
unitPrice(instructions: readonly Instruction[]): Promise<bigint>;
|
|
46
50
|
simulate(wire: Base64EncodedWireTransaction, watch: readonly Address[]): Promise<Simulated>;
|
|
47
51
|
send(wire: Base64EncodedWireTransaction): Promise<Sent>;
|
|
52
|
+
sendBundle?: (wires: readonly Base64EncodedWireTransaction[]) => Promise<string>;
|
|
53
|
+
bundleSize?: number;
|
|
48
54
|
};
|
|
49
55
|
export type Report = {
|
|
50
56
|
filled: {
|
|
51
57
|
intent: Address;
|
|
52
58
|
profit: bigint;
|
|
59
|
+
cost: bigint;
|
|
53
60
|
signature: string;
|
|
54
61
|
rent?: bigint;
|
|
55
62
|
}[];
|
|
56
63
|
sent: {
|
|
57
64
|
intent: Address;
|
|
58
65
|
profit: bigint;
|
|
66
|
+
cost: bigint;
|
|
59
67
|
signature: string;
|
|
60
68
|
rent?: bigint;
|
|
69
|
+
holds?: Hold;
|
|
61
70
|
}[];
|
|
62
71
|
skipped: {
|
|
63
72
|
intent: Address;
|
|
@@ -73,22 +82,10 @@ export declare const SIMULATION_REFUSED = "the fill failed in simulation, so it
|
|
|
73
82
|
export declare const BALANCES_REFUSED = "the fill would leave the solver with less of a token than planned, so it was not sent";
|
|
74
83
|
export declare const ROUTE_ACCOUNT_BUDGETS: readonly [40, 30, 20];
|
|
75
84
|
export declare const tooLarge: (bytes: number | null, accounts: number) => string;
|
|
85
|
+
export declare const DEFAULT_CONCURRENCY = 4;
|
|
86
|
+
export declare const MAX_CONCURRENCY = 32;
|
|
87
|
+
export declare const badConcurrency: (value: number) => string;
|
|
88
|
+
export declare const ALREADY_FILLING = "the order already has a fill in this tick";
|
|
89
|
+
export declare const INVENTORY_SPENT = "the solver no longer holds enough of the output token for this fill";
|
|
90
|
+
export declare function firstToSend(a: Plan, b: Plan): number;
|
|
76
91
|
export declare function tick(o: SolverOptions): Promise<Report>;
|
|
77
|
-
export type Flight = {
|
|
78
|
-
until: bigint;
|
|
79
|
-
signature: string;
|
|
80
|
-
};
|
|
81
|
-
export declare const FAILED_ON_CHAIN = "the fill was sent but failed on chain";
|
|
82
|
-
export declare function landings(flights: Map<Address, Flight>, now: bigint, listed: readonly {
|
|
83
|
-
address: Address;
|
|
84
|
-
intent: Intent;
|
|
85
|
-
}[], failedOnChain: (signature: string) => Promise<boolean>, held: Backoff): Promise<{
|
|
86
|
-
intent: Address;
|
|
87
|
-
error: string;
|
|
88
|
-
}[]>;
|
|
89
|
-
export declare const CONFIG_TTL_MS = 30000;
|
|
90
|
-
export declare const BLOCKHASH_TTL_MS = 20000;
|
|
91
|
-
export type Remembering = Chain & {
|
|
92
|
-
forget(): void;
|
|
93
|
-
};
|
|
94
|
-
export declare function remembering(chain: Chain, clock?: () => number): Remembering;
|