@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,534 @@
|
|
|
1
|
+
import type { BigIntish } from "@morpho-org/morpho-ts";
|
|
2
|
+
import type { Address, Hash, Hex } from "viem";
|
|
3
|
+
import { type IMarket, type IMarketParams, MarketParams } from "../market/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Plain make-side offer input accepted by {@link Offer}.
|
|
6
|
+
*
|
|
7
|
+
* Use this shape when app or API data is already protocol-shaped and needs to
|
|
8
|
+
* flow into `Offer.from`, `Group.create`, `Tree.create`, or
|
|
9
|
+
* take-side conversion helpers. Use {@link Offer.create} instead for new maker
|
|
10
|
+
* offers so deterministic fields are validated before grouping or signing.
|
|
11
|
+
* The `group` field is optional. When omitted, {@link Offer.group} lazily
|
|
12
|
+
* derives the standalone group id from this offer hashed with the protocol
|
|
13
|
+
* zero group id. `Group.create` copies offers into a shared group and overrides
|
|
14
|
+
* this field on the copies it owns.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { IOffer } from "@morpho-org/midnight-sdk";
|
|
19
|
+
*
|
|
20
|
+
* const offer: IOffer = {
|
|
21
|
+
* market: {
|
|
22
|
+
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
23
|
+
* collateralParams: [
|
|
24
|
+
* {
|
|
25
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
26
|
+
* lltv: 770000000000000000n,
|
|
27
|
+
* maxLif: 1061007957559681697n,
|
|
28
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
29
|
+
* },
|
|
30
|
+
* ],
|
|
31
|
+
* maturity: 1n,
|
|
32
|
+
* rcfThreshold: 0n,
|
|
33
|
+
* enterGate: "0x0000000000000000000000000000000000000000",
|
|
34
|
+
* liquidatorGate: "0x0000000000000000000000000000000000000000",
|
|
35
|
+
* },
|
|
36
|
+
* buy: true,
|
|
37
|
+
* maker: "0x0000000000000000000000000000000000000002",
|
|
38
|
+
* start: 0n,
|
|
39
|
+
* expiry: 2n,
|
|
40
|
+
* tick: 100n,
|
|
41
|
+
* callback: "0x0000000000000000000000000000000000000000",
|
|
42
|
+
* callbackData: "0x",
|
|
43
|
+
* receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000000",
|
|
44
|
+
* ratifier: "0x0000000000000000000000000000000000000003",
|
|
45
|
+
* reduceOnly: false,
|
|
46
|
+
* maxUnits: 0n,
|
|
47
|
+
* maxAssets: 100n,
|
|
48
|
+
* continuousFeeCap: 317097919n,
|
|
49
|
+
* };
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export interface IOffer {
|
|
53
|
+
/** Market this offer trades. */
|
|
54
|
+
readonly market: IMarketParams | IMarket;
|
|
55
|
+
/** Whether the maker buys units. */
|
|
56
|
+
readonly buy: boolean;
|
|
57
|
+
/** Offer maker. */
|
|
58
|
+
readonly maker: Address;
|
|
59
|
+
/** Start timestamp. */
|
|
60
|
+
readonly start: BigIntish;
|
|
61
|
+
/** Expiry timestamp. */
|
|
62
|
+
readonly expiry: BigIntish;
|
|
63
|
+
/** Midnight tick. */
|
|
64
|
+
readonly tick: BigIntish;
|
|
65
|
+
/** Consumption group id; defaults to the offer hash with the zero group id. */
|
|
66
|
+
readonly group?: Hash;
|
|
67
|
+
/** Optional maker callback. */
|
|
68
|
+
readonly callback: Address;
|
|
69
|
+
/** Callback payload. */
|
|
70
|
+
readonly callbackData: Hex;
|
|
71
|
+
/** Receiver used when the maker is the seller. */
|
|
72
|
+
readonly receiverIfMakerIsSeller: Address;
|
|
73
|
+
/** Ratifier contract. */
|
|
74
|
+
readonly ratifier: Address;
|
|
75
|
+
/** Whether the offer can only reduce maker exposure. */
|
|
76
|
+
readonly reduceOnly: boolean;
|
|
77
|
+
/** Maximum units; zero means max assets controls consumption. */
|
|
78
|
+
readonly maxUnits: BigIntish;
|
|
79
|
+
/** Maximum buyer or seller assets, depending on side. */
|
|
80
|
+
readonly maxAssets: BigIntish;
|
|
81
|
+
/** Maximum market continuous fee accepted by this offer. */
|
|
82
|
+
readonly continuousFeeCap: BigIntish;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Maker-side Midnight offer.
|
|
86
|
+
*
|
|
87
|
+
* Build new maker offers with {@link Offer.create}, then pass them to
|
|
88
|
+
* `Group.create` for shared-consumption ladders or directly to `Tree.create`
|
|
89
|
+
* for standalone offers. API/take-side code can convert a plain `IOffer`
|
|
90
|
+
* into this class before ABI encoding. The class resolves the onchain `group`
|
|
91
|
+
* field lazily. Standalone offers derive their group id from the offer hash
|
|
92
|
+
* with the zero group id; `Group.create` copies offers and overrides the group
|
|
93
|
+
* on those copies when several offers share one consumption bucket. Offers
|
|
94
|
+
* hydrated from API or decoded data may also carry a known group id.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
99
|
+
*
|
|
100
|
+
* const offer = Offer.create({
|
|
101
|
+
* market: {
|
|
102
|
+
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
103
|
+
* collateralParams: [
|
|
104
|
+
* {
|
|
105
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
106
|
+
* lltv: 770000000000000000n,
|
|
107
|
+
* maxLif: 1061007957559681697n,
|
|
108
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
109
|
+
* },
|
|
110
|
+
* ],
|
|
111
|
+
* maturity: 1n,
|
|
112
|
+
* rcfThreshold: 0n,
|
|
113
|
+
* enterGate: "0x0000000000000000000000000000000000000000",
|
|
114
|
+
* liquidatorGate: "0x0000000000000000000000000000000000000000",
|
|
115
|
+
* },
|
|
116
|
+
* buy: false,
|
|
117
|
+
* maker: "0x0000000000000000000000000000000000000002",
|
|
118
|
+
* start: 0n,
|
|
119
|
+
* expiry: 2n,
|
|
120
|
+
* tick: 100n,
|
|
121
|
+
* callback: "0x0000000000000000000000000000000000000000",
|
|
122
|
+
* callbackData: "0x",
|
|
123
|
+
* receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000002",
|
|
124
|
+
* ratifier: "0x0000000000000000000000000000000000000003",
|
|
125
|
+
* reduceOnly: false,
|
|
126
|
+
* maxUnits: 100n,
|
|
127
|
+
* maxAssets: 0n,
|
|
128
|
+
* continuousFeeCap: 317097919n,
|
|
129
|
+
* });
|
|
130
|
+
* console.log(offer.buy);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare class Offer {
|
|
134
|
+
/** Market this offer trades. */
|
|
135
|
+
readonly market: MarketParams;
|
|
136
|
+
/** Whether the maker buys units. */
|
|
137
|
+
readonly buy: boolean;
|
|
138
|
+
/** Offer maker. */
|
|
139
|
+
readonly maker: Address;
|
|
140
|
+
/** Start timestamp. */
|
|
141
|
+
readonly start: bigint;
|
|
142
|
+
/** Expiry timestamp. */
|
|
143
|
+
readonly expiry: bigint;
|
|
144
|
+
/** Midnight tick. */
|
|
145
|
+
readonly tick: bigint;
|
|
146
|
+
private cachedGroup;
|
|
147
|
+
private cachedHash;
|
|
148
|
+
/** Optional maker callback. */
|
|
149
|
+
readonly callback: Address;
|
|
150
|
+
/** Callback payload. */
|
|
151
|
+
readonly callbackData: Hex;
|
|
152
|
+
/** Receiver used when maker is seller. */
|
|
153
|
+
readonly receiverIfMakerIsSeller: Address;
|
|
154
|
+
/** Ratifier contract. */
|
|
155
|
+
readonly ratifier: Address;
|
|
156
|
+
/** Whether the offer can only reduce maker exposure. */
|
|
157
|
+
readonly reduceOnly: boolean;
|
|
158
|
+
/** Maximum units; zero means max assets controls consumption. */
|
|
159
|
+
readonly maxUnits: bigint;
|
|
160
|
+
/** Maximum buyer or seller assets, depending on side. */
|
|
161
|
+
readonly maxAssets: bigint;
|
|
162
|
+
/** Maximum market continuous fee accepted by this offer. */
|
|
163
|
+
readonly continuousFeeCap: bigint;
|
|
164
|
+
constructor(offer: IOffer);
|
|
165
|
+
/**
|
|
166
|
+
* Returns an offer instance from class or plain input.
|
|
167
|
+
*
|
|
168
|
+
* Use at boundaries that accept either maker-created `Offer` instances or
|
|
169
|
+
* decoded `IOffer` objects from an API response. For brand-new maker input,
|
|
170
|
+
* prefer {@link Offer.create} so deterministic parameters are validated first.
|
|
171
|
+
*
|
|
172
|
+
* @param offer - Offer class or plain input.
|
|
173
|
+
* @returns Offer instance.
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
177
|
+
* import { zeroAddress } from "viem";
|
|
178
|
+
*
|
|
179
|
+
* const offer = Offer.from({
|
|
180
|
+
* market: {
|
|
181
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
182
|
+
* collateralParams: [
|
|
183
|
+
* {
|
|
184
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
185
|
+
* lltv: 770000000000000000n,
|
|
186
|
+
* maxLif: 1061007957559681697n,
|
|
187
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
188
|
+
* },
|
|
189
|
+
* ],
|
|
190
|
+
* maturity: 54_000n,
|
|
191
|
+
* rcfThreshold: 0n,
|
|
192
|
+
* enterGate: zeroAddress,
|
|
193
|
+
* liquidatorGate: zeroAddress,
|
|
194
|
+
* },
|
|
195
|
+
* buy: true,
|
|
196
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
197
|
+
* start: 0n,
|
|
198
|
+
* expiry: 3_600n,
|
|
199
|
+
* tick: 5_000n,
|
|
200
|
+
* callback: zeroAddress,
|
|
201
|
+
* callbackData: "0x",
|
|
202
|
+
* receiverIfMakerIsSeller: zeroAddress,
|
|
203
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
204
|
+
* reduceOnly: false,
|
|
205
|
+
* maxUnits: 100n,
|
|
206
|
+
* maxAssets: 0n,
|
|
207
|
+
* continuousFeeCap: 317097919n,
|
|
208
|
+
* });
|
|
209
|
+
* console.log(offer.buy);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
static from(offer: IOffer): Offer;
|
|
213
|
+
/**
|
|
214
|
+
* Consumption group id encoded into this offer.
|
|
215
|
+
*
|
|
216
|
+
* When no group id was provided, the value is computed on first access by
|
|
217
|
+
* hashing this offer with the protocol zero group id. The computed value is
|
|
218
|
+
* cached because offer hashing is resource-intensive.
|
|
219
|
+
*
|
|
220
|
+
* @returns Consumption group id.
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
224
|
+
* import { zeroAddress } from "viem";
|
|
225
|
+
*
|
|
226
|
+
* const loanToken = "0x0000000000000000000000000000000000006000";
|
|
227
|
+
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
228
|
+
* const oracle = "0x0000000000000000000000000000000000008000";
|
|
229
|
+
* const maker = "0x0000000000000000000000000000000000009000";
|
|
230
|
+
* const ratifier = "0x0000000000000000000000000000000000004000";
|
|
231
|
+
*
|
|
232
|
+
* const offer = Offer.create({
|
|
233
|
+
* market: {
|
|
234
|
+
* loanToken,
|
|
235
|
+
* collateralParams: [
|
|
236
|
+
* {
|
|
237
|
+
* token: collateralToken,
|
|
238
|
+
* lltv: 770000000000000000n,
|
|
239
|
+
* maxLif: 1061007957559681697n,
|
|
240
|
+
* oracle,
|
|
241
|
+
* },
|
|
242
|
+
* ],
|
|
243
|
+
* maturity: 2_000n,
|
|
244
|
+
* rcfThreshold: 0n,
|
|
245
|
+
* enterGate: zeroAddress,
|
|
246
|
+
* liquidatorGate: zeroAddress,
|
|
247
|
+
* },
|
|
248
|
+
* buy: true,
|
|
249
|
+
* maker,
|
|
250
|
+
* tick: 5_000n,
|
|
251
|
+
* expiry: 2_100n,
|
|
252
|
+
* ratifier,
|
|
253
|
+
* maxAssets: 100n,
|
|
254
|
+
* });
|
|
255
|
+
*
|
|
256
|
+
* const group = offer.group;
|
|
257
|
+
* // group satisfies Hash
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
get group(): Hash;
|
|
261
|
+
/**
|
|
262
|
+
* Canonical protocol offer hash for this offer.
|
|
263
|
+
*
|
|
264
|
+
* The hash includes {@link Offer.group}. It is computed lazily and cached
|
|
265
|
+
* because hashing includes market hashing and ABI encoding.
|
|
266
|
+
*
|
|
267
|
+
* @returns Offer hash.
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
271
|
+
* import { zeroAddress } from "viem";
|
|
272
|
+
*
|
|
273
|
+
* const loanToken = "0x0000000000000000000000000000000000006000";
|
|
274
|
+
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
275
|
+
* const oracle = "0x0000000000000000000000000000000000008000";
|
|
276
|
+
* const maker = "0x0000000000000000000000000000000000009000";
|
|
277
|
+
* const ratifier = "0x0000000000000000000000000000000000004000";
|
|
278
|
+
*
|
|
279
|
+
* const offer = Offer.create({
|
|
280
|
+
* market: {
|
|
281
|
+
* loanToken,
|
|
282
|
+
* collateralParams: [
|
|
283
|
+
* {
|
|
284
|
+
* token: collateralToken,
|
|
285
|
+
* lltv: 770000000000000000n,
|
|
286
|
+
* maxLif: 1061007957559681697n,
|
|
287
|
+
* oracle,
|
|
288
|
+
* },
|
|
289
|
+
* ],
|
|
290
|
+
* maturity: 2_000n,
|
|
291
|
+
* rcfThreshold: 0n,
|
|
292
|
+
* enterGate: zeroAddress,
|
|
293
|
+
* liquidatorGate: zeroAddress,
|
|
294
|
+
* },
|
|
295
|
+
* buy: true,
|
|
296
|
+
* maker,
|
|
297
|
+
* tick: 5_000n,
|
|
298
|
+
* expiry: 2_100n,
|
|
299
|
+
* ratifier,
|
|
300
|
+
* maxAssets: 100n,
|
|
301
|
+
* });
|
|
302
|
+
*
|
|
303
|
+
* const hash = offer.hash;
|
|
304
|
+
* // hash satisfies Hash
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
get hash(): Hash;
|
|
308
|
+
/**
|
|
309
|
+
* Creates a validated maker-side Midnight offer.
|
|
310
|
+
*
|
|
311
|
+
* This is the first step of the make-side flow. After creation, pass related
|
|
312
|
+
* offers to `Group.create` when they share consumption, or pass standalone
|
|
313
|
+
* offers directly to `Tree.create`. Omit `group` for brand-new maker offers;
|
|
314
|
+
* provide it when hydrating an offer that already has a protocol group, such
|
|
315
|
+
* as an offer decoded from the API.
|
|
316
|
+
*
|
|
317
|
+
* @param params.market - Market params or hydrated market this offer trades.
|
|
318
|
+
* @param params.buy - Whether the maker buys loan assets.
|
|
319
|
+
* @param params.maker - Maker address.
|
|
320
|
+
* @param params.tick - Offer tick.
|
|
321
|
+
* @param params.group - Optional consumption group id for already-grouped offers.
|
|
322
|
+
* @param params.tickSpacing - Optional market tick spacing; defaults to `DEFAULT_TICK_SPACING`.
|
|
323
|
+
* @param params.maxUnits - Optional unit cap; defaults to zero.
|
|
324
|
+
* @param params.maxAssets - Optional buyer or seller asset cap; defaults to zero.
|
|
325
|
+
* @param params.continuousFeeCap - Optional maximum market continuous fee accepted by this offer; defaults to `MAX_CONTINUOUS_FEE`.
|
|
326
|
+
* @param params.start - Optional offer start timestamp; defaults to zero.
|
|
327
|
+
* @param params.expiry - Offer expiry timestamp.
|
|
328
|
+
* @param params.callback - Optional callback address; defaults to the zero address.
|
|
329
|
+
* @param params.callbackData - Optional callback payload; defaults to `0x`.
|
|
330
|
+
* @param params.receiverIfMakerIsSeller - Optional receiver used when maker is seller.
|
|
331
|
+
* @param params.ratifier - Ratifier contract address.
|
|
332
|
+
* @param params.reduceOnly - Optional flag restricting the offer to exposure-reducing execution.
|
|
333
|
+
* @returns Offer instance.
|
|
334
|
+
* @throws {InvalidOfferParameterError} when the offer cannot satisfy protocol parameter rules.
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* import { Offer } from "@morpho-org/midnight-sdk";
|
|
338
|
+
* import { zeroAddress } from "viem";
|
|
339
|
+
*
|
|
340
|
+
* const loanToken = "0x0000000000000000000000000000000000006000";
|
|
341
|
+
* const collateralToken = "0x0000000000000000000000000000000000007000";
|
|
342
|
+
* const oracle = "0x0000000000000000000000000000000000008000";
|
|
343
|
+
* const maker = "0x0000000000000000000000000000000000009000";
|
|
344
|
+
* const ratifier = "0x0000000000000000000000000000000000004000";
|
|
345
|
+
* const apiGroup =
|
|
346
|
+
* "0x1111111111111111111111111111111111111111111111111111111111111111";
|
|
347
|
+
*
|
|
348
|
+
* const offer = Offer.create({
|
|
349
|
+
* market: {
|
|
350
|
+
* loanToken,
|
|
351
|
+
* collateralParams: [
|
|
352
|
+
* {
|
|
353
|
+
* token: collateralToken,
|
|
354
|
+
* lltv: 770000000000000000n,
|
|
355
|
+
* maxLif: 1061007957559681697n,
|
|
356
|
+
* oracle,
|
|
357
|
+
* },
|
|
358
|
+
* ],
|
|
359
|
+
* maturity: 2_000n,
|
|
360
|
+
* rcfThreshold: 0n,
|
|
361
|
+
* enterGate: zeroAddress,
|
|
362
|
+
* liquidatorGate: zeroAddress,
|
|
363
|
+
* },
|
|
364
|
+
* buy: true,
|
|
365
|
+
* maker,
|
|
366
|
+
* tick: 5_000n,
|
|
367
|
+
* group: apiGroup,
|
|
368
|
+
* expiry: 2_100n,
|
|
369
|
+
* ratifier,
|
|
370
|
+
* maxAssets: 100n,
|
|
371
|
+
* });
|
|
372
|
+
* // offer satisfies Offer
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
static create(params: BuildOfferParams): Offer;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* ABI tuple shape for `Offer`.
|
|
379
|
+
*
|
|
380
|
+
* This is the shape consumed by viem encoders, Merkle leaf hashing, payload
|
|
381
|
+
* encoding, and take calldata encoders. Build it with `OfferUtils.toStruct` or
|
|
382
|
+
* `GroupUtils.toStructs`; grouped encoders derive a shared group id from the
|
|
383
|
+
* offer list, while single-offer encoders read the offer's group unless an
|
|
384
|
+
* explicit override is supplied.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* import type { OfferStruct } from "@morpho-org/midnight-sdk";
|
|
389
|
+
* import { zeroAddress, zeroHash } from "viem";
|
|
390
|
+
*
|
|
391
|
+
* const offer: OfferStruct = {
|
|
392
|
+
* market: {
|
|
393
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
394
|
+
* collateralParams: [
|
|
395
|
+
* {
|
|
396
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
397
|
+
* lltv: 770000000000000000n,
|
|
398
|
+
* maxLif: 1061007957559681697n,
|
|
399
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
400
|
+
* },
|
|
401
|
+
* ],
|
|
402
|
+
* maturity: 2_000n,
|
|
403
|
+
* rcfThreshold: 0n,
|
|
404
|
+
* enterGate: zeroAddress,
|
|
405
|
+
* liquidatorGate: zeroAddress,
|
|
406
|
+
* },
|
|
407
|
+
* buy: true,
|
|
408
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
409
|
+
* start: 0n,
|
|
410
|
+
* expiry: 2_100n,
|
|
411
|
+
* tick: 5_000n,
|
|
412
|
+
* group: zeroHash,
|
|
413
|
+
* callback: zeroAddress,
|
|
414
|
+
* callbackData: "0x",
|
|
415
|
+
* receiverIfMakerIsSeller: zeroAddress,
|
|
416
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
417
|
+
* reduceOnly: false,
|
|
418
|
+
* maxUnits: 0n,
|
|
419
|
+
* maxAssets: 100n,
|
|
420
|
+
* continuousFeeCap: 317097919n,
|
|
421
|
+
* };
|
|
422
|
+
* console.log(offer.group);
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
export interface OfferStruct {
|
|
426
|
+
/** Market this offer trades. */
|
|
427
|
+
readonly market: MarketParams;
|
|
428
|
+
/** Whether the maker buys units. */
|
|
429
|
+
readonly buy: boolean;
|
|
430
|
+
/** Offer maker. */
|
|
431
|
+
readonly maker: Address;
|
|
432
|
+
/** Start timestamp. */
|
|
433
|
+
readonly start: bigint;
|
|
434
|
+
/** Expiry timestamp. */
|
|
435
|
+
readonly expiry: bigint;
|
|
436
|
+
/** Midnight tick. */
|
|
437
|
+
readonly tick: bigint;
|
|
438
|
+
/** Consumption group. */
|
|
439
|
+
readonly group: Hash;
|
|
440
|
+
/** Optional maker callback. */
|
|
441
|
+
readonly callback: Address;
|
|
442
|
+
/** Callback payload. */
|
|
443
|
+
readonly callbackData: Hex;
|
|
444
|
+
/** Receiver used when maker is seller. */
|
|
445
|
+
readonly receiverIfMakerIsSeller: Address;
|
|
446
|
+
/** Ratifier contract. */
|
|
447
|
+
readonly ratifier: Address;
|
|
448
|
+
/** Whether the offer can only reduce maker exposure. */
|
|
449
|
+
readonly reduceOnly: boolean;
|
|
450
|
+
/** Maximum units; zero means max assets controls consumption. */
|
|
451
|
+
readonly maxUnits: bigint;
|
|
452
|
+
/** Maximum buyer or seller assets, depending on side. */
|
|
453
|
+
readonly maxAssets: bigint;
|
|
454
|
+
/** Maximum market continuous fee accepted by this offer. */
|
|
455
|
+
readonly continuousFeeCap: bigint;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Parameters for {@link Offer.create}.
|
|
459
|
+
*
|
|
460
|
+
* These are make-side parameters entered by a maker or order-management app
|
|
461
|
+
* before any tree, ratifier data, or mempool payload exists. The optional
|
|
462
|
+
* `group` field is useful when instantiating an offer that already belongs to a
|
|
463
|
+
* protocol group, such as an offer returned by the Midnight API. Omit it for
|
|
464
|
+
* fresh maker-side offers that will be grouped with `Group.create`.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* import type { BuildOfferParams } from "@morpho-org/midnight-sdk";
|
|
469
|
+
* import { zeroAddress } from "viem";
|
|
470
|
+
*
|
|
471
|
+
* const params: BuildOfferParams = {
|
|
472
|
+
* market: {
|
|
473
|
+
* loanToken: "0x0000000000000000000000000000000000006000",
|
|
474
|
+
* collateralParams: [
|
|
475
|
+
* {
|
|
476
|
+
* token: "0x0000000000000000000000000000000000007000",
|
|
477
|
+
* lltv: 770000000000000000n,
|
|
478
|
+
* maxLif: 1061007957559681697n,
|
|
479
|
+
* oracle: "0x0000000000000000000000000000000000008000",
|
|
480
|
+
* },
|
|
481
|
+
* ],
|
|
482
|
+
* maturity: 2_000n,
|
|
483
|
+
* rcfThreshold: 0n,
|
|
484
|
+
* enterGate: zeroAddress,
|
|
485
|
+
* liquidatorGate: zeroAddress,
|
|
486
|
+
* },
|
|
487
|
+
* buy: true,
|
|
488
|
+
* maker: "0x0000000000000000000000000000000000009000",
|
|
489
|
+
* tick: 5_000n,
|
|
490
|
+
* group: "0x1111111111111111111111111111111111111111111111111111111111111111",
|
|
491
|
+
* expiry: 2_100n,
|
|
492
|
+
* ratifier: "0x0000000000000000000000000000000000004000",
|
|
493
|
+
* maxAssets: 100n,
|
|
494
|
+
* };
|
|
495
|
+
* console.log(params.group);
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
export interface BuildOfferParams {
|
|
499
|
+
/** Market this offer trades. */
|
|
500
|
+
readonly market: IMarketParams | IMarket;
|
|
501
|
+
/** Whether the maker buys units. */
|
|
502
|
+
readonly buy: boolean;
|
|
503
|
+
/** Maker address. */
|
|
504
|
+
readonly maker: Address;
|
|
505
|
+
/** Tick. */
|
|
506
|
+
readonly tick: BigIntish;
|
|
507
|
+
/**
|
|
508
|
+
* Optional consumption group id for already-grouped offers, such as offers
|
|
509
|
+
* decoded from the API. Omit for fresh maker-side offers.
|
|
510
|
+
*/
|
|
511
|
+
readonly group?: Hash;
|
|
512
|
+
/** Market tick spacing; defaults to the protocol's default spacing. */
|
|
513
|
+
readonly tickSpacing?: BigIntish;
|
|
514
|
+
/** Maximum units; defaults to zero. Exactly one of `maxUnits` and `maxAssets` must be non-zero. */
|
|
515
|
+
readonly maxUnits?: BigIntish;
|
|
516
|
+
/** Maximum buyer or seller assets; defaults to zero. Exactly one of `maxUnits` and `maxAssets` must be non-zero. */
|
|
517
|
+
readonly maxAssets?: BigIntish;
|
|
518
|
+
/** Maximum market continuous fee accepted by this offer; defaults to the protocol maximum. */
|
|
519
|
+
readonly continuousFeeCap?: BigIntish;
|
|
520
|
+
/** Offer start timestamp; defaults to zero. */
|
|
521
|
+
readonly start?: BigIntish;
|
|
522
|
+
/** Offer expiry timestamp. */
|
|
523
|
+
readonly expiry: BigIntish;
|
|
524
|
+
/** Callback address; defaults to zero address. */
|
|
525
|
+
readonly callback?: Address;
|
|
526
|
+
/** Callback payload; defaults to `0x`. */
|
|
527
|
+
readonly callbackData?: Hex;
|
|
528
|
+
/** Receiver used when maker is seller; defaults to zero for buy offers and maker for sell offers. */
|
|
529
|
+
readonly receiverIfMakerIsSeller?: Address;
|
|
530
|
+
/** Ratifier contract. */
|
|
531
|
+
readonly ratifier: Address;
|
|
532
|
+
/** Whether the offer can only reduce maker exposure. */
|
|
533
|
+
readonly reduceOnly?: boolean;
|
|
534
|
+
}
|