@scallop-io/sui-scallop-sdk 0.42.7 → 0.44.0
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 +125 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -29
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +4 -60
- package/dist/models/scallopClient.d.ts +10 -10
- package/dist/models/scallopUtils.d.ts +3 -1
- package/dist/queries/coreQuery.d.ts +2 -1
- package/dist/types/builder/core.d.ts +18 -18
- package/dist/types/builder/index.d.ts +0 -2
- package/dist/types/builder/spool.d.ts +8 -9
- package/dist/types/constant/enum.d.ts +8 -0
- package/dist/types/query/core.d.ts +1 -1
- package/dist/types/query/portfolio.d.ts +44 -28
- package/dist/types/query/spool.d.ts +1 -1
- package/dist/utils/query.d.ts +3 -0
- package/package.json +24 -18
- package/src/builders/coreBuilder.ts +7 -7
- package/src/builders/spoolBuilder.ts +4 -4
- package/src/constants/enum.ts +22 -0
- package/src/models/scallopClient.ts +20 -20
- package/src/models/scallopUtils.ts +38 -15
- package/src/queries/coreQuery.ts +6 -1
- package/src/queries/portfolioQuery.ts +55 -14
- package/src/types/builder/core.ts +34 -29
- package/src/types/builder/index.ts +0 -2
- package/src/types/builder/spool.ts +15 -17
- package/src/types/constant/enum.ts +13 -0
- package/src/types/query/core.ts +2 -0
- package/src/types/query/portfolio.ts +46 -36
- package/src/types/query/spool.ts +1 -1
- package/src/utils/query.ts +18 -2
|
@@ -6,8 +6,8 @@ import { ScallopUtils } from './scallopUtils';
|
|
|
6
6
|
import { ScallopBuilder } from './scallopBuilder';
|
|
7
7
|
import { ScallopQuery } from './scallopQuery';
|
|
8
8
|
import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
9
|
+
import type { TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
10
|
+
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
11
11
|
import type {
|
|
12
12
|
ScallopClientFnReturnType,
|
|
13
13
|
ScallopInstanceParams,
|
|
@@ -237,14 +237,14 @@ export class ScallopClient {
|
|
|
237
237
|
collateralCoinName: SupportCollateralCoins,
|
|
238
238
|
amount: number,
|
|
239
239
|
sign?: S,
|
|
240
|
-
obligationId?:
|
|
240
|
+
obligationId?: string,
|
|
241
241
|
walletAddress?: string
|
|
242
242
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
243
243
|
public async depositCollateral<S extends boolean>(
|
|
244
244
|
collateralCoinName: SupportCollateralCoins,
|
|
245
245
|
amount: number,
|
|
246
246
|
sign: S = true as S,
|
|
247
|
-
obligationId?:
|
|
247
|
+
obligationId?: string,
|
|
248
248
|
walletAddress?: string
|
|
249
249
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
250
250
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -374,14 +374,14 @@ export class ScallopClient {
|
|
|
374
374
|
stakeCoinName: SupportStakeCoins,
|
|
375
375
|
amount: number,
|
|
376
376
|
sign?: S,
|
|
377
|
-
stakeAccountId?:
|
|
377
|
+
stakeAccountId?: string,
|
|
378
378
|
walletAddress?: string
|
|
379
379
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
380
380
|
public async depositAndStake<S extends boolean>(
|
|
381
381
|
stakeCoinName: SupportStakeCoins,
|
|
382
382
|
amount: number,
|
|
383
383
|
sign: S = true as S,
|
|
384
|
-
stakeAccountId?:
|
|
384
|
+
stakeAccountId?: string,
|
|
385
385
|
walletAddress?: string
|
|
386
386
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
387
387
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -543,16 +543,16 @@ export class ScallopClient {
|
|
|
543
543
|
amount: number,
|
|
544
544
|
callback: (
|
|
545
545
|
txBlock: ScallopTxBlock,
|
|
546
|
-
coin:
|
|
547
|
-
) =>
|
|
546
|
+
coin: TransactionObjectArgument | string
|
|
547
|
+
) => SuiObjectArg
|
|
548
548
|
): Promise<SuiTransactionBlockResponse>;
|
|
549
549
|
public async flashLoan<S extends boolean>(
|
|
550
550
|
poolCoinName: SupportPoolCoins,
|
|
551
551
|
amount: number,
|
|
552
552
|
callback: (
|
|
553
553
|
txBlock: ScallopTxBlock,
|
|
554
|
-
coin:
|
|
555
|
-
) =>
|
|
554
|
+
coin: TransactionObjectArgument | string
|
|
555
|
+
) => SuiObjectArg,
|
|
556
556
|
sign?: S,
|
|
557
557
|
walletAddress?: string
|
|
558
558
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
@@ -561,8 +561,8 @@ export class ScallopClient {
|
|
|
561
561
|
amount: number,
|
|
562
562
|
callback: (
|
|
563
563
|
txBlock: ScallopTxBlock,
|
|
564
|
-
coin:
|
|
565
|
-
) =>
|
|
564
|
+
coin: TransactionObjectArgument | string
|
|
565
|
+
) => SuiObjectArg,
|
|
566
566
|
sign: S = true as S,
|
|
567
567
|
walletAddress?: string
|
|
568
568
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
@@ -637,14 +637,14 @@ export class ScallopClient {
|
|
|
637
637
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
638
638
|
amount: number,
|
|
639
639
|
sign?: S,
|
|
640
|
-
stakeAccountId?:
|
|
640
|
+
stakeAccountId?: string,
|
|
641
641
|
walletAddress?: string
|
|
642
642
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
643
643
|
public async stake<S extends boolean>(
|
|
644
644
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
645
645
|
amount: number,
|
|
646
646
|
sign: S = true as S,
|
|
647
|
-
stakeAccountId?:
|
|
647
|
+
stakeAccountId?: string,
|
|
648
648
|
walletAddress?: string
|
|
649
649
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
650
650
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -689,14 +689,14 @@ export class ScallopClient {
|
|
|
689
689
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
690
690
|
amount: number,
|
|
691
691
|
sign?: S,
|
|
692
|
-
stakeAccountId?:
|
|
692
|
+
stakeAccountId?: string,
|
|
693
693
|
walletAddress?: string
|
|
694
694
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
695
695
|
public async unstake<S extends boolean>(
|
|
696
696
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
697
697
|
amount: number,
|
|
698
698
|
sign: S = true as S,
|
|
699
|
-
stakeAccountId?:
|
|
699
|
+
stakeAccountId?: string,
|
|
700
700
|
walletAddress?: string
|
|
701
701
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
702
702
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -737,14 +737,14 @@ export class ScallopClient {
|
|
|
737
737
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
738
738
|
amount: number,
|
|
739
739
|
sign?: S,
|
|
740
|
-
stakeAccountId?:
|
|
740
|
+
stakeAccountId?: string,
|
|
741
741
|
walletAddress?: string
|
|
742
742
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
743
743
|
public async unstakeAndWithdraw<S extends boolean>(
|
|
744
744
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
745
745
|
amount: number,
|
|
746
746
|
sign: S = true as S,
|
|
747
|
-
stakeAccountId?:
|
|
747
|
+
stakeAccountId?: string,
|
|
748
748
|
walletAddress?: string
|
|
749
749
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
750
750
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -791,13 +791,13 @@ export class ScallopClient {
|
|
|
791
791
|
public async claim<S extends boolean>(
|
|
792
792
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
793
793
|
sign?: S,
|
|
794
|
-
stakeAccountId?:
|
|
794
|
+
stakeAccountId?: string,
|
|
795
795
|
walletAddress?: string
|
|
796
796
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
797
797
|
public async claim<S extends boolean>(
|
|
798
798
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
799
799
|
sign: S = true as S,
|
|
800
|
-
stakeAccountId?:
|
|
800
|
+
stakeAccountId?: string,
|
|
801
801
|
walletAddress?: string
|
|
802
802
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
803
803
|
const txBlock = this.builder.createTxBlock();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SUI_TYPE_ARG, normalizeStructTag } from '@mysten/sui.js/utils';
|
|
2
|
-
import { SuiKit } from '@scallop-io/sui-kit';
|
|
2
|
+
import { SuiAddressArg, SuiKit } from '@scallop-io/sui-kit';
|
|
3
3
|
import { SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
4
4
|
import { ScallopAddress } from './scallopAddress';
|
|
5
5
|
import { ScallopQuery } from './scallopQuery';
|
|
@@ -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 =
|
|
@@ -271,7 +294,7 @@ export class ScallopUtils {
|
|
|
271
294
|
* @param obligationId - The obligation id.
|
|
272
295
|
* @return Asset coin Names.
|
|
273
296
|
*/
|
|
274
|
-
public async getObligationCoinNames(obligationId:
|
|
297
|
+
public async getObligationCoinNames(obligationId: SuiAddressArg) {
|
|
275
298
|
const obligation = await queryObligation(this._query, obligationId);
|
|
276
299
|
const collateralCoinTypes = obligation.collaterals.map((collateral) => {
|
|
277
300
|
return `0x${collateral.type.name}`;
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
calculateMarketCollateralData,
|
|
13
13
|
} from '../utils';
|
|
14
14
|
import type { SuiObjectResponse, SuiObjectData } from '@mysten/sui.js/client';
|
|
15
|
+
import type { SuiAddressArg } from '@scallop-io/sui-kit';
|
|
15
16
|
import type { ScallopQuery } from '../models';
|
|
16
17
|
import {
|
|
17
18
|
Market,
|
|
@@ -98,6 +99,8 @@ export const queryMarket = async (query: ScallopQuery) => {
|
|
|
98
99
|
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
99
100
|
coinDecimal: query.utils.getCoinDecimal(poolCoinName),
|
|
100
101
|
coinPrice: coinPrice,
|
|
102
|
+
highKink: parsedMarketPoolData.highKink,
|
|
103
|
+
midKink: parsedMarketPoolData.midKink,
|
|
101
104
|
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
102
105
|
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
103
106
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
@@ -352,6 +355,8 @@ export const getMarketPool = async (
|
|
|
352
355
|
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
353
356
|
coinDecimal: query.utils.getCoinDecimal(poolCoinName),
|
|
354
357
|
coinPrice: coinPrice ?? 0,
|
|
358
|
+
highKink: parsedMarketPoolData.highKink,
|
|
359
|
+
midKink: parsedMarketPoolData.midKink,
|
|
355
360
|
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
356
361
|
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
357
362
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
@@ -599,7 +604,7 @@ export const getObligations = async (
|
|
|
599
604
|
*/
|
|
600
605
|
export const queryObligation = async (
|
|
601
606
|
query: ScallopQuery,
|
|
602
|
-
obligationId:
|
|
607
|
+
obligationId: SuiAddressArg
|
|
603
608
|
) => {
|
|
604
609
|
const packageId = query.address.get('core.packages.query.id');
|
|
605
610
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
|
|
3
|
+
import { minBigNumber } from 'src/utils';
|
|
3
4
|
import type { ScallopQuery } from '../models';
|
|
4
5
|
import type {
|
|
5
6
|
Market,
|
|
@@ -133,7 +134,9 @@ export const getLending = async (
|
|
|
133
134
|
let stakedCoin = BigNumber(0);
|
|
134
135
|
let stakedValue = BigNumber(0);
|
|
135
136
|
let availableUnstakeAmount = BigNumber(0);
|
|
137
|
+
let availableUnstakeCoin = BigNumber(0);
|
|
136
138
|
let availableClaimAmount = BigNumber(0);
|
|
139
|
+
let availableClaimCoin = BigNumber(0);
|
|
137
140
|
|
|
138
141
|
if (spool) {
|
|
139
142
|
for (const stakeAccount of stakeAccounts) {
|
|
@@ -161,6 +164,7 @@ export const getLending = async (
|
|
|
161
164
|
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
162
165
|
accountStakedMarketCoinAmount
|
|
163
166
|
);
|
|
167
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(-1 * coinDecimal);
|
|
164
168
|
|
|
165
169
|
const baseIndexRate = 1_000_000_000;
|
|
166
170
|
const increasedPointRate = spool?.currentPointIndex
|
|
@@ -175,6 +179,7 @@ export const getLending = async (
|
|
|
175
179
|
.multipliedBy(spool.exchangeRateNumerator)
|
|
176
180
|
.dividedBy(spool.exchangeRateDenominator)
|
|
177
181
|
);
|
|
182
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(-1 * coinDecimal);
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
185
|
|
|
@@ -185,6 +190,20 @@ export const getLending = async (
|
|
|
185
190
|
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
186
191
|
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
187
192
|
|
|
193
|
+
const unstakedMarketAmount = BigNumber(marketCoinAmount);
|
|
194
|
+
const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
|
|
195
|
+
|
|
196
|
+
const availableSupplyAmount = BigNumber(coinAmount);
|
|
197
|
+
const availableSupplyCoin = availableSupplyAmount.shiftedBy(-1 * coinDecimal);
|
|
198
|
+
const availableWithdrawAmount = minBigNumber(
|
|
199
|
+
suppliedAmount,
|
|
200
|
+
marketPool?.supplyAmount ?? Infinity
|
|
201
|
+
).plus(stakedAmount);
|
|
202
|
+
const availableWithdrawCoin = minBigNumber(
|
|
203
|
+
suppliedCoin,
|
|
204
|
+
marketPool?.supplyCoin ?? Infinity
|
|
205
|
+
).plus(stakedCoin);
|
|
206
|
+
|
|
188
207
|
const lending: Lending = {
|
|
189
208
|
coinName: poolCoinName,
|
|
190
209
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
@@ -194,7 +213,7 @@ export const getLending = async (
|
|
|
194
213
|
coinPrice: coinPrice ?? 0,
|
|
195
214
|
supplyApr: marketPool?.supplyApr ?? 0,
|
|
196
215
|
supplyApy: marketPool?.supplyApy ?? 0,
|
|
197
|
-
rewardApr: spool?.
|
|
216
|
+
rewardApr: spool?.rewardApr ?? 0,
|
|
198
217
|
suppliedAmount: suppliedAmount.plus(stakedAmount).toNumber(),
|
|
199
218
|
suppliedCoin: suppliedCoin.plus(stakedCoin).toNumber(),
|
|
200
219
|
suppliedValue: suppliedValue.plus(stakedValue).toNumber(),
|
|
@@ -203,11 +222,21 @@ export const getLending = async (
|
|
|
203
222
|
stakedAmount: stakedAmount.toNumber(),
|
|
204
223
|
stakedCoin: stakedCoin.toNumber(),
|
|
205
224
|
stakedValue: stakedValue.toNumber(),
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
225
|
+
unstakedMarketAmount: unstakedMarketAmount.toNumber(),
|
|
226
|
+
unstakedMarketCoin: unstakedMarketCoin.toNumber(),
|
|
227
|
+
unstakedAmount: suppliedAmount.toNumber(),
|
|
228
|
+
unstakedCoin: suppliedCoin.toNumber(),
|
|
229
|
+
unstakedValue: suppliedValue.toNumber(),
|
|
230
|
+
availableSupplyAmount: availableSupplyAmount.toNumber(),
|
|
231
|
+
availableSupplyCoin: availableSupplyCoin.toNumber(),
|
|
232
|
+
availableWithdrawAmount: availableWithdrawAmount.toNumber(),
|
|
233
|
+
availableWithdrawCoin: availableWithdrawCoin.toNumber(),
|
|
234
|
+
availableStakeAmount: unstakedMarketAmount.toNumber(),
|
|
235
|
+
availableStakeCoin: unstakedMarketCoin.toNumber(),
|
|
209
236
|
availableUnstakeAmount: availableUnstakeAmount.toNumber(),
|
|
237
|
+
availableUnstakeCoin: availableUnstakeCoin.toNumber(),
|
|
210
238
|
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
239
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
211
240
|
};
|
|
212
241
|
|
|
213
242
|
return lending;
|
|
@@ -323,6 +352,8 @@ export const getObligationAccount = async (
|
|
|
323
352
|
coinName: collateralCoinName,
|
|
324
353
|
coinType: collateral.type.name,
|
|
325
354
|
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
355
|
+
coinDecimal: coinDecimal,
|
|
356
|
+
coinPrice: coinPrice,
|
|
326
357
|
depositedAmount: depositedAmount.toNumber(),
|
|
327
358
|
depositedCoin: depositedCoin.toNumber(),
|
|
328
359
|
depositedValue: depositedValue.toNumber(),
|
|
@@ -373,6 +404,8 @@ export const getObligationAccount = async (
|
|
|
373
404
|
coinName: poolCoinName,
|
|
374
405
|
coinType: debt.type.name,
|
|
375
406
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
407
|
+
coinDecimal: coinDecimal,
|
|
408
|
+
coinPrice: coinPrice,
|
|
376
409
|
borrowedAmount: borrowedAmount.toNumber(),
|
|
377
410
|
borrowedCoin: borrowedCoin.toNumber(),
|
|
378
411
|
borrowedValue: borrowedValue.toNumber(),
|
|
@@ -449,8 +482,8 @@ export const getObligationAccount = async (
|
|
|
449
482
|
if (marketCollateral) {
|
|
450
483
|
const availableWithdrawAmount =
|
|
451
484
|
obligationAccount.totalBorrowedValueWithWeight === 0
|
|
452
|
-
? obligationCollateral.depositedAmount
|
|
453
|
-
:
|
|
485
|
+
? BigNumber(obligationCollateral.depositedAmount)
|
|
486
|
+
: minBigNumber(
|
|
454
487
|
BigNumber(obligationAccount.totalAvailableCollateralValue)
|
|
455
488
|
.dividedBy(marketCollateral.collateralFactor)
|
|
456
489
|
.dividedBy(marketCollateral.coinPrice)
|
|
@@ -460,8 +493,11 @@ export const getObligationAccount = async (
|
|
|
460
493
|
obligationCollateral.depositedAmount,
|
|
461
494
|
marketCollateral.depositAmount
|
|
462
495
|
);
|
|
463
|
-
obligationCollateral.availableWithdrawAmount =
|
|
464
|
-
|
|
496
|
+
obligationCollateral.availableWithdrawAmount =
|
|
497
|
+
availableWithdrawAmount.toNumber();
|
|
498
|
+
obligationCollateral.availableWithdrawCoin = availableWithdrawAmount
|
|
499
|
+
.shiftedBy(-1 * obligationCollateral.coinDecimal)
|
|
500
|
+
.toNumber();
|
|
465
501
|
}
|
|
466
502
|
}
|
|
467
503
|
for (const [assetCoinName, obligationDebt] of Object.entries(
|
|
@@ -473,12 +509,11 @@ export const getObligationAccount = async (
|
|
|
473
509
|
obligationDebt.availableRepayAmount
|
|
474
510
|
)
|
|
475
511
|
// Note: reduced chance of failure when calculations are inaccurate
|
|
476
|
-
.multipliedBy(1.01)
|
|
477
|
-
.toNumber();
|
|
512
|
+
.multipliedBy(1.01);
|
|
478
513
|
|
|
479
514
|
const availableBorrowAmount =
|
|
480
515
|
obligationAccount.totalAvailableCollateralValue !== 0
|
|
481
|
-
?
|
|
516
|
+
? minBigNumber(
|
|
482
517
|
BigNumber(obligationAccount.totalAvailableCollateralValue)
|
|
483
518
|
.dividedBy(
|
|
484
519
|
BigNumber(marketPool.coinPrice).multipliedBy(
|
|
@@ -490,9 +525,15 @@ export const getObligationAccount = async (
|
|
|
490
525
|
.toNumber(),
|
|
491
526
|
marketPool.supplyAmount
|
|
492
527
|
)
|
|
493
|
-
: 0;
|
|
494
|
-
obligationDebt.availableBorrowAmount = availableBorrowAmount;
|
|
495
|
-
obligationDebt.
|
|
528
|
+
: BigNumber(0);
|
|
529
|
+
obligationDebt.availableBorrowAmount = availableBorrowAmount.toNumber();
|
|
530
|
+
obligationDebt.availableBorrowCoin = availableBorrowAmount
|
|
531
|
+
.shiftedBy(-1 * obligationDebt.coinDecimal)
|
|
532
|
+
.toNumber();
|
|
533
|
+
obligationDebt.availableRepayAmount = availableRepayAmount.toNumber();
|
|
534
|
+
obligationDebt.availableRepayCoin = availableRepayAmount
|
|
535
|
+
.shiftedBy(-1 * obligationDebt.coinDecimal)
|
|
536
|
+
.toNumber();
|
|
496
537
|
}
|
|
497
538
|
}
|
|
498
539
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
SuiTxBlock as SuiKitTxBlock,
|
|
3
|
+
SuiAddressArg,
|
|
4
|
+
SuiObjectArg,
|
|
3
5
|
SuiTxArg,
|
|
4
6
|
} from '@scallop-io/sui-kit';
|
|
7
|
+
import type { TransactionResult } from '@mysten/sui.js/transactions';
|
|
5
8
|
import type { ScallopBuilder } from '../../models';
|
|
6
9
|
import type {
|
|
7
10
|
SupportCollateralCoins,
|
|
8
11
|
SupportPoolCoins,
|
|
9
12
|
SupportAssetCoins,
|
|
10
13
|
} from '../constant';
|
|
11
|
-
import type { TransactionResult } from './index';
|
|
12
14
|
|
|
13
15
|
export type CoreIds = {
|
|
14
16
|
protocolPkg: string;
|
|
@@ -21,55 +23,58 @@ export type CoreIds = {
|
|
|
21
23
|
export type CoreNormalMethods = {
|
|
22
24
|
openObligation: () => TransactionResult;
|
|
23
25
|
returnObligation: (
|
|
24
|
-
obligation:
|
|
25
|
-
obligationHotPotato:
|
|
26
|
+
obligation: SuiAddressArg,
|
|
27
|
+
obligationHotPotato: SuiObjectArg
|
|
26
28
|
) => void;
|
|
27
29
|
openObligationEntry: () => void;
|
|
28
30
|
addCollateral: (
|
|
29
|
-
obligation:
|
|
30
|
-
coin:
|
|
31
|
+
obligation: SuiAddressArg,
|
|
32
|
+
coin: SuiObjectArg,
|
|
31
33
|
collateralCoinName: SupportCollateralCoins
|
|
32
34
|
) => void;
|
|
33
35
|
takeCollateral: (
|
|
34
|
-
obligation:
|
|
35
|
-
obligationKey:
|
|
36
|
-
amount:
|
|
36
|
+
obligation: SuiAddressArg,
|
|
37
|
+
obligationKey: SuiAddressArg,
|
|
38
|
+
amount: SuiTxArg,
|
|
37
39
|
collateralCoinName: SupportCollateralCoins
|
|
38
40
|
) => TransactionResult;
|
|
39
41
|
deposit: (
|
|
40
|
-
coin:
|
|
42
|
+
coin: SuiObjectArg,
|
|
41
43
|
poolCoinName: SupportPoolCoins
|
|
42
44
|
) => TransactionResult;
|
|
43
|
-
depositEntry: (coin:
|
|
45
|
+
depositEntry: (coin: SuiObjectArg, poolCoinName: SupportPoolCoins) => void;
|
|
44
46
|
withdraw: (
|
|
45
|
-
marketCoin:
|
|
47
|
+
marketCoin: SuiObjectArg,
|
|
46
48
|
poolCoinName: SupportPoolCoins
|
|
47
49
|
) => TransactionResult;
|
|
48
|
-
withdrawEntry: (
|
|
50
|
+
withdrawEntry: (
|
|
51
|
+
marketCoin: SuiObjectArg,
|
|
52
|
+
poolCoinName: SupportPoolCoins
|
|
53
|
+
) => void;
|
|
49
54
|
borrow: (
|
|
50
|
-
obligation:
|
|
51
|
-
obligationKey:
|
|
52
|
-
amount:
|
|
55
|
+
obligation: SuiAddressArg,
|
|
56
|
+
obligationKey: SuiAddressArg,
|
|
57
|
+
amount: SuiTxArg,
|
|
53
58
|
poolCoinName: SupportPoolCoins
|
|
54
59
|
) => TransactionResult;
|
|
55
60
|
borrowEntry: (
|
|
56
|
-
obligation:
|
|
57
|
-
obligationKey:
|
|
58
|
-
amount:
|
|
61
|
+
obligation: SuiAddressArg,
|
|
62
|
+
obligationKey: SuiAddressArg,
|
|
63
|
+
amount: SuiTxArg,
|
|
59
64
|
poolCoinName: SupportPoolCoins
|
|
60
65
|
) => void;
|
|
61
66
|
repay: (
|
|
62
|
-
obligation:
|
|
63
|
-
coin:
|
|
67
|
+
obligation: SuiAddressArg,
|
|
68
|
+
coin: SuiObjectArg,
|
|
64
69
|
poolCoinName: SupportPoolCoins
|
|
65
70
|
) => void;
|
|
66
71
|
borrowFlashLoan: (
|
|
67
|
-
amount:
|
|
72
|
+
amount: SuiTxArg,
|
|
68
73
|
poolCoinName: SupportPoolCoins
|
|
69
74
|
) => TransactionResult;
|
|
70
75
|
repayFlashLoan: (
|
|
71
|
-
coin:
|
|
72
|
-
loan:
|
|
76
|
+
coin: SuiObjectArg,
|
|
77
|
+
loan: SuiAddressArg,
|
|
73
78
|
poolCoinName: SupportPoolCoins
|
|
74
79
|
) => void;
|
|
75
80
|
};
|
|
@@ -78,19 +83,19 @@ export type CoreQuickMethods = {
|
|
|
78
83
|
addCollateralQuick: (
|
|
79
84
|
amount: number,
|
|
80
85
|
collateralCoinName: SupportCollateralCoins,
|
|
81
|
-
obligationId?:
|
|
86
|
+
obligationId?: SuiAddressArg
|
|
82
87
|
) => Promise<void>;
|
|
83
88
|
takeCollateralQuick: (
|
|
84
89
|
amount: number,
|
|
85
90
|
collateralCoinName: SupportCollateralCoins,
|
|
86
|
-
obligationId?:
|
|
87
|
-
obligationKey?:
|
|
91
|
+
obligationId?: SuiAddressArg,
|
|
92
|
+
obligationKey?: SuiAddressArg
|
|
88
93
|
) => Promise<TransactionResult>;
|
|
89
94
|
borrowQuick: (
|
|
90
95
|
amount: number,
|
|
91
96
|
poolCoinName: SupportPoolCoins,
|
|
92
|
-
obligationId?:
|
|
93
|
-
obligationKey?:
|
|
97
|
+
obligationId?: SuiAddressArg,
|
|
98
|
+
obligationKey?: SuiAddressArg
|
|
94
99
|
) => Promise<TransactionResult>;
|
|
95
100
|
depositQuick: (
|
|
96
101
|
amount: number,
|
|
@@ -103,7 +108,7 @@ export type CoreQuickMethods = {
|
|
|
103
108
|
repayQuick: (
|
|
104
109
|
amount: number,
|
|
105
110
|
poolCoinName: SupportPoolCoins,
|
|
106
|
-
obligationId?:
|
|
111
|
+
obligationId?: SuiAddressArg
|
|
107
112
|
) => Promise<void>;
|
|
108
113
|
updateAssetPricesQuick: (
|
|
109
114
|
assetCoinNames?: SupportAssetCoins[]
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { TransactionArgument } from '@mysten/sui.js/transactions';
|
|
2
1
|
import type { CoreTxBlock } from './core';
|
|
3
2
|
import type { SpoolTxBlock } from './spool';
|
|
4
3
|
|
|
@@ -6,4 +5,3 @@ export type * from './core';
|
|
|
6
5
|
export type * from './spool';
|
|
7
6
|
|
|
8
7
|
export type ScallopTxBlock = CoreTxBlock & SpoolTxBlock;
|
|
9
|
-
export type TransactionResult = TransactionArgument & TransactionArgument[];
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
SuiTxBlock as SuiKitTxBlock,
|
|
3
|
+
SuiAddressArg,
|
|
4
|
+
SuiObjectArg,
|
|
3
5
|
SuiTxArg,
|
|
4
6
|
} from '@scallop-io/sui-kit';
|
|
7
|
+
import type { TransactionResult } from '@mysten/sui.js/transactions';
|
|
5
8
|
import type { ScallopBuilder } from '../../models';
|
|
6
9
|
import type { SupportStakeMarketCoins } from '../constant';
|
|
7
|
-
import type { TransactionResult } from './index';
|
|
8
10
|
|
|
9
11
|
export type SpoolIds = {
|
|
10
12
|
spoolPkg: string;
|
|
@@ -15,41 +17,37 @@ export type SpoolNormalMethods = {
|
|
|
15
17
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
16
18
|
) => TransactionResult;
|
|
17
19
|
stake: (
|
|
18
|
-
stakeAccount:
|
|
19
|
-
coin:
|
|
20
|
+
stakeAccount: SuiAddressArg,
|
|
21
|
+
coin: SuiObjectArg,
|
|
20
22
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
21
23
|
) => void;
|
|
22
24
|
unstake: (
|
|
23
|
-
stakeAccount:
|
|
24
|
-
amount:
|
|
25
|
+
stakeAccount: SuiAddressArg,
|
|
26
|
+
amount: SuiTxArg,
|
|
25
27
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
26
28
|
) => TransactionResult;
|
|
27
29
|
claim: (
|
|
28
|
-
stakeAccount:
|
|
30
|
+
stakeAccount: SuiAddressArg,
|
|
29
31
|
stakeMarketCoinName: SupportStakeMarketCoins
|
|
30
32
|
) => TransactionResult;
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
export type SpoolQuickMethods = {
|
|
34
36
|
stakeQuick(
|
|
35
|
-
amountOrMarketCoin: number,
|
|
37
|
+
amountOrMarketCoin: SuiObjectArg | number,
|
|
36
38
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
37
|
-
stakeAccountId?:
|
|
38
|
-
): Promise<void>;
|
|
39
|
-
stakeQuick(
|
|
40
|
-
amountOrMarketCoin: TransactionResult,
|
|
41
|
-
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
42
|
-
stakeAccountId?: SuiTxArg
|
|
39
|
+
stakeAccountId?: SuiAddressArg
|
|
43
40
|
): Promise<void>;
|
|
41
|
+
|
|
44
42
|
unstakeQuick(
|
|
45
43
|
amount: number,
|
|
46
44
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
47
|
-
stakeAccountId?:
|
|
48
|
-
): Promise<TransactionResult>;
|
|
45
|
+
stakeAccountId?: SuiAddressArg
|
|
46
|
+
): Promise<TransactionResult[]>;
|
|
49
47
|
claimQuick(
|
|
50
48
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
51
|
-
stakeAccountId?:
|
|
52
|
-
): Promise<TransactionResult>;
|
|
49
|
+
stakeAccountId?: SuiAddressArg
|
|
50
|
+
): Promise<TransactionResult[]>;
|
|
53
51
|
};
|
|
54
52
|
|
|
55
53
|
export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock &
|
|
@@ -25,3 +25,16 @@ export type StakeMarketCoins = {
|
|
|
25
25
|
export type RewardCoins = {
|
|
26
26
|
[key in SupportStakeMarketCoins]: SupportRewardCoins;
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export type AssetCoinIds = {
|
|
30
|
+
[key in SupportAssetCoins]: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type PickFromUnion<T, K extends string> = K extends T ? K : never;
|
|
34
|
+
|
|
35
|
+
export type WormholeCoinIds = {
|
|
36
|
+
[key in PickFromUnion<
|
|
37
|
+
SupportAssetCoins,
|
|
38
|
+
'eth' | 'btc' | 'usdc' | 'usdt' | 'apt' | 'sol'
|
|
39
|
+
>]: string;
|
|
40
|
+
};
|