@morpho-org/blue-sdk 1.7.4 → 1.7.6

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.
@@ -1,4 +1,4 @@
1
- import { Address } from "../types";
1
+ import { Address, BigIntish } from "../types";
2
2
  export declare const ERC20_ALLOWANCE_RECIPIENTS: readonly ["morpho", "permit2", "bundler"];
3
3
  export declare const PERMIT2_ALLOWANCE_RECIPIENTS: readonly ["morpho", "bundler"];
4
4
  export type Erc20AllowanceRecipient = (typeof ERC20_ALLOWANCE_RECIPIENTS)[number];
@@ -8,6 +8,11 @@ export interface Permit2Allowance {
8
8
  expiration: bigint;
9
9
  nonce: bigint;
10
10
  }
11
+ export interface InputPermit2Allowance {
12
+ amount: BigIntish;
13
+ expiration: BigIntish;
14
+ nonce: BigIntish;
15
+ }
11
16
  export interface InputHolding {
12
17
  user: Address;
13
18
  token: Address;
@@ -15,7 +20,7 @@ export interface InputHolding {
15
20
  [key in Erc20AllowanceRecipient]: bigint;
16
21
  };
17
22
  permit2Allowances: {
18
- [key in Permit2AllowanceRecipient]: Permit2Allowance;
23
+ [key in Permit2AllowanceRecipient]: InputPermit2Allowance;
19
24
  };
20
25
  erc2612Nonce?: bigint;
21
26
  canTransfer?: boolean;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Holding = exports.PERMIT2_ALLOWANCE_RECIPIENTS = exports.ERC20_ALLOWANCE_RECIPIENTS = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
- const addresses_1 = require("../addresses");
6
5
  exports.ERC20_ALLOWANCE_RECIPIENTS = [
7
6
  "morpho",
8
7
  "permit2",
@@ -42,16 +41,27 @@ class Holding {
42
41
  * `undefined` if the token does not support ERC-2612.
43
42
  */
44
43
  erc2612Nonce;
45
- constructor({ user, token, erc20Allowances, permit2Allowances, balance, erc2612Nonce, canTransfer = true, }) {
44
+ constructor({ user, token, erc20Allowances, permit2Allowances, balance, erc2612Nonce, canTransfer, }) {
46
45
  this.user = user;
47
46
  this.token = token;
48
47
  this.balance = balance;
49
- this.canTransfer = token === addresses_1.NATIVE_ADDRESS || canTransfer;
48
+ this.canTransfer = canTransfer;
50
49
  this.erc20Allowances = (0, morpho_ts_1.fromEntries)((0, morpho_ts_1.entries)(erc20Allowances).map(([address, allowance]) => [
51
50
  address,
52
51
  allowance,
53
52
  ]));
54
- this.permit2Allowances = permit2Allowances;
53
+ this.permit2Allowances = {
54
+ morpho: {
55
+ amount: BigInt(permit2Allowances.morpho.amount),
56
+ expiration: BigInt(permit2Allowances.morpho.expiration),
57
+ nonce: BigInt(permit2Allowances.morpho.nonce),
58
+ },
59
+ bundler: {
60
+ amount: BigInt(permit2Allowances.bundler.amount),
61
+ expiration: BigInt(permit2Allowances.bundler.expiration),
62
+ nonce: BigInt(permit2Allowances.bundler.nonce),
63
+ },
64
+ };
55
65
  if (erc2612Nonce != null)
56
66
  this.erc2612Nonce = erc2612Nonce;
57
67
  }
@@ -1,4 +1,4 @@
1
- import { Market } from "../market";
1
+ import { Market, MaxBorrowOptions, MaxWithdrawCollateralOptions } from "../market";
2
2
  import { Address, BigIntish, MarketId } from "../types";
3
3
  export interface InputPosition {
4
4
  user: Address;
@@ -119,5 +119,8 @@ export declare class AccrualPosition extends Position implements InputAccrualPos
119
119
  shares: bigint;
120
120
  };
121
121
  getRepayCapacityLimit(loanTokenBalance: bigint): import("../market").CapacityLimit;
122
- getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint): import("../market").MaxPositionCapacities;
122
+ getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint, options?: {
123
+ borrow?: MaxBorrowOptions;
124
+ withdrawCollateral?: MaxWithdrawCollateralOptions;
125
+ }): import("../market").MaxPositionCapacities;
123
126
  }
@@ -196,8 +196,8 @@ class AccrualPosition extends Position {
196
196
  getRepayCapacityLimit(loanTokenBalance) {
197
197
  return this.market.getRepayCapacityLimit(this.borrowShares, loanTokenBalance);
198
198
  }
199
- getMaxCapacities(loanTokenBalance, collateralTokenBalance) {
200
- return this.market.getMaxCapacities(this, loanTokenBalance, collateralTokenBalance);
199
+ getMaxCapacities(loanTokenBalance, collateralTokenBalance, options) {
200
+ return this.market.getMaxCapacities(this, loanTokenBalance, collateralTokenBalance, options);
201
201
  }
202
202
  }
203
203
  exports.AccrualPosition = AccrualPosition;
@@ -1,11 +1,10 @@
1
1
  import { RoundingDirection } from "../maths";
2
- import { Address } from "../types";
2
+ import { Address, BigIntish } from "../types";
3
3
  import { InputToken } from "./Token";
4
4
  import { WrappedToken } from "./WrappedToken";
5
5
  export declare class ConstantWrappedToken extends WrappedToken {
6
- readonly underlying: Address;
7
- private readonly _underlyingDecimals;
8
- constructor(token: InputToken, underlying: Address, _underlyingDecimals?: number);
6
+ readonly underlyingDecimals: bigint;
7
+ constructor(token: InputToken, underlying: Address, underlyingDecimals?: BigIntish);
9
8
  toWrappedExactAmountIn(unwrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
10
9
  /** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
11
10
  toWrappedExactAmountOut(wrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
@@ -4,12 +4,10 @@ exports.ConstantWrappedToken = void 0;
4
4
  const maths_1 = require("../maths");
5
5
  const WrappedToken_1 = require("./WrappedToken");
6
6
  class ConstantWrappedToken extends WrappedToken_1.WrappedToken {
7
- underlying;
8
- _underlyingDecimals;
9
- constructor(token, underlying, _underlyingDecimals = 18) {
7
+ underlyingDecimals;
8
+ constructor(token, underlying, underlyingDecimals = 18n) {
10
9
  super(token, underlying);
11
- this.underlying = underlying;
12
- this._underlyingDecimals = _underlyingDecimals;
10
+ this.underlyingDecimals = BigInt(underlyingDecimals);
13
11
  }
14
12
  toWrappedExactAmountIn(unwrappedAmount, _slippage, rounding = "Down") {
15
13
  return super.toWrappedExactAmountIn(unwrappedAmount, 0n, rounding);
@@ -27,10 +25,10 @@ class ConstantWrappedToken extends WrappedToken_1.WrappedToken {
27
25
  return super.toUnwrappedExactAmountOut(unwrappedAmount, 0n, rounding);
28
26
  }
29
27
  _wrap(amount) {
30
- return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this.decimals), 10n ** BigInt(this._underlyingDecimals));
28
+ return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this.decimals), 10n ** this.underlyingDecimals);
31
29
  }
32
30
  _unwrap(amount) {
33
- return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this._underlyingDecimals), 10n ** BigInt(this.decimals));
31
+ return maths_1.MathLib.mulDivDown(amount, 10n ** this.underlyingDecimals, 10n ** BigInt(this.decimals));
34
32
  }
35
33
  }
36
34
  exports.ConstantWrappedToken = ConstantWrappedToken;
@@ -1,9 +1,9 @@
1
1
  import { ChainId } from "../chain";
2
2
  import { RoundingDirection } from "../maths";
3
- import { Address } from "../types";
3
+ import { Address, BigIntish } from "../types";
4
4
  export interface InputToken {
5
5
  address: Address;
6
- decimals: number;
6
+ decimals: BigIntish;
7
7
  symbol: string;
8
8
  name?: string;
9
9
  }
@@ -27,7 +27,7 @@ class Token {
27
27
  name;
28
28
  constructor({ address, decimals, symbol, name }) {
29
29
  this.address = address;
30
- this.decimals = decimals;
30
+ this.decimals = Number(decimals);
31
31
  this.symbol = symbol;
32
32
  this.name = name ?? symbol;
33
33
  }
@@ -11,7 +11,7 @@ class VaultToken extends WrappedToken_1.WrappedToken {
11
11
  super(config, config.asset);
12
12
  this.totalAssets = totalAssets;
13
13
  this.totalSupply = totalSupply;
14
- this.decimalsOffset = config.decimalsOffset;
14
+ this.decimalsOffset = BigInt(config.decimalsOffset);
15
15
  }
16
16
  _wrap(amount, rounding) {
17
17
  return VaultUtils_1.VaultUtils.toShares(amount, this, this, rounding);
@@ -1,9 +1,9 @@
1
1
  import { ChainId } from "../chain";
2
- import { Address } from "../types";
2
+ import { Address, BigIntish } from "../types";
3
3
  export interface InputVaultConfig {
4
4
  address: Address;
5
- decimals: number;
6
- decimalsOffset: bigint;
5
+ decimals: BigIntish;
6
+ decimalsOffset: BigIntish;
7
7
  symbol: string;
8
8
  name: string;
9
9
  asset: Address;
@@ -20,8 +20,8 @@ class VaultConfig {
20
20
  constructor({ address, decimals, decimalsOffset, symbol, name, asset, }, chainId) {
21
21
  this.chainId = chainId;
22
22
  this.address = address;
23
- this.decimals = decimals;
24
- this.decimalsOffset = decimalsOffset;
23
+ this.decimals = Number(decimals);
24
+ this.decimalsOffset = BigInt(decimalsOffset);
25
25
  this.symbol = symbol;
26
26
  this.name = name;
27
27
  this.asset = asset;
@@ -8,7 +8,7 @@ export declare class VaultMarketAllocation implements InputVaultMarketAllocation
8
8
  /**
9
9
  * The vault's configuration on the corresponding market.
10
10
  */
11
- config: VaultMarketConfig;
11
+ readonly config: VaultMarketConfig;
12
12
  /**
13
13
  * The vault's position on the corresponding market.
14
14
  */
@@ -8,17 +8,17 @@ export interface InputVaultMarketConfig {
8
8
  pendingCap: Pending<bigint>;
9
9
  removableAt: bigint;
10
10
  enabled: boolean;
11
- publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
11
+ publicAllocatorConfig: VaultMarketPublicAllocatorConfig;
12
12
  }
13
13
  export declare class VaultMarketConfig implements InputVaultMarketConfig {
14
14
  /**
15
15
  * The vault's address.
16
16
  */
17
- vault: Address;
17
+ readonly vault: Address;
18
18
  /**
19
19
  * The market's id.
20
20
  */
21
- marketId: MarketId;
21
+ readonly marketId: MarketId;
22
22
  /**
23
23
  * The maximum amount of tokens that can be allocated to this market.
24
24
  */
@@ -38,6 +38,6 @@ export declare class VaultMarketConfig implements InputVaultMarketConfig {
38
38
  /**
39
39
  * The vault's PublicAllocator configuration on the corresponding market.
40
40
  */
41
- publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
41
+ readonly publicAllocatorConfig: VaultMarketPublicAllocatorConfig;
42
42
  constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }: InputVaultMarketConfig);
43
43
  }
@@ -12,11 +12,11 @@ export declare class VaultMarketPublicAllocatorConfig implements InputVaultMarke
12
12
  /**
13
13
  * The vault's address.
14
14
  */
15
- vault: Address;
15
+ readonly vault: Address;
16
16
  /**
17
17
  * The market's id.
18
18
  */
19
- marketId: MarketId;
19
+ readonly marketId: MarketId;
20
20
  /**
21
21
  * The maximum amount of tokens that can be allocated to this market by the vault via the PublicAllocator.
22
22
  */
@@ -0,0 +1,26 @@
1
+ import { Address } from "../types";
2
+ export interface InputVaultUser {
3
+ vault: Address;
4
+ user: Address;
5
+ isAllocator: boolean;
6
+ allowance: bigint;
7
+ }
8
+ export declare class VaultUser implements InputVaultUser {
9
+ /**
10
+ * The vault's address.
11
+ */
12
+ readonly vault: Address;
13
+ /**
14
+ * The user's address.
15
+ */
16
+ readonly user: Address;
17
+ /**
18
+ * Whether the user is an allocator of the vault.
19
+ */
20
+ isAllocator: boolean;
21
+ /**
22
+ * The allowance of the vault over the user's underlying assets.
23
+ */
24
+ allowance: bigint;
25
+ constructor({ vault, user, isAllocator, allowance }: InputVaultUser);
26
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaultUser = void 0;
4
+ class VaultUser {
5
+ /**
6
+ * The vault's address.
7
+ */
8
+ vault;
9
+ /**
10
+ * The user's address.
11
+ */
12
+ user;
13
+ /**
14
+ * Whether the user is an allocator of the vault.
15
+ */
16
+ isAllocator;
17
+ /**
18
+ * The allowance of the vault over the user's underlying assets.
19
+ */
20
+ allowance;
21
+ constructor({ vault, user, isAllocator, allowance }) {
22
+ this.vault = vault;
23
+ this.user = user;
24
+ this.isAllocator = isAllocator;
25
+ this.allowance = allowance;
26
+ }
27
+ }
28
+ exports.VaultUser = VaultUser;
@@ -3,4 +3,5 @@ export * from "./VaultConfig";
3
3
  export * from "./VaultMarketAllocation";
4
4
  export * from "./VaultMarketConfig";
5
5
  export * from "./VaultMarketPublicAllocatorConfig";
6
+ export * from "./VaultUser";
6
7
  export * from "./Vault";
@@ -19,4 +19,5 @@ __exportStar(require("./VaultConfig"), exports);
19
19
  __exportStar(require("./VaultMarketAllocation"), exports);
20
20
  __exportStar(require("./VaultMarketConfig"), exports);
21
21
  __exportStar(require("./VaultMarketPublicAllocatorConfig"), exports);
22
+ __exportStar(require("./VaultUser"), exports);
22
23
  __exportStar(require("./Vault"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morpho-org/blue-sdk",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "author": "Morpho Association <contact@morpho.org>",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -16,16 +16,16 @@
16
16
  "keccak256": "^1.0.6"
17
17
  },
18
18
  "devDependencies": {
19
- "@morpho-org/morpho-test": "^1.7.4",
20
- "@morpho-org/morpho-ts": "^1.7.4",
19
+ "@morpho-org/morpho-test": "^1.7.6",
20
+ "@morpho-org/morpho-ts": "^1.7.6",
21
21
  "@types/jest": "^29.5.12",
22
22
  "@types/node": "^22.1.0",
23
23
  "jest": "^29.7.0",
24
24
  "ts-jest": "^29.2.2",
25
- "typescript": "^5.4.5"
25
+ "typescript": "^5.6.2"
26
26
  },
27
27
  "peerDependencies": {
28
- "@morpho-org/morpho-ts": "^1.7.4"
28
+ "@morpho-org/morpho-ts": "^1.7.6"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
@@ -49,5 +49,5 @@
49
49
  ],
50
50
  "preset": "ts-jest"
51
51
  },
52
- "gitHead": "09517429d483381a758182323547e8a6fe75f2c9"
52
+ "gitHead": "b9b7433ff982d938ed14653295a9badb747b22dd"
53
53
  }