@morpho-org/midnight-sdk 1.8.0 → 2.1.0-next.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/MIGRATION-v1-to-v2.md +6 -0
- package/README.md +17 -15
- package/lib/cjs/abis.d.ts +1870 -1461
- package/lib/cjs/abis.js +2151 -1626
- package/lib/cjs/api/MidnightApi.d.ts +10 -8
- package/lib/cjs/api/MidnightApi.js +13 -11
- package/lib/cjs/api/helpers.d.ts +2 -18
- package/lib/cjs/api/helpers.js +4 -5
- package/lib/cjs/api/types.d.ts +6 -5
- package/lib/cjs/api/version.generated.d.ts +1 -1
- package/lib/cjs/api/version.generated.js +2 -2
- package/lib/cjs/bundlesV2.d.ts +15 -0
- package/lib/cjs/bundlesV2.js +2 -0
- package/lib/cjs/errors.d.ts +13 -27
- package/lib/cjs/errors.js +8 -39
- package/lib/cjs/fetch/Ratifier.js +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/position/PositionUtils.js +11 -35
- package/lib/esm/abis.d.ts +1870 -1461
- package/lib/esm/abis.js +2150 -1625
- package/lib/esm/api/MidnightApi.d.ts +10 -8
- package/lib/esm/api/MidnightApi.js +13 -11
- package/lib/esm/api/helpers.d.ts +2 -18
- package/lib/esm/api/helpers.js +8 -5
- package/lib/esm/api/types.d.ts +6 -5
- package/lib/esm/api/version.generated.d.ts +1 -1
- package/lib/esm/api/version.generated.js +2 -2
- package/lib/esm/bundlesV2.d.ts +15 -0
- package/lib/esm/bundlesV2.js +1 -0
- package/lib/esm/errors.d.ts +13 -27
- package/lib/esm/errors.js +8 -36
- package/lib/esm/fetch/Ratifier.js +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/position/PositionUtils.js +12 -36
- package/package.json +8 -7
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Migrating from midnight-sdk v1 to v2
|
|
2
|
+
|
|
3
|
+
midnight-sdk v2 removes `midnightBundlesAbi` (MidnightBundles V1). Use `midnightBundlesV2Abi`
|
|
4
|
+
against the `midnightBundlesV2` address. V2 acts for `msg.sender` (no `taker` argument), takes no
|
|
5
|
+
inline token permits, and takes the `Market` struct as its first argument; the README's atomic-take
|
|
6
|
+
recipe shows the V2 call. Integrations that still call V1 must pin midnight-sdk v1.
|
package/README.md
CHANGED
|
@@ -153,7 +153,7 @@ book `bids` are maker buy offers.
|
|
|
153
153
|
The quote's `averageWorstPrice` is an **aggregate** guard over the requested target: a favorable
|
|
154
154
|
offer can compensate for a worse one, and the worse offer does not satisfy the guard on its own.
|
|
155
155
|
That guard only holds if every returned offer settles together, so execute a quote through
|
|
156
|
-
`
|
|
156
|
+
`MidnightBundlesV2` in a single transaction. The bundle skips offers that became stale since the
|
|
157
157
|
quote, reverts unless the exact target is reached, and enforces one aggregate consideration bound
|
|
158
158
|
(`maxBuyerAssets` for asks, `minSellerAssets` for bids). Never split a quote into independent
|
|
159
159
|
`Midnight.take` transactions: a stale first leg reverts but still consumes its nonce, so the
|
|
@@ -164,7 +164,7 @@ and resolve approvals for you; the recipe below shows the same route with this p
|
|
|
164
164
|
```ts
|
|
165
165
|
import { getChainAddress, MathLib } from "@morpho-org/morpho-ts";
|
|
166
166
|
import { MidnightApi } from "@morpho-org/midnight-sdk/api";
|
|
167
|
-
import {
|
|
167
|
+
import { midnightBundlesV2Abi, type MarketParams } from "@morpho-org/midnight-sdk";
|
|
168
168
|
import {
|
|
169
169
|
maxUint256,
|
|
170
170
|
parseUnits,
|
|
@@ -176,11 +176,14 @@ import {
|
|
|
176
176
|
import { base } from "viem/chains";
|
|
177
177
|
|
|
178
178
|
const chainId = base.id;
|
|
179
|
-
|
|
179
|
+
// Throws `UnknownAddressError` until the chain's `midnightBundlesV2` is pinned in morpho-ts or
|
|
180
|
+
// registered with `registerCustomAddresses`.
|
|
181
|
+
const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
|
|
180
182
|
|
|
181
183
|
export async function takeAskQuoteAtomically(params: {
|
|
182
184
|
readonly walletClient: WalletClient;
|
|
183
185
|
readonly taker: Address;
|
|
186
|
+
readonly market: MarketParams;
|
|
184
187
|
readonly marketId: Hash;
|
|
185
188
|
readonly deadline: bigint;
|
|
186
189
|
}) {
|
|
@@ -197,24 +200,22 @@ export async function takeAskQuoteAtomically(params: {
|
|
|
197
200
|
// not what the caller asked for.
|
|
198
201
|
const maxBuyerAssets = MathLib.wMulUp(targetUnits, quote.data.averageWorstPrice);
|
|
199
202
|
|
|
200
|
-
// Two confirmed prerequisites before this call: the taker has approved `
|
|
201
|
-
// to spend `maxBuyerAssets` of the loan token
|
|
202
|
-
// `
|
|
203
|
-
//
|
|
204
|
-
// behalf (`@morpho-org/morpho-sdk`'s `getMidnightAuthorizationRequirement` resolves this
|
|
205
|
-
// for you).
|
|
203
|
+
// Two confirmed prerequisites before this call: the taker has approved `midnightBundlesV2`
|
|
204
|
+
// to spend `maxBuyerAssets` of the loan token, and has authorized the bundle on Midnight via
|
|
205
|
+
// `Midnight.setIsAuthorized(midnightBundlesV2, true, taker)`. V2 acts for `msg.sender`, so the
|
|
206
|
+
// taker sends the transaction (`@morpho-org/morpho-sdk`'s entity `getRequirements()` resolves both).
|
|
206
207
|
return params.walletClient.writeContract({
|
|
207
208
|
account: params.taker,
|
|
208
209
|
chain: base,
|
|
209
|
-
address:
|
|
210
|
-
abi:
|
|
211
|
-
functionName: "
|
|
210
|
+
address: midnightBundlesV2,
|
|
211
|
+
abi: midnightBundlesV2Abi,
|
|
212
|
+
functionName: "midnightBundlesV2BuyWithUnitsTargetAndWithdrawCollateral",
|
|
212
213
|
args: [
|
|
214
|
+
params.market,
|
|
213
215
|
targetUnits,
|
|
214
216
|
maxBuyerAssets,
|
|
215
|
-
params.taker,
|
|
216
217
|
false, // reduceOnly
|
|
217
|
-
|
|
218
|
+
false, // repayEnabled
|
|
218
219
|
quote.data.takeableOffers, // { offer, units, ratifierData }[] straight from the quote
|
|
219
220
|
[], // collateralWithdrawals
|
|
220
221
|
zeroAddress, // collateralReceiver
|
|
@@ -222,12 +223,13 @@ export async function takeAskQuoteAtomically(params: {
|
|
|
222
223
|
zeroAddress, // referralFeeRecipient
|
|
223
224
|
maxUint256, // maxContinuousFee: bound this to the fee the caller accepts
|
|
224
225
|
params.deadline,
|
|
226
|
+
zeroAddress, // wrappedNative
|
|
225
227
|
],
|
|
226
228
|
});
|
|
227
229
|
}
|
|
228
230
|
```
|
|
229
231
|
|
|
230
|
-
Bids mirror this with `
|
|
232
|
+
Bids mirror this with `midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget` and a
|
|
231
233
|
`minSellerAssets` floor derived from the same `averageWorstPrice`. Prefer the `*WithAssetsTarget*`
|
|
232
234
|
variants when the caller fixes the asset amount instead of the unit amount.
|
|
233
235
|
|