@augustdigital/sdk 4.24.1 → 4.24.3-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/abis/LendingPoolV2.d.ts +55 -1413
- package/lib/abis/LendingPoolV2.js.map +1 -1
- package/lib/abis/LendingPoolV3.d.ts +35 -1677
- package/lib/abis/LendingPoolV3.js.map +1 -1
- package/lib/abis/RewardDistributor.d.ts +46 -267
- package/lib/abis/RewardDistributor.js.map +1 -1
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +78 -1456
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js.map +1 -1
- package/lib/abis/TokenizedVaultV2WithDepositWithPermit.d.ts +85 -0
- package/lib/abis/TokenizedVaultV2WithDepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2WithDepositWithPermit.js.map +1 -0
- package/lib/abis/index.d.ts +0 -2
- package/lib/abis/index.js +0 -2
- package/lib/abis/index.js.map +1 -1
- package/lib/adapters/evm/index.d.ts +1 -20
- package/lib/adapters/evm/index.js +0 -16
- package/lib/adapters/evm/index.js.map +1 -1
- package/lib/adapters/solana/getters.js +1 -2
- package/lib/adapters/solana/getters.js.map +1 -1
- package/lib/adapters/solana/index.js.map +1 -1
- package/lib/adapters/sui/index.js.map +1 -1
- package/lib/adapters/sui/transformer.js +1 -4
- package/lib/adapters/sui/transformer.js.map +1 -1
- package/lib/core/constants/core.d.ts +1 -1
- package/lib/core/constants/core.js +4 -4
- package/lib/core/constants/core.js.map +1 -1
- package/lib/core/constants/vaults.d.ts +0 -2
- package/lib/core/constants/vaults.js +1 -3
- package/lib/core/constants/vaults.js.map +1 -1
- package/lib/core/constants/web3.js +1 -0
- package/lib/core/constants/web3.js.map +1 -1
- package/lib/core/constants.adapters.d.ts +117 -0
- package/lib/core/constants.adapters.js +160 -0
- package/lib/core/constants.adapters.js.map +1 -0
- package/lib/core/constants.core.d.ts +78 -0
- package/lib/core/constants.core.js +75 -0
- package/lib/core/constants.core.js.map +1 -0
- package/lib/core/constants.vaults.d.ts +64 -0
- package/lib/core/constants.vaults.js +156 -0
- package/lib/core/constants.vaults.js.map +1 -0
- package/lib/core/constants.web3.d.ts +31 -0
- package/lib/core/constants.web3.js +100 -0
- package/lib/core/constants.web3.js.map +1 -0
- package/lib/core/fetcher.d.ts +3 -2
- package/lib/core/fetcher.js +5 -7
- package/lib/core/fetcher.js.map +1 -1
- package/lib/core/helpers/core.d.ts +1 -1
- package/lib/core/helpers/vaults.d.ts +0 -1
- package/lib/core/helpers/vaults.js +1 -19
- package/lib/core/helpers/vaults.js.map +1 -1
- package/lib/core/helpers/web3.d.ts +4 -6
- package/lib/core/helpers/web3.js.map +1 -1
- package/lib/core/helpers.adapters.d.ts +9 -0
- package/lib/core/helpers.adapters.js +28 -0
- package/lib/core/helpers.adapters.js.map +1 -0
- package/lib/core/helpers.core.d.ts +48 -0
- package/lib/core/helpers.core.js +210 -0
- package/lib/core/helpers.core.js.map +1 -0
- package/lib/core/helpers.signer.d.ts +9 -0
- package/lib/core/helpers.signer.js +54 -0
- package/lib/core/helpers.signer.js.map +1 -0
- package/lib/core/helpers.vaults.d.ts +36 -0
- package/lib/core/helpers.vaults.js +145 -0
- package/lib/core/helpers.vaults.js.map +1 -0
- package/lib/core/helpers.web3.d.ts +95 -0
- package/lib/core/helpers.web3.js +376 -0
- package/lib/core/helpers.web3.js.map +1 -0
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/main.d.ts +1 -5
- package/lib/main.js +0 -13
- package/lib/main.js.map +1 -1
- package/lib/modules/vaults/adapter.helpers.js +1 -2
- package/lib/modules/vaults/adapter.helpers.js.map +1 -1
- package/lib/modules/vaults/getters.js +87 -129
- package/lib/modules/vaults/getters.js.map +1 -1
- package/lib/modules/vaults/main.js +6 -9
- package/lib/modules/vaults/main.js.map +1 -1
- package/lib/modules/vaults/read.actions.d.ts +3 -21
- package/lib/modules/vaults/read.actions.js +1 -130
- package/lib/modules/vaults/read.actions.js.map +1 -1
- package/lib/modules/vaults/utils.js +5 -11
- package/lib/modules/vaults/utils.js.map +1 -1
- package/lib/modules/vaults/write.actions.js +7 -8
- package/lib/modules/vaults/write.actions.js.map +1 -1
- package/lib/services/subgraph/vaults.js +6 -6
- package/lib/services/subgraph/vaults.js.map +1 -1
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -2
- package/lib/types/index.js.map +1 -1
- package/lib/types/vaults.d.ts +0 -2
- package/lib/types/vaults.js.map +1 -1
- package/lib/types/webserver.d.ts +0 -2
- package/lib/verify.d.ts +2 -0
- package/lib/verify.js +33 -0
- package/lib/verify.js.map +1 -0
- package/package.json +12 -12
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +0 -454
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +0 -327
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js.map +0 -1
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +0 -1466
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +0 -1092
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js.map +0 -1
- package/lib/modules/sub-accounts/fetcher.d.ts +0 -10
- package/lib/modules/sub-accounts/fetcher.js +0 -33
- package/lib/modules/sub-accounts/fetcher.js.map +0 -1
- package/lib/modules/sub-accounts/index.d.ts +0 -2
- package/lib/modules/sub-accounts/index.js +0 -19
- package/lib/modules/sub-accounts/index.js.map +0 -1
- package/lib/modules/sub-accounts/main.d.ts +0 -16
- package/lib/modules/sub-accounts/main.js +0 -39
- package/lib/modules/sub-accounts/main.js.map +0 -1
- package/lib/types/sub-accounts.d.ts +0 -8
- package/lib/types/sub-accounts.js +0 -3
- package/lib/types/sub-accounts.js.map +0 -1
- package/lib/types/typed-contract.d.ts +0 -38
- package/lib/types/typed-contract.js +0 -3
- package/lib/types/typed-contract.js.map +0 -1
|
@@ -199,13 +199,13 @@ async function getVaultLoans(vault, options) {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
async function getVaultAllocations(vault, options) {
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
let protocolExposure = [];
|
|
203
|
+
let tokenExposure = [];
|
|
204
204
|
let cefiExposure = [];
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
let cefiBorrowerResponses = {};
|
|
206
|
+
let otcPositions = {};
|
|
207
|
+
let defiPerBorrower = {};
|
|
208
|
+
let exposurePerCategory = {
|
|
209
209
|
supplying: [],
|
|
210
210
|
borrowing: [],
|
|
211
211
|
wallet: [],
|
|
@@ -215,7 +215,7 @@ async function getVaultAllocations(vault, options) {
|
|
|
215
215
|
lending: [],
|
|
216
216
|
loanBalance: 0,
|
|
217
217
|
};
|
|
218
|
-
|
|
218
|
+
let netValue = { value: 0 };
|
|
219
219
|
let debankErr = false;
|
|
220
220
|
let unfilteredTokens = [];
|
|
221
221
|
let uniqueBorrowers;
|
|
@@ -237,7 +237,7 @@ async function getVaultAllocations(vault, options) {
|
|
|
237
237
|
catch (e) {
|
|
238
238
|
core_1.Logger.log.error('getVaultAllocations:borrowers', e);
|
|
239
239
|
}
|
|
240
|
-
const hardcodedSubaccount = Object.values(core_1.VAULT_ALLOCATION_SUBACCOUNTS).find((entry) => entry.address.toLowerCase() === vault.toLowerCase()
|
|
240
|
+
const hardcodedSubaccount = Object.values(core_1.VAULT_ALLOCATION_SUBACCOUNTS).find((entry) => entry.address.toLowerCase() === vault.toLowerCase());
|
|
241
241
|
if (hardcodedSubaccount) {
|
|
242
242
|
const debankRes = await (0, debank_1.fetchDebankResponse)(hardcodedSubaccount.subaccount);
|
|
243
243
|
if (debankRes === false) {
|
|
@@ -364,20 +364,27 @@ async function getVaultAvailableRedemptions({ vault, wallet, options, }) {
|
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
const version = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
367
|
+
let abi;
|
|
367
368
|
let decimals;
|
|
369
|
+
switch (version) {
|
|
370
|
+
case 'evm-2': {
|
|
371
|
+
abi = TokenizedVaultV2_1.ABI_TOKENIZED_VAULT_V2;
|
|
372
|
+
decimals = await (0, core_1.getDecimals)(provider, await (0, core_1.getReceiptTokenAddress)(provider, vault), false);
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
default: {
|
|
376
|
+
abi = abis_1.ABI_LENDING_POOL_V2;
|
|
377
|
+
decimals = await (0, core_1.getDecimals)(provider, vault);
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
368
381
|
const vaultContract = (0, core_1.createContract)({
|
|
369
382
|
address: vault,
|
|
370
|
-
abi:
|
|
383
|
+
abi: abi,
|
|
371
384
|
provider,
|
|
372
385
|
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
decimals = await (0, core_1.getDecimals)(provider, vault);
|
|
378
|
-
}
|
|
379
|
-
const ld = await vaultContract.lagDuration();
|
|
380
|
-
const lagDuration = Number(ld);
|
|
386
|
+
const ld = await vaultContract['lagDuration']();
|
|
387
|
+
const lagDuration = parseInt(ld);
|
|
381
388
|
const { withdrawalRequesteds, withdrawalProcesseds } = await (0, subgraph_1.getSubgraphAllWithdrawals)(vault, provider);
|
|
382
389
|
const availableRedemptions = [];
|
|
383
390
|
const pendingRedemptions = [];
|
|
@@ -551,7 +558,7 @@ async function getVaultAvailableRedemptions({ vault, wallet, options, }) {
|
|
|
551
558
|
}
|
|
552
559
|
}
|
|
553
560
|
else {
|
|
554
|
-
if (foundRedemptionAgainstClaim) {
|
|
561
|
+
if (!!foundRedemptionAgainstClaim) {
|
|
555
562
|
availableRedemptions.push({
|
|
556
563
|
id: ev.transactionHash_ || ev.id,
|
|
557
564
|
hash: ev.transactionHash_ || ev.id,
|
|
@@ -606,7 +613,7 @@ async function getVaultRedemptionHistory({ vault, wallet, options, }) {
|
|
|
606
613
|
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
607
614
|
provider,
|
|
608
615
|
});
|
|
609
|
-
|
|
616
|
+
let logPromises = [];
|
|
610
617
|
const currentBlock = await provider.getBlockNumber();
|
|
611
618
|
let startingBlock = currentBlock - (0, core_1.determineBlockSkipInternal)(chainId);
|
|
612
619
|
let endBlock = currentBlock;
|
|
@@ -692,28 +699,41 @@ async function getVaultPositions({ vault, wallet, solanaWallet, options, }) {
|
|
|
692
699
|
}
|
|
693
700
|
const provider = (0, core_1.createProvider)(options.rpcUrl);
|
|
694
701
|
let decimals;
|
|
702
|
+
let abi;
|
|
695
703
|
const version = (0, core_1.getVaultVersionV2)(v);
|
|
704
|
+
switch (version) {
|
|
705
|
+
case 'evm-2': {
|
|
706
|
+
decimals = await (0, core_1.getDecimals)(provider, await (0, core_1.getReceiptTokenAddress)(provider, vault), false);
|
|
707
|
+
abi = TokenizedVaultV2_1.ABI_TOKENIZED_VAULT_V2;
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
default: {
|
|
711
|
+
decimals = await (0, core_1.getDecimals)(provider, vault);
|
|
712
|
+
abi = abis_1.ABI_LENDING_POOL_V2;
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
696
716
|
const vaultContract = (0, core_1.createContract)({
|
|
697
717
|
provider,
|
|
698
|
-
abi:
|
|
718
|
+
abi: abi,
|
|
699
719
|
address: v.address,
|
|
700
720
|
});
|
|
701
721
|
let bal = BigInt(0);
|
|
702
|
-
if (
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
722
|
+
if (wallet && (0, ethers_1.isAddress)(wallet)) {
|
|
723
|
+
switch (version) {
|
|
724
|
+
case 'evm-2': {
|
|
725
|
+
const receiptContract = (0, core_1.createContract)({
|
|
726
|
+
provider,
|
|
727
|
+
abi: TokenizedVaultV2Receipt_1.ABI_TOKENIZED_VAULT_V2_RECEIPT,
|
|
728
|
+
address: await (0, core_1.getReceiptTokenAddress)(provider, vault),
|
|
729
|
+
});
|
|
730
|
+
bal = await receiptContract.balanceOf(wallet);
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
default: {
|
|
734
|
+
bal = await vaultContract.balanceOf(wallet);
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
717
737
|
}
|
|
718
738
|
}
|
|
719
739
|
const balance = (0, core_1.toNormalizedBn)(bal, decimals);
|
|
@@ -782,7 +802,7 @@ async function getVaultApy({ vault, options, historical, }) {
|
|
|
782
802
|
}
|
|
783
803
|
const baseUrl = core_1.WEBSERVER_ENDPOINTS.public.tokenizedVault.historicalApy(vault);
|
|
784
804
|
const historicalApy = await (0, core_1.fetchAugustPublic)(`${baseUrl}${paramBuilder(historical, baseUrl)}`, {
|
|
785
|
-
headers: options?.headers
|
|
805
|
+
headers: !!options?.headers
|
|
786
806
|
? options?.headers
|
|
787
807
|
: undefined,
|
|
788
808
|
});
|
|
@@ -920,7 +940,7 @@ async function getVaultTvl({ vault, options, historical, }) {
|
|
|
920
940
|
abi: TokenizedVaultV2Receipt_1.ABI_TOKENIZED_VAULT_V2_RECEIPT,
|
|
921
941
|
provider,
|
|
922
942
|
});
|
|
923
|
-
const totalSupply = await receiptTokenContract.
|
|
943
|
+
const totalSupply = await receiptTokenContract.getTotalSupply();
|
|
924
944
|
return [
|
|
925
945
|
{
|
|
926
946
|
value: (0, core_1.toNormalizedBn)(totalSupply, receiptTokenDecimals),
|
|
@@ -939,7 +959,7 @@ async function getVaultTvl({ vault, options, historical, }) {
|
|
|
939
959
|
default: {
|
|
940
960
|
const vaultContract = (0, core_1.createContract)({
|
|
941
961
|
address: vault,
|
|
942
|
-
abi:
|
|
962
|
+
abi: TokenizedVaultV2_1.ABI_TOKENIZED_VAULT_V2,
|
|
943
963
|
provider,
|
|
944
964
|
});
|
|
945
965
|
const decimals = await (0, core_1.getDecimals)(provider, vault);
|
|
@@ -1041,14 +1061,14 @@ async function getVaultBorrowerHealthFactor({ vault, options, }) {
|
|
|
1041
1061
|
abi: abis_1.ABI_LOAN,
|
|
1042
1062
|
});
|
|
1043
1063
|
return {
|
|
1044
|
-
borrower:
|
|
1064
|
+
borrower: await loanContract.borrower(),
|
|
1045
1065
|
loan: l,
|
|
1046
1066
|
};
|
|
1047
1067
|
}));
|
|
1048
1068
|
const uniqueBorrowers = [
|
|
1049
1069
|
...new Set(formattedLoansArray.map((l) => l.borrower)),
|
|
1050
1070
|
];
|
|
1051
|
-
|
|
1071
|
+
let borrowerResponses = {};
|
|
1052
1072
|
for (const b of uniqueBorrowers) {
|
|
1053
1073
|
const response = await (0, core_1.fetchAugustWithKey)(options.augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.health_factor(b));
|
|
1054
1074
|
if (response.status === 200) {
|
|
@@ -1208,7 +1228,7 @@ async function getVaultUserLifetimePnl({ vault, wallet, options, }) {
|
|
|
1208
1228
|
wallet,
|
|
1209
1229
|
options,
|
|
1210
1230
|
}),
|
|
1211
|
-
(0, core_1.fetchTokenizedVault)(vault, options?.headers
|
|
1231
|
+
(0, core_1.fetchTokenizedVault)(vault, options?.headers),
|
|
1212
1232
|
]);
|
|
1213
1233
|
const tokenizedVault = tokenizedVaultResult?.[0];
|
|
1214
1234
|
if (!tokenizedVault) {
|
|
@@ -1223,10 +1243,10 @@ async function getVaultUserLifetimePnl({ vault, wallet, options, }) {
|
|
|
1223
1243
|
const vaultContract = (0, core_1.createContract)({
|
|
1224
1244
|
provider,
|
|
1225
1245
|
address: vault,
|
|
1226
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
1246
|
+
abi: version === 'evm-2' ? TokenizedVaultV2_1.ABI_TOKENIZED_VAULT_V2 : abis_1.ABI_LENDING_POOL_V2,
|
|
1227
1247
|
});
|
|
1228
1248
|
try {
|
|
1229
|
-
underlyingAssetAddress =
|
|
1249
|
+
underlyingAssetAddress = await vaultContract.asset();
|
|
1230
1250
|
const underlyingContract = (0, core_1.createContract)({
|
|
1231
1251
|
provider,
|
|
1232
1252
|
address: underlyingAssetAddress,
|
|
@@ -1247,62 +1267,19 @@ async function getVaultUserLifetimePnl({ vault, wallet, options, }) {
|
|
|
1247
1267
|
}
|
|
1248
1268
|
return { underlyingTokenSymbol, underlyingAssetAddress };
|
|
1249
1269
|
})();
|
|
1250
|
-
|
|
1251
|
-
let
|
|
1252
|
-
let totalWithdrawalsInAssets = BigInt(0);
|
|
1270
|
+
let totalDepositedRaw = BigInt(0);
|
|
1271
|
+
let totalWithdrawalsRequestedRaw = BigInt(0);
|
|
1253
1272
|
for (const historyItem of userHistory) {
|
|
1254
1273
|
const amount = BigInt(historyItem.amount);
|
|
1255
|
-
if ((0, core_1.isBadTransaction)(historyItem.transactionHash_, tokenizedVault.chain)) {
|
|
1256
|
-
continue;
|
|
1257
|
-
}
|
|
1258
1274
|
if (historyItem.type === 'deposit') {
|
|
1259
|
-
|
|
1260
|
-
? historyItem.assetIn.toLowerCase()
|
|
1261
|
-
: 'default';
|
|
1262
|
-
const current = depositsByAsset.get(assetKey) ?? BigInt(0);
|
|
1263
|
-
depositsByAsset.set(assetKey, current + amount);
|
|
1264
|
-
}
|
|
1265
|
-
else if (historyItem.type === 'withdraw-request') {
|
|
1266
|
-
totalWithdrawalsInShares += amount;
|
|
1267
|
-
}
|
|
1268
|
-
else if (historyItem.type === 'withdraw-processed' &&
|
|
1269
|
-
historyItem.isInstant) {
|
|
1270
|
-
totalWithdrawalsInAssets += amount;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
const assetDecimals = new Map();
|
|
1274
|
-
await Promise.all(Array.from(depositsByAsset.keys()).map(async (assetAddress) => {
|
|
1275
|
-
if (assetAddress === 'default') {
|
|
1276
|
-
assetDecimals.set(assetAddress, decimals);
|
|
1275
|
+
totalDepositedRaw += amount;
|
|
1277
1276
|
}
|
|
1278
|
-
else
|
|
1279
|
-
|
|
1280
|
-
|
|
1277
|
+
else if (historyItem.type === 'withdraw-request' ||
|
|
1278
|
+
(historyItem.type === 'withdraw-processed' && historyItem.isInstant)) {
|
|
1279
|
+
totalWithdrawalsRequestedRaw += amount;
|
|
1281
1280
|
}
|
|
1282
|
-
}));
|
|
1283
|
-
const totalDepositedRaw = new Map();
|
|
1284
|
-
for (const [assetAddress, rawAmount] of depositsByAsset) {
|
|
1285
|
-
const assetDec = assetDecimals.get(assetAddress) ?? decimals;
|
|
1286
|
-
totalDepositedRaw.set(assetAddress, (0, core_1.toNormalizedBn)(rawAmount, assetDec));
|
|
1287
|
-
}
|
|
1288
|
-
const assetPrices = new Map();
|
|
1289
|
-
if (tokenizedVault.chain) {
|
|
1290
|
-
await Promise.all(Array.from(depositsByAsset.keys()).map(async (assetAddress) => {
|
|
1291
|
-
if (assetAddress === 'default') {
|
|
1292
|
-
assetPrices.set(assetAddress, 0);
|
|
1293
|
-
}
|
|
1294
|
-
else {
|
|
1295
|
-
try {
|
|
1296
|
-
const price = await (0, core_1.fetchTokenPriceByAddress)(assetAddress, tokenizedVault.chain, options?.headers);
|
|
1297
|
-
assetPrices.set(assetAddress, price);
|
|
1298
|
-
}
|
|
1299
|
-
catch (error) {
|
|
1300
|
-
core_1.Logger.log.warn('getVaultUserLifetimePnl:fetchAssetPrice', `Failed to fetch price for ${assetAddress}: ${error}`);
|
|
1301
|
-
assetPrices.set(assetAddress, 0);
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
}));
|
|
1305
1281
|
}
|
|
1282
|
+
const totalDeposited = (0, core_1.toNormalizedBn)(totalDepositedRaw, decimals);
|
|
1306
1283
|
const { underlyingTokenSymbol, underlyingAssetAddress } = await underlyingSymbolPromise;
|
|
1307
1284
|
let currentPositionValue = (0, core_1.toNormalizedBn)(0, decimals);
|
|
1308
1285
|
const pricePromise = underlyingAssetAddress && tokenizedVault.chain
|
|
@@ -1315,9 +1292,7 @@ async function getVaultUserLifetimePnl({ vault, wallet, options, }) {
|
|
|
1315
1292
|
});
|
|
1316
1293
|
let sharePriceRaw = BigInt(0);
|
|
1317
1294
|
try {
|
|
1318
|
-
const lpTokenAddress = version === 'evm-2'
|
|
1319
|
-
? (await vaultContract.lpTokenAddress())
|
|
1320
|
-
: vault;
|
|
1295
|
+
const lpTokenAddress = version === 'evm-2' ? await vaultContract.lpTokenAddress() : vault;
|
|
1321
1296
|
let currentShares = BigInt(0);
|
|
1322
1297
|
if (version === 'evm-2') {
|
|
1323
1298
|
const lpTokenContract = (0, core_1.createContract)({
|
|
@@ -1354,42 +1329,25 @@ async function getVaultUserLifetimePnl({ vault, wallet, options, }) {
|
|
|
1354
1329
|
currentPositionValue = currentPosition.walletBalance;
|
|
1355
1330
|
}
|
|
1356
1331
|
}
|
|
1357
|
-
let
|
|
1332
|
+
let totalWithdrawalsRequestedInAssetsRaw = totalWithdrawalsRequestedRaw;
|
|
1358
1333
|
if (version === 'evm-2' && sharePriceRaw > BigInt(0)) {
|
|
1359
|
-
|
|
1360
|
-
(
|
|
1361
|
-
}
|
|
1362
|
-
else {
|
|
1363
|
-
totalWithdrawnRaw += totalWithdrawalsInShares;
|
|
1334
|
+
totalWithdrawalsRequestedInAssetsRaw =
|
|
1335
|
+
(totalWithdrawalsRequestedRaw * sharePriceRaw) / BigInt(10 ** decimals);
|
|
1364
1336
|
}
|
|
1365
|
-
const totalWithdrawn = (0, core_1.toNormalizedBn)(totalWithdrawnRaw, decimals);
|
|
1366
1337
|
const tokenPriceUsd = await pricePromise;
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
totalDepositedUsd += Number(normalizedAmount.normalized) * assetPrice;
|
|
1377
|
-
}
|
|
1378
|
-
const totalWithdrawnUsd = Number(totalWithdrawn.normalized) * effectiveTokenPrice;
|
|
1379
|
-
const currentPositionValueUsd = Number(currentPositionValue.normalized) * effectiveTokenPrice;
|
|
1380
|
-
const lifetimePnlUsd = currentPositionValueUsd + totalWithdrawnUsd - totalDepositedUsd;
|
|
1381
|
-
const scaleFactor = BigInt(10 ** 18);
|
|
1382
|
-
const tokenPriceScaled = BigInt(Math.round(effectiveTokenPrice * Number(scaleFactor)));
|
|
1383
|
-
const totalDepositedUsdScaled = BigInt(Math.round(totalDepositedUsd * Number(scaleFactor)));
|
|
1384
|
-
const totalDepositedNativeRaw = tokenPriceScaled > BigInt(0)
|
|
1385
|
-
? (totalDepositedUsdScaled * BigInt(10 ** decimals)) / tokenPriceScaled
|
|
1386
|
-
: BigInt(0);
|
|
1387
|
-
const totalDeposited = (0, core_1.toNormalizedBn)(totalDepositedNativeRaw, decimals);
|
|
1388
|
-
const lifetimePnlUsdScaled = BigInt(Math.round(lifetimePnlUsd * Number(scaleFactor)));
|
|
1389
|
-
const lifetimePnlRaw = tokenPriceScaled > BigInt(0)
|
|
1390
|
-
? (lifetimePnlUsdScaled * BigInt(10 ** decimals)) / tokenPriceScaled
|
|
1391
|
-
: BigInt(0);
|
|
1338
|
+
const totalWithdrawnRaw = totalWithdrawalsRequestedInAssetsRaw;
|
|
1339
|
+
const totalWithdrawn = (0, core_1.toNormalizedBn)(totalWithdrawnRaw, decimals);
|
|
1340
|
+
const totalWithdrawalsRequestedInAssets = (0, core_1.toNormalizedBn)(totalWithdrawalsRequestedInAssetsRaw, decimals);
|
|
1341
|
+
const totalDepositedUsd = Number(totalDeposited.normalized) * tokenPriceUsd;
|
|
1342
|
+
const totalWithdrawnUsd = Number(totalWithdrawn.normalized) * tokenPriceUsd;
|
|
1343
|
+
const currentPositionValueUsd = Number(currentPositionValue.normalized) * tokenPriceUsd;
|
|
1344
|
+
const lifetimePnlRaw = BigInt(currentPositionValue.raw) +
|
|
1345
|
+
totalWithdrawalsRequestedInAssetsRaw -
|
|
1346
|
+
totalDepositedRaw;
|
|
1392
1347
|
const lifetimePnl = (0, core_1.toNormalizedBn)(lifetimePnlRaw, decimals);
|
|
1348
|
+
const lifetimePnlUsd = currentPositionValueUsd +
|
|
1349
|
+
Number(totalWithdrawalsRequestedInAssets.normalized) * tokenPriceUsd -
|
|
1350
|
+
totalDepositedUsd;
|
|
1393
1351
|
const pnlPercentage = totalDepositedUsd > 0
|
|
1394
1352
|
? Number.parseFloat(((lifetimePnlUsd / totalDepositedUsd) * 100).toFixed(2))
|
|
1395
1353
|
: 0;
|
|
@@ -1601,7 +1559,7 @@ async function getPreviewRedemption({ vault, sharesAmount, options, }) {
|
|
|
1601
1559
|
abi: TokenizedVaultV2_1.ABI_TOKENIZED_VAULT_V2,
|
|
1602
1560
|
provider,
|
|
1603
1561
|
});
|
|
1604
|
-
const lpTokenAddress =
|
|
1562
|
+
const lpTokenAddress = await contract.lpTokenAddress();
|
|
1605
1563
|
const lpTokenContract = (0, core_1.createContract)({
|
|
1606
1564
|
address: lpTokenAddress,
|
|
1607
1565
|
abi: abis_1.ABI_LENDING_POOL_V2,
|