@scallop-io/sui-scallop-sdk 0.46.49 → 0.46.51
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.js +93 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -26
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +3 -3
- package/dist/models/scallopQuery.d.ts +2 -1
- package/dist/queries/loyaltyProgramQuery.d.ts +1 -1
- package/dist/queries/priceQuery.d.ts +1 -1
- package/dist/types/model.d.ts +3 -1
- package/package.json +1 -1
- package/src/constants/cache.ts +1 -1
- package/src/models/scallopBuilder.ts +3 -3
- package/src/models/scallopQuery.ts +19 -14
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/priceQuery.ts +43 -6
- package/src/types/model.ts +3 -1
- package/src/utils/query.ts +17 -15
|
@@ -51,7 +51,7 @@ export declare class ScallopBuilder {
|
|
|
51
51
|
* @param sender - Sender address.
|
|
52
52
|
* @return Take coin and left coin.
|
|
53
53
|
*/
|
|
54
|
-
selectCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, assetCoinName: SupportAssetCoins, amount: number, sender
|
|
54
|
+
selectCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, assetCoinName: SupportAssetCoins, amount: number, sender?: string): Promise<{
|
|
55
55
|
takeCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
|
|
56
56
|
leftCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
|
|
57
57
|
}>;
|
|
@@ -64,7 +64,7 @@ export declare class ScallopBuilder {
|
|
|
64
64
|
* @param sender - Sender address.
|
|
65
65
|
* @return Take coin and left coin.
|
|
66
66
|
*/
|
|
67
|
-
selectMarketCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, marketCoinName: SupportMarketCoins, amount: number, sender
|
|
67
|
+
selectMarketCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, marketCoinName: SupportMarketCoins, amount: number, sender?: string): Promise<{
|
|
68
68
|
takeCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
|
|
69
69
|
leftCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
|
|
70
70
|
totalAmount: number;
|
|
@@ -78,7 +78,7 @@ export declare class ScallopBuilder {
|
|
|
78
78
|
* @param sender - Sender address.
|
|
79
79
|
* @return Take coin and left coin.
|
|
80
80
|
*/
|
|
81
|
-
selectSCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, sCoinName: SupportSCoin, amount: number, sender
|
|
81
|
+
selectSCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, sCoinName: SupportSCoin, amount: number, sender?: string): Promise<{
|
|
82
82
|
takeCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
|
|
83
83
|
leftCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
|
|
84
84
|
totalAmount: number;
|
|
@@ -4,7 +4,7 @@ import { ScallopAddress } from './scallopAddress';
|
|
|
4
4
|
import { ScallopUtils } from './scallopUtils';
|
|
5
5
|
import { ScallopIndexer } from './scallopIndexer';
|
|
6
6
|
import { ScallopCache } from './scallopCache';
|
|
7
|
-
import { SuiObjectData } from '@mysten/sui.js/
|
|
7
|
+
import { SuiObjectData } from '@mysten/sui.js/client';
|
|
8
8
|
/**
|
|
9
9
|
* @description
|
|
10
10
|
* It provides methods for getting on-chain data from the Scallop contract.
|
|
@@ -24,6 +24,7 @@ export declare class ScallopQuery {
|
|
|
24
24
|
utils: ScallopUtils;
|
|
25
25
|
indexer: ScallopIndexer;
|
|
26
26
|
cache: ScallopCache;
|
|
27
|
+
walletAddress: string;
|
|
27
28
|
constructor(params: ScallopQueryParams, instance?: ScallopInstanceParams);
|
|
28
29
|
/**
|
|
29
30
|
* Request the scallop API to initialize data.
|
package/dist/types/model.d.ts
CHANGED
|
@@ -27,7 +27,9 @@ export type ScallopBuilderParams = ScallopParams & {
|
|
|
27
27
|
walletAddress?: string;
|
|
28
28
|
pythEndpoints?: string[];
|
|
29
29
|
};
|
|
30
|
-
export type ScallopQueryParams = ScallopParams
|
|
30
|
+
export type ScallopQueryParams = ScallopParams & {
|
|
31
|
+
walletAddress?: string;
|
|
32
|
+
};
|
|
31
33
|
export type ScallopUtilsParams = ScallopParams & {
|
|
32
34
|
pythEndpoints?: string[];
|
|
33
35
|
};
|
package/package.json
CHANGED
package/src/constants/cache.ts
CHANGED
|
@@ -122,7 +122,7 @@ export class ScallopBuilder {
|
|
|
122
122
|
txBlock: ScallopTxBlock | SuiKitTxBlock,
|
|
123
123
|
assetCoinName: SupportAssetCoins,
|
|
124
124
|
amount: number,
|
|
125
|
-
sender: string
|
|
125
|
+
sender: string = this.walletAddress
|
|
126
126
|
) {
|
|
127
127
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
128
128
|
const coins = await this.utils.selectCoins(amount, coinType, sender);
|
|
@@ -143,7 +143,7 @@ export class ScallopBuilder {
|
|
|
143
143
|
txBlock: ScallopTxBlock | SuiKitTxBlock,
|
|
144
144
|
marketCoinName: SupportMarketCoins,
|
|
145
145
|
amount: number,
|
|
146
|
-
sender: string
|
|
146
|
+
sender: string = this.walletAddress
|
|
147
147
|
) {
|
|
148
148
|
const marketCoinType = this.utils.parseMarketCoinType(marketCoinName);
|
|
149
149
|
const coins = await this.utils.selectCoins(amount, marketCoinType, sender);
|
|
@@ -171,7 +171,7 @@ export class ScallopBuilder {
|
|
|
171
171
|
txBlock: ScallopTxBlock | SuiKitTxBlock,
|
|
172
172
|
sCoinName: SupportSCoin,
|
|
173
173
|
amount: number,
|
|
174
|
-
sender: string
|
|
174
|
+
sender: string = this.walletAddress
|
|
175
175
|
) {
|
|
176
176
|
const sCoinType = this.utils.parseSCoinType(sCoinName);
|
|
177
177
|
const coins = await this.utils.selectCoins(amount, sCoinType, sender);
|
|
@@ -52,12 +52,13 @@ import { ScallopUtils } from './scallopUtils';
|
|
|
52
52
|
import { ScallopIndexer } from './scallopIndexer';
|
|
53
53
|
import { ScallopCache } from './scallopCache';
|
|
54
54
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
55
|
-
import { SuiObjectData } from '@mysten/sui.js/
|
|
55
|
+
import { SuiObjectData } from '@mysten/sui.js/client';
|
|
56
56
|
import {
|
|
57
57
|
getSCoinAmount,
|
|
58
58
|
getSCoinAmounts,
|
|
59
59
|
getSCoinTotalSupply,
|
|
60
60
|
} from 'src/queries/sCoinQuery';
|
|
61
|
+
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* @description
|
|
@@ -79,6 +80,7 @@ export class ScallopQuery {
|
|
|
79
80
|
public utils: ScallopUtils;
|
|
80
81
|
public indexer: ScallopIndexer;
|
|
81
82
|
public cache: ScallopCache;
|
|
83
|
+
public walletAddress: string;
|
|
82
84
|
|
|
83
85
|
public constructor(
|
|
84
86
|
params: ScallopQueryParams,
|
|
@@ -106,6 +108,9 @@ export class ScallopQuery {
|
|
|
106
108
|
query: this,
|
|
107
109
|
});
|
|
108
110
|
this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
|
|
111
|
+
this.walletAddress = normalizeSuiAddress(
|
|
112
|
+
params?.walletAddress || this.suiKit.currentAddress()
|
|
113
|
+
);
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
/**
|
|
@@ -205,7 +210,7 @@ export class ScallopQuery {
|
|
|
205
210
|
* @param ownerAddress - The owner address.
|
|
206
211
|
* @return Obligations data.
|
|
207
212
|
*/
|
|
208
|
-
public async getObligations(ownerAddress
|
|
213
|
+
public async getObligations(ownerAddress: string = this.walletAddress) {
|
|
209
214
|
return await getObligations(this, ownerAddress);
|
|
210
215
|
}
|
|
211
216
|
|
|
@@ -228,7 +233,7 @@ export class ScallopQuery {
|
|
|
228
233
|
*/
|
|
229
234
|
public async getCoinAmounts(
|
|
230
235
|
assetCoinNames?: SupportAssetCoins[],
|
|
231
|
-
ownerAddress
|
|
236
|
+
ownerAddress: string = this.walletAddress
|
|
232
237
|
) {
|
|
233
238
|
return await getCoinAmounts(this, assetCoinNames, ownerAddress);
|
|
234
239
|
}
|
|
@@ -242,7 +247,7 @@ export class ScallopQuery {
|
|
|
242
247
|
*/
|
|
243
248
|
public async getCoinAmount(
|
|
244
249
|
assetCoinName: SupportAssetCoins,
|
|
245
|
-
ownerAddress
|
|
250
|
+
ownerAddress: string = this.walletAddress
|
|
246
251
|
) {
|
|
247
252
|
return await getCoinAmount(this, assetCoinName, ownerAddress);
|
|
248
253
|
}
|
|
@@ -256,7 +261,7 @@ export class ScallopQuery {
|
|
|
256
261
|
*/
|
|
257
262
|
public async getMarketCoinAmounts(
|
|
258
263
|
marketCoinNames?: SupportMarketCoins[],
|
|
259
|
-
ownerAddress
|
|
264
|
+
ownerAddress: string = this.walletAddress
|
|
260
265
|
) {
|
|
261
266
|
return await getMarketCoinAmounts(this, marketCoinNames, ownerAddress);
|
|
262
267
|
}
|
|
@@ -270,7 +275,7 @@ export class ScallopQuery {
|
|
|
270
275
|
*/
|
|
271
276
|
public async getMarketCoinAmount(
|
|
272
277
|
marketCoinName: SupportMarketCoins,
|
|
273
|
-
ownerAddress
|
|
278
|
+
ownerAddress: string = this.walletAddress
|
|
274
279
|
) {
|
|
275
280
|
return await getMarketCoinAmount(this, marketCoinName, ownerAddress);
|
|
276
281
|
}
|
|
@@ -331,7 +336,7 @@ export class ScallopQuery {
|
|
|
331
336
|
* @param ownerAddress - The owner address.
|
|
332
337
|
* @return All Stake accounts data.
|
|
333
338
|
*/
|
|
334
|
-
public async getAllStakeAccounts(ownerAddress
|
|
339
|
+
public async getAllStakeAccounts(ownerAddress: string = this.walletAddress) {
|
|
335
340
|
return await getStakeAccounts(this, ownerAddress);
|
|
336
341
|
}
|
|
337
342
|
|
|
@@ -344,7 +349,7 @@ export class ScallopQuery {
|
|
|
344
349
|
*/
|
|
345
350
|
public async getStakeAccounts(
|
|
346
351
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
347
|
-
ownerAddress
|
|
352
|
+
ownerAddress: string = this.walletAddress
|
|
348
353
|
) {
|
|
349
354
|
const allStakeAccount = await this.getAllStakeAccounts(ownerAddress);
|
|
350
355
|
return allStakeAccount[stakeMarketCoinName] ?? [];
|
|
@@ -472,7 +477,7 @@ export class ScallopQuery {
|
|
|
472
477
|
*/
|
|
473
478
|
public async getLendings(
|
|
474
479
|
poolCoinNames?: SupportPoolCoins[],
|
|
475
|
-
ownerAddress
|
|
480
|
+
ownerAddress: string = this.walletAddress,
|
|
476
481
|
indexer: boolean = false
|
|
477
482
|
) {
|
|
478
483
|
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
@@ -488,7 +493,7 @@ export class ScallopQuery {
|
|
|
488
493
|
*/
|
|
489
494
|
public async getLending(
|
|
490
495
|
poolCoinName: SupportPoolCoins,
|
|
491
|
-
ownerAddress
|
|
496
|
+
ownerAddress: string = this.walletAddress,
|
|
492
497
|
indexer: boolean = false
|
|
493
498
|
) {
|
|
494
499
|
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
@@ -505,7 +510,7 @@ export class ScallopQuery {
|
|
|
505
510
|
* @return All obligation accounts information.
|
|
506
511
|
*/
|
|
507
512
|
public async getObligationAccounts(
|
|
508
|
-
ownerAddress
|
|
513
|
+
ownerAddress: string = this.walletAddress,
|
|
509
514
|
indexer: boolean = false
|
|
510
515
|
) {
|
|
511
516
|
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
@@ -524,7 +529,7 @@ export class ScallopQuery {
|
|
|
524
529
|
*/
|
|
525
530
|
public async getObligationAccount(
|
|
526
531
|
obligationId: string,
|
|
527
|
-
ownerAddress
|
|
532
|
+
ownerAddress: string = this.walletAddress,
|
|
528
533
|
indexer: boolean = false
|
|
529
534
|
) {
|
|
530
535
|
return await getObligationAccount(
|
|
@@ -619,7 +624,7 @@ export class ScallopQuery {
|
|
|
619
624
|
*/
|
|
620
625
|
public async getSCoinAmounts(
|
|
621
626
|
sCoinNames?: SupportSCoin[],
|
|
622
|
-
ownerAddress
|
|
627
|
+
ownerAddress: string = this.walletAddress
|
|
623
628
|
) {
|
|
624
629
|
return await getSCoinAmounts(this, sCoinNames, ownerAddress);
|
|
625
630
|
}
|
|
@@ -633,7 +638,7 @@ export class ScallopQuery {
|
|
|
633
638
|
*/
|
|
634
639
|
public async getSCoinAmount(
|
|
635
640
|
sCoinName: SupportSCoin | SupportMarketCoins,
|
|
636
|
-
ownerAddress
|
|
641
|
+
ownerAddress: string = this.walletAddress
|
|
637
642
|
) {
|
|
638
643
|
const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
|
|
639
644
|
return parsedSCoinName
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SuiObjectData } from '@mysten/sui.js/
|
|
1
|
+
import { SuiObjectData } from '@mysten/sui.js/client';
|
|
2
2
|
import type { ScallopQuery } from '../models';
|
|
3
3
|
import type { SupportAssetCoins } from '../types';
|
|
4
4
|
|
|
@@ -61,16 +61,53 @@ export const getPythPrices = async (
|
|
|
61
61
|
query: ScallopQuery,
|
|
62
62
|
assetCoinNames: SupportAssetCoins[]
|
|
63
63
|
) => {
|
|
64
|
+
const pythPriceFeedIds = assetCoinNames.reduce(
|
|
65
|
+
(prev, assetCoinName) => {
|
|
66
|
+
const pythPriceFeed = query.address.get(
|
|
67
|
+
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
68
|
+
);
|
|
69
|
+
if (!prev[pythPriceFeed]) {
|
|
70
|
+
prev[pythPriceFeed] = [assetCoinName];
|
|
71
|
+
} else {
|
|
72
|
+
prev[pythPriceFeed].push(assetCoinName);
|
|
73
|
+
}
|
|
74
|
+
return prev;
|
|
75
|
+
},
|
|
76
|
+
{} as Record<string, SupportAssetCoins[]>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Fetch multiple objects at once to save rpc calls
|
|
80
|
+
const priceFeedObjects = await query.cache.queryGetObjects(
|
|
81
|
+
Object.keys(pythPriceFeedIds),
|
|
82
|
+
{ showContent: true }
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const assetToPriceFeedMapping = priceFeedObjects.reduce(
|
|
86
|
+
(prev, priceFeedObject) => {
|
|
87
|
+
pythPriceFeedIds[priceFeedObject.objectId].forEach((assetCoinName) => {
|
|
88
|
+
prev[assetCoinName] = priceFeedObject;
|
|
89
|
+
});
|
|
90
|
+
return prev;
|
|
91
|
+
},
|
|
92
|
+
{} as Record<SupportAssetCoins, SuiObjectData>
|
|
93
|
+
);
|
|
94
|
+
|
|
64
95
|
return (
|
|
65
96
|
await Promise.all(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
Object.entries(assetToPriceFeedMapping).map(
|
|
98
|
+
async ([assetCoinName, priceFeedObject]) => ({
|
|
99
|
+
coinName: assetCoinName,
|
|
100
|
+
price: await getPythPrice(
|
|
101
|
+
query,
|
|
102
|
+
assetCoinName as SupportAssetCoins,
|
|
103
|
+
priceFeedObject
|
|
104
|
+
),
|
|
105
|
+
})
|
|
106
|
+
)
|
|
70
107
|
)
|
|
71
108
|
).reduce(
|
|
72
109
|
(prev, curr) => {
|
|
73
|
-
prev[curr.coinName] = curr.price;
|
|
110
|
+
prev[curr.coinName as SupportAssetCoins] = curr.price;
|
|
74
111
|
return prev;
|
|
75
112
|
},
|
|
76
113
|
{} as Record<SupportAssetCoins, number>
|
package/src/types/model.ts
CHANGED
|
@@ -41,7 +41,9 @@ export type ScallopBuilderParams = ScallopParams & {
|
|
|
41
41
|
pythEndpoints?: string[];
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export type ScallopQueryParams = ScallopParams
|
|
44
|
+
export type ScallopQueryParams = ScallopParams & {
|
|
45
|
+
walletAddress?: string;
|
|
46
|
+
};
|
|
45
47
|
|
|
46
48
|
export type ScallopUtilsParams = ScallopParams & {
|
|
47
49
|
pythEndpoints?: string[];
|
package/src/utils/query.ts
CHANGED
|
@@ -512,23 +512,25 @@ export const calculateBorrowIncentivePoolPointData = (
|
|
|
512
512
|
.multipliedBy(rewardCoinPrice);
|
|
513
513
|
|
|
514
514
|
const weightScale = BigNumber(1_000_000_000_000);
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
515
|
+
|
|
516
|
+
const rewardRate =
|
|
517
|
+
rewardValueForYear
|
|
518
|
+
.multipliedBy(
|
|
519
|
+
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
520
|
+
weightScale
|
|
521
|
+
)
|
|
519
522
|
)
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
523
|
+
.dividedBy(weightedStakedValue)
|
|
524
|
+
.isFinite() && parsedBorrowIncentivePoolPointData.points > 0
|
|
525
|
+
? rewardValueForYear
|
|
526
|
+
.multipliedBy(
|
|
527
|
+
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
528
|
+
weightScale
|
|
529
|
+
)
|
|
527
530
|
)
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
: Infinity;
|
|
531
|
+
.dividedBy(weightedStakedValue)
|
|
532
|
+
.toNumber()
|
|
533
|
+
: Infinity;
|
|
532
534
|
|
|
533
535
|
return {
|
|
534
536
|
distributedPointPerSec: distributedPointPerSec.toNumber(),
|