@seekdaseek/plugin-agentfeed 0.1.0 → 0.1.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/index.d.ts +2 -0
- package/dist/index.js +26 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ declare class AgentFeedService extends Service {
|
|
|
18
18
|
private payerAddress;
|
|
19
19
|
/** path -> { usd, checkedAt } of last approved quote */
|
|
20
20
|
private approvedQuotes;
|
|
21
|
+
/** requirements that survived the spend policy on the most recent payment */
|
|
22
|
+
private lastSurvivingReqs;
|
|
21
23
|
/** lifetime spend counter for this process (informational) */
|
|
22
24
|
private totalSpentUsd;
|
|
23
25
|
constructor(runtime: IAgentRuntime);
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,8 @@ var AgentFeedService = class _AgentFeedService extends Service {
|
|
|
23
23
|
payerAddress = "";
|
|
24
24
|
/** path -> { usd, checkedAt } of last approved quote */
|
|
25
25
|
approvedQuotes = /* @__PURE__ */ new Map();
|
|
26
|
+
/** requirements that survived the spend policy on the most recent payment */
|
|
27
|
+
lastSurvivingReqs = [];
|
|
26
28
|
/** lifetime spend counter for this process (informational) */
|
|
27
29
|
totalSpentUsd = 0;
|
|
28
30
|
static async start(runtime) {
|
|
@@ -50,8 +52,18 @@ var AgentFeedService = class _AgentFeedService extends Service {
|
|
|
50
52
|
const keypair = await createKeyPairSignerFromBytes(bytes);
|
|
51
53
|
this.payerAddress = keypair.address;
|
|
52
54
|
const signer = toClientSvmSigner(keypair);
|
|
55
|
+
const capBaseUnits = Math.round(this.maxSpendUsd * 10 ** USDC_DECIMALS);
|
|
56
|
+
const maxSpendPolicy = (_v, reqs) => {
|
|
57
|
+
const surviving = reqs.filter((r) => {
|
|
58
|
+
const raw = Number(r?.maxAmountRequired ?? r?.amount ?? r?.maxAmount);
|
|
59
|
+
return Number.isFinite(raw) && raw > 0 && raw <= capBaseUnits;
|
|
60
|
+
});
|
|
61
|
+
this.lastSurvivingReqs = surviving;
|
|
62
|
+
return surviving;
|
|
63
|
+
};
|
|
53
64
|
this.payFetch = wrapFetchWithPaymentFromConfig(fetch, {
|
|
54
|
-
schemes: [{ network: "solana:*", client: new ExactSvmScheme(signer) }]
|
|
65
|
+
schemes: [{ network: "solana:*", client: new ExactSvmScheme(signer) }],
|
|
66
|
+
policies: [maxSpendPolicy]
|
|
55
67
|
});
|
|
56
68
|
logger.info(
|
|
57
69
|
`[agentfeed] ready \u2014 payer ${this.payerAddress.slice(0, 4)}\u2026${this.payerAddress.slice(-4)}, base ${this.baseUrl}, cap $${this.maxSpendUsd}/call`
|
|
@@ -126,8 +138,19 @@ var AgentFeedService = class _AgentFeedService extends Service {
|
|
|
126
138
|
if (!res.ok) {
|
|
127
139
|
return { ok: false, status: res.status, data, error: `AgentFeed HTTP ${res.status}` };
|
|
128
140
|
}
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
let paidUsd = 0;
|
|
142
|
+
if (settlement) {
|
|
143
|
+
const s = settlement;
|
|
144
|
+
let raw = Number(s?.amount ?? s?.paidAmount);
|
|
145
|
+
if (!Number.isFinite(raw) || raw <= 0) {
|
|
146
|
+
const net = String(s?.network ?? "");
|
|
147
|
+
const req = this.lastSurvivingReqs.find((r) => String(r?.network ?? "") === net) ?? this.lastSurvivingReqs[0];
|
|
148
|
+
raw = Number(req?.maxAmountRequired ?? req?.amount ?? req?.maxAmount);
|
|
149
|
+
}
|
|
150
|
+
paidUsd = Number.isFinite(raw) && raw > 0 ? raw / 10 ** USDC_DECIMALS : quotedUsd;
|
|
151
|
+
this.totalSpentUsd += paidUsd;
|
|
152
|
+
}
|
|
153
|
+
return { ok: true, status: res.status, data, paidUsd, settlement };
|
|
131
154
|
} catch (e) {
|
|
132
155
|
return { ok: false, status: 0, data: null, error: e?.message || String(e) };
|
|
133
156
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seekdaseek/plugin-agentfeed",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "elizaOS plugin for AgentFeed — paid crypto market data (liquidations, positioning, funding, token risk) over x402 micropayments on Solana. $0.001–$0.01 per call in USDC, no API keys, no subscriptions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|