@elizaos/plugin-wallet 2.0.0-beta.1
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/LICENSE +21 -0
- package/README.md +64 -0
- package/auto-enable.ts +76 -0
- package/dist/LpManagementService-BWrQ5-cO.mjs +353 -0
- package/dist/MockLpService-D_Apn4Fd.mjs +99 -0
- package/dist/aerodrome-CfnESC32.mjs +890 -0
- package/dist/chunk-hT5z_Zn9.mjs +35 -0
- package/dist/index.d.mts +34727 -0
- package/dist/index.mjs +21590 -0
- package/dist/lib/server-wallet-trade.d.mts +34 -0
- package/dist/lib/server-wallet-trade.mjs +306 -0
- package/dist/meteora-BPX39hZo.mjs +22640 -0
- package/dist/orca-Bybp1HXO.mjs +249 -0
- package/dist/pancakeswp-CkEXlXti.mjs +604 -0
- package/dist/plugin-ZO_MTyd0.mjs +529 -0
- package/dist/raydium-rfaM9yEf.mjs +539 -0
- package/dist/sdk/index.d.mts +32492 -0
- package/dist/sdk/index.mjs +6415 -0
- package/dist/types-D5252NZk.mjs +487 -0
- package/dist/uniswap-CReXgXVN.mjs +573 -0
- package/dist/wallet-action.d.mts +6 -0
- package/dist/wallet-action.mjs +820 -0
- package/package.json +152 -0
- package/src/actions/failure-codes.ts +79 -0
- package/src/actions/index.ts +1 -0
- package/src/analytics/birdeye/actions/wallet-search-address.ts +9 -0
- package/src/analytics/birdeye/birdeye-task.ts +175 -0
- package/src/analytics/birdeye/birdeye.ts +813 -0
- package/src/analytics/birdeye/constants.ts +74 -0
- package/src/analytics/birdeye/providers/agent-portfolio-provider.ts +18 -0
- package/src/analytics/birdeye/providers/market.ts +227 -0
- package/src/analytics/birdeye/providers/portfolio-factory.test.ts +138 -0
- package/src/analytics/birdeye/providers/portfolio-factory.ts +252 -0
- package/src/analytics/birdeye/providers/trending.ts +365 -0
- package/src/analytics/birdeye/providers/wallet.ts +14 -0
- package/src/analytics/birdeye/search-category.test.ts +207 -0
- package/src/analytics/birdeye/search-category.ts +506 -0
- package/src/analytics/birdeye/service.ts +992 -0
- package/src/analytics/birdeye/tasks/birdeye.ts +232 -0
- package/src/analytics/birdeye/types/api/common.ts +305 -0
- package/src/analytics/birdeye/types/api/defi.ts +220 -0
- package/src/analytics/birdeye/types/api/pair.ts +200 -0
- package/src/analytics/birdeye/types/api/search.ts +86 -0
- package/src/analytics/birdeye/types/api/token.ts +635 -0
- package/src/analytics/birdeye/types/api/trader.ts +76 -0
- package/src/analytics/birdeye/types/api/wallet.ts +181 -0
- package/src/analytics/birdeye/types/shared.ts +106 -0
- package/src/analytics/birdeye/utils.ts +700 -0
- package/src/analytics/dexscreener/errors.ts +28 -0
- package/src/analytics/dexscreener/index.ts +3 -0
- package/src/analytics/dexscreener/search-category.test.ts +49 -0
- package/src/analytics/dexscreener/search-category.ts +42 -0
- package/src/analytics/dexscreener/service.ts +595 -0
- package/src/analytics/dexscreener/types.ts +128 -0
- package/src/analytics/lpinfo/index.d.ts +7 -0
- package/src/analytics/lpinfo/index.ts +52 -0
- package/src/analytics/lpinfo/kamino/README.md +102 -0
- package/src/analytics/lpinfo/kamino/index.ts +24 -0
- package/src/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.ts +422 -0
- package/src/analytics/lpinfo/kamino/providers/kaminoPoolProvider.ts +365 -0
- package/src/analytics/lpinfo/kamino/providers/kaminoProvider.ts +496 -0
- package/src/analytics/lpinfo/kamino/services/kaminoLiquidityService.ts +1123 -0
- package/src/analytics/lpinfo/kamino/services/kaminoService.ts +758 -0
- package/src/analytics/lpinfo/steer/README.md +169 -0
- package/src/analytics/lpinfo/steer/index.ts +23 -0
- package/src/analytics/lpinfo/steer/providers/steerLiquidityProvider.ts +544 -0
- package/src/analytics/lpinfo/steer/services/steerLiquidityService.ts +1690 -0
- package/src/analytics/lpinfo/steer/steer-display-types.ts +99 -0
- package/src/analytics/news/index.ts +52 -0
- package/src/analytics/news/interfaces/types.ts +222 -0
- package/src/analytics/news/providers/defiNewsProvider.ts +734 -0
- package/src/analytics/news/services/newsDataService.ts +332 -0
- package/src/analytics/news/utils/formatters.ts +151 -0
- package/src/analytics/token-info/action.ts +240 -0
- package/src/analytics/token-info/index.ts +3 -0
- package/src/analytics/token-info/params.ts +215 -0
- package/src/analytics/token-info/providers.ts +681 -0
- package/src/analytics/token-info/service.ts +168 -0
- package/src/analytics/token-info/types.ts +74 -0
- package/src/audit/audit-log.ts +45 -0
- package/src/browser-shim/build-shim.ts +123 -0
- package/src/browser-shim/index.ts +5 -0
- package/src/browser-shim/shim.template.js +563 -0
- package/src/chains/evm/.github/workflows/npm-deploy.yml +112 -0
- package/src/chains/evm/LICENSE +21 -0
- package/src/chains/evm/README.md +106 -0
- package/src/chains/evm/actions/helpers.ts +147 -0
- package/src/chains/evm/actions/swap.ts +839 -0
- package/src/chains/evm/actions/transfer.ts +254 -0
- package/src/chains/evm/biome.json +61 -0
- package/src/chains/evm/bridge-router.ts +660 -0
- package/src/chains/evm/build.ts +89 -0
- package/src/chains/evm/chain-handler.ts +416 -0
- package/src/chains/evm/constants.ts +23 -0
- package/src/chains/evm/contracts/artifacts/OZGovernor.json +1707 -0
- package/src/chains/evm/contracts/artifacts/TimelockController.json +1007 -0
- package/src/chains/evm/contracts/artifacts/VoteToken.json +895 -0
- package/src/chains/evm/dex/aerodrome/index.ts +34 -0
- package/src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts +558 -0
- package/src/chains/evm/dex/aerodrome/types.ts +318 -0
- package/src/chains/evm/dex/pancakeswp/index.ts +35 -0
- package/src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts +743 -0
- package/src/chains/evm/dex/pancakeswp/types.ts +65 -0
- package/src/chains/evm/dex/uniswap/index.ts +35 -0
- package/src/chains/evm/dex/uniswap/services/UniswapV3LpService.ts +759 -0
- package/src/chains/evm/dex/uniswap/types.ts +390 -0
- package/src/chains/evm/generated/specs/spec-helpers.ts +73 -0
- package/src/chains/evm/generated/specs/specs.ts +151 -0
- package/src/chains/evm/gov-router.ts +250 -0
- package/src/chains/evm/index.browser.ts +16 -0
- package/src/chains/evm/index.ts +31 -0
- package/src/chains/evm/prompts.ts +193 -0
- package/src/chains/evm/providers/get-balance.ts +123 -0
- package/src/chains/evm/providers/wallet.ts +715 -0
- package/src/chains/evm/routes/sign.ts +333 -0
- package/src/chains/evm/rpc-providers.ts +410 -0
- package/src/chains/evm/service.ts +140 -0
- package/src/chains/evm/templates/index.ts +10 -0
- package/src/chains/evm/types/index.ts +432 -0
- package/src/chains/evm/vitest.config.ts +18 -0
- package/src/chains/registry.ts +668 -0
- package/src/chains/solana/README.md +367 -0
- package/src/chains/wallet-action.ts +533 -0
- package/src/chains/wallet-router.test.ts +296 -0
- package/src/contracts.ts +65 -0
- package/src/core-augmentation.ts +10 -0
- package/src/index.ts +71 -0
- package/src/lib/server-wallet-trade.ts +192 -0
- package/src/lib/wallet-export-guard.ts +330 -0
- package/src/lp/actions/liquidity.ts +827 -0
- package/src/lp/e2e/real-token-tests.ts +428 -0
- package/src/lp/e2e/scenarios.ts +470 -0
- package/src/lp/e2e/test-utils.ts +145 -0
- package/src/lp/lp-manager-entry.ts +303 -0
- package/src/lp/services/ConcentratedLiquidityService.ts +120 -0
- package/src/lp/services/DexInteractionService.ts +226 -0
- package/src/lp/services/LpManagementService.test.ts +148 -0
- package/src/lp/services/LpManagementService.ts +632 -0
- package/src/lp/services/UserLpProfileService.ts +163 -0
- package/src/lp/services/VaultService.ts +153 -0
- package/src/lp/services/YieldOptimizationService.ts +344 -0
- package/src/lp/services/__tests__/MockLpService.ts +146 -0
- package/src/lp/tasks/LpAutoRebalanceTask.ts +117 -0
- package/src/lp/tasks/__tests__/LpAutoRebalanceTask.test.ts +370 -0
- package/src/lp/types.ts +582 -0
- package/src/lp/utils/solanaClient.ts +143 -0
- package/src/plugin.ts +125 -0
- package/src/policy/policy.ts +19 -0
- package/src/providers/canonical-provider.ts +27 -0
- package/src/providers/unified-wallet-provider.ts +79 -0
- package/src/register-routes.ts +11 -0
- package/src/routes/plugin.ts +47 -0
- package/src/routes/wallet-market-overview-route.ts +869 -0
- package/src/sdk/abi.ts +258 -0
- package/src/sdk/bridge/abis.ts +126 -0
- package/src/sdk/bridge/client.ts +518 -0
- package/src/sdk/bridge/index.ts +56 -0
- package/src/sdk/bridge/solana.ts +604 -0
- package/src/sdk/bridge/types.ts +202 -0
- package/src/sdk/convenience.ts +347 -0
- package/src/sdk/escrow/MutualStakeEscrow.ts +480 -0
- package/src/sdk/escrow/types.ts +64 -0
- package/src/sdk/escrow/verifiers.ts +73 -0
- package/src/sdk/identity/erc8004.ts +692 -0
- package/src/sdk/identity/reputation.ts +449 -0
- package/src/sdk/identity/uaid.ts +497 -0
- package/src/sdk/identity/validation.ts +372 -0
- package/src/sdk/index.ts +763 -0
- package/src/sdk/policy/SpendingPolicy.ts +260 -0
- package/src/sdk/policy/UptoBillingPolicy.ts +320 -0
- package/src/sdk/router/PaymentRouter.ts +215 -0
- package/src/sdk/router/index.ts +8 -0
- package/src/sdk/swap/SwapModule.ts +310 -0
- package/src/sdk/swap/abi.ts +117 -0
- package/src/sdk/swap/index.ts +34 -0
- package/src/sdk/swap/types.ts +135 -0
- package/src/sdk/tokens/decimals.ts +140 -0
- package/src/sdk/tokens/registry.ts +911 -0
- package/src/sdk/tokens/solana.ts +419 -0
- package/src/sdk/tokens/transfers.ts +327 -0
- package/src/sdk/types.ts +158 -0
- package/src/sdk/wallet-core.ts +115 -0
- package/src/sdk/x402/budget.ts +168 -0
- package/src/sdk/x402/chains/abstract/index.ts +280 -0
- package/src/sdk/x402/client.ts +320 -0
- package/src/sdk/x402/index.ts +46 -0
- package/src/sdk/x402/middleware.ts +92 -0
- package/src/sdk/x402/multi-asset.ts +144 -0
- package/src/sdk/x402/types.ts +156 -0
- package/src/services/wallet-backend-service.ts +328 -0
- package/src/types/wallet-router.ts +227 -0
- package/src/utils/intent-trajectory.ts +106 -0
- package/src/wallet/backend.ts +62 -0
- package/src/wallet/errors.ts +49 -0
- package/src/wallet/index.ts +27 -0
- package/src/wallet/local-eoa-backend.ts +201 -0
- package/src/wallet/pending.ts +60 -0
- package/src/wallet/select-backend.ts +47 -0
- package/src/wallet/steward-backend.ts +161 -0
- package/src/wallet-action.ts +1 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ERC-8004: Trustless Agents — Reputation Registry Client
|
|
3
|
+
*
|
|
4
|
+
* On-chain reputation system for AI agents. Clients can leave scored feedback,
|
|
5
|
+
* agents can respond, and anyone can query aggregated reputation summaries.
|
|
6
|
+
*
|
|
7
|
+
* Spec: https://eips.ethereum.org/EIPS/eip-8004
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
type Address,
|
|
11
|
+
type Chain,
|
|
12
|
+
createPublicClient,
|
|
13
|
+
getContract,
|
|
14
|
+
type Hash,
|
|
15
|
+
type Hex,
|
|
16
|
+
http,
|
|
17
|
+
type PublicClient,
|
|
18
|
+
type WalletClient,
|
|
19
|
+
} from "viem";
|
|
20
|
+
import {
|
|
21
|
+
arbitrum,
|
|
22
|
+
arbitrumSepolia,
|
|
23
|
+
base,
|
|
24
|
+
baseSepolia,
|
|
25
|
+
mainnet,
|
|
26
|
+
polygon,
|
|
27
|
+
} from "viem/chains";
|
|
28
|
+
import { KNOWN_REGISTRY_ADDRESSES, type SupportedChain } from "./erc8004.js";
|
|
29
|
+
|
|
30
|
+
// ─── ABI ─────────────────────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
export const ReputationRegistryAbi = [
|
|
33
|
+
{
|
|
34
|
+
name: "giveFeedback",
|
|
35
|
+
type: "function",
|
|
36
|
+
stateMutability: "nonpayable",
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: "agentId", type: "uint256" },
|
|
39
|
+
{ name: "score", type: "int128" },
|
|
40
|
+
{ name: "category", type: "uint8" },
|
|
41
|
+
{ name: "comment", type: "string" },
|
|
42
|
+
{ name: "taskRef", type: "string" },
|
|
43
|
+
{ name: "verifierRef", type: "string" },
|
|
44
|
+
{ name: "clientRef", type: "string" },
|
|
45
|
+
{ name: "contentHash", type: "bytes32" },
|
|
46
|
+
],
|
|
47
|
+
outputs: [],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "readFeedback",
|
|
51
|
+
type: "function",
|
|
52
|
+
stateMutability: "view",
|
|
53
|
+
inputs: [
|
|
54
|
+
{ name: "agentId", type: "uint256" },
|
|
55
|
+
{ name: "client", type: "address" },
|
|
56
|
+
{ name: "index", type: "uint64" },
|
|
57
|
+
],
|
|
58
|
+
outputs: [
|
|
59
|
+
{ name: "score", type: "int128" },
|
|
60
|
+
{ name: "category", type: "uint8" },
|
|
61
|
+
{ name: "comment", type: "string" },
|
|
62
|
+
{ name: "taskRef", type: "string" },
|
|
63
|
+
{ name: "revoked", type: "bool" },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "readAllFeedback",
|
|
68
|
+
type: "function",
|
|
69
|
+
stateMutability: "view",
|
|
70
|
+
inputs: [
|
|
71
|
+
{ name: "agentId", type: "uint256" },
|
|
72
|
+
{ name: "clients", type: "address[]" },
|
|
73
|
+
{ name: "category", type: "string" },
|
|
74
|
+
{ name: "taskRef", type: "string" },
|
|
75
|
+
{ name: "includeRevoked", type: "bool" },
|
|
76
|
+
],
|
|
77
|
+
outputs: [
|
|
78
|
+
{ name: "scores", type: "int128[]" },
|
|
79
|
+
{ name: "categories", type: "uint8[]" },
|
|
80
|
+
{ name: "comments", type: "string[]" },
|
|
81
|
+
{ name: "taskRefs", type: "string[]" },
|
|
82
|
+
{ name: "revoked", type: "bool[]" },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "getSummary",
|
|
87
|
+
type: "function",
|
|
88
|
+
stateMutability: "view",
|
|
89
|
+
inputs: [
|
|
90
|
+
{ name: "agentId", type: "uint256" },
|
|
91
|
+
{ name: "clients", type: "address[]" },
|
|
92
|
+
{ name: "category", type: "string" },
|
|
93
|
+
{ name: "taskRef", type: "string" },
|
|
94
|
+
],
|
|
95
|
+
outputs: [
|
|
96
|
+
{ name: "count", type: "uint64" },
|
|
97
|
+
{ name: "totalScore", type: "int128" },
|
|
98
|
+
{ name: "avgCategory", type: "uint8" },
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "getClients",
|
|
103
|
+
type: "function",
|
|
104
|
+
stateMutability: "view",
|
|
105
|
+
inputs: [{ name: "agentId", type: "uint256" }],
|
|
106
|
+
outputs: [{ name: "", type: "address[]" }],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "getLastIndex",
|
|
110
|
+
type: "function",
|
|
111
|
+
stateMutability: "view",
|
|
112
|
+
inputs: [
|
|
113
|
+
{ name: "agentId", type: "uint256" },
|
|
114
|
+
{ name: "client", type: "address" },
|
|
115
|
+
],
|
|
116
|
+
outputs: [{ name: "", type: "uint64" }],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "appendResponse",
|
|
120
|
+
type: "function",
|
|
121
|
+
stateMutability: "nonpayable",
|
|
122
|
+
inputs: [
|
|
123
|
+
{ name: "agentId", type: "uint256" },
|
|
124
|
+
{ name: "client", type: "address" },
|
|
125
|
+
{ name: "index", type: "uint64" },
|
|
126
|
+
{ name: "response", type: "string" },
|
|
127
|
+
{ name: "contentHash", type: "bytes32" },
|
|
128
|
+
],
|
|
129
|
+
outputs: [],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "revokeFeedback",
|
|
133
|
+
type: "function",
|
|
134
|
+
stateMutability: "nonpayable",
|
|
135
|
+
inputs: [
|
|
136
|
+
{ name: "agentId", type: "uint256" },
|
|
137
|
+
{ name: "index", type: "uint64" },
|
|
138
|
+
],
|
|
139
|
+
outputs: [],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "getResponseCount",
|
|
143
|
+
type: "function",
|
|
144
|
+
stateMutability: "view",
|
|
145
|
+
inputs: [
|
|
146
|
+
{ name: "agentId", type: "uint256" },
|
|
147
|
+
{ name: "client", type: "address" },
|
|
148
|
+
{ name: "index", type: "uint64" },
|
|
149
|
+
{ name: "responders", type: "address[]" },
|
|
150
|
+
],
|
|
151
|
+
outputs: [{ name: "", type: "uint64" }],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "getIdentityRegistry",
|
|
155
|
+
type: "function",
|
|
156
|
+
stateMutability: "view",
|
|
157
|
+
inputs: [],
|
|
158
|
+
outputs: [{ name: "", type: "address" }],
|
|
159
|
+
},
|
|
160
|
+
] as const;
|
|
161
|
+
|
|
162
|
+
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
163
|
+
|
|
164
|
+
export interface ReputationClientConfig {
|
|
165
|
+
reputationAddress?: Address;
|
|
166
|
+
chain: SupportedChain;
|
|
167
|
+
rpcUrl?: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface GiveFeedbackParams {
|
|
171
|
+
agentId: bigint;
|
|
172
|
+
score: bigint;
|
|
173
|
+
category: number;
|
|
174
|
+
comment: string;
|
|
175
|
+
taskRef: string;
|
|
176
|
+
verifierRef: string;
|
|
177
|
+
clientRef: string;
|
|
178
|
+
contentHash: Hex;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface FeedbackEntry {
|
|
182
|
+
score: bigint;
|
|
183
|
+
category: number;
|
|
184
|
+
comment: string;
|
|
185
|
+
taskRef: string;
|
|
186
|
+
revoked: boolean;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface AgentReputationSummary {
|
|
190
|
+
count: bigint;
|
|
191
|
+
totalScore: bigint;
|
|
192
|
+
avgCategory: number;
|
|
193
|
+
clients: Address[];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface FeedbackFilters {
|
|
197
|
+
clients?: Address[];
|
|
198
|
+
category?: string;
|
|
199
|
+
taskRef?: string;
|
|
200
|
+
includeRevoked?: boolean;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface RespondToFeedbackParams {
|
|
204
|
+
agentId: bigint;
|
|
205
|
+
client: Address;
|
|
206
|
+
index: bigint;
|
|
207
|
+
response: string;
|
|
208
|
+
contentHash: Hex;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ─── Chains ──────────────────────────────────────────────────────────────────
|
|
212
|
+
|
|
213
|
+
const CHAINS: Record<string, Chain> = {
|
|
214
|
+
base,
|
|
215
|
+
"base-sepolia": baseSepolia,
|
|
216
|
+
ethereum: mainnet,
|
|
217
|
+
arbitrum,
|
|
218
|
+
polygon,
|
|
219
|
+
"arbitrum-sepolia": arbitrumSepolia,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// ─── Client ──────────────────────────────────────────────────────────────────
|
|
223
|
+
|
|
224
|
+
export class ReputationClient {
|
|
225
|
+
private readonly publicClient: PublicClient;
|
|
226
|
+
private readonly reputationAddress: Address;
|
|
227
|
+
private readonly chain: Chain;
|
|
228
|
+
|
|
229
|
+
constructor(config: ReputationClientConfig) {
|
|
230
|
+
const resolvedAddress =
|
|
231
|
+
config.reputationAddress ??
|
|
232
|
+
KNOWN_REGISTRY_ADDRESSES[config.chain]?.reputation;
|
|
233
|
+
if (!resolvedAddress) {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`ReputationClient: No reputation address provided and no known address for chain "${config.chain}"`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
this.reputationAddress = resolvedAddress;
|
|
239
|
+
|
|
240
|
+
const chain = CHAINS[config.chain];
|
|
241
|
+
if (!chain)
|
|
242
|
+
throw new Error(`ReputationClient: Unsupported chain "${config.chain}"`);
|
|
243
|
+
this.chain = chain;
|
|
244
|
+
this.publicClient = createPublicClient({
|
|
245
|
+
chain,
|
|
246
|
+
transport: http(config.rpcUrl),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private getReadContract() {
|
|
251
|
+
return getContract({
|
|
252
|
+
address: this.reputationAddress,
|
|
253
|
+
abi: ReputationRegistryAbi,
|
|
254
|
+
client: this.publicClient,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private getWriteContract(walletClient: WalletClient) {
|
|
259
|
+
return getContract({
|
|
260
|
+
address: this.reputationAddress,
|
|
261
|
+
abi: ReputationRegistryAbi,
|
|
262
|
+
client: { public: this.publicClient, wallet: walletClient },
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Submit feedback for an agent.
|
|
268
|
+
*/
|
|
269
|
+
async giveFeedback(
|
|
270
|
+
walletClient: WalletClient,
|
|
271
|
+
params: GiveFeedbackParams,
|
|
272
|
+
): Promise<Hash> {
|
|
273
|
+
if (!walletClient.account)
|
|
274
|
+
throw new Error("ReputationClient: WalletClient has no account");
|
|
275
|
+
const contract = this.getWriteContract(walletClient);
|
|
276
|
+
return contract.write.giveFeedback(
|
|
277
|
+
[
|
|
278
|
+
params.agentId,
|
|
279
|
+
params.score,
|
|
280
|
+
params.category,
|
|
281
|
+
params.comment,
|
|
282
|
+
params.taskRef,
|
|
283
|
+
params.verifierRef,
|
|
284
|
+
params.clientRef,
|
|
285
|
+
params.contentHash,
|
|
286
|
+
],
|
|
287
|
+
{ account: walletClient.account, chain: this.chain },
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Read a specific feedback entry.
|
|
293
|
+
*/
|
|
294
|
+
async readFeedback(
|
|
295
|
+
agentId: bigint,
|
|
296
|
+
client: Address,
|
|
297
|
+
index: bigint,
|
|
298
|
+
): Promise<FeedbackEntry> {
|
|
299
|
+
const contract = this.getReadContract();
|
|
300
|
+
const [score, category, comment, taskRef, revoked] =
|
|
301
|
+
(await contract.read.readFeedback([agentId, client, index])) as [
|
|
302
|
+
bigint,
|
|
303
|
+
number,
|
|
304
|
+
string,
|
|
305
|
+
string,
|
|
306
|
+
boolean,
|
|
307
|
+
];
|
|
308
|
+
|
|
309
|
+
return { score, category, comment, taskRef, revoked };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Get agent reputation summary: aggregated score + list of clients.
|
|
314
|
+
*/
|
|
315
|
+
async getAgentReputation(
|
|
316
|
+
agentId: bigint,
|
|
317
|
+
options?: { clients?: Address[]; category?: string; taskRef?: string },
|
|
318
|
+
): Promise<AgentReputationSummary> {
|
|
319
|
+
const contract = this.getReadContract();
|
|
320
|
+
|
|
321
|
+
const clients = (await contract.read.getClients([agentId])) as Address[];
|
|
322
|
+
|
|
323
|
+
const filterClients = options?.clients ?? clients;
|
|
324
|
+
const category = options?.category ?? "";
|
|
325
|
+
const taskRef = options?.taskRef ?? "";
|
|
326
|
+
|
|
327
|
+
const [count, totalScore, avgCategory] = (await contract.read.getSummary([
|
|
328
|
+
agentId,
|
|
329
|
+
filterClients,
|
|
330
|
+
category,
|
|
331
|
+
taskRef,
|
|
332
|
+
])) as [bigint, bigint, number];
|
|
333
|
+
|
|
334
|
+
return { count, totalScore, avgCategory, clients };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Read all feedback for an agent with optional filters.
|
|
339
|
+
*/
|
|
340
|
+
async getAllFeedback(
|
|
341
|
+
agentId: bigint,
|
|
342
|
+
options?: FeedbackFilters,
|
|
343
|
+
): Promise<FeedbackEntry[]> {
|
|
344
|
+
const contract = this.getReadContract();
|
|
345
|
+
|
|
346
|
+
const clients = options?.clients ?? [];
|
|
347
|
+
const category = options?.category ?? "";
|
|
348
|
+
const taskRef = options?.taskRef ?? "";
|
|
349
|
+
const includeRevoked = options?.includeRevoked ?? false;
|
|
350
|
+
|
|
351
|
+
const [scores, categories, comments, taskRefs, revoked] =
|
|
352
|
+
(await contract.read.readAllFeedback([
|
|
353
|
+
agentId,
|
|
354
|
+
clients,
|
|
355
|
+
category,
|
|
356
|
+
taskRef,
|
|
357
|
+
includeRevoked,
|
|
358
|
+
])) as [bigint[], number[], string[], string[], boolean[]];
|
|
359
|
+
|
|
360
|
+
return scores.map((score, i) => ({
|
|
361
|
+
score,
|
|
362
|
+
category: categories[i],
|
|
363
|
+
comment: comments[i],
|
|
364
|
+
taskRef: taskRefs[i],
|
|
365
|
+
revoked: revoked[i],
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Append a response to existing feedback.
|
|
371
|
+
*/
|
|
372
|
+
async respondToFeedback(
|
|
373
|
+
walletClient: WalletClient,
|
|
374
|
+
params: RespondToFeedbackParams,
|
|
375
|
+
): Promise<Hash> {
|
|
376
|
+
if (!walletClient.account)
|
|
377
|
+
throw new Error("ReputationClient: WalletClient has no account");
|
|
378
|
+
const contract = this.getWriteContract(walletClient);
|
|
379
|
+
return contract.write.appendResponse(
|
|
380
|
+
[
|
|
381
|
+
params.agentId,
|
|
382
|
+
params.client,
|
|
383
|
+
params.index,
|
|
384
|
+
params.response,
|
|
385
|
+
params.contentHash,
|
|
386
|
+
],
|
|
387
|
+
{ account: walletClient.account, chain: this.chain },
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Revoke own feedback for an agent.
|
|
393
|
+
*/
|
|
394
|
+
async revokeFeedback(
|
|
395
|
+
walletClient: WalletClient,
|
|
396
|
+
agentId: bigint,
|
|
397
|
+
index: bigint,
|
|
398
|
+
): Promise<Hash> {
|
|
399
|
+
if (!walletClient.account)
|
|
400
|
+
throw new Error("ReputationClient: WalletClient has no account");
|
|
401
|
+
const contract = this.getWriteContract(walletClient);
|
|
402
|
+
return contract.write.revokeFeedback([agentId, index], {
|
|
403
|
+
account: walletClient.account,
|
|
404
|
+
chain: this.chain,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Get the linked identity registry address.
|
|
410
|
+
*/
|
|
411
|
+
async getIdentityRegistry(): Promise<Address> {
|
|
412
|
+
const contract = this.getReadContract();
|
|
413
|
+
return contract.read.getIdentityRegistry() as Promise<Address>;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Get the last feedback index for a client on an agent.
|
|
418
|
+
*/
|
|
419
|
+
async getLastIndex(agentId: bigint, client: Address): Promise<bigint> {
|
|
420
|
+
const contract = this.getReadContract();
|
|
421
|
+
return contract.read.getLastIndex([agentId, client]) as Promise<bigint>;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Get clients who have left feedback for an agent.
|
|
426
|
+
*/
|
|
427
|
+
async getClients(agentId: bigint): Promise<Address[]> {
|
|
428
|
+
const contract = this.getReadContract();
|
|
429
|
+
return contract.read.getClients([agentId]) as Promise<Address[]>;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Get the number of responses for a specific feedback entry.
|
|
434
|
+
*/
|
|
435
|
+
async getResponseCount(
|
|
436
|
+
agentId: bigint,
|
|
437
|
+
client: Address,
|
|
438
|
+
index: bigint,
|
|
439
|
+
responders: Address[],
|
|
440
|
+
): Promise<bigint> {
|
|
441
|
+
const contract = this.getReadContract();
|
|
442
|
+
return contract.read.getResponseCount([
|
|
443
|
+
agentId,
|
|
444
|
+
client,
|
|
445
|
+
index,
|
|
446
|
+
responders,
|
|
447
|
+
]) as Promise<bigint>;
|
|
448
|
+
}
|
|
449
|
+
}
|