@defisaver/positions-sdk 0.0.183-dev-allocator-3 → 0.0.183-dev-allocator-5
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/cjs/config/contracts.d.ts +98 -12
- package/cjs/config/contracts.js +7 -3
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +10 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +38 -30
- package/cjs/types/contracts/generated/MorphoBlueView.d.ts +5 -5
- package/esm/config/contracts.d.ts +98 -12
- package/esm/config/contracts.js +7 -3
- package/esm/helpers/morphoBlueHelpers/index.d.ts +10 -2
- package/esm/helpers/morphoBlueHelpers/index.js +36 -29
- package/esm/types/contracts/generated/MorphoBlueView.d.ts +5 -5
- package/package.json +1 -1
- package/src/config/contracts.js +7 -3
- package/src/helpers/morphoBlueHelpers/index.ts +41 -28
- package/src/types/contracts/generated/MorphoBlueView.ts +9 -5
|
@@ -6311,21 +6311,11 @@ export namespace USDCPriceFeed {
|
|
|
6311
6311
|
export namespace MorphoBlueView {
|
|
6312
6312
|
let abi_73: ({
|
|
6313
6313
|
inputs: {
|
|
6314
|
-
components:
|
|
6315
|
-
components: {
|
|
6316
|
-
internalType: string;
|
|
6317
|
-
name: string;
|
|
6318
|
-
type: string;
|
|
6319
|
-
}[];
|
|
6320
|
-
internalType: string;
|
|
6321
|
-
name: string;
|
|
6322
|
-
type: string;
|
|
6323
|
-
} | {
|
|
6314
|
+
components: {
|
|
6324
6315
|
internalType: string;
|
|
6325
6316
|
name: string;
|
|
6326
6317
|
type: string;
|
|
6327
|
-
|
|
6328
|
-
})[];
|
|
6318
|
+
}[];
|
|
6329
6319
|
internalType: string;
|
|
6330
6320
|
name: string;
|
|
6331
6321
|
type: string;
|
|
@@ -6408,6 +6398,102 @@ export namespace MorphoBlueView {
|
|
|
6408
6398
|
address: string;
|
|
6409
6399
|
createdBlock: number;
|
|
6410
6400
|
oldVersions: {
|
|
6401
|
+
"20219255": {
|
|
6402
|
+
abi: ({
|
|
6403
|
+
inputs: {
|
|
6404
|
+
components: ({
|
|
6405
|
+
components: {
|
|
6406
|
+
internalType: string;
|
|
6407
|
+
name: string;
|
|
6408
|
+
type: string;
|
|
6409
|
+
}[];
|
|
6410
|
+
internalType: string;
|
|
6411
|
+
name: string;
|
|
6412
|
+
type: string;
|
|
6413
|
+
} | {
|
|
6414
|
+
internalType: string;
|
|
6415
|
+
name: string;
|
|
6416
|
+
type: string;
|
|
6417
|
+
components?: undefined;
|
|
6418
|
+
})[];
|
|
6419
|
+
internalType: string;
|
|
6420
|
+
name: string;
|
|
6421
|
+
type: string;
|
|
6422
|
+
}[];
|
|
6423
|
+
name: string;
|
|
6424
|
+
outputs: ({
|
|
6425
|
+
internalType: string;
|
|
6426
|
+
name: string;
|
|
6427
|
+
type: string;
|
|
6428
|
+
components?: undefined;
|
|
6429
|
+
} | {
|
|
6430
|
+
components: {
|
|
6431
|
+
internalType: string;
|
|
6432
|
+
name: string;
|
|
6433
|
+
type: string;
|
|
6434
|
+
}[];
|
|
6435
|
+
internalType: string;
|
|
6436
|
+
name: string;
|
|
6437
|
+
type: string;
|
|
6438
|
+
})[];
|
|
6439
|
+
stateMutability: string;
|
|
6440
|
+
type: string;
|
|
6441
|
+
} | {
|
|
6442
|
+
inputs: ({
|
|
6443
|
+
internalType: string;
|
|
6444
|
+
name: string;
|
|
6445
|
+
type: string;
|
|
6446
|
+
components?: undefined;
|
|
6447
|
+
} | {
|
|
6448
|
+
components: {
|
|
6449
|
+
internalType: string;
|
|
6450
|
+
name: string;
|
|
6451
|
+
type: string;
|
|
6452
|
+
}[];
|
|
6453
|
+
internalType: string;
|
|
6454
|
+
name: string;
|
|
6455
|
+
type: string;
|
|
6456
|
+
})[];
|
|
6457
|
+
name: string;
|
|
6458
|
+
outputs: {
|
|
6459
|
+
internalType: string;
|
|
6460
|
+
name: string;
|
|
6461
|
+
type: string;
|
|
6462
|
+
}[];
|
|
6463
|
+
stateMutability: string;
|
|
6464
|
+
type: string;
|
|
6465
|
+
} | {
|
|
6466
|
+
inputs: ({
|
|
6467
|
+
components: {
|
|
6468
|
+
internalType: string;
|
|
6469
|
+
name: string;
|
|
6470
|
+
type: string;
|
|
6471
|
+
}[];
|
|
6472
|
+
internalType: string;
|
|
6473
|
+
name: string;
|
|
6474
|
+
type: string;
|
|
6475
|
+
} | {
|
|
6476
|
+
internalType: string;
|
|
6477
|
+
name: string;
|
|
6478
|
+
type: string;
|
|
6479
|
+
components?: undefined;
|
|
6480
|
+
})[];
|
|
6481
|
+
name: string;
|
|
6482
|
+
outputs: {
|
|
6483
|
+
components: {
|
|
6484
|
+
internalType: string;
|
|
6485
|
+
name: string;
|
|
6486
|
+
type: string;
|
|
6487
|
+
}[];
|
|
6488
|
+
internalType: string;
|
|
6489
|
+
name: string;
|
|
6490
|
+
type: string;
|
|
6491
|
+
}[];
|
|
6492
|
+
stateMutability: string;
|
|
6493
|
+
type: string;
|
|
6494
|
+
})[];
|
|
6495
|
+
address: string;
|
|
6496
|
+
};
|
|
6411
6497
|
"18976639": {
|
|
6412
6498
|
abi: ({
|
|
6413
6499
|
inputs: {
|
package/cjs/config/contracts.js
CHANGED
|
@@ -993,12 +993,16 @@ module.exports = {
|
|
|
993
993
|
}
|
|
994
994
|
},
|
|
995
995
|
"MorphoBlueView": {
|
|
996
|
-
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "
|
|
996
|
+
"abi": [{ "inputs": [], "name": "LEGACY_MORPHO_TOKEN", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "MORPHO_TOKEN_WRAPPER", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "PUBLIC_ALLOCATOR", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "_marketParams", "type": "tuple" }, { "components": [{ "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct MorphoBlueView.LiquidityChangeParams[]", "name": "_params", "type": "tuple[]" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "components": [{ "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint128", "name": "lastUpdate", "type": "uint128" }, { "internalType": "uint128", "name": "fee", "type": "uint128" }], "internalType": "struct Market", "name": "market", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingId", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingParams", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
997
997
|
"networks": {
|
|
998
998
|
"1": {
|
|
999
|
-
"address": "
|
|
1000
|
-
"createdBlock":
|
|
999
|
+
"address": "0xCbFc68c2e07d4CAb24d80D426A9f85Dbe26bAdA9",
|
|
1000
|
+
"createdBlock": 21429349,
|
|
1001
1001
|
"oldVersions": {
|
|
1002
|
+
"20219255": {
|
|
1003
|
+
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct MorphoBlueView.LiquidityChangeParams", "name": "params", "type": "tuple" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "components": [{ "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint128", "name": "lastUpdate", "type": "uint128" }, { "internalType": "uint128", "name": "fee", "type": "uint128" }], "internalType": "struct Market", "name": "market", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingId", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingParams", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
1004
|
+
"address": "0x10B621823D4f3E85fBDF759e252598e4e097C1fd",
|
|
1005
|
+
},
|
|
1002
1006
|
"18976639": {
|
|
1003
1007
|
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
1004
1008
|
"address": "0xE29175a86B60138403a9534A391acaDb19f1E9a6",
|
|
@@ -8,11 +8,19 @@ export declare const getMorphoBlueAggregatedPositionData: ({ usedAssets, assetsD
|
|
|
8
8
|
}) => MorphoBlueAggregatedPositionData;
|
|
9
9
|
export declare const getSupplyRate: (totalSupplyAssets: string, totalBorrowAssets: string, borrowRate: string, fee: string) => string;
|
|
10
10
|
export declare const getBorrowRate: (borrowRate: string, totalBorrowShares: string) => string;
|
|
11
|
-
export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMarketData,
|
|
11
|
+
export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMarketData, actions: {
|
|
12
|
+
action: string;
|
|
13
|
+
amount: string;
|
|
14
|
+
asset: string;
|
|
15
|
+
}[], web3: Web3, network: NetworkNumber) => Promise<{
|
|
12
16
|
borrowRate: string;
|
|
13
17
|
supplyRate: string;
|
|
14
18
|
}>;
|
|
15
|
-
export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<
|
|
19
|
+
export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<{
|
|
20
|
+
reallocatableLiquidity: string;
|
|
21
|
+
targetBorrowUtilization: string;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const getLiquidityToAllocate: (amountToBorrow: string, totalBorrow: string, totalSupply: string, targetBorrowUtilization: string, reallocatableLiquidityAssets: string) => string;
|
|
16
24
|
export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
|
|
17
25
|
vaults: string[];
|
|
18
26
|
withdrawals: (string | string[])[][][];
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getReallocation = exports.getReallocatableLiquidity = exports.getApyAfterValuesEstimation = exports.getBorrowRate = exports.getSupplyRate = exports.getMorphoBlueAggregatedPositionData = void 0;
|
|
15
|
+
exports.getReallocation = exports.getLiquidityToAllocate = exports.getReallocatableLiquidity = exports.getApyAfterValuesEstimation = exports.getBorrowRate = exports.getSupplyRate = exports.getMorphoBlueAggregatedPositionData = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const tokens_1 = require("@defisaver/tokens");
|
|
18
18
|
const moneymarket_1 = require("../../moneymarket");
|
|
@@ -85,28 +85,30 @@ const getBorrowRate = (borrowRate, totalBorrowShares) => {
|
|
|
85
85
|
return new decimal_js_1.default(compound(borrowRate)).div(1e18).mul(100).toString();
|
|
86
86
|
};
|
|
87
87
|
exports.getBorrowRate = getBorrowRate;
|
|
88
|
-
const getApyAfterValuesEstimation = (selectedMarket,
|
|
88
|
+
const getApyAfterValuesEstimation = (selectedMarket, actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
89
|
const morphoBlueViewContract = (0, contracts_1.MorphoBlueViewContract)(web3, network);
|
|
90
90
|
const lltvInWei = (0, tokens_1.assetAmountInWei)(selectedMarket.lltv, 'ETH');
|
|
91
91
|
const marketData = [selectedMarket.loanToken, selectedMarket.collateralToken, selectedMarket.oracle, selectedMarket.irm, lltvInWei];
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
92
|
+
const params = actions.map(({ action, asset, amount }) => {
|
|
93
|
+
const isBorrowOperation = constants_1.borrowOperations.includes(action);
|
|
94
|
+
const amountInWei = (0, tokens_1.assetAmountInWei)(amount, asset);
|
|
95
|
+
let liquidityAdded;
|
|
96
|
+
let liquidityRemoved;
|
|
97
|
+
if (isBorrowOperation) {
|
|
98
|
+
liquidityAdded = action === 'payback' ? amountInWei : '0';
|
|
99
|
+
liquidityRemoved = action === 'borrow' ? amountInWei : '0';
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
liquidityAdded = action === 'collateral' ? amountInWei : '0';
|
|
103
|
+
liquidityRemoved = action === 'withdraw' ? amountInWei : '0';
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
liquidityAdded,
|
|
107
|
+
liquidityRemoved,
|
|
108
|
+
isBorrowOperation,
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
const data = yield morphoBlueViewContract.methods.getApyAfterValuesEstimation(marketData, params).call();
|
|
110
112
|
const borrowRate = (0, exports.getBorrowRate)(data.borrowRate, data.market.totalBorrowShares);
|
|
111
113
|
const supplyRate = (0, exports.getSupplyRate)(data.market.totalSupplyAssets, data.market.totalBorrowAssets, data.borrowRate, data.market.fee);
|
|
112
114
|
return { borrowRate, supplyRate };
|
|
@@ -177,9 +179,23 @@ const getReallocatableLiquidity = (marketId, network = common_1.NetworkNumber.Et
|
|
|
177
179
|
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketByUniqueKey;
|
|
178
180
|
if (!marketData)
|
|
179
181
|
throw new Error('Market data not found');
|
|
180
|
-
return marketData.reallocatableLiquidityAssets;
|
|
182
|
+
return { reallocatableLiquidity: marketData.reallocatableLiquidityAssets, targetBorrowUtilization: marketData.targetBorrowUtilization };
|
|
181
183
|
});
|
|
182
184
|
exports.getReallocatableLiquidity = getReallocatableLiquidity;
|
|
185
|
+
const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply, targetBorrowUtilization, reallocatableLiquidityAssets) => {
|
|
186
|
+
const newTotalBorrowAssets = new decimal_js_1.default(totalBorrow).add(amountToBorrow).toString();
|
|
187
|
+
const leftToBorrow = new decimal_js_1.default(totalSupply).sub(totalBorrow).toString();
|
|
188
|
+
let liquidityToAllocate = new decimal_js_1.default(newTotalBorrowAssets).div(targetBorrowUtilization).mul(1e18).sub(totalSupply)
|
|
189
|
+
.toFixed(0)
|
|
190
|
+
.toString();
|
|
191
|
+
if (new decimal_js_1.default(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new decimal_js_1.default(liquidityToAllocate).lt('0')) {
|
|
192
|
+
liquidityToAllocate = new decimal_js_1.default(amountToBorrow).sub(leftToBorrow).toString();
|
|
193
|
+
if (new decimal_js_1.default(reallocatableLiquidityAssets).lt(liquidityToAllocate))
|
|
194
|
+
throw new Error('Not enough liquidity available to allocate');
|
|
195
|
+
}
|
|
196
|
+
return liquidityToAllocate;
|
|
197
|
+
};
|
|
198
|
+
exports.getLiquidityToAllocate = getLiquidityToAllocate;
|
|
183
199
|
const getReallocation = (marketId, amountToBorrow, network = common_1.NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
200
|
var _b, _c, _d;
|
|
185
201
|
const response = yield fetch(API_URL, {
|
|
@@ -195,19 +211,11 @@ const getReallocation = (marketId, amountToBorrow, network = common_1.NetworkNum
|
|
|
195
211
|
if (!marketData)
|
|
196
212
|
throw new Error('Market data not found');
|
|
197
213
|
const newTotalBorrowAssets = new decimal_js_1.default(marketData.state.borrowAssets).add(amountToBorrow).toString();
|
|
198
|
-
const leftToBorrow = new decimal_js_1.default(marketData.state.supplyAssets).sub(marketData.state.borrowAssets).toString();
|
|
199
214
|
const newUtil = new decimal_js_1.default(newTotalBorrowAssets).div(marketData.state.supplyAssets).toString();
|
|
200
215
|
const newUtilScaled = new decimal_js_1.default(newUtil).mul(1e18).toString();
|
|
201
216
|
if (new decimal_js_1.default(newUtilScaled).lt(marketData.targetBorrowUtilization))
|
|
202
217
|
return { vaults: [], withdrawals: [] };
|
|
203
|
-
|
|
204
|
-
.toFixed(0)
|
|
205
|
-
.toString();
|
|
206
|
-
if (new decimal_js_1.default(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
|
|
207
|
-
liquidityToAllocate = new decimal_js_1.default(amountToBorrow).sub(leftToBorrow).toString();
|
|
208
|
-
if (new decimal_js_1.default(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate))
|
|
209
|
-
throw new Error('Not enough liquidity available to allocate');
|
|
210
|
-
}
|
|
218
|
+
const liquidityToAllocate = (0, exports.getLiquidityToAllocate)(amountToBorrow, marketData.state.borrowAssets, marketData.state.supplyAssets, marketData.targetBorrowUtilization, marketData.reallocatableLiquidityAssets);
|
|
211
219
|
const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce((acc, item) => {
|
|
212
220
|
const vaultAddress = item.vault.address;
|
|
213
221
|
acc[vaultAddress] = new decimal_js_1.default(acc[vaultAddress] || '0').add(item.assets).toString();
|
|
@@ -64,20 +64,17 @@ export type MarketStructOutputStruct = {
|
|
|
64
64
|
};
|
|
65
65
|
export type MarketStructOutput = MarketStructOutputArray & MarketStructOutputStruct;
|
|
66
66
|
export declare namespace MorphoBlueView {
|
|
67
|
-
type LiquidityChangeParamsStruct = [
|
|
68
|
-
marketParams: MarketParamsStruct;
|
|
67
|
+
type LiquidityChangeParamsStruct = [boolean, number | string | BN, number | string | BN] | {
|
|
69
68
|
isBorrowOperation: boolean;
|
|
70
69
|
liquidityAdded: number | string | BN;
|
|
71
70
|
liquidityRemoved: number | string | BN;
|
|
72
71
|
};
|
|
73
72
|
type LiquidityChangeParamsStructOutputArray = [
|
|
74
|
-
MarketParamsStructOutput,
|
|
75
73
|
boolean,
|
|
76
74
|
string,
|
|
77
75
|
string
|
|
78
76
|
];
|
|
79
77
|
type LiquidityChangeParamsStructOutputStruct = {
|
|
80
|
-
marketParams: MarketParamsStructOutput;
|
|
81
78
|
isBorrowOperation: boolean;
|
|
82
79
|
liquidityAdded: string;
|
|
83
80
|
liquidityRemoved: string;
|
|
@@ -160,8 +157,11 @@ export interface MorphoBlueView extends BaseContract {
|
|
|
160
157
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): MorphoBlueView;
|
|
161
158
|
clone(): MorphoBlueView;
|
|
162
159
|
methods: {
|
|
160
|
+
LEGACY_MORPHO_TOKEN(): NonPayableTransactionObject<string>;
|
|
163
161
|
MORPHO_BLUE_ADDRESS(): NonPayableTransactionObject<string>;
|
|
164
|
-
|
|
162
|
+
MORPHO_TOKEN_WRAPPER(): NonPayableTransactionObject<string>;
|
|
163
|
+
PUBLIC_ALLOCATOR(): NonPayableTransactionObject<string>;
|
|
164
|
+
getApyAfterValuesEstimation(_marketParams: MarketParamsStruct, _params: MorphoBlueView.LiquidityChangeParamsStruct[]): NonPayableTransactionObject<[
|
|
165
165
|
string,
|
|
166
166
|
MarketStructOutput
|
|
167
167
|
] & {
|
|
@@ -6311,21 +6311,11 @@ export namespace USDCPriceFeed {
|
|
|
6311
6311
|
export namespace MorphoBlueView {
|
|
6312
6312
|
let abi_73: ({
|
|
6313
6313
|
inputs: {
|
|
6314
|
-
components:
|
|
6315
|
-
components: {
|
|
6316
|
-
internalType: string;
|
|
6317
|
-
name: string;
|
|
6318
|
-
type: string;
|
|
6319
|
-
}[];
|
|
6320
|
-
internalType: string;
|
|
6321
|
-
name: string;
|
|
6322
|
-
type: string;
|
|
6323
|
-
} | {
|
|
6314
|
+
components: {
|
|
6324
6315
|
internalType: string;
|
|
6325
6316
|
name: string;
|
|
6326
6317
|
type: string;
|
|
6327
|
-
|
|
6328
|
-
})[];
|
|
6318
|
+
}[];
|
|
6329
6319
|
internalType: string;
|
|
6330
6320
|
name: string;
|
|
6331
6321
|
type: string;
|
|
@@ -6408,6 +6398,102 @@ export namespace MorphoBlueView {
|
|
|
6408
6398
|
address: string;
|
|
6409
6399
|
createdBlock: number;
|
|
6410
6400
|
oldVersions: {
|
|
6401
|
+
"20219255": {
|
|
6402
|
+
abi: ({
|
|
6403
|
+
inputs: {
|
|
6404
|
+
components: ({
|
|
6405
|
+
components: {
|
|
6406
|
+
internalType: string;
|
|
6407
|
+
name: string;
|
|
6408
|
+
type: string;
|
|
6409
|
+
}[];
|
|
6410
|
+
internalType: string;
|
|
6411
|
+
name: string;
|
|
6412
|
+
type: string;
|
|
6413
|
+
} | {
|
|
6414
|
+
internalType: string;
|
|
6415
|
+
name: string;
|
|
6416
|
+
type: string;
|
|
6417
|
+
components?: undefined;
|
|
6418
|
+
})[];
|
|
6419
|
+
internalType: string;
|
|
6420
|
+
name: string;
|
|
6421
|
+
type: string;
|
|
6422
|
+
}[];
|
|
6423
|
+
name: string;
|
|
6424
|
+
outputs: ({
|
|
6425
|
+
internalType: string;
|
|
6426
|
+
name: string;
|
|
6427
|
+
type: string;
|
|
6428
|
+
components?: undefined;
|
|
6429
|
+
} | {
|
|
6430
|
+
components: {
|
|
6431
|
+
internalType: string;
|
|
6432
|
+
name: string;
|
|
6433
|
+
type: string;
|
|
6434
|
+
}[];
|
|
6435
|
+
internalType: string;
|
|
6436
|
+
name: string;
|
|
6437
|
+
type: string;
|
|
6438
|
+
})[];
|
|
6439
|
+
stateMutability: string;
|
|
6440
|
+
type: string;
|
|
6441
|
+
} | {
|
|
6442
|
+
inputs: ({
|
|
6443
|
+
internalType: string;
|
|
6444
|
+
name: string;
|
|
6445
|
+
type: string;
|
|
6446
|
+
components?: undefined;
|
|
6447
|
+
} | {
|
|
6448
|
+
components: {
|
|
6449
|
+
internalType: string;
|
|
6450
|
+
name: string;
|
|
6451
|
+
type: string;
|
|
6452
|
+
}[];
|
|
6453
|
+
internalType: string;
|
|
6454
|
+
name: string;
|
|
6455
|
+
type: string;
|
|
6456
|
+
})[];
|
|
6457
|
+
name: string;
|
|
6458
|
+
outputs: {
|
|
6459
|
+
internalType: string;
|
|
6460
|
+
name: string;
|
|
6461
|
+
type: string;
|
|
6462
|
+
}[];
|
|
6463
|
+
stateMutability: string;
|
|
6464
|
+
type: string;
|
|
6465
|
+
} | {
|
|
6466
|
+
inputs: ({
|
|
6467
|
+
components: {
|
|
6468
|
+
internalType: string;
|
|
6469
|
+
name: string;
|
|
6470
|
+
type: string;
|
|
6471
|
+
}[];
|
|
6472
|
+
internalType: string;
|
|
6473
|
+
name: string;
|
|
6474
|
+
type: string;
|
|
6475
|
+
} | {
|
|
6476
|
+
internalType: string;
|
|
6477
|
+
name: string;
|
|
6478
|
+
type: string;
|
|
6479
|
+
components?: undefined;
|
|
6480
|
+
})[];
|
|
6481
|
+
name: string;
|
|
6482
|
+
outputs: {
|
|
6483
|
+
components: {
|
|
6484
|
+
internalType: string;
|
|
6485
|
+
name: string;
|
|
6486
|
+
type: string;
|
|
6487
|
+
}[];
|
|
6488
|
+
internalType: string;
|
|
6489
|
+
name: string;
|
|
6490
|
+
type: string;
|
|
6491
|
+
}[];
|
|
6492
|
+
stateMutability: string;
|
|
6493
|
+
type: string;
|
|
6494
|
+
})[];
|
|
6495
|
+
address: string;
|
|
6496
|
+
};
|
|
6411
6497
|
"18976639": {
|
|
6412
6498
|
abi: ({
|
|
6413
6499
|
inputs: {
|
package/esm/config/contracts.js
CHANGED
|
@@ -992,12 +992,16 @@ module.exports = {
|
|
|
992
992
|
}
|
|
993
993
|
},
|
|
994
994
|
"MorphoBlueView": {
|
|
995
|
-
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "
|
|
995
|
+
"abi": [{ "inputs": [], "name": "LEGACY_MORPHO_TOKEN", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "MORPHO_TOKEN_WRAPPER", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "PUBLIC_ALLOCATOR", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "_marketParams", "type": "tuple" }, { "components": [{ "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct MorphoBlueView.LiquidityChangeParams[]", "name": "_params", "type": "tuple[]" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "components": [{ "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint128", "name": "lastUpdate", "type": "uint128" }, { "internalType": "uint128", "name": "fee", "type": "uint128" }], "internalType": "struct Market", "name": "market", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingId", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingParams", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
996
996
|
"networks": {
|
|
997
997
|
"1": {
|
|
998
|
-
"address": "
|
|
999
|
-
"createdBlock":
|
|
998
|
+
"address": "0xCbFc68c2e07d4CAb24d80D426A9f85Dbe26bAdA9",
|
|
999
|
+
"createdBlock": 21429349,
|
|
1000
1000
|
"oldVersions": {
|
|
1001
|
+
"20219255": {
|
|
1002
|
+
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct MorphoBlueView.LiquidityChangeParams", "name": "params", "type": "tuple" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "components": [{ "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint128", "name": "lastUpdate", "type": "uint128" }, { "internalType": "uint128", "name": "fee", "type": "uint128" }], "internalType": "struct Market", "name": "market", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingId", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingParams", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
1003
|
+
"address": "0x10B621823D4f3E85fBDF759e252598e4e097C1fd",
|
|
1004
|
+
},
|
|
1001
1005
|
"18976639": {
|
|
1002
1006
|
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
1003
1007
|
"address": "0xE29175a86B60138403a9534A391acaDb19f1E9a6",
|
|
@@ -8,11 +8,19 @@ export declare const getMorphoBlueAggregatedPositionData: ({ usedAssets, assetsD
|
|
|
8
8
|
}) => MorphoBlueAggregatedPositionData;
|
|
9
9
|
export declare const getSupplyRate: (totalSupplyAssets: string, totalBorrowAssets: string, borrowRate: string, fee: string) => string;
|
|
10
10
|
export declare const getBorrowRate: (borrowRate: string, totalBorrowShares: string) => string;
|
|
11
|
-
export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMarketData,
|
|
11
|
+
export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMarketData, actions: {
|
|
12
|
+
action: string;
|
|
13
|
+
amount: string;
|
|
14
|
+
asset: string;
|
|
15
|
+
}[], web3: Web3, network: NetworkNumber) => Promise<{
|
|
12
16
|
borrowRate: string;
|
|
13
17
|
supplyRate: string;
|
|
14
18
|
}>;
|
|
15
|
-
export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<
|
|
19
|
+
export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<{
|
|
20
|
+
reallocatableLiquidity: string;
|
|
21
|
+
targetBorrowUtilization: string;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const getLiquidityToAllocate: (amountToBorrow: string, totalBorrow: string, totalSupply: string, targetBorrowUtilization: string, reallocatableLiquidityAssets: string) => string;
|
|
16
24
|
export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
|
|
17
25
|
vaults: string[];
|
|
18
26
|
withdrawals: (string | string[])[][][];
|
|
@@ -76,28 +76,30 @@ export const getBorrowRate = (borrowRate, totalBorrowShares) => {
|
|
|
76
76
|
}
|
|
77
77
|
return new Dec(compound(borrowRate)).div(1e18).mul(100).toString();
|
|
78
78
|
};
|
|
79
|
-
export const getApyAfterValuesEstimation = (selectedMarket,
|
|
79
|
+
export const getApyAfterValuesEstimation = (selectedMarket, actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
80
|
const morphoBlueViewContract = MorphoBlueViewContract(web3, network);
|
|
81
81
|
const lltvInWei = assetAmountInWei(selectedMarket.lltv, 'ETH');
|
|
82
82
|
const marketData = [selectedMarket.loanToken, selectedMarket.collateralToken, selectedMarket.oracle, selectedMarket.irm, lltvInWei];
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
const params = actions.map(({ action, asset, amount }) => {
|
|
84
|
+
const isBorrowOperation = borrowOperations.includes(action);
|
|
85
|
+
const amountInWei = assetAmountInWei(amount, asset);
|
|
86
|
+
let liquidityAdded;
|
|
87
|
+
let liquidityRemoved;
|
|
88
|
+
if (isBorrowOperation) {
|
|
89
|
+
liquidityAdded = action === 'payback' ? amountInWei : '0';
|
|
90
|
+
liquidityRemoved = action === 'borrow' ? amountInWei : '0';
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
liquidityAdded = action === 'collateral' ? amountInWei : '0';
|
|
94
|
+
liquidityRemoved = action === 'withdraw' ? amountInWei : '0';
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
liquidityAdded,
|
|
98
|
+
liquidityRemoved,
|
|
99
|
+
isBorrowOperation,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const data = yield morphoBlueViewContract.methods.getApyAfterValuesEstimation(marketData, params).call();
|
|
101
103
|
const borrowRate = getBorrowRate(data.borrowRate, data.market.totalBorrowShares);
|
|
102
104
|
const supplyRate = getSupplyRate(data.market.totalSupplyAssets, data.market.totalBorrowAssets, data.borrowRate, data.market.fee);
|
|
103
105
|
return { borrowRate, supplyRate };
|
|
@@ -167,8 +169,21 @@ export const getReallocatableLiquidity = (marketId, network = NetworkNumber.Eth)
|
|
|
167
169
|
const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketByUniqueKey;
|
|
168
170
|
if (!marketData)
|
|
169
171
|
throw new Error('Market data not found');
|
|
170
|
-
return marketData.reallocatableLiquidityAssets;
|
|
172
|
+
return { reallocatableLiquidity: marketData.reallocatableLiquidityAssets, targetBorrowUtilization: marketData.targetBorrowUtilization };
|
|
171
173
|
});
|
|
174
|
+
export const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply, targetBorrowUtilization, reallocatableLiquidityAssets) => {
|
|
175
|
+
const newTotalBorrowAssets = new Dec(totalBorrow).add(amountToBorrow).toString();
|
|
176
|
+
const leftToBorrow = new Dec(totalSupply).sub(totalBorrow).toString();
|
|
177
|
+
let liquidityToAllocate = new Dec(newTotalBorrowAssets).div(targetBorrowUtilization).mul(1e18).sub(totalSupply)
|
|
178
|
+
.toFixed(0)
|
|
179
|
+
.toString();
|
|
180
|
+
if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new Dec(liquidityToAllocate).lt('0')) {
|
|
181
|
+
liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
|
|
182
|
+
if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate))
|
|
183
|
+
throw new Error('Not enough liquidity available to allocate');
|
|
184
|
+
}
|
|
185
|
+
return liquidityToAllocate;
|
|
186
|
+
};
|
|
172
187
|
export const getReallocation = (marketId, amountToBorrow, network = NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
188
|
var _b, _c, _d;
|
|
174
189
|
const response = yield fetch(API_URL, {
|
|
@@ -184,19 +199,11 @@ export const getReallocation = (marketId, amountToBorrow, network = NetworkNumbe
|
|
|
184
199
|
if (!marketData)
|
|
185
200
|
throw new Error('Market data not found');
|
|
186
201
|
const newTotalBorrowAssets = new Dec(marketData.state.borrowAssets).add(amountToBorrow).toString();
|
|
187
|
-
const leftToBorrow = new Dec(marketData.state.supplyAssets).sub(marketData.state.borrowAssets).toString();
|
|
188
202
|
const newUtil = new Dec(newTotalBorrowAssets).div(marketData.state.supplyAssets).toString();
|
|
189
203
|
const newUtilScaled = new Dec(newUtil).mul(1e18).toString();
|
|
190
204
|
if (new Dec(newUtilScaled).lt(marketData.targetBorrowUtilization))
|
|
191
205
|
return { vaults: [], withdrawals: [] };
|
|
192
|
-
|
|
193
|
-
.toFixed(0)
|
|
194
|
-
.toString();
|
|
195
|
-
if (new Dec(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
|
|
196
|
-
liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
|
|
197
|
-
if (new Dec(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate))
|
|
198
|
-
throw new Error('Not enough liquidity available to allocate');
|
|
199
|
-
}
|
|
206
|
+
const liquidityToAllocate = getLiquidityToAllocate(amountToBorrow, marketData.state.borrowAssets, marketData.state.supplyAssets, marketData.targetBorrowUtilization, marketData.reallocatableLiquidityAssets);
|
|
200
207
|
const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce((acc, item) => {
|
|
201
208
|
const vaultAddress = item.vault.address;
|
|
202
209
|
acc[vaultAddress] = new Dec(acc[vaultAddress] || '0').add(item.assets).toString();
|
|
@@ -64,20 +64,17 @@ export type MarketStructOutputStruct = {
|
|
|
64
64
|
};
|
|
65
65
|
export type MarketStructOutput = MarketStructOutputArray & MarketStructOutputStruct;
|
|
66
66
|
export declare namespace MorphoBlueView {
|
|
67
|
-
type LiquidityChangeParamsStruct = [
|
|
68
|
-
marketParams: MarketParamsStruct;
|
|
67
|
+
type LiquidityChangeParamsStruct = [boolean, number | string | BN, number | string | BN] | {
|
|
69
68
|
isBorrowOperation: boolean;
|
|
70
69
|
liquidityAdded: number | string | BN;
|
|
71
70
|
liquidityRemoved: number | string | BN;
|
|
72
71
|
};
|
|
73
72
|
type LiquidityChangeParamsStructOutputArray = [
|
|
74
|
-
MarketParamsStructOutput,
|
|
75
73
|
boolean,
|
|
76
74
|
string,
|
|
77
75
|
string
|
|
78
76
|
];
|
|
79
77
|
type LiquidityChangeParamsStructOutputStruct = {
|
|
80
|
-
marketParams: MarketParamsStructOutput;
|
|
81
78
|
isBorrowOperation: boolean;
|
|
82
79
|
liquidityAdded: string;
|
|
83
80
|
liquidityRemoved: string;
|
|
@@ -160,8 +157,11 @@ export interface MorphoBlueView extends BaseContract {
|
|
|
160
157
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): MorphoBlueView;
|
|
161
158
|
clone(): MorphoBlueView;
|
|
162
159
|
methods: {
|
|
160
|
+
LEGACY_MORPHO_TOKEN(): NonPayableTransactionObject<string>;
|
|
163
161
|
MORPHO_BLUE_ADDRESS(): NonPayableTransactionObject<string>;
|
|
164
|
-
|
|
162
|
+
MORPHO_TOKEN_WRAPPER(): NonPayableTransactionObject<string>;
|
|
163
|
+
PUBLIC_ALLOCATOR(): NonPayableTransactionObject<string>;
|
|
164
|
+
getApyAfterValuesEstimation(_marketParams: MarketParamsStruct, _params: MorphoBlueView.LiquidityChangeParamsStruct[]): NonPayableTransactionObject<[
|
|
165
165
|
string,
|
|
166
166
|
MarketStructOutput
|
|
167
167
|
] & {
|
package/package.json
CHANGED
package/src/config/contracts.js
CHANGED
|
@@ -993,12 +993,16 @@ module.exports = {
|
|
|
993
993
|
}
|
|
994
994
|
},
|
|
995
995
|
"MorphoBlueView": {
|
|
996
|
-
"abi": [{"inputs":[],"name":"MORPHO_BLUE_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"
|
|
996
|
+
"abi": [{"inputs":[],"name":"LEGACY_MORPHO_TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MORPHO_BLUE_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MORPHO_TOKEN_WRAPPER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PUBLIC_ALLOCATOR","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"_marketParams","type":"tuple"},{"components":[{"internalType":"bool","name":"isBorrowOperation","type":"bool"},{"internalType":"uint256","name":"liquidityAdded","type":"uint256"},{"internalType":"uint256","name":"liquidityRemoved","type":"uint256"}],"internalType":"struct MorphoBlueView.LiquidityChangeParams[]","name":"_params","type":"tuple[]"}],"name":"getApyAfterValuesEstimation","outputs":[{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"components":[{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint128","name":"lastUpdate","type":"uint128"},{"internalType":"uint128","name":"fee","type":"uint128"}],"internalType":"struct Market","name":"market","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"getMarketId","outputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"getMarketInfo","outputs":[{"components":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"lastUpdate","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"internalType":"uint256","name":"oracle","type":"uint256"}],"internalType":"struct MorphoBlueView.MarketInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"name":"getMarketInfoNotTuple","outputs":[{"components":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"lastUpdate","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"internalType":"uint256","name":"oracle","type":"uint256"}],"internalType":"struct MorphoBlueView.MarketInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"marketId","type":"bytes32"},{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getRatio","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"marketId","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"getRatioUsingId","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getRatioUsingParams","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getUserInfo","outputs":[{"components":[{"internalType":"uint256","name":"supplyShares","type":"uint256"},{"internalType":"uint256","name":"suppliedInAssets","type":"uint256"},{"internalType":"uint256","name":"borrowShares","type":"uint256"},{"internalType":"uint256","name":"borrowedInAssets","type":"uint256"},{"internalType":"uint256","name":"collateral","type":"uint256"}],"internalType":"struct MorphoBlueView.PositionInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"morphoBlue","outputs":[{"internalType":"contract IMorphoBlue","name":"","type":"address"}],"stateMutability":"view","type":"function"}],
|
|
997
997
|
"networks": {
|
|
998
998
|
"1": {
|
|
999
|
-
"address": "
|
|
1000
|
-
"createdBlock":
|
|
999
|
+
"address": "0xCbFc68c2e07d4CAb24d80D426A9f85Dbe26bAdA9",
|
|
1000
|
+
"createdBlock": 21429349,
|
|
1001
1001
|
"oldVersions": {
|
|
1002
|
+
"20219255": {
|
|
1003
|
+
"abi": [{"inputs":[],"name":"MORPHO_BLUE_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"bool","name":"isBorrowOperation","type":"bool"},{"internalType":"uint256","name":"liquidityAdded","type":"uint256"},{"internalType":"uint256","name":"liquidityRemoved","type":"uint256"}],"internalType":"struct MorphoBlueView.LiquidityChangeParams","name":"params","type":"tuple"}],"name":"getApyAfterValuesEstimation","outputs":[{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"components":[{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint128","name":"lastUpdate","type":"uint128"},{"internalType":"uint128","name":"fee","type":"uint128"}],"internalType":"struct Market","name":"market","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"getMarketId","outputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"getMarketInfo","outputs":[{"components":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"lastUpdate","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"internalType":"uint256","name":"oracle","type":"uint256"}],"internalType":"struct MorphoBlueView.MarketInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"name":"getMarketInfoNotTuple","outputs":[{"components":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"lastUpdate","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"internalType":"uint256","name":"oracle","type":"uint256"}],"internalType":"struct MorphoBlueView.MarketInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"marketId","type":"bytes32"},{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getRatio","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"marketId","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"getRatioUsingId","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getRatioUsingParams","outputs":[{"internalType":"uint256","name":"ratio","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getUserInfo","outputs":[{"components":[{"internalType":"uint256","name":"supplyShares","type":"uint256"},{"internalType":"uint256","name":"suppliedInAssets","type":"uint256"},{"internalType":"uint256","name":"borrowShares","type":"uint256"},{"internalType":"uint256","name":"borrowedInAssets","type":"uint256"},{"internalType":"uint256","name":"collateral","type":"uint256"}],"internalType":"struct MorphoBlueView.PositionInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"morphoBlue","outputs":[{"internalType":"contract IMorphoBlue","name":"","type":"address"}],"stateMutability":"view","type":"function"}],
|
|
1004
|
+
"address": "0x10B621823D4f3E85fBDF759e252598e4e097C1fd",
|
|
1005
|
+
},
|
|
1002
1006
|
"18976639": {
|
|
1003
1007
|
"abi": [{"inputs":[],"name":"MORPHO_BLUE_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"getMarketId","outputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"}],"name":"getMarketInfo","outputs":[{"components":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"lastUpdate","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"internalType":"uint256","name":"oracle","type":"uint256"}],"internalType":"struct MorphoBlueView.MarketInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"name":"getMarketInfoNotTuple","outputs":[{"components":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint128","name":"totalSupplyAssets","type":"uint128"},{"internalType":"uint128","name":"totalSupplyShares","type":"uint128"},{"internalType":"uint128","name":"totalBorrowAssets","type":"uint128"},{"internalType":"uint128","name":"totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"lastUpdate","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"borrowRate","type":"uint256"},{"internalType":"uint256","name":"oracle","type":"uint256"}],"internalType":"struct MorphoBlueView.MarketInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"loanToken","type":"address"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"irm","type":"address"},{"internalType":"uint256","name":"lltv","type":"uint256"}],"internalType":"struct MarketParams","name":"marketParams","type":"tuple"},{"internalType":"address","name":"owner","type":"address"}],"name":"getUserInfo","outputs":[{"components":[{"internalType":"uint256","name":"supplyShares","type":"uint256"},{"internalType":"uint256","name":"suppliedInAssets","type":"uint256"},{"internalType":"uint256","name":"borrowShares","type":"uint256"},{"internalType":"uint256","name":"borrowedInAssets","type":"uint256"},{"internalType":"uint256","name":"collateral","type":"uint256"}],"internalType":"struct MorphoBlueView.PositionInfo","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"morphoBlue","outputs":[{"internalType":"contract IMorphoBlue","name":"","type":"address"}],"stateMutability":"view","type":"function"}],
|
|
1004
1008
|
"address": "0xE29175a86B60138403a9534A391acaDb19f1E9a6",
|
|
@@ -92,27 +92,33 @@ export const getBorrowRate = (borrowRate: string, totalBorrowShares: string) =>
|
|
|
92
92
|
return new Dec(compound(borrowRate)).div(1e18).mul(100).toString();
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
export const getApyAfterValuesEstimation = async (selectedMarket: MorphoBlueMarketData, action: string, amount: string, asset: string, web3: Web3, network: NetworkNumber) => {
|
|
95
|
+
export const getApyAfterValuesEstimation = async (selectedMarket: MorphoBlueMarketData, actions: { action: string, amount: string, asset: string }[], web3: Web3, network: NetworkNumber) => {
|
|
96
96
|
const morphoBlueViewContract = MorphoBlueViewContract(web3, network);
|
|
97
97
|
const lltvInWei = assetAmountInWei(selectedMarket.lltv, 'ETH');
|
|
98
98
|
const marketData: MarketParamsStruct = [selectedMarket.loanToken, selectedMarket.collateralToken, selectedMarket.oracle, selectedMarket.irm, lltvInWei];
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
|
|
100
|
+
const params = actions.map(({ action, asset, amount }) => {
|
|
101
|
+
const isBorrowOperation = borrowOperations.includes(action);
|
|
102
|
+
const amountInWei = assetAmountInWei(amount, asset);
|
|
103
|
+
let liquidityAdded;
|
|
104
|
+
let liquidityRemoved;
|
|
105
|
+
if (isBorrowOperation) {
|
|
106
|
+
liquidityAdded = action === 'payback' ? amountInWei : '0';
|
|
107
|
+
liquidityRemoved = action === 'borrow' ? amountInWei : '0';
|
|
108
|
+
} else {
|
|
109
|
+
liquidityAdded = action === 'collateral' ? amountInWei : '0';
|
|
110
|
+
liquidityRemoved = action === 'withdraw' ? amountInWei : '0';
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
liquidityAdded,
|
|
114
|
+
liquidityRemoved,
|
|
115
|
+
isBorrowOperation,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
const data = await morphoBlueViewContract.methods.getApyAfterValuesEstimation(
|
|
111
119
|
marketData,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
liquidityRemoved,
|
|
115
|
-
]).call();
|
|
120
|
+
params,
|
|
121
|
+
).call();
|
|
116
122
|
const borrowRate = getBorrowRate(data.borrowRate, data.market.totalBorrowShares);
|
|
117
123
|
const supplyRate = getSupplyRate(data.market.totalSupplyAssets, data.market.totalBorrowAssets, data.borrowRate, data.market.fee);
|
|
118
124
|
return { borrowRate, supplyRate };
|
|
@@ -170,7 +176,7 @@ const MARKET_QUERY = `
|
|
|
170
176
|
}
|
|
171
177
|
`;
|
|
172
178
|
|
|
173
|
-
export const getReallocatableLiquidity = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth): Promise<string> => {
|
|
179
|
+
export const getReallocatableLiquidity = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth): Promise<{ reallocatableLiquidity: string, targetBorrowUtilization: string }> => {
|
|
174
180
|
const response = await fetch(API_URL, {
|
|
175
181
|
method: 'POST',
|
|
176
182
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -185,7 +191,22 @@ export const getReallocatableLiquidity = async (marketId: string, network: Netwo
|
|
|
185
191
|
|
|
186
192
|
if (!marketData) throw new Error('Market data not found');
|
|
187
193
|
|
|
188
|
-
return marketData.reallocatableLiquidityAssets;
|
|
194
|
+
return { reallocatableLiquidity: marketData.reallocatableLiquidityAssets, targetBorrowUtilization: marketData.targetBorrowUtilization };
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const getLiquidityToAllocate = (amountToBorrow: string, totalBorrow: string, totalSupply: string, targetBorrowUtilization: string, reallocatableLiquidityAssets: string) => {
|
|
198
|
+
const newTotalBorrowAssets = new Dec(totalBorrow).add(amountToBorrow).toString();
|
|
199
|
+
const leftToBorrow = new Dec(totalSupply).sub(totalBorrow).toString();
|
|
200
|
+
let liquidityToAllocate = new Dec(newTotalBorrowAssets).div(targetBorrowUtilization).mul(1e18).sub(totalSupply)
|
|
201
|
+
.toFixed(0)
|
|
202
|
+
.toString();
|
|
203
|
+
|
|
204
|
+
if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new Dec(liquidityToAllocate).lt('0')) {
|
|
205
|
+
liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
|
|
206
|
+
if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate)) throw new Error('Not enough liquidity available to allocate');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return liquidityToAllocate;
|
|
189
210
|
};
|
|
190
211
|
|
|
191
212
|
export const getReallocation = async (marketId: string, amountToBorrow: string, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
@@ -204,21 +225,13 @@ export const getReallocation = async (marketId: string, amountToBorrow: string,
|
|
|
204
225
|
if (!marketData) throw new Error('Market data not found');
|
|
205
226
|
|
|
206
227
|
const newTotalBorrowAssets = new Dec(marketData.state.borrowAssets).add(amountToBorrow).toString();
|
|
207
|
-
const leftToBorrow = new Dec(marketData.state.supplyAssets).sub(marketData.state.borrowAssets).toString();
|
|
208
228
|
|
|
209
229
|
const newUtil = new Dec(newTotalBorrowAssets).div(marketData.state.supplyAssets).toString();
|
|
210
230
|
const newUtilScaled = new Dec(newUtil).mul(1e18).toString();
|
|
211
231
|
|
|
212
232
|
if (new Dec(newUtilScaled).lt(marketData.targetBorrowUtilization)) return { vaults: [], withdrawals: [] };
|
|
213
233
|
|
|
214
|
-
|
|
215
|
-
.toFixed(0)
|
|
216
|
-
.toString();
|
|
217
|
-
|
|
218
|
-
if (new Dec(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
|
|
219
|
-
liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
|
|
220
|
-
if (new Dec(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate)) throw new Error('Not enough liquidity available to allocate');
|
|
221
|
-
}
|
|
234
|
+
const liquidityToAllocate = getLiquidityToAllocate(amountToBorrow, marketData.state.borrowAssets, marketData.state.supplyAssets, marketData.targetBorrowUtilization, marketData.reallocatableLiquidityAssets);
|
|
222
235
|
|
|
223
236
|
const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce(
|
|
224
237
|
(acc: Record<string, string>, item: MorphoBluePublicAllocatorItem) => {
|
|
@@ -87,22 +87,19 @@ export type MarketStructOutput = MarketStructOutputArray &
|
|
|
87
87
|
|
|
88
88
|
export declare namespace MorphoBlueView {
|
|
89
89
|
export type LiquidityChangeParamsStruct =
|
|
90
|
-
| [
|
|
90
|
+
| [boolean, number | string | BN, number | string | BN]
|
|
91
91
|
| {
|
|
92
|
-
marketParams: MarketParamsStruct;
|
|
93
92
|
isBorrowOperation: boolean;
|
|
94
93
|
liquidityAdded: number | string | BN;
|
|
95
94
|
liquidityRemoved: number | string | BN;
|
|
96
95
|
};
|
|
97
96
|
|
|
98
97
|
export type LiquidityChangeParamsStructOutputArray = [
|
|
99
|
-
MarketParamsStructOutput,
|
|
100
98
|
boolean,
|
|
101
99
|
string,
|
|
102
100
|
string
|
|
103
101
|
];
|
|
104
102
|
export type LiquidityChangeParamsStructOutputStruct = {
|
|
105
|
-
marketParams: MarketParamsStructOutput;
|
|
106
103
|
isBorrowOperation: boolean;
|
|
107
104
|
liquidityAdded: string;
|
|
108
105
|
liquidityRemoved: string;
|
|
@@ -202,10 +199,17 @@ export interface MorphoBlueView extends BaseContract {
|
|
|
202
199
|
): MorphoBlueView;
|
|
203
200
|
clone(): MorphoBlueView;
|
|
204
201
|
methods: {
|
|
202
|
+
LEGACY_MORPHO_TOKEN(): NonPayableTransactionObject<string>;
|
|
203
|
+
|
|
205
204
|
MORPHO_BLUE_ADDRESS(): NonPayableTransactionObject<string>;
|
|
206
205
|
|
|
206
|
+
MORPHO_TOKEN_WRAPPER(): NonPayableTransactionObject<string>;
|
|
207
|
+
|
|
208
|
+
PUBLIC_ALLOCATOR(): NonPayableTransactionObject<string>;
|
|
209
|
+
|
|
207
210
|
getApyAfterValuesEstimation(
|
|
208
|
-
|
|
211
|
+
_marketParams: MarketParamsStruct,
|
|
212
|
+
_params: MorphoBlueView.LiquidityChangeParamsStruct[]
|
|
209
213
|
): NonPayableTransactionObject<
|
|
210
214
|
[string, MarketStructOutput] & {
|
|
211
215
|
borrowRate: string;
|