@scallop-io/sui-scallop-sdk 1.3.3 → 1.3.4-alpha.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/constants/coinGecko.d.ts +2 -0
- package/dist/constants/index.d.ts +7 -0
- package/dist/constants/poolAddress.d.ts +5 -0
- package/dist/constants/pyth.d.ts +2 -0
- package/dist/constants/queryKeys.d.ts +2 -1
- package/dist/index.js +1471 -1311
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1463 -1311
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +4 -4
- package/dist/models/scallopUtils.d.ts +6 -1
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/queries/spoolQuery.d.ts +1 -1
- package/dist/types/query/core.d.ts +1 -0
- package/dist/types/utils.d.ts +12 -0
- package/dist/utils/util.d.ts +2 -2
- package/package.json +1 -1
- package/src/constants/coinGecko.ts +18 -0
- package/src/constants/enum.ts +11 -4
- package/src/constants/index.ts +7 -0
- package/src/constants/poolAddress.ts +94 -0
- package/src/constants/pyth.ts +19 -0
- package/src/constants/queryKeys.ts +2 -2
- package/src/constants/testAddress.ts +76 -35
- package/src/models/scallopBuilder.ts +2 -3
- package/src/models/scallopQuery.ts +4 -3
- package/src/models/scallopUtils.ts +64 -29
- package/src/queries/coreQuery.ts +222 -216
- package/src/queries/isolatedAsset.ts +4 -4
- package/src/queries/portfolioQuery.ts +6 -9
- package/src/queries/referralQuery.ts +0 -1
- package/src/queries/spoolQuery.ts +1 -1
- package/src/types/query/core.ts +1 -0
- package/src/types/utils.ts +13 -0
- package/src/utils/util.ts +2 -1
- package/dist/models/scallopPrice.d.ts +0 -0
- package/src/models/scallopPrice.ts +0 -0
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
SUPPORT_SCOIN,
|
|
19
19
|
sCoinIds,
|
|
20
20
|
suiBridgeCoins,
|
|
21
|
+
COIN_GECKGO_IDS,
|
|
22
|
+
POOL_ADDRESSES,
|
|
21
23
|
} from '../constants';
|
|
22
24
|
import { getPythPrice, queryObligation } from '../queries';
|
|
23
25
|
import {
|
|
@@ -28,7 +30,7 @@ import {
|
|
|
28
30
|
isSuiBridgeAsset,
|
|
29
31
|
isWormholeAsset,
|
|
30
32
|
} from '../utils';
|
|
31
|
-
import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
33
|
+
import { PYTH_ENDPOINTS, PYTH_FEED_IDS } from 'src/constants/pyth';
|
|
32
34
|
import { ScallopCache } from './scallopCache';
|
|
33
35
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
34
36
|
import type {
|
|
@@ -45,6 +47,7 @@ import type {
|
|
|
45
47
|
ScallopUtilsInstanceParams,
|
|
46
48
|
SupportSuiBridgeCoins,
|
|
47
49
|
SupportWormholeCoins,
|
|
50
|
+
PoolAddressInfo,
|
|
48
51
|
} from '../types';
|
|
49
52
|
import { queryKeys } from 'src/constants';
|
|
50
53
|
import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
@@ -129,10 +132,9 @@ export class ScallopUtils {
|
|
|
129
132
|
* @param address - ScallopAddress instance.
|
|
130
133
|
*/
|
|
131
134
|
public async init(force: boolean = false, address?: ScallopAddress) {
|
|
132
|
-
if (
|
|
135
|
+
if (address && !this.address) this.address = address;
|
|
136
|
+
if (force || !this.address.getAddresses()) {
|
|
133
137
|
await this.address.read();
|
|
134
|
-
} else {
|
|
135
|
-
this.address = address;
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
|
|
@@ -553,39 +555,51 @@ export class ScallopUtils {
|
|
|
553
555
|
const priceId = this.address.get(
|
|
554
556
|
`core.coins.${coinName}.oracle.pyth.feed`
|
|
555
557
|
);
|
|
556
|
-
|
|
558
|
+
if (priceId) {
|
|
559
|
+
acc[coinName] = priceId;
|
|
560
|
+
}
|
|
557
561
|
return acc;
|
|
558
562
|
},
|
|
559
563
|
{} as Record<SupportAssetCoins, string>
|
|
560
564
|
);
|
|
561
565
|
|
|
562
566
|
await Promise.allSettled(
|
|
563
|
-
Object.entries(priceIds)
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
567
|
+
Object.entries(priceIds)
|
|
568
|
+
.filter(([_, priceId]) => !!priceId)
|
|
569
|
+
.map(async ([coinName, priceId]) => {
|
|
570
|
+
// console.log({ coinName, priceId, endpoint });
|
|
571
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint);
|
|
572
|
+
try {
|
|
573
|
+
const feed = await this.cache.queryClient.fetchQuery({
|
|
574
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeed(
|
|
575
|
+
priceId,
|
|
576
|
+
endpoint
|
|
577
|
+
),
|
|
578
|
+
queryFn: async () => {
|
|
579
|
+
return (
|
|
580
|
+
(await pythConnection.getLatestPriceFeeds([priceId])) ??
|
|
581
|
+
[]
|
|
582
|
+
);
|
|
583
|
+
},
|
|
579
584
|
});
|
|
580
|
-
|
|
585
|
+
if (feed[0]) {
|
|
586
|
+
const data = parseDataFromPythPriceFeed(
|
|
587
|
+
feed[0],
|
|
588
|
+
this.address
|
|
589
|
+
);
|
|
590
|
+
this._priceMap.set(coinName as SupportAssetCoins, {
|
|
591
|
+
price: data.price,
|
|
592
|
+
publishTime: data.publishTime,
|
|
593
|
+
});
|
|
594
|
+
coinPrices[coinName as SupportAssetCoins] = data.price;
|
|
595
|
+
failedRequests.delete(coinName as SupportAssetCoins); // remove success price feed to prevent duplicate request on the next endpoint
|
|
596
|
+
}
|
|
597
|
+
} catch (e) {
|
|
598
|
+
console.warn(
|
|
599
|
+
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
600
|
+
);
|
|
581
601
|
}
|
|
582
|
-
|
|
583
|
-
} catch (e) {
|
|
584
|
-
console.warn(
|
|
585
|
-
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
})
|
|
602
|
+
})
|
|
589
603
|
);
|
|
590
604
|
if (failedRequests.size === 0) break;
|
|
591
605
|
}
|
|
@@ -670,4 +684,25 @@ export class ScallopUtils {
|
|
|
670
684
|
}
|
|
671
685
|
return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
|
|
672
686
|
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Get detailed contract address and price id information for supported pool in Scallop
|
|
690
|
+
* @returns Supported pool informations
|
|
691
|
+
*/
|
|
692
|
+
public getSupportedPoolAddresses(): PoolAddressInfo[] {
|
|
693
|
+
return SUPPORT_POOLS.map((poolName) => {
|
|
694
|
+
const sCoinName = this.parseSCoinName(poolName)!;
|
|
695
|
+
return {
|
|
696
|
+
name: this.parseSymbol(poolName),
|
|
697
|
+
coingeckoId: COIN_GECKGO_IDS[poolName],
|
|
698
|
+
decimal: coinDecimals[poolName],
|
|
699
|
+
pythFeedId: PYTH_FEED_IDS[poolName],
|
|
700
|
+
...POOL_ADDRESSES[poolName],
|
|
701
|
+
sCoinAddress: sCoinIds[sCoinName],
|
|
702
|
+
marketCoinAddress: this.parseMarketCoinType(poolName),
|
|
703
|
+
coinAddress: this.parseCoinType(poolName),
|
|
704
|
+
sCoinName: sCoinName ? this.parseSymbol(sCoinName) : undefined,
|
|
705
|
+
};
|
|
706
|
+
});
|
|
707
|
+
}
|
|
673
708
|
}
|