@dfm-fi/agent 0.2.1543 → 0.2.1550
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/examples/fund-app-wallet.d.ts +2 -0
- package/dist/examples/fund-app-wallet.d.ts.map +1 -0
- package/dist/examples/fund-app-wallet.js +39 -0
- package/dist/examples/fund-app-wallet.js.map +1 -0
- package/dist/examples/recover-app-wallet-assets.d.ts +2 -0
- package/dist/examples/recover-app-wallet-assets.d.ts.map +1 -0
- package/dist/examples/recover-app-wallet-assets.js +86 -0
- package/dist/examples/recover-app-wallet-assets.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fund-app-wallet.d.ts","sourceRoot":"","sources":["../../src/examples/fund-app-wallet.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Top up the app wallet from its owner — the ONE signature the app-wallet model
|
|
3
|
+
* cannot avoid, because it is the owner's money leaving the owner's wallet.
|
|
4
|
+
*
|
|
5
|
+
* The other direction (app wallet → owner) is `recover-app-wallet-assets.ts`.
|
|
6
|
+
*
|
|
7
|
+
* DFM_API_URL=https://n2-api.dfm.finance \
|
|
8
|
+
* DFM_AGENT_KEYPAIR_PATH=~/.config/dfm/test-6vch.json \
|
|
9
|
+
* USDC=11.1 [SOL=0.01] npx tsx src/examples/fund-app-wallet.ts
|
|
10
|
+
*/
|
|
11
|
+
import { loadConfig } from '../config.js';
|
|
12
|
+
import { SiwsSession } from '../session.js';
|
|
13
|
+
import { DfmApiClient } from '../api-client.js';
|
|
14
|
+
import { signBase64Transaction } from '../signing.js';
|
|
15
|
+
import { submitSignedTx } from '../submit.js';
|
|
16
|
+
async function main() {
|
|
17
|
+
const config = loadConfig();
|
|
18
|
+
const api = new DfmApiClient(config, new SiwsSession(config));
|
|
19
|
+
const usdcMicros = Math.round(Number(process.env.USDC ?? '0') * 1e6);
|
|
20
|
+
const solLamports = Math.round(Number(process.env.SOL ?? '0') * 1e9);
|
|
21
|
+
if (usdcMicros <= 0 && solLamports <= 0)
|
|
22
|
+
throw new Error('set USDC and/or SOL');
|
|
23
|
+
const prepared = await api.prepareOperatingFund({
|
|
24
|
+
...(usdcMicros > 0 ? { usdcMicros } : {}),
|
|
25
|
+
...(solLamports > 0 ? { solLamports } : {}),
|
|
26
|
+
});
|
|
27
|
+
const signed = signBase64Transaction(config, prepared.transaction);
|
|
28
|
+
const signature = await submitSignedTx(config, signed, prepared.blockhash, prepared.lastValidBlockHeight,
|
|
29
|
+
// Backend broadcast: without `preparedTxId` this is the one write that
|
|
30
|
+
// demands a client RPC.
|
|
31
|
+
{ api, preparedTxId: prepared.preparedTxId });
|
|
32
|
+
console.log(`funded ${prepared.operatingWalletAddress} with ${usdcMicros / 1e6} USDC ` +
|
|
33
|
+
`+ ${solLamports / 1e9} SOL — ${signature}`);
|
|
34
|
+
}
|
|
35
|
+
main().catch((e) => {
|
|
36
|
+
console.error('FAILED', e instanceof Error ? e.message : e);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=fund-app-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fund-app-wallet.js","sourceRoot":"","sources":["../../src/examples/fund-app-wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,M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O,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recover-app-wallet-assets.d.ts","sourceRoot":"","sources":["../../src/examples/recover-app-wallet-assets.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recover what a test cycle stranded in the app wallet: every non-USDC, non-share
|
|
3
|
+
* token goes OUT to one destination, in one pass, so it can be swapped back to
|
|
4
|
+
* USDC from a wallet whose key is local (`contracts/scripts/swap-wallet-tokens-to-usdc.js`).
|
|
5
|
+
*
|
|
6
|
+
* An in-kind cancel and the per-leg surplus refunds pay the user in BASKET TOKENS,
|
|
7
|
+
* and the app wallet has no swap surface — so the value sits there until it is
|
|
8
|
+
* moved. This is the move.
|
|
9
|
+
*
|
|
10
|
+
* Dry-run by default; `--execute` sends. Fund shares are skipped (redeem them, do
|
|
11
|
+
* not transfer them) and so is USDC (it is already the thing we want).
|
|
12
|
+
*
|
|
13
|
+
* DFM_API_URL=https://n2-api.dfm.finance \
|
|
14
|
+
* DFM_AGENT_KEYPAIR_PATH=~/.config/dfm/test-6vch.json \
|
|
15
|
+
* DEST=<address> MIN_USD=0.05 npx tsx src/examples/recover-app-wallet-assets.ts [--execute]
|
|
16
|
+
*
|
|
17
|
+
* Prints the `MINTS=` line the swap script takes, so the two steps chain.
|
|
18
|
+
*/
|
|
19
|
+
import { loadConfig } from '../config.js';
|
|
20
|
+
import { SiwsSession } from '../session.js';
|
|
21
|
+
import { DfmApiClient } from '../api-client.js';
|
|
22
|
+
const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
|
23
|
+
async function main() {
|
|
24
|
+
const execute = process.argv.includes('--execute');
|
|
25
|
+
const config = loadConfig();
|
|
26
|
+
const api = new DfmApiClient(config, new SiwsSession(config));
|
|
27
|
+
// No DEST = let the server resolve it (saved withdrawal wallet, else the
|
|
28
|
+
// owner). NAMING the sign-in wallet is refused ("it only identifies you"),
|
|
29
|
+
// so for a wallet whose owner IS its sign-in identity this is the only way out.
|
|
30
|
+
const dest = process.env.DEST;
|
|
31
|
+
const minUsd = Number(process.env.MIN_USD ?? '0.05');
|
|
32
|
+
const only = process.env.ONLY_MINT;
|
|
33
|
+
const assets = (await api.authRequest('/agent/operating/assets', { method: 'GET' }));
|
|
34
|
+
// Dust below the floor costs more in rent and fees than it returns; a fund
|
|
35
|
+
// share is a CLAIM, not value in hand — it leaves through redeem, never here.
|
|
36
|
+
const movable = assets.assets.filter((a) => a.mint !== USDC &&
|
|
37
|
+
!a.isFundShare &&
|
|
38
|
+
(a.valueUsd ?? 0) >= minUsd &&
|
|
39
|
+
(!only || a.mint === only));
|
|
40
|
+
const total = movable.reduce((sum, a) => sum + (a.valueUsd ?? 0), 0);
|
|
41
|
+
console.log(`app wallet ${assets.operatingWalletAddress} → ${dest ?? '(server-resolved destination)'}`);
|
|
42
|
+
console.log(`${movable.length} tokens worth ~$${total.toFixed(2)} (floor $${minUsd})\n`);
|
|
43
|
+
for (const a of movable)
|
|
44
|
+
console.log(` ${a.mint.slice(0, 8)}… ${a.uiAmount} ≈ $${(a.valueUsd ?? 0).toFixed(3)}`);
|
|
45
|
+
// The destination has to pay for its own swaps afterwards, and a test wallet
|
|
46
|
+
// that just spent its SOL on rent cannot. Move gas in the same pass.
|
|
47
|
+
const solLamports = Number(process.env.SOL_LAMPORTS ?? '0');
|
|
48
|
+
if (!execute) {
|
|
49
|
+
if (solLamports > 0)
|
|
50
|
+
console.log(`\nwould also send ${(solLamports / 1e9).toFixed(4)} SOL for gas`);
|
|
51
|
+
console.log('\nDRY-RUN — nothing sent. Re-run with --execute.');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log('');
|
|
55
|
+
if (solLamports > 0) {
|
|
56
|
+
try {
|
|
57
|
+
const r = await api.authRequest('/agent/operating/float/withdraw', {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
body: JSON.stringify({ solLamports, ...(dest ? { destination: dest } : {}) }),
|
|
60
|
+
});
|
|
61
|
+
console.log(`sent ${(solLamports / 1e9).toFixed(4)} SOL for gas — ${r.signature}`);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.log(`FAILED SOL gas — ${e.message.slice(0, 140)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const a of movable) {
|
|
68
|
+
try {
|
|
69
|
+
const r = await api.authRequest('/agent/operating/assets/withdraw', {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
body: JSON.stringify({ mint: a.mint, all: true, ...(dest ? { destination: dest } : {}) }),
|
|
72
|
+
});
|
|
73
|
+
console.log(`sent ${a.mint.slice(0, 8)}… ${r.sentAmount} — ${r.signature}`);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
console.log(`FAILED ${a.mint.slice(0, 8)}… ${e.message.slice(0, 140)}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
console.log(`\nMINTS="${movable.map((a) => `${a.label ?? a.mint.slice(0, 4)}:${a.mint}`).join(',')}"`);
|
|
81
|
+
}
|
|
82
|
+
main().catch((e) => {
|
|
83
|
+
console.error('FAILED', e instanceof Error ? e.message : e);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=recover-app-wallet-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recover-app-wallet-assets.js","sourceRoot":"","sources":["../../src/examples/recover-app-wallet-assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,cAA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