@morpho-org/midnight-sdk 0.1.0 → 1.1.1

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 (128) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -46
  3. package/lib/cjs/abis.d.ts +1185 -996
  4. package/lib/cjs/abis.js +1445 -1211
  5. package/lib/cjs/api/MidnightApi.d.ts +22 -16
  6. package/lib/cjs/api/MidnightApi.js +89 -19
  7. package/lib/cjs/api/helpers.d.ts +11 -1
  8. package/lib/cjs/api/helpers.js +54 -4
  9. package/lib/cjs/api/types.d.ts +35 -9
  10. package/lib/cjs/constants.d.ts +12 -11
  11. package/lib/cjs/constants.js +14 -12
  12. package/lib/cjs/errors.d.ts +89 -1
  13. package/lib/cjs/errors.js +114 -3
  14. package/lib/cjs/fetch/Market.js +37 -3
  15. package/lib/cjs/fetch/index.d.ts +0 -1
  16. package/lib/cjs/fetch/index.js +0 -1
  17. package/lib/cjs/fetch/utils.d.ts +1 -1
  18. package/lib/cjs/fetch/utils.js +9 -2
  19. package/lib/cjs/index.d.ts +1 -1
  20. package/lib/cjs/index.js +2 -23
  21. package/lib/cjs/market/Market.d.ts +99 -33
  22. package/lib/cjs/market/Market.js +137 -28
  23. package/lib/cjs/market/MarketUtils.d.ts +61 -41
  24. package/lib/cjs/market/MarketUtils.js +108 -48
  25. package/lib/cjs/market/Position.d.ts +16 -11
  26. package/lib/cjs/market/Position.js +18 -12
  27. package/lib/cjs/market/PositionUtils.d.ts +6 -4
  28. package/lib/cjs/market/PositionUtils.js +9 -6
  29. package/lib/cjs/math/TickLib.d.ts +22 -0
  30. package/lib/cjs/math/TickLib.js +30 -0
  31. package/lib/cjs/math/index.d.ts +0 -1
  32. package/lib/cjs/math/index.js +0 -1
  33. package/lib/cjs/offers/Offer.d.ts +218 -12
  34. package/lib/cjs/offers/Offer.js +215 -7
  35. package/lib/cjs/offers/OfferUtils.d.ts +249 -143
  36. package/lib/cjs/offers/OfferUtils.js +326 -45
  37. package/lib/cjs/queries/GetPosition.d.ts +1 -1
  38. package/lib/cjs/queries/GetPosition.js +1 -1
  39. package/lib/cjs/signatures/EcrecoverRatifierUtils.d.ts +184 -38
  40. package/lib/cjs/signatures/EcrecoverRatifierUtils.js +296 -80
  41. package/lib/cjs/signatures/Group.d.ts +12 -4
  42. package/lib/cjs/signatures/Group.js +17 -7
  43. package/lib/cjs/signatures/GroupUtils.d.ts +60 -4
  44. package/lib/cjs/signatures/GroupUtils.js +57 -2
  45. package/lib/cjs/signatures/Payload.d.ts +277 -277
  46. package/lib/cjs/signatures/Payload.js +517 -534
  47. package/lib/cjs/signatures/RatifierUtils.d.ts +57 -0
  48. package/lib/cjs/signatures/RatifierUtils.js +105 -0
  49. package/lib/cjs/signatures/SetterRatifierUtils.d.ts +52 -13
  50. package/lib/cjs/signatures/SetterRatifierUtils.js +62 -19
  51. package/lib/cjs/signatures/Tree.d.ts +28 -16
  52. package/lib/cjs/signatures/Tree.js +35 -15
  53. package/lib/cjs/signatures/TreeUtils.d.ts +185 -63
  54. package/lib/cjs/signatures/TreeUtils.js +89 -79
  55. package/lib/cjs/signatures/eip712.d.ts +22 -0
  56. package/lib/cjs/signatures/eip712.js +26 -0
  57. package/lib/cjs/signatures/index.d.ts +2 -0
  58. package/lib/cjs/signatures/index.js +4 -0
  59. package/lib/cjs/signatures/offerStructInternal.d.ts +14 -0
  60. package/lib/cjs/signatures/offerStructInternal.js +72 -0
  61. package/lib/esm/abis.d.ts +1185 -996
  62. package/lib/esm/abis.js +1445 -1211
  63. package/lib/esm/api/MidnightApi.d.ts +22 -16
  64. package/lib/esm/api/MidnightApi.js +91 -21
  65. package/lib/esm/api/helpers.d.ts +11 -1
  66. package/lib/esm/api/helpers.js +54 -5
  67. package/lib/esm/api/types.d.ts +35 -9
  68. package/lib/esm/constants.d.ts +12 -11
  69. package/lib/esm/constants.js +13 -11
  70. package/lib/esm/errors.d.ts +89 -1
  71. package/lib/esm/errors.js +108 -2
  72. package/lib/esm/fetch/Market.js +38 -4
  73. package/lib/esm/fetch/index.d.ts +0 -1
  74. package/lib/esm/fetch/index.js +0 -1
  75. package/lib/esm/fetch/utils.d.ts +1 -1
  76. package/lib/esm/fetch/utils.js +9 -2
  77. package/lib/esm/index.d.ts +1 -1
  78. package/lib/esm/index.js +1 -1
  79. package/lib/esm/market/Market.d.ts +99 -33
  80. package/lib/esm/market/Market.js +137 -28
  81. package/lib/esm/market/MarketUtils.d.ts +61 -41
  82. package/lib/esm/market/MarketUtils.js +109 -49
  83. package/lib/esm/market/Position.d.ts +16 -11
  84. package/lib/esm/market/Position.js +19 -13
  85. package/lib/esm/market/PositionUtils.d.ts +6 -4
  86. package/lib/esm/market/PositionUtils.js +9 -6
  87. package/lib/esm/math/TickLib.d.ts +22 -0
  88. package/lib/esm/math/TickLib.js +31 -1
  89. package/lib/esm/math/index.d.ts +0 -1
  90. package/lib/esm/math/index.js +0 -1
  91. package/lib/esm/offers/Offer.d.ts +218 -12
  92. package/lib/esm/offers/Offer.js +216 -8
  93. package/lib/esm/offers/OfferUtils.d.ts +249 -143
  94. package/lib/esm/offers/OfferUtils.js +329 -48
  95. package/lib/esm/queries/GetPosition.d.ts +1 -1
  96. package/lib/esm/queries/GetPosition.js +1 -1
  97. package/lib/esm/signatures/EcrecoverRatifierUtils.d.ts +184 -38
  98. package/lib/esm/signatures/EcrecoverRatifierUtils.js +298 -82
  99. package/lib/esm/signatures/Group.d.ts +12 -4
  100. package/lib/esm/signatures/Group.js +17 -7
  101. package/lib/esm/signatures/GroupUtils.d.ts +60 -4
  102. package/lib/esm/signatures/GroupUtils.js +57 -2
  103. package/lib/esm/signatures/Payload.d.ts +277 -277
  104. package/lib/esm/signatures/Payload.js +517 -531
  105. package/lib/esm/signatures/RatifierUtils.d.ts +57 -0
  106. package/lib/esm/signatures/RatifierUtils.js +105 -0
  107. package/lib/esm/signatures/SetterRatifierUtils.d.ts +52 -13
  108. package/lib/esm/signatures/SetterRatifierUtils.js +62 -19
  109. package/lib/esm/signatures/Tree.d.ts +28 -16
  110. package/lib/esm/signatures/Tree.js +36 -16
  111. package/lib/esm/signatures/TreeUtils.d.ts +185 -63
  112. package/lib/esm/signatures/TreeUtils.js +91 -81
  113. package/lib/esm/signatures/eip712.d.ts +22 -0
  114. package/lib/esm/signatures/eip712.js +22 -0
  115. package/lib/esm/signatures/index.d.ts +2 -0
  116. package/lib/esm/signatures/index.js +2 -0
  117. package/lib/esm/signatures/offerStructInternal.d.ts +14 -0
  118. package/lib/esm/signatures/offerStructInternal.js +67 -0
  119. package/package.json +31 -34
  120. package/lib/cjs/fetch/Offer.d.ts +0 -74
  121. package/lib/cjs/fetch/Offer.js +0 -119
  122. package/lib/cjs/math/ConsumableUnitsLib.d.ts +0 -57
  123. package/lib/cjs/math/ConsumableUnitsLib.js +0 -77
  124. package/lib/esm/fetch/Offer.d.ts +0 -74
  125. package/lib/esm/fetch/Offer.js +0 -116
  126. package/lib/esm/math/ConsumableUnitsLib.d.ts +0 -57
  127. package/lib/esm/math/ConsumableUnitsLib.js +0 -74
  128. package/src/index.ts +0 -19
@@ -20,12 +20,14 @@ const GroupUtils_js_1 = require("./GroupUtils.js");
20
20
  *
21
21
  * const offer = Offer.create({
22
22
  * market: {
23
+ * chainId: 8453,
24
+ * midnight: "0x0000000000000000000000000000000000001000",
23
25
  * loanToken: "0x0000000000000000000000000000000000006000",
24
26
  * collateralParams: [
25
27
  * {
26
28
  * token: "0x0000000000000000000000000000000000007000",
27
29
  * lltv: 770000000000000000n,
28
- * maxLif: 1061007957559681697n,
30
+ * liquidationCursor: 250000000000000000n,
29
31
  * oracle: "0x0000000000000000000000000000000000008000",
30
32
  * },
31
33
  * ],
@@ -67,12 +69,14 @@ class Group {
67
69
  *
68
70
  * const offer = Offer.create({
69
71
  * market: {
72
+ * chainId: 8453,
73
+ * midnight: "0x0000000000000000000000000000000000001000",
70
74
  * loanToken: "0x0000000000000000000000000000000000006000",
71
75
  * collateralParams: [
72
76
  * {
73
77
  * token: "0x0000000000000000000000000000000000007000",
74
78
  * lltv: 770000000000000000n,
75
- * maxLif: 1061007957559681697n,
79
+ * liquidationCursor: 250000000000000000n,
76
80
  * oracle: "0x0000000000000000000000000000000000008000",
77
81
  * },
78
82
  * ],
@@ -112,12 +116,14 @@ class Group {
112
116
  *
113
117
  * const offer = Offer.create({
114
118
  * market: {
119
+ * chainId: 8453,
120
+ * midnight: "0x0000000000000000000000000000000000001000",
115
121
  * loanToken: "0x0000000000000000000000000000000000006000",
116
122
  * collateralParams: [
117
123
  * {
118
124
  * token: "0x0000000000000000000000000000000000007000",
119
125
  * lltv: 770000000000000000n,
120
- * maxLif: 1061007957559681697n,
126
+ * liquidationCursor: 250000000000000000n,
121
127
  * oracle: "0x0000000000000000000000000000000000008000",
122
128
  * },
123
129
  * ],
@@ -138,9 +144,11 @@ class Group {
138
144
  * ```
139
145
  */
140
146
  static from(entry) {
141
- return entry instanceof Group
142
- ? entry
143
- : new Group("offers" in entry ? entry.offers : [entry]);
147
+ if (entry instanceof Group)
148
+ return entry;
149
+ if (GroupUtils_js_1.GroupUtils.isGroupInput(entry))
150
+ return new Group(entry.offers);
151
+ return new Group([entry]);
144
152
  }
145
153
  /**
146
154
  * Creates a protocol-valid offer group.
@@ -161,12 +169,14 @@ class Group {
161
169
  *
162
170
  * const offer = Offer.create({
163
171
  * market: {
172
+ * chainId: 8453,
173
+ * midnight: "0x0000000000000000000000000000000000001000",
164
174
  * loanToken: "0x0000000000000000000000000000000000006000",
165
175
  * collateralParams: [
166
176
  * {
167
177
  * token: "0x0000000000000000000000000000000000007000",
168
178
  * lltv: 770000000000000000n,
169
- * maxLif: 1061007957559681697n,
179
+ * liquidationCursor: 250000000000000000n,
170
180
  * oracle: "0x0000000000000000000000000000000000008000",
171
181
  * },
172
182
  * ],
@@ -12,12 +12,14 @@ import { type IOffer, type OfferStruct } from "../offers/index.js";
12
12
  * offers: [
13
13
  * Offer.create({
14
14
  * market: {
15
+ * chainId: 8453,
16
+ * midnight: "0x0000000000000000000000000000000000001000",
15
17
  * loanToken: "0x0000000000000000000000000000000000006000",
16
18
  * collateralParams: [
17
19
  * {
18
20
  * token: "0x0000000000000000000000000000000000007000",
19
21
  * lltv: 770000000000000000n,
20
- * maxLif: 1061007957559681697n,
22
+ * liquidationCursor: 250000000000000000n,
21
23
  * oracle: "0x0000000000000000000000000000000000008000",
22
24
  * },
23
25
  * ],
@@ -57,12 +59,14 @@ export interface IGroup {
57
59
  *
58
60
  * const input: GroupInput = Offer.create({
59
61
  * market: {
62
+ * chainId: 8453,
63
+ * midnight: "0x0000000000000000000000000000000000001000",
60
64
  * loanToken: "0x0000000000000000000000000000000000006000",
61
65
  * collateralParams: [
62
66
  * {
63
67
  * token: "0x0000000000000000000000000000000000007000",
64
68
  * lltv: 770000000000000000n,
65
- * maxLif: 1061007957559681697n,
69
+ * liquidationCursor: 250000000000000000n,
66
70
  * oracle: "0x0000000000000000000000000000000000008000",
67
71
  * },
68
72
  * ],
@@ -99,6 +103,54 @@ export type GroupInput = IGroup | IOffer;
99
103
  * ```
100
104
  */
101
105
  export declare namespace GroupUtils {
106
+ /**
107
+ * Returns whether an entry is an explicit group rather than a standalone offer.
108
+ *
109
+ * Plain offer objects can also contain incidental `offers` properties, so the
110
+ * discriminant must reject values that still carry the offer `market` field.
111
+ *
112
+ * @param entry - Group or offer input to inspect.
113
+ * @returns Whether `entry` is an explicit group input.
114
+ * @example
115
+ * ```ts
116
+ * import { GroupUtils, Offer } from "@morpho-org/midnight-sdk";
117
+ *
118
+ * const offer = Offer.from({
119
+ * market: {
120
+ * chainId: 8453,
121
+ * midnight: "0x0000000000000000000000000000000000001000",
122
+ * loanToken: "0x0000000000000000000000000000000000006000",
123
+ * collateralParams: [
124
+ * {
125
+ * token: "0x0000000000000000000000000000000000007000",
126
+ * lltv: 770000000000000000n,
127
+ * liquidationCursor: 250000000000000000n,
128
+ * oracle: "0x0000000000000000000000000000000000008000",
129
+ * },
130
+ * ],
131
+ * maturity: 54_000n,
132
+ * rcfThreshold: 0n,
133
+ * enterGate: "0x0000000000000000000000000000000000000000",
134
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
135
+ * },
136
+ * buy: true,
137
+ * maker: "0x0000000000000000000000000000000000009000",
138
+ * start: 0n,
139
+ * expiry: 3_600n,
140
+ * tick: 5_000n,
141
+ * callback: "0x0000000000000000000000000000000000000000",
142
+ * callbackData: "0x",
143
+ * receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000000",
144
+ * ratifier: "0x0000000000000000000000000000000000004000",
145
+ * reduceOnly: false,
146
+ * maxUnits: 100n,
147
+ * maxAssets: 0n,
148
+ * continuousFeeCap: 0n,
149
+ * });
150
+ * console.log(GroupUtils.isGroupInput(offer));
151
+ * ```
152
+ */
153
+ function isGroupInput(entry: GroupInput): entry is IGroup;
102
154
  /**
103
155
  * Derives the deterministic content-addressed id for a group of offers.
104
156
  *
@@ -115,12 +167,14 @@ export declare namespace GroupUtils {
115
167
  *
116
168
  * const offer = Offer.create({
117
169
  * market: {
170
+ * chainId: 8453,
171
+ * midnight: "0x0000000000000000000000000000000000001000",
118
172
  * loanToken: "0x0000000000000000000000000000000000006000",
119
173
  * collateralParams: [
120
174
  * {
121
175
  * token: "0x0000000000000000000000000000000000007000",
122
176
  * lltv: 770000000000000000n,
123
- * maxLif: 1061007957559681697n,
177
+ * liquidationCursor: 250000000000000000n,
124
178
  * oracle: "0x0000000000000000000000000000000000008000",
125
179
  * },
126
180
  * ],
@@ -162,12 +216,14 @@ export declare namespace GroupUtils {
162
216
  *
163
217
  * const offer = Offer.create({
164
218
  * market: {
219
+ * chainId: 8453,
220
+ * midnight: "0x0000000000000000000000000000000000001000",
165
221
  * loanToken: "0x0000000000000000000000000000000000006000",
166
222
  * collateralParams: [
167
223
  * {
168
224
  * token: "0x0000000000000000000000000000000000007000",
169
225
  * lltv: 770000000000000000n,
170
- * maxLif: 1061007957559681697n,
226
+ * liquidationCursor: 250000000000000000n,
171
227
  * oracle: "0x0000000000000000000000000000000000008000",
172
228
  * },
173
229
  * ],
@@ -22,6 +22,57 @@ const index_js_1 = require("../offers/index.js");
22
22
  */
23
23
  var GroupUtils;
24
24
  (function (GroupUtils) {
25
+ /**
26
+ * Returns whether an entry is an explicit group rather than a standalone offer.
27
+ *
28
+ * Plain offer objects can also contain incidental `offers` properties, so the
29
+ * discriminant must reject values that still carry the offer `market` field.
30
+ *
31
+ * @param entry - Group or offer input to inspect.
32
+ * @returns Whether `entry` is an explicit group input.
33
+ * @example
34
+ * ```ts
35
+ * import { GroupUtils, Offer } from "@morpho-org/midnight-sdk";
36
+ *
37
+ * const offer = Offer.from({
38
+ * market: {
39
+ * chainId: 8453,
40
+ * midnight: "0x0000000000000000000000000000000000001000",
41
+ * loanToken: "0x0000000000000000000000000000000000006000",
42
+ * collateralParams: [
43
+ * {
44
+ * token: "0x0000000000000000000000000000000000007000",
45
+ * lltv: 770000000000000000n,
46
+ * liquidationCursor: 250000000000000000n,
47
+ * oracle: "0x0000000000000000000000000000000000008000",
48
+ * },
49
+ * ],
50
+ * maturity: 54_000n,
51
+ * rcfThreshold: 0n,
52
+ * enterGate: "0x0000000000000000000000000000000000000000",
53
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
54
+ * },
55
+ * buy: true,
56
+ * maker: "0x0000000000000000000000000000000000009000",
57
+ * start: 0n,
58
+ * expiry: 3_600n,
59
+ * tick: 5_000n,
60
+ * callback: "0x0000000000000000000000000000000000000000",
61
+ * callbackData: "0x",
62
+ * receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000000",
63
+ * ratifier: "0x0000000000000000000000000000000000004000",
64
+ * reduceOnly: false,
65
+ * maxUnits: 100n,
66
+ * maxAssets: 0n,
67
+ * continuousFeeCap: 0n,
68
+ * });
69
+ * console.log(GroupUtils.isGroupInput(offer));
70
+ * ```
71
+ */
72
+ function isGroupInput(entry) {
73
+ return "offers" in entry && !("market" in entry);
74
+ }
75
+ GroupUtils.isGroupInput = isGroupInput;
25
76
  /**
26
77
  * Derives the deterministic content-addressed id for a group of offers.
27
78
  *
@@ -38,12 +89,14 @@ var GroupUtils;
38
89
  *
39
90
  * const offer = Offer.create({
40
91
  * market: {
92
+ * chainId: 8453,
93
+ * midnight: "0x0000000000000000000000000000000000001000",
41
94
  * loanToken: "0x0000000000000000000000000000000000006000",
42
95
  * collateralParams: [
43
96
  * {
44
97
  * token: "0x0000000000000000000000000000000000007000",
45
98
  * lltv: 770000000000000000n,
46
- * maxLif: 1061007957559681697n,
99
+ * liquidationCursor: 250000000000000000n,
47
100
  * oracle: "0x0000000000000000000000000000000000008000",
48
101
  * },
49
102
  * ],
@@ -94,12 +147,14 @@ var GroupUtils;
94
147
  *
95
148
  * const offer = Offer.create({
96
149
  * market: {
150
+ * chainId: 8453,
151
+ * midnight: "0x0000000000000000000000000000000000001000",
97
152
  * loanToken: "0x0000000000000000000000000000000000006000",
98
153
  * collateralParams: [
99
154
  * {
100
155
  * token: "0x0000000000000000000000000000000000007000",
101
156
  * lltv: 770000000000000000n,
102
- * maxLif: 1061007957559681697n,
157
+ * liquidationCursor: 250000000000000000n,
103
158
  * oracle: "0x0000000000000000000000000000000000008000",
104
159
  * },
105
160
  * ],