@zakyirsyaad/monagent-plugin 0.1.0 → 0.1.3
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/commands/monad/identity/get.d.ts +19 -0
- package/dist/commands/monad/identity/get.js +113 -0
- package/dist/commands/monad/identity/register.d.ts +16 -0
- package/dist/commands/monad/identity/register.js +122 -0
- package/dist/commands/monad/jobs/complete.d.ts +15 -0
- package/dist/commands/monad/jobs/complete.js +63 -0
- package/dist/commands/{jobs → monad/jobs}/create.d.ts +5 -2
- package/dist/commands/monad/jobs/create.js +88 -0
- package/dist/commands/monad/jobs/refund.d.ts +14 -0
- package/dist/commands/monad/jobs/refund.js +56 -0
- package/dist/commands/{pay.d.ts → monad/pay.d.ts} +5 -2
- package/dist/commands/monad/pay.js +123 -0
- package/dist/commands/monad/reputation/check.d.ts +18 -0
- package/dist/commands/monad/reputation/check.js +103 -0
- package/dist/commands/monad/reputation/give.d.ts +15 -0
- package/dist/commands/monad/reputation/give.js +99 -0
- package/dist/commands/monad/x402/pay.d.ts +21 -0
- package/dist/commands/monad/x402/pay.js +224 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.js +10 -7
- package/dist/monad.d.ts +424 -0
- package/dist/monad.js +186 -0
- package/dist/sdk.d.ts +62 -39
- package/dist/sdk.js +95 -8
- package/oclif.manifest.json +1304 -24
- package/package.json +47 -11
- package/dist/commands/identity/get.d.ts +0 -13
- package/dist/commands/identity/get.js +0 -59
- package/dist/commands/identity/register.d.ts +0 -12
- package/dist/commands/identity/register.js +0 -39
- package/dist/commands/jobs/create.js +0 -38
- package/dist/commands/pay.js +0 -33
- package/dist/commands/reputation/check.d.ts +0 -12
- package/dist/commands/reputation/check.js +0 -46
- package/dist/commands/reputation/give.d.ts +0 -12
- package/dist/commands/reputation/give.js +0 -45
- package/dist/commands/x402/pay.d.ts +0 -13
- package/dist/commands/x402/pay.js +0 -67
- package/dist/commands.test.d.ts +0 -1
- package/dist/commands.test.js +0 -141
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakyirsyaad/monagent-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "MetaMask Agent Wallet Plugin for Monad A2A Commerce & Trust (ERC-8004 & x402)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -18,19 +18,23 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "tsc -p
|
|
21
|
+
"build": "tsc -p tsconfig.json && oclif manifest",
|
|
22
22
|
"test": "tsx --test \"src/**/*.test.ts\""
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
25
|
+
"@x402/core": "^2.18.0",
|
|
26
|
+
"@x402/evm": "^2.18.0",
|
|
26
27
|
"viem": "2.55.8",
|
|
27
28
|
"zod": "^4.4.3"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@metamask/agent-wallet": "^6.2.0"
|
|
31
|
+
"@metamask/agent-wallet": "^6.2.0 || ^7.0.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
34
|
+
"@metamask/agent-wallet": "^6.2.1",
|
|
35
|
+
"@oclif/core": "^4.14.0",
|
|
33
36
|
"@types/node": "^26.1.0",
|
|
37
|
+
"oclif": "^4.24.0",
|
|
34
38
|
"tsx": "^4.22.4",
|
|
35
39
|
"typescript": "^6.0.3"
|
|
36
40
|
},
|
|
@@ -41,7 +45,7 @@
|
|
|
41
45
|
},
|
|
42
46
|
"mm": {
|
|
43
47
|
"schemaVersion": 1,
|
|
44
|
-
"minCliVersion": "^6.2.0",
|
|
48
|
+
"minCliVersion": "^6.2.0 || ^7.0.0",
|
|
45
49
|
"capabilities": [],
|
|
46
50
|
"commands": [
|
|
47
51
|
{
|
|
@@ -54,7 +58,8 @@
|
|
|
54
58
|
"balances"
|
|
55
59
|
],
|
|
56
60
|
"targetChains": [
|
|
57
|
-
10143
|
|
61
|
+
10143,
|
|
62
|
+
143
|
|
58
63
|
]
|
|
59
64
|
},
|
|
60
65
|
{
|
|
@@ -67,7 +72,8 @@
|
|
|
67
72
|
"accounts"
|
|
68
73
|
],
|
|
69
74
|
"targetChains": [
|
|
70
|
-
10143
|
|
75
|
+
10143,
|
|
76
|
+
143
|
|
71
77
|
]
|
|
72
78
|
},
|
|
73
79
|
{
|
|
@@ -79,7 +85,8 @@
|
|
|
79
85
|
"accounts"
|
|
80
86
|
],
|
|
81
87
|
"targetChains": [
|
|
82
|
-
10143
|
|
88
|
+
10143,
|
|
89
|
+
143
|
|
83
90
|
]
|
|
84
91
|
},
|
|
85
92
|
{
|
|
@@ -89,7 +96,8 @@
|
|
|
89
96
|
],
|
|
90
97
|
"dataAccess": [],
|
|
91
98
|
"targetChains": [
|
|
92
|
-
10143
|
|
99
|
+
10143,
|
|
100
|
+
143
|
|
93
101
|
]
|
|
94
102
|
},
|
|
95
103
|
{
|
|
@@ -102,7 +110,8 @@
|
|
|
102
110
|
"accounts"
|
|
103
111
|
],
|
|
104
112
|
"targetChains": [
|
|
105
|
-
10143
|
|
113
|
+
10143,
|
|
114
|
+
143
|
|
106
115
|
]
|
|
107
116
|
},
|
|
108
117
|
{
|
|
@@ -115,7 +124,8 @@
|
|
|
115
124
|
"balances"
|
|
116
125
|
],
|
|
117
126
|
"targetChains": [
|
|
118
|
-
10143
|
|
127
|
+
10143,
|
|
128
|
+
143
|
|
119
129
|
]
|
|
120
130
|
},
|
|
121
131
|
{
|
|
@@ -130,6 +140,32 @@
|
|
|
130
140
|
"targetChains": [
|
|
131
141
|
10143
|
|
132
142
|
]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"id": "monad:jobs:complete",
|
|
146
|
+
"capabilities": [
|
|
147
|
+
"wallet-read",
|
|
148
|
+
"wallet-submit"
|
|
149
|
+
],
|
|
150
|
+
"dataAccess": [
|
|
151
|
+
"balances"
|
|
152
|
+
],
|
|
153
|
+
"targetChains": [
|
|
154
|
+
10143
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"id": "monad:jobs:refund",
|
|
159
|
+
"capabilities": [
|
|
160
|
+
"wallet-read",
|
|
161
|
+
"wallet-submit"
|
|
162
|
+
],
|
|
163
|
+
"dataAccess": [
|
|
164
|
+
"balances"
|
|
165
|
+
],
|
|
166
|
+
"targetChains": [
|
|
167
|
+
10143
|
|
168
|
+
]
|
|
133
169
|
}
|
|
134
170
|
]
|
|
135
171
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type MonadAgentCard } from "@monagent/shared";
|
|
2
|
-
import { PluginCommand, type CommandIO } from "../../sdk.js";
|
|
3
|
-
export interface GetIdentityResult {
|
|
4
|
-
agentId: string;
|
|
5
|
-
owner: string;
|
|
6
|
-
walletAddress: string;
|
|
7
|
-
card?: MonadAgentCard;
|
|
8
|
-
}
|
|
9
|
-
export declare class MonadIdentityGetCommand extends PluginCommand<GetIdentityResult> {
|
|
10
|
-
static description: string;
|
|
11
|
-
protected readonly pluginCommandId = "monad:identity:get";
|
|
12
|
-
execute(io: CommandIO): Promise<GetIdentityResult>;
|
|
13
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { parseAbi } from "viem";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { MONAD_TESTNET_CHAIN_ID, MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY, monadAgentCardSchema, } from "@monagent/shared";
|
|
4
|
-
import { PluginCommand } from "../../sdk.js";
|
|
5
|
-
const erc8004IdentityAbi = parseAbi([
|
|
6
|
-
"function tokenURI(uint256 tokenId) view returns (string)",
|
|
7
|
-
"function getAgentWallet(uint256 agentId) view returns (address)",
|
|
8
|
-
"function ownerOf(uint256 tokenId) view returns (address)",
|
|
9
|
-
]);
|
|
10
|
-
const getIdentityInputSchema = z.object({
|
|
11
|
-
agentId: z.string().regex(/^\d+$/, "agentId must be a numeric string"),
|
|
12
|
-
});
|
|
13
|
-
export class MonadIdentityGetCommand extends PluginCommand {
|
|
14
|
-
static description = "Get agent identity details from Monad Testnet ERC-8004 Registry";
|
|
15
|
-
pluginCommandId = "monad:identity:get";
|
|
16
|
-
async execute(io) {
|
|
17
|
-
const rawInputs = await io.resolveInputs(getIdentityInputSchema);
|
|
18
|
-
const { agentId } = getIdentityInputSchema.parse(rawInputs);
|
|
19
|
-
const client = this.ctx.publicClient(MONAD_TESTNET_CHAIN_ID);
|
|
20
|
-
const tokenIdBigInt = BigInt(agentId);
|
|
21
|
-
const [owner, walletAddress, uri] = await Promise.all([
|
|
22
|
-
client.readContract({
|
|
23
|
-
address: MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY,
|
|
24
|
-
abi: erc8004IdentityAbi,
|
|
25
|
-
functionName: "ownerOf",
|
|
26
|
-
args: [tokenIdBigInt],
|
|
27
|
-
}),
|
|
28
|
-
client.readContract({
|
|
29
|
-
address: MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY,
|
|
30
|
-
abi: erc8004IdentityAbi,
|
|
31
|
-
functionName: "getAgentWallet",
|
|
32
|
-
args: [tokenIdBigInt],
|
|
33
|
-
}),
|
|
34
|
-
client.readContract({
|
|
35
|
-
address: MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY,
|
|
36
|
-
abi: erc8004IdentityAbi,
|
|
37
|
-
functionName: "tokenURI",
|
|
38
|
-
args: [tokenIdBigInt],
|
|
39
|
-
}),
|
|
40
|
-
]);
|
|
41
|
-
let card;
|
|
42
|
-
if (uri.startsWith("data:application/json;utf8,")) {
|
|
43
|
-
try {
|
|
44
|
-
const decoded = decodeURIComponent(uri.replace("data:application/json;utf8,", ""));
|
|
45
|
-
const parsed = JSON.parse(decoded);
|
|
46
|
-
card = monadAgentCardSchema.parse(parsed);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
io.warn(`Could not parse agent metadata URI for agentId ${agentId}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
agentId,
|
|
54
|
-
owner,
|
|
55
|
-
walletAddress,
|
|
56
|
-
card,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type MonadAgentCard } from "@monagent/shared";
|
|
2
|
-
import { PluginCommand, type CommandIO } from "../../sdk.js";
|
|
3
|
-
export interface RegisterIdentityResult {
|
|
4
|
-
transactionHash: `0x${string}`;
|
|
5
|
-
agentCard: MonadAgentCard;
|
|
6
|
-
registryAddress: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class MonadIdentityRegisterCommand extends PluginCommand<RegisterIdentityResult> {
|
|
9
|
-
static description: string;
|
|
10
|
-
protected readonly pluginCommandId = "monad:identity:register";
|
|
11
|
-
execute(io: CommandIO): Promise<RegisterIdentityResult>;
|
|
12
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { encodeFunctionData, parseAbi } from "viem";
|
|
2
|
-
import { MONAD_TESTNET_CHAIN_ID, MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY, monadAgentCardSchema, } from "@monagent/shared";
|
|
3
|
-
import { PluginCommand } from "../../sdk.js";
|
|
4
|
-
const erc8004IdentityAbi = parseAbi([
|
|
5
|
-
"function register(string agentURI) returns (uint256 agentId)",
|
|
6
|
-
"function tokenURI(uint256 tokenId) view returns (string)",
|
|
7
|
-
"function getAgentWallet(uint256 agentId) view returns (address)",
|
|
8
|
-
"function ownerOf(uint256 tokenId) view returns (address)",
|
|
9
|
-
]);
|
|
10
|
-
export class MonadIdentityRegisterCommand extends PluginCommand {
|
|
11
|
-
static description = "Register an AI Agent identity on Monad Testnet ERC-8004 Registry";
|
|
12
|
-
pluginCommandId = "monad:identity:register";
|
|
13
|
-
async execute(io) {
|
|
14
|
-
const rawInputs = await io.resolveInputs(monadAgentCardSchema);
|
|
15
|
-
const card = monadAgentCardSchema.parse(rawInputs);
|
|
16
|
-
const agentUri = `data:application/json;utf8,${encodeURIComponent(JSON.stringify(card))}`;
|
|
17
|
-
const data = encodeFunctionData({
|
|
18
|
-
abi: erc8004IdentityAbi,
|
|
19
|
-
functionName: "register",
|
|
20
|
-
args: [agentUri],
|
|
21
|
-
});
|
|
22
|
-
const executor = this.ctx.walletExecutor(io, this.pluginCommandId);
|
|
23
|
-
const result = await executor({
|
|
24
|
-
kind: "transaction",
|
|
25
|
-
chainId: MONAD_TESTNET_CHAIN_ID,
|
|
26
|
-
to: MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY,
|
|
27
|
-
data,
|
|
28
|
-
});
|
|
29
|
-
if (result.status !== "success" || !result.hash) {
|
|
30
|
-
throw new Error(`Failed to register agent identity on Monad: status ${result.status}`);
|
|
31
|
-
}
|
|
32
|
-
io.log(`Agent identity registered on Monad! TxHash: ${result.hash}`);
|
|
33
|
-
return {
|
|
34
|
-
transactionHash: result.hash,
|
|
35
|
-
agentCard: card,
|
|
36
|
-
registryAddress: MONAD_TESTNET_ERC8004_IDENTITY_REGISTRY,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { parseEther } from "viem";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { MONAD_TESTNET_CHAIN_ID } from "@monagent/shared";
|
|
4
|
-
import { PluginCommand } from "../../sdk.js";
|
|
5
|
-
const createJobInputSchema = z.object({
|
|
6
|
-
workerAddress: z.string().regex(/^0x[a-fA-F0-9]{40}$/),
|
|
7
|
-
bountyMon: z.string().regex(/^\d+(\.\d+)?$/),
|
|
8
|
-
taskDescription: z.string().min(1).max(500),
|
|
9
|
-
deadlineHours: z.number().int().min(1).max(168).default(24),
|
|
10
|
-
});
|
|
11
|
-
export class MonadJobsCreateCommand extends PluginCommand {
|
|
12
|
-
static description = "Create and fund a subcontracted A2A task escrow on Monad";
|
|
13
|
-
pluginCommandId = "monad:jobs:create";
|
|
14
|
-
async execute(io) {
|
|
15
|
-
const rawInputs = await io.resolveInputs(createJobInputSchema);
|
|
16
|
-
const { workerAddress, bountyMon, taskDescription, deadlineHours } = createJobInputSchema.parse(rawInputs);
|
|
17
|
-
io.log(`Creating A2A Job for worker ${workerAddress} with bounty ${bountyMon} MON (Deadline: ${deadlineHours}h)`);
|
|
18
|
-
const executor = this.ctx.walletExecutor(io, this.pluginCommandId);
|
|
19
|
-
const tx = await executor({
|
|
20
|
-
kind: "transaction",
|
|
21
|
-
chainId: MONAD_TESTNET_CHAIN_ID,
|
|
22
|
-
to: workerAddress,
|
|
23
|
-
value: parseEther(bountyMon),
|
|
24
|
-
});
|
|
25
|
-
if (tx.status !== "success" || !tx.hash) {
|
|
26
|
-
throw new Error(`Failed to fund job escrow on Monad: status ${tx.status}`);
|
|
27
|
-
}
|
|
28
|
-
const jobId = `job_${Date.now()}_${tx.hash.slice(2, 10)}`;
|
|
29
|
-
io.log(`Job escrow funded! JobId: ${jobId}, Tx: ${tx.hash}`);
|
|
30
|
-
return {
|
|
31
|
-
jobId,
|
|
32
|
-
workerAddress,
|
|
33
|
-
bountyMon,
|
|
34
|
-
taskDescription,
|
|
35
|
-
escrowTransactionHash: tx.hash,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
package/dist/commands/pay.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { parseEther } from "viem";
|
|
2
|
-
import { MONAD_TESTNET_CHAIN_ID, monadPaymentInputSchema, } from "@monagent/shared";
|
|
3
|
-
import { PluginCommand } from "../sdk.js";
|
|
4
|
-
export class MonadPayCommand extends PluginCommand {
|
|
5
|
-
static description = "Send direct MON or ERC-20 payment on Monad Testnet";
|
|
6
|
-
pluginCommandId = "monad:pay";
|
|
7
|
-
async execute(io) {
|
|
8
|
-
const rawInputs = await io.resolveInputs(monadPaymentInputSchema);
|
|
9
|
-
const { to, amount, token, memo } = monadPaymentInputSchema.parse(rawInputs);
|
|
10
|
-
if (token !== "MON") {
|
|
11
|
-
throw new Error(`Token ${token} not yet supported directly in quick-pay. Use MON for native transfers.`);
|
|
12
|
-
}
|
|
13
|
-
const valueInWei = parseEther(amount);
|
|
14
|
-
const executor = this.ctx.walletExecutor(io, this.pluginCommandId);
|
|
15
|
-
const result = await executor({
|
|
16
|
-
kind: "transaction",
|
|
17
|
-
chainId: MONAD_TESTNET_CHAIN_ID,
|
|
18
|
-
to,
|
|
19
|
-
value: valueInWei,
|
|
20
|
-
});
|
|
21
|
-
if (result.status !== "success" || !result.hash) {
|
|
22
|
-
throw new Error(`Failed to send MON payment: status ${result.status}`);
|
|
23
|
-
}
|
|
24
|
-
io.log(`Paid ${amount} MON to ${to}. TxHash: ${result.hash}`);
|
|
25
|
-
return {
|
|
26
|
-
transactionHash: result.hash,
|
|
27
|
-
to,
|
|
28
|
-
amount,
|
|
29
|
-
token,
|
|
30
|
-
memo,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PluginCommand, type CommandIO } from "../../sdk.js";
|
|
2
|
-
export interface CheckReputationResult {
|
|
3
|
-
agentId: string;
|
|
4
|
-
feedbackCount: number;
|
|
5
|
-
averageScore: number;
|
|
6
|
-
trustTier: "HIGH" | "MEDIUM" | "LOW" | "UNRATED";
|
|
7
|
-
}
|
|
8
|
-
export declare class MonadReputationCheckCommand extends PluginCommand<CheckReputationResult> {
|
|
9
|
-
static description: string;
|
|
10
|
-
protected readonly pluginCommandId = "monad:reputation:check";
|
|
11
|
-
execute(io: CommandIO): Promise<CheckReputationResult>;
|
|
12
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { parseAbi } from "viem";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { MONAD_TESTNET_CHAIN_ID, MONAD_TESTNET_ERC8004_REPUTATION_REGISTRY, } from "@monagent/shared";
|
|
4
|
-
import { PluginCommand } from "../../sdk.js";
|
|
5
|
-
const erc8004ReputationAbi = parseAbi([
|
|
6
|
-
"function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)",
|
|
7
|
-
]);
|
|
8
|
-
const checkReputationInputSchema = z.object({
|
|
9
|
-
agentId: z.string().regex(/^\d+$/, "agentId must be a numeric string"),
|
|
10
|
-
tag1: z.string().default(""),
|
|
11
|
-
tag2: z.string().default(""),
|
|
12
|
-
});
|
|
13
|
-
export class MonadReputationCheckCommand extends PluginCommand {
|
|
14
|
-
static description = "Check peer agent reputation on Monad ERC-8004 Reputation Registry";
|
|
15
|
-
pluginCommandId = "monad:reputation:check";
|
|
16
|
-
async execute(io) {
|
|
17
|
-
const rawInputs = await io.resolveInputs(checkReputationInputSchema);
|
|
18
|
-
const { agentId, tag1, tag2 } = checkReputationInputSchema.parse(rawInputs);
|
|
19
|
-
const client = this.ctx.publicClient(MONAD_TESTNET_CHAIN_ID);
|
|
20
|
-
const tokenIdBigInt = BigInt(agentId);
|
|
21
|
-
const [count, summaryValue, decimals] = await client.readContract({
|
|
22
|
-
address: MONAD_TESTNET_ERC8004_REPUTATION_REGISTRY,
|
|
23
|
-
abi: erc8004ReputationAbi,
|
|
24
|
-
functionName: "getSummary",
|
|
25
|
-
args: [tokenIdBigInt, [], tag1, tag2],
|
|
26
|
-
});
|
|
27
|
-
const feedbackCount = Number(count);
|
|
28
|
-
const scoreDivider = 10 ** decimals;
|
|
29
|
-
const averageScore = feedbackCount > 0 ? Number(summaryValue) / (feedbackCount * scoreDivider) : 0;
|
|
30
|
-
let trustTier = "UNRATED";
|
|
31
|
-
if (feedbackCount > 0) {
|
|
32
|
-
if (averageScore >= 80)
|
|
33
|
-
trustTier = "HIGH";
|
|
34
|
-
else if (averageScore >= 50)
|
|
35
|
-
trustTier = "MEDIUM";
|
|
36
|
-
else
|
|
37
|
-
trustTier = "LOW";
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
agentId,
|
|
41
|
-
feedbackCount,
|
|
42
|
-
averageScore,
|
|
43
|
-
trustTier,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type MonadReputationFeedback } from "@monagent/shared";
|
|
2
|
-
import { PluginCommand, type CommandIO } from "../../sdk.js";
|
|
3
|
-
export interface GiveReputationResult {
|
|
4
|
-
transactionHash: `0x${string}`;
|
|
5
|
-
feedback: MonadReputationFeedback;
|
|
6
|
-
registryAddress: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class MonadReputationGiveCommand extends PluginCommand<GiveReputationResult> {
|
|
9
|
-
static description: string;
|
|
10
|
-
protected readonly pluginCommandId = "monad:reputation:give";
|
|
11
|
-
execute(io: CommandIO): Promise<GiveReputationResult>;
|
|
12
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { encodeFunctionData, keccak256, parseAbi, toHex } from "viem";
|
|
2
|
-
import { MONAD_TESTNET_CHAIN_ID, MONAD_TESTNET_ERC8004_REPUTATION_REGISTRY, monadReputationFeedbackSchema, } from "@monagent/shared";
|
|
3
|
-
import { PluginCommand } from "../../sdk.js";
|
|
4
|
-
const erc8004ReputationAbi = parseAbi([
|
|
5
|
-
"function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)",
|
|
6
|
-
]);
|
|
7
|
-
export class MonadReputationGiveCommand extends PluginCommand {
|
|
8
|
-
static description = "Submit on-chain peer feedback to Monad ERC-8004 Reputation Registry";
|
|
9
|
-
pluginCommandId = "monad:reputation:give";
|
|
10
|
-
async execute(io) {
|
|
11
|
-
const rawInputs = await io.resolveInputs(monadReputationFeedbackSchema);
|
|
12
|
-
const feedback = monadReputationFeedbackSchema.parse(rawInputs);
|
|
13
|
-
const feedbackHash = feedback.feedbackURI ? keccak256(toHex(feedback.feedbackURI)) : keccak256(toHex("feedback"));
|
|
14
|
-
const data = encodeFunctionData({
|
|
15
|
-
abi: erc8004ReputationAbi,
|
|
16
|
-
functionName: "giveFeedback",
|
|
17
|
-
args: [
|
|
18
|
-
BigInt(feedback.agentId),
|
|
19
|
-
BigInt(feedback.value),
|
|
20
|
-
feedback.decimals,
|
|
21
|
-
feedback.tag1,
|
|
22
|
-
feedback.tag2,
|
|
23
|
-
feedback.endpoint,
|
|
24
|
-
feedback.feedbackURI,
|
|
25
|
-
feedbackHash,
|
|
26
|
-
],
|
|
27
|
-
});
|
|
28
|
-
const executor = this.ctx.walletExecutor(io, this.pluginCommandId);
|
|
29
|
-
const result = await executor({
|
|
30
|
-
kind: "transaction",
|
|
31
|
-
chainId: MONAD_TESTNET_CHAIN_ID,
|
|
32
|
-
to: MONAD_TESTNET_ERC8004_REPUTATION_REGISTRY,
|
|
33
|
-
data,
|
|
34
|
-
});
|
|
35
|
-
if (result.status !== "success" || !result.hash) {
|
|
36
|
-
throw new Error(`Failed to submit reputation feedback on Monad: status ${result.status}`);
|
|
37
|
-
}
|
|
38
|
-
io.log(`Feedback submitted on Monad! TxHash: ${result.hash}`);
|
|
39
|
-
return {
|
|
40
|
-
transactionHash: result.hash,
|
|
41
|
-
feedback,
|
|
42
|
-
registryAddress: MONAD_TESTNET_ERC8004_REPUTATION_REGISTRY,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { PluginCommand, type CommandIO } from "../../sdk.js";
|
|
2
|
-
export interface X402PayResult {
|
|
3
|
-
url: string;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
response: string;
|
|
6
|
-
paymentSettled: boolean;
|
|
7
|
-
paymentTransactionHash?: `0x${string}`;
|
|
8
|
-
}
|
|
9
|
-
export declare class MonadX402PayCommand extends PluginCommand<X402PayResult> {
|
|
10
|
-
static description: string;
|
|
11
|
-
protected readonly pluginCommandId = "monad:x402:pay";
|
|
12
|
-
execute(io: CommandIO): Promise<X402PayResult>;
|
|
13
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { parseEther } from "viem";
|
|
2
|
-
import { MONAD_TESTNET_CHAIN_ID, monadX402PaymentSchema, } from "@monagent/shared";
|
|
3
|
-
import { PluginCommand } from "../../sdk.js";
|
|
4
|
-
export class MonadX402PayCommand extends PluginCommand {
|
|
5
|
-
static description = "Execute paid tool/API call over HTTP 402 with Monad micropayments";
|
|
6
|
-
pluginCommandId = "monad:x402:pay";
|
|
7
|
-
async execute(io) {
|
|
8
|
-
const rawInputs = await io.resolveInputs(monadX402PaymentSchema);
|
|
9
|
-
const { url, method, body, maxSpendMon } = monadX402PaymentSchema.parse(rawInputs);
|
|
10
|
-
io.log(`Executing request to paid API: ${url}`);
|
|
11
|
-
// Initial probe to check if 402 Payment Required is returned
|
|
12
|
-
const initialRes = await fetch(url, {
|
|
13
|
-
method,
|
|
14
|
-
headers: {
|
|
15
|
-
Accept: "application/json",
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
},
|
|
18
|
-
body: method === "POST" ? body : undefined,
|
|
19
|
-
}).catch(() => null);
|
|
20
|
-
if (initialRes && initialRes.status !== 402) {
|
|
21
|
-
const text = await initialRes.text();
|
|
22
|
-
return {
|
|
23
|
-
url,
|
|
24
|
-
statusCode: initialRes.status,
|
|
25
|
-
response: text,
|
|
26
|
-
paymentSettled: false,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
// Parse x402 payment requirements from headers or body
|
|
30
|
-
const recipient = initialRes?.headers.get("x-payment-recipient") || "0x1111111111111111111111111111111111111111";
|
|
31
|
-
const paymentAmount = initialRes?.headers.get("x-payment-amount") || "0.01";
|
|
32
|
-
if (Number(paymentAmount) > Number(maxSpendMon)) {
|
|
33
|
-
throw new Error(`Requested payment ${paymentAmount} MON exceeds maximum spend limit of ${maxSpendMon} MON`);
|
|
34
|
-
}
|
|
35
|
-
io.log(`Server requested 402 Payment: ${paymentAmount} MON to ${recipient}. Executing on Monad...`);
|
|
36
|
-
const executor = this.ctx.walletExecutor(io, this.pluginCommandId);
|
|
37
|
-
const tx = await executor({
|
|
38
|
-
kind: "transaction",
|
|
39
|
-
chainId: MONAD_TESTNET_CHAIN_ID,
|
|
40
|
-
to: recipient,
|
|
41
|
-
value: parseEther(paymentAmount),
|
|
42
|
-
});
|
|
43
|
-
if (tx.status !== "success" || !tx.hash) {
|
|
44
|
-
throw new Error(`402 payment settlement failed on Monad: ${tx.status}`);
|
|
45
|
-
}
|
|
46
|
-
io.log(`Payment confirmed: ${tx.hash}. Retrying paid API request with payment proof...`);
|
|
47
|
-
// Retry with Monad transaction proof
|
|
48
|
-
const paidRes = await fetch(url, {
|
|
49
|
-
method,
|
|
50
|
-
headers: {
|
|
51
|
-
Accept: "application/json",
|
|
52
|
-
"Content-Type": "application/json",
|
|
53
|
-
"X-Payment-Tx": tx.hash,
|
|
54
|
-
"X-Payment-Chain": String(MONAD_TESTNET_CHAIN_ID),
|
|
55
|
-
},
|
|
56
|
-
body: method === "POST" ? body : undefined,
|
|
57
|
-
});
|
|
58
|
-
const responseText = await paidRes.text();
|
|
59
|
-
return {
|
|
60
|
-
url,
|
|
61
|
-
statusCode: paidRes.status,
|
|
62
|
-
response: responseText,
|
|
63
|
-
paymentSettled: true,
|
|
64
|
-
paymentTransactionHash: tx.hash,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
package/dist/commands.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|