@intent-engine/solver 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/dist/src/build.d.ts +46 -0
- package/dist/src/build.js +139 -0
- package/dist/src/build.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/issue.d.ts +12 -0
- package/dist/src/issue.js +45 -0
- package/dist/src/issue.js.map +1 -0
- package/dist/src/jito.d.ts +9 -0
- package/dist/src/jito.js +43 -0
- package/dist/src/jito.js.map +1 -0
- package/dist/src/jupiter.d.ts +20 -0
- package/dist/src/jupiter.js +156 -0
- package/dist/src/jupiter.js.map +1 -0
- package/dist/src/lookup.d.ts +3 -0
- package/dist/src/lookup.js +19 -0
- package/dist/src/lookup.js.map +1 -0
- package/dist/src/market.d.ts +27 -0
- package/dist/src/market.js +2 -0
- package/dist/src/market.js.map +1 -0
- package/dist/src/plan.d.ts +36 -0
- package/dist/src/plan.js +74 -0
- package/dist/src/plan.js.map +1 -0
- package/dist/src/solver.d.ts +66 -0
- package/dist/src/solver.js +120 -0
- package/dist/src/solver.js.map +1 -0
- package/package.json +37 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Address, type Base64EncodedWireTransaction, type Blockhash, type Instruction, type TransactionSigner } from "@solana/kit";
|
|
2
|
+
import type { Plan } from "./plan.js";
|
|
3
|
+
export declare const COMPUTE_BUDGET_ADDRESS: Address;
|
|
4
|
+
export declare const MAX_COMPUTE_UNITS = 1400000;
|
|
5
|
+
export declare function computeUnitLimit(units: number): Instruction;
|
|
6
|
+
export declare const UNIT_HEADROOM_DIVISOR = 10n;
|
|
7
|
+
export declare const UNIT_HEADROOM_FLOOR = 1000n;
|
|
8
|
+
export declare function headroom(consumed: bigint): number;
|
|
9
|
+
export declare const MAX_MICRO_LAMPORTS: bigint;
|
|
10
|
+
export declare function computeUnitPrice(microLamports: bigint): Instruction;
|
|
11
|
+
export type Tip = {
|
|
12
|
+
account: Address;
|
|
13
|
+
lamports: bigint;
|
|
14
|
+
};
|
|
15
|
+
export type FillContext = {
|
|
16
|
+
solver: TransactionSigner;
|
|
17
|
+
feeRecipient: Address;
|
|
18
|
+
inputTokenProgram: Address;
|
|
19
|
+
outputTokenProgram: Address;
|
|
20
|
+
computeUnits: number;
|
|
21
|
+
unitPrice: bigint;
|
|
22
|
+
createSolverInput: boolean;
|
|
23
|
+
createSolverOutput: boolean;
|
|
24
|
+
tip: Tip | null;
|
|
25
|
+
};
|
|
26
|
+
export declare function payoutAccounts(plan: Pick<Plan, "intent" | "fees">, feeRecipient: Address, inputTokenProgram: Address): Promise<{
|
|
27
|
+
name: string;
|
|
28
|
+
address: Address;
|
|
29
|
+
}[]>;
|
|
30
|
+
export declare function fillInstructions(plan: Plan, ctx: FillContext): Promise<Instruction[]>;
|
|
31
|
+
export declare function lookupTablesOf(plan: Plan, own?: readonly Address[]): Address[];
|
|
32
|
+
export declare const TOKEN_PROGRAMS: Address[];
|
|
33
|
+
export declare function solverTableAccounts(solver: Address, feeRecipient: Address, mints: readonly {
|
|
34
|
+
mint: Address;
|
|
35
|
+
tokenProgram: Address;
|
|
36
|
+
}[]): Promise<Address[]>;
|
|
37
|
+
export declare const PACKET_DATA_SIZE = 1232;
|
|
38
|
+
export declare const MAX_TX_ACCOUNTS = 64;
|
|
39
|
+
export declare function accountsOf(instructions: readonly Instruction[], payer: Address): number;
|
|
40
|
+
export declare const locksFit: (accounts: number) => boolean;
|
|
41
|
+
export declare const bytesFit: (bytes: number) => boolean;
|
|
42
|
+
export declare function wireSize(wire: Base64EncodedWireTransaction): number;
|
|
43
|
+
export declare function compile(instructions: readonly Instruction[], payer: TransactionSigner, latest: {
|
|
44
|
+
blockhash: Blockhash;
|
|
45
|
+
lastValidBlockHeight: bigint;
|
|
46
|
+
}, tables: Readonly<Record<Address, Address[]>>): Promise<Base64EncodedWireTransaction>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { appendTransactionMessageInstructions, getBase64Encoder, compressTransactionMessageUsingAddressLookupTables, createTransactionMessage, getBase64EncodedWireTransaction, pipe, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signTransactionMessageWithSigners, } from "@solana/kit";
|
|
2
|
+
import { getTransferSolInstruction } from "@solana-program/system";
|
|
3
|
+
import { getCreateAssociatedTokenIdempotentInstructionAsync } from "@solana-program/token";
|
|
4
|
+
import { buildFlashFill, findAssociatedTokenAddress, findConfigPda, findEventAuthorityPda, INSTRUCTIONS_SYSVAR_ADDRESS, } from "@intent-engine/core";
|
|
5
|
+
import { JITO_TIP_ACCOUNTS } from "./jito.js";
|
|
6
|
+
export const COMPUTE_BUDGET_ADDRESS = "ComputeBudget111111111111111111111111111111";
|
|
7
|
+
export const MAX_COMPUTE_UNITS = 1_400_000;
|
|
8
|
+
export function computeUnitLimit(units) {
|
|
9
|
+
if (!Number.isInteger(units) || units < 1 || units > MAX_COMPUTE_UNITS) {
|
|
10
|
+
throw new RangeError(`a compute unit limit must be 1 to ${MAX_COMPUTE_UNITS}, got ${units}`);
|
|
11
|
+
}
|
|
12
|
+
const data = new Uint8Array(5);
|
|
13
|
+
data[0] = 2;
|
|
14
|
+
new DataView(data.buffer).setUint32(1, units, true);
|
|
15
|
+
return { programAddress: COMPUTE_BUDGET_ADDRESS, data };
|
|
16
|
+
}
|
|
17
|
+
export const UNIT_HEADROOM_DIVISOR = 10n;
|
|
18
|
+
export const UNIT_HEADROOM_FLOOR = 1000n;
|
|
19
|
+
export function headroom(consumed) {
|
|
20
|
+
const padded = consumed + consumed / UNIT_HEADROOM_DIVISOR + UNIT_HEADROOM_FLOOR;
|
|
21
|
+
return Math.min(Number(padded), MAX_COMPUTE_UNITS);
|
|
22
|
+
}
|
|
23
|
+
export const MAX_MICRO_LAMPORTS = (1n << 64n) - 1n;
|
|
24
|
+
export function computeUnitPrice(microLamports) {
|
|
25
|
+
if (microLamports < 0n || microLamports > MAX_MICRO_LAMPORTS) {
|
|
26
|
+
throw new RangeError(`a compute unit price must be 0 to ${MAX_MICRO_LAMPORTS} micro-lamports, got ${microLamports}`);
|
|
27
|
+
}
|
|
28
|
+
const data = new Uint8Array(9);
|
|
29
|
+
data[0] = 3;
|
|
30
|
+
new DataView(data.buffer).setBigUint64(1, microLamports, true);
|
|
31
|
+
return { programAddress: COMPUTE_BUDGET_ADDRESS, data };
|
|
32
|
+
}
|
|
33
|
+
export async function payoutAccounts(plan, feeRecipient, inputTokenProgram) {
|
|
34
|
+
const intent = plan.intent;
|
|
35
|
+
const owners = [
|
|
36
|
+
...(plan.fees.protocol > 0n ? [{ name: "fee", owner: feeRecipient }] : []),
|
|
37
|
+
...(plan.fees.partner > 0n ? [{ name: "partner", owner: intent.partner }] : []),
|
|
38
|
+
...(intent.agentFee > 0n ? [{ name: "agent", owner: intent.rentPayer }] : []),
|
|
39
|
+
];
|
|
40
|
+
return Promise.all(owners.map(async ({ name, owner }) => ({
|
|
41
|
+
name,
|
|
42
|
+
address: await findAssociatedTokenAddress({ owner, mint: intent.inputMint, tokenProgram: inputTokenProgram }),
|
|
43
|
+
})));
|
|
44
|
+
}
|
|
45
|
+
export async function fillInstructions(plan, ctx) {
|
|
46
|
+
const intent = plan.intent;
|
|
47
|
+
const owner = ctx.solver.address;
|
|
48
|
+
const solverInput = await findAssociatedTokenAddress({
|
|
49
|
+
owner,
|
|
50
|
+
mint: intent.inputMint,
|
|
51
|
+
tokenProgram: ctx.inputTokenProgram,
|
|
52
|
+
});
|
|
53
|
+
const solverOutput = await findAssociatedTokenAddress({
|
|
54
|
+
owner,
|
|
55
|
+
mint: intent.outputMint,
|
|
56
|
+
tokenProgram: ctx.outputTokenProgram,
|
|
57
|
+
});
|
|
58
|
+
const flash = await buildFlashFill({
|
|
59
|
+
solver: ctx.solver,
|
|
60
|
+
owner: intent.owner,
|
|
61
|
+
nonce: intent.nonce,
|
|
62
|
+
inputMint: intent.inputMint,
|
|
63
|
+
outputMint: intent.outputMint,
|
|
64
|
+
inputTokenProgram: ctx.inputTokenProgram,
|
|
65
|
+
outputTokenProgram: ctx.outputTokenProgram,
|
|
66
|
+
receiver: intent.receiver,
|
|
67
|
+
solverInput,
|
|
68
|
+
solverOutput,
|
|
69
|
+
...(plan.fees.protocol > 0n ? { feeRecipient: ctx.feeRecipient } : {}),
|
|
70
|
+
...(plan.fees.partner > 0n ? { partner: intent.partner } : {}),
|
|
71
|
+
mandate: intent.mandate,
|
|
72
|
+
...(intent.agentFee > 0n ? { agent: intent.rentPayer } : {}),
|
|
73
|
+
amountIn: plan.amountIn,
|
|
74
|
+
amountOut: plan.required,
|
|
75
|
+
maxFeeBps: plan.feeBps + intent.partnerBps,
|
|
76
|
+
prefix: [
|
|
77
|
+
computeUnitLimit(ctx.computeUnits),
|
|
78
|
+
...(ctx.unitPrice > 0n ? [computeUnitPrice(ctx.unitPrice)] : []),
|
|
79
|
+
...(ctx.createSolverInput
|
|
80
|
+
? [
|
|
81
|
+
await getCreateAssociatedTokenIdempotentInstructionAsync({
|
|
82
|
+
payer: ctx.solver,
|
|
83
|
+
owner,
|
|
84
|
+
mint: intent.inputMint,
|
|
85
|
+
tokenProgram: ctx.inputTokenProgram,
|
|
86
|
+
}),
|
|
87
|
+
]
|
|
88
|
+
: []),
|
|
89
|
+
...(ctx.createSolverOutput
|
|
90
|
+
? [
|
|
91
|
+
await getCreateAssociatedTokenIdempotentInstructionAsync({
|
|
92
|
+
payer: ctx.solver,
|
|
93
|
+
owner,
|
|
94
|
+
mint: intent.outputMint,
|
|
95
|
+
tokenProgram: ctx.outputTokenProgram,
|
|
96
|
+
}),
|
|
97
|
+
]
|
|
98
|
+
: []),
|
|
99
|
+
],
|
|
100
|
+
route: [...plan.route.instructions, ...(plan.arbitrage?.instructions ?? [])],
|
|
101
|
+
});
|
|
102
|
+
const tip = ctx.tip === null
|
|
103
|
+
? []
|
|
104
|
+
: [getTransferSolInstruction({ source: ctx.solver, destination: ctx.tip.account, amount: ctx.tip.lamports })];
|
|
105
|
+
return [...flash, ...tip];
|
|
106
|
+
}
|
|
107
|
+
export function lookupTablesOf(plan, own = []) {
|
|
108
|
+
return [...new Set([...own, ...plan.route.lookupTables, ...(plan.arbitrage?.lookupTables ?? [])])];
|
|
109
|
+
}
|
|
110
|
+
export const TOKEN_PROGRAMS = [
|
|
111
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
112
|
+
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
|
|
113
|
+
];
|
|
114
|
+
export async function solverTableAccounts(solver, feeRecipient, mints) {
|
|
115
|
+
const [config] = await findConfigPda();
|
|
116
|
+
const [events] = await findEventAuthorityPda();
|
|
117
|
+
const owned = [];
|
|
118
|
+
for (const { mint, tokenProgram } of mints) {
|
|
119
|
+
for (const owner of [feeRecipient, solver]) {
|
|
120
|
+
owned.push(await findAssociatedTokenAddress({ owner, mint, tokenProgram }));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return [...new Set([config, events, INSTRUCTIONS_SYSVAR_ADDRESS, ...TOKEN_PROGRAMS, ...JITO_TIP_ACCOUNTS, ...owned])];
|
|
124
|
+
}
|
|
125
|
+
export const PACKET_DATA_SIZE = 1_232;
|
|
126
|
+
export const MAX_TX_ACCOUNTS = 64;
|
|
127
|
+
export function accountsOf(instructions, payer) {
|
|
128
|
+
return new Set([payer, ...instructions.flatMap((ix) => [ix.programAddress, ...(ix.accounts ?? []).map((m) => m.address)])]).size;
|
|
129
|
+
}
|
|
130
|
+
export const locksFit = (accounts) => accounts <= MAX_TX_ACCOUNTS;
|
|
131
|
+
export const bytesFit = (bytes) => bytes <= PACKET_DATA_SIZE;
|
|
132
|
+
export function wireSize(wire) {
|
|
133
|
+
return getBase64Encoder().encode(wire).length;
|
|
134
|
+
}
|
|
135
|
+
export async function compile(instructions, payer, latest, tables) {
|
|
136
|
+
const message = pipe(createTransactionMessage({ version: 0 }), (m) => setTransactionMessageFeePayerSigner(payer, m), (m) => setTransactionMessageLifetimeUsingBlockhash(latest, m), (m) => appendTransactionMessageInstructions(instructions, m), (m) => compressTransactionMessageUsingAddressLookupTables(m, tables));
|
|
137
|
+
return getBase64EncodedWireTransaction(await signTransactionMessageWithSigners(message));
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oCAAoC,EACpC,gBAAgB,EAGhB,kDAAkD,EAClD,wBAAwB,EACxB,+BAA+B,EAE/B,IAAI,EACJ,mCAAmC,EACnC,2CAA2C,EAC3C,iCAAiC,GAElC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,kDAAkD,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,aAAa,EACb,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,MAAM,CAAC,MAAM,sBAAsB,GAAG,6CAAwD,CAAC;AAC/F,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;A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,CAAC,EAAE,MAAM,CAAC,CACrE,CAAC;IACF,OAAO,+BAA+B,CAAC,MAAM,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./build.js";
|
|
2
|
+
export * from "./issue.js";
|
|
3
|
+
export * from "./jito.js";
|
|
4
|
+
export * from "./jupiter.js";
|
|
5
|
+
export * from "./lookup.js";
|
|
6
|
+
export * from "./market.js";
|
|
7
|
+
export * from "./plan.js";
|
|
8
|
+
export * from "./solver.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Address, type Instruction } from "@solana/kit";
|
|
2
|
+
import type { Pricer } from "./market.js";
|
|
3
|
+
export type IssueRoute = {
|
|
4
|
+
inputMint: Address;
|
|
5
|
+
outputMint: Address;
|
|
6
|
+
outputTokenProgram: Address;
|
|
7
|
+
out: bigint;
|
|
8
|
+
in: bigint;
|
|
9
|
+
};
|
|
10
|
+
export declare const MINT_TO = 7;
|
|
11
|
+
export declare function issueInstruction(mint: Address, token: Address, authority: Address, tokenProgram: Address, amount: bigint): Instruction;
|
|
12
|
+
export declare function issuePricer(routes: readonly IssueRoute[]): Pricer;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AccountRole, getU64Encoder } from "@solana/kit";
|
|
2
|
+
import { findAssociatedTokenAddress } from "@intent-engine/core";
|
|
3
|
+
export const MINT_TO = 7;
|
|
4
|
+
export function issueInstruction(mint, token, authority, tokenProgram, amount) {
|
|
5
|
+
const data = new Uint8Array(9);
|
|
6
|
+
data[0] = MINT_TO;
|
|
7
|
+
data.set(getU64Encoder().encode(amount), 1);
|
|
8
|
+
return {
|
|
9
|
+
programAddress: tokenProgram,
|
|
10
|
+
accounts: [
|
|
11
|
+
{ address: mint, role: AccountRole.WRITABLE },
|
|
12
|
+
{ address: token, role: AccountRole.WRITABLE },
|
|
13
|
+
{ address: authority, role: AccountRole.READONLY_SIGNER },
|
|
14
|
+
],
|
|
15
|
+
data,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function issuePricer(routes) {
|
|
19
|
+
for (const route of routes) {
|
|
20
|
+
if (route.out <= 0n || route.in <= 0n) {
|
|
21
|
+
throw new RangeError(`the issue rate for ${route.outputMint} must be positive on both sides`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
async quote(request) {
|
|
26
|
+
const route = routes.find((r) => r.inputMint === request.inputMint && r.outputMint === request.outputMint);
|
|
27
|
+
if (route === undefined) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const amountOut = (request.amountIn * route.out) / route.in;
|
|
31
|
+
const token = await findAssociatedTokenAddress({
|
|
32
|
+
owner: request.taker,
|
|
33
|
+
mint: route.outputMint,
|
|
34
|
+
tokenProgram: route.outputTokenProgram,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
amountIn: request.amountIn,
|
|
38
|
+
amountOut,
|
|
39
|
+
instructions: [issueInstruction(route.outputMint, token, request.taker, route.outputTokenProgram, amountOut)],
|
|
40
|
+
lookupTables: [],
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=issue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue.js","sourceRoot":"","sources":["../../src/issue.ts"],"names":[],"mappings":"AAAA,OAAO,EA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KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3G,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,SAAS,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;YAC5D,MAAM,KAAK,GAAG,MAAM,0BAA0B,CAAC;gBAC7C,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,IAAI,EAAE,KAAK,CAAC,UAAU;gBACtB,YAAY,EAAE,KAAK,CAAC,kBAAkB;aACvC,CAAC,CAAC;YACH,OAAO;gBACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,SAAS;gBACT,YAAY,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;gBAC7G,YAAY,EAAE,EAAE;aACjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Address, Base64EncodedWireTransaction } from "@solana/kit";
|
|
2
|
+
import type { Fetch } from "./market.js";
|
|
3
|
+
export declare const JITO_TIP_ACCOUNTS: Address[];
|
|
4
|
+
export declare const MAX_BUNDLE = 5;
|
|
5
|
+
export declare function tipAccount(entropy: number): Address;
|
|
6
|
+
export declare function jitoBundles(options: {
|
|
7
|
+
url: string;
|
|
8
|
+
fetch: Fetch;
|
|
9
|
+
}): (wires: readonly Base64EncodedWireTransaction[]) => Promise<string>;
|
package/dist/src/jito.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const JITO_TIP_ACCOUNTS = [
|
|
2
|
+
"96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
|
|
3
|
+
"HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
|
|
4
|
+
"Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY",
|
|
5
|
+
"ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49",
|
|
6
|
+
"DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
|
|
7
|
+
"ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt",
|
|
8
|
+
"DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL",
|
|
9
|
+
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT",
|
|
10
|
+
];
|
|
11
|
+
export const MAX_BUNDLE = 5;
|
|
12
|
+
export function tipAccount(entropy) {
|
|
13
|
+
if (!Number.isInteger(entropy) || entropy < 0) {
|
|
14
|
+
throw new RangeError(`tip entropy must be a non-negative integer, got ${entropy}`);
|
|
15
|
+
}
|
|
16
|
+
const account = JITO_TIP_ACCOUNTS[entropy % JITO_TIP_ACCOUNTS.length];
|
|
17
|
+
if (account === undefined) {
|
|
18
|
+
throw new RangeError("no tip account");
|
|
19
|
+
}
|
|
20
|
+
return account;
|
|
21
|
+
}
|
|
22
|
+
export function jitoBundles(options) {
|
|
23
|
+
return async (wires) => {
|
|
24
|
+
if (wires.length < 1 || wires.length > MAX_BUNDLE) {
|
|
25
|
+
throw new RangeError(`a bundle holds 1 to ${MAX_BUNDLE} transactions, got ${wires.length}`);
|
|
26
|
+
}
|
|
27
|
+
const response = await options.fetch(`${options.url}/api/v1/bundles`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "content-type": "application/json" },
|
|
30
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "sendBundle", params: [wires, { encoding: "base64" }] }),
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`jito rejected the bundle with status ${response.status}`);
|
|
34
|
+
}
|
|
35
|
+
const reply = (await response.json());
|
|
36
|
+
if (typeof reply.result === "string") {
|
|
37
|
+
return reply.result;
|
|
38
|
+
}
|
|
39
|
+
const message = typeof reply.error?.message === "string" ? reply.error.message : "no bundle id returned";
|
|
40
|
+
throw new Error(`jito rejected the bundle: ${message}`);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=jito.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jito.js","sourceRoot":"","sources":["../../src/jito.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,8CAA8C;IAC9C,8CAA8C;IAC9C,8CAA8C;IAC9C,8CAA8C;IAC9C,8CAA8C;IAC9C,8CAA8C;IAC9C,8CAA8C;IAC9C,8CAA8C;CAClC,CAAC;AAEf,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAE5B,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,UAAU,CAAC,mDAAmD,OAAO,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAsC;IAChE,OAAO,KAAK,EAAE,KAA8C,EAAmB,EAAE;QAC/E,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;YAClD,MAAM,IAAI,UAAU,CAAC,uBAAuB,UAAU,sBAAsB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9F,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,iBAAiB,EAAE;YACpE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;SAC/G,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,wCAAwC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7E,CAAC;QACD,MAAM,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAwD,CAAC;QAC7F,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC,MAAM,CAAC;QACtB,CAAC;QACD,MAAM,OAAO,GAAG,OAAO,KAAK,CAAC,KAAK,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC;QACzG,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Address } from "@solana/kit";
|
|
2
|
+
import type { Fetch, Pricer } from "./market.js";
|
|
3
|
+
export type JupiterOptions = {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
fetch: Fetch;
|
|
6
|
+
slippageBps: number;
|
|
7
|
+
maxAccounts: number;
|
|
8
|
+
swapPrograms?: ReadonlySet<Address>;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const RATE_LIMITED = 429;
|
|
12
|
+
export declare class RateLimited extends Error {
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
export declare const JUPITER_PROGRAM: Address<"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4">;
|
|
16
|
+
export declare const ASSOCIATED_TOKEN_PROGRAM: Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
17
|
+
export declare const SETUP_PROGRAMS: ReadonlySet<Address>;
|
|
18
|
+
export declare const ATA_CREATE = 0;
|
|
19
|
+
export declare const ATA_CREATE_IDEMPOTENT = 1;
|
|
20
|
+
export declare function jupiterPricer(options: JupiterOptions): Pricer;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { AccountRole, address, getBase64Encoder } from "@solana/kit";
|
|
2
|
+
export const RATE_LIMITED = 429;
|
|
3
|
+
export class RateLimited extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super("the aggregator is rate limiting this solver; try again on the next run");
|
|
6
|
+
this.name = "RateLimited";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export const JUPITER_PROGRAM = address("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");
|
|
10
|
+
export const ASSOCIATED_TOKEN_PROGRAM = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
11
|
+
export const SETUP_PROGRAMS = new Set([ASSOCIATED_TOKEN_PROGRAM]);
|
|
12
|
+
function allowed(ix, programs, what) {
|
|
13
|
+
if (!programs.has(ix.programAddress)) {
|
|
14
|
+
throw new Error(`jupiter ${what} calls ${ix.programAddress}, which this solver does not sign for`);
|
|
15
|
+
}
|
|
16
|
+
return ix;
|
|
17
|
+
}
|
|
18
|
+
export const ATA_CREATE = 0;
|
|
19
|
+
export const ATA_CREATE_IDEMPOTENT = 1;
|
|
20
|
+
const ATA_PAYER = 0;
|
|
21
|
+
const ATA_WALLET = 2;
|
|
22
|
+
const ATA_MINT = 3;
|
|
23
|
+
function ownAccount(ix, request, what) {
|
|
24
|
+
const data = ix.data ?? new Uint8Array();
|
|
25
|
+
const kind = data.length === 0 ? ATA_CREATE : data[0];
|
|
26
|
+
const opens = data.length <= 1 && (kind === ATA_CREATE || kind === ATA_CREATE_IDEMPOTENT);
|
|
27
|
+
const mint = ix.accounts?.[ATA_MINT]?.address;
|
|
28
|
+
if (!opens ||
|
|
29
|
+
ix.accounts?.[ATA_PAYER]?.address !== request.taker ||
|
|
30
|
+
ix.accounts?.[ATA_WALLET]?.address !== request.taker ||
|
|
31
|
+
(mint !== request.inputMint && mint !== request.outputMint)) {
|
|
32
|
+
throw new Error(`jupiter ${what} does more than open this solver's own token account for the traded mints`);
|
|
33
|
+
}
|
|
34
|
+
return ix;
|
|
35
|
+
}
|
|
36
|
+
function oncePerMint(setup) {
|
|
37
|
+
const mints = setup.map((ix) => ix.accounts?.[ATA_MINT]?.address);
|
|
38
|
+
if (new Set(mints).size !== mints.length) {
|
|
39
|
+
throw new Error("jupiter setup opens the same token account more than once");
|
|
40
|
+
}
|
|
41
|
+
return setup;
|
|
42
|
+
}
|
|
43
|
+
function field(value, name) {
|
|
44
|
+
if (value === null || typeof value !== "object" || !(name in value)) {
|
|
45
|
+
throw new Error(`jupiter response is missing ${name}`);
|
|
46
|
+
}
|
|
47
|
+
return value[name];
|
|
48
|
+
}
|
|
49
|
+
function text(value, name) {
|
|
50
|
+
const found = field(value, name);
|
|
51
|
+
if (typeof found !== "string") {
|
|
52
|
+
throw new Error(`jupiter response field ${name} is not a string`);
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
function amount(value, name) {
|
|
57
|
+
const raw = text(value, name);
|
|
58
|
+
if (!/^\d+$/.test(raw)) {
|
|
59
|
+
throw new Error(`jupiter response field ${name} is not an amount: ${raw}`);
|
|
60
|
+
}
|
|
61
|
+
return BigInt(raw);
|
|
62
|
+
}
|
|
63
|
+
function instruction(value) {
|
|
64
|
+
const accounts = field(value, "accounts");
|
|
65
|
+
if (!Array.isArray(accounts)) {
|
|
66
|
+
throw new Error("jupiter instruction accounts are not a list");
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
programAddress: address(text(value, "programId")),
|
|
70
|
+
accounts: accounts.map((meta) => {
|
|
71
|
+
const signer = field(meta, "isSigner") === true;
|
|
72
|
+
const writable = field(meta, "isWritable") === true;
|
|
73
|
+
const role = signer
|
|
74
|
+
? writable
|
|
75
|
+
? AccountRole.WRITABLE_SIGNER
|
|
76
|
+
: AccountRole.READONLY_SIGNER
|
|
77
|
+
: writable
|
|
78
|
+
? AccountRole.WRITABLE
|
|
79
|
+
: AccountRole.READONLY;
|
|
80
|
+
return { address: address(text(meta, "pubkey")), role };
|
|
81
|
+
}),
|
|
82
|
+
data: new Uint8Array(getBase64Encoder().encode(text(value, "data"))),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function instructions(value, name) {
|
|
86
|
+
if (!(value !== null && typeof value === "object" && name in value)) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const found = value[name];
|
|
90
|
+
if (found === null || found === undefined) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
return (Array.isArray(found) ? found : [found]).map(instruction);
|
|
94
|
+
}
|
|
95
|
+
async function body(response, what) {
|
|
96
|
+
if (response.status === RATE_LIMITED) {
|
|
97
|
+
throw new RateLimited();
|
|
98
|
+
}
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
throw new Error(`jupiter ${what} failed with status ${response.status}`);
|
|
101
|
+
}
|
|
102
|
+
return response.json();
|
|
103
|
+
}
|
|
104
|
+
export function jupiterPricer(options) {
|
|
105
|
+
return {
|
|
106
|
+
async quote(request) {
|
|
107
|
+
const query = new URLSearchParams({
|
|
108
|
+
inputMint: request.inputMint,
|
|
109
|
+
outputMint: request.outputMint,
|
|
110
|
+
amount: request.amountIn.toString(),
|
|
111
|
+
slippageBps: String(options.slippageBps),
|
|
112
|
+
maxAccounts: String(request.maxAccounts ?? options.maxAccounts),
|
|
113
|
+
onlyDirectRoutes: "false",
|
|
114
|
+
});
|
|
115
|
+
const keyed = options.apiKey === undefined ? {} : { "x-api-key": options.apiKey };
|
|
116
|
+
const quoted = await options.fetch(`${options.baseUrl}/quote?${query.toString()}`, { headers: keyed });
|
|
117
|
+
if (quoted.status === 400 || quoted.status === 404) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const quote = await body(quoted, "quote");
|
|
121
|
+
if (amount(quote, "inAmount") !== request.amountIn) {
|
|
122
|
+
throw new Error("jupiter quoted a different input amount than requested");
|
|
123
|
+
}
|
|
124
|
+
const built = await body(await options.fetch(`${options.baseUrl}/swap-instructions`, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: { "content-type": "application/json", ...keyed },
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
quoteResponse: quote,
|
|
129
|
+
userPublicKey: request.taker,
|
|
130
|
+
wrapAndUnwrapSol: false,
|
|
131
|
+
dynamicComputeUnitLimit: false,
|
|
132
|
+
}),
|
|
133
|
+
}), "swap-instructions");
|
|
134
|
+
const tables = field(built, "addressLookupTableAddresses");
|
|
135
|
+
if (!Array.isArray(tables)) {
|
|
136
|
+
throw new Error("jupiter lookup tables are not a list");
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
amountIn: request.amountIn,
|
|
140
|
+
amountOut: amount(quote, "otherAmountThreshold"),
|
|
141
|
+
instructions: [
|
|
142
|
+
...oncePerMint(instructions(built, "setupInstructions").map((ix) => ownAccount(allowed(ix, SETUP_PROGRAMS, "setup"), request, "setup"))),
|
|
143
|
+
allowed(instruction(field(built, "swapInstruction")), options.swapPrograms ?? new Set([JUPITER_PROGRAM]), "swap"),
|
|
144
|
+
...instructions(built, "cleanupInstruction").map((ix) => ownAccount(allowed(ix, SETUP_PROGRAMS, "cleanup"), request, "cleanup")),
|
|
145
|
+
],
|
|
146
|
+
lookupTables: tables.map((t) => {
|
|
147
|
+
if (typeof t !== "string") {
|
|
148
|
+
throw new Error("jupiter lookup table is not an address");
|
|
149
|
+
}
|
|
150
|
+
return address(t);
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=jupiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jupiter.js","sourceRoot":"","sources":["../../src/jupiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,OAAO,EAAE,gBAAgB,EAAoB,MAAM,aAAa,CAAC;AAYrG,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEhC,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC;QACE,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAChF,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;AAChG,MAAM,CAAC,MAAM,cAAc,GAAyB,IAAI,GAAG,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC;AAExF,SAAS,OAAO,CAAC,EAAe,EAAE,QAA8B,EAAE,IAAY;IAC5E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,UAAU,EAAE,CAAC,cAAc,uCAAuC,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,MAAM,CAAC,MAAM,qBAAqB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AAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CACzH;oBACD,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC;oBACjH,GAAG,YAAY,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACtD,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CACvE;iBACF;gBACD,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAU,EAAE,EAAE;oBACtC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;wBAC1B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;oBAC5D,CAAC;oBACD,OAAO,OAAO,CAAC,CAAC,CAAY,CAAC;gBAC/B,CAAC,CAAC;aACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getAddressDecoder } from "@solana/kit";
|
|
2
|
+
export const LOOKUP_TABLE_HEADER = 56;
|
|
3
|
+
const LOOKUP_TABLE_TAG = 1;
|
|
4
|
+
export function decodeLookupTable(data) {
|
|
5
|
+
if (data.length < LOOKUP_TABLE_HEADER || (data.length - LOOKUP_TABLE_HEADER) % 32 !== 0) {
|
|
6
|
+
throw new Error(`a lookup table of ${data.length} bytes is malformed`);
|
|
7
|
+
}
|
|
8
|
+
const tag = new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(0, true);
|
|
9
|
+
if (tag !== LOOKUP_TABLE_TAG) {
|
|
10
|
+
throw new Error(`account is not a lookup table (tag ${tag})`);
|
|
11
|
+
}
|
|
12
|
+
const decoder = getAddressDecoder();
|
|
13
|
+
const out = [];
|
|
14
|
+
for (let at = LOOKUP_TABLE_HEADER; at < data.length; at += 32) {
|
|
15
|
+
out.push(decoder.decode(data.subarray(at, at + 32)));
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../src/lookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AACtC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAChD,IAAI,IAAI,CAAC,MAAM,GAAG,mBAAmB,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,MAAM,qBAAqB,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3F,IAAI,GAAG,KAAK,gBAAgB,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,GAAG,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,IAAI,EAAE,GAAG,mBAAmB,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;QAC9D,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Address, Instruction } from "@solana/kit";
|
|
2
|
+
export type QuoteRequest = {
|
|
3
|
+
inputMint: Address;
|
|
4
|
+
outputMint: Address;
|
|
5
|
+
amountIn: bigint;
|
|
6
|
+
taker: Address;
|
|
7
|
+
maxAccounts?: number;
|
|
8
|
+
};
|
|
9
|
+
export type Quote = {
|
|
10
|
+
amountIn: bigint;
|
|
11
|
+
amountOut: bigint;
|
|
12
|
+
instructions: Instruction[];
|
|
13
|
+
lookupTables: Address[];
|
|
14
|
+
};
|
|
15
|
+
export interface Pricer {
|
|
16
|
+
quote(request: QuoteRequest): Promise<Quote | null>;
|
|
17
|
+
}
|
|
18
|
+
export type FetchResponse = {
|
|
19
|
+
ok: boolean;
|
|
20
|
+
status: number;
|
|
21
|
+
json(): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
export type Fetch = (url: string, init?: {
|
|
24
|
+
method?: string;
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
body?: string;
|
|
27
|
+
}) => Promise<FetchResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../src/market.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import { type Config, type FeeShares, type Intent, type IntentParams } from "@intent-engine/core";
|
|
3
|
+
import type { Pricer, Quote } from "./market.js";
|
|
4
|
+
export type Cycle = (mint: Address, amount: bigint) => Promise<Quote | null>;
|
|
5
|
+
export type Strategy = {
|
|
6
|
+
minProfit: ReadonlyMap<Address, bigint>;
|
|
7
|
+
maxFeeBps: number;
|
|
8
|
+
cycle?: Cycle;
|
|
9
|
+
routeAccounts?: number;
|
|
10
|
+
};
|
|
11
|
+
export type Payable = (draft: Pick<Plan, "intent" | "fees">) => Promise<string | null>;
|
|
12
|
+
export type Plan = {
|
|
13
|
+
address: Address;
|
|
14
|
+
intent: Intent;
|
|
15
|
+
amountIn: bigint;
|
|
16
|
+
required: bigint;
|
|
17
|
+
feeBps: number;
|
|
18
|
+
fees: FeeShares;
|
|
19
|
+
route: Quote;
|
|
20
|
+
arbitrage: Quote | null;
|
|
21
|
+
profit: bigint;
|
|
22
|
+
};
|
|
23
|
+
export type Decision = {
|
|
24
|
+
kind: "fill";
|
|
25
|
+
plan: Plan;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "skip";
|
|
28
|
+
reason: string;
|
|
29
|
+
};
|
|
30
|
+
export type Standing = {
|
|
31
|
+
params: IntentParams;
|
|
32
|
+
floor: bigint;
|
|
33
|
+
feeBps: number;
|
|
34
|
+
};
|
|
35
|
+
export declare function standing(intent: Intent, config: Config, now: bigint, strategy: Strategy): Standing | string;
|
|
36
|
+
export declare function decide(address: Address, intent: Intent, config: Config, now: bigint, pricer: Pricer, solver: Address, strategy: Strategy, payable?: Payable): Promise<Decision>;
|
package/dist/src/plan.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { decodeParamsLoose, feeBpsFor, INTENT_VERSION, IntentStatus, Kind, kindBit, PAUSE_FILL, remainingOf, requiredOut, splitFees, } from "@intent-engine/core";
|
|
2
|
+
const skip = (reason) => ({ kind: "skip", reason });
|
|
3
|
+
export function standing(intent, config, now, strategy) {
|
|
4
|
+
if (intent.version !== INTENT_VERSION) {
|
|
5
|
+
return `unsupported intent version ${intent.version}`;
|
|
6
|
+
}
|
|
7
|
+
if (intent.status !== IntentStatus.Open) {
|
|
8
|
+
return "not open";
|
|
9
|
+
}
|
|
10
|
+
if (now >= intent.expiresAt) {
|
|
11
|
+
return "expired";
|
|
12
|
+
}
|
|
13
|
+
if ((config.paused & PAUSE_FILL) !== 0) {
|
|
14
|
+
return "fills are paused";
|
|
15
|
+
}
|
|
16
|
+
const params = decodeParamsLoose(intent.kind, Uint8Array.from(intent.params));
|
|
17
|
+
if ("unknown" in params) {
|
|
18
|
+
return `unreadable params: ${params.reason}`;
|
|
19
|
+
}
|
|
20
|
+
if ((config.fillDisabledKinds & kindBit(params.kind)) !== 0n) {
|
|
21
|
+
return "fills of this kind are stopped";
|
|
22
|
+
}
|
|
23
|
+
if (params.kind === Kind.AttestedResult) {
|
|
24
|
+
return "settles only with an attestation";
|
|
25
|
+
}
|
|
26
|
+
const floor = strategy.minProfit.get(intent.outputMint);
|
|
27
|
+
if (floor === undefined) {
|
|
28
|
+
return `no profit floor is set for ${intent.outputMint}`;
|
|
29
|
+
}
|
|
30
|
+
const feeBps = feeBpsFor(config, params.kind);
|
|
31
|
+
if (feeBps + intent.partnerBps > strategy.maxFeeBps) {
|
|
32
|
+
return `fees of ${feeBps + intent.partnerBps} bps exceed the bound of ${strategy.maxFeeBps}`;
|
|
33
|
+
}
|
|
34
|
+
return { params, floor, feeBps };
|
|
35
|
+
}
|
|
36
|
+
export async function decide(address, intent, config, now, pricer, solver, strategy, payable = async () => null) {
|
|
37
|
+
const ready = standing(intent, config, now, strategy);
|
|
38
|
+
if (typeof ready === "string") {
|
|
39
|
+
return skip(ready);
|
|
40
|
+
}
|
|
41
|
+
const { params, floor, feeBps } = ready;
|
|
42
|
+
const amountIn = remainingOf(intent);
|
|
43
|
+
const fees = splitFees(amountIn, feeBps, intent.partnerBps, intent.partnerCutBps);
|
|
44
|
+
const required = requiredOut(params, amountIn, now);
|
|
45
|
+
const unpayable = await payable({ intent, fees });
|
|
46
|
+
if (unpayable !== null) {
|
|
47
|
+
return skip(unpayable);
|
|
48
|
+
}
|
|
49
|
+
const route = await pricer.quote({
|
|
50
|
+
inputMint: intent.inputMint,
|
|
51
|
+
outputMint: intent.outputMint,
|
|
52
|
+
amountIn: fees.net,
|
|
53
|
+
taker: solver,
|
|
54
|
+
...(strategy.routeAccounts === undefined ? {} : { maxAccounts: strategy.routeAccounts }),
|
|
55
|
+
});
|
|
56
|
+
if (route === null) {
|
|
57
|
+
return skip("no route");
|
|
58
|
+
}
|
|
59
|
+
if (route.amountOut < required) {
|
|
60
|
+
return skip(`the route pays ${route.amountOut}, less than the ${required} the intent requires`);
|
|
61
|
+
}
|
|
62
|
+
const spread = route.amountOut - required;
|
|
63
|
+
const arbitrage = strategy.cycle !== undefined && spread > 0n ? await strategy.cycle(intent.outputMint, spread) : null;
|
|
64
|
+
const gain = arbitrage !== null && arbitrage.amountIn <= spread && arbitrage.amountOut > arbitrage.amountIn ? arbitrage : null;
|
|
65
|
+
const profit = gain === null ? spread : spread - gain.amountIn + gain.amountOut;
|
|
66
|
+
if (profit < floor) {
|
|
67
|
+
return skip(`profit ${profit} is below ${floor}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
kind: "fill",
|
|
71
|
+
plan: { address, intent, amountIn, required, feeBps, fees, route, arbitrage: gain, profit },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/plan.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EAEjB,SAAS,EAGT,cAAc,EACd,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,SAAS,GACV,MAAM,qBAAqB,CAAC;AA4B7B,MAAM,IAAI,GAAG,CAAC,MAAc,EAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAItE,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,MAAc,EAAE,GAAW,EAAE,QAAkB;IACtF,IAAI,MAAM,CAAC,OAAO,KAAK,cAAc,EAAE,CAAC;QACtC,OAAO,8BAA8B,MAAM,CAAC,OAAO,EAAE,CAAC;IACxD,CAAC;IACD,IAAI,MAAM,CAAC,MAAM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
1
|
+
import type { Address, Base64EncodedWireTransaction, Blockhash, Instruction, TransactionSigner } from "@solana/kit";
|
|
2
|
+
import { type Config, type Intent } from "@intent-engine/core";
|
|
3
|
+
import { type Tip } from "./build.js";
|
|
4
|
+
import type { Pricer } from "./market.js";
|
|
5
|
+
import { type Strategy } from "./plan.js";
|
|
6
|
+
export type Chain = {
|
|
7
|
+
config(): Promise<Config>;
|
|
8
|
+
intents(): Promise<{
|
|
9
|
+
address: Address;
|
|
10
|
+
intent: Intent;
|
|
11
|
+
}[]>;
|
|
12
|
+
now(): Promise<bigint>;
|
|
13
|
+
tokenProgram(mint: Address): Promise<Address>;
|
|
14
|
+
exists(address: Address): Promise<boolean>;
|
|
15
|
+
lookupTables(addresses: readonly Address[]): Promise<Record<Address, Address[]>>;
|
|
16
|
+
blockhash(): Promise<{
|
|
17
|
+
blockhash: Blockhash;
|
|
18
|
+
lastValidBlockHeight: bigint;
|
|
19
|
+
}>;
|
|
20
|
+
tokenAmount(address: Address): Promise<bigint>;
|
|
21
|
+
};
|
|
22
|
+
export type Simulated = {
|
|
23
|
+
err: string | null;
|
|
24
|
+
unitsConsumed: bigint | null;
|
|
25
|
+
balances: readonly (bigint | null)[];
|
|
26
|
+
};
|
|
27
|
+
export type Sent = {
|
|
28
|
+
signature: string;
|
|
29
|
+
confirmed: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type SolverOptions = {
|
|
32
|
+
chain: Chain;
|
|
33
|
+
pricer: Pricer;
|
|
34
|
+
solver: TransactionSigner;
|
|
35
|
+
strategy: Strategy;
|
|
36
|
+
tip: Tip | null;
|
|
37
|
+
lookupTables?: readonly Address[];
|
|
38
|
+
unitPrice(instructions: readonly Instruction[]): Promise<bigint>;
|
|
39
|
+
simulate(wire: Base64EncodedWireTransaction, watch: readonly Address[]): Promise<Simulated>;
|
|
40
|
+
send(wire: Base64EncodedWireTransaction): Promise<Sent>;
|
|
41
|
+
};
|
|
42
|
+
export type Report = {
|
|
43
|
+
filled: {
|
|
44
|
+
intent: Address;
|
|
45
|
+
profit: bigint;
|
|
46
|
+
signature: string;
|
|
47
|
+
}[];
|
|
48
|
+
sent: {
|
|
49
|
+
intent: Address;
|
|
50
|
+
profit: bigint;
|
|
51
|
+
signature: string;
|
|
52
|
+
}[];
|
|
53
|
+
skipped: {
|
|
54
|
+
intent: Address;
|
|
55
|
+
reason: string;
|
|
56
|
+
}[];
|
|
57
|
+
failed: {
|
|
58
|
+
intent: Address;
|
|
59
|
+
error: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
export declare const SIMULATION_REFUSED = "the fill failed in simulation, so it was not sent";
|
|
63
|
+
export declare const BALANCES_REFUSED = "the fill would leave the solver with less of a token than planned, so it was not sent";
|
|
64
|
+
export declare const ROUTE_ACCOUNT_BUDGETS: readonly [40, 30, 20];
|
|
65
|
+
export declare const tooLarge: (bytes: number | null, accounts: number) => string;
|
|
66
|
+
export declare function tick(o: SolverOptions): Promise<Report>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { findAssociatedTokenAddress } from "@intent-engine/core";
|
|
2
|
+
import { accountsOf, bytesFit, compile, fillInstructions, headroom, locksFit, lookupTablesOf, MAX_COMPUTE_UNITS, MAX_TX_ACCOUNTS, PACKET_DATA_SIZE, payoutAccounts, wireSize, } from "./build.js";
|
|
3
|
+
import { RateLimited } from "./jupiter.js";
|
|
4
|
+
import { decide, standing } from "./plan.js";
|
|
5
|
+
export const SIMULATION_REFUSED = "the fill failed in simulation, so it was not sent";
|
|
6
|
+
export const BALANCES_REFUSED = "the fill would leave the solver with less of a token than planned, so it was not sent";
|
|
7
|
+
export const ROUTE_ACCOUNT_BUDGETS = [40, 30, 20];
|
|
8
|
+
export const tooLarge = (bytes, accounts) => `even the smallest route makes the fill ${bytes === null ? "lock" : `${bytes} bytes with`} ${accounts} accounts; a transaction holds ${PACKET_DATA_SIZE} bytes and ${MAX_TX_ACCOUNTS} accounts`;
|
|
9
|
+
export async function tick(o) {
|
|
10
|
+
const report = { filled: [], sent: [], skipped: [], failed: [] };
|
|
11
|
+
const [config, now, intents] = await Promise.all([o.chain.config(), o.chain.now(), o.chain.intents()]);
|
|
12
|
+
let limited = null;
|
|
13
|
+
for (const { address, intent } of intents) {
|
|
14
|
+
if (limited !== null) {
|
|
15
|
+
report.skipped.push({ intent: address, reason: limited });
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const ready = standing(intent, config, now, o.strategy);
|
|
19
|
+
if (typeof ready === "string") {
|
|
20
|
+
report.skipped.push({ intent: address, reason: ready });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const inputTokenProgram = await o.chain.tokenProgram(intent.inputMint);
|
|
25
|
+
const payable = async (draft) => {
|
|
26
|
+
const missing = [];
|
|
27
|
+
for (const payout of await payoutAccounts(draft, config.feeRecipient, inputTokenProgram)) {
|
|
28
|
+
if (!(await o.chain.exists(payout.address))) {
|
|
29
|
+
missing.push(payout.name);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return missing.length === 0 ? null : `no ${missing.join(" or ")} account to pay into`;
|
|
33
|
+
};
|
|
34
|
+
const solverInput = await findAssociatedTokenAddress({
|
|
35
|
+
owner: o.solver.address,
|
|
36
|
+
mint: intent.inputMint,
|
|
37
|
+
tokenProgram: inputTokenProgram,
|
|
38
|
+
});
|
|
39
|
+
const outputTokenProgram = await o.chain.tokenProgram(intent.outputMint);
|
|
40
|
+
const solverOutput = await findAssociatedTokenAddress({
|
|
41
|
+
owner: o.solver.address,
|
|
42
|
+
mint: intent.outputMint,
|
|
43
|
+
tokenProgram: outputTokenProgram,
|
|
44
|
+
});
|
|
45
|
+
const draft = {
|
|
46
|
+
solver: o.solver,
|
|
47
|
+
feeRecipient: config.feeRecipient,
|
|
48
|
+
inputTokenProgram,
|
|
49
|
+
outputTokenProgram,
|
|
50
|
+
computeUnits: MAX_COMPUTE_UNITS,
|
|
51
|
+
unitPrice: 0n,
|
|
52
|
+
createSolverInput: !(await o.chain.exists(solverInput)),
|
|
53
|
+
createSolverOutput: !(await o.chain.exists(solverOutput)),
|
|
54
|
+
tip: o.tip,
|
|
55
|
+
};
|
|
56
|
+
let fitting = null;
|
|
57
|
+
let skipped = null;
|
|
58
|
+
let size = { bytes: null, accounts: 0 };
|
|
59
|
+
const latest = await o.chain.blockhash();
|
|
60
|
+
for (const routeAccounts of ROUTE_ACCOUNT_BUDGETS) {
|
|
61
|
+
const decision = await decide(address, intent, config, now, o.pricer, o.solver.address, { ...o.strategy, routeAccounts }, payable);
|
|
62
|
+
if (decision.kind === "skip") {
|
|
63
|
+
skipped = decision.reason;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const plan = decision.plan;
|
|
67
|
+
const context = { ...draft, unitPrice: await o.unitPrice(await fillInstructions(plan, draft)) };
|
|
68
|
+
const instructions = await fillInstructions(plan, context);
|
|
69
|
+
const accounts = accountsOf(instructions, o.solver.address);
|
|
70
|
+
if (!locksFit(accounts)) {
|
|
71
|
+
size = { bytes: null, accounts };
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const tables = await o.chain.lookupTables(lookupTablesOf(plan, o.lookupTables));
|
|
75
|
+
const probe = await compile(instructions, o.solver, latest, tables);
|
|
76
|
+
const bytes = wireSize(probe);
|
|
77
|
+
size = { bytes, accounts };
|
|
78
|
+
if (bytesFit(bytes)) {
|
|
79
|
+
fitting = { plan, context, tables, probe };
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (skipped !== null || fitting === null) {
|
|
84
|
+
report.skipped.push({ intent: address, reason: skipped ?? tooLarge(size.bytes, size.accounts) });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const { plan, context, tables, probe } = fitting;
|
|
88
|
+
const before = [await o.chain.tokenAmount(solverInput), await o.chain.tokenAmount(solverOutput)];
|
|
89
|
+
const simulated = await o.simulate(probe, [solverInput, solverOutput]);
|
|
90
|
+
if (simulated.err !== null) {
|
|
91
|
+
report.failed.push({ intent: address, error: `${SIMULATION_REFUSED}: ${simulated.err}` });
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const [inputAfter, outputAfter] = simulated.balances;
|
|
95
|
+
const least = [before[0] ?? 0n, (before[1] ?? 0n) + plan.profit];
|
|
96
|
+
if (inputAfter === null || inputAfter === undefined || outputAfter === null || outputAfter === undefined || inputAfter < (least[0] ?? 0n) || outputAfter < (least[1] ?? 0n)) {
|
|
97
|
+
report.failed.push({
|
|
98
|
+
intent: address,
|
|
99
|
+
error: `${BALANCES_REFUSED}: input ${before[0]} to ${inputAfter}, output ${before[1]} to ${outputAfter}, expected at least ${least[0]} and ${least[1]}`,
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const wire = simulated.unitsConsumed === null
|
|
104
|
+
? probe
|
|
105
|
+
: await compile(await fillInstructions(plan, { ...context, computeUnits: headroom(simulated.unitsConsumed) }), o.solver, latest, tables);
|
|
106
|
+
const sent = await o.send(wire);
|
|
107
|
+
(sent.confirmed ? report.filled : report.sent).push({ intent: address, profit: plan.profit, signature: sent.signature });
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof RateLimited) {
|
|
111
|
+
limited = error.message;
|
|
112
|
+
report.skipped.push({ intent: address, reason: limited });
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
report.failed.push({ intent: address, error: error instanceof Error ? error.message : String(error) });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return report;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=solver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solver.js","sourceRoot":"","sources":["../../src/solver.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,0BAA0B,EAAe,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EACL,UAAU,EACV,QAAQ,EACR,OAAO,EAEP,gBAAg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AAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intent-engine/solver",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A solver that fills intent engine intents at a profit",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/src"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22.12.0"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/src/index.d.ts",
|
|
19
|
+
"import": "./dist/src/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@solana-program/system": "0.14.1",
|
|
24
|
+
"@solana-program/token": "0.16.1",
|
|
25
|
+
"@solana/kit": "8.4.0",
|
|
26
|
+
"@intent-engine/core": "0.1.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "26.6.4",
|
|
30
|
+
"fast-check": "4.10.2",
|
|
31
|
+
"litesvm": "1.5.0",
|
|
32
|
+
"typescript": "7.0.2",
|
|
33
|
+
"vitest": "5.0.3"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -p tsconfig.build.json",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
38
|
+
"test": "vitest run --fsModuleCache"
|
|
39
|
+
}
|
|
6
40
|
}
|
package/README.md
DELETED