@morpho-dev/router 0.7.0 → 0.7.2
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.js +1999 -2137
- package/dist/evm/bytecode/erc20.txt +1 -1
- package/dist/evm/bytecode/morpho.txt +1 -1
- package/dist/evm/bytecode/multicall3.txt +1 -1
- package/dist/evm/bytecode/oracle.txt +1 -1
- package/dist/evm/bytecode/vault.txt +1 -1
- package/dist/index.browser.d.mts +1116 -282
- package/dist/index.browser.d.mts.map +1 -1
- package/dist/index.browser.d.ts +1116 -282
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +193 -456
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +193 -456
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.mts +1154 -329
- package/dist/index.node.d.mts.map +1 -1
- package/dist/index.node.d.ts +1130 -305
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +4342 -4540
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +4345 -4537
- package/dist/index.node.mjs.map +1 -1
- package/docs/integrator.md +5 -6
- package/package.json +1 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -98,6 +98,61 @@ const MetaMorpho = parseAbi([
|
|
|
98
98
|
//#region src/core/Abi/MetaMorphoFactory.ts
|
|
99
99
|
const MetaMorphoFactory = parseAbi(["event CreateMetaMorpho(address indexed metaMorpho,address indexed caller,address initialOwner,uint256 initialTimelock,address indexed asset,string name,string symbol,bytes32 salt)", "function isMetaMorpho(address) view returns (bool)"]);
|
|
100
100
|
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/core/Abi/MorphoV2.ts
|
|
103
|
+
const MorphoV2 = parseAbi([
|
|
104
|
+
"constructor()",
|
|
105
|
+
"function collateralOf(bytes32 id, address user, address collateralToken) view returns (uint256)",
|
|
106
|
+
"function consume(bytes32 group, uint256 amount)",
|
|
107
|
+
"function consumed(address user, bytes32 group) view returns (uint256)",
|
|
108
|
+
"function debtOf(bytes32 id, address user) view returns (uint256)",
|
|
109
|
+
"function defaultFees(address loanToken, uint256 index) view returns (uint16)",
|
|
110
|
+
"function feeSetter() view returns (address)",
|
|
111
|
+
"function fees(bytes32 id) view returns (uint16[6])",
|
|
112
|
+
"function flashLoan(address token, uint256 assets, address callback, bytes data)",
|
|
113
|
+
"function isHealthy((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, bytes32 id, address borrower) view returns (bool)",
|
|
114
|
+
"function liquidate((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, (uint256 collateralIndex, uint256 repaid, uint256 seized)[] seizures, address borrower, bytes data) returns ((uint256 collateralIndex, uint256 repaid, uint256 seized)[])",
|
|
115
|
+
"function multicall(bytes[] calls)",
|
|
116
|
+
"function obligationCreated(bytes32 id) view returns (bool)",
|
|
117
|
+
"function obligationState(bytes32 id) view returns (uint128 totalUnits, uint128 totalShares, uint256 withdrawable, bool created)",
|
|
118
|
+
"function owner() view returns (address)",
|
|
119
|
+
"function repay((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, address onBehalf)",
|
|
120
|
+
"function session(address user) view returns (bytes32)",
|
|
121
|
+
"function setDefaultTradingFee(address loanToken, uint256 index, uint256 newTradingFee)",
|
|
122
|
+
"function setFeeSetter(address newFeeSetter)",
|
|
123
|
+
"function setObligationTradingFee(bytes32 id, uint256 index, uint256 newTradingFee)",
|
|
124
|
+
"function setOwner(address newOwner)",
|
|
125
|
+
"function setTradingFeeRecipient(address recipient)",
|
|
126
|
+
"function sharesOf(bytes32 id, address user) view returns (uint256)",
|
|
127
|
+
"function shuffleSession()",
|
|
128
|
+
"function supplyCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
|
|
129
|
+
"function take(uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, address taker, ((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, bool buy, address maker, uint256 assets, uint256 obligationUnits, uint256 obligationShares, uint256 start, uint256 expiry, uint256 tick, bytes32 group, bytes32 session, address callback, bytes callbackData) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof, address takerCallback, bytes takerCallbackData) returns (uint256, uint256, uint256, uint256)",
|
|
130
|
+
"function totalShares(bytes32 id) view returns (uint256)",
|
|
131
|
+
"function totalUnits(bytes32 id) view returns (uint256)",
|
|
132
|
+
"function touchObligation((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation) returns (bytes32)",
|
|
133
|
+
"function tradingFee(bytes32 id, uint256 timeToMaturity) view returns (uint256)",
|
|
134
|
+
"function tradingFeeRecipient() view returns (address)",
|
|
135
|
+
"function withdraw((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, uint256 shares, address onBehalf) returns (uint256, uint256)",
|
|
136
|
+
"function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
|
|
137
|
+
"function withdrawable(bytes32 id) view returns (uint256)",
|
|
138
|
+
"event Constructor(address indexed owner)",
|
|
139
|
+
"event Consume(address indexed user, bytes32 indexed group, uint256 amount)",
|
|
140
|
+
"event FlashLoan(address indexed caller, address indexed token, uint256 assets)",
|
|
141
|
+
"event Liquidate(address indexed caller, bytes32 indexed id, (uint256 collateralIndex, uint256 repaid, uint256 seized)[] seizures, address indexed borrower, uint256 totalRepaid, uint256 badDebt)",
|
|
142
|
+
"event ObligationCreated(bytes32 indexed id, (address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation)",
|
|
143
|
+
"event Repay(address indexed caller, bytes32 indexed id, uint256 obligationUnits, address indexed onBehalf)",
|
|
144
|
+
"event SetDefaultTradingFee(address indexed loanToken, uint256 indexed index, uint256 newTradingFee)",
|
|
145
|
+
"event SetFeeSetter(address indexed feeSetter)",
|
|
146
|
+
"event SetObligationTradingFee(bytes32 indexed id, uint256 indexed index, uint256 newTradingFee)",
|
|
147
|
+
"event SetOwner(address indexed owner)",
|
|
148
|
+
"event SetTradingFeeRecipient(address indexed recipient)",
|
|
149
|
+
"event ShuffleSession(address indexed user, bytes32 session)",
|
|
150
|
+
"event SupplyCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)",
|
|
151
|
+
"event Take(address caller, bytes32 indexed id, address indexed maker, address indexed taker, bool offerIsBuy, uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, bool buyerIsLender, bool sellerIsBorrower, bytes32 group, uint256 consumed)",
|
|
152
|
+
"event Withdraw(address indexed caller, bytes32 indexed id, uint256 obligationUnits, uint256 shares, address indexed onBehalf)",
|
|
153
|
+
"event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)"
|
|
154
|
+
]);
|
|
155
|
+
|
|
101
156
|
//#endregion
|
|
102
157
|
//#region src/core/Abi/index.ts
|
|
103
158
|
var Abi_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -105,6 +160,7 @@ var Abi_exports = /* @__PURE__ */ __exportAll({
|
|
|
105
160
|
MetaMorpho: () => MetaMorpho,
|
|
106
161
|
MetaMorphoFactory: () => MetaMorphoFactory,
|
|
107
162
|
Morpho: () => Morpho,
|
|
163
|
+
MorphoV2: () => MorphoV2,
|
|
108
164
|
Oracle: () => Oracle
|
|
109
165
|
});
|
|
110
166
|
const Oracle = [{
|
|
@@ -253,107 +309,14 @@ const Morpho = [
|
|
|
253
309
|
//#region src/core/Callback.ts
|
|
254
310
|
var Callback_exports = /* @__PURE__ */ __exportAll({
|
|
255
311
|
Type: () => Type$1,
|
|
256
|
-
decode: () => decode$2,
|
|
257
|
-
decodeBuyERC20: () => decodeBuyERC20,
|
|
258
|
-
decodeBuyVaultV1Callback: () => decodeBuyVaultV1Callback,
|
|
259
|
-
decodeSellERC20Callback: () => decodeSellERC20Callback,
|
|
260
|
-
encode: () => encode$2,
|
|
261
|
-
encodeBuyERC20: () => encodeBuyERC20,
|
|
262
|
-
encodeBuyVaultV1Callback: () => encodeBuyVaultV1Callback,
|
|
263
|
-
encodeSellERC20Callback: () => encodeSellERC20Callback,
|
|
264
312
|
isEmptyCallback: () => isEmptyCallback
|
|
265
313
|
});
|
|
266
314
|
let Type$1 = /* @__PURE__ */ function(Type) {
|
|
267
315
|
Type["BuyWithEmptyCallback"] = "buy_with_empty_callback";
|
|
268
|
-
Type["
|
|
269
|
-
Type["BuyVaultV1Callback"] = "buy_vault_v1_callback";
|
|
270
|
-
Type["SellERC20Callback"] = "sell_erc20_callback";
|
|
316
|
+
Type["SellWithEmptyCallback"] = "sell_with_empty_callback";
|
|
271
317
|
return Type;
|
|
272
318
|
}({});
|
|
273
319
|
const isEmptyCallback = (offer) => offer.callback.data === "0x";
|
|
274
|
-
function decode$2(type, data) {
|
|
275
|
-
switch (type) {
|
|
276
|
-
case Type$1.BuyERC20: return decodeBuyERC20(data);
|
|
277
|
-
case Type$1.BuyVaultV1Callback: return decodeBuyVaultV1Callback(data);
|
|
278
|
-
case Type$1.SellERC20Callback: return decodeSellERC20Callback(data);
|
|
279
|
-
default: throw new Error("Invalid callback type");
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
function encode$2(type, data) {
|
|
283
|
-
switch (type) {
|
|
284
|
-
case Type$1.BuyERC20:
|
|
285
|
-
if (!("tokens" in data)) throw new Error("Invalid callback data");
|
|
286
|
-
return encodeBuyERC20(data);
|
|
287
|
-
case Type$1.BuyVaultV1Callback:
|
|
288
|
-
if (!("vaults" in data)) throw new Error("Invalid callback data");
|
|
289
|
-
return encodeBuyVaultV1Callback(data);
|
|
290
|
-
case Type$1.SellERC20Callback:
|
|
291
|
-
if (!("collaterals" in data)) throw new Error("Invalid callback data");
|
|
292
|
-
return encodeSellERC20Callback(data);
|
|
293
|
-
default: throw new Error("Invalid callback type");
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Decodes BuyERC20 callback data into positions.
|
|
298
|
-
* @param data - The ABI-encoded callback data containing token addresses and amounts.
|
|
299
|
-
* @returns Array of positions with contract address and amount.
|
|
300
|
-
* @throws If data is empty, malformed, or arrays have mismatched lengths.
|
|
301
|
-
*/
|
|
302
|
-
function decodeBuyERC20(data) {
|
|
303
|
-
if (!data || data === "0x") throw new Error("Empty callback data");
|
|
304
|
-
let tokens;
|
|
305
|
-
let amounts;
|
|
306
|
-
try {
|
|
307
|
-
[tokens, amounts] = decodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], data);
|
|
308
|
-
} catch (_) {
|
|
309
|
-
throw new Error("Invalid BuyERC20 callback data");
|
|
310
|
-
}
|
|
311
|
-
if (tokens.length !== amounts.length) throw new Error("Mismatched array lengths");
|
|
312
|
-
return tokens.map((token, index) => ({
|
|
313
|
-
contract: token,
|
|
314
|
-
amount: amounts[index]
|
|
315
|
-
}));
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Encodes BuyERC20 callback parameters into ABI-encoded data.
|
|
319
|
-
* @param parameters - The tokens and amounts to encode.
|
|
320
|
-
* @returns ABI-encoded hex string.
|
|
321
|
-
*/
|
|
322
|
-
function encodeBuyERC20(parameters) {
|
|
323
|
-
return encodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], [parameters.tokens, parameters.amounts]);
|
|
324
|
-
}
|
|
325
|
-
function decodeBuyVaultV1Callback(data) {
|
|
326
|
-
if (!data || data === "0x") throw new Error("Empty callback data");
|
|
327
|
-
try {
|
|
328
|
-
const [vaults, amounts] = decodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], data);
|
|
329
|
-
if (vaults.length !== amounts.length) throw new Error("Mismatched array lengths");
|
|
330
|
-
return vaults.map((v, i) => ({
|
|
331
|
-
contract: v,
|
|
332
|
-
amount: amounts[i]
|
|
333
|
-
}));
|
|
334
|
-
} catch (_) {
|
|
335
|
-
throw new Error("Invalid BuyVaultV1Callback callback data");
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
function decodeSellERC20Callback(data) {
|
|
339
|
-
if (!data || data === "0x") throw new Error("Empty callback data");
|
|
340
|
-
try {
|
|
341
|
-
const [collaterals, amounts] = decodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], data);
|
|
342
|
-
if (collaterals.length !== amounts.length) throw new Error("Mismatched array lengths");
|
|
343
|
-
return collaterals.map((c, i) => ({
|
|
344
|
-
contract: c,
|
|
345
|
-
amount: amounts[i]
|
|
346
|
-
}));
|
|
347
|
-
} catch (_) {
|
|
348
|
-
throw new Error("Invalid SellERC20Callback callback data");
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
function encodeBuyVaultV1Callback(parameters) {
|
|
352
|
-
return encodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], [parameters.vaults, parameters.amounts]);
|
|
353
|
-
}
|
|
354
|
-
function encodeSellERC20Callback(parameters) {
|
|
355
|
-
return encodeAbiParameters([{ type: "address[]" }, { type: "uint256[]" }], [parameters.collaterals, parameters.amounts]);
|
|
356
|
-
}
|
|
357
320
|
|
|
358
321
|
//#endregion
|
|
359
322
|
//#region src/utils/BigMath.ts
|
|
@@ -603,8 +566,8 @@ const chains$1 = {
|
|
|
603
566
|
name: "ethereum-virtual-testnet",
|
|
604
567
|
custom: {
|
|
605
568
|
morpho: {
|
|
606
|
-
address: "
|
|
607
|
-
blockCreated:
|
|
569
|
+
address: "0x634b095371e4e45feed94c1a45c37798e173ea50",
|
|
570
|
+
blockCreated: 23226700
|
|
608
571
|
},
|
|
609
572
|
morphoBlue: {
|
|
610
573
|
address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
@@ -1109,11 +1072,9 @@ var Liquidity_exports = /* @__PURE__ */ __exportAll({
|
|
|
1109
1072
|
calculateMaxDebt: () => calculateMaxDebt,
|
|
1110
1073
|
generateAllowancePoolId: () => generateAllowancePoolId,
|
|
1111
1074
|
generateBalancePoolId: () => generateBalancePoolId,
|
|
1112
|
-
generateBuyVaultCallbackPoolId: () => generateBuyVaultCallbackPoolId,
|
|
1113
1075
|
generateDebtPoolId: () => generateDebtPoolId,
|
|
1114
1076
|
generateMarketLiquidityPoolId: () => generateMarketLiquidityPoolId,
|
|
1115
1077
|
generateObligationCollateralPoolId: () => generateObligationCollateralPoolId,
|
|
1116
|
-
generateSellERC20CallbackPoolId: () => generateSellERC20CallbackPoolId,
|
|
1117
1078
|
generateUserVaultPositionPoolId: () => generateUserVaultPositionPoolId,
|
|
1118
1079
|
generateVaultPositionPoolId: () => generateVaultPositionPoolId
|
|
1119
1080
|
});
|
|
@@ -1142,14 +1103,6 @@ function generateAllowancePoolId(parameters) {
|
|
|
1142
1103
|
return `${user}-${chainId.toString()}-${token}-allowance`.toLowerCase();
|
|
1143
1104
|
}
|
|
1144
1105
|
/**
|
|
1145
|
-
* Generate pool ID for sell ERC20 callback pools.
|
|
1146
|
-
* Each offer has its own callback pool to prevent liquidity conflicts.
|
|
1147
|
-
*/
|
|
1148
|
-
function generateSellERC20CallbackPoolId(parameters) {
|
|
1149
|
-
const { user, chainId, obligationId, token, offerHash } = parameters;
|
|
1150
|
-
return `${user}-${chainId.toString()}-${obligationId}-${token}-${offerHash}-sell_erc20_callback`.toLowerCase();
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
1106
|
* Generate pool ID for obligation collateral pools.
|
|
1154
1107
|
* Obligation collateral pools represent collateral already deposited in the obligation.
|
|
1155
1108
|
* These pools are shared across all offers with the same obligation.
|
|
@@ -1159,13 +1112,6 @@ function generateObligationCollateralPoolId(parameters) {
|
|
|
1159
1112
|
return `${user}-${chainId.toString()}-${obligationId}-${token}-obligation-collateral`.toLowerCase();
|
|
1160
1113
|
}
|
|
1161
1114
|
/**
|
|
1162
|
-
* Generate pool ID for buy vault callback pools.
|
|
1163
|
-
*/
|
|
1164
|
-
function generateBuyVaultCallbackPoolId(parameters) {
|
|
1165
|
-
const { user, chainId, vault, offerHash } = parameters;
|
|
1166
|
-
return `${user}-${chainId.toString()}-${vault}-${offerHash}-${Type$1.BuyVaultV1Callback}`.toLowerCase();
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
1115
|
* Generate pool ID for debt pools.
|
|
1170
1116
|
*/
|
|
1171
1117
|
function generateDebtPoolId(parameters) {
|
|
@@ -1545,6 +1491,7 @@ var Offer_exports = /* @__PURE__ */ __exportAll({
|
|
|
1545
1491
|
obligationId: () => obligationId,
|
|
1546
1492
|
random: () => random$1,
|
|
1547
1493
|
serialize: () => serialize,
|
|
1494
|
+
takeEvent: () => takeEvent,
|
|
1548
1495
|
toSnakeCase: () => toSnakeCase,
|
|
1549
1496
|
types: () => types
|
|
1550
1497
|
});
|
|
@@ -1663,7 +1610,7 @@ function random$1(config) {
|
|
|
1663
1610
|
const chain = config?.chains ? config.chains[int(config.chains.length)] : chains$1.ethereum;
|
|
1664
1611
|
const loanToken = config?.loanTokens ? config.loanTokens[int(config.loanTokens.length)] : address();
|
|
1665
1612
|
const collateralCandidates = config?.collateralTokens ? config.collateralTokens.filter((a) => a !== loanToken) : [address()];
|
|
1666
|
-
|
|
1613
|
+
collateralCandidates[int(collateralCandidates.length)];
|
|
1667
1614
|
const maturityOption = weightedChoice([["end_of_month", 1], ["end_of_next_month", 1]]);
|
|
1668
1615
|
const maturity = config?.maturity ?? from$11(maturityOption);
|
|
1669
1616
|
const lltv = from$13(weightedChoice([
|
|
@@ -1690,21 +1637,10 @@ function random$1(config) {
|
|
|
1690
1637
|
const unit = BigInt(10) ** BigInt(loanTokenDecimals);
|
|
1691
1638
|
const amountBase = BigInt(100 + int(999901));
|
|
1692
1639
|
const assetsScaled = config?.assets ?? amountBase * unit;
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
};
|
|
1698
|
-
const sellCallbackAddress = "0x3333333333333333333333333333333333333333";
|
|
1699
|
-
const amount = assetsScaled * 1000000000000000000000n;
|
|
1700
|
-
return {
|
|
1701
|
-
address: sellCallbackAddress,
|
|
1702
|
-
data: encodeSellERC20Callback({
|
|
1703
|
-
collaterals: [collateralAsset],
|
|
1704
|
-
amounts: [amount]
|
|
1705
|
-
})
|
|
1706
|
-
};
|
|
1707
|
-
})();
|
|
1640
|
+
const emptyCallback = {
|
|
1641
|
+
address: zeroAddress,
|
|
1642
|
+
data: "0x"
|
|
1643
|
+
};
|
|
1708
1644
|
return from$9({
|
|
1709
1645
|
maker: config?.maker ?? address(),
|
|
1710
1646
|
assets: assetsScaled,
|
|
@@ -1723,7 +1659,7 @@ function random$1(config) {
|
|
|
1723
1659
|
...random$3(),
|
|
1724
1660
|
lltv
|
|
1725
1661
|
})).sort((a, b) => a.asset.localeCompare(b.asset)),
|
|
1726
|
-
callback: config?.callback ??
|
|
1662
|
+
callback: config?.callback ?? emptyCallback
|
|
1727
1663
|
});
|
|
1728
1664
|
}
|
|
1729
1665
|
const weightedChoice = (pairs) => {
|
|
@@ -2013,6 +1949,94 @@ function decode$1(data) {
|
|
|
2013
1949
|
});
|
|
2014
1950
|
}
|
|
2015
1951
|
/**
|
|
1952
|
+
* ABI for the Take event emitted by the Morpho V2 contract.
|
|
1953
|
+
*/
|
|
1954
|
+
const takeEvent = {
|
|
1955
|
+
type: "event",
|
|
1956
|
+
name: "Take",
|
|
1957
|
+
inputs: [
|
|
1958
|
+
{
|
|
1959
|
+
name: "caller",
|
|
1960
|
+
type: "address",
|
|
1961
|
+
indexed: false,
|
|
1962
|
+
internalType: "address"
|
|
1963
|
+
},
|
|
1964
|
+
{
|
|
1965
|
+
name: "id",
|
|
1966
|
+
type: "bytes32",
|
|
1967
|
+
indexed: true,
|
|
1968
|
+
internalType: "bytes32"
|
|
1969
|
+
},
|
|
1970
|
+
{
|
|
1971
|
+
name: "maker",
|
|
1972
|
+
type: "address",
|
|
1973
|
+
indexed: true,
|
|
1974
|
+
internalType: "address"
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
name: "taker",
|
|
1978
|
+
type: "address",
|
|
1979
|
+
indexed: true,
|
|
1980
|
+
internalType: "address"
|
|
1981
|
+
},
|
|
1982
|
+
{
|
|
1983
|
+
name: "offerIsBuy",
|
|
1984
|
+
type: "bool",
|
|
1985
|
+
indexed: false,
|
|
1986
|
+
internalType: "bool"
|
|
1987
|
+
},
|
|
1988
|
+
{
|
|
1989
|
+
name: "buyerAssets",
|
|
1990
|
+
type: "uint256",
|
|
1991
|
+
indexed: false,
|
|
1992
|
+
internalType: "uint256"
|
|
1993
|
+
},
|
|
1994
|
+
{
|
|
1995
|
+
name: "sellerAssets",
|
|
1996
|
+
type: "uint256",
|
|
1997
|
+
indexed: false,
|
|
1998
|
+
internalType: "uint256"
|
|
1999
|
+
},
|
|
2000
|
+
{
|
|
2001
|
+
name: "obligationUnits",
|
|
2002
|
+
type: "uint256",
|
|
2003
|
+
indexed: false,
|
|
2004
|
+
internalType: "uint256"
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
name: "obligationShares",
|
|
2008
|
+
type: "uint256",
|
|
2009
|
+
indexed: false,
|
|
2010
|
+
internalType: "uint256"
|
|
2011
|
+
},
|
|
2012
|
+
{
|
|
2013
|
+
name: "buyerIsLender",
|
|
2014
|
+
type: "bool",
|
|
2015
|
+
indexed: false,
|
|
2016
|
+
internalType: "bool"
|
|
2017
|
+
},
|
|
2018
|
+
{
|
|
2019
|
+
name: "sellerIsBorrower",
|
|
2020
|
+
type: "bool",
|
|
2021
|
+
indexed: false,
|
|
2022
|
+
internalType: "bool"
|
|
2023
|
+
},
|
|
2024
|
+
{
|
|
2025
|
+
name: "group",
|
|
2026
|
+
type: "bytes32",
|
|
2027
|
+
indexed: false,
|
|
2028
|
+
internalType: "bytes32"
|
|
2029
|
+
},
|
|
2030
|
+
{
|
|
2031
|
+
name: "consumed",
|
|
2032
|
+
type: "uint256",
|
|
2033
|
+
indexed: false,
|
|
2034
|
+
internalType: "uint256"
|
|
2035
|
+
}
|
|
2036
|
+
],
|
|
2037
|
+
anonymous: false
|
|
2038
|
+
};
|
|
2039
|
+
/**
|
|
2016
2040
|
* ABI for the Consume event emitted by the Obligation contract.
|
|
2017
2041
|
*/
|
|
2018
2042
|
const consumedEvent = {
|
|
@@ -2766,6 +2790,16 @@ const BrandTypeId = Symbol.for("mempool/Brand");
|
|
|
2766
2790
|
//#endregion
|
|
2767
2791
|
//#region src/api/Schema/OfferResponse.ts
|
|
2768
2792
|
var OfferResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$2 });
|
|
2793
|
+
function normalizeChainId(chainId) {
|
|
2794
|
+
const parsedChainId = Number(chainId);
|
|
2795
|
+
if (!Number.isInteger(parsedChainId) || parsedChainId <= 0) throw new Error(`Invalid chain id: ${String(chainId)}`);
|
|
2796
|
+
return parsedChainId;
|
|
2797
|
+
}
|
|
2798
|
+
function normalizeBlockNumber(blockNumber) {
|
|
2799
|
+
const parsedBlockNumber = Number(blockNumber);
|
|
2800
|
+
if (!Number.isInteger(parsedBlockNumber) || parsedBlockNumber < 0) throw new Error(`Invalid block number: ${String(blockNumber)}`);
|
|
2801
|
+
return parsedBlockNumber;
|
|
2802
|
+
}
|
|
2769
2803
|
/**
|
|
2770
2804
|
* Creates an `OfferResponse` matching the Solidity Offer struct layout.
|
|
2771
2805
|
* @constructor
|
|
@@ -2773,6 +2807,8 @@ var OfferResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$2 });
|
|
|
2773
2807
|
* @returns The created `OfferResponse`. {@link OfferResponse}
|
|
2774
2808
|
*/
|
|
2775
2809
|
function from$2(input) {
|
|
2810
|
+
const chainId = normalizeChainId(input.chainId);
|
|
2811
|
+
const blockNumber = normalizeBlockNumber(input.blockNumber);
|
|
2776
2812
|
const base = {
|
|
2777
2813
|
offer: {
|
|
2778
2814
|
obligation: {
|
|
@@ -2799,15 +2835,15 @@ function from$2(input) {
|
|
|
2799
2835
|
},
|
|
2800
2836
|
offer_hash: input.hash,
|
|
2801
2837
|
obligation_id: id({
|
|
2802
|
-
chainId
|
|
2838
|
+
chainId,
|
|
2803
2839
|
loanToken: input.loanToken,
|
|
2804
2840
|
collaterals: [...input.collaterals],
|
|
2805
2841
|
maturity: input.maturity
|
|
2806
2842
|
}),
|
|
2807
|
-
chain_id:
|
|
2843
|
+
chain_id: chainId,
|
|
2808
2844
|
consumed: input.consumed.toString(),
|
|
2809
2845
|
takeable: input.takeable.toString(),
|
|
2810
|
-
block_number:
|
|
2846
|
+
block_number: blockNumber
|
|
2811
2847
|
};
|
|
2812
2848
|
if (!input.proof || !input.root || !input.signature) return {
|
|
2813
2849
|
...base,
|
|
@@ -2867,8 +2903,8 @@ const offerExample = {
|
|
|
2867
2903
|
price: "2750000000000000000",
|
|
2868
2904
|
group: "0x000000000000000000000000000000000000000000000000000000000008b8f4",
|
|
2869
2905
|
session: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
2870
|
-
callback: "
|
|
2871
|
-
callback_data: "
|
|
2906
|
+
callback: "0x0000000000000000000000000000000000000000",
|
|
2907
|
+
callback_data: "0x"
|
|
2872
2908
|
},
|
|
2873
2909
|
offer_hash: "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
|
|
2874
2910
|
obligation_id: "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc",
|
|
@@ -2920,25 +2956,10 @@ const validateOfferExample = {
|
|
|
2920
2956
|
lltv: "860000000000000000"
|
|
2921
2957
|
}],
|
|
2922
2958
|
callback: {
|
|
2923
|
-
address: "
|
|
2924
|
-
data: "
|
|
2959
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
2960
|
+
data: "0x"
|
|
2925
2961
|
}
|
|
2926
2962
|
};
|
|
2927
|
-
const callbackTypesRequestExample = { callbacks: [{
|
|
2928
|
-
chain_id: 1,
|
|
2929
|
-
addresses: [
|
|
2930
|
-
"0x1111111111111111111111111111111111111111",
|
|
2931
|
-
"0x3333333333333333333333333333333333333333",
|
|
2932
|
-
"0x9999999999999999999999999999999999999999"
|
|
2933
|
-
]
|
|
2934
|
-
}] };
|
|
2935
|
-
const callbackTypesResponseExample = [{
|
|
2936
|
-
chain_id: 1,
|
|
2937
|
-
sell_erc20_callback: ["0x1111111111111111111111111111111111111111"],
|
|
2938
|
-
buy_erc20: ["0x5555555555555555555555555555555555555555"],
|
|
2939
|
-
buy_vault_v1_callback: ["0x3333333333333333333333333333333333333333"],
|
|
2940
|
-
not_supported: ["0x9999999999999999999999999999999999999999"]
|
|
2941
|
-
}];
|
|
2942
2963
|
const routerStatusExample = {
|
|
2943
2964
|
status: "live",
|
|
2944
2965
|
initialized: true,
|
|
@@ -3007,55 +3028,6 @@ __decorate([ApiProperty({
|
|
|
3007
3028
|
type: "string",
|
|
3008
3029
|
example: validateOfferExample.callback.data
|
|
3009
3030
|
})], ValidateCallbackRequest.prototype, "data", void 0);
|
|
3010
|
-
var CallbackTypesChainRequest = class {};
|
|
3011
|
-
__decorate([ApiProperty({
|
|
3012
|
-
type: "number",
|
|
3013
|
-
example: callbackTypesRequestExample.callbacks[0].chain_id
|
|
3014
|
-
})], CallbackTypesChainRequest.prototype, "chain_id", void 0);
|
|
3015
|
-
__decorate([ApiProperty({
|
|
3016
|
-
type: () => [String],
|
|
3017
|
-
example: callbackTypesRequestExample.callbacks[0].addresses
|
|
3018
|
-
})], CallbackTypesChainRequest.prototype, "addresses", void 0);
|
|
3019
|
-
var CallbackTypesRequest = class {};
|
|
3020
|
-
__decorate([ApiProperty({
|
|
3021
|
-
type: () => [CallbackTypesChainRequest],
|
|
3022
|
-
example: callbackTypesRequestExample.callbacks
|
|
3023
|
-
})], CallbackTypesRequest.prototype, "callbacks", void 0);
|
|
3024
|
-
var CallbackTypesChainResponse = class {};
|
|
3025
|
-
__decorate([ApiProperty({
|
|
3026
|
-
type: "number",
|
|
3027
|
-
example: callbackTypesResponseExample[0].chain_id
|
|
3028
|
-
})], CallbackTypesChainResponse.prototype, "chain_id", void 0);
|
|
3029
|
-
__decorate([ApiProperty({
|
|
3030
|
-
type: () => [String],
|
|
3031
|
-
required: false,
|
|
3032
|
-
example: callbackTypesResponseExample[0].buy_vault_v1_callback
|
|
3033
|
-
})], CallbackTypesChainResponse.prototype, "buy_vault_v1_callback", void 0);
|
|
3034
|
-
__decorate([ApiProperty({
|
|
3035
|
-
type: () => [String],
|
|
3036
|
-
required: false,
|
|
3037
|
-
example: callbackTypesResponseExample[0].sell_erc20_callback
|
|
3038
|
-
})], CallbackTypesChainResponse.prototype, "sell_erc20_callback", void 0);
|
|
3039
|
-
__decorate([ApiProperty({
|
|
3040
|
-
type: () => [String],
|
|
3041
|
-
required: false,
|
|
3042
|
-
example: callbackTypesResponseExample[0].buy_erc20
|
|
3043
|
-
})], CallbackTypesChainResponse.prototype, "buy_erc20", void 0);
|
|
3044
|
-
__decorate([ApiProperty({
|
|
3045
|
-
type: () => [String],
|
|
3046
|
-
example: callbackTypesResponseExample[0].not_supported
|
|
3047
|
-
})], CallbackTypesChainResponse.prototype, "not_supported", void 0);
|
|
3048
|
-
var CallbackTypesSuccessResponse = class extends SuccessResponse {};
|
|
3049
|
-
__decorate([ApiProperty({
|
|
3050
|
-
type: "string",
|
|
3051
|
-
nullable: true,
|
|
3052
|
-
example: "maturity:1:1730415600:end_of_next_month"
|
|
3053
|
-
})], CallbackTypesSuccessResponse.prototype, "cursor", void 0);
|
|
3054
|
-
__decorate([ApiProperty({
|
|
3055
|
-
type: () => [CallbackTypesChainResponse],
|
|
3056
|
-
description: "Callback types grouped by chain.",
|
|
3057
|
-
example: callbackTypesResponseExample
|
|
3058
|
-
})], CallbackTypesSuccessResponse.prototype, "data", void 0);
|
|
3059
3031
|
var AskResponse = class {};
|
|
3060
3032
|
__decorate([ApiProperty({
|
|
3061
3033
|
type: "string",
|
|
@@ -3573,7 +3545,7 @@ __decorate([
|
|
|
3573
3545
|
methods: ["post"],
|
|
3574
3546
|
path: "/v1/validate",
|
|
3575
3547
|
summary: "Validate offers",
|
|
3576
|
-
description: "Validates offers against router validation rules. Returns unsigned payload + root on success, or issues only on validation failure."
|
|
3548
|
+
description: "Validates offers against router validation rules. Only empty callbacks (zero address, 0x data) are accepted. Returns unsigned payload + root on success, or issues only on validation failure."
|
|
3577
3549
|
}),
|
|
3578
3550
|
ApiBody({ type: ValidateOffersRequest }),
|
|
3579
3551
|
ApiResponse({
|
|
@@ -3592,28 +3564,6 @@ ValidateController = __decorate([ApiTags("Make"), ApiResponse({
|
|
|
3592
3564
|
description: "Bad Request",
|
|
3593
3565
|
type: BadRequestResponse
|
|
3594
3566
|
})], ValidateController);
|
|
3595
|
-
let CallbacksController = class CallbacksController {
|
|
3596
|
-
async resolveCallbackTypes() {}
|
|
3597
|
-
};
|
|
3598
|
-
__decorate([
|
|
3599
|
-
ApiOperation({
|
|
3600
|
-
methods: ["post"],
|
|
3601
|
-
path: "/v1/callbacks",
|
|
3602
|
-
summary: "Resolve callback types",
|
|
3603
|
-
description: "Returns callback types for callback addresses grouped by chain."
|
|
3604
|
-
}),
|
|
3605
|
-
ApiBody({ type: CallbackTypesRequest }),
|
|
3606
|
-
ApiResponse({
|
|
3607
|
-
status: 200,
|
|
3608
|
-
description: "Success",
|
|
3609
|
-
type: CallbackTypesSuccessResponse
|
|
3610
|
-
})
|
|
3611
|
-
], CallbacksController.prototype, "resolveCallbackTypes", null);
|
|
3612
|
-
CallbacksController = __decorate([ApiTags("Make"), ApiResponse({
|
|
3613
|
-
status: 400,
|
|
3614
|
-
description: "Bad Request",
|
|
3615
|
-
type: BadRequestResponse
|
|
3616
|
-
})], CallbacksController);
|
|
3617
3567
|
let OffersController = class OffersController {
|
|
3618
3568
|
async getOffers() {}
|
|
3619
3569
|
};
|
|
@@ -3763,12 +3713,6 @@ const configRulesMaturityExample = {
|
|
|
3763
3713
|
name: "end_of_next_month",
|
|
3764
3714
|
timestamp: 1730415600
|
|
3765
3715
|
};
|
|
3766
|
-
const configRulesCallbackExample = {
|
|
3767
|
-
type: "callback",
|
|
3768
|
-
chain_id: 1,
|
|
3769
|
-
address: "0x1111111111111111111111111111111111111111",
|
|
3770
|
-
callback_type: "sell_erc20_callback"
|
|
3771
|
-
};
|
|
3772
3716
|
const configRulesLoanTokenExample = {
|
|
3773
3717
|
type: "loan_token",
|
|
3774
3718
|
chain_id: 1,
|
|
@@ -3782,7 +3726,6 @@ const configRulesOracleExample = {
|
|
|
3782
3726
|
const configRulesChecksumExample = "f1d2d2f924e986ac86fdf7b36c94bcdf";
|
|
3783
3727
|
const configRulesPayloadExample = [
|
|
3784
3728
|
configRulesMaturityExample,
|
|
3785
|
-
configRulesCallbackExample,
|
|
3786
3729
|
configRulesLoanTokenExample,
|
|
3787
3730
|
configRulesOracleExample
|
|
3788
3731
|
];
|
|
@@ -3847,14 +3790,9 @@ __decorate([ApiProperty({
|
|
|
3847
3790
|
})], ConfigRulesRuleResponse.prototype, "timestamp", void 0);
|
|
3848
3791
|
__decorate([ApiProperty({
|
|
3849
3792
|
type: "string",
|
|
3850
|
-
example:
|
|
3793
|
+
example: configRulesLoanTokenExample.address,
|
|
3851
3794
|
required: false
|
|
3852
3795
|
})], ConfigRulesRuleResponse.prototype, "address", void 0);
|
|
3853
|
-
__decorate([ApiProperty({
|
|
3854
|
-
type: "string",
|
|
3855
|
-
example: configRulesCallbackExample.callback_type,
|
|
3856
|
-
required: false
|
|
3857
|
-
})], ConfigRulesRuleResponse.prototype, "callback_type", void 0);
|
|
3858
3796
|
var ConfigRulesSuccessResponse = class {};
|
|
3859
3797
|
__decorate([ApiProperty({ type: () => ConfigRulesMeta })], ConfigRulesSuccessResponse.prototype, "meta", void 0);
|
|
3860
3798
|
__decorate([ApiProperty({
|
|
@@ -3915,7 +3853,7 @@ __decorate([
|
|
|
3915
3853
|
methods: ["get"],
|
|
3916
3854
|
path: "/v1/config/rules",
|
|
3917
3855
|
summary: "Get config rules",
|
|
3918
|
-
description: "Returns configured rules for supported chains."
|
|
3856
|
+
description: "Returns configured rules (maturities, loan tokens, oracles) for supported chains."
|
|
3919
3857
|
}),
|
|
3920
3858
|
ApiQuery({
|
|
3921
3859
|
name: "cursor",
|
|
@@ -4094,8 +4032,7 @@ const OpenApi = async () => {
|
|
|
4094
4032
|
ObligationsController,
|
|
4095
4033
|
HealthController,
|
|
4096
4034
|
UsersController,
|
|
4097
|
-
ValidateController
|
|
4098
|
-
CallbacksController
|
|
4035
|
+
ValidateController
|
|
4099
4036
|
],
|
|
4100
4037
|
document: {
|
|
4101
4038
|
openapi: "3.1.0",
|
|
@@ -4352,16 +4289,6 @@ const GetBookParams = z$1.object({
|
|
|
4352
4289
|
})
|
|
4353
4290
|
});
|
|
4354
4291
|
const ValidateOffersBody = z$1.object({ offers: z$1.array(z$1.unknown()).min(1, { message: "'offers' must contain at least 1 offer" }) }).strict();
|
|
4355
|
-
const CallbackTypesBody = z$1.object({ callbacks: z$1.array(z$1.object({
|
|
4356
|
-
chain_id: z$1.number().int().positive().meta({
|
|
4357
|
-
description: "Chain id.",
|
|
4358
|
-
example: 1
|
|
4359
|
-
}),
|
|
4360
|
-
addresses: z$1.array(z$1.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "Callback address must be a valid 20-byte address" }).transform((val) => val.toLowerCase())).meta({
|
|
4361
|
-
description: "Callback contract addresses.",
|
|
4362
|
-
example: ["0x1111111111111111111111111111111111111111", "0x3333333333333333333333333333333333333333"]
|
|
4363
|
-
})
|
|
4364
|
-
}).strict()) }).strict();
|
|
4365
4292
|
const GetUserPositionsParams = z$1.object({
|
|
4366
4293
|
...PaginationQueryParams.shape,
|
|
4367
4294
|
user_address: z$1.string().regex(/^0x[a-fA-F0-9]{40}$/, { error: "User address must be a valid 20-byte address" }).transform((val) => val.toLowerCase()).meta({
|
|
@@ -4380,7 +4307,6 @@ const schemas = {
|
|
|
4380
4307
|
get_obligation: GetObligationParams,
|
|
4381
4308
|
get_book: GetBookParams,
|
|
4382
4309
|
validate_offers: ValidateOffersBody,
|
|
4383
|
-
callback_types: CallbackTypesBody,
|
|
4384
4310
|
get_user_positions: GetUserPositionsParams
|
|
4385
4311
|
};
|
|
4386
4312
|
function parse(action, query) {
|
|
@@ -4395,7 +4321,6 @@ function safeParse(action, query, error) {
|
|
|
4395
4321
|
var Schema_exports = /* @__PURE__ */ __exportAll({
|
|
4396
4322
|
BookResponse: () => BookResponse_exports,
|
|
4397
4323
|
BooksController: () => BooksController,
|
|
4398
|
-
CallbacksController: () => CallbacksController,
|
|
4399
4324
|
ChainHealth: () => ChainHealth,
|
|
4400
4325
|
ChainsHealthResponse: () => ChainsHealthResponse,
|
|
4401
4326
|
CollectorHealth: () => CollectorHealth,
|
|
@@ -4674,23 +4599,11 @@ function createHttpClient(config) {
|
|
|
4674
4599
|
issues: []
|
|
4675
4600
|
};
|
|
4676
4601
|
};
|
|
4677
|
-
const getCallbackTypes = async (requestPayload) => {
|
|
4678
|
-
const response = await request("/v1/callbacks", {
|
|
4679
|
-
method: "POST",
|
|
4680
|
-
headers: { "content-type": "application/json" },
|
|
4681
|
-
body: JSON.stringify(requestPayload)
|
|
4682
|
-
});
|
|
4683
|
-
const json = await response.json();
|
|
4684
|
-
if (!response.ok) throw new Error(`Gatekeeper callbacks request failed: ${extractErrorMessage(json) ?? response.statusText}`);
|
|
4685
|
-
if (!("data" in json) || !Array.isArray(json.data)) throw new Error("Gatekeeper callbacks response is invalid.");
|
|
4686
|
-
return json.data;
|
|
4687
|
-
};
|
|
4688
4602
|
return {
|
|
4689
4603
|
baseUrl,
|
|
4690
4604
|
validate,
|
|
4691
4605
|
getConfigRules,
|
|
4692
|
-
isAllowed
|
|
4693
|
-
getCallbackTypes
|
|
4606
|
+
isAllowed
|
|
4694
4607
|
};
|
|
4695
4608
|
}
|
|
4696
4609
|
function mergeHeaders(base, extra) {
|
|
@@ -4814,36 +4727,6 @@ function create(parameters) {
|
|
|
4814
4727
|
|
|
4815
4728
|
//#endregion
|
|
4816
4729
|
//#region src/gatekeeper/GateConfig.ts
|
|
4817
|
-
/**
|
|
4818
|
-
* Returns the callback configuration for a given chain and callback type, if it exists.
|
|
4819
|
-
*
|
|
4820
|
-
* @param chain - Chain name for which to read the validation configuration
|
|
4821
|
-
* @param type - Callback type to retrieve
|
|
4822
|
-
* @returns The matching callback configuration or undefined if not configured
|
|
4823
|
-
*/
|
|
4824
|
-
function getCallback(chain, type) {
|
|
4825
|
-
return configs[chain].callbacks?.find((c) => c.type === type);
|
|
4826
|
-
}
|
|
4827
|
-
/**
|
|
4828
|
-
* Attempts to infer the configured callback type from a callback address on a chain.
|
|
4829
|
-
* Skips the empty callback type as it does not carry addresses.
|
|
4830
|
-
*
|
|
4831
|
-
* @param chain - Chain name for which to infer the callback type
|
|
4832
|
-
* @param address - Callback contract address
|
|
4833
|
-
* @returns The callback type when found, otherwise undefined
|
|
4834
|
-
*/
|
|
4835
|
-
function getCallbackType(chain, address) {
|
|
4836
|
-
return configs[chain].callbacks?.find((c) => c.type !== Type$1.BuyWithEmptyCallback && c.addresses.includes(address?.toLowerCase()))?.type;
|
|
4837
|
-
}
|
|
4838
|
-
/**
|
|
4839
|
-
* Returns the list of allowed non-empty callback addresses for a chain.
|
|
4840
|
-
*
|
|
4841
|
-
* @param chain - Chain name
|
|
4842
|
-
* @returns Array of allowed callback addresses (lowercased). Empty when none configured
|
|
4843
|
-
*/
|
|
4844
|
-
const getCallbackAddresses = (chain) => {
|
|
4845
|
-
return configs[chain].callbacks?.filter((c) => c.type !== Type$1.BuyWithEmptyCallback).flatMap((c) => c.addresses) ?? [];
|
|
4846
|
-
};
|
|
4847
4730
|
const assets = {
|
|
4848
4731
|
[ChainId.ETHEREUM.toString()]: [
|
|
4849
4732
|
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
@@ -4915,63 +4798,19 @@ const oracles = {
|
|
|
4915
4798
|
};
|
|
4916
4799
|
const configs = {
|
|
4917
4800
|
ethereum: {
|
|
4918
|
-
callbacks: [
|
|
4919
|
-
{
|
|
4920
|
-
type: Type$1.BuyVaultV1Callback,
|
|
4921
|
-
addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
|
|
4922
|
-
vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
|
|
4923
|
-
},
|
|
4924
|
-
{
|
|
4925
|
-
type: Type$1.SellERC20Callback,
|
|
4926
|
-
addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
|
|
4927
|
-
},
|
|
4928
|
-
{ type: Type$1.BuyWithEmptyCallback }
|
|
4929
|
-
],
|
|
4801
|
+
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4930
4802
|
maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
|
|
4931
4803
|
},
|
|
4932
4804
|
base: {
|
|
4933
|
-
callbacks: [
|
|
4934
|
-
{
|
|
4935
|
-
type: Type$1.BuyVaultV1Callback,
|
|
4936
|
-
addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
|
|
4937
|
-
vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0xFf62A7c278C62eD665133147129245053Bbf5918"]
|
|
4938
|
-
},
|
|
4939
|
-
{
|
|
4940
|
-
type: Type$1.SellERC20Callback,
|
|
4941
|
-
addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
|
|
4942
|
-
},
|
|
4943
|
-
{ type: Type$1.BuyWithEmptyCallback }
|
|
4944
|
-
],
|
|
4805
|
+
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4945
4806
|
maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
|
|
4946
4807
|
},
|
|
4947
4808
|
"ethereum-virtual-testnet": {
|
|
4948
|
-
callbacks: [
|
|
4949
|
-
{
|
|
4950
|
-
type: Type$1.BuyVaultV1Callback,
|
|
4951
|
-
addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
|
|
4952
|
-
vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
|
|
4953
|
-
},
|
|
4954
|
-
{
|
|
4955
|
-
type: Type$1.SellERC20Callback,
|
|
4956
|
-
addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
|
|
4957
|
-
},
|
|
4958
|
-
{ type: Type$1.BuyWithEmptyCallback }
|
|
4959
|
-
],
|
|
4809
|
+
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4960
4810
|
maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
|
|
4961
4811
|
},
|
|
4962
4812
|
anvil: {
|
|
4963
|
-
callbacks: [
|
|
4964
|
-
{
|
|
4965
|
-
type: Type$1.BuyVaultV1Callback,
|
|
4966
|
-
addresses: ["0x3333333333333333333333333333333333333333", "0x4444444444444444444444444444444444444444"],
|
|
4967
|
-
vaultFactories: ["0xA9c3D3a366466Fa809d1Ae982Fb2c46E5fC41101", "0x1897A8997241C1cD4bD0698647e4EB7213535c24"]
|
|
4968
|
-
},
|
|
4969
|
-
{
|
|
4970
|
-
type: Type$1.SellERC20Callback,
|
|
4971
|
-
addresses: ["0x1111111111111111111111111111111111111111", "0x2222222222222222222222222222222222222222"]
|
|
4972
|
-
},
|
|
4973
|
-
{ type: Type$1.BuyWithEmptyCallback }
|
|
4974
|
-
],
|
|
4813
|
+
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4975
4814
|
maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth]
|
|
4976
4815
|
}
|
|
4977
4816
|
};
|
|
@@ -4991,109 +4830,13 @@ var Rules_exports = /* @__PURE__ */ __exportAll({
|
|
|
4991
4830
|
/**
|
|
4992
4831
|
* set of rules to validate offers.
|
|
4993
4832
|
*
|
|
4994
|
-
* @param
|
|
4833
|
+
* @param _parameters - Validity parameters with chain and client
|
|
4995
4834
|
* @returns Array of validation rules to evaluate against offers
|
|
4996
4835
|
*/
|
|
4997
|
-
function validity(
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
if (callbackType !== Type$1.SellERC20Callback) return;
|
|
5002
|
-
const decoded = decode$2(callbackType, offer.callback.data);
|
|
5003
|
-
if (decoded.length === 0) return { message: "Callback data cannot be decoded or is empty." };
|
|
5004
|
-
if (callbackType === Type$1.SellERC20Callback) {
|
|
5005
|
-
const offerCollaterals = new Set(offer.collaterals.map((c) => c.asset.toLowerCase()));
|
|
5006
|
-
if (decoded.length !== offer.collaterals.length) return { message: `Sell callback collateral length mismatch. Expected ${offer.collaterals.length}, got ${decoded.length}.` };
|
|
5007
|
-
for (const { contract } of decoded) if (!offerCollaterals.has(contract.toLowerCase())) return { message: "Sell callback collateral is not part of offer collaterals." };
|
|
5008
|
-
}
|
|
5009
|
-
});
|
|
5010
|
-
const buyCallbackVaultInvalid = batch("buy_offers_callback_vault_invalid", "Validates that buy offers have valid vault callbacks registered in allowed factories with matching assets", async (offers) => {
|
|
5011
|
-
const validationIssues = /* @__PURE__ */ new Map();
|
|
5012
|
-
const offersByVaultAddress = /* @__PURE__ */ new Map();
|
|
5013
|
-
for (let i = 0; i < offers.length; i++) {
|
|
5014
|
-
const offer = offers[i];
|
|
5015
|
-
if (getCallbackType(client.chain.name, offer.callback.address) !== Type$1.BuyVaultV1Callback) continue;
|
|
5016
|
-
try {
|
|
5017
|
-
const callbackVaults = decodeBuyVaultV1Callback(offer.callback.data);
|
|
5018
|
-
for (const { contract } of callbackVaults) {
|
|
5019
|
-
const normalizedVaultAddress = contract.toLowerCase();
|
|
5020
|
-
if (!offersByVaultAddress.has(normalizedVaultAddress)) offersByVaultAddress.set(normalizedVaultAddress, []);
|
|
5021
|
-
offersByVaultAddress.get(normalizedVaultAddress).push({
|
|
5022
|
-
index: i,
|
|
5023
|
-
offer
|
|
5024
|
-
});
|
|
5025
|
-
}
|
|
5026
|
-
} catch (_) {}
|
|
5027
|
-
}
|
|
5028
|
-
const uniqueVaultAddresses = Array.from(offersByVaultAddress.keys());
|
|
5029
|
-
if (uniqueVaultAddresses.length === 0) return validationIssues;
|
|
5030
|
-
const allowedFactories = getCallback(client.chain.name, Type$1.BuyVaultV1Callback)?.vaultFactories.map((f) => f.toLowerCase());
|
|
5031
|
-
if (!allowedFactories) return validationIssues;
|
|
5032
|
-
const multicallContracts = [];
|
|
5033
|
-
for (const vaultAddress of uniqueVaultAddresses) {
|
|
5034
|
-
multicallContracts.push({
|
|
5035
|
-
address: vaultAddress,
|
|
5036
|
-
abi: ERC4626,
|
|
5037
|
-
functionName: "asset"
|
|
5038
|
-
});
|
|
5039
|
-
for (const factoryAddress of allowedFactories) multicallContracts.push({
|
|
5040
|
-
address: factoryAddress,
|
|
5041
|
-
abi: MetaMorphoFactory,
|
|
5042
|
-
functionName: "isMetaMorpho",
|
|
5043
|
-
args: [vaultAddress]
|
|
5044
|
-
});
|
|
5045
|
-
}
|
|
5046
|
-
const multicallResults = await multicall(client, {
|
|
5047
|
-
contracts: multicallContracts,
|
|
5048
|
-
allowFailure: true
|
|
5049
|
-
});
|
|
5050
|
-
const vaultAssetByAddress = /* @__PURE__ */ new Map();
|
|
5051
|
-
const registeredVaults = /* @__PURE__ */ new Set();
|
|
5052
|
-
const numberOfFactories = allowedFactories.length;
|
|
5053
|
-
let resultIndex = 0;
|
|
5054
|
-
for (const vaultAddress of uniqueVaultAddresses) {
|
|
5055
|
-
const assetCallResult = multicallResults[resultIndex++];
|
|
5056
|
-
const assetAddress = assetCallResult.status === "success" ? assetCallResult.result : null;
|
|
5057
|
-
vaultAssetByAddress.set(vaultAddress, assetAddress);
|
|
5058
|
-
let isRegisteredInFactory = false;
|
|
5059
|
-
for (let factoryIndex = 0; factoryIndex < numberOfFactories; factoryIndex++) {
|
|
5060
|
-
const factoryCallResult = multicallResults[resultIndex++];
|
|
5061
|
-
if (factoryCallResult.status === "success" && factoryCallResult.result === true) isRegisteredInFactory = true;
|
|
5062
|
-
}
|
|
5063
|
-
if (isRegisteredInFactory) registeredVaults.add(vaultAddress);
|
|
5064
|
-
}
|
|
5065
|
-
const uniqueOffers = /* @__PURE__ */ new Map();
|
|
5066
|
-
for (const offersArray of offersByVaultAddress.values()) for (const { index, offer } of offersArray) uniqueOffers.set(index, offer);
|
|
5067
|
-
for (const [index, offer] of uniqueOffers) try {
|
|
5068
|
-
const callbackVaults = decodeBuyVaultV1Callback(offer.callback.data);
|
|
5069
|
-
const vaultsWithIssues = [];
|
|
5070
|
-
for (const { contract } of callbackVaults) {
|
|
5071
|
-
const normalizedVaultAddress = contract.toLowerCase();
|
|
5072
|
-
const assetAddress = vaultAssetByAddress.get(normalizedVaultAddress);
|
|
5073
|
-
const isRegistered = registeredVaults.has(normalizedVaultAddress);
|
|
5074
|
-
const failureReasons = [];
|
|
5075
|
-
if (assetAddress === null) failureReasons.push("asset call failed");
|
|
5076
|
-
else if (assetAddress && assetAddress.toLowerCase() !== offer.loanToken.toLowerCase()) failureReasons.push("asset mismatch");
|
|
5077
|
-
if (!isRegistered) failureReasons.push("not registered in factory");
|
|
5078
|
-
if (failureReasons.length > 0) vaultsWithIssues.push({
|
|
5079
|
-
vaultAddress: contract,
|
|
5080
|
-
failureReasons: failureReasons.join(", ")
|
|
5081
|
-
});
|
|
5082
|
-
}
|
|
5083
|
-
if (vaultsWithIssues.length > 0) {
|
|
5084
|
-
const failureDetails = vaultsWithIssues.map((v) => `${v.vaultAddress} (${v.failureReasons})`).join("; ");
|
|
5085
|
-
validationIssues.set(index, { message: `Buy offer callback vaults are invalid: ${failureDetails}` });
|
|
5086
|
-
}
|
|
5087
|
-
} catch (_) {}
|
|
5088
|
-
return validationIssues;
|
|
5089
|
-
});
|
|
5090
|
-
return [
|
|
5091
|
-
single("expiry", "Validates that offer has not expired", (offer) => {
|
|
5092
|
-
if (offer.expiry < Math.floor(Date.now() / 1e3)) return { message: "Expiry mismatch" };
|
|
5093
|
-
}),
|
|
5094
|
-
sellErc20CallbackInvalid,
|
|
5095
|
-
buyCallbackVaultInvalid
|
|
5096
|
-
];
|
|
4836
|
+
function validity(_parameters) {
|
|
4837
|
+
return [single("expiry", "Validates that offer has not expired", (offer) => {
|
|
4838
|
+
if (offer.expiry < Math.floor(Date.now() / 1e3)) return { message: "Expiry mismatch" };
|
|
4839
|
+
})];
|
|
5097
4840
|
}
|
|
5098
4841
|
const chains = ({ chains }) => single("chain_ids", `Validates that offer chain is one of: [${chains.map((c) => c.id).join(", ")}]`, (offer) => {
|
|
5099
4842
|
const allowedChainIds = chains.map((c) => c.id);
|
|
@@ -5103,12 +4846,10 @@ const maturity = ({ maturities }) => single("maturity", `Validates that offer ma
|
|
|
5103
4846
|
const allowedMaturities = maturities.map((m) => from$11(m));
|
|
5104
4847
|
if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be end of current month (${allowedMaturities[0]}) or end of next month (${allowedMaturities[1]}). Got: ${offer.maturity}` };
|
|
5105
4848
|
});
|
|
5106
|
-
const callback = ({ callbacks
|
|
5107
|
-
if (isEmptyCallback(offer)
|
|
5108
|
-
if (isEmptyCallback(offer) &&
|
|
5109
|
-
if (
|
|
5110
|
-
if (!allowedAddresses.includes(offer.callback.address?.toLowerCase())) return { message: `Callback address ${offer.callback.address} is not allowed.` };
|
|
5111
|
-
}
|
|
4849
|
+
const callback = ({ callbacks }) => single("callback", `Validates callbacks: buy empty callback is ${callbacks.includes(Type$1.BuyWithEmptyCallback) ? "allowed" : "not allowed"}; sell empty callback is ${callbacks.includes(Type$1.SellWithEmptyCallback) ? "allowed" : "not allowed"}; non-empty callbacks are rejected`, (offer) => {
|
|
4850
|
+
if (!isEmptyCallback(offer)) return { message: "Non-empty callbacks are not supported." };
|
|
4851
|
+
if (isEmptyCallback(offer) && offer.buy && !callbacks.includes(Type$1.BuyWithEmptyCallback)) return { message: "Buy offers with empty callback not allowed." };
|
|
4852
|
+
if (isEmptyCallback(offer) && !offer.buy && !callbacks.includes(Type$1.SellWithEmptyCallback)) return { message: "Sell offers with empty callback not allowed." };
|
|
5112
4853
|
});
|
|
5113
4854
|
/**
|
|
5114
4855
|
* A validation rule that checks if the offer's tokens are allowed for its chain.
|
|
@@ -5173,12 +4914,8 @@ const morphoRules = (chains$2) => {
|
|
|
5173
4914
|
chains({ chains: chains$2 }),
|
|
5174
4915
|
maturity({ maturities: [MaturityType.EndOfMonth, MaturityType.EndOfNextMonth] }),
|
|
5175
4916
|
callback({
|
|
5176
|
-
callbacks: [
|
|
5177
|
-
|
|
5178
|
-
Type$1.BuyVaultV1Callback,
|
|
5179
|
-
Type$1.SellERC20Callback
|
|
5180
|
-
],
|
|
5181
|
-
allowedAddresses: chains$2.flatMap((c) => getCallbackAddresses(c.name))
|
|
4917
|
+
callbacks: [Type$1.BuyWithEmptyCallback, Type$1.SellWithEmptyCallback],
|
|
4918
|
+
allowedAddresses: []
|
|
5182
4919
|
}),
|
|
5183
4920
|
token({ assetsByChainId }),
|
|
5184
4921
|
oracle({ oraclesByChainId })
|