@spicenet-io/spiceflow-core 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +45 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/conditionalIntents.d.ts +68 -0
- package/dist/conditionalIntents.d.ts.map +1 -0
- package/dist/index.cjs +182 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +168 -0
- package/package.json +2 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FeePolicy, FeeAssessment } from "./fees.js";
|
|
2
|
-
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { Address, Hash, Hex } from "viem";
|
|
3
3
|
import type { Call, TokenTransferConfig } from "./types.js";
|
|
4
|
+
import type { ConditionalIntentAuthorization, ConditionalSignal, ConditionalCancellation } from "./conditionalIntents.js";
|
|
4
5
|
export type { Call, TokenTransferConfig };
|
|
5
6
|
export interface SignedCall extends Call {
|
|
6
7
|
signature: Hex;
|
|
@@ -91,6 +92,49 @@ export interface EstimateActionFeesResponse {
|
|
|
91
92
|
code?: string;
|
|
92
93
|
};
|
|
93
94
|
}
|
|
95
|
+
export interface RegisterConditionalIntentRequest {
|
|
96
|
+
authorization: ConditionalIntentAuthorization;
|
|
97
|
+
authorizationSignature: Hex;
|
|
98
|
+
triggerSpecification: Hex;
|
|
99
|
+
action: {
|
|
100
|
+
user: Address;
|
|
101
|
+
intents: Intent7702[];
|
|
102
|
+
chainAuthorizations?: ChainAuthorization7702[];
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export interface RegisterConditionalIntentResponse {
|
|
106
|
+
conditionalIntentId: Hash;
|
|
107
|
+
state: "armed" | "eligible" | "executing" | "reconciling" | "completed" | "cancelled" | "expired" | "failed" | "needs_attention";
|
|
108
|
+
readToken?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ConditionalIntentStatus {
|
|
111
|
+
executionStatus?: string;
|
|
112
|
+
executionStopped?: boolean;
|
|
113
|
+
conditionalIntentId: Hash;
|
|
114
|
+
state: RegisterConditionalIntentResponse["state"];
|
|
115
|
+
validAfter: number;
|
|
116
|
+
expiresAt: number;
|
|
117
|
+
acceptedSignal?: {
|
|
118
|
+
signalId: string;
|
|
119
|
+
observedAt: number;
|
|
120
|
+
};
|
|
121
|
+
owner?: Address;
|
|
122
|
+
clientId?: string;
|
|
123
|
+
executionDigest?: Hash;
|
|
124
|
+
triggerSpecificationHash?: Hash;
|
|
125
|
+
/** Returned only to an authenticated owner reader, never execution credentials. */
|
|
126
|
+
triggerSpecification?: Hex;
|
|
127
|
+
evaluator?: Address;
|
|
128
|
+
semantics?: "state" | "event";
|
|
129
|
+
actionId?: string;
|
|
130
|
+
reason?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface SubmitConditionalSignalRequest extends ConditionalSignal {
|
|
133
|
+
signature: Hex;
|
|
134
|
+
}
|
|
135
|
+
export interface CancelConditionalIntentRequest extends ConditionalCancellation {
|
|
136
|
+
signature: Hex;
|
|
137
|
+
}
|
|
94
138
|
export interface StepIdParams {
|
|
95
139
|
actionId: string;
|
|
96
140
|
intentIndex: number;
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CA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
import type { Call, TokenTransferConfig } from "./types.js";
|
|
3
|
+
export declare const CONDITIONAL_INTENT_VERSION: 1;
|
|
4
|
+
export type ConditionalTriggerSemantics = "state" | "event";
|
|
5
|
+
export interface ConditionalExecutionBatch {
|
|
6
|
+
chainId: bigint | number;
|
|
7
|
+
calls: Call[];
|
|
8
|
+
tokenTransfers: TokenTransferConfig[];
|
|
9
|
+
}
|
|
10
|
+
export interface ConditionalDelegationAuthorization {
|
|
11
|
+
address: Address;
|
|
12
|
+
chainId: bigint | number;
|
|
13
|
+
nonce: bigint | number;
|
|
14
|
+
r: Hex;
|
|
15
|
+
s: Hex;
|
|
16
|
+
yParity?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ConditionalIntentAuthorization {
|
|
19
|
+
owner: Address;
|
|
20
|
+
clientId: string;
|
|
21
|
+
serviceId: string;
|
|
22
|
+
authorizationNonce: bigint;
|
|
23
|
+
executionDigest: Hash;
|
|
24
|
+
executionPlanHash: Hash;
|
|
25
|
+
triggerSpecificationHash: Hash;
|
|
26
|
+
evaluator: Address;
|
|
27
|
+
semantics: ConditionalTriggerSemantics;
|
|
28
|
+
maxSignalAgeSeconds: bigint;
|
|
29
|
+
validAfter: bigint;
|
|
30
|
+
expiresAt: bigint;
|
|
31
|
+
maxExecutions: 1;
|
|
32
|
+
}
|
|
33
|
+
export interface ConditionalSignal {
|
|
34
|
+
intentId: Hash;
|
|
35
|
+
executionDigest: Hash;
|
|
36
|
+
triggerSpecificationHash: Hash;
|
|
37
|
+
signalId: string;
|
|
38
|
+
observedAt: bigint;
|
|
39
|
+
validUntil: bigint;
|
|
40
|
+
satisfied: true;
|
|
41
|
+
evidenceHash?: Hash;
|
|
42
|
+
}
|
|
43
|
+
export interface ConditionalCancellation {
|
|
44
|
+
owner: Address;
|
|
45
|
+
serviceId: string;
|
|
46
|
+
intentId: Hash;
|
|
47
|
+
cancellationNonce: bigint;
|
|
48
|
+
expiresAt: bigint;
|
|
49
|
+
}
|
|
50
|
+
export interface ConditionalReadAuthorization {
|
|
51
|
+
owner: Address;
|
|
52
|
+
reader: Address;
|
|
53
|
+
serviceId: string;
|
|
54
|
+
/** zero hash grants owner-scoped list reads; otherwise it scopes one intent. */
|
|
55
|
+
intentId: Hash | null;
|
|
56
|
+
expiresAt: bigint;
|
|
57
|
+
nonce: bigint;
|
|
58
|
+
}
|
|
59
|
+
/** Commits to ordered calls and service-consumed funding metadata, never signatures or display text. */
|
|
60
|
+
export declare function hashConditionalExecutionPlan(batches: ConditionalExecutionBatch[], delegationAuthorizations?: ConditionalDelegationAuthorization[]): Hash;
|
|
61
|
+
/** Hash to pass to the wallet's existing EIP-191 signMessage({ message: { raw } }) path. */
|
|
62
|
+
export declare function hashConditionalIntentAuthorization(value: ConditionalIntentAuthorization): Hash;
|
|
63
|
+
export declare function getConditionalIntentId(authorizationHash: Hash): Hash;
|
|
64
|
+
export declare function hashConditionalSignal(value: ConditionalSignal, serviceId: string): Hash;
|
|
65
|
+
export declare function hashConditionalCancellation(value: ConditionalCancellation): Hash;
|
|
66
|
+
export declare function hashConditionalReadAuthorization(value: ConditionalReadAuthorization): Hash;
|
|
67
|
+
export declare function conditionalHashMessage(hash: Hash): Hex;
|
|
68
|
+
//# sourceMappingURL=conditionalIntents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionalIntents.d.ts","sourceRoot":"","sources":["../src/conditionalIntents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE5D,eAAO,MAAM,0BAA0B,EAAG,CAAU,CAAC;AACrD,MAAM,MAAM,2BAA2B,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,KAAK,EAAE,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IAC3C,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AA8BD,wGAAwG;AACxG,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,yBAAyB,EAAE,EACpC,wBAAwB,GAAE,kCAAkC,EAAO,GAClE,IAAI,CAkCN;AA4BD,4FAA4F;AAC5F,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,8BAA8B,GAAG,IAAI,CAkB9F;AAED,wBAAgB,sBAAsB,CAAC,iBAAiB,EAAE,IAAI,GAAG,IAAI,CAKpE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAiBvF;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,uBAAuB,GAAG,IAAI,CAahF;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,4BAA4B,GAAG,IAAI,CAc1F;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAEtD"}
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var index_exports = {};
|
|
21
21
|
__export(index_exports, {
|
|
22
22
|
CHAINS: () => CHAINS,
|
|
23
|
+
CONDITIONAL_INTENT_VERSION: () => CONDITIONAL_INTENT_VERSION,
|
|
23
24
|
ChainBatchHashAbi: () => ChainBatchHashAbi,
|
|
24
25
|
DELEGATE_ABI: () => DELEGATE_ABI,
|
|
25
26
|
ERC20_ABI: () => ERC20_ABI,
|
|
@@ -40,6 +41,7 @@ __export(index_exports, {
|
|
|
40
41
|
applySlippage: () => applySlippage,
|
|
41
42
|
areEquivalent: () => areEquivalent,
|
|
42
43
|
buildUniV3SwapCalls: () => buildUniV3SwapCalls,
|
|
44
|
+
conditionalHashMessage: () => conditionalHashMessage,
|
|
43
45
|
convertAmountBetweenDecimals: () => convertAmountBetweenDecimals,
|
|
44
46
|
fetchWithRetry: () => fetchWithRetry,
|
|
45
47
|
formatTokenAmount: () => formatTokenAmount,
|
|
@@ -48,6 +50,7 @@ __export(index_exports, {
|
|
|
48
50
|
getChainIdsByNetwork: () => getChainIdsByNetwork,
|
|
49
51
|
getChainMeta: () => getChainMeta,
|
|
50
52
|
getChainsByNetwork: () => getChainsByNetwork,
|
|
53
|
+
getConditionalIntentId: () => getConditionalIntentId,
|
|
51
54
|
getDelegateContract: () => getDelegateContract,
|
|
52
55
|
getDeployment: () => getDeployment,
|
|
53
56
|
getEquivalenceGroup: () => getEquivalenceGroup,
|
|
@@ -65,6 +68,11 @@ __export(index_exports, {
|
|
|
65
68
|
getTokensForChain: () => getTokensForChain,
|
|
66
69
|
getViemChain: () => getViemChain,
|
|
67
70
|
hashChainBatches: () => hashChainBatches,
|
|
71
|
+
hashConditionalCancellation: () => hashConditionalCancellation,
|
|
72
|
+
hashConditionalExecutionPlan: () => hashConditionalExecutionPlan,
|
|
73
|
+
hashConditionalIntentAuthorization: () => hashConditionalIntentAuthorization,
|
|
74
|
+
hashConditionalReadAuthorization: () => hashConditionalReadAuthorization,
|
|
75
|
+
hashConditionalSignal: () => hashConditionalSignal,
|
|
68
76
|
isBtcDenominated: () => isBtcDenominated,
|
|
69
77
|
isNativeToken: () => isNativeToken,
|
|
70
78
|
isSpicenetChainId: () => isSpicenetChainId,
|
|
@@ -139,6 +147,166 @@ async function getRecentBlock(publicClient) {
|
|
|
139
147
|
return await publicClient.getBlockNumber();
|
|
140
148
|
}
|
|
141
149
|
|
|
150
|
+
// src/conditionalIntents.ts
|
|
151
|
+
var import_viem2 = require("viem");
|
|
152
|
+
var CONDITIONAL_INTENT_VERSION = 1;
|
|
153
|
+
var callTuple = [
|
|
154
|
+
{ name: "to", type: "address" },
|
|
155
|
+
{ name: "value", type: "uint256" },
|
|
156
|
+
{ name: "data", type: "bytes" }
|
|
157
|
+
];
|
|
158
|
+
var transferTuple = [
|
|
159
|
+
{ name: "fromKind", type: "uint8" },
|
|
160
|
+
{ name: "fromAddress", type: "address" },
|
|
161
|
+
{ name: "to", type: "address" },
|
|
162
|
+
{ name: "token", type: "address" },
|
|
163
|
+
{ name: "amount", type: "uint256" }
|
|
164
|
+
];
|
|
165
|
+
var batchTuple = [
|
|
166
|
+
{ name: "chainId", type: "uint256" },
|
|
167
|
+
{ name: "calls", type: "tuple[]", components: callTuple },
|
|
168
|
+
{ name: "tokenTransfers", type: "tuple[]", components: transferTuple }
|
|
169
|
+
];
|
|
170
|
+
var zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
171
|
+
function encodePlanTransfer(transfer) {
|
|
172
|
+
if (transfer.from === "solver") return [1, zeroAddress, transfer.to, transfer.token, transfer.amount];
|
|
173
|
+
if (transfer.from === "escrow") return [2, zeroAddress, transfer.to, transfer.token, transfer.amount];
|
|
174
|
+
return [0, transfer.from, transfer.to, transfer.token, transfer.amount];
|
|
175
|
+
}
|
|
176
|
+
function hashConditionalExecutionPlan(batches, delegationAuthorizations = []) {
|
|
177
|
+
const normalized = batches.map((batch) => [
|
|
178
|
+
BigInt(batch.chainId),
|
|
179
|
+
batch.calls,
|
|
180
|
+
batch.tokenTransfers.map(encodePlanTransfer)
|
|
181
|
+
]);
|
|
182
|
+
return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)(
|
|
183
|
+
[
|
|
184
|
+
{ type: "bytes32" },
|
|
185
|
+
{ type: "uint256" },
|
|
186
|
+
{ type: "tuple[]", components: batchTuple },
|
|
187
|
+
{ type: "tuple[]", components: [
|
|
188
|
+
{ name: "address", type: "address" },
|
|
189
|
+
{ name: "chainId", type: "uint256" },
|
|
190
|
+
{ name: "nonce", type: "uint256" },
|
|
191
|
+
{ name: "r", type: "bytes32" },
|
|
192
|
+
{ name: "s", type: "bytes32" },
|
|
193
|
+
{ name: "yParity", type: "uint8" }
|
|
194
|
+
] }
|
|
195
|
+
],
|
|
196
|
+
[
|
|
197
|
+
(0, import_viem2.keccak256)((0, import_viem2.stringToHex)("spice.conditional.execution-plan")),
|
|
198
|
+
BigInt(CONDITIONAL_INTENT_VERSION),
|
|
199
|
+
normalized,
|
|
200
|
+
delegationAuthorizations.map((auth) => [
|
|
201
|
+
auth.address,
|
|
202
|
+
BigInt(auth.chainId),
|
|
203
|
+
BigInt(auth.nonce),
|
|
204
|
+
auth.r,
|
|
205
|
+
auth.s,
|
|
206
|
+
auth.yParity ?? 0
|
|
207
|
+
])
|
|
208
|
+
]
|
|
209
|
+
));
|
|
210
|
+
}
|
|
211
|
+
var authorizationTypes = [
|
|
212
|
+
{ name: "domain", type: "bytes32" },
|
|
213
|
+
{ name: "version", type: "uint256" },
|
|
214
|
+
{ name: "owner", type: "address" },
|
|
215
|
+
{ name: "clientIdHash", type: "bytes32" },
|
|
216
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
217
|
+
{ name: "authorizationNonce", type: "uint256" },
|
|
218
|
+
{ name: "executionDigest", type: "bytes32" },
|
|
219
|
+
{ name: "executionPlanHash", type: "bytes32" },
|
|
220
|
+
{ name: "triggerSpecificationHash", type: "bytes32" },
|
|
221
|
+
{ name: "evaluator", type: "address" },
|
|
222
|
+
{ name: "semantics", type: "uint8" },
|
|
223
|
+
{ name: "maxSignalAgeSeconds", type: "uint256" },
|
|
224
|
+
{ name: "validAfter", type: "uint256" },
|
|
225
|
+
{ name: "expiresAt", type: "uint256" },
|
|
226
|
+
{ name: "maxExecutions", type: "uint256" }
|
|
227
|
+
];
|
|
228
|
+
function hashText(value) {
|
|
229
|
+
return (0, import_viem2.keccak256)((0, import_viem2.stringToHex)(value));
|
|
230
|
+
}
|
|
231
|
+
function semanticsValue(value) {
|
|
232
|
+
return value === "state" ? 0 : 1;
|
|
233
|
+
}
|
|
234
|
+
function hashConditionalIntentAuthorization(value) {
|
|
235
|
+
return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)(authorizationTypes, [
|
|
236
|
+
hashText("spice.conditional.authorization"),
|
|
237
|
+
BigInt(CONDITIONAL_INTENT_VERSION),
|
|
238
|
+
value.owner,
|
|
239
|
+
hashText(value.clientId),
|
|
240
|
+
hashText(value.serviceId),
|
|
241
|
+
value.authorizationNonce,
|
|
242
|
+
value.executionDigest,
|
|
243
|
+
value.executionPlanHash,
|
|
244
|
+
value.triggerSpecificationHash,
|
|
245
|
+
value.evaluator,
|
|
246
|
+
semanticsValue(value.semantics),
|
|
247
|
+
value.maxSignalAgeSeconds,
|
|
248
|
+
value.validAfter,
|
|
249
|
+
value.expiresAt,
|
|
250
|
+
BigInt(value.maxExecutions)
|
|
251
|
+
]));
|
|
252
|
+
}
|
|
253
|
+
function getConditionalIntentId(authorizationHash) {
|
|
254
|
+
return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)(
|
|
255
|
+
[{ type: "bytes32" }, { type: "bytes32" }],
|
|
256
|
+
[hashText("spice.conditional.intent-id"), authorizationHash]
|
|
257
|
+
));
|
|
258
|
+
}
|
|
259
|
+
function hashConditionalSignal(value, serviceId) {
|
|
260
|
+
return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)(
|
|
261
|
+
[
|
|
262
|
+
{ name: "domain", type: "bytes32" },
|
|
263
|
+
{ name: "version", type: "uint256" },
|
|
264
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
265
|
+
{ name: "intentId", type: "bytes32" },
|
|
266
|
+
{ name: "executionDigest", type: "bytes32" },
|
|
267
|
+
{ name: "triggerSpecificationHash", type: "bytes32" },
|
|
268
|
+
{ name: "signalIdHash", type: "bytes32" },
|
|
269
|
+
{ name: "observedAt", type: "uint256" },
|
|
270
|
+
{ name: "validUntil", type: "uint256" },
|
|
271
|
+
{ name: "satisfied", type: "bool" },
|
|
272
|
+
{ name: "evidenceHash", type: "bytes32" }
|
|
273
|
+
],
|
|
274
|
+
[hashText("spice.conditional.signal"), BigInt(CONDITIONAL_INTENT_VERSION), hashText(serviceId), value.intentId, value.executionDigest, value.triggerSpecificationHash, hashText(value.signalId), value.observedAt, value.validUntil, value.satisfied, value.evidenceHash ?? "0x" + "00".repeat(32)]
|
|
275
|
+
));
|
|
276
|
+
}
|
|
277
|
+
function hashConditionalCancellation(value) {
|
|
278
|
+
return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)(
|
|
279
|
+
[
|
|
280
|
+
{ name: "domain", type: "bytes32" },
|
|
281
|
+
{ name: "version", type: "uint256" },
|
|
282
|
+
{ name: "owner", type: "address" },
|
|
283
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
284
|
+
{ name: "intentId", type: "bytes32" },
|
|
285
|
+
{ name: "cancellationNonce", type: "uint256" },
|
|
286
|
+
{ name: "expiresAt", type: "uint256" }
|
|
287
|
+
],
|
|
288
|
+
[hashText("spice.conditional.cancel"), BigInt(CONDITIONAL_INTENT_VERSION), value.owner, hashText(value.serviceId), value.intentId, value.cancellationNonce, value.expiresAt]
|
|
289
|
+
));
|
|
290
|
+
}
|
|
291
|
+
function hashConditionalReadAuthorization(value) {
|
|
292
|
+
return (0, import_viem2.keccak256)((0, import_viem2.encodeAbiParameters)(
|
|
293
|
+
[
|
|
294
|
+
{ name: "domain", type: "bytes32" },
|
|
295
|
+
{ name: "version", type: "uint256" },
|
|
296
|
+
{ name: "owner", type: "address" },
|
|
297
|
+
{ name: "reader", type: "address" },
|
|
298
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
299
|
+
{ name: "intentId", type: "bytes32" },
|
|
300
|
+
{ name: "expiresAt", type: "uint256" },
|
|
301
|
+
{ name: "nonce", type: "uint256" }
|
|
302
|
+
],
|
|
303
|
+
[hashText("spice.conditional.read"), BigInt(CONDITIONAL_INTENT_VERSION), value.owner, value.reader, hashText(value.serviceId), value.intentId ?? "0x" + "00".repeat(32), value.expiresAt, value.nonce]
|
|
304
|
+
));
|
|
305
|
+
}
|
|
306
|
+
function conditionalHashMessage(hash) {
|
|
307
|
+
return hash;
|
|
308
|
+
}
|
|
309
|
+
|
|
142
310
|
// src/http.ts
|
|
143
311
|
var HttpError = class extends Error {
|
|
144
312
|
constructor(message, status, code, body) {
|
|
@@ -1145,7 +1313,7 @@ var CHAINS = {
|
|
|
1145
1313
|
};
|
|
1146
1314
|
|
|
1147
1315
|
// src/chains/index.ts
|
|
1148
|
-
var
|
|
1316
|
+
var import_viem3 = require("viem");
|
|
1149
1317
|
function getChainMeta(chainId) {
|
|
1150
1318
|
return CHAINS[chainId];
|
|
1151
1319
|
}
|
|
@@ -1174,7 +1342,7 @@ function getEscrowContract(chainId) {
|
|
|
1174
1342
|
}
|
|
1175
1343
|
function toViemChain(meta) {
|
|
1176
1344
|
if (meta.chainType === "starknet") return void 0;
|
|
1177
|
-
return (0,
|
|
1345
|
+
return (0, import_viem3.defineChain)({
|
|
1178
1346
|
id: meta.id,
|
|
1179
1347
|
name: meta.name,
|
|
1180
1348
|
nativeCurrency: meta.nativeCurrency,
|
|
@@ -2929,7 +3097,7 @@ var spicenetEscrowAbi = [
|
|
|
2929
3097
|
];
|
|
2930
3098
|
|
|
2931
3099
|
// src/swap.ts
|
|
2932
|
-
var
|
|
3100
|
+
var import_viem4 = require("viem");
|
|
2933
3101
|
function applySlippage(amount, slippage = 0.03) {
|
|
2934
3102
|
const slippageBps = BigInt(Math.floor((1 - slippage) * 1e4));
|
|
2935
3103
|
return amount * slippageBps / 10000n;
|
|
@@ -2948,8 +3116,8 @@ function buildUniV3SwapCalls(params) {
|
|
|
2948
3116
|
{
|
|
2949
3117
|
to: tokenIn,
|
|
2950
3118
|
value: 0n,
|
|
2951
|
-
data: (0,
|
|
2952
|
-
abi:
|
|
3119
|
+
data: (0, import_viem4.encodeFunctionData)({
|
|
3120
|
+
abi: import_viem4.erc20Abi,
|
|
2953
3121
|
functionName: "approve",
|
|
2954
3122
|
args: [config.swapRouter, amountIn]
|
|
2955
3123
|
})
|
|
@@ -2957,7 +3125,7 @@ function buildUniV3SwapCalls(params) {
|
|
|
2957
3125
|
{
|
|
2958
3126
|
to: config.swapRouter,
|
|
2959
3127
|
value: 0n,
|
|
2960
|
-
data: (0,
|
|
3128
|
+
data: (0, import_viem4.encodeFunctionData)({
|
|
2961
3129
|
abi: uniV3SwapRouterAbi,
|
|
2962
3130
|
functionName: "exactInputSingle",
|
|
2963
3131
|
args: [
|
|
@@ -2984,6 +3152,7 @@ var SPICE_COMBINED_FEE_RECIPIENT = SPICE_GAS_FEE_RECIPIENT;
|
|
|
2984
3152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2985
3153
|
0 && (module.exports = {
|
|
2986
3154
|
CHAINS,
|
|
3155
|
+
CONDITIONAL_INTENT_VERSION,
|
|
2987
3156
|
ChainBatchHashAbi,
|
|
2988
3157
|
DELEGATE_ABI,
|
|
2989
3158
|
ERC20_ABI,
|
|
@@ -3004,6 +3173,7 @@ var SPICE_COMBINED_FEE_RECIPIENT = SPICE_GAS_FEE_RECIPIENT;
|
|
|
3004
3173
|
applySlippage,
|
|
3005
3174
|
areEquivalent,
|
|
3006
3175
|
buildUniV3SwapCalls,
|
|
3176
|
+
conditionalHashMessage,
|
|
3007
3177
|
convertAmountBetweenDecimals,
|
|
3008
3178
|
fetchWithRetry,
|
|
3009
3179
|
formatTokenAmount,
|
|
@@ -3012,6 +3182,7 @@ var SPICE_COMBINED_FEE_RECIPIENT = SPICE_GAS_FEE_RECIPIENT;
|
|
|
3012
3182
|
getChainIdsByNetwork,
|
|
3013
3183
|
getChainMeta,
|
|
3014
3184
|
getChainsByNetwork,
|
|
3185
|
+
getConditionalIntentId,
|
|
3015
3186
|
getDelegateContract,
|
|
3016
3187
|
getDeployment,
|
|
3017
3188
|
getEquivalenceGroup,
|
|
@@ -3029,6 +3200,11 @@ var SPICE_COMBINED_FEE_RECIPIENT = SPICE_GAS_FEE_RECIPIENT;
|
|
|
3029
3200
|
getTokensForChain,
|
|
3030
3201
|
getViemChain,
|
|
3031
3202
|
hashChainBatches,
|
|
3203
|
+
hashConditionalCancellation,
|
|
3204
|
+
hashConditionalExecutionPlan,
|
|
3205
|
+
hashConditionalIntentAuthorization,
|
|
3206
|
+
hashConditionalReadAuthorization,
|
|
3207
|
+
hashConditionalSignal,
|
|
3032
3208
|
isBtcDenominated,
|
|
3033
3209
|
isNativeToken,
|
|
3034
3210
|
isSpicenetChainId,
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,166 @@ async function getRecentBlock(publicClient) {
|
|
|
51
51
|
return await publicClient.getBlockNumber();
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
// src/conditionalIntents.ts
|
|
55
|
+
import { encodeAbiParameters as encodeAbiParameters2, keccak256 as keccak2562, stringToHex } from "viem";
|
|
56
|
+
var CONDITIONAL_INTENT_VERSION = 1;
|
|
57
|
+
var callTuple = [
|
|
58
|
+
{ name: "to", type: "address" },
|
|
59
|
+
{ name: "value", type: "uint256" },
|
|
60
|
+
{ name: "data", type: "bytes" }
|
|
61
|
+
];
|
|
62
|
+
var transferTuple = [
|
|
63
|
+
{ name: "fromKind", type: "uint8" },
|
|
64
|
+
{ name: "fromAddress", type: "address" },
|
|
65
|
+
{ name: "to", type: "address" },
|
|
66
|
+
{ name: "token", type: "address" },
|
|
67
|
+
{ name: "amount", type: "uint256" }
|
|
68
|
+
];
|
|
69
|
+
var batchTuple = [
|
|
70
|
+
{ name: "chainId", type: "uint256" },
|
|
71
|
+
{ name: "calls", type: "tuple[]", components: callTuple },
|
|
72
|
+
{ name: "tokenTransfers", type: "tuple[]", components: transferTuple }
|
|
73
|
+
];
|
|
74
|
+
var zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
75
|
+
function encodePlanTransfer(transfer) {
|
|
76
|
+
if (transfer.from === "solver") return [1, zeroAddress, transfer.to, transfer.token, transfer.amount];
|
|
77
|
+
if (transfer.from === "escrow") return [2, zeroAddress, transfer.to, transfer.token, transfer.amount];
|
|
78
|
+
return [0, transfer.from, transfer.to, transfer.token, transfer.amount];
|
|
79
|
+
}
|
|
80
|
+
function hashConditionalExecutionPlan(batches, delegationAuthorizations = []) {
|
|
81
|
+
const normalized = batches.map((batch) => [
|
|
82
|
+
BigInt(batch.chainId),
|
|
83
|
+
batch.calls,
|
|
84
|
+
batch.tokenTransfers.map(encodePlanTransfer)
|
|
85
|
+
]);
|
|
86
|
+
return keccak2562(encodeAbiParameters2(
|
|
87
|
+
[
|
|
88
|
+
{ type: "bytes32" },
|
|
89
|
+
{ type: "uint256" },
|
|
90
|
+
{ type: "tuple[]", components: batchTuple },
|
|
91
|
+
{ type: "tuple[]", components: [
|
|
92
|
+
{ name: "address", type: "address" },
|
|
93
|
+
{ name: "chainId", type: "uint256" },
|
|
94
|
+
{ name: "nonce", type: "uint256" },
|
|
95
|
+
{ name: "r", type: "bytes32" },
|
|
96
|
+
{ name: "s", type: "bytes32" },
|
|
97
|
+
{ name: "yParity", type: "uint8" }
|
|
98
|
+
] }
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
keccak2562(stringToHex("spice.conditional.execution-plan")),
|
|
102
|
+
BigInt(CONDITIONAL_INTENT_VERSION),
|
|
103
|
+
normalized,
|
|
104
|
+
delegationAuthorizations.map((auth) => [
|
|
105
|
+
auth.address,
|
|
106
|
+
BigInt(auth.chainId),
|
|
107
|
+
BigInt(auth.nonce),
|
|
108
|
+
auth.r,
|
|
109
|
+
auth.s,
|
|
110
|
+
auth.yParity ?? 0
|
|
111
|
+
])
|
|
112
|
+
]
|
|
113
|
+
));
|
|
114
|
+
}
|
|
115
|
+
var authorizationTypes = [
|
|
116
|
+
{ name: "domain", type: "bytes32" },
|
|
117
|
+
{ name: "version", type: "uint256" },
|
|
118
|
+
{ name: "owner", type: "address" },
|
|
119
|
+
{ name: "clientIdHash", type: "bytes32" },
|
|
120
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
121
|
+
{ name: "authorizationNonce", type: "uint256" },
|
|
122
|
+
{ name: "executionDigest", type: "bytes32" },
|
|
123
|
+
{ name: "executionPlanHash", type: "bytes32" },
|
|
124
|
+
{ name: "triggerSpecificationHash", type: "bytes32" },
|
|
125
|
+
{ name: "evaluator", type: "address" },
|
|
126
|
+
{ name: "semantics", type: "uint8" },
|
|
127
|
+
{ name: "maxSignalAgeSeconds", type: "uint256" },
|
|
128
|
+
{ name: "validAfter", type: "uint256" },
|
|
129
|
+
{ name: "expiresAt", type: "uint256" },
|
|
130
|
+
{ name: "maxExecutions", type: "uint256" }
|
|
131
|
+
];
|
|
132
|
+
function hashText(value) {
|
|
133
|
+
return keccak2562(stringToHex(value));
|
|
134
|
+
}
|
|
135
|
+
function semanticsValue(value) {
|
|
136
|
+
return value === "state" ? 0 : 1;
|
|
137
|
+
}
|
|
138
|
+
function hashConditionalIntentAuthorization(value) {
|
|
139
|
+
return keccak2562(encodeAbiParameters2(authorizationTypes, [
|
|
140
|
+
hashText("spice.conditional.authorization"),
|
|
141
|
+
BigInt(CONDITIONAL_INTENT_VERSION),
|
|
142
|
+
value.owner,
|
|
143
|
+
hashText(value.clientId),
|
|
144
|
+
hashText(value.serviceId),
|
|
145
|
+
value.authorizationNonce,
|
|
146
|
+
value.executionDigest,
|
|
147
|
+
value.executionPlanHash,
|
|
148
|
+
value.triggerSpecificationHash,
|
|
149
|
+
value.evaluator,
|
|
150
|
+
semanticsValue(value.semantics),
|
|
151
|
+
value.maxSignalAgeSeconds,
|
|
152
|
+
value.validAfter,
|
|
153
|
+
value.expiresAt,
|
|
154
|
+
BigInt(value.maxExecutions)
|
|
155
|
+
]));
|
|
156
|
+
}
|
|
157
|
+
function getConditionalIntentId(authorizationHash) {
|
|
158
|
+
return keccak2562(encodeAbiParameters2(
|
|
159
|
+
[{ type: "bytes32" }, { type: "bytes32" }],
|
|
160
|
+
[hashText("spice.conditional.intent-id"), authorizationHash]
|
|
161
|
+
));
|
|
162
|
+
}
|
|
163
|
+
function hashConditionalSignal(value, serviceId) {
|
|
164
|
+
return keccak2562(encodeAbiParameters2(
|
|
165
|
+
[
|
|
166
|
+
{ name: "domain", type: "bytes32" },
|
|
167
|
+
{ name: "version", type: "uint256" },
|
|
168
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
169
|
+
{ name: "intentId", type: "bytes32" },
|
|
170
|
+
{ name: "executionDigest", type: "bytes32" },
|
|
171
|
+
{ name: "triggerSpecificationHash", type: "bytes32" },
|
|
172
|
+
{ name: "signalIdHash", type: "bytes32" },
|
|
173
|
+
{ name: "observedAt", type: "uint256" },
|
|
174
|
+
{ name: "validUntil", type: "uint256" },
|
|
175
|
+
{ name: "satisfied", type: "bool" },
|
|
176
|
+
{ name: "evidenceHash", type: "bytes32" }
|
|
177
|
+
],
|
|
178
|
+
[hashText("spice.conditional.signal"), BigInt(CONDITIONAL_INTENT_VERSION), hashText(serviceId), value.intentId, value.executionDigest, value.triggerSpecificationHash, hashText(value.signalId), value.observedAt, value.validUntil, value.satisfied, value.evidenceHash ?? "0x" + "00".repeat(32)]
|
|
179
|
+
));
|
|
180
|
+
}
|
|
181
|
+
function hashConditionalCancellation(value) {
|
|
182
|
+
return keccak2562(encodeAbiParameters2(
|
|
183
|
+
[
|
|
184
|
+
{ name: "domain", type: "bytes32" },
|
|
185
|
+
{ name: "version", type: "uint256" },
|
|
186
|
+
{ name: "owner", type: "address" },
|
|
187
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
188
|
+
{ name: "intentId", type: "bytes32" },
|
|
189
|
+
{ name: "cancellationNonce", type: "uint256" },
|
|
190
|
+
{ name: "expiresAt", type: "uint256" }
|
|
191
|
+
],
|
|
192
|
+
[hashText("spice.conditional.cancel"), BigInt(CONDITIONAL_INTENT_VERSION), value.owner, hashText(value.serviceId), value.intentId, value.cancellationNonce, value.expiresAt]
|
|
193
|
+
));
|
|
194
|
+
}
|
|
195
|
+
function hashConditionalReadAuthorization(value) {
|
|
196
|
+
return keccak2562(encodeAbiParameters2(
|
|
197
|
+
[
|
|
198
|
+
{ name: "domain", type: "bytes32" },
|
|
199
|
+
{ name: "version", type: "uint256" },
|
|
200
|
+
{ name: "owner", type: "address" },
|
|
201
|
+
{ name: "reader", type: "address" },
|
|
202
|
+
{ name: "serviceIdHash", type: "bytes32" },
|
|
203
|
+
{ name: "intentId", type: "bytes32" },
|
|
204
|
+
{ name: "expiresAt", type: "uint256" },
|
|
205
|
+
{ name: "nonce", type: "uint256" }
|
|
206
|
+
],
|
|
207
|
+
[hashText("spice.conditional.read"), BigInt(CONDITIONAL_INTENT_VERSION), value.owner, value.reader, hashText(value.serviceId), value.intentId ?? "0x" + "00".repeat(32), value.expiresAt, value.nonce]
|
|
208
|
+
));
|
|
209
|
+
}
|
|
210
|
+
function conditionalHashMessage(hash) {
|
|
211
|
+
return hash;
|
|
212
|
+
}
|
|
213
|
+
|
|
54
214
|
// src/http.ts
|
|
55
215
|
var HttpError = class extends Error {
|
|
56
216
|
constructor(message, status, code, body) {
|
|
@@ -2895,6 +3055,7 @@ var SPICE_PLATFORM_FEE_RECIPIENT = "0xa4bB4c1D188B94c0cF691Dad213dE24169fA0A50";
|
|
|
2895
3055
|
var SPICE_COMBINED_FEE_RECIPIENT = SPICE_GAS_FEE_RECIPIENT;
|
|
2896
3056
|
export {
|
|
2897
3057
|
CHAINS,
|
|
3058
|
+
CONDITIONAL_INTENT_VERSION,
|
|
2898
3059
|
ChainBatchHashAbi,
|
|
2899
3060
|
DELEGATE_ABI,
|
|
2900
3061
|
ERC20_ABI,
|
|
@@ -2915,6 +3076,7 @@ export {
|
|
|
2915
3076
|
applySlippage,
|
|
2916
3077
|
areEquivalent,
|
|
2917
3078
|
buildUniV3SwapCalls,
|
|
3079
|
+
conditionalHashMessage,
|
|
2918
3080
|
convertAmountBetweenDecimals,
|
|
2919
3081
|
fetchWithRetry,
|
|
2920
3082
|
formatTokenAmount,
|
|
@@ -2923,6 +3085,7 @@ export {
|
|
|
2923
3085
|
getChainIdsByNetwork,
|
|
2924
3086
|
getChainMeta,
|
|
2925
3087
|
getChainsByNetwork,
|
|
3088
|
+
getConditionalIntentId,
|
|
2926
3089
|
getDelegateContract,
|
|
2927
3090
|
getDeployment,
|
|
2928
3091
|
getEquivalenceGroup,
|
|
@@ -2940,6 +3103,11 @@ export {
|
|
|
2940
3103
|
getTokensForChain,
|
|
2941
3104
|
getViemChain,
|
|
2942
3105
|
hashChainBatches,
|
|
3106
|
+
hashConditionalCancellation,
|
|
3107
|
+
hashConditionalExecutionPlan,
|
|
3108
|
+
hashConditionalIntentAuthorization,
|
|
3109
|
+
hashConditionalReadAuthorization,
|
|
3110
|
+
hashConditionalSignal,
|
|
2943
3111
|
isBtcDenominated,
|
|
2944
3112
|
isNativeToken,
|
|
2945
3113
|
isSpicenetChainId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spicenet-io/spiceflow-core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"validate:tokens": "tsx scripts/validate-tokens.ts",
|
|
13
13
|
"generate:logos": "tsx scripts/generate-logos.ts && prettier --write src/logos.ts --log-level silent",
|
|
14
14
|
"build": "bun run generate:logos && bun run validate:tokens && rimraf dist && tsup src/index.ts --format esm,cjs --out-dir dist --clean && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
15
|
+
"test:conditional-intents": "bun test test/conditionalIntents.test.ts",
|
|
15
16
|
"setup:hooks": "cp scripts/hooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push",
|
|
16
17
|
"format": "prettier --write . --ignore-unknown",
|
|
17
18
|
"docs:build": "typedoc --options typedoc.json",
|