@scallop-io/sui-scallop-sdk 2.0.0-alpha.1 → 2.0.0-alpha.10
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 +71 -11
- package/dist/index.d.ts +71 -11
- package/dist/index.js +16 -16
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +33 -33
- package/src/builders/{oracle.ts → oracles/index.ts} +47 -45
- package/src/builders/oracles/pyth.ts +44 -0
- package/src/builders/oracles/switchboard.ts +270 -0
- package/src/constants/testAddress.ts +36 -487
- package/src/models/scallopAddress.ts +10 -1
- package/src/models/scallopBuilder.ts +4 -6
- package/src/models/scallopCache.ts +2 -2
- package/src/models/scallopClient.ts +8 -11
- package/src/models/scallopConstants.ts +94 -36
- package/src/models/scallopQuery.ts +18 -16
- package/src/models/scallopUtils.ts +14 -8
- package/src/queries/borrowIncentiveQuery.ts +4 -2
- package/src/queries/coreQuery.ts +4 -2
- package/src/queries/index.ts +1 -0
- package/src/queries/poolAddressesQuery.ts +31 -12
- package/src/queries/portfolioQuery.ts +4 -12
- package/src/queries/switchboardQuery.ts +64 -0
- package/src/queries/xOracleQuery.ts +29 -21
- package/src/types/address.ts +11 -3
- package/src/types/constant/common.ts +1 -0
- package/src/types/constant/xOracle.ts +5 -2
- package/src/types/model.ts +2 -0
- package/src/types/query/portfolio.ts +1 -0
- package/src/utils/query.ts +3 -4
- package/src/models/scallopPrice.ts +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ScallopQuery } from 'src/models';
|
|
2
|
+
|
|
3
|
+
export const getOnDemandAggObjectIds = async (
|
|
4
|
+
query: ScallopQuery,
|
|
5
|
+
coinNames: string[],
|
|
6
|
+
switchboardRegistryTableId: string = query.address.get(
|
|
7
|
+
'core.oracles.switchboard.registryTableId'
|
|
8
|
+
)
|
|
9
|
+
): Promise<string[]> => {
|
|
10
|
+
const missingAgg: Array<{
|
|
11
|
+
idx: number;
|
|
12
|
+
coinName: string;
|
|
13
|
+
}> = [];
|
|
14
|
+
|
|
15
|
+
// Check if Aggregator is already registered in Address API
|
|
16
|
+
const registeredAggs = coinNames.map((coinName, idx) => {
|
|
17
|
+
const registeredAgg = query.utils.address.get(
|
|
18
|
+
`core.coins.${coinName}.oracle.switchboard`
|
|
19
|
+
);
|
|
20
|
+
if (registeredAgg) {
|
|
21
|
+
return registeredAgg;
|
|
22
|
+
} else {
|
|
23
|
+
missingAgg.push({
|
|
24
|
+
idx,
|
|
25
|
+
coinName,
|
|
26
|
+
});
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (missingAgg.length === 0) return registeredAggs;
|
|
32
|
+
|
|
33
|
+
// If not, query from the registry table
|
|
34
|
+
const missingCoinNames = missingAgg.map((agg) => agg.coinName);
|
|
35
|
+
const coinTypes = missingCoinNames.map((coinName) => {
|
|
36
|
+
const coinType = query.utils.parseCoinType(coinName);
|
|
37
|
+
if (!coinType) throw new Error(`Invalid coin name: ${coinName}`);
|
|
38
|
+
return coinType;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await Promise.all(
|
|
42
|
+
coinTypes.map(async (coinType, idx) => {
|
|
43
|
+
const dfName = {
|
|
44
|
+
type: '0x1::type_name::TypeName',
|
|
45
|
+
value: {
|
|
46
|
+
name: coinType.slice(2),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const resp = await query.cache.queryGetDynamicFieldObject({
|
|
51
|
+
parentId: switchboardRegistryTableId,
|
|
52
|
+
name: dfName,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (!resp?.data?.content || resp.data.content.dataType !== 'moveObject')
|
|
56
|
+
throw new Error(`No on-demand aggregator found for ${coinType}`);
|
|
57
|
+
|
|
58
|
+
const content = resp.data.content;
|
|
59
|
+
registeredAggs[idx] = (content.fields as any).value;
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return registeredAggs;
|
|
64
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SuiObjectResponse } from '@mysten/sui/client';
|
|
2
2
|
import { ScallopAddress, ScallopUtils } from 'src/models';
|
|
3
|
-
import { xOracleRuleType } from 'src/types';
|
|
3
|
+
import { SupportOracleType, xOracleRuleType } from 'src/types';
|
|
4
4
|
|
|
5
|
-
const PRIMARY_PRICE_UPDATE_POLICY =
|
|
6
|
-
|
|
7
|
-
const SECONDARY_PRICE_UPDDATE_POLICY =
|
|
8
|
-
|
|
5
|
+
// const PRIMARY_PRICE_UPDATE_POLICY =
|
|
6
|
+
// '0x56e48a141f20a3a6a6d3fc43e58b01fc63f756c08224870e7890c80ec9d2afee';
|
|
7
|
+
// const SECONDARY_PRICE_UPDDATE_POLICY =
|
|
8
|
+
// '0xef4d9430ae42c1b24199ac55e87ddd7262622447ee3c7de8868efe839b3d8705';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Query the price update policy table ids. Usually the value for these table will be constant.
|
|
@@ -22,14 +22,14 @@ export const getPriceUpdatePolicies = async (
|
|
|
22
22
|
const [primaryPriceUpdatePolicyTable, secondaryPriceUpdatePolicyTable] =
|
|
23
23
|
await Promise.all([
|
|
24
24
|
address.cache.queryGetDynamicFieldObject({
|
|
25
|
-
parentId:
|
|
25
|
+
parentId: address.get('core.oracles.primaryPriceUpdatePolicyObject'),
|
|
26
26
|
name: {
|
|
27
27
|
type: priceUpdatePolicyRulesKeyType,
|
|
28
28
|
value: { dummy_field: false },
|
|
29
29
|
},
|
|
30
30
|
}),
|
|
31
31
|
address.cache.queryGetDynamicFieldObject({
|
|
32
|
-
parentId:
|
|
32
|
+
parentId: address.get('core.oracles.secondaryPriceUpdatePolicyObject'),
|
|
33
33
|
name: {
|
|
34
34
|
type: priceUpdatePolicyRulesKeyType,
|
|
35
35
|
value: { dummy_field: false },
|
|
@@ -43,39 +43,47 @@ export const getPriceUpdatePolicies = async (
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
47
|
-
|
|
48
|
-
const SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
49
|
-
|
|
46
|
+
// const PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
47
|
+
// '0xc22c9d691ee4c780de09db91d8b487d863211ebf08720772144bcf716318826c';
|
|
48
|
+
// const SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
49
|
+
// '0x3b184ff859f5de30eeaf186898e5224925be6bb6d2baa74347ef471a8cd1c0d3';
|
|
50
50
|
|
|
51
51
|
export const getAssetOracles = async (
|
|
52
52
|
utils: ScallopUtils,
|
|
53
53
|
ruleType: xOracleRuleType
|
|
54
54
|
): Promise<Record<string, string[]> | null> => {
|
|
55
|
-
if (
|
|
55
|
+
if (
|
|
56
|
+
ruleType === 'primary' &&
|
|
57
|
+
!utils.address.get('core.oracles.primaryPriceUpdatePolicyVecsetId')
|
|
58
|
+
) {
|
|
56
59
|
console.error('Primary price update policy vecset id is not set');
|
|
57
60
|
return null;
|
|
58
61
|
}
|
|
59
|
-
if (
|
|
62
|
+
if (
|
|
63
|
+
ruleType === 'secondary' &&
|
|
64
|
+
!utils.address.get('core.oracles.secondaryPriceUpdatePolicyVecsetId')
|
|
65
|
+
) {
|
|
60
66
|
console.error('Secondary price update policy vecset id is not set');
|
|
61
67
|
return null;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
const ruleTypeNameToOracleType: Record<string,
|
|
70
|
+
const ruleTypeNameToOracleType: Record<string, SupportOracleType> = {
|
|
65
71
|
[`${utils.address.get('core.packages.pyth.object')}::rule::Rule`]: 'pyth',
|
|
66
72
|
[`${utils.address.get('core.packages.supra.object')}::rule::Rule`]: 'supra',
|
|
67
73
|
[`${utils.address.get('core.packages.switchboard.object')}::rule::Rule`]:
|
|
68
74
|
'switchboard',
|
|
69
75
|
};
|
|
70
76
|
|
|
71
|
-
const
|
|
77
|
+
const assetOracles = {} as Record<string, SupportOracleType[]>;
|
|
72
78
|
let cursor = null;
|
|
73
79
|
do {
|
|
74
80
|
const response = await utils.cache.queryGetDynamicFields({
|
|
75
81
|
parentId:
|
|
76
82
|
ruleType === 'primary'
|
|
77
|
-
?
|
|
78
|
-
:
|
|
83
|
+
? utils.address.get('core.oracles.primaryPriceUpdatePolicyVecsetId')
|
|
84
|
+
: utils.address.get(
|
|
85
|
+
'core.oracles.secondaryPriceUpdatePolicyVecsetId'
|
|
86
|
+
),
|
|
79
87
|
cursor,
|
|
80
88
|
limit: 10,
|
|
81
89
|
});
|
|
@@ -97,8 +105,8 @@ export const getAssetOracles = async (
|
|
|
97
105
|
|
|
98
106
|
const assetName = utils.parseCoinNameFromType(`0x${typeName}`);
|
|
99
107
|
if (!assetName) throw new Error(`Invalid asset name: ${assetName}`);
|
|
100
|
-
if (!
|
|
101
|
-
|
|
108
|
+
if (!assetOracles[assetName]) {
|
|
109
|
+
assetOracles[assetName] = [];
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
const value = fields.value as {
|
|
@@ -109,7 +117,7 @@ export const getAssetOracles = async (
|
|
|
109
117
|
};
|
|
110
118
|
|
|
111
119
|
value.fields.contents.forEach((content) => {
|
|
112
|
-
|
|
120
|
+
assetOracles[assetName].push(
|
|
113
121
|
ruleTypeNameToOracleType[`0x${content.fields.name}`]
|
|
114
122
|
);
|
|
115
123
|
});
|
|
@@ -117,5 +125,5 @@ export const getAssetOracles = async (
|
|
|
117
125
|
if (!hasNextPage) break;
|
|
118
126
|
} while (cursor);
|
|
119
127
|
|
|
120
|
-
return
|
|
128
|
+
return assetOracles;
|
|
121
129
|
};
|
package/src/types/address.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type SupportOracleType = (typeof _SUPPORT_ORACLES)[number];
|
|
1
|
+
import { _SUPPORT_ORACLES, SupportOracleType } from './constant/xOracle';
|
|
3
2
|
|
|
4
3
|
export interface AddressesInterface {
|
|
5
4
|
core: {
|
|
@@ -46,6 +45,8 @@ export interface AddressesInterface {
|
|
|
46
45
|
? {
|
|
47
46
|
registry: string;
|
|
48
47
|
registryCap: string;
|
|
48
|
+
registryTableId: string;
|
|
49
|
+
state: string;
|
|
49
50
|
}
|
|
50
51
|
: K extends (typeof _SUPPORT_ORACLES)[2]
|
|
51
52
|
? {
|
|
@@ -56,7 +57,14 @@ export interface AddressesInterface {
|
|
|
56
57
|
wormholeState: string;
|
|
57
58
|
}
|
|
58
59
|
: never;
|
|
59
|
-
} & {
|
|
60
|
+
} & {
|
|
61
|
+
xOracle: string;
|
|
62
|
+
xOracleCap: string;
|
|
63
|
+
primaryPriceUpdatePolicyObject: string;
|
|
64
|
+
secondaryPriceUpdatePolicyObject: string;
|
|
65
|
+
primaryPriceUpdatePolicyVecsetId: string;
|
|
66
|
+
secondaryPriceUpdatePolicyVecsetId: string;
|
|
67
|
+
};
|
|
60
68
|
packages: Partial<
|
|
61
69
|
Record<
|
|
62
70
|
string,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export const _SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
|
|
2
|
+
export type SupportOracleType = (typeof _SUPPORT_ORACLES)[number];
|
|
3
|
+
|
|
1
4
|
export type xOracleRules = {
|
|
2
|
-
primary:
|
|
3
|
-
secondary:
|
|
5
|
+
primary: SupportOracleType[];
|
|
6
|
+
secondary: SupportOracleType[];
|
|
4
7
|
};
|
|
5
8
|
export type xOracleRuleType = keyof xOracleRules;
|
|
6
9
|
|
package/src/types/model.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type ScallopClientVeScaReturnType<T extends boolean> = T extends true
|
|
|
28
28
|
|
|
29
29
|
export type ScallopBaseInstanceParams = {
|
|
30
30
|
suiKit?: SuiKit;
|
|
31
|
+
cache?: ScallopCache;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type ScallopCacheInstanceParams = ScallopBaseInstanceParams & {
|
|
@@ -40,6 +41,7 @@ export type ScallopAddressInstanceParams = ScallopBaseInstanceParams & {
|
|
|
40
41
|
|
|
41
42
|
export type ScallopConstantsInstanceParams = {
|
|
42
43
|
address?: ScallopAddress;
|
|
44
|
+
cache?: ScallopCache;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
export type ScallopIndexerInstanceParams = {
|
package/src/utils/query.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { normalizeStructTag
|
|
2
|
+
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
3
3
|
import type { ScallopUtils } from '../models';
|
|
4
4
|
import type {
|
|
5
5
|
OriginMarketPoolData,
|
|
@@ -581,6 +581,7 @@ export const parseOriginBorrowIncentiveAccountPoolPointData = (
|
|
|
581
581
|
* @return Parsed borrow incentive account data
|
|
582
582
|
*/
|
|
583
583
|
export const parseOriginBorrowIncentiveAccountData = (
|
|
584
|
+
utils: ScallopUtils,
|
|
584
585
|
originBorrowIncentiveAccountData: OriginBorrowIncentiveAccountData
|
|
585
586
|
): ParsedBorrowIncentiveAccountData => {
|
|
586
587
|
return {
|
|
@@ -591,9 +592,7 @@ export const parseOriginBorrowIncentiveAccountData = (
|
|
|
591
592
|
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
592
593
|
(acc, point) => {
|
|
593
594
|
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
594
|
-
const name =
|
|
595
|
-
parsed.pointType
|
|
596
|
-
).name.toLowerCase() as string;
|
|
595
|
+
const name = utils.parseCoinNameFromType(parsed.pointType);
|
|
597
596
|
acc[name] = parsed;
|
|
598
597
|
return acc;
|
|
599
598
|
},
|
|
File without changes
|