@morpho-org/blue-sdk 2.0.0-alpha.3 → 2.0.0-test.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.
- package/lib/addresses.d.ts +1 -1
- package/lib/errors.d.ts +6 -0
- package/lib/errors.js +13 -1
- package/lib/helpers/format/format.test.d.ts +1 -0
- package/lib/helpers/format/format.test.js +255 -0
- package/lib/helpers/format/index.d.ts +1 -0
- package/lib/helpers/format/index.js +17 -0
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.js +18 -0
- package/lib/holding/Holding.d.ts +2 -7
- package/lib/holding/Holding.js +4 -14
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/maths/MathLib.js +2 -1
- package/lib/token/ConstantWrappedToken.d.ts +4 -3
- package/lib/token/ConstantWrappedToken.js +7 -5
- package/lib/token/Token.d.ts +2 -2
- package/lib/token/Token.js +1 -1
- package/lib/token/VaultToken.js +1 -1
- package/lib/types.d.ts +5 -2
- package/lib/vault/Vault.d.ts +1 -1
- package/lib/vault/VaultConfig.d.ts +3 -3
- package/lib/vault/VaultConfig.js +2 -2
- package/lib/vault/VaultMarketAllocation.d.ts +2 -2
- package/lib/vault/VaultMarketConfig.d.ts +4 -4
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +2 -2
- package/lib/vault/index.d.ts +0 -1
- package/lib/vault/index.js +0 -1
- package/package.json +6 -6
- package/lib/vault/VaultUser.d.ts +0 -26
- package/lib/vault/VaultUser.js +0 -28
package/lib/addresses.d.ts
CHANGED
|
@@ -87,7 +87,7 @@ export declare const getChainAddresses: (chainId: number) => ChainAddresses;
|
|
|
87
87
|
* - unwrapped token has same number of decimals than wrapped tokens.
|
|
88
88
|
*/
|
|
89
89
|
export declare const unwrappedTokensMapping: Record<ChainId, Record<Address, Address>>;
|
|
90
|
-
export declare function getUnwrappedToken(wrappedToken: Address, chainId: ChainId):
|
|
90
|
+
export declare function getUnwrappedToken(wrappedToken: Address, chainId: ChainId): string | undefined;
|
|
91
91
|
/**
|
|
92
92
|
* The registry of all known ERC20Wrapper tokens.
|
|
93
93
|
*/
|
package/lib/errors.d.ts
CHANGED
|
@@ -46,6 +46,12 @@ export declare namespace BlueErrors {
|
|
|
46
46
|
constructor(user: Address, marketId: MarketId);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
export declare class InvalidSignatureError extends Error {
|
|
50
|
+
readonly hash: string;
|
|
51
|
+
readonly signer: Address;
|
|
52
|
+
readonly recovered: Address;
|
|
53
|
+
constructor(hash: string, signer: Address, recovered: Address);
|
|
54
|
+
}
|
|
49
55
|
export interface ErrorClass<E extends Error> {
|
|
50
56
|
new (...args: any[]): E;
|
|
51
57
|
}
|
package/lib/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlueErrors = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
|
|
3
|
+
exports.InvalidSignatureError = exports.BlueErrors = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
|
|
4
4
|
exports._try = _try;
|
|
5
5
|
class UnknownDataError extends Error {
|
|
6
6
|
}
|
|
@@ -94,6 +94,18 @@ var BlueErrors;
|
|
|
94
94
|
}
|
|
95
95
|
BlueErrors.InsufficientCollateral = InsufficientCollateral;
|
|
96
96
|
})(BlueErrors || (exports.BlueErrors = BlueErrors = {}));
|
|
97
|
+
class InvalidSignatureError extends Error {
|
|
98
|
+
hash;
|
|
99
|
+
signer;
|
|
100
|
+
recovered;
|
|
101
|
+
constructor(hash, signer, recovered) {
|
|
102
|
+
super(`invalid signature for hash ${hash}: expected ${signer}, recovered ${recovered}`);
|
|
103
|
+
this.hash = hash;
|
|
104
|
+
this.signer = signer;
|
|
105
|
+
this.recovered = recovered;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.InvalidSignatureError = InvalidSignatureError;
|
|
97
109
|
function _try(accessor, ...errorClasses) {
|
|
98
110
|
try {
|
|
99
111
|
return accessor();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const format_1 = require("./format");
|
|
4
|
+
describe("format", () => {
|
|
5
|
+
const number = 12345.6789;
|
|
6
|
+
const bigint = 123456789n;
|
|
7
|
+
const decimals = 4;
|
|
8
|
+
describe("hex", () => {
|
|
9
|
+
describe("should properly format number in hex format", () => {
|
|
10
|
+
it("without option", () => {
|
|
11
|
+
expect(format_1.format.hex.of(number)).toEqual((123456789).toString(16));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe("should properly format bigint in hex format", () => {
|
|
15
|
+
it("without option", () => {
|
|
16
|
+
expect(format_1.format.hex.of(bigint, decimals)).toEqual((123456789).toString(16));
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe("number", () => {
|
|
21
|
+
describe("should properly format number in number format", () => {
|
|
22
|
+
it("without option", () => {
|
|
23
|
+
expect(format_1.format.number.of(number)).toEqual("12345.6789");
|
|
24
|
+
});
|
|
25
|
+
it("with digits", () => {
|
|
26
|
+
expect(format_1.format.number.digits(2).of(number)).toEqual("12345.67");
|
|
27
|
+
});
|
|
28
|
+
it("with min", () => {
|
|
29
|
+
expect(format_1.format.number.min(20000).of(number)).toEqual("< 20000.0000");
|
|
30
|
+
});
|
|
31
|
+
it("with max", () => {
|
|
32
|
+
expect(format_1.format.number.max(10000).of(number)).toEqual("> 10000.0000");
|
|
33
|
+
});
|
|
34
|
+
it("with sign", () => {
|
|
35
|
+
expect(format_1.format.number.sign().of(number)).toEqual("+12345.6789");
|
|
36
|
+
});
|
|
37
|
+
it("with unit", () => {
|
|
38
|
+
expect(format_1.format.number.unit("$").of(number)).toEqual("$12345.6789");
|
|
39
|
+
});
|
|
40
|
+
it("without trailing zeros", () => {
|
|
41
|
+
expect(format_1.format.number.digits(6).of(number)).toEqual("12345.678900");
|
|
42
|
+
expect(format_1.format.number.digits(6).removeTrailingZero().of(number)).toEqual("12345.6789");
|
|
43
|
+
});
|
|
44
|
+
it("with locale", () => {
|
|
45
|
+
expect(format_1.format.number.locale("fr-FR").of(number)).toEqual("12345,6789");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("should properly format bigint in number format", () => {
|
|
49
|
+
it("without option", () => {
|
|
50
|
+
expect(format_1.format.number.of(bigint, decimals)).toEqual("12345.6789");
|
|
51
|
+
});
|
|
52
|
+
it("with digits", () => {
|
|
53
|
+
expect(format_1.format.number.digits(2).of(bigint, decimals)).toEqual("12345.67");
|
|
54
|
+
});
|
|
55
|
+
it("with min", () => {
|
|
56
|
+
expect(format_1.format.number.min(20000).of(bigint, decimals)).toEqual("< 20000.0000");
|
|
57
|
+
});
|
|
58
|
+
it("with max", () => {
|
|
59
|
+
expect(format_1.format.number.max(10000).of(bigint, decimals)).toEqual("> 10000.0000");
|
|
60
|
+
});
|
|
61
|
+
it("with sign", () => {
|
|
62
|
+
expect(format_1.format.number.sign().of(bigint, decimals)).toEqual("+12345.6789");
|
|
63
|
+
});
|
|
64
|
+
it("with unit", () => {
|
|
65
|
+
expect(format_1.format.number.unit("$").of(bigint, decimals)).toEqual("$12345.6789");
|
|
66
|
+
});
|
|
67
|
+
it("without trailing zeros", () => {
|
|
68
|
+
expect(format_1.format.number.digits(6).of(bigint, decimals)).toEqual("12345.678900");
|
|
69
|
+
expect(format_1.format.number.digits(6).removeTrailingZero().of(bigint, decimals)).toEqual("12345.6789");
|
|
70
|
+
});
|
|
71
|
+
it("with locale", () => {
|
|
72
|
+
expect(format_1.format.number.locale("fr-FR").of(bigint, decimals)).toEqual("12345,6789");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe("short", () => {
|
|
77
|
+
describe("should properly format number in short format", () => {
|
|
78
|
+
it("without option", () => {
|
|
79
|
+
expect(format_1.format.short.of(number)).toEqual("12.3456789k");
|
|
80
|
+
});
|
|
81
|
+
it("with digits", () => {
|
|
82
|
+
expect(format_1.format.short.digits(2).of(number)).toEqual("12.34k");
|
|
83
|
+
});
|
|
84
|
+
it("with min", () => {
|
|
85
|
+
expect(format_1.format.short.min(20000).of(number)).toEqual("< 20.0000000k");
|
|
86
|
+
});
|
|
87
|
+
it("with max", () => {
|
|
88
|
+
expect(format_1.format.short.max(10000).of(number)).toEqual("> 10.0000000k");
|
|
89
|
+
});
|
|
90
|
+
it("with sign", () => {
|
|
91
|
+
expect(format_1.format.short.sign().of(number)).toEqual("+12.3456789k");
|
|
92
|
+
});
|
|
93
|
+
it("with unit", () => {
|
|
94
|
+
expect(format_1.format.short.unit("€").of(number)).toEqual("12.3456789k €");
|
|
95
|
+
});
|
|
96
|
+
it("without trailing zeros", () => {
|
|
97
|
+
expect(format_1.format.short.digits(8).of(number)).toEqual("12.34567890k");
|
|
98
|
+
expect(format_1.format.short.digits(8).removeTrailingZero().of(number)).toEqual("12.3456789k");
|
|
99
|
+
});
|
|
100
|
+
it("with small numbers with commas", () => {
|
|
101
|
+
expect(format_1.format.short.smallValuesWithCommas().of(number / 10)).toEqual("1,234.56789");
|
|
102
|
+
});
|
|
103
|
+
it("with locale", () => {
|
|
104
|
+
expect(format_1.format.short.locale("fr-FR").of(number)).toEqual("12,3456789k");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe("should properly format bigint in short format", () => {
|
|
108
|
+
it("without option", () => {
|
|
109
|
+
expect(format_1.format.short.of(bigint, decimals)).toEqual("12.3456789k");
|
|
110
|
+
});
|
|
111
|
+
it("with digits", () => {
|
|
112
|
+
expect(format_1.format.short.digits(2).of(bigint, decimals)).toEqual("12.34k");
|
|
113
|
+
});
|
|
114
|
+
it("with min", () => {
|
|
115
|
+
expect(format_1.format.short.min(20000).of(bigint, decimals)).toEqual("< 20.0000000k");
|
|
116
|
+
});
|
|
117
|
+
it("with max", () => {
|
|
118
|
+
expect(format_1.format.short.max(10000).of(bigint, decimals)).toEqual("> 10.0000000k");
|
|
119
|
+
});
|
|
120
|
+
it("with sign", () => {
|
|
121
|
+
expect(format_1.format.short.sign().of(bigint, decimals)).toEqual("+12.3456789k");
|
|
122
|
+
});
|
|
123
|
+
it("with unit", () => {
|
|
124
|
+
expect(format_1.format.short.unit("€").of(bigint, decimals)).toEqual("12.3456789k €");
|
|
125
|
+
});
|
|
126
|
+
it("without trailing zeros", () => {
|
|
127
|
+
expect(format_1.format.short.digits(8).of(bigint, decimals)).toEqual("12.34567890k");
|
|
128
|
+
expect(format_1.format.short.digits(8).removeTrailingZero().of(bigint, decimals)).toEqual("12.3456789k");
|
|
129
|
+
});
|
|
130
|
+
it("with locale", () => {
|
|
131
|
+
expect(format_1.format.short.locale("fr-FR").of(bigint, decimals)).toEqual("12,3456789k");
|
|
132
|
+
});
|
|
133
|
+
it("with small numbers with commas", () => {
|
|
134
|
+
expect(format_1.format.short.smallValuesWithCommas().of(bigint, decimals + 1)).toEqual("1,234.56789");
|
|
135
|
+
});
|
|
136
|
+
it("with small numbers with commas with locale", () => {
|
|
137
|
+
expect(format_1.format.short
|
|
138
|
+
.smallValuesWithCommas()
|
|
139
|
+
.locale("fr-FR")
|
|
140
|
+
.of(bigint, decimals + 1)).toEqual("1\u202F234,56789");
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe("commas", () => {
|
|
145
|
+
describe("should properly format number in commas format", () => {
|
|
146
|
+
it("without option", () => {
|
|
147
|
+
expect(format_1.format.commas.of(number)).toEqual("12,345.6789");
|
|
148
|
+
});
|
|
149
|
+
it("with digits", () => {
|
|
150
|
+
expect(format_1.format.commas.digits(2).of(number)).toEqual("12,345.67");
|
|
151
|
+
});
|
|
152
|
+
it("with min", () => {
|
|
153
|
+
expect(format_1.format.commas.min(20000).of(number)).toEqual("< 20,000.0000");
|
|
154
|
+
});
|
|
155
|
+
it("with max", () => {
|
|
156
|
+
expect(format_1.format.commas.max(10000).of(number)).toEqual("> 10,000.0000");
|
|
157
|
+
});
|
|
158
|
+
it("with sign", () => {
|
|
159
|
+
expect(format_1.format.commas.sign().of(number)).toEqual("+12,345.6789");
|
|
160
|
+
});
|
|
161
|
+
it("with unit", () => {
|
|
162
|
+
expect(format_1.format.commas.unit("ETH").of(number)).toEqual("12,345.6789 ETH");
|
|
163
|
+
});
|
|
164
|
+
it("without trailing zeros", () => {
|
|
165
|
+
expect(format_1.format.commas.digits(6).of(number)).toEqual("12,345.678900");
|
|
166
|
+
expect(format_1.format.commas.digits(6).removeTrailingZero().of(number)).toEqual("12,345.6789");
|
|
167
|
+
});
|
|
168
|
+
it("with locale", () => {
|
|
169
|
+
expect(format_1.format.commas.locale("fr-FR").of(number)).toEqual("12\u202F345,6789");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe("should properly format bigint in commas format", () => {
|
|
173
|
+
it("without option", () => {
|
|
174
|
+
expect(format_1.format.commas.of(bigint, decimals)).toEqual("12,345.6789");
|
|
175
|
+
});
|
|
176
|
+
it("with digits", () => {
|
|
177
|
+
expect(format_1.format.commas.digits(2).of(bigint, decimals)).toEqual("12,345.67");
|
|
178
|
+
});
|
|
179
|
+
it("with min", () => {
|
|
180
|
+
expect(format_1.format.commas.min(20000).of(bigint, decimals)).toEqual("< 20,000.0000");
|
|
181
|
+
});
|
|
182
|
+
it("with max", () => {
|
|
183
|
+
expect(format_1.format.commas.max(10000).of(bigint, decimals)).toEqual("> 10,000.0000");
|
|
184
|
+
});
|
|
185
|
+
it("with sign", () => {
|
|
186
|
+
expect(format_1.format.commas.sign().of(bigint, decimals)).toEqual("+12,345.6789");
|
|
187
|
+
});
|
|
188
|
+
it("with unit", () => {
|
|
189
|
+
expect(format_1.format.commas.unit("ETH").of(bigint, decimals)).toEqual("12,345.6789 ETH");
|
|
190
|
+
});
|
|
191
|
+
it("without trailing zeros", () => {
|
|
192
|
+
expect(format_1.format.commas.digits(6).of(bigint, decimals)).toEqual("12,345.678900");
|
|
193
|
+
expect(format_1.format.commas.digits(6).removeTrailingZero().of(bigint, decimals)).toEqual("12,345.6789");
|
|
194
|
+
});
|
|
195
|
+
it("with locale", () => {
|
|
196
|
+
// the correct space in fr-FR is narrow no-break space (U+202F)
|
|
197
|
+
expect(format_1.format.commas.locale("fr-FR").of(bigint, decimals)).toEqual("12\u202F345,6789");
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
describe("percent", () => {
|
|
202
|
+
describe("should properly format number in percent format", () => {
|
|
203
|
+
it("without option", () => {
|
|
204
|
+
expect(format_1.format.percent.of(number)).toEqual("1234567.8900");
|
|
205
|
+
});
|
|
206
|
+
it("with digits", () => {
|
|
207
|
+
expect(format_1.format.percent.digits(1).of(number)).toEqual("1234567.8");
|
|
208
|
+
});
|
|
209
|
+
it("with min", () => {
|
|
210
|
+
expect(format_1.format.percent.min(20000).of(number)).toEqual("< 2000000.0000");
|
|
211
|
+
});
|
|
212
|
+
it("with max", () => {
|
|
213
|
+
expect(format_1.format.percent.max(10000).of(number)).toEqual("> 1000000.0000");
|
|
214
|
+
});
|
|
215
|
+
it("with sign", () => {
|
|
216
|
+
expect(format_1.format.percent.sign().of(number)).toEqual("+1234567.8900");
|
|
217
|
+
});
|
|
218
|
+
it("with unit", () => {
|
|
219
|
+
expect(format_1.format.percent.unit("%").of(number)).toEqual("1234567.8900%");
|
|
220
|
+
});
|
|
221
|
+
it("without trailing zeros", () => {
|
|
222
|
+
expect(format_1.format.percent.removeTrailingZero().of(number)).toEqual("1234567.89");
|
|
223
|
+
});
|
|
224
|
+
it("with locale", () => {
|
|
225
|
+
expect(format_1.format.percent.locale("fr-FR").of(number)).toEqual("1234567,8900");
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
describe("should properly format bigint in percent format", () => {
|
|
229
|
+
it("without option", () => {
|
|
230
|
+
expect(format_1.format.percent.of(bigint, decimals)).toEqual("1234567.8900");
|
|
231
|
+
});
|
|
232
|
+
it("with digits", () => {
|
|
233
|
+
expect(format_1.format.percent.digits(1).of(bigint, decimals)).toEqual("1234567.8");
|
|
234
|
+
});
|
|
235
|
+
it("with min", () => {
|
|
236
|
+
expect(format_1.format.percent.min(20000).of(bigint, decimals)).toEqual("< 2000000.0000");
|
|
237
|
+
});
|
|
238
|
+
it("with max", () => {
|
|
239
|
+
expect(format_1.format.percent.max(10000).of(bigint, decimals)).toEqual("> 1000000.0000");
|
|
240
|
+
});
|
|
241
|
+
it("with sign", () => {
|
|
242
|
+
expect(format_1.format.percent.sign().of(bigint, decimals)).toEqual("+1234567.8900");
|
|
243
|
+
});
|
|
244
|
+
it("with unit", () => {
|
|
245
|
+
expect(format_1.format.percent.unit("%").of(bigint, decimals)).toEqual("1234567.8900%");
|
|
246
|
+
});
|
|
247
|
+
it("without trailing zeros", () => {
|
|
248
|
+
expect(format_1.format.percent.removeTrailingZero().of(bigint, decimals)).toEqual("1234567.89");
|
|
249
|
+
});
|
|
250
|
+
it("with locale", () => {
|
|
251
|
+
expect(format_1.format.percent.locale("fr-FR").of(bigint, decimals)).toEqual("1234567,8900");
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./format";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./format"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./locale"), exports);
|
|
18
|
+
__exportStar(require("./format"), exports);
|
package/lib/holding/Holding.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address
|
|
1
|
+
import { Address } 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,11 +8,6 @@ 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
|
-
}
|
|
16
11
|
export interface InputHolding {
|
|
17
12
|
user: Address;
|
|
18
13
|
token: Address;
|
|
@@ -20,7 +15,7 @@ export interface InputHolding {
|
|
|
20
15
|
[key in Erc20AllowanceRecipient]: bigint;
|
|
21
16
|
};
|
|
22
17
|
permit2Allowances: {
|
|
23
|
-
[key in Permit2AllowanceRecipient]:
|
|
18
|
+
[key in Permit2AllowanceRecipient]: Permit2Allowance;
|
|
24
19
|
};
|
|
25
20
|
erc2612Nonce?: bigint;
|
|
26
21
|
canTransfer?: boolean;
|
package/lib/holding/Holding.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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");
|
|
5
6
|
exports.ERC20_ALLOWANCE_RECIPIENTS = [
|
|
6
7
|
"morpho",
|
|
7
8
|
"permit2",
|
|
@@ -41,27 +42,16 @@ class Holding {
|
|
|
41
42
|
* `undefined` if the token does not support ERC-2612.
|
|
42
43
|
*/
|
|
43
44
|
erc2612Nonce;
|
|
44
|
-
constructor({ user, token, erc20Allowances, permit2Allowances, balance, erc2612Nonce, canTransfer, }) {
|
|
45
|
+
constructor({ user, token, erc20Allowances, permit2Allowances, balance, erc2612Nonce, canTransfer = true, }) {
|
|
45
46
|
this.user = user;
|
|
46
47
|
this.token = token;
|
|
47
48
|
this.balance = balance;
|
|
48
|
-
this.canTransfer = canTransfer;
|
|
49
|
+
this.canTransfer = token === addresses_1.NATIVE_ADDRESS || canTransfer;
|
|
49
50
|
this.erc20Allowances = (0, morpho_ts_1.fromEntries)((0, morpho_ts_1.entries)(erc20Allowances).map(([address, allowance]) => [
|
|
50
51
|
address,
|
|
51
52
|
allowance,
|
|
52
53
|
]));
|
|
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
|
-
};
|
|
54
|
+
this.permit2Allowances = permit2Allowances;
|
|
65
55
|
if (erc2612Nonce != null)
|
|
66
56
|
this.erc2612Nonce = erc2612Nonce;
|
|
67
57
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./maths";
|
|
|
9
9
|
export * from "./user";
|
|
10
10
|
export * from "./holding";
|
|
11
11
|
export * from "./position";
|
|
12
|
+
export * from "./helpers";
|
|
12
13
|
export * from "./vault";
|
|
13
14
|
export * as constants from "./constants";
|
|
14
15
|
export * as errors from "./errors";
|
|
@@ -20,4 +21,5 @@ export * as holding from "./holding";
|
|
|
20
21
|
export * as types from "./types";
|
|
21
22
|
export * as maths from "./maths";
|
|
22
23
|
export * as user from "./user";
|
|
24
|
+
export * as helpers from "./helpers";
|
|
23
25
|
export * as vault from "./vault";
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.vault = exports.user = exports.maths = exports.types = exports.holding = exports.position = exports.token = exports.chain = exports.market = exports.errors = exports.constants = void 0;
|
|
29
|
+
exports.vault = exports.helpers = exports.user = exports.maths = exports.types = exports.holding = exports.position = exports.token = exports.chain = exports.market = exports.errors = exports.constants = void 0;
|
|
30
30
|
__exportStar(require("./addresses"), exports);
|
|
31
31
|
__exportStar(require("./constants"), exports);
|
|
32
32
|
__exportStar(require("./errors"), exports);
|
|
@@ -38,6 +38,7 @@ __exportStar(require("./maths"), exports);
|
|
|
38
38
|
__exportStar(require("./user"), exports);
|
|
39
39
|
__exportStar(require("./holding"), exports);
|
|
40
40
|
__exportStar(require("./position"), exports);
|
|
41
|
+
__exportStar(require("./helpers"), exports);
|
|
41
42
|
__exportStar(require("./vault"), exports);
|
|
42
43
|
exports.constants = __importStar(require("./constants"));
|
|
43
44
|
exports.errors = __importStar(require("./errors"));
|
|
@@ -49,4 +50,5 @@ exports.holding = __importStar(require("./holding"));
|
|
|
49
50
|
exports.types = __importStar(require("./types"));
|
|
50
51
|
exports.maths = __importStar(require("./maths"));
|
|
51
52
|
exports.user = __importStar(require("./user"));
|
|
53
|
+
exports.helpers = __importStar(require("./helpers"));
|
|
52
54
|
exports.vault = __importStar(require("./vault"));
|
package/lib/maths/MathLib.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MathLib = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const helpers_1 = require("../helpers");
|
|
5
6
|
/**
|
|
6
7
|
* Library to manage fixed-point arithmetic.
|
|
7
8
|
* This library reproduces the behaviour of the solidity library MathLib
|
|
@@ -156,7 +157,7 @@ class MathLib {
|
|
|
156
157
|
static rateToApy(rate, period) {
|
|
157
158
|
const { unit, duration } = morpho_ts_1.Time.toPeriod(period);
|
|
158
159
|
const factor = morpho_ts_1.Time[unit].from.y(1) / duration;
|
|
159
|
-
return ((1 + Number(
|
|
160
|
+
return ((1 + Number(helpers_1.format.number.locale("en").of(BigInt(rate), 18))) ** factor -
|
|
160
161
|
1);
|
|
161
162
|
}
|
|
162
163
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { RoundingDirection } from "../maths";
|
|
2
|
-
import { Address
|
|
2
|
+
import { Address } from "../types";
|
|
3
3
|
import { InputToken } from "./Token";
|
|
4
4
|
import { WrappedToken } from "./WrappedToken";
|
|
5
5
|
export declare class ConstantWrappedToken extends WrappedToken {
|
|
6
|
-
readonly
|
|
7
|
-
|
|
6
|
+
readonly underlying: Address;
|
|
7
|
+
private readonly _underlyingDecimals;
|
|
8
|
+
constructor(token: InputToken, underlying: Address, _underlyingDecimals?: number);
|
|
8
9
|
toWrappedExactAmountIn(unwrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
9
10
|
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
10
11
|
toWrappedExactAmountOut(wrappedAmount: bigint, _slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
@@ -4,10 +4,12 @@ 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
|
-
|
|
8
|
-
|
|
7
|
+
underlying;
|
|
8
|
+
_underlyingDecimals;
|
|
9
|
+
constructor(token, underlying, _underlyingDecimals = 18) {
|
|
9
10
|
super(token, underlying);
|
|
10
|
-
this.
|
|
11
|
+
this.underlying = underlying;
|
|
12
|
+
this._underlyingDecimals = _underlyingDecimals;
|
|
11
13
|
}
|
|
12
14
|
toWrappedExactAmountIn(unwrappedAmount, _slippage, rounding = "Down") {
|
|
13
15
|
return super.toWrappedExactAmountIn(unwrappedAmount, 0n, rounding);
|
|
@@ -25,10 +27,10 @@ class ConstantWrappedToken extends WrappedToken_1.WrappedToken {
|
|
|
25
27
|
return super.toUnwrappedExactAmountOut(unwrappedAmount, 0n, rounding);
|
|
26
28
|
}
|
|
27
29
|
_wrap(amount) {
|
|
28
|
-
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this.decimals), 10n ** this.
|
|
30
|
+
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this.decimals), 10n ** BigInt(this._underlyingDecimals));
|
|
29
31
|
}
|
|
30
32
|
_unwrap(amount) {
|
|
31
|
-
return maths_1.MathLib.mulDivDown(amount, 10n ** this.
|
|
33
|
+
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this._underlyingDecimals), 10n ** BigInt(this.decimals));
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
exports.ConstantWrappedToken = ConstantWrappedToken;
|
package/lib/token/Token.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ChainId } from "../chain";
|
|
2
2
|
import { RoundingDirection } from "../maths";
|
|
3
|
-
import { Address
|
|
3
|
+
import { Address } from "../types";
|
|
4
4
|
export interface InputToken {
|
|
5
5
|
address: Address;
|
|
6
|
-
decimals:
|
|
6
|
+
decimals: number;
|
|
7
7
|
symbol: string;
|
|
8
8
|
name?: string;
|
|
9
9
|
}
|
package/lib/token/Token.js
CHANGED
package/lib/token/VaultToken.js
CHANGED
|
@@ -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 =
|
|
14
|
+
this.decimalsOffset = config.decimalsOffset;
|
|
15
15
|
}
|
|
16
16
|
_wrap(amount, rounding) {
|
|
17
17
|
return VaultUtils_1.VaultUtils.toShares(amount, this, this, rounding);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
export type Hex64 = string & {
|
|
2
|
+
__LENGTH__: 64;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* The address of a Contract, or an EOA
|
|
3
6
|
*/
|
|
4
|
-
export type Address =
|
|
7
|
+
export type Address = string;
|
|
5
8
|
/**
|
|
6
9
|
* The id of a market used on the Blue contract
|
|
7
10
|
*/
|
|
8
|
-
export type MarketId = `0x${
|
|
11
|
+
export type MarketId = `0x${Hex64}` & {
|
|
9
12
|
__TYPE__: "marketId";
|
|
10
13
|
};
|
|
11
14
|
export type BigIntish = bigint | string | number | boolean;
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export declare class Vault extends VaultToken implements InputVault {
|
|
|
111
111
|
*/
|
|
112
112
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
113
113
|
constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }: InputVault);
|
|
114
|
-
get asset():
|
|
114
|
+
get asset(): string;
|
|
115
115
|
/**
|
|
116
116
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
117
117
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ChainId } from "../chain";
|
|
2
|
-
import { Address
|
|
2
|
+
import { Address } from "../types";
|
|
3
3
|
export interface InputVaultConfig {
|
|
4
4
|
address: Address;
|
|
5
|
-
decimals:
|
|
6
|
-
decimalsOffset:
|
|
5
|
+
decimals: number;
|
|
6
|
+
decimalsOffset: bigint;
|
|
7
7
|
symbol: string;
|
|
8
8
|
name: string;
|
|
9
9
|
asset: Address;
|
package/lib/vault/VaultConfig.js
CHANGED
|
@@ -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 =
|
|
24
|
-
this.decimalsOffset =
|
|
23
|
+
this.decimals = decimals;
|
|
24
|
+
this.decimalsOffset = decimalsOffset;
|
|
25
25
|
this.symbol = symbol;
|
|
26
26
|
this.name = name;
|
|
27
27
|
this.asset = asset;
|
|
@@ -8,13 +8,13 @@ export declare class VaultMarketAllocation implements InputVaultMarketAllocation
|
|
|
8
8
|
/**
|
|
9
9
|
* The vault's configuration on the corresponding market.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
config: VaultMarketConfig;
|
|
12
12
|
/**
|
|
13
13
|
* The vault's position on the corresponding market.
|
|
14
14
|
*/
|
|
15
15
|
readonly position: AccrualPosition;
|
|
16
16
|
constructor({ config, position }: InputVaultMarketAllocation);
|
|
17
|
-
get vault():
|
|
17
|
+
get vault(): string;
|
|
18
18
|
get marketId(): import("..").MarketId;
|
|
19
19
|
get utilization(): bigint;
|
|
20
20
|
}
|
|
@@ -8,17 +8,17 @@ export interface InputVaultMarketConfig {
|
|
|
8
8
|
pendingCap: Pending<bigint>;
|
|
9
9
|
removableAt: bigint;
|
|
10
10
|
enabled: boolean;
|
|
11
|
-
publicAllocatorConfig
|
|
11
|
+
publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
|
|
12
12
|
}
|
|
13
13
|
export declare class VaultMarketConfig implements InputVaultMarketConfig {
|
|
14
14
|
/**
|
|
15
15
|
* The vault's address.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
vault: Address;
|
|
18
18
|
/**
|
|
19
19
|
* The market's id.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
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
|
-
|
|
41
|
+
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
|
-
|
|
15
|
+
vault: Address;
|
|
16
16
|
/**
|
|
17
17
|
* The market's id.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
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
|
*/
|
package/lib/vault/index.d.ts
CHANGED
package/lib/vault/index.js
CHANGED
|
@@ -19,5 +19,4 @@ __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);
|
|
23
22
|
__exportStar(require("./Vault"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-test.1",
|
|
4
4
|
"author": "Morpho Association <contact@morpho.org>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"keccak256": "^1.0.6"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@morpho-org/morpho-test": "^2.0.0-
|
|
21
|
-
"@morpho-org/morpho-ts": "^2.0.0-
|
|
20
|
+
"@morpho-org/morpho-test": "^2.0.0-test.1",
|
|
21
|
+
"@morpho-org/morpho-ts": "^2.0.0-test.1",
|
|
22
22
|
"@nomicfoundation/hardhat-ethers": "^3.0.6",
|
|
23
23
|
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
|
|
24
24
|
"@types/chai": "^4.3.14",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"mocha": "^10.4.0",
|
|
40
40
|
"ts-jest": "^29.2.4",
|
|
41
41
|
"ts-node": "^10.9.2",
|
|
42
|
-
"typescript": "^5.
|
|
42
|
+
"typescript": "^5.4.5"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@morpho-org/morpho-ts": "^2.0.0-
|
|
45
|
+
"@morpho-org/morpho-ts": "^2.0.0-test.1"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
],
|
|
67
67
|
"preset": "ts-jest"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "c435f8f652383995fd6bb52379d0b570138e43d9"
|
|
70
70
|
}
|
package/lib/vault/VaultUser.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/vault/VaultUser.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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;
|