@rebelfi/agent-sdk 1.0.1 → 1.0.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/cjs/client.js +3 -3
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/commands/account.js +12 -16
- package/dist/cjs/commands/account.js.map +1 -1
- package/dist/cjs/commands/auth.js +3 -3
- package/dist/cjs/commands/flows.js +159 -0
- package/dist/cjs/commands/flows.js.map +1 -0
- package/dist/cjs/commands/orders.js +1 -0
- package/dist/cjs/commands/orders.js.map +1 -1
- package/dist/cjs/config.js +7 -7
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/errors.js +5 -5
- package/dist/cjs/flows/conditions.js +23 -0
- package/dist/cjs/flows/conditions.js.map +1 -0
- package/dist/cjs/flows/executor.js +220 -0
- package/dist/cjs/flows/executor.js.map +1 -0
- package/dist/cjs/flows/helpers.js +51 -0
- package/dist/cjs/flows/helpers.js.map +1 -0
- package/dist/cjs/flows/index.js +41 -0
- package/dist/cjs/flows/index.js.map +1 -0
- package/dist/cjs/flows/resolve.js +39 -0
- package/dist/cjs/flows/resolve.js.map +1 -0
- package/dist/cjs/flows/store.js +53 -0
- package/dist/cjs/flows/store.js.map +1 -0
- package/dist/cjs/flows/templates.js +54 -0
- package/dist/cjs/flows/templates.js.map +1 -0
- package/dist/cjs/flows/types.js +3 -0
- package/dist/cjs/flows/types.js.map +1 -0
- package/dist/cjs/index.js +30 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/intent/program-registry.js +2 -2
- package/dist/cjs/orders/sugar.js +3 -2
- package/dist/cjs/orders/sugar.js.map +1 -1
- package/dist/cjs/verify/decoders/rebelsig.js +162 -0
- package/dist/cjs/verify/decoders/rebelsig.js.map +1 -0
- package/dist/cjs/verify/flags.js +1 -1
- package/dist/cjs/verify/index.js +6 -6
- package/dist/cjs/verify/registry.js +1 -1
- package/dist/cli.js +38 -6
- package/dist/cli.js.map +1 -1
- package/dist/client.js +3 -3
- package/dist/client.js.map +1 -1
- package/dist/commands/account.js +13 -17
- package/dist/commands/account.js.map +1 -1
- package/dist/commands/auth.js +3 -3
- package/dist/commands/flows.d.ts +19 -0
- package/dist/commands/flows.js +149 -0
- package/dist/commands/flows.js.map +1 -0
- package/dist/commands/orders.js +1 -0
- package/dist/commands/orders.js.map +1 -1
- package/dist/config.d.ts +12 -12
- package/dist/config.js +7 -7
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +3 -3
- package/dist/flows/conditions.d.ts +13 -0
- package/dist/flows/conditions.js +16 -0
- package/dist/flows/conditions.js.map +1 -0
- package/dist/flows/executor.d.ts +51 -0
- package/dist/flows/executor.js +217 -0
- package/dist/flows/executor.js.map +1 -0
- package/dist/flows/helpers.d.ts +15 -0
- package/dist/flows/helpers.js +40 -0
- package/dist/flows/helpers.js.map +1 -0
- package/dist/flows/index.d.ts +10 -0
- package/dist/flows/index.js +12 -0
- package/dist/flows/index.js.map +1 -0
- package/dist/flows/resolve.d.ts +5 -0
- package/dist/flows/resolve.js +33 -0
- package/dist/flows/resolve.js.map +1 -0
- package/dist/flows/store.d.ts +10 -0
- package/dist/flows/store.js +42 -0
- package/dist/flows/store.js.map +1 -0
- package/dist/flows/templates.d.ts +14 -0
- package/dist/flows/templates.js +51 -0
- package/dist/flows/templates.js.map +1 -0
- package/dist/flows/types.d.ts +82 -0
- package/dist/flows/types.js +2 -0
- package/dist/flows/types.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/intent/program-registry.js +2 -2
- package/dist/orders/sugar.js +3 -2
- package/dist/orders/sugar.js.map +1 -1
- package/dist/verify/decoders/rebelsig.d.ts +5 -0
- package/dist/verify/decoders/rebelsig.js +159 -0
- package/dist/verify/decoders/rebelsig.js.map +1 -0
- package/dist/verify/flags.js +1 -1
- package/dist/verify/index.js +6 -6
- package/dist/verify/registry.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeHeartbeat = executeHeartbeat;
|
|
4
|
+
const store_js_1 = require("./store.js");
|
|
5
|
+
const helpers_js_1 = require("./helpers.js");
|
|
6
|
+
const resolve_js_1 = require("./resolve.js");
|
|
7
|
+
// --- Core function ---
|
|
8
|
+
async function executeHeartbeat(opts = {}) {
|
|
9
|
+
const store = (0, store_js_1.loadFlows)();
|
|
10
|
+
const results = [];
|
|
11
|
+
const now = opts.now ? opts.now() : Date.now();
|
|
12
|
+
let modified = false;
|
|
13
|
+
const activeFlows = store.flows.filter(helpers_js_1.isFlowActive);
|
|
14
|
+
if (activeFlows.length === 0)
|
|
15
|
+
return results;
|
|
16
|
+
const payloads = [];
|
|
17
|
+
const flowMap = new Map();
|
|
18
|
+
for (const flow of activeFlows) {
|
|
19
|
+
if ((0, helpers_js_1.isFlowExpired)(flow, now)) {
|
|
20
|
+
flow.status = 'failed';
|
|
21
|
+
const event = (0, helpers_js_1.makeFlowEvent)('expired', { detail: `Expired at ${flow.policy.expiresAt}` });
|
|
22
|
+
flow.history.push(event);
|
|
23
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
24
|
+
results.push({ flowId: flow.id, status: 'failed', event });
|
|
25
|
+
modified = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
// Check cooldown
|
|
29
|
+
if ((0, helpers_js_1.isInCooldown)(flow, now))
|
|
30
|
+
continue;
|
|
31
|
+
// Check max attempts
|
|
32
|
+
if (flow.policy.maxAttempts !== undefined && (0, helpers_js_1.getAttemptCount)(flow) >= flow.policy.maxAttempts) {
|
|
33
|
+
flow.status = 'failed';
|
|
34
|
+
const event = (0, helpers_js_1.makeFlowEvent)('failed', { detail: `Reached ${flow.policy.maxAttempts} attempts` });
|
|
35
|
+
flow.history.push(event);
|
|
36
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
37
|
+
results.push({ flowId: flow.id, status: 'failed', event });
|
|
38
|
+
modified = true;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
// Get current step
|
|
42
|
+
const currentStep = (0, helpers_js_1.getCurrentStep)(flow);
|
|
43
|
+
if (!currentStep)
|
|
44
|
+
continue;
|
|
45
|
+
// Build payload
|
|
46
|
+
const intentToSend = getIntentForHeartbeat(flow);
|
|
47
|
+
payloads.push({
|
|
48
|
+
flowId: flow.id,
|
|
49
|
+
version: flow.version,
|
|
50
|
+
status: flow.status,
|
|
51
|
+
type: flow.type,
|
|
52
|
+
chain: flow.chain,
|
|
53
|
+
wallet: flow.wallet,
|
|
54
|
+
currentStepId: currentStep.id,
|
|
55
|
+
steps: flow.steps,
|
|
56
|
+
state: flow.state,
|
|
57
|
+
intent: intentToSend,
|
|
58
|
+
policy: flow.policy,
|
|
59
|
+
});
|
|
60
|
+
flowMap.set(flow.id, flow);
|
|
61
|
+
}
|
|
62
|
+
if (payloads.length === 0) {
|
|
63
|
+
if (modified)
|
|
64
|
+
(0, store_js_1.saveFlows)(store);
|
|
65
|
+
return results;
|
|
66
|
+
}
|
|
67
|
+
// Dry run stops here
|
|
68
|
+
if (opts.dryRun) {
|
|
69
|
+
for (const payload of payloads) {
|
|
70
|
+
results.push({
|
|
71
|
+
flowId: payload.flowId,
|
|
72
|
+
status: 'waiting',
|
|
73
|
+
event: (0, helpers_js_1.makeFlowEvent)('heartbeat', { detail: 'Dry run — would send to server' }),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (modified)
|
|
77
|
+
(0, store_js_1.saveFlows)(store);
|
|
78
|
+
return results;
|
|
79
|
+
}
|
|
80
|
+
// No heartbeat callback — nothing more to do
|
|
81
|
+
if (!opts.heartbeatCall) {
|
|
82
|
+
if (modified)
|
|
83
|
+
(0, store_js_1.saveFlows)(store);
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
// Call heartbeat endpoint
|
|
87
|
+
let response;
|
|
88
|
+
try {
|
|
89
|
+
response = await opts.heartbeatCall(payloads);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
93
|
+
for (const payload of payloads) {
|
|
94
|
+
const flow = flowMap.get(payload.flowId);
|
|
95
|
+
const event = (0, helpers_js_1.makeFlowEvent)('heartbeat', { detail: `Server error: ${message}` });
|
|
96
|
+
flow.history.push(event);
|
|
97
|
+
results.push({ flowId: flow.id, status: flow.status, event });
|
|
98
|
+
}
|
|
99
|
+
modified = true;
|
|
100
|
+
(0, store_js_1.saveFlows)(store);
|
|
101
|
+
return results;
|
|
102
|
+
}
|
|
103
|
+
// Process results
|
|
104
|
+
for (const flowResult of response.results) {
|
|
105
|
+
const flow = flowMap.get(flowResult.flowId);
|
|
106
|
+
if (!flow)
|
|
107
|
+
continue;
|
|
108
|
+
const payload = payloads.find(p => p.flowId === flowResult.flowId);
|
|
109
|
+
const result = await handleFlowResult(flow, flowResult, opts, payload?.intent ?? null);
|
|
110
|
+
if (result) {
|
|
111
|
+
results.push(result);
|
|
112
|
+
modified = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (modified)
|
|
116
|
+
(0, store_js_1.saveFlows)(store);
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
// --- Result handler ---
|
|
120
|
+
async function handleFlowResult(flow, result, opts, resolvedIntent) {
|
|
121
|
+
if (!result.actionable) {
|
|
122
|
+
const event = (0, helpers_js_1.makeFlowEvent)('condition_checked', {
|
|
123
|
+
detail: result.condition
|
|
124
|
+
? `Price: ${result.condition.currentPrice}, target: ${result.condition.targetPrice}, distance: ${result.condition.distance != null ? (result.condition.distance * 100).toFixed(1) + '%' : 'unknown'}`
|
|
125
|
+
: 'Not actionable',
|
|
126
|
+
data: result.condition,
|
|
127
|
+
});
|
|
128
|
+
flow.history.push(event);
|
|
129
|
+
return { flowId: flow.id, status: flow.status, event };
|
|
130
|
+
}
|
|
131
|
+
// Condition met but no transaction
|
|
132
|
+
if (!result.transaction) {
|
|
133
|
+
if (result.error) {
|
|
134
|
+
// Build failed — record as execution failure and retry later
|
|
135
|
+
const event = (0, helpers_js_1.makeFlowEvent)('execution_failed', {
|
|
136
|
+
detail: `Build failed: ${result.error}`,
|
|
137
|
+
data: result.condition,
|
|
138
|
+
});
|
|
139
|
+
flow.history.push(event);
|
|
140
|
+
flow.state.attempts += 1;
|
|
141
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
142
|
+
return { flowId: flow.id, status: flow.status, event };
|
|
143
|
+
}
|
|
144
|
+
const event = (0, helpers_js_1.makeFlowEvent)('condition_met', {
|
|
145
|
+
detail: 'Condition met, no transaction returned',
|
|
146
|
+
data: result.condition,
|
|
147
|
+
});
|
|
148
|
+
flow.history.push(event);
|
|
149
|
+
advanceToNextStep(flow);
|
|
150
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
151
|
+
return { flowId: flow.id, status: flow.status, event };
|
|
152
|
+
}
|
|
153
|
+
// Transaction returned — verify and sign
|
|
154
|
+
const attemptEvent = (0, helpers_js_1.makeFlowEvent)('execution_attempted');
|
|
155
|
+
flow.history.push(attemptEvent);
|
|
156
|
+
if (opts.verifyTransaction) {
|
|
157
|
+
if (!resolvedIntent) {
|
|
158
|
+
const failEvent = (0, helpers_js_1.makeFlowEvent)('execution_failed', { detail: 'No intent available for verification' });
|
|
159
|
+
flow.history.push(failEvent);
|
|
160
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
161
|
+
return { flowId: flow.id, status: flow.status, event: failEvent };
|
|
162
|
+
}
|
|
163
|
+
const verification = await opts.verifyTransaction(result.transaction, resolvedIntent);
|
|
164
|
+
if (!verification.matched) {
|
|
165
|
+
const failEvent = (0, helpers_js_1.makeFlowEvent)('execution_failed', {
|
|
166
|
+
detail: `Verification failed: ${verification.discrepancies.join('; ')}`,
|
|
167
|
+
});
|
|
168
|
+
flow.history.push(failEvent);
|
|
169
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
170
|
+
return { flowId: flow.id, status: flow.status, event: failEvent };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (opts.signAndSubmit) {
|
|
174
|
+
try {
|
|
175
|
+
const txid = await opts.signAndSubmit(result.transaction);
|
|
176
|
+
const successEvent = (0, helpers_js_1.makeFlowEvent)('execution_succeeded', {
|
|
177
|
+
txid,
|
|
178
|
+
detail: result.quote ? JSON.stringify(result.quote) : undefined,
|
|
179
|
+
});
|
|
180
|
+
flow.history.push(successEvent);
|
|
181
|
+
advanceToCompletion(flow);
|
|
182
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
183
|
+
return { flowId: flow.id, status: flow.status, event: successEvent };
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
187
|
+
const failEvent = (0, helpers_js_1.makeFlowEvent)('execution_failed', { detail: `Submit failed: ${message}` });
|
|
188
|
+
flow.history.push(failEvent);
|
|
189
|
+
flow.state.attempts += 1;
|
|
190
|
+
(0, helpers_js_1.incrementVersion)(flow);
|
|
191
|
+
return { flowId: flow.id, status: flow.status, event: failEvent };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
// --- Internal helpers ---
|
|
197
|
+
function getIntentForHeartbeat(flow) {
|
|
198
|
+
for (let i = flow.state.currentStepIndex; i < flow.steps.length; i++) {
|
|
199
|
+
const step = flow.steps[i];
|
|
200
|
+
if ((0, helpers_js_1.isIntentStep)(step) && !(0, resolve_js_1.isDeferredIntent)(step.intent)) {
|
|
201
|
+
return step.intent;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
function advanceToNextStep(flow) {
|
|
207
|
+
flow.state.currentStepIndex += 1;
|
|
208
|
+
flow.state.attempts = 0;
|
|
209
|
+
if (flow.state.currentStepIndex >= flow.steps.length) {
|
|
210
|
+
flow.status = 'completed';
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
flow.status = 'active';
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function advanceToCompletion(flow) {
|
|
217
|
+
flow.state.currentStepIndex = flow.steps.length;
|
|
218
|
+
flow.status = 'completed';
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/flows/executor.ts"],"names":[],"mappings":";;AA2DA,4CAqHC;AAhLD,yCAAkD;AAClD,6CAEgD;AAChD,6CAAgD;AAqDhD,wBAAwB;AAEjB,KAAK,UAAU,gBAAgB,CAAC,OAAwB,EAAE;IAC/D,MAAM,KAAK,GAAG,IAAA,oBAAS,GAAE,CAAC;IAC1B,MAAM,OAAO,GAA0B,EAAE,CAAC;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAC/C,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,yBAAY,CAAC,CAAC;IACrD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAE7C,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAgB,CAAC;IAExC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,IAAI,IAAA,0BAAa,EAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;YACvB,MAAM,KAAK,GAAG,IAAA,0BAAa,EAAC,SAAS,EAAE,EAAE,MAAM,EAAE,cAAc,IAAI,CAA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IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACxB,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAU;IACrC,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAChD,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFlowActive = isFlowActive;
|
|
4
|
+
exports.getCurrentStep = getCurrentStep;
|
|
5
|
+
exports.isConditionStep = isConditionStep;
|
|
6
|
+
exports.isIntentStep = isIntentStep;
|
|
7
|
+
exports.isFlowExpired = isFlowExpired;
|
|
8
|
+
exports.isInCooldown = isInCooldown;
|
|
9
|
+
exports.getAttemptCount = getAttemptCount;
|
|
10
|
+
exports.makeFlowEvent = makeFlowEvent;
|
|
11
|
+
exports.incrementVersion = incrementVersion;
|
|
12
|
+
function isFlowActive(flow) {
|
|
13
|
+
return flow.status === 'pending' || flow.status === 'active' || flow.status === 'waiting';
|
|
14
|
+
}
|
|
15
|
+
function getCurrentStep(flow) {
|
|
16
|
+
return flow.steps[flow.state.currentStepIndex] ?? null;
|
|
17
|
+
}
|
|
18
|
+
function isConditionStep(step) {
|
|
19
|
+
return step.type === 'condition';
|
|
20
|
+
}
|
|
21
|
+
function isIntentStep(step) {
|
|
22
|
+
return step.type === 'intent';
|
|
23
|
+
}
|
|
24
|
+
function isFlowExpired(flow, now) {
|
|
25
|
+
if (!flow.policy.expiresAt)
|
|
26
|
+
return false;
|
|
27
|
+
return (now ?? Date.now()) >= flow.policy.expiresAt;
|
|
28
|
+
}
|
|
29
|
+
function isInCooldown(flow, now) {
|
|
30
|
+
const cooldown = flow.policy.cooldown ?? 60;
|
|
31
|
+
const lastAttempt = [...flow.history].reverse().find((e) => e.type === 'execution_attempted' || e.type === 'execution_succeeded' || e.type === 'execution_failed');
|
|
32
|
+
if (!lastAttempt)
|
|
33
|
+
return false;
|
|
34
|
+
const elapsed = ((now ?? Date.now()) - new Date(lastAttempt.timestamp).getTime()) / 1000;
|
|
35
|
+
return elapsed < cooldown;
|
|
36
|
+
}
|
|
37
|
+
function getAttemptCount(flow) {
|
|
38
|
+
return flow.history.filter((e) => e.type === 'execution_attempted').length;
|
|
39
|
+
}
|
|
40
|
+
function makeFlowEvent(type, opts) {
|
|
41
|
+
return {
|
|
42
|
+
timestamp: new Date().toISOString(),
|
|
43
|
+
type,
|
|
44
|
+
...opts,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function incrementVersion(flow) {
|
|
48
|
+
flow.version += 1;
|
|
49
|
+
flow.updatedAt = Date.now();
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/flows/helpers.ts"],"names":[],"mappings":";;AAEA,oCAEC;AAED,wCAEC;AAED,0CAEC;AAED,oCAEC;AAED,sCAGC;AAED,oCAQC;AAED,0CAEC;AAED,sCAWC;AAED,4CAGC;AAnDD,SAAgB,YAAY,CAAC,IAAU;IACrC,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;AAC5F,CAAC;AAED,SAAgB,cAAc,CAAC,IAAU;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAA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,CAAC,CAAC,MAAM,CAAC;AAC7E,CAAC;AAED,SAAgB,aAAa,CAAC,IAAmB,EAAE,IAKlD;IACC,OAAO;QACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,IAAI;QACJ,GAAG,IAAI;KACR,CAAC;AACJ,CAAC;AAED,SAAgB,gBAAgB,CAAC,IAAU;IACzC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;IAClB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLimitOrder = exports.executeHeartbeat = exports.incrementVersion = exports.makeFlowEvent = exports.getAttemptCount = exports.isInCooldown = exports.isFlowExpired = exports.isIntentStep = exports.isConditionStep = exports.getCurrentStep = exports.isFlowActive = exports.resolveRefs = exports.resolveRef = exports.isDeferredIntent = exports.isStepOutputRef = exports.timeReachedCondition = exports.priceAboveCondition = exports.priceBelowCondition = exports.isTimeCondition = exports.isPriceCondition = exports.removeFlow = exports.updateFlow = exports.getFlow = exports.addFlow = exports.saveFlows = exports.loadFlows = void 0;
|
|
4
|
+
var store_js_1 = require("./store.js");
|
|
5
|
+
Object.defineProperty(exports, "loadFlows", { enumerable: true, get: function () { return store_js_1.loadFlows; } });
|
|
6
|
+
Object.defineProperty(exports, "saveFlows", { enumerable: true, get: function () { return store_js_1.saveFlows; } });
|
|
7
|
+
Object.defineProperty(exports, "addFlow", { enumerable: true, get: function () { return store_js_1.addFlow; } });
|
|
8
|
+
Object.defineProperty(exports, "getFlow", { enumerable: true, get: function () { return store_js_1.getFlow; } });
|
|
9
|
+
Object.defineProperty(exports, "updateFlow", { enumerable: true, get: function () { return store_js_1.updateFlow; } });
|
|
10
|
+
Object.defineProperty(exports, "removeFlow", { enumerable: true, get: function () { return store_js_1.removeFlow; } });
|
|
11
|
+
// Conditions
|
|
12
|
+
var conditions_js_1 = require("./conditions.js");
|
|
13
|
+
Object.defineProperty(exports, "isPriceCondition", { enumerable: true, get: function () { return conditions_js_1.isPriceCondition; } });
|
|
14
|
+
Object.defineProperty(exports, "isTimeCondition", { enumerable: true, get: function () { return conditions_js_1.isTimeCondition; } });
|
|
15
|
+
Object.defineProperty(exports, "priceBelowCondition", { enumerable: true, get: function () { return conditions_js_1.priceBelowCondition; } });
|
|
16
|
+
Object.defineProperty(exports, "priceAboveCondition", { enumerable: true, get: function () { return conditions_js_1.priceAboveCondition; } });
|
|
17
|
+
Object.defineProperty(exports, "timeReachedCondition", { enumerable: true, get: function () { return conditions_js_1.timeReachedCondition; } });
|
|
18
|
+
// Resolve
|
|
19
|
+
var resolve_js_1 = require("./resolve.js");
|
|
20
|
+
Object.defineProperty(exports, "isStepOutputRef", { enumerable: true, get: function () { return resolve_js_1.isStepOutputRef; } });
|
|
21
|
+
Object.defineProperty(exports, "isDeferredIntent", { enumerable: true, get: function () { return resolve_js_1.isDeferredIntent; } });
|
|
22
|
+
Object.defineProperty(exports, "resolveRef", { enumerable: true, get: function () { return resolve_js_1.resolveRef; } });
|
|
23
|
+
Object.defineProperty(exports, "resolveRefs", { enumerable: true, get: function () { return resolve_js_1.resolveRefs; } });
|
|
24
|
+
// Helpers
|
|
25
|
+
var helpers_js_1 = require("./helpers.js");
|
|
26
|
+
Object.defineProperty(exports, "isFlowActive", { enumerable: true, get: function () { return helpers_js_1.isFlowActive; } });
|
|
27
|
+
Object.defineProperty(exports, "getCurrentStep", { enumerable: true, get: function () { return helpers_js_1.getCurrentStep; } });
|
|
28
|
+
Object.defineProperty(exports, "isConditionStep", { enumerable: true, get: function () { return helpers_js_1.isConditionStep; } });
|
|
29
|
+
Object.defineProperty(exports, "isIntentStep", { enumerable: true, get: function () { return helpers_js_1.isIntentStep; } });
|
|
30
|
+
Object.defineProperty(exports, "isFlowExpired", { enumerable: true, get: function () { return helpers_js_1.isFlowExpired; } });
|
|
31
|
+
Object.defineProperty(exports, "isInCooldown", { enumerable: true, get: function () { return helpers_js_1.isInCooldown; } });
|
|
32
|
+
Object.defineProperty(exports, "getAttemptCount", { enumerable: true, get: function () { return helpers_js_1.getAttemptCount; } });
|
|
33
|
+
Object.defineProperty(exports, "makeFlowEvent", { enumerable: true, get: function () { return helpers_js_1.makeFlowEvent; } });
|
|
34
|
+
Object.defineProperty(exports, "incrementVersion", { enumerable: true, get: function () { return helpers_js_1.incrementVersion; } });
|
|
35
|
+
// Executor
|
|
36
|
+
var executor_js_1 = require("./executor.js");
|
|
37
|
+
Object.defineProperty(exports, "executeHeartbeat", { enumerable: true, get: function () { return executor_js_1.executeHeartbeat; } });
|
|
38
|
+
// Templates
|
|
39
|
+
var templates_js_1 = require("./templates.js");
|
|
40
|
+
Object.defineProperty(exports, "createLimitOrder", { enumerable: true, get: function () { return templates_js_1.createLimitOrder; } });
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/flows/index.ts"],"names":[],"mappings":";;;AAUA,uCAA4F;AAAnF,qGAAA,SAAS,OAAA;AAAE,qGAAA,SAAS,OAAA;AAAE,mGAAA,OAAO,OAAA;AAAE,mGAAA,OAAO,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,sGAAA,UAAU,OAAA;AAEvE,aAAa;AACb,iDAAoI;AAA3H,iHAAA,gBAAgB,OAAA;AAAE,gHAAA,eAAe,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAE1G,UAAU;AACV,2CAA0F;AAAjF,6GAAA,eAAe,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,yGAAA,WAAW,OAAA;AAEnE,UAAU;AACV,2CAA0K;AAAjK,0GAAA,YAAY,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,6GAAA,eAAe,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,2GAAA,aAAa,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,6GAAA,eAAe,OAAA;AAAE,2GAAA,aAAa,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AAEnJ,WAAW;AACX,6CAAiD;AAAxC,+GAAA,gBAAgB,OAAA;AAGzB,YAAY;AACZ,+CAAkD;AAAzC,gHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isStepOutputRef = isStepOutputRef;
|
|
4
|
+
exports.isDeferredIntent = isDeferredIntent;
|
|
5
|
+
exports.resolveRef = resolveRef;
|
|
6
|
+
exports.resolveRefs = resolveRefs;
|
|
7
|
+
const errors_js_1 = require("../errors.js");
|
|
8
|
+
function isStepOutputRef(value) {
|
|
9
|
+
return typeof value === 'object' && value !== null && '$ref' in value && 'path' in value;
|
|
10
|
+
}
|
|
11
|
+
function isDeferredIntent(intent) {
|
|
12
|
+
return typeof intent === 'object' && intent !== null && 'action' in intent && 'params' in intent && !('chain' in intent);
|
|
13
|
+
}
|
|
14
|
+
function resolveRef(ref, stepOutputs) {
|
|
15
|
+
const output = stepOutputs[ref.$ref];
|
|
16
|
+
if (!output) {
|
|
17
|
+
throw new errors_js_1.SdkError('UNRESOLVED_REF', `Step "${ref.$ref}" has no output`);
|
|
18
|
+
}
|
|
19
|
+
const parts = ref.path.split('.');
|
|
20
|
+
let value = output;
|
|
21
|
+
for (const part of parts) {
|
|
22
|
+
if (typeof value !== 'object' || value === null) {
|
|
23
|
+
throw new errors_js_1.SdkError('UNRESOLVED_REF', `Cannot resolve path "${ref.path}" on step "${ref.$ref}"`);
|
|
24
|
+
}
|
|
25
|
+
value = value[part];
|
|
26
|
+
}
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
throw new errors_js_1.SdkError('UNRESOLVED_REF', `Path "${ref.path}" not found in step "${ref.$ref}" output`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function resolveRefs(params, stepOutputs) {
|
|
33
|
+
const resolved = {};
|
|
34
|
+
for (const [key, value] of Object.entries(params)) {
|
|
35
|
+
resolved[key] = isStepOutputRef(value) ? resolveRef(value, stepOutputs) : value;
|
|
36
|
+
}
|
|
37
|
+
return resolved;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../src/flows/resolve.ts"],"names":[],"mappings":";;AAIA,0CAEC;AAED,4CAEC;AAED,gCAoBC;AAED,kCASC;AA3CD,4CAAwC;AAIxC,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AAC3F,CAAC;AAED,SAAgB,gBAAgB,CAAC,MAAe;IAC9C,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,IAAI,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC;AAC3H,CAAC;AAED,SAAgB,UAAU,CAAC,GAAkB,EAAE,WAAuC;IACpF,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,oBAAQ,CAAC,gBAAgB,EAAE,SAAS,GAAG,CAAC,IAAI,iBAAiB,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,KAAK,GAAY,MAAM,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChD,MAAM,IAAI,oBAAQ,CAAC,gBAAgB,EAAE,wBAAwB,GAAG,CAAC,IAAI,cAAc,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;QAClG,CAAC;QACD,KAAK,GAAI,KAAiC,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,oBAAQ,CAAC,gBAAgB,EAAE,SAAS,GAAG,CAAC,IAAI,wBAAwB,GAAG,CAAC,IAAI,UAAU,CAAC,CAAC;IACpG,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,WAAW,CACzB,MAA+B,EAC/B,WAAuC;IAEvC,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,QAAQ,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadFlows = loadFlows;
|
|
7
|
+
exports.saveFlows = saveFlows;
|
|
8
|
+
exports.addFlow = addFlow;
|
|
9
|
+
exports.getFlow = getFlow;
|
|
10
|
+
exports.updateFlow = updateFlow;
|
|
11
|
+
exports.removeFlow = removeFlow;
|
|
12
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const config_js_1 = require("../config.js");
|
|
15
|
+
const errors_js_1 = require("../errors.js");
|
|
16
|
+
const FLOWS_FILE = node_path_1.default.join(config_js_1.CONFIG_DIR, 'flows.json');
|
|
17
|
+
function loadFlows() {
|
|
18
|
+
try {
|
|
19
|
+
const raw = node_fs_1.default.readFileSync(FLOWS_FILE, 'utf-8');
|
|
20
|
+
return JSON.parse(raw);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return { flows: [] };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function saveFlows(store) {
|
|
27
|
+
node_fs_1.default.mkdirSync(config_js_1.CONFIG_DIR, { recursive: true });
|
|
28
|
+
node_fs_1.default.writeFileSync(FLOWS_FILE, JSON.stringify(store, null, 2), 'utf-8');
|
|
29
|
+
}
|
|
30
|
+
function addFlow(flow) {
|
|
31
|
+
const store = loadFlows();
|
|
32
|
+
store.flows.push(flow);
|
|
33
|
+
saveFlows(store);
|
|
34
|
+
}
|
|
35
|
+
function getFlow(id) {
|
|
36
|
+
const store = loadFlows();
|
|
37
|
+
return store.flows.find((f) => f.id === id) || null;
|
|
38
|
+
}
|
|
39
|
+
function updateFlow(id, updates) {
|
|
40
|
+
const store = loadFlows();
|
|
41
|
+
const index = store.flows.findIndex((f) => f.id === id);
|
|
42
|
+
if (index === -1) {
|
|
43
|
+
throw new errors_js_1.SdkError('FLOW_NOT_FOUND', `Flow "${id}" not found`);
|
|
44
|
+
}
|
|
45
|
+
store.flows[index] = { ...store.flows[index], ...updates, updatedAt: Date.now() };
|
|
46
|
+
saveFlows(store);
|
|
47
|
+
}
|
|
48
|
+
function removeFlow(id) {
|
|
49
|
+
const store = loadFlows();
|
|
50
|
+
store.flows = store.flows.filter((f) => f.id !== id);
|
|
51
|
+
saveFlows(store);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/flows/store.ts"],"names":[],"mappings":";;;;;AAYA,8BAOC;AAED,8BAGC;AAED,0BAIC;AAED,0BAGC;AAED,gCAQC;AAED,gCAIC;AAnDD,sDAAyB;AACzB,0DAA6B;AAC7B,4CAA0C;AAC1C,4CAAwC;AAGxC,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,sBAAU,EAAE,YAAY,CAAC,CAAC;AAMvD,SAAgB,SAAS;IACvB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,iBAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAe,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED,SAAgB,SAAS,CAAC,KAAiB;IACzC,iBAAE,CAAC,SAAS,CAAC,sBAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,iBAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,SAAgB,OAAO,CAAC,IAAU;IAChC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,SAAS,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED,SAAgB,OAAO,CAAC,EAAU;IAChC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC;AACtD,CAAC;AAED,SAAgB,UAAU,CAAC,EAAU,EAAE,OAAsB;IAC3D,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACxD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,oBAAQ,CAAC,gBAAgB,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IACjE,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAClF,SAAS,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED,SAAgB,UAAU,CAAC,EAAU;IACnC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,SAAS,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLimitOrder = createLimitOrder;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const sugar_js_1 = require("../orders/sugar.js");
|
|
6
|
+
const conditions_js_1 = require("./conditions.js");
|
|
7
|
+
function createLimitOrder(params) {
|
|
8
|
+
const price = parseFloat(params.targetPrice);
|
|
9
|
+
const condition = (0, conditions_js_1.priceAboveCondition)(params.sellSymbol, price);
|
|
10
|
+
const conditionStep = {
|
|
11
|
+
id: 'wait-for-price',
|
|
12
|
+
type: 'condition',
|
|
13
|
+
condition,
|
|
14
|
+
};
|
|
15
|
+
const intent = (0, sugar_js_1.parseSwapSugar)({
|
|
16
|
+
sellAmount: params.sellAmount,
|
|
17
|
+
sellSymbol: params.sellSymbol,
|
|
18
|
+
buySymbol: params.buySymbol,
|
|
19
|
+
price: params.targetPrice,
|
|
20
|
+
slippage: params.slippage,
|
|
21
|
+
from: params.wallet,
|
|
22
|
+
chain: params.chain,
|
|
23
|
+
});
|
|
24
|
+
const intentStep = {
|
|
25
|
+
id: 'execute-swap',
|
|
26
|
+
type: 'intent',
|
|
27
|
+
dependsOn: ['wait-for-price'],
|
|
28
|
+
intent,
|
|
29
|
+
};
|
|
30
|
+
const now = Date.now();
|
|
31
|
+
return {
|
|
32
|
+
id: (0, node_crypto_1.randomUUID)(),
|
|
33
|
+
type: 'limit-order',
|
|
34
|
+
chain: params.chain,
|
|
35
|
+
wallet: params.wallet,
|
|
36
|
+
status: 'waiting',
|
|
37
|
+
steps: [conditionStep, intentStep],
|
|
38
|
+
state: {
|
|
39
|
+
currentStepIndex: 0,
|
|
40
|
+
stepOutputs: {},
|
|
41
|
+
attempts: 0,
|
|
42
|
+
},
|
|
43
|
+
policy: {
|
|
44
|
+
cooldown: params.cooldown ?? 60,
|
|
45
|
+
maxAttempts: params.maxAttempts,
|
|
46
|
+
expiresAt: params.expiresAt,
|
|
47
|
+
},
|
|
48
|
+
version: 1,
|
|
49
|
+
createdAt: now,
|
|
50
|
+
updatedAt: now,
|
|
51
|
+
history: [{ timestamp: new Date(now).toISOString(), type: 'created' }],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/flows/templates.ts"],"names":[],"mappings":";;AAkBA,4CAoDC;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B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B;QACD,OAAO,EAAE,CAAC;QACV,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,GAAG;QACd,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/flows/types.ts"],"names":[],"mappings":""}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseSwapSugar = exports.evaluateOrders = exports.updateOrder = exports.getOrder = exports.addOrder = exports.saveOrders = exports.loadOrders = exports.isEvmChain = exports.normalizeAddress = exports.parseChain = exports.getExecutionRef = exports.getProgramRef = exports.createProgramRegistry = exports.createTokenRegistry = exports.evaluateConstraint = exports.verifyIntentV2 = exports.verifyIntent = exports.analyzeTransaction = exports.validatePay = exports.validateCancel = exports.validateClaim = exports.fetchTransfer = exports.validateAmount = exports.validateAddress = exports.wrapCommand = exports.outputError = exports.outputSuccess = exports.toSdkError = exports.ANCHOR_ERROR_MAP = exports.SdkError = exports.getTransfer = exports.createHttpClient = exports.initContacts = exports.resolveRecipient = exports.listContacts = exports.getContact = exports.removeContact = exports.addContact = exports.saveContacts = exports.loadContacts = exports.CONFIG_DIR = exports.clearApiKey = exports.getApiKey = exports.getApiUrl = exports.getWallet = exports.saveConfig = exports.loadConfig = void 0;
|
|
3
|
+
exports.addFlow = exports.saveFlows = exports.loadFlows = exports.parseSwapSugar = exports.evaluateOrders = exports.updateOrder = exports.getOrder = exports.addOrder = exports.saveOrders = exports.loadOrders = exports.isEvmChain = exports.normalizeAddress = exports.parseChain = exports.getExecutionRef = exports.getProgramRef = exports.createProgramRegistry = exports.createTokenRegistry = exports.evaluateConstraint = exports.verifyIntentV2 = exports.verifyIntent = exports.analyzeTransaction = exports.validatePay = exports.validateCancel = exports.validateClaim = exports.fetchTransfer = exports.validateAmount = exports.validateAddress = exports.wrapCommand = exports.outputError = exports.outputSuccess = exports.toSdkError = exports.ANCHOR_ERROR_MAP = exports.SdkError = exports.getTransfer = exports.createHttpClient = exports.initContacts = exports.resolveRecipient = exports.listContacts = exports.getContact = exports.removeContact = exports.addContact = exports.saveContacts = exports.loadContacts = exports.CONFIG_DIR = exports.clearApiKey = exports.getApiKey = exports.getApiUrl = exports.getWallet = exports.saveConfig = exports.loadConfig = void 0;
|
|
4
|
+
exports.createLimitOrder = exports.executeHeartbeat = exports.incrementVersion = exports.makeFlowEvent = exports.getAttemptCount = exports.isInCooldown = exports.isFlowExpired = exports.isIntentStep = exports.isConditionStep = exports.getCurrentStep = exports.isFlowActive = exports.resolveRefs = exports.resolveRef = exports.isDeferredIntent = exports.isStepOutputRef = exports.timeReachedCondition = exports.priceAboveCondition = exports.priceBelowCondition = exports.isTimeCondition = exports.isPriceCondition = exports.removeFlow = exports.updateFlow = exports.getFlow = void 0;
|
|
4
5
|
var config_js_1 = require("./config.js");
|
|
5
6
|
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_js_1.loadConfig; } });
|
|
6
7
|
Object.defineProperty(exports, "saveConfig", { enumerable: true, get: function () { return config_js_1.saveConfig; } });
|
|
@@ -61,4 +62,32 @@ Object.defineProperty(exports, "getOrder", { enumerable: true, get: function ()
|
|
|
61
62
|
Object.defineProperty(exports, "updateOrder", { enumerable: true, get: function () { return index_js_4.updateOrder; } });
|
|
62
63
|
Object.defineProperty(exports, "evaluateOrders", { enumerable: true, get: function () { return index_js_4.evaluateOrders; } });
|
|
63
64
|
Object.defineProperty(exports, "parseSwapSugar", { enumerable: true, get: function () { return index_js_4.parseSwapSugar; } });
|
|
65
|
+
// Flows
|
|
66
|
+
var index_js_5 = require("./flows/index.js");
|
|
67
|
+
Object.defineProperty(exports, "loadFlows", { enumerable: true, get: function () { return index_js_5.loadFlows; } });
|
|
68
|
+
Object.defineProperty(exports, "saveFlows", { enumerable: true, get: function () { return index_js_5.saveFlows; } });
|
|
69
|
+
Object.defineProperty(exports, "addFlow", { enumerable: true, get: function () { return index_js_5.addFlow; } });
|
|
70
|
+
Object.defineProperty(exports, "getFlow", { enumerable: true, get: function () { return index_js_5.getFlow; } });
|
|
71
|
+
Object.defineProperty(exports, "updateFlow", { enumerable: true, get: function () { return index_js_5.updateFlow; } });
|
|
72
|
+
Object.defineProperty(exports, "removeFlow", { enumerable: true, get: function () { return index_js_5.removeFlow; } });
|
|
73
|
+
Object.defineProperty(exports, "isPriceCondition", { enumerable: true, get: function () { return index_js_5.isPriceCondition; } });
|
|
74
|
+
Object.defineProperty(exports, "isTimeCondition", { enumerable: true, get: function () { return index_js_5.isTimeCondition; } });
|
|
75
|
+
Object.defineProperty(exports, "priceBelowCondition", { enumerable: true, get: function () { return index_js_5.priceBelowCondition; } });
|
|
76
|
+
Object.defineProperty(exports, "priceAboveCondition", { enumerable: true, get: function () { return index_js_5.priceAboveCondition; } });
|
|
77
|
+
Object.defineProperty(exports, "timeReachedCondition", { enumerable: true, get: function () { return index_js_5.timeReachedCondition; } });
|
|
78
|
+
Object.defineProperty(exports, "isStepOutputRef", { enumerable: true, get: function () { return index_js_5.isStepOutputRef; } });
|
|
79
|
+
Object.defineProperty(exports, "isDeferredIntent", { enumerable: true, get: function () { return index_js_5.isDeferredIntent; } });
|
|
80
|
+
Object.defineProperty(exports, "resolveRef", { enumerable: true, get: function () { return index_js_5.resolveRef; } });
|
|
81
|
+
Object.defineProperty(exports, "resolveRefs", { enumerable: true, get: function () { return index_js_5.resolveRefs; } });
|
|
82
|
+
Object.defineProperty(exports, "isFlowActive", { enumerable: true, get: function () { return index_js_5.isFlowActive; } });
|
|
83
|
+
Object.defineProperty(exports, "getCurrentStep", { enumerable: true, get: function () { return index_js_5.getCurrentStep; } });
|
|
84
|
+
Object.defineProperty(exports, "isConditionStep", { enumerable: true, get: function () { return index_js_5.isConditionStep; } });
|
|
85
|
+
Object.defineProperty(exports, "isIntentStep", { enumerable: true, get: function () { return index_js_5.isIntentStep; } });
|
|
86
|
+
Object.defineProperty(exports, "isFlowExpired", { enumerable: true, get: function () { return index_js_5.isFlowExpired; } });
|
|
87
|
+
Object.defineProperty(exports, "isInCooldown", { enumerable: true, get: function () { return index_js_5.isInCooldown; } });
|
|
88
|
+
Object.defineProperty(exports, "getAttemptCount", { enumerable: true, get: function () { return index_js_5.getAttemptCount; } });
|
|
89
|
+
Object.defineProperty(exports, "makeFlowEvent", { enumerable: true, get: function () { return index_js_5.makeFlowEvent; } });
|
|
90
|
+
Object.defineProperty(exports, "incrementVersion", { enumerable: true, get: function () { return index_js_5.incrementVersion; } });
|
|
91
|
+
Object.defineProperty(exports, "executeHeartbeat", { enumerable: true, get: function () { return index_js_5.executeHeartbeat; } });
|
|
92
|
+
Object.defineProperty(exports, "createLimitOrder", { enumerable: true, get: function () { return index_js_5.createLimitOrder; } });
|
|
64
93
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,yCAA+G;AAAtG,uGAAA,UAAU,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,uGAAA,UAAU,OAAA;AAEzF,6CAAgJ;AAAvI,2GAAA,YAAY,OAAA;AAAE,2GAAA,YAAY,OAAA;AAAE,yGAAA,UAAU,OAAA;AAAE,4GAAA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,mGAAA,OAAO,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,sGAAA,UAAU,OAAA;AAC9D,4GAAA,gBAAgB,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AAAE,gHAAA,oBAAoB,OAAA;AACjG,2GAAA,eAAe,OAAA;AAAE,4GAAA,gBAAgB,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,uGAAA,WAAW,OAAA;AAC1D,wGAAA,YAAY,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,4GAAA,gBAAgB,OAAA;AAC1I,4GAAA,gBAAgB,OAAA;AAChB,4GAAA,gBAAgB,OAAA"}
|
|
@@ -8,12 +8,12 @@ const BUNDLED_PROGRAMS = {
|
|
|
8
8
|
solana: {
|
|
9
9
|
mainnet: {
|
|
10
10
|
handshake: { address: 'HANDu9uNdnraNbcueGfXhd3UPu6BXfQroKAsSxFhPXEQ' },
|
|
11
|
-
|
|
11
|
+
rebelsig: { address: 'SiLKos3MCFggwLsjSeuRiCdcs2MLoJNwq59XwTvEwcS' },
|
|
12
12
|
jupiter: { address: 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4' },
|
|
13
13
|
},
|
|
14
14
|
devnet: {
|
|
15
15
|
handshake: { address: 'HANDu9uNdnraNbcueGfXhd3UPu6BXfQroKAsSxFhPXEQ' },
|
|
16
|
-
|
|
16
|
+
rebelsig: { address: 'SiLKos3MCFggwLsjSeuRiCdcs2MLoJNwq59XwTvEwcS' },
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
};
|
package/dist/cjs/orders/sugar.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSwapSugar = parseSwapSugar;
|
|
4
4
|
const errors_js_1 = require("../errors.js");
|
|
5
|
-
const DEFAULT_SLIPPAGE =
|
|
5
|
+
const DEFAULT_SLIPPAGE = 1;
|
|
6
6
|
const MAX_SLIPPAGE = 10;
|
|
7
7
|
function parseSwapSugar(input) {
|
|
8
8
|
const slippage = input.slippage ?? DEFAULT_SLIPPAGE;
|
|
@@ -17,7 +17,7 @@ function parseSwapSugar(input) {
|
|
|
17
17
|
if (!Number.isFinite(price) || price <= 0) {
|
|
18
18
|
throw new errors_js_1.SdkError('INVALID_PRICE', `INVALID_PRICE: Price must be positive. Got: ${input.price}`);
|
|
19
19
|
}
|
|
20
|
-
const rawOut = sellAmount
|
|
20
|
+
const rawOut = sellAmount * price;
|
|
21
21
|
const minOut = rawOut * (1 - slippage / 100);
|
|
22
22
|
// Use enough decimal places to avoid precision loss
|
|
23
23
|
const minOutStr = minOut.toFixed(12).replace(/0+$/, '').replace(/\.$/, '');
|
|
@@ -30,6 +30,7 @@ function parseSwapSugar(input) {
|
|
|
30
30
|
tokenOut: { tokenSymbol: input.buySymbol },
|
|
31
31
|
amountIn: input.sellAmount,
|
|
32
32
|
amountOut: { gte: minOutStr },
|
|
33
|
+
slippage: slippage / 100,
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
//# sourceMappingURL=sugar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sugar.js","sourceRoot":"","sources":["../../../src/orders/sugar.ts"],"names":[],"mappings":";;AAgBA,
|
|
1
|
+
{"version":3,"file":"sugar.js","sourceRoot":"","sources":["../../../src/orders/sugar.ts"],"names":[],"mappings":";;AAgBA,wCAkCC;AAjDD,4CAAwC;AAExC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,YAAY,GAAG,EAAE,CAAC;AAYxB,SAAgB,cAAc,CAAC,KAAqB;IAClD,MAA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