@scallop-io/sui-scallop-sdk 2.3.0 → 2.3.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.
- package/dist/index.d.mts +23 -19
- package/dist/index.d.ts +23 -19
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
- package/src/builders/oracles/pyth.ts +11 -3
- package/src/builders/spoolBuilder.ts +3 -6
- package/src/constants/queryKeys.ts +5 -1
- package/src/constants/rpc.ts +0 -1
- package/src/models/interface.ts +1 -1
- package/src/models/scallop.ts +1 -1
- package/src/models/scallopAddress.ts +2 -2
- package/src/models/scallopBuilder.ts +6 -2
- package/src/models/scallopClient.ts +16 -19
- package/src/models/scallopQuery.ts +1 -1
- package/src/models/scallopUtils.ts +2 -1
- package/src/queries/poolAddressesQuery.ts +0 -1
package/package.json
CHANGED
|
@@ -95,8 +95,12 @@ export const updatePythPriceFeeds = async (
|
|
|
95
95
|
'0xa8b8dcc9880166edb57b53e05f8df7364d31b5d9b7d107fd27f0b69cf338b687',
|
|
96
96
|
}
|
|
97
97
|
);
|
|
98
|
-
const priceIds =
|
|
99
|
-
|
|
98
|
+
const priceIds = Array.from(
|
|
99
|
+
new Set(
|
|
100
|
+
assetCoinNames.map((assetCoinName) =>
|
|
101
|
+
builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
102
|
+
)
|
|
103
|
+
)
|
|
100
104
|
);
|
|
101
105
|
|
|
102
106
|
const endpoints = builder.utils.pythEndpoints ?? [
|
|
@@ -106,7 +110,11 @@ export const updatePythPriceFeeds = async (
|
|
|
106
110
|
// iterate through the endpoints
|
|
107
111
|
for (const endpoint of endpoints) {
|
|
108
112
|
try {
|
|
109
|
-
const pythConnection = new SuiPriceServiceConnection(endpoint
|
|
113
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
114
|
+
priceFeedRequestConfig: {
|
|
115
|
+
binary: true,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
110
118
|
const priceUpdateData =
|
|
111
119
|
await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
112
120
|
|
|
@@ -196,7 +196,7 @@ const generateSpoolNormalMethod: GenerateSpoolNormalMethod = ({
|
|
|
196
196
|
*
|
|
197
197
|
* @description
|
|
198
198
|
* The quick methods are the same as the normal methods, but they will automatically
|
|
199
|
-
* help users organize transaction blocks,
|
|
199
|
+
* help users organize transaction blocks, including getting stake account info, and transferring
|
|
200
200
|
* coins to the sender. So, they are all asynchronous methods.
|
|
201
201
|
*
|
|
202
202
|
* @param builder - Scallop builder instance.
|
|
@@ -273,7 +273,7 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
273
273
|
for (const account of stakeAccounts) {
|
|
274
274
|
if (account.staked === 0) continue;
|
|
275
275
|
const amountToUnstake = Math.min(amount, account.staked);
|
|
276
|
-
const marketCoin =
|
|
276
|
+
const marketCoin = txBlock.unstake(
|
|
277
277
|
account.id,
|
|
278
278
|
amountToUnstake,
|
|
279
279
|
stakeMarketCoinName
|
|
@@ -281,10 +281,7 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
281
281
|
|
|
282
282
|
// convert to new sCoin
|
|
283
283
|
if (returnSCoin) {
|
|
284
|
-
const sCoin =
|
|
285
|
-
stakeMarketCoinName,
|
|
286
|
-
marketCoin
|
|
287
|
-
);
|
|
284
|
+
const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
|
|
288
285
|
toTransfer.push(sCoin);
|
|
289
286
|
} else {
|
|
290
287
|
toTransfer.push(marketCoin);
|
package/src/constants/rpc.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { getFullnodeUrl } from '@mysten/sui/client';
|
|
|
2
2
|
|
|
3
3
|
export const RPC_PROVIDERS = [
|
|
4
4
|
getFullnodeUrl('mainnet'),
|
|
5
|
-
'https://sui-mainnet.public.blastapi.io',
|
|
6
5
|
'https://sui-mainnet-ca-2.cosmostation.io',
|
|
7
6
|
'https://sui-mainnet-eu-4.cosmostation.io',
|
|
8
7
|
'https://sui-mainnet-endpoint.blockvision.org',
|
package/src/models/interface.ts
CHANGED
|
@@ -24,7 +24,7 @@ interface ScallopBuilderInterface extends ScallopQueryInterface {
|
|
|
24
24
|
query: ScallopQuery;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
interface ScallopClientInterface extends
|
|
27
|
+
interface ScallopClientInterface extends ScallopBuilderInterface {
|
|
28
28
|
builder: ScallopBuilder;
|
|
29
29
|
}
|
|
30
30
|
|
package/src/models/scallop.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type ScallopParams = {
|
|
|
23
23
|
} & ScallopClientParams;
|
|
24
24
|
class Scallop {
|
|
25
25
|
public readonly client: ScallopClient;
|
|
26
|
-
public constructor(params: ScallopParams) {
|
|
26
|
+
public constructor(params: ScallopParams = {}) {
|
|
27
27
|
this.client = params.client ?? new ScallopClient(params);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -12,7 +12,7 @@ export type ScallopAddressParams = {
|
|
|
12
12
|
addresses?: string[];
|
|
13
13
|
};
|
|
14
14
|
auth?: string;
|
|
15
|
-
|
|
15
|
+
networkType?: NetworkType;
|
|
16
16
|
forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
17
17
|
defaultValues?: {
|
|
18
18
|
addresses?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
@@ -452,7 +452,7 @@ class ScallopAddress {
|
|
|
452
452
|
...params,
|
|
453
453
|
});
|
|
454
454
|
|
|
455
|
-
this.network = params.
|
|
455
|
+
this.network = params.networkType ?? 'mainnet';
|
|
456
456
|
this.addressId = params.addressId ?? this.defaultParamValues.addressId;
|
|
457
457
|
this.auth = params.auth ?? '';
|
|
458
458
|
|
|
@@ -39,7 +39,7 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
39
39
|
public readonly useOnChainXOracleList: boolean;
|
|
40
40
|
public readonly sponsoredFeeds: string[];
|
|
41
41
|
|
|
42
|
-
public constructor(params: ScallopBuilderParams) {
|
|
42
|
+
public constructor(params: ScallopBuilderParams = {}) {
|
|
43
43
|
this.query = params.query ?? new ScallopQuery(params);
|
|
44
44
|
this.usePythPullModel = params.usePythPullModel ?? true;
|
|
45
45
|
this.useOnChainXOracleList = params.useOnChainXOracleList ?? true;
|
|
@@ -112,9 +112,13 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
112
112
|
} else {
|
|
113
113
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
114
114
|
const coins = await this.utils.selectCoins(amount, coinType, sender);
|
|
115
|
+
const totalAmount = coins.reduce((prev, coin) => {
|
|
116
|
+
prev += Number(coin.balance);
|
|
117
|
+
return prev;
|
|
118
|
+
}, 0);
|
|
115
119
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
116
120
|
|
|
117
|
-
return { takeCoin, leftCoin };
|
|
121
|
+
return { takeCoin, leftCoin, totalAmount };
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
|
|
@@ -42,7 +42,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
42
42
|
public readonly builder: ScallopBuilder;
|
|
43
43
|
public networkType: NetworkType;
|
|
44
44
|
|
|
45
|
-
public constructor(params: ScallopClientParams) {
|
|
45
|
+
public constructor(params: ScallopClientParams = {}) {
|
|
46
46
|
this.builder = params.builder ?? new ScallopBuilder(params);
|
|
47
47
|
this.networkType = params.networkType ?? 'mainnet';
|
|
48
48
|
}
|
|
@@ -84,9 +84,9 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* Query market data.
|
|
87
|
-
*
|
|
87
|
+
* @deprecated use ScallopQuery instance instead
|
|
88
88
|
* @description
|
|
89
|
-
* This method might be
|
|
89
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
90
90
|
*
|
|
91
91
|
* @return Market data.
|
|
92
92
|
*/
|
|
@@ -96,9 +96,9 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* Get obligations data.
|
|
99
|
-
*
|
|
99
|
+
* @deprecated use ScallopQuery instance instead
|
|
100
100
|
* @description
|
|
101
|
-
* This method might be
|
|
101
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
102
102
|
*
|
|
103
103
|
* @param ownerAddress - The owner address.
|
|
104
104
|
* @return Obligations data.
|
|
@@ -110,9 +110,9 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* Query obligation data.
|
|
113
|
-
*
|
|
113
|
+
* @deprecated use ScallopQuery instance instead
|
|
114
114
|
* @description
|
|
115
|
-
* This method might be
|
|
115
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
116
116
|
*
|
|
117
117
|
* @param obligationId - The obligation id.
|
|
118
118
|
* @return Obligation data.
|
|
@@ -123,9 +123,9 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* Query all stake accounts data.
|
|
126
|
-
*
|
|
126
|
+
* @deprecated use ScallopQuery instance instead
|
|
127
127
|
* @description
|
|
128
|
-
* This method might be
|
|
128
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
129
129
|
*
|
|
130
130
|
* @param ownerAddress - The owner address.
|
|
131
131
|
* @return All stake accounts data.
|
|
@@ -137,9 +137,9 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
139
|
* Query stake account data.
|
|
140
|
-
*
|
|
140
|
+
* @deprecated use ScallopQuery instance instead
|
|
141
141
|
* @description
|
|
142
|
-
* This method might be
|
|
142
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
143
143
|
*
|
|
144
144
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
145
145
|
* @param ownerAddress - The owner address.
|
|
@@ -152,9 +152,10 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Query stake pool data.
|
|
155
|
+
* @deprecated use ScallopQuery instance instead
|
|
155
156
|
*
|
|
156
157
|
* @description
|
|
157
|
-
* This method might be
|
|
158
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
158
159
|
*
|
|
159
160
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
160
161
|
* @return Stake pool data.
|
|
@@ -165,9 +166,10 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
165
166
|
|
|
166
167
|
/**
|
|
167
168
|
* Query reward pool data.
|
|
169
|
+
* @deprecated use ScallopQuery instance instead
|
|
168
170
|
*
|
|
169
171
|
* @description
|
|
170
|
-
* This method might be
|
|
172
|
+
* This method might be deprecated in the future, please use the {@link ScallopQuery} query instance instead.
|
|
171
173
|
*
|
|
172
174
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
173
175
|
* @return Reward pool data.
|
|
@@ -730,12 +732,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
730
732
|
throw new Error(`Invalid sCoin type: ${stakeMarketCoinName}`);
|
|
731
733
|
|
|
732
734
|
// merge to existing sCoins if exist
|
|
733
|
-
await this.utils.mergeSimilarCoins(
|
|
734
|
-
txBlock,
|
|
735
|
-
sCoin,
|
|
736
|
-
sCoinType,
|
|
737
|
-
requireSender(txBlock)
|
|
738
|
-
);
|
|
735
|
+
await this.utils.mergeSimilarCoins(txBlock, sCoin, sCoinType, sender);
|
|
739
736
|
}
|
|
740
737
|
|
|
741
738
|
txBlock.transferObjects([sCoin], sender);
|
|
@@ -74,7 +74,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
74
74
|
public readonly indexer: ScallopIndexer;
|
|
75
75
|
public readonly utils: ScallopUtils;
|
|
76
76
|
|
|
77
|
-
constructor(params: ScallopQueryParams) {
|
|
77
|
+
constructor(params: ScallopQueryParams = {}) {
|
|
78
78
|
this.utils = params.utils ?? new ScallopUtils(params);
|
|
79
79
|
this.indexer =
|
|
80
80
|
params.indexer ??
|
|
@@ -542,11 +542,12 @@ class ScallopUtils implements ScallopUtilsInterface {
|
|
|
542
542
|
const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
|
|
543
543
|
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
544
544
|
timeout: this.timeout,
|
|
545
|
+
httpRetries: 0,
|
|
545
546
|
});
|
|
546
547
|
|
|
547
548
|
try {
|
|
548
549
|
const feeds = await this.queryClient.fetchQuery({
|
|
549
|
-
queryKey: queryKeys.oracle.getPythLatestPriceFeeds(),
|
|
550
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeeds(priceIds),
|
|
550
551
|
queryFn: async () => {
|
|
551
552
|
return await pythConnection.getLatestPriceFeeds(priceIds);
|
|
552
553
|
},
|
|
@@ -3,7 +3,6 @@ import { AddressesInterface, OptionalKeys, PoolAddress } from 'src/types';
|
|
|
3
3
|
|
|
4
4
|
const RPC_PROVIDERS = [
|
|
5
5
|
getFullnodeUrl('mainnet'),
|
|
6
|
-
'https://sui-mainnet.public.blastapi.io',
|
|
7
6
|
'https://sui-mainnet-ca-2.cosmostation.io',
|
|
8
7
|
'https://sui-mainnet-eu-4.cosmostation.io',
|
|
9
8
|
'https://sui-mainnet-endpoint.blockvision.org',
|