@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
@@ -17,12 +17,14 @@ import { GroupUtils } from "./GroupUtils.js";
17
17
  *
18
18
  * const offer = Offer.create({
19
19
  * market: {
20
+ * chainId: 8453,
21
+ * midnight: "0x0000000000000000000000000000000000001000",
20
22
  * loanToken: "0x0000000000000000000000000000000000006000",
21
23
  * collateralParams: [
22
24
  * {
23
25
  * token: "0x0000000000000000000000000000000000007000",
24
26
  * lltv: 770000000000000000n,
25
- * maxLif: 1061007957559681697n,
27
+ * liquidationCursor: 250000000000000000n,
26
28
  * oracle: "0x0000000000000000000000000000000000008000",
27
29
  * },
28
30
  * ],
@@ -64,12 +66,14 @@ export class Group {
64
66
  *
65
67
  * const offer = Offer.create({
66
68
  * market: {
69
+ * chainId: 8453,
70
+ * midnight: "0x0000000000000000000000000000000000001000",
67
71
  * loanToken: "0x0000000000000000000000000000000000006000",
68
72
  * collateralParams: [
69
73
  * {
70
74
  * token: "0x0000000000000000000000000000000000007000",
71
75
  * lltv: 770000000000000000n,
72
- * maxLif: 1061007957559681697n,
76
+ * liquidationCursor: 250000000000000000n,
73
77
  * oracle: "0x0000000000000000000000000000000000008000",
74
78
  * },
75
79
  * ],
@@ -109,12 +113,14 @@ export class Group {
109
113
  *
110
114
  * const offer = Offer.create({
111
115
  * market: {
116
+ * chainId: 8453,
117
+ * midnight: "0x0000000000000000000000000000000000001000",
112
118
  * loanToken: "0x0000000000000000000000000000000000006000",
113
119
  * collateralParams: [
114
120
  * {
115
121
  * token: "0x0000000000000000000000000000000000007000",
116
122
  * lltv: 770000000000000000n,
117
- * maxLif: 1061007957559681697n,
123
+ * liquidationCursor: 250000000000000000n,
118
124
  * oracle: "0x0000000000000000000000000000000000008000",
119
125
  * },
120
126
  * ],
@@ -135,9 +141,11 @@ export class Group {
135
141
  * ```
136
142
  */
137
143
  static from(entry) {
138
- return entry instanceof Group
139
- ? entry
140
- : new Group("offers" in entry ? entry.offers : [entry]);
144
+ if (entry instanceof Group)
145
+ return entry;
146
+ if (GroupUtils.isGroupInput(entry))
147
+ return new Group(entry.offers);
148
+ return new Group([entry]);
141
149
  }
142
150
  /**
143
151
  * Creates a protocol-valid offer group.
@@ -158,12 +166,14 @@ export class Group {
158
166
  *
159
167
  * const offer = Offer.create({
160
168
  * market: {
169
+ * chainId: 8453,
170
+ * midnight: "0x0000000000000000000000000000000000001000",
161
171
  * loanToken: "0x0000000000000000000000000000000000006000",
162
172
  * collateralParams: [
163
173
  * {
164
174
  * token: "0x0000000000000000000000000000000000007000",
165
175
  * lltv: 770000000000000000n,
166
- * maxLif: 1061007957559681697n,
176
+ * liquidationCursor: 250000000000000000n,
167
177
  * oracle: "0x0000000000000000000000000000000000008000",
168
178
  * },
169
179
  * ],
@@ -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
  * ],
@@ -19,6 +19,57 @@ import { OfferUtils } from "../offers/index.js";
19
19
  */
20
20
  export var GroupUtils;
21
21
  (function (GroupUtils) {
22
+ /**
23
+ * Returns whether an entry is an explicit group rather than a standalone offer.
24
+ *
25
+ * Plain offer objects can also contain incidental `offers` properties, so the
26
+ * discriminant must reject values that still carry the offer `market` field.
27
+ *
28
+ * @param entry - Group or offer input to inspect.
29
+ * @returns Whether `entry` is an explicit group input.
30
+ * @example
31
+ * ```ts
32
+ * import { GroupUtils, Offer } from "@morpho-org/midnight-sdk";
33
+ *
34
+ * const offer = Offer.from({
35
+ * market: {
36
+ * chainId: 8453,
37
+ * midnight: "0x0000000000000000000000000000000000001000",
38
+ * loanToken: "0x0000000000000000000000000000000000006000",
39
+ * collateralParams: [
40
+ * {
41
+ * token: "0x0000000000000000000000000000000000007000",
42
+ * lltv: 770000000000000000n,
43
+ * liquidationCursor: 250000000000000000n,
44
+ * oracle: "0x0000000000000000000000000000000000008000",
45
+ * },
46
+ * ],
47
+ * maturity: 54_000n,
48
+ * rcfThreshold: 0n,
49
+ * enterGate: "0x0000000000000000000000000000000000000000",
50
+ * liquidatorGate: "0x0000000000000000000000000000000000000000",
51
+ * },
52
+ * buy: true,
53
+ * maker: "0x0000000000000000000000000000000000009000",
54
+ * start: 0n,
55
+ * expiry: 3_600n,
56
+ * tick: 5_000n,
57
+ * callback: "0x0000000000000000000000000000000000000000",
58
+ * callbackData: "0x",
59
+ * receiverIfMakerIsSeller: "0x0000000000000000000000000000000000000000",
60
+ * ratifier: "0x0000000000000000000000000000000000004000",
61
+ * reduceOnly: false,
62
+ * maxUnits: 100n,
63
+ * maxAssets: 0n,
64
+ * continuousFeeCap: 0n,
65
+ * });
66
+ * console.log(GroupUtils.isGroupInput(offer));
67
+ * ```
68
+ */
69
+ function isGroupInput(entry) {
70
+ return "offers" in entry && !("market" in entry);
71
+ }
72
+ GroupUtils.isGroupInput = isGroupInput;
22
73
  /**
23
74
  * Derives the deterministic content-addressed id for a group of offers.
24
75
  *
@@ -35,12 +86,14 @@ export var GroupUtils;
35
86
  *
36
87
  * const offer = Offer.create({
37
88
  * market: {
89
+ * chainId: 8453,
90
+ * midnight: "0x0000000000000000000000000000000000001000",
38
91
  * loanToken: "0x0000000000000000000000000000000000006000",
39
92
  * collateralParams: [
40
93
  * {
41
94
  * token: "0x0000000000000000000000000000000000007000",
42
95
  * lltv: 770000000000000000n,
43
- * maxLif: 1061007957559681697n,
96
+ * liquidationCursor: 250000000000000000n,
44
97
  * oracle: "0x0000000000000000000000000000000000008000",
45
98
  * },
46
99
  * ],
@@ -91,12 +144,14 @@ export var GroupUtils;
91
144
  *
92
145
  * const offer = Offer.create({
93
146
  * market: {
147
+ * chainId: 8453,
148
+ * midnight: "0x0000000000000000000000000000000000001000",
94
149
  * loanToken: "0x0000000000000000000000000000000000006000",
95
150
  * collateralParams: [
96
151
  * {
97
152
  * token: "0x0000000000000000000000000000000000007000",
98
153
  * lltv: 770000000000000000n,
99
- * maxLif: 1061007957559681697n,
154
+ * liquidationCursor: 250000000000000000n,
100
155
  * oracle: "0x0000000000000000000000000000000000008000",
101
156
  * },
102
157
  * ],