@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.
Files changed (119) hide show
  1. package/lib/abis/LendingPoolV2.d.ts +55 -1413
  2. package/lib/abis/LendingPoolV2.js.map +1 -1
  3. package/lib/abis/LendingPoolV3.d.ts +35 -1677
  4. package/lib/abis/LendingPoolV3.js.map +1 -1
  5. package/lib/abis/RewardDistributor.d.ts +46 -267
  6. package/lib/abis/RewardDistributor.js.map +1 -1
  7. package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +78 -1456
  8. package/lib/abis/TokenizedVaultV2DepositWithPermit.js.map +1 -1
  9. package/lib/abis/TokenizedVaultV2WithDepositWithPermit.d.ts +85 -0
  10. package/lib/abis/TokenizedVaultV2WithDepositWithPermit.js +1878 -0
  11. package/lib/abis/TokenizedVaultV2WithDepositWithPermit.js.map +1 -0
  12. package/lib/abis/index.d.ts +0 -2
  13. package/lib/abis/index.js +0 -2
  14. package/lib/abis/index.js.map +1 -1
  15. package/lib/adapters/evm/index.d.ts +1 -20
  16. package/lib/adapters/evm/index.js +0 -16
  17. package/lib/adapters/evm/index.js.map +1 -1
  18. package/lib/adapters/solana/getters.js +1 -2
  19. package/lib/adapters/solana/getters.js.map +1 -1
  20. package/lib/adapters/solana/index.js.map +1 -1
  21. package/lib/adapters/sui/index.js.map +1 -1
  22. package/lib/adapters/sui/transformer.js +1 -4
  23. package/lib/adapters/sui/transformer.js.map +1 -1
  24. package/lib/core/constants/core.d.ts +1 -1
  25. package/lib/core/constants/core.js +4 -4
  26. package/lib/core/constants/core.js.map +1 -1
  27. package/lib/core/constants/vaults.d.ts +0 -2
  28. package/lib/core/constants/vaults.js +1 -3
  29. package/lib/core/constants/vaults.js.map +1 -1
  30. package/lib/core/constants/web3.js +1 -0
  31. package/lib/core/constants/web3.js.map +1 -1
  32. package/lib/core/constants.adapters.d.ts +117 -0
  33. package/lib/core/constants.adapters.js +160 -0
  34. package/lib/core/constants.adapters.js.map +1 -0
  35. package/lib/core/constants.core.d.ts +78 -0
  36. package/lib/core/constants.core.js +75 -0
  37. package/lib/core/constants.core.js.map +1 -0
  38. package/lib/core/constants.vaults.d.ts +64 -0
  39. package/lib/core/constants.vaults.js +156 -0
  40. package/lib/core/constants.vaults.js.map +1 -0
  41. package/lib/core/constants.web3.d.ts +31 -0
  42. package/lib/core/constants.web3.js +100 -0
  43. package/lib/core/constants.web3.js.map +1 -0
  44. package/lib/core/fetcher.d.ts +3 -2
  45. package/lib/core/fetcher.js +5 -7
  46. package/lib/core/fetcher.js.map +1 -1
  47. package/lib/core/helpers/core.d.ts +1 -1
  48. package/lib/core/helpers/vaults.d.ts +0 -1
  49. package/lib/core/helpers/vaults.js +1 -19
  50. package/lib/core/helpers/vaults.js.map +1 -1
  51. package/lib/core/helpers/web3.d.ts +4 -6
  52. package/lib/core/helpers/web3.js.map +1 -1
  53. package/lib/core/helpers.adapters.d.ts +9 -0
  54. package/lib/core/helpers.adapters.js +28 -0
  55. package/lib/core/helpers.adapters.js.map +1 -0
  56. package/lib/core/helpers.core.d.ts +48 -0
  57. package/lib/core/helpers.core.js +210 -0
  58. package/lib/core/helpers.core.js.map +1 -0
  59. package/lib/core/helpers.signer.d.ts +9 -0
  60. package/lib/core/helpers.signer.js +54 -0
  61. package/lib/core/helpers.signer.js.map +1 -0
  62. package/lib/core/helpers.vaults.d.ts +36 -0
  63. package/lib/core/helpers.vaults.js +145 -0
  64. package/lib/core/helpers.vaults.js.map +1 -0
  65. package/lib/core/helpers.web3.d.ts +95 -0
  66. package/lib/core/helpers.web3.js +376 -0
  67. package/lib/core/helpers.web3.js.map +1 -0
  68. package/lib/index.d.ts +0 -2
  69. package/lib/index.js +0 -2
  70. package/lib/index.js.map +1 -1
  71. package/lib/main.d.ts +1 -5
  72. package/lib/main.js +0 -13
  73. package/lib/main.js.map +1 -1
  74. package/lib/modules/vaults/adapter.helpers.js +1 -2
  75. package/lib/modules/vaults/adapter.helpers.js.map +1 -1
  76. package/lib/modules/vaults/getters.js +87 -129
  77. package/lib/modules/vaults/getters.js.map +1 -1
  78. package/lib/modules/vaults/main.js +6 -9
  79. package/lib/modules/vaults/main.js.map +1 -1
  80. package/lib/modules/vaults/read.actions.d.ts +3 -21
  81. package/lib/modules/vaults/read.actions.js +1 -130
  82. package/lib/modules/vaults/read.actions.js.map +1 -1
  83. package/lib/modules/vaults/utils.js +5 -11
  84. package/lib/modules/vaults/utils.js.map +1 -1
  85. package/lib/modules/vaults/write.actions.js +7 -8
  86. package/lib/modules/vaults/write.actions.js.map +1 -1
  87. package/lib/services/subgraph/vaults.js +6 -6
  88. package/lib/services/subgraph/vaults.js.map +1 -1
  89. package/lib/types/index.d.ts +0 -2
  90. package/lib/types/index.js +0 -2
  91. package/lib/types/index.js.map +1 -1
  92. package/lib/types/vaults.d.ts +0 -2
  93. package/lib/types/vaults.js.map +1 -1
  94. package/lib/types/webserver.d.ts +0 -2
  95. package/lib/verify.d.ts +2 -0
  96. package/lib/verify.js +33 -0
  97. package/lib/verify.js.map +1 -0
  98. package/package.json +12 -12
  99. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +0 -454
  100. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +0 -327
  101. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js.map +0 -1
  102. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +0 -1466
  103. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +0 -1092
  104. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js.map +0 -1
  105. package/lib/modules/sub-accounts/fetcher.d.ts +0 -10
  106. package/lib/modules/sub-accounts/fetcher.js +0 -33
  107. package/lib/modules/sub-accounts/fetcher.js.map +0 -1
  108. package/lib/modules/sub-accounts/index.d.ts +0 -2
  109. package/lib/modules/sub-accounts/index.js +0 -19
  110. package/lib/modules/sub-accounts/index.js.map +0 -1
  111. package/lib/modules/sub-accounts/main.d.ts +0 -16
  112. package/lib/modules/sub-accounts/main.js +0 -39
  113. package/lib/modules/sub-accounts/main.js.map +0 -1
  114. package/lib/types/sub-accounts.d.ts +0 -8
  115. package/lib/types/sub-accounts.js +0 -3
  116. package/lib/types/sub-accounts.js.map +0 -1
  117. package/lib/types/typed-contract.d.ts +0 -38
  118. package/lib/types/typed-contract.js +0 -3
  119. 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
- const protocolExposure = [];
203
- const tokenExposure = [];
202
+ let protocolExposure = [];
203
+ let tokenExposure = [];
204
204
  let cefiExposure = [];
205
- const cefiBorrowerResponses = {};
206
- const otcPositions = {};
207
- const defiPerBorrower = {};
208
- const exposurePerCategory = {
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
- const netValue = { value: 0 };
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() && !entry.useDebank);
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: abis_1.ABI_LENDING_POOL_V2,
383
+ abi: abi,
371
384
  provider,
372
385
  });
373
- if (version === 'evm-2') {
374
- decimals = await (0, core_1.getDecimals)(provider, await (0, core_1.getReceiptTokenAddress)(provider, vault), false);
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
- const logPromises = [];
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: abis_1.ABI_LENDING_POOL_V2,
718
+ abi: abi,
699
719
  address: v.address,
700
720
  });
701
721
  let bal = BigInt(0);
702
- if (version === 'evm-2') {
703
- decimals = await (0, core_1.getDecimals)(provider, await (0, core_1.getReceiptTokenAddress)(provider, vault), false);
704
- if (wallet && (0, ethers_1.isAddress)(wallet)) {
705
- const receiptContract = (0, core_1.createContract)({
706
- provider,
707
- abi: TokenizedVaultV2Receipt_1.ABI_TOKENIZED_VAULT_V2_RECEIPT,
708
- address: await (0, core_1.getReceiptTokenAddress)(provider, vault),
709
- });
710
- bal = await receiptContract.balanceOf(wallet);
711
- }
712
- }
713
- else {
714
- decimals = await (0, core_1.getDecimals)(provider, vault);
715
- if (wallet && (0, ethers_1.isAddress)(wallet)) {
716
- bal = await vaultContract.balanceOf(wallet);
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.totalSupply();
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: abis_1.ABI_LENDING_POOL_V2,
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: (await loanContract.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
- const borrowerResponses = {};
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, false, false),
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 = (await vaultContract.asset());
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
- const depositsByAsset = new Map();
1251
- let totalWithdrawalsInShares = BigInt(0);
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
- const assetKey = 'assetIn' in historyItem && typeof historyItem.assetIn === 'string'
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
- const dec = await (0, core_1.getDecimals)(provider, assetAddress, false);
1280
- assetDecimals.set(assetAddress, dec);
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 totalWithdrawnRaw = totalWithdrawalsInAssets;
1332
+ let totalWithdrawalsRequestedInAssetsRaw = totalWithdrawalsRequestedRaw;
1358
1333
  if (version === 'evm-2' && sharePriceRaw > BigInt(0)) {
1359
- totalWithdrawnRaw +=
1360
- (totalWithdrawalsInShares * sharePriceRaw) / BigInt(10 ** decimals);
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 effectiveTokenPrice = tokenPriceUsd > 0 ? tokenPriceUsd : 1;
1368
- if (tokenPriceUsd <= 0) {
1369
- core_1.Logger.log.warn('getVaultUserLifetimePnl:tokenPrice', `Invalid underlying token price: ${tokenPriceUsd}, using fallback of 1`);
1370
- }
1371
- let totalDepositedUsd = 0;
1372
- for (const [assetAddress, normalizedAmount] of totalDepositedRaw) {
1373
- const assetPrice = assetAddress === 'default'
1374
- ? effectiveTokenPrice
1375
- : assetPrices.get(assetAddress) || effectiveTokenPrice;
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 = (await contract.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,