@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.
@@ -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
- '0x56e48a141f20a3a6a6d3fc43e58b01fc63f756c08224870e7890c80ec9d2afee';
7
- const SECONDARY_PRICE_UPDDATE_POLICY =
8
- '0xef4d9430ae42c1b24199ac55e87ddd7262622447ee3c7de8868efe839b3d8705';
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: PRIMARY_PRICE_UPDATE_POLICY,
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: SECONDARY_PRICE_UPDDATE_POLICY,
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
- '0xc22c9d691ee4c780de09db91d8b487d863211ebf08720772144bcf716318826c';
48
- const SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID =
49
- '0x3b184ff859f5de30eeaf186898e5224925be6bb6d2baa74347ef471a8cd1c0d3';
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 (ruleType === 'primary' && !PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID) {
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 (ruleType === 'secondary' && !SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID) {
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, 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 assetPrimaryOracles = {} as Record<string, string[]>;
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
- ? PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID
78
- : SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID,
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 (!assetPrimaryOracles[assetName]) {
101
- assetPrimaryOracles[assetName] = [];
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
- assetPrimaryOracles[assetName].push(
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 assetPrimaryOracles;
128
+ return assetOracles;
121
129
  };
@@ -1,5 +1,4 @@
1
- const _SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
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
- } & { xOracle: string; xOracleCap: string };
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,
@@ -39,6 +39,7 @@ export type Whitelist = {
39
39
  wormhole: Set<string>;
40
40
  oracles: Set<string>;
41
41
  borrowIncentiveRewards: Set<string>;
42
+ rewardsAsPoint: Set<string>;
42
43
  pythEndpoints: Set<string>;
43
44
  deprecated: Set<string>;
44
45
  };
@@ -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: string[];
3
- secondary: string[];
5
+ primary: SupportOracleType[];
6
+ secondary: SupportOracleType[];
4
7
  };
5
8
  export type xOracleRuleType = keyof xOracleRules;
6
9
 
@@ -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 = {
@@ -114,6 +114,7 @@ export type ObligationBorrowIcentiveReward = {
114
114
  symbol: string;
115
115
  coinDecimal: number;
116
116
  coinPrice: number;
117
+ weightedBorrowAmount: number;
117
118
  availableClaimCoin: number;
118
119
  availableClaimAmount: number;
119
120
  boostValue: number;
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { normalizeStructTag, parseStructTag } from '@mysten/sui/utils';
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 = parseStructTag(
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