@dfm-fi/agent 0.2.707 → 0.2.730
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/create-flow.d.ts +25 -0
- package/dist/create-flow.d.ts.map +1 -1
- package/dist/create-flow.js +59 -19
- package/dist/create-flow.js.map +1 -1
- package/dist/create-flow.metadata.test.d.ts +2 -0
- package/dist/create-flow.metadata.test.d.ts.map +1 -0
- package/dist/create-flow.metadata.test.js +100 -0
- package/dist/create-flow.metadata.test.js.map +1 -0
- package/dist/manager-flow.d.ts +12 -2
- package/dist/manager-flow.d.ts.map +1 -1
- package/dist/manager-flow.js +48 -5
- package/dist/manager-flow.js.map +1 -1
- package/dist/manager-flow.reconfigure.test.d.ts +2 -0
- package/dist/manager-flow.reconfigure.test.d.ts.map +1 -0
- package/dist/manager-flow.reconfigure.test.js +153 -0
- package/dist/manager-flow.reconfigure.test.js.map +1 -0
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +8 -2
- package/dist/mcp-server.js.map +1 -1
- package/dist/recovery-flow.d.ts.map +1 -1
- package/dist/recovery-flow.deadleg.test.d.ts +2 -0
- package/dist/recovery-flow.deadleg.test.d.ts.map +1 -0
- package/dist/recovery-flow.deadleg.test.js +143 -0
- package/dist/recovery-flow.deadleg.test.js.map +1 -0
- package/dist/recovery-flow.js +50 -1
- package/dist/recovery-flow.js.map +1 -1
- package/dist/zap-v2-flow.d.ts +13 -0
- package/dist/zap-v2-flow.d.ts.map +1 -1
- package/dist/zap-v2-flow.js +71 -18
- package/dist/zap-v2-flow.js.map +1 -1
- package/dist/zap-v2-flow.pending.test.d.ts +2 -0
- package/dist/zap-v2-flow.pending.test.d.ts.map +1 -0
- package/dist/zap-v2-flow.pending.test.js +119 -0
- package/dist/zap-v2-flow.pending.test.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #61 regression (runnable: `npx tsx agent/src/zap-v2-flow.pending.test.ts`).
|
|
3
|
+
*
|
|
4
|
+
* The agent package has no jest runner — this is a self-contained assertion
|
|
5
|
+
* script (exit 1 on failure) covering the #61 contract: when the poll window
|
|
6
|
+
* elapses with the escrow STILL OPEN (or it auto-settled / disappeared), the
|
|
7
|
+
* redeem flow must return `settlement:"pending"` (ok:true) WITHOUT calling the
|
|
8
|
+
* close builder — NOT throw a hard error. On the OLD code `pollUntilReady` threw,
|
|
9
|
+
* so `runRedeem` rejected and `prepareZapOutCloseV2` was never reached either;
|
|
10
|
+
* here we assert the NEW resume-able contract: a resolved pending result + no
|
|
11
|
+
* close attempt.
|
|
12
|
+
*/
|
|
13
|
+
import { runRedeem } from './zap-v2-flow.js';
|
|
14
|
+
const VAULT = 'Vau1t1111111111111111111111111111111111111';
|
|
15
|
+
const USER = 'User1111111111111111111111111111111111111111';
|
|
16
|
+
const ESCROW = 'Escrow11111111111111111111111111111111111111';
|
|
17
|
+
function openRedeemStatus() {
|
|
18
|
+
return {
|
|
19
|
+
escrowPda: ESCROW,
|
|
20
|
+
vault: VAULT,
|
|
21
|
+
user: USER,
|
|
22
|
+
mode: 1, // redeem
|
|
23
|
+
state: 4, // PARTIAL_OUT
|
|
24
|
+
nAssets: 10,
|
|
25
|
+
assetMints: [],
|
|
26
|
+
filledMask: 0x1ff, // 9/10
|
|
27
|
+
legProgress: [],
|
|
28
|
+
legsFilled: 9,
|
|
29
|
+
legsTotal: 10,
|
|
30
|
+
readyToClose: false, // never ready within the window
|
|
31
|
+
legFailures: [],
|
|
32
|
+
openedAt: 0,
|
|
33
|
+
expiresAt: 9_999_999_999,
|
|
34
|
+
isExpired: false,
|
|
35
|
+
slippageBps: 300,
|
|
36
|
+
plannedAmountIn: [],
|
|
37
|
+
minOuts: [],
|
|
38
|
+
actualOuts: [],
|
|
39
|
+
inputAmount: '0',
|
|
40
|
+
sharesIn: '1000000',
|
|
41
|
+
minSharesOut: '0',
|
|
42
|
+
minUsdcOut: '0',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
let failures = 0;
|
|
46
|
+
function assert(cond, msg) {
|
|
47
|
+
if (!cond) {
|
|
48
|
+
console.error(` ✗ ${msg}`);
|
|
49
|
+
failures++;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(` ✓ ${msg}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function caseTimeout() {
|
|
56
|
+
console.log('case: poll TIMEOUT with escrow still open → pending (no close)');
|
|
57
|
+
let closeCalled = 0;
|
|
58
|
+
const mockApi = {
|
|
59
|
+
getZapV2Status: async () => openRedeemStatus(),
|
|
60
|
+
prepareZapOutCloseV2: async () => {
|
|
61
|
+
closeCalled++;
|
|
62
|
+
return { transactions: [], blockhash: '', lastValidBlockHeight: 0, escrowPda: ESCROW };
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const res = await runRedeem({}, // config — unused on the pending path
|
|
66
|
+
mockApi, USER, VAULT, '1000000', { poll: { timeoutSecs: 0.3, intervalSecs: 0.1 } });
|
|
67
|
+
assert(res.ok === true, 'result.ok === true (not an error)');
|
|
68
|
+
assert(res.settlement === 'pending', `settlement === 'pending' (got '${res.settlement}')`);
|
|
69
|
+
assert(res.closeSignatures.length === 0, 'no close signatures');
|
|
70
|
+
assert(closeCalled === 0, 'prepareZapOutCloseV2 was NOT called');
|
|
71
|
+
assert(res.pending?.reason === 'timeout', `pending.reason === 'timeout' (got '${res.pending?.reason}')`);
|
|
72
|
+
assert(res.pending?.legsFilled === 9 && res.pending?.legsTotal === 10, 'pending carries 9/10 legs');
|
|
73
|
+
}
|
|
74
|
+
async function caseGone() {
|
|
75
|
+
console.log('case: escrow GONE during poll (auto-settled) → pending/gone (no throw)');
|
|
76
|
+
let calls = 0;
|
|
77
|
+
const mockApi = {
|
|
78
|
+
// resume guard (call 0) + first poll (call 1) see the escrow OPEN, then it
|
|
79
|
+
// disappears (call 2+) = a genuine mid-poll settle. The guard requires having
|
|
80
|
+
// seen it open before concluding 'gone' (so a not-yet-propagated fresh escrow
|
|
81
|
+
// isn't mis-reported) — realistic settle must show it open first.
|
|
82
|
+
getZapV2Status: async () => (calls++ < 2 ? openRedeemStatus() : null),
|
|
83
|
+
prepareZapOutCloseV2: async () => {
|
|
84
|
+
throw new Error('close must not be called on gone');
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
const res = await runRedeem({}, mockApi, USER, VAULT, '1000000', { poll: { timeoutSecs: 5, intervalSecs: 0.1 } });
|
|
88
|
+
assert(res.ok === true, 'result.ok === true');
|
|
89
|
+
assert(res.settlement === 'pending', `settlement === 'pending' (got '${res.settlement}')`);
|
|
90
|
+
assert(res.pending?.reason === 'gone', `pending.reason === 'gone' (got '${res.pending?.reason}')`);
|
|
91
|
+
}
|
|
92
|
+
async function caseFreshNullNotGone() {
|
|
93
|
+
console.log('case: null reads WITHOUT ever seeing the escrow open → timeout, NOT gone (race ⑥ guard)');
|
|
94
|
+
let calls = 0;
|
|
95
|
+
const mockApi = {
|
|
96
|
+
// resume guard (call 0) sees it open; every poll read after is null BEFORE the
|
|
97
|
+
// poll loop ever observes it open itself (propagation blip / not-yet-visible).
|
|
98
|
+
// The fix must NOT declare 'gone' here — it keeps waiting → 'timeout'. The OLD
|
|
99
|
+
// code returned 'gone' on the first null, mis-reporting a live escrow as settled.
|
|
100
|
+
getZapV2Status: async () => (calls++ === 0 ? openRedeemStatus() : null),
|
|
101
|
+
prepareZapOutCloseV2: async () => {
|
|
102
|
+
throw new Error('close must not be called');
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const res = await runRedeem({}, mockApi, USER, VAULT, '1000000', { poll: { timeoutSecs: 0.3, intervalSecs: 0.1 } });
|
|
106
|
+
assert(res.settlement === 'pending', `settlement === 'pending' (got '${res.settlement}')`);
|
|
107
|
+
assert(res.pending?.reason === 'timeout', `reason === 'timeout' not 'gone' (got '${res.pending?.reason}')`);
|
|
108
|
+
}
|
|
109
|
+
(async () => {
|
|
110
|
+
await caseTimeout();
|
|
111
|
+
await caseGone();
|
|
112
|
+
await caseFreshNullNotGone();
|
|
113
|
+
if (failures > 0) {
|
|
114
|
+
console.error(`\n#61 regression FAILED (${failures} assertion(s))`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
console.log('\n#61 regression PASSED');
|
|
118
|
+
})();
|
|
119
|
+
//# sourceMappingURL=zap-v2-flow.pending.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zap-v2-flow.pending.test.js","sourceRoot":"","sources":["../src/zap-v2-flow.pending.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,MAAM,KAAK,GAAG,4CAA4C,CAAC;AAC3D,MAAM,IAAI,GAAG,8CAA8C,CAAC;AAC5D,MAAM,MAAM,GAAG,8CAA8C,CAAC;AAE9D,SAAS,gBAAgB;IACvB,OAAO;QACL,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,CAAC,EAAE,SAAS;QAClB,KAAK,EAAE,CAAC,EAAE,cAAc;QACxB,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,KAAK,EAAE,OAAO;QAC1B,WAAW,EAAE,EAAE;QACf,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,KAAK,EAAE,gCAAgC;QACrD,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,aAAa;QACxB,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,GAAG;QAChB,eAAe,EAAE,EAAE;QACnB,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,EAAE;QACd,WAAW,EAAE,GAAG;QAChB,QAAQ,EAAE,SAAS;QACnB,YAAY,EAAE,GAAG;QACjB,UAAU,EA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