Skip to content

Commit c024ee5

Browse files
committed
refactor(morpho-sdk): colocate midnight action params
1 parent 304470d commit c024ee5

10 files changed

Lines changed: 155 additions & 136 deletions

File tree

packages/morpho-sdk/src/actions/midnight/authorization.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { midnightAbi } from "@morpho-org/midnight-sdk";
22
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData } from "viem";
3+
import { type Address, encodeFunctionData } from "viem";
44
import { addTransactionMetadata } from "../../helpers/index.js";
55
import type {
6+
Metadata,
67
MidnightAuthorizationAction,
78
Transaction,
89
} from "../../types/index.js";
9-
import type { MidnightAuthorizationParams } from "./types.js";
10+
11+
/** Parameters for {@link midnightAuthorization}. */
12+
export interface MidnightAuthorizationParams {
13+
readonly chainId: number;
14+
readonly authorized: Address;
15+
readonly onBehalf: Address;
16+
readonly isAuthorized?: boolean;
17+
readonly metadata?: Metadata;
18+
}
1019

1120
/** Encodes `Midnight.setIsAuthorized(authorized, true, onBehalf)`. */
1221
export const midnightAuthorization = (

packages/morpho-sdk/src/actions/midnight/borrowMarket.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { MarketUtils, midnightBundlesAbi } from "@morpho-org/midnight-sdk";
1+
import {
2+
type MarketInput,
3+
MarketUtils,
4+
midnightBundlesAbi,
5+
} from "@morpho-org/midnight-sdk";
26
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData, zeroAddress } from "viem";
7+
import { type Address, encodeFunctionData, zeroAddress } from "viem";
48
import { addTransactionMetadata } from "../../helpers/index.js";
59
import {
10+
type AnyRequirementSignature,
611
EmptyMidnightTakesError,
12+
type Metadata,
713
type MidnightBorrowMarketAction,
814
MidnightTakeMarketMismatchError,
915
MidnightTakeSideMismatchError,
@@ -13,10 +19,24 @@ import {
1319
UnknownMidnightCollateralError,
1420
} from "../../types/index.js";
1521
import { encodeMidnightTokenPermit } from "./encodeMidnightTokenPermit.js";
16-
import type {
17-
MidnightBorrowMarketParams,
18-
MidnightCollateralSupply,
19-
} from "./types.js";
22+
import type { MidnightCollateralSupply, MidnightTake } from "./types.js";
23+
24+
/** Parameters for {@link midnightBorrowMarket}. */
25+
export interface MidnightBorrowMarketParams {
26+
readonly chainId: number;
27+
readonly market: MarketInput;
28+
readonly collateralAssets: bigint;
29+
readonly loanAssets: bigint;
30+
readonly maxUnits: bigint;
31+
readonly taker: Address;
32+
readonly receiver?: Address;
33+
readonly collateralIndex?: bigint;
34+
readonly takes: readonly MidnightTake[];
35+
readonly signatures?:
36+
| AnyRequirementSignature
37+
| readonly AnyRequirementSignature[];
38+
readonly metadata?: Metadata;
39+
}
2040

2141
/** Encodes the borrow-market Midnight bundle. */
2242
export const midnightBorrowMarket = (

packages/morpho-sdk/src/actions/midnight/cancelOffer.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { midnightAbi } from "@morpho-org/midnight-sdk";
22
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData, maxUint256 } from "viem";
3+
import { type Address, encodeFunctionData, type Hex, maxUint256 } from "viem";
44
import { addTransactionMetadata } from "../../helpers/index.js";
55
import type {
6+
Metadata,
67
MidnightCancelOfferAction,
78
Transaction,
89
} from "../../types/index.js";
9-
import type { MidnightCancelOfferParams } from "./types.js";
10+
11+
/** Parameters for {@link midnightCancelOffer}. */
12+
export interface MidnightCancelOfferParams {
13+
readonly chainId: number;
14+
readonly group: Hex;
15+
readonly onBehalf: Address;
16+
readonly amount?: bigint;
17+
readonly metadata?: Metadata;
18+
}
1019

1120
/** Encodes `Midnight.setConsumed(group, maxUint256, onBehalf)`. */
1221
export const midnightCancelOffer = (

packages/morpho-sdk/src/actions/midnight/lendMarket.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { MarketUtils, midnightBundlesAbi } from "@morpho-org/midnight-sdk";
1+
import {
2+
type MarketInput,
3+
MarketUtils,
4+
midnightBundlesAbi,
5+
} from "@morpho-org/midnight-sdk";
26
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData, zeroAddress } from "viem";
7+
import { type Address, encodeFunctionData, zeroAddress } from "viem";
48
import { addTransactionMetadata } from "../../helpers/index.js";
59
import {
10+
type AnyRequirementSignature,
611
EmptyMidnightTakesError,
12+
type Metadata,
713
type MidnightLendMarketAction,
814
MidnightTakeMarketMismatchError,
915
MidnightTakeSideMismatchError,
@@ -12,7 +18,21 @@ import {
1218
type Transaction,
1319
} from "../../types/index.js";
1420
import { encodeMidnightTokenPermit } from "./encodeMidnightTokenPermit.js";
15-
import type { MidnightLendMarketParams } from "./types.js";
21+
import type { MidnightTake } from "./types.js";
22+
23+
/** Parameters for {@link midnightLendMarket}. */
24+
export interface MidnightLendMarketParams {
25+
readonly chainId: number;
26+
readonly market: MarketInput;
27+
readonly assets: bigint;
28+
readonly minUnits: bigint;
29+
readonly taker: Address;
30+
readonly takes: readonly MidnightTake[];
31+
readonly signatures?:
32+
| AnyRequirementSignature
33+
| readonly AnyRequirementSignature[];
34+
readonly metadata?: Metadata;
35+
}
1636

1737
/** Encodes the lend-market Midnight bundle. */
1838
export const midnightLendMarket = (

packages/morpho-sdk/src/actions/midnight/ratifyRoot.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { setterRatifierAbi } from "@morpho-org/midnight-sdk";
22
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData } from "viem";
3+
import { type Address, encodeFunctionData, type Hex } from "viem";
44
import { addTransactionMetadata } from "../../helpers/index.js";
55
import type {
6+
Metadata,
67
MidnightRatifyRootAction,
78
Transaction,
89
} from "../../types/index.js";
9-
import type { MidnightRatifyRootParams } from "./types.js";
10+
11+
/** Parameters for {@link midnightRatifyRoot}. */
12+
export interface MidnightRatifyRootParams {
13+
readonly chainId: number;
14+
readonly maker: Address;
15+
readonly root: Hex;
16+
readonly isRootRatified?: boolean;
17+
readonly metadata?: Metadata;
18+
}
1019

1120
/** Encodes `SetterRatifier.setIsRootRatified(maker, root, true)`. */
1221
export const midnightRatifyRoot = (

packages/morpho-sdk/src/actions/midnight/redeem.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
import { MarketUtils, midnightAbi } from "@morpho-org/midnight-sdk";
1+
import {
2+
type MarketInput,
3+
MarketUtils,
4+
midnightAbi,
5+
} from "@morpho-org/midnight-sdk";
26
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData } from "viem";
7+
import { type Address, encodeFunctionData } from "viem";
48
import { addTransactionMetadata } from "../../helpers/index.js";
59
import {
10+
type Metadata,
611
type MidnightRedeemAction,
712
NonPositiveMidnightAmountError,
813
type Transaction,
914
} from "../../types/index.js";
10-
import type { MidnightRedeemParams } from "./types.js";
15+
16+
/** Parameters for {@link midnightRedeem}. */
17+
export interface MidnightRedeemParams {
18+
readonly chainId: number;
19+
readonly market: MarketInput;
20+
readonly units: bigint;
21+
readonly onBehalf: Address;
22+
readonly receiver?: Address;
23+
readonly metadata?: Metadata;
24+
}
1125

1226
/** Encodes `Midnight.withdraw` for credit redemption. */
1327
export const midnightRedeem = (

packages/morpho-sdk/src/actions/midnight/repayWithdrawCollateral.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1-
import { MarketUtils, midnightBundlesAbi } from "@morpho-org/midnight-sdk";
1+
import {
2+
type MarketInput,
3+
MarketUtils,
4+
midnightBundlesAbi,
5+
} from "@morpho-org/midnight-sdk";
26
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData, zeroAddress } from "viem";
7+
import { type Address, encodeFunctionData, zeroAddress } from "viem";
48
import { addTransactionMetadata } from "../../helpers/index.js";
59
import {
10+
type AnyRequirementSignature,
11+
type Metadata,
612
type MidnightRepayWithdrawCollateralAction,
713
NegativeMidnightAmountError,
814
NonPositiveMidnightAmountError,
915
type Transaction,
1016
} from "../../types/index.js";
1117
import { encodeMidnightTokenPermit } from "./encodeMidnightTokenPermit.js";
12-
import type {
13-
MidnightCollateralWithdrawal,
14-
MidnightRepayWithdrawCollateralParams,
15-
} from "./types.js";
18+
import type { MidnightCollateralWithdrawal } from "./types.js";
19+
20+
/** Parameters for {@link midnightRepayWithdrawCollateral}. */
21+
export interface MidnightRepayWithdrawCollateralParams {
22+
readonly chainId: number;
23+
readonly market: MarketInput;
24+
readonly repayUnits: bigint;
25+
readonly withdrawCollateralAssets: bigint;
26+
readonly onBehalf: Address;
27+
readonly receiver?: Address;
28+
readonly collateralIndex?: bigint;
29+
readonly signatures?:
30+
| AnyRequirementSignature
31+
| readonly AnyRequirementSignature[];
32+
readonly metadata?: Metadata;
33+
}
1634

1735
/** Encodes the repay and/or withdraw-collateral Midnight bundle. */
1836
export const midnightRepayWithdrawCollateral = (

packages/morpho-sdk/src/actions/midnight/submitOffers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
2+
import type { Address, Hex } from "viem";
23
import type {
34
MidnightSubmitOffersAction,
45
Transaction,
56
} from "../../types/index.js";
6-
import type { MidnightSubmitOffersParams } from "./types.js";
7+
8+
/** Parameters for {@link midnightSubmitOffers}. */
9+
export interface MidnightSubmitOffersParams {
10+
readonly chainId: number;
11+
readonly group: Hex;
12+
readonly root: Hex;
13+
readonly maker: Address;
14+
readonly ratifier: Address;
15+
readonly ratifierType: "ecrecover" | "setter";
16+
readonly offers: number;
17+
readonly payload: Hex;
18+
}
719

820
/** Encodes the Midnight mempool payload submission transaction. */
921
export const midnightSubmitOffers = (

packages/morpho-sdk/src/actions/midnight/supplyCollateral.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
import { MarketUtils, midnightAbi } from "@morpho-org/midnight-sdk";
1+
import {
2+
type MarketInput,
3+
MarketUtils,
4+
midnightAbi,
5+
} from "@morpho-org/midnight-sdk";
26
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3-
import { encodeFunctionData } from "viem";
7+
import { type Address, encodeFunctionData } from "viem";
48
import { addTransactionMetadata } from "../../helpers/index.js";
59
import {
10+
type Metadata,
611
type MidnightSupplyCollateralAction,
712
NonPositiveMidnightAmountError,
813
type Transaction,
914
} from "../../types/index.js";
10-
import type { MidnightSupplyCollateralParams } from "./types.js";
15+
16+
/** Parameters for {@link midnightSupplyCollateral}. */
17+
export interface MidnightSupplyCollateralParams {
18+
readonly chainId: number;
19+
readonly market: MarketInput;
20+
readonly collateralIndex?: bigint;
21+
readonly assets: bigint;
22+
readonly onBehalf: Address;
23+
readonly metadata?: Metadata;
24+
}
1125

1226
/** Encodes `Midnight.supplyCollateral`. */
1327
export const midnightSupplyCollateral = (

0 commit comments

Comments
 (0)