@subwallet/extension-base 1.3.50-0 → 1.3.52-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 (63) hide show
  1. package/cjs/constants/environment.js +3 -1
  2. package/cjs/koni/background/handlers/State.js +1 -5
  3. package/cjs/packageInfo.js +1 -1
  4. package/cjs/services/balance-service/index.js +3 -4
  5. package/cjs/services/balance-service/transfer/cardano-transfer.js +43 -11
  6. package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +13 -92
  7. package/cjs/services/balance-service/transfer/xcm/index.js +12 -4
  8. package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +3 -1
  9. package/cjs/services/chain-service/utils/patch.js +3 -2
  10. package/cjs/services/earning-service/handlers/native-staking/dtao.js +28 -301
  11. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
  12. package/cjs/services/earning-service/handlers/native-staking/tao.js +174 -148
  13. package/cjs/services/earning-service/handlers/nomination-pool/index.js +11 -5
  14. package/cjs/services/earning-service/service.js +5 -2
  15. package/cjs/services/fee-service/utils/tokenPayFee.js +17 -13
  16. package/cjs/services/price-service/coingecko.js +3 -3
  17. package/cjs/services/swap-service/handler/base-handler.js +5 -2
  18. package/cjs/services/swap-service/handler/chainflip-handler.js +35 -12
  19. package/cjs/services/swap-service/handler/hydradx-handler.js +19 -13
  20. package/cjs/services/swap-service/index.js +8 -5
  21. package/cjs/services/transaction-service/utils.js +31 -22
  22. package/cjs/utils/account/common.js +1 -0
  23. package/cjs/utils/account/transform.js +1 -1
  24. package/cjs/utils/index.js +12 -0
  25. package/cjs/utils/setup-api-sdk.js +27 -0
  26. package/constants/environment.d.ts +1 -0
  27. package/constants/environment.js +1 -0
  28. package/koni/background/handlers/State.js +3 -7
  29. package/package.json +13 -7
  30. package/packageInfo.js +1 -1
  31. package/services/balance-service/index.js +3 -4
  32. package/services/balance-service/transfer/cardano-transfer.js +42 -10
  33. package/services/balance-service/transfer/xcm/acrossBridge/index.js +14 -93
  34. package/services/balance-service/transfer/xcm/index.js +12 -4
  35. package/services/chain-service/handler/bitcoin/BitcoinApi.js +3 -1
  36. package/services/chain-service/utils/patch.d.ts +1 -0
  37. package/services/chain-service/utils/patch.js +1 -1
  38. package/services/earning-service/handlers/native-staking/dtao.d.ts +4 -36
  39. package/services/earning-service/handlers/native-staking/dtao.js +24 -298
  40. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -2
  41. package/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
  42. package/services/earning-service/handlers/native-staking/tao.d.ts +25 -5
  43. package/services/earning-service/handlers/native-staking/tao.js +169 -149
  44. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -2
  45. package/services/earning-service/handlers/nomination-pool/index.js +11 -5
  46. package/services/earning-service/service.d.ts +1 -0
  47. package/services/earning-service/service.js +4 -2
  48. package/services/fee-service/utils/tokenPayFee.js +17 -13
  49. package/services/price-service/coingecko.js +2 -3
  50. package/services/swap-service/handler/base-handler.js +6 -3
  51. package/services/swap-service/handler/chainflip-handler.js +34 -13
  52. package/services/swap-service/handler/hydradx-handler.js +19 -13
  53. package/services/swap-service/index.js +8 -5
  54. package/services/transaction-service/utils.d.ts +0 -1
  55. package/services/transaction-service/utils.js +31 -21
  56. package/types/swap/index.d.ts +1 -1
  57. package/types/yield/info/chain/info.d.ts +1 -0
  58. package/utils/account/common.js +1 -0
  59. package/utils/account/transform.js +1 -1
  60. package/utils/index.d.ts +1 -0
  61. package/utils/index.js +2 -1
  62. package/utils/setup-api-sdk.d.ts +1 -0
  63. package/utils/setup-api-sdk.js +20 -0
@@ -150,7 +150,7 @@ export default class NominationPoolHandler extends BasePoolHandler {
150
150
 
151
151
  /* Subscribe pool position */
152
152
 
153
- async parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, _deriveSessionProgress, address) {
153
+ async parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, address) {
154
154
  const chainInfo = this.chainInfo;
155
155
  const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
156
156
  const _maxNominatorRewardedPerValidator = (substrateApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
@@ -245,14 +245,13 @@ export default class NominationPoolHandler extends BasePoolHandler {
245
245
  return;
246
246
  }
247
247
  if (ledgers) {
248
- var _substrateApi$api$der, _substrateApi$api$der2;
249
- const [_currentEra, _deriveSessionProgress] = await Promise.all([substrateApi.api.query.staking.currentEra(), (_substrateApi$api$der = substrateApi.api.derive) === null || _substrateApi$api$der === void 0 ? void 0 : (_substrateApi$api$der2 = _substrateApi$api$der.session) === null || _substrateApi$api$der2 === void 0 ? void 0 : _substrateApi$api$der2.progress()]);
248
+ const _currentEra = await substrateApi.api.query.staking.currentEra();
250
249
  const currentEra = _currentEra.toString();
251
250
  await Promise.all(ledgers.map(async (_poolMemberInfo, i) => {
252
251
  const poolMemberInfo = _poolMemberInfo.toPrimitive();
253
252
  const owner = reformatAddress(useAddresses[i], 42);
254
253
  if (poolMemberInfo) {
255
- const nominatorMetadata = await this.parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, _deriveSessionProgress, owner);
254
+ const nominatorMetadata = await this.parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, owner);
256
255
  resultCallback({
257
256
  ...defaultInfo,
258
257
  ...nominatorMetadata,
@@ -565,7 +564,14 @@ export default class NominationPoolHandler extends BasePoolHandler {
565
564
  async handleYieldWithdraw(address, unstakingInfo) {
566
565
  const chainApi = await this.substrateApi.isReady;
567
566
  if (chainApi.api.tx.nominationPools.withdrawUnbonded.meta.args.length === 2) {
568
- const slashingSpanCount = await chainApi.api.call.nominationPoolsApi.memberPendingSlash(address);
567
+ var _chainApi$api$call, _chainApi$api$call$no;
568
+ let slashingSpanCount;
569
+ if ((_chainApi$api$call = chainApi.api.call) !== null && _chainApi$api$call !== void 0 && (_chainApi$api$call$no = _chainApi$api$call.nominationPoolsApi) !== null && _chainApi$api$call$no !== void 0 && _chainApi$api$call$no.memberPendingSlash) {
570
+ slashingSpanCount = await chainApi.api.call.nominationPoolsApi.memberPendingSlash(address);
571
+ } else {
572
+ // Incase api call not exists
573
+ slashingSpanCount = chainApi.api.consts.staking.historyDepth.toPrimitive();
574
+ }
569
575
  return chainApi.api.tx.nominationPools.withdrawUnbonded({
570
576
  Id: address
571
577
  }, slashingSpanCount);
@@ -8,6 +8,7 @@ import { PromiseHandler } from '@subwallet/extension-base/utils';
8
8
  import { BehaviorSubject } from 'rxjs';
9
9
  import { EarningSlippageResult } from './handlers/native-staking/dtao';
10
10
  import { BasePoolHandler } from './handlers';
11
+ export declare const fetchPoolsData: () => Promise<Record<string, YieldPoolInfo>>;
11
12
  export default class EarningService implements StoppableServiceInterface, PersistDataServiceInterface {
12
13
  protected readonly state: KoniState;
13
14
  protected handlers: Record<string, BasePoolHandler>;
@@ -14,7 +14,7 @@ import { addLazy, createPromiseHandler, filterAddressByChainInfo, removeLazy } f
14
14
  import { fetchStaticCache } from '@subwallet/extension-base/utils/fetchStaticCache';
15
15
  import { BehaviorSubject, combineLatest } from 'rxjs';
16
16
  import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, BifrostMantaLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler, SubnetTaoStakingPoolHandler, TaoNativeStakingPoolHandler } from "./handlers/index.js";
17
- const fetchPoolsData = async () => {
17
+ export const fetchPoolsData = async () => {
18
18
  const fetchData = await fetchStaticCache('earning/yield-pools.json', {
19
19
  data: {}
20
20
  });
@@ -350,7 +350,9 @@ export default class EarningService {
350
350
  const unsubList = [];
351
351
  for (const handler of Object.values(this.handlers)) {
352
352
  // Force subscribe onchain data
353
- const forceSubscribe = handler.type === YieldPoolType.LIQUID_STAKING || handler.type === YieldPoolType.LENDING || !onlineData[handler.slug];
353
+ const forceSubscribe = handler.type === YieldPoolType.LIQUID_STAKING || handler.type === YieldPoolType.LENDING ||
354
+ // Skip subscribing for subnet staking handlers because subnet staking slugs are not included in the online cache (only slugs with netuid are cached)
355
+ !onlineData[handler.slug] && handler.type !== YieldPoolType.SUBNET_STAKING;
354
356
  if (!this.useOnlineCacheOnly || forceSubscribe) {
355
357
  handler.subscribePoolInfo(callback).then(unsub => {
356
358
  if (!cancel) {
@@ -4,7 +4,7 @@
4
4
  import { _AssetType } from '@subwallet/chain-list/types';
5
5
  import { _getAssetDecimals, _getAssetPriceId, _getTokenOnChainAssetId } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { checkLiquidityForPool, estimateTokensForPool, getReserveForPool } from '@subwallet/extension-base/services/swap-service/handler/asset-hub/utils';
7
- import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
7
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
8
8
  import BigN from 'bignumber.js';
9
9
  export async function getAssetHubTokensCanPayFee(request) {
10
10
  const {
@@ -122,20 +122,24 @@ export function batchExtrinsicSetFeeHydration(substrateApi, tx, feeSetting, asse
122
122
  return tx;
123
123
  }
124
124
  export async function getHydrationRate(address, hdx, desToken) {
125
- var _subwalletApiSdk$swap;
126
- const quoteRate = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.getHydrationRate({
127
- address,
128
- pair: {
129
- slug: `${hdx.slug}___${desToken.slug}`,
130
- from: hdx.slug,
131
- to: desToken.slug
132
- }
133
- }));
134
- if (!quoteRate) {
135
- return undefined;
136
- } else {
125
+ let quoteRate;
126
+ try {
127
+ const quote = await subwalletApiSdk.swapApi.getHydrationRate({
128
+ address,
129
+ pair: {
130
+ slug: `${hdx.slug}___${desToken.slug}`,
131
+ from: hdx.slug,
132
+ to: desToken.slug
133
+ }
134
+ });
135
+ quoteRate = quote.rate;
136
+ } catch (error) {
137
+ console.error(`Failed to fetch swap quote: ${error.message}`);
138
+ }
139
+ if (quoteRate) {
137
140
  const hdxDecimal = _getAssetDecimals(hdx);
138
141
  const desTokenDecimal = _getAssetDecimals(desToken);
139
142
  return new BigN(quoteRate).multipliedBy(10 ** (desTokenDecimal - hdxDecimal)).toFixed();
140
143
  }
144
+ return undefined;
141
145
  }
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { isProductionMode } from '@subwallet/extension-base/constants';
5
5
  import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
6
- import { subwalletApiSdk } from '@subwallet/subwallet-api-sdk';
6
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
7
7
  import { isArray } from '@polkadot/util';
8
8
  const DEFAULT_CURRENCY = 'USD';
9
9
  const DERIVATIVE_TOKEN_SLUG_LIST = ['susds', 'savings-dai'];
@@ -141,8 +141,7 @@ export const getPriceMap = async (priceIds, currency = 'USD', skipDerivativePric
141
141
  };
142
142
  export const getHistoryPrice = async (priceId, type) => {
143
143
  try {
144
- var _subwalletApiSdk$pric;
145
- const response = await ((_subwalletApiSdk$pric = subwalletApiSdk.priceHistoryApi) === null || _subwalletApiSdk$pric === void 0 ? void 0 : _subwalletApiSdk$pric.getPriceHistory(priceId, type));
144
+ const response = await subwalletApiSdk.priceHistoryApi.getPriceHistory(priceId, type);
146
145
  if (response) {
147
146
  return response;
148
147
  }
@@ -10,13 +10,14 @@ import { _isSufficientToken } from '@subwallet/extension-base/core/utils';
10
10
  import { createXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
11
11
  import { _isAcrossChainBridge, AcrossErrorMsg } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
12
12
  import { estimateXcmFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
13
- import { _getAssetDecimals, _getAssetOriginChain, _getAssetSymbol, _getChainNativeTokenSlug, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
13
+ import { _getAssetDecimals, _getAssetOriginChain, _getAssetSymbol, _getChainNativeTokenSlug, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken, _isPureBitcoinChain } from '@subwallet/extension-base/services/chain-service/utils';
14
14
  import { DEFAULT_EXCESS_AMOUNT_WEIGHT, FEE_RATE_MULTIPLIER } from '@subwallet/extension-base/services/swap-service/utils';
15
15
  import { BasicTxErrorType, SwapStepType, TransferTxErrorType } from '@subwallet/extension-base/types';
16
16
  import { CommonStepType, DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
17
17
  import { DynamicSwapType, SwapErrorType, SwapFeeType } from '@subwallet/extension-base/types/swap';
18
18
  import { _reformatAddressWithChain, balanceFormatter, formatNumber } from '@subwallet/extension-base/utils';
19
19
  import { getId } from '@subwallet/extension-base/utils/getId';
20
+ import { isBitcoinAddress } from '@subwallet/keyring/utils/address/validate';
20
21
  import BigN from 'bignumber.js';
21
22
  import { t } from 'i18next';
22
23
  import { isEthereumAddress } from '@polkadot/util-crypto';
@@ -372,8 +373,10 @@ export class SwapBaseHandler {
372
373
  if (recipient) {
373
374
  const isEvmAddress = isEthereumAddress(recipient);
374
375
  const isEvmDestChain = _isChainEvmCompatible(swapToChain);
375
- if (isEvmAddress !== isEvmDestChain) {
376
- // todo: update condition if support swap chain # EVM or Substrate
376
+ const isBtcAddress = isBitcoinAddress(recipient);
377
+ const isBtcDestChain = _isPureBitcoinChain(swapToChain);
378
+ if (isEvmAddress !== isEvmDestChain || isBtcAddress !== isBtcDestChain) {
379
+ // todo: update condition if support swap chain # EVM, Substrate, Bitcoin
377
380
  return [new TransactionError(SwapErrorType.INVALID_RECIPIENT)];
378
381
  }
379
382
  }
@@ -4,15 +4,17 @@
4
4
  import { COMMON_ASSETS } from '@subwallet/chain-list';
5
5
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
6
6
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
7
+ import { createBitcoinTransaction } from '@subwallet/extension-base/services/balance-service/transfer/bitcoin-transfer';
7
8
  import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
8
9
  import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
9
- import { _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
10
+ import { _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken, _isPureBitcoinChain } from '@subwallet/extension-base/services/chain-service/utils';
10
11
  import { SwapBaseHandler } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
11
12
  import { BasicTxErrorType, CommonStepType, DynamicSwapType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types';
12
13
  import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
13
14
  import { _reformatAddressWithChain, fetchFromProxyService } from '@subwallet/extension-base/utils';
14
15
  import { getId } from '@subwallet/extension-base/utils/getId';
15
16
  import BigNumber from 'bignumber.js';
17
+ import * as bitcoin from 'bitcoinjs-lib';
16
18
  const INTERMEDIARY_MAINNET_ASSET_SLUG = COMMON_ASSETS.USDC_ETHEREUM;
17
19
  const INTERMEDIARY_TESTNET_ASSET_SLUG = COMMON_ASSETS.USDC_SEPOLIA;
18
20
  export class ChainflipSwapHandler {
@@ -58,6 +60,8 @@ export class ChainflipSwapHandler {
58
60
  async handleSubmitStep(params) {
59
61
  const {
60
62
  address,
63
+ currentStep,
64
+ process,
61
65
  quote,
62
66
  recipient,
63
67
  slippage
@@ -66,10 +70,10 @@ export class ChainflipSwapHandler {
66
70
  const fromAsset = this.chainService.getAssetBySlug(pair.from);
67
71
  const chainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
68
72
  const toChainInfo = this.chainService.getChainInfoByKey(fromAsset.originChain);
69
- const chainType = _isChainSubstrateCompatible(chainInfo) ? ChainType.SUBSTRATE : ChainType.EVM;
73
+ const chainType = _isChainSubstrateCompatible(chainInfo) ? ChainType.SUBSTRATE : _isPureBitcoinChain(chainInfo) ? ChainType.BITCOIN : ChainType.EVM; // todo: improve throw error for unknown chain
70
74
  const receiver = _reformatAddressWithChain(recipient !== null && recipient !== void 0 ? recipient : address, toChainInfo);
71
75
  const minReceive = new BigNumber(quote.rate).times(1 - slippage).toString();
72
- const processMetadata = params.process.steps[params.currentStep].metadata;
76
+ const processMetadata = process.steps[currentStep].metadata;
73
77
  const quoteMetadata = processMetadata;
74
78
  const fromAssetId = quoteMetadata.fromAssetId;
75
79
  const toAssetId = quoteMetadata.toAssetId;
@@ -114,17 +118,17 @@ export class ChainflipSwapHandler {
114
118
  const txData = {
115
119
  address,
116
120
  provider: this.providerInfo,
117
- quote: params.quote,
118
- slippage: params.slippage,
121
+ quote,
122
+ slippage,
119
123
  recipient,
120
- depositChannelId: depositChannelId,
121
- depositAddress: depositAddress,
122
- process: params.process
124
+ depositChannelId,
125
+ depositAddress,
126
+ process
123
127
  };
124
128
  let extrinsic;
125
129
  if (chainType === ChainType.SUBSTRATE) {
126
- const chainApi = this.chainService.getSubstrateApi(chainInfo.slug);
127
- const substrateApi = await chainApi.isReady;
130
+ const _substrateApi = this.chainService.getSubstrateApi(chainInfo.slug);
131
+ const substrateApi = await _substrateApi.isReady;
128
132
  const [submittableExtrinsic] = await createSubstrateExtrinsic({
129
133
  from: address,
130
134
  networkKey: chainInfo.slug,
@@ -136,9 +140,8 @@ export class ChainflipSwapHandler {
136
140
  value: quote.fromAmount
137
141
  });
138
142
  extrinsic = submittableExtrinsic;
139
- } else {
140
- const id = getId();
141
- const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(id, chainInfo.slug, 'evm');
143
+ } else if (chainType === ChainType.EVM) {
144
+ const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(getId(), chainInfo.slug, 'evm');
142
145
  if (_isNativeToken(fromAsset)) {
143
146
  const [transactionConfig] = await getEVMTransactionObject({
144
147
  chain: chainInfo.slug,
@@ -163,6 +166,24 @@ export class ChainflipSwapHandler {
163
166
  });
164
167
  extrinsic = transactionConfig;
165
168
  }
169
+ } else if (chainType === ChainType.BITCOIN) {
170
+ const bitcoinApi = this.chainService.getBitcoinApi(chainInfo.slug);
171
+ const feeInfo = await this.swapBaseHandler.feeService.subscribeChainFee(getId(), chainInfo.slug, 'bitcoin');
172
+ const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
173
+ const [transaction] = await createBitcoinTransaction({
174
+ bitcoinApi,
175
+ chain: chainInfo.slug,
176
+ from: address,
177
+ feeInfo,
178
+ to: depositAddress,
179
+ transferAll: false,
180
+ value: quote.fromAmount,
181
+ network
182
+ });
183
+ extrinsic = transaction;
184
+ } else {
185
+ // todo: update this when support new chainType rather than substrate, evm, bitcoin
186
+ throw new Error('Unknown swap chain type');
166
187
  }
167
188
  return {
168
189
  txChain: fromAsset.originChain,
@@ -12,7 +12,7 @@ import { BasicTxErrorType, DynamicSwapType } from '@subwallet/extension-base/typ
12
12
  import { CommonStepType } from '@subwallet/extension-base/types/service-base';
13
13
  import { SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
14
14
  import { _reformatAddressWithChain } from '@subwallet/extension-base/utils';
15
- import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
15
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
16
16
  import BigN from 'bignumber.js';
17
17
  import { isHex } from '@polkadot/util';
18
18
  const HYDRADX_SUBWALLET_REFERRAL_CODE = 'WALLET';
@@ -137,21 +137,27 @@ export class HydradxHandler {
137
137
  let bnSendingValue = BigN(fromAmount);
138
138
  let bnExpectedReceive = BigN(selectedQuote.toAmount);
139
139
  if (needModifyData) {
140
- var _subwalletApiSdk$swap;
140
+ var _quotes;
141
141
  // override info if xcm-swap-xcm
142
142
  bnSendingValue = bnSendingValue.multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT);
143
143
  bnExpectedReceive = bnExpectedReceive.multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT);
144
- const quotes = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.fetchSwapQuoteData({
145
- address: sender,
146
- pair: {
147
- from: swapPairInfo.from,
148
- to: swapPairInfo.to,
149
- slug: swapPairInfo.slug
150
- },
151
- fromAmount: bnSendingValue.toFixed(0, 1),
152
- slippage: params.request.slippage
153
- }));
154
- const quoteAskResponse = quotes === null || quotes === void 0 ? void 0 : quotes.find(quote => quote.provider === this.providerSlug);
144
+ let quotes = []; // todo
145
+
146
+ try {
147
+ quotes = await subwalletApiSdk.swapApi.fetchSwapQuoteData({
148
+ address: sender,
149
+ pair: {
150
+ from: swapPairInfo.from,
151
+ to: swapPairInfo.to,
152
+ slug: swapPairInfo.slug
153
+ },
154
+ fromAmount: bnSendingValue.toFixed(0, 1),
155
+ slippage: params.request.slippage
156
+ });
157
+ } catch (error) {
158
+ throw new Error(`Failed to fetch swap quote: ${error.message}`);
159
+ }
160
+ const quoteAskResponse = (_quotes = quotes) === null || _quotes === void 0 ? void 0 : _quotes.find(quote => quote.provider === this.providerSlug);
155
161
  if (!quoteAskResponse || !quoteAskResponse.quote) {
156
162
  return Promise.resolve(undefined);
157
163
  }
@@ -17,7 +17,7 @@ import { BasicTxErrorType, DynamicSwapType } from '@subwallet/extension-base/typ
17
17
  import { DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
18
18
  import { _SUPPORTED_SWAP_PROVIDERS, SwapErrorType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
19
19
  import { _reformatAddressWithChain, createPromiseHandler, reformatAddress } from '@subwallet/extension-base/utils';
20
- import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
20
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
21
21
  import BigN from 'bignumber.js';
22
22
  import { t } from 'i18next';
23
23
  import { BehaviorSubject } from 'rxjs';
@@ -36,7 +36,6 @@ export class SwapService {
36
36
  this.chainService = state.chainService;
37
37
  }
38
38
  async askProvidersForQuote(_request) {
39
- var _subwalletApiSdk$swap;
40
39
  const availableQuotes = [];
41
40
 
42
41
  // hotfix // todo: remove later
@@ -44,7 +43,7 @@ export class SwapService {
44
43
  ..._request,
45
44
  isSupportKyberVersion: true
46
45
  };
47
- const quotes = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.fetchSwapQuoteData(request));
46
+ const quotes = await subwalletApiSdk.swapApi.fetchSwapQuoteData(request);
48
47
  if (Array.isArray(quotes)) {
49
48
  quotes.forEach(quoteData => {
50
49
  if (!_SUPPORTED_SWAP_PROVIDERS.includes(quoteData.provider)) {
@@ -265,8 +264,12 @@ export class SwapService {
265
264
  return [[], undefined];
266
265
  }
267
266
  async getLatestQuoteFromSwapRequest(request) {
268
- var _subwalletApiSdk$swap2;
269
- const availablePath = await ((_subwalletApiSdk$swap2 = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap2 === void 0 ? void 0 : _subwalletApiSdk$swap2.findAvailablePath(request));
267
+ let availablePath;
268
+ try {
269
+ availablePath = await subwalletApiSdk.swapApi.findAvailablePath(request);
270
+ } catch (e) {
271
+ console.log('Error findAvailablePath', e);
272
+ }
270
273
  if (!availablePath) {
271
274
  return {
272
275
  path: [],
@@ -2,7 +2,6 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { ExtrinsicDataTypeMap, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { ChainflipSwapTxData, SimpleSwapTxData } from '@subwallet/extension-base/types/swap';
4
4
  export declare function parseTransactionData<T extends ExtrinsicType>(data: unknown): ExtrinsicDataTypeMap[T];
5
- export declare function getTransactionId(value: string): Promise<string>;
6
5
  export declare function getExplorerLink(chainInfo: _ChainInfo, value: string, type: 'account' | 'tx'): string | undefined;
7
6
  export declare function getChainflipExplorerLink(data: ChainflipSwapTxData, chainInfo: _ChainInfo): string;
8
7
  export declare function getSimpleSwapExplorerLink(data: SimpleSwapTxData): string;
@@ -43,12 +43,18 @@ function getBlockExplorerAccountRoute(explorerLink) {
43
43
  if (explorerLink.includes('devnet-explorer.mosaicchain.io')) {
44
44
  return 'accounts';
45
45
  }
46
+ if (explorerLink.includes('pdexmon.com')) {
47
+ return 'holders';
48
+ }
46
49
  return 'address';
47
50
  }
48
51
  function getBlockExplorerTxRoute(chainInfo) {
49
52
  if (_isPureEvmChain(chainInfo) || _isPureBitcoinChain(chainInfo)) {
50
53
  return 'tx';
51
54
  }
55
+ if (['moonbeam'].includes(chainInfo.slug)) {
56
+ return 'tx';
57
+ }
52
58
  if (_isPureCardanoChain(chainInfo) || _isPureTonChain(chainInfo)) {
53
59
  return 'transaction';
54
60
  }
@@ -58,33 +64,38 @@ function getBlockExplorerTxRoute(chainInfo) {
58
64
  if (['gen6_public'].includes(chainInfo.slug)) {
59
65
  return '#/extrinsics';
60
66
  }
61
- if (['mosaicTest'].includes(chainInfo.slug)) {
67
+ if (['mosaicTest', 'polkadex'].includes(chainInfo.slug)) {
62
68
  return 'transactions';
63
69
  }
70
+ if (['autonomys'].includes(chainInfo.slug)) {
71
+ return 'extrinsics';
72
+ }
64
73
  const explorerLink = _getBlockExplorerFromChain(chainInfo);
65
74
  if (explorerLink && explorerLink.includes('statescan.io')) {
66
75
  return '#/extrinsics';
67
76
  }
68
77
  return 'extrinsic';
69
78
  }
70
- export function getTransactionId(value) {
71
- const query = `
72
- query ExtrinsicQuery {
73
- extrinsics(where: {hash_eq: ${value}}, limit: 1) {
74
- id
75
- }
76
- }`;
77
- const apiUrl = 'https://archive-explorer.truth-network.io/graphql';
78
- return fetch(apiUrl, {
79
- method: 'POST',
80
- headers: {
81
- 'Content-Type': 'application/json'
82
- },
83
- body: JSON.stringify({
84
- query
85
- })
86
- }).then(response => response.json()).then(result => result.data.extrinsics[0].id);
87
- }
79
+
80
+ // export function getTransactionId (value: string): Promise<string> {
81
+ // const query = `
82
+ // query ExtrinsicQuery {
83
+ // extrinsics(where: {hash_eq: ${value}}, limit: 1) {
84
+ // id
85
+ // }
86
+ // }`;
87
+ //
88
+ // const apiUrl = 'https://archive-explorer.truth-network.io/graphql';
89
+ //
90
+ // return fetch(apiUrl, {
91
+ // method: 'POST',
92
+ // headers: { 'Content-Type': 'application/json' },
93
+ // body: JSON.stringify({ query })
94
+ // })
95
+ // .then((response) => response.json())
96
+ // .then((result: SWApiResponse<ExtrinsicsDataResponse>) => result.data.extrinsics[0].id);
97
+ // }
98
+
88
99
  export function getExplorerLink(chainInfo, value, type) {
89
100
  const explorerLink = _getBlockExplorerFromChain(chainInfo);
90
101
  if (explorerLink && type === 'account') {
@@ -120,6 +131,5 @@ export function getChainflipExplorerLink(data, chainInfo) {
120
131
  return `${chainflipDomain}/channels/${data.depositChannelId}`;
121
132
  }
122
133
  export function getSimpleSwapExplorerLink(data) {
123
- const simpleswapDomain = SIMPLE_SWAP_EXPLORER;
124
- return `${simpleswapDomain}/exchange?id=${data.id}`;
134
+ return `${SIMPLE_SWAP_EXPLORER}/exchange?id=${data.id}`;
125
135
  }
@@ -117,7 +117,7 @@ export interface SimpleSwapValidationMetadata {
117
117
  maxSwap: AmountData;
118
118
  chain: _ChainInfo;
119
119
  }
120
- export interface QuoteAskResponse {
120
+ export interface ProcessedQuoteAskResponse {
121
121
  quote?: SwapQuote;
122
122
  error?: SwapError;
123
123
  }
@@ -90,6 +90,7 @@ export interface BaseYieldPoolMetadata {
90
90
  netuid: number;
91
91
  subnetSymbol: string;
92
92
  };
93
+ minValidate?: string;
93
94
  }
94
95
  /**
95
96
  * @interface NormalYieldPoolMetadata
@@ -49,6 +49,7 @@ export const _reformatAddressWithChain = (address, chainInfo) => {
49
49
  const isTestnet = chainInfo.isTestnet;
50
50
  return reformatAddress(address, isTestnet ? 0 : 1);
51
51
  } else {
52
+ // EVM, Bitcoin
52
53
  return address;
53
54
  }
54
55
  };
@@ -166,7 +166,7 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
166
166
  case AccountChainType.CARDANO:
167
167
  return [...BASE_TRANSFER_ACTIONS];
168
168
  case AccountChainType.BITCOIN:
169
- return [...BASE_TRANSFER_ACTIONS];
169
+ return [...BASE_TRANSFER_ACTIONS, ExtrinsicType.SWAP];
170
170
  }
171
171
  } else if (signMode === AccountSignMode.QR) {
172
172
  switch (networkType) {
package/utils/index.d.ts CHANGED
@@ -69,3 +69,4 @@ export * from './registry';
69
69
  export * from './swap';
70
70
  export * from './translate';
71
71
  export * from './bitcoin';
72
+ export * from './setup-api-sdk';
package/utils/index.js CHANGED
@@ -346,4 +346,5 @@ export * from "./promise.js";
346
346
  export * from "./registry.js";
347
347
  export * from "./swap.js";
348
348
  export * from "./translate.js";
349
- export * from "./bitcoin/index.js";
349
+ export * from "./bitcoin/index.js";
350
+ export * from "./setup-api-sdk.js";
@@ -0,0 +1 @@
1
+ export declare function setupApiSDK(): void;
@@ -0,0 +1,20 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { APP_VERSION, BACKEND_API_URL, BACKEND_PRICE_HISTORY_URL } from '@subwallet/extension-base/constants';
5
+ import { ChainListVersion } from '@subwallet/extension-base/services/chain-service/utils';
6
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
7
+ import { TARGET_ENV } from "./environment.js";
8
+ export function setupApiSDK() {
9
+ subwalletApiSdk.updateConfig({
10
+ appVersion: APP_VERSION,
11
+ baseUrl: BACKEND_API_URL,
12
+ platform: TARGET_ENV,
13
+ chainListVersion: ChainListVersion
14
+ });
15
+
16
+ // Custom the price history API with other different base URL
17
+ subwalletApiSdk.priceHistoryApi.updateConfig({
18
+ baseUrl: BACKEND_PRICE_HISTORY_URL
19
+ });
20
+ }