@scallop-io/sui-scallop-sdk 0.42.6 → 0.42.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/constants/enum.d.ts +3 -1
- package/dist/index.js +183 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -81
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopUtils.d.ts +1 -0
- package/dist/types/constant/enum.d.ts +8 -0
- package/dist/types/query/core.d.ts +2 -2
- package/dist/types/query/portfolio.d.ts +53 -36
- package/dist/types/query/spool.d.ts +3 -3
- package/dist/utils/query.d.ts +3 -0
- package/package.json +1 -1
- package/src/constants/enum.ts +22 -0
- package/src/models/scallopUtils.ts +36 -13
- package/src/queries/coreQuery.ts +4 -0
- package/src/queries/portfolioQuery.ts +115 -68
- package/src/queries/spoolQuery.ts +2 -2
- package/src/types/constant/enum.ts +13 -0
- package/src/types/query/core.ts +3 -1
- package/src/types/query/portfolio.ts +56 -45
- package/src/types/query/spool.ts +3 -3
- package/src/utils/query.ts +22 -6
|
@@ -64,6 +64,7 @@ export declare class ScallopUtils {
|
|
|
64
64
|
*/
|
|
65
65
|
parseCoinNameFromType<T extends SupportAssetCoins>(coinType: string): T extends SupportAssetCoins ? T : SupportAssetCoins;
|
|
66
66
|
parseCoinNameFromType<T extends SupportMarketCoins>(coinType: string): T extends SupportMarketCoins ? T : SupportMarketCoins;
|
|
67
|
+
parseCoinNameFromType<T extends SupportCoins>(coinType: string): T extends SupportCoins ? T : SupportCoins;
|
|
67
68
|
/**
|
|
68
69
|
* Convert marke coin name to coin name.
|
|
69
70
|
*
|
|
@@ -14,3 +14,11 @@ export type StakeMarketCoins = {
|
|
|
14
14
|
export type RewardCoins = {
|
|
15
15
|
[key in SupportStakeMarketCoins]: SupportRewardCoins;
|
|
16
16
|
};
|
|
17
|
+
export type AssetCoinIds = {
|
|
18
|
+
[key in SupportAssetCoins]: string;
|
|
19
|
+
};
|
|
20
|
+
type PickFromUnion<T, K extends string> = K extends T ? K : never;
|
|
21
|
+
export type WormholeCoinIds = {
|
|
22
|
+
[key in PickFromUnion<SupportAssetCoins, 'eth' | 'btc' | 'usdc' | 'usdt' | 'apt' | 'sol'>]: string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -109,13 +109,13 @@ export type CollateralStat = {
|
|
|
109
109
|
};
|
|
110
110
|
export type MarketPool = {
|
|
111
111
|
coinName: SupportPoolCoins;
|
|
112
|
-
symbol:
|
|
112
|
+
symbol: string;
|
|
113
113
|
coinType: string;
|
|
114
114
|
marketCoinType: string;
|
|
115
115
|
coinWrappedType: CoinWrappedType;
|
|
116
116
|
coinDecimal: number;
|
|
117
117
|
coinPrice: number;
|
|
118
|
-
} & Required<Pick<ParsedMarketPoolData, 'reserveFactor' | 'borrowWeight' | 'marketCoinSupplyAmount' | 'minBorrowAmount'>> & CalculatedMarketPoolData;
|
|
118
|
+
} & Required<Pick<ParsedMarketPoolData, 'highKink' | 'midKink' | 'reserveFactor' | 'borrowWeight' | 'marketCoinSupplyAmount' | 'minBorrowAmount'>> & CalculatedMarketPoolData;
|
|
119
119
|
export type MarketCollateral = {
|
|
120
120
|
coinName: SupportCollateralCoins;
|
|
121
121
|
symbol: string;
|
|
@@ -17,52 +17,69 @@ export type Lending = Required<Pick<MarketPool, 'coinName' | 'symbol' | 'coinTyp
|
|
|
17
17
|
stakedAmount: number;
|
|
18
18
|
stakedCoin: number;
|
|
19
19
|
stakedValue: number;
|
|
20
|
+
unstakedMarketAmount: number;
|
|
21
|
+
unstakedMarketCoin: number;
|
|
22
|
+
unstakedAmount: number;
|
|
23
|
+
unstakedCoin: number;
|
|
24
|
+
unstakedValue: number;
|
|
20
25
|
availableSupplyAmount: number;
|
|
26
|
+
availableSupplyCoin: number;
|
|
21
27
|
availableWithdrawAmount: number;
|
|
28
|
+
availableWithdrawCoin: number;
|
|
22
29
|
availableStakeAmount: number;
|
|
30
|
+
availableStakeCoin: number;
|
|
23
31
|
availableUnstakeAmount: number;
|
|
32
|
+
availableUnstakeCoin: number;
|
|
24
33
|
availableClaimAmount: number;
|
|
34
|
+
availableClaimCoin: number;
|
|
25
35
|
};
|
|
26
36
|
export type ObligationAccount = {
|
|
27
|
-
obligationId
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
totalDebtValue: number;
|
|
37
|
+
obligationId: string;
|
|
38
|
+
totalDepositedValue: number;
|
|
39
|
+
totalBorrowedValue: number;
|
|
31
40
|
totalBalanceValue: number;
|
|
32
41
|
totalBorrowCapacityValue: number;
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
totalAvailableCollateralValue: number;
|
|
43
|
+
totalBorrowedValueWithWeight: number;
|
|
44
|
+
totalRequiredCollateralValue: number;
|
|
45
|
+
totalUnhealthyCollateralValue: number;
|
|
46
|
+
totalRiskLevel: number;
|
|
47
|
+
totalDepositedPools: number;
|
|
48
|
+
totalBorrowedPools: number;
|
|
49
|
+
collaterals: OptionalKeys<Record<SupportCollateralCoins, ObligationCollateral>>;
|
|
50
|
+
debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
|
|
51
|
+
};
|
|
52
|
+
export type ObligationCollateral = {
|
|
53
|
+
coinName: SupportCollateralCoins;
|
|
54
|
+
coinType: string;
|
|
55
|
+
symbol: string;
|
|
56
|
+
coinDecimal: number;
|
|
57
|
+
coinPrice: number;
|
|
58
|
+
depositedAmount: number;
|
|
59
|
+
depositedCoin: number;
|
|
60
|
+
depositedValue: number;
|
|
61
|
+
borrowCapacityValue: number;
|
|
35
62
|
requiredCollateralValue: number;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
debtAmount: number;
|
|
57
|
-
debtCoin: number;
|
|
58
|
-
debtValue: number;
|
|
59
|
-
debtValueWithWeight: number;
|
|
60
|
-
borrowIndex: number;
|
|
61
|
-
availableBorrowAmount: number;
|
|
62
|
-
availableBorrowCoin: number;
|
|
63
|
-
availableRepayAmount: number;
|
|
64
|
-
availableRepayCoin: number;
|
|
65
|
-
}>>;
|
|
63
|
+
availableDepositAmount: number;
|
|
64
|
+
availableDepositCoin: number;
|
|
65
|
+
availableWithdrawAmount: number;
|
|
66
|
+
availableWithdrawCoin: number;
|
|
67
|
+
};
|
|
68
|
+
export type ObligationDebt = {
|
|
69
|
+
coinName: SupportPoolCoins;
|
|
70
|
+
coinType: string;
|
|
71
|
+
symbol: string;
|
|
72
|
+
coinDecimal: number;
|
|
73
|
+
coinPrice: number;
|
|
74
|
+
borrowedAmount: number;
|
|
75
|
+
borrowedCoin: number;
|
|
76
|
+
borrowedValue: number;
|
|
77
|
+
borrowedValueWithWeight: number;
|
|
78
|
+
borrowIndex: number;
|
|
79
|
+
availableBorrowAmount: number;
|
|
80
|
+
availableBorrowCoin: number;
|
|
81
|
+
availableRepayAmount: number;
|
|
82
|
+
availableRepayCoin: number;
|
|
66
83
|
};
|
|
67
84
|
export type TotalValueLocked = {
|
|
68
85
|
supplyValue: number;
|
|
@@ -7,8 +7,8 @@ export type RewardPools = OptionalKeys<Record<SupportStakeMarketCoins, RewardPoo
|
|
|
7
7
|
export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
|
|
8
8
|
export type Spools = OptionalKeys<Record<SupportStakeMarketCoins, Spool>>;
|
|
9
9
|
export type Spool = {
|
|
10
|
-
|
|
11
|
-
symbol:
|
|
10
|
+
marketCoinName: SupportStakeMarketCoins;
|
|
11
|
+
symbol: string;
|
|
12
12
|
coinType: string;
|
|
13
13
|
marketCoinType: string;
|
|
14
14
|
rewardCoinType: string;
|
|
@@ -72,7 +72,7 @@ export type ParsedRewardPoolData = {
|
|
|
72
72
|
spoolId: string;
|
|
73
73
|
};
|
|
74
74
|
export type CalculatedRewardPoolData = {
|
|
75
|
-
|
|
75
|
+
rewardApr: number;
|
|
76
76
|
totalRewardAmount: number;
|
|
77
77
|
totalRewardCoin: number;
|
|
78
78
|
totalRewardValue: number;
|
package/dist/utils/query.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
1
2
|
import type { ScallopUtils } from '../models';
|
|
2
3
|
import type { OriginMarketPoolData, ParsedMarketPoolData, CalculatedMarketPoolData, OriginMarketCollateralData, ParsedMarketCollateralData, CalculatedMarketCollateralData, OriginStakePoolData, ParsedStakePoolData, CalculatedStakePoolData, OriginRewardPoolData, ParsedRewardPoolData, CalculatedRewardPoolData } from '../types';
|
|
3
4
|
/**
|
|
@@ -32,3 +33,5 @@ export declare const calculateStakePoolData: (parsedStakePoolData: ParsedStakePo
|
|
|
32
33
|
*/
|
|
33
34
|
export declare const parseOriginRewardPoolData: (originRewardPoolData: OriginRewardPoolData) => ParsedRewardPoolData;
|
|
34
35
|
export declare const calculateRewardPoolData: (parsedStakePoolData: ParsedStakePoolData, parsedRewardPoolData: ParsedRewardPoolData, calculatedStakePoolData: CalculatedStakePoolData, rewardCoinPrice: number, rewardCoinDecimal: number) => CalculatedRewardPoolData;
|
|
36
|
+
export declare const minBigNumber: (...args: BigNumber.Value[]) => BigNumber;
|
|
37
|
+
export declare const maxBigNumber: (...args: BigNumber.Value[]) => BigNumber;
|
package/package.json
CHANGED
package/src/constants/enum.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type {
|
|
|
4
4
|
MarketCoins,
|
|
5
5
|
StakeMarketCoins,
|
|
6
6
|
RewardCoins,
|
|
7
|
+
AssetCoinIds,
|
|
8
|
+
WormholeCoinIds,
|
|
7
9
|
} from '../types';
|
|
8
10
|
|
|
9
11
|
export const coinDecimals: SupportCoinDecimals = {
|
|
@@ -58,3 +60,23 @@ export const rewardCoins: RewardCoins = {
|
|
|
58
60
|
susdc: 'sui',
|
|
59
61
|
susdt: 'sui',
|
|
60
62
|
};
|
|
63
|
+
|
|
64
|
+
export const coinIds: AssetCoinIds = {
|
|
65
|
+
sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
66
|
+
eth: '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5',
|
|
67
|
+
btc: '0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881',
|
|
68
|
+
usdc: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf',
|
|
69
|
+
usdt: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c',
|
|
70
|
+
apt: '0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37',
|
|
71
|
+
sol: '0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8',
|
|
72
|
+
cetus: '0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const wormholeCoinIds: WormholeCoinIds = {
|
|
76
|
+
eth: '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5',
|
|
77
|
+
btc: '0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881',
|
|
78
|
+
usdc: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf',
|
|
79
|
+
usdt: '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c',
|
|
80
|
+
apt: '0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37',
|
|
81
|
+
sol: '0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8',
|
|
82
|
+
};
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
SUPPORT_COLLATERALS,
|
|
11
11
|
rewardCoins,
|
|
12
12
|
coinDecimals,
|
|
13
|
+
wormholeCoinIds,
|
|
14
|
+
coinIds,
|
|
13
15
|
} from '../constants';
|
|
14
16
|
import { queryObligation } from '../queries';
|
|
15
17
|
import { parseDataFromPythPriceFeed, isMarketCoin } from '../utils';
|
|
@@ -108,16 +110,22 @@ export class ScallopUtils {
|
|
|
108
110
|
*/
|
|
109
111
|
public parseCoinType(coinName: SupportCoins) {
|
|
110
112
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
111
|
-
const coinPackageId =
|
|
113
|
+
const coinPackageId =
|
|
114
|
+
this._address.get(`core.coins.${coinName}.id`) ??
|
|
115
|
+
coinIds[coinName] ??
|
|
116
|
+
undefined;
|
|
117
|
+
if (!coinPackageId) {
|
|
118
|
+
throw Error(`Coin ${coinName} is not supported`);
|
|
119
|
+
}
|
|
112
120
|
if (coinName === 'sui')
|
|
113
121
|
return normalizeStructTag(`${coinPackageId}::sui::SUI`);
|
|
114
122
|
const wormHoleCoinIds = [
|
|
115
|
-
this._address.get('core.coins.usdc.id'),
|
|
116
|
-
this._address.get('core.coins.usdt.id'),
|
|
117
|
-
this._address.get('core.coins.eth.id'),
|
|
118
|
-
this._address.get('core.coins.btc.id'),
|
|
119
|
-
this._address.get('core.coins.sol.id'),
|
|
120
|
-
this._address.get('core.coins.apt.id'),
|
|
123
|
+
this._address.get('core.coins.usdc.id') ?? wormholeCoinIds.usdc,
|
|
124
|
+
this._address.get('core.coins.usdt.id') ?? wormholeCoinIds.usdt,
|
|
125
|
+
this._address.get('core.coins.eth.id') ?? wormholeCoinIds.eth,
|
|
126
|
+
this._address.get('core.coins.btc.id') ?? wormholeCoinIds.btc,
|
|
127
|
+
this._address.get('core.coins.sol.id') ?? wormholeCoinIds.sol,
|
|
128
|
+
this._address.get('core.coins.apt.id') ?? wormholeCoinIds.apt,
|
|
121
129
|
];
|
|
122
130
|
if (wormHoleCoinIds.includes(coinPackageId)) {
|
|
123
131
|
return `${coinPackageId}::coin::COIN`;
|
|
@@ -154,6 +162,9 @@ export class ScallopUtils {
|
|
|
154
162
|
public parseCoinNameFromType<T extends SupportMarketCoins>(
|
|
155
163
|
coinType: string
|
|
156
164
|
): T extends SupportMarketCoins ? T : SupportMarketCoins;
|
|
165
|
+
public parseCoinNameFromType<T extends SupportCoins>(
|
|
166
|
+
coinType: string
|
|
167
|
+
): T extends SupportCoins ? T : SupportCoins;
|
|
157
168
|
public parseCoinNameFromType(coinType: string) {
|
|
158
169
|
coinType = normalizeStructTag(coinType);
|
|
159
170
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
@@ -162,12 +173,24 @@ export class ScallopUtils {
|
|
|
162
173
|
coinType = coinTypeMatch?.[1] || coinType;
|
|
163
174
|
|
|
164
175
|
const wormHoleCoinTypeMap: Record<string, SupportAssetCoins> = {
|
|
165
|
-
[`${
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
[`${
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
[`${
|
|
177
|
+
this._address.get('core.coins.usdc.id') ?? wormholeCoinIds.usdc
|
|
178
|
+
}::coin::COIN`]: 'usdc',
|
|
179
|
+
[`${
|
|
180
|
+
this._address.get('core.coins.usdt.id') ?? wormholeCoinIds.usdt
|
|
181
|
+
}::coin::COIN`]: 'usdt',
|
|
182
|
+
[`${
|
|
183
|
+
this._address.get('core.coins.eth.id') ?? wormholeCoinIds.eth
|
|
184
|
+
}::coin::COIN`]: 'eth',
|
|
185
|
+
[`${
|
|
186
|
+
this._address.get('core.coins.btc.id') ?? wormholeCoinIds.btc
|
|
187
|
+
}::coin::COIN`]: 'btc',
|
|
188
|
+
[`${
|
|
189
|
+
this._address.get('core.coins.sol.id') ?? wormholeCoinIds.sol
|
|
190
|
+
}::coin::COIN`]: 'sol',
|
|
191
|
+
[`${
|
|
192
|
+
this._address.get('core.coins.apt.id') ?? wormholeCoinIds.apt
|
|
193
|
+
}::coin::COIN`]: 'apt',
|
|
171
194
|
};
|
|
172
195
|
|
|
173
196
|
const assetCoinName =
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -98,6 +98,8 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
98
98
|
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
99
99
|
coinDecimal: query.utils.getCoinDecimal(poolCoinName),
|
|
100
100
|
coinPrice: coinPrice,
|
|
101
|
+
highKink: parsedMarketPoolData.highKink,
|
|
102
|
+
midKink: parsedMarketPoolData.midKink,
|
|
101
103
|
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
102
104
|
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
103
105
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
@@ -352,6 +354,8 @@ export const getMarketPool = async (
|
|
|
352
354
|
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
353
355
|
coinDecimal: query.utils.getCoinDecimal(poolCoinName),
|
|
354
356
|
coinPrice: coinPrice ?? 0,
|
|
357
|
+
highKink: parsedMarketPoolData.highKink,
|
|
358
|
+
midKink: parsedMarketPoolData.midKink,
|
|
355
359
|
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
356
360
|
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
357
361
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|