@scallop-io/sui-scallop-sdk 0.47.4 → 0.47.6

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.
@@ -272,18 +272,13 @@ export const getStakeAccounts = async (
272
272
  }
273
273
  } while (hasNextPage);
274
274
 
275
- const stakeAccounts: StakeAccounts = {
276
- susdc: [],
277
- sweth: [],
278
- ssui: [],
279
- swusdc: [],
280
- swusdt: [],
281
- scetus: [],
282
- safsui: [],
283
- shasui: [],
284
- svsui: [],
285
- // ssca: [],
286
- };
275
+ const stakeAccounts: StakeAccounts = SUPPORT_SPOOLS.reduce(
276
+ (acc, stakeName) => {
277
+ acc[stakeName] = [];
278
+ return acc;
279
+ },
280
+ {} as StakeAccounts
281
+ );
287
282
 
288
283
  const stakeMarketCoinTypes: Record<SupportStakeMarketCoins, string> =
289
284
  Object.keys(stakeAccounts).reduce(
@@ -300,6 +295,16 @@ export const getStakeAccounts = async (
300
295
  {} as Record<SupportStakeMarketCoins, string>
301
296
  );
302
297
 
298
+ // Reverse the mapping
299
+ const reversedStakeMarketCoinTypes: Record<string, SupportStakeMarketCoins> =
300
+ Object.entries(stakeMarketCoinTypes).reduce(
301
+ (reversedTypes, [key, value]) => {
302
+ reversedTypes[value] = key as SupportStakeMarketCoins;
303
+ return reversedTypes;
304
+ },
305
+ {} as Record<string, SupportStakeMarketCoins>
306
+ );
307
+
303
308
  const stakeObjectIds: string[] = stakeObjectsResponse
304
309
  .map((ref: any) => ref?.data?.objectId)
305
310
  .filter((id: any) => id !== undefined);
@@ -318,98 +323,30 @@ export const getStakeAccounts = async (
318
323
  const index = Number(fields.index);
319
324
  const points = Number(fields.points);
320
325
  const totalPoints = Number(fields.total_points);
321
- if (normalizeStructTag(type) === stakeMarketCoinTypes.sweth) {
322
- stakeAccounts.sweth.push({
323
- id,
324
- type: normalizeStructTag(type),
325
- stakePoolId,
326
- stakeType: normalizeStructTag(stakeType),
327
- staked,
328
- index,
329
- points,
330
- totalPoints,
331
- });
332
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.ssui) {
333
- stakeAccounts.ssui.push({
334
- id,
335
- type: normalizeStructTag(type),
336
- stakePoolId,
337
- stakeType: normalizeStructTag(stakeType),
338
- staked,
339
- index,
340
- points,
341
- totalPoints,
342
- });
343
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.swusdc) {
344
- stakeAccounts.swusdc.push({
345
- id,
346
- type: normalizeStructTag(type),
347
- stakePoolId,
348
- stakeType: normalizeStructTag(stakeType),
349
- staked,
350
- index,
351
- points,
352
- totalPoints,
353
- });
354
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.swusdt) {
355
- stakeAccounts.swusdt.push({
356
- id,
357
- type: normalizeStructTag(type),
358
- stakePoolId,
359
- stakeType: normalizeStructTag(stakeType),
360
- staked,
361
- index,
362
- points,
363
- totalPoints,
364
- });
365
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.scetus) {
366
- stakeAccounts.scetus.push({
367
- id,
368
- type: normalizeStructTag(type),
369
- stakePoolId,
370
- stakeType: normalizeStructTag(stakeType),
371
- staked,
372
- index,
373
- points,
374
- totalPoints,
375
- });
376
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.safsui) {
377
- stakeAccounts.safsui.push({
378
- id,
379
- type: normalizeStructTag(type),
380
- stakePoolId,
381
- stakeType: normalizeStructTag(stakeType),
382
- staked,
383
- index,
384
- points,
385
- totalPoints,
386
- });
387
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.shasui) {
388
- stakeAccounts.shasui.push({
389
- id,
390
- type: normalizeStructTag(type),
391
- stakePoolId,
392
- stakeType: normalizeStructTag(stakeType),
393
- staked,
394
- index,
395
- points,
396
- totalPoints,
397
- });
398
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.svsui) {
399
- stakeAccounts.svsui.push({
400
- id,
401
- type: normalizeStructTag(type),
402
- stakePoolId,
403
- stakeType: normalizeStructTag(stakeType),
404
- staked,
405
- index,
406
- points,
407
- totalPoints,
408
- });
409
- } else if (normalizeStructTag(type) === stakeMarketCoinTypes.susdc) {
410
- stakeAccounts.susdc.push({
326
+
327
+ const stakeMarketCoinTypeMap: Record<
328
+ SupportStakeMarketCoins,
329
+ StakeAccounts[SupportStakeMarketCoins]
330
+ > = {
331
+ sweth: stakeAccounts.sweth,
332
+ ssui: stakeAccounts.ssui,
333
+ swusdc: stakeAccounts.swusdc,
334
+ swusdt: stakeAccounts.swusdt,
335
+ scetus: stakeAccounts.scetus,
336
+ safsui: stakeAccounts.safsui,
337
+ shasui: stakeAccounts.shasui,
338
+ svsui: stakeAccounts.svsui,
339
+ susdc: stakeAccounts.susdc,
340
+ };
341
+
342
+ const normalizedType = normalizeStructTag(type);
343
+ const stakeAccountArray =
344
+ stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
345
+
346
+ if (stakeAccountArray) {
347
+ stakeAccountArray.push({
411
348
  id,
412
- type: normalizeStructTag(type),
349
+ type: normalizedType,
413
350
  stakePoolId,
414
351
  stakeType: normalizeStructTag(stakeType),
415
352
  staked,
@@ -8,6 +8,8 @@ import {
8
8
  SUPPORT_BORROW_INCENTIVE_POOLS,
9
9
  SUPPORT_BORROW_INCENTIVE_REWARDS,
10
10
  SUPPORT_SCOIN,
11
+ SUPPORT_SUI_BRIDGE,
12
+ SUPPORT_WORMHOLE,
11
13
  } from '../../constants';
12
14
 
13
15
  type ParseMarketCoins<T extends string> = `s${T}`;
@@ -29,6 +31,8 @@ export type SupportMarketCoins =
29
31
  | ParseMarketCoins<SupportPoolCoins>
30
32
  | SupportStakeMarketCoins;
31
33
  export type SupportStakeMarketCoins = (typeof SUPPORT_SPOOLS)[number];
34
+ export type SupportSuiBridgeCoins = (typeof SUPPORT_SUI_BRIDGE)[number];
35
+ export type SupportWormholeCoins = (typeof SUPPORT_WORMHOLE)[number];
32
36
  export type SupportStakeCoins = Extract<
33
37
  SupportPoolCoins,
34
38
  ParseCoins<SupportStakeMarketCoins>
@@ -7,6 +7,7 @@ import {
7
7
  SupportBorrowIncentiveCoins,
8
8
  SupportBorrowIncentiveRewardCoins,
9
9
  SupportSCoin,
10
+ SupportSuiBridgeCoins,
10
11
  } from './common';
11
12
 
12
13
  export type Coins = {
@@ -33,6 +34,10 @@ export type StakeRewardCoins = {
33
34
  [key in SupportStakeMarketCoins]: SupportStakeRewardCoins;
34
35
  };
35
36
 
37
+ export type SuiBridgeCoins = {
38
+ [K in SupportSuiBridgeCoins]: K;
39
+ };
40
+
36
41
  export type BorrowIncentiveRewardCoins = {
37
42
  [key in SupportBorrowIncentiveCoins]: SupportBorrowIncentiveRewardCoins[];
38
43
  };
@@ -65,3 +70,7 @@ export type WormholeCoinIds = {
65
70
  export type VoloCoinIds = {
66
71
  [key in PickFromUnion<SupportAssetCoins, 'vsui'>]: string;
67
72
  };
73
+
74
+ export type SuiBridgedCoinPackageIds = {
75
+ [key in SupportSuiBridgeCoins]: string;
76
+ };
@@ -12,6 +12,7 @@ import type {
12
12
  ScallopIndexer,
13
13
  } from '../models';
14
14
  import { ScallopCache } from 'src/models/scallopCache';
15
+ import { AddressesInterface } from './address';
15
16
 
16
17
  export type ScallopClientFnReturnType<T extends boolean> = T extends true
17
18
  ? SuiTransactionBlockResponse
@@ -59,10 +60,12 @@ export type ScallopAddressParams = {
59
60
  id: string;
60
61
  auth?: string;
61
62
  network?: NetworkType;
63
+ forceInterface?: Record<NetworkType, AddressesInterface>;
62
64
  };
63
65
 
64
66
  export type ScallopParams = {
65
67
  addressesId?: string;
68
+ forceAddressesInterface?: Record<NetworkType, AddressesInterface>;
66
69
  walletAddress?: string;
67
70
  } & SuiKitParams;
68
71
 
package/src/utils/util.ts CHANGED
@@ -6,12 +6,16 @@ import {
6
6
  MAX_LOCK_DURATION,
7
7
  SUPPORT_BORROW_INCENTIVE_REWARDS,
8
8
  SUPPORT_SCOIN,
9
+ SUPPORT_SUI_BRIDGE,
10
+ SUPPORT_WORMHOLE,
9
11
  } from '../constants';
10
12
  import type { ScallopAddress } from '../models';
11
13
  import type {
12
14
  SupportAssetCoins,
13
15
  SupportCoins,
14
16
  SupportMarketCoins,
17
+ SupportSuiBridgeCoins,
18
+ SupportWormholeCoins,
15
19
  } from '../types';
16
20
 
17
21
  const COIN_SET = Array.from(
@@ -33,11 +37,29 @@ export const isMarketCoin = (
33
37
  );
34
38
  };
35
39
 
36
- export const parseAssetSymbol = (coinName: SupportAssetCoins): string => {
37
- const isWormhole = coinName.charAt(0) === 'w';
38
- if (isWormhole) {
40
+ export const isSuiBridgeAsset = (
41
+ coinName: any
42
+ ): coinName is SupportSuiBridgeCoins => {
43
+ return SUPPORT_SUI_BRIDGE.includes(coinName);
44
+ };
45
+
46
+ export const isWormholeAsset = (
47
+ coinName: any
48
+ ): coinName is SupportWormholeCoins => {
49
+ return SUPPORT_WORMHOLE.includes(coinName);
50
+ };
51
+
52
+ export const parseAssetSymbol = (coinName: SupportCoins): string => {
53
+ if (isWormholeAsset(coinName)) {
39
54
  return `w${coinName.slice(1).toUpperCase()}`;
40
55
  }
56
+ if (isSuiBridgeAsset(coinName)) {
57
+ return `sb${coinName.slice(2).toUpperCase()}`;
58
+ }
59
+ if (isMarketCoin(coinName)) {
60
+ const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
61
+ return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
62
+ }
41
63
  switch (coinName) {
42
64
  case 'afsui':
43
65
  return 'afSUI';