@agether/sdk 2.3.4 → 2.4.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/dist/cli.d.ts +27 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +341 -1
- package/dist/clients/AgentIdentityClient.d.ts +188 -0
- package/dist/clients/AgentIdentityClient.d.ts.map +1 -0
- package/dist/clients/AgentIdentityClient.js +337 -0
- package/dist/clients/AgetherClient.d.ts +74 -0
- package/dist/clients/AgetherClient.d.ts.map +1 -0
- package/dist/clients/AgetherClient.js +172 -0
- package/dist/clients/MorphoClient.d.ts +482 -0
- package/dist/clients/MorphoClient.d.ts.map +1 -0
- package/dist/clients/MorphoClient.js +1717 -0
- package/dist/clients/ScoringClient.d.ts +89 -0
- package/dist/clients/ScoringClient.d.ts.map +1 -0
- package/dist/clients/ScoringClient.js +93 -0
- package/dist/clients/X402Client.d.ts +168 -0
- package/dist/clients/X402Client.d.ts.map +1 -0
- package/dist/clients/X402Client.js +378 -0
- package/dist/index.d.mts +87 -1
- package/dist/index.d.ts +87 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +341 -1
- package/dist/index.mjs +341 -1
- package/dist/types/index.d.ts +132 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +46 -0
- package/dist/utils/abis.d.ts +29 -0
- package/dist/utils/abis.d.ts.map +1 -0
- package/dist/utils/abis.js +139 -0
- package/dist/utils/config.d.ts +36 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +168 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +75 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1047,7 +1047,259 @@ var MorphoClient = class {
|
|
|
1047
1047
|
};
|
|
1048
1048
|
}
|
|
1049
1049
|
// ════════════════════════════════════════════════════════
|
|
1050
|
-
// Lending
|
|
1050
|
+
// Supply-Side (Lending) — earn yield by supplying USDC
|
|
1051
|
+
// ════════════════════════════════════════════════════════
|
|
1052
|
+
/**
|
|
1053
|
+
* Supply USDC to a Morpho Blue market as a lender (earn yield).
|
|
1054
|
+
*
|
|
1055
|
+
* Unlike `supplyCollateral` (borrower-side), this is the **lender-side**:
|
|
1056
|
+
* you deposit the loanToken (USDC) into the market's supply pool and earn
|
|
1057
|
+
* interest paid by borrowers.
|
|
1058
|
+
*
|
|
1059
|
+
* @param usdcAmount - Amount of USDC to supply (e.g. '500')
|
|
1060
|
+
* @param collateralSymbol - Market collateral token to identify which market (e.g. 'WETH')
|
|
1061
|
+
* Optional — defaults to highest-APY market
|
|
1062
|
+
*/
|
|
1063
|
+
async supplyAsset(usdcAmount, collateralSymbol) {
|
|
1064
|
+
const acctAddr = await this.getAccountAddress();
|
|
1065
|
+
const amount = ethers2.parseUnits(usdcAmount, 6);
|
|
1066
|
+
const morphoAddr = this.config.contracts.morphoBlue;
|
|
1067
|
+
const usdcAddr = this.config.contracts.usdc;
|
|
1068
|
+
let params;
|
|
1069
|
+
let usedCollateral;
|
|
1070
|
+
if (collateralSymbol) {
|
|
1071
|
+
params = await this.findMarketForCollateral(collateralSymbol);
|
|
1072
|
+
usedCollateral = collateralSymbol;
|
|
1073
|
+
} else {
|
|
1074
|
+
const rates = await this.getMarketRates();
|
|
1075
|
+
if (rates.length === 0) throw new AgetherError("No markets available", "NO_MARKETS");
|
|
1076
|
+
const best = rates.reduce((a, b) => a.supplyApy > b.supplyApy ? a : b);
|
|
1077
|
+
params = await this.findMarketForCollateral(best.collateralToken);
|
|
1078
|
+
usedCollateral = best.collateralToken;
|
|
1079
|
+
}
|
|
1080
|
+
const marketId = ethers2.keccak256(
|
|
1081
|
+
ethers2.AbiCoder.defaultAbiCoder().encode(
|
|
1082
|
+
["address", "address", "address", "address", "uint256"],
|
|
1083
|
+
[params.loanToken, params.collateralToken, params.oracle, params.irm, params.lltv]
|
|
1084
|
+
)
|
|
1085
|
+
);
|
|
1086
|
+
const usdcContract = new Contract2(usdcAddr, ERC20_ABI, this._signer);
|
|
1087
|
+
const acctBalance = await usdcContract.balanceOf(acctAddr);
|
|
1088
|
+
if (acctBalance < amount) {
|
|
1089
|
+
const shortfall = amount - acctBalance;
|
|
1090
|
+
const eoaBalance = await usdcContract.balanceOf(await this.getSignerAddress());
|
|
1091
|
+
if (eoaBalance < shortfall) {
|
|
1092
|
+
throw new AgetherError(
|
|
1093
|
+
`Insufficient USDC. Need ${usdcAmount}, AgentAccount has ${ethers2.formatUnits(acctBalance, 6)}, EOA has ${ethers2.formatUnits(eoaBalance, 6)}.`,
|
|
1094
|
+
"INSUFFICIENT_BALANCE"
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
const transferTx = await usdcContract.transfer(acctAddr, shortfall);
|
|
1098
|
+
await transferTx.wait();
|
|
1099
|
+
this._refreshSigner();
|
|
1100
|
+
}
|
|
1101
|
+
const targets = [usdcAddr, morphoAddr];
|
|
1102
|
+
const values = [0n, 0n];
|
|
1103
|
+
const datas = [
|
|
1104
|
+
erc20Iface.encodeFunctionData("approve", [morphoAddr, amount]),
|
|
1105
|
+
morphoIface.encodeFunctionData("supply", [
|
|
1106
|
+
this._toTuple(params),
|
|
1107
|
+
amount,
|
|
1108
|
+
0n,
|
|
1109
|
+
acctAddr,
|
|
1110
|
+
"0x"
|
|
1111
|
+
])
|
|
1112
|
+
];
|
|
1113
|
+
const receipt = await this.batch(targets, values, datas);
|
|
1114
|
+
return {
|
|
1115
|
+
tx: receipt.hash,
|
|
1116
|
+
amount: usdcAmount,
|
|
1117
|
+
marketId,
|
|
1118
|
+
collateralToken: usedCollateral,
|
|
1119
|
+
agentAccount: acctAddr
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Withdraw supplied USDC (+ earned interest) from a Morpho Blue market.
|
|
1124
|
+
*
|
|
1125
|
+
* @param usdcAmount - Amount to withdraw (e.g. '100' or 'all' for full position)
|
|
1126
|
+
* @param collateralSymbol - Market collateral to identify which market
|
|
1127
|
+
* @param receiver - Destination address (defaults to EOA)
|
|
1128
|
+
*/
|
|
1129
|
+
async withdrawSupply(usdcAmount, collateralSymbol, receiver) {
|
|
1130
|
+
const acctAddr = await this.getAccountAddress();
|
|
1131
|
+
const morphoAddr = this.config.contracts.morphoBlue;
|
|
1132
|
+
const dest = receiver || await this.getSignerAddress();
|
|
1133
|
+
let params;
|
|
1134
|
+
if (collateralSymbol) {
|
|
1135
|
+
params = await this.findMarketForCollateral(collateralSymbol);
|
|
1136
|
+
} else {
|
|
1137
|
+
const { params: p } = await this._findActiveSupplyMarket();
|
|
1138
|
+
params = p;
|
|
1139
|
+
}
|
|
1140
|
+
const marketId = ethers2.keccak256(
|
|
1141
|
+
ethers2.AbiCoder.defaultAbiCoder().encode(
|
|
1142
|
+
["address", "address", "address", "address", "uint256"],
|
|
1143
|
+
[params.loanToken, params.collateralToken, params.oracle, params.irm, params.lltv]
|
|
1144
|
+
)
|
|
1145
|
+
);
|
|
1146
|
+
let withdrawAssets;
|
|
1147
|
+
let withdrawShares;
|
|
1148
|
+
if (usdcAmount === "all") {
|
|
1149
|
+
const pos = await this.morphoBlue.position(marketId, acctAddr);
|
|
1150
|
+
withdrawShares = BigInt(pos.supplyShares);
|
|
1151
|
+
withdrawAssets = 0n;
|
|
1152
|
+
if (withdrawShares === 0n) throw new AgetherError("No supply position to withdraw", "NO_SUPPLY");
|
|
1153
|
+
} else {
|
|
1154
|
+
withdrawAssets = ethers2.parseUnits(usdcAmount, 6);
|
|
1155
|
+
withdrawShares = 0n;
|
|
1156
|
+
}
|
|
1157
|
+
const data = morphoIface.encodeFunctionData("withdraw", [
|
|
1158
|
+
this._toTuple(params),
|
|
1159
|
+
withdrawAssets,
|
|
1160
|
+
withdrawShares,
|
|
1161
|
+
acctAddr,
|
|
1162
|
+
dest
|
|
1163
|
+
]);
|
|
1164
|
+
const receipt = await this.exec(morphoAddr, data);
|
|
1165
|
+
let remainingSupply = "0";
|
|
1166
|
+
try {
|
|
1167
|
+
const pos = await this.morphoBlue.position(marketId, acctAddr);
|
|
1168
|
+
const mkt = await this.morphoBlue.market(marketId);
|
|
1169
|
+
const totalSupplyAssets = BigInt(mkt.totalSupplyAssets);
|
|
1170
|
+
const totalSupplyShares = BigInt(mkt.totalSupplyShares);
|
|
1171
|
+
const currentAssets = totalSupplyShares > 0n ? BigInt(pos.supplyShares) * totalSupplyAssets / totalSupplyShares : 0n;
|
|
1172
|
+
remainingSupply = ethers2.formatUnits(currentAssets, 6);
|
|
1173
|
+
} catch (e) {
|
|
1174
|
+
console.warn("[agether] failed to read remaining supply:", e instanceof Error ? e.message : e);
|
|
1175
|
+
}
|
|
1176
|
+
return {
|
|
1177
|
+
tx: receipt.hash,
|
|
1178
|
+
amount: usdcAmount,
|
|
1179
|
+
remainingSupply,
|
|
1180
|
+
destination: dest
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Get supply (lending) positions with yield tracking.
|
|
1185
|
+
*
|
|
1186
|
+
* Uses Morpho GraphQL API (no eth_getLogs / no DB / no indexer):
|
|
1187
|
+
* 1. `userByAddress` → all market positions with current supplyAssets, supplyApy
|
|
1188
|
+
* 2. `transactions` → all MarketSupply/MarketWithdraw history for net deposited
|
|
1189
|
+
* 3. earnedYield = currentSupplyAssets − netDeposited
|
|
1190
|
+
*
|
|
1191
|
+
* @param collateralSymbol - Market collateral token (optional, returns all if omitted)
|
|
1192
|
+
*/
|
|
1193
|
+
async getSupplyPositions(collateralSymbol) {
|
|
1194
|
+
const acctAddr = (await this.getAccountAddress()).toLowerCase();
|
|
1195
|
+
const chainId = this.config.chainId;
|
|
1196
|
+
const positionsQuery = `{
|
|
1197
|
+
userByAddress(address: "${acctAddr}", chainId: ${chainId}) {
|
|
1198
|
+
marketPositions {
|
|
1199
|
+
market {
|
|
1200
|
+
uniqueKey
|
|
1201
|
+
loanAsset { symbol address decimals }
|
|
1202
|
+
collateralAsset { symbol address }
|
|
1203
|
+
state { supplyApy }
|
|
1204
|
+
}
|
|
1205
|
+
state {
|
|
1206
|
+
supplyShares
|
|
1207
|
+
supplyAssets
|
|
1208
|
+
supplyAssetsUsd
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}`;
|
|
1213
|
+
const posResp = await axios.post(MORPHO_API_URL, { query: positionsQuery }, { timeout: 15e3 });
|
|
1214
|
+
const user = posResp.data?.data?.userByAddress;
|
|
1215
|
+
if (!user?.marketPositions) return [];
|
|
1216
|
+
const activePositions = user.marketPositions.filter(
|
|
1217
|
+
(p) => p.state && BigInt(p.state.supplyShares ?? "0") > 0n
|
|
1218
|
+
);
|
|
1219
|
+
if (activePositions.length === 0) return [];
|
|
1220
|
+
const filtered = collateralSymbol ? activePositions.filter((p) => {
|
|
1221
|
+
const sym = p.market.collateralAsset?.symbol;
|
|
1222
|
+
return sym && sym.toUpperCase() === collateralSymbol.toUpperCase();
|
|
1223
|
+
}) : activePositions;
|
|
1224
|
+
if (filtered.length === 0) return [];
|
|
1225
|
+
const netDepositedMap = await this._computeNetDepositedAll(acctAddr, chainId);
|
|
1226
|
+
const results = [];
|
|
1227
|
+
for (const p of filtered) {
|
|
1228
|
+
const currentAssets = BigInt(p.state.supplyAssets ?? "0");
|
|
1229
|
+
const marketKey = p.market.uniqueKey.toLowerCase();
|
|
1230
|
+
const netDeposited = netDepositedMap.get(marketKey) ?? 0n;
|
|
1231
|
+
const earnedYield = currentAssets > netDeposited ? currentAssets - netDeposited : 0n;
|
|
1232
|
+
results.push({
|
|
1233
|
+
marketId: p.market.uniqueKey,
|
|
1234
|
+
loanToken: p.market.loanAsset.symbol,
|
|
1235
|
+
collateralToken: p.market.collateralAsset?.symbol ?? "none",
|
|
1236
|
+
supplyShares: p.state.supplyShares,
|
|
1237
|
+
suppliedAssets: ethers2.formatUnits(currentAssets, p.market.loanAsset.decimals),
|
|
1238
|
+
netDeposited: ethers2.formatUnits(netDeposited, p.market.loanAsset.decimals),
|
|
1239
|
+
earnedYield: ethers2.formatUnits(earnedYield, p.market.loanAsset.decimals),
|
|
1240
|
+
supplyApy: p.market.state?.supplyApy ?? 0
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
return results;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Pay a recipient using ONLY earned yield from a supply position.
|
|
1247
|
+
*
|
|
1248
|
+
* Computes available yield, verifies the requested amount doesn't exceed it,
|
|
1249
|
+
* then withdraws from the supply position and sends directly to the recipient.
|
|
1250
|
+
*
|
|
1251
|
+
* @param recipient - Address to receive the USDC
|
|
1252
|
+
* @param usdcAmount - Amount to pay from yield (e.g. '5.50')
|
|
1253
|
+
* @param collateralSymbol - Market collateral to identify which supply position
|
|
1254
|
+
*/
|
|
1255
|
+
async payFromYield(recipient, usdcAmount, collateralSymbol) {
|
|
1256
|
+
const acctAddr = await this.getAccountAddress();
|
|
1257
|
+
const morphoAddr = this.config.contracts.morphoBlue;
|
|
1258
|
+
const amount = ethers2.parseUnits(usdcAmount, 6);
|
|
1259
|
+
const positions = await this.getSupplyPositions(collateralSymbol);
|
|
1260
|
+
if (positions.length === 0) {
|
|
1261
|
+
throw new AgetherError("No supply position found", "NO_SUPPLY");
|
|
1262
|
+
}
|
|
1263
|
+
const pos = positions.reduce(
|
|
1264
|
+
(a, b) => parseFloat(a.earnedYield) > parseFloat(b.earnedYield) ? a : b
|
|
1265
|
+
);
|
|
1266
|
+
const availableYield = ethers2.parseUnits(pos.earnedYield, 6);
|
|
1267
|
+
if (amount > availableYield) {
|
|
1268
|
+
throw new AgetherError(
|
|
1269
|
+
`Requested ${usdcAmount} USDC exceeds available yield of ${pos.earnedYield} USDC. Use withdrawSupply to withdraw principal.`,
|
|
1270
|
+
"EXCEEDS_YIELD"
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
const params = await this.findMarketForCollateral(pos.collateralToken);
|
|
1274
|
+
const data = morphoIface.encodeFunctionData("withdraw", [
|
|
1275
|
+
this._toTuple(params),
|
|
1276
|
+
amount,
|
|
1277
|
+
0n,
|
|
1278
|
+
acctAddr,
|
|
1279
|
+
recipient
|
|
1280
|
+
]);
|
|
1281
|
+
const receipt = await this.exec(morphoAddr, data);
|
|
1282
|
+
let remainingYield = "0";
|
|
1283
|
+
let remainingSupply = "0";
|
|
1284
|
+
try {
|
|
1285
|
+
const updatedPositions = await this.getSupplyPositions(pos.collateralToken);
|
|
1286
|
+
if (updatedPositions.length > 0) {
|
|
1287
|
+
remainingYield = updatedPositions[0].earnedYield;
|
|
1288
|
+
remainingSupply = updatedPositions[0].suppliedAssets;
|
|
1289
|
+
}
|
|
1290
|
+
} catch (e) {
|
|
1291
|
+
console.warn("[agether] failed to read remaining yield:", e instanceof Error ? e.message : e);
|
|
1292
|
+
}
|
|
1293
|
+
return {
|
|
1294
|
+
tx: receipt.hash,
|
|
1295
|
+
yieldWithdrawn: usdcAmount,
|
|
1296
|
+
recipient,
|
|
1297
|
+
remainingYield,
|
|
1298
|
+
remainingSupply
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
// ════════════════════════════════════════════════════════
|
|
1302
|
+
// Collateral & Borrowing Operations (all via AgentAccount)
|
|
1051
1303
|
// ════════════════════════════════════════════════════════
|
|
1052
1304
|
/**
|
|
1053
1305
|
* Deposit collateral into Morpho Blue.
|
|
@@ -1678,6 +1930,94 @@ var MorphoClient = class {
|
|
|
1678
1930
|
const params = await this.findMarketForCollateral("WETH");
|
|
1679
1931
|
return { params, symbol: "WETH" };
|
|
1680
1932
|
}
|
|
1933
|
+
/** Find the first market where the agent has a supply (lending) position. */
|
|
1934
|
+
async _findActiveSupplyMarket() {
|
|
1935
|
+
const acctAddr = await this.getAccountAddress();
|
|
1936
|
+
const markets = await this.getMarkets();
|
|
1937
|
+
for (const m of markets) {
|
|
1938
|
+
if (!m.collateralAsset || m.collateralAsset.address === ethers2.ZeroAddress) continue;
|
|
1939
|
+
try {
|
|
1940
|
+
const pos = await this.morphoBlue.position(m.uniqueKey, acctAddr);
|
|
1941
|
+
if (BigInt(pos.supplyShares) > 0n) {
|
|
1942
|
+
return {
|
|
1943
|
+
params: {
|
|
1944
|
+
loanToken: m.loanAsset.address,
|
|
1945
|
+
collateralToken: m.collateralAsset.address,
|
|
1946
|
+
oracle: m.oracle,
|
|
1947
|
+
irm: m.irm,
|
|
1948
|
+
lltv: m.lltv
|
|
1949
|
+
},
|
|
1950
|
+
symbol: m.collateralAsset.symbol
|
|
1951
|
+
};
|
|
1952
|
+
}
|
|
1953
|
+
} catch (e) {
|
|
1954
|
+
console.warn("[agether] _findActiveSupplyMarket position check failed:", e instanceof Error ? e.message : e);
|
|
1955
|
+
continue;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
throw new AgetherError("No active supply position found", "NO_SUPPLY");
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1961
|
+
* Compute net deposited amounts per market using Morpho GraphQL API.
|
|
1962
|
+
*
|
|
1963
|
+
* Fetches all MarketSupply and MarketWithdraw transactions for the account,
|
|
1964
|
+
* then computes: netDeposited[marketId] = Σ Supply.assets − Σ Withdraw.assets
|
|
1965
|
+
*
|
|
1966
|
+
* Returns a Map<marketId (lowercase), bigint>.
|
|
1967
|
+
*
|
|
1968
|
+
* Uses pagination (100 per page) for completeness, though agent accounts
|
|
1969
|
+
* typically have single-digit transaction counts.
|
|
1970
|
+
*/
|
|
1971
|
+
async _computeNetDepositedAll(accountAddr, chainId) {
|
|
1972
|
+
const result = /* @__PURE__ */ new Map();
|
|
1973
|
+
let skip = 0;
|
|
1974
|
+
const pageSize = 100;
|
|
1975
|
+
let hasMore = true;
|
|
1976
|
+
while (hasMore) {
|
|
1977
|
+
const txQuery = `{
|
|
1978
|
+
transactions(
|
|
1979
|
+
first: ${pageSize}
|
|
1980
|
+
skip: ${skip}
|
|
1981
|
+
where: {
|
|
1982
|
+
userAddress_in: ["${accountAddr}"]
|
|
1983
|
+
type_in: [MarketSupply, MarketWithdraw]
|
|
1984
|
+
chainId_in: [${chainId}]
|
|
1985
|
+
}
|
|
1986
|
+
) {
|
|
1987
|
+
pageInfo { count countTotal }
|
|
1988
|
+
items {
|
|
1989
|
+
type
|
|
1990
|
+
data {
|
|
1991
|
+
... on MarketTransferTransactionData {
|
|
1992
|
+
assets
|
|
1993
|
+
market { uniqueKey }
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}`;
|
|
1999
|
+
const resp = await axios.post(MORPHO_API_URL, { query: txQuery }, { timeout: 15e3 });
|
|
2000
|
+
const txData = resp.data?.data?.transactions;
|
|
2001
|
+
if (!txData?.items) break;
|
|
2002
|
+
for (const tx of txData.items) {
|
|
2003
|
+
const marketKey = tx.data?.market?.uniqueKey?.toLowerCase();
|
|
2004
|
+
if (!marketKey || !tx.data?.assets) continue;
|
|
2005
|
+
const assets = BigInt(tx.data.assets);
|
|
2006
|
+
const current = result.get(marketKey) ?? 0n;
|
|
2007
|
+
if (tx.type === "MarketSupply") {
|
|
2008
|
+
result.set(marketKey, current + assets);
|
|
2009
|
+
} else if (tx.type === "MarketWithdraw") {
|
|
2010
|
+
const newVal = current - assets;
|
|
2011
|
+
result.set(marketKey, newVal > 0n ? newVal : 0n);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
const fetched = skip + txData.items.length;
|
|
2015
|
+
const total = txData.pageInfo?.countTotal ?? 0;
|
|
2016
|
+
hasMore = fetched < total;
|
|
2017
|
+
skip += pageSize;
|
|
2018
|
+
}
|
|
2019
|
+
return result;
|
|
2020
|
+
}
|
|
1681
2021
|
};
|
|
1682
2022
|
|
|
1683
2023
|
// src/clients/ScoringClient.ts
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agether SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Architecture (v2 — Safe + Safe7579):
|
|
5
|
+
* - Agent registers via ERC-8004 → gets agentId
|
|
6
|
+
* - Agether4337Factory creates Safe proxy with Safe7579 adapter per agent
|
|
7
|
+
* - Agether8004ValidationModule: ownership + KYA gate + module lock (single 7579 validator)
|
|
8
|
+
* - AgetherHookMultiplexer: admin-managed hook chain
|
|
9
|
+
* - All execution via ERC-4337 UserOps through EntryPoint v0.7
|
|
10
|
+
* - Agether8004Scorer: oracle-based credit scoring
|
|
11
|
+
* - Morpho Blue: direct overcollateralized lending (agents interact via UserOps)
|
|
12
|
+
* - x402: HTTP payment protocol for scoring API
|
|
13
|
+
*/
|
|
14
|
+
export declare enum ChainId {
|
|
15
|
+
Ethereum = 1,
|
|
16
|
+
Base = 8453,
|
|
17
|
+
BaseSepolia = 84532,
|
|
18
|
+
Sepolia = 11155111,
|
|
19
|
+
Hardhat = 31337
|
|
20
|
+
}
|
|
21
|
+
/** Morpho Blue MarketParams struct */
|
|
22
|
+
export interface MorphoMarketParams {
|
|
23
|
+
loanToken: string;
|
|
24
|
+
collateralToken: string;
|
|
25
|
+
oracle: string;
|
|
26
|
+
irm: string;
|
|
27
|
+
lltv: bigint;
|
|
28
|
+
}
|
|
29
|
+
/** Morpho Blue onchain position for an account */
|
|
30
|
+
export interface MorphoPosition {
|
|
31
|
+
supplyShares: bigint;
|
|
32
|
+
borrowShares: bigint;
|
|
33
|
+
collateral: bigint;
|
|
34
|
+
}
|
|
35
|
+
/** Morpho market info (from GraphQL API or onchain) */
|
|
36
|
+
export interface MorphoMarketInfo {
|
|
37
|
+
uniqueKey: string;
|
|
38
|
+
loanAsset: {
|
|
39
|
+
address: string;
|
|
40
|
+
symbol: string;
|
|
41
|
+
decimals: number;
|
|
42
|
+
};
|
|
43
|
+
collateralAsset: {
|
|
44
|
+
address: string;
|
|
45
|
+
symbol: string;
|
|
46
|
+
decimals: number;
|
|
47
|
+
};
|
|
48
|
+
oracle: string;
|
|
49
|
+
irm: string;
|
|
50
|
+
lltv: bigint;
|
|
51
|
+
totalSupplyAssets: bigint;
|
|
52
|
+
totalBorrowAssets: bigint;
|
|
53
|
+
utilization: number;
|
|
54
|
+
}
|
|
55
|
+
/** Onchain score attestation from Agether8004Scorer contract */
|
|
56
|
+
export interface ScoreAttestation {
|
|
57
|
+
score: bigint;
|
|
58
|
+
timestamp: bigint;
|
|
59
|
+
signer: string;
|
|
60
|
+
}
|
|
61
|
+
/** Score result from backend scoring API */
|
|
62
|
+
export interface ScoreResult {
|
|
63
|
+
agentId: string;
|
|
64
|
+
score: number;
|
|
65
|
+
timestamp: number;
|
|
66
|
+
breakdown: {
|
|
67
|
+
kyaBonus: number;
|
|
68
|
+
accountBonus: number;
|
|
69
|
+
balanceBonus: number;
|
|
70
|
+
historyBonus: number;
|
|
71
|
+
baseScore: number;
|
|
72
|
+
};
|
|
73
|
+
txHash?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface TransactionResult {
|
|
76
|
+
txHash: string;
|
|
77
|
+
blockNumber: number;
|
|
78
|
+
status: 'success' | 'failed';
|
|
79
|
+
gasUsed: bigint;
|
|
80
|
+
}
|
|
81
|
+
export interface X402PaymentRequest {
|
|
82
|
+
service: string;
|
|
83
|
+
amount: bigint;
|
|
84
|
+
asset: string;
|
|
85
|
+
chain: ChainId;
|
|
86
|
+
recipient: string;
|
|
87
|
+
}
|
|
88
|
+
export interface X402PaymentResult {
|
|
89
|
+
paymentId: string;
|
|
90
|
+
txHash: string;
|
|
91
|
+
amount: bigint;
|
|
92
|
+
chain: ChainId;
|
|
93
|
+
status: 'pending' | 'confirmed' | 'failed';
|
|
94
|
+
}
|
|
95
|
+
export interface AgetherConfig {
|
|
96
|
+
chainId: ChainId;
|
|
97
|
+
rpcUrl: string;
|
|
98
|
+
contracts: ContractAddresses;
|
|
99
|
+
scoringEndpoint?: string;
|
|
100
|
+
kyaEndpoint?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface ContractAddresses {
|
|
103
|
+
safeSingleton: string;
|
|
104
|
+
safeProxyFactory: string;
|
|
105
|
+
safe7579: string;
|
|
106
|
+
entryPoint: string;
|
|
107
|
+
agether4337Factory: string;
|
|
108
|
+
agether7579Bootstrap: string;
|
|
109
|
+
erc8004ValidationModule: string;
|
|
110
|
+
agetherHookMultiplexer: string;
|
|
111
|
+
validationRegistry: string;
|
|
112
|
+
agether8004Scorer: string;
|
|
113
|
+
timelockController: string;
|
|
114
|
+
identityRegistry: string;
|
|
115
|
+
usdc: string;
|
|
116
|
+
morphoBlue: string;
|
|
117
|
+
}
|
|
118
|
+
export declare class AgetherError extends Error {
|
|
119
|
+
code: string;
|
|
120
|
+
details?: Record<string, unknown> | undefined;
|
|
121
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
|
|
122
|
+
}
|
|
123
|
+
export declare class InsufficientBalanceError extends AgetherError {
|
|
124
|
+
constructor(available: bigint, required: bigint);
|
|
125
|
+
}
|
|
126
|
+
export declare class ScoringRejectedError extends AgetherError {
|
|
127
|
+
constructor(riskScore: number, reason?: string);
|
|
128
|
+
}
|
|
129
|
+
export declare class AgentNotApprovedError extends AgetherError {
|
|
130
|
+
constructor(agentId: bigint);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,oBAAY,OAAO;IACjB,QAAQ,IAAI;IACZ,IAAI,OAAO;IACX,WAAW,QAAQ;IACnB,OAAO,WAAW;IAClB,OAAO,QAAQ;CAChB;AAID,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;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AAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAK3C;AAED,qBAAa,wBAAyB,SAAQ,YAAY;gBAC5C,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAOhD;AAED,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAO/C;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,EAAE,MAAM;CAO5B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agether SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Architecture (v2 — Safe + Safe7579):
|
|
5
|
+
* - Agent registers via ERC-8004 → gets agentId
|
|
6
|
+
* - Agether4337Factory creates Safe proxy with Safe7579 adapter per agent
|
|
7
|
+
* - Agether8004ValidationModule: ownership + KYA gate + module lock (single 7579 validator)
|
|
8
|
+
* - AgetherHookMultiplexer: admin-managed hook chain
|
|
9
|
+
* - All execution via ERC-4337 UserOps through EntryPoint v0.7
|
|
10
|
+
* - Agether8004Scorer: oracle-based credit scoring
|
|
11
|
+
* - Morpho Blue: direct overcollateralized lending (agents interact via UserOps)
|
|
12
|
+
* - x402: HTTP payment protocol for scoring API
|
|
13
|
+
*/
|
|
14
|
+
// ============ Enums ============
|
|
15
|
+
export var ChainId;
|
|
16
|
+
(function (ChainId) {
|
|
17
|
+
ChainId[ChainId["Ethereum"] = 1] = "Ethereum";
|
|
18
|
+
ChainId[ChainId["Base"] = 8453] = "Base";
|
|
19
|
+
ChainId[ChainId["BaseSepolia"] = 84532] = "BaseSepolia";
|
|
20
|
+
ChainId[ChainId["Sepolia"] = 11155111] = "Sepolia";
|
|
21
|
+
ChainId[ChainId["Hardhat"] = 31337] = "Hardhat";
|
|
22
|
+
})(ChainId || (ChainId = {}));
|
|
23
|
+
// ============ Error Types ============
|
|
24
|
+
export class AgetherError extends Error {
|
|
25
|
+
constructor(message, code, details) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.details = details;
|
|
29
|
+
this.name = 'AgetherError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class InsufficientBalanceError extends AgetherError {
|
|
33
|
+
constructor(available, required) {
|
|
34
|
+
super(`Insufficient balance: available ${available}, required ${required}`, 'INSUFFICIENT_BALANCE', { available: available.toString(), required: required.toString() });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class ScoringRejectedError extends AgetherError {
|
|
38
|
+
constructor(riskScore, reason) {
|
|
39
|
+
super(`Scoring rejected: risk score ${riskScore}${reason ? `, ${reason}` : ''}`, 'SCORING_REJECTED', { riskScore, reason });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class AgentNotApprovedError extends AgetherError {
|
|
43
|
+
constructor(agentId) {
|
|
44
|
+
super(`Agent ${agentId} is not KYA-approved. Submit code for validation first.`, 'AGENT_NOT_APPROVED', { agentId: agentId.toString() });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract ABIs (minimal for SDK)
|
|
3
|
+
*
|
|
4
|
+
* Architecture (v2 — Safe + Safe7579):
|
|
5
|
+
* - Agether4337Factory (deploys Safe proxies with modules)
|
|
6
|
+
* - Agether8004ValidationModule (ownership + KYA + module lock)
|
|
7
|
+
* - AgetherHookMultiplexer (admin-managed hooks)
|
|
8
|
+
* - Agether8004Scorer (oracle-based credit scores)
|
|
9
|
+
* - ValidationRegistry (KYA code validation)
|
|
10
|
+
* - ERC-8004 IdentityRegistry
|
|
11
|
+
* - Morpho Blue (direct overcollateralized lending)
|
|
12
|
+
* - EntryPoint v0.7 (ERC-4337 UserOp submission)
|
|
13
|
+
*/
|
|
14
|
+
export declare const IDENTITY_REGISTRY_ABI: string[];
|
|
15
|
+
export declare const AGETHER_4337_FACTORY_ABI: string[];
|
|
16
|
+
export declare const SAFE_AGENT_FACTORY_ABI: string[];
|
|
17
|
+
export declare const ACCOUNT_FACTORY_ABI: string[];
|
|
18
|
+
export declare const AGETHER_8004_VALIDATION_MODULE_ABI: string[];
|
|
19
|
+
export declare const ERC8004_VALIDATION_MODULE_ABI: string[];
|
|
20
|
+
export declare const AGETHER_HOOK_MULTIPLEXER_ABI: string[];
|
|
21
|
+
export declare const HOOK_MULTIPLEXER_ABI: string[];
|
|
22
|
+
export declare const AGETHER_8004_SCORER_ABI: string[];
|
|
23
|
+
export declare const AGENT_REPUTATION_ABI: string[];
|
|
24
|
+
export declare const VALIDATION_REGISTRY_ABI: string[];
|
|
25
|
+
export declare const MORPHO_BLUE_ABI: string[];
|
|
26
|
+
export declare const ERC20_ABI: string[];
|
|
27
|
+
export declare const ENTRYPOINT_V07_ABI: string[];
|
|
28
|
+
export declare const SAFE7579_ACCOUNT_ABI: string[];
|
|
29
|
+
//# sourceMappingURL=abis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abis.d.ts","sourceRoot":"","sources":["../../src/utils/abis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,eAAO,MAAM,qBAAqB,UAOjC,CAAC;AAIF,eAAO,MAAM,wBAAwB,UAepC,CAAC;AAGF,eAAO,MAAM,sBAAsB,UAA2B,CAAC;AAC/D,eAAO,MAAM,mBAAmB,UAA2B,CAAC;AAI5D,eAAO,MAAM,kCAAkC,UAU9C,CAAC;AAGF,eAAO,MAAM,6BAA6B,UAAqC,CAAC;AAIhF,eAAO,MAAM,4BAA4B,UAMxC,CAAC;AAGF,eAAO,MAAM,oBAAoB,UAA+B,CAAC;AAIjE,eAAO,MAAM,uBAAuB,UASnC,CAAC;AAGF,eAAO,MAAM,oBAAoB,UAA0B,CAAC;AAI5D,eAAO,MAAM,uBAAuB,UAKnC,CAAC;AAIF,eAAO,MAAM,eAAe,UAoB3B,CAAC;AAIF,eAAO,MAAM,SAAS,UASrB,CAAC;AAIF,eAAO,MAAM,kBAAkB,UAQ9B,CAAC;AAIF,eAAO,MAAM,oBAAoB,UAQhC,CAAC"}
|