@morpho-org/blue-sdk 1.0.5 → 1.2.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.
Files changed (105) hide show
  1. package/README.md +2 -2
  2. package/lib/addresses.d.ts +35 -21
  3. package/lib/addresses.js +51 -14
  4. package/lib/chain.d.ts +30 -0
  5. package/lib/chain.js +288 -0
  6. package/lib/chain.test.js +22 -0
  7. package/lib/constants.d.ts +27 -6
  8. package/lib/constants.js +28 -8
  9. package/lib/errors.d.ts +18 -7
  10. package/lib/errors.js +38 -10
  11. package/lib/helpers/format/format.js +21 -60
  12. package/lib/helpers/index.d.ts +0 -2
  13. package/lib/helpers/index.js +0 -2
  14. package/lib/holding/Holding.d.ts +3 -4
  15. package/lib/holding/Holding.js +32 -4
  16. package/lib/index.d.ts +0 -8
  17. package/lib/index.js +1 -9
  18. package/lib/market/Market.d.ts +206 -55
  19. package/lib/market/Market.js +266 -64
  20. package/lib/market/MarketConfig.d.ts +17 -9
  21. package/lib/market/MarketConfig.js +39 -21
  22. package/lib/market/MarketUtils.d.ts +151 -102
  23. package/lib/market/MarketUtils.js +94 -38
  24. package/lib/market/MarketUtils.test.js +1 -2
  25. package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
  26. package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
  27. package/lib/maths/MathLib.d.ts +35 -15
  28. package/lib/maths/MathLib.js +53 -33
  29. package/lib/maths/SharesMath.d.ts +3 -3
  30. package/lib/maths/SharesMath.js +2 -3
  31. package/lib/maths/index.d.ts +0 -1
  32. package/lib/maths/index.js +0 -1
  33. package/lib/position/Position.d.ts +5 -26
  34. package/lib/position/Position.js +29 -36
  35. package/lib/tests/mocks/markets.d.ts +1 -0
  36. package/lib/tests/mocks/markets.js +35 -29
  37. package/lib/token/Token.d.ts +4 -3
  38. package/lib/token/Token.js +28 -3
  39. package/lib/token/WrappedToken.d.ts +3 -3
  40. package/lib/token/WrappedToken.js +18 -11
  41. package/lib/token/index.d.ts +1 -1
  42. package/lib/token/index.js +1 -1
  43. package/lib/types.d.ts +1 -0
  44. package/lib/types.js +3 -4
  45. package/lib/user/User.js +12 -0
  46. package/lib/vault/Vault.d.ts +12 -12
  47. package/lib/vault/Vault.js +102 -18
  48. package/lib/vault/VaultConfig.js +9 -3
  49. package/lib/vault/VaultMarketAllocation.d.ts +20 -0
  50. package/lib/vault/VaultMarketAllocation.js +30 -0
  51. package/lib/vault/VaultMarketConfig.d.ts +43 -0
  52. package/lib/vault/VaultMarketConfig.js +43 -0
  53. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
  54. package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
  55. package/lib/vault/VaultUtils.d.ts +8 -9
  56. package/lib/vault/VaultUtils.js +2 -3
  57. package/lib/vault/index.d.ts +3 -1
  58. package/lib/vault/index.js +3 -1
  59. package/package.json +3 -6
  60. package/lib/chain/chain.constants.d.ts +0 -3
  61. package/lib/chain/chain.constants.js +0 -232
  62. package/lib/chain/chain.test.js +0 -37
  63. package/lib/chain/chain.types.d.ts +0 -20
  64. package/lib/chain/chain.types.js +0 -30
  65. package/lib/chain/chain.utils.d.ts +0 -14
  66. package/lib/chain/chain.utils.js +0 -30
  67. package/lib/chain/index.d.ts +0 -2
  68. package/lib/chain/index.js +0 -18
  69. package/lib/ethers/ethers.test.d.ts +0 -1
  70. package/lib/ethers/ethers.test.js +0 -11
  71. package/lib/ethers/index.d.ts +0 -2
  72. package/lib/ethers/index.js +0 -18
  73. package/lib/ethers/safeGetAddress.d.ts +0 -1
  74. package/lib/ethers/safeGetAddress.js +0 -6
  75. package/lib/ethers/safeParseUnits.d.ts +0 -2
  76. package/lib/ethers/safeParseUnits.js +0 -25
  77. package/lib/evm.d.ts +0 -36
  78. package/lib/evm.js +0 -113
  79. package/lib/helpers/getChecksumedAddress.d.ts +0 -7
  80. package/lib/helpers/getChecksumedAddress.js +0 -17
  81. package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
  82. package/lib/helpers/isZeroAddressOrUnset.js +0 -14
  83. package/lib/maths/MathUtils.d.ts +0 -15
  84. package/lib/maths/MathUtils.js +0 -33
  85. package/lib/notifications.d.ts +0 -98
  86. package/lib/notifications.js +0 -52
  87. package/lib/signatures/index.d.ts +0 -12
  88. package/lib/signatures/index.js +0 -39
  89. package/lib/signatures/manager.d.ts +0 -10
  90. package/lib/signatures/manager.js +0 -37
  91. package/lib/signatures/permit.d.ts +0 -21
  92. package/lib/signatures/permit.js +0 -101
  93. package/lib/signatures/permit2.d.ts +0 -20
  94. package/lib/signatures/permit2.js +0 -91
  95. package/lib/signatures/types.d.ts +0 -13
  96. package/lib/signatures/types.js +0 -2
  97. package/lib/signatures/utils.d.ts +0 -6
  98. package/lib/signatures/utils.js +0 -44
  99. package/lib/token/ERC20Metadata.d.ts +0 -249
  100. package/lib/token/ERC20Metadata.js +0 -81
  101. package/lib/token/TokenNamespace.d.ts +0 -18
  102. package/lib/token/TokenNamespace.js +0 -55
  103. package/lib/vault/VaultAllocation.d.ts +0 -38
  104. package/lib/vault/VaultAllocation.js +0 -18
  105. /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
- import { BigNumberish } from "ethers";
2
1
  import { Time } from "@morpho-org/morpho-ts";
2
+ import { BigIntish } from "../types";
3
3
  export type RoundingDirection = "Up" | "Down";
4
4
  /**
5
5
  * Library to manage fixed-point arithmetic.
@@ -10,72 +10,85 @@ export type RoundingDirection = "Up" | "Down";
10
10
  */
11
11
  export declare class MathLib {
12
12
  static WAD: bigint;
13
+ static MAX_UINT_256: bigint;
13
14
  static MAX_UINT_160: bigint;
14
15
  static MAX_UINT_128: bigint;
15
16
  static MAX_UINT_48: bigint;
17
+ static maxUint(nBits: number): bigint;
18
+ /**
19
+ * Returns the absolute value of a number
20
+ * @param a The number
21
+ */
22
+ static abs(a: BigIntish): bigint;
16
23
  /**
17
24
  * Returns the smallest number given as param
18
25
  * @param x The first number
19
26
  * @param y The second number
20
27
  */
21
- static min(x: BigNumberish, y: BigNumberish): bigint;
28
+ static min(...xs: BigIntish[]): bigint;
22
29
  /**
23
30
  * Returns the greatest number given as param
24
31
  * @param x The first number
25
32
  * @param y The second number
26
33
  */
27
- static max(x: BigNumberish, y: BigNumberish): bigint;
34
+ static max(...xs: BigIntish[]): bigint;
35
+ /**
36
+ * Returns the subtraction of b from a, floored to zero if negative
37
+ * @param x The first number
38
+ * @param y The second number
39
+ */
40
+ static zeroFloorSub(x: BigIntish, y: BigIntish): bigint;
28
41
  /**
29
42
  * Perform the WAD-based multiplication of 2 numbers, rounded down
30
43
  * @param x The first number
31
44
  * @param y The second number
32
45
  */
33
- static wMulDown(x: BigNumberish, y: BigNumberish): bigint;
46
+ static wMulDown(x: BigIntish, y: BigIntish): bigint;
34
47
  /**
35
48
  * Perform the WAD-based multiplication of 2 numbers, rounded up
36
49
  * @param x The first number
37
50
  * @param y The second number
38
51
  */
39
- static wMulUp(x: BigNumberish, y: BigNumberish): bigint;
52
+ static wMulUp(x: BigIntish, y: BigIntish): bigint;
40
53
  /**
41
54
  * Perform the WAD-based multiplication of 2 numbers with a provided rounding direction
42
55
  * @param x The first number
43
56
  * @param y The second number
44
57
  */
45
- static wMul(x: bigint, y: bigint, rounding: RoundingDirection): bigint;
58
+ static wMul(x: BigIntish, y: BigIntish, rounding: RoundingDirection): bigint;
46
59
  /**
47
60
  * Perform the WAD-based division of 2 numbers, rounded down
48
61
  * @param x The first number
49
62
  * @param y The second number
50
63
  */
51
- static wDivDown(x: BigNumberish, y: BigNumberish): bigint;
64
+ static wDivDown(x: BigIntish, y: BigIntish): bigint;
52
65
  /**
53
66
  * Perform the WAD-based multiplication of 2 numbers, rounded up
54
67
  * @param x The first number
55
68
  * @param y The second number
56
69
  */
57
- static wDivUp(x: BigNumberish, y: BigNumberish): bigint;
70
+ static wDivUp(x: BigIntish, y: BigIntish): bigint;
58
71
  /**
59
72
  * Perform the WAD-based multiplication of 2 numbers with a provided rounding direction
60
73
  * @param x The first number
61
74
  * @param y The second number
62
75
  */
63
- static wDiv(x: BigNumberish, y: BigNumberish, rounding: RoundingDirection): bigint;
76
+ static wDiv(x: BigIntish, y: BigIntish, rounding: RoundingDirection): bigint;
64
77
  /**
65
78
  * Multiply two numbers and divide by a denominator, rounding down the result
66
79
  * @param x The first number
67
80
  * @param y The second number
68
81
  * @param denominator The denominator
69
82
  */
70
- static mulDivDown(x: BigNumberish, y: BigNumberish, denominator: BigNumberish): bigint;
83
+ static mulDivDown(x: BigIntish, y: BigIntish, denominator: BigIntish): bigint;
71
84
  /**
72
85
  * Multiply two numbers and divide by a denominator, rounding up the result
73
86
  * @param x The first number
74
87
  * @param y The second number
75
88
  * @param denominator The denominator
76
89
  */
77
- static mulDivUp(x: BigNumberish, y: BigNumberish, denominator: BigNumberish): bigint;
78
- static mulDiv(x: BigNumberish, y: BigNumberish, denominator: BigNumberish, rounding: RoundingDirection): bigint;
90
+ static mulDivUp(x: BigIntish, y: BigIntish, denominator: BigIntish): bigint;
91
+ static mulDiv(x: BigIntish, y: BigIntish, denominator: BigIntish, rounding: RoundingDirection): bigint;
79
92
  /**
80
93
  * The sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1,
81
94
  * to approximate a continuous compound interest rate.
@@ -83,12 +96,19 @@ export declare class MathLib {
83
96
  * @param x The base of the exponent
84
97
  * @param n The exponent
85
98
  */
86
- static wTaylorCompounded(x: BigNumberish, n: BigNumberish): bigint;
99
+ static wTaylorCompounded(x: BigIntish, n: BigIntish): bigint;
100
+ /**
101
+ * Converts an apr to compounded apy
102
+ *
103
+ * @param apr The rate to convert (in WAD)
104
+ * @param compounding The compounding basis
105
+ */
106
+ static rateToApy(rate: BigIntish, unit: Time.Unit): number;
87
107
  /**
88
108
  * Converts an apr to compounded apy
89
109
  *
90
- * @param apr The apr to convert (in WAD)
110
+ * @param apr The yearly apr to convert (in WAD)
91
111
  * @param compounding The compounding basis
92
112
  */
93
- static aprToApy(apr: bigint, compounding: Time.Unit): bigint;
113
+ static aprToApy(apr: BigIntish, compounding: Time.Unit): number;
94
114
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MathLib = void 0;
4
- const ethers_1 = require("ethers");
5
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const helpers_1 = require("../helpers");
6
6
  /**
7
7
  * Library to manage fixed-point arithmetic.
8
8
  * This library reproduces the behaviour of the solidity library MathLib
@@ -11,25 +11,49 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
11
11
  *
12
12
  */
13
13
  class MathLib {
14
+ static WAD = 1000000000000000000n;
15
+ static MAX_UINT_256 = MathLib.maxUint(256);
16
+ static MAX_UINT_160 = MathLib.maxUint(160);
17
+ static MAX_UINT_128 = MathLib.maxUint(128);
18
+ static MAX_UINT_48 = MathLib.maxUint(48);
19
+ static maxUint(nBits) {
20
+ if (nBits % 4 !== 0)
21
+ throw new Error(`Invalid number of bits: ${nBits}`);
22
+ return BigInt("0x" + "f".repeat(nBits / 4));
23
+ }
24
+ /**
25
+ * Returns the absolute value of a number
26
+ * @param a The number
27
+ */
28
+ static abs(a) {
29
+ a = BigInt(a);
30
+ return a >= 0 ? a : -a;
31
+ }
14
32
  /**
15
33
  * Returns the smallest number given as param
16
34
  * @param x The first number
17
35
  * @param y The second number
18
36
  */
19
- static min(x, y) {
20
- x = (0, ethers_1.toBigInt)(x);
21
- y = (0, ethers_1.toBigInt)(y);
22
- return x <= y ? x : y;
37
+ static min(...xs) {
38
+ return xs.map(BigInt).reduce((x, y) => (x <= y ? x : y));
23
39
  }
24
40
  /**
25
41
  * Returns the greatest number given as param
26
42
  * @param x The first number
27
43
  * @param y The second number
28
44
  */
29
- static max(x, y) {
30
- x = (0, ethers_1.toBigInt)(x);
31
- y = (0, ethers_1.toBigInt)(y);
32
- return x <= y ? y : x;
45
+ static max(...xs) {
46
+ return xs.map(BigInt).reduce((x, y) => (x <= y ? y : x));
47
+ }
48
+ /**
49
+ * Returns the subtraction of b from a, floored to zero if negative
50
+ * @param x The first number
51
+ * @param y The second number
52
+ */
53
+ static zeroFloorSub(x, y) {
54
+ x = BigInt(x);
55
+ y = BigInt(y);
56
+ return x <= y ? 0n : x - y;
33
57
  }
34
58
  /**
35
59
  * Perform the WAD-based multiplication of 2 numbers, rounded down
@@ -37,8 +61,6 @@ class MathLib {
37
61
  * @param y The second number
38
62
  */
39
63
  static wMulDown(x, y) {
40
- x = (0, ethers_1.toBigInt)(x);
41
- y = (0, ethers_1.toBigInt)(y);
42
64
  return MathLib.wMul(x, y, "Down");
43
65
  }
44
66
  /**
@@ -47,8 +69,6 @@ class MathLib {
47
69
  * @param y The second number
48
70
  */
49
71
  static wMulUp(x, y) {
50
- x = (0, ethers_1.toBigInt)(x);
51
- y = (0, ethers_1.toBigInt)(y);
52
72
  return MathLib.wMul(x, y, "Up");
53
73
  }
54
74
  /**
@@ -65,8 +85,6 @@ class MathLib {
65
85
  * @param y The second number
66
86
  */
67
87
  static wDivDown(x, y) {
68
- x = (0, ethers_1.toBigInt)(x);
69
- y = (0, ethers_1.toBigInt)(y);
70
88
  return MathLib.wDiv(x, y, "Down");
71
89
  }
72
90
  /**
@@ -75,8 +93,6 @@ class MathLib {
75
93
  * @param y The second number
76
94
  */
77
95
  static wDivUp(x, y) {
78
- x = (0, ethers_1.toBigInt)(x);
79
- y = (0, ethers_1.toBigInt)(y);
80
96
  return MathLib.wDiv(x, y, "Up");
81
97
  }
82
98
  /**
@@ -94,9 +110,9 @@ class MathLib {
94
110
  * @param denominator The denominator
95
111
  */
96
112
  static mulDivDown(x, y, denominator) {
97
- x = (0, ethers_1.toBigInt)(x);
98
- y = (0, ethers_1.toBigInt)(y);
99
- denominator = (0, ethers_1.toBigInt)(denominator);
113
+ x = BigInt(x);
114
+ y = BigInt(y);
115
+ denominator = BigInt(denominator);
100
116
  if (denominator === 0n)
101
117
  throw Error("MathLib: DIVISION_BY_ZERO");
102
118
  return (x * y) / denominator;
@@ -108,9 +124,9 @@ class MathLib {
108
124
  * @param denominator The denominator
109
125
  */
110
126
  static mulDivUp(x, y, denominator) {
111
- x = (0, ethers_1.toBigInt)(x);
112
- y = (0, ethers_1.toBigInt)(y);
113
- denominator = (0, ethers_1.toBigInt)(denominator);
127
+ x = BigInt(x);
128
+ y = BigInt(y);
129
+ denominator = BigInt(denominator);
114
130
  if (denominator === 0n)
115
131
  throw Error("MathLib: DIVISION_BY_ZERO");
116
132
  const roundup = (x * y) % denominator > 0 ? 1n : 0n;
@@ -127,9 +143,7 @@ class MathLib {
127
143
  * @param n The exponent
128
144
  */
129
145
  static wTaylorCompounded(x, n) {
130
- x = (0, ethers_1.toBigInt)(x);
131
- n = (0, ethers_1.toBigInt)(n);
132
- const firstTerm = x * n;
146
+ const firstTerm = BigInt(x) * BigInt(n);
133
147
  const secondTerm = MathLib.mulDivDown(firstTerm, firstTerm, 2n * MathLib.WAD);
134
148
  const thirdTerm = MathLib.mulDivDown(secondTerm, firstTerm, 3n * MathLib.WAD);
135
149
  return firstTerm + secondTerm + thirdTerm;
@@ -137,17 +151,23 @@ class MathLib {
137
151
  /**
138
152
  * Converts an apr to compounded apy
139
153
  *
140
- * @param apr The apr to convert (in WAD)
154
+ * @param apr The rate to convert (in WAD)
155
+ * @param compounding The compounding basis
156
+ */
157
+ static rateToApy(rate, unit) {
158
+ const factor = morpho_ts_1.Time[unit].from.y(1n);
159
+ return ((1 + Number(helpers_1.format.number.of(BigInt(rate), 18))) ** Number(factor) - 1);
160
+ }
161
+ /**
162
+ * Converts an apr to compounded apy
163
+ *
164
+ * @param apr The yearly apr to convert (in WAD)
141
165
  * @param compounding The compounding basis
142
166
  */
143
167
  static aprToApy(apr, compounding) {
144
168
  const factor = morpho_ts_1.Time[compounding].from.y(1n);
145
- const rate = apr / factor;
146
- return ((0, ethers_1.parseUnits)(((+(0, ethers_1.formatUnits)(this.WAD + rate)) ** Number(factor)).toFixed(18)) - this.WAD);
169
+ const rate = BigInt(apr) / factor;
170
+ return this.rateToApy(rate, compounding);
147
171
  }
148
172
  }
149
173
  exports.MathLib = MathLib;
150
- MathLib.WAD = (0, ethers_1.parseUnits)("1");
151
- MathLib.MAX_UINT_160 = BigInt("0x" + "f".repeat(40));
152
- MathLib.MAX_UINT_128 = BigInt("0x" + "f".repeat(32));
153
- MathLib.MAX_UINT_48 = BigInt("0x" + "f".repeat(12));
@@ -1,4 +1,4 @@
1
- import { BigNumberish } from "ethers";
1
+ import { BigIntish } from "../types";
2
2
  import { RoundingDirection } from "./MathLib";
3
3
  /**
4
4
  * JS implementation of {@link https://github.com/morpho-org/morpho-blue/blob/main/src/libraries/SharesMathLib.sol SharesMathLib} used by Morpho Blue
@@ -7,6 +7,6 @@ import { RoundingDirection } from "./MathLib";
7
7
  export declare namespace SharesMath {
8
8
  const VIRTUAL_SHARES = 1000000n;
9
9
  const VIRTUAL_ASSETS = 1n;
10
- function toAssets(shares: BigNumberish, totalAssets: BigNumberish, totalShares: BigNumberish, rounding: RoundingDirection): bigint;
11
- function toShares(assets: BigNumberish, totalAssets: BigNumberish, totalShares: BigNumberish, rounding: RoundingDirection): bigint;
10
+ function toAssets(shares: BigIntish, totalAssets: BigIntish, totalShares: BigIntish, rounding: RoundingDirection): bigint;
11
+ function toShares(assets: BigIntish, totalAssets: BigIntish, totalShares: BigIntish, rounding: RoundingDirection): bigint;
12
12
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SharesMath = void 0;
4
- const ethers_1 = require("ethers");
5
4
  const MathLib_1 = require("./MathLib");
6
5
  /**
7
6
  * JS implementation of {@link https://github.com/morpho-org/morpho-blue/blob/main/src/libraries/SharesMathLib.sol SharesMathLib} used by Morpho Blue
@@ -12,11 +11,11 @@ var SharesMath;
12
11
  SharesMath.VIRTUAL_SHARES = 1000000n;
13
12
  SharesMath.VIRTUAL_ASSETS = 1n;
14
13
  function toAssets(shares, totalAssets, totalShares, rounding) {
15
- return MathLib_1.MathLib.mulDiv(shares, (0, ethers_1.toBigInt)(totalAssets) + SharesMath.VIRTUAL_ASSETS, (0, ethers_1.toBigInt)(totalShares) + SharesMath.VIRTUAL_SHARES, rounding);
14
+ return MathLib_1.MathLib.mulDiv(shares, BigInt(totalAssets) + SharesMath.VIRTUAL_ASSETS, BigInt(totalShares) + SharesMath.VIRTUAL_SHARES, rounding);
16
15
  }
17
16
  SharesMath.toAssets = toAssets;
18
17
  function toShares(assets, totalAssets, totalShares, rounding) {
19
- return MathLib_1.MathLib.mulDiv(assets, (0, ethers_1.toBigInt)(totalShares) + SharesMath.VIRTUAL_SHARES, (0, ethers_1.toBigInt)(totalAssets) + SharesMath.VIRTUAL_ASSETS, rounding);
18
+ return MathLib_1.MathLib.mulDiv(assets, BigInt(totalShares) + SharesMath.VIRTUAL_SHARES, BigInt(totalAssets) + SharesMath.VIRTUAL_ASSETS, rounding);
20
19
  }
21
20
  SharesMath.toShares = toShares;
22
21
  })(SharesMath || (exports.SharesMath = SharesMath = {}));
@@ -1,4 +1,3 @@
1
1
  export * from "./MathLib";
2
2
  export * from "./SharesMath";
3
- export * from "./MathUtils";
4
3
  export * from "./AdaptiveCurveIrmLib";
@@ -16,5 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./MathLib"), exports);
18
18
  __exportStar(require("./SharesMath"), exports);
19
- __exportStar(require("./MathUtils"), exports);
20
19
  __exportStar(require("./AdaptiveCurveIrmLib"), exports);
@@ -1,22 +1,13 @@
1
- import { BigNumberish, Provider } from "ethers";
2
- import { ViewOverrides } from "ethers-types/dist/common";
3
- import { ChainId } from "../chain";
4
- import { Market, MarketConfig } from "../market";
1
+ import { Market } from "../market";
5
2
  import { Address, MarketId } from "../types";
6
3
  export interface InputPosition {
7
4
  user: Address;
8
5
  marketId: MarketId;
9
- supplyShares: BigNumberish;
10
- borrowShares: BigNumberish;
11
- collateral: BigNumberish;
6
+ supplyShares: bigint;
7
+ borrowShares: bigint;
8
+ collateral: bigint;
12
9
  }
13
10
  export declare class Position implements InputPosition {
14
- static fetch(user: Address, marketId: MarketId, runner: {
15
- provider: Provider;
16
- }, { chainId, overrides, }?: {
17
- chainId?: ChainId;
18
- overrides?: ViewOverrides;
19
- }): Promise<Position>;
20
11
  /**
21
12
  * The user holding this position.
22
13
  */
@@ -42,18 +33,6 @@ export declare class Position implements InputPosition {
42
33
  export interface InputAccrualPosition extends Omit<InputPosition, "marketId"> {
43
34
  }
44
35
  export declare class AccrualPosition extends Position implements InputAccrualPosition {
45
- static fetchFromId(user: Address, marketId: MarketId, runner: {
46
- provider: Provider;
47
- }, options: {
48
- chainId?: ChainId;
49
- overrides?: ViewOverrides;
50
- }): Promise<AccrualPosition>;
51
- static fetchFromConfig(user: Address, config: MarketConfig, runner: {
52
- provider: Provider;
53
- }, options: {
54
- chainId?: ChainId;
55
- overrides?: ViewOverrides;
56
- }): Promise<AccrualPosition>;
57
36
  /**
58
37
  * The market on which this position is held.
59
38
  */
@@ -112,7 +91,7 @@ export declare class AccrualPosition extends Position implements InputAccrualPos
112
91
  get borrowCapacityLimit(): import("../market").CapacityLimit;
113
92
  get withdrawCapacityLimit(): import("../market").CapacityLimit;
114
93
  get withdrawCollateralCapacityLimit(): import("../market").CapacityLimit;
115
- accrueInterest(timestamp: BigNumberish): AccrualPosition;
94
+ accrueInterest(timestamp: bigint): AccrualPosition;
116
95
  getRepayCapacityLimit(loanTokenBalance: bigint): import("../market").CapacityLimit;
117
96
  getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint): import("../market").MaxPositionCapacities;
118
97
  }
@@ -1,48 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AccrualPosition = exports.Position = void 0;
4
- const ethers_1 = require("ethers");
5
- const ethers_types_1 = require("ethers-types");
6
- const addresses_1 = require("../addresses");
7
- const chain_1 = require("../chain");
8
- const market_1 = require("../market");
9
4
  class Position {
10
- static async fetch(user, marketId, runner, { chainId, overrides = {}, } = {}) {
11
- chainId ?? (chainId = chain_1.ChainUtils.parseSupportedChainId((await runner.provider.getNetwork()).chainId));
12
- const { morpho } = (0, addresses_1.getChainAddresses)(chainId);
13
- const { supplyShares, borrowShares, collateral } = await ethers_types_1.MorphoBlue__factory.connect(morpho, runner).position(marketId, user, overrides);
14
- return new Position({
15
- user,
16
- marketId,
17
- supplyShares,
18
- borrowShares,
19
- collateral,
20
- });
21
- }
5
+ /**
6
+ * The user holding this position.
7
+ */
8
+ user;
9
+ /**
10
+ * The id of the market on which this position is held.
11
+ */
12
+ marketId;
13
+ /**
14
+ * The amount of supply shares held with this position.
15
+ */
16
+ supplyShares;
17
+ /**
18
+ * The amount of borrow shares held with this position.
19
+ */
20
+ borrowShares;
21
+ /**
22
+ * The amount of collateral assets held with this position.
23
+ */
24
+ collateral;
22
25
  constructor({ user, marketId, supplyShares, borrowShares, collateral, }) {
23
26
  this.user = user;
24
27
  this.marketId = marketId;
25
- this.supplyShares = (0, ethers_1.toBigInt)(supplyShares);
26
- this.borrowShares = (0, ethers_1.toBigInt)(borrowShares);
27
- this.collateral = (0, ethers_1.toBigInt)(collateral);
28
+ this.supplyShares = supplyShares;
29
+ this.borrowShares = borrowShares;
30
+ this.collateral = collateral;
28
31
  }
29
32
  }
30
33
  exports.Position = Position;
31
34
  class AccrualPosition extends Position {
32
- static async fetchFromId(user, marketId, runner, options) {
33
- const [position, market] = await Promise.all([
34
- await Position.fetch(user, marketId, runner, options),
35
- await market_1.Market.fetchFromId(marketId, runner, options),
36
- ]);
37
- return new AccrualPosition(position, market);
38
- }
39
- static async fetchFromConfig(user, config, runner, options) {
40
- const [position, market] = await Promise.all([
41
- await Position.fetch(user, config.id, runner, options),
42
- await market_1.Market.fetchFromConfig(config, runner, options),
43
- ]);
44
- return new AccrualPosition(position, market);
45
- }
35
+ /**
36
+ * The market on which this position is held.
37
+ */
38
+ market;
46
39
  constructor(position, market) {
47
40
  super({ ...position, marketId: market.id });
48
41
  this.market = market;
@@ -124,10 +117,10 @@ class AccrualPosition extends Position {
124
117
  return this.market.getBorrowCapacityUsage(this);
125
118
  }
126
119
  get borrowCapacityLimit() {
127
- return this.market.getBorrowCapacityLimit(this.collateral);
120
+ return this.market.getBorrowCapacityLimit(this);
128
121
  }
129
122
  get withdrawCapacityLimit() {
130
- return this.market.getWithdrawCapacityLimit(this.supplyShares);
123
+ return this.market.getWithdrawCapacityLimit(this);
131
124
  }
132
125
  get withdrawCollateralCapacityLimit() {
133
126
  return this.market.getWithdrawCollateralCapacityLimit(this);
@@ -1,6 +1,7 @@
1
1
  import { MarketConfig } from "../../market";
2
2
  export declare const MAINNET_MARKETS: {
3
3
  eth_wstEth: MarketConfig;
4
+ eth_wstEth_2: MarketConfig;
4
5
  eth_rEth: MarketConfig;
5
6
  usdt_wbtc: MarketConfig;
6
7
  usdt_wstEth: MarketConfig;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MAINNET_MARKETS = void 0;
4
- const ethers_1 = require("ethers");
5
4
  const market_1 = require("../../market");
6
5
  exports.MAINNET_MARKETS = {
7
6
  eth_wstEth: new market_1.MarketConfig({
@@ -9,28 +8,35 @@ exports.MAINNET_MARKETS = {
9
8
  collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
10
9
  oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
11
10
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
12
- lltv: (0, ethers_1.parseUnits)("0.945"),
11
+ lltv: 945000000000000000n,
12
+ }),
13
+ eth_wstEth_2: new market_1.MarketConfig({
14
+ loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
15
+ collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
16
+ oracle: "0xbD60A6770b27E084E8617335ddE769241B0e71D8",
17
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
18
+ lltv: 945000000000000000n,
13
19
  }),
14
20
  eth_rEth: new market_1.MarketConfig({
15
21
  loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
16
22
  collateralToken: "0xae78736Cd615f374D3085123A210448E74Fc6393",
17
23
  oracle: "0x1b4A3F92e5Fffd1d35A98751c9FE4472483579bB",
18
24
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
19
- lltv: (0, ethers_1.parseUnits)("0.945"),
25
+ lltv: 945000000000000000n,
20
26
  }),
21
27
  usdt_wbtc: new market_1.MarketConfig({
22
28
  loanToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
23
29
  collateralToken: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
24
30
  oracle: "0x008bF4B1cDA0cc9f0e882E0697f036667652E1ef",
25
31
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
26
- lltv: (0, ethers_1.parseUnits)("0.86"),
32
+ lltv: 860000000000000000n,
27
33
  }),
28
34
  usdt_wstEth: new market_1.MarketConfig({
29
35
  loanToken: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
30
36
  collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
31
37
  oracle: "0x95DB30fAb9A3754e42423000DF27732CB2396992",
32
38
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
33
- lltv: (0, ethers_1.parseUnits)("0.86"),
39
+ lltv: 860000000000000000n,
34
40
  }),
35
41
  usdc_wbtc: new market_1.MarketConfig({
36
42
  // USDC(wBTC, 86%, Chainlink, AdaptiveCurve)
@@ -38,7 +44,7 @@ exports.MAINNET_MARKETS = {
38
44
  collateralToken: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
39
45
  oracle: "0xDddd770BADd886dF3864029e4B377B5F6a2B6b83",
40
46
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
41
- lltv: (0, ethers_1.parseUnits)("0.86"),
47
+ lltv: 860000000000000000n,
42
48
  }),
43
49
  usdc_wstEth: new market_1.MarketConfig({
44
50
  // USDC(wstETH, 86%, Chainlink, AdaptiveCurve)
@@ -46,7 +52,7 @@ exports.MAINNET_MARKETS = {
46
52
  collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
47
53
  oracle: "0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2",
48
54
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
49
- lltv: (0, ethers_1.parseUnits)("0.86"),
55
+ lltv: 860000000000000000n,
50
56
  }),
51
57
  usdc_sDai: new market_1.MarketConfig({
52
58
  // USDC(wstETH, 86%, Chainlink, AdaptiveCurve)
@@ -54,55 +60,55 @@ exports.MAINNET_MARKETS = {
54
60
  collateralToken: "0x83F20F44975D03b1b09e64809B757c47f942BEeA",
55
61
  oracle: "0x6CAFE228eC0B0bC2D076577d56D35Fe704318f6d",
56
62
  irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
57
- lltv: (0, ethers_1.parseUnits)("0.965"),
63
+ lltv: 96500000000000000000n,
58
64
  }),
59
65
  idle_usdc: new market_1.MarketConfig({
60
66
  loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
61
- collateralToken: ethers_1.ZeroAddress,
62
- oracle: ethers_1.ZeroAddress,
63
- irm: ethers_1.ZeroAddress,
67
+ collateralToken: "0x0000000000000000000000000000000000000000",
68
+ oracle: "0x0000000000000000000000000000000000000000",
69
+ irm: "0x0000000000000000000000000000000000000000",
64
70
  lltv: 0n,
65
71
  }),
66
72
  crvUsd_stkcvxcrvUSDTWBTCWETH: new market_1.MarketConfig({
67
- collateralToken: "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278",
68
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
69
- lltv: (0, ethers_1.parseUnits)("0.86"),
70
73
  loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
74
+ collateralToken: "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278",
71
75
  oracle: "0x077Af6c2D4A75D4145d141F9e9421864C3940CB3",
76
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
77
+ lltv: 860000000000000000n,
72
78
  }),
73
79
  crvUsd_stkcvxcrvUSDCWBTCWETH: new market_1.MarketConfig({
74
- collateralToken: "0x0ea1a65A2c255f24Ee8D81eA6AaC54Decd9d269e",
75
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
76
- lltv: (0, ethers_1.parseUnits)("0.86"),
77
80
  loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
81
+ collateralToken: "0x0ea1a65A2c255f24Ee8D81eA6AaC54Decd9d269e",
78
82
  oracle: "0xd2F7C3B2fC97cC7b6AfDd76D163394680EFc35b9",
83
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
84
+ lltv: 860000000000000000n,
79
85
  }),
80
86
  crvUsd_stkcvxcrvCRVUSDTBTCWSTETH: new market_1.MarketConfig({
81
- collateralToken: "0x3ce8Ec9f3d89aD0A2DdbCC3FDB8991BD241Fc82E",
82
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
83
- lltv: (0, ethers_1.parseUnits)("0.86"),
84
87
  loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
88
+ collateralToken: "0x3ce8Ec9f3d89aD0A2DdbCC3FDB8991BD241Fc82E",
85
89
  oracle: "0xa9f7900476F43C45Ebf56cEa669B9c960C176112",
90
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
91
+ lltv: 860000000000000000n,
86
92
  }),
87
93
  crvUsd_stkcvxTryLSD: new market_1.MarketConfig({
88
- collateralToken: "0x6BA072F0d22806F2C52e9792AF47f2D59103BEBE",
89
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
90
- lltv: (0, ethers_1.parseUnits)("0.86"),
91
94
  loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
95
+ collateralToken: "0x6BA072F0d22806F2C52e9792AF47f2D59103BEBE",
92
96
  oracle: "0x18B0d7311a97c5377445C80c768ab5201Bb27B5a",
97
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
98
+ lltv: 860000000000000000n,
93
99
  }),
94
100
  crvUsd_stkcvxcrvUSDETHCRV: new market_1.MarketConfig({
95
- collateralToken: "0xAc904BAfBb5FB04Deb2b6198FdCEedE75a78Ce5a",
96
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
97
- lltv: (0, ethers_1.parseUnits)("0.86"),
98
101
  loanToken: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
102
+ collateralToken: "0xAc904BAfBb5FB04Deb2b6198FdCEedE75a78Ce5a",
99
103
  oracle: "0xad7e157815df05029125B568E39d5402550d60bb",
104
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
105
+ lltv: 860000000000000000n,
100
106
  }),
101
107
  usda_re7Eth: new market_1.MarketConfig({
102
- collateralToken: "0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0",
103
- irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
104
- lltv: (0, ethers_1.parseUnits)("0.86"),
105
108
  loanToken: "0x0000206329b97DB379d5E1Bf586BbDB969C63274",
109
+ collateralToken: "0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0",
106
110
  oracle: "0x76052A2A28fDCB8124f4686C63C68355b142de3B",
111
+ irm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
112
+ lltv: 860000000000000000n,
107
113
  }),
108
114
  };