@subwallet/extension-base 1.1.52-0 → 1.1.53-beta.0

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.
Files changed (107) hide show
  1. package/background/KoniTypes.d.ts +9 -1
  2. package/background/KoniTypes.js +1 -0
  3. package/background/errors/SwapError.d.ts +6 -0
  4. package/background/errors/SwapError.js +57 -0
  5. package/background/errors/TransactionError.js +9 -0
  6. package/cjs/background/KoniTypes.js +1 -0
  7. package/cjs/background/errors/SwapError.js +64 -0
  8. package/cjs/background/errors/TransactionError.js +9 -0
  9. package/cjs/koni/api/dotsama/balance.js +464 -0
  10. package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
  11. package/cjs/koni/api/staking/bonding/utils.js +35 -6
  12. package/cjs/koni/background/handlers/Extension.js +85 -0
  13. package/cjs/koni/background/handlers/State.js +25 -5
  14. package/cjs/packageInfo.js +1 -1
  15. package/cjs/services/balance-service/helpers/subscribe/balance.js +140 -0
  16. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  17. package/cjs/services/balance-service/index.js +6 -3
  18. package/cjs/services/chain-service/constants.js +1 -1
  19. package/cjs/services/chain-service/index.js +43 -18
  20. package/cjs/services/chain-service/utils/index.js +7 -2
  21. package/cjs/services/chain-service/utils/patch.js +1 -1
  22. package/cjs/services/chain-service/utils.js +506 -0
  23. package/cjs/services/earning-service/constants/chains.js +4 -2
  24. package/cjs/services/earning-service/handlers/native-staking/astar.js +4 -3
  25. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +22 -3
  26. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
  27. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
  28. package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
  29. package/cjs/services/request-service/handler/ConnectWCRequestHandler.js +0 -1
  30. package/cjs/services/storage-service/index.js +241 -0
  31. package/cjs/services/swap-service/handler/base-handler.js +171 -0
  32. package/cjs/services/swap-service/handler/chainflip-handler.js +407 -0
  33. package/cjs/services/swap-service/handler/hydradx-handler.js +444 -0
  34. package/cjs/services/swap-service/index.js +249 -0
  35. package/cjs/services/swap-service/utils.js +126 -0
  36. package/cjs/services/transaction-service/index.js +20 -0
  37. package/cjs/services/transaction-service/utils.js +6 -0
  38. package/cjs/services/wallet-connect-service/helpers.js +1 -1
  39. package/cjs/services/wallet-connect-service/index.js +19 -0
  40. package/cjs/types/balance.js +1 -0
  41. package/cjs/types/fee/evm.js +1 -0
  42. package/cjs/types/fee/fee.js +70 -0
  43. package/cjs/types/fee/index.js +27 -1
  44. package/cjs/types/service-base.js +1 -0
  45. package/cjs/types/swap/index.js +50 -0
  46. package/cjs/types.js +1 -0
  47. package/cjs/utils/address.js +34 -0
  48. package/cjs/utils/eth/parseTransaction/index.js +1 -1
  49. package/cjs/utils/index.js +12 -0
  50. package/cjs/utils/keyring.js +57 -0
  51. package/cjs/utils/swap.js +78 -0
  52. package/koni/api/staking/bonding/utils.d.ts +3 -1
  53. package/koni/api/staking/bonding/utils.js +32 -6
  54. package/koni/background/handlers/Extension.d.ts +5 -0
  55. package/koni/background/handlers/Extension.js +85 -0
  56. package/koni/background/handlers/State.d.ts +2 -0
  57. package/koni/background/handlers/State.js +26 -6
  58. package/package.json +64 -7
  59. package/packageInfo.js +1 -1
  60. package/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  61. package/services/balance-service/index.js +6 -3
  62. package/services/base/types.d.ts +4 -0
  63. package/services/chain-service/constants.js +1 -1
  64. package/services/chain-service/index.d.ts +4 -0
  65. package/services/chain-service/index.js +24 -0
  66. package/services/chain-service/utils/index.d.ts +6 -5
  67. package/services/chain-service/utils/index.js +5 -2
  68. package/services/chain-service/utils/patch.js +1 -1
  69. package/services/earning-service/constants/chains.d.ts +1 -0
  70. package/services/earning-service/constants/chains.js +1 -0
  71. package/services/earning-service/handlers/native-staking/astar.js +4 -3
  72. package/services/earning-service/handlers/native-staking/relay-chain.js +24 -5
  73. package/services/event-service/types.d.ts +1 -0
  74. package/services/request-service/handler/ConnectWCRequestHandler.js +0 -1
  75. package/services/swap-service/handler/base-handler.d.ts +38 -0
  76. package/services/swap-service/handler/base-handler.js +162 -0
  77. package/services/swap-service/handler/chainflip-handler.d.ts +30 -0
  78. package/services/swap-service/handler/chainflip-handler.js +399 -0
  79. package/services/swap-service/handler/hydradx-handler.d.ts +36 -0
  80. package/services/swap-service/handler/hydradx-handler.js +435 -0
  81. package/services/swap-service/index.d.ts +32 -0
  82. package/services/swap-service/index.js +240 -0
  83. package/services/swap-service/utils.d.ts +18 -0
  84. package/services/swap-service/utils.js +105 -0
  85. package/services/transaction-service/index.js +20 -0
  86. package/services/transaction-service/utils.d.ts +2 -0
  87. package/services/transaction-service/utils.js +6 -2
  88. package/services/wallet-connect-service/helpers.js +1 -1
  89. package/services/wallet-connect-service/index.d.ts +1 -0
  90. package/services/wallet-connect-service/index.js +19 -1
  91. package/types/fee/evm.d.ts +49 -0
  92. package/types/fee/evm.js +1 -0
  93. package/types/fee/fee.d.ts +32 -0
  94. package/types/fee/fee.js +63 -0
  95. package/types/fee/index.d.ts +2 -49
  96. package/types/fee/index.js +5 -1
  97. package/types/service-base.d.ts +10 -0
  98. package/types/service-base.js +1 -0
  99. package/types/swap/index.d.ts +166 -0
  100. package/types/swap/index.js +41 -0
  101. package/types/yield/info/chain/target.d.ts +2 -0
  102. package/types/yield/info/pallet.d.ts +4 -0
  103. package/utils/eth/parseTransaction/index.js +1 -1
  104. package/utils/index.d.ts +1 -0
  105. package/utils/index.js +2 -1
  106. package/utils/swap.d.ts +3 -0
  107. package/utils/swap.js +70 -0
@@ -197,13 +197,13 @@ export function getYieldAvailableActionsByPosition(yieldPosition, yieldPoolInfo,
197
197
  const result = [];
198
198
  if ([YieldPoolType.NATIVE_STAKING, YieldPoolType.NOMINATION_POOL].includes(yieldPoolInfo.type)) {
199
199
  result.push(YieldAction.STAKE);
200
- const bnActiveStake = new BN(yieldPosition.activeStake);
201
- if (yieldPosition.activeStake && bnActiveStake.gt(BN_ZERO)) {
200
+ const bnActiveStake = new BigNumber(yieldPosition.activeStake);
201
+ if (yieldPosition.activeStake && bnActiveStake.gt('0')) {
202
202
  result.push(YieldAction.UNSTAKE);
203
203
  const isAstarNetwork = _STAKING_CHAIN_GROUP.astar.includes(yieldPosition.chain);
204
204
  const isAmplitudeNetwork = _STAKING_CHAIN_GROUP.amplitude.includes(yieldPosition.chain);
205
- const bnUnclaimedReward = new BN(unclaimedReward || '0');
206
- if ((yieldPosition.type === YieldPoolType.NOMINATION_POOL || isAmplitudeNetwork) && bnUnclaimedReward.gt(BN_ZERO) || isAstarNetwork) {
205
+ const bnUnclaimedReward = new BigNumber(unclaimedReward || '0');
206
+ if ((yieldPosition.type === YieldPoolType.NOMINATION_POOL || isAmplitudeNetwork) && bnUnclaimedReward.gt('0') || isAstarNetwork) {
207
207
  result.push(YieldAction.CLAIM_REWARD);
208
208
  }
209
209
  }
@@ -216,8 +216,8 @@ export function getYieldAvailableActionsByPosition(yieldPosition, yieldPoolInfo,
216
216
  }
217
217
  } else if (yieldPoolInfo.type === YieldPoolType.LIQUID_STAKING) {
218
218
  result.push(YieldAction.START_EARNING);
219
- const activeBalance = new BN(yieldPosition.activeStake || '0');
220
- if (activeBalance.gt(BN_ZERO)) {
219
+ const activeBalance = new BigNumber(yieldPosition.activeStake);
220
+ if (activeBalance.gt('0')) {
221
221
  result.push(YieldAction.UNSTAKE);
222
222
  }
223
223
  const hasWithdrawal = yieldPosition.unstakings.some(unstakingInfo => unstakingInfo.status === UnstakingStatus.CLAIMABLE);
@@ -350,6 +350,32 @@ export function getSupportedDaysByHistoryDepth(erasPerDay, maxSupportedEras) {
350
350
  return 15;
351
351
  }
352
352
  }
353
+ export function getValidatorPointsMap(eraRewardMap) {
354
+ // mapping store validator and totalPoints
355
+ const validatorTotalPointsMap = {};
356
+ Object.values(eraRewardMap).forEach(info => {
357
+ const individual = info.individual;
358
+ Object.entries(individual).forEach(([validator, rawPoints]) => {
359
+ const points = rawPoints.replaceAll(',', '');
360
+ if (!validatorTotalPointsMap[validator]) {
361
+ validatorTotalPointsMap[validator] = new BigNumber(points);
362
+ } else {
363
+ validatorTotalPointsMap[validator] = validatorTotalPointsMap[validator].plus(points);
364
+ }
365
+ });
366
+ });
367
+ return validatorTotalPointsMap;
368
+ }
369
+ export function getTopValidatorByPoints(validatorPointsList) {
370
+ const sortValidatorPointsList = Object.fromEntries(Object.entries(validatorPointsList).sort((a, b) => a[1].minus(b[1]).toNumber()).reverse());
371
+
372
+ // keep 50% first validator
373
+ const entries = Object.entries(sortValidatorPointsList);
374
+ const endIndex = Math.ceil(entries.length / 2);
375
+ const top50PercentEntries = entries.slice(0, endIndex);
376
+ const top50PercentRecord = Object.fromEntries(top50PercentEntries);
377
+ return Object.keys(top50PercentRecord);
378
+ }
353
379
  export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
354
380
  const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
355
381
  const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);
@@ -237,5 +237,10 @@ export default class KoniExtension {
237
237
  private completeCampaignBanner;
238
238
  private subscribeBuyTokens;
239
239
  private subscribeBuyServices;
240
+ private subscribeSwapPairs;
241
+ private handleSwapRequest;
242
+ private getLatestSwapQuote;
243
+ private validateSwapProcess;
244
+ private handleSwapStep;
240
245
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
241
246
  }
@@ -3943,6 +3943,78 @@ export default class KoniExtension {
3943
3943
 
3944
3944
  /* Buy service */
3945
3945
 
3946
+ /* Swap service */
3947
+ async subscribeSwapPairs(id, port) {
3948
+ const cb = createSubscription(id, port);
3949
+ let ready = false;
3950
+ await this.#koniState.swapService.waitForStarted();
3951
+ const callback = rs => {
3952
+ if (ready) {
3953
+ cb(rs);
3954
+ }
3955
+ };
3956
+ const subscription = this.#koniState.swapService.subscribeSwapPairs(callback);
3957
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
3958
+ port.onDisconnect.addListener(() => {
3959
+ this.cancelSubscription(id);
3960
+ });
3961
+ ready = true;
3962
+ return this.#koniState.swapService.getSwapPairs();
3963
+ }
3964
+ async handleSwapRequest(request) {
3965
+ return this.#koniState.swapService.handleSwapRequest(request);
3966
+ }
3967
+ async getLatestSwapQuote(swapRequest) {
3968
+ return this.#koniState.swapService.getLatestQuotes(swapRequest);
3969
+ }
3970
+ async validateSwapProcess(params) {
3971
+ return this.#koniState.swapService.validateSwapProcess(params);
3972
+ }
3973
+ async handleSwapStep(inputData) {
3974
+ const {
3975
+ address,
3976
+ process,
3977
+ quote,
3978
+ recipient
3979
+ } = inputData;
3980
+ if (!quote || !address || !process) {
3981
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
3982
+ }
3983
+ const isLastStep = inputData.currentStep + 1 === process.steps.length;
3984
+ const swapValidations = await this.#koniState.swapService.validateSwapProcess({
3985
+ address,
3986
+ process,
3987
+ selectedQuote: quote,
3988
+ recipient
3989
+ });
3990
+ if (swapValidations.length > 0) {
3991
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(swapValidations);
3992
+ }
3993
+
3994
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3995
+ const {
3996
+ chainType,
3997
+ extrinsic,
3998
+ extrinsicType,
3999
+ transferNativeAmount,
4000
+ txChain,
4001
+ txData
4002
+ } = await this.#koniState.swapService.handleSwapProcess(inputData);
4003
+ return await this.#koniState.transactionService.handleTransaction({
4004
+ address,
4005
+ chain: txChain,
4006
+ transaction: extrinsic,
4007
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
4008
+ data: txData,
4009
+ extrinsicType,
4010
+ // change this depends on step
4011
+ chainType,
4012
+ resolveOnDone: !isLastStep,
4013
+ transferNativeAmount
4014
+ });
4015
+ }
4016
+ /* Swap service */
4017
+
3946
4018
  // --------------------------------------------------------------
3947
4019
  // eslint-disable-next-line @typescript-eslint/require-await
3948
4020
  async handle(id, type, request, port) {
@@ -4472,6 +4544,19 @@ export default class KoniExtension {
4472
4544
  case 'pri(database.exportJson)':
4473
4545
  return this.#koniState.dbService.getExportJson();
4474
4546
  /* Database */
4547
+
4548
+ /* Swap service */
4549
+ case 'pri(swapService.subscribePairs)':
4550
+ return this.subscribeSwapPairs(id, port);
4551
+ case 'pri(swapService.handleSwapRequest)':
4552
+ return this.handleSwapRequest(request);
4553
+ case 'pri(swapService.getLatestQuote)':
4554
+ return this.getLatestSwapQuote(request);
4555
+ case 'pri(swapService.validateSwapProcess)':
4556
+ return this.validateSwapProcess(request);
4557
+ case 'pri(swapService.handleSwapStep)':
4558
+ return this.handleSwapStep(request);
4559
+ /* Swap service */
4475
4560
  // Default
4476
4561
  default:
4477
4562
  throw new Error(`Unable to handle message of type ${type}`);
@@ -21,6 +21,7 @@ import { AuthUrls, MetaRequest, SignRequest } from '@subwallet/extension-base/se
21
21
  import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
22
22
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
23
23
  import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
24
+ import { SwapService } from '@subwallet/extension-base/services/swap-service';
24
25
  import TransactionService from '@subwallet/extension-base/services/transaction-service';
25
26
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
26
27
  import { BalanceMap, EvmFeeInfo } from '@subwallet/extension-base/types';
@@ -71,6 +72,7 @@ export default class KoniState {
71
72
  readonly buyService: BuyService;
72
73
  readonly earningService: EarningService;
73
74
  readonly feeService: FeeService;
75
+ readonly swapService: SwapService;
74
76
  private generalStatus;
75
77
  private waitSleeping;
76
78
  private waitStarting;
@@ -28,10 +28,11 @@ import SettingService from '@subwallet/extension-base/services/setting-service/S
28
28
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
29
29
  import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
30
30
  import { SUBSCAN_API_CHAIN_MAP } from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
31
+ import { SwapService } from '@subwallet/extension-base/services/swap-service';
31
32
  import TransactionService from '@subwallet/extension-base/services/transaction-service';
32
33
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
33
34
  import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
34
- import { isAccountAll, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
35
+ import { isAccountAll, stripUrl, TARGET_ENV, wait } from '@subwallet/extension-base/utils';
35
36
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
36
37
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
37
38
  import { decodePair } from '@subwallet/keyring/pair/decode';
@@ -104,6 +105,7 @@ export default class KoniState {
104
105
  this.transactionService = new TransactionService(this);
105
106
  this.earningService = new EarningService(this);
106
107
  this.feeService = new FeeService(this);
108
+ this.swapService = new SwapService(this);
107
109
  this.subscription = new KoniSubscription(this, this.dbService);
108
110
  this.cron = new KoniCron(this, this.subscription, this.dbService);
109
111
  this.logger = createLogger('State');
@@ -226,6 +228,7 @@ export default class KoniState {
226
228
  this.eventService.emit('chain.ready', true);
227
229
  await this.balanceService.init();
228
230
  await this.earningService.init();
231
+ await this.swapService.init();
229
232
  this.onReady();
230
233
  this.onAccountAdd();
231
234
  this.onAccountRemove();
@@ -1201,17 +1204,34 @@ export default class KoniState {
1201
1204
  maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
1202
1205
  data: transactionParams.data
1203
1206
  };
1207
+ const getTransactionGas = async () => {
1208
+ try {
1209
+ transaction.gas = await web3.eth.estimateGas({
1210
+ ...transaction
1211
+ });
1212
+ } catch (e) {
1213
+ // @ts-ignore
1214
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1215
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1216
+ }
1217
+ };
1204
1218
 
1205
1219
  // Calculate transaction data
1206
1220
  try {
1207
- transaction.gas = await web3.eth.estimateGas({
1208
- ...transaction
1209
- });
1221
+ await Promise.race([getTransactionGas(), wait(3000).then(async () => {
1222
+ if (!transaction.gas) {
1223
+ await this.chainService.initSingleApi(networkKey);
1224
+ await getTransactionGas();
1225
+ }
1226
+ })]);
1210
1227
  } catch (e) {
1211
1228
  // @ts-ignore
1212
1229
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1213
1230
  throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1214
1231
  }
1232
+ if (!transaction.gas) {
1233
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS);
1234
+ }
1215
1235
  let estimateGas;
1216
1236
 
1217
1237
  // TODO: Review, If not override, transaction maybe fail because fee too low
@@ -1396,7 +1416,7 @@ export default class KoniState {
1396
1416
  // Stopping services
1397
1417
  await Promise.all([this.cron.stop(), this.subscription.stop()]);
1398
1418
  await this.pauseAllNetworks(undefined, 'IDLE mode');
1399
- await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop()]);
1419
+ await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop(), this.swapService.stop()]);
1400
1420
 
1401
1421
  // Complete sleeping
1402
1422
  sleeping.resolve();
@@ -1428,7 +1448,7 @@ export default class KoniState {
1428
1448
  }
1429
1449
 
1430
1450
  // Start services
1431
- await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start()]);
1451
+ await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start(), this.swapService.start()]);
1432
1452
 
1433
1453
  // Complete starting
1434
1454
  starting.resolve();
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.52-0",
20
+ "version": "1.1.53-beta.0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -44,6 +44,11 @@
44
44
  "require": "./cjs/background/errors/ProviderError.js",
45
45
  "default": "./background/errors/ProviderError.js"
46
46
  },
47
+ "./background/errors/SwapError": {
48
+ "types": "./background/errors/SwapError.d.ts",
49
+ "require": "./cjs/background/errors/SwapError.js",
50
+ "default": "./background/errors/SwapError.js"
51
+ },
47
52
  "./background/errors/SWError": {
48
53
  "types": "./background/errors/SWError.d.ts",
49
54
  "require": "./cjs/background/errors/SWError.js",
@@ -1355,6 +1360,31 @@
1355
1360
  "require": "./cjs/services/subscan-service/types.js",
1356
1361
  "default": "./services/subscan-service/types.js"
1357
1362
  },
1363
+ "./services/swap-service": {
1364
+ "types": "./services/swap-service/index.d.ts",
1365
+ "require": "./cjs/services/swap-service/index.js",
1366
+ "default": "./services/swap-service/index.js"
1367
+ },
1368
+ "./services/swap-service/handler/base-handler": {
1369
+ "types": "./services/swap-service/handler/base-handler.d.ts",
1370
+ "require": "./cjs/services/swap-service/handler/base-handler.js",
1371
+ "default": "./services/swap-service/handler/base-handler.js"
1372
+ },
1373
+ "./services/swap-service/handler/chainflip-handler": {
1374
+ "types": "./services/swap-service/handler/chainflip-handler.d.ts",
1375
+ "require": "./cjs/services/swap-service/handler/chainflip-handler.js",
1376
+ "default": "./services/swap-service/handler/chainflip-handler.js"
1377
+ },
1378
+ "./services/swap-service/handler/hydradx-handler": {
1379
+ "types": "./services/swap-service/handler/hydradx-handler.d.ts",
1380
+ "require": "./cjs/services/swap-service/handler/hydradx-handler.js",
1381
+ "default": "./services/swap-service/handler/hydradx-handler.js"
1382
+ },
1383
+ "./services/swap-service/utils": {
1384
+ "types": "./services/swap-service/utils.d.ts",
1385
+ "require": "./cjs/services/swap-service/utils.js",
1386
+ "default": "./services/swap-service/utils.js"
1387
+ },
1358
1388
  "./services/transaction-service": {
1359
1389
  "types": "./services/transaction-service/index.d.ts",
1360
1390
  "require": "./cjs/services/transaction-service/index.js",
@@ -1560,11 +1590,31 @@
1560
1590
  "require": "./cjs/types/fee/index.js",
1561
1591
  "default": "./types/fee/index.js"
1562
1592
  },
1593
+ "./types/fee/evm": {
1594
+ "types": "./types/fee/evm.d.ts",
1595
+ "require": "./cjs/types/fee/evm.js",
1596
+ "default": "./types/fee/evm.js"
1597
+ },
1598
+ "./types/fee/fee": {
1599
+ "types": "./types/fee/fee.d.ts",
1600
+ "require": "./cjs/types/fee/fee.js",
1601
+ "default": "./types/fee/fee.js"
1602
+ },
1563
1603
  "./types/ordinal": {
1564
1604
  "types": "./types/ordinal.d.ts",
1565
1605
  "require": "./cjs/types/ordinal.js",
1566
1606
  "default": "./types/ordinal.js"
1567
1607
  },
1608
+ "./types/service-base": {
1609
+ "types": "./types/service-base.d.ts",
1610
+ "require": "./cjs/types/service-base.js",
1611
+ "default": "./types/service-base.js"
1612
+ },
1613
+ "./types/swap": {
1614
+ "types": "./types/swap/index.d.ts",
1615
+ "require": "./cjs/types/swap/index.js",
1616
+ "default": "./types/swap/index.js"
1617
+ },
1568
1618
  "./types/transaction": {
1569
1619
  "types": "./types/transaction.d.ts",
1570
1620
  "require": "./cjs/types/transaction.js",
@@ -1781,6 +1831,11 @@
1781
1831
  "./utils/staticData/crowdloanFunds.json": "./utils/staticData/crowdloanFunds.json",
1782
1832
  "./utils/staticData/marketingCampaigns.json": "./utils/staticData/marketingCampaigns.json",
1783
1833
  "./utils/staticData/termAndCondition.json": "./utils/staticData/termAndCondition.json",
1834
+ "./utils/swap": {
1835
+ "types": "./utils/swap.d.ts",
1836
+ "require": "./cjs/utils/swap.js",
1837
+ "default": "./utils/swap.js"
1838
+ },
1784
1839
  "./utils/translate": {
1785
1840
  "types": "./utils/translate.d.ts",
1786
1841
  "require": "./cjs/utils/translate.js",
@@ -1791,10 +1846,12 @@
1791
1846
  "@acala-network/api": "^5.0.2",
1792
1847
  "@apollo/client": "^3.7.14",
1793
1848
  "@azns/resolver-core": "^1.4.0",
1849
+ "@chainflip/sdk": "^1.3.0",
1794
1850
  "@equilab/api": "~1.14.25",
1795
1851
  "@ethereumjs/common": "^4.1.0",
1796
1852
  "@ethereumjs/tx": "^5.1.0",
1797
1853
  "@ethersproject/abi": "^5.7.0",
1854
+ "@galacticcouncil/sdk": "^1.2.1",
1798
1855
  "@json-rpc-tools/utils": "^1.7.6",
1799
1856
  "@metamask/safe-event-emitter": "^2.0.0",
1800
1857
  "@metaverse-network-sdk/type-definitions": "^0.0.1-13",
@@ -1816,11 +1873,11 @@
1816
1873
  "@reduxjs/toolkit": "^1.9.1",
1817
1874
  "@sora-substrate/type-definitions": "^1.17.7",
1818
1875
  "@substrate/connect": "^0.7.26",
1819
- "@subwallet/chain-list": "0.2.54",
1820
- "@subwallet/extension-base": "^1.1.52-0",
1821
- "@subwallet/extension-chains": "^1.1.52-0",
1822
- "@subwallet/extension-dapp": "^1.1.52-0",
1823
- "@subwallet/extension-inject": "^1.1.52-0",
1876
+ "@subwallet/chain-list": "0.2.55-beta.3",
1877
+ "@subwallet/extension-base": "^1.1.53-0",
1878
+ "@subwallet/extension-chains": "^1.1.53-0",
1879
+ "@subwallet/extension-dapp": "^1.1.53-0",
1880
+ "@subwallet/extension-inject": "^1.1.53-0",
1824
1881
  "@subwallet/keyring": "^0.1.3",
1825
1882
  "@subwallet/ui-keyring": "^0.1.3",
1826
1883
  "@walletconnect/sign-client": "^2.8.4",
@@ -1857,4 +1914,4 @@
1857
1914
  "web3-eth-contract": "^1.10.0",
1858
1915
  "web3-utils": "^1.10.0"
1859
1916
  }
1860
- }
1917
+ }
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.1.52-0'
10
+ version: '1.1.53-0'
11
11
  };
@@ -90,7 +90,8 @@ const subscribeWithSystemAccountPallet = async ({
90
90
  if (_isSubstrateRelayChain(chainInfo) && substrateApi.query.nominationPools) {
91
91
  var _substrateApi$rx$quer;
92
92
  poolSubscribe = (_substrateApi$rx$quer = substrateApi.rx.query.nominationPools.poolMembers) === null || _substrateApi$rx$quer === void 0 ? void 0 : _substrateApi$rx$quer.multi(addresses);
93
- } else {
93
+ }
94
+ if (!poolSubscribe) {
94
95
  poolSubscribe = new Observable(subscriber => {
95
96
  subscriber.next(addresses.map(() => ({
96
97
  toPrimitive() {
@@ -185,7 +185,8 @@ export class BalanceService {
185
185
  const chainInfoMap = this.state.chainService.getChainInfoMap();
186
186
  const evmApiMap = this.state.chainService.getEvmApiMap();
187
187
  const substrateApiMap = this.state.chainService.getSubstrateApiMap();
188
- const unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
188
+ let unsub = noop;
189
+ unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
189
190
  const rs = result[0];
190
191
  if (rs.tokenSlug === tSlug) {
191
192
  hasError = false;
@@ -197,15 +198,17 @@ export class BalanceService {
197
198
  if (callback) {
198
199
  callback(balance);
199
200
  } else {
201
+ var _unsub;
200
202
  // Auto unsubscribe if no callback
201
- unsub();
203
+ (_unsub = unsub) === null || _unsub === void 0 ? void 0 : _unsub();
202
204
  }
203
205
  resolve([unsub, balance]);
204
206
  }
205
207
  });
206
208
  setTimeout(() => {
207
209
  if (hasError) {
208
- unsub();
210
+ var _unsub2;
211
+ (_unsub2 = unsub) === null || _unsub2 === void 0 ? void 0 : _unsub2();
209
212
  reject(new Error(t('Failed to get balance. Please check your internet connection or change your network endpoint')));
210
213
  }
211
214
  }, 9999);
@@ -1,3 +1,4 @@
1
+ import { OptimalProcessParams, OptimalProcessResult } from '@subwallet/extension-base/types/service-base';
1
2
  import { PromiseHandler } from '@subwallet/extension-base/utils/promise';
2
3
  export declare enum ServiceStatus {
3
4
  NOT_INITIALIZED = "not_initialized",
@@ -32,3 +33,6 @@ export interface CronServiceInterface {
32
33
  startCron: () => Promise<void>;
33
34
  stopCron: () => Promise<void>;
34
35
  }
36
+ export interface ServiceWithProcessInterface {
37
+ generateOptimalProcess(params: OptimalProcessParams): Promise<OptimalProcessResult>;
38
+ }
@@ -28,7 +28,7 @@ export const _BALANCE_CHAIN_GROUP = {
28
28
  kintsugi: ['kintsugi', 'interlay', 'kintsugi_test', 'mangatax_para'],
29
29
  genshiro: ['genshiro_testnet', 'genshiro'],
30
30
  equilibrium_parachain: ['equilibrium_parachain'],
31
- bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude', 'continuum_network'],
31
+ bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'hydradx_rococo', 'pendulum', 'amplitude', 'continuum_network'],
32
32
  statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya'],
33
33
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
34
34
  // perhaps there are some runtime updates
@@ -23,6 +23,7 @@ export declare class ChainService {
23
23
  private assetRegistrySubject;
24
24
  private multiChainAssetMapSubject;
25
25
  private xcmRefMapSubject;
26
+ private swapRefMapSubject;
26
27
  private assetLogoMapSubject;
27
28
  private chainLogoMapSubject;
28
29
  private assetMapPatch;
@@ -31,7 +32,9 @@ export declare class ChainService {
31
32
  private assetSettingSubject;
32
33
  private logger;
33
34
  constructor(dbService: DatabaseService, eventService: EventService);
35
+ subscribeSwapRefMap(): Subject<Record<string, _AssetRef>>;
34
36
  get xcmRefMap(): Record<string, _AssetRef>;
37
+ get swapRefMap(): Record<string, _AssetRef>;
35
38
  getEvmApi(slug: string): import("./handler/EvmApi").EvmApi;
36
39
  getEvmApiMap(): Record<string, import("./handler/EvmApi").EvmApi>;
37
40
  getSubstrateApiMap(): Record<string, import("./handler/SubstrateApi").SubstrateApi>;
@@ -90,6 +93,7 @@ export declare class ChainService {
90
93
  autoEnableTokens(): Promise<void>;
91
94
  handleLatestData(): void;
92
95
  private initApis;
96
+ initSingleApi(slug: string): Promise<boolean>;
93
97
  private initApiForChain;
94
98
  private destroyApiForChain;
95
99
  enableChain(chainSlug: string): Promise<boolean>;
@@ -35,6 +35,7 @@ export class ChainService {
35
35
  assetRegistrySubject = new Subject();
36
36
  multiChainAssetMapSubject = new Subject();
37
37
  xcmRefMapSubject = new Subject();
38
+ swapRefMapSubject = new Subject();
38
39
  assetLogoMapSubject = new BehaviorSubject(AssetLogoMap);
39
40
  chainLogoMapSubject = new BehaviorSubject(ChainLogoMap);
40
41
  assetMapPatch = JSON.stringify({});
@@ -50,6 +51,7 @@ export class ChainService {
50
51
  this.chainStateMapSubject.next(this.dataMap.chainStateMap);
51
52
  this.assetRegistrySubject.next(this.dataMap.assetRegistry);
52
53
  this.xcmRefMapSubject.next(this.xcmRefMap);
54
+ this.swapRefMapSubject.next(this.swapRefMap);
53
55
  if (MODULE_SUPPORT.MANTA_ZK) {
54
56
  console.log('Init Manta ZK');
55
57
  this.mantaChainHandler = new MantaPrivateHandler(dbService);
@@ -58,6 +60,9 @@ export class ChainService {
58
60
  this.evmChainHandler = new EvmChainHandler(this);
59
61
  this.logger = createLogger('chain-service');
60
62
  }
63
+ subscribeSwapRefMap() {
64
+ return this.swapRefMapSubject;
65
+ }
61
66
 
62
67
  // Getter
63
68
  get xcmRefMap() {
@@ -69,6 +74,15 @@ export class ChainService {
69
74
  });
70
75
  return result;
71
76
  }
77
+ get swapRefMap() {
78
+ const result = {};
79
+ Object.entries(this.dataMap.assetRefMap).forEach(([key, assetRef]) => {
80
+ if (assetRef.path === _AssetRefPath.SWAP) {
81
+ result[key] = assetRef;
82
+ }
83
+ });
84
+ return result;
85
+ }
72
86
  getEvmApi(slug) {
73
87
  return this.evmChainHandler.getEvmApiByChain(slug);
74
88
  }
@@ -481,6 +495,7 @@ export class ChainService {
481
495
  });
482
496
  this.dataMap.assetRefMap = updatedAssetRefMap;
483
497
  this.xcmRefMapSubject.next(this.xcmRefMap);
498
+ this.swapRefMapSubject.next(this.swapRefMap);
484
499
  this.logger.log('Finished updating latest asset ref');
485
500
  }
486
501
  handleLatestPriceId(latestPriceIds) {
@@ -594,6 +609,15 @@ export class ChainService {
594
609
  }
595
610
  }));
596
611
  }
612
+ async initSingleApi(slug) {
613
+ const chainInfoMap = this.getChainInfoMap();
614
+ const chainStateMap = this.getChainStateMap();
615
+ if (!chainStateMap[slug].active) {
616
+ return false;
617
+ }
618
+ await this.initApiForChain(chainInfoMap[slug]);
619
+ return true;
620
+ }
597
621
  async initApiForChain(chainInfo) {
598
622
  const {
599
623
  endpoint,
@@ -51,14 +51,15 @@ export declare function _isSubstrateRelayChain(chainInfo: _ChainInfo): boolean;
51
51
  export declare function _isSubstrateParaChain(chainInfo: _ChainInfo): boolean;
52
52
  export declare function _getEvmAbiExplorer(chainInfo: _ChainInfo): string;
53
53
  export declare function _isAssetValuable(assetInfo: _ChainAsset): boolean;
54
- export declare function _getMultiChainAsset(assetInfo: _ChainAsset): string;
55
- export declare function _getAssetPriceId(assetInfo: _ChainAsset): string;
54
+ export declare function _getMultiChainAsset(assetInfo?: _ChainAsset): string;
55
+ export declare function _getAssetPriceId(assetInfo?: _ChainAsset): string;
56
+ export declare function _getAssetName(assetInfo?: _ChainAsset): string;
56
57
  export declare function _getMultiChainAssetPriceId(multiChainAsset: _MultiChainAsset): string;
57
- export declare function _getAssetSymbol(assetInfo: _ChainAsset): string;
58
+ export declare function _getAssetSymbol(assetInfo?: _ChainAsset): string;
58
59
  export declare function _getMultiChainAssetSymbol(multiChainAsset: _MultiChainAsset): string;
59
- export declare function _getAssetOriginChain(assetInfo: _ChainAsset): string;
60
+ export declare function _getAssetOriginChain(assetInfo?: _ChainAsset): string;
60
61
  export declare function _getChainName(chainInfo: _ChainInfo): string;
61
- export declare function _getAssetDecimals(assetInfo: _ChainAsset): number;
62
+ export declare function _getAssetDecimals(assetInfo?: _ChainAsset): number;
62
63
  export declare function _getBlockExplorerFromChain(chainInfo: _ChainInfo): string | undefined;
63
64
  export declare function _parseMetadataForSmartContractAsset(contractAddress: string): Record<string, string>;
64
65
  export declare function _isChainTestNet(chainInfo: _ChainInfo): boolean;
@@ -280,6 +280,9 @@ export function _getMultiChainAsset(assetInfo) {
280
280
  export function _getAssetPriceId(assetInfo) {
281
281
  return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.priceId) || '';
282
282
  }
283
+ export function _getAssetName(assetInfo) {
284
+ return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.name) || '';
285
+ }
283
286
  export function _getMultiChainAssetPriceId(multiChainAsset) {
284
287
  return (multiChainAsset === null || multiChainAsset === void 0 ? void 0 : multiChainAsset.priceId) || '';
285
288
  }
@@ -290,13 +293,13 @@ export function _getMultiChainAssetSymbol(multiChainAsset) {
290
293
  return multiChainAsset.symbol;
291
294
  }
292
295
  export function _getAssetOriginChain(assetInfo) {
293
- return assetInfo.originChain;
296
+ return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.originChain) || '';
294
297
  }
295
298
  export function _getChainName(chainInfo) {
296
299
  return chainInfo.name;
297
300
  }
298
301
  export function _getAssetDecimals(assetInfo) {
299
- return assetInfo.decimals || 0;
302
+ return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.decimals) || 0;
300
303
  }
301
304
  export function _getBlockExplorerFromChain(chainInfo) {
302
305
  let blockExplorer;
@@ -5,7 +5,7 @@ import fetch from 'cross-fetch';
5
5
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
6
6
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
7
7
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
8
- const ChainListVersion = '0.2.54';
8
+ const ChainListVersion = '0.2.55-beta.3';
9
9
  export async function fetchPatchData(slug) {
10
10
  try {
11
11
  const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
@@ -13,6 +13,7 @@ export declare const _STAKING_CHAIN_GROUP: {
13
13
  krest_network: string[];
14
14
  manta: string[];
15
15
  };
16
+ export declare const MaxEraRewardPointsEras = 14;
16
17
  export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
17
18
  export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
18
19
  export declare const MANTA_MIN_DELEGATION = 500;
@@ -18,6 +18,7 @@ export const _STAKING_CHAIN_GROUP = {
18
18
  krest_network: ['krest_network'],
19
19
  manta: ['manta_network']
20
20
  };
21
+ export const MaxEraRewardPointsEras = 14;
21
22
 
22
23
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
23
24
  export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");