@scallop-io/sui-scallop-sdk 1.3.4-alpha.6 → 1.3.4-hotfix
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/builders/borrowIncentiveBuilder.d.ts +12 -0
- package/dist/builders/coreBuilder.d.ts +12 -0
- package/dist/builders/index.d.ts +12 -0
- package/dist/builders/loyaltyProgramBuilder.d.ts +12 -0
- package/dist/builders/oracle.d.ts +14 -0
- package/dist/builders/referralBuilder.d.ts +12 -0
- package/dist/builders/sCoinBuilder.d.ts +4 -0
- package/dist/builders/spoolBuilder.d.ts +12 -0
- package/dist/builders/vescaBuilder.d.ts +25 -0
- package/dist/constants/cache.d.ts +14 -0
- package/dist/constants/common.d.ts +20 -0
- package/dist/constants/enum.d.ts +13 -0
- package/dist/constants/flashloan.d.ts +2 -0
- package/dist/constants/index.d.ts +5 -0
- package/dist/constants/pyth.d.ts +3 -0
- package/dist/constants/queryKeys.d.ts +58 -0
- package/dist/constants/testAddress.d.ts +2 -0
- package/dist/constants/tokenBucket.d.ts +2 -0
- package/dist/constants/vesca.d.ts +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2317 -2481
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2316 -2470
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.ts +8 -0
- package/dist/models/scallop.d.ts +74 -0
- package/dist/models/scallopAddress.d.ts +150 -0
- package/dist/models/scallopBuilder.d.ts +89 -0
- package/dist/models/scallopCache.d.ts +74 -0
- package/dist/models/scallopClient.d.ts +321 -0
- package/dist/models/scallopIndexer.d.ts +89 -0
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +474 -0
- package/dist/models/scallopUtils.d.ts +217 -0
- package/dist/queries/borrowIncentiveQuery.d.ts +61 -0
- package/dist/queries/coreQuery.d.ts +167 -0
- package/dist/queries/index.d.ts +8 -0
- package/dist/queries/isolatedAsset.d.ts +14 -0
- package/dist/queries/loyaltyProgramQuery.d.ts +10 -0
- package/dist/queries/portfolioQuery.d.ts +73 -0
- package/dist/queries/priceQuery.d.ts +16 -0
- package/dist/queries/referralQuery.d.ts +7 -0
- package/dist/queries/sCoinQuery.d.ts +41 -0
- package/dist/queries/spoolQuery.d.ts +70 -0
- package/dist/queries/supplyLimit.d.ts +9 -0
- package/dist/queries/vescaQuery.d.ts +36 -0
- package/dist/types/address.d.ts +107 -0
- package/dist/types/builder/borrowIncentive.d.ts +35 -0
- package/dist/types/builder/core.d.ts +56 -0
- package/dist/types/builder/index.d.ts +24 -0
- package/dist/types/builder/loyaltyProgram.d.ts +23 -0
- package/dist/types/builder/referral.d.ts +30 -0
- package/dist/types/builder/sCoin.d.ts +37 -0
- package/dist/types/builder/spool.d.ts +29 -0
- package/dist/types/builder/vesca.d.ts +51 -0
- package/dist/types/constant/common.d.ts +24 -0
- package/dist/types/constant/enum.d.ts +48 -0
- package/dist/types/constant/index.d.ts +2 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/model.d.ts +54 -0
- package/dist/types/query/borrowIncentive.d.ts +124 -0
- package/dist/types/query/core.d.ts +361 -0
- package/dist/types/query/index.d.ts +7 -0
- package/dist/types/query/loyaltyProgram.d.ts +5 -0
- package/dist/types/query/portfolio.d.ts +115 -0
- package/dist/types/query/sCoin.d.ts +1 -0
- package/dist/types/query/spool.d.ts +122 -0
- package/dist/types/query/vesca.d.ts +26 -0
- package/dist/types/utils.d.ts +9 -0
- package/dist/utils/builder.d.ts +15 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/indexer.d.ts +17 -0
- package/dist/utils/query.d.ts +62 -0
- package/dist/utils/tokenBucket.d.ts +11 -0
- package/dist/utils/util.d.ts +26 -0
- package/package.json +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +1 -1
- package/src/constants/common.ts +2 -1
- package/src/constants/enum.ts +0 -8
- package/src/constants/index.ts +0 -7
- package/src/constants/pyth.ts +0 -19
- package/src/constants/queryKeys.ts +5 -1
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallop.ts +2 -3
- package/src/models/scallopAddress.ts +2 -2
- package/src/models/scallopBuilder.ts +3 -4
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +26 -27
- package/src/models/scallopPrice.ts +0 -0
- package/src/models/scallopQuery.ts +17 -63
- package/src/models/scallopUtils.ts +96 -96
- package/src/queries/borrowIncentiveQuery.ts +13 -6
- package/src/queries/coreQuery.ts +23 -38
- package/src/queries/index.ts +5 -8
- package/src/queries/{isolatedAssetQuery.ts → isolatedAsset.ts} +2 -2
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +34 -55
- package/src/queries/spoolQuery.ts +17 -17
- package/src/queries/{supplyLimitQuery.ts → supplyLimit.ts} +2 -2
- package/src/types/query/index.ts +4 -4
- package/src/types/utils.ts +0 -13
- package/src/utils/tokenBucket.ts +1 -2
- package/src/utils/util.ts +1 -2
- package/src/constants/coinGecko.ts +0 -18
- package/src/constants/poolAddress.ts +0 -94
- package/src/constants/rpc.ts +0 -16
- package/src/models/suiKit.ts +0 -11
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import type { ScallopUtils } from '../models';
|
|
3
|
+
import type { OriginMarketPoolData, ParsedMarketPoolData, CalculatedMarketPoolData, OriginMarketCollateralData, ParsedMarketCollateralData, CalculatedMarketCollateralData, OriginSpoolData, ParsedSpoolData, CalculatedSpoolData, OriginSpoolRewardPoolData, ParsedSpoolRewardPoolData, CalculatedSpoolRewardPoolData, OriginBorrowIncentivePoolData, ParsedBorrowIncentivePoolData, OriginBorrowIncentiveAccountData, ParsedBorrowIncentiveAccountData, OriginBorrowIncentivePoolPointData, ParsedBorrowIncentivePoolPointData, CalculatedBorrowIncentivePoolPointData, OriginBorrowIncentiveAccountPoolData, ParsedBorrowIncentiveAccountPoolData } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Parse origin market pool data to a more readable format.
|
|
6
|
+
*
|
|
7
|
+
* @param originMarketPoolData - Origin market pool data
|
|
8
|
+
* @return Parsed market pool data
|
|
9
|
+
*/
|
|
10
|
+
export declare const parseOriginMarketPoolData: (originMarketPoolData: OriginMarketPoolData) => ParsedMarketPoolData;
|
|
11
|
+
export declare const calculateMarketPoolData: (utils: ScallopUtils, parsedMarketPoolData: ParsedMarketPoolData) => CalculatedMarketPoolData;
|
|
12
|
+
/**
|
|
13
|
+
* Parse origin market collateral data to a more readable format.
|
|
14
|
+
*
|
|
15
|
+
* @param originMarketCollateralData - Origin market collateral data
|
|
16
|
+
* @return Parsed market collateral data
|
|
17
|
+
*/
|
|
18
|
+
export declare const parseOriginMarketCollateralData: (originMarketCollateralData: OriginMarketCollateralData) => ParsedMarketCollateralData;
|
|
19
|
+
export declare const calculateMarketCollateralData: (utils: ScallopUtils, parsedMarketCollateralData: ParsedMarketCollateralData) => CalculatedMarketCollateralData;
|
|
20
|
+
/**
|
|
21
|
+
* Parse origin spool data to a more readable format.
|
|
22
|
+
*
|
|
23
|
+
* @param originSpoolData - Origin spool data
|
|
24
|
+
* @return Parsed spool data
|
|
25
|
+
*/
|
|
26
|
+
export declare const parseOriginSpoolData: (originSpoolData: OriginSpoolData) => ParsedSpoolData;
|
|
27
|
+
export declare const calculateSpoolData: (parsedSpoolData: ParsedSpoolData, stakeMarketCoinPrice: number, stakeMarketCoinDecimal: number) => CalculatedSpoolData;
|
|
28
|
+
/**
|
|
29
|
+
* Parse origin spool reward pool data to a more readable format.
|
|
30
|
+
*
|
|
31
|
+
* @param originRewardPoolData - Origin reward pool data
|
|
32
|
+
* @return Parsed spool reward pool data
|
|
33
|
+
*/
|
|
34
|
+
export declare const parseOriginSpoolRewardPoolData: (originSpoolRewardPoolData: OriginSpoolRewardPoolData) => ParsedSpoolRewardPoolData;
|
|
35
|
+
export declare const calculateSpoolRewardPoolData: (parsedSpoolData: ParsedSpoolData, parsedSpoolRewardPoolData: ParsedSpoolRewardPoolData, calculatedSpoolData: CalculatedSpoolData, rewardCoinPrice: number, rewardCoinDecimal: number) => CalculatedSpoolRewardPoolData;
|
|
36
|
+
export declare const parseOriginBorrowIncentivesPoolPointData: (originBorrowIncentivePoolPointData: OriginBorrowIncentivePoolPointData) => ParsedBorrowIncentivePoolPointData;
|
|
37
|
+
/**
|
|
38
|
+
* Parse origin borrow incentive pool data to a more readable format.
|
|
39
|
+
*
|
|
40
|
+
* @param originBorrowIncentivePoolData - Origin borrow incentive pool data
|
|
41
|
+
* @return Parsed borrow incentive pool data
|
|
42
|
+
*/
|
|
43
|
+
export declare const parseOriginBorrowIncentivePoolData: (originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
44
|
+
export declare const calculateBorrowIncentivePoolPointData: (parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData, rewardCoinPrice: number, rewardCoinDecimal: number, poolCoinPrice: number, poolCoinDecimal: number) => CalculatedBorrowIncentivePoolPointData;
|
|
45
|
+
export declare const parseOriginBorrowIncentiveAccountPoolPointData: (originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData) => ParsedBorrowIncentiveAccountPoolData;
|
|
46
|
+
/**
|
|
47
|
+
* Parse origin borrow incentive account data to a more readable format.
|
|
48
|
+
*
|
|
49
|
+
* @param originBorrowIncentiveAccountData - Origin borrow incentive account data
|
|
50
|
+
* @return Parsed borrow incentive account data
|
|
51
|
+
*/
|
|
52
|
+
export declare const parseOriginBorrowIncentiveAccountData: (originBorrowIncentiveAccountData: OriginBorrowIncentiveAccountData) => ParsedBorrowIncentiveAccountData;
|
|
53
|
+
export declare const minBigNumber: (...args: BigNumber.Value[]) => BigNumber;
|
|
54
|
+
export declare const maxBigNumber: (...args: BigNumber.Value[]) => BigNumber;
|
|
55
|
+
/**
|
|
56
|
+
* Dynamically adjust the decrease or increase ratio according to the amount
|
|
57
|
+
* @param amount - The amount required to calculate factor.
|
|
58
|
+
* @param scaleStep - The scale step required to determine the factor..
|
|
59
|
+
* @param type - The type of the calculation.
|
|
60
|
+
* @return The estimated factor
|
|
61
|
+
* */
|
|
62
|
+
export declare const estimatedFactor: (amount: number, scaleStep: number, type: "increase" | "decrease") => number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class TokenBucket {
|
|
2
|
+
private tokensPerInterval;
|
|
3
|
+
private interval;
|
|
4
|
+
private tokens;
|
|
5
|
+
private lastRefill;
|
|
6
|
+
constructor(tokensPerInterval: number, intervalInMs: number);
|
|
7
|
+
refill(): void;
|
|
8
|
+
removeTokens(count: number): boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const callWithRateLimit: <T>(tokenBucket: TokenBucket, fn: () => Promise<T>, retryDelayInMs?: number, maxRetries?: number, backoffFactor?: number) => Promise<T | null>;
|
|
11
|
+
export { TokenBucket, callWithRateLimit };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PriceFeed } from '@pythnetwork/pyth-sui-js';
|
|
2
|
+
import type { ScallopAddress } from '../models';
|
|
3
|
+
import type { SupportAssetCoins, SupportCoins, SupportMarketCoins, SupportSuiBridgeCoins, SupportWormholeCoins } from '../types';
|
|
4
|
+
export declare const isMarketCoin: (coinName: SupportCoins) => coinName is SupportMarketCoins;
|
|
5
|
+
export declare const isSuiBridgeAsset: (coinName: any) => coinName is SupportSuiBridgeCoins;
|
|
6
|
+
export declare const isWormholeAsset: (coinName: any) => coinName is SupportWormholeCoins;
|
|
7
|
+
export declare const parseAssetSymbol: (coinName: SupportCoins) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Parse price from pyth price feed.
|
|
10
|
+
*
|
|
11
|
+
* @param feed - Price feed object from pyth.
|
|
12
|
+
* @param address - Scallop address instance.
|
|
13
|
+
* @return Price Data inclue coin name, price, and publish time.
|
|
14
|
+
*/
|
|
15
|
+
export declare const parseDataFromPythPriceFeed: (feed: PriceFeed, address: ScallopAddress) => {
|
|
16
|
+
coinName: SupportAssetCoins;
|
|
17
|
+
price: number;
|
|
18
|
+
publishTime: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Find the closest unlock round timestamp (12AM) to the given unlock at timestamp in seconds.
|
|
22
|
+
*
|
|
23
|
+
* @param unlockAtInSecondTimestamp - Unlock at in seconds timestamp to find the closest round.
|
|
24
|
+
* @returns Closest round (12AM) in seconds timestamp.
|
|
25
|
+
*/
|
|
26
|
+
export declare const findClosestUnlockRound: (unlockAtInSecondTimestamp: number) => number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scallop-io/sui-scallop-sdk",
|
|
3
|
-
"version": "1.3.4-
|
|
3
|
+
"version": "1.3.4-hotfix",
|
|
4
4
|
"description": "Typescript sdk for interacting with Scallop contract on SUI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"scripts": {
|
|
150
150
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
151
151
|
"build": "pnpm run build:types && pnpm run build:tsup",
|
|
152
|
-
"build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap
|
|
152
|
+
"build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap",
|
|
153
153
|
"build:types": "tsc --build",
|
|
154
154
|
"watch:tsup": "tsup ./src/index.ts --format esm,cjs --clean --splitting --watch",
|
|
155
155
|
"watch:types": "tsc --watch",
|
|
@@ -38,7 +38,7 @@ const generateLoyaltyProgramQuickMethod: GenerateLoyaltyProgramQuickMethod = ({
|
|
|
38
38
|
}) => {
|
|
39
39
|
return {
|
|
40
40
|
claimLoyaltyRevenueQuick: async (veScaKey) => {
|
|
41
|
-
veScaKey = veScaKey
|
|
41
|
+
veScaKey = veScaKey || (await builder.query.getVeScas())[0]?.keyObject;
|
|
42
42
|
const sender = requireSender(txBlock);
|
|
43
43
|
if (!veScaKey) throw new Error(`No veScaKey found for user ${sender}`);
|
|
44
44
|
|
package/src/constants/common.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// export const API_BASE_URL = 'https://sui.api.scallop.io';
|
|
1
2
|
export const API_BASE_URL = 'https://sui.apis.scallop.io' as const;
|
|
2
3
|
export const SDK_API_BASE_URL = 'https://sdk.api.scallop.io' as const;
|
|
3
4
|
|
|
@@ -7,7 +8,7 @@ export const USE_TEST_ADDRESS: boolean = false;
|
|
|
7
8
|
export const ADDRESSES_ID =
|
|
8
9
|
IS_VE_SCA_TEST || USE_TEST_ADDRESS
|
|
9
10
|
? ('65fb07c39c845425d71d7b18' as const)
|
|
10
|
-
: ('
|
|
11
|
+
: ('675c65cd301dd817ea262e76' as const);
|
|
11
12
|
// : ('664dfe22898c36c159e28bc8' as const);
|
|
12
13
|
|
|
13
14
|
export const PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST
|
package/src/constants/enum.ts
CHANGED
|
@@ -183,14 +183,6 @@ export const sCoinIds: types.SCoinIds = {
|
|
|
183
183
|
'0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC',
|
|
184
184
|
} as const;
|
|
185
185
|
|
|
186
|
-
export const sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
187
|
-
(acc, [coinName, coinType]) => {
|
|
188
|
-
acc[coinType] = coinName as types.SupportSCoin;
|
|
189
|
-
return acc;
|
|
190
|
-
},
|
|
191
|
-
{} as Record<string, types.SupportSCoin>
|
|
192
|
-
);
|
|
193
|
-
|
|
194
186
|
// TEST VERSION
|
|
195
187
|
// export const sCoinIds: types.SCoinIds = {
|
|
196
188
|
// ssui: '0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI',
|
package/src/constants/index.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
export * from './cache';
|
|
2
|
-
export * from './coinGecko';
|
|
3
1
|
export * from './common';
|
|
4
2
|
export * from './enum';
|
|
5
3
|
export * from './flashloan';
|
|
6
|
-
export * from './poolAddress';
|
|
7
|
-
export * from './pyth';
|
|
8
4
|
export * from './queryKeys';
|
|
9
|
-
export * from './rpc';
|
|
10
|
-
export * from './testAddress';
|
|
11
|
-
export * from './tokenBucket';
|
|
12
5
|
export * from './vesca';
|
package/src/constants/pyth.ts
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import { SupportPoolCoins } from 'src/types';
|
|
2
|
-
|
|
3
1
|
export const PYTH_ENDPOINTS: {
|
|
4
2
|
[k in 'mainnet' | 'testnet']: string[];
|
|
5
3
|
} = {
|
|
6
4
|
testnet: ['https://hermes-beta.pyth.network'],
|
|
7
5
|
mainnet: ['https://hermes.pyth.network', 'https://scallop.rpc.p2p.world'],
|
|
8
6
|
};
|
|
9
|
-
|
|
10
|
-
export const PYTH_FEED_IDS: Record<SupportPoolCoins, string> = {
|
|
11
|
-
usdc: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
|
|
12
|
-
sbeth: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
|
|
13
|
-
weth: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
|
|
14
|
-
wbtc: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
|
|
15
|
-
wusdc: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
|
|
16
|
-
wusdt: '2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b',
|
|
17
|
-
sui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
18
|
-
wapt: '03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5',
|
|
19
|
-
wsol: 'ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
|
|
20
|
-
cetus: 'e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef',
|
|
21
|
-
afsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
22
|
-
hasui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
23
|
-
vsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
24
|
-
sca: '7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc',
|
|
25
|
-
};
|
|
@@ -99,6 +99,10 @@ export const queryKeys = {
|
|
|
99
99
|
],
|
|
100
100
|
},
|
|
101
101
|
oracle: {
|
|
102
|
-
|
|
102
|
+
getPythLatestPriceFeed: (pythPriceId?: string) => [
|
|
103
|
+
'oracle',
|
|
104
|
+
'getPythPriceId',
|
|
105
|
+
{ pythPriceId },
|
|
106
|
+
],
|
|
103
107
|
},
|
|
104
108
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const DEFAULT_TOKENS_PER_INTERVAL =
|
|
1
|
+
export const DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
2
2
|
export const DEFAULT_INTERVAL_IN_MS = 300;
|
package/src/models/scallop.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
DEFAULT_TOKENS_PER_INTERVAL,
|
|
23
23
|
} from 'src/constants/tokenBucket';
|
|
24
24
|
import type { QueryClient } from '@tanstack/query-core';
|
|
25
|
-
import { newSuiKit } from './suiKit';
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* @argument params - The parameters for the Scallop instance.
|
|
@@ -55,7 +54,7 @@ export class Scallop {
|
|
|
55
54
|
queryClient?: QueryClient
|
|
56
55
|
) {
|
|
57
56
|
this.params = params;
|
|
58
|
-
this.suiKit =
|
|
57
|
+
this.suiKit = new SuiKit(params);
|
|
59
58
|
this.cache = new ScallopCache(
|
|
60
59
|
this.suiKit,
|
|
61
60
|
params.walletAddress,
|
|
@@ -66,7 +65,7 @@ export class Scallop {
|
|
|
66
65
|
);
|
|
67
66
|
this.address = new ScallopAddress(
|
|
68
67
|
{
|
|
69
|
-
id: params?.addressesId
|
|
68
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
70
69
|
network: params?.networkType,
|
|
71
70
|
forceInterface: params?.forceAddressesInterface,
|
|
72
71
|
},
|
|
@@ -393,11 +393,11 @@ export class ScallopAddress {
|
|
|
393
393
|
'Content-Type': 'application/json',
|
|
394
394
|
Accept: 'application/json',
|
|
395
395
|
},
|
|
396
|
-
timeout:
|
|
396
|
+
timeout: 30000,
|
|
397
397
|
});
|
|
398
398
|
if (auth) this._auth = auth;
|
|
399
399
|
this._id = id;
|
|
400
|
-
this._network = network
|
|
400
|
+
this._network = network || 'mainnet';
|
|
401
401
|
this._addressesMap = USE_TEST_ADDRESS
|
|
402
402
|
? new Map([['mainnet', TEST_ADDRESSES]])
|
|
403
403
|
: new Map();
|
|
@@ -19,7 +19,6 @@ import type {
|
|
|
19
19
|
} from '../types';
|
|
20
20
|
import { ScallopCache } from './scallopCache';
|
|
21
21
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
22
|
-
import { newSuiKit } from './suiKit';
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* @description
|
|
@@ -47,11 +46,11 @@ export class ScallopBuilder {
|
|
|
47
46
|
params: ScallopBuilderParams,
|
|
48
47
|
instance?: ScallopBuilderInstanceParams
|
|
49
48
|
) {
|
|
50
|
-
this.suiKit = instance?.suiKit ??
|
|
49
|
+
this.suiKit = instance?.suiKit ?? new SuiKit(params);
|
|
51
50
|
|
|
52
51
|
this.params = params;
|
|
53
52
|
this.walletAddress = normalizeSuiAddress(
|
|
54
|
-
params?.walletAddress
|
|
53
|
+
params?.walletAddress || this.suiKit.currentAddress()
|
|
55
54
|
);
|
|
56
55
|
|
|
57
56
|
if (instance?.query) {
|
|
@@ -67,7 +66,7 @@ export class ScallopBuilder {
|
|
|
67
66
|
);
|
|
68
67
|
this.address = new ScallopAddress(
|
|
69
68
|
{
|
|
70
|
-
id: params?.addressesId
|
|
69
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
71
70
|
network: params?.networkType,
|
|
72
71
|
forceInterface: params?.forceAddressesInterface,
|
|
73
72
|
},
|
|
@@ -255,7 +255,7 @@ export class ScallopCache {
|
|
|
255
255
|
if (!input.coinType) return '0';
|
|
256
256
|
|
|
257
257
|
return (
|
|
258
|
-
((await this.queryGetAllCoinBalances(input.owner))
|
|
258
|
+
((await this.queryGetAllCoinBalances(input.owner)) || {})[
|
|
259
259
|
normalizeStructTag(input.coinType)
|
|
260
260
|
] ?? '0'
|
|
261
261
|
);
|
|
@@ -34,7 +34,6 @@ import type {
|
|
|
34
34
|
ScallopClientVeScaReturnType,
|
|
35
35
|
ScallopClientInstanceParams,
|
|
36
36
|
} from '../types';
|
|
37
|
-
import { newSuiKit } from './suiKit';
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* @description
|
|
@@ -65,9 +64,9 @@ export class ScallopClient {
|
|
|
65
64
|
) {
|
|
66
65
|
this.params = params;
|
|
67
66
|
this.suiKit =
|
|
68
|
-
instance?.suiKit ?? instance?.builder?.suiKit ??
|
|
67
|
+
instance?.suiKit ?? instance?.builder?.suiKit ?? new SuiKit(params);
|
|
69
68
|
this.walletAddress = normalizeSuiAddress(
|
|
70
|
-
params?.walletAddress
|
|
69
|
+
params?.walletAddress || this.suiKit.currentAddress()
|
|
71
70
|
);
|
|
72
71
|
|
|
73
72
|
if (instance?.builder) {
|
|
@@ -84,7 +83,7 @@ export class ScallopClient {
|
|
|
84
83
|
);
|
|
85
84
|
this.address = new ScallopAddress(
|
|
86
85
|
{
|
|
87
|
-
id: params?.addressesId
|
|
86
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
88
87
|
network: params?.networkType,
|
|
89
88
|
forceInterface: params?.forceAddressesInterface,
|
|
90
89
|
},
|
|
@@ -143,7 +142,7 @@ export class ScallopClient {
|
|
|
143
142
|
* @return Obligations data.
|
|
144
143
|
*/
|
|
145
144
|
public async getObligations(ownerAddress?: string) {
|
|
146
|
-
const owner = ownerAddress
|
|
145
|
+
const owner = ownerAddress || this.walletAddress;
|
|
147
146
|
return await this.query.getObligations(owner);
|
|
148
147
|
}
|
|
149
148
|
|
|
@@ -170,7 +169,7 @@ export class ScallopClient {
|
|
|
170
169
|
* @return All stake accounts data.
|
|
171
170
|
*/
|
|
172
171
|
async getAllStakeAccounts(ownerAddress?: string) {
|
|
173
|
-
const owner = ownerAddress
|
|
172
|
+
const owner = ownerAddress || this.walletAddress;
|
|
174
173
|
return await this.query.getAllStakeAccounts(owner);
|
|
175
174
|
}
|
|
176
175
|
|
|
@@ -188,7 +187,7 @@ export class ScallopClient {
|
|
|
188
187
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
189
188
|
ownerAddress?: string
|
|
190
189
|
) {
|
|
191
|
-
const owner = ownerAddress
|
|
190
|
+
const owner = ownerAddress || this.walletAddress;
|
|
192
191
|
return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
|
|
193
192
|
}
|
|
194
193
|
|
|
@@ -273,11 +272,11 @@ export class ScallopClient {
|
|
|
273
272
|
walletAddress?: string
|
|
274
273
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
275
274
|
const txBlock = this.builder.createTxBlock();
|
|
276
|
-
const sender = walletAddress
|
|
275
|
+
const sender = walletAddress || this.walletAddress;
|
|
277
276
|
txBlock.setSender(sender);
|
|
278
277
|
|
|
279
278
|
const obligations = await this.query.getObligations(sender);
|
|
280
|
-
const specificObligationId = obligationId
|
|
279
|
+
const specificObligationId = obligationId || obligations[0]?.id;
|
|
281
280
|
if (specificObligationId) {
|
|
282
281
|
await txBlock.addCollateralQuick(
|
|
283
282
|
amount,
|
|
@@ -320,7 +319,7 @@ export class ScallopClient {
|
|
|
320
319
|
walletAddress?: string
|
|
321
320
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
322
321
|
const txBlock = this.builder.createTxBlock();
|
|
323
|
-
const sender = walletAddress
|
|
322
|
+
const sender = walletAddress || this.walletAddress;
|
|
324
323
|
txBlock.setSender(sender);
|
|
325
324
|
|
|
326
325
|
const collateralCoin = await txBlock.takeCollateralQuick(
|
|
@@ -366,7 +365,7 @@ export class ScallopClient {
|
|
|
366
365
|
walletAddress?: string
|
|
367
366
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
368
367
|
const txBlock = this.builder.createTxBlock();
|
|
369
|
-
const sender = walletAddress
|
|
368
|
+
const sender = walletAddress || this.walletAddress;
|
|
370
369
|
txBlock.setSender(sender);
|
|
371
370
|
|
|
372
371
|
const sCoin = await txBlock.depositQuick(amount, poolCoinName);
|
|
@@ -410,14 +409,14 @@ export class ScallopClient {
|
|
|
410
409
|
walletAddress?: string
|
|
411
410
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
412
411
|
const txBlock = this.builder.createTxBlock();
|
|
413
|
-
const sender = walletAddress
|
|
412
|
+
const sender = walletAddress || this.walletAddress;
|
|
414
413
|
txBlock.setSender(sender);
|
|
415
414
|
|
|
416
415
|
const stakeMarketCoinName =
|
|
417
416
|
this.utils.parseMarketCoinName<SupportStakeMarketCoins>(stakeCoinName);
|
|
418
417
|
const stakeAccounts =
|
|
419
418
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
420
|
-
const targetStakeAccount = stakeAccountId
|
|
419
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
421
420
|
|
|
422
421
|
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
423
422
|
if (targetStakeAccount) {
|
|
@@ -467,7 +466,7 @@ export class ScallopClient {
|
|
|
467
466
|
walletAddress?: string
|
|
468
467
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
469
468
|
const txBlock = this.builder.createTxBlock();
|
|
470
|
-
const sender = walletAddress
|
|
469
|
+
const sender = walletAddress || this.walletAddress;
|
|
471
470
|
txBlock.setSender(sender);
|
|
472
471
|
|
|
473
472
|
const coin = await txBlock.withdrawQuick(amount, poolCoinName);
|
|
@@ -502,7 +501,7 @@ export class ScallopClient {
|
|
|
502
501
|
walletAddress?: string
|
|
503
502
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
504
503
|
const txBlock = this.builder.createTxBlock();
|
|
505
|
-
const sender = walletAddress
|
|
504
|
+
const sender = walletAddress || this.walletAddress;
|
|
506
505
|
txBlock.setSender(sender);
|
|
507
506
|
|
|
508
507
|
const availableStake = (
|
|
@@ -550,7 +549,7 @@ export class ScallopClient {
|
|
|
550
549
|
walletAddress?: string
|
|
551
550
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
552
551
|
const txBlock = this.builder.createTxBlock();
|
|
553
|
-
const sender = walletAddress
|
|
552
|
+
const sender = walletAddress || this.walletAddress;
|
|
554
553
|
txBlock.setSender(sender);
|
|
555
554
|
|
|
556
555
|
const availableStake = (
|
|
@@ -611,7 +610,7 @@ export class ScallopClient {
|
|
|
611
610
|
walletAddress?: string
|
|
612
611
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
613
612
|
const txBlock = this.builder.createTxBlock();
|
|
614
|
-
const sender = walletAddress
|
|
613
|
+
const sender = walletAddress || this.walletAddress;
|
|
615
614
|
txBlock.setSender(sender);
|
|
616
615
|
const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
|
|
617
616
|
txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
|
|
@@ -648,7 +647,7 @@ export class ScallopClient {
|
|
|
648
647
|
walletAddress?: string
|
|
649
648
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
650
649
|
const txBlock = this.builder.createTxBlock();
|
|
651
|
-
const sender = walletAddress
|
|
650
|
+
const sender = walletAddress || this.walletAddress;
|
|
652
651
|
txBlock.setSender(sender);
|
|
653
652
|
|
|
654
653
|
const stakeAccount = txBlock.createStakeAccount(marketCoinName);
|
|
@@ -692,12 +691,12 @@ export class ScallopClient {
|
|
|
692
691
|
walletAddress?: string
|
|
693
692
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
694
693
|
const txBlock = this.builder.createTxBlock();
|
|
695
|
-
const sender = walletAddress
|
|
694
|
+
const sender = walletAddress || this.walletAddress;
|
|
696
695
|
txBlock.setSender(sender);
|
|
697
696
|
|
|
698
697
|
const stakeAccounts =
|
|
699
698
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
700
|
-
const targetStakeAccount = stakeAccountId
|
|
699
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
701
700
|
if (targetStakeAccount) {
|
|
702
701
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
703
702
|
} else {
|
|
@@ -744,7 +743,7 @@ export class ScallopClient {
|
|
|
744
743
|
walletAddress?: string
|
|
745
744
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
746
745
|
const txBlock = this.builder.createTxBlock();
|
|
747
|
-
const sender = walletAddress
|
|
746
|
+
const sender = walletAddress || this.walletAddress;
|
|
748
747
|
txBlock.setSender(sender);
|
|
749
748
|
|
|
750
749
|
const sCoin = await txBlock.unstakeQuick(
|
|
@@ -803,7 +802,7 @@ export class ScallopClient {
|
|
|
803
802
|
walletAddress?: string
|
|
804
803
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
805
804
|
const txBlock = this.builder.createTxBlock();
|
|
806
|
-
const sender = walletAddress
|
|
805
|
+
const sender = walletAddress || this.walletAddress;
|
|
807
806
|
txBlock.setSender(sender);
|
|
808
807
|
|
|
809
808
|
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
@@ -864,7 +863,7 @@ export class ScallopClient {
|
|
|
864
863
|
walletAddress?: string
|
|
865
864
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
866
865
|
const txBlock = this.builder.createTxBlock();
|
|
867
|
-
const sender = walletAddress
|
|
866
|
+
const sender = walletAddress || this.walletAddress;
|
|
868
867
|
txBlock.setSender(sender);
|
|
869
868
|
|
|
870
869
|
const rewardCoins = await txBlock.claimQuick(
|
|
@@ -900,7 +899,7 @@ export class ScallopClient {
|
|
|
900
899
|
walletAddress?: string
|
|
901
900
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
902
901
|
const txBlock = this.builder.createTxBlock();
|
|
903
|
-
const sender = walletAddress
|
|
902
|
+
const sender = walletAddress || this.walletAddress;
|
|
904
903
|
txBlock.setSender(sender);
|
|
905
904
|
|
|
906
905
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
|
|
@@ -930,7 +929,7 @@ export class ScallopClient {
|
|
|
930
929
|
walletAddress?: string
|
|
931
930
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
932
931
|
const txBlock = this.builder.createTxBlock();
|
|
933
|
-
const sender = walletAddress
|
|
932
|
+
const sender = walletAddress || this.walletAddress;
|
|
934
933
|
txBlock.setSender(sender);
|
|
935
934
|
|
|
936
935
|
await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
|
|
@@ -962,7 +961,7 @@ export class ScallopClient {
|
|
|
962
961
|
walletAddress?: string
|
|
963
962
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
964
963
|
const txBlock = this.builder.createTxBlock();
|
|
965
|
-
const sender = walletAddress
|
|
964
|
+
const sender = walletAddress || this.walletAddress;
|
|
966
965
|
txBlock.setSender(sender);
|
|
967
966
|
|
|
968
967
|
const rewardCoins = [];
|
|
@@ -1187,7 +1186,7 @@ export class ScallopClient {
|
|
|
1187
1186
|
}
|
|
1188
1187
|
|
|
1189
1188
|
const txBlock = this.builder.createTxBlock();
|
|
1190
|
-
const recipient = receiveAddress
|
|
1189
|
+
const recipient = receiveAddress || this.walletAddress;
|
|
1191
1190
|
const packageId = this.address.get('core.packages.testCoin.id');
|
|
1192
1191
|
const treasuryId = this.address.get(`core.coins.${assetCoinName}.treasury`);
|
|
1193
1192
|
const target = `${packageId}::${assetCoinName}::mint`;
|
|
File without changes
|