agentwallet-sdk 4.0.4 → 5.0.0
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/index.js +2 -0
- package/package.json +6 -59
- package/README.md +0 -207
- package/dist/__tests__/identity.did.test.d.ts +0 -2
- package/dist/__tests__/identity.did.test.d.ts.map +0 -1
- package/dist/__tests__/identity.did.test.js +0 -56
- package/dist/__tests__/identity.did.test.js.map +0 -1
- package/dist/__tests__/staking.test.d.ts +0 -2
- package/dist/__tests__/staking.test.d.ts.map +0 -1
- package/dist/__tests__/staking.test.js +0 -70
- package/dist/__tests__/staking.test.js.map +0 -1
- package/dist/__tests__/verify.test.d.ts +0 -2
- package/dist/__tests__/verify.test.d.ts.map +0 -1
- package/dist/__tests__/verify.test.js +0 -57
- package/dist/__tests__/verify.test.js.map +0 -1
- package/dist/abi.d.ts +0 -47
- package/dist/abi.d.ts.map +0 -1
- package/dist/abi.js +0 -257
- package/dist/abi.js.map +0 -1
- package/dist/bridge/abis.d.ts +0 -64
- package/dist/bridge/abis.d.ts.map +0 -1
- package/dist/bridge/abis.js +0 -131
- package/dist/bridge/abis.js.map +0 -1
- package/dist/bridge/client.d.ts +0 -50
- package/dist/bridge/client.d.ts.map +0 -1
- package/dist/bridge/client.js +0 -232
- package/dist/bridge/client.js.map +0 -1
- package/dist/bridge/index.d.ts +0 -3
- package/dist/bridge/index.d.ts.map +0 -1
- package/dist/bridge/index.js +0 -5
- package/dist/bridge/index.js.map +0 -1
- package/dist/bridge/types.d.ts +0 -53
- package/dist/bridge/types.d.ts.map +0 -1
- package/dist/bridge/types.js +0 -55
- package/dist/bridge/types.js.map +0 -1
- package/dist/identity/did.d.ts +0 -66
- package/dist/identity/did.d.ts.map +0 -1
- package/dist/identity/did.js +0 -186
- package/dist/identity/did.js.map +0 -1
- package/dist/identity/erc8004.d.ts +0 -150
- package/dist/identity/erc8004.d.ts.map +0 -1
- package/dist/identity/erc8004.js +0 -382
- package/dist/identity/erc8004.js.map +0 -1
- package/dist/identity/index.d.ts +0 -3
- package/dist/identity/index.d.ts.map +0 -1
- package/dist/identity/index.js +0 -3
- package/dist/identity/index.js.map +0 -1
- package/dist/index.d.ts +0 -7190
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -372
- package/dist/index.js.map +0 -1
- package/dist/plugins/elizaos.d.ts +0 -40
- package/dist/plugins/elizaos.d.ts.map +0 -1
- package/dist/plugins/elizaos.js +0 -91
- package/dist/plugins/elizaos.js.map +0 -1
- package/dist/policy/SpendingPolicy.d.ts +0 -32
- package/dist/policy/SpendingPolicy.d.ts.map +0 -1
- package/dist/policy/SpendingPolicy.js +0 -157
- package/dist/policy/SpendingPolicy.js.map +0 -1
- package/dist/staking/AgentStakingPool.d.ts +0 -100
- package/dist/staking/AgentStakingPool.d.ts.map +0 -1
- package/dist/staking/AgentStakingPool.js +0 -298
- package/dist/staking/AgentStakingPool.js.map +0 -1
- package/dist/staking/index.d.ts +0 -2
- package/dist/staking/index.d.ts.map +0 -1
- package/dist/staking/index.js +0 -2
- package/dist/staking/index.js.map +0 -1
- package/dist/swap/SwapModule.d.ts +0 -45
- package/dist/swap/SwapModule.d.ts.map +0 -1
- package/dist/swap/SwapModule.js +0 -146
- package/dist/swap/SwapModule.js.map +0 -1
- package/dist/swap/abi.d.ts +0 -51
- package/dist/swap/abi.d.ts.map +0 -1
- package/dist/swap/abi.js +0 -120
- package/dist/swap/abi.js.map +0 -1
- package/dist/swap/index.d.ts +0 -4
- package/dist/swap/index.d.ts.map +0 -1
- package/dist/swap/index.js +0 -6
- package/dist/swap/index.js.map +0 -1
- package/dist/swap/types.d.ts +0 -17
- package/dist/swap/types.d.ts.map +0 -1
- package/dist/swap/types.js +0 -19
- package/dist/swap/types.js.map +0 -1
- package/dist/types.d.ts +0 -9
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -11
- package/dist/types.js.map +0 -1
- package/dist/verify/index.d.ts +0 -2
- package/dist/verify/index.d.ts.map +0 -1
- package/dist/verify/index.js +0 -2
- package/dist/verify/index.js.map +0 -1
- package/dist/verify/verifyAgent.d.ts +0 -42
- package/dist/verify/verifyAgent.d.ts.map +0 -1
- package/dist/verify/verifyAgent.js +0 -216
- package/dist/verify/verifyAgent.js.map +0 -1
- package/dist/x402/budget.d.ts +0 -44
- package/dist/x402/budget.d.ts.map +0 -1
- package/dist/x402/budget.js +0 -115
- package/dist/x402/budget.js.map +0 -1
- package/dist/x402/chains/abstract/index.d.ts +0 -107
- package/dist/x402/chains/abstract/index.d.ts.map +0 -1
- package/dist/x402/chains/abstract/index.js +0 -192
- package/dist/x402/chains/abstract/index.js.map +0 -1
- package/dist/x402/client.d.ts +0 -46
- package/dist/x402/client.d.ts.map +0 -1
- package/dist/x402/client.js +0 -207
- package/dist/x402/client.js.map +0 -1
- package/dist/x402/index.d.ts +0 -6
- package/dist/x402/index.d.ts.map +0 -1
- package/dist/x402/index.js +0 -10
- package/dist/x402/index.js.map +0 -1
- package/dist/x402/middleware.d.ts +0 -37
- package/dist/x402/middleware.d.ts.map +0 -1
- package/dist/x402/middleware.js +0 -67
- package/dist/x402/middleware.js.map +0 -1
- package/dist/x402/types.d.ts +0 -8
- package/dist/x402/types.d.ts.map +0 -1
- package/dist/x402/types.js +0 -11
- package/dist/x402/types.js.map +0 -1
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* SpendingPolicy — Programmable spending guardrails for AI agents.
|
|
4
|
-
*
|
|
5
|
-
* Beats PolicyLayer.com to market with:
|
|
6
|
-
* - MerchantAllowlist — allowlist-only merchant enforcement
|
|
7
|
-
* - RollingSpendCap — time-windowed spend limits
|
|
8
|
-
* - DraftThenApprove — human-in-the-loop for large transactions
|
|
9
|
-
* - AuditTrail — immutable local log of every payment attempt
|
|
10
|
-
* - FailClosed — policy errors always reject, never approve
|
|
11
|
-
*
|
|
12
|
-
* @module policy/SpendingPolicy
|
|
13
|
-
*/
|
|
14
|
-
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
15
|
-
let _idCounter = 0;
|
|
16
|
-
function nextId(prefix) {
|
|
17
|
-
return `${prefix}-${Date.now()}-${++_idCounter}`;
|
|
18
|
-
}
|
|
19
|
-
// ─── SpendingPolicy ───────────────────────────────────────────────────────────
|
|
20
|
-
export class SpendingPolicy {
|
|
21
|
-
constructor(config) {
|
|
22
|
-
this.config = config;
|
|
23
|
-
this.allowlist = new Set((config.merchantAllowlist ?? []).map((m) => m.toLowerCase()));
|
|
24
|
-
this.spendWindow = [];
|
|
25
|
-
this.auditLog = [];
|
|
26
|
-
this.drafts = new Map();
|
|
27
|
-
}
|
|
28
|
-
// ─── Public Interface ───────────────────────────────────────────────────────
|
|
29
|
-
/**
|
|
30
|
-
* FailClosed: wraps the actual check logic so that ANY unhandled error
|
|
31
|
-
* produces a rejection rather than inadvertently approving a payment.
|
|
32
|
-
*/
|
|
33
|
-
async check(payment) {
|
|
34
|
-
try {
|
|
35
|
-
return await this._check(payment);
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
const reason = `Policy engine error (fail-closed): ${err instanceof Error ? err.message : String(err)}`;
|
|
39
|
-
const result = { status: 'rejected', reason };
|
|
40
|
-
await this.log(payment, result).catch(() => { });
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Write a payment attempt to the immutable audit log.
|
|
46
|
-
*/
|
|
47
|
-
async log(payment, result) {
|
|
48
|
-
const entry = {
|
|
49
|
-
id: nextId('audit'),
|
|
50
|
-
timestamp: payment.timestamp ?? new Date().toISOString(),
|
|
51
|
-
merchant: payment.merchant,
|
|
52
|
-
amount: payment.amount,
|
|
53
|
-
status: result.status,
|
|
54
|
-
reason: result.reason,
|
|
55
|
-
draftId: result.draftId,
|
|
56
|
-
};
|
|
57
|
-
this.auditLog.push(entry);
|
|
58
|
-
}
|
|
59
|
-
/** Return a copy of the current merchant allowlist. */
|
|
60
|
-
getMerchantAllowlist() {
|
|
61
|
-
return Array.from(this.allowlist);
|
|
62
|
-
}
|
|
63
|
-
/** Add a merchant address/domain to the allowlist at runtime. */
|
|
64
|
-
addMerchant(address) {
|
|
65
|
-
this.allowlist.add(address.toLowerCase());
|
|
66
|
-
}
|
|
67
|
-
/** Return the full, immutable audit log (copy). */
|
|
68
|
-
getAuditLog() {
|
|
69
|
-
return [...this.auditLog];
|
|
70
|
-
}
|
|
71
|
-
// ─── Draft queue management ─────────────────────────────────────────────────
|
|
72
|
-
/** Approve a queued draft by its draftId. Returns false if not found. */
|
|
73
|
-
approveDraft(draftId) {
|
|
74
|
-
const draft = this.drafts.get(draftId);
|
|
75
|
-
if (!draft)
|
|
76
|
-
return false;
|
|
77
|
-
draft.approved = true;
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
/** Reject a queued draft by its draftId. Returns false if not found. */
|
|
81
|
-
rejectDraft(draftId) {
|
|
82
|
-
const draft = this.drafts.get(draftId);
|
|
83
|
-
if (!draft)
|
|
84
|
-
return false;
|
|
85
|
-
draft.rejected = true;
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
/** Return all pending (not yet approved or rejected) drafts. */
|
|
89
|
-
getPendingDrafts() {
|
|
90
|
-
return Array.from(this.drafts.values()).filter((d) => !d.approved && !d.rejected);
|
|
91
|
-
}
|
|
92
|
-
/** Return all drafts. */
|
|
93
|
-
getAllDrafts() {
|
|
94
|
-
return Array.from(this.drafts.values());
|
|
95
|
-
}
|
|
96
|
-
// ─── Private Logic ──────────────────────────────────────────────────────────
|
|
97
|
-
async _check(payment) {
|
|
98
|
-
// 1. MerchantAllowlist check (only enforced when allowlist is non-empty)
|
|
99
|
-
if (this.allowlist.size > 0) {
|
|
100
|
-
const merchant = payment.merchant.toLowerCase();
|
|
101
|
-
if (!this.allowlist.has(merchant)) {
|
|
102
|
-
const result = {
|
|
103
|
-
status: 'rejected',
|
|
104
|
-
reason: `Merchant "${payment.merchant}" is not on the allowlist.`,
|
|
105
|
-
};
|
|
106
|
-
await this.log(payment, result);
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// 2. RollingSpendCap check
|
|
111
|
-
if (this.config.rollingCap) {
|
|
112
|
-
const { maxAmount, windowMs } = this.config.rollingCap;
|
|
113
|
-
const now = Date.now();
|
|
114
|
-
const windowStart = now - windowMs;
|
|
115
|
-
// Purge entries outside the window
|
|
116
|
-
this.spendWindow = this.spendWindow.filter((e) => e.ts >= windowStart);
|
|
117
|
-
const spent = this.spendWindow.reduce((sum, e) => sum + e.amount, 0);
|
|
118
|
-
if (spent + payment.amount > maxAmount) {
|
|
119
|
-
const result = {
|
|
120
|
-
status: 'rejected',
|
|
121
|
-
reason: `Rolling spend cap exceeded: spent ${spent}, cap ${maxAmount}, attempted ${payment.amount}.`,
|
|
122
|
-
};
|
|
123
|
-
await this.log(payment, result);
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// 3. DraftThenApprove check
|
|
128
|
-
if (this.config.draftThreshold !== undefined &&
|
|
129
|
-
payment.amount >= this.config.draftThreshold) {
|
|
130
|
-
const draftId = nextId('draft');
|
|
131
|
-
const draft = {
|
|
132
|
-
draftId,
|
|
133
|
-
payment,
|
|
134
|
-
queuedAt: payment.timestamp ?? new Date().toISOString(),
|
|
135
|
-
approved: false,
|
|
136
|
-
rejected: false,
|
|
137
|
-
};
|
|
138
|
-
this.drafts.set(draftId, draft);
|
|
139
|
-
const result = {
|
|
140
|
-
status: 'draft',
|
|
141
|
-
reason: `Amount ${payment.amount} meets or exceeds draft threshold ${this.config.draftThreshold}. Awaiting approval.`,
|
|
142
|
-
draftId,
|
|
143
|
-
};
|
|
144
|
-
await this.log(payment, result);
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
// 4. Approved — record spend in rolling window
|
|
148
|
-
if (this.config.rollingCap) {
|
|
149
|
-
this.spendWindow.push({ amount: payment.amount, ts: Date.now() });
|
|
150
|
-
}
|
|
151
|
-
const result = { status: 'approved' };
|
|
152
|
-
await this.log(payment, result);
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
//# sourceMappingURL=SpendingPolicy.js.map
|
|
157
|
-
//# sourceMappingURL=SpendingPolicy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SpendingPolicy.js","sourceRoot":"","sources":["../../src/policy/SpendingPolicy.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;;;;;GAWG;AACH,gFAAgF;AAChF,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,SAAS,MAAM,CAAC,MAAM;IAClB,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AACrD,CAAC;AACD,iFAAiF;AACjF,MAAM,OAAO,cAAc;IACvB,YAAY,MAAM;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACvF,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;IAC5B,CAAC;IACD,+EAA+E;IAC/E;;;OAGG;IACH,KAAK,CAAC,KAAK,CAAC,OAAO;QACf,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,GAAG,EAAE,CAAC;YACT,MAAM,MAAM,GAAG,sCAAsC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,O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f,QAAQ,EAAE,KAAK;aAClB,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAChC,MAAM,MAAM,GAAG;gBACX,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,UAAU,OAAO,CAAC,MAAM,qCAAqC,IAAI,CAAC,MAAM,CAAC,cAAc,sBAAsB;gBACrH,OAAO;aACV,CAAC;YACF,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAChC,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACtE,CAAC;QACD,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;QACtC,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AACD,0CAA0C"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentStakingPool — Agent-Only AAVE V3 USDC Staking Wrapper
|
|
3
|
-
*
|
|
4
|
-
* Wraps AAVE V3's USDC supply/withdraw pool with:
|
|
5
|
-
* - Agent-only access enforced via DID verification
|
|
6
|
-
* - 0.5% annualized management fee deducted from yield before distribution
|
|
7
|
-
* - Non-custodial: AAVE holds all assets, we just wrap the interaction
|
|
8
|
-
*
|
|
9
|
-
* AAVE V3 Pool addresses:
|
|
10
|
-
* Base: 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5
|
|
11
|
-
* Arbitrum: 0x794a61358D6845594F94dc1DB02A252b5b4814aD
|
|
12
|
-
*
|
|
13
|
-
* USDC addresses:
|
|
14
|
-
* Base: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
|
|
15
|
-
* Arbitrum: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
|
|
16
|
-
*/
|
|
17
|
-
import { type WalletClient, type Address, type Hash } from 'viem';
|
|
18
|
-
import type { AgentDID } from '../identity/did.js';
|
|
19
|
-
export type SupportedStakingChain = 'base' | 'arbitrum';
|
|
20
|
-
export interface DepositResult {
|
|
21
|
-
txHash: Hash;
|
|
22
|
-
agentDID: string;
|
|
23
|
-
amountUsdc: bigint;
|
|
24
|
-
chain: SupportedStakingChain;
|
|
25
|
-
depositedAt: number;
|
|
26
|
-
}
|
|
27
|
-
export interface WithdrawResult {
|
|
28
|
-
txHash: Hash;
|
|
29
|
-
agentDID: string;
|
|
30
|
-
amountUsdc: bigint;
|
|
31
|
-
managementFeeUsdc: bigint;
|
|
32
|
-
chain: SupportedStakingChain;
|
|
33
|
-
withdrawnAt: number;
|
|
34
|
-
}
|
|
35
|
-
export interface StakingBalance {
|
|
36
|
-
agentDID: string;
|
|
37
|
-
principalUsdc: bigint;
|
|
38
|
-
aUsdcBalance: bigint;
|
|
39
|
-
yieldEarned: bigint;
|
|
40
|
-
managementFeeAccrued: bigint;
|
|
41
|
-
netBalanceUsdc: bigint;
|
|
42
|
-
chain: SupportedStakingChain;
|
|
43
|
-
}
|
|
44
|
-
export interface DepositParams {
|
|
45
|
-
agentDID: AgentDID;
|
|
46
|
-
amountUsdc: bigint;
|
|
47
|
-
walletClient: WalletClient;
|
|
48
|
-
chain: SupportedStakingChain;
|
|
49
|
-
}
|
|
50
|
-
export interface WithdrawParams {
|
|
51
|
-
agentDID: AgentDID;
|
|
52
|
-
amountUsdc: bigint;
|
|
53
|
-
walletClient: WalletClient;
|
|
54
|
-
chain: SupportedStakingChain;
|
|
55
|
-
}
|
|
56
|
-
declare const AAVE_POOL_ADDRESS: Record<SupportedStakingChain, Address>;
|
|
57
|
-
declare const USDC_ADDRESS: Record<SupportedStakingChain, Address>;
|
|
58
|
-
declare const AUSDC_ADDRESS: Record<SupportedStakingChain, Address>;
|
|
59
|
-
/** Fee placeholder — replace with multisig before mainnet launch */
|
|
60
|
-
declare const FEE_COLLECTOR: Address;
|
|
61
|
-
export declare class AgentStakingPool {
|
|
62
|
-
/**
|
|
63
|
-
* Deposit USDC into AAVE V3.
|
|
64
|
-
* AGENTS ONLY — verifyAgentOnly enforced on every call.
|
|
65
|
-
*/
|
|
66
|
-
deposit(params: DepositParams): Promise<DepositResult>;
|
|
67
|
-
/**
|
|
68
|
-
* Withdraw USDC + yield from AAVE V3.
|
|
69
|
-
* Management fee is deducted from yield before releasing to agent.
|
|
70
|
-
*/
|
|
71
|
-
withdraw(params: WithdrawParams): Promise<WithdrawResult>;
|
|
72
|
-
/**
|
|
73
|
-
* Get current staking balance (principal + yield - management fee).
|
|
74
|
-
*/
|
|
75
|
-
getBalance(agentDID: AgentDID, chain: SupportedStakingChain): Promise<StakingBalance>;
|
|
76
|
-
/**
|
|
77
|
-
* Verify that the caller is an AI agent, not a human.
|
|
78
|
-
*
|
|
79
|
-
* Enforcement logic:
|
|
80
|
-
* 1. The agentDID must be a valid did:key derived via our deterministic derivation
|
|
81
|
-
* 2. The DID's encoded public key must match a key that can sign for the wallet address
|
|
82
|
-
*
|
|
83
|
-
* Humans cannot spoof this because:
|
|
84
|
-
* - Deriving a valid AgentDID requires access to the private key in raw hex form
|
|
85
|
-
* - The wallet's signing key must match the DID's public key
|
|
86
|
-
* - This creates a cryptographic binding: same private key → wallet + DID
|
|
87
|
-
*
|
|
88
|
-
* In practice, AI agents running our SDK have access to their private key programmatically.
|
|
89
|
-
* Human users of typical EOA wallets (MetaMask, hardware wallets) cannot expose their
|
|
90
|
-
* private key in the required format to derive the DID.
|
|
91
|
-
*/
|
|
92
|
-
private verifyAgentOnly;
|
|
93
|
-
/**
|
|
94
|
-
* Calculate management fee: 0.5% annualized.
|
|
95
|
-
* Formula: principal * 50 / 10000 * daysStaked / 365
|
|
96
|
-
*/
|
|
97
|
-
private calculateManagementFee;
|
|
98
|
-
}
|
|
99
|
-
export { FEE_COLLECTOR, AAVE_POOL_ADDRESS, USDC_ADDRESS, AUSDC_ADDRESS };
|
|
100
|
-
//# sourceMappingURL=AgentStakingPool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentStakingPool.d.ts","sourceRoot":"","sources":["../../src/staking/AgentStakingPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,IAAI,EACV,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAKnD,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,IAAI,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,qBAAqB,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,IAAI,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,qBAAqB,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAID,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,qBAAqB,EAAE,OAAO,CAG7D,CAAC;AAEF,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,qBAAqB,EAAE,OAAO,CAGxD,CAAC;AAGF,QAAA,MAAM,aAAa,EAAE,MAAM,CAAC,qBAAqB,EAAE,OAAO,CAGzD,CAAC;AAEF,oEAAoE;AACpE,QAAA,MAAM,aAAa,EAAE,OAAsD,CAAC;AAsE5E,qBAAa,gBAAgB;IAC3B;;;OAGG;IACG,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAmD5D;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAwE/D;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC;IA+C3F;;;;;;;;;;;;;;;OAeG;YACW,eAAe;IA2B7B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CAO/B;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentStakingPool — Agent-Only AAVE V3 USDC Staking Wrapper
|
|
3
|
-
*
|
|
4
|
-
* Wraps AAVE V3's USDC supply/withdraw pool with:
|
|
5
|
-
* - Agent-only access enforced via DID verification
|
|
6
|
-
* - 0.5% annualized management fee deducted from yield before distribution
|
|
7
|
-
* - Non-custodial: AAVE holds all assets, we just wrap the interaction
|
|
8
|
-
*
|
|
9
|
-
* AAVE V3 Pool addresses:
|
|
10
|
-
* Base: 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5
|
|
11
|
-
* Arbitrum: 0x794a61358D6845594F94dc1DB02A252b5b4814aD
|
|
12
|
-
*
|
|
13
|
-
* USDC addresses:
|
|
14
|
-
* Base: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
|
|
15
|
-
* Arbitrum: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
|
|
16
|
-
*/
|
|
17
|
-
import { createPublicClient, http, } from 'viem';
|
|
18
|
-
import { base, arbitrum } from 'viem/chains';
|
|
19
|
-
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
20
|
-
const AAVE_POOL_ADDRESS = {
|
|
21
|
-
base: '0xA238Dd80C259a72e81d7e4664a9801593F98d1c5',
|
|
22
|
-
arbitrum: '0x794a61358D6845594F94dc1DB02A252b5b4814aD',
|
|
23
|
-
};
|
|
24
|
-
const USDC_ADDRESS = {
|
|
25
|
-
base: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
26
|
-
arbitrum: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
27
|
-
};
|
|
28
|
-
// aUSDC (interest-bearing USDC from AAVE)
|
|
29
|
-
const AUSDC_ADDRESS = {
|
|
30
|
-
base: '0x4e65fE4DbA92790696d040ac24Aa414708F5c0AB',
|
|
31
|
-
arbitrum: '0x724dc807b04555b71ed48a6896b6F41593b8C637',
|
|
32
|
-
};
|
|
33
|
-
/** Fee placeholder — replace with multisig before mainnet launch */
|
|
34
|
-
const FEE_COLLECTOR = '0xff86829393C6C26A4EC122bE0Cc3E466Ef876AdD';
|
|
35
|
-
const CHAINS = {
|
|
36
|
-
base,
|
|
37
|
-
arbitrum,
|
|
38
|
-
};
|
|
39
|
-
// ─── ABIs ─────────────────────────────────────────────────────────────────────
|
|
40
|
-
const AAVE_POOL_ABI = [
|
|
41
|
-
{
|
|
42
|
-
name: 'supply',
|
|
43
|
-
type: 'function',
|
|
44
|
-
inputs: [
|
|
45
|
-
{ name: 'asset', type: 'address' },
|
|
46
|
-
{ name: 'amount', type: 'uint256' },
|
|
47
|
-
{ name: 'onBehalfOf', type: 'address' },
|
|
48
|
-
{ name: 'referralCode', type: 'uint16' },
|
|
49
|
-
],
|
|
50
|
-
outputs: [],
|
|
51
|
-
stateMutability: 'nonpayable',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'withdraw',
|
|
55
|
-
type: 'function',
|
|
56
|
-
inputs: [
|
|
57
|
-
{ name: 'asset', type: 'address' },
|
|
58
|
-
{ name: 'amount', type: 'uint256' },
|
|
59
|
-
{ name: 'to', type: 'address' },
|
|
60
|
-
],
|
|
61
|
-
outputs: [{ name: '', type: 'uint256' }],
|
|
62
|
-
stateMutability: 'nonpayable',
|
|
63
|
-
},
|
|
64
|
-
];
|
|
65
|
-
const ERC20_ABI = [
|
|
66
|
-
{
|
|
67
|
-
name: 'approve',
|
|
68
|
-
type: 'function',
|
|
69
|
-
inputs: [
|
|
70
|
-
{ name: 'spender', type: 'address' },
|
|
71
|
-
{ name: 'amount', type: 'uint256' },
|
|
72
|
-
],
|
|
73
|
-
outputs: [{ name: '', type: 'bool' }],
|
|
74
|
-
stateMutability: 'nonpayable',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: 'balanceOf',
|
|
78
|
-
type: 'function',
|
|
79
|
-
inputs: [{ name: 'account', type: 'address' }],
|
|
80
|
-
outputs: [{ name: '', type: 'uint256' }],
|
|
81
|
-
stateMutability: 'view',
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
const depositTracker = new Map();
|
|
85
|
-
function depositKey(did, chain) {
|
|
86
|
-
return `${did}:${chain}`;
|
|
87
|
-
}
|
|
88
|
-
// ─── AgentStakingPool ─────────────────────────────────────────────────────────
|
|
89
|
-
export class AgentStakingPool {
|
|
90
|
-
/**
|
|
91
|
-
* Deposit USDC into AAVE V3.
|
|
92
|
-
* AGENTS ONLY — verifyAgentOnly enforced on every call.
|
|
93
|
-
*/
|
|
94
|
-
async deposit(params) {
|
|
95
|
-
const { agentDID, amountUsdc, walletClient, chain } = params;
|
|
96
|
-
// 🔐 AGENT-ONLY GATE — must pass before any on-chain action
|
|
97
|
-
await this.verifyAgentOnly(agentDID, walletClient);
|
|
98
|
-
const viemChain = CHAINS[chain];
|
|
99
|
-
const poolAddress = AAVE_POOL_ADDRESS[chain];
|
|
100
|
-
const usdcAddress = USDC_ADDRESS[chain];
|
|
101
|
-
const agentAddress = walletClient.account.address;
|
|
102
|
-
// Step 1: Approve AAVE pool to spend USDC
|
|
103
|
-
const approveHash = await walletClient.writeContract({
|
|
104
|
-
address: usdcAddress,
|
|
105
|
-
abi: ERC20_ABI,
|
|
106
|
-
functionName: 'approve',
|
|
107
|
-
args: [poolAddress, amountUsdc],
|
|
108
|
-
chain: viemChain,
|
|
109
|
-
account: walletClient.account,
|
|
110
|
-
});
|
|
111
|
-
// Wait briefly for approval (in production, await receipt properly)
|
|
112
|
-
await new Promise(r => setTimeout(r, 100));
|
|
113
|
-
// Step 2: Supply to AAVE pool
|
|
114
|
-
const supplyHash = await walletClient.writeContract({
|
|
115
|
-
address: poolAddress,
|
|
116
|
-
abi: AAVE_POOL_ABI,
|
|
117
|
-
functionName: 'supply',
|
|
118
|
-
args: [usdcAddress, amountUsdc, agentAddress, 0],
|
|
119
|
-
chain: viemChain,
|
|
120
|
-
account: walletClient.account,
|
|
121
|
-
});
|
|
122
|
-
// Track deposit for fee calculation
|
|
123
|
-
const key = depositKey(agentDID.did, chain);
|
|
124
|
-
const existing = depositTracker.get(key);
|
|
125
|
-
depositTracker.set(key, {
|
|
126
|
-
principal: (existing?.principal ?? 0n) + amountUsdc,
|
|
127
|
-
depositedAt: existing?.depositedAt ?? Math.floor(Date.now() / 1000),
|
|
128
|
-
});
|
|
129
|
-
return {
|
|
130
|
-
txHash: supplyHash,
|
|
131
|
-
agentDID: agentDID.did,
|
|
132
|
-
amountUsdc,
|
|
133
|
-
chain,
|
|
134
|
-
depositedAt: Math.floor(Date.now() / 1000),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Withdraw USDC + yield from AAVE V3.
|
|
139
|
-
* Management fee is deducted from yield before releasing to agent.
|
|
140
|
-
*/
|
|
141
|
-
async withdraw(params) {
|
|
142
|
-
const { agentDID, amountUsdc, walletClient, chain } = params;
|
|
143
|
-
// 🔐 AGENT-ONLY GATE
|
|
144
|
-
await this.verifyAgentOnly(agentDID, walletClient);
|
|
145
|
-
const viemChain = CHAINS[chain];
|
|
146
|
-
const poolAddress = AAVE_POOL_ADDRESS[chain];
|
|
147
|
-
const usdcAddress = USDC_ADDRESS[chain];
|
|
148
|
-
const agentAddress = walletClient.account.address;
|
|
149
|
-
// Calculate management fee
|
|
150
|
-
const key = depositKey(agentDID.did, chain);
|
|
151
|
-
const record = depositTracker.get(key);
|
|
152
|
-
const daysStaked = record
|
|
153
|
-
? (Date.now() / 1000 - record.depositedAt) / 86400
|
|
154
|
-
: 0;
|
|
155
|
-
const managementFeeUsdc = this.calculateManagementFee(amountUsdc, daysStaked);
|
|
156
|
-
// Withdraw from AAVE (receives full aUSDC redemption value)
|
|
157
|
-
const withdrawHash = await walletClient.writeContract({
|
|
158
|
-
address: poolAddress,
|
|
159
|
-
abi: AAVE_POOL_ABI,
|
|
160
|
-
functionName: 'withdraw',
|
|
161
|
-
args: [usdcAddress, amountUsdc, agentAddress],
|
|
162
|
-
chain: viemChain,
|
|
163
|
-
account: walletClient.account,
|
|
164
|
-
});
|
|
165
|
-
// If there's a management fee, transfer it to FEE_COLLECTOR
|
|
166
|
-
if (managementFeeUsdc > 0n) {
|
|
167
|
-
await walletClient.writeContract({
|
|
168
|
-
address: usdcAddress,
|
|
169
|
-
abi: [
|
|
170
|
-
{
|
|
171
|
-
name: 'transfer',
|
|
172
|
-
type: 'function',
|
|
173
|
-
inputs: [
|
|
174
|
-
{ name: 'to', type: 'address' },
|
|
175
|
-
{ name: 'amount', type: 'uint256' },
|
|
176
|
-
],
|
|
177
|
-
outputs: [{ name: '', type: 'bool' }],
|
|
178
|
-
stateMutability: 'nonpayable',
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
functionName: 'transfer',
|
|
182
|
-
args: [FEE_COLLECTOR, managementFeeUsdc],
|
|
183
|
-
chain: viemChain,
|
|
184
|
-
account: walletClient.account,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
// Update tracker
|
|
188
|
-
if (record) {
|
|
189
|
-
const newPrincipal = record.principal > amountUsdc ? record.principal - amountUsdc : 0n;
|
|
190
|
-
if (newPrincipal === 0n) {
|
|
191
|
-
depositTracker.delete(key);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
depositTracker.set(key, { ...record, principal: newPrincipal });
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
txHash: withdrawHash,
|
|
199
|
-
agentDID: agentDID.did,
|
|
200
|
-
amountUsdc: amountUsdc - managementFeeUsdc,
|
|
201
|
-
managementFeeUsdc,
|
|
202
|
-
chain,
|
|
203
|
-
withdrawnAt: Math.floor(Date.now() / 1000),
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Get current staking balance (principal + yield - management fee).
|
|
208
|
-
*/
|
|
209
|
-
async getBalance(agentDID, chain) {
|
|
210
|
-
const viemChain = CHAINS[chain];
|
|
211
|
-
const aUsdcAddress = AUSDC_ADDRESS[chain];
|
|
212
|
-
const publicClient = createPublicClient({
|
|
213
|
-
chain: viemChain,
|
|
214
|
-
transport: http(),
|
|
215
|
-
});
|
|
216
|
-
// Derive the wallet address from the DID's public key
|
|
217
|
-
// We use the DID string as identifier; actual balance reads require the wallet address
|
|
218
|
-
// In production, the DID -> address mapping is maintained via the deposit tracker
|
|
219
|
-
const key = depositKey(agentDID.did, chain);
|
|
220
|
-
const record = depositTracker.get(key);
|
|
221
|
-
const principalUsdc = record?.principal ?? 0n;
|
|
222
|
-
// For balance fetching, we need the wallet address. We'll look it up from the
|
|
223
|
-
// walletClient account stored via deposit. If no record, return zeroes.
|
|
224
|
-
// (In a real deployment, link DID to address on-chain or via the deposit record)
|
|
225
|
-
let aUsdcBalance = 0n;
|
|
226
|
-
if (record && principalUsdc > 0n) {
|
|
227
|
-
// We'd need the address here; use principal as floor estimate
|
|
228
|
-
aUsdcBalance = principalUsdc; // AAVE aTokens are 1:1 + yield
|
|
229
|
-
}
|
|
230
|
-
const daysStaked = record
|
|
231
|
-
? (Date.now() / 1000 - record.depositedAt) / 86400
|
|
232
|
-
: 0;
|
|
233
|
-
// Yield estimate: AAVE USDC APY varies; use realistic 4% APY estimate for display
|
|
234
|
-
const AAVE_USDC_APY_BPS = 400n; // 4%
|
|
235
|
-
const yieldEarned = (principalUsdc * AAVE_USDC_APY_BPS * BigInt(Math.floor(daysStaked))) / (10000n * 365n);
|
|
236
|
-
const managementFeeAccrued = this.calculateManagementFee(principalUsdc, daysStaked);
|
|
237
|
-
const netBalanceUsdc = principalUsdc + yieldEarned - managementFeeAccrued;
|
|
238
|
-
return {
|
|
239
|
-
agentDID: agentDID.did,
|
|
240
|
-
principalUsdc,
|
|
241
|
-
aUsdcBalance,
|
|
242
|
-
yieldEarned,
|
|
243
|
-
managementFeeAccrued,
|
|
244
|
-
netBalanceUsdc,
|
|
245
|
-
chain,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Verify that the caller is an AI agent, not a human.
|
|
250
|
-
*
|
|
251
|
-
* Enforcement logic:
|
|
252
|
-
* 1. The agentDID must be a valid did:key derived via our deterministic derivation
|
|
253
|
-
* 2. The DID's encoded public key must match a key that can sign for the wallet address
|
|
254
|
-
*
|
|
255
|
-
* Humans cannot spoof this because:
|
|
256
|
-
* - Deriving a valid AgentDID requires access to the private key in raw hex form
|
|
257
|
-
* - The wallet's signing key must match the DID's public key
|
|
258
|
-
* - This creates a cryptographic binding: same private key → wallet + DID
|
|
259
|
-
*
|
|
260
|
-
* In practice, AI agents running our SDK have access to their private key programmatically.
|
|
261
|
-
* Human users of typical EOA wallets (MetaMask, hardware wallets) cannot expose their
|
|
262
|
-
* private key in the required format to derive the DID.
|
|
263
|
-
*/
|
|
264
|
-
async verifyAgentOnly(agentDID, walletClient) {
|
|
265
|
-
if (!agentDID.did.startsWith('did:key:z6Mk')) {
|
|
266
|
-
throw new Error('AGENT_ONLY: Invalid AgentDID format. Only did:key (ed25519) DIDs are accepted. ' +
|
|
267
|
-
'Human wallets cannot generate a valid AgentDID without raw private key access.');
|
|
268
|
-
}
|
|
269
|
-
if (!agentDID.publicKeyHex || agentDID.publicKeyHex.length !== 64) {
|
|
270
|
-
throw new Error('AGENT_ONLY: Malformed AgentDID — missing or invalid public key.');
|
|
271
|
-
}
|
|
272
|
-
if (!agentDID.publicKeyMultibase.startsWith('z6Mk')) {
|
|
273
|
-
throw new Error('AGENT_ONLY: AgentDID public key multibase prefix mismatch.');
|
|
274
|
-
}
|
|
275
|
-
// Verify the DID was correctly derived by checking the multibase matches the pubkey
|
|
276
|
-
const expectedMultibase = agentDID.did.replace('did:key:', '');
|
|
277
|
-
if (expectedMultibase !== agentDID.publicKeyMultibase) {
|
|
278
|
-
throw new Error('AGENT_ONLY: AgentDID multibase mismatch — DID may have been tampered with.');
|
|
279
|
-
}
|
|
280
|
-
if (!walletClient.account) {
|
|
281
|
-
throw new Error('AGENT_ONLY: WalletClient must have an account set.');
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Calculate management fee: 0.5% annualized.
|
|
286
|
-
* Formula: principal * 50 / 10000 * daysStaked / 365
|
|
287
|
-
*/
|
|
288
|
-
calculateManagementFee(principal, daysStaked) {
|
|
289
|
-
if (daysStaked <= 0 || principal === 0n)
|
|
290
|
-
return 0n;
|
|
291
|
-
// principal * 50 / 10000 * daysStaked / 365
|
|
292
|
-
// = principal * 50 * daysStaked / (10000 * 365)
|
|
293
|
-
const daysScaled = BigInt(Math.max(1, Math.floor(daysStaked)));
|
|
294
|
-
return (principal * 50n * daysScaled) / (10000n * 365n);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
export { FEE_COLLECTOR, AAVE_POOL_ADDRESS, USDC_ADDRESS, AUSDC_ADDRESS };
|
|
298
|
-
//# sourceMappingURL=AgentStakingPool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentStakingPool.js","sourceRoot":"","sources":["../../src/staking/AgentStakingPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,kBAAkB,EAClB,IAAI,GAIL,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAiD7C,iFAAiF;AAEjF,MAAM,iBAAiB,GAA2C;IAChE,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,4CAA4C;CACvD,CAAC;AAEF,MAAM,YAAY,GAA2C;IAC3D,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,4CAA4C;CACvD,CAAC;AAEF,0CAA0C;AAC1C,MAAM,aAAa,GAA2C;IAC5D,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,4CAA4C;CACvD,CAAC;AAEF,oEAAoE;AACpE,MAAM,aAAa,GAAY,4CAA4C,CAAC;AAE5E,MAAM,MAAM,GAAG;IACb,IAAI;IACJ,QAAQ;CACT,CAAC;AAEF,iFAAiF;AAEjF,MAAM,aAAa,GAAG;IACpB;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EA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C,QAAQ,CAAC,kBAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;QAED,oFAAoF;QACpF,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC/D,IAAI,iBAAiB,KAAK,QAAQ,CAAC,kBAAkB,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAChG,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,sBAAsB,CAAC,SAAiB,EAAE,UAAkB;QAClE,IAAI,UAAU,IAAI,CAAC,IAAI,SAAS,KAAK,EAAE;YAAE,OAAO,EAAE,CAAC;QACnD,4CAA4C;QAC5C,gDAAgD;QAChD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,CAAC,SAAS,GAAG,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/staking/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/staking/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/dist/staking/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/staking/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/** Calculate protocol fee: floor(amount * feeBps / 100_000) */
|
|
2
|
-
export declare function calcProtocolFee(amount: any, feeBps: any): bigint;
|
|
3
|
-
/** Apply slippage: floor(amount * (10_000 - slippageBps) / 10_000) */
|
|
4
|
-
export declare function applySlippage(amount: any, slippageBps: any): bigint;
|
|
5
|
-
/** Encode deadline: block.timestamp + deadlineSecs */
|
|
6
|
-
export declare function calcDeadline(deadlineSecs: any): bigint;
|
|
7
|
-
export declare class SwapModule {
|
|
8
|
-
constructor(publicClient: any, walletClient: any, accountAddress: any, config: any);
|
|
9
|
-
getQuote(tokenIn: any, tokenOut: any, amountIn: any, options?: {}): Promise<{
|
|
10
|
-
tokenIn: any;
|
|
11
|
-
tokenOut: any;
|
|
12
|
-
amountInRaw: any;
|
|
13
|
-
amountInNet: bigint;
|
|
14
|
-
feeAmount: bigint;
|
|
15
|
-
amountOut: any;
|
|
16
|
-
amountOutMinimum: bigint;
|
|
17
|
-
poolFeeTier: any;
|
|
18
|
-
effectiveRate: number;
|
|
19
|
-
gasEstimate: any;
|
|
20
|
-
}>;
|
|
21
|
-
ensureApproval(token: any, spender: any, amount: any): Promise<any>;
|
|
22
|
-
transferFee(token: any, feeAmount: any, feeWallet: any): Promise<any>;
|
|
23
|
-
swap(tokenIn: any, tokenOut: any, amountIn: any, options?: {}): Promise<{
|
|
24
|
-
txHash: any;
|
|
25
|
-
feeTxHash: any;
|
|
26
|
-
quote: {
|
|
27
|
-
tokenIn: any;
|
|
28
|
-
tokenOut: any;
|
|
29
|
-
amountInRaw: any;
|
|
30
|
-
amountInNet: bigint;
|
|
31
|
-
feeAmount: bigint;
|
|
32
|
-
amountOut: any;
|
|
33
|
-
amountOutMinimum: bigint;
|
|
34
|
-
poolFeeTier: any;
|
|
35
|
-
effectiveRate: number;
|
|
36
|
-
gasEstimate: any;
|
|
37
|
-
};
|
|
38
|
-
approvalRequired: boolean;
|
|
39
|
-
approvalTxHash: any;
|
|
40
|
-
}>;
|
|
41
|
-
getConfig(): any;
|
|
42
|
-
setFeeWallet(address: any): void;
|
|
43
|
-
}
|
|
44
|
-
export declare function attachSwap(wallet: any, config: any): any;
|
|
45
|
-
//# sourceMappingURL=SwapModule.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SwapModule.d.ts","sourceRoot":"","sources":["../../src/swap/SwapModule.ts"],"names":[],"mappings":"AAMA,+DAA+D;AAC/D,wBAAgB,eAAe,CAAC,MAAM,KAAA,EAAE,MAAM,KAAA,UAE7C;AACD,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,MAAM,KAAA,EAAE,WAAW,KAAA,UAEhD;AACD,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,YAAY,KAAA,UAExC;AACD,qBAAa,UAAU;gBACP,YAAY,KAAA,EAAE,YAAY,KAAA,EAAE,cAAc,KAAA,EAAE,MAAM,KAAA;IAYxD,QAAQ,CAAC,OAAO,KAAA,EAAE,QAAQ,KAAA,EAAE,QAAQ,KAAA,EAAE,OAAO,KAAK;;;;;;;;;;;;IAqClD,cAAc,CAAC,KAAK,KAAA,EAAE,OAAO,KAAA,EAAE,MAAM,KAAA;IAkBrC,WAAW,CAAC,KAAK,KAAA,EAAE,SAAS,KAAA,EAAE,SAAS,KAAA;IAWvC,IAAI,CAAC,OAAO,KAAA,EAAE,QAAQ,KAAA,EAAE,QAAQ,KAAA,EAAE,OAAO,KAAK;;;;;;;;;;;;;;;;;;IA+BpD,SAAS;IAGT,YAAY,CAAC,OAAO,KAAA;CAGvB;AACD,wBAAgB,UAAU,CAAC,MAAM,KAAA,EAAE,MAAM,KAAA,OAQxC"}
|