@morpho-dev/router 0.7.2 → 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 +834 -334
- package/dist/drizzle/migrations/0000_setup_single_migration_folder.sql +64 -64
- package/dist/drizzle/migrations/0001_add-trigger-for-consumed-events.sql +5 -5
- package/dist/drizzle/migrations/0002_insert-status-code.sql +1 -1
- package/dist/drizzle/migrations/0003_update-triggers-for-consumed-events.sql +1 -1
- package/dist/drizzle/migrations/0004_drop-status-offers-foreign-key-constraint.sql +1 -1
- package/dist/drizzle/migrations/0005_add-index-to-boost-group-query-and-offer-hash.sql +1 -1
- package/dist/drizzle/migrations/0006_add-callbacks-and-positions-relations.sql +11 -11
- package/dist/drizzle/migrations/0008_validation.sql +10 -10
- package/dist/drizzle/migrations/0009_add-transfers-table.sql +4 -4
- package/dist/drizzle/migrations/0010_add-price.sql +1 -1
- package/dist/drizzle/migrations/0011_nullable-callback-amount.sql +1 -1
- package/dist/drizzle/migrations/0012_add-position-asset.sql +1 -1
- package/dist/drizzle/migrations/0013_remove-depecrated-domains.sql +13 -13
- package/dist/drizzle/migrations/0014_rename-offers-v2-into-offers.sql +19 -19
- package/dist/drizzle/migrations/0015_add-lots-table.sql +3 -3
- package/dist/drizzle/migrations/0016_merkle-metadata.sql +7 -7
- package/dist/drizzle/migrations/0017_dusty_the_hunter.sql +1 -1
- package/dist/drizzle/migrations/0018_add_chain_collector_constraints.sql +3 -3
- package/dist/drizzle/migrations/0019_add-obligation-units-shares.sql +2 -2
- package/dist/drizzle/migrations/0020_add-session.sql +1 -1
- package/dist/drizzle/migrations/0021_drop_chain_collector_epoch_indexes.sql +2 -2
- package/dist/drizzle/migrations/0021_migrate-rate-to-price.sql +6 -6
- package/dist/drizzle/migrations/0022_consolidate-price.sql +5 -5
- package/dist/drizzle/migrations/0023_remove-block-number-for-collaterals.sql +1 -1
- package/dist/drizzle/migrations/0024_add-obligation-id-to-lots.sql +8 -0
- package/dist/drizzle/migrations/0025_rename-price-to-tick.sql +202 -0
- package/dist/drizzle/migrations/0026_add-receiver-if-maker-is-seller.sql +1 -0
- package/dist/drizzle/migrations/meta/0000_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0001_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0002_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0003_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0004_snapshot.json +47 -47
- package/dist/drizzle/migrations/meta/0005_snapshot.json +47 -47
- package/dist/drizzle/migrations/meta/0006_snapshot.json +61 -61
- package/dist/drizzle/migrations/meta/0008_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0009_snapshot.json +66 -66
- package/dist/drizzle/migrations/meta/0010_snapshot.json +66 -66
- package/dist/drizzle/migrations/meta/0013_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0014_snapshot.json +48 -48
- package/dist/drizzle/migrations/meta/0015_snapshot.json +52 -52
- package/dist/drizzle/migrations/meta/0016_snapshot.json +61 -61
- package/dist/drizzle/migrations/meta/0017_snapshot.json +61 -61
- package/dist/drizzle/migrations/meta/0018_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0019_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0023_snapshot.json +62 -62
- package/dist/drizzle/migrations/meta/0024_snapshot.json +1448 -0
- package/dist/drizzle/migrations/meta/0025_snapshot.json +1448 -0
- package/dist/drizzle/migrations/meta/0026_snapshot.json +1454 -0
- package/dist/drizzle/migrations/meta/_journal.json +21 -0
- package/dist/evm/bytecode/morpho.txt +1 -1
- package/dist/index.browser.d.mts +206 -77
- package/dist/index.browser.d.mts.map +1 -1
- package/dist/index.browser.d.ts +206 -77
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +445 -197
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +440 -198
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.mts +347 -119
- package/dist/index.node.d.mts.map +1 -1
- package/dist/index.node.d.ts +347 -119
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +865 -312
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +861 -314
- package/dist/index.node.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -11,11 +11,191 @@ import { generateDocument } from "openapi-metadata";
|
|
|
11
11
|
import { ApiBody, ApiOperation, ApiParam, ApiProperty, ApiQuery, ApiResponse, ApiTags } from "openapi-metadata/decorators";
|
|
12
12
|
import createOpenApiFetchClient from "openapi-fetch";
|
|
13
13
|
|
|
14
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/typeof.js
|
|
15
|
+
function _typeof(o) {
|
|
16
|
+
"@babel/helpers - typeof";
|
|
17
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
18
|
+
return typeof o;
|
|
19
|
+
} : function(o) {
|
|
20
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
21
|
+
}, _typeof(o);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/toPrimitive.js
|
|
26
|
+
function toPrimitive(t, r) {
|
|
27
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
28
|
+
var e = t[Symbol.toPrimitive];
|
|
29
|
+
if (void 0 !== e) {
|
|
30
|
+
var i = e.call(t, r || "default");
|
|
31
|
+
if ("object" != _typeof(i)) return i;
|
|
32
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
33
|
+
}
|
|
34
|
+
return ("string" === r ? String : Number)(t);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/toPropertyKey.js
|
|
39
|
+
function toPropertyKey(t) {
|
|
40
|
+
var i = toPrimitive(t, "string");
|
|
41
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/defineProperty.js
|
|
46
|
+
function _defineProperty(e, r, t) {
|
|
47
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
48
|
+
value: t,
|
|
49
|
+
enumerable: !0,
|
|
50
|
+
configurable: !0,
|
|
51
|
+
writable: !0
|
|
52
|
+
}) : e[r] = t, e;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/utils/Errors.ts
|
|
57
|
+
var Errors_exports = /* @__PURE__ */ __exportAll({
|
|
58
|
+
BaseError: () => BaseError,
|
|
59
|
+
ReorgError: () => ReorgError
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Base error class inherited by all errors thrown by mempool.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { Errors } from 'mempool'
|
|
67
|
+
* throw new Errors.BaseError('An error occurred')
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
var BaseError = class BaseError extends Error {
|
|
71
|
+
constructor(shortMessage, options = {}) {
|
|
72
|
+
const details = (() => {
|
|
73
|
+
if (options.cause instanceof BaseError) {
|
|
74
|
+
if (options.cause.details) return options.cause.details;
|
|
75
|
+
if (options.cause.shortMessage) return options.cause.shortMessage;
|
|
76
|
+
}
|
|
77
|
+
if (options.cause && "details" in options.cause && typeof options.cause.details === "string") return options.cause.details;
|
|
78
|
+
if (options.cause?.message) return options.cause.message;
|
|
79
|
+
return options.details;
|
|
80
|
+
})();
|
|
81
|
+
const message = [
|
|
82
|
+
shortMessage || "An error occurred.",
|
|
83
|
+
...options.metaMessages ? ["", ...options.metaMessages] : [],
|
|
84
|
+
...details ? ["", details ? `Details: ${details}` : void 0] : []
|
|
85
|
+
].filter((x) => typeof x === "string").join("\n");
|
|
86
|
+
super(message, options.cause ? { cause: options.cause } : void 0);
|
|
87
|
+
_defineProperty(this, "details", void 0);
|
|
88
|
+
_defineProperty(this, "shortMessage", void 0);
|
|
89
|
+
_defineProperty(this, "cause", void 0);
|
|
90
|
+
_defineProperty(this, "name", "BaseError");
|
|
91
|
+
this.cause = options.cause;
|
|
92
|
+
this.details = details;
|
|
93
|
+
this.shortMessage = shortMessage;
|
|
94
|
+
}
|
|
95
|
+
walk(fn) {
|
|
96
|
+
return walk(this, fn);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/** @internal */
|
|
100
|
+
function walk(err, fn) {
|
|
101
|
+
if (fn?.(err)) return err;
|
|
102
|
+
if (err && typeof err === "object" && "cause" in err && err.cause) return walk(err.cause, fn);
|
|
103
|
+
return fn ? null : err;
|
|
104
|
+
}
|
|
105
|
+
var ReorgError = class extends BaseError {
|
|
106
|
+
constructor(blockNumber) {
|
|
107
|
+
super(`Reorg detected at block number ${blockNumber}`);
|
|
108
|
+
_defineProperty(this, "name", "ReorgError");
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/core/Tick.ts
|
|
114
|
+
var Tick_exports = /* @__PURE__ */ __exportAll({
|
|
115
|
+
InvalidPriceError: () => InvalidPriceError,
|
|
116
|
+
InvalidTickError: () => InvalidTickError,
|
|
117
|
+
MAX_PRICE: () => MAX_PRICE,
|
|
118
|
+
TICK_RANGE: () => TICK_RANGE,
|
|
119
|
+
priceToTick: () => priceToTick,
|
|
120
|
+
tickToPrice: () => tickToPrice
|
|
121
|
+
});
|
|
122
|
+
/** ln(1 + 0.025), scaled by 1e18. Matches TickLib onchain constant. */
|
|
123
|
+
const LN_ONE_PLUS_DELTA = 24692612590371501n;
|
|
124
|
+
/** ln(2), scaled by 1e18. Matches TickLib onchain constant. */
|
|
125
|
+
const LN2 = 693147180559945309n;
|
|
126
|
+
const WAD$1 = 10n ** 18n;
|
|
127
|
+
const WAD_SQUARED = 10n ** 36n;
|
|
128
|
+
const PRICE_STEP = 10n ** 13n;
|
|
129
|
+
const HALF_TICK_RANGE = 495n;
|
|
130
|
+
/** Tick domain supported by Morpho V2. */
|
|
131
|
+
const TICK_RANGE = 990;
|
|
132
|
+
/** Max allowed price (1e18 in wad). */
|
|
133
|
+
const MAX_PRICE = WAD$1;
|
|
134
|
+
/**
|
|
135
|
+
* Converts a tick to a wad price using the same approximation and rounding as TickLib.
|
|
136
|
+
* @param tick - Tick value in the inclusive range [0, 990].
|
|
137
|
+
* @returns The price in wad units.
|
|
138
|
+
* @throws {@link InvalidTickError} If tick is not an integer in range [0, 990].
|
|
139
|
+
*/
|
|
140
|
+
function tickToPrice(tick) {
|
|
141
|
+
assertTick(tick);
|
|
142
|
+
return divHalfDownUnchecked(divHalfDownUnchecked(WAD_SQUARED, WAD$1 + wExp(LN_ONE_PLUS_DELTA * (HALF_TICK_RANGE - BigInt(tick)))), PRICE_STEP) * PRICE_STEP;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the lowest tick with a higher-or-equal price.
|
|
146
|
+
* @param price - Price in wad units.
|
|
147
|
+
* @returns The first tick whose {@link tickToPrice} is greater than or equal to `price`.
|
|
148
|
+
* @throws {@link InvalidPriceError} If price is outside [0, 1e18].
|
|
149
|
+
*/
|
|
150
|
+
function priceToTick(price) {
|
|
151
|
+
assertPrice(price);
|
|
152
|
+
let low = 0;
|
|
153
|
+
let high = TICK_RANGE;
|
|
154
|
+
while (low !== high) {
|
|
155
|
+
const mid = Math.floor((low + high) / 2);
|
|
156
|
+
if (tickToPrice(mid) < price) low = mid + 1;
|
|
157
|
+
else high = mid;
|
|
158
|
+
}
|
|
159
|
+
return low;
|
|
160
|
+
}
|
|
161
|
+
function divHalfDownUnchecked(x, d) {
|
|
162
|
+
return (x + (d - 1n) / 2n) / d;
|
|
163
|
+
}
|
|
164
|
+
function wExp(x) {
|
|
165
|
+
if (x < 0n) return WAD_SQUARED / wExp(-x);
|
|
166
|
+
const q = (x + LN2 / 2n) / LN2;
|
|
167
|
+
const r = x - q * LN2;
|
|
168
|
+
const secondTerm = r * r / (2n * WAD$1);
|
|
169
|
+
const thirdTerm = secondTerm * r / (3n * WAD$1);
|
|
170
|
+
return WAD$1 + r + secondTerm + thirdTerm << q;
|
|
171
|
+
}
|
|
172
|
+
function assertTick(tick) {
|
|
173
|
+
if (!Number.isInteger(tick) || tick < 0 || tick > TICK_RANGE) throw new InvalidTickError(tick);
|
|
174
|
+
}
|
|
175
|
+
function assertPrice(price) {
|
|
176
|
+
if (price < 0n || price > MAX_PRICE) throw new InvalidPriceError(price);
|
|
177
|
+
}
|
|
178
|
+
var InvalidTickError = class extends BaseError {
|
|
179
|
+
constructor(tick) {
|
|
180
|
+
super(`Invalid tick: ${tick}. Tick must be an integer between 0 and ${TICK_RANGE}.`);
|
|
181
|
+
_defineProperty(this, "name", "Tick.InvalidTickError");
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var InvalidPriceError = class extends BaseError {
|
|
185
|
+
constructor(price) {
|
|
186
|
+
super(`Invalid price: ${price}. Price must be between 0 and ${MAX_PRICE}.`);
|
|
187
|
+
_defineProperty(this, "name", "Tick.InvalidPriceError");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
14
192
|
//#region src/api/Schema/BookResponse.ts
|
|
15
193
|
var BookResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$15 });
|
|
16
194
|
function from$15(level) {
|
|
195
|
+
const price = tickToPrice(level.tick);
|
|
17
196
|
return {
|
|
18
|
-
|
|
197
|
+
tick: level.tick,
|
|
198
|
+
price: price.toString(),
|
|
19
199
|
assets: level.assets.toString(),
|
|
20
200
|
count: level.count
|
|
21
201
|
};
|
|
@@ -62,6 +242,7 @@ var ObligationResponse_exports = /* @__PURE__ */ __exportAll({ from: () => from$
|
|
|
62
242
|
* Creates an `ObligationResponse` from a `Obligation`.
|
|
63
243
|
* @constructor
|
|
64
244
|
* @param obligation - {@link Obligation}
|
|
245
|
+
* @param quote - {@link Quote}
|
|
65
246
|
* @returns The created `ObligationResponse`. {@link ObligationResponse}
|
|
66
247
|
*/
|
|
67
248
|
function from$14(obligation, quote) {
|
|
@@ -75,8 +256,14 @@ function from$14(obligation, quote) {
|
|
|
75
256
|
oracle: c.oracle
|
|
76
257
|
})),
|
|
77
258
|
maturity: obligation.maturity,
|
|
78
|
-
ask: {
|
|
79
|
-
|
|
259
|
+
ask: {
|
|
260
|
+
tick: quote.ask.tick,
|
|
261
|
+
price: quote.ask.price.toString()
|
|
262
|
+
},
|
|
263
|
+
bid: {
|
|
264
|
+
tick: quote.bid.tick,
|
|
265
|
+
price: quote.bid.price.toString()
|
|
266
|
+
}
|
|
80
267
|
};
|
|
81
268
|
}
|
|
82
269
|
|
|
@@ -122,18 +309,18 @@ const MorphoV2 = parseAbi([
|
|
|
122
309
|
"function setFeeSetter(address newFeeSetter)",
|
|
123
310
|
"function setObligationTradingFee(bytes32 id, uint256 index, uint256 newTradingFee)",
|
|
124
311
|
"function setOwner(address newOwner)",
|
|
125
|
-
"function setTradingFeeRecipient(address
|
|
312
|
+
"function setTradingFeeRecipient(address feeRecipient)",
|
|
126
313
|
"function sharesOf(bytes32 id, address user) view returns (uint256)",
|
|
127
314
|
"function shuffleSession()",
|
|
128
315
|
"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
|
|
316
|
+
"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)",
|
|
130
317
|
"function totalShares(bytes32 id) view returns (uint256)",
|
|
131
318
|
"function totalUnits(bytes32 id) view returns (uint256)",
|
|
132
319
|
"function touchObligation((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation) returns (bytes32)",
|
|
133
320
|
"function tradingFee(bytes32 id, uint256 timeToMaturity) view returns (uint256)",
|
|
134
321
|
"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)",
|
|
322
|
+
"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)",
|
|
323
|
+
"function withdrawCollateral((address loanToken, (address token, uint256 lltv, address oracle)[] collaterals, uint256 maturity) obligation, address collateral, uint256 assets, address onBehalf, address receiver)",
|
|
137
324
|
"function withdrawable(bytes32 id) view returns (uint256)",
|
|
138
325
|
"event Constructor(address indexed owner)",
|
|
139
326
|
"event Consume(address indexed user, bytes32 indexed group, uint256 amount)",
|
|
@@ -145,12 +332,12 @@ const MorphoV2 = parseAbi([
|
|
|
145
332
|
"event SetFeeSetter(address indexed feeSetter)",
|
|
146
333
|
"event SetObligationTradingFee(bytes32 indexed id, uint256 indexed index, uint256 newTradingFee)",
|
|
147
334
|
"event SetOwner(address indexed owner)",
|
|
148
|
-
"event SetTradingFeeRecipient(address indexed
|
|
335
|
+
"event SetTradingFeeRecipient(address indexed feeRecipient)",
|
|
149
336
|
"event ShuffleSession(address indexed user, bytes32 session)",
|
|
150
337
|
"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
|
|
153
|
-
"event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf)"
|
|
338
|
+
"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)",
|
|
339
|
+
"event Withdraw(address caller, bytes32 indexed id, uint256 obligationUnits, uint256 shares, address indexed onBehalf, address indexed receiver)",
|
|
340
|
+
"event WithdrawCollateral(address caller, bytes32 indexed id, address indexed collateral, uint256 assets, address indexed onBehalf, address receiver)"
|
|
154
341
|
]);
|
|
155
342
|
|
|
156
343
|
//#endregion
|
|
@@ -363,105 +550,6 @@ function* batch$1(array, batchSize) {
|
|
|
363
550
|
for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize);
|
|
364
551
|
}
|
|
365
552
|
|
|
366
|
-
//#endregion
|
|
367
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/typeof.js
|
|
368
|
-
function _typeof(o) {
|
|
369
|
-
"@babel/helpers - typeof";
|
|
370
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
371
|
-
return typeof o;
|
|
372
|
-
} : function(o) {
|
|
373
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
374
|
-
}, _typeof(o);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
//#endregion
|
|
378
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/toPrimitive.js
|
|
379
|
-
function toPrimitive(t, r) {
|
|
380
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
381
|
-
var e = t[Symbol.toPrimitive];
|
|
382
|
-
if (void 0 !== e) {
|
|
383
|
-
var i = e.call(t, r || "default");
|
|
384
|
-
if ("object" != _typeof(i)) return i;
|
|
385
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
386
|
-
}
|
|
387
|
-
return ("string" === r ? String : Number)(t);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
//#endregion
|
|
391
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/toPropertyKey.js
|
|
392
|
-
function toPropertyKey(t) {
|
|
393
|
-
var i = toPrimitive(t, "string");
|
|
394
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
//#endregion
|
|
398
|
-
//#region \0@oxc-project+runtime@0.110.0/helpers/defineProperty.js
|
|
399
|
-
function _defineProperty(e, r, t) {
|
|
400
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
401
|
-
value: t,
|
|
402
|
-
enumerable: !0,
|
|
403
|
-
configurable: !0,
|
|
404
|
-
writable: !0
|
|
405
|
-
}) : e[r] = t, e;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
//#endregion
|
|
409
|
-
//#region src/utils/Errors.ts
|
|
410
|
-
var Errors_exports = /* @__PURE__ */ __exportAll({
|
|
411
|
-
BaseError: () => BaseError,
|
|
412
|
-
ReorgError: () => ReorgError
|
|
413
|
-
});
|
|
414
|
-
/**
|
|
415
|
-
* Base error class inherited by all errors thrown by mempool.
|
|
416
|
-
*
|
|
417
|
-
* @example
|
|
418
|
-
* ```ts
|
|
419
|
-
* import { Errors } from 'mempool'
|
|
420
|
-
* throw new Errors.BaseError('An error occurred')
|
|
421
|
-
* ```
|
|
422
|
-
*/
|
|
423
|
-
var BaseError = class BaseError extends Error {
|
|
424
|
-
constructor(shortMessage, options = {}) {
|
|
425
|
-
const details = (() => {
|
|
426
|
-
if (options.cause instanceof BaseError) {
|
|
427
|
-
if (options.cause.details) return options.cause.details;
|
|
428
|
-
if (options.cause.shortMessage) return options.cause.shortMessage;
|
|
429
|
-
}
|
|
430
|
-
if (options.cause && "details" in options.cause && typeof options.cause.details === "string") return options.cause.details;
|
|
431
|
-
if (options.cause?.message) return options.cause.message;
|
|
432
|
-
return options.details;
|
|
433
|
-
})();
|
|
434
|
-
const message = [
|
|
435
|
-
shortMessage || "An error occurred.",
|
|
436
|
-
...options.metaMessages ? ["", ...options.metaMessages] : [],
|
|
437
|
-
...details ? ["", details ? `Details: ${details}` : void 0] : []
|
|
438
|
-
].filter((x) => typeof x === "string").join("\n");
|
|
439
|
-
super(message, options.cause ? { cause: options.cause } : void 0);
|
|
440
|
-
_defineProperty(this, "details", void 0);
|
|
441
|
-
_defineProperty(this, "shortMessage", void 0);
|
|
442
|
-
_defineProperty(this, "cause", void 0);
|
|
443
|
-
_defineProperty(this, "name", "BaseError");
|
|
444
|
-
this.cause = options.cause;
|
|
445
|
-
this.details = details;
|
|
446
|
-
this.shortMessage = shortMessage;
|
|
447
|
-
}
|
|
448
|
-
walk(fn) {
|
|
449
|
-
return walk(this, fn);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
/** @internal */
|
|
453
|
-
function walk(err, fn) {
|
|
454
|
-
if (fn?.(err)) return err;
|
|
455
|
-
if (err && typeof err === "object" && "cause" in err && err.cause) return walk(err.cause, fn);
|
|
456
|
-
return fn ? null : err;
|
|
457
|
-
}
|
|
458
|
-
var ReorgError = class extends BaseError {
|
|
459
|
-
constructor(blockNumber) {
|
|
460
|
-
super(`Reorg detected at block number ${blockNumber}`);
|
|
461
|
-
_defineProperty(this, "name", "ReorgError");
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
|
|
465
553
|
//#endregion
|
|
466
554
|
//#region src/core/Chain.ts
|
|
467
555
|
var Chain_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -566,8 +654,8 @@ const chains$1 = {
|
|
|
566
654
|
name: "ethereum-virtual-testnet",
|
|
567
655
|
custom: {
|
|
568
656
|
morpho: {
|
|
569
|
-
address: "
|
|
570
|
-
blockCreated:
|
|
657
|
+
address: "0xc9f3c65996fc46b9500608b2c9a9152c01c540f7",
|
|
658
|
+
blockCreated: 23226871
|
|
571
659
|
},
|
|
572
660
|
morphoBlue: {
|
|
573
661
|
address: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
@@ -1508,7 +1596,7 @@ const OfferSchema = () => {
|
|
|
1508
1596
|
assets: z$1.bigint({ coerce: true }).min(0n).max(maxUint256),
|
|
1509
1597
|
obligationUnits: z$1.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),
|
|
1510
1598
|
obligationShares: z$1.bigint({ coerce: true }).min(0n).max(maxUint256).optional().default(0n),
|
|
1511
|
-
|
|
1599
|
+
tick: z$1.coerce.number().int().min(0).max(990),
|
|
1512
1600
|
maturity: MaturitySchema,
|
|
1513
1601
|
expiry: z$1.number().int().max(Number.MAX_SAFE_INTEGER),
|
|
1514
1602
|
start: z$1.number().int().max(Number.MAX_SAFE_INTEGER),
|
|
@@ -1529,7 +1617,8 @@ const OfferSchema = () => {
|
|
|
1529
1617
|
callback: z$1.object({
|
|
1530
1618
|
address: z$1.string().transform(transformAddress),
|
|
1531
1619
|
data: z$1.string().transform(transformHex)
|
|
1532
|
-
})
|
|
1620
|
+
}),
|
|
1621
|
+
receiverIfMakerIsSeller: z$1.string().transform(transformAddress)
|
|
1533
1622
|
}).refine((data) => data.start < data.expiry, {
|
|
1534
1623
|
message: "start must be before expiry",
|
|
1535
1624
|
path: ["start"]
|
|
@@ -1545,8 +1634,12 @@ const OfferSchema = () => {
|
|
|
1545
1634
|
* @returns The created offer.
|
|
1546
1635
|
*/
|
|
1547
1636
|
function from$9(input) {
|
|
1637
|
+
const normalizedInput = {
|
|
1638
|
+
...input,
|
|
1639
|
+
receiverIfMakerIsSeller: input.receiverIfMakerIsSeller ?? input.maker
|
|
1640
|
+
};
|
|
1548
1641
|
try {
|
|
1549
|
-
return OfferSchema().parse(
|
|
1642
|
+
return OfferSchema().parse(normalizedInput);
|
|
1550
1643
|
} catch (error) {
|
|
1551
1644
|
throw new InvalidOfferError(error);
|
|
1552
1645
|
}
|
|
@@ -1580,7 +1673,7 @@ const serialize = (offer) => ({
|
|
|
1580
1673
|
assets: offer.assets.toString(),
|
|
1581
1674
|
obligationUnits: offer.obligationUnits.toString(),
|
|
1582
1675
|
obligationShares: offer.obligationShares.toString(),
|
|
1583
|
-
|
|
1676
|
+
tick: offer.tick,
|
|
1584
1677
|
maturity: Number(offer.maturity),
|
|
1585
1678
|
expiry: Number(offer.expiry),
|
|
1586
1679
|
start: Number(offer.start),
|
|
@@ -1598,6 +1691,7 @@ const serialize = (offer) => ({
|
|
|
1598
1691
|
address: offer.callback.address,
|
|
1599
1692
|
data: offer.callback.data
|
|
1600
1693
|
},
|
|
1694
|
+
receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller,
|
|
1601
1695
|
hash: hash(offer)
|
|
1602
1696
|
});
|
|
1603
1697
|
/**
|
|
@@ -1625,14 +1719,13 @@ function random$1(config) {
|
|
|
1625
1719
|
[.98, 2]
|
|
1626
1720
|
]));
|
|
1627
1721
|
const buy = config?.buy !== void 0 ? config.buy : bool();
|
|
1628
|
-
const
|
|
1629
|
-
const
|
|
1630
|
-
const
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
return [BigInt(q) * (ONE / 4n), buy ? 1 + idx : 1 + (len - 1 - idx)];
|
|
1722
|
+
const tickMin = buy ? 0 : 495;
|
|
1723
|
+
const len = (buy ? 495 : 990) - tickMin + 1;
|
|
1724
|
+
const tickPairs = Array.from({ length: len }, (_, idx) => {
|
|
1725
|
+
const weight = buy ? 1 + idx : 1 + (len - 1 - idx);
|
|
1726
|
+
return [tickMin + idx, weight];
|
|
1634
1727
|
});
|
|
1635
|
-
const
|
|
1728
|
+
const tick = config?.tick ?? weightedChoice(tickPairs);
|
|
1636
1729
|
const loanTokenDecimals = config?.assetsDecimals?.[loanToken] ?? 18;
|
|
1637
1730
|
const unit = BigInt(10) ** BigInt(loanTokenDecimals);
|
|
1638
1731
|
const amountBase = BigInt(100 + int(999901));
|
|
@@ -1641,12 +1734,13 @@ function random$1(config) {
|
|
|
1641
1734
|
address: zeroAddress,
|
|
1642
1735
|
data: "0x"
|
|
1643
1736
|
};
|
|
1737
|
+
const maker = config?.maker ?? address();
|
|
1644
1738
|
return from$9({
|
|
1645
|
-
maker
|
|
1739
|
+
maker,
|
|
1646
1740
|
assets: assetsScaled,
|
|
1647
1741
|
obligationUnits: config?.obligationUnits ?? 0n,
|
|
1648
1742
|
obligationShares: config?.obligationShares ?? 0n,
|
|
1649
|
-
|
|
1743
|
+
tick,
|
|
1650
1744
|
maturity,
|
|
1651
1745
|
expiry: config?.expiry ?? maturity - 1,
|
|
1652
1746
|
start: config?.start ?? maturity - 10,
|
|
@@ -1659,7 +1753,8 @@ function random$1(config) {
|
|
|
1659
1753
|
...random$3(),
|
|
1660
1754
|
lltv
|
|
1661
1755
|
})).sort((a, b) => a.asset.localeCompare(b.asset)),
|
|
1662
|
-
callback: config?.callback ?? emptyCallback
|
|
1756
|
+
callback: config?.callback ?? emptyCallback,
|
|
1757
|
+
receiverIfMakerIsSeller: config?.receiverIfMakerIsSeller ?? maker
|
|
1663
1758
|
});
|
|
1664
1759
|
}
|
|
1665
1760
|
const weightedChoice = (pairs) => {
|
|
@@ -1711,7 +1806,7 @@ const types = {
|
|
|
1711
1806
|
type: "uint256"
|
|
1712
1807
|
},
|
|
1713
1808
|
{
|
|
1714
|
-
name: "
|
|
1809
|
+
name: "tick",
|
|
1715
1810
|
type: "uint256"
|
|
1716
1811
|
},
|
|
1717
1812
|
{
|
|
@@ -1745,6 +1840,10 @@ const types = {
|
|
|
1745
1840
|
{
|
|
1746
1841
|
name: "callback",
|
|
1747
1842
|
type: "Callback"
|
|
1843
|
+
},
|
|
1844
|
+
{
|
|
1845
|
+
name: "receiverIfMakerIsSeller",
|
|
1846
|
+
type: "address"
|
|
1748
1847
|
}
|
|
1749
1848
|
],
|
|
1750
1849
|
Collateral: [
|
|
@@ -1779,7 +1878,7 @@ function hash(offer) {
|
|
|
1779
1878
|
assets: offer.assets,
|
|
1780
1879
|
obligationUnits: offer.obligationUnits,
|
|
1781
1880
|
obligationShares: offer.obligationShares,
|
|
1782
|
-
|
|
1881
|
+
tick: BigInt(offer.tick),
|
|
1783
1882
|
maturity: BigInt(offer.maturity),
|
|
1784
1883
|
expiry: BigInt(offer.expiry),
|
|
1785
1884
|
group: offer.group,
|
|
@@ -1790,7 +1889,8 @@ function hash(offer) {
|
|
|
1790
1889
|
callback: {
|
|
1791
1890
|
address: offer.callback.address.toLowerCase(),
|
|
1792
1891
|
data: offer.callback.data
|
|
1793
|
-
}
|
|
1892
|
+
},
|
|
1893
|
+
receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller.toLowerCase()
|
|
1794
1894
|
},
|
|
1795
1895
|
primaryType: "Offer",
|
|
1796
1896
|
types
|
|
@@ -1830,7 +1930,7 @@ const OfferAbi = [
|
|
|
1830
1930
|
type: "uint256"
|
|
1831
1931
|
},
|
|
1832
1932
|
{
|
|
1833
|
-
name: "
|
|
1933
|
+
name: "tick",
|
|
1834
1934
|
type: "uint256"
|
|
1835
1935
|
},
|
|
1836
1936
|
{
|
|
@@ -1893,6 +1993,10 @@ const OfferAbi = [
|
|
|
1893
1993
|
name: "data",
|
|
1894
1994
|
type: "bytes"
|
|
1895
1995
|
}]
|
|
1996
|
+
},
|
|
1997
|
+
{
|
|
1998
|
+
name: "receiverIfMakerIsSeller",
|
|
1999
|
+
type: "address"
|
|
1896
2000
|
}
|
|
1897
2001
|
];
|
|
1898
2002
|
function encode$1(offer) {
|
|
@@ -1901,7 +2005,7 @@ function encode$1(offer) {
|
|
|
1901
2005
|
offer.assets,
|
|
1902
2006
|
offer.obligationUnits,
|
|
1903
2007
|
offer.obligationShares,
|
|
1904
|
-
offer.
|
|
2008
|
+
BigInt(offer.tick),
|
|
1905
2009
|
BigInt(offer.maturity),
|
|
1906
2010
|
BigInt(offer.expiry),
|
|
1907
2011
|
offer.group,
|
|
@@ -1911,7 +2015,8 @@ function encode$1(offer) {
|
|
|
1911
2015
|
offer.loanToken,
|
|
1912
2016
|
BigInt(offer.start),
|
|
1913
2017
|
offer.collaterals,
|
|
1914
|
-
offer.callback
|
|
2018
|
+
offer.callback,
|
|
2019
|
+
offer.receiverIfMakerIsSeller
|
|
1915
2020
|
]);
|
|
1916
2021
|
}
|
|
1917
2022
|
function decode$1(data) {
|
|
@@ -1926,7 +2031,7 @@ function decode$1(data) {
|
|
|
1926
2031
|
assets: decoded[1],
|
|
1927
2032
|
obligationUnits: decoded[2],
|
|
1928
2033
|
obligationShares: decoded[3],
|
|
1929
|
-
|
|
2034
|
+
tick: Number(decoded[4]),
|
|
1930
2035
|
maturity: from$11(Number(decoded[5])),
|
|
1931
2036
|
expiry: Number(decoded[6]),
|
|
1932
2037
|
group: decoded[7],
|
|
@@ -1945,7 +2050,8 @@ function decode$1(data) {
|
|
|
1945
2050
|
callback: {
|
|
1946
2051
|
address: decoded[14].address,
|
|
1947
2052
|
data: decoded[14].data
|
|
1948
|
-
}
|
|
2053
|
+
},
|
|
2054
|
+
receiverIfMakerIsSeller: decoded[15]
|
|
1949
2055
|
});
|
|
1950
2056
|
}
|
|
1951
2057
|
/**
|
|
@@ -2021,6 +2127,12 @@ const takeEvent = {
|
|
|
2021
2127
|
indexed: false,
|
|
2022
2128
|
internalType: "bool"
|
|
2023
2129
|
},
|
|
2130
|
+
{
|
|
2131
|
+
name: "sellerReceiver",
|
|
2132
|
+
type: "address",
|
|
2133
|
+
indexed: false,
|
|
2134
|
+
internalType: "address"
|
|
2135
|
+
},
|
|
2024
2136
|
{
|
|
2025
2137
|
name: "group",
|
|
2026
2138
|
type: "bytes32",
|
|
@@ -2210,16 +2322,16 @@ function from$7(parameters) {
|
|
|
2210
2322
|
//#region src/core/Quote.ts
|
|
2211
2323
|
var Quote_exports = /* @__PURE__ */ __exportAll({
|
|
2212
2324
|
InvalidQuoteError: () => InvalidQuoteError,
|
|
2213
|
-
QuoteSchema: () => QuoteSchema,
|
|
2214
2325
|
from: () => from$6,
|
|
2215
2326
|
fromSnakeCase: () => fromSnakeCase,
|
|
2216
2327
|
random: () => random
|
|
2217
2328
|
});
|
|
2218
|
-
const
|
|
2329
|
+
const SideInputSchema = z$1.object({ tick: z$1.number().int().min(0).max(TICK_RANGE).nullable() }).strict();
|
|
2330
|
+
const QuoteInputSchema = z$1.object({
|
|
2219
2331
|
obligationId: z$1.string().transform(transformHex),
|
|
2220
|
-
ask:
|
|
2221
|
-
bid:
|
|
2222
|
-
});
|
|
2332
|
+
ask: SideInputSchema,
|
|
2333
|
+
bid: SideInputSchema
|
|
2334
|
+
}).strict();
|
|
2223
2335
|
/**
|
|
2224
2336
|
* Creates a quote for a given obligation.
|
|
2225
2337
|
* @constructor
|
|
@@ -2229,16 +2341,16 @@ const QuoteSchema = z$1.object({
|
|
|
2229
2341
|
*
|
|
2230
2342
|
* @example
|
|
2231
2343
|
* ```ts
|
|
2232
|
-
* const quote = Quote.from({ obligationId: "0x123", ask: {
|
|
2344
|
+
* const quote = Quote.from({ obligationId: "0x123", ask: { tick: 500 }, bid: { tick: 510 } });
|
|
2233
2345
|
* ```
|
|
2234
2346
|
*/
|
|
2235
2347
|
function from$6(parameters) {
|
|
2236
2348
|
try {
|
|
2237
|
-
const parsedQuote =
|
|
2349
|
+
const parsedQuote = QuoteInputSchema.parse(parameters);
|
|
2238
2350
|
return {
|
|
2239
2351
|
obligationId: parsedQuote.obligationId,
|
|
2240
|
-
ask: parsedQuote.ask,
|
|
2241
|
-
bid: parsedQuote.bid
|
|
2352
|
+
ask: sideFromTick(parsedQuote.ask),
|
|
2353
|
+
bid: sideFromTick(parsedQuote.bid)
|
|
2242
2354
|
};
|
|
2243
2355
|
} catch (error) {
|
|
2244
2356
|
throw new InvalidQuoteError(error);
|
|
@@ -2265,8 +2377,8 @@ function fromSnakeCase(snake) {
|
|
|
2265
2377
|
function random() {
|
|
2266
2378
|
return from$6({
|
|
2267
2379
|
obligationId: id(random$2()),
|
|
2268
|
-
ask: {
|
|
2269
|
-
bid: {
|
|
2380
|
+
ask: { tick: int(TICK_RANGE + 1) },
|
|
2381
|
+
bid: { tick: int(TICK_RANGE + 1) }
|
|
2270
2382
|
});
|
|
2271
2383
|
}
|
|
2272
2384
|
var InvalidQuoteError = class extends BaseError {
|
|
@@ -2275,6 +2387,12 @@ var InvalidQuoteError = class extends BaseError {
|
|
|
2275
2387
|
_defineProperty(this, "name", "Quote.InvalidQuoteError");
|
|
2276
2388
|
}
|
|
2277
2389
|
};
|
|
2390
|
+
function sideFromTick(side) {
|
|
2391
|
+
return {
|
|
2392
|
+
tick: side.tick,
|
|
2393
|
+
price: side.tick === null ? 0n : tickToPrice(side.tick)
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2278
2396
|
|
|
2279
2397
|
//#endregion
|
|
2280
2398
|
//#region src/core/TradingFee.ts
|
|
@@ -2827,11 +2945,12 @@ function from$2(input) {
|
|
|
2827
2945
|
obligation_shares: input.obligationShares.toString(),
|
|
2828
2946
|
start: input.start,
|
|
2829
2947
|
expiry: input.expiry,
|
|
2830
|
-
|
|
2948
|
+
tick: input.tick,
|
|
2831
2949
|
group: input.group,
|
|
2832
2950
|
session: input.session,
|
|
2833
2951
|
callback: input.callback.address,
|
|
2834
|
-
callback_data: input.callback.data
|
|
2952
|
+
callback_data: input.callback.data,
|
|
2953
|
+
receiver_if_maker_is_seller: input.receiverIfMakerIsSeller
|
|
2835
2954
|
},
|
|
2836
2955
|
offer_hash: input.hash,
|
|
2837
2956
|
obligation_id: id({
|
|
@@ -2881,7 +3000,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
2881
3000
|
//#region src/api/Schema/openapi.ts
|
|
2882
3001
|
const timestampExample = "2024-01-01T12:00:00.000Z";
|
|
2883
3002
|
const offerCursorExample = "eyJvZmZzZXQiOjEwMH0";
|
|
2884
|
-
const obligationCursorExample = "
|
|
3003
|
+
const obligationCursorExample = "eyJzb3J0IjpbImlkIl0sImlkIjoiMHgxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiLCJhc2siOiIwIiwiYmlkIjoiMCIsIm1hdHVyaXR5IjoxNzYxOTIyODAwfQ";
|
|
2885
3004
|
const offerExample = {
|
|
2886
3005
|
offer: {
|
|
2887
3006
|
obligation: {
|
|
@@ -2900,11 +3019,12 @@ const offerExample = {
|
|
|
2900
3019
|
obligation_shares: "0",
|
|
2901
3020
|
start: 1761922790,
|
|
2902
3021
|
expiry: 1761922799,
|
|
2903
|
-
|
|
3022
|
+
tick: 495,
|
|
2904
3023
|
group: "0x000000000000000000000000000000000000000000000000000000000008b8f4",
|
|
2905
3024
|
session: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
2906
3025
|
callback: "0x0000000000000000000000000000000000000000",
|
|
2907
|
-
callback_data: "0x"
|
|
3026
|
+
callback_data: "0x",
|
|
3027
|
+
receiver_if_maker_is_seller: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"
|
|
2908
3028
|
},
|
|
2909
3029
|
offer_hash: "0xac4bd8318ec914f89f8af913f162230575b0ac0696a19256bc12138c5cfe1427",
|
|
2910
3030
|
obligation_id: "0x25690ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9abc",
|
|
@@ -2941,7 +3061,7 @@ const validateOfferExample = {
|
|
|
2941
3061
|
assets: "369216000000000000000000",
|
|
2942
3062
|
obligation_units: "0",
|
|
2943
3063
|
obligation_shares: "0",
|
|
2944
|
-
|
|
3064
|
+
tick: 495,
|
|
2945
3065
|
maturity: 1761922799,
|
|
2946
3066
|
expiry: 1761922799,
|
|
2947
3067
|
start: 1761922790,
|
|
@@ -2958,7 +3078,8 @@ const validateOfferExample = {
|
|
|
2958
3078
|
callback: {
|
|
2959
3079
|
address: "0x0000000000000000000000000000000000000000",
|
|
2960
3080
|
data: "0x"
|
|
2961
|
-
}
|
|
3081
|
+
},
|
|
3082
|
+
receiver_if_maker_is_seller: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401"
|
|
2962
3083
|
};
|
|
2963
3084
|
const routerStatusExample = {
|
|
2964
3085
|
status: "live",
|
|
@@ -3029,11 +3150,23 @@ __decorate([ApiProperty({
|
|
|
3029
3150
|
example: validateOfferExample.callback.data
|
|
3030
3151
|
})], ValidateCallbackRequest.prototype, "data", void 0);
|
|
3031
3152
|
var AskResponse = class {};
|
|
3153
|
+
__decorate([ApiProperty({
|
|
3154
|
+
type: "number",
|
|
3155
|
+
nullable: true,
|
|
3156
|
+
example: 500,
|
|
3157
|
+
description: "Best ask tick. Null when there is no active ask quote."
|
|
3158
|
+
})], AskResponse.prototype, "tick", void 0);
|
|
3032
3159
|
__decorate([ApiProperty({
|
|
3033
3160
|
type: "string",
|
|
3034
3161
|
example: "1000000000000000000"
|
|
3035
3162
|
})], AskResponse.prototype, "price", void 0);
|
|
3036
3163
|
var BidResponse = class {};
|
|
3164
|
+
__decorate([ApiProperty({
|
|
3165
|
+
type: "number",
|
|
3166
|
+
nullable: true,
|
|
3167
|
+
example: 500,
|
|
3168
|
+
description: "Best bid tick. Null when there is no active bid quote."
|
|
3169
|
+
})], BidResponse.prototype, "tick", void 0);
|
|
3037
3170
|
__decorate([ApiProperty({
|
|
3038
3171
|
type: "string",
|
|
3039
3172
|
example: "1000000000000000000"
|
|
@@ -3085,9 +3218,11 @@ __decorate([ApiProperty({
|
|
|
3085
3218
|
example: offerExample.offer.expiry
|
|
3086
3219
|
})], OfferDataResponse.prototype, "expiry", void 0);
|
|
3087
3220
|
__decorate([ApiProperty({
|
|
3088
|
-
type: "
|
|
3089
|
-
example: offerExample.offer.
|
|
3090
|
-
|
|
3221
|
+
type: "number",
|
|
3222
|
+
example: offerExample.offer.tick,
|
|
3223
|
+
minimum: 0,
|
|
3224
|
+
maximum: 990
|
|
3225
|
+
})], OfferDataResponse.prototype, "tick", void 0);
|
|
3091
3226
|
__decorate([ApiProperty({
|
|
3092
3227
|
type: "string",
|
|
3093
3228
|
example: offerExample.offer.group
|
|
@@ -3104,6 +3239,10 @@ __decorate([ApiProperty({
|
|
|
3104
3239
|
type: "string",
|
|
3105
3240
|
example: offerExample.offer.callback_data
|
|
3106
3241
|
})], OfferDataResponse.prototype, "callback_data", void 0);
|
|
3242
|
+
__decorate([ApiProperty({
|
|
3243
|
+
type: "string",
|
|
3244
|
+
example: offerExample.offer.receiver_if_maker_is_seller
|
|
3245
|
+
})], OfferDataResponse.prototype, "receiver_if_maker_is_seller", void 0);
|
|
3107
3246
|
var OfferListItemResponse = class {};
|
|
3108
3247
|
__decorate([ApiProperty({
|
|
3109
3248
|
type: () => OfferDataResponse,
|
|
@@ -3328,9 +3467,11 @@ __decorate([ApiProperty({
|
|
|
3328
3467
|
required: false
|
|
3329
3468
|
})], ValidateOfferRequest.prototype, "obligation_shares", void 0);
|
|
3330
3469
|
__decorate([ApiProperty({
|
|
3331
|
-
type: "
|
|
3332
|
-
example: validateOfferExample.
|
|
3333
|
-
|
|
3470
|
+
type: "number",
|
|
3471
|
+
example: validateOfferExample.tick,
|
|
3472
|
+
minimum: 0,
|
|
3473
|
+
maximum: 990
|
|
3474
|
+
})], ValidateOfferRequest.prototype, "tick", void 0);
|
|
3334
3475
|
__decorate([ApiProperty({
|
|
3335
3476
|
type: "number",
|
|
3336
3477
|
example: validateOfferExample.maturity
|
|
@@ -3371,6 +3512,10 @@ __decorate([ApiProperty({
|
|
|
3371
3512
|
type: () => ValidateCallbackRequest,
|
|
3372
3513
|
example: validateOfferExample.callback
|
|
3373
3514
|
})], ValidateOfferRequest.prototype, "callback", void 0);
|
|
3515
|
+
__decorate([ApiProperty({
|
|
3516
|
+
type: "string",
|
|
3517
|
+
example: validateOfferExample.receiver_if_maker_is_seller
|
|
3518
|
+
})], ValidateOfferRequest.prototype, "receiver_if_maker_is_seller", void 0);
|
|
3374
3519
|
var ValidateOffersRequest = class {};
|
|
3375
3520
|
__decorate([ApiProperty({
|
|
3376
3521
|
type: () => [ValidateOfferRequest],
|
|
@@ -3430,9 +3575,16 @@ __decorate([ApiProperty({
|
|
|
3430
3575
|
description: "List of validation issues. Returned when any offer fails validation."
|
|
3431
3576
|
})], ValidationFailureResponse.prototype, "data", void 0);
|
|
3432
3577
|
var BookLevelResponse = class {};
|
|
3578
|
+
__decorate([ApiProperty({
|
|
3579
|
+
type: "number",
|
|
3580
|
+
example: 495,
|
|
3581
|
+
minimum: 0,
|
|
3582
|
+
maximum: 990
|
|
3583
|
+
})], BookLevelResponse.prototype, "tick", void 0);
|
|
3433
3584
|
__decorate([ApiProperty({
|
|
3434
3585
|
type: "string",
|
|
3435
|
-
example: "
|
|
3586
|
+
example: "500000000000000000",
|
|
3587
|
+
description: "Price derived from tick, scaled by 1e18."
|
|
3436
3588
|
})], BookLevelResponse.prototype, "price", void 0);
|
|
3437
3589
|
__decorate([ApiProperty({
|
|
3438
3590
|
type: "string",
|
|
@@ -3446,6 +3598,7 @@ const positionExample = {
|
|
|
3446
3598
|
chain_id: 1,
|
|
3447
3599
|
contract: "0xC9A9C45C0eB717f8b5F193Af6bAa05A1c0Ac5078",
|
|
3448
3600
|
user: "0x7b093658BE7f90B63D7c359e8f408e503c2D9401",
|
|
3601
|
+
obligation_id: "0x12590ae1aee324a005be565f3bcdd16dbf8daf7969b26c181c8b8f467dad9f67",
|
|
3449
3602
|
reserved: "200000000000000000000",
|
|
3450
3603
|
block_number: 21345678
|
|
3451
3604
|
};
|
|
@@ -3462,6 +3615,12 @@ __decorate([ApiProperty({
|
|
|
3462
3615
|
type: "string",
|
|
3463
3616
|
example: positionExample.user
|
|
3464
3617
|
})], PositionListItemResponse.prototype, "user", void 0);
|
|
3618
|
+
__decorate([ApiProperty({
|
|
3619
|
+
type: "string",
|
|
3620
|
+
nullable: true,
|
|
3621
|
+
example: positionExample.obligation_id,
|
|
3622
|
+
description: "Obligation id this reserved amount belongs to, or null if no lots exist."
|
|
3623
|
+
})], PositionListItemResponse.prototype, "obligation_id", void 0);
|
|
3465
3624
|
__decorate([ApiProperty({
|
|
3466
3625
|
type: "string",
|
|
3467
3626
|
example: positionExample.reserved
|
|
@@ -3489,7 +3648,7 @@ __decorate([ApiProperty({
|
|
|
3489
3648
|
})], BookListResponse.prototype, "cursor", void 0);
|
|
3490
3649
|
__decorate([ApiProperty({
|
|
3491
3650
|
type: () => [BookLevelResponse],
|
|
3492
|
-
description: "Aggregated book levels grouped by
|
|
3651
|
+
description: "Aggregated book levels grouped by offer tick."
|
|
3493
3652
|
})], BookListResponse.prototype, "data", void 0);
|
|
3494
3653
|
let BooksController = class BooksController {
|
|
3495
3654
|
async getBook() {}
|
|
@@ -3499,7 +3658,7 @@ __decorate([
|
|
|
3499
3658
|
methods: ["get"],
|
|
3500
3659
|
path: "/v1/books/{obligationId}/{side}",
|
|
3501
3660
|
summary: "Get aggregated book",
|
|
3502
|
-
description: "Returns aggregated book data for a given obligation and side. Offers are grouped by
|
|
3661
|
+
description: "Returns aggregated book data for a given obligation and side. Offers are grouped by tick with summed takeable amounts, and each level includes the corresponding wad-scaled price. Book levels are sorted by tick (ascending for sell side, descending for buy side)."
|
|
3503
3662
|
}),
|
|
3504
3663
|
ApiParam({
|
|
3505
3664
|
name: "obligationId",
|
|
@@ -3524,7 +3683,7 @@ __decorate([
|
|
|
3524
3683
|
name: "limit",
|
|
3525
3684
|
type: "number",
|
|
3526
3685
|
example: 10,
|
|
3527
|
-
description: "Maximum number of
|
|
3686
|
+
description: "Maximum number of tick levels to return."
|
|
3528
3687
|
}),
|
|
3529
3688
|
ApiResponse({
|
|
3530
3689
|
status: 200,
|
|
@@ -3718,6 +3877,11 @@ const configRulesLoanTokenExample = {
|
|
|
3718
3877
|
chain_id: 1,
|
|
3719
3878
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
3720
3879
|
};
|
|
3880
|
+
const configRulesCollateralTokenExample = {
|
|
3881
|
+
type: "collateral_token",
|
|
3882
|
+
chain_id: 1,
|
|
3883
|
+
address: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
3884
|
+
};
|
|
3721
3885
|
const configRulesOracleExample = {
|
|
3722
3886
|
type: "oracle",
|
|
3723
3887
|
chain_id: 1,
|
|
@@ -3727,6 +3891,7 @@ const configRulesChecksumExample = "f1d2d2f924e986ac86fdf7b36c94bcdf";
|
|
|
3727
3891
|
const configRulesPayloadExample = [
|
|
3728
3892
|
configRulesMaturityExample,
|
|
3729
3893
|
configRulesLoanTokenExample,
|
|
3894
|
+
configRulesCollateralTokenExample,
|
|
3730
3895
|
configRulesOracleExample
|
|
3731
3896
|
];
|
|
3732
3897
|
const configContractNames = [
|
|
@@ -3853,7 +4018,7 @@ __decorate([
|
|
|
3853
4018
|
methods: ["get"],
|
|
3854
4019
|
path: "/v1/config/rules",
|
|
3855
4020
|
summary: "Get config rules",
|
|
3856
|
-
description: "Returns configured rules (maturities, loan tokens, oracles) for supported chains."
|
|
4021
|
+
description: "Returns configured rules (maturities, loan tokens, collateral tokens, oracles) for supported chains."
|
|
3857
4022
|
}),
|
|
3858
4023
|
ApiQuery({
|
|
3859
4024
|
name: "cursor",
|
|
@@ -3873,7 +4038,7 @@ __decorate([
|
|
|
3873
4038
|
name: "types",
|
|
3874
4039
|
type: ["string"],
|
|
3875
4040
|
required: false,
|
|
3876
|
-
example: "maturity,loan_token,oracle",
|
|
4041
|
+
example: "maturity,loan_token,collateral_token,oracle",
|
|
3877
4042
|
description: "Filter by rule types (comma-separated).",
|
|
3878
4043
|
style: "form",
|
|
3879
4044
|
explode: false
|
|
@@ -3903,13 +4068,13 @@ __decorate([
|
|
|
3903
4068
|
methods: ["get"],
|
|
3904
4069
|
path: "/v1/obligations",
|
|
3905
4070
|
summary: "List all obligations",
|
|
3906
|
-
description: "Returns a list of obligations with their current best ask and bid.
|
|
4071
|
+
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."
|
|
3907
4072
|
}),
|
|
3908
4073
|
ApiQuery({
|
|
3909
4074
|
name: "cursor",
|
|
3910
4075
|
type: "string",
|
|
3911
4076
|
example: obligationCursorExample,
|
|
3912
|
-
description: "
|
|
4077
|
+
description: "Pagination cursor in base64url-encoded format."
|
|
3913
4078
|
}),
|
|
3914
4079
|
ApiQuery({
|
|
3915
4080
|
name: "limit",
|
|
@@ -3953,6 +4118,15 @@ __decorate([
|
|
|
3953
4118
|
style: "form",
|
|
3954
4119
|
explode: false
|
|
3955
4120
|
}),
|
|
4121
|
+
ApiQuery({
|
|
4122
|
+
name: "sort",
|
|
4123
|
+
type: "string",
|
|
4124
|
+
required: false,
|
|
4125
|
+
example: "-ask,bid,maturity",
|
|
4126
|
+
description: "Sort order as comma-separated fields (`id`, `ask`, `bid`, `maturity`). Prefix with `-` for descending order. Max 3 fields.",
|
|
4127
|
+
style: "form",
|
|
4128
|
+
explode: false
|
|
4129
|
+
}),
|
|
3956
4130
|
ApiResponse({
|
|
3957
4131
|
status: 200,
|
|
3958
4132
|
description: "Success",
|
|
@@ -3991,7 +4165,7 @@ __decorate([
|
|
|
3991
4165
|
methods: ["get"],
|
|
3992
4166
|
path: "/v1/users/{userAddress}/positions",
|
|
3993
4167
|
summary: "Get user positions",
|
|
3994
|
-
description: "Returns positions for a user with reserved balance.
|
|
4168
|
+
description: "Returns positions for a user with reserved balance per obligation. Each (position, obligation) pair is returned as a separate row. Positions with no lots return a single row with obligation_id = null and reserved = 0."
|
|
3995
4169
|
}),
|
|
3996
4170
|
ApiParam({
|
|
3997
4171
|
name: "userAddress",
|
|
@@ -4079,6 +4253,7 @@ function from$1(position) {
|
|
|
4079
4253
|
chain_id: position.chainId,
|
|
4080
4254
|
contract: position.contract,
|
|
4081
4255
|
user: position.user,
|
|
4256
|
+
obligation_id: position.obligationId,
|
|
4082
4257
|
reserved: position.reserved.toString(),
|
|
4083
4258
|
block_number: position.blockNumber
|
|
4084
4259
|
};
|
|
@@ -4088,10 +4263,12 @@ function from$1(position) {
|
|
|
4088
4263
|
//#region src/api/Schema/requests.ts
|
|
4089
4264
|
const MAX_LIMIT = 100;
|
|
4090
4265
|
const DEFAULT_LIMIT = 20;
|
|
4266
|
+
const MAX_OBLIGATION_SORT_FIELDS = 3;
|
|
4091
4267
|
const CONFIG_RULES_MAX_LIMIT = 1e3;
|
|
4092
4268
|
const CONFIG_RULES_DEFAULT_LIMIT = 100;
|
|
4093
4269
|
const CONFIG_CONTRACTS_MAX_LIMIT = 1e3;
|
|
4094
4270
|
const CONFIG_CONTRACTS_DEFAULT_LIMIT = 1e3;
|
|
4271
|
+
const OBLIGATION_SORT_ENTRY_REGEX = /^-?(id|ask|bid|maturity)$/;
|
|
4095
4272
|
/** Validate cursor is a valid base64url-encoded JSON object.
|
|
4096
4273
|
* Domain layer handles semantic validation of cursor fields. */
|
|
4097
4274
|
function isValidBase64urlJson(val) {
|
|
@@ -4132,10 +4309,11 @@ const ConfigRuleTypes = z$1.enum([
|
|
|
4132
4309
|
"maturity",
|
|
4133
4310
|
"callback",
|
|
4134
4311
|
"loan_token",
|
|
4312
|
+
"collateral_token",
|
|
4135
4313
|
"oracle"
|
|
4136
4314
|
]);
|
|
4137
4315
|
const GetConfigRulesQueryParams = z$1.object({
|
|
4138
|
-
cursor: z$1.string().regex(/^(maturity|callback|loan_token|oracle):[1-9]\d*:.+$/, { message: "Cursor must be in the format type:chain_id:<value>" }).optional().meta({
|
|
4316
|
+
cursor: z$1.string().regex(/^(maturity|callback|loan_token|collateral_token|oracle):[1-9]\d*:.+$/, { message: "Cursor must be in the format type:chain_id:<value>" }).optional().meta({
|
|
4139
4317
|
description: "Pagination cursor in type:chain_id:<value> format",
|
|
4140
4318
|
example: "maturity:1:1730415600:end_of_next_month"
|
|
4141
4319
|
}),
|
|
@@ -4145,7 +4323,7 @@ const GetConfigRulesQueryParams = z$1.object({
|
|
|
4145
4323
|
}),
|
|
4146
4324
|
types: csvArray(ConfigRuleTypes).meta({
|
|
4147
4325
|
description: "Filter by rule types (comma-separated).",
|
|
4148
|
-
example: "maturity,loan_token,oracle"
|
|
4326
|
+
example: "maturity,loan_token,collateral_token,oracle"
|
|
4149
4327
|
}),
|
|
4150
4328
|
chains: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
|
|
4151
4329
|
description: "Filter by chain IDs (comma-separated).",
|
|
@@ -4220,9 +4398,12 @@ const GetOffersQueryParams = PaginationQueryParams.omit({ cursor: true }).extend
|
|
|
4220
4398
|
});
|
|
4221
4399
|
const GetObligationsQueryParams = z$1.object({
|
|
4222
4400
|
...PaginationQueryParams.shape,
|
|
4223
|
-
cursor: z$1.string().optional().
|
|
4224
|
-
|
|
4225
|
-
|
|
4401
|
+
cursor: z$1.string().optional().refine((val) => {
|
|
4402
|
+
if (!val) return true;
|
|
4403
|
+
return isValidBase64urlJson(val);
|
|
4404
|
+
}, { message: "Invalid cursor format. Must be a valid base64url-encoded cursor object" }).meta({
|
|
4405
|
+
description: "Pagination cursor in base64url-encoded format.",
|
|
4406
|
+
example: "eyJzb3J0IjpbImlkIl0sImlkIjoiMHgxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiLCJhc2siOiIwIiwiYmlkIjoiMCIsIm1hdHVyaXR5IjoxNzYxOTIyODAwfQ"
|
|
4226
4407
|
}),
|
|
4227
4408
|
chains: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Chain must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
|
|
4228
4409
|
description: "Filter by chain IDs (comma-separated).",
|
|
@@ -4239,18 +4420,35 @@ const GetObligationsQueryParams = z$1.object({
|
|
|
4239
4420
|
maturities: csvArray(z$1.string().regex(/^[1-9]\d*$/, { message: "Maturity must be a positive integer" }).transform((val) => Number.parseInt(val, 10))).meta({
|
|
4240
4421
|
description: "Filter by exact maturity timestamps (comma-separated, unix seconds).",
|
|
4241
4422
|
example: "1761922800,1764524800"
|
|
4423
|
+
}),
|
|
4424
|
+
sort: csvArray(z$1.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) => {
|
|
4425
|
+
if (!entries) return;
|
|
4426
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4427
|
+
for (const entry of entries) {
|
|
4428
|
+
const field = entry.startsWith("-") ? entry.slice(1) : entry;
|
|
4429
|
+
if (seen.has(field)) {
|
|
4430
|
+
ctx.addIssue({
|
|
4431
|
+
code: "custom",
|
|
4432
|
+
message: `Duplicate sort field: ${field}`
|
|
4433
|
+
});
|
|
4434
|
+
return;
|
|
4435
|
+
}
|
|
4436
|
+
seen.add(field);
|
|
4437
|
+
}
|
|
4438
|
+
}).meta({
|
|
4439
|
+
description: "Sort order as comma-separated fields. Prefix a field with '-' for descending order. Max 3 fields.",
|
|
4440
|
+
example: "-ask,bid,maturity"
|
|
4242
4441
|
})
|
|
4243
4442
|
});
|
|
4244
4443
|
const GetObligationParams = z$1.object({ obligation_id: z$1.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({
|
|
4245
4444
|
description: "Obligation id",
|
|
4246
4445
|
example: "0x1234567890123456789012345678901234567890123456789012345678901234"
|
|
4247
4446
|
}) });
|
|
4248
|
-
/** Validate a book cursor format: {side,
|
|
4447
|
+
/** Validate a book cursor format: {side, lastTick, offersCursor} */
|
|
4249
4448
|
function isValidBookCursor(cursorString) {
|
|
4250
|
-
const isNumericString = (value) => typeof value === "string" && /^-?\d+$/.test(value);
|
|
4251
4449
|
try {
|
|
4252
4450
|
const v = JSON.parse(Buffer.from(cursorString, "base64url").toString("utf8"));
|
|
4253
|
-
return (v?.side === "buy" || v?.side === "sell") &&
|
|
4451
|
+
return (v?.side === "buy" || v?.side === "sell") && typeof v?.lastTick === "number" && Number.isInteger(v.lastTick) && (v?.offersCursor === null || typeof v?.offersCursor === "string");
|
|
4254
4452
|
} catch {
|
|
4255
4453
|
return false;
|
|
4256
4454
|
}
|
|
@@ -4411,7 +4609,7 @@ async function getOffers(apiClient, parameters) {
|
|
|
4411
4609
|
assets: offerData.assets,
|
|
4412
4610
|
obligation_units: offerData.obligation_units,
|
|
4413
4611
|
obligation_shares: offerData.obligation_shares,
|
|
4414
|
-
|
|
4612
|
+
tick: offerData.tick,
|
|
4415
4613
|
maturity: from$11(offerData.obligation.maturity),
|
|
4416
4614
|
expiry: offerData.expiry,
|
|
4417
4615
|
start: offerData.start,
|
|
@@ -4428,7 +4626,8 @@ async function getOffers(apiClient, parameters) {
|
|
|
4428
4626
|
callback: {
|
|
4429
4627
|
address: offerData.callback,
|
|
4430
4628
|
data: offerData.callback_data
|
|
4431
|
-
}
|
|
4629
|
+
},
|
|
4630
|
+
receiver_if_maker_is_seller: offerData.receiver_if_maker_is_seller
|
|
4432
4631
|
}),
|
|
4433
4632
|
hash: item.offer_hash,
|
|
4434
4633
|
consumed: BigInt(item.consumed),
|
|
@@ -4445,13 +4644,15 @@ async function getOffers(apiClient, parameters) {
|
|
|
4445
4644
|
};
|
|
4446
4645
|
}
|
|
4447
4646
|
async function getObligations(apiClient, parameters) {
|
|
4647
|
+
const sort = parameters?.sort?.length ? parameters.sort.join(",") : void 0;
|
|
4448
4648
|
const { data, error, response } = await apiClient.GET("/v1/obligations", { params: { query: {
|
|
4449
4649
|
cursor: parameters?.cursor,
|
|
4450
4650
|
limit: parameters?.limit,
|
|
4451
4651
|
chains: parameters?.chainIds,
|
|
4452
4652
|
loan_tokens: parameters?.loanTokens,
|
|
4453
4653
|
collateral_tokens: parameters?.collateralTokens,
|
|
4454
|
-
maturities: parameters?.maturities
|
|
4654
|
+
maturities: parameters?.maturities,
|
|
4655
|
+
sort
|
|
4455
4656
|
} } });
|
|
4456
4657
|
if (error !== void 0) {
|
|
4457
4658
|
switch (response.status) {
|
|
@@ -4475,10 +4676,10 @@ async function getObligations(apiClient, parameters) {
|
|
|
4475
4676
|
const { obligationId: _, ...returned } = {
|
|
4476
4677
|
id: () => id(obligation),
|
|
4477
4678
|
...obligation,
|
|
4478
|
-
...
|
|
4479
|
-
|
|
4480
|
-
ask: item.ask,
|
|
4481
|
-
bid: item.bid
|
|
4679
|
+
...from$6({
|
|
4680
|
+
obligationId: item.id,
|
|
4681
|
+
ask: { tick: item.ask.tick },
|
|
4682
|
+
bid: { tick: item.bid.tick }
|
|
4482
4683
|
})
|
|
4483
4684
|
};
|
|
4484
4685
|
return returned;
|
|
@@ -4759,6 +4960,33 @@ const assets = {
|
|
|
4759
4960
|
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
|
|
4760
4961
|
]
|
|
4761
4962
|
};
|
|
4963
|
+
const collateralAssets = {
|
|
4964
|
+
[ChainId.ETHEREUM.toString()]: [
|
|
4965
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
4966
|
+
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
4967
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
4968
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
4969
|
+
],
|
|
4970
|
+
[ChainId.BASE.toString()]: [
|
|
4971
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
4972
|
+
"0x4200000000000000000000000000000000000006",
|
|
4973
|
+
"0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
|
|
4974
|
+
"0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
|
|
4975
|
+
"0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
|
|
4976
|
+
],
|
|
4977
|
+
[ChainId["ETHEREUM-VIRTUAL-TESTNET"].toString()]: [
|
|
4978
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
4979
|
+
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
4980
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
4981
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
4982
|
+
],
|
|
4983
|
+
[ChainId.ANVIL.toString()]: [
|
|
4984
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
4985
|
+
"0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
4986
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
4987
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
|
|
4988
|
+
]
|
|
4989
|
+
};
|
|
4762
4990
|
const oracles = {
|
|
4763
4991
|
[ChainId.ETHEREUM.toString()]: [
|
|
4764
4992
|
"0xDddd770BADd886dF3864029e4B377B5F6a2B6b83",
|
|
@@ -4799,19 +5027,19 @@ const oracles = {
|
|
|
4799
5027
|
const configs = {
|
|
4800
5028
|
ethereum: {
|
|
4801
5029
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4802
|
-
maturities: [MaturityType.
|
|
5030
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4803
5031
|
},
|
|
4804
5032
|
base: {
|
|
4805
5033
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4806
|
-
maturities: [MaturityType.
|
|
5034
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4807
5035
|
},
|
|
4808
5036
|
"ethereum-virtual-testnet": {
|
|
4809
5037
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4810
|
-
maturities: [MaturityType.
|
|
5038
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4811
5039
|
},
|
|
4812
5040
|
anvil: {
|
|
4813
5041
|
callbacks: [{ type: Type$1.BuyWithEmptyCallback }, { type: Type$1.SellWithEmptyCallback }],
|
|
4814
|
-
maturities: [MaturityType.
|
|
5042
|
+
maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek]
|
|
4815
5043
|
}
|
|
4816
5044
|
};
|
|
4817
5045
|
|
|
@@ -4821,10 +5049,11 @@ var Rules_exports = /* @__PURE__ */ __exportAll({
|
|
|
4821
5049
|
amountMutualExclusivity: () => amountMutualExclusivity,
|
|
4822
5050
|
callback: () => callback,
|
|
4823
5051
|
chains: () => chains,
|
|
5052
|
+
collateralToken: () => collateralToken,
|
|
5053
|
+
loanToken: () => loanToken,
|
|
4824
5054
|
maturity: () => maturity,
|
|
4825
5055
|
oracle: () => oracle,
|
|
4826
5056
|
sameMaker: () => sameMaker,
|
|
4827
|
-
token: () => token,
|
|
4828
5057
|
validity: () => validity
|
|
4829
5058
|
});
|
|
4830
5059
|
/**
|
|
@@ -4844,7 +5073,7 @@ const chains = ({ chains }) => single("chain_ids", `Validates that offer chain i
|
|
|
4844
5073
|
});
|
|
4845
5074
|
const maturity = ({ maturities }) => single("maturity", `Validates that offer maturity is one of: [${maturities.join(", ")}]`, (offer) => {
|
|
4846
5075
|
const allowedMaturities = maturities.map((m) => from$11(m));
|
|
4847
|
-
if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be
|
|
5076
|
+
if (!allowedMaturities.includes(offer.maturity)) return { message: `Maturity must be one of (${allowedMaturities.join(", ")}). Got: ${offer.maturity}` };
|
|
4848
5077
|
});
|
|
4849
5078
|
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
5079
|
if (!isEmptyCallback(offer)) return { message: "Non-empty callbacks are not supported." };
|
|
@@ -4852,15 +5081,25 @@ const callback = ({ callbacks }) => single("callback", `Validates callbacks: buy
|
|
|
4852
5081
|
if (isEmptyCallback(offer) && !offer.buy && !callbacks.includes(Type$1.SellWithEmptyCallback)) return { message: "Sell offers with empty callback not allowed." };
|
|
4853
5082
|
});
|
|
4854
5083
|
/**
|
|
4855
|
-
* A validation rule that checks if the offer's
|
|
4856
|
-
* @param assetsByChainId - Allowed
|
|
5084
|
+
* A validation rule that checks if the offer's loan token is allowed for its chain.
|
|
5085
|
+
* @param assetsByChainId - Allowed loan tokens indexed by chain id.
|
|
5086
|
+
* @returns The issue that was found. If the offer is valid, this will be undefined.
|
|
5087
|
+
*/
|
|
5088
|
+
const loanToken = ({ assetsByChainId }) => single("loan_token", "Validates that offer loan token is in the allowed token list for the offer chain", (offer) => {
|
|
5089
|
+
const allowedLoanTokens = assetsByChainId[offer.chainId]?.map((asset) => asset.toLowerCase());
|
|
5090
|
+
if (!allowedLoanTokens || allowedLoanTokens.length === 0) return { message: `No allowed loan tokens for chain ${offer.chainId}` };
|
|
5091
|
+
if (!allowedLoanTokens.includes(offer.loanToken.toLowerCase())) return { message: "Loan token is not allowed" };
|
|
5092
|
+
});
|
|
5093
|
+
/**
|
|
5094
|
+
* A validation rule that checks if the offer's collateral tokens are allowed for its chain.
|
|
5095
|
+
* @param collateralAssetsByChainId - Allowed collateral tokens indexed by chain id.
|
|
4857
5096
|
* @returns The issue that was found. If the offer is valid, this will be undefined.
|
|
4858
5097
|
*/
|
|
4859
|
-
const
|
|
4860
|
-
const
|
|
4861
|
-
if (
|
|
4862
|
-
if (
|
|
4863
|
-
if (offer.collaterals.some((collateral) => !
|
|
5098
|
+
const collateralToken = ({ collateralAssetsByChainId }) => single("collateral_token", "Validates that offer collateral tokens are in the allowed token list for the offer chain", (offer) => {
|
|
5099
|
+
const allowedCollateralTokens = collateralAssetsByChainId[offer.chainId]?.map((asset) => asset.toLowerCase()) ?? [];
|
|
5100
|
+
if (allowedCollateralTokens.length === 0) return { message: `No allowed collateral tokens for chain ${offer.chainId}` };
|
|
5101
|
+
if (offer.collaterals.length === 0) return { message: "At least one collateral token is required" };
|
|
5102
|
+
if (offer.collaterals.some((collateral) => !allowedCollateralTokens.includes(collateral.asset.toLowerCase()))) return { message: "Collateral token is not allowed" };
|
|
4864
5103
|
});
|
|
4865
5104
|
/**
|
|
4866
5105
|
* A validation rule that checks if the offer's oracle addresses are allowed for its chain.
|
|
@@ -4903,21 +5142,24 @@ const amountMutualExclusivity = () => single("amount_mutual_exclusivity", "Valid
|
|
|
4903
5142
|
//#region src/gatekeeper/morphoRules.ts
|
|
4904
5143
|
const morphoRules = (chains$2) => {
|
|
4905
5144
|
const assetsByChainId = {};
|
|
5145
|
+
const collateralAssetsByChainId = {};
|
|
4906
5146
|
const oraclesByChainId = {};
|
|
4907
5147
|
for (const chain of chains$2) {
|
|
4908
5148
|
assetsByChainId[chain.id] = assets[chain.id.toString()] ?? [];
|
|
5149
|
+
collateralAssetsByChainId[chain.id] = collateralAssets[chain.id.toString()] ?? [];
|
|
4909
5150
|
oraclesByChainId[chain.id] = oracles[chain.id.toString()] ?? [];
|
|
4910
5151
|
}
|
|
4911
5152
|
return [
|
|
4912
5153
|
sameMaker(),
|
|
4913
5154
|
amountMutualExclusivity(),
|
|
4914
5155
|
chains({ chains: chains$2 }),
|
|
4915
|
-
maturity({ maturities: [MaturityType.
|
|
5156
|
+
maturity({ maturities: [MaturityType.EndOfWeek, MaturityType.EndOfNextWeek] }),
|
|
4916
5157
|
callback({
|
|
4917
5158
|
callbacks: [Type$1.BuyWithEmptyCallback, Type$1.SellWithEmptyCallback],
|
|
4918
5159
|
allowedAddresses: []
|
|
4919
5160
|
}),
|
|
4920
|
-
|
|
5161
|
+
loanToken({ assetsByChainId }),
|
|
5162
|
+
collateralToken({ collateralAssetsByChainId }),
|
|
4921
5163
|
oracle({ oraclesByChainId })
|
|
4922
5164
|
];
|
|
4923
5165
|
};
|
|
@@ -5243,5 +5485,5 @@ var utils_exports = /* @__PURE__ */ __exportAll({
|
|
|
5243
5485
|
});
|
|
5244
5486
|
|
|
5245
5487
|
//#endregion
|
|
5246
|
-
export { Abi_exports as Abi, BrandTypeId, Callback_exports as Callback, Chain_exports as Chain, ChainRegistry_exports as ChainRegistry, Collateral_exports as Collateral, ERC4626_exports as ERC4626, Errors_exports as Errors, Format_exports as Format, Gatekeeper_exports as Gatekeeper, Client_exports as GatekeeperClient, LLTV_exports as LLTV, Liquidity_exports as Liquidity, Maturity_exports as Maturity, MempoolClient_exports as Mempool, Obligation_exports as Obligation, Offer_exports as Offer, Oracle_exports as Oracle, Position_exports as Position, Quote_exports as Quote, Schema_exports as RouterApi, Client_exports$1 as RouterClient, Rules_exports as Rules, time_exports as Time, TradingFee_exports as TradingFee, Transfer_exports as Transfer, Tree_exports as Tree, utils_exports as Utils, Gate_exports as Validation, morphoRules };
|
|
5488
|
+
export { Abi_exports as Abi, BrandTypeId, Callback_exports as Callback, Chain_exports as Chain, ChainRegistry_exports as ChainRegistry, Collateral_exports as Collateral, ERC4626_exports as ERC4626, Errors_exports as Errors, Format_exports as Format, Gatekeeper_exports as Gatekeeper, Client_exports as GatekeeperClient, LLTV_exports as LLTV, Liquidity_exports as Liquidity, Maturity_exports as Maturity, MempoolClient_exports as Mempool, Obligation_exports as Obligation, Offer_exports as Offer, Oracle_exports as Oracle, Position_exports as Position, Quote_exports as Quote, Schema_exports as RouterApi, Client_exports$1 as RouterClient, Rules_exports as Rules, Tick_exports as Tick, time_exports as Time, TradingFee_exports as TradingFee, Transfer_exports as Transfer, Tree_exports as Tree, utils_exports as Utils, Gate_exports as Validation, morphoRules };
|
|
5247
5489
|
//# sourceMappingURL=index.browser.mjs.map
|