@1delta/margin-fetcher 0.0.9 → 0.0.11
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/dist/abis/morpho/blue.d.ts +76 -0
- package/dist/abis/morpho/blue.d.ts.map +1 -0
- package/dist/abis/morpho/blue.js +99 -0
- package/dist/abis/morpho/lens.d.ts +16 -0
- package/dist/abis/morpho/lens.d.ts.map +1 -0
- package/dist/abis/morpho/lens.js +31 -0
- package/dist/flash-liquidity/index.d.ts +1 -0
- package/dist/flash-liquidity/index.d.ts.map +1 -1
- package/dist/flash-liquidity/index.js +1 -0
- package/dist/flash-liquidity/utils.d.ts +11 -0
- package/dist/flash-liquidity/utils.d.ts.map +1 -0
- package/dist/flash-liquidity/utils.js +17 -0
- package/dist/lending/aave-v2-type/publicCallParse.d.ts +2 -1
- package/dist/lending/aave-v2-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v2-type/publicCallParse.js +7 -4
- package/dist/lending/aave-v3-type/publicCallParse.d.ts +3 -2
- package/dist/lending/aave-v3-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v3-type/publicCallParse.js +11 -8
- package/dist/lending/aave-v3-type/types.d.ts +2 -0
- package/dist/lending/aave-v3-type/types.d.ts.map +1 -1
- package/dist/lending/compound-v3/publicCallParse.d.ts +5 -4
- package/dist/lending/compound-v3/publicCallParse.d.ts.map +1 -1
- package/dist/lending/compound-v3/publicCallParse.js +39 -23
- package/dist/lending/compound-v3/types.d.ts +2 -0
- package/dist/lending/compound-v3/types.d.ts.map +1 -1
- package/dist/lending/fetchLender.d.ts +2 -1
- package/dist/lending/fetchLender.d.ts.map +1 -1
- package/dist/lending/fetchLender.js +12 -8
- package/dist/lending/fetchLenderAll.d.ts +8 -0
- package/dist/lending/fetchLenderAll.d.ts.map +1 -0
- package/dist/lending/fetchLenderAll.js +12 -0
- package/dist/lending/fetchLenderExt.d.ts +8 -0
- package/dist/lending/fetchLenderExt.d.ts.map +1 -0
- package/dist/lending/fetchLenderExt.js +28 -0
- package/dist/lending/index.d.ts +1 -0
- package/dist/lending/index.d.ts.map +1 -1
- package/dist/lending/index.js +1 -0
- package/dist/lending/init/publicCallParse.d.ts +2 -1
- package/dist/lending/init/publicCallParse.d.ts.map +1 -1
- package/dist/lending/init/publicCallParse.js +3 -2
- package/dist/lending/init/types.d.ts +2 -0
- package/dist/lending/init/types.d.ts.map +1 -1
- package/dist/lending/morpho/convertPublic.d.ts +9 -0
- package/dist/lending/morpho/convertPublic.d.ts.map +1 -0
- package/dist/lending/morpho/convertPublic.js +115 -0
- package/dist/lending/morpho/fetchPublic.d.ts +3 -0
- package/dist/lending/morpho/fetchPublic.d.ts.map +1 -0
- package/dist/lending/morpho/fetchPublic.js +72 -0
- package/dist/lending/morpho/publicCallBuild.d.ts +8 -0
- package/dist/lending/morpho/publicCallBuild.d.ts.map +1 -0
- package/dist/lending/morpho/publicCallBuild.js +6 -0
- package/dist/lending/morpho/types.d.ts +106 -0
- package/dist/lending/morpho/types.d.ts.map +1 -0
- package/dist/lending/morpho/types.js +1 -0
- package/dist/lending/types/index.d.ts +18 -0
- package/dist/lending/types/index.d.ts.map +1 -0
- package/dist/lending/types/index.js +1 -0
- package/dist/lending/user-data/aave-v2-type/userCallParse.js +1 -1
- package/dist/lending/user-data/compound-v3/userCallParse.js +2 -2
- package/dist/lending/user-data/init/userCallParse.js +1 -1
- package/dist/lending/user-data/morpho/decoder.d.ts +21 -0
- package/dist/lending/user-data/morpho/decoder.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/decoder.js +52 -0
- package/dist/lending/user-data/morpho/morphoLib.d.ts +5 -0
- package/dist/lending/user-data/morpho/morphoLib.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/morphoLib.js +21 -0
- package/dist/lending/user-data/morpho/types.d.ts +12 -0
- package/dist/lending/user-data/morpho/types.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/types.js +13 -0
- package/dist/lending/user-data/morpho/userCallBuild.d.ts +6 -0
- package/dist/lending/user-data/morpho/userCallBuild.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/userCallBuild.js +36 -0
- package/dist/lending/user-data/morpho/userCallParse.d.ts +11 -0
- package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/userCallParse.js +99 -0
- package/dist/lending/user-data/morpho/userCallParseNoDeploy.d.ts +11 -0
- package/dist/lending/user-data/morpho/userCallParseNoDeploy.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/userCallParseNoDeploy.js +112 -0
- package/dist/lending/user-data/types.d.ts +1 -1
- package/dist/lending/user-data/types.d.ts.map +1 -1
- package/dist/lending-pairs/computeLendingPairs.d.ts +2 -0
- package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
- package/dist/lending-pairs/computeLendingPairs.js +57 -30
- package/dist/prices/main-prices/fetchOracleData.d.ts +0 -1
- package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
- package/dist/prices/main-prices/fetchOracleData.js +86 -55
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +41 -16
- package/package.json +1 -1
- package/src/flash-liquidity/index.ts +2 -1
- package/src/flash-liquidity/utils.ts +22 -0
- package/src/lending/aave-v2-type/publicCallParse.ts +9 -4
- package/src/lending/aave-v3-type/publicCallParse.ts +13 -8
- package/src/lending/aave-v3-type/types.ts +2 -0
- package/src/lending/compound-v3/publicCallParse.ts +95 -36
- package/src/lending/compound-v3/types.ts +2 -0
- package/src/lending/fetchLender.ts +23 -17
- package/src/lending/index.ts +2 -1
- package/src/lending/init/publicCallParse.ts +5 -2
- package/src/lending/init/types.ts +3 -0
- package/src/lending/types/index.ts +16 -0
- package/src/lending/user-data/aave-v2-type/userCallParse.ts +1 -1
- package/src/lending/user-data/compound-v3/userCallParse.ts +2 -2
- package/src/lending/user-data/init/userCallParse.ts +1 -1
- package/src/lending/user-data/types.ts +1 -1
- package/src/lending-pairs/computeLendingPairs.ts +417 -315
- package/src/prices/main-prices/fetchOracleData.ts +187 -109
- package/src/utils/index.ts +90 -58
- package/test/index.test.ts +15 -7
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export type GetMarketsResponse = {
|
|
2
|
+
markets: {
|
|
3
|
+
items: {
|
|
4
|
+
uniqueKey: string;
|
|
5
|
+
irmAddress: string;
|
|
6
|
+
oracleAddress: string;
|
|
7
|
+
lltv: string;
|
|
8
|
+
loanAsset: {
|
|
9
|
+
address: string;
|
|
10
|
+
name: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
decimals: number;
|
|
13
|
+
priceUsd: string;
|
|
14
|
+
};
|
|
15
|
+
collateralAsset: {
|
|
16
|
+
address: string;
|
|
17
|
+
name: string;
|
|
18
|
+
symbol: string;
|
|
19
|
+
decimals: number;
|
|
20
|
+
priceUsd: string;
|
|
21
|
+
};
|
|
22
|
+
state: {
|
|
23
|
+
borrowApy: string;
|
|
24
|
+
supplyApy: string;
|
|
25
|
+
price: string;
|
|
26
|
+
rewards: {
|
|
27
|
+
asset: {
|
|
28
|
+
address: string;
|
|
29
|
+
name: string;
|
|
30
|
+
symbol: string;
|
|
31
|
+
decimals: number;
|
|
32
|
+
};
|
|
33
|
+
amountPerBorrowedToken: string;
|
|
34
|
+
amountPerSuppliedToken: string;
|
|
35
|
+
}[];
|
|
36
|
+
borrowAssets: string;
|
|
37
|
+
borrowAssetsUsd: string;
|
|
38
|
+
supplyAssets: string;
|
|
39
|
+
supplyAssetsUsd: string;
|
|
40
|
+
collateralAssets: string;
|
|
41
|
+
collateralAssetsUsd: string;
|
|
42
|
+
};
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export interface BaseYields {
|
|
47
|
+
variableBorrowRate: number;
|
|
48
|
+
stableBorrowRate: number;
|
|
49
|
+
depositRate: number;
|
|
50
|
+
}
|
|
51
|
+
export type RewardsMap = {
|
|
52
|
+
[rewardId: string]: BaseYields;
|
|
53
|
+
};
|
|
54
|
+
export interface MorphoMarket {
|
|
55
|
+
/** the 1delta lender enum */
|
|
56
|
+
lender: string;
|
|
57
|
+
collateralDecimals?: number;
|
|
58
|
+
loanDecimals?: number;
|
|
59
|
+
/** the market hash */
|
|
60
|
+
id: string;
|
|
61
|
+
/** market params */
|
|
62
|
+
lltv: string;
|
|
63
|
+
oracle: string;
|
|
64
|
+
irm: string;
|
|
65
|
+
collateralAddress: string;
|
|
66
|
+
loanAddress: string;
|
|
67
|
+
}
|
|
68
|
+
export interface MorphoGeneralPublicResponse {
|
|
69
|
+
data: {
|
|
70
|
+
[tokenSymbol: string]: {
|
|
71
|
+
poolId: string;
|
|
72
|
+
underlying: string;
|
|
73
|
+
totalDeposits: number;
|
|
74
|
+
totalDebtStable: 0;
|
|
75
|
+
totalDebt: number;
|
|
76
|
+
totalDepositsUSD: number;
|
|
77
|
+
totalDebtStableUSD: 0;
|
|
78
|
+
totalDebtUSD: number;
|
|
79
|
+
depositRate: number;
|
|
80
|
+
variableBorrowRate: number;
|
|
81
|
+
stakingYield: number;
|
|
82
|
+
stableBorrowRate: 0;
|
|
83
|
+
rewards?: RewardsMap;
|
|
84
|
+
decimals: number;
|
|
85
|
+
config: {
|
|
86
|
+
[0]: {
|
|
87
|
+
category: number;
|
|
88
|
+
borrowCollateralFactor: number;
|
|
89
|
+
collateralFactor: number;
|
|
90
|
+
borrowFactor: 1;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
collateralActive: boolean;
|
|
94
|
+
borrowingEnabled: boolean;
|
|
95
|
+
hasStable: false;
|
|
96
|
+
isActive: true;
|
|
97
|
+
isFrozen: false;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
/** morpho market info */
|
|
101
|
+
params: {
|
|
102
|
+
market: MorphoMarket;
|
|
103
|
+
};
|
|
104
|
+
chainId: string;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lending/morpho/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface GenericCurrency {
|
|
2
|
+
/** chainId as string */
|
|
3
|
+
chainId: string;
|
|
4
|
+
/** lower case address */
|
|
5
|
+
address: string;
|
|
6
|
+
/** name */
|
|
7
|
+
name?: string;
|
|
8
|
+
/** symbol */
|
|
9
|
+
symbol?: string;
|
|
10
|
+
/** decimal number */
|
|
11
|
+
decimals: number;
|
|
12
|
+
/** extensible */
|
|
13
|
+
[k: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export type GenericTokenList = {
|
|
16
|
+
[addressLowerCase: string]: GenericCurrency;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lending/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB;IACjB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Lender } from "@1delta/asset-registry";
|
|
2
2
|
import { getAaveAssets, getAssetMeta, toGenericPriceKey, toOracleKey } from "../../../assets";
|
|
3
3
|
import { AaveV2TypeGetUserReserveData } from "../types";
|
|
4
|
-
import { parseRawAmount } from "../../../prices";
|
|
5
4
|
import { AURELIUS_REWARD_ASSETS } from "../../aave-v2-type/misc";
|
|
6
5
|
import { getLenderAssets } from "../../../utils";
|
|
7
6
|
import { createBaseTypeUserState } from "../utils";
|
|
8
7
|
import { Asset as SupportedAssets } from "@1delta/asset-registry";
|
|
8
|
+
import { parseRawAmount } from "../../../utils/parsing";
|
|
9
9
|
export const getAaveV2UserDataConverter = (lender, chainId, account, prices, pricesHist, lenderData) => {
|
|
10
10
|
switch (lender) {
|
|
11
11
|
case Lender.AURELIUS: {
|
|
@@ -36,7 +36,7 @@ export const getCompoundV3UserDataConverter = (lender, chainId, account, prices,
|
|
|
36
36
|
deposits,
|
|
37
37
|
depositsUSD: Number(deposits) * price,
|
|
38
38
|
debtStableUSD: 0,
|
|
39
|
-
debt: 0,
|
|
39
|
+
debt: "0",
|
|
40
40
|
debtUSD: 0,
|
|
41
41
|
collateralActive: true,
|
|
42
42
|
// user depos raw
|
|
@@ -66,7 +66,7 @@ export const getCompoundV3UserDataConverter = (lender, chainId, account, prices,
|
|
|
66
66
|
depositsUSD: Number(deposits) * priceBase,
|
|
67
67
|
debtUSD: Number(debt) * priceBase,
|
|
68
68
|
// populate values for totals
|
|
69
|
-
debtStable: 0,
|
|
69
|
+
debtStable: "0",
|
|
70
70
|
debtStableUSD: 0,
|
|
71
71
|
collateralActive: true,
|
|
72
72
|
// user depos raw
|
|
@@ -60,7 +60,7 @@ export const getInitUserDataConverter = (lender, chainId, account, prices, price
|
|
|
60
60
|
deposits: deposits,
|
|
61
61
|
depositsRaw,
|
|
62
62
|
debt: debt,
|
|
63
|
-
debtStable: 0,
|
|
63
|
+
debtStable: "0",
|
|
64
64
|
debtStableUSD: 0,
|
|
65
65
|
depositsUSD: price * Number(deposits),
|
|
66
66
|
debtUSD: price * Number(debt),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface BalanceInfo {
|
|
2
|
+
index: number;
|
|
3
|
+
supplyShares: bigint;
|
|
4
|
+
borrowShares: bigint;
|
|
5
|
+
supplyAssets: bigint;
|
|
6
|
+
borrowAssets: bigint;
|
|
7
|
+
collateral: bigint;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Decode:
|
|
11
|
+
* [ uint256 count (32 bytes) ]
|
|
12
|
+
* then for each of `count` records:
|
|
13
|
+
* uint16 index (2 bytes),
|
|
14
|
+
* uint256 supplyShares (32 bytes),
|
|
15
|
+
* uint128 borrowShares (16 bytes),
|
|
16
|
+
* uint256 supplyAssets (32 bytes),
|
|
17
|
+
* uint256 borrowAssets (32 bytes),
|
|
18
|
+
* uint128 collateral (16 bytes)
|
|
19
|
+
*/
|
|
20
|
+
export declare function decodePackedDataset(hex: string): BalanceInfo[];
|
|
21
|
+
//# sourceMappingURL=decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/morpho/decoder.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAcD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,EAAE,CAsC9D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const WORD = 32;
|
|
2
|
+
const HALF = 16;
|
|
3
|
+
/** Read `len` bytes at `off` as a big‐endian BigInt. */
|
|
4
|
+
function readBigIntBE(buf, off, len) {
|
|
5
|
+
let v = 0n;
|
|
6
|
+
for (let i = 0; i < len; i++) {
|
|
7
|
+
v = (v << 8n) | BigInt(buf[off + i]);
|
|
8
|
+
}
|
|
9
|
+
return v;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Decode:
|
|
13
|
+
* [ uint256 count (32 bytes) ]
|
|
14
|
+
* then for each of `count` records:
|
|
15
|
+
* uint16 index (2 bytes),
|
|
16
|
+
* uint256 supplyShares (32 bytes),
|
|
17
|
+
* uint128 borrowShares (16 bytes),
|
|
18
|
+
* uint256 supplyAssets (32 bytes),
|
|
19
|
+
* uint256 borrowAssets (32 bytes),
|
|
20
|
+
* uint128 collateral (16 bytes)
|
|
21
|
+
*/
|
|
22
|
+
export function decodePackedDataset(hex) {
|
|
23
|
+
if (hex.startsWith("0x"))
|
|
24
|
+
hex = hex.slice(2);
|
|
25
|
+
const buf = Uint8Array.from(hex.match(/.{1,2}/g).map((b) => parseInt(b, 16)));
|
|
26
|
+
// 1) count (uint256)
|
|
27
|
+
const count = Number(readBigIntBE(buf, 0, 2));
|
|
28
|
+
const out = [];
|
|
29
|
+
let off = 2;
|
|
30
|
+
for (let i = 0; i < count; i++) {
|
|
31
|
+
// 2) index (uint16)
|
|
32
|
+
const index = Number(readBigIntBE(buf, off, 2));
|
|
33
|
+
off += 2;
|
|
34
|
+
// 3) supplyShares (uint256)
|
|
35
|
+
const supplyShares = readBigIntBE(buf, off, WORD);
|
|
36
|
+
off += WORD;
|
|
37
|
+
// 4) borrowShares (uint128)
|
|
38
|
+
const borrowShares = readBigIntBE(buf, off, HALF);
|
|
39
|
+
off += HALF;
|
|
40
|
+
// 5) supplyAssets (uint256)
|
|
41
|
+
const supplyAssets = readBigIntBE(buf, off, WORD);
|
|
42
|
+
off += WORD;
|
|
43
|
+
// 6) borrowAssets (uint256)
|
|
44
|
+
const borrowAssets = readBigIntBE(buf, off, WORD);
|
|
45
|
+
off += WORD;
|
|
46
|
+
// 7) collateral (uint128)
|
|
47
|
+
const collateral = readBigIntBE(buf, off, HALF);
|
|
48
|
+
off += HALF;
|
|
49
|
+
out.push({ index, supplyShares, borrowShares, supplyAssets, borrowAssets, collateral });
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function toSharesDown(assets: bigint, totalAssets: bigint, totalShares: bigint): bigint;
|
|
2
|
+
export declare function toAssetsDown(shares: bigint, totalAssets: bigint, totalShares: bigint): bigint;
|
|
3
|
+
export declare function toSharesUp(assets: bigint, totalAssets: bigint, totalShares: bigint): bigint;
|
|
4
|
+
export declare function toAssetsUp(shares: bigint, totalAssets: bigint, totalShares: bigint): bigint;
|
|
5
|
+
//# sourceMappingURL=morphoLib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"morphoLib.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/morpho/morphoLib.ts"],"names":[],"mappings":"AAcA,wBAAgB,YAAY,CACxB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,MAAM,CAMR;AAED,wBAAgB,YAAY,CACxB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,MAAM,CAMR;AAED,wBAAgB,UAAU,CACtB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,MAAM,CAMR;AAED,wBAAgB,UAAU,CACtB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,MAAM,CAMR"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Constants
|
|
2
|
+
const VIRTUAL_SHARES = 10n ** 6n;
|
|
3
|
+
const VIRTUAL_ASSETS = 1n;
|
|
4
|
+
function mulDivDown(x, y, d) {
|
|
5
|
+
return (x * y) / d;
|
|
6
|
+
}
|
|
7
|
+
function mulDivUp(x, y, d) {
|
|
8
|
+
return (x * y + (d - 1n)) / d;
|
|
9
|
+
}
|
|
10
|
+
export function toSharesDown(assets, totalAssets, totalShares) {
|
|
11
|
+
return mulDivDown(assets, totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS);
|
|
12
|
+
}
|
|
13
|
+
export function toAssetsDown(shares, totalAssets, totalShares) {
|
|
14
|
+
return mulDivDown(shares, totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES);
|
|
15
|
+
}
|
|
16
|
+
export function toSharesUp(assets, totalAssets, totalShares) {
|
|
17
|
+
return mulDivUp(assets, totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS);
|
|
18
|
+
}
|
|
19
|
+
export function toAssetsUp(shares, totalAssets, totalShares) {
|
|
20
|
+
return mulDivUp(shares, totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES);
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum MorphoPositionParams {
|
|
2
|
+
supplyShares = 0,
|
|
3
|
+
borrowShares = 1,
|
|
4
|
+
collateral = 2
|
|
5
|
+
}
|
|
6
|
+
export declare enum MorphoMarketParams {
|
|
7
|
+
totalSupplyAssets = 0,
|
|
8
|
+
totalSupplyShares = 1,
|
|
9
|
+
totalBorrowAssets = 2,
|
|
10
|
+
totalBorrowShares = 3
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/morpho/types.ts"],"names":[],"mappings":"AAAA,oBAAY,oBAAoB;IAC5B,YAAY,IAAI;IAChB,YAAY,IAAA;IACZ,UAAU,IAAA;CACb;AAED,oBAAY,kBAAkB;IAC1B,iBAAiB,IAAI;IACrB,iBAAiB,IAAA;IACjB,iBAAiB,IAAA;IACjB,iBAAiB,IAAA;CACpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export var MorphoPositionParams;
|
|
2
|
+
(function (MorphoPositionParams) {
|
|
3
|
+
MorphoPositionParams[MorphoPositionParams["supplyShares"] = 0] = "supplyShares";
|
|
4
|
+
MorphoPositionParams[MorphoPositionParams["borrowShares"] = 1] = "borrowShares";
|
|
5
|
+
MorphoPositionParams[MorphoPositionParams["collateral"] = 2] = "collateral";
|
|
6
|
+
})(MorphoPositionParams || (MorphoPositionParams = {}));
|
|
7
|
+
export var MorphoMarketParams;
|
|
8
|
+
(function (MorphoMarketParams) {
|
|
9
|
+
MorphoMarketParams[MorphoMarketParams["totalSupplyAssets"] = 0] = "totalSupplyAssets";
|
|
10
|
+
MorphoMarketParams[MorphoMarketParams["totalSupplyShares"] = 1] = "totalSupplyShares";
|
|
11
|
+
MorphoMarketParams[MorphoMarketParams["totalBorrowAssets"] = 2] = "totalBorrowAssets";
|
|
12
|
+
MorphoMarketParams[MorphoMarketParams["totalBorrowShares"] = 3] = "totalBorrowShares";
|
|
13
|
+
})(MorphoMarketParams || (MorphoMarketParams = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Lender } from "@1delta/asset-registry";
|
|
2
|
+
import { Call } from "../../../utils/multicall";
|
|
3
|
+
import { MorphoMarket } from "../../morpho/types";
|
|
4
|
+
export declare const buildMorphoUserCall: (chainId: string, account: string, lender: Lender, marketsToQuery: MorphoMarket[]) => Call[];
|
|
5
|
+
export declare const buildMorphoUserCallWithLens: (chainId: string, account: string, lender: Lender, marketsToQuery: MorphoMarket[]) => Call[];
|
|
6
|
+
//# sourceMappingURL=userCallBuild.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userCallBuild.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/morpho/userCallBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAyB,MAAM,wBAAwB,CAAA;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AA6BjD,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,EAAE,QAAQ,MAAM,EAAE,gBAAgB,YAAY,EAAE,KAAG,IAAI,EAW1H,CAAA;AAID,eAAO,MAAM,2BAA2B,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,EAAE,QAAQ,MAAM,EAAE,gBAAgB,YAAY,EAAE,KAAG,IAAI,EAWlI,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Chain, MORPHO_BLUE_POOL_DATA } from "@1delta/asset-registry";
|
|
2
|
+
import { chunk } from "lodash";
|
|
3
|
+
const MORPHO_LENS = {
|
|
4
|
+
[Chain.BASE]: "0x98542B95B44a4732EffB1F4F01A696F1546236d3"
|
|
5
|
+
};
|
|
6
|
+
const getBaseMorphoCalls = (lender, chainId, account, marketsToQuery) => {
|
|
7
|
+
return marketsToQuery.flatMap(({ id }) => [
|
|
8
|
+
{
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
address: MORPHO_BLUE_POOL_DATA[lender][chainId],
|
|
11
|
+
name: 'position',
|
|
12
|
+
params: [id, account],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
address: MORPHO_BLUE_POOL_DATA[lender][chainId],
|
|
17
|
+
name: 'market',
|
|
18
|
+
params: [id],
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
};
|
|
22
|
+
export const buildMorphoUserCall = (chainId, account, lender, marketsToQuery) => {
|
|
23
|
+
const calls = getBaseMorphoCalls(lender, chainId, account, marketsToQuery);
|
|
24
|
+
console.log("calls", calls);
|
|
25
|
+
return calls;
|
|
26
|
+
};
|
|
27
|
+
export const buildMorphoUserCallWithLens = (chainId, account, lender, marketsToQuery) => {
|
|
28
|
+
// 100 per call
|
|
29
|
+
const marketSlices = chunk(marketsToQuery, 100);
|
|
30
|
+
return marketSlices.flatMap((marketsInChunk) => ({
|
|
31
|
+
address: MORPHO_LENS[chainId],
|
|
32
|
+
name: 'getUserDataCompact',
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
params: [marketsInChunk.map(a => a.id), account, MORPHO_BLUE_POOL_DATA[lender][chainId]],
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Lender } from "@1delta/asset-registry";
|
|
2
|
+
import { MorphoUserReserveResponse } from "../types";
|
|
3
|
+
import { MorphoMarket } from "../../morpho/types";
|
|
4
|
+
export declare const getMorphoUserDataConverterWithlens: (lender: Lender, chainId: string, account: string, markets: MorphoMarket[], prices: {
|
|
5
|
+
[asset: string]: number;
|
|
6
|
+
}, pricesHist: {
|
|
7
|
+
[asset: string]: number;
|
|
8
|
+
}, lenderData: any) => [(data: any[]) => {
|
|
9
|
+
[market: string]: MorphoUserReserveResponse;
|
|
10
|
+
} | undefined, number];
|
|
11
|
+
//# sourceMappingURL=userCallParse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userCallParse.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/morpho/userCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,eAAO,MAAM,kCAAkC,GAC7C,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,SAAS,MAAM,EACf,SAAS,YAAY,EAAE,EACvB,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,YAAY;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACvC,YAAY,GAAG,KACd,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAAA;CAAE,GAAG,SAAS,EAAE,MAAM,CA0DvF,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getAssetMeta, toGenericPriceKey, toOracleKey } from "../../../assets";
|
|
2
|
+
import { createBaseTypeUserState } from "../utils";
|
|
3
|
+
import { parseRawAmount } from "../../../utils/parsing";
|
|
4
|
+
import { decodePackedDataset } from "./decoder";
|
|
5
|
+
export const getMorphoUserDataConverterWithlens = (lender, chainId, account, markets, prices, pricesHist, lenderData) => {
|
|
6
|
+
const expectedNumberOfCalls = markets.length * 2;
|
|
7
|
+
return [
|
|
8
|
+
(data) => {
|
|
9
|
+
// chunksizes depend on markets
|
|
10
|
+
const slices = Math.ceil(markets.length / 100);
|
|
11
|
+
if (data.length !== slices) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
// de-chunk the calldata
|
|
15
|
+
const returnDatas = data.flatMap(d => decodePackedDataset(d));
|
|
16
|
+
let datas = {};
|
|
17
|
+
for (let i = 0; i < returnDatas.length; i++) {
|
|
18
|
+
let totalDebt24h = 0;
|
|
19
|
+
let totalDeposits24h = 0;
|
|
20
|
+
const balanceData = returnDatas[i];
|
|
21
|
+
const market = markets[balanceData.index];
|
|
22
|
+
const { dataForMarket, addedDebt, addedDeposits } = createMorphoEntryFromMarketWithLens(i, balanceData, chainId, market, prices, pricesHist);
|
|
23
|
+
if (!dataForMarket)
|
|
24
|
+
continue;
|
|
25
|
+
totalDebt24h += addedDebt;
|
|
26
|
+
totalDeposits24h += addedDeposits;
|
|
27
|
+
const payload = {
|
|
28
|
+
chainId,
|
|
29
|
+
account,
|
|
30
|
+
lendingPositions: { "0": dataForMarket },
|
|
31
|
+
rewards: {},
|
|
32
|
+
userEMode: 0,
|
|
33
|
+
};
|
|
34
|
+
const userData = createBaseTypeUserState(payload, lenderData, totalDeposits24h, totalDebt24h);
|
|
35
|
+
datas[market.lender] = {
|
|
36
|
+
...payload,
|
|
37
|
+
...userData,
|
|
38
|
+
id: market.id
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return datas;
|
|
42
|
+
},
|
|
43
|
+
expectedNumberOfCalls,
|
|
44
|
+
];
|
|
45
|
+
};
|
|
46
|
+
function createMorphoEntryFromMarketWithLens(i, balanceInfo, chainId, market, prices, pricesHist) {
|
|
47
|
+
const loanMeta = getAssetMeta(chainId, market.loanAddress);
|
|
48
|
+
const loanKey = toOracleKey(loanMeta?.assetGroup) ?? toGenericPriceKey(market.loanAddress, chainId);
|
|
49
|
+
// prices
|
|
50
|
+
const priceLoan = prices[loanKey] ?? 1;
|
|
51
|
+
const priceHistLoan = pricesHist?.[loanKey] ?? priceLoan;
|
|
52
|
+
const deposits = balanceInfo.supplyAssets;
|
|
53
|
+
const borrow = balanceInfo.borrowAssets;
|
|
54
|
+
const depositDec = parseRawAmount(deposits.toString(), market.loanDecimals ?? loanMeta?.decimals ?? 18);
|
|
55
|
+
const borrowDec = parseRawAmount(borrow.toString(), market.loanDecimals ?? loanMeta?.decimals ?? 18);
|
|
56
|
+
const dataForLoanAsset = {
|
|
57
|
+
poolId: market.loanAddress,
|
|
58
|
+
underlying: market.loanAddress,
|
|
59
|
+
deposits: parseRawAmount(deposits.toString(), market.loanDecimals ?? loanMeta?.decimals ?? 18),
|
|
60
|
+
depositsRaw: deposits.toString(),
|
|
61
|
+
debtStable: "0",
|
|
62
|
+
debt: borrowDec,
|
|
63
|
+
depositsUSD: Number(depositDec) * priceLoan,
|
|
64
|
+
debtStableUSD: 0,
|
|
65
|
+
debtUSD: Number(borrowDec) * priceLoan,
|
|
66
|
+
stableBorrowRate: "0",
|
|
67
|
+
collateralActive: true,
|
|
68
|
+
claimableRewards: 0,
|
|
69
|
+
};
|
|
70
|
+
const assetMeta = getAssetMeta(chainId, market.collateralAddress);
|
|
71
|
+
const decimals = market.collateralDecimals ?? assetMeta?.decimals ?? 18;
|
|
72
|
+
const collateralDec = parseRawAmount(balanceInfo.collateral.toString(), decimals);
|
|
73
|
+
const key = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(market.collateralAddress, chainId);
|
|
74
|
+
// prices
|
|
75
|
+
const price = prices[key] ?? 1;
|
|
76
|
+
const priceHist = pricesHist?.[key] ?? price;
|
|
77
|
+
const dataForCollateralAsset = {
|
|
78
|
+
poolId: market.collateralAddress,
|
|
79
|
+
underlying: market.collateralAddress,
|
|
80
|
+
deposits: collateralDec,
|
|
81
|
+
depositsRaw: balanceInfo.collateral.toString(),
|
|
82
|
+
debtStable: "0",
|
|
83
|
+
debt: "0",
|
|
84
|
+
depositsUSD: Number(collateralDec) * price,
|
|
85
|
+
debtStableUSD: 0,
|
|
86
|
+
debtUSD: 0,
|
|
87
|
+
stableBorrowRate: "0",
|
|
88
|
+
collateralActive: true,
|
|
89
|
+
claimableRewards: 0,
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
dataForMarket: {
|
|
93
|
+
[market.loanAddress]: dataForLoanAsset,
|
|
94
|
+
[market.collateralAddress]: dataForCollateralAsset
|
|
95
|
+
},
|
|
96
|
+
addedDeposits: Number(depositDec) * priceHistLoan + Number(collateralDec) * priceHist,
|
|
97
|
+
addedDebt: Number(borrowDec) * priceHistLoan
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Lender } from "@1delta/asset-registry";
|
|
2
|
+
import { MorphoUserReserveResponse } from "../types";
|
|
3
|
+
import { MorphoMarket } from "../../morpho/types";
|
|
4
|
+
export declare const getMorphoUserDataConverter: (lender: Lender, chainId: string, account: string, markets: MorphoMarket[], prices: {
|
|
5
|
+
[asset: string]: number;
|
|
6
|
+
}, pricesHist: {
|
|
7
|
+
[asset: string]: number;
|
|
8
|
+
}, lenderData: any) => [(data: any[]) => {
|
|
9
|
+
[market: string]: MorphoUserReserveResponse;
|
|
10
|
+
} | undefined, number];
|
|
11
|
+
//# sourceMappingURL=userCallParseNoDeploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userCallParseNoDeploy.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/morpho/userCallParseNoDeploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,eAAO,MAAM,0BAA0B,GACrC,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,SAAS,MAAM,EACf,SAAS,YAAY,EAAE,EACvB,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,YAAY;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACvC,YAAY,GAAG,KACd,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAAA;CAAE,GAAG,SAAS,EAAE,MAAM,CAoDvF,CAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getAssetMeta, toGenericPriceKey, toOracleKey } from "../../../assets";
|
|
2
|
+
import { createBaseTypeUserState } from "../utils";
|
|
3
|
+
import { MorphoPositionParams } from "./types";
|
|
4
|
+
import { parseRawAmount } from "../../../utils/parsing";
|
|
5
|
+
import { toAssetsDown } from "./morphoLib";
|
|
6
|
+
export const getMorphoUserDataConverter = (lender, chainId, account, markets, prices, pricesHist, lenderData) => {
|
|
7
|
+
const expectedNumberOfCalls = markets.length * 2;
|
|
8
|
+
return [
|
|
9
|
+
(data) => {
|
|
10
|
+
if (data.length !== expectedNumberOfCalls) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
let datas = {};
|
|
14
|
+
for (let i = 0; i < markets.length; i++) {
|
|
15
|
+
let totalDebt24h = 0;
|
|
16
|
+
let totalDeposits24h = 0;
|
|
17
|
+
const market = markets[i];
|
|
18
|
+
const { dataForMarket, addedDebt, addedDeposits } = createMorphoEntryFromMarket(i, data, chainId, market, prices, pricesHist);
|
|
19
|
+
if (!dataForMarket)
|
|
20
|
+
continue;
|
|
21
|
+
totalDebt24h += addedDebt;
|
|
22
|
+
totalDeposits24h += addedDeposits;
|
|
23
|
+
const payload = {
|
|
24
|
+
chainId,
|
|
25
|
+
account,
|
|
26
|
+
lendingPositions: { "0": dataForMarket },
|
|
27
|
+
rewards: {},
|
|
28
|
+
};
|
|
29
|
+
const userData = createBaseTypeUserState(payload, lenderData, totalDeposits24h, totalDebt24h);
|
|
30
|
+
datas[market.lender] = {
|
|
31
|
+
...payload,
|
|
32
|
+
...userData,
|
|
33
|
+
id: market.id
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return datas;
|
|
37
|
+
},
|
|
38
|
+
expectedNumberOfCalls,
|
|
39
|
+
];
|
|
40
|
+
};
|
|
41
|
+
function createMorphoEntryFromMarket(i, data, chainId, market, prices, pricesHist) {
|
|
42
|
+
const userPosition = data[2 * i];
|
|
43
|
+
const marketData = data[2 * i + 1];
|
|
44
|
+
const collateralBalance = userPosition[MorphoPositionParams.collateral]?.toString();
|
|
45
|
+
const currentLendShares = userPosition[MorphoPositionParams.supplyShares]?.toString();
|
|
46
|
+
const currentBorrowShares = userPosition[MorphoPositionParams.borrowShares]?.toString();
|
|
47
|
+
const totalSupplyShares = BigInt(marketData[MorphoPositionParams.collateral]?.toString() ?? 0n);
|
|
48
|
+
const totalSupplyAssets = BigInt(marketData[MorphoPositionParams.supplyShares]?.toString() ?? 0n);
|
|
49
|
+
const totalBorrowShares = BigInt(marketData[MorphoPositionParams.borrowShares]?.toString() ?? 0n);
|
|
50
|
+
const totalBorrowAssets = BigInt(marketData[MorphoPositionParams.borrowShares]?.toString() ?? 0n);
|
|
51
|
+
if (currentLendShares === "0" &&
|
|
52
|
+
currentBorrowShares === "0" &&
|
|
53
|
+
collateralBalance === "0") {
|
|
54
|
+
return {
|
|
55
|
+
dataForMarket: undefined,
|
|
56
|
+
addedDeposits: 0,
|
|
57
|
+
addedDebt: 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const loanMeta = getAssetMeta(chainId, market.loanAddress);
|
|
61
|
+
const loanKey = toOracleKey(loanMeta?.assetGroup) ?? toGenericPriceKey(market.loanAddress, chainId);
|
|
62
|
+
// prices
|
|
63
|
+
const priceLoan = prices[loanKey] ?? 1;
|
|
64
|
+
const priceHistLoan = pricesHist?.[loanKey] ?? priceLoan;
|
|
65
|
+
const deposits = toAssetsDown(currentLendShares, totalSupplyAssets, totalSupplyShares);
|
|
66
|
+
const borrow = toAssetsDown(currentBorrowShares, totalBorrowAssets, totalBorrowShares);
|
|
67
|
+
const depositDec = parseRawAmount(deposits.toString(), market.loanDecimals ?? loanMeta?.decimals ?? 18);
|
|
68
|
+
const borrowDec = parseRawAmount(borrow.toString(), market.loanDecimals ?? loanMeta?.decimals ?? 18);
|
|
69
|
+
const dataForLoanAsset = {
|
|
70
|
+
poolId: market.loanAddress,
|
|
71
|
+
underlying: market.loanAddress,
|
|
72
|
+
deposits: parseRawAmount(deposits.toString(), market.loanDecimals ?? loanMeta?.decimals ?? 18),
|
|
73
|
+
depositsRaw: deposits.toString(),
|
|
74
|
+
debtStable: "0",
|
|
75
|
+
debt: borrowDec,
|
|
76
|
+
depositsUSD: Number(depositDec) * priceLoan,
|
|
77
|
+
debtStableUSD: 0,
|
|
78
|
+
debtUSD: Number(borrowDec) * priceLoan,
|
|
79
|
+
stableBorrowRate: "0",
|
|
80
|
+
collateralActive: true,
|
|
81
|
+
claimableRewards: 0,
|
|
82
|
+
};
|
|
83
|
+
const assetMeta = getAssetMeta(chainId, market.collateralAddress);
|
|
84
|
+
const decimals = market.collateralDecimals ?? assetMeta?.decimals ?? 18;
|
|
85
|
+
const collateralDec = parseRawAmount(collateralBalance, decimals);
|
|
86
|
+
const key = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(market.collateralAddress, chainId);
|
|
87
|
+
// prices
|
|
88
|
+
const price = prices[key] ?? 1;
|
|
89
|
+
const priceHist = pricesHist?.[key] ?? price;
|
|
90
|
+
const dataForCollateralAsset = {
|
|
91
|
+
poolId: market.collateralAddress,
|
|
92
|
+
underlying: market.collateralAddress,
|
|
93
|
+
deposits: collateralDec,
|
|
94
|
+
depositsRaw: collateralBalance,
|
|
95
|
+
debtStable: "0",
|
|
96
|
+
debt: "0",
|
|
97
|
+
depositsUSD: Number(collateralDec) * price,
|
|
98
|
+
debtStableUSD: 0,
|
|
99
|
+
debtUSD: 0,
|
|
100
|
+
stableBorrowRate: "0",
|
|
101
|
+
collateralActive: true,
|
|
102
|
+
claimableRewards: 0,
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
dataForMarket: {
|
|
106
|
+
[market.loanAddress]: dataForLoanAsset,
|
|
107
|
+
[market.collateralAddress]: dataForCollateralAsset
|
|
108
|
+
},
|
|
109
|
+
addedDeposits: Number(depositDec) * priceHistLoan + Number(collateralDec) * priceHist,
|
|
110
|
+
addedDebt: Number(borrowDec) * priceHistLoan
|
|
111
|
+
};
|
|
112
|
+
}
|