@scallop-io/sui-scallop-sdk 1.4.7 → 1.4.8
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/index.js +51 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -32
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +44 -36
- package/dist/queries/portfolioQuery.d.ts +44 -38
- package/package.json +1 -1
- package/src/models/scallopQuery.ts +8 -1
- package/src/queries/poolAddressesQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +54 -29
package/dist/index.mjs
CHANGED
|
@@ -4047,14 +4047,14 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4047
4047
|
// src/queries/portfolioQuery.ts
|
|
4048
4048
|
import BigNumber5 from "bignumber.js";
|
|
4049
4049
|
import { normalizeStructTag as normalizeStructTag5, SUI_TYPE_ARG } from "@scallop-io/sui-kit";
|
|
4050
|
-
var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress, marketPools, indexer = false) => {
|
|
4050
|
+
var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress, marketPools, coinPrices, indexer = false) => {
|
|
4051
4051
|
const marketCoinNames = poolCoinNames.map(
|
|
4052
4052
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
4053
4053
|
);
|
|
4054
4054
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
4055
4055
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
4056
4056
|
);
|
|
4057
|
-
|
|
4057
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
4058
4058
|
marketPools = marketPools ?? (await query.getMarketPools(poolCoinNames, {
|
|
4059
4059
|
indexer,
|
|
4060
4060
|
coinPrices
|
|
@@ -4225,9 +4225,9 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
4225
4225
|
};
|
|
4226
4226
|
return lending;
|
|
4227
4227
|
};
|
|
4228
|
-
var getObligationAccounts = async (query, ownerAddress, market, indexer = false) => {
|
|
4228
|
+
var getObligationAccounts = async (query, ownerAddress, market, coinPrices, indexer = false) => {
|
|
4229
4229
|
market = market ?? await query.getMarketPools(void 0, { indexer });
|
|
4230
|
-
|
|
4230
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({
|
|
4231
4231
|
marketPools: market.pools
|
|
4232
4232
|
});
|
|
4233
4233
|
const [coinAmounts, obligations] = await Promise.all([
|
|
@@ -4587,19 +4587,24 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4587
4587
|
return tvl;
|
|
4588
4588
|
};
|
|
4589
4589
|
var getUserPortfolio = async (query, walletAddress, indexer = false) => {
|
|
4590
|
-
const
|
|
4591
|
-
const
|
|
4590
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
4591
|
+
const market = await query.getMarketPools(void 0, { indexer, coinPrices });
|
|
4592
|
+
const [lendings, obligationAccounts, borrowIncentivePools, veScas] = await Promise.all([
|
|
4592
4593
|
query.getLendings(void 0, walletAddress, {
|
|
4593
4594
|
indexer,
|
|
4594
|
-
marketPools: market.pools
|
|
4595
|
+
marketPools: market.pools,
|
|
4596
|
+
coinPrices
|
|
4595
4597
|
}),
|
|
4596
4598
|
query.getObligationAccounts(walletAddress, {
|
|
4597
4599
|
indexer,
|
|
4598
|
-
market
|
|
4600
|
+
market,
|
|
4601
|
+
coinPrices
|
|
4599
4602
|
}),
|
|
4600
4603
|
query.getBorrowIncentivePools(void 0, {
|
|
4601
|
-
marketPools: market.pools
|
|
4602
|
-
|
|
4604
|
+
marketPools: market.pools,
|
|
4605
|
+
coinPrices
|
|
4606
|
+
}),
|
|
4607
|
+
query.getVeScas({ walletAddress, excludeEmpty: true })
|
|
4603
4608
|
]);
|
|
4604
4609
|
const parsedLendings = Object.values(lendings).filter((t) => t.availableWithdrawCoin > 0).map((lending) => ({
|
|
4605
4610
|
suppliedCoin: lending.availableWithdrawCoin,
|
|
@@ -4686,28 +4691,39 @@ var getUserPortfolio = async (query, walletAddress, indexer = false) => {
|
|
|
4686
4691
|
},
|
|
4687
4692
|
{}
|
|
4688
4693
|
);
|
|
4694
|
+
const parsedVeScas = veScas.map(
|
|
4695
|
+
({ keyId, lockedScaCoin, currentVeScaBalance, unlockAt }) => ({
|
|
4696
|
+
veScaKey: keyId,
|
|
4697
|
+
coinPrice: coinPrices.sca ?? 0,
|
|
4698
|
+
lockedScaInCoin: lockedScaCoin,
|
|
4699
|
+
lockedScaInUsd: lockedScaCoin * (coinPrices.sca ?? 0),
|
|
4700
|
+
currentVeScaBalance,
|
|
4701
|
+
remainingLockPeriodInDays: unlockAt - Date.now() > 0 ? (unlockAt - Date.now()) / 864e5 : 0,
|
|
4702
|
+
unlockAt
|
|
4703
|
+
})
|
|
4704
|
+
);
|
|
4689
4705
|
return {
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4706
|
+
totalSupplyValue: parsedLendings.reduce((acc, curr) => {
|
|
4707
|
+
acc += curr.suppliedValue;
|
|
4708
|
+
return acc;
|
|
4709
|
+
}, 0),
|
|
4710
|
+
...parsedObligationAccounts.reduce(
|
|
4711
|
+
(acc, curr) => {
|
|
4712
|
+
acc.totalDebtValue += curr.totalDebtsInUsd;
|
|
4713
|
+
acc.totalCollateralValue += curr.totalCollateralInUsd;
|
|
4693
4714
|
return acc;
|
|
4694
|
-
},
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
totalCollateralValue: 0
|
|
4707
|
-
}
|
|
4708
|
-
),
|
|
4709
|
-
obligations: parsedObligationAccounts
|
|
4710
|
-
},
|
|
4715
|
+
},
|
|
4716
|
+
{
|
|
4717
|
+
totalDebtValue: 0,
|
|
4718
|
+
totalCollateralValue: 0
|
|
4719
|
+
}
|
|
4720
|
+
),
|
|
4721
|
+
totalLockedScaValue: parsedVeScas.reduce((acc, curr) => {
|
|
4722
|
+
acc += curr.lockedScaInUsd;
|
|
4723
|
+
return acc;
|
|
4724
|
+
}, 0),
|
|
4725
|
+
lendings: parsedLendings,
|
|
4726
|
+
borrowings: parsedObligationAccounts,
|
|
4711
4727
|
pendingRewards: {
|
|
4712
4728
|
lendings: Object.entries(pendingLendingRewards).reduce(
|
|
4713
4729
|
(acc, [key, value]) => {
|
|
@@ -4731,7 +4747,8 @@ var getUserPortfolio = async (query, walletAddress, indexer = false) => {
|
|
|
4731
4747
|
},
|
|
4732
4748
|
[]
|
|
4733
4749
|
)
|
|
4734
|
-
}
|
|
4750
|
+
},
|
|
4751
|
+
veScas: parsedVeScas
|
|
4735
4752
|
};
|
|
4736
4753
|
};
|
|
4737
4754
|
|
|
@@ -5572,7 +5589,7 @@ var getAllAddresses = async (query) => {
|
|
|
5572
5589
|
sCoinTreasury,
|
|
5573
5590
|
sCoinType,
|
|
5574
5591
|
coinDecimalId,
|
|
5575
|
-
coinType
|
|
5592
|
+
coinType: `0x${coinType}`
|
|
5576
5593
|
};
|
|
5577
5594
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
5578
5595
|
})
|
|
@@ -8264,6 +8281,7 @@ var ScallopQuery = class {
|
|
|
8264
8281
|
poolCoinNames,
|
|
8265
8282
|
ownerAddress,
|
|
8266
8283
|
args?.marketPools,
|
|
8284
|
+
args?.coinPrices,
|
|
8267
8285
|
args?.indexer
|
|
8268
8286
|
);
|
|
8269
8287
|
}
|
|
@@ -8293,6 +8311,7 @@ var ScallopQuery = class {
|
|
|
8293
8311
|
this,
|
|
8294
8312
|
ownerAddress,
|
|
8295
8313
|
args?.market,
|
|
8314
|
+
args?.coinPrices,
|
|
8296
8315
|
args?.indexer
|
|
8297
8316
|
);
|
|
8298
8317
|
}
|