@morpho-dev/router 0.8.0 → 0.9.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.js +574 -244
- package/dist/drizzle/migrations/0026_add-receiver-if-maker-is-seller.sql +1 -0
- package/dist/drizzle/migrations/meta/0026_snapshot.json +1454 -0
- package/dist/drizzle/migrations/meta/_journal.json +7 -0
- package/dist/evm/bytecode/morpho.txt +1 -1
- package/dist/index.browser.d.mts +105 -46
- package/dist/index.browser.d.mts.map +1 -1
- package/dist/index.browser.d.ts +105 -46
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +147 -51
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +147 -51
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.mts +165 -56
- package/dist/index.node.d.mts.map +1 -1
- package/dist/index.node.d.ts +165 -56
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +583 -245
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +584 -246
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -283,6 +283,7 @@ var ObligationResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$
|
|
|
283
283
|
* Creates an `ObligationResponse` from a `Obligation`.
|
|
284
284
|
* @constructor
|
|
285
285
|
* @param obligation - {@link Obligation}
|
|
286
|
+
* @param quote - {@link Quote}
|
|
286
287
|
* @returns The created `ObligationResponse`. {@link ObligationResponse}
|
|
287
288
|
*/
|
|
288
289
|
function from$14(obligation, quote) {
|
|
@@ -296,8 +297,14 @@ function from$14(obligation, quote) {
|
|
|
296
297
|
oracle: c.oracle
|
|
297
298
|
})),
|
|
298
299
|
maturity: obligation.maturity,
|
|
299
|
-
ask: {
|
|
300
|
-
|
|
300
|
+
ask: {
|
|
301
|
+
tick: quote.ask.tick,
|
|
302
|
+
price: quote.ask.price.toString()
|
|
303
|
+
},
|
|
304
|
+
bid: {
|
|
305
|
+
tick: quote.bid.tick,
|
|
306
|
+
price: quote.bid.price.toString()
|
|
307
|
+
}
|
|
301
308
|
};
|
|
302
309
|
}
|
|
303
310
|
|
|
@@ -343,18 +350,18 @@ const MorphoV2 = (0, viem.parseAbi)([
|
|
|
343
350
|
"function setFeeSetter(address newFeeSetter)",
|
|
344
351
|
"function setObligationTradingFee(bytes32 id, uint256 index, uint256 newTradingFee)",
|
|
345
352
|
"function setOwner(address newOwner)",
|
|
346
|
-
"function setTradingFeeRecipient(address
|
|
353
|
+
"function setTradingFeeRecipient(address feeRecipient)",
|
|
347
354
|
"function sharesOf(bytes32 id, address user) view returns (uint256)",
|
|
348
355
|
"function shuffleSession()",
|
|
349
356
|
"function supplyCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
|
|
350
|
-
"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
|
|
357
|
+
"function take(uint256 buyerAssets, uint256 sellerAssets, uint256 obligationUnits, uint256 obligationShares, address taker, address takerCallback, bytes takerCallbackData, address receiverIfTakerIsSeller, ((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, address receiverIfMakerIsSeller) offer, (uint8 v, bytes32 r, bytes32 s) sig, bytes32 root, bytes32[] proof) returns (uint256, uint256, uint256, uint256)",
|
|
351
358
|
"function totalShares(bytes32 id) view returns (uint256)",
|
|
352
359
|
"function totalUnits(bytes32 id) view returns (uint256)",
|
|
353
360
|
"function touchObligation((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation) returns (bytes32)",
|
|
354
361
|
"function tradingFee(bytes32 id, uint256 timeToMaturity) view returns (uint256)",
|
|
355
362
|
"function tradingFeeRecipient() view returns (address)",
|
|
356
|
-
"function withdraw((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, uint256 shares, address onBehalf) returns (uint256, uint256)",
|
|
357
|
-
"function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf)",
|
|
363
|
+
"function withdraw((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, uint256 obligationUnits, uint256 shares, address onBehalf, address receiver) returns (uint256, uint256)",
|
|
364
|
+
"function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf, address receiver)",
|
|
358
365
|
"function withdrawable(bytes32 id) view returns (uint256)",
|
|
359
366
|
"event Constructor(address indexed owner)",
|
|
360
367
|
"event Consume(address indexed user, bytes32 indexed group, uint256 amount)",
|
|
@@ -366,12 +373,12 @@ const MorphoV2 = (0, viem.parseAbi)([
|
|
|
366
373
|
"event SetFeeSetter(address indexed feeSetter)",
|
|
367
374
|
"event SetObligationTradingFee(bytes32 indexed id, uint256 indexed index, uint256 newTradingFee)",
|
|
368
375
|
"event SetOwner(address indexed owner)",
|
|
369
|
-
"event SetTradingFeeRecipient(address indexed
|
|
376
|
+
"event SetTradingFeeRecipient(address indexed feeRecipient)",
|
|
370
377
|
"event ShuffleSession(address indexed user, bytes32 session)",
|
|
371
378
|
"event SupplyCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)",
|
|
372
|
-
"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)",
|
|
373
|
-
"event Withdraw(address
|
|
374
|
-
"event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)"
|
|
379
|
+
"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, address sellerReceiver, bytes32 group, uint256 consumed)",
|
|
380
|
+
"event Withdraw(address caller, bytes32 indexed id, uint256 obligationUnits, uint256 shares, address indexed onBehalf, address indexed receiver)",
|
|
381
|
+
"event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf, address receiver)"
|
|
375
382
|
]);
|
|
376
383
|
|
|
377
384
|
//#endregion
|
|
@@ -688,8 +695,8 @@ const chains$1 = {
|
|
|
688
695
|
name: "ethereum-virtual-testnet",
|
|
689
696
|
custom: {
|
|
690
697
|
morpho: {
|
|
691
|
-
address: "
|
|
692
|
-
blockCreated:
|
|
698
|
+
address: "0xc9f3c65996fc46b9500608b2c9a9152c01c540f7",
|
|
699
|
+
blockCreated: 23226871
|
|
693
700
|
},
|
|
694
701
|
morphoBlue: {
|
|
695
702
|
address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
@@ -1651,7 +1658,8 @@ const OfferSchema = () => {
|
|
|
1651
1658
|
callback: zod.object({
|
|
1652
1659
|
address: zod.string().transform(transformAddress),
|
|
1653
1660
|
data: zod.string().transform(transformHex)
|
|
1654
|
-
})
|
|
1661
|
+
}),
|
|
1662
|
+
receiverIfMakerIsSeller: zod.string().transform(transformAddress)
|
|
1655
1663
|
}).refine((data) => data.start < data.expiry, {
|
|
1656
1664
|
message: "start must be before expiry",
|
|
1657
1665
|
path: ["start"]
|
|
@@ -1667,8 +1675,12 @@ const OfferSchema = () => {
|
|
|
1667
1675
|
* @returns The created offer.
|
|
1668
1676
|
*/
|
|
1669
1677
|
function from$9(input) {
|
|
1678
|
+
const normalizedInput = {
|
|
1679
|
+
...input,
|
|
1680
|
+
receiverIfMakerIsSeller: input.receiverIfMakerIsSeller ?? input.maker
|
|
1681
|
+
};
|
|
1670
1682
|
try {
|
|
1671
|
-
return OfferSchema().parse(
|
|
1683
|
+
return OfferSchema().parse(normalizedInput);
|
|
1672
1684
|
} catch (error) {
|
|
1673
1685
|
throw new InvalidOfferError(error);
|
|
1674
1686
|
}
|
|
@@ -1720,6 +1732,7 @@ const serialize = (offer) => ({
|
|
|
1720
1732
|
address: offer.callback.address,
|
|
1721
1733
|
data: offer.callback.data
|
|
1722
1734
|
},
|
|
1735
|
+
receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller,
|
|
1723
1736
|
hash: hash(offer)
|
|
1724
1737
|
});
|
|
1725
1738
|
/**
|
|
@@ -1762,8 +1775,9 @@ function random$1(config) {
|
|
|
1762
1775
|
address: viem.zeroAddress,
|
|
1763
1776
|
data: "0x"
|
|
1764
1777
|
};
|
|
1778
|
+
const maker = config?.maker ?? address();
|
|
1765
1779
|
return from$9({
|
|
1766
|
-
maker
|
|
1780
|
+
maker,
|
|
1767
1781
|
assets: assetsScaled,
|
|
1768
1782
|
obligationUnits: config?.obligationUnits ?? 0n,
|
|
1769
1783
|
obligationShares: config?.obligationShares ?? 0n,
|
|
@@ -1780,7 +1794,8 @@ function random$1(config) {
|
|
|
1780
1794
|
...random$3(),
|
|
1781
1795
|
lltv
|
|
1782
1796
|
})).sort((a, b) => a.asset.localeCompare(b.asset)),
|
|
1783
|
-
callback: config?.callback ?? emptyCallback
|
|
1797
|
+
callback: config?.callback ?? emptyCallback,
|
|
1798
|
+
receiverIfMakerIsSeller: config?.receiverIfMakerIsSeller ?? maker
|
|
1784
1799
|
});
|
|
1785
1800
|
}
|
|
1786
1801
|
const weightedChoice = (pairs) => {
|
|
@@ -1866,6 +1881,10 @@ const types = {
|
|
|
1866
1881
|
{
|
|
1867
1882
|
name: "callback",
|
|
1868
1883
|
type: "Callback"
|
|
1884
|
+
},
|
|
1885
|
+
{
|
|
1886
|
+
name: "receiverIfMakerIsSeller",
|
|
1887
|
+
type: "address"
|
|
1869
1888
|
}
|
|
1870
1889
|
],
|
|
1871
1890
|
Collateral: [
|
|
@@ -1911,7 +1930,8 @@ function hash(offer) {
|
|
|
1911
1930
|
callback: {
|
|
1912
1931
|
address: offer.callback.address.toLowerCase(),
|
|
1913
1932
|
data: offer.callback.data
|
|
1914
|
-
}
|
|
1933
|
+
},
|
|
1934
|
+
receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller.toLowerCase()
|
|
1915
1935
|
},
|
|
1916
1936
|
primaryType: "Offer",
|
|
1917
1937
|
types
|
|
@@ -2014,6 +2034,10 @@ const OfferAbi = [
|
|
|
2014
2034
|
name: "data",
|
|
2015
2035
|
type: "bytes"
|
|
2016
2036
|
}]
|
|
2037
|
+
},
|
|
2038
|
+
{
|
|
2039
|
+
name: "receiverIfMakerIsSeller",
|
|
2040
|
+
type: "address"
|
|
2017
2041
|
}
|
|
2018
2042
|
];
|
|
2019
2043
|
function encode$1(offer) {
|
|
@@ -2032,7 +2056,8 @@ function encode$1(offer) {
|
|
|
2032
2056
|
offer.loanToken,
|
|
2033
2057
|
BigInt(offer.start),
|
|
2034
2058
|
offer.collaterals,
|
|
2035
|
-
offer.callback
|
|
2059
|
+
offer.callback,
|
|
2060
|
+
offer.receiverIfMakerIsSeller
|
|
2036
2061
|
]);
|
|
2037
2062
|
}
|
|
2038
2063
|
function decode$1(data) {
|
|
@@ -2066,7 +2091,8 @@ function decode$1(data) {
|
|
|
2066
2091
|
callback: {
|
|
2067
2092
|
address: decoded[14].address,
|
|
2068
2093
|
data: decoded[14].data
|
|
2069
|
-
}
|
|
2094
|
+
},
|
|
2095
|
+
receiverIfMakerIsSeller: decoded[15]
|
|
2070
2096
|
});
|
|
2071
2097
|
}
|
|
2072
2098
|
/**
|
|
@@ -2142,6 +2168,12 @@ const takeEvent = {
|
|
|
2142
2168
|
indexed: false,
|
|
2143
2169
|
internalType: "bool"
|
|
2144
2170
|
},
|
|
2171
|
+
{
|
|
2172
|
+
name: "sellerReceiver",
|
|
2173
|
+
type: "address",
|
|
2174
|
+
indexed: false,
|
|
2175
|
+
internalType: "address"
|
|
2176
|
+
},
|
|
2145
2177
|
{
|
|
2146
2178
|
name: "group",
|
|
2147
2179
|
type: "bytes32",
|
|
@@ -2331,16 +2363,16 @@ function from$7(parameters) {
|
|
|
2331
2363
|
//#region src/core/Quote.ts
|
|
2332
2364
|
var Quote_exports = /* @__PURE__ */ __exportAll({
|
|
2333
2365
|
InvalidQuoteError: () => InvalidQuoteError,
|
|
2334
|
-
QuoteSchema: () => QuoteSchema,
|
|
2335
2366
|
from: () => from$6,
|
|
2336
2367
|
fromSnakeCase: () => fromSnakeCase,
|
|
2337
2368
|
random: () => random
|
|
2338
2369
|
});
|
|
2339
|
-
const
|
|
2370
|
+
const SideInputSchema = zod.object({ tick: zod.number().int().min(0).max(TICK_RANGE).nullable() }).strict();
|
|
2371
|
+
const QuoteInputSchema = zod.object({
|
|
2340
2372
|
obligationId: zod.string().transform(transformHex),
|
|
2341
|
-
ask:
|
|
2342
|
-
bid:
|
|
2343
|
-
});
|
|
2373
|
+
ask: SideInputSchema,
|
|
2374
|
+
bid: SideInputSchema
|
|
2375
|
+
}).strict();
|
|
2344
2376
|
/**
|
|
2345
2377
|
* Creates a quote for a given obligation.
|
|
2346
2378
|
* @constructor
|
|
@@ -2350,16 +2382,16 @@ const QuoteSchema = zod.object({
|
|
|
2350
2382
|
*
|
|
2351
2383
|
* @example
|
|
2352
2384
|
* ```ts
|
|
2353
|
-
* const quote = Quote.from({ obligationId: "0x123", ask: {
|
|
2385
|
+
* const quote = Quote.from({ obligationId: "0x123", ask: { tick: 500 }, bid: { tick: 510 } });
|
|
2354
2386
|
* ```
|
|
2355
2387
|
*/
|
|
2356
2388
|
function from$6(parameters) {
|
|
2357
2389
|
try {
|
|
2358
|
-
const parsedQuote =
|
|
2390
|
+
const parsedQuote = QuoteInputSchema.parse(parameters);
|
|
2359
2391
|
return {
|
|
2360
2392
|
obligationId: parsedQuote.obligationId,
|
|
2361
|
-
ask: parsedQuote.ask,
|
|
2362
|
-
bid: parsedQuote.bid
|
|
2393
|
+
ask: sideFromTick(parsedQuote.ask),
|
|
2394
|
+
bid: sideFromTick(parsedQuote.bid)
|
|
2363
2395
|
};
|
|
2364
2396
|
} catch (error) {
|
|
2365
2397
|
throw new InvalidQuoteError(error);
|
|
@@ -2386,8 +2418,8 @@ function fromSnakeCase(snake) {
|
|
|
2386
2418
|
function random() {
|
|
2387
2419
|
return from$6({
|
|
2388
2420
|
obligationId: id(random$2()),
|
|
2389
|
-
ask: {
|
|
2390
|
-
bid: {
|
|
2421
|
+
ask: { tick: int(TICK_RANGE + 1) },
|
|
2422
|
+
bid: { tick: int(TICK_RANGE + 1) }
|
|
2391
2423
|
});
|
|
2392
2424
|
}
|
|
2393
2425
|
var InvalidQuoteError = class extends BaseError {
|
|
@@ -2396,6 +2428,12 @@ var InvalidQuoteError = class extends BaseError {
|
|
|
2396
2428
|
_defineProperty(this, "name", "Quote.InvalidQuoteError");
|
|
2397
2429
|
}
|
|
2398
2430
|
};
|
|
2431
|
+
function sideFromTick(side) {
|
|
2432
|
+
return {
|
|
2433
|
+
tick: side.tick,
|
|
2434
|
+
price: side.tick === null ? 0n : tickToPrice(side.tick)
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2399
2437
|
|
|
2400
2438
|
//#endregion
|
|
2401
2439
|
//#region src/core/TradingFee.ts
|
|
@@ -2952,7 +2990,8 @@ function from$2(input) {
|
|
|
2952
2990
|
group: input.group,
|
|
2953
2991
|
session: input.session,
|
|
2954
2992
|
callback: input.callback.address,
|
|
2955
|
-
callback_data: input.callback.data
|
|
2993
|
+
callback_data: input.callback.data,
|
|
2994
|
+
receiver_if_maker_is_seller: input.receiverIfMakerIsSeller
|
|
2956
2995
|
},
|
|
2957
2996
|
offer_hash: input.hash,
|
|
2958
2997
|
obligation_id: id({
|
|
@@ -3002,7 +3041,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
3002
3041
|
//#region src/api/Schema/openapi.ts
|
|
3003
3042
|
const timestampExample = "2024-01-01T12:00:00.000Z";
|
|
3004
3043
|
const offerCursorExample = "eyJvZmZzZXQiOjEwMH0";
|
|
3005
|
-
const obligationCursorExample = "
|
|
3044
|
+
const obligationCursorExample = "eyJzb3J0IjpbImlkIl0sImlkIjoiMHgxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiLCJhc2siOiIwIiwiYmlkIjoiMCIsIm1hdHVyaXR5IjoxNzYxOTIyODAwfQ";
|
|
3006
3045
|
const offerExample = {
|
|
3007
3046
|
offer: {
|
|
3008
3047
|
obligation: {
|
|
@@ -3025,7 +3064,8 @@ const offerExample = {
|
|
|
3025
3064
|
group: "0x000000000000000000000000000000000000000000000000000000000008b8f4",
|
|
3026
3065
|
session: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
3027
3066
|
callback: "0x0000000000000000000000000000000000000000",
|
|
3028
|
-
callback_data: "0x"
|
|
3067
|
+
callback_data: "0x",
|
|
3068
|
+
receiver_if_maker_is_seller: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"
|
|
3029
3069
|
},
|
|
3030
3070
|
offer_hash: "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
|
|
3031
3071
|
obligation_id: "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc",
|
|
@@ -3079,7 +3119,8 @@ const validateOfferExample = {
|
|
|
3079
3119
|
callback: {
|
|
3080
3120
|
address: "0x0000000000000000000000000000000000000000",
|
|
3081
3121
|
data: "0x"
|
|
3082
|
-
}
|
|
3122
|
+
},
|
|
3123
|
+
receiver_if_maker_is_seller: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"
|
|
3083
3124
|
};
|
|
3084
3125
|
const routerStatusExample = {
|
|
3085
3126
|
status: "live",
|
|
@@ -3150,11 +3191,23 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3150
3191
|
example: validateOfferExample.callback.data
|
|
3151
3192
|
})], ValidateCallbackRequest.prototype, "data", void 0);
|
|
3152
3193
|
var AskResponse = class {};
|
|
3194
|
+
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3195
|
+
type: "number",
|
|
3196
|
+
nullable: true,
|
|
3197
|
+
example: 500,
|
|
3198
|
+
description: "Best ask tick. Null when there is no active ask quote."
|
|
3199
|
+
})], AskResponse.prototype, "tick", void 0);
|
|
3153
3200
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3154
3201
|
type: "string",
|
|
3155
3202
|
example: "1000000000000000000"
|
|
3156
3203
|
})], AskResponse.prototype, "price", void 0);
|
|
3157
3204
|
var BidResponse = class {};
|
|
3205
|
+
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3206
|
+
type: "number",
|
|
3207
|
+
nullable: true,
|
|
3208
|
+
example: 500,
|
|
3209
|
+
description: "Best bid tick. Null when there is no active bid quote."
|
|
3210
|
+
})], BidResponse.prototype, "tick", void 0);
|
|
3158
3211
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3159
3212
|
type: "string",
|
|
3160
3213
|
example: "1000000000000000000"
|
|
@@ -3227,6 +3280,10 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3227
3280
|
type: "string",
|
|
3228
3281
|
example: offerExample.offer.callback_data
|
|
3229
3282
|
})], OfferDataResponse.prototype, "callback_data", void 0);
|
|
3283
|
+
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3284
|
+
type: "string",
|
|
3285
|
+
example: offerExample.offer.receiver_if_maker_is_seller
|
|
3286
|
+
})], OfferDataResponse.prototype, "receiver_if_maker_is_seller", void 0);
|
|
3230
3287
|
var OfferListItemResponse = class {};
|
|
3231
3288
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3232
3289
|
type: () => OfferDataResponse,
|
|
@@ -3496,6 +3553,10 @@ __decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
|
3496
3553
|
type: () => ValidateCallbackRequest,
|
|
3497
3554
|
example: validateOfferExample.callback
|
|
3498
3555
|
})], ValidateOfferRequest.prototype, "callback", void 0);
|
|
3556
|
+
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3557
|
+
type: "string",
|
|
3558
|
+
example: validateOfferExample.receiver_if_maker_is_seller
|
|
3559
|
+
})], ValidateOfferRequest.prototype, "receiver_if_maker_is_seller", void 0);
|
|
3499
3560
|
var ValidateOffersRequest = class {};
|
|
3500
3561
|
__decorate([(0, openapi_metadata_decorators.ApiProperty)({
|
|
3501
3562
|
type: () => [ValidateOfferRequest],
|
|
@@ -4048,13 +4109,13 @@ __decorate([
|
|
|
4048
4109
|
methods: ["get"],
|
|
4049
4110
|
path: "/v1/obligations",
|
|
4050
4111
|
summary: "List all obligations",
|
|
4051
|
-
description: "Returns a list of obligations with their current best ask and bid.
|
|
4112
|
+
description: "Returns a list of obligations with their current best ask and bid. Sorting is customizable with the sort parameter and defaults to id ascending."
|
|
4052
4113
|
}),
|
|
4053
4114
|
(0, openapi_metadata_decorators.ApiQuery)({
|
|
4054
4115
|
name: "cursor",
|
|
4055
4116
|
type: "string",
|
|
4056
4117
|
example: obligationCursorExample,
|
|
4057
|
-
description: "
|
|
4118
|
+
description: "Pagination cursor in base64url-encoded format."
|
|
4058
4119
|
}),
|
|
4059
4120
|
(0, openapi_metadata_decorators.ApiQuery)({
|
|
4060
4121
|
name: "limit",
|
|
@@ -4098,6 +4159,15 @@ __decorate([
|
|
|
4098
4159
|
style: "form",
|
|
4099
4160
|
explode: false
|
|
4100
4161
|
}),
|
|
4162
|
+
(0, openapi_metadata_decorators.ApiQuery)({
|
|
4163
|
+
name: "sort",
|
|
4164
|
+
type: "string",
|
|
4165
|
+
required: false,
|
|
4166
|
+
example: "-ask,bid,maturity",
|
|
4167
|
+
description: "Sort order as comma-separated fields (`id`, `ask`, `bid`, `maturity`). Prefix with `-` for descending order. Max 3 fields.",
|
|
4168
|
+
style: "form",
|
|
4169
|
+
explode: false
|
|
4170
|
+
}),
|
|
4101
4171
|
(0, openapi_metadata_decorators.ApiResponse)({
|
|
4102
4172
|
status: 200,
|
|
4103
4173
|
description: "Success",
|
|
@@ -4234,10 +4304,12 @@ function from$1(position) {
|
|
|
4234
4304
|
//#region src/api/Schema/requests.ts
|
|
4235
4305
|
const MAX_LIMIT = 100;
|
|
4236
4306
|
const DEFAULT_LIMIT = 20;
|
|
4307
|
+
const MAX_OBLIGATION_SORT_FIELDS = 3;
|
|
4237
4308
|
const CONFIG_RULES_MAX_LIMIT = 1e3;
|
|
4238
4309
|
const CONFIG_RULES_DEFAULT_LIMIT = 100;
|
|
4239
4310
|
const CONFIG_CONTRACTS_MAX_LIMIT = 1e3;
|
|
4240
4311
|
const CONFIG_CONTRACTS_DEFAULT_LIMIT = 1e3;
|
|
4312
|
+
const OBLIGATION_SORT_ENTRY_REGEX = /^-?(id|ask|bid|maturity)$/;
|
|
4241
4313
|
/** Validate cursor is a valid base64url-encoded JSON object.
|
|
4242
4314
|
* Domain layer handles semantic validation of cursor fields. */
|
|
4243
4315
|
function isValidBase64urlJson(val) {
|
|
@@ -4367,9 +4439,12 @@ const GetOffersQueryParams = PaginationQueryParams.omit({ cursor: true }).extend
|
|
|
4367
4439
|
});
|
|
4368
4440
|
const GetObligationsQueryParams = zod.object({
|
|
4369
4441
|
...PaginationQueryParams.shape,
|
|
4370
|
-
cursor: zod.string().optional().
|
|
4371
|
-
|
|
4372
|
-
|
|
4442
|
+
cursor: zod.string().optional().refine((val) => {
|
|
4443
|
+
if (!val) return true;
|
|
4444
|
+
return isValidBase64urlJson(val);
|
|
4445
|
+
}, { message: "Invalid cursor format. Must be a valid base64url-encoded cursor object" }).meta({
|
|
4446
|
+
description: "Pagination cursor in base64url-encoded format.",
|
|
4447
|
+
example: "eyJzb3J0IjpbImlkIl0sImlkIjoiMHgxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiLCJhc2siOiIwIiwiYmlkIjoiMCIsIm1hdHVyaXR5IjoxNzYxOTIyODAwfQ"
|
|
4373
4448
|
}),
|
|
4374
4449
|
chains: csvArray(zod.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
|
|
4375
4450
|
description: "Filter by chain IDs (comma-separated).",
|
|
@@ -4386,6 +4461,24 @@ const GetObligationsQueryParams = zod.object({
|
|
|
4386
4461
|
maturities: csvArray(zod.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
|
|
4387
4462
|
description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
|
|
4388
4463
|
example: "1761922800,1764524800"
|
|
4464
|
+
}),
|
|
4465
|
+
sort: csvArray(zod.string().regex(OBLIGATION_SORT_ENTRY_REGEX, { message: "Sort entries must be one of: id, ask, bid, maturity (optionally prefixed with '-')" })).refine((entries) => entries === void 0 || entries.length <= MAX_OBLIGATION_SORT_FIELDS, { message: `Sort cannot include more than ${MAX_OBLIGATION_SORT_FIELDS} fields` }).superRefine((entries, ctx) => {
|
|
4466
|
+
if (!entries) return;
|
|
4467
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4468
|
+
for (const entry of entries) {
|
|
4469
|
+
const field = entry.startsWith("-") ? entry.slice(1) : entry;
|
|
4470
|
+
if (seen.has(field)) {
|
|
4471
|
+
ctx.addIssue({
|
|
4472
|
+
code: "custom",
|
|
4473
|
+
message: `Duplicate sort field: ${field}`
|
|
4474
|
+
});
|
|
4475
|
+
return;
|
|
4476
|
+
}
|
|
4477
|
+
seen.add(field);
|
|
4478
|
+
}
|
|
4479
|
+
}).meta({
|
|
4480
|
+
description: "Sort order as comma-separated fields. Prefix a field with '-' for descending order. Max 3 fields.",
|
|
4481
|
+
example: "-ask,bid,maturity"
|
|
4389
4482
|
})
|
|
4390
4483
|
});
|
|
4391
4484
|
const GetObligationParams = zod.object({ obligation_id: zod.string({ error: "Obligation id is required and must be a valid 32-byte hex string" }).regex(/^0x[a-fA-F0-9]{64}$/, { error: "Obligation id must be a valid 32-byte hex string" }).transform((val) => val.toLowerCase()).meta({
|
|
@@ -4574,7 +4667,8 @@ async function getOffers(apiClient, parameters) {
|
|
|
4574
4667
|
callback: {
|
|
4575
4668
|
address: offerData.callback,
|
|
4576
4669
|
data: offerData.callback_data
|
|
4577
|
-
}
|
|
4670
|
+
},
|
|
4671
|
+
receiver_if_maker_is_seller: offerData.receiver_if_maker_is_seller
|
|
4578
4672
|
}),
|
|
4579
4673
|
hash: item.offer_hash,
|
|
4580
4674
|
consumed: BigInt(item.consumed),
|
|
@@ -4591,13 +4685,15 @@ async function getOffers(apiClient, parameters) {
|
|
|
4591
4685
|
};
|
|
4592
4686
|
}
|
|
4593
4687
|
async function getObligations(apiClient, parameters) {
|
|
4688
|
+
const sort = parameters?.sort?.length ? parameters.sort.join(",") : void 0;
|
|
4594
4689
|
const { data, error, response } = await apiClient.GET("/v1/obligations", { params: { query: {
|
|
4595
4690
|
cursor: parameters?.cursor,
|
|
4596
4691
|
limit: parameters?.limit,
|
|
4597
4692
|
chains: parameters?.chainIds,
|
|
4598
4693
|
loan_tokens: parameters?.loanTokens,
|
|
4599
4694
|
collateral_tokens: parameters?.collateralTokens,
|
|
4600
|
-
maturities: parameters?.maturities
|
|
4695
|
+
maturities: parameters?.maturities,
|
|
4696
|
+
sort
|
|
4601
4697
|
} } });
|
|
4602
4698
|
if (error !== void 0) {
|
|
4603
4699
|
switch (response.status) {
|
|
@@ -4621,10 +4717,10 @@ async function getObligations(apiClient, parameters) {
|
|
|
4621
4717
|
const { obligationId: _, ...returned } = {
|
|
4622
4718
|
id: () => id(obligation),
|
|
4623
4719
|
...obligation,
|
|
4624
|
-
...
|
|
4625
|
-
|
|
4626
|
-
ask: item.ask,
|
|
4627
|
-
bid: item.bid
|
|
4720
|
+
...from$6({
|
|
4721
|
+
obligationId: item.id,
|
|
4722
|
+
ask: { tick: item.ask.tick },
|
|
4723
|
+
bid: { tick: item.bid.tick }
|
|
4628
4724
|
})
|
|
4629
4725
|
};
|
|
4630
4726
|
return returned;
|
|
@@ -4972,19 +5068,19 @@ const oracles = {
|
|
|
4972
5068
|
const configs = {
|
|
4973
5069
|
ethereum: {
|
|
4974
5070
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4975
|
-
maturities: [MaturityType.
|
|
5071
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4976
5072
|
},
|
|
4977
5073
|
base: {
|
|
4978
5074
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4979
|
-
maturities: [MaturityType.
|
|
5075
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4980
5076
|
},
|
|
4981
5077
|
"ethereum-virtual-testnet": {
|
|
4982
5078
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4983
|
-
maturities: [MaturityType.
|
|
5079
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4984
5080
|
},
|
|
4985
5081
|
anvil: {
|
|
4986
5082
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4987
|
-
maturities: [MaturityType.
|
|
5083
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4988
5084
|
}
|
|
4989
5085
|
};
|
|
4990
5086
|
|
|
@@ -5018,7 +5114,7 @@ const chains = ({ chains }) => single("chain_ids", `Validates that offer chain i
|
|
|
5018
5114
|
});
|
|
5019
5115
|
const maturity = ({ maturities }) => single("maturity", `Validates that offer maturity is one of: [${maturities.join(", ")}]`, (offer) => {
|
|
5020
5116
|
const allowedMaturities = maturities.map((m) => from$11(m));
|
|
5021
|
-
if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be
|
|
5117
|
+
if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be one of (${allowedMaturities.join(", ")}). Got: ${offer.maturity}` };
|
|
5022
5118
|
});
|
|
5023
5119
|
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) => {
|
|
5024
5120
|
if (!isEmptyCallback(offer)) return { message: "Non-empty callbacks are not supported." };
|
|
@@ -5098,7 +5194,7 @@ const morphoRules = (chains$2) => {
|
|
|
5098
5194
|
sameMaker(),
|
|
5099
5195
|
amountMutualExclusivity(),
|
|
5100
5196
|
chains({ chains: chains$2 }),
|
|
5101
|
-
maturity({ maturities: [MaturityType.
|
|
5197
|
+
maturity({ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek] }),
|
|
5102
5198
|
callback({
|
|
5103
5199
|
callbacks: [Type$1.BuyWithEmptyCallback, Type$1.SellWithEmptyCallback],
|
|
5104
5200
|
allowedAddresses: []
|