@morpho-org/midnight-sdk 0.1.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/README.md +252 -0
- package/lib/cjs/abis.d.ts +3170 -0
- package/lib/cjs/abis.js +4073 -0
- package/lib/cjs/api/MidnightApi.d.ts +532 -0
- package/lib/cjs/api/MidnightApi.js +713 -0
- package/lib/cjs/api/helpers.d.ts +20 -0
- package/lib/cjs/api/helpers.js +189 -0
- package/lib/cjs/api/index.d.ts +2 -0
- package/lib/cjs/api/index.js +21 -0
- package/lib/cjs/api/types.d.ts +453 -0
- package/lib/cjs/api/types.js +2 -0
- package/lib/cjs/constants.d.ts +168 -0
- package/lib/cjs/constants.js +187 -0
- package/lib/cjs/errors.d.ts +253 -0
- package/lib/cjs/errors.js +309 -0
- package/lib/cjs/fetch/Market.d.ts +65 -0
- package/lib/cjs/fetch/Market.js +117 -0
- package/lib/cjs/fetch/Offer.d.ts +74 -0
- package/lib/cjs/fetch/Offer.js +119 -0
- package/lib/cjs/fetch/Position.d.ts +85 -0
- package/lib/cjs/fetch/Position.js +148 -0
- package/lib/cjs/fetch/Ratifier.d.ts +38 -0
- package/lib/cjs/fetch/Ratifier.js +57 -0
- package/lib/cjs/fetch/index.d.ts +5 -0
- package/lib/cjs/fetch/index.js +21 -0
- package/lib/cjs/fetch/types.d.ts +57 -0
- package/lib/cjs/fetch/types.js +2 -0
- package/lib/cjs/fetch/utils.d.ts +8 -0
- package/lib/cjs/fetch/utils.js +18 -0
- package/lib/cjs/index.d.ts +18 -0
- package/lib/cjs/index.js +57 -0
- package/lib/cjs/market/Market.d.ts +613 -0
- package/lib/cjs/market/Market.js +503 -0
- package/lib/cjs/market/MarketUtils.d.ts +189 -0
- package/lib/cjs/market/MarketUtils.js +303 -0
- package/lib/cjs/market/Position.d.ts +424 -0
- package/lib/cjs/market/Position.js +425 -0
- package/lib/cjs/market/PositionUtils.d.ts +115 -0
- package/lib/cjs/market/PositionUtils.js +194 -0
- package/lib/cjs/market/index.d.ts +4 -0
- package/lib/cjs/market/index.js +20 -0
- package/lib/cjs/math/ConsumableUnitsLib.d.ts +57 -0
- package/lib/cjs/math/ConsumableUnitsLib.js +77 -0
- package/lib/cjs/math/TakeAmountsLib.d.ts +175 -0
- package/lib/cjs/math/TakeAmountsLib.js +199 -0
- package/lib/cjs/math/TickLib.d.ts +200 -0
- package/lib/cjs/math/TickLib.js +272 -0
- package/lib/cjs/math/index.d.ts +3 -0
- package/lib/cjs/math/index.js +19 -0
- package/lib/cjs/offers/Offer.d.ts +534 -0
- package/lib/cjs/offers/Offer.js +343 -0
- package/lib/cjs/offers/OfferUtils.d.ts +565 -0
- package/lib/cjs/offers/OfferUtils.js +659 -0
- package/lib/cjs/offers/index.d.ts +2 -0
- package/lib/cjs/offers/index.js +18 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/queries/GetPosition.d.ts +55 -0
- package/lib/cjs/queries/GetPosition.js +74 -0
- package/lib/cjs/queries/index.d.ts +1 -0
- package/lib/cjs/queries/index.js +37 -0
- package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +733 -0
- package/lib/cjs/signatures/EcrecoverRatifierUtils.js +618 -0
- package/lib/cjs/signatures/Group.d.ts +178 -0
- package/lib/cjs/signatures/Group.js +193 -0
- package/lib/cjs/signatures/GroupUtils.d.ts +191 -0
- package/lib/cjs/signatures/GroupUtils.js +127 -0
- package/lib/cjs/signatures/Payload.d.ts +283 -0
- package/lib/cjs/signatures/Payload.js +570 -0
- package/lib/cjs/signatures/RatifierUtils.d.ts +109 -0
- package/lib/cjs/signatures/RatifierUtils.js +76 -0
- package/lib/cjs/signatures/SetterRatifierUtils.d.ts +243 -0
- package/lib/cjs/signatures/SetterRatifierUtils.js +217 -0
- package/lib/cjs/signatures/Tree.d.ts +241 -0
- package/lib/cjs/signatures/Tree.js +263 -0
- package/lib/cjs/signatures/TreeUtils.d.ts +573 -0
- package/lib/cjs/signatures/TreeUtils.js +461 -0
- package/lib/cjs/signatures/index.d.ts +7 -0
- package/lib/cjs/signatures/index.js +23 -0
- package/lib/esm/abis.d.ts +3170 -0
- package/lib/esm/abis.js +4070 -0
- package/lib/esm/api/MidnightApi.d.ts +532 -0
- package/lib/esm/api/MidnightApi.js +709 -0
- package/lib/esm/api/helpers.d.ts +20 -0
- package/lib/esm/api/helpers.js +180 -0
- package/lib/esm/api/index.d.ts +2 -0
- package/lib/esm/api/index.js +2 -0
- package/lib/esm/api/types.d.ts +453 -0
- package/lib/esm/api/types.js +1 -0
- package/lib/esm/constants.d.ts +168 -0
- package/lib/esm/constants.js +184 -0
- package/lib/esm/errors.d.ts +253 -0
- package/lib/esm/errors.js +291 -0
- package/lib/esm/fetch/Market.d.ts +65 -0
- package/lib/esm/fetch/Market.js +113 -0
- package/lib/esm/fetch/Offer.d.ts +74 -0
- package/lib/esm/fetch/Offer.js +116 -0
- package/lib/esm/fetch/Position.d.ts +85 -0
- package/lib/esm/fetch/Position.js +144 -0
- package/lib/esm/fetch/Ratifier.d.ts +38 -0
- package/lib/esm/fetch/Ratifier.js +54 -0
- package/lib/esm/fetch/index.d.ts +5 -0
- package/lib/esm/fetch/index.js +5 -0
- package/lib/esm/fetch/types.d.ts +57 -0
- package/lib/esm/fetch/types.js +1 -0
- package/lib/esm/fetch/utils.d.ts +8 -0
- package/lib/esm/fetch/utils.js +12 -0
- package/lib/esm/index.d.ts +18 -0
- package/lib/esm/index.js +18 -0
- package/lib/esm/market/Market.d.ts +613 -0
- package/lib/esm/market/Market.js +498 -0
- package/lib/esm/market/MarketUtils.d.ts +189 -0
- package/lib/esm/market/MarketUtils.js +300 -0
- package/lib/esm/market/Position.d.ts +424 -0
- package/lib/esm/market/Position.js +420 -0
- package/lib/esm/market/PositionUtils.d.ts +115 -0
- package/lib/esm/market/PositionUtils.js +191 -0
- package/lib/esm/market/index.d.ts +4 -0
- package/lib/esm/market/index.js +4 -0
- package/lib/esm/math/ConsumableUnitsLib.d.ts +57 -0
- package/lib/esm/math/ConsumableUnitsLib.js +74 -0
- package/lib/esm/math/TakeAmountsLib.d.ts +175 -0
- package/lib/esm/math/TakeAmountsLib.js +196 -0
- package/lib/esm/math/TickLib.d.ts +200 -0
- package/lib/esm/math/TickLib.js +269 -0
- package/lib/esm/math/index.d.ts +3 -0
- package/lib/esm/math/index.js +3 -0
- package/lib/esm/offers/Offer.d.ts +534 -0
- package/lib/esm/offers/Offer.js +339 -0
- package/lib/esm/offers/OfferUtils.d.ts +565 -0
- package/lib/esm/offers/OfferUtils.js +656 -0
- package/lib/esm/offers/index.d.ts +2 -0
- package/lib/esm/offers/index.js +2 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/queries/GetPosition.d.ts +55 -0
- package/lib/esm/queries/GetPosition.js +71 -0
- package/lib/esm/queries/index.d.ts +1 -0
- package/lib/esm/queries/index.js +1 -0
- package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +733 -0
- package/lib/esm/signatures/EcrecoverRatifierUtils.js +615 -0
- package/lib/esm/signatures/Group.d.ts +178 -0
- package/lib/esm/signatures/Group.js +189 -0
- package/lib/esm/signatures/GroupUtils.d.ts +191 -0
- package/lib/esm/signatures/GroupUtils.js +124 -0
- package/lib/esm/signatures/Payload.d.ts +283 -0
- package/lib/esm/signatures/Payload.js +564 -0
- package/lib/esm/signatures/RatifierUtils.d.ts +109 -0
- package/lib/esm/signatures/RatifierUtils.js +73 -0
- package/lib/esm/signatures/SetterRatifierUtils.d.ts +243 -0
- package/lib/esm/signatures/SetterRatifierUtils.js +214 -0
- package/lib/esm/signatures/Tree.d.ts +241 -0
- package/lib/esm/signatures/Tree.js +259 -0
- package/lib/esm/signatures/TreeUtils.d.ts +573 -0
- package/lib/esm/signatures/TreeUtils.js +458 -0
- package/lib/esm/signatures/index.d.ts +7 -0
- package/lib/esm/signatures/index.js +7 -0
- package/package.json +69 -0
- package/src/index.ts +19 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Offer = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const index_js_1 = require("../market/index.js");
|
|
6
|
+
const OfferUtils_js_1 = require("./OfferUtils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Maker-side Midnight offer.
|
|
9
|
+
*
|
|
10
|
+
* Build new maker offers with {@link Offer.create}, then pass them to
|
|
11
|
+
* `Group.create` for shared-consumption ladders or directly to `Tree.create`
|
|
12
|
+
* for standalone offers. API/take-side code can convert a plain `IOffer`
|
|
13
|
+
* into this class before ABI encoding. The class resolves the onchain `group`
|
|
14
|
+
* field lazily. Standalone offers derive their group id from the offer hash
|
|
15
|
+
* with the zero group id; `Group.create` copies offers and overrides the group
|
|
16
|
+
* on those copies when several offers share one consumption bucket. Offers
|
|
17
|
+
* hydrated from API or decoded data may also carry a known group id.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
22
|
+
*
|
|
23
|
+
* const offer = Offer.create({
|
|
24
|
+
* market: {
|
|
25
|
+
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
26
|
+
* collateralParams: [
|
|
27
|
+
* {
|
|
28
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
29
|
+
* lltv: 770000000000000000n,
|
|
30
|
+
* maxLif: 1061007957559681697n,
|
|
31
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
32
|
+
* },
|
|
33
|
+
* ],
|
|
34
|
+
* maturity: 1n,
|
|
35
|
+
* rcfThreshold: 0n,
|
|
36
|
+
* enterGate: "0x0000000000000000000000000000000000000000",
|
|
37
|
+
* liquidatorGate: "0x0000000000000000000000000000000000000000",
|
|
38
|
+
* },
|
|
39
|
+
* buy: false,
|
|
40
|
+
* maker: "0x0000000000000000000000000000000000000002",
|
|
41
|
+
* start: 0n,
|
|
42
|
+
* expiry: 2n,
|
|
43
|
+
* tick: 100n,
|
|
44
|
+
* callback: "0x0000000000000000000000000000000000000000",
|
|
45
|
+
* callbackData: "0x",
|
|
46
|
+
* receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000002",
|
|
47
|
+
* ratifier: "0x0000000000000000000000000000000000000003",
|
|
48
|
+
* reduceOnly: false,
|
|
49
|
+
* maxUnits: 100n,
|
|
50
|
+
* maxAssets: 0n,
|
|
51
|
+
* continuousFeeCap: 317097919n,
|
|
52
|
+
* });
|
|
53
|
+
* console.log(offer.buy);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
class Offer {
|
|
57
|
+
/** Market this offer trades. */
|
|
58
|
+
market;
|
|
59
|
+
/** Whether the maker buys units. */
|
|
60
|
+
buy;
|
|
61
|
+
/** Offer maker. */
|
|
62
|
+
maker;
|
|
63
|
+
/** Start timestamp. */
|
|
64
|
+
start;
|
|
65
|
+
/** Expiry timestamp. */
|
|
66
|
+
expiry;
|
|
67
|
+
/** Midnight tick. */
|
|
68
|
+
tick;
|
|
69
|
+
cachedGroup;
|
|
70
|
+
cachedHash;
|
|
71
|
+
/** Optional maker callback. */
|
|
72
|
+
callback;
|
|
73
|
+
/** Callback payload. */
|
|
74
|
+
callbackData;
|
|
75
|
+
/** Receiver used when maker is seller. */
|
|
76
|
+
receiverIfMakerIsSeller;
|
|
77
|
+
/** Ratifier contract. */
|
|
78
|
+
ratifier;
|
|
79
|
+
/** Whether the offer can only reduce maker exposure. */
|
|
80
|
+
reduceOnly;
|
|
81
|
+
/** Maximum units; zero means max assets controls consumption. */
|
|
82
|
+
maxUnits;
|
|
83
|
+
/** Maximum buyer or seller assets, depending on side. */
|
|
84
|
+
maxAssets;
|
|
85
|
+
/** Maximum market continuous fee accepted by this offer. */
|
|
86
|
+
continuousFeeCap;
|
|
87
|
+
constructor(offer) {
|
|
88
|
+
this.market = index_js_1.MarketParams.from(offer.market);
|
|
89
|
+
this.buy = offer.buy;
|
|
90
|
+
this.maker = offer.maker;
|
|
91
|
+
this.start = BigInt(offer.start);
|
|
92
|
+
this.expiry = BigInt(offer.expiry);
|
|
93
|
+
this.tick = BigInt(offer.tick);
|
|
94
|
+
this.cachedGroup = offer.group;
|
|
95
|
+
this.callback = offer.callback;
|
|
96
|
+
this.callbackData = offer.callbackData;
|
|
97
|
+
this.receiverIfMakerIsSeller = offer.receiverIfMakerIsSeller;
|
|
98
|
+
this.ratifier = offer.ratifier;
|
|
99
|
+
this.reduceOnly = offer.reduceOnly;
|
|
100
|
+
this.maxUnits = BigInt(offer.maxUnits);
|
|
101
|
+
this.maxAssets = BigInt(offer.maxAssets);
|
|
102
|
+
this.continuousFeeCap = BigInt(offer.continuousFeeCap);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns an offer instance from class or plain input.
|
|
106
|
+
*
|
|
107
|
+
* Use at boundaries that accept either maker-created `Offer` instances or
|
|
108
|
+
* decoded `IOffer` objects from an API response. For brand-new maker input,
|
|
109
|
+
* prefer {@link Offer.create} so deterministic parameters are validated first.
|
|
110
|
+
*
|
|
111
|
+
* @param offer - Offer class or plain input.
|
|
112
|
+
* @returns Offer instance.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
116
|
+
* import { zeroAddress } from "viem";
|
|
117
|
+
*
|
|
118
|
+
* const offer = Offer.from({
|
|
119
|
+
* market: {
|
|
120
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
121
|
+
* collateralParams: [
|
|
122
|
+
* {
|
|
123
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
124
|
+
* lltv: 770000000000000000n,
|
|
125
|
+
* maxLif: 1061007957559681697n,
|
|
126
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
127
|
+
* },
|
|
128
|
+
* ],
|
|
129
|
+
* maturity: 54_000n,
|
|
130
|
+
* rcfThreshold: 0n,
|
|
131
|
+
* enterGate: zeroAddress,
|
|
132
|
+
* liquidatorGate: zeroAddress,
|
|
133
|
+
* },
|
|
134
|
+
* buy: true,
|
|
135
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
136
|
+
* start: 0n,
|
|
137
|
+
* expiry: 3_600n,
|
|
138
|
+
* tick: 5_000n,
|
|
139
|
+
* callback: zeroAddress,
|
|
140
|
+
* callbackData: "0x",
|
|
141
|
+
* receiverIfMakerIsSeller: zeroAddress,
|
|
142
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
143
|
+
* reduceOnly: false,
|
|
144
|
+
* maxUnits: 100n,
|
|
145
|
+
* maxAssets: 0n,
|
|
146
|
+
* continuousFeeCap: 317097919n,
|
|
147
|
+
* });
|
|
148
|
+
* console.log(offer.buy);
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
static from(offer) {
|
|
152
|
+
return offer instanceof Offer ? offer : new Offer(offer);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Consumption group id encoded into this offer.
|
|
156
|
+
*
|
|
157
|
+
* When no group id was provided, the value is computed on first access by
|
|
158
|
+
* hashing this offer with the protocol zero group id. The computed value is
|
|
159
|
+
* cached because offer hashing is resource-intensive.
|
|
160
|
+
*
|
|
161
|
+
* @returns Consumption group id.
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
165
|
+
* import { zeroAddress } from "viem";
|
|
166
|
+
*
|
|
167
|
+
* const loanToken = "0x0000000000000000000000000000000000006000";
|
|
168
|
+
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
169
|
+
* const oracle = "0x0000000000000000000000000000000000008000";
|
|
170
|
+
* const maker = "0x0000000000000000000000000000000000009000";
|
|
171
|
+
* const ratifier = "0x0000000000000000000000000000000000004000";
|
|
172
|
+
*
|
|
173
|
+
* const offer = Offer.create({
|
|
174
|
+
* market: {
|
|
175
|
+
* loanToken,
|
|
176
|
+
* collateralParams: [
|
|
177
|
+
* {
|
|
178
|
+
* token: collateralToken,
|
|
179
|
+
* lltv: 770000000000000000n,
|
|
180
|
+
* maxLif: 1061007957559681697n,
|
|
181
|
+
* oracle,
|
|
182
|
+
* },
|
|
183
|
+
* ],
|
|
184
|
+
* maturity: 2_000n,
|
|
185
|
+
* rcfThreshold: 0n,
|
|
186
|
+
* enterGate: zeroAddress,
|
|
187
|
+
* liquidatorGate: zeroAddress,
|
|
188
|
+
* },
|
|
189
|
+
* buy: true,
|
|
190
|
+
* maker,
|
|
191
|
+
* tick: 5_000n,
|
|
192
|
+
* expiry: 2_100n,
|
|
193
|
+
* ratifier,
|
|
194
|
+
* maxAssets: 100n,
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* const group = offer.group;
|
|
198
|
+
* // group satisfies Hash
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
get group() {
|
|
202
|
+
this.cachedGroup ??= OfferUtils_js_1.OfferUtils.groupHash(this);
|
|
203
|
+
return this.cachedGroup;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Canonical protocol offer hash for this offer.
|
|
207
|
+
*
|
|
208
|
+
* The hash includes {@link Offer.group}. It is computed lazily and cached
|
|
209
|
+
* because hashing includes market hashing and ABI encoding.
|
|
210
|
+
*
|
|
211
|
+
* @returns Offer hash.
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
215
|
+
* import { zeroAddress } from "viem";
|
|
216
|
+
*
|
|
217
|
+
* const loanToken = "0x0000000000000000000000000000000000006000";
|
|
218
|
+
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
219
|
+
* const oracle = "0x0000000000000000000000000000000000008000";
|
|
220
|
+
* const maker = "0x0000000000000000000000000000000000009000";
|
|
221
|
+
* const ratifier = "0x0000000000000000000000000000000000004000";
|
|
222
|
+
*
|
|
223
|
+
* const offer = Offer.create({
|
|
224
|
+
* market: {
|
|
225
|
+
* loanToken,
|
|
226
|
+
* collateralParams: [
|
|
227
|
+
* {
|
|
228
|
+
* token: collateralToken,
|
|
229
|
+
* lltv: 770000000000000000n,
|
|
230
|
+
* maxLif: 1061007957559681697n,
|
|
231
|
+
* oracle,
|
|
232
|
+
* },
|
|
233
|
+
* ],
|
|
234
|
+
* maturity: 2_000n,
|
|
235
|
+
* rcfThreshold: 0n,
|
|
236
|
+
* enterGate: zeroAddress,
|
|
237
|
+
* liquidatorGate: zeroAddress,
|
|
238
|
+
* },
|
|
239
|
+
* buy: true,
|
|
240
|
+
* maker,
|
|
241
|
+
* tick: 5_000n,
|
|
242
|
+
* expiry: 2_100n,
|
|
243
|
+
* ratifier,
|
|
244
|
+
* maxAssets: 100n,
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* const hash = offer.hash;
|
|
248
|
+
* // hash satisfies Hash
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
get hash() {
|
|
252
|
+
this.cachedHash ??= OfferUtils_js_1.OfferUtils.hash(this);
|
|
253
|
+
return this.cachedHash;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Creates a validated maker-side Midnight offer.
|
|
257
|
+
*
|
|
258
|
+
* This is the first step of the make-side flow. After creation, pass related
|
|
259
|
+
* offers to `Group.create` when they share consumption, or pass standalone
|
|
260
|
+
* offers directly to `Tree.create`. Omit `group` for brand-new maker offers;
|
|
261
|
+
* provide it when hydrating an offer that already has a protocol group, such
|
|
262
|
+
* as an offer decoded from the API.
|
|
263
|
+
*
|
|
264
|
+
* @param params.market - Market params or hydrated market this offer trades.
|
|
265
|
+
* @param params.buy - Whether the maker buys loan assets.
|
|
266
|
+
* @param params.maker - Maker address.
|
|
267
|
+
* @param params.tick - Offer tick.
|
|
268
|
+
* @param params.group - Optional consumption group id for already-grouped offers.
|
|
269
|
+
* @param params.tickSpacing - Optional market tick spacing; defaults to `DEFAULT_TICK_SPACING`.
|
|
270
|
+
* @param params.maxUnits - Optional unit cap; defaults to zero.
|
|
271
|
+
* @param params.maxAssets - Optional buyer or seller asset cap; defaults to zero.
|
|
272
|
+
* @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `MAX_CONTINUOUS_FEE`.
|
|
273
|
+
* @param params.start - Optional offer start timestamp; defaults to zero.
|
|
274
|
+
* @param params.expiry - Offer expiry timestamp.
|
|
275
|
+
* @param params.callback - Optional callback address; defaults to the zero address.
|
|
276
|
+
* @param params.callbackData - Optional callback payload; defaults to `0x`.
|
|
277
|
+
* @param params.receiverIfMakerIsSeller - Optional receiver used when maker is seller.
|
|
278
|
+
* @param params.ratifier - Ratifier contract address.
|
|
279
|
+
* @param params.reduceOnly - Optional flag restricting the offer to exposure-reducing execution.
|
|
280
|
+
* @returns Offer instance.
|
|
281
|
+
* @throws {InvalidOfferParameterError} when the offer cannot satisfy protocol parameter rules.
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
285
|
+
* import { zeroAddress } from "viem";
|
|
286
|
+
*
|
|
287
|
+
* const loanToken = "0x0000000000000000000000000000000000006000";
|
|
288
|
+
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
289
|
+
* const oracle = "0x0000000000000000000000000000000000008000";
|
|
290
|
+
* const maker = "0x0000000000000000000000000000000000009000";
|
|
291
|
+
* const ratifier = "0x0000000000000000000000000000000000004000";
|
|
292
|
+
* const apiGroup =
|
|
293
|
+
* "0x1111111111111111111111111111111111111111111111111111111111111111";
|
|
294
|
+
*
|
|
295
|
+
* const offer = Offer.create({
|
|
296
|
+
* market: {
|
|
297
|
+
* loanToken,
|
|
298
|
+
* collateralParams: [
|
|
299
|
+
* {
|
|
300
|
+
* token: collateralToken,
|
|
301
|
+
* lltv: 770000000000000000n,
|
|
302
|
+
* maxLif: 1061007957559681697n,
|
|
303
|
+
* oracle,
|
|
304
|
+
* },
|
|
305
|
+
* ],
|
|
306
|
+
* maturity: 2_000n,
|
|
307
|
+
* rcfThreshold: 0n,
|
|
308
|
+
* enterGate: zeroAddress,
|
|
309
|
+
* liquidatorGate: zeroAddress,
|
|
310
|
+
* },
|
|
311
|
+
* buy: true,
|
|
312
|
+
* maker,
|
|
313
|
+
* tick: 5_000n,
|
|
314
|
+
* group: apiGroup,
|
|
315
|
+
* expiry: 2_100n,
|
|
316
|
+
* ratifier,
|
|
317
|
+
* maxAssets: 100n,
|
|
318
|
+
* });
|
|
319
|
+
* // offer satisfies Offer
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
static create(params) {
|
|
323
|
+
const validated = OfferUtils_js_1.OfferUtils.validateOfferParams(params);
|
|
324
|
+
return new Offer({
|
|
325
|
+
market: params.market,
|
|
326
|
+
buy: params.buy,
|
|
327
|
+
maker: params.maker,
|
|
328
|
+
start: validated.start,
|
|
329
|
+
expiry: validated.expiry,
|
|
330
|
+
tick: validated.tick,
|
|
331
|
+
group: params.group,
|
|
332
|
+
callback: params.callback ?? viem_1.zeroAddress,
|
|
333
|
+
callbackData: params.callbackData ?? "0x",
|
|
334
|
+
receiverIfMakerIsSeller: validated.receiverIfMakerIsSeller,
|
|
335
|
+
ratifier: params.ratifier,
|
|
336
|
+
reduceOnly: params.reduceOnly ?? false,
|
|
337
|
+
maxUnits: validated.maxUnits,
|
|
338
|
+
maxAssets: validated.maxAssets,
|
|
339
|
+
continuousFeeCap: validated.continuousFeeCap,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
exports.Offer = Offer;
|