agentsolis-mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +184 -2
- package/dist/abi.js +140 -0
- package/dist/abi.js.map +1 -0
- package/dist/bip39-english.js +261 -0
- package/dist/bip39-english.js.map +1 -0
- package/dist/chain.js +192 -0
- package/dist/chain.js.map +1 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/deal.js +185 -0
- package/dist/deal.js.map +1 -0
- package/dist/fee.js +76 -0
- package/dist/fee.js.map +1 -0
- package/dist/guard.js +65 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/money.js +30 -0
- package/dist/money.js.map +1 -0
- package/dist/resources.js +53 -0
- package/dist/resources.js.map +1 -0
- package/dist/sandbox.js +132 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/server.js +186 -0
- package/dist/server.js.map +1 -0
- package/dist/settings.js +32 -0
- package/dist/settings.js.map +1 -0
- package/dist/status.js +85 -0
- package/dist/status.js.map +1 -0
- package/dist/tools.js +183 -0
- package/dist/tools.js.map +1 -0
- package/package.json +50 -4
- package/server.json +45 -0
package/dist/deal.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { decodeFunctionData, encodeAbiParameters, encodeFunctionData, getAddress, keccak256, toBytes, } from "viem";
|
|
3
|
+
import { approveAbi, proposeDealAbi } from "./abi.js";
|
|
4
|
+
import { CHAIN_ARBITRUM_ONE, ESCROW_V2, FEE_NOTE, PREPARE_WARNING, USDC_ARBITRUM_ONE, } from "./constants.js";
|
|
5
|
+
import { arbitrationReserveUnits, protocolFeeUnits } from "./fee.js";
|
|
6
|
+
import { assertMinimum } from "./fee.js";
|
|
7
|
+
import { rejectKeyMaterial } from "./guard.js";
|
|
8
|
+
import { formatUsdc, parseUsdc } from "./money.js";
|
|
9
|
+
export const MIN_WINDOW = 600;
|
|
10
|
+
export const MAX_WINDOW = 30 * 24 * 60 * 60;
|
|
11
|
+
export const MIN_AUTOMATIC_DECISION = 24 * 60 * 60;
|
|
12
|
+
export const MIN_AUTOMATIC_FALLBACK_BPS = 5_000;
|
|
13
|
+
export const MIN_REVIEW_DECISION = 2 * 24 * 60 * 60;
|
|
14
|
+
export const MIN_REVIEW_ARBITRATION = 7 * 24 * 60 * 60;
|
|
15
|
+
export function requireChecksum(value, label) {
|
|
16
|
+
if (typeof value !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(value)) {
|
|
17
|
+
throw new Error(`${label} must be a checksummed 20-byte address.`);
|
|
18
|
+
}
|
|
19
|
+
let checksum;
|
|
20
|
+
try {
|
|
21
|
+
checksum = getAddress(value);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new Error(`${label} must be a checksummed 20-byte address.`);
|
|
25
|
+
}
|
|
26
|
+
if (value !== checksum) {
|
|
27
|
+
throw new Error(`${label} must be a checksummed address.`);
|
|
28
|
+
}
|
|
29
|
+
if (checksum === "0x0000000000000000000000000000000000000000") {
|
|
30
|
+
throw new Error(`${label} cannot be the zero address.`);
|
|
31
|
+
}
|
|
32
|
+
return checksum;
|
|
33
|
+
}
|
|
34
|
+
export function manifestHashOf(manifest) {
|
|
35
|
+
return keccak256(toBytes(manifest));
|
|
36
|
+
}
|
|
37
|
+
export function computeDealId(escrow, chainId, buyer, seller, salt) {
|
|
38
|
+
return keccak256(encodeAbiParameters([
|
|
39
|
+
{ type: "address" },
|
|
40
|
+
{ type: "uint256" },
|
|
41
|
+
{ type: "address" },
|
|
42
|
+
{ type: "address" },
|
|
43
|
+
{ type: "bytes32" },
|
|
44
|
+
], [escrow, BigInt(chainId), buyer, seller, salt]));
|
|
45
|
+
}
|
|
46
|
+
function requireWindow(name, value, minimum) {
|
|
47
|
+
if (!Number.isInteger(value) || value < minimum || value > MAX_WINDOW) {
|
|
48
|
+
throw new Error(`${name} must be a whole number of seconds from ${minimum} to ${MAX_WINDOW}.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function parseSalt(salt, randomSalt) {
|
|
52
|
+
if (salt === undefined || salt === "") {
|
|
53
|
+
return randomSalt ? randomSalt() : `0x${randomBytes(32).toString("hex")}`;
|
|
54
|
+
}
|
|
55
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(salt)) {
|
|
56
|
+
throw new Error("salt must be a 0x-prefixed 32-byte hex value.");
|
|
57
|
+
}
|
|
58
|
+
return salt;
|
|
59
|
+
}
|
|
60
|
+
export function prepareDeal(input, context) {
|
|
61
|
+
rejectKeyMaterial(input);
|
|
62
|
+
if (context.chainId !== CHAIN_ARBITRUM_ONE) {
|
|
63
|
+
throw new Error("prepare_deal in this version only builds Arbitrum One (chain 42161) transactions. Nothing was sent.");
|
|
64
|
+
}
|
|
65
|
+
if (context.paused) {
|
|
66
|
+
throw new Error("The live config says paused. No transaction was built.");
|
|
67
|
+
}
|
|
68
|
+
if (!context.acceptingFunds) {
|
|
69
|
+
throw new Error("The live config is not accepting funds. No transaction was built.");
|
|
70
|
+
}
|
|
71
|
+
if (!context.publicAccess) {
|
|
72
|
+
throw new Error("Public access is closed. No transaction was built.");
|
|
73
|
+
}
|
|
74
|
+
if (getAddress(context.escrow) !== ESCROW_V2 || getAddress(context.token) !== USDC_ARBITRUM_ONE) {
|
|
75
|
+
throw new Error("Config addresses do not match the published Arbitrum One escrow and USDC contracts. No transaction was built.");
|
|
76
|
+
}
|
|
77
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(context.policyHash)) {
|
|
78
|
+
throw new Error("The live policy hash is missing. No transaction was built.");
|
|
79
|
+
}
|
|
80
|
+
const buyer = requireChecksum(input.buyer, "buyer");
|
|
81
|
+
const seller = requireChecksum(input.seller, "seller");
|
|
82
|
+
if (buyer === seller)
|
|
83
|
+
throw new Error("Buyer and seller must be different wallets.");
|
|
84
|
+
if (input.mode !== "automatic" && input.mode !== "buyer_review") {
|
|
85
|
+
throw new Error("mode must be automatic or buyer_review.");
|
|
86
|
+
}
|
|
87
|
+
if (typeof input.manifest !== "string" || input.manifest.length < 1 || input.manifest.length > 20_000) {
|
|
88
|
+
throw new Error("manifest must be the agreed text, from 1 to 20000 characters.");
|
|
89
|
+
}
|
|
90
|
+
requireWindow("acceptance_window", input.acceptance_window, MIN_WINDOW);
|
|
91
|
+
requireWindow("delivery_window", input.delivery_window, MIN_WINDOW);
|
|
92
|
+
if (input.mode === "automatic") {
|
|
93
|
+
requireWindow("decision_window", input.decision_window, MIN_AUTOMATIC_DECISION);
|
|
94
|
+
requireWindow("arbitration_window", input.arbitration_window, MIN_WINDOW);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
requireWindow("decision_window", input.decision_window, MIN_REVIEW_DECISION);
|
|
98
|
+
requireWindow("arbitration_window", input.arbitration_window, MIN_REVIEW_ARBITRATION);
|
|
99
|
+
}
|
|
100
|
+
if (!Number.isInteger(input.fallback_seller_bps) || input.fallback_seller_bps < 0 || input.fallback_seller_bps > 10_000) {
|
|
101
|
+
throw new Error("fallback_seller_bps must be an integer from 0 to 10000.");
|
|
102
|
+
}
|
|
103
|
+
if (input.mode === "automatic" && input.fallback_seller_bps < MIN_AUTOMATIC_FALLBACK_BPS) {
|
|
104
|
+
throw new Error("Automatic deals require fallback_seller_bps of at least 5000.");
|
|
105
|
+
}
|
|
106
|
+
const amount = parseUsdc(input.amount_usdc);
|
|
107
|
+
assertMinimum(amount, input.mode);
|
|
108
|
+
const fee = protocolFeeUnits(amount);
|
|
109
|
+
const reserve = input.mode === "buyer_review" ? arbitrationReserveUnits(amount) : 0n;
|
|
110
|
+
if (context.onChainFeeUnits !== undefined && context.onChainFeeUnits !== fee) {
|
|
111
|
+
throw new Error(`On-chain protocol fee ${context.onChainFeeUnits.toString()} units does not match the formula ${fee.toString()} units. No transaction was built.`);
|
|
112
|
+
}
|
|
113
|
+
if (input.mode === "buyer_review" &&
|
|
114
|
+
context.onChainReserveUnits !== undefined &&
|
|
115
|
+
context.onChainReserveUnits !== reserve) {
|
|
116
|
+
throw new Error("On-chain review reserve does not match the formula. No transaction was built.");
|
|
117
|
+
}
|
|
118
|
+
const buyerTotal = amount + reserve + fee;
|
|
119
|
+
const salt = parseSalt(input.salt, context.randomSalt);
|
|
120
|
+
const manifestHash = manifestHashOf(input.manifest);
|
|
121
|
+
const policyHash = context.policyHash;
|
|
122
|
+
const dealId = computeDealId(context.escrow, context.chainId, buyer, seller, salt);
|
|
123
|
+
const modeIndex = input.mode === "automatic" ? 0 : 1;
|
|
124
|
+
const approval = encodeFunctionData({
|
|
125
|
+
abi: approveAbi,
|
|
126
|
+
functionName: "approve",
|
|
127
|
+
args: [context.escrow, buyerTotal],
|
|
128
|
+
});
|
|
129
|
+
const proposal = encodeFunctionData({
|
|
130
|
+
abi: proposeDealAbi,
|
|
131
|
+
functionName: "proposeDeal",
|
|
132
|
+
args: [
|
|
133
|
+
{
|
|
134
|
+
salt,
|
|
135
|
+
seller,
|
|
136
|
+
mode: modeIndex,
|
|
137
|
+
amount,
|
|
138
|
+
arbitrationReserve: reserve,
|
|
139
|
+
fallbackSellerBps: input.fallback_seller_bps,
|
|
140
|
+
manifestHash,
|
|
141
|
+
policyHash,
|
|
142
|
+
acceptanceWindow: BigInt(input.acceptance_window),
|
|
143
|
+
deliveryWindow: BigInt(input.delivery_window),
|
|
144
|
+
decisionWindow: BigInt(input.decision_window),
|
|
145
|
+
arbitrationWindow: BigInt(input.arbitration_window),
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
const decodedApprove = decodeFunctionData({ abi: approveAbi, data: approval });
|
|
150
|
+
const decodedProposal = decodeFunctionData({ abi: proposeDealAbi, data: proposal });
|
|
151
|
+
if (decodedApprove.functionName !== "approve" || decodedProposal.functionName !== "proposeDeal") {
|
|
152
|
+
throw new Error("Calldata could not be decoded. No transaction was returned.");
|
|
153
|
+
}
|
|
154
|
+
const warnings = [
|
|
155
|
+
PREPARE_WARNING,
|
|
156
|
+
FEE_NOTE,
|
|
157
|
+
"Funds are locked, then paid out, refunded or split by the agreed rules.",
|
|
158
|
+
];
|
|
159
|
+
if (context.couponsEnabled || context.foundingVouchersEnabled) {
|
|
160
|
+
warnings.push("This unsigned transaction uses the base protocol fee. It does not apply a coupon or Founding waiver.");
|
|
161
|
+
}
|
|
162
|
+
const transactions = [
|
|
163
|
+
{ purpose: "usdc_approve", chainId: CHAIN_ARBITRUM_ONE, to: context.token, data: approval, value: "0" },
|
|
164
|
+
{ purpose: "propose_deal", chainId: CHAIN_ARBITRUM_ONE, to: context.escrow, data: proposal, value: "0" },
|
|
165
|
+
];
|
|
166
|
+
return {
|
|
167
|
+
deal_id: dealId,
|
|
168
|
+
manifest_hash: manifestHash,
|
|
169
|
+
policy_hash: policyHash,
|
|
170
|
+
amount_units: amount.toString(),
|
|
171
|
+
amount_usdc: formatUsdc(amount),
|
|
172
|
+
buyer_total_units: buyerTotal.toString(),
|
|
173
|
+
buyer_total_usdc: formatUsdc(buyerTotal),
|
|
174
|
+
protocol_fee_units: fee.toString(),
|
|
175
|
+
protocol_fee_usdc: formatUsdc(fee),
|
|
176
|
+
reserve_units: reserve.toString(),
|
|
177
|
+
buyer,
|
|
178
|
+
seller,
|
|
179
|
+
mode: input.mode,
|
|
180
|
+
salt,
|
|
181
|
+
unsigned_transactions: transactions,
|
|
182
|
+
warnings,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=deal.js.map
|
package/dist/deal.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deal.js","sourceRoot":"","sources":["../src/deal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,OAAO,GAER,MAA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er fee math matching fee_math.py and the v2 escrow.
|
|
3
|
+
* Fee = amount * 150 / 10000, capped at 50 USDC.
|
|
4
|
+
* Buyer Review reserve = amount * 500 / 10000, minimum 5 USDC, maximum 100 USDC.
|
|
5
|
+
* Division truncates toward zero, the same way as Solidity and Python //.
|
|
6
|
+
*/
|
|
7
|
+
import { FEE_NOTE } from "./constants.js";
|
|
8
|
+
import { rejectKeyMaterial } from "./guard.js";
|
|
9
|
+
import { formatUsdc, parseUsdc } from "./money.js";
|
|
10
|
+
export const FEE_BPS = 150n;
|
|
11
|
+
export const BPS_DENOMINATOR = 10000n;
|
|
12
|
+
export const MAX_PROTOCOL_FEE_UNITS = 50000000n;
|
|
13
|
+
export const MIN_AUTOMATIC_UNITS = 10000000n;
|
|
14
|
+
export const MIN_REVIEW_UNITS = 100000000n;
|
|
15
|
+
export const MIN_RESERVE_UNITS = 5000000n;
|
|
16
|
+
export const MAX_RESERVE_UNITS = 100000000n;
|
|
17
|
+
export function protocolFeeUnits(amountUnits) {
|
|
18
|
+
if (amountUnits < 0n)
|
|
19
|
+
throw new Error("amount");
|
|
20
|
+
const fee = (amountUnits * FEE_BPS) / BPS_DENOMINATOR;
|
|
21
|
+
return fee > MAX_PROTOCOL_FEE_UNITS ? MAX_PROTOCOL_FEE_UNITS : fee;
|
|
22
|
+
}
|
|
23
|
+
export function arbitrationReserveUnits(amountUnits) {
|
|
24
|
+
let reserve = (amountUnits * 500n) / BPS_DENOMINATOR;
|
|
25
|
+
if (reserve < MIN_RESERVE_UNITS)
|
|
26
|
+
reserve = MIN_RESERVE_UNITS;
|
|
27
|
+
if (reserve > MAX_RESERVE_UNITS)
|
|
28
|
+
reserve = MAX_RESERVE_UNITS;
|
|
29
|
+
return reserve;
|
|
30
|
+
}
|
|
31
|
+
export function assertMinimum(amountUnits, mode) {
|
|
32
|
+
if (mode === "automatic" && amountUnits < MIN_AUTOMATIC_UNITS) {
|
|
33
|
+
throw new Error(`${formatUsdc(amountUnits)} USDC is below the 10 USDC minimum for an automatic deal.`);
|
|
34
|
+
}
|
|
35
|
+
if (mode === "buyer_review" && amountUnits < MIN_REVIEW_UNITS) {
|
|
36
|
+
throw new Error(`${formatUsdc(amountUnits)} USDC is below the 100 USDC minimum for a buyer review deal.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function quoteFee(input) {
|
|
40
|
+
rejectKeyMaterial(input);
|
|
41
|
+
if (input.mode !== "automatic" && input.mode !== "buyer_review") {
|
|
42
|
+
throw new Error("mode must be automatic or buyer_review.");
|
|
43
|
+
}
|
|
44
|
+
if (input.starter !== "buyer" && input.starter !== "seller") {
|
|
45
|
+
throw new Error("starter must be buyer or seller.");
|
|
46
|
+
}
|
|
47
|
+
const amount = parseUsdc(input.amount_usdc);
|
|
48
|
+
assertMinimum(amount, input.mode);
|
|
49
|
+
const fee = protocolFeeUnits(amount);
|
|
50
|
+
const reserve = input.mode === "buyer_review" ? arbitrationReserveUnits(amount) : 0n;
|
|
51
|
+
const buyerPays = input.starter === "buyer";
|
|
52
|
+
const buyerDeposit = amount + reserve + (buyerPays ? fee : 0n);
|
|
53
|
+
const sellerReceives = amount - (buyerPays ? 0n : fee);
|
|
54
|
+
const quote = {
|
|
55
|
+
amount_usdc: formatUsdc(amount),
|
|
56
|
+
amount_units: amount.toString(),
|
|
57
|
+
mode: input.mode,
|
|
58
|
+
starter: input.starter,
|
|
59
|
+
fee: formatUsdc(fee),
|
|
60
|
+
fee_units: fee.toString(),
|
|
61
|
+
fee_capped: (amount * FEE_BPS) / BPS_DENOMINATOR > MAX_PROTOCOL_FEE_UNITS,
|
|
62
|
+
buyer_deposit: formatUsdc(buyerDeposit),
|
|
63
|
+
buyer_deposit_units: buyerDeposit.toString(),
|
|
64
|
+
seller_receives: formatUsdc(sellerReceives),
|
|
65
|
+
seller_receives_units: sellerReceives.toString(),
|
|
66
|
+
minimum_usdc: input.mode === "automatic" ? "10.00" : "100.00",
|
|
67
|
+
minimum_ok: true,
|
|
68
|
+
note: FEE_NOTE,
|
|
69
|
+
};
|
|
70
|
+
if (input.mode === "buyer_review") {
|
|
71
|
+
quote.review_bond_each_side = formatUsdc(reserve);
|
|
72
|
+
quote.review_bond_each_side_units = reserve.toString();
|
|
73
|
+
}
|
|
74
|
+
return quote;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=fee.js.map
|
package/dist/fee.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee.js","sourceRoot":"","sources":["../src/fee.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;AAC5B,MAAM,CAAC,MAAM,eAAe,GAAG,MAAO,CAAC;AACvC,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAW,CAAC;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAW,CAAC;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAY,CAAC;AAK9C,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAClD,IAAI,WAAW,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,eAAe,CAAC;IACtD,OAAO,GAAG,GAAG,sBAAsB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,WAAmB;IACzD,IAAI,OAAO,GAAG,CAAC,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AO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/guard.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BIP39_ENGLISH_SET } from "./bip39-english.js";
|
|
2
|
+
const KEY_MESSAGE = "This tool does not accept a private key or seed phrase. Remove it and try again. Nothing was sent.";
|
|
3
|
+
const HEX_64 = /(?:^|[^0-9a-fA-F])(?:0x)?([0-9a-fA-F]{64})(?![0-9a-fA-F])/gi;
|
|
4
|
+
/** Fields whose entire value may be a 0x-prefixed 32-byte id. A bare 64-hex string is still rejected. */
|
|
5
|
+
const HEX32_FIELDS = new Set(["salt", "deal_id"]);
|
|
6
|
+
export class InputRejected extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(KEY_MESSAGE);
|
|
9
|
+
this.name = "InputRejected";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function looksLikeSeedPhrase(value) {
|
|
13
|
+
const entire = value.trim().split(/\s+/).filter(Boolean);
|
|
14
|
+
if ((entire.length === 12 || entire.length === 24) &&
|
|
15
|
+
entire.every((word) => /^[A-Za-z]+$/.test(word))) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const lowered = entire.map((word) => word.toLowerCase());
|
|
19
|
+
if ((lowered.length === 12 || lowered.length === 24) && lowered.every((word) => BIP39_ENGLISH_SET.has(word))) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const words = value.toLowerCase().split(/[^a-z]+/).filter(Boolean);
|
|
23
|
+
for (const size of [12, 24]) {
|
|
24
|
+
for (let index = 0; index + size <= words.length; index += 1) {
|
|
25
|
+
let match = true;
|
|
26
|
+
for (let offset = 0; offset < size; offset += 1) {
|
|
27
|
+
if (!BIP39_ENGLISH_SET.has(words[index + offset] ?? "")) {
|
|
28
|
+
match = false;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (match)
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
function fieldHasKeyMaterial(field, value) {
|
|
39
|
+
if (looksLikeSeedPhrase(value))
|
|
40
|
+
return true;
|
|
41
|
+
const trimmed = value.trim();
|
|
42
|
+
if (HEX32_FIELDS.has(field) && /^0x[0-9a-fA-F]{64}$/.test(trimmed))
|
|
43
|
+
return false;
|
|
44
|
+
if (/^[0-9a-fA-F]{64}$/.test(trimmed))
|
|
45
|
+
return true;
|
|
46
|
+
HEX_64.lastIndex = 0;
|
|
47
|
+
return HEX_64.test(value);
|
|
48
|
+
}
|
|
49
|
+
export function rejectKeyMaterial(value, field = "input") {
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
if (fieldHasKeyMaterial(field, value))
|
|
52
|
+
throw new InputRejected();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
for (const item of value)
|
|
57
|
+
rejectKeyMaterial(item, field);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (value && typeof value === "object") {
|
|
61
|
+
for (const [key, item] of Object.entries(value))
|
|
62
|
+
rejectKeyMaterial(item, key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,GACf,oGAAoG,CAAC;AAEvG,MAAM,MAAM,GAAG,6DAA6D,CAAC;AAE7E,yGAAyG;AACzG,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAElD,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;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AAO,CAAC,KAAK,CAAC;YAAE,iBAAiB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChF,CAAC;AACH,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* stdio entry. stdout is reserved for MCP messages. Do not write logs here.
|
|
4
|
+
*/
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { createAgentServer } from "./server.js";
|
|
7
|
+
const server = createAgentServer();
|
|
8
|
+
await server.connect(new StdioServerTransport());
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;GAEG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;AACnC,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC"}
|
package/dist/money.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const SCALE = 1000000n;
|
|
2
|
+
export function parseUsdc(value) {
|
|
3
|
+
if (typeof value !== "string") {
|
|
4
|
+
throw new Error("Enter a USDC amount as a decimal string.");
|
|
5
|
+
}
|
|
6
|
+
const trimmed = value.trim();
|
|
7
|
+
if (!/^\d+(\.\d{1,6})?$/.test(trimmed)) {
|
|
8
|
+
throw new Error("Enter a USDC amount with at most 6 decimal places.");
|
|
9
|
+
}
|
|
10
|
+
const [whole, frac = ""] = trimmed.split(".");
|
|
11
|
+
const units = BigInt(whole) * SCALE + BigInt(frac.padEnd(6, "0"));
|
|
12
|
+
if (units <= 0n) {
|
|
13
|
+
throw new Error("Budget must be greater than zero.");
|
|
14
|
+
}
|
|
15
|
+
if (units >= 2n ** 256n) {
|
|
16
|
+
throw new Error("Amount is too large.");
|
|
17
|
+
}
|
|
18
|
+
return units;
|
|
19
|
+
}
|
|
20
|
+
/** USDC decimal string with at least two fraction digits and no thousands separator. */
|
|
21
|
+
export function formatUsdc(units) {
|
|
22
|
+
const negative = units < 0n;
|
|
23
|
+
const absolute = negative ? -units : units;
|
|
24
|
+
const whole = absolute / SCALE;
|
|
25
|
+
let fraction = (absolute % SCALE).toString().padStart(6, "0").replace(/0+$/, "");
|
|
26
|
+
if (fraction.length < 2)
|
|
27
|
+
fraction = fraction.padEnd(2, "0");
|
|
28
|
+
return `${negative ? "-" : ""}${whole.toString()}.${fraction}`;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=money.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.js","sourceRoot":"","sources":["../src/money.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,QAAU,CAAC;AAEzB,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAClE,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,KAAK,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,QAAQ,GAAG,KAAK,GAAG,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3C,MAAM,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC/B,IAAI,QAAQ,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5D,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,QAAQ,EAAE,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ESCROW_SEPOLIA, ESCROW_V1, ESCROW_V2, USDC_ARBITRUM_ONE, USDC_ARBITRUM_SEPOLIA, } from "./constants.js";
|
|
2
|
+
export const addressesResource = {
|
|
3
|
+
uri: "agentsolis://addresses",
|
|
4
|
+
mimeType: "application/json",
|
|
5
|
+
text: JSON.stringify({
|
|
6
|
+
mainnet: {
|
|
7
|
+
chain_id: 42161,
|
|
8
|
+
network: "Arbitrum One",
|
|
9
|
+
escrow_v2: ESCROW_V2,
|
|
10
|
+
escrow_v1_legacy_read_only: ESCROW_V1,
|
|
11
|
+
usdc: USDC_ARBITRUM_ONE,
|
|
12
|
+
status: "working contract. This server only reads it and builds unsigned calldata.",
|
|
13
|
+
},
|
|
14
|
+
testnet: {
|
|
15
|
+
chain_id: 421614,
|
|
16
|
+
network: "Arbitrum Sepolia",
|
|
17
|
+
escrow: ESCROW_SEPOLIA,
|
|
18
|
+
usdc: USDC_ARBITRUM_SEPOLIA,
|
|
19
|
+
status: "paused test deployment with public access closed. This server does not send transactions to it.",
|
|
20
|
+
},
|
|
21
|
+
}, null, 2),
|
|
22
|
+
};
|
|
23
|
+
export const rulesResource = {
|
|
24
|
+
uri: "agentsolis://rules",
|
|
25
|
+
mimeType: "text/plain",
|
|
26
|
+
text: [
|
|
27
|
+
"AgentSolis escrow rules used by this tool",
|
|
28
|
+
"",
|
|
29
|
+
"Network: Arbitrum One, chain 42161. Token: Circle native USDC, 6 decimals.",
|
|
30
|
+
"Modes: Automatic from 10 USDC. Buyer Review from 100 USDC.",
|
|
31
|
+
"Protocol fee: 1.5% of the job amount, capped at 50 USDC, paid by the side that starts the deal, and only when the seller is paid.",
|
|
32
|
+
"No protocol fee on refund, cancel, expiry, buyer win, or fallback split.",
|
|
33
|
+
"Buyer-started deal: the fee is added to the buyer deposit. Seller-started offer: the fee is taken from the seller payout. This tool prepares buyer-started deals only.",
|
|
34
|
+
"Buyer Review reserve and seller bond: 5% each side, minimum 5 USDC, maximum 100 USDC.",
|
|
35
|
+
"Windows: 10 minutes to 30 days. Automatic decision window at least 1 day and seller fallback at least 50%. Buyer Review decision window at least 2 days and arbitration window at least 7 days.",
|
|
36
|
+
"Funds are locked, then paid out, refunded or split by the agreed rules.",
|
|
37
|
+
"The contract is not upgradeable. Pause stops new deals only. Fee changes have a 48-hour delay and stay at or below 3% and a 100 USDC cap. The team holds the owner keys. This tool does not.",
|
|
38
|
+
"",
|
|
39
|
+
"Escrow contract: source verified on Arbiscan and Sourcify (14 Nov 2026); no independent review yet.",
|
|
40
|
+
"",
|
|
41
|
+
"Not done, as of 23 Nov 2026:",
|
|
42
|
+
"- No independent review.",
|
|
43
|
+
"- No production x402.",
|
|
44
|
+
"- No deals recorded yet.",
|
|
45
|
+
"- This package does not sign, hold keys, or broadcast.",
|
|
46
|
+
"",
|
|
47
|
+
"AgentSolis never asks for a private key or seed phrase.",
|
|
48
|
+
"Live config: https://agentsolis.solists.com.tr/mainnet/config",
|
|
49
|
+
"Wallet-free demo: https://agentsolis.solists.com.tr/play",
|
|
50
|
+
"Wallet-free MCP tools: sandbox_create_deal, sandbox_advance_deal, sandbox_get_deal (simulated, no real funds).",
|
|
51
|
+
].join("\n"),
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,wBAAwB;IAC7B,QAAQ,EAAE,kBAAkB;IAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;QACE,OAAO,EAAE;YACP,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,cAAc;YACvB,SAAS,EAAE,SAAS;YACpB,0BAA0B,EAAE,SAAS;YACrC,IAAI,EAAE,iBAAiB;YACvB,MAAM,EAAE,2EAA2E;SACpF;QACD,OAAO,EAAE;YACP,QAAQ,EAAE,MAAM;YAChB,OAAO,EAAE,kBAAkB;YAC3B,MAAM,EAAE,cAAc;YACtB,IAAI,EAAE,qBAAqB;YAC3B,MAAM,EAAE,iGAAiG;SAC1G;KACF,EACD,IAAI,EACJ,CAAC,CACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,oBAAoB;IACzB,QAAQ,EAAE,YAAY;IACtB,IAAI,EAAE;QACJ,2CAA2C;QAC3C,EAAE;QACF,4EAA4E;QAC5E,4DAA4D;QAC5D,mIAAmI;QACnI,0EAA0E;QAC1E,wKAAwK;QACxK,uFAAuF;QACvF,iMAAiM;QACjM,yEAAyE;QACzE,8LAA8L;QAC9L,EAAE;QACF,qGAAqG;QACrG,EAAE;QACF,8BAA8B;QAC9B,0BAA0B;QAC1B,uBAAuB;QACvB,0BAA0B;QAC1B,wDAAwD;QACxD,EAAE;QACF,yDAAyD;QACzD,+DAA+D;QAC/D,0DAA0D;QAC1D,gHAAgH;KACjH,CAAC,IAAI,CAAC,IAAI,CAAC;CACb,CAAC"}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet-free sandbox. Everything here is simulated in this process's memory.
|
|
3
|
+
* It never reads or writes a blockchain, never uses a wallet, key or USDC,
|
|
4
|
+
* and never calls the network. Data is lost when the process stops.
|
|
5
|
+
*/
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
7
|
+
import { quoteFee } from "./fee.js";
|
|
8
|
+
import { rejectKeyMaterial } from "./guard.js";
|
|
9
|
+
import { formatUsdc } from "./money.js";
|
|
10
|
+
export const SANDBOX_LABEL = "SANDBOX - simulated, no real funds";
|
|
11
|
+
export const SANDBOX_NOTE = "Nothing touched a blockchain. No wallet, key or USDC was used. This is a simplified flow: real deals also have deadlines, fallback splits and Buyer Review arbitration (see agentsolis://rules). For a real deal, use prepare_deal; a wallet owner signs.";
|
|
12
|
+
export const SANDBOX_MAX_DEALS = 50;
|
|
13
|
+
const NEXT = {
|
|
14
|
+
funded: ["deliver", "refund"],
|
|
15
|
+
delivered: ["release"],
|
|
16
|
+
released: [],
|
|
17
|
+
refunded: [],
|
|
18
|
+
};
|
|
19
|
+
const HINT = {
|
|
20
|
+
funded: "Simulated USDC is locked. Next: call sandbox_advance_deal with action 'deliver' (seller delivers) or 'refund' (buyer gets everything back, no fee).",
|
|
21
|
+
delivered: "The seller marked the job delivered. Next: call sandbox_advance_deal with action 'release' to pay the seller.",
|
|
22
|
+
released: "Done. The seller was paid and the protocol fee was charged, all simulated. Try prepare_deal to see a real unsigned transaction.",
|
|
23
|
+
refunded: "Done. The buyer got the full deposit back and no fee was charged, all simulated.",
|
|
24
|
+
};
|
|
25
|
+
function addUnits(...values) {
|
|
26
|
+
return formatUsdc(values.reduce((sum, value) => sum + BigInt(value), 0n));
|
|
27
|
+
}
|
|
28
|
+
export class SandboxStore {
|
|
29
|
+
now;
|
|
30
|
+
deals = new Map();
|
|
31
|
+
constructor(now = () => new Date()) {
|
|
32
|
+
this.now = now;
|
|
33
|
+
}
|
|
34
|
+
create(input) {
|
|
35
|
+
rejectKeyMaterial(input);
|
|
36
|
+
const job = (input.job_description ?? "").trim();
|
|
37
|
+
if (!job)
|
|
38
|
+
throw new Error("job_description is required. Example: 'Translate a 300-word product page to Spanish.'");
|
|
39
|
+
if (job.length > 2000)
|
|
40
|
+
throw new Error("job_description must be 2000 characters or fewer.");
|
|
41
|
+
const mode = input.mode ?? "automatic";
|
|
42
|
+
const quote = quoteFee({ amount_usdc: input.amount_usdc, mode, starter: "buyer" });
|
|
43
|
+
const reserveUnits = quote.review_bond_each_side_units ?? "0";
|
|
44
|
+
if (this.deals.size >= SANDBOX_MAX_DEALS) {
|
|
45
|
+
const oldest = this.deals.keys().next().value;
|
|
46
|
+
if (oldest !== undefined)
|
|
47
|
+
this.deals.delete(oldest);
|
|
48
|
+
}
|
|
49
|
+
const deal_id = `sandbox-${randomBytes(6).toString("hex")}`;
|
|
50
|
+
const deal = {
|
|
51
|
+
deal_id,
|
|
52
|
+
mode,
|
|
53
|
+
job_description: job,
|
|
54
|
+
state: "funded",
|
|
55
|
+
amount_usdc: quote.amount_usdc,
|
|
56
|
+
fee: quote.fee,
|
|
57
|
+
review_reserve: addUnits(reserveUnits),
|
|
58
|
+
buyer_locked: quote.buyer_deposit,
|
|
59
|
+
history: [{ step: "created and funded (simulated)", at: this.now().toISOString() }],
|
|
60
|
+
units: { amount: quote.amount_units, fee: quote.fee_units, reserve: reserveUnits },
|
|
61
|
+
};
|
|
62
|
+
this.deals.set(deal_id, deal);
|
|
63
|
+
return this.view(deal);
|
|
64
|
+
}
|
|
65
|
+
get(dealId) {
|
|
66
|
+
return this.view(this.find(dealId));
|
|
67
|
+
}
|
|
68
|
+
advance(dealId, action) {
|
|
69
|
+
const deal = this.find(dealId);
|
|
70
|
+
const allowed = NEXT[deal.state];
|
|
71
|
+
if (!allowed.includes(action)) {
|
|
72
|
+
const options = allowed.length ? allowed.join(" or ") : "nothing, the deal is finished";
|
|
73
|
+
throw new Error(`${SANDBOX_LABEL}: cannot '${action}' a ${deal.state} deal. Allowed now: ${options}.`);
|
|
74
|
+
}
|
|
75
|
+
const at = this.now().toISOString();
|
|
76
|
+
if (action === "deliver") {
|
|
77
|
+
deal.state = "delivered";
|
|
78
|
+
deal.history.push({ step: "seller marked delivered (simulated)", at });
|
|
79
|
+
}
|
|
80
|
+
else if (action === "release") {
|
|
81
|
+
deal.state = "released";
|
|
82
|
+
deal.payout = {
|
|
83
|
+
seller_received: addUnits(deal.units.amount),
|
|
84
|
+
protocol_fee: addUnits(deal.units.fee),
|
|
85
|
+
returned_to_buyer: addUnits(deal.units.reserve),
|
|
86
|
+
};
|
|
87
|
+
deal.history.push({ step: "buyer released payment to seller (simulated)", at });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
deal.state = "refunded";
|
|
91
|
+
deal.payout = {
|
|
92
|
+
seller_received: "0.00",
|
|
93
|
+
protocol_fee: "0.00",
|
|
94
|
+
returned_to_buyer: addUnits(deal.units.amount, deal.units.fee, deal.units.reserve),
|
|
95
|
+
};
|
|
96
|
+
deal.history.push({ step: "refunded to buyer (simulated)", at });
|
|
97
|
+
}
|
|
98
|
+
return this.view(deal);
|
|
99
|
+
}
|
|
100
|
+
find(dealId) {
|
|
101
|
+
rejectKeyMaterial(dealId, "sandbox_deal_id");
|
|
102
|
+
const deal = this.deals.get(String(dealId ?? "").trim());
|
|
103
|
+
if (!deal) {
|
|
104
|
+
throw new Error(`${SANDBOX_LABEL}: no sandbox deal with id '${dealId}'. Sandbox deals live only in this server process. Create one with sandbox_create_deal.`);
|
|
105
|
+
}
|
|
106
|
+
return deal;
|
|
107
|
+
}
|
|
108
|
+
view(deal) {
|
|
109
|
+
return {
|
|
110
|
+
sandbox: true,
|
|
111
|
+
label: SANDBOX_LABEL,
|
|
112
|
+
deal_id: deal.deal_id,
|
|
113
|
+
state: deal.state,
|
|
114
|
+
mode: deal.mode,
|
|
115
|
+
job_description: deal.job_description,
|
|
116
|
+
buyer: "demo-buyer (simulated)",
|
|
117
|
+
seller: "demo-seller (simulated)",
|
|
118
|
+
amounts_usdc: {
|
|
119
|
+
job: deal.amount_usdc,
|
|
120
|
+
protocol_fee_if_seller_paid: deal.fee,
|
|
121
|
+
review_reserve: deal.review_reserve,
|
|
122
|
+
buyer_locked: deal.buyer_locked,
|
|
123
|
+
},
|
|
124
|
+
...(deal.payout ? { payout_usdc: deal.payout } : {}),
|
|
125
|
+
allowed_actions: NEXT[deal.state],
|
|
126
|
+
next: HINT[deal.state],
|
|
127
|
+
history: deal.history,
|
|
128
|
+
note: SANDBOX_NOTE,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAa,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,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