@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.9 → 2.3.1
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 +1841 -1809
- package/dist/index.d.ts +1841 -1809
- package/dist/index.js +49 -2
- package/dist/index.mjs +15 -2
- package/package.json +8 -7
- package/src/builders/borrowIncentiveBuilder.ts +4 -4
- package/src/builders/coreBuilder.ts +86 -59
- package/src/builders/index.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +2 -2
- package/src/builders/oracles/index.ts +365 -114
- package/src/builders/oracles/pyth.ts +135 -0
- package/src/builders/referralBuilder.ts +4 -10
- package/src/builders/sCoinBuilder.ts +2 -2
- package/src/builders/spoolBuilder.ts +5 -8
- package/src/builders/vescaBuilder.ts +5 -5
- package/src/constants/common.ts +3 -0
- package/src/constants/index.ts +1 -1
- package/src/constants/queryKeys.ts +1 -1
- package/src/constants/rpc.ts +0 -1
- package/src/constants/testAddress.ts +99 -271
- package/src/constants/xoracle.ts +2 -8
- package/src/index.ts +1 -1
- package/src/models/index.ts +1 -2
- package/src/models/interface.ts +7 -7
- package/src/models/rateLimiter.ts +55 -0
- package/src/models/scallop.ts +2 -2
- package/src/models/scallopAddress.ts +7 -35
- package/src/models/scallopBuilder.ts +19 -12
- package/src/models/scallopClient.ts +47 -33
- package/src/models/scallopConstants.ts +3 -3
- package/src/models/scallopIndexer.ts +3 -4
- package/src/models/scallopQuery.ts +113 -57
- package/src/models/scallopQueryClient.ts +1 -1
- package/src/models/scallopSuiKit.ts +1 -1
- package/src/models/scallopUtils.ts +12 -7
- package/src/queries/borrowIncentiveQuery.ts +4 -3
- package/src/queries/coreQuery.ts +114 -186
- package/src/queries/index.ts +3 -4
- package/src/queries/loyaltyProgramQuery.ts +2 -2
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/poolAddressesQuery.ts +1 -4
- package/src/queries/portfolioQuery.ts +68 -16
- package/src/queries/priceQuery.ts +2 -3
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +57 -74
- package/src/queries/vescaQuery.ts +3 -3
- package/src/queries/xOracleQuery.ts +4 -21
- package/src/types/address.ts +47 -98
- package/src/types/builder/core.ts +40 -15
- package/src/types/builder/index.ts +17 -1
- package/src/types/constant/enum.ts +64 -0
- package/src/types/constant/index.ts +1 -2
- package/src/types/constant/xOracle.ts +7 -10
- package/src/types/index.ts +1 -1
- package/src/types/query/core.ts +3 -0
- package/src/types/query/index.ts +1 -0
- package/src/types/query/sCoin.ts +1 -0
- package/src/{builders/utils.ts → utils/builder.ts} +1 -1
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/indexer.ts +47 -0
- package/src/{queries/utils.ts → utils/query.ts} +7 -25
- package/src/utils/util.ts +42 -0
- package/src/builders/oracles/error.ts +0 -18
- package/src/builders/oracles/oraclePackageRegistry.ts +0 -336
- package/src/builders/oracles/priceFeedUpdater.ts +0 -112
- package/src/builders/oracles/priceUpdateRequester.ts +0 -50
- package/src/builders/oracles/xOracleUpdateStrategy.ts +0 -214
- package/src/builders/oracles/xOracleUpdater.ts +0 -153
- package/src/constants/api.ts +0 -2
- package/src/models/utils.ts +0 -97
- package/src/types/builder/type.ts +0 -25
- package/src/types/constant/package.ts +0 -16
- /package/src/types/{util.ts → utils.ts} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export class RateLimiter {
|
|
2
|
+
private tokens: number;
|
|
3
|
+
private lastRefillTime: number;
|
|
4
|
+
private readonly refillRate: number; // tokens per millisecond
|
|
5
|
+
|
|
6
|
+
constructor(private readonly capacity: number = 10) {
|
|
7
|
+
this.refillRate = this.capacity / 1000; // 10 tokens per second = 0.01 tokens/ms
|
|
8
|
+
this.tokens = this.capacity;
|
|
9
|
+
this.lastRefillTime = Date.now();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private refill() {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
const elapsed = now - this.lastRefillTime;
|
|
15
|
+
const newTokens = elapsed * this.refillRate;
|
|
16
|
+
|
|
17
|
+
this.tokens = Math.min(this.capacity, this.tokens + newTokens);
|
|
18
|
+
this.lastRefillTime = now;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private getTimeToNextToken(): number {
|
|
22
|
+
this.refill();
|
|
23
|
+
|
|
24
|
+
if (this.tokens >= 1) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Calculate exact milliseconds needed for 1 full token
|
|
29
|
+
const deficit = 1 - this.tokens;
|
|
30
|
+
return Math.ceil(deficit / this.refillRate);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async acquireToken(): Promise<void> {
|
|
34
|
+
// eslint-disable-next-line no-constant-condition
|
|
35
|
+
while (true) {
|
|
36
|
+
const waitTime = this.getTimeToNextToken();
|
|
37
|
+
|
|
38
|
+
if (waitTime === 0) {
|
|
39
|
+
if (this.tokens >= 1) {
|
|
40
|
+
this.tokens -= 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
47
|
+
this.refill();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async execute<T>(fn: () => Promise<T>): Promise<T> {
|
|
52
|
+
await this.acquireToken();
|
|
53
|
+
return await fn();
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/models/scallop.ts
CHANGED
|
@@ -18,12 +18,12 @@ import ScallopClient, { ScallopClientParams } from './scallopClient';
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
type ScallopParams = {
|
|
21
|
+
export type ScallopParams = {
|
|
22
22
|
client?: ScallopClient;
|
|
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
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { NetworkType } from '@scallop-io/sui-kit';
|
|
2
|
-
import { API_BASE_URL } from 'src/constants
|
|
3
|
-
import {
|
|
4
|
-
import { AddressesInterface, AddressStringPath } from 'src/types/address';
|
|
2
|
+
import { API_BASE_URL, queryKeys } from 'src/constants';
|
|
3
|
+
import { AddressesInterface, AddressStringPath } from 'src/types';
|
|
5
4
|
import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
|
|
6
5
|
import { QueryKey } from '@tanstack/query-core';
|
|
7
6
|
import { AxiosRequestConfig } from 'axios';
|
|
8
|
-
import { parseUrl } from '
|
|
7
|
+
import { parseUrl } from 'src/utils';
|
|
9
8
|
|
|
10
9
|
export type ScallopAddressParams = {
|
|
11
10
|
addressId?: string;
|
|
@@ -13,7 +12,7 @@ export type ScallopAddressParams = {
|
|
|
13
12
|
addresses?: string[];
|
|
14
13
|
};
|
|
15
14
|
auth?: string;
|
|
16
|
-
|
|
15
|
+
networkType?: NetworkType;
|
|
17
16
|
forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
18
17
|
defaultValues?: {
|
|
19
18
|
addresses?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
@@ -243,17 +242,6 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
243
242
|
state: '',
|
|
244
243
|
wormhole: '',
|
|
245
244
|
wormholeState: '',
|
|
246
|
-
lst: {
|
|
247
|
-
afsui: {
|
|
248
|
-
safeId: '',
|
|
249
|
-
stakedSuiVaultId: '',
|
|
250
|
-
configId: '',
|
|
251
|
-
},
|
|
252
|
-
hasui: {
|
|
253
|
-
configId: '',
|
|
254
|
-
staking: '',
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
245
|
},
|
|
258
246
|
},
|
|
259
247
|
packages: {
|
|
@@ -285,28 +273,12 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
285
273
|
id: '',
|
|
286
274
|
upgradeCap: '',
|
|
287
275
|
},
|
|
288
|
-
supra: {
|
|
289
|
-
id: '',
|
|
290
|
-
upgradeCap: '',
|
|
291
|
-
},
|
|
276
|
+
supra: { id: '', upgradeCap: '' },
|
|
292
277
|
pyth: {
|
|
293
278
|
id: '',
|
|
294
279
|
upgradeCap: '',
|
|
295
|
-
lst: {
|
|
296
|
-
afsui: {
|
|
297
|
-
id: '',
|
|
298
|
-
object: '',
|
|
299
|
-
},
|
|
300
|
-
hasui: {
|
|
301
|
-
id: '',
|
|
302
|
-
object: '',
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
switchboard: {
|
|
307
|
-
id: '',
|
|
308
|
-
upgradeCap: '',
|
|
309
280
|
},
|
|
281
|
+
switchboard: { id: '', upgradeCap: '' },
|
|
310
282
|
xOracle: {
|
|
311
283
|
id: '',
|
|
312
284
|
upgradeCap: '',
|
|
@@ -480,7 +452,7 @@ class ScallopAddress {
|
|
|
480
452
|
...params,
|
|
481
453
|
});
|
|
482
454
|
|
|
483
|
-
this.network = params.
|
|
455
|
+
this.network = params.networkType ?? 'mainnet';
|
|
484
456
|
this.addressId = params.addressId ?? this.defaultParamValues.addressId;
|
|
485
457
|
this.auth = params.auth ?? '';
|
|
486
458
|
|
|
@@ -12,13 +12,13 @@ import type {
|
|
|
12
12
|
SuiTxArg,
|
|
13
13
|
SuiVecTxArg,
|
|
14
14
|
} from '@scallop-io/sui-kit';
|
|
15
|
-
import type { ScallopTxBlock
|
|
15
|
+
import type { ScallopTxBlock } from '../types';
|
|
16
16
|
import { ScallopBuilderInterface } from './interface';
|
|
17
17
|
|
|
18
18
|
export type ScallopBuilderParams = {
|
|
19
19
|
query?: ScallopQuery;
|
|
20
20
|
usePythPullModel?: boolean;
|
|
21
|
-
|
|
21
|
+
sponsoredFeeds?: string[];
|
|
22
22
|
useOnChainXOracleList?: boolean;
|
|
23
23
|
} & ScallopQueryParams;
|
|
24
24
|
|
|
@@ -37,13 +37,13 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
37
37
|
public readonly query: ScallopQuery;
|
|
38
38
|
public readonly usePythPullModel: boolean;
|
|
39
39
|
public readonly useOnChainXOracleList: boolean;
|
|
40
|
-
public readonly
|
|
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;
|
|
46
|
-
this.
|
|
46
|
+
this.sponsoredFeeds = params.sponsoredFeeds ?? [];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
get utils() {
|
|
@@ -96,22 +96,29 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
96
96
|
* @param assetCoinName - Specific support asset coin name.
|
|
97
97
|
* @param amount - Amount of coins to be selected.
|
|
98
98
|
* @param sender - Sender address.
|
|
99
|
+
* @param isSponsored - Whether the transaction is a sponsored transaction.
|
|
99
100
|
* @return Take coin and left coin.
|
|
100
101
|
*/
|
|
101
|
-
async selectCoin
|
|
102
|
+
async selectCoin(
|
|
102
103
|
txBlock: ScallopTxBlock | SuiKitTxBlock,
|
|
103
|
-
assetCoinName:
|
|
104
|
+
assetCoinName: string,
|
|
104
105
|
amount: number,
|
|
105
|
-
sender: string = this.walletAddress
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
sender: string = this.walletAddress,
|
|
107
|
+
isSponsored: boolean = false
|
|
108
|
+
) {
|
|
109
|
+
if (assetCoinName === 'sui' && !isSponsored) {
|
|
108
110
|
const [takeCoin] = txBlock.splitSUIFromGas([amount]);
|
|
109
|
-
return { takeCoin }
|
|
111
|
+
return { takeCoin };
|
|
110
112
|
} else {
|
|
111
113
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
112
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);
|
|
113
119
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
114
|
-
|
|
120
|
+
|
|
121
|
+
return { takeCoin, leftCoin, totalAmount };
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
|
|
@@ -5,10 +5,10 @@ import type {
|
|
|
5
5
|
TransactionObjectArgument,
|
|
6
6
|
TransactionResult,
|
|
7
7
|
} from '@mysten/sui/transactions';
|
|
8
|
-
import { requireSender } from '
|
|
8
|
+
import { requireSender } from 'src/utils';
|
|
9
9
|
import type { NetworkType, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
10
|
+
import type { ScallopTxBlock } from '../types';
|
|
10
11
|
import { ScallopClientInterface } from './interface';
|
|
11
|
-
import { ScallopTxBlock } from 'src/types/builder';
|
|
12
12
|
|
|
13
13
|
export type ScallopClientParams = {
|
|
14
14
|
networkType?: NetworkType;
|
|
@@ -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.
|
|
@@ -210,6 +212,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
210
212
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
211
213
|
* @param obligationId - The obligation object.
|
|
212
214
|
* @param walletAddress - The wallet address of the owner.
|
|
215
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
213
216
|
* @return Transaction block response or transaction block.
|
|
214
217
|
*/
|
|
215
218
|
async depositCollateral(
|
|
@@ -221,30 +224,38 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
221
224
|
amount: number,
|
|
222
225
|
sign?: S,
|
|
223
226
|
obligationId?: string,
|
|
224
|
-
walletAddress?: string
|
|
227
|
+
walletAddress?: string,
|
|
228
|
+
isSponsoredTx?: boolean
|
|
225
229
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
226
230
|
async depositCollateral<S extends boolean>(
|
|
227
231
|
collateralCoinName: string,
|
|
228
232
|
amount: number,
|
|
229
233
|
sign: S = true as S,
|
|
230
234
|
obligationId?: string,
|
|
231
|
-
walletAddress?: string
|
|
235
|
+
walletAddress?: string,
|
|
236
|
+
isSponsoredTx?: boolean
|
|
232
237
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
233
238
|
const txBlock = this.builder.createTxBlock();
|
|
234
239
|
const sender = walletAddress ?? this.walletAddress;
|
|
235
240
|
txBlock.setSender(sender);
|
|
236
241
|
|
|
237
|
-
const
|
|
238
|
-
|
|
242
|
+
const specificObligationId =
|
|
243
|
+
obligationId ?? (await this.query.getObligations(sender))[0]?.id;
|
|
239
244
|
if (specificObligationId) {
|
|
240
245
|
await txBlock.addCollateralQuick(
|
|
241
246
|
amount,
|
|
242
247
|
collateralCoinName,
|
|
243
|
-
specificObligationId
|
|
248
|
+
specificObligationId,
|
|
249
|
+
isSponsoredTx
|
|
244
250
|
);
|
|
245
251
|
} else {
|
|
246
252
|
const [obligation, obligationKey, hotPotato] = txBlock.openObligation();
|
|
247
|
-
await txBlock.addCollateralQuick(
|
|
253
|
+
await txBlock.addCollateralQuick(
|
|
254
|
+
amount,
|
|
255
|
+
collateralCoinName,
|
|
256
|
+
obligation,
|
|
257
|
+
isSponsoredTx
|
|
258
|
+
);
|
|
248
259
|
txBlock.returnObligation(obligation, hotPotato);
|
|
249
260
|
txBlock.transferObjects([obligationKey], sender);
|
|
250
261
|
}
|
|
@@ -267,6 +278,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
267
278
|
* @param obligationId - The obligation object.
|
|
268
279
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
269
280
|
* @param walletAddress - The wallet address of the owner.
|
|
281
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
270
282
|
* @return Transaction block response or transaction block.
|
|
271
283
|
*/
|
|
272
284
|
async withdrawCollateral<S extends boolean>(
|
|
@@ -275,7 +287,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
275
287
|
sign: S = true as S,
|
|
276
288
|
obligationId: string,
|
|
277
289
|
obligationKey: string,
|
|
278
|
-
walletAddress?: string
|
|
290
|
+
walletAddress?: string,
|
|
291
|
+
isSponsoredTx?: boolean
|
|
279
292
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
280
293
|
const txBlock = this.builder.createTxBlock();
|
|
281
294
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -285,7 +298,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
285
298
|
amount,
|
|
286
299
|
collateralCoinName,
|
|
287
300
|
obligationId,
|
|
288
|
-
obligationKey
|
|
301
|
+
obligationKey,
|
|
302
|
+
{ isSponsoredTx }
|
|
289
303
|
);
|
|
290
304
|
txBlock.transferObjects([collateralCoin], sender);
|
|
291
305
|
|
|
@@ -449,6 +463,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
449
463
|
* @param obligationId - The obligation object.
|
|
450
464
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
451
465
|
* @param walletAddress - The wallet address of the owner.
|
|
466
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
452
467
|
* @return Transaction block response or transaction block.
|
|
453
468
|
*/
|
|
454
469
|
async borrow<S extends boolean>(
|
|
@@ -457,7 +472,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
457
472
|
sign: S = true as S,
|
|
458
473
|
obligationId: string,
|
|
459
474
|
obligationKey: string,
|
|
460
|
-
walletAddress?: string
|
|
475
|
+
walletAddress?: string,
|
|
476
|
+
isSponsoredTx?: boolean
|
|
461
477
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
462
478
|
const txBlock = this.builder.createTxBlock();
|
|
463
479
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -471,7 +487,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
471
487
|
amount,
|
|
472
488
|
poolCoinName,
|
|
473
489
|
obligationId,
|
|
474
|
-
obligationKey
|
|
490
|
+
obligationKey,
|
|
491
|
+
{ isSponsoredTx }
|
|
475
492
|
);
|
|
476
493
|
txBlock.transferObjects([coin], sender);
|
|
477
494
|
if (sign && availableStake) {
|
|
@@ -495,6 +512,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
495
512
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
496
513
|
* @param obligationId - The obligation object.
|
|
497
514
|
* @param walletAddress - The wallet address of the owner.
|
|
515
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
498
516
|
* @return Transaction block response or transaction block.
|
|
499
517
|
*/
|
|
500
518
|
async repay<S extends boolean>(
|
|
@@ -503,7 +521,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
503
521
|
sign: S = true as S,
|
|
504
522
|
obligationId: string,
|
|
505
523
|
obligationKey: string,
|
|
506
|
-
walletAddress?: string
|
|
524
|
+
walletAddress?: string,
|
|
525
|
+
isSponsoredTx?: boolean
|
|
507
526
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
508
527
|
const txBlock = this.builder.createTxBlock();
|
|
509
528
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -513,7 +532,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
513
532
|
if (sign && availableStake) {
|
|
514
533
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
515
534
|
}
|
|
516
|
-
await txBlock.repayQuick(amount, poolCoinName, obligationId);
|
|
535
|
+
await txBlock.repayQuick(amount, poolCoinName, obligationId, isSponsoredTx);
|
|
517
536
|
if (sign && availableStake) {
|
|
518
537
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKey);
|
|
519
538
|
}
|
|
@@ -713,12 +732,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
713
732
|
throw new Error(`Invalid sCoin type: ${stakeMarketCoinName}`);
|
|
714
733
|
|
|
715
734
|
// merge to existing sCoins if exist
|
|
716
|
-
await this.utils.mergeSimilarCoins(
|
|
717
|
-
txBlock,
|
|
718
|
-
sCoin,
|
|
719
|
-
sCoinType,
|
|
720
|
-
requireSender(txBlock)
|
|
721
|
-
);
|
|
735
|
+
await this.utils.mergeSimilarCoins(txBlock, sCoin, sCoinType, sender);
|
|
722
736
|
}
|
|
723
737
|
|
|
724
738
|
txBlock.transferObjects([sCoin], sender);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PoolAddress, Whitelist } from 'src/types
|
|
1
|
+
import { PoolAddress, Whitelist } from 'src/types';
|
|
2
2
|
import ScallopAddress, { ScallopAddressParams } from './scallopAddress';
|
|
3
3
|
import { NetworkType, parseStructTag } from '@scallop-io/sui-kit';
|
|
4
|
-
import { queryKeys } from 'src/constants
|
|
5
|
-
import { parseUrl } from '
|
|
4
|
+
import { queryKeys } from 'src/constants';
|
|
5
|
+
import { parseUrl } from 'src/utils';
|
|
6
6
|
|
|
7
7
|
const isEmptyObject = (obj: object) => {
|
|
8
8
|
return Object.keys(obj).length === 0;
|
|
@@ -10,10 +10,9 @@ import {
|
|
|
10
10
|
Spool,
|
|
11
11
|
Spools,
|
|
12
12
|
TotalValueLocked,
|
|
13
|
-
} from 'src/types
|
|
13
|
+
} from 'src/types';
|
|
14
14
|
import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
|
|
15
|
-
import { SDK_API_BASE_URL } from 'src/constants
|
|
16
|
-
import { queryKeys } from 'src/constants/queryKeys';
|
|
15
|
+
import { queryKeys, SDK_API_BASE_URL } from 'src/constants';
|
|
17
16
|
|
|
18
17
|
export type ScallopIndexerParams = {
|
|
19
18
|
indexerApiUrl?: string;
|
|
@@ -135,7 +134,7 @@ class ScallopIndexer extends ScallopAxios {
|
|
|
135
134
|
borrowIncentivePools: BorrowIncentivePool[];
|
|
136
135
|
}>(
|
|
137
136
|
'/api/borrowIncentivePools/migrate',
|
|
138
|
-
queryKeys.api.
|
|
137
|
+
queryKeys.api.getBorrowIncentivePools()
|
|
139
138
|
);
|
|
140
139
|
|
|
141
140
|
if (response.status === 200) {
|