@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.
- package/cjs/constants/environment.js +3 -1
- package/cjs/koni/background/handlers/State.js +1 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +3 -4
- package/cjs/services/balance-service/transfer/cardano-transfer.js +43 -11
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +13 -92
- package/cjs/services/balance-service/transfer/xcm/index.js +12 -4
- package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +3 -1
- package/cjs/services/chain-service/utils/patch.js +3 -2
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +28 -301
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
- package/cjs/services/earning-service/handlers/native-staking/tao.js +174 -148
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +11 -5
- package/cjs/services/earning-service/service.js +5 -2
- package/cjs/services/fee-service/utils/tokenPayFee.js +17 -13
- package/cjs/services/price-service/coingecko.js +3 -3
- package/cjs/services/swap-service/handler/base-handler.js +5 -2
- package/cjs/services/swap-service/handler/chainflip-handler.js +35 -12
- package/cjs/services/swap-service/handler/hydradx-handler.js +19 -13
- package/cjs/services/swap-service/index.js +8 -5
- package/cjs/services/transaction-service/utils.js +31 -22
- package/cjs/utils/account/common.js +1 -0
- package/cjs/utils/account/transform.js +1 -1
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/setup-api-sdk.js +27 -0
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +1 -0
- package/koni/background/handlers/State.js +3 -7
- package/package.json +13 -7
- package/packageInfo.js +1 -1
- package/services/balance-service/index.js +3 -4
- package/services/balance-service/transfer/cardano-transfer.js +42 -10
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +14 -93
- package/services/balance-service/transfer/xcm/index.js +12 -4
- package/services/chain-service/handler/bitcoin/BitcoinApi.js +3 -1
- package/services/chain-service/utils/patch.d.ts +1 -0
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +4 -36
- package/services/earning-service/handlers/native-staking/dtao.js +24 -298
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
- package/services/earning-service/handlers/native-staking/tao.d.ts +25 -5
- package/services/earning-service/handlers/native-staking/tao.js +169 -149
- package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -2
- package/services/earning-service/handlers/nomination-pool/index.js +11 -5
- package/services/earning-service/service.d.ts +1 -0
- package/services/earning-service/service.js +4 -2
- package/services/fee-service/utils/tokenPayFee.js +17 -13
- package/services/price-service/coingecko.js +2 -3
- package/services/swap-service/handler/base-handler.js +6 -3
- package/services/swap-service/handler/chainflip-handler.js +34 -13
- package/services/swap-service/handler/hydradx-handler.js +19 -13
- package/services/swap-service/index.js +8 -5
- package/services/transaction-service/utils.d.ts +0 -1
- package/services/transaction-service/utils.js +31 -21
- package/types/swap/index.d.ts +1 -1
- package/types/yield/info/chain/info.d.ts +1 -0
- package/utils/account/common.js +1 -0
- package/utils/account/transform.js +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/setup-api-sdk.d.ts +1 -0
- 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,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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 ||
|
|
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-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
376
|
-
|
|
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 =
|
|
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
|
|
118
|
-
slippage
|
|
121
|
+
quote,
|
|
122
|
+
slippage,
|
|
119
123
|
recipient,
|
|
120
|
-
depositChannelId
|
|
121
|
-
depositAddress
|
|
122
|
-
process
|
|
124
|
+
depositChannelId,
|
|
125
|
+
depositAddress,
|
|
126
|
+
process
|
|
123
127
|
};
|
|
124
128
|
let extrinsic;
|
|
125
129
|
if (chainType === ChainType.SUBSTRATE) {
|
|
126
|
-
const
|
|
127
|
-
const substrateApi = await
|
|
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
|
|
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-
|
|
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
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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-
|
|
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
|
|
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
|
-
|
|
269
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
124
|
-
return `${simpleswapDomain}/exchange?id=${data.id}`;
|
|
134
|
+
return `${SIMPLE_SWAP_EXPLORER}/exchange?id=${data.id}`;
|
|
125
135
|
}
|
package/types/swap/index.d.ts
CHANGED
package/utils/account/common.js
CHANGED
|
@@ -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
package/utils/index.js
CHANGED
|
@@ -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
|
+
}
|