@morpho-org/blue-sdk 1.0.6 → 1.2.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/README.md +2 -2
- package/lib/addresses.d.ts +34 -20
- package/lib/addresses.js +50 -13
- package/lib/chain.d.ts +30 -0
- package/lib/chain.js +288 -0
- package/lib/chain.test.js +22 -0
- package/lib/constants.d.ts +27 -6
- package/lib/constants.js +28 -8
- package/lib/errors.d.ts +18 -7
- package/lib/errors.js +38 -10
- package/lib/helpers/format/format.js +21 -60
- package/lib/helpers/index.d.ts +0 -2
- package/lib/helpers/index.js +0 -2
- package/lib/holding/Holding.d.ts +3 -4
- package/lib/holding/Holding.js +32 -4
- package/lib/index.d.ts +0 -8
- package/lib/index.js +1 -9
- package/lib/market/Market.d.ts +202 -54
- package/lib/market/Market.js +263 -62
- package/lib/market/MarketConfig.d.ts +17 -9
- package/lib/market/MarketConfig.js +39 -21
- package/lib/market/MarketUtils.d.ts +151 -102
- package/lib/market/MarketUtils.js +91 -39
- package/lib/market/MarketUtils.test.js +1 -2
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
- package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
- package/lib/maths/MathLib.d.ts +35 -15
- package/lib/maths/MathLib.js +53 -33
- package/lib/maths/SharesMath.d.ts +3 -3
- package/lib/maths/SharesMath.js +2 -3
- package/lib/maths/index.d.ts +0 -1
- package/lib/maths/index.js +0 -1
- package/lib/position/Position.d.ts +5 -26
- package/lib/position/Position.js +28 -35
- package/lib/tests/mocks/markets.d.ts +1 -0
- package/lib/tests/mocks/markets.js +35 -29
- package/lib/token/Token.d.ts +4 -3
- package/lib/token/Token.js +28 -3
- package/lib/token/WrappedToken.js +12 -6
- package/lib/token/index.d.ts +1 -1
- package/lib/token/index.js +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +3 -4
- package/lib/user/User.js +12 -0
- package/lib/vault/Vault.d.ts +12 -12
- package/lib/vault/Vault.js +102 -18
- package/lib/vault/VaultConfig.js +9 -3
- package/lib/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/vault/VaultMarketAllocation.js +30 -0
- package/lib/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/vault/VaultMarketConfig.js +43 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
- package/lib/vault/VaultUtils.d.ts +8 -9
- package/lib/vault/VaultUtils.js +2 -3
- package/lib/vault/index.d.ts +3 -1
- package/lib/vault/index.js +3 -1
- package/package.json +6 -11
- package/lib/chain/chain.constants.d.ts +0 -3
- package/lib/chain/chain.constants.js +0 -232
- package/lib/chain/chain.test.js +0 -37
- package/lib/chain/chain.types.d.ts +0 -20
- package/lib/chain/chain.types.js +0 -30
- package/lib/chain/chain.utils.d.ts +0 -14
- package/lib/chain/chain.utils.js +0 -30
- package/lib/chain/index.d.ts +0 -2
- package/lib/chain/index.js +0 -18
- package/lib/ethers/ethers.test.d.ts +0 -1
- package/lib/ethers/ethers.test.js +0 -11
- package/lib/ethers/index.d.ts +0 -2
- package/lib/ethers/index.js +0 -18
- package/lib/ethers/safeGetAddress.d.ts +0 -1
- package/lib/ethers/safeGetAddress.js +0 -6
- package/lib/ethers/safeParseUnits.d.ts +0 -2
- package/lib/ethers/safeParseUnits.js +0 -25
- package/lib/evm.d.ts +0 -36
- package/lib/evm.js +0 -113
- package/lib/helpers/getChecksumedAddress.d.ts +0 -7
- package/lib/helpers/getChecksumedAddress.js +0 -17
- package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
- package/lib/helpers/isZeroAddressOrUnset.js +0 -14
- package/lib/maths/MathUtils.d.ts +0 -15
- package/lib/maths/MathUtils.js +0 -33
- package/lib/notifications.d.ts +0 -98
- package/lib/notifications.js +0 -52
- package/lib/signatures/index.d.ts +0 -12
- package/lib/signatures/index.js +0 -39
- package/lib/signatures/manager.d.ts +0 -10
- package/lib/signatures/manager.js +0 -37
- package/lib/signatures/permit.d.ts +0 -21
- package/lib/signatures/permit.js +0 -101
- package/lib/signatures/permit2.d.ts +0 -20
- package/lib/signatures/permit2.js +0 -91
- package/lib/signatures/types.d.ts +0 -13
- package/lib/signatures/types.js +0 -2
- package/lib/signatures/utils.d.ts +0 -6
- package/lib/signatures/utils.js +0 -44
- package/lib/token/ERC20Metadata.d.ts +0 -249
- package/lib/token/ERC20Metadata.js +0 -81
- package/lib/token/TokenNamespace.d.ts +0 -18
- package/lib/token/TokenNamespace.js +0 -55
- package/lib/vault/VaultAllocation.d.ts +0 -38
- package/lib/vault/VaultAllocation.js +0 -18
- /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
package/lib/maths/MathLib.d.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
78
|
-
static mulDiv(x:
|
|
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:
|
|
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:
|
|
113
|
+
static aprToApy(apr: BigIntish, compounding: Time.Unit): number;
|
|
94
114
|
}
|
package/lib/maths/MathLib.js
CHANGED
|
@@ -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(
|
|
20
|
-
|
|
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(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 = (
|
|
98
|
-
y = (
|
|
99
|
-
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 = (
|
|
112
|
-
y = (
|
|
113
|
-
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
|
-
|
|
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
|
|
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
|
|
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 {
|
|
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:
|
|
11
|
-
function toShares(assets:
|
|
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
|
}
|
package/lib/maths/SharesMath.js
CHANGED
|
@@ -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, (
|
|
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, (
|
|
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 = {}));
|
package/lib/maths/index.d.ts
CHANGED
package/lib/maths/index.js
CHANGED
|
@@ -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 {
|
|
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:
|
|
10
|
-
borrowShares:
|
|
11
|
-
collateral:
|
|
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:
|
|
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
|
}
|
package/lib/position/Position.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
26
|
-
this.borrowShares =
|
|
27
|
-
this.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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
@@ -127,7 +120,7 @@ class AccrualPosition extends Position {
|
|
|
127
120
|
return this.market.getBorrowCapacityLimit(this);
|
|
128
121
|
}
|
|
129
122
|
get withdrawCapacityLimit() {
|
|
130
|
-
return this.market.getWithdrawCapacityLimit(this
|
|
123
|
+
return this.market.getWithdrawCapacityLimit(this);
|
|
131
124
|
}
|
|
132
125
|
get withdrawCollateralCapacityLimit() {
|
|
133
126
|
return this.market.getWithdrawCollateralCapacityLimit(this);
|
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
63
|
+
lltv: 96500000000000000000n,
|
|
58
64
|
}),
|
|
59
65
|
idle_usdc: new market_1.MarketConfig({
|
|
60
66
|
loanToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
61
|
-
collateralToken:
|
|
62
|
-
oracle:
|
|
63
|
-
irm:
|
|
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
|
};
|
package/lib/token/Token.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChainId } from "../chain";
|
|
2
2
|
import { RoundingDirection } from "../maths";
|
|
3
3
|
import { Address } from "../types";
|
|
4
4
|
export interface InputToken {
|
|
@@ -8,6 +8,7 @@ export interface InputToken {
|
|
|
8
8
|
name?: string;
|
|
9
9
|
}
|
|
10
10
|
export declare class Token implements InputToken {
|
|
11
|
+
static native(chainId: ChainId): Token;
|
|
11
12
|
/**
|
|
12
13
|
* The token's address.
|
|
13
14
|
*/
|
|
@@ -36,10 +37,10 @@ export declare class TokenWithPrice extends Token {
|
|
|
36
37
|
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
37
38
|
* @param amount The amount of USD to quote.
|
|
38
39
|
*/
|
|
39
|
-
fromUsd(amount:
|
|
40
|
+
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint | null;
|
|
40
41
|
/**
|
|
41
42
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
42
43
|
* @param amount The amount of tokens to quote.
|
|
43
44
|
*/
|
|
44
|
-
toUsd(amount:
|
|
45
|
+
toUsd(amount: bigint, rounding?: RoundingDirection): bigint | null;
|
|
45
46
|
}
|