@intent-engine/cli 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/accounts.d.ts +112 -0
- package/dist/src/accounts.js +162 -0
- package/dist/src/accounts.js.map +1 -0
- package/dist/src/agent/actions.d.ts +45 -0
- package/dist/src/agent/actions.js +43 -0
- package/dist/src/agent/actions.js.map +1 -0
- package/dist/src/agent/budget.d.ts +22 -0
- package/dist/src/agent/budget.js +31 -0
- package/dist/src/agent/budget.js.map +1 -0
- package/dist/src/agent/claims.d.ts +15 -0
- package/dist/src/agent/claims.js +47 -0
- package/dist/src/agent/claims.js.map +1 -0
- package/dist/src/agent/create.d.ts +56 -0
- package/dist/src/agent/create.js +119 -0
- package/dist/src/agent/create.js.map +1 -0
- package/dist/src/agent/mandate.d.ts +30 -0
- package/dist/src/agent/mandate.js +480 -0
- package/dist/src/agent/mandate.js.map +1 -0
- package/dist/src/agent/mcp.d.ts +17 -0
- package/dist/src/agent/mcp.js +53 -0
- package/dist/src/agent/mcp.js.map +1 -0
- package/dist/src/agent/names.d.ts +1 -0
- package/dist/src/agent/names.js +3 -0
- package/dist/src/agent/names.js.map +1 -0
- package/dist/src/agent/owner.d.ts +40 -0
- package/dist/src/agent/owner.js +123 -0
- package/dist/src/agent/owner.js.map +1 -0
- package/dist/src/agent/prepare.d.ts +14 -0
- package/dist/src/agent/prepare.js +32 -0
- package/dist/src/agent/prepare.js.map +1 -0
- package/dist/src/agent/problems.d.ts +120 -0
- package/dist/src/agent/problems.js +189 -0
- package/dist/src/agent/problems.js.map +1 -0
- package/dist/src/agent/read.d.ts +13 -0
- package/dist/src/agent/read.js +210 -0
- package/dist/src/agent/read.js.map +1 -0
- package/dist/src/agent/registry.d.ts +2 -0
- package/dist/src/agent/registry.js +24 -0
- package/dist/src/agent/registry.js.map +1 -0
- package/dist/src/agent/relay.d.ts +20 -0
- package/dist/src/agent/relay.js +43 -0
- package/dist/src/agent/relay.js.map +1 -0
- package/dist/src/agent/schema.d.ts +68 -0
- package/dist/src/agent/schema.js +210 -0
- package/dist/src/agent/schema.js.map +1 -0
- package/dist/src/agent/settle.d.ts +5 -0
- package/dist/src/agent/settle.js +145 -0
- package/dist/src/agent/settle.js.map +1 -0
- package/dist/src/agent/shapes.d.ts +165 -0
- package/dist/src/agent/shapes.js +163 -0
- package/dist/src/agent/shapes.js.map +1 -0
- package/dist/src/agent/signed.d.ts +21 -0
- package/dist/src/agent/signed.js +363 -0
- package/dist/src/agent/signed.js.map +1 -0
- package/dist/src/agent/wallet.d.ts +18 -0
- package/dist/src/agent/wallet.js +186 -0
- package/dist/src/agent/wallet.js.map +1 -0
- package/dist/src/args.d.ts +491 -0
- package/dist/src/args.js +1124 -0
- package/dist/src/args.js.map +1 -0
- package/dist/src/bin.d.ts +2 -0
- package/dist/src/bin.js +4 -0
- package/dist/src/bin.js.map +1 -0
- package/dist/src/commands.d.ts +51 -0
- package/dist/src/commands.js +451 -0
- package/dist/src/commands.js.map +1 -0
- package/dist/src/compute.d.ts +19 -0
- package/dist/src/compute.js +81 -0
- package/dist/src/compute.js.map +1 -0
- package/dist/src/crank.d.ts +39 -0
- package/dist/src/crank.js +171 -0
- package/dist/src/crank.js.map +1 -0
- package/dist/src/events.d.ts +8 -0
- package/dist/src/events.js +43 -0
- package/dist/src/events.js.map +1 -0
- package/dist/src/flows.d.ts +23 -0
- package/dist/src/flows.js +128 -0
- package/dist/src/flows.js.map +1 -0
- package/dist/src/main.d.ts +32 -0
- package/dist/src/main.js +99 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/render.d.ts +5 -0
- package/dist/src/render.js +46 -0
- package/dist/src/render.js.map +1 -0
- package/dist/src/tokens.d.ts +11 -0
- package/dist/src/tokens.js +20 -0
- package/dist/src/tokens.js.map +1 -0
- package/dist/src/transport.d.ts +155 -0
- package/dist/src/transport.js +173 -0
- package/dist/src/transport.js.map +1 -0
- package/dist/src/treasury.d.ts +27 -0
- package/dist/src/treasury.js +85 -0
- package/dist/src/treasury.js.map +1 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +2 -0
- package/dist/src/version.js.map +1 -0
- package/dist/src/wallet.d.ts +30 -0
- package/dist/src/wallet.js +109 -0
- package/dist/src/wallet.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,112 @@
|
|
|
1
|
+
import { type Address } from "@solana/kit";
|
|
2
|
+
import { type FeeConfig, type Intent } from "@intent-engine/core";
|
|
3
|
+
import type { AccountView, Transport } from "./transport.js";
|
|
4
|
+
export declare const STATUS: readonly ["open", "filled", "cancelled", "expired", "filling"];
|
|
5
|
+
export declare function createdAccount(transport: Transport, address: Address): Promise<AccountView | null>;
|
|
6
|
+
export declare class MissingAccount extends Error {
|
|
7
|
+
readonly address: Address;
|
|
8
|
+
constructor(what: string, address: Address);
|
|
9
|
+
}
|
|
10
|
+
export declare function engineAccount(transport: Transport, address: Address, discriminator: ArrayLike<number>, what: string): Promise<Uint8Array>;
|
|
11
|
+
export declare function loadIntent(transport: Transport, owner: Address, nonce: bigint): Promise<{
|
|
12
|
+
address: Address<string>;
|
|
13
|
+
intent: Intent;
|
|
14
|
+
}>;
|
|
15
|
+
export declare class NotAMint extends Error {
|
|
16
|
+
readonly address: Address;
|
|
17
|
+
constructor(address: Address);
|
|
18
|
+
}
|
|
19
|
+
export declare function loadConfig(transport: Transport): Promise<{
|
|
20
|
+
address: Address<string>;
|
|
21
|
+
config: import("@intent-engine/core").Config;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function tokenProgramOf(transport: Transport, mint: Address): Promise<Address>;
|
|
24
|
+
export declare const MINT_DECIMALS_OFFSET = 44;
|
|
25
|
+
export declare const MINT_BASE_SIZE = 82;
|
|
26
|
+
export declare const TOKEN_PROGRAMS: Address[];
|
|
27
|
+
export declare const SCALING_EXTENSIONS: number[];
|
|
28
|
+
export declare const EXTENSIONS_OFFSET = 166;
|
|
29
|
+
export declare function scalesDisplay(data: Uint8Array): boolean;
|
|
30
|
+
export declare function mintOf(transport: Transport, mint: Address): Promise<{
|
|
31
|
+
tokenProgram: Address;
|
|
32
|
+
decimals: number;
|
|
33
|
+
scaled: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const EXTENDED_TYPE_OFFSET = 165;
|
|
36
|
+
export declare const EXTENDED_MINT_TYPE = 1;
|
|
37
|
+
export declare function isMintData(data: Uint8Array): boolean;
|
|
38
|
+
export declare function quoteOf(intent: Intent, config: FeeConfig, at: bigint): {
|
|
39
|
+
at: bigint;
|
|
40
|
+
amountIn: bigint;
|
|
41
|
+
requiredOut: bigint;
|
|
42
|
+
feeBps: number;
|
|
43
|
+
partnerBps: number;
|
|
44
|
+
protocolFee: bigint;
|
|
45
|
+
partnerFee: bigint;
|
|
46
|
+
net: bigint;
|
|
47
|
+
};
|
|
48
|
+
export declare function describeIntent(address: Address, intent: Intent): {
|
|
49
|
+
address: Address;
|
|
50
|
+
owner: Address;
|
|
51
|
+
inputMint: Address;
|
|
52
|
+
outputMint: Address;
|
|
53
|
+
receiver: Address;
|
|
54
|
+
rentPayer: Address;
|
|
55
|
+
nonce: bigint;
|
|
56
|
+
escrowed: bigint;
|
|
57
|
+
createdAt: bigint;
|
|
58
|
+
expiresAt: bigint;
|
|
59
|
+
status: "cancelled" | "expired" | "filled" | "filling" | "open" | `unknown(${number})`;
|
|
60
|
+
version: number;
|
|
61
|
+
flags: number;
|
|
62
|
+
filled: bigint;
|
|
63
|
+
revision: number;
|
|
64
|
+
bounty: number;
|
|
65
|
+
partner?: Address;
|
|
66
|
+
partnerBps?: number;
|
|
67
|
+
params: {
|
|
68
|
+
kind: string;
|
|
69
|
+
raw: string;
|
|
70
|
+
reason: string;
|
|
71
|
+
} | {
|
|
72
|
+
unknown: true;
|
|
73
|
+
raw: Uint8Array;
|
|
74
|
+
reason: string;
|
|
75
|
+
kind: string | undefined;
|
|
76
|
+
} | {
|
|
77
|
+
amountIn: bigint;
|
|
78
|
+
minResult: bigint;
|
|
79
|
+
maxResult: bigint;
|
|
80
|
+
attestor: Address;
|
|
81
|
+
raw?: never;
|
|
82
|
+
reason?: never;
|
|
83
|
+
kind: string | undefined;
|
|
84
|
+
} | {
|
|
85
|
+
amountIn: bigint;
|
|
86
|
+
startOut: bigint;
|
|
87
|
+
endOut: bigint;
|
|
88
|
+
startTs: bigint;
|
|
89
|
+
endTs: bigint;
|
|
90
|
+
raw?: never;
|
|
91
|
+
reason?: never;
|
|
92
|
+
kind: string | undefined;
|
|
93
|
+
} | {
|
|
94
|
+
makeAmount: bigint;
|
|
95
|
+
takeAmount: bigint;
|
|
96
|
+
raw?: never;
|
|
97
|
+
reason?: never;
|
|
98
|
+
kind: string | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
amountIn: bigint;
|
|
101
|
+
minOut: bigint;
|
|
102
|
+
raw?: never;
|
|
103
|
+
reason?: never;
|
|
104
|
+
kind: string | undefined;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export declare const TOKEN_AMOUNT_OFFSET = 64;
|
|
108
|
+
export declare function tokenAmountOf(data: Uint8Array | null): bigint | null;
|
|
109
|
+
export declare function chainTime(transport: Transport): Promise<bigint>;
|
|
110
|
+
export declare function rentExemptMinimum(transport: Transport, dataLength: number): Promise<bigint>;
|
|
111
|
+
export declare function clusterDomain(transport: Transport): Promise<Uint8Array>;
|
|
112
|
+
export declare const sameBytes: (a: ArrayLike<number>, b: ArrayLike<number>) => boolean;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { getBase58Encoder } from "@solana/kit";
|
|
2
|
+
import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
|
|
3
|
+
import { decodeParams, decodeParamsLoose, feeBpsFor, remainingOf, requiredOut, splitFees, findConfigPda, findIntentPda, getConfigDecoder, getConfigDiscriminatorBytes, getIntentDecoder, getIntentDiscriminatorBytes, INTENT_ENGINE_PROGRAM_ADDRESS, INTENT_VERSION, Kind, } from "@intent-engine/core";
|
|
4
|
+
export const STATUS = ["open", "filled", "cancelled", "expired", "filling"];
|
|
5
|
+
export async function createdAccount(transport, address) {
|
|
6
|
+
const view = await transport.getAccount(address);
|
|
7
|
+
return view === null || (view.owner === SYSTEM_PROGRAM_ADDRESS && view.data.length === 0) ? null : view;
|
|
8
|
+
}
|
|
9
|
+
export class MissingAccount extends Error {
|
|
10
|
+
address;
|
|
11
|
+
constructor(what, address) {
|
|
12
|
+
super(`${what} ${address} does not exist`);
|
|
13
|
+
this.name = "MissingAccount";
|
|
14
|
+
this.address = address;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export async function engineAccount(transport, address, discriminator, what) {
|
|
18
|
+
const view = await createdAccount(transport, address);
|
|
19
|
+
if (view === null) {
|
|
20
|
+
throw new MissingAccount(what, address);
|
|
21
|
+
}
|
|
22
|
+
const head = view.data.subarray(0, discriminator.length);
|
|
23
|
+
if (view.owner !== INTENT_ENGINE_PROGRAM_ADDRESS || !head.every((b, i) => b === discriminator[i])) {
|
|
24
|
+
throw new Error(`${address} is not an engine ${what}`);
|
|
25
|
+
}
|
|
26
|
+
return view.data;
|
|
27
|
+
}
|
|
28
|
+
export async function loadIntent(transport, owner, nonce) {
|
|
29
|
+
const [address] = await findIntentPda({ owner, nonce });
|
|
30
|
+
const data = await engineAccount(transport, address, getIntentDiscriminatorBytes(), "intent");
|
|
31
|
+
return { address, intent: getIntentDecoder().decode(data) };
|
|
32
|
+
}
|
|
33
|
+
export class NotAMint extends Error {
|
|
34
|
+
address;
|
|
35
|
+
constructor(address) {
|
|
36
|
+
super(`${address} is not a token mint`);
|
|
37
|
+
this.name = "NotAMint";
|
|
38
|
+
this.address = address;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function loadConfig(transport) {
|
|
42
|
+
const [address] = await findConfigPda();
|
|
43
|
+
const data = await engineAccount(transport, address, getConfigDiscriminatorBytes(), "config");
|
|
44
|
+
return { address, config: getConfigDecoder().decode(data) };
|
|
45
|
+
}
|
|
46
|
+
export async function tokenProgramOf(transport, mint) {
|
|
47
|
+
const view = await createdAccount(transport, mint);
|
|
48
|
+
if (view === null) {
|
|
49
|
+
throw new MissingAccount("mint", mint);
|
|
50
|
+
}
|
|
51
|
+
return view.owner;
|
|
52
|
+
}
|
|
53
|
+
export const MINT_DECIMALS_OFFSET = 44;
|
|
54
|
+
export const MINT_BASE_SIZE = 82;
|
|
55
|
+
export const TOKEN_PROGRAMS = [
|
|
56
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
57
|
+
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
|
|
58
|
+
];
|
|
59
|
+
export const SCALING_EXTENSIONS = [10, 25];
|
|
60
|
+
export const EXTENSIONS_OFFSET = 166;
|
|
61
|
+
export function scalesDisplay(data) {
|
|
62
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
63
|
+
for (let at = EXTENSIONS_OFFSET; at + 4 <= data.length; at += 4 + view.getUint16(at + 2, true)) {
|
|
64
|
+
if (SCALING_EXTENSIONS.includes(view.getUint16(at, true))) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
export async function mintOf(transport, mint) {
|
|
71
|
+
const view = await transport.getAccount(mint);
|
|
72
|
+
if (view === null) {
|
|
73
|
+
throw new MissingAccount("mint", mint);
|
|
74
|
+
}
|
|
75
|
+
if (!TOKEN_PROGRAMS.includes(view.owner) || !isMintData(view.data)) {
|
|
76
|
+
throw new NotAMint(mint);
|
|
77
|
+
}
|
|
78
|
+
return { tokenProgram: view.owner, decimals: view.data[MINT_DECIMALS_OFFSET], scaled: scalesDisplay(view.data) };
|
|
79
|
+
}
|
|
80
|
+
export const EXTENDED_TYPE_OFFSET = 165;
|
|
81
|
+
export const EXTENDED_MINT_TYPE = 1;
|
|
82
|
+
export function isMintData(data) {
|
|
83
|
+
return data.length === MINT_BASE_SIZE || data[EXTENDED_TYPE_OFFSET] === EXTENDED_MINT_TYPE;
|
|
84
|
+
}
|
|
85
|
+
export function quoteOf(intent, config, at) {
|
|
86
|
+
const params = decodeParams(intent.kind, Uint8Array.from(intent.params));
|
|
87
|
+
const amountIn = remainingOf(intent);
|
|
88
|
+
const feeBps = feeBpsFor(config, params.kind);
|
|
89
|
+
const fees = splitFees(amountIn, feeBps, intent.partnerBps, intent.partnerCutBps);
|
|
90
|
+
return {
|
|
91
|
+
at,
|
|
92
|
+
amountIn,
|
|
93
|
+
requiredOut: requiredOut(params, amountIn, at),
|
|
94
|
+
feeBps,
|
|
95
|
+
partnerBps: intent.partnerBps,
|
|
96
|
+
protocolFee: fees.protocol,
|
|
97
|
+
partnerFee: fees.partner,
|
|
98
|
+
net: fees.net,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const hex = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
102
|
+
export function describeIntent(address, intent) {
|
|
103
|
+
const raw = Uint8Array.from(intent.params);
|
|
104
|
+
const params = intent.version === INTENT_VERSION
|
|
105
|
+
? decodeParamsLoose(intent.kind, raw)
|
|
106
|
+
: { kind: intent.kind, unknown: true, raw, reason: `unsupported version ${intent.version}` };
|
|
107
|
+
return {
|
|
108
|
+
address,
|
|
109
|
+
owner: intent.owner,
|
|
110
|
+
inputMint: intent.inputMint,
|
|
111
|
+
outputMint: intent.outputMint,
|
|
112
|
+
receiver: intent.receiver,
|
|
113
|
+
rentPayer: intent.rentPayer,
|
|
114
|
+
nonce: intent.nonce,
|
|
115
|
+
escrowed: intent.escrowed,
|
|
116
|
+
createdAt: intent.createdAt,
|
|
117
|
+
expiresAt: intent.expiresAt,
|
|
118
|
+
status: STATUS[intent.status] ?? `unknown(${intent.status})`,
|
|
119
|
+
version: intent.version,
|
|
120
|
+
flags: intent.flags,
|
|
121
|
+
filled: intent.filled,
|
|
122
|
+
revision: intent.revision,
|
|
123
|
+
bounty: intent.bounty,
|
|
124
|
+
...(intent.partnerBps === 0 ? {} : { partner: intent.partner, partnerBps: intent.partnerBps }),
|
|
125
|
+
params: "unknown" in params && params.unknown
|
|
126
|
+
? { kind: `unknown(${params.kind})`, raw: hex(params.raw), reason: params.reason }
|
|
127
|
+
: { ...params, kind: Kind[params.kind] },
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const CLOCK_SYSVAR = "SysvarC1ock11111111111111111111111111111111";
|
|
131
|
+
const CLOCK_UNIX_TIMESTAMP = 32;
|
|
132
|
+
export const TOKEN_AMOUNT_OFFSET = 64;
|
|
133
|
+
export function tokenAmountOf(data) {
|
|
134
|
+
if (data === null || data.length < TOKEN_AMOUNT_OFFSET + 8) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return new DataView(data.buffer, data.byteOffset).getBigUint64(TOKEN_AMOUNT_OFFSET, true);
|
|
138
|
+
}
|
|
139
|
+
export async function chainTime(transport) {
|
|
140
|
+
const view = await transport.getAccount(CLOCK_SYSVAR);
|
|
141
|
+
if (view === null) {
|
|
142
|
+
throw new Error("the clock sysvar is missing");
|
|
143
|
+
}
|
|
144
|
+
return new DataView(view.data.buffer, view.data.byteOffset).getBigInt64(CLOCK_UNIX_TIMESTAMP, true);
|
|
145
|
+
}
|
|
146
|
+
const RENT_SYSVAR = "SysvarRent111111111111111111111111111111111";
|
|
147
|
+
const ACCOUNT_STORAGE_OVERHEAD = 128n;
|
|
148
|
+
const RENT_THRESHOLD_OFFSET = 8;
|
|
149
|
+
export async function rentExemptMinimum(transport, dataLength) {
|
|
150
|
+
const view = await transport.getAccount(RENT_SYSVAR);
|
|
151
|
+
if (view === null) {
|
|
152
|
+
throw new Error("the rent sysvar is missing");
|
|
153
|
+
}
|
|
154
|
+
const rent = new DataView(view.data.buffer, view.data.byteOffset);
|
|
155
|
+
const perYear = rent.getBigUint64(0, true) * (ACCOUNT_STORAGE_OVERHEAD + BigInt(dataLength));
|
|
156
|
+
return BigInt(Math.floor(Number(perYear) * rent.getFloat64(RENT_THRESHOLD_OFFSET, true)));
|
|
157
|
+
}
|
|
158
|
+
export async function clusterDomain(transport) {
|
|
159
|
+
return Uint8Array.from(getBase58Encoder().encode(await transport.genesisHash()));
|
|
160
|
+
}
|
|
161
|
+
export const sameBytes = (a, b) => a.length === b.length && Array.from(a).every((v, i) => v === b[i]);
|
|
162
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EACL,YAAY,EACZ,iBAAiB,EAEjB,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,2BAA2B,EAC3B,gBAAgB,EAChB,2BAA2B,EAC3B,6BAA6B,EAC7B,cAAc,EAEd,IAAI,GACL,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAErF,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAoB,EAAE,OAAgB;IACzE,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,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Address, TransactionSigner } from "@solana/kit";
|
|
2
|
+
import type { Transport } from "../transport.js";
|
|
3
|
+
import { type Problem } from "./problems.js";
|
|
4
|
+
import type { Budget } from "./budget.js";
|
|
5
|
+
import type { Relay } from "./relay.js";
|
|
6
|
+
import { type Call, type Claims } from "./claims.js";
|
|
7
|
+
import { InvalidInput, type Schema } from "./schema.js";
|
|
8
|
+
import type { WalletAccess } from "./wallet.js";
|
|
9
|
+
export type Effect = "read" | "prepare" | "submit";
|
|
10
|
+
export type AgentContext = {
|
|
11
|
+
transport: Transport;
|
|
12
|
+
relay: Relay | undefined;
|
|
13
|
+
agent: AgentKey | undefined;
|
|
14
|
+
claims: Claims;
|
|
15
|
+
wallet?: WalletAccess;
|
|
16
|
+
};
|
|
17
|
+
export type AgentKey = {
|
|
18
|
+
signer: TransactionSigner;
|
|
19
|
+
budget: Budget;
|
|
20
|
+
owners: ReadonlySet<Address>;
|
|
21
|
+
};
|
|
22
|
+
export type Action<I> = {
|
|
23
|
+
name: string;
|
|
24
|
+
title: string;
|
|
25
|
+
description: string;
|
|
26
|
+
effect: Effect;
|
|
27
|
+
repeats?: true;
|
|
28
|
+
input: Schema<I>;
|
|
29
|
+
output: Schema<unknown>;
|
|
30
|
+
run(ctx: AgentContext, input: I, call: Call): Promise<object>;
|
|
31
|
+
};
|
|
32
|
+
export type AnyAction = Action<never>;
|
|
33
|
+
export declare const define: <I>(action: Action<I>) => AnyAction;
|
|
34
|
+
export declare function toJson(value: unknown): unknown;
|
|
35
|
+
export declare class OutputMismatch extends Error {
|
|
36
|
+
constructor(action: string, cause: InvalidInput);
|
|
37
|
+
}
|
|
38
|
+
export type Outcome = {
|
|
39
|
+
ok: true;
|
|
40
|
+
value: Record<string, unknown>;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
problem: Problem;
|
|
44
|
+
};
|
|
45
|
+
export declare function invoke(action: AnyAction, ctx: AgentContext, raw: unknown): Promise<Outcome>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { problemOf } from "./problems.js";
|
|
2
|
+
import { callOf } from "./claims.js";
|
|
3
|
+
import { InvalidInput } from "./schema.js";
|
|
4
|
+
export const define = (action) => action;
|
|
5
|
+
export function toJson(value) {
|
|
6
|
+
if (typeof value === "bigint") {
|
|
7
|
+
return value.toString();
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return value.map(toJson);
|
|
11
|
+
}
|
|
12
|
+
if (value !== null && typeof value === "object") {
|
|
13
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, toJson(v)]));
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export class OutputMismatch extends Error {
|
|
18
|
+
constructor(action, cause) {
|
|
19
|
+
super(`${action} produced output outside its schema: ${cause.message}`);
|
|
20
|
+
this.name = "OutputMismatch";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function invoke(action, ctx, raw) {
|
|
24
|
+
const call = callOf();
|
|
25
|
+
try {
|
|
26
|
+
const input = action.input.read(raw ?? {}, "");
|
|
27
|
+
const value = toJson(await action.run(ctx, input, call));
|
|
28
|
+
try {
|
|
29
|
+
action.output.read(value, "");
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw error instanceof InvalidInput ? new OutputMismatch(action.name, error) : error;
|
|
33
|
+
}
|
|
34
|
+
return { ok: true, value: value };
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
for (const undo of call.undo.reverse()) {
|
|
38
|
+
undo();
|
|
39
|
+
}
|
|
40
|
+
return { ok: false, problem: problemOf(error) };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=actions.js.map
|
|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MAAM,EAAE,CAAC;IACtB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAc,EAAE,IAAI,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC;YACH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,YAAY,YAAY,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACvF,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAgC,EAAE,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACvC,IAAI,EAAE,CAAC;QACT,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;IAClD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const BUDGET_WINDOW = 3600n;
|
|
2
|
+
export declare const ACCOUNT_OVERHEAD_BYTES = 128n;
|
|
3
|
+
export declare const RENT_LAMPORTS_PER_BYTE = 6960n;
|
|
4
|
+
export declare const VAULT_BYTES = 170;
|
|
5
|
+
export declare const SIGNATURE_FEE = 5000n;
|
|
6
|
+
export declare const TOKEN_ACCOUNT_RENT_BYTES = 170;
|
|
7
|
+
export declare const rentFor: (bytes: number) => bigint;
|
|
8
|
+
export declare function createCost(economics: {
|
|
9
|
+
createFee: number;
|
|
10
|
+
crankBounty: number;
|
|
11
|
+
}): bigint;
|
|
12
|
+
export type Spend = {
|
|
13
|
+
at: bigint;
|
|
14
|
+
lamports: bigint;
|
|
15
|
+
};
|
|
16
|
+
export type Budget = {
|
|
17
|
+
hourly: bigint;
|
|
18
|
+
spends: Spend[];
|
|
19
|
+
};
|
|
20
|
+
export declare const budgetOf: (hourly: bigint) => Budget;
|
|
21
|
+
export declare function reserve(budget: Budget, lamports: bigint, now: bigint): Spend;
|
|
22
|
+
export declare function release(budget: Budget, spend: Spend): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getIntentSize } from "@intent-engine/core";
|
|
2
|
+
import { AgentRefusal } from "./problems.js";
|
|
3
|
+
export const BUDGET_WINDOW = 3600n;
|
|
4
|
+
export const ACCOUNT_OVERHEAD_BYTES = 128n;
|
|
5
|
+
export const RENT_LAMPORTS_PER_BYTE = 6960n;
|
|
6
|
+
export const VAULT_BYTES = 170;
|
|
7
|
+
export const SIGNATURE_FEE = 5000n;
|
|
8
|
+
export const TOKEN_ACCOUNT_RENT_BYTES = 170;
|
|
9
|
+
export const rentFor = (bytes) => (BigInt(bytes) + ACCOUNT_OVERHEAD_BYTES) * RENT_LAMPORTS_PER_BYTE;
|
|
10
|
+
export function createCost(economics) {
|
|
11
|
+
return (BigInt(economics.createFee) +
|
|
12
|
+
BigInt(economics.crankBounty) +
|
|
13
|
+
rentFor(getIntentSize()) +
|
|
14
|
+
rentFor(VAULT_BYTES) +
|
|
15
|
+
SIGNATURE_FEE);
|
|
16
|
+
}
|
|
17
|
+
export const budgetOf = (hourly) => ({ hourly, spends: [] });
|
|
18
|
+
export function reserve(budget, lamports, now) {
|
|
19
|
+
budget.spends = budget.spends.filter((s) => s.at > now - BUDGET_WINDOW);
|
|
20
|
+
const used = budget.spends.reduce((sum, s) => sum + s.lamports, 0n);
|
|
21
|
+
if (used + lamports > budget.hourly) {
|
|
22
|
+
throw new AgentRefusal("BudgetExhausted", `this key may spend ${budget.hourly} lamports per hour and has ${budget.hourly - used} left; this needs ${lamports}`, true);
|
|
23
|
+
}
|
|
24
|
+
const spend = { at: now, lamports };
|
|
25
|
+
budget.spends.push(spend);
|
|
26
|
+
return spend;
|
|
27
|
+
}
|
|
28
|
+
export function release(budget, spend) {
|
|
29
|
+
budget.spends = budget.spends.filter((s) => s !== spend);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../../../src/agent/budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAM,CAAC;AACpC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAM,CAAC;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,KAAM,CAAC;AACpC,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,sBAAsB,CAAC,GAAG,sBAAsB,CAAC;AAEpH,MAAM,UAAU,UAAU,CAAC,SAAqD;IAC9E,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;QAC3B,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC;QAC7B,OAAO,CAAC,aAAa,EAAE,CAAC;QACxB,OAAO,CAAC,WAAW,CAAC;QACpB,aAAa,CACd,CAAC;AACJ,CAAC;AAMD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAE7E,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,QAAgB,EAAE,GAAW;IACnE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,aAAa,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACpE,IAAI,IAAI,GAAG,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACpC,MAAM,IAAI,YAAY,CACpB,iBAAiB,EACjB,sBAAsB,MAAM,CAAC,MAAM,8BAA8B,MAAM,CAAC,MAAM,GAAG,IAAI,qBAAqB,QAAQ,EAAE,EACpH,IAAI,CACL,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;IACpC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,KAAY;IAClD,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
export declare const PREPARED_TTL = 120n;
|
|
3
|
+
export declare const MAX_PENDING_PER_OWNER = 16;
|
|
4
|
+
export type Claims = {
|
|
5
|
+
held: Map<Address, Map<bigint, bigint>>;
|
|
6
|
+
busy: Set<string>;
|
|
7
|
+
};
|
|
8
|
+
export type Call = {
|
|
9
|
+
undo: (() => void)[];
|
|
10
|
+
};
|
|
11
|
+
export declare const claimsOf: () => Claims;
|
|
12
|
+
export declare const callOf: () => Call;
|
|
13
|
+
export declare function claimedBy(claims: Claims, owner: Address, now: bigint): Set<bigint>;
|
|
14
|
+
export declare function claim(claims: Claims, call: Call, owner: Address, nonce: bigint, until: bigint, now: bigint): void;
|
|
15
|
+
export declare function enter(claims: Claims, key: string): () => void;
|