@defisaver/positions-sdk 2.1.168-stable-pair-dev → 2.1.169-portfolio-api-dev
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/aaveV3/index.d.ts +2 -12
- package/cjs/aaveV3/sgho.d.ts +2 -16
- package/cjs/aaveV4/lend.d.ts +2 -43
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/ethena.d.ts +2 -1
- package/cjs/claiming/king.d.ts +2 -1
- package/cjs/claiming/spark.d.ts +2 -2
- package/cjs/fluid/index.d.ts +5 -49
- package/cjs/helpers/aaveV4Helpers/index.js +1 -11
- package/cjs/liquity/index.d.ts +2 -12
- package/cjs/liquityV2/index.d.ts +8 -23
- package/cjs/liquityV2/index.js +37 -19
- package/cjs/moneymarket/moneymarketCommonService.js +2 -12
- package/cjs/portfolio/index.d.ts +16 -8
- package/cjs/portfolio/index.js +458 -520
- package/cjs/portfolio/lendingProtocols.d.ts +184 -0
- package/cjs/portfolio/lendingProtocols.js +196 -0
- package/cjs/savings/index.d.ts +8 -2
- package/cjs/savings/index.js +33 -4
- package/cjs/types/aave.d.ts +98 -2
- package/cjs/types/aaveV4.d.ts +44 -0
- package/cjs/types/common.d.ts +0 -1
- package/cjs/types/common.js +0 -1
- package/cjs/types/compound.d.ts +26 -2
- package/cjs/types/curveUsd.d.ts +9 -1
- package/cjs/types/fluid.d.ts +13 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquity.d.ts +12 -0
- package/cjs/types/liquityV2.d.ts +24 -0
- package/cjs/types/llamaLend.d.ts +12 -1
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/portfolio.d.ts +125 -5
- package/cjs/types/savings/index.d.ts +9 -1
- package/cjs/types/spark.d.ts +21 -1
- package/cjs/umbrella/index.d.ts +2 -3
- package/esm/aaveV3/index.d.ts +2 -12
- package/esm/aaveV3/sgho.d.ts +2 -16
- package/esm/aaveV4/lend.d.ts +2 -43
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +1 -1
- package/esm/claiming/ethena.d.ts +2 -1
- package/esm/claiming/king.d.ts +2 -1
- package/esm/claiming/spark.d.ts +2 -2
- package/esm/claiming/spark.js +1 -1
- package/esm/fluid/index.d.ts +5 -49
- package/esm/helpers/aaveV4Helpers/index.js +1 -11
- package/esm/liquity/index.d.ts +2 -12
- package/esm/liquityV2/index.d.ts +8 -23
- package/esm/liquityV2/index.js +35 -18
- package/esm/moneymarket/moneymarketCommonService.js +2 -12
- package/esm/portfolio/index.d.ts +16 -8
- package/esm/portfolio/index.js +458 -522
- package/esm/portfolio/lendingProtocols.d.ts +184 -0
- package/esm/portfolio/lendingProtocols.js +189 -0
- package/esm/savings/index.d.ts +8 -2
- package/esm/savings/index.js +31 -3
- package/esm/types/aave.d.ts +98 -2
- package/esm/types/aaveV4.d.ts +44 -0
- package/esm/types/common.d.ts +0 -1
- package/esm/types/common.js +0 -1
- package/esm/types/compound.d.ts +26 -2
- package/esm/types/curveUsd.d.ts +9 -1
- package/esm/types/fluid.d.ts +13 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquity.d.ts +12 -0
- package/esm/types/liquityV2.d.ts +24 -0
- package/esm/types/llamaLend.d.ts +12 -1
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/portfolio.d.ts +125 -5
- package/esm/types/savings/index.d.ts +9 -1
- package/esm/types/spark.d.ts +21 -1
- package/esm/umbrella/index.d.ts +2 -3
- package/package.json +1 -1
- package/src/aaveV3/index.ts +2 -1
- package/src/aaveV3/sgho.ts +2 -17
- package/src/aaveV4/lend.ts +2 -48
- package/src/claiming/aaveV3.ts +4 -2
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +3 -3
- package/src/claiming/spark.ts +6 -4
- package/src/fluid/index.ts +4 -3
- package/src/helpers/aaveV4Helpers/index.ts +1 -12
- package/src/liquity/index.ts +2 -2
- package/src/liquityV2/index.ts +48 -22
- package/src/moneymarket/moneymarketCommonService.ts +2 -13
- package/src/portfolio/index.ts +306 -331
- package/src/portfolio/lendingProtocols.ts +281 -0
- package/src/savings/index.ts +41 -4
- package/src/types/aave.ts +104 -1
- package/src/types/aaveV4.ts +49 -0
- package/src/types/common.ts +0 -1
- package/src/types/compound.ts +38 -2
- package/src/types/curveUsd.ts +17 -1
- package/src/types/fluid.ts +14 -0
- package/src/types/index.ts +1 -0
- package/src/types/liquity.ts +13 -1
- package/src/types/liquityV2.ts +26 -1
- package/src/types/llamaLend.ts +19 -1
- package/src/types/morphoBlue.ts +3 -0
- package/src/types/portfolio.ts +151 -5
- package/src/types/savings/index.ts +12 -1
- package/src/types/spark.ts +25 -1
- package/src/umbrella/index.ts +2 -1
package/esm/fluid/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client, PublicClient } from 'viem';
|
|
2
2
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
|
-
import { FluidAssetsData, FluidMarketData, FluidMarketInfo, FluidUsedAssets, FluidVaultData, InnerFluidMarketData } from '../types';
|
|
3
|
+
import { FluidAssetsData, FluidEarnPositionData, FluidMarketData, FluidMarketInfo, FluidUsedAssets, FluidVaultData, InnerFluidMarketData } from '../types';
|
|
4
4
|
export { FluidMerklOpportunityType, buildFluidMerklRewardMap, getFluidMerklCampaigns, attachFluidMerklIncentives, } from './merkl';
|
|
5
5
|
export declare const EMPTY_USED_ASSET: {
|
|
6
6
|
isSupplied: boolean;
|
|
@@ -71,54 +71,10 @@ export declare const getFluidTokenData: (provider: EthereumProvider, network: Ne
|
|
|
71
71
|
depositRate: string;
|
|
72
72
|
withdrawRate: string;
|
|
73
73
|
}>;
|
|
74
|
-
export declare const _getFluidDepositData: (provider: Client, network: NetworkNumber, token: string, address: EthAddress) => Promise<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
totalDeposited: string;
|
|
79
|
-
withdrawable: string;
|
|
80
|
-
apy: string;
|
|
81
|
-
depositRate: string;
|
|
82
|
-
withdrawRate: string;
|
|
83
|
-
deposited: string;
|
|
84
|
-
depositedShares: string;
|
|
85
|
-
}>;
|
|
86
|
-
export declare const getFluidDepositData: (provider: EthereumProvider, network: NetworkNumber, token: string, address: EthAddress) => Promise<{
|
|
87
|
-
fTokenAddress: string | undefined;
|
|
88
|
-
fTokenSymbol: string;
|
|
89
|
-
decimals: string;
|
|
90
|
-
totalDeposited: string;
|
|
91
|
-
withdrawable: string;
|
|
92
|
-
apy: string;
|
|
93
|
-
depositRate: string;
|
|
94
|
-
withdrawRate: string;
|
|
95
|
-
deposited: string;
|
|
96
|
-
depositedShares: string;
|
|
97
|
-
}>;
|
|
98
|
-
export declare const _getAllUserEarnPositionsWithFTokens: (provider: Client, network: NetworkNumber, user: EthAddress) => Promise<{
|
|
99
|
-
fTokenAddress: string | undefined;
|
|
100
|
-
fTokenSymbol: string;
|
|
101
|
-
decimals: string;
|
|
102
|
-
totalDeposited: string;
|
|
103
|
-
withdrawable: string;
|
|
104
|
-
apy: string;
|
|
105
|
-
depositRate: string;
|
|
106
|
-
withdrawRate: string;
|
|
107
|
-
deposited: string;
|
|
108
|
-
depositedShares: string;
|
|
109
|
-
}[]>;
|
|
110
|
-
export declare const getAllUserEarnPositionsWithFTokens: (provider: EthereumProvider, network: NetworkNumber, user: EthAddress) => Promise<{
|
|
111
|
-
fTokenAddress: string | undefined;
|
|
112
|
-
fTokenSymbol: string;
|
|
113
|
-
decimals: string;
|
|
114
|
-
totalDeposited: string;
|
|
115
|
-
withdrawable: string;
|
|
116
|
-
apy: string;
|
|
117
|
-
depositRate: string;
|
|
118
|
-
withdrawRate: string;
|
|
119
|
-
deposited: string;
|
|
120
|
-
depositedShares: string;
|
|
121
|
-
}[]>;
|
|
74
|
+
export declare const _getFluidDepositData: (provider: Client, network: NetworkNumber, token: string, address: EthAddress) => Promise<FluidEarnPositionData>;
|
|
75
|
+
export declare const getFluidDepositData: (provider: EthereumProvider, network: NetworkNumber, token: string, address: EthAddress) => Promise<FluidEarnPositionData>;
|
|
76
|
+
export declare const _getAllUserEarnPositionsWithFTokens: (provider: Client, network: NetworkNumber, user: EthAddress) => Promise<FluidEarnPositionData[]>;
|
|
77
|
+
export declare const getAllUserEarnPositionsWithFTokens: (provider: EthereumProvider, network: NetworkNumber, user: EthAddress) => Promise<FluidEarnPositionData[]>;
|
|
122
78
|
export declare const _getUserPositions: (provider: PublicClient, network: NetworkNumber, user: EthAddress) => Promise<{
|
|
123
79
|
marketData: FluidMarketData | undefined;
|
|
124
80
|
userData: {
|
|
@@ -151,15 +151,12 @@ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
|
151
151
|
let supplyUnstable = 0;
|
|
152
152
|
let longAsset = '';
|
|
153
153
|
let shortAsset = '';
|
|
154
|
-
let stableCollAsset = '';
|
|
155
154
|
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, reserveId, }) => {
|
|
156
155
|
const spokeAsset = `${symbol}-${reserveId}`;
|
|
157
156
|
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
158
157
|
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
159
|
-
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
158
|
+
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
160
159
|
supplyStable += 1;
|
|
161
|
-
stableCollAsset = spokeAsset;
|
|
162
|
-
}
|
|
163
160
|
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
164
161
|
borrowStable += 1;
|
|
165
162
|
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
@@ -174,7 +171,6 @@ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
|
174
171
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
175
172
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
176
173
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
177
|
-
const isStablePair = supplyStable === 1 && borrowStable === 1 && supplyUnstable === 0 && borrowUnstable === 0;
|
|
178
174
|
if (isLong) {
|
|
179
175
|
return {
|
|
180
176
|
leveragedType: LeverageType.Long,
|
|
@@ -193,12 +189,6 @@ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
|
|
|
193
189
|
leveragedAsset: longAsset,
|
|
194
190
|
};
|
|
195
191
|
}
|
|
196
|
-
if (isStablePair) {
|
|
197
|
-
return {
|
|
198
|
-
leveragedType: LeverageType.StablePair,
|
|
199
|
-
leveragedAsset: stableCollAsset,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
192
|
return {
|
|
203
193
|
leveragedType: LeverageType.None,
|
|
204
194
|
leveragedAsset: '',
|
package/esm/liquity/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
|
-
import { LiquityTroveInfo } from '../types';
|
|
3
|
+
import { LiquityStakingData, LiquityTroveInfo } from '../types';
|
|
4
4
|
export declare const LIQUITY_NORMAL_MODE_RATIO = 110;
|
|
5
5
|
export declare const LIQUITY_RECOVERY_MODE_RATIO = 150;
|
|
6
6
|
export declare const _getLiquityAccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
@@ -8,14 +8,4 @@ export declare const getLiquityAccountBalances: (provider: EthereumProvider, net
|
|
|
8
8
|
export declare const getDebtInFront: (provider: EthereumProvider, address: EthAddress) => Promise<string>;
|
|
9
9
|
export declare const _getLiquityTroveInfo: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
|
|
10
10
|
export declare const getLiquityTroveInfo: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress) => Promise<LiquityTroveInfo>;
|
|
11
|
-
export declare const getLiquityStakingData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<
|
|
12
|
-
totalLUSDDeposited: string;
|
|
13
|
-
totalLQTYStaked: string;
|
|
14
|
-
stakedLQTY: string;
|
|
15
|
-
stakedLUSDBalance: string;
|
|
16
|
-
rewardETH: string;
|
|
17
|
-
rewardLUSD: string;
|
|
18
|
-
stabilityRewardETH: string;
|
|
19
|
-
stabilityRewardLQTY: string;
|
|
20
|
-
showStakingBalances: boolean;
|
|
21
|
-
}>;
|
|
11
|
+
export declare const getLiquityStakingData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<LiquityStakingData>;
|
package/esm/liquityV2/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client, PublicClient } from 'viem';
|
|
2
2
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
|
-
import { LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2Versions } from '../types';
|
|
3
|
+
import { LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2Versions } from '../types';
|
|
4
4
|
export type SPYieldGainParameters = {
|
|
5
5
|
P: string;
|
|
6
6
|
aggWeightedDebtSum: string;
|
|
@@ -19,6 +19,11 @@ export declare const nftContractCreationBlockMapping: {
|
|
|
19
19
|
liquityv2wstethlegacy: number;
|
|
20
20
|
liquityv2rethlegacy: number;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* The trove ids of several accounts in one market: the market's NFT transfers are read once for all of them, rather
|
|
24
|
+
* than once per account as _getLiquityV2UserTroveIds does.
|
|
25
|
+
*/
|
|
26
|
+
export declare const _getLiquityV2UsersTroveIds: (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, accounts: EthAddress[]) => Promise<Record<EthAddress, string[]>>;
|
|
22
27
|
export declare const _getLiquityV2UserTroveIds: (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
|
|
23
28
|
troves: {
|
|
24
29
|
troveId: string;
|
|
@@ -52,25 +57,5 @@ export type sBoldYieldParameters = {
|
|
|
52
57
|
wsETH: string;
|
|
53
58
|
rETH: string;
|
|
54
59
|
};
|
|
55
|
-
export declare const getLiquityV2Staking: (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => Promise<
|
|
56
|
-
|
|
57
|
-
stakedBOLDBalance: string;
|
|
58
|
-
stabilityRewardColl: string;
|
|
59
|
-
stabilityRewardYield: string;
|
|
60
|
-
showStakingBalances: boolean;
|
|
61
|
-
debtTokenBalance: string;
|
|
62
|
-
stabilityPoolApy: string;
|
|
63
|
-
}>;
|
|
64
|
-
export declare const getLiquitySAndYBold: (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => Promise<{
|
|
65
|
-
spApy: string;
|
|
66
|
-
yBoldApy: string;
|
|
67
|
-
totalBoldDepositedSBold: string;
|
|
68
|
-
boldRateSBold: string;
|
|
69
|
-
maxWithdrawSBold: string;
|
|
70
|
-
totalBoldDepositedYBold: string;
|
|
71
|
-
boldRateYBold: string;
|
|
72
|
-
maxWithdrawYBold: string;
|
|
73
|
-
sBoldBalance: string;
|
|
74
|
-
yBoldBalance: string;
|
|
75
|
-
stYBoldBalance: string;
|
|
76
|
-
}>;
|
|
60
|
+
export declare const getLiquityV2Staking: (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => Promise<LiquityV2StakingData>;
|
|
61
|
+
export declare const getLiquitySAndYBold: (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => Promise<LiquityV2SBoldYBoldData>;
|
package/esm/liquityV2/index.js
CHANGED
|
@@ -121,36 +121,53 @@ export const nftContractCreationBlockMapping = {
|
|
|
121
121
|
[LiquityV2Versions.LiquityV2WstEthLegacy]: 21686238,
|
|
122
122
|
[LiquityV2Versions.LiquityV2REthLegacy]: 21686257,
|
|
123
123
|
};
|
|
124
|
-
|
|
124
|
+
/** Every Transfer of a market's trove NFT since the contract was created (or, on a fork, in the last 1000 blocks). */
|
|
125
|
+
const getTroveTransfers = (provider, network, troveNFTAddress, limitBlocksForEventFetching, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
126
|
const nftContract = createViemContractFromConfigFunc('LiquityV2TroveNFT', troveNFTAddress)(provider, network);
|
|
126
127
|
const nftContractCreationBlock = nftContractCreationBlockMapping[market];
|
|
127
128
|
const currentBlock = +(yield provider.getBlockNumber()).toString();
|
|
128
129
|
const _events = yield nftContract.getEvents.Transfer({}, { fromBlock: limitBlocksForEventFetching ? BigInt(currentBlock - 1000) : BigInt(nftContractCreationBlock) });
|
|
129
|
-
|
|
130
|
+
return _events.map((event) => ({
|
|
130
131
|
from: event.args.from, to: event.args.to, tokenId: event.args.tokenId.toString(), blockNumber: +(event.blockNumber.toString()),
|
|
131
132
|
}));
|
|
132
|
-
const userTransferredTroves = events.filter((event) => compareAddresses(event.to, account));
|
|
133
|
-
// check if the last know transfer address is the user
|
|
134
|
-
userTransferredTroves.forEach((event, index) => {
|
|
135
|
-
const otherTransfers = events.filter((e) => event.blockNumber < e.blockNumber && e.tokenId === event.tokenId);
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
userTransferredTroves[index].invalid = !!otherTransfers.length;
|
|
138
|
-
});
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
return userTransferredTroves.filter((event) => !event.invalid).map((event) => ({ troveId: event.tokenId }));
|
|
141
133
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
/** The troves transferred to an account that it still holds: no later transfer of the same trove. */
|
|
135
|
+
const getAccountTransferredTroves = (events, account) => events
|
|
136
|
+
.filter((event) => compareAddresses(event.to, account))
|
|
137
|
+
.filter((event) => !events.some((e) => event.blockNumber < e.blockNumber && e.tokenId === event.tokenId))
|
|
138
|
+
.map((event) => ({ troveId: event.tokenId }));
|
|
139
|
+
const getTransferredTroves = (provider, network, troveNFTAddress, limitBlocksForEventFetching, market, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
return (getAccountTransferredTroves(yield getTroveTransfers(provider, network, troveNFTAddress, limitBlocksForEventFetching, market), account));
|
|
141
|
+
});
|
|
142
|
+
/** The troves an account opened and still owns, then the ones transferred to it, each once. */
|
|
143
|
+
const mergeTroveIds = (userTroves, userTransferredTroves) => {
|
|
147
144
|
const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
|
|
148
145
|
const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (t.troveId === value.troveId)));
|
|
149
146
|
const troveIds = filteredTroves.map((trove) => trove.troveId);
|
|
150
147
|
const troveIdsSet = new Set(troveIds);
|
|
151
148
|
const troveIdsArray = Array.from(troveIdsSet);
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
return troveIdsArray.map((troveId) => troves.find((trove) => trove.troveId === troveId));
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* The trove ids of several accounts in one market: the market's NFT transfers are read once for all of them, rather
|
|
153
|
+
* than once per account as _getLiquityV2UserTroveIds does.
|
|
154
|
+
*/
|
|
155
|
+
export const _getLiquityV2UsersTroveIds = (provider, network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
const [userTroves, events] = yield Promise.all([
|
|
157
|
+
Promise.all(accounts.map((account) => getUserTroves(provider, network, selectedMarket.isLegacy, account, selectedMarket.marketAddress))),
|
|
158
|
+
getTroveTransfers(provider, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.value),
|
|
159
|
+
]);
|
|
160
|
+
return Object.fromEntries(accounts.map((account, i) => [
|
|
161
|
+
account,
|
|
162
|
+
mergeTroveIds(userTroves[i].troves, getAccountTransferredTroves(events, account)).map(({ troveId }) => troveId),
|
|
163
|
+
]));
|
|
164
|
+
});
|
|
165
|
+
export const _getLiquityV2UserTroveIds = (provider, network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
+
const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = yield Promise.all([
|
|
167
|
+
getUserTroves(provider, network, selectedMarket.isLegacy, account, selectedMarket.marketAddress),
|
|
168
|
+
getTransferredTroves(provider, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.value, account),
|
|
169
|
+
]);
|
|
170
|
+
return { troves: mergeTroveIds(userTroves, userTransferredTroves), nextFreeTroveIndex };
|
|
154
171
|
});
|
|
155
172
|
export const getLiquityV2UserTroveIds = (provider, network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () { return _getLiquityV2UserTroveIds(getViemProvider(provider, network), network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, account); });
|
|
156
173
|
const getDebtInFrontForSingleMarketLiquityV2 = (provider_1, network_1, isLegacy_1, marketAddress_1, troveId_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, isLegacy_1, marketAddress_1, troveId_1, ...args_1], void 0, function* (provider, network, isLegacy, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) {
|
|
@@ -11,7 +11,7 @@ export const calcShortLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => ne
|
|
|
11
11
|
export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
12
12
|
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse)
|
|
13
13
|
return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
14
|
-
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair
|
|
14
|
+
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair)
|
|
15
15
|
return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
16
16
|
console.error('invalid leverageType', leverageType);
|
|
17
17
|
return '0';
|
|
@@ -33,14 +33,11 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
33
33
|
let supplyUnstable = 0;
|
|
34
34
|
let longAsset = '';
|
|
35
35
|
let shortAsset = '';
|
|
36
|
-
let stableCollAsset = '';
|
|
37
36
|
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, }) => {
|
|
38
37
|
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
39
38
|
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
40
|
-
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
39
|
+
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
41
40
|
supplyStable += 1;
|
|
42
|
-
stableCollAsset = symbol;
|
|
43
|
-
}
|
|
44
41
|
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
45
42
|
borrowStable += 1;
|
|
46
43
|
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
@@ -55,7 +52,6 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
55
52
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
56
53
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
57
54
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
58
|
-
const isStablePair = supplyStable === 1 && borrowStable === 1 && supplyUnstable === 0 && borrowUnstable === 0;
|
|
59
55
|
if (isLong) {
|
|
60
56
|
return {
|
|
61
57
|
leveragedType: LeverageType.Long,
|
|
@@ -74,12 +70,6 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
74
70
|
leveragedAsset: longAsset,
|
|
75
71
|
};
|
|
76
72
|
}
|
|
77
|
-
if (isStablePair) {
|
|
78
|
-
return {
|
|
79
|
-
leveragedType: LeverageType.StablePair,
|
|
80
|
-
leveragedAsset: stableCollAsset,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
73
|
return {
|
|
84
74
|
leveragedType: LeverageType.None,
|
|
85
75
|
leveragedAsset: '',
|
package/esm/portfolio/index.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
-
import { PortfolioMarketsData, PortfolioPositionsData } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { PortfolioData, PortfolioDataOptions, PortfolioMarketsData, PortfolioMarketsResult, PortfolioPositionsData, PortfolioUserData, ShifterPortfolioMarketsData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Every market the portfolio reads on a network — the markets half of getPortfolioData, for a caller that keeps
|
|
5
|
+
* markets apart from what it reads per address (a cache shared by many addresses). A market that fails is left out
|
|
6
|
+
* of `markets` and named in `errors`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPortfolioMarketsData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, isSim?: boolean): Promise<PortfolioMarketsResult>;
|
|
9
|
+
/**
|
|
10
|
+
* What the portfolio reads per address — the other half of getPortfolioData — against `markets` from
|
|
11
|
+
* getPortfolioMarketsData. `markets` can be a promise: reads that do not need a market (Maker, Fluid, Liquity, staking,
|
|
12
|
+
* rewards) start at once, and each read on a market waits for it. A position on a market missing from `markets` is an
|
|
13
|
+
* entry with an error.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPortfolioUserData(provider: EthereumProvider, network: NetworkNumber, addresses: EthAddress[], markets: PortfolioMarketsData | Promise<PortfolioMarketsData>, isSim?: boolean, options?: PortfolioDataOptions): Promise<PortfolioUserData>;
|
|
16
|
+
export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean, options?: PortfolioDataOptions): Promise<PortfolioData>;
|
|
9
17
|
export declare function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
|
|
10
18
|
positions: PortfolioPositionsData;
|
|
11
|
-
markets:
|
|
19
|
+
markets: ShifterPortfolioMarketsData;
|
|
12
20
|
}>;
|
|
13
21
|
export * from './discovery';
|
|
14
22
|
export { getWalletLendingSummaries } from './lendingSummaries';
|