@dfm-fi/agent 0.2.1550 → 0.2.1553
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zap-cycle.d.ts","sourceRoot":"","sources":["../../src/examples/zap-cycle.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One full retail cycle on an EXISTING vault, through the app wallet (keyless:
|
|
3
|
+
* the server signs, exactly as the web UI does): deposit USDC → legs → mint,
|
|
4
|
+
* then redeem the whole position back to USDC.
|
|
5
|
+
*
|
|
6
|
+
* This is the acceptance harness for the #80 sandwich: every leg is a plain user
|
|
7
|
+
* swap from a throwaway wallet, so the run is only a pass if EVERY transaction
|
|
8
|
+
* lands (`err: null`) and the wallets end empty.
|
|
9
|
+
*
|
|
10
|
+
* DFM_API_URL=https://n2-api.dfm.finance \
|
|
11
|
+
* DFM_AGENT_KEYPAIR_PATH=~/.config/dfm/test-6vch.json \
|
|
12
|
+
* VAULT=<pda> DEPOSIT_USDC=10 [REDEEM=false] npx tsx src/examples/zap-cycle.ts
|
|
13
|
+
*/
|
|
14
|
+
import { loadConfig } from '../config.js';
|
|
15
|
+
import { SiwsSession } from '../session.js';
|
|
16
|
+
import { DfmApiClient } from '../api-client.js';
|
|
17
|
+
async function main() {
|
|
18
|
+
const config = loadConfig();
|
|
19
|
+
const api = new DfmApiClient(config, new SiwsSession(config));
|
|
20
|
+
const vault = process.env.VAULT;
|
|
21
|
+
if (!vault)
|
|
22
|
+
throw new Error('VAULT is required');
|
|
23
|
+
const usdcAmount = String(Math.round(Number(process.env.DEPOSIT_USDC ?? '10') * 1e6));
|
|
24
|
+
const before = await api.getOperatingFloatBalance();
|
|
25
|
+
console.log(`float before: ${JSON.stringify(before)}`);
|
|
26
|
+
if (Number(usdcAmount) > 0) {
|
|
27
|
+
const dep = await api.executeViaOperatingWallet('deposit', { vault, usdcAmount });
|
|
28
|
+
console.log(`DEPOSIT ${JSON.stringify(dep)}`);
|
|
29
|
+
}
|
|
30
|
+
if (process.env.REDEEM === 'false')
|
|
31
|
+
return;
|
|
32
|
+
// The deposit answers as soon as it is submitted; the shares appear when the
|
|
33
|
+
// close mints them, so read the position instead of trusting the response.
|
|
34
|
+
const shares = await pollShares(api, vault);
|
|
35
|
+
console.log(`shares: ${shares ?? '(none)'}`);
|
|
36
|
+
if (!shares || shares === '0')
|
|
37
|
+
throw new Error('no shares to redeem');
|
|
38
|
+
const red = await api.executeViaOperatingWallet('redeem', { vault, shares });
|
|
39
|
+
console.log(`REDEEM ${JSON.stringify(red)}`);
|
|
40
|
+
console.log(`float after: ${JSON.stringify(await api.getOperatingFloatBalance())}`);
|
|
41
|
+
}
|
|
42
|
+
async function pollShares(api, vault) {
|
|
43
|
+
for (let i = 0; i < 40; i++) {
|
|
44
|
+
const positions = (await api.getPortfolioPositions());
|
|
45
|
+
const row = Array.isArray(positions) ? positions.find((p) => p.vaultAddress === vault) : undefined;
|
|
46
|
+
if (row?.shares && row.shares !== '0')
|
|
47
|
+
return row.shares;
|
|
48
|
+
await new Promise((r) => setTimeout(r, 5_000));
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
main().catch((e) => {
|
|
53
|
+
console.error('FAILED', e instanceof Error ? e.message : e);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=zap-cycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zap-cycle.js","sourceRoot":"","sources":["../../src/examples/zap-cycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhD,KAAK,UA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