@morpho-org/blue-sdk 1.0.4 → 1.0.6
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/addresses.js +1 -1
- package/lib/market/Market.d.ts +4 -1
- package/lib/market/Market.js +4 -3
- package/lib/market/MarketUtils.js +5 -1
- package/lib/position/Position.js +1 -1
- package/lib/token/ERC20Metadata.js +1 -1
- package/lib/token/WrappedToken.d.ts +3 -3
- package/lib/token/WrappedToken.js +6 -5
- package/package.json +2 -2
package/lib/addresses.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare const addresses: {
|
|
|
71
71
|
readonly 8453: {
|
|
72
72
|
readonly morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb";
|
|
73
73
|
readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
74
|
-
readonly bundler: "
|
|
74
|
+
readonly bundler: "0x23055618898e202386e6c13955a58D3C68200BFB";
|
|
75
75
|
readonly wNative: "0x4200000000000000000000000000000000000006";
|
|
76
76
|
readonly adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687";
|
|
77
77
|
readonly publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467";
|
package/lib/addresses.js
CHANGED
|
@@ -79,7 +79,7 @@ exports.addresses = {
|
|
|
79
79
|
[chain_1.ChainId.BaseMainnet]: {
|
|
80
80
|
morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
|
|
81
81
|
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
82
|
-
bundler: "
|
|
82
|
+
bundler: "0x23055618898e202386e6c13955a58D3C68200BFB",
|
|
83
83
|
wNative: "0x4200000000000000000000000000000000000006",
|
|
84
84
|
adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687",
|
|
85
85
|
publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467",
|
package/lib/market/Market.d.ts
CHANGED
|
@@ -144,7 +144,10 @@ export declare class Market implements InputMarket {
|
|
|
144
144
|
toSupplyShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
145
145
|
toBorrowAssets(shares: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
146
146
|
toBorrowShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
|
|
147
|
-
getBorrowCapacityLimit(collateral
|
|
147
|
+
getBorrowCapacityLimit({ collateral, borrowShares, }: {
|
|
148
|
+
collateral: bigint;
|
|
149
|
+
borrowShares?: bigint;
|
|
150
|
+
}): CapacityLimit;
|
|
148
151
|
getRepayCapacityLimit(borrowShares: bigint, loanTokenBalance: bigint): CapacityLimit;
|
|
149
152
|
getWithdrawCapacityLimit(supplyShares: bigint): CapacityLimit;
|
|
150
153
|
getWithdrawCollateralCapacityLimit(position: {
|
package/lib/market/Market.js
CHANGED
|
@@ -170,8 +170,9 @@ class Market {
|
|
|
170
170
|
toBorrowShares(assets, rounding) {
|
|
171
171
|
return MarketUtils_1.MarketUtils.toBorrowShares(assets, this, rounding);
|
|
172
172
|
}
|
|
173
|
-
getBorrowCapacityLimit(collateral) {
|
|
174
|
-
|
|
173
|
+
getBorrowCapacityLimit({ collateral, borrowShares = 0n, }) {
|
|
174
|
+
// handle edge cases when the user is liquidatable (maxBorrow < borrow)
|
|
175
|
+
const maxBorrowableAssets = maths_1.MathUtils.zeroFloorSub(this.getMaxBorrowAssets(collateral), this.toBorrowAssets(borrowShares));
|
|
175
176
|
const { liquidity } = this;
|
|
176
177
|
if (maxBorrowableAssets > liquidity)
|
|
177
178
|
return {
|
|
@@ -227,7 +228,7 @@ class Market {
|
|
|
227
228
|
limiter: CapacityLimitReason.balance,
|
|
228
229
|
},
|
|
229
230
|
withdraw: this.getWithdrawCapacityLimit(position.supplyShares),
|
|
230
|
-
borrow: this.getBorrowCapacityLimit(position
|
|
231
|
+
borrow: this.getBorrowCapacityLimit(position),
|
|
231
232
|
repay: this.getRepayCapacityLimit(position.borrowShares, loanTokenBalance),
|
|
232
233
|
supplyCollateral: {
|
|
233
234
|
value: collateralTokenBalance,
|
|
@@ -24,8 +24,12 @@ var MarketUtils;
|
|
|
24
24
|
MarketUtils.getLiquidationIncentiveFactor = getLiquidationIncentiveFactor;
|
|
25
25
|
function getUtilization({ totalSupplyAssets, totalBorrowAssets, }) {
|
|
26
26
|
totalSupplyAssets = (0, ethers_1.toBigInt)(totalSupplyAssets);
|
|
27
|
-
|
|
27
|
+
totalBorrowAssets = (0, ethers_1.toBigInt)(totalBorrowAssets);
|
|
28
|
+
if (totalSupplyAssets === 0n) {
|
|
29
|
+
if (totalBorrowAssets > 0n)
|
|
30
|
+
return ethers_1.MaxUint256;
|
|
28
31
|
return 0n;
|
|
32
|
+
}
|
|
29
33
|
return maths_1.MathLib.wDivDown(totalBorrowAssets, totalSupplyAssets);
|
|
30
34
|
}
|
|
31
35
|
MarketUtils.getUtilization = getUtilization;
|
package/lib/position/Position.js
CHANGED
|
@@ -124,7 +124,7 @@ class AccrualPosition extends Position {
|
|
|
124
124
|
return this.market.getBorrowCapacityUsage(this);
|
|
125
125
|
}
|
|
126
126
|
get borrowCapacityLimit() {
|
|
127
|
-
return this.market.getBorrowCapacityLimit(this
|
|
127
|
+
return this.market.getBorrowCapacityLimit(this);
|
|
128
128
|
}
|
|
129
129
|
get withdrawCapacityLimit() {
|
|
130
130
|
return this.market.getWithdrawCapacityLimit(this.supplyShares);
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ERC20Metadata__factory = exports.Bytes32ERC20__factory = exports.decodeString = exports.isBytes32ERC20Metadata = void 0;
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const ethers_types_1 = require("ethers-types");
|
|
9
|
-
const addresses_1 = __importDefault(require("
|
|
9
|
+
const addresses_1 = __importDefault(require("../addresses"));
|
|
10
10
|
const chain_1 = require("../chain");
|
|
11
11
|
const isBytes32ERC20Metadata = (address, chainId) => {
|
|
12
12
|
switch (chainId) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RoundingDirection } from "../maths";
|
|
2
2
|
import { Address } from "../types";
|
|
3
|
-
import { Vault } from "../vault";
|
|
3
|
+
import { Vault, VaultConfig } from "../vault";
|
|
4
4
|
import { InputToken, Token } from "./Token";
|
|
5
5
|
export declare abstract class WrappedToken extends Token {
|
|
6
6
|
readonly underlying: Address;
|
|
@@ -33,10 +33,10 @@ export declare class ExchangeRateWrappedToken extends WrappedToken {
|
|
|
33
33
|
constructor(token: InputToken, underlying: Address, wrappedTokenExchangeRate: bigint);
|
|
34
34
|
}
|
|
35
35
|
export declare class VaultToken extends WrappedToken {
|
|
36
|
-
readonly underlying: Address;
|
|
37
36
|
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
38
37
|
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
39
38
|
totalAssets: bigint;
|
|
40
39
|
totalSupply: bigint;
|
|
41
|
-
|
|
40
|
+
config: VaultConfig;
|
|
41
|
+
constructor(token: InputToken, { totalAssets, totalSupply, config, }: Pick<Vault, "totalAssets" | "totalSupply" | "config">);
|
|
42
42
|
}
|
|
@@ -4,6 +4,7 @@ exports.VaultToken = exports.ExchangeRateWrappedToken = exports.ConstantWrappedT
|
|
|
4
4
|
const ethers_1 = require("ethers");
|
|
5
5
|
const ethers_2 = require("../ethers");
|
|
6
6
|
const maths_1 = require("../maths");
|
|
7
|
+
const vault_1 = require("../vault");
|
|
7
8
|
const Token_1 = require("./Token");
|
|
8
9
|
class WrappedToken extends Token_1.Token {
|
|
9
10
|
constructor(token, underlying) {
|
|
@@ -72,16 +73,16 @@ class ExchangeRateWrappedToken extends WrappedToken {
|
|
|
72
73
|
exports.ExchangeRateWrappedToken = ExchangeRateWrappedToken;
|
|
73
74
|
class VaultToken extends WrappedToken {
|
|
74
75
|
_wrap(amount, rounding) {
|
|
75
|
-
return
|
|
76
|
+
return vault_1.VaultUtils.toShares(amount, this, this.config, rounding);
|
|
76
77
|
}
|
|
77
78
|
_unwrap(amount, rounding) {
|
|
78
|
-
return
|
|
79
|
+
return vault_1.VaultUtils.toAssets(amount, this, this.config, rounding);
|
|
79
80
|
}
|
|
80
|
-
constructor(token,
|
|
81
|
-
super(token,
|
|
82
|
-
this.underlying = underlying;
|
|
81
|
+
constructor(token, { totalAssets, totalSupply, config, }) {
|
|
82
|
+
super(token, config.asset);
|
|
83
83
|
this.totalAssets = totalAssets;
|
|
84
84
|
this.totalSupply = totalSupply;
|
|
85
|
+
this.config = config;
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
exports.VaultToken = VaultToken;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"author": "Morpho Association <contact@morpho.org>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
],
|
|
51
51
|
"preset": "ts-jest"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "bbda7acf4856a4096456091ef5862d0df7e06f22"
|
|
54
54
|
}
|