@1delta/margin-fetcher 0.0.9 → 0.0.10
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 +2 -1
- package/dist/lending/compound-v3/publicCallParse.d.ts.map +1 -1
- package/dist/lending/compound-v3/publicCallParse.js +3 -2
- 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/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-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 +5 -2
- 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-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 @@
|
|
|
1
|
+
{"version":3,"file":"fetchLenderAll.d.ts","sourceRoot":"","sources":["../../src/lending/fetchLenderAll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAM/C,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EACf,SAAS,MAAM,EAAE,EACjB,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,kBAAkB,gBAAgB,EAClC,gBAAgB,sBAAsB,KACrC,OAAO,CAAC;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAcnC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Lender } from '@1delta/asset-registry';
|
|
2
|
+
import { getLenderPublicData } from './fetchLender';
|
|
3
|
+
import { getLenderPublicDataViaApi } from './fetchLenderExt';
|
|
4
|
+
const LENDERS_VIA_API = [Lender.MORPHO_BLUE];
|
|
5
|
+
export const getLenderPublicDataAll = async (chainId, lenders, prices, additionalYields, multicallRetry) => {
|
|
6
|
+
const lendersApi = lenders.filter(l => LENDERS_VIA_API.includes(l));
|
|
7
|
+
const lendersOnChain = lenders.filter(l => !LENDERS_VIA_API.includes(l));
|
|
8
|
+
const onChain = getLenderPublicData(chainId, lendersOnChain, prices, additionalYields, multicallRetry);
|
|
9
|
+
const api = getLenderPublicDataViaApi(chainId, lendersApi, prices, additionalYields);
|
|
10
|
+
const [onChainRes, apiRes] = await Promise.all([onChain, api]);
|
|
11
|
+
return { ...onChainRes, ...apiRes };
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AdditionalYields } from '../types';
|
|
2
|
+
import { Lender } from '@1delta/asset-registry';
|
|
3
|
+
export declare const getLenderPublicDataViaApi: (chainId: string, lenders: Lender[], prices: {
|
|
4
|
+
[asset: string]: number;
|
|
5
|
+
}, additionalYields: AdditionalYields) => Promise<{
|
|
6
|
+
[lender: string]: any;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=fetchLenderExt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchLenderExt.d.ts","sourceRoot":"","sources":["../../src/lending/fetchLenderExt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAc/C,eAAO,MAAM,yBAAyB,GACpC,SAAS,MAAM,EACf,SAAS,MAAM,EAAE,EACjB,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,kBAAkB,gBAAgB,KACjC,OAAO,CAAC;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAuBnC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isMorphoType, isMultiMarket } from '../utils';
|
|
2
|
+
import { fetchMorphoPublicData } from './morpho/publicCallBuild';
|
|
3
|
+
async function getgetLenderDataFromApi(lender, chainId, prices, additionalYields) {
|
|
4
|
+
if (isMorphoType(lender))
|
|
5
|
+
return await fetchMorphoPublicData(chainId, additionalYields);
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
export const getLenderPublicDataViaApi = async (chainId, lenders, prices, additionalYields) => {
|
|
9
|
+
let promises = [];
|
|
10
|
+
for (const lender of lenders) {
|
|
11
|
+
promises.push(getgetLenderDataFromApi(lender, chainId, prices, additionalYields));
|
|
12
|
+
}
|
|
13
|
+
const results = await Promise.all(promises);
|
|
14
|
+
const lenderData = {};
|
|
15
|
+
for (let i = 0; i < lenders.length; i++) {
|
|
16
|
+
const lender = lenders[i];
|
|
17
|
+
if (isMultiMarket(lender)) {
|
|
18
|
+
const dataObtained = results[i];
|
|
19
|
+
Object.keys(dataObtained.data).forEach((marketId) => {
|
|
20
|
+
lenderData[marketId] = dataObtained.data[marketId];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
lenderData[lender] = results[i];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return lenderData;
|
|
28
|
+
};
|
package/dist/lending/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lending/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lending/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
package/dist/lending/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { InitGeneralPublicResponse } from "./types";
|
|
2
2
|
import { AdditionalYields } from "../../types";
|
|
3
3
|
import { Lender } from "@1delta/asset-registry";
|
|
4
|
+
import { GenericTokenList } from "../types";
|
|
4
5
|
export declare const INIT_EMODE_LABELS: {
|
|
5
6
|
[mode: number]: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const getInitReservesDataConverter: (lender: Lender, chainId: string, prices: {
|
|
8
9
|
[asset: string]: number;
|
|
9
|
-
}, additionalYields: AdditionalYields) => [(data: any[]) => InitGeneralPublicResponse | undefined, number];
|
|
10
|
+
}, additionalYields: AdditionalYields, tokenList?: GenericTokenList) => [(data: any[]) => InitGeneralPublicResponse | undefined, number];
|
|
10
11
|
//# sourceMappingURL=publicCallParse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicCallParse.d.ts","sourceRoot":"","sources":["../../../src/lending/init/publicCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"publicCallParse.d.ts","sourceRoot":"","sources":["../../../src/lending/init/publicCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAOvD,CAAA;AAED,eAAO,MAAM,4BAA4B,GACvC,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,kBAAkB,gBAAgB,EAClC,YAAW,gBAAqB,KAC/B,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,yBAAyB,GAAG,SAAS,EAAE,MAAM,CAqEjE,CAAA"}
|
|
@@ -9,7 +9,7 @@ export const INIT_EMODE_LABELS = {
|
|
|
9
9
|
[5]: 'Ethena',
|
|
10
10
|
[6]: 'BTC',
|
|
11
11
|
};
|
|
12
|
-
export const getInitReservesDataConverter = (lender, chainId, prices, additionalYields) => {
|
|
12
|
+
export const getInitReservesDataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
13
13
|
const expectedNumberOfCalls = INIT_MODES.length;
|
|
14
14
|
return [
|
|
15
15
|
(data) => {
|
|
@@ -19,7 +19,7 @@ export const getInitReservesDataConverter = (lender, chainId, prices, additional
|
|
|
19
19
|
const modeOne = 0;
|
|
20
20
|
let result = Object.assign({}, ...data[modeOne]?.map((dat) => {
|
|
21
21
|
const asset = dat?.underlying.toLowerCase();
|
|
22
|
-
const meta = getAssetMeta(chainId, asset);
|
|
22
|
+
const meta = tokenList[asset] ?? { ...getAssetMeta(chainId, asset), address: asset };
|
|
23
23
|
const totalDeposits = parseRawAmount(dat?.totalSupply.toString(), meta?.decimals);
|
|
24
24
|
const totalDebt = parseRawAmount(dat?.totalDebt.toString(), meta.decimals);
|
|
25
25
|
const oracleKey = toOracleKey(meta?.assetGroup) ?? toGenericPriceKey(asset, chainId);
|
|
@@ -29,6 +29,7 @@ export const getInitReservesDataConverter = (lender, chainId, prices, additional
|
|
|
29
29
|
[asset]: {
|
|
30
30
|
poolId: asset,
|
|
31
31
|
underlying: asset,
|
|
32
|
+
asset: meta,
|
|
32
33
|
borrowCap: parseRawAmount(dat?.borrowCap.toString(), meta.decimals),
|
|
33
34
|
canBurn: Boolean(dat?.canBurn),
|
|
34
35
|
canFlash: Boolean(dat?.canFlash),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { RewardsMap } from "../aave-v3-type/types";
|
|
2
|
+
import { GenericCurrency } from "../types";
|
|
2
3
|
export interface InitGeneralPublicResponse {
|
|
3
4
|
data: {
|
|
4
5
|
[tokenSymbol: string]: {
|
|
6
|
+
asset: GenericCurrency;
|
|
5
7
|
unbacked?: number;
|
|
6
8
|
depositRate: number;
|
|
7
9
|
averageStableBorrowRate?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lending/init/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lending/init/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAG1C,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE;QACJ,CAAC,WAAW,EAAE,MAAM,GAAG;YAErB,KAAK,EAAE,eAAe,CAAA;YAEtB,QAAQ,CAAC,EAAE,MAAM,CAAA;YACjB,WAAW,EAAE,MAAM,CAAA;YACnB,uBAAuB,CAAC,EAAE,MAAM,CAAA;YAChC,cAAc,CAAC,EAAE,MAAM,CAAA;YACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;YAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAA;YAE5B,MAAM,EAAE;gBACN,CAAC,MAAM,EAAE,MAAM,GAAG;oBAChB,QAAQ,EAAE,MAAM,CAAA;oBAEhB,sBAAsB,EAAE,MAAM,CAAA;oBAC9B,gBAAgB,EAAE,MAAM,CAAA;oBACxB,YAAY,EAAE,MAAM,CAAA;iBACrB,CAAA;aACF,CAAA;YAGD,OAAO,CAAC,EAAE,UAAU,CAAA;YAGpB,QAAQ,CAAC,EAAE,MAAM,CAAA;YACjB,aAAa,CAAC,EAAE,MAAM,CAAA;YACtB,wBAAwB,CAAC,EAAE,OAAO,CAAA;YAClC,uBAAuB,CAAC,EAAE,OAAO,CAAA;YAGjC,QAAQ,CAAC,EAAE,OAAO,CAAA;YAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;SACnB,CAAA;KACF,CAAA;IACD,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,oBAAY,8BAA8B;IACxC,OAAO,IAAI;IACX,WAAW,IAAA;IACX,KAAK,IAAA;CACN"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MorphoGeneralPublicResponse, GetMarketsResponse } from './types';
|
|
2
|
+
import { AdditionalYields } from '../../types';
|
|
3
|
+
export declare function convertMarketsToMorphoResponse(response: GetMarketsResponse, chainId: string, additionalYields?: AdditionalYields): {
|
|
4
|
+
chainId: string;
|
|
5
|
+
data: {
|
|
6
|
+
[m: string]: MorphoGeneralPublicResponse;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=convertPublic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertPublic.d.ts","sourceRoot":"","sources":["../../../src/lending/morpho/convertPublic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAc,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAkB9C,wBAAgB,8BAA8B,CAC1C,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,MAAM,EACf,gBAAgB,GAAE,gBAA2E,GAC9F;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,2BAA2B,CAAA;KAAE,CAAA;CAAE,CAiHzE"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { formatUnits } from 'viem';
|
|
2
|
+
import { apyToApr } from '../user-data/utils';
|
|
3
|
+
import { getAssetMeta } from '../../assets';
|
|
4
|
+
function parseLtv(ltv) {
|
|
5
|
+
let str = 0;
|
|
6
|
+
try {
|
|
7
|
+
str = Number(formatUnits(BigInt(ltv), 18));
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
}
|
|
11
|
+
return str;
|
|
12
|
+
}
|
|
13
|
+
function formatNr(n, d) {
|
|
14
|
+
return Number(formatUnits(BigInt(n ?? 0), d));
|
|
15
|
+
}
|
|
16
|
+
export function convertMarketsToMorphoResponse(response, chainId, additionalYields = { intrinsicYields: {}, lenderRewards: {}, loaded: true }) {
|
|
17
|
+
const data = {};
|
|
18
|
+
response.markets.items.forEach((market) => {
|
|
19
|
+
const { uniqueKey, lltv, irmAddress, oracleAddress, loanAsset, collateralAsset, state, } = market;
|
|
20
|
+
if (collateralAsset && loanAsset && oracleAddress) {
|
|
21
|
+
const m = "MORPHO_BLUE_" + collateralAsset.symbol?.toUpperCase() + "_" + loanAsset.symbol?.toUpperCase() + "_" + uniqueKey.slice(2).toUpperCase();
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
if (!data[m])
|
|
24
|
+
data[m] = { data: {} };
|
|
25
|
+
// 1. LOAN asset entry
|
|
26
|
+
const loanRewards = {};
|
|
27
|
+
// state.rewards?.forEach((reward) => {
|
|
28
|
+
// loanRewards[reward.asset.address] = {
|
|
29
|
+
// depositRate: formatNr(reward.amountPerSuppliedToken, reward.asset.decimals),
|
|
30
|
+
// variableBorrowRate: formatNr(reward.amountPerBorrowedToken, reward.asset.decimals),
|
|
31
|
+
// stableBorrowRate: 0,
|
|
32
|
+
// }
|
|
33
|
+
// })
|
|
34
|
+
const loanAssetAddress = loanAsset.address.toLowerCase();
|
|
35
|
+
data[m].data[loanAssetAddress] = {
|
|
36
|
+
poolId: loanAssetAddress,
|
|
37
|
+
underlying: loanAssetAddress,
|
|
38
|
+
totalDeposits: formatNr(state.supplyAssets, loanAsset.decimals),
|
|
39
|
+
totalDebtStable: 0,
|
|
40
|
+
totalDebt: formatNr(state.borrowAssets, loanAsset.decimals),
|
|
41
|
+
totalDepositsUSD: Number(state.supplyAssetsUsd),
|
|
42
|
+
totalDebtStableUSD: 0,
|
|
43
|
+
totalDebtUSD: Number(state.borrowAssetsUsd),
|
|
44
|
+
depositRate: apyToApr(Number(state.supplyApy)) * 100,
|
|
45
|
+
variableBorrowRate: apyToApr(Number(state.borrowApy)) * 100,
|
|
46
|
+
stableBorrowRate: 0,
|
|
47
|
+
stakingYield: additionalYields.intrinsicYields[getAssetMeta(chainId, loanAssetAddress)?.assetGroup] ?? 0,
|
|
48
|
+
rewards: Object.keys(loanRewards).length > 0 ? loanRewards : undefined,
|
|
49
|
+
decimals: loanAsset.decimals,
|
|
50
|
+
config: {
|
|
51
|
+
0: {
|
|
52
|
+
category: 0,
|
|
53
|
+
borrowCollateralFactor: 0,
|
|
54
|
+
collateralFactor: 0,
|
|
55
|
+
borrowFactor: 1,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
collateralActive: false,
|
|
59
|
+
borrowingEnabled: true,
|
|
60
|
+
hasStable: false,
|
|
61
|
+
isActive: true,
|
|
62
|
+
isFrozen: false,
|
|
63
|
+
};
|
|
64
|
+
const ltv = parseLtv(lltv);
|
|
65
|
+
const collateralAssetAddress = collateralAsset.address.toLowerCase();
|
|
66
|
+
// 2. COLLATERAL asset entry
|
|
67
|
+
data[m].data[collateralAssetAddress] = {
|
|
68
|
+
poolId: collateralAssetAddress,
|
|
69
|
+
underlying: collateralAssetAddress,
|
|
70
|
+
totalDeposits: formatNr(state.collateralAssets, collateralAsset.decimals),
|
|
71
|
+
totalDebtStable: 0,
|
|
72
|
+
totalDebt: 0,
|
|
73
|
+
totalDepositsUSD: Number(state.collateralAssetsUsd),
|
|
74
|
+
totalDebtStableUSD: 0,
|
|
75
|
+
totalDebtUSD: 0,
|
|
76
|
+
depositRate: 0,
|
|
77
|
+
variableBorrowRate: 0,
|
|
78
|
+
stableBorrowRate: 0,
|
|
79
|
+
stakingYield: additionalYields.intrinsicYields[getAssetMeta(chainId, collateralAssetAddress)?.assetGroup] ?? 0,
|
|
80
|
+
rewards: undefined,
|
|
81
|
+
decimals: collateralAsset.decimals,
|
|
82
|
+
config: {
|
|
83
|
+
0: {
|
|
84
|
+
category: 0,
|
|
85
|
+
borrowCollateralFactor: ltv,
|
|
86
|
+
collateralFactor: ltv,
|
|
87
|
+
borrowFactor: 1,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
collateralActive: true,
|
|
91
|
+
borrowingEnabled: false,
|
|
92
|
+
hasStable: false,
|
|
93
|
+
isActive: true,
|
|
94
|
+
isFrozen: false,
|
|
95
|
+
};
|
|
96
|
+
data[m].params = {
|
|
97
|
+
market: {
|
|
98
|
+
lender: m,
|
|
99
|
+
collateralDecimals: collateralAsset.decimals,
|
|
100
|
+
loanDecimals: loanAsset.decimals,
|
|
101
|
+
id: uniqueKey,
|
|
102
|
+
lltv,
|
|
103
|
+
oracle: oracleAddress,
|
|
104
|
+
irm: irmAddress,
|
|
105
|
+
collateralAddress: collateralAsset.address,
|
|
106
|
+
loanAddress: loanAsset.address,
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
data,
|
|
113
|
+
chainId
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchPublic.d.ts","sourceRoot":"","sources":["../../../src/lending/morpho/fetchPublic.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM,WAoDjE,CAAA;AAKD,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,gBAqBvD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const query = (first, skip, chainId) => `
|
|
2
|
+
query GetMarkets {
|
|
3
|
+
markets(first: ${first}, skip: ${skip}, where: {
|
|
4
|
+
chainId_in: [${chainId}],
|
|
5
|
+
whitelisted: true
|
|
6
|
+
},
|
|
7
|
+
orderBy: SupplyAssetsUsd,
|
|
8
|
+
orderDirection: Desc
|
|
9
|
+
) {
|
|
10
|
+
items {
|
|
11
|
+
uniqueKey
|
|
12
|
+
irmAddress
|
|
13
|
+
oracleAddress
|
|
14
|
+
lltv
|
|
15
|
+
loanAsset {
|
|
16
|
+
address
|
|
17
|
+
name
|
|
18
|
+
symbol
|
|
19
|
+
decimals
|
|
20
|
+
priceUsd
|
|
21
|
+
}
|
|
22
|
+
collateralAsset {
|
|
23
|
+
address
|
|
24
|
+
name
|
|
25
|
+
symbol
|
|
26
|
+
decimals
|
|
27
|
+
priceUsd
|
|
28
|
+
}
|
|
29
|
+
state {
|
|
30
|
+
borrowApy
|
|
31
|
+
supplyApy
|
|
32
|
+
price
|
|
33
|
+
rewards {
|
|
34
|
+
asset {
|
|
35
|
+
address
|
|
36
|
+
name
|
|
37
|
+
symbol
|
|
38
|
+
decimals
|
|
39
|
+
}
|
|
40
|
+
amountPerBorrowedToken
|
|
41
|
+
amountPerSuppliedToken
|
|
42
|
+
}
|
|
43
|
+
borrowAssets
|
|
44
|
+
borrowAssetsUsd
|
|
45
|
+
supplyAssets
|
|
46
|
+
supplyAssetsUsd
|
|
47
|
+
collateralAssets
|
|
48
|
+
collateralAssetsUsd
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
const BASE_URL = "https://blue-api.morpho.org/graphql";
|
|
55
|
+
export async function fetchMorphoMarkets(chainId) {
|
|
56
|
+
const requestBody = {
|
|
57
|
+
query: query(500, 0, chainId),
|
|
58
|
+
variables: {},
|
|
59
|
+
};
|
|
60
|
+
const response = await fetch(BASE_URL, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: {
|
|
63
|
+
'Content-Type': 'application/json',
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify(requestBody),
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
throw new Error(`Network error: ${response.status} - ${response.statusText}`);
|
|
69
|
+
}
|
|
70
|
+
const data = await response.json();
|
|
71
|
+
return data.data;
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AdditionalYields } from "../../types";
|
|
2
|
+
export declare function fetchMorphoPublicData(chainId: string, yields?: AdditionalYields): Promise<{
|
|
3
|
+
chainId: string;
|
|
4
|
+
data: {
|
|
5
|
+
[m: string]: import("./types").MorphoGeneralPublicResponse;
|
|
6
|
+
};
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=publicCallBuild.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicCallBuild.d.ts","sourceRoot":"","sources":["../../../src/lending/morpho/publicCallBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAI9C,wBAAsB,qBAAqB,CACvC,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,gBAA2E;;;;;GAItF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { convertMarketsToMorphoResponse } from "./convertPublic";
|
|
2
|
+
import { fetchMorphoMarkets } from "./fetchPublic";
|
|
3
|
+
export async function fetchMorphoPublicData(chainId, yields = { intrinsicYields: {}, lenderRewards: {}, loaded: true }) {
|
|
4
|
+
const mbData = await fetchMorphoMarkets(chainId);
|
|
5
|
+
return convertMarketsToMorphoResponse(mbData, chainId, yields);
|
|
6
|
+
}
|
|
@@ -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: {
|
|
@@ -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
|
+
}
|