@0xsquid/react-hooks 8.3.1-beta-update-ethers.0 → 8.3.1-beta-stellar-issued-assets.2
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/dist/core/constants.d.ts +1 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/queries/queries-keys.d.ts +5 -1
- package/dist/core/types/index.d.ts +1 -1
- package/dist/core/types/stellar.d.ts +52 -0
- package/dist/core/types/tokens.d.ts +4 -0
- package/dist/core/types/transaction.d.ts +19 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/stellar/useStellarTrustLine.d.ts +13 -0
- package/dist/hooks/transaction/useGetRoute.d.ts +18 -7
- package/dist/{index-qAOvcSon.js → index-xSvE7oVI.js} +743 -329
- package/dist/index-xSvE7oVI.js.map +1 -0
- package/dist/{index-CMrdTYeW.js → index-z1TwF4-p.js} +730 -331
- package/dist/index-z1TwF4-p.js.map +1 -0
- package/dist/{index.es-Cu_QQTg-.js → index.es-CtYD1WrB.js} +2 -2
- package/dist/{index.es-Cu_QQTg-.js.map → index.es-CtYD1WrB.js.map} +1 -1
- package/dist/{index.es-DRgOycmm.js → index.es-Rc3LIf6Y.js} +2 -2
- package/dist/{index.es-DRgOycmm.js.map → index.es-Rc3LIf6Y.js.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/{secretService-B_-XWo1F.js → secretService-BEEQh-7r.js} +2 -2
- package/dist/{secretService-B_-XWo1F.js.map → secretService-BEEQh-7r.js.map} +1 -1
- package/dist/{secretService-B3sc6ibT.js → secretService-aK5p-g0D.js} +2 -2
- package/dist/{secretService-B3sc6ibT.js.map → secretService-aK5p-g0D.js.map} +1 -1
- package/dist/services/external/rpcService.d.ts +1 -1
- package/dist/services/external/stellarApiClient.d.ts +4 -0
- package/dist/services/external/stellarRpcClient.d.ts +2 -2
- package/dist/services/external/xrplRpcClient.d.ts +2 -1
- package/dist/services/index.d.ts +2 -0
- package/dist/services/internal/routeService.d.ts +8 -0
- package/dist/services/internal/stellarService.d.ts +9 -0
- package/dist/services/internal/transactionService.d.ts +14 -1
- package/dist/services/internal/xrplService.d.ts +2 -0
- package/dist/{stellarService.client-Ciqw9lmL.js → stellarService.client-BB88L49R.js} +2 -2
- package/dist/{stellarService.client-Ciqw9lmL.js.map → stellarService.client-BB88L49R.js.map} +1 -1
- package/dist/{stellarService.client-sRzC5VSD.js → stellarService.client-Dl_XfhX_.js} +2 -2
- package/dist/{stellarService.client-sRzC5VSD.js.map → stellarService.client-Dl_XfhX_.js.map} +1 -1
- package/package.json +5 -5
- package/dist/index-CMrdTYeW.js.map +0 -1
- package/dist/index-qAOvcSon.js.map +0 -1
|
@@ -13,7 +13,7 @@ import { isValidXAddress, isValidClassicAddress } from 'ripple-address-codec';
|
|
|
13
13
|
import { getAssociatedTokenAddress, createAssociatedTokenAccountInstruction, createTransferInstruction } from '@solana/spl-token';
|
|
14
14
|
import { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-base';
|
|
15
15
|
import { PublicKey, VersionedTransaction, Transaction, SystemProgram, Connection } from '@solana/web3.js';
|
|
16
|
-
import {
|
|
16
|
+
import { StrKey, Networks, nativeToScVal, Address, rpc, TransactionBuilder, BASE_FEE, Contract, TimeoutInfinite, scValToNative, Asset, Operation, Transaction as Transaction$1, xdr } from '@stellar/stellar-sdk';
|
|
17
17
|
import { SUI_TESTNET_CHAIN, SUI_MAINNET_CHAIN } from '@mysten/wallet-standard';
|
|
18
18
|
import { CloudflareProvider, BrowserProvider, JsonRpcSigner, JsonRpcProvider, ethers, Interface, Contract as Contract$1, isError } from 'ethers';
|
|
19
19
|
import BigNumber$1, { BigNumber } from 'bignumber.js';
|
|
@@ -81,6 +81,7 @@ const gasRefundMultiplier = 25;
|
|
|
81
81
|
const internalSquidApiBaseUrl = "https://app.squidrouter.com/api";
|
|
82
82
|
const XAMAN_API_URL = `${internalSquidApiBaseUrl}/xaman/`;
|
|
83
83
|
const TOKEN_PRICE_API_URL = `${internalSquidApiBaseUrl}/coingecko`;
|
|
84
|
+
const DEFAULT_ROUTE_REFETCH_INTERVAL = 30_000;
|
|
84
85
|
const SOLANA_RPC_URL = "https://meredith-ute2ko-fast-mainnet.helius-rpc.com";
|
|
85
86
|
const INTEGRATOR_ID = "squid-widget-playground-local-cd33cba6-7e12-4fcc-8d5d-35e286f655ea";
|
|
86
87
|
const DEFAULT_COUNTRY_CODE = "US";
|
|
@@ -20096,14 +20097,17 @@ function isXrplAddressValid(address) {
|
|
|
20096
20097
|
return isValidXAddress(address) || isValidClassicAddress(address);
|
|
20097
20098
|
}
|
|
20098
20099
|
function buildXrplTrustSetTx({ amount, sourceAddress, token, }) {
|
|
20099
|
-
const
|
|
20100
|
+
const asset = parseXrplTokenAddress(token.address);
|
|
20101
|
+
if (!asset) {
|
|
20102
|
+
throw new Error("Invalid asset");
|
|
20103
|
+
}
|
|
20100
20104
|
return {
|
|
20101
20105
|
TransactionType: XrplTransactionType.TRUST_SET,
|
|
20102
20106
|
Flags: XrplTransactionFlag.tfSetNoRipple,
|
|
20103
20107
|
Account: sourceAddress,
|
|
20104
20108
|
LimitAmount: {
|
|
20105
|
-
currency,
|
|
20106
|
-
issuer,
|
|
20109
|
+
currency: asset.code,
|
|
20110
|
+
issuer: asset.issuer,
|
|
20107
20111
|
value: amount,
|
|
20108
20112
|
},
|
|
20109
20113
|
};
|
|
@@ -20132,6 +20136,16 @@ function parseXrplPaymentTx(data) {
|
|
|
20132
20136
|
throw new Error("Could not parse payment transaction");
|
|
20133
20137
|
}
|
|
20134
20138
|
}
|
|
20139
|
+
function parseXrplTokenAddress(address) {
|
|
20140
|
+
const [code, issuer] = address.split(".");
|
|
20141
|
+
if (!code || !issuer) {
|
|
20142
|
+
return null;
|
|
20143
|
+
}
|
|
20144
|
+
return {
|
|
20145
|
+
code,
|
|
20146
|
+
issuer,
|
|
20147
|
+
};
|
|
20148
|
+
}
|
|
20135
20149
|
|
|
20136
20150
|
const chains = [XrplCAIP2ChainId.MAINNET, XrplCAIP2ChainId.TESTNET];
|
|
20137
20151
|
class XrplWalletConnect {
|
|
@@ -20834,6 +20848,309 @@ const isBitcoinAddressValid = (address$1) => {
|
|
|
20834
20848
|
}
|
|
20835
20849
|
};
|
|
20836
20850
|
|
|
20851
|
+
var HistoryTxType;
|
|
20852
|
+
(function (HistoryTxType) {
|
|
20853
|
+
HistoryTxType[HistoryTxType["SWAP"] = 0] = "SWAP";
|
|
20854
|
+
HistoryTxType[HistoryTxType["BUY"] = 1] = "BUY";
|
|
20855
|
+
HistoryTxType[HistoryTxType["SEND"] = 2] = "SEND";
|
|
20856
|
+
})(HistoryTxType || (HistoryTxType = {}));
|
|
20857
|
+
|
|
20858
|
+
var TransactionType;
|
|
20859
|
+
(function (TransactionType) {
|
|
20860
|
+
TransactionType["BRIDGE"] = "BRIDGE";
|
|
20861
|
+
TransactionType["BRIDGE_CALL"] = "BRIDGE_CALL";
|
|
20862
|
+
TransactionType["CALL_BRIDGE"] = "CALL_BRIDGE";
|
|
20863
|
+
TransactionType["CALL_BRIDGE_CALL"] = "CALL_BRIDGE_CALL";
|
|
20864
|
+
})(TransactionType || (TransactionType = {}));
|
|
20865
|
+
var AxelarStatusResponseType;
|
|
20866
|
+
(function (AxelarStatusResponseType) {
|
|
20867
|
+
AxelarStatusResponseType["GAS_PAID_NOT_ENOUGH_GAS"] = "gas_paid_not_enough_gas";
|
|
20868
|
+
AxelarStatusResponseType["DESTINATION_EXECUTED"] = "destination_executed";
|
|
20869
|
+
AxelarStatusResponseType["EXPRESS_EXECUTED"] = "express_executed";
|
|
20870
|
+
AxelarStatusResponseType["CROSS_MULTICALL_EXECUTED"] = "CrossMulticallExecuted";
|
|
20871
|
+
AxelarStatusResponseType["CROSS_MULTICALL_FAILED"] = "CrossMulticallFailed";
|
|
20872
|
+
AxelarStatusResponseType["SRC_GATEWAY_CALLED"] = "source_gateway_called";
|
|
20873
|
+
AxelarStatusResponseType["DEST_GATEWAY_APPROVED"] = "destination_gateway_approved";
|
|
20874
|
+
AxelarStatusResponseType["DESTINATION_EXECUTE_ERROR"] = "destination_execute_error";
|
|
20875
|
+
AxelarStatusResponseType["DESTINATION_EXECUTING"] = "executing";
|
|
20876
|
+
AxelarStatusResponseType["UNKNOWN_ERROR"] = "unknown_error";
|
|
20877
|
+
AxelarStatusResponseType["CANNOT_FETCH_STATUS"] = "cannot_fetch_status";
|
|
20878
|
+
AxelarStatusResponseType["ERROR"] = "error";
|
|
20879
|
+
})(AxelarStatusResponseType || (AxelarStatusResponseType = {}));
|
|
20880
|
+
var TransactionStatus;
|
|
20881
|
+
(function (TransactionStatus) {
|
|
20882
|
+
// Submitted transaction, returned by squid axelar
|
|
20883
|
+
TransactionStatus["SUCCESS"] = "success";
|
|
20884
|
+
TransactionStatus["NEEDS_GAS"] = "needs_gas";
|
|
20885
|
+
TransactionStatus["ONGOING"] = "ongoing";
|
|
20886
|
+
TransactionStatus["PARTIAL_SUCCESS"] = "partial_success";
|
|
20887
|
+
TransactionStatus["NOT_FOUND"] = "not_found";
|
|
20888
|
+
// Unsubmitted Transaction, can be status from wallet
|
|
20889
|
+
TransactionStatus["INITIAL_LOADING"] = "initialLoading";
|
|
20890
|
+
TransactionStatus["GENERATING_DEPOSIT"] = "generating_deposit";
|
|
20891
|
+
TransactionStatus["ERROR"] = "error";
|
|
20892
|
+
TransactionStatus["WARNING"] = "warning";
|
|
20893
|
+
TransactionStatus["PENDING"] = "pending";
|
|
20894
|
+
TransactionStatus["REJECTED"] = "rejected";
|
|
20895
|
+
// Coral refund
|
|
20896
|
+
TransactionStatus["REFUNDED"] = "refunded";
|
|
20897
|
+
})(TransactionStatus || (TransactionStatus = {}));
|
|
20898
|
+
var SendTransactionStatus;
|
|
20899
|
+
(function (SendTransactionStatus) {
|
|
20900
|
+
SendTransactionStatus[SendTransactionStatus["ONGOING"] = 0] = "ONGOING";
|
|
20901
|
+
SendTransactionStatus[SendTransactionStatus["SUCCESS"] = 1] = "SUCCESS";
|
|
20902
|
+
SendTransactionStatus[SendTransactionStatus["ERROR"] = 2] = "ERROR";
|
|
20903
|
+
})(SendTransactionStatus || (SendTransactionStatus = {}));
|
|
20904
|
+
|
|
20905
|
+
const getQueryHeaders = (integratorId, requestId) => {
|
|
20906
|
+
return {
|
|
20907
|
+
...(integratorId ? { "X-Integrator-Id": integratorId } : {}),
|
|
20908
|
+
...(requestId ? { "X-Request-Id": requestId } : {}),
|
|
20909
|
+
};
|
|
20910
|
+
};
|
|
20911
|
+
const getStatusCode = (error) => {
|
|
20912
|
+
if (axios.isAxiosError(error)) {
|
|
20913
|
+
return error.response?.status;
|
|
20914
|
+
}
|
|
20915
|
+
return undefined;
|
|
20916
|
+
};
|
|
20917
|
+
const is404Error = (error) => {
|
|
20918
|
+
const statusCode = getStatusCode(error);
|
|
20919
|
+
if (statusCode === 404) {
|
|
20920
|
+
return true;
|
|
20921
|
+
}
|
|
20922
|
+
return false;
|
|
20923
|
+
};
|
|
20924
|
+
|
|
20925
|
+
const formatTransactionHistoryDate = (transaction) => {
|
|
20926
|
+
if (!transaction?.timestamp)
|
|
20927
|
+
return undefined;
|
|
20928
|
+
try {
|
|
20929
|
+
const date = new Date(Number(transaction.timestamp));
|
|
20930
|
+
// Format date to: MMM DD. Examples:
|
|
20931
|
+
// Jan 01
|
|
20932
|
+
// May 12
|
|
20933
|
+
const month = new Intl.DateTimeFormat(DEFAULT_LOCALE, {
|
|
20934
|
+
month: "short",
|
|
20935
|
+
}).format(date);
|
|
20936
|
+
const day = date.toLocaleString(DEFAULT_LOCALE, { day: "2-digit" });
|
|
20937
|
+
return { month, day };
|
|
20938
|
+
}
|
|
20939
|
+
catch (error) {
|
|
20940
|
+
console.error("Error formatting date:", error);
|
|
20941
|
+
return undefined;
|
|
20942
|
+
}
|
|
20943
|
+
};
|
|
20944
|
+
const getAxelarExplorerTxUrl = (urlPrefix, routeType, txID) => {
|
|
20945
|
+
if (!urlPrefix) {
|
|
20946
|
+
return undefined;
|
|
20947
|
+
}
|
|
20948
|
+
const txType = routeType ?? TransactionType.BRIDGE;
|
|
20949
|
+
if (txType === TransactionType.CALL_BRIDGE ||
|
|
20950
|
+
txType === TransactionType.BRIDGE) {
|
|
20951
|
+
return `${urlPrefix}transfer/${txID}`;
|
|
20952
|
+
}
|
|
20953
|
+
return `${urlPrefix}gmp/${txID}`;
|
|
20954
|
+
};
|
|
20955
|
+
const getSourceExplorerTxUrl = (chain, txID) => {
|
|
20956
|
+
if (!chain || !chain.blockExplorerUrls[0] || !txID) {
|
|
20957
|
+
return undefined;
|
|
20958
|
+
}
|
|
20959
|
+
let txSuffix;
|
|
20960
|
+
switch (chain.chainId) {
|
|
20961
|
+
case CHAIN_IDS.AGORIC:
|
|
20962
|
+
case CHAIN_IDS.XRPL:
|
|
20963
|
+
case CHAIN_IDS.XRPL_TESTNET:
|
|
20964
|
+
txSuffix = "/transactions/";
|
|
20965
|
+
break;
|
|
20966
|
+
default:
|
|
20967
|
+
txSuffix = "/tx/";
|
|
20968
|
+
}
|
|
20969
|
+
if (chain.blockExplorerUrls[0].endsWith("/")) {
|
|
20970
|
+
txSuffix = txSuffix.slice(1);
|
|
20971
|
+
}
|
|
20972
|
+
return `${chain.blockExplorerUrls[0]}${txSuffix}${txID}`;
|
|
20973
|
+
};
|
|
20974
|
+
const getMainExplorerUrl = (transaction) => {
|
|
20975
|
+
// The most accurate one is coming from squid /status api
|
|
20976
|
+
if (transaction?.statusResponse?.axelarTransactionUrl) {
|
|
20977
|
+
return transaction?.statusResponse.axelarTransactionUrl;
|
|
20978
|
+
}
|
|
20979
|
+
// If not, we can try to get it from the source chain
|
|
20980
|
+
if (transaction?.sourceTxExplorerUrl) {
|
|
20981
|
+
return transaction?.sourceTxExplorerUrl;
|
|
20982
|
+
}
|
|
20983
|
+
// If not, we can try to guess it from the transaction type
|
|
20984
|
+
if (transaction && transaction?.transactionId) {
|
|
20985
|
+
return getAxelarExplorerTxUrl(transaction.statusResponse?.axelarTransactionUrl, transaction.routeType, transaction.transactionId);
|
|
20986
|
+
}
|
|
20987
|
+
return undefined;
|
|
20988
|
+
};
|
|
20989
|
+
const formatDistance = (date, baseDate, options) => {
|
|
20990
|
+
const { includeSeconds = false, addSuffix = false, locale = { locale: DEFAULT_LOCALE }, } = options || {};
|
|
20991
|
+
const elapsedMilliseconds = Math.abs(new Date(date).getTime() - new Date(baseDate).getTime());
|
|
20992
|
+
const seconds = Math.round(elapsedMilliseconds / 1000);
|
|
20993
|
+
const minutes = Math.round(seconds / 60);
|
|
20994
|
+
const hours = Math.round(minutes / 60);
|
|
20995
|
+
const days = Math.round(hours / 24);
|
|
20996
|
+
const months = Math.round(days / 30.44);
|
|
20997
|
+
const years = Math.round(days / 365.25);
|
|
20998
|
+
const rtf = new Intl.RelativeTimeFormat(locale.locale, { numeric: "auto" });
|
|
20999
|
+
let formatted = "";
|
|
21000
|
+
if (includeSeconds && seconds < 45) {
|
|
21001
|
+
const unit = addSuffix ? "second" : "seconds";
|
|
21002
|
+
formatted = rtf.format(-seconds, unit);
|
|
21003
|
+
}
|
|
21004
|
+
else if (minutes < 60) {
|
|
21005
|
+
formatted = rtf.format(-minutes, "minutes");
|
|
21006
|
+
}
|
|
21007
|
+
else if (hours < 24) {
|
|
21008
|
+
formatted = rtf.format(-hours, "hours");
|
|
21009
|
+
}
|
|
21010
|
+
else if (days < 30) {
|
|
21011
|
+
formatted = rtf.format(-days, "days");
|
|
21012
|
+
}
|
|
21013
|
+
else if (months < 12) {
|
|
21014
|
+
formatted = rtf.format(-months, "months");
|
|
21015
|
+
}
|
|
21016
|
+
else {
|
|
21017
|
+
formatted = rtf.format(-years, "years");
|
|
21018
|
+
}
|
|
21019
|
+
// remove "ago" from the string
|
|
21020
|
+
// before: "2 minutes ago"
|
|
21021
|
+
// after: "2 minutes"
|
|
21022
|
+
return addSuffix ? formatted : formatted.replace(/\b(?:ago)\b/, "").trim();
|
|
21023
|
+
};
|
|
21024
|
+
const formatSeconds = (seconds, secondsTemplate = "s", minutesTemplate = "m", hoursTemplate = "h") => {
|
|
21025
|
+
let duration = "";
|
|
21026
|
+
if (seconds < 60) {
|
|
21027
|
+
duration = `${seconds.toString()}${secondsTemplate}`;
|
|
21028
|
+
}
|
|
21029
|
+
else {
|
|
21030
|
+
duration = formatDistance(0, seconds * 1000, { includeSeconds: true });
|
|
21031
|
+
}
|
|
21032
|
+
const result = duration.startsWith("1 ")
|
|
21033
|
+
? duration
|
|
21034
|
+
.replace(" minute", minutesTemplate)
|
|
21035
|
+
.replace(" hour", hoursTemplate)
|
|
21036
|
+
: duration
|
|
21037
|
+
.replace(" minutes", minutesTemplate)
|
|
21038
|
+
.replace(" hours", hoursTemplate);
|
|
21039
|
+
return result;
|
|
21040
|
+
};
|
|
21041
|
+
/**
|
|
21042
|
+
* Remove the chainData from statusResponse to gain some storage space
|
|
21043
|
+
*/
|
|
21044
|
+
const formatSwapTxStatusResponseForStorage = (sr) => {
|
|
21045
|
+
if (!sr) {
|
|
21046
|
+
return sr;
|
|
21047
|
+
}
|
|
21048
|
+
return {
|
|
21049
|
+
axelarTransactionUrl: sr.axelarTransactionUrl,
|
|
21050
|
+
toChain: sr.toChain?.transactionUrl
|
|
21051
|
+
? {
|
|
21052
|
+
transactionUrl: sr.toChain?.transactionUrl,
|
|
21053
|
+
}
|
|
21054
|
+
: undefined,
|
|
21055
|
+
};
|
|
21056
|
+
};
|
|
21057
|
+
const simplifyRouteAction = (action) => {
|
|
21058
|
+
return {
|
|
21059
|
+
type: action.type,
|
|
21060
|
+
provider: action.provider,
|
|
21061
|
+
data: {
|
|
21062
|
+
type: action.data?.type,
|
|
21063
|
+
},
|
|
21064
|
+
...(action.coralV2Order ? { isCoralV2: true } : undefined),
|
|
21065
|
+
};
|
|
21066
|
+
};
|
|
21067
|
+
const fetchSwapTransactionStatus = async ({ transaction, integratorId, apiUrl, }) => {
|
|
21068
|
+
const statusEndpoint = `${apiUrl}/v2/status`;
|
|
21069
|
+
try {
|
|
21070
|
+
const response = await axios.get(statusEndpoint, {
|
|
21071
|
+
params: {
|
|
21072
|
+
transactionId: transaction?.transactionIdForStatus ?? transaction?.transactionId,
|
|
21073
|
+
fromChainId: transaction?.fromChain,
|
|
21074
|
+
toChainId: transaction?.toChain,
|
|
21075
|
+
bridgeType: transaction?.bridgeType,
|
|
21076
|
+
quoteId: transaction?.quoteId,
|
|
21077
|
+
depositTxVerificationSignature: transaction?.depositTxVerificationSignature,
|
|
21078
|
+
},
|
|
21079
|
+
headers: getQueryHeaders(integratorId, transaction?.quoteId),
|
|
21080
|
+
});
|
|
21081
|
+
return response.data;
|
|
21082
|
+
}
|
|
21083
|
+
catch (error) {
|
|
21084
|
+
if (error) {
|
|
21085
|
+
throw new Error("Fetch transaction status failed", { cause: error });
|
|
21086
|
+
}
|
|
21087
|
+
throw new Error("Fetch transaction status failed", { cause: undefined });
|
|
21088
|
+
}
|
|
21089
|
+
};
|
|
21090
|
+
const compareTransactionIds = (idA, idB) => {
|
|
21091
|
+
if (!idA || !idB) {
|
|
21092
|
+
return false;
|
|
21093
|
+
}
|
|
21094
|
+
const normalizedA = idA.toLowerCase();
|
|
21095
|
+
const normalizedB = idB.toLowerCase();
|
|
21096
|
+
return normalizedA.includes(normalizedB) || normalizedB.includes(normalizedA);
|
|
21097
|
+
};
|
|
21098
|
+
/**
|
|
21099
|
+
* Checks if the provided action is Coral bridge action
|
|
21100
|
+
*/
|
|
21101
|
+
function isCoralBridgeAction(action) {
|
|
21102
|
+
return (action.type === ActionType.RFQ &&
|
|
21103
|
+
// TODO: update types
|
|
21104
|
+
action.provider?.toLowerCase() === "coral");
|
|
21105
|
+
}
|
|
21106
|
+
function sleep(ms) {
|
|
21107
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21108
|
+
}
|
|
21109
|
+
const isDepositRoute = (route) => {
|
|
21110
|
+
return (!!route &&
|
|
21111
|
+
route.transactionRequest?.type === SquidDataType.ChainflipDepositAddress);
|
|
21112
|
+
};
|
|
21113
|
+
/**
|
|
21114
|
+
* Checks if the route contains a Chainflip bridge action
|
|
21115
|
+
*/
|
|
21116
|
+
function isChainflipBridgeTransaction(actions = []) {
|
|
21117
|
+
return actions.some((action) => action.type === ActionType.BRIDGE &&
|
|
21118
|
+
action.data?.type === BridgeType.CHAINFLIP);
|
|
21119
|
+
}
|
|
21120
|
+
/**
|
|
21121
|
+
* Checks if a route is of type {@link OnChainExecutionData}
|
|
21122
|
+
*
|
|
21123
|
+
* On-chain routes require calling a smart contract to execute
|
|
21124
|
+
*/
|
|
21125
|
+
function isOnChainTxData(squidData) {
|
|
21126
|
+
return [
|
|
21127
|
+
SquidDataType.OnChainExecution,
|
|
21128
|
+
SquidDataType.DepositAddressWithSignature,
|
|
21129
|
+
SquidDataType.DepositAddressCalldata,
|
|
21130
|
+
SquidDataType.DepositAddressWithSignature,
|
|
21131
|
+
SquidDataType.DepositAddressWithMemo,
|
|
21132
|
+
].includes(squidData.type);
|
|
21133
|
+
}
|
|
21134
|
+
/**
|
|
21135
|
+
* Checks if a route is of type deposit-with-signature
|
|
21136
|
+
*
|
|
21137
|
+
* deposit-with-signature routes are on-chain routes
|
|
21138
|
+
* that require a signature from the user to execute
|
|
21139
|
+
*/
|
|
21140
|
+
function isDepositWithSignatureTxData(squidData) {
|
|
21141
|
+
return squidData.type === SquidDataType.DepositAddressWithSignature;
|
|
21142
|
+
}
|
|
21143
|
+
function getHistoryTransactionId(tx) {
|
|
21144
|
+
switch (tx.txType) {
|
|
21145
|
+
case HistoryTxType.SWAP:
|
|
21146
|
+
return tx.data.transactionId;
|
|
21147
|
+
case HistoryTxType.BUY:
|
|
21148
|
+
return tx.data.orderId;
|
|
21149
|
+
case HistoryTxType.SEND:
|
|
21150
|
+
return tx.data.hash;
|
|
21151
|
+
}
|
|
21152
|
+
}
|
|
21153
|
+
|
|
20837
21154
|
const STANDARD_FEATURES = [
|
|
20838
21155
|
"standard:connect",
|
|
20839
21156
|
"standard:events",
|
|
@@ -21010,7 +21327,7 @@ const isSolanaAddressValid = (address) => {
|
|
|
21010
21327
|
* This will be used for the swap flow - Using Jupiter Dex under the hood
|
|
21011
21328
|
*/
|
|
21012
21329
|
const executeSolanaSwap = async ({ route, signer, connection, onSigned, }) => {
|
|
21013
|
-
if (!route
|
|
21330
|
+
if (!route.transactionRequest || !isOnChainTxData(route.transactionRequest)) {
|
|
21014
21331
|
throw new Error("Invalid parameters");
|
|
21015
21332
|
}
|
|
21016
21333
|
const swapRequest = route.transactionRequest.data;
|
|
@@ -21097,6 +21414,28 @@ const executeSolanaTransfer = async ({ amount, target, signer, connection, sourc
|
|
|
21097
21414
|
return signature;
|
|
21098
21415
|
};
|
|
21099
21416
|
|
|
21417
|
+
var StellarHorizonAssetType;
|
|
21418
|
+
(function (StellarHorizonAssetType) {
|
|
21419
|
+
/**
|
|
21420
|
+
* XLM native token
|
|
21421
|
+
*/
|
|
21422
|
+
StellarHorizonAssetType["NATIVE"] = "native";
|
|
21423
|
+
/**
|
|
21424
|
+
* 1-4 char asset code (e.g. USDC)
|
|
21425
|
+
*/
|
|
21426
|
+
StellarHorizonAssetType["ALPHANUM4"] = "credit_alphanum4";
|
|
21427
|
+
/**
|
|
21428
|
+
* 5-12 char asset code (e.g. wstETH)
|
|
21429
|
+
*/
|
|
21430
|
+
StellarHorizonAssetType["ALPHANUM12"] = "credit_alphanum12";
|
|
21431
|
+
})(StellarHorizonAssetType || (StellarHorizonAssetType = {}));
|
|
21432
|
+
var StellarTokenType;
|
|
21433
|
+
(function (StellarTokenType) {
|
|
21434
|
+
StellarTokenType["NATIVE_TOKEN"] = "nativeToken";
|
|
21435
|
+
StellarTokenType["ISSUER_TOKEN"] = "issuerToken";
|
|
21436
|
+
StellarTokenType["CONTRACT_TOKEN"] = "contractToken";
|
|
21437
|
+
})(StellarTokenType || (StellarTokenType = {}));
|
|
21438
|
+
|
|
21100
21439
|
function isStellarAddressValid(address) {
|
|
21101
21440
|
return StrKey.isValidEd25519PublicKey(address);
|
|
21102
21441
|
}
|
|
@@ -21118,6 +21457,78 @@ function stellarAddressToScVal(addressString) {
|
|
|
21118
21457
|
type: "address",
|
|
21119
21458
|
});
|
|
21120
21459
|
}
|
|
21460
|
+
function getStellarTrustLineAsset(token) {
|
|
21461
|
+
// The address format for issued assets is `CODE-ISSUER`
|
|
21462
|
+
// Example: USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN
|
|
21463
|
+
const [code, issuer] = token.address.split("-");
|
|
21464
|
+
if (!code || !issuer) {
|
|
21465
|
+
return null;
|
|
21466
|
+
}
|
|
21467
|
+
return {
|
|
21468
|
+
code,
|
|
21469
|
+
issuer,
|
|
21470
|
+
};
|
|
21471
|
+
}
|
|
21472
|
+
function isStellarToken(token) {
|
|
21473
|
+
try {
|
|
21474
|
+
const stellarToken = token;
|
|
21475
|
+
return (Object.values(StellarTokenType).includes(stellarToken.chainAssetConfig.stellar.assetType) &&
|
|
21476
|
+
typeof stellarToken.chainAssetConfig.stellar.contractAddress === "string");
|
|
21477
|
+
}
|
|
21478
|
+
catch {
|
|
21479
|
+
return false;
|
|
21480
|
+
}
|
|
21481
|
+
}
|
|
21482
|
+
function isStellarIssuedToken(token) {
|
|
21483
|
+
try {
|
|
21484
|
+
return (isStellarToken(token) &&
|
|
21485
|
+
token.chainAssetConfig.stellar.assetType === StellarTokenType.ISSUER_TOKEN);
|
|
21486
|
+
}
|
|
21487
|
+
catch {
|
|
21488
|
+
return false;
|
|
21489
|
+
}
|
|
21490
|
+
}
|
|
21491
|
+
function getStellarHorizonApiUrl(chain) {
|
|
21492
|
+
try {
|
|
21493
|
+
const stellarChain = chain;
|
|
21494
|
+
const [horizonApiUrl] = stellarChain.horizonRpcList;
|
|
21495
|
+
if (typeof horizonApiUrl !== "string") {
|
|
21496
|
+
throw new Error("Invalid Horizon API URL");
|
|
21497
|
+
}
|
|
21498
|
+
return horizonApiUrl;
|
|
21499
|
+
}
|
|
21500
|
+
catch {
|
|
21501
|
+
return null;
|
|
21502
|
+
}
|
|
21503
|
+
}
|
|
21504
|
+
const VALID_ASSET_TYPES = new Set(Object.values(StellarHorizonAssetType));
|
|
21505
|
+
function isValidNativeAsset(asset) {
|
|
21506
|
+
return (typeof asset === "object" &&
|
|
21507
|
+
asset !== null &&
|
|
21508
|
+
"balance" in asset &&
|
|
21509
|
+
typeof asset.balance === "string" &&
|
|
21510
|
+
"asset_type" in asset &&
|
|
21511
|
+
asset.asset_type === StellarHorizonAssetType.NATIVE);
|
|
21512
|
+
}
|
|
21513
|
+
function isValidIssuedAsset(asset) {
|
|
21514
|
+
return (typeof asset === "object" &&
|
|
21515
|
+
asset !== null &&
|
|
21516
|
+
"balance" in asset &&
|
|
21517
|
+
typeof asset.balance === "string" &&
|
|
21518
|
+
"asset_type" in asset &&
|
|
21519
|
+
typeof asset.asset_type === "string" &&
|
|
21520
|
+
VALID_ASSET_TYPES.has(asset.asset_type) &&
|
|
21521
|
+
asset.asset_type !== StellarHorizonAssetType.NATIVE &&
|
|
21522
|
+
"asset_code" in asset &&
|
|
21523
|
+
typeof asset.asset_code === "string" &&
|
|
21524
|
+
"asset_issuer" in asset &&
|
|
21525
|
+
typeof asset.asset_issuer === "string" &&
|
|
21526
|
+
"limit" in asset &&
|
|
21527
|
+
typeof asset.limit === "string");
|
|
21528
|
+
}
|
|
21529
|
+
function isValidHorizonAsset(asset) {
|
|
21530
|
+
return isValidNativeAsset(asset) || isValidIssuedAsset(asset);
|
|
21531
|
+
}
|
|
21121
21532
|
|
|
21122
21533
|
const SUI_FEATURES = ["sui:signTransaction"];
|
|
21123
21534
|
function isSuiStandardWallet(wallet) {
|
|
@@ -21885,285 +22296,6 @@ async function getXummClient() {
|
|
|
21885
22296
|
return xummClient;
|
|
21886
22297
|
}
|
|
21887
22298
|
|
|
21888
|
-
const getQueryHeaders = (integratorId, requestId) => {
|
|
21889
|
-
return {
|
|
21890
|
-
...(integratorId ? { "X-Integrator-Id": integratorId } : {}),
|
|
21891
|
-
...(requestId ? { "X-Request-Id": requestId } : {}),
|
|
21892
|
-
};
|
|
21893
|
-
};
|
|
21894
|
-
const getStatusCode = (error) => {
|
|
21895
|
-
if (axios.isAxiosError(error)) {
|
|
21896
|
-
return error.response?.status;
|
|
21897
|
-
}
|
|
21898
|
-
return undefined;
|
|
21899
|
-
};
|
|
21900
|
-
const is404Error = (error) => {
|
|
21901
|
-
const statusCode = getStatusCode(error);
|
|
21902
|
-
if (statusCode === 404) {
|
|
21903
|
-
return true;
|
|
21904
|
-
}
|
|
21905
|
-
return false;
|
|
21906
|
-
};
|
|
21907
|
-
|
|
21908
|
-
var HistoryTxType;
|
|
21909
|
-
(function (HistoryTxType) {
|
|
21910
|
-
HistoryTxType[HistoryTxType["SWAP"] = 0] = "SWAP";
|
|
21911
|
-
HistoryTxType[HistoryTxType["BUY"] = 1] = "BUY";
|
|
21912
|
-
HistoryTxType[HistoryTxType["SEND"] = 2] = "SEND";
|
|
21913
|
-
})(HistoryTxType || (HistoryTxType = {}));
|
|
21914
|
-
|
|
21915
|
-
var TransactionType;
|
|
21916
|
-
(function (TransactionType) {
|
|
21917
|
-
TransactionType["BRIDGE"] = "BRIDGE";
|
|
21918
|
-
TransactionType["BRIDGE_CALL"] = "BRIDGE_CALL";
|
|
21919
|
-
TransactionType["CALL_BRIDGE"] = "CALL_BRIDGE";
|
|
21920
|
-
TransactionType["CALL_BRIDGE_CALL"] = "CALL_BRIDGE_CALL";
|
|
21921
|
-
})(TransactionType || (TransactionType = {}));
|
|
21922
|
-
var AxelarStatusResponseType;
|
|
21923
|
-
(function (AxelarStatusResponseType) {
|
|
21924
|
-
AxelarStatusResponseType["GAS_PAID_NOT_ENOUGH_GAS"] = "gas_paid_not_enough_gas";
|
|
21925
|
-
AxelarStatusResponseType["DESTINATION_EXECUTED"] = "destination_executed";
|
|
21926
|
-
AxelarStatusResponseType["EXPRESS_EXECUTED"] = "express_executed";
|
|
21927
|
-
AxelarStatusResponseType["CROSS_MULTICALL_EXECUTED"] = "CrossMulticallExecuted";
|
|
21928
|
-
AxelarStatusResponseType["CROSS_MULTICALL_FAILED"] = "CrossMulticallFailed";
|
|
21929
|
-
AxelarStatusResponseType["SRC_GATEWAY_CALLED"] = "source_gateway_called";
|
|
21930
|
-
AxelarStatusResponseType["DEST_GATEWAY_APPROVED"] = "destination_gateway_approved";
|
|
21931
|
-
AxelarStatusResponseType["DESTINATION_EXECUTE_ERROR"] = "destination_execute_error";
|
|
21932
|
-
AxelarStatusResponseType["DESTINATION_EXECUTING"] = "executing";
|
|
21933
|
-
AxelarStatusResponseType["UNKNOWN_ERROR"] = "unknown_error";
|
|
21934
|
-
AxelarStatusResponseType["CANNOT_FETCH_STATUS"] = "cannot_fetch_status";
|
|
21935
|
-
AxelarStatusResponseType["ERROR"] = "error";
|
|
21936
|
-
})(AxelarStatusResponseType || (AxelarStatusResponseType = {}));
|
|
21937
|
-
var TransactionStatus;
|
|
21938
|
-
(function (TransactionStatus) {
|
|
21939
|
-
// Submitted transaction, returned by squid axelar
|
|
21940
|
-
TransactionStatus["SUCCESS"] = "success";
|
|
21941
|
-
TransactionStatus["NEEDS_GAS"] = "needs_gas";
|
|
21942
|
-
TransactionStatus["ONGOING"] = "ongoing";
|
|
21943
|
-
TransactionStatus["PARTIAL_SUCCESS"] = "partial_success";
|
|
21944
|
-
TransactionStatus["NOT_FOUND"] = "not_found";
|
|
21945
|
-
// Unsubmitted Transaction, can be status from wallet
|
|
21946
|
-
TransactionStatus["INITIAL_LOADING"] = "initialLoading";
|
|
21947
|
-
TransactionStatus["GENERATING_DEPOSIT"] = "generating_deposit";
|
|
21948
|
-
TransactionStatus["ERROR"] = "error";
|
|
21949
|
-
TransactionStatus["WARNING"] = "warning";
|
|
21950
|
-
TransactionStatus["PENDING"] = "pending";
|
|
21951
|
-
TransactionStatus["REJECTED"] = "rejected";
|
|
21952
|
-
// Coral refund
|
|
21953
|
-
TransactionStatus["REFUNDED"] = "refunded";
|
|
21954
|
-
})(TransactionStatus || (TransactionStatus = {}));
|
|
21955
|
-
var SendTransactionStatus;
|
|
21956
|
-
(function (SendTransactionStatus) {
|
|
21957
|
-
SendTransactionStatus[SendTransactionStatus["ONGOING"] = 0] = "ONGOING";
|
|
21958
|
-
SendTransactionStatus[SendTransactionStatus["SUCCESS"] = 1] = "SUCCESS";
|
|
21959
|
-
SendTransactionStatus[SendTransactionStatus["ERROR"] = 2] = "ERROR";
|
|
21960
|
-
})(SendTransactionStatus || (SendTransactionStatus = {}));
|
|
21961
|
-
|
|
21962
|
-
const formatTransactionHistoryDate = (transaction) => {
|
|
21963
|
-
if (!transaction?.timestamp)
|
|
21964
|
-
return undefined;
|
|
21965
|
-
try {
|
|
21966
|
-
const date = new Date(Number(transaction.timestamp));
|
|
21967
|
-
// Format date to: MMM DD. Examples:
|
|
21968
|
-
// Jan 01
|
|
21969
|
-
// May 12
|
|
21970
|
-
const month = new Intl.DateTimeFormat(DEFAULT_LOCALE, {
|
|
21971
|
-
month: "short",
|
|
21972
|
-
}).format(date);
|
|
21973
|
-
const day = date.toLocaleString(DEFAULT_LOCALE, { day: "2-digit" });
|
|
21974
|
-
return { month, day };
|
|
21975
|
-
}
|
|
21976
|
-
catch (error) {
|
|
21977
|
-
console.error("Error formatting date:", error);
|
|
21978
|
-
return undefined;
|
|
21979
|
-
}
|
|
21980
|
-
};
|
|
21981
|
-
const getAxelarExplorerTxUrl = (urlPrefix, routeType, txID) => {
|
|
21982
|
-
if (!urlPrefix) {
|
|
21983
|
-
return undefined;
|
|
21984
|
-
}
|
|
21985
|
-
const txType = routeType ?? TransactionType.BRIDGE;
|
|
21986
|
-
if (txType === TransactionType.CALL_BRIDGE ||
|
|
21987
|
-
txType === TransactionType.BRIDGE) {
|
|
21988
|
-
return `${urlPrefix}transfer/${txID}`;
|
|
21989
|
-
}
|
|
21990
|
-
return `${urlPrefix}gmp/${txID}`;
|
|
21991
|
-
};
|
|
21992
|
-
const getSourceExplorerTxUrl = (chain, txID) => {
|
|
21993
|
-
if (!chain || !chain.blockExplorerUrls[0] || !txID) {
|
|
21994
|
-
return undefined;
|
|
21995
|
-
}
|
|
21996
|
-
let txSuffix;
|
|
21997
|
-
switch (chain.chainId) {
|
|
21998
|
-
case CHAIN_IDS.AGORIC:
|
|
21999
|
-
case CHAIN_IDS.XRPL:
|
|
22000
|
-
case CHAIN_IDS.XRPL_TESTNET:
|
|
22001
|
-
txSuffix = "/transactions/";
|
|
22002
|
-
break;
|
|
22003
|
-
default:
|
|
22004
|
-
txSuffix = "/tx/";
|
|
22005
|
-
}
|
|
22006
|
-
if (chain.blockExplorerUrls[0].endsWith("/")) {
|
|
22007
|
-
txSuffix = txSuffix.slice(1);
|
|
22008
|
-
}
|
|
22009
|
-
return `${chain.blockExplorerUrls[0]}${txSuffix}${txID}`;
|
|
22010
|
-
};
|
|
22011
|
-
const getMainExplorerUrl = (transaction) => {
|
|
22012
|
-
// The most accurate one is coming from squid /status api
|
|
22013
|
-
if (transaction?.statusResponse?.axelarTransactionUrl) {
|
|
22014
|
-
return transaction?.statusResponse.axelarTransactionUrl;
|
|
22015
|
-
}
|
|
22016
|
-
// If not, we can try to get it from the source chain
|
|
22017
|
-
if (transaction?.sourceTxExplorerUrl) {
|
|
22018
|
-
return transaction?.sourceTxExplorerUrl;
|
|
22019
|
-
}
|
|
22020
|
-
// If not, we can try to guess it from the transaction type
|
|
22021
|
-
if (transaction && transaction?.transactionId) {
|
|
22022
|
-
return getAxelarExplorerTxUrl(transaction.statusResponse?.axelarTransactionUrl, transaction.routeType, transaction.transactionId);
|
|
22023
|
-
}
|
|
22024
|
-
return undefined;
|
|
22025
|
-
};
|
|
22026
|
-
const formatDistance = (date, baseDate, options) => {
|
|
22027
|
-
const { includeSeconds = false, addSuffix = false, locale = { locale: DEFAULT_LOCALE }, } = options || {};
|
|
22028
|
-
const elapsedMilliseconds = Math.abs(new Date(date).getTime() - new Date(baseDate).getTime());
|
|
22029
|
-
const seconds = Math.round(elapsedMilliseconds / 1000);
|
|
22030
|
-
const minutes = Math.round(seconds / 60);
|
|
22031
|
-
const hours = Math.round(minutes / 60);
|
|
22032
|
-
const days = Math.round(hours / 24);
|
|
22033
|
-
const months = Math.round(days / 30.44);
|
|
22034
|
-
const years = Math.round(days / 365.25);
|
|
22035
|
-
const rtf = new Intl.RelativeTimeFormat(locale.locale, { numeric: "auto" });
|
|
22036
|
-
let formatted = "";
|
|
22037
|
-
if (includeSeconds && seconds < 45) {
|
|
22038
|
-
const unit = addSuffix ? "second" : "seconds";
|
|
22039
|
-
formatted = rtf.format(-seconds, unit);
|
|
22040
|
-
}
|
|
22041
|
-
else if (minutes < 60) {
|
|
22042
|
-
formatted = rtf.format(-minutes, "minutes");
|
|
22043
|
-
}
|
|
22044
|
-
else if (hours < 24) {
|
|
22045
|
-
formatted = rtf.format(-hours, "hours");
|
|
22046
|
-
}
|
|
22047
|
-
else if (days < 30) {
|
|
22048
|
-
formatted = rtf.format(-days, "days");
|
|
22049
|
-
}
|
|
22050
|
-
else if (months < 12) {
|
|
22051
|
-
formatted = rtf.format(-months, "months");
|
|
22052
|
-
}
|
|
22053
|
-
else {
|
|
22054
|
-
formatted = rtf.format(-years, "years");
|
|
22055
|
-
}
|
|
22056
|
-
// remove "ago" from the string
|
|
22057
|
-
// before: "2 minutes ago"
|
|
22058
|
-
// after: "2 minutes"
|
|
22059
|
-
return addSuffix ? formatted : formatted.replace(/\b(?:ago)\b/, "").trim();
|
|
22060
|
-
};
|
|
22061
|
-
const formatSeconds = (seconds, secondsTemplate = "s", minutesTemplate = "m", hoursTemplate = "h") => {
|
|
22062
|
-
let duration = "";
|
|
22063
|
-
if (seconds < 60) {
|
|
22064
|
-
duration = `${seconds.toString()}${secondsTemplate}`;
|
|
22065
|
-
}
|
|
22066
|
-
else {
|
|
22067
|
-
duration = formatDistance(0, seconds * 1000, { includeSeconds: true });
|
|
22068
|
-
}
|
|
22069
|
-
const result = duration.startsWith("1 ")
|
|
22070
|
-
? duration
|
|
22071
|
-
.replace(" minute", minutesTemplate)
|
|
22072
|
-
.replace(" hour", hoursTemplate)
|
|
22073
|
-
: duration
|
|
22074
|
-
.replace(" minutes", minutesTemplate)
|
|
22075
|
-
.replace(" hours", hoursTemplate);
|
|
22076
|
-
return result;
|
|
22077
|
-
};
|
|
22078
|
-
/**
|
|
22079
|
-
* Remove the chainData from statusResponse to gain some storage space
|
|
22080
|
-
*/
|
|
22081
|
-
const formatSwapTxStatusResponseForStorage = (sr) => {
|
|
22082
|
-
if (!sr) {
|
|
22083
|
-
return sr;
|
|
22084
|
-
}
|
|
22085
|
-
return {
|
|
22086
|
-
axelarTransactionUrl: sr.axelarTransactionUrl,
|
|
22087
|
-
toChain: sr.toChain?.transactionUrl
|
|
22088
|
-
? {
|
|
22089
|
-
transactionUrl: sr.toChain?.transactionUrl,
|
|
22090
|
-
}
|
|
22091
|
-
: undefined,
|
|
22092
|
-
};
|
|
22093
|
-
};
|
|
22094
|
-
const simplifyRouteAction = (action) => {
|
|
22095
|
-
return {
|
|
22096
|
-
type: action.type,
|
|
22097
|
-
provider: action.provider,
|
|
22098
|
-
data: {
|
|
22099
|
-
type: action.data?.type,
|
|
22100
|
-
},
|
|
22101
|
-
...(action.coralV2Order ? { isCoralV2: true } : undefined),
|
|
22102
|
-
};
|
|
22103
|
-
};
|
|
22104
|
-
const fetchSwapTransactionStatus = async ({ transaction, integratorId, apiUrl, }) => {
|
|
22105
|
-
const statusEndpoint = `${apiUrl}/v2/status`;
|
|
22106
|
-
try {
|
|
22107
|
-
const response = await axios.get(statusEndpoint, {
|
|
22108
|
-
params: {
|
|
22109
|
-
transactionId: transaction?.transactionIdForStatus ?? transaction?.transactionId,
|
|
22110
|
-
fromChainId: transaction?.fromChain,
|
|
22111
|
-
toChainId: transaction?.toChain,
|
|
22112
|
-
bridgeType: transaction?.bridgeType,
|
|
22113
|
-
quoteId: transaction?.quoteId,
|
|
22114
|
-
},
|
|
22115
|
-
headers: getQueryHeaders(integratorId, transaction?.quoteId),
|
|
22116
|
-
});
|
|
22117
|
-
return response.data;
|
|
22118
|
-
}
|
|
22119
|
-
catch (error) {
|
|
22120
|
-
if (error) {
|
|
22121
|
-
throw new Error("Fetch transaction status failed", { cause: error });
|
|
22122
|
-
}
|
|
22123
|
-
throw new Error("Fetch transaction status failed", { cause: undefined });
|
|
22124
|
-
}
|
|
22125
|
-
};
|
|
22126
|
-
const compareTransactionIds = (idA, idB) => {
|
|
22127
|
-
if (!idA || !idB) {
|
|
22128
|
-
return false;
|
|
22129
|
-
}
|
|
22130
|
-
const normalizedA = idA.toLowerCase();
|
|
22131
|
-
const normalizedB = idB.toLowerCase();
|
|
22132
|
-
return normalizedA.includes(normalizedB) || normalizedB.includes(normalizedA);
|
|
22133
|
-
};
|
|
22134
|
-
/**
|
|
22135
|
-
* Checks if the provided action is Coral bridge action
|
|
22136
|
-
*/
|
|
22137
|
-
function isCoralBridgeAction(action) {
|
|
22138
|
-
return (action.type === ActionType.RFQ &&
|
|
22139
|
-
// TODO: update types
|
|
22140
|
-
action.provider?.toLowerCase() === "coral");
|
|
22141
|
-
}
|
|
22142
|
-
function sleep(ms) {
|
|
22143
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
22144
|
-
}
|
|
22145
|
-
const isDepositRoute = (route) => {
|
|
22146
|
-
return (!!route &&
|
|
22147
|
-
route.transactionRequest?.type === SquidDataType.ChainflipDepositAddress);
|
|
22148
|
-
};
|
|
22149
|
-
/**
|
|
22150
|
-
* Checks if the route contains a Chainflip bridge action
|
|
22151
|
-
*/
|
|
22152
|
-
function isChainflipBridgeTransaction(actions = []) {
|
|
22153
|
-
return actions.some((action) => action.type === ActionType.BRIDGE &&
|
|
22154
|
-
action.data?.type === BridgeType.CHAINFLIP);
|
|
22155
|
-
}
|
|
22156
|
-
function getHistoryTransactionId(tx) {
|
|
22157
|
-
switch (tx.txType) {
|
|
22158
|
-
case HistoryTxType.SWAP:
|
|
22159
|
-
return tx.data.transactionId;
|
|
22160
|
-
case HistoryTxType.BUY:
|
|
22161
|
-
return tx.data.orderId;
|
|
22162
|
-
case HistoryTxType.SEND:
|
|
22163
|
-
return tx.data.hash;
|
|
22164
|
-
}
|
|
22165
|
-
}
|
|
22166
|
-
|
|
22167
22299
|
var QueryKeys;
|
|
22168
22300
|
(function (QueryKeys) {
|
|
22169
22301
|
QueryKeys["All"] = "all";
|
|
@@ -22196,6 +22328,8 @@ var QueryKeys;
|
|
|
22196
22328
|
QueryKeys["XrplAccountActivatedInfo"] = "xrplAccountActivatedInfo";
|
|
22197
22329
|
QueryKeys["FiatToCryptoPaymentMethods"] = "fiatToCryptoPaymentMethods";
|
|
22198
22330
|
QueryKeys["Stellar"] = "stellar";
|
|
22331
|
+
QueryKeys["StellarTrustLine"] = "stellarTrustLine";
|
|
22332
|
+
QueryKeys["IsStellarTrustLineApproved"] = "isStellarTrustLineApproved";
|
|
22199
22333
|
QueryKeys["StellarAccountActivatedInfo"] = "stellarAccountActivatedInfo";
|
|
22200
22334
|
QueryKeys["Hedera"] = "hedera";
|
|
22201
22335
|
QueryKeys["IsHederaTokenAssociated"] = "isHederaTokenAssociated";
|
|
@@ -22303,7 +22437,7 @@ const keys = () => ({
|
|
|
22303
22437
|
// ============
|
|
22304
22438
|
// Approval
|
|
22305
22439
|
// ============
|
|
22306
|
-
routeApproved: (routeData, allowanceInWei) => [
|
|
22440
|
+
routeApproved: (routeData, allowanceInWei, isAllowanceQueryEnabled, hasAllowance) => [
|
|
22307
22441
|
...keys().transactions(),
|
|
22308
22442
|
QueryKeys.RouteApproved,
|
|
22309
22443
|
routeData?.params.fromAddress,
|
|
@@ -22311,6 +22445,8 @@ const keys = () => ({
|
|
|
22311
22445
|
routeData?.params.fromToken,
|
|
22312
22446
|
routeData?.params.fromAmount,
|
|
22313
22447
|
allowanceInWei?.toString(),
|
|
22448
|
+
isAllowanceQueryEnabled,
|
|
22449
|
+
hasAllowance,
|
|
22314
22450
|
],
|
|
22315
22451
|
sendTransactionGas: (chainId, tokenAddress, from) => [
|
|
22316
22452
|
QueryKeys.All,
|
|
@@ -22383,6 +22519,23 @@ const keys = () => ({
|
|
|
22383
22519
|
// ============
|
|
22384
22520
|
// Stellar
|
|
22385
22521
|
// ============
|
|
22522
|
+
stellarTrustLine: (tokenAddress, chainId, address) => [
|
|
22523
|
+
...keys().stellar(),
|
|
22524
|
+
QueryKeys.StellarTrustLine,
|
|
22525
|
+
tokenAddress,
|
|
22526
|
+
chainId,
|
|
22527
|
+
address,
|
|
22528
|
+
],
|
|
22529
|
+
isStellarTrustLineApproved: (address, chainId, chainType, tokenAddress, trustLineLimit, amountToApprove) => [
|
|
22530
|
+
...keys().stellar(),
|
|
22531
|
+
QueryKeys.IsStellarTrustLineApproved,
|
|
22532
|
+
address,
|
|
22533
|
+
chainId,
|
|
22534
|
+
chainType,
|
|
22535
|
+
tokenAddress,
|
|
22536
|
+
trustLineLimit,
|
|
22537
|
+
amountToApprove?.toString(),
|
|
22538
|
+
],
|
|
22386
22539
|
stellarAccountActivatedInfo: (address, chainId, chainType) => [
|
|
22387
22540
|
...keys().stellar(),
|
|
22388
22541
|
QueryKeys.StellarAccountActivatedInfo,
|
|
@@ -22418,6 +22571,8 @@ const getPrefixKey = (key) => {
|
|
|
22418
22571
|
return [...keys().transactions(), key];
|
|
22419
22572
|
case QueryKeys.XrplTrustLine:
|
|
22420
22573
|
return [...keys().xrpl(), key];
|
|
22574
|
+
case QueryKeys.StellarTrustLine:
|
|
22575
|
+
return [...keys().stellar(), key];
|
|
22421
22576
|
case QueryKeys.IsHederaTokenAssociated:
|
|
22422
22577
|
return [...keys().hedera(), key];
|
|
22423
22578
|
default:
|
|
@@ -23132,7 +23287,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23132
23287
|
};
|
|
23133
23288
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23134
23289
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23135
|
-
const { fetchAllSecretBalances } = await import('./secretService-
|
|
23290
|
+
const { fetchAllSecretBalances } = await import('./secretService-aK5p-g0D.js');
|
|
23136
23291
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23137
23292
|
};
|
|
23138
23293
|
function getTokenAssetsKey(token) {
|
|
@@ -24605,6 +24760,25 @@ function convertEvmAddressToHederaAccountId(address) {
|
|
|
24605
24760
|
return "0.0." + Number(address);
|
|
24606
24761
|
}
|
|
24607
24762
|
|
|
24763
|
+
/**
|
|
24764
|
+
* Return the expiry of a route in milliseconds
|
|
24765
|
+
*
|
|
24766
|
+
* @param route - Squid route
|
|
24767
|
+
* @returns expiry in milliseconds
|
|
24768
|
+
*/
|
|
24769
|
+
function getRouteExpiry(route) {
|
|
24770
|
+
if (!route?.transactionRequest)
|
|
24771
|
+
return DEFAULT_ROUTE_REFETCH_INTERVAL;
|
|
24772
|
+
if (!isOnChainTxData(route.transactionRequest)) {
|
|
24773
|
+
return DEFAULT_ROUTE_REFETCH_INTERVAL;
|
|
24774
|
+
}
|
|
24775
|
+
const { expiryOffset } = route.transactionRequest;
|
|
24776
|
+
if (expiryOffset != null && Number(expiryOffset) >= 0) {
|
|
24777
|
+
return Number(expiryOffset) * 1_000;
|
|
24778
|
+
}
|
|
24779
|
+
return DEFAULT_ROUTE_REFETCH_INTERVAL;
|
|
24780
|
+
}
|
|
24781
|
+
|
|
24608
24782
|
/**
|
|
24609
24783
|
* Minimum length of a search query to search by address
|
|
24610
24784
|
* Some tokens can have very short addresses (e.g. "uosmo", "uixo", "satoshi", etc...)
|
|
@@ -26417,7 +26591,7 @@ function useStellarWallets() {
|
|
|
26417
26591
|
try {
|
|
26418
26592
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
26419
26593
|
const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module');
|
|
26420
|
-
const { formatStellarWallet } = await import('./stellarService.client-
|
|
26594
|
+
const { formatStellarWallet } = await import('./stellarService.client-BB88L49R.js');
|
|
26421
26595
|
const modules = [...initializeAllModules(), new LedgerModule()];
|
|
26422
26596
|
const promises = modules.map(async (module) => {
|
|
26423
26597
|
const isAvailable = await module.isAvailable();
|
|
@@ -27917,7 +28091,7 @@ function hederaWalletConnect(parameters) {
|
|
|
27917
28091
|
const optionalChains = config.chains.map((x) => x.id);
|
|
27918
28092
|
if (!optionalChains.length)
|
|
27919
28093
|
return;
|
|
27920
|
-
const { EthereumProvider } = await import('./index.es-
|
|
28094
|
+
const { EthereumProvider } = await import('./index.es-Rc3LIf6Y.js');
|
|
27921
28095
|
const rawProvider = await EthereumProvider.init({
|
|
27922
28096
|
...restParameters,
|
|
27923
28097
|
disableProviderPing: true,
|
|
@@ -29280,12 +29454,15 @@ const getAllXrplTokensBalance = async (userAddress, xrplTokens, xrplChains) => {
|
|
|
29280
29454
|
};
|
|
29281
29455
|
const getStellarTokenBalance = async (userAddress, token, chain) => {
|
|
29282
29456
|
const stellarClient = await getClient(chain);
|
|
29283
|
-
|
|
29457
|
+
if (!isStellarToken(token)) {
|
|
29458
|
+
throw new Error("Token must be a Stellar token");
|
|
29459
|
+
}
|
|
29460
|
+
const balance = await stellarClient.getBalance(userAddress, token.chainAssetConfig.stellar.contractAddress, chain.chainId);
|
|
29284
29461
|
return BigInt(balance);
|
|
29285
29462
|
};
|
|
29286
29463
|
const getAllStellarTokensBalance = async (userAddress, stellarTokens, stellarChains) => {
|
|
29287
29464
|
const getBalancesForChain = async (chain) => {
|
|
29288
|
-
const tokensForChain = stellarTokens.filter((t) => t.chainId === chain.chainId);
|
|
29465
|
+
const tokensForChain = stellarTokens.filter((t) => t.chainId === chain.chainId && isStellarToken(t));
|
|
29289
29466
|
const stellarClient = await getClient(chain);
|
|
29290
29467
|
const allBalances = await stellarClient.getAllBalances(userAddress, tokensForChain);
|
|
29291
29468
|
return allBalances.map((token) => {
|
|
@@ -29340,7 +29517,7 @@ class StellarRpcClient {
|
|
|
29340
29517
|
.build();
|
|
29341
29518
|
const simulateTxResponse = await this.server.simulateTransaction(tx);
|
|
29342
29519
|
if ("error" in simulateTxResponse) {
|
|
29343
|
-
const isNoBalanceError =
|
|
29520
|
+
const isNoBalanceError = /trying to get non-existing value for contract instance|trustline entry is missing for account/.test(simulateTxResponse.error);
|
|
29344
29521
|
// If the error message indicates that the user has no balance just return 0
|
|
29345
29522
|
// We don't want to spam with this error as it's pretty common
|
|
29346
29523
|
if (isNoBalanceError) {
|
|
@@ -29356,7 +29533,7 @@ class StellarRpcClient {
|
|
|
29356
29533
|
}
|
|
29357
29534
|
async getAllBalances(userAddress, tokens) {
|
|
29358
29535
|
const balancePromises = tokens.map((token) => {
|
|
29359
|
-
return this.getBalance(userAddress, token.
|
|
29536
|
+
return this.getBalance(userAddress, token.chainAssetConfig.stellar.contractAddress, token.chainId);
|
|
29360
29537
|
});
|
|
29361
29538
|
const results = await Promise.allSettled(balancePromises);
|
|
29362
29539
|
const balances = results.map((result) => {
|
|
@@ -29456,9 +29633,9 @@ class XrplRpcClient {
|
|
|
29456
29633
|
},
|
|
29457
29634
|
]);
|
|
29458
29635
|
}
|
|
29459
|
-
async getTrustLine(address,
|
|
29460
|
-
const response = await this.getTrustLines(address, issuer);
|
|
29461
|
-
const trustLine = response.lines.find((line) => line.currency ===
|
|
29636
|
+
async getTrustLine(address, asset) {
|
|
29637
|
+
const response = await this.getTrustLines(address, asset.issuer);
|
|
29638
|
+
const trustLine = response.lines.find((line) => line.currency === asset.code);
|
|
29462
29639
|
return trustLine ?? null;
|
|
29463
29640
|
}
|
|
29464
29641
|
async accountActivatedInfo(address) {
|
|
@@ -29634,9 +29811,26 @@ class StellarApiClient {
|
|
|
29634
29811
|
const baseReserveBn = BigInt(latestLedger.base_reserve_in_stroops);
|
|
29635
29812
|
return baseReserveBn;
|
|
29636
29813
|
}
|
|
29814
|
+
async getTrustLines(userAddress) {
|
|
29815
|
+
const response = await fetch(`${this.apiUrl}/accounts/${userAddress}`);
|
|
29816
|
+
if (!response.ok) {
|
|
29817
|
+
throw new Error(`Failed to fetch account data: ${response.statusText}`);
|
|
29818
|
+
}
|
|
29819
|
+
const data = await response.json();
|
|
29820
|
+
if (!Array.isArray(data?.balances)) {
|
|
29821
|
+
throw new Error("Invalid response from Horizon API");
|
|
29822
|
+
}
|
|
29823
|
+
const assets = data.balances.filter(isValidHorizonAsset);
|
|
29824
|
+
return assets.filter(isValidIssuedAsset);
|
|
29825
|
+
}
|
|
29826
|
+
async getTrustLine(address, asset) {
|
|
29827
|
+
const trustLines = await this.getTrustLines(address);
|
|
29828
|
+
const trustLine = trustLines.find((line) => line.asset_code === asset.code && line.asset_issuer === asset.issuer);
|
|
29829
|
+
return trustLine ?? null;
|
|
29830
|
+
}
|
|
29637
29831
|
}
|
|
29638
29832
|
|
|
29639
|
-
const DEFAULT_REFETCH_INTERVAL$
|
|
29833
|
+
const DEFAULT_REFETCH_INTERVAL$2 = 20_000;
|
|
29640
29834
|
function useStellarAccountActivation({ address, chain, token, }) {
|
|
29641
29835
|
/**
|
|
29642
29836
|
* Checks if the destination account exists on the Stellar network
|
|
@@ -29652,9 +29846,8 @@ function useStellarAccountActivation({ address, chain, token, }) {
|
|
|
29652
29846
|
if (!address) {
|
|
29653
29847
|
throw new Error("Destination address is required");
|
|
29654
29848
|
}
|
|
29655
|
-
|
|
29656
|
-
|
|
29657
|
-
if (typeof horizonApiUrl !== "string") {
|
|
29849
|
+
const horizonApiUrl = getStellarHorizonApiUrl(chain);
|
|
29850
|
+
if (!horizonApiUrl) {
|
|
29658
29851
|
throw new Error("Invalid Horizon API URL");
|
|
29659
29852
|
}
|
|
29660
29853
|
const stellarApiClient = new StellarApiClient(horizonApiUrl);
|
|
@@ -29670,7 +29863,7 @@ function useStellarAccountActivation({ address, chain, token, }) {
|
|
|
29670
29863
|
};
|
|
29671
29864
|
},
|
|
29672
29865
|
enabled: !!address && chain?.chainType === ChainType.STELLAR,
|
|
29673
|
-
refetchInterval: DEFAULT_REFETCH_INTERVAL$
|
|
29866
|
+
refetchInterval: DEFAULT_REFETCH_INTERVAL$2,
|
|
29674
29867
|
refetchOnWindowFocus: true,
|
|
29675
29868
|
});
|
|
29676
29869
|
return {
|
|
@@ -29678,6 +29871,149 @@ function useStellarAccountActivation({ address, chain, token, }) {
|
|
|
29678
29871
|
};
|
|
29679
29872
|
}
|
|
29680
29873
|
|
|
29874
|
+
/**
|
|
29875
|
+
* Maximum asset amount on Stellar
|
|
29876
|
+
* @see https://developers.stellar.org/docs/learn/fundamentals/stellar-data-structures/assets#amount-precision
|
|
29877
|
+
*/
|
|
29878
|
+
const MAX_ASSET_AMOUNT = "922337203685.4775807";
|
|
29879
|
+
const DEFAULT_REFETCH_INTERVAL$1 = 20_000;
|
|
29880
|
+
function useStellarTrustLine({ address, chain, token, amount }) {
|
|
29881
|
+
const { stellarSigner } = useSigner({ chain });
|
|
29882
|
+
const queryClient = useQueryClient();
|
|
29883
|
+
/**
|
|
29884
|
+
* Retrieves the destination account's trust line data for the given token
|
|
29885
|
+
*/
|
|
29886
|
+
const trustLineQuery = useQuery({
|
|
29887
|
+
queryKey: keys().stellarTrustLine(token?.address, chain?.chainId, address),
|
|
29888
|
+
queryFn: async () => {
|
|
29889
|
+
if (chain?.chainType !== ChainType.STELLAR ||
|
|
29890
|
+
token?.type !== ChainType.STELLAR) {
|
|
29891
|
+
return null;
|
|
29892
|
+
}
|
|
29893
|
+
if (!address || !isStellarAddressValid(address)) {
|
|
29894
|
+
return null;
|
|
29895
|
+
}
|
|
29896
|
+
// Only issued tokens require trust lines
|
|
29897
|
+
// Other token types like contract tokens don't need trust lines
|
|
29898
|
+
if (!isStellarIssuedToken(token)) {
|
|
29899
|
+
return null;
|
|
29900
|
+
}
|
|
29901
|
+
const asset = getStellarTrustLineAsset(token);
|
|
29902
|
+
if (!asset) {
|
|
29903
|
+
throw new Error("Invalid asset");
|
|
29904
|
+
}
|
|
29905
|
+
const horizonApiUrl = getStellarHorizonApiUrl(chain);
|
|
29906
|
+
if (!horizonApiUrl) {
|
|
29907
|
+
throw new Error("Invalid Horizon API URL");
|
|
29908
|
+
}
|
|
29909
|
+
const stellarApiClient = new StellarApiClient(horizonApiUrl);
|
|
29910
|
+
return stellarApiClient.getTrustLine(address, asset);
|
|
29911
|
+
},
|
|
29912
|
+
enabled: !!address &&
|
|
29913
|
+
chain?.chainType === ChainType.STELLAR &&
|
|
29914
|
+
token?.type === ChainType.STELLAR,
|
|
29915
|
+
refetchInterval: DEFAULT_REFETCH_INTERVAL$1,
|
|
29916
|
+
});
|
|
29917
|
+
/**
|
|
29918
|
+
* Creates a trust line where the destination account authorizes to receive the given token
|
|
29919
|
+
*/
|
|
29920
|
+
const createTrustLine = useMutation({
|
|
29921
|
+
mutationFn: async () => {
|
|
29922
|
+
try {
|
|
29923
|
+
if (!stellarSigner) {
|
|
29924
|
+
throw new Error("Stellar signer not found");
|
|
29925
|
+
}
|
|
29926
|
+
if (!address) {
|
|
29927
|
+
throw new Error("Destination address is required");
|
|
29928
|
+
}
|
|
29929
|
+
if (chain?.chainType !== ChainType.STELLAR ||
|
|
29930
|
+
token?.type !== ChainType.STELLAR) {
|
|
29931
|
+
throw new Error("Chain and token to approve must be a Stellar token");
|
|
29932
|
+
}
|
|
29933
|
+
if (!isStellarIssuedToken(token)) {
|
|
29934
|
+
throw new Error("Token must be a Stellar issued token");
|
|
29935
|
+
}
|
|
29936
|
+
const assetInfo = getStellarTrustLineAsset(token);
|
|
29937
|
+
if (!assetInfo) {
|
|
29938
|
+
throw new Error("Invalid asset");
|
|
29939
|
+
}
|
|
29940
|
+
const network = getStellarNetwork(chain.chainId);
|
|
29941
|
+
if (network == null) {
|
|
29942
|
+
throw new Error(`Stellar network not found for chain ${chain.chainId}`);
|
|
29943
|
+
}
|
|
29944
|
+
const client = await getClient(chain);
|
|
29945
|
+
const account = await client.getAccount(address);
|
|
29946
|
+
const asset = new Asset(assetInfo.code, assetInfo.issuer);
|
|
29947
|
+
const changeTrustOperation = Operation.changeTrust({
|
|
29948
|
+
asset,
|
|
29949
|
+
limit: MAX_ASSET_AMOUNT,
|
|
29950
|
+
});
|
|
29951
|
+
const builtTransaction = new TransactionBuilder(account, {
|
|
29952
|
+
fee: (BigInt(BASE_FEE) * BigInt(2)).toString(),
|
|
29953
|
+
networkPassphrase: network,
|
|
29954
|
+
})
|
|
29955
|
+
.addOperation(changeTrustOperation)
|
|
29956
|
+
.setTimeout(300)
|
|
29957
|
+
.build();
|
|
29958
|
+
const { signedTxXdr } = await stellarSigner.signTransaction(builtTransaction.toXDR(), {
|
|
29959
|
+
networkPassphrase: network,
|
|
29960
|
+
});
|
|
29961
|
+
const signedTransaction = new Transaction$1(signedTxXdr, network);
|
|
29962
|
+
const sentTransaction = await client.sendTransaction(signedTransaction);
|
|
29963
|
+
const txStatus = await client.waitForTransaction(sentTransaction.hash, {
|
|
29964
|
+
interval: 1_000,
|
|
29965
|
+
});
|
|
29966
|
+
if (txStatus !== rpc.Api.GetTransactionStatus.SUCCESS) {
|
|
29967
|
+
throw new Error(`Transaction failed with status: ${txStatus}`);
|
|
29968
|
+
}
|
|
29969
|
+
return true;
|
|
29970
|
+
}
|
|
29971
|
+
catch (error) {
|
|
29972
|
+
console.error("Error creating trust line:", error);
|
|
29973
|
+
return false;
|
|
29974
|
+
}
|
|
29975
|
+
},
|
|
29976
|
+
async onSuccess() {
|
|
29977
|
+
queryClient.invalidateQueries({
|
|
29978
|
+
queryKey: getPrefixKey(QueryKeys.StellarTrustLine),
|
|
29979
|
+
});
|
|
29980
|
+
},
|
|
29981
|
+
});
|
|
29982
|
+
/**
|
|
29983
|
+
* Checks if the destination account has created a trust line to receive the given token.
|
|
29984
|
+
*/
|
|
29985
|
+
const isTrustLineApproved = useQuery({
|
|
29986
|
+
queryKey: keys().isStellarTrustLineApproved(address, token?.chainId, token?.type, token?.address, trustLineQuery.data?.limit, amount),
|
|
29987
|
+
queryFn: async () => {
|
|
29988
|
+
if (token?.type !== ChainType.STELLAR) {
|
|
29989
|
+
return true;
|
|
29990
|
+
}
|
|
29991
|
+
// The native Stellar token doesn't need a trust line
|
|
29992
|
+
if (token.address.toLowerCase() === nativeStellarTokenAddress.toLowerCase()) {
|
|
29993
|
+
return true;
|
|
29994
|
+
}
|
|
29995
|
+
if (!amount) {
|
|
29996
|
+
throw new Error("Amount is required");
|
|
29997
|
+
}
|
|
29998
|
+
const limitBn = BigNumber$1(trustLineQuery.data?.limit || "0");
|
|
29999
|
+
const balanceBn = BigNumber$1(trustLineQuery.data?.balance || "0");
|
|
30000
|
+
const availableAllowanceBn = limitBn.minus(balanceBn);
|
|
30001
|
+
const amountBn = BigNumber$1(formatBNToReadable(amount, token.decimals));
|
|
30002
|
+
return availableAllowanceBn.gte(amountBn);
|
|
30003
|
+
},
|
|
30004
|
+
enabled: !!address &&
|
|
30005
|
+
!!amount &&
|
|
30006
|
+
!trustLineQuery?.isLoading &&
|
|
30007
|
+
trustLineQuery?.isFetched &&
|
|
30008
|
+
token?.type === ChainType.STELLAR,
|
|
30009
|
+
});
|
|
30010
|
+
return {
|
|
30011
|
+
createTrustLine,
|
|
30012
|
+
trustLineQuery,
|
|
30013
|
+
isTrustLineApproved,
|
|
30014
|
+
};
|
|
30015
|
+
}
|
|
30016
|
+
|
|
29681
30017
|
const useAddressBookStore = create(persist((set) => ({
|
|
29682
30018
|
addressBook: [],
|
|
29683
30019
|
add: (newAddressData) => {
|
|
@@ -31300,15 +31636,18 @@ async function sendTransactionXrpl({ amount, signer, to, token, from, }) {
|
|
|
31300
31636
|
txHash: hash,
|
|
31301
31637
|
};
|
|
31302
31638
|
}
|
|
31303
|
-
const
|
|
31639
|
+
const asset = parseXrplTokenAddress(token.address);
|
|
31640
|
+
if (!asset) {
|
|
31641
|
+
throw new Error("Invalid asset");
|
|
31642
|
+
}
|
|
31304
31643
|
const amountFormatted = formatBNToReadable(amount, token.decimals);
|
|
31305
31644
|
const { hash } = await signer.signAndSubmit({
|
|
31306
31645
|
network: xrplNetwork,
|
|
31307
31646
|
tx: {
|
|
31308
31647
|
...baseTransaction,
|
|
31309
31648
|
Amount: {
|
|
31310
|
-
currency,
|
|
31311
|
-
issuer,
|
|
31649
|
+
currency: asset.code,
|
|
31650
|
+
issuer: asset.issuer,
|
|
31312
31651
|
value: amountFormatted,
|
|
31313
31652
|
},
|
|
31314
31653
|
},
|
|
@@ -31972,7 +32311,12 @@ const useErc20Allowance = ({ tokenAddress, ownerAddress, spenderAddress, amount
|
|
|
31972
32311
|
const parsedOwnerAddress = parseEvmAddress(ownerAddress);
|
|
31973
32312
|
const parsedSpenderAddress = parseEvmAddress(spenderAddress);
|
|
31974
32313
|
const isNativeToken = parsedTokenAddress?.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
|
|
31975
|
-
const isDepositAddressTx = transactionType
|
|
32314
|
+
const isDepositAddressTx = !!transactionType &&
|
|
32315
|
+
[
|
|
32316
|
+
SquidDataType.DepositAddressCalldata,
|
|
32317
|
+
SquidDataType.DepositAddressWithSignature,
|
|
32318
|
+
SquidDataType.DepositAddressWithMemo,
|
|
32319
|
+
].includes(transactionType);
|
|
31976
32320
|
const result = useReadContract({
|
|
31977
32321
|
abi: erc20Abi,
|
|
31978
32322
|
address: parsedTokenAddress ?? undefined,
|
|
@@ -32041,7 +32385,7 @@ const useApproval = ({ squidRoute, }) => {
|
|
|
32041
32385
|
* On Error: Showing the error message if any
|
|
32042
32386
|
* @returns {boolean} approved
|
|
32043
32387
|
*/
|
|
32044
|
-
const routeApproved = useQuery(keys().routeApproved(squidRoute, allowanceInWei), async () => {
|
|
32388
|
+
const routeApproved = useQuery(keys().routeApproved(squidRoute, allowanceInWei, erc20AllowanceQueryEnabled, hasAllowance), async () => {
|
|
32045
32389
|
if (erc20AllowanceQueryEnabled) {
|
|
32046
32390
|
return hasAllowance;
|
|
32047
32391
|
}
|
|
@@ -35262,7 +35606,9 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35262
35606
|
if (!route?.transactionRequest)
|
|
35263
35607
|
return undefined;
|
|
35264
35608
|
const { quoteId } = route;
|
|
35609
|
+
const currentTx = getTransaction(id);
|
|
35265
35610
|
const tx = {
|
|
35611
|
+
...currentTx,
|
|
35266
35612
|
fromChain,
|
|
35267
35613
|
toChain,
|
|
35268
35614
|
routeType: route.transactionRequest.type,
|
|
@@ -35280,7 +35626,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35280
35626
|
};
|
|
35281
35627
|
setTransactionStoreState(id, tx);
|
|
35282
35628
|
return tx;
|
|
35283
|
-
}, [fromChain, setTransactionStoreState,
|
|
35629
|
+
}, [fromChain, toChain, setTransactionStoreState, getTransaction]);
|
|
35284
35630
|
const getCosmosSignerClient = useCallback(async () => {
|
|
35285
35631
|
if (!fromChain)
|
|
35286
35632
|
return null;
|
|
@@ -35652,7 +35998,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35652
35998
|
if (!route?.transactionRequest || !xrplSigner) {
|
|
35653
35999
|
throw new Error("Need all parameters");
|
|
35654
36000
|
}
|
|
35655
|
-
if (route.transactionRequest
|
|
36001
|
+
if (!isOnChainTxData(route.transactionRequest)) {
|
|
35656
36002
|
throw new Error("Invalid route type");
|
|
35657
36003
|
}
|
|
35658
36004
|
const { data } = route.transactionRequest;
|
|
@@ -35688,10 +36034,10 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35688
36034
|
}
|
|
35689
36035
|
}, {});
|
|
35690
36036
|
const swapMutationSui = useMutation(async ({ id, route }) => {
|
|
35691
|
-
if (!route || !suiSigner || !fromChain) {
|
|
36037
|
+
if (!route?.transactionRequest || !suiSigner || !fromChain) {
|
|
35692
36038
|
throw new Error("Need all parameters");
|
|
35693
36039
|
}
|
|
35694
|
-
if (route.transactionRequest
|
|
36040
|
+
if (!isOnChainTxData(route.transactionRequest)) {
|
|
35695
36041
|
throw new Error("Invalid route type");
|
|
35696
36042
|
}
|
|
35697
36043
|
const suiWalletState = connectedWalletsByChainType[ChainType.SUI];
|
|
@@ -35742,28 +36088,56 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35742
36088
|
});
|
|
35743
36089
|
}, {});
|
|
35744
36090
|
const swapMutationStellar = useMutation(async ({ id, route }) => {
|
|
35745
|
-
if (!stellarSigner ||
|
|
36091
|
+
if (!stellarSigner ||
|
|
36092
|
+
!route?.transactionRequest ||
|
|
36093
|
+
!squid ||
|
|
36094
|
+
!fromChain) {
|
|
35746
36095
|
throw new Error("Need all parameters");
|
|
35747
36096
|
}
|
|
36097
|
+
if (!isOnChainTxData(route.transactionRequest)) {
|
|
36098
|
+
throw new Error("Invalid route type");
|
|
36099
|
+
}
|
|
35748
36100
|
const fromChainId = route.params.fromChain;
|
|
35749
36101
|
const stellarNetwork = getStellarNetwork(fromChainId);
|
|
35750
36102
|
if (stellarNetwork == null) {
|
|
35751
36103
|
throw new Error(`No Stellar network found for chainId ${fromChainId}`);
|
|
35752
36104
|
}
|
|
35753
|
-
const { data: xdrHex, gasPrice } = route.transactionRequest;
|
|
35754
|
-
const { address } = await stellarSigner.getAddress();
|
|
35755
36105
|
const client = await getClient(fromChain);
|
|
35756
|
-
|
|
35757
|
-
|
|
35758
|
-
|
|
35759
|
-
|
|
35760
|
-
|
|
35761
|
-
|
|
35762
|
-
|
|
35763
|
-
|
|
35764
|
-
|
|
35765
|
-
|
|
35766
|
-
|
|
36106
|
+
// TODO: at the moment we're receiving different formats depending on the route type.
|
|
36107
|
+
//
|
|
36108
|
+
// For OnChainExecution we get a single operation xdr string, so we need to build
|
|
36109
|
+
// a full transaction frontend-side (by adding the operation to a new transaction).
|
|
36110
|
+
//
|
|
36111
|
+
// For DepositAddressCalldata we get the full transaction xdr,
|
|
36112
|
+
// so we just need to send it to the wallet for signing.
|
|
36113
|
+
//
|
|
36114
|
+
// In the future this will be standardized backend-side so we have a unified flow for all route types.
|
|
36115
|
+
let txXdrToSign;
|
|
36116
|
+
if (route.transactionRequest.type === SquidDataType.OnChainExecution) {
|
|
36117
|
+
const { data: operationXdrHex, gasPrice } = route.transactionRequest;
|
|
36118
|
+
const { address } = await stellarSigner.getAddress();
|
|
36119
|
+
const account = await client.getAccount(address);
|
|
36120
|
+
const operation = xdr.Operation.fromXDR(operationXdrHex, "hex");
|
|
36121
|
+
const builtTransaction = new TransactionBuilder(account, {
|
|
36122
|
+
fee: gasPrice || (BigInt(BASE_FEE) * BigInt(2)).toString(),
|
|
36123
|
+
networkPassphrase: stellarNetwork,
|
|
36124
|
+
})
|
|
36125
|
+
.addOperation(operation)
|
|
36126
|
+
.setTimeout(300)
|
|
36127
|
+
.build();
|
|
36128
|
+
// This is a smart-contract transaction, so it needs to be simulated first
|
|
36129
|
+
const preparedTransaction = await client.prepareTransaction(builtTransaction);
|
|
36130
|
+
txXdrToSign = preparedTransaction.toXDR();
|
|
36131
|
+
}
|
|
36132
|
+
else if (route.transactionRequest.type === SquidDataType.DepositAddressCalldata) {
|
|
36133
|
+
// For this route type, we get the full transaction xdr in the data field.
|
|
36134
|
+
// This is a payment transaction, so simulation must be skipped.
|
|
36135
|
+
txXdrToSign = route.transactionRequest.data;
|
|
36136
|
+
}
|
|
36137
|
+
else {
|
|
36138
|
+
throw new Error(`Invalid route type ${route.transactionRequest.type}`);
|
|
36139
|
+
}
|
|
36140
|
+
const { signedTxXdr } = await stellarSigner.signTransaction(txXdrToSign, {
|
|
35767
36141
|
networkPassphrase: stellarNetwork,
|
|
35768
36142
|
});
|
|
35769
36143
|
const signedTransaction = new Transaction$1(signedTxXdr, stellarNetwork);
|
|
@@ -35847,11 +36221,36 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35847
36221
|
squidRoute,
|
|
35848
36222
|
]);
|
|
35849
36223
|
const swapMutation = useMutation(async (mutationParams) => {
|
|
35850
|
-
if (!mutationParams.route)
|
|
35851
|
-
throw new Error("
|
|
36224
|
+
if (!mutationParams.route?.transactionRequest) {
|
|
36225
|
+
throw new Error("Route is required");
|
|
36226
|
+
}
|
|
35852
36227
|
const sourceChain = findChain(mutationParams.route.params?.fromChain);
|
|
35853
36228
|
if (!sourceChain)
|
|
35854
36229
|
throw new Error("Could not find source chain");
|
|
36230
|
+
// For deposit-with-signature routes, we need to prompt the user
|
|
36231
|
+
// for a signature before continuing the swap flow
|
|
36232
|
+
if (isDepositWithSignatureTxData(mutationParams.route.transactionRequest)) {
|
|
36233
|
+
if (!mutationParams.route.transactionRequest.signatureRequired) {
|
|
36234
|
+
throw new Error("Data to sign was empty");
|
|
36235
|
+
}
|
|
36236
|
+
switch (sourceChain.chainType) {
|
|
36237
|
+
case ChainType.EVM: {
|
|
36238
|
+
if (!evmSigner) {
|
|
36239
|
+
throw new Error("EVM signer is required");
|
|
36240
|
+
}
|
|
36241
|
+
const signature = await evmSigner.signMessage(mutationParams.route.transactionRequest.signatureRequired);
|
|
36242
|
+
const currentTx = getTransaction(mutationParams.id);
|
|
36243
|
+
setTransactionStoreState(mutationParams.id, {
|
|
36244
|
+
...currentTx,
|
|
36245
|
+
depositTxVerificationSignature: signature,
|
|
36246
|
+
});
|
|
36247
|
+
break;
|
|
36248
|
+
}
|
|
36249
|
+
default:
|
|
36250
|
+
throw new Error(`deposit-with-signature flow not implemented for chain type: ${sourceChain.chainType}`);
|
|
36251
|
+
}
|
|
36252
|
+
}
|
|
36253
|
+
// After getting signature (if needed), continue with the swap flow
|
|
35855
36254
|
switch (sourceChain.chainType) {
|
|
35856
36255
|
case ChainType.COSMOS: {
|
|
35857
36256
|
return swapMutationCosmos.mutateAsync(mutationParams);
|
|
@@ -36040,7 +36439,7 @@ const useGetRoute = () => {
|
|
|
36040
36439
|
};
|
|
36041
36440
|
const useGetRouteWrapper = ({ enabled, cacheTime = 5 * 60 * 1000, // 5 minutes
|
|
36042
36441
|
staleTime = 60 * 1000, // 1 minute
|
|
36043
|
-
refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt >
|
|
36442
|
+
refetchOnWindowFocus = (query) => Date.now() - query.state.dataUpdatedAt > DEFAULT_ROUTE_REFETCH_INTERVAL, // Update if older than default refetch interval, when window is focused
|
|
36044
36443
|
refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true, }) => {
|
|
36045
36444
|
const config = useConfigStore((state) => state.config);
|
|
36046
36445
|
const squid = useSquidStore((state) => state.squid);
|
|
@@ -36549,12 +36948,12 @@ function useXrplTrustLine({ address, chain, token, amount }) {
|
|
|
36549
36948
|
if (!address || !isXrplAddressValid(address)) {
|
|
36550
36949
|
return null;
|
|
36551
36950
|
}
|
|
36552
|
-
const
|
|
36553
|
-
if (!
|
|
36951
|
+
const trustLineAsset = parseXrplTokenAddress(token.address);
|
|
36952
|
+
if (!trustLineAsset) {
|
|
36554
36953
|
return null;
|
|
36555
36954
|
}
|
|
36556
36955
|
const xrplClient = await getClient(chain);
|
|
36557
|
-
const trustLine = await xrplClient.getTrustLine(address,
|
|
36956
|
+
const trustLine = await xrplClient.getTrustLine(address, trustLineAsset);
|
|
36558
36957
|
return trustLine;
|
|
36559
36958
|
},
|
|
36560
36959
|
enabled: !!address &&
|
|
@@ -36792,5 +37191,5 @@ const SquidProvider = ({ children, config, placeholder, }) => {
|
|
|
36792
37191
|
React.createElement(CosmosProvider, null, children)))))))))) : (placeholder);
|
|
36793
37192
|
};
|
|
36794
37193
|
|
|
36795
|
-
export {
|
|
36796
|
-
//# sourceMappingURL=index-
|
|
37194
|
+
export { useSwap as $, AxelarStatusResponseType as A, useKeyboardNavigation as B, CHAIN_IDS as C, DEFAULT_LOCALE as D, useSquidQueryClient as E, useSquid as F, useStellarAccountActivation as G, HistoryTxType as H, useStellarTrustLine as I, useAddressBookStore as J, useAssetsColorsStore as K, useFavoriteTokensStore as L, useHistoryStore as M, Nr as N, useSendTransactionStore as O, useConfigStore as P, QueryKeys as Q, useSquidStore as R, SquidStatusErrorType as S, TransactionErrorType as T, useSwapRoutePersistStore as U, useTransactionStore as V, Wo as W, XamanXrplNetwork as X, ConnectingWalletStatus as Y, useWalletStore as Z, useDepositAddress as _, WindowWalletFlag as a, sortTokensBySharedSubgraphIds as a$, useAllConnectedWalletBalances as a0, useAllTokensWithBalanceForChainType as a1, useCosmosBalance as a2, useEvmBalance as a3, useMultiChainBalance as a4, useMultipleTokenPrices as a5, useNativeBalance as a6, useNativeTokenForChain as a7, useSingleTokenPrice as a8, useSquidTokens as a9, useMultiChainWallet as aA, useSigner as aB, useWallet as aC, useWallets as aD, useXrplTrustLine as aE, TX_STATUS_CONSTANTS as aF, FINAL_TRANSACTION_STATUSES as aG, useGetFiatQuote as aH, useGetOnRampConfig as aI, useExecuteFiatQuote as aJ, useFiatOnRampTxStatus as aK, useFiatTransactions as aL, useCurrencyDetails as aM, useCountryDetails as aN, useAvailableQuotes as aO, useRecommendedQuote as aP, useGetOnrampPaymentTypes as aQ, useSuggestedFiatAmounts as aR, SquidProvider as aS, EnsService as aT, getXummClient as aU, isXamanXAppContext as aV, getQueryHeaders as aW, getStatusCode as aX, is404Error as aY, assetsBaseUrl as aZ, shareSubgraphId as a_, useHistoricalData as aa, useTokensData as ab, useEstimateSendTransaction as ac, useSendTransaction as ad, useSendTransactionGas as ae, useAllTransactionsStatus as af, useApproval as ag, useEstimate as ah, useEstimatePriceImpact as ai, useExecuteTransaction as aj, useGetRoute as ak, useGetRouteWrapper as al, useRouteWarnings as am, useSendTransactionStatus as an, useSwapTransactionStatus as ao, useAvatar as ap, useHistory as aq, useUserParams as ar, useDebouncedValue as as, useAddToken as at, useAutoConnect as au, useEnsDataForAddress as av, useEnsSearch as aw, useGnosisContext as ax, useIsSameAddressAndGnosisContext as ay, useIntegratorContext as az, chainTypeToZeroAddressMap as b, formatUnitsRounded as b$, getSupportedChainIdsForDirection as b0, filterChains as b1, filterTokens as b2, getTokenImage as b3, getNewSwapParamsFromInput as b4, sortAllTokens as b5, findToken as b6, findNativeToken as b7, normalizeIbcAddress as b8, groupTokensBySymbol as b9, isFallbackAddressNeeded as bA, suggestChainOrThrow as bB, normalizeError as bC, transactionErrorCode as bD, isUserRejectionError as bE, getTransactionError as bF, handleTransactionErrorEvents as bG, isSwapRouteError as bH, isStatusError as bI, createQuoteRequestParamsHash as bJ, WidgetEvents as bK, EvmNetworkNotSupportedErrorCode as bL, addEthereumChain as bM, parseEvmAddress as bN, formatEvmWallet as bO, filterWagmiConnector as bP, waitForReceiptWithRetry as bQ, getUserCountry as bR, getCountryData as bS, getCurrencyData as bT, adaptiveRound as bU, getSuggestedAmountsForCurrency as bV, HederaExtensionHelper as bW, convertHederaAccountIdToEvmAddress as bX, convertEvmAddressToHederaAccountId as bY, parseToBigInt as bZ, roundNumericValue as b_, groupTokensByChainId as ba, filterViewableTokens as bb, getSecretNetworkBalances as bc, getTokenAssetsKey as bd, fetchAssetsColors as be, initializeSquidWithAssetsColors as bf, isEmptyObject as bg, normalizeTokenSymbol as bh, areTokenSymbolsCompatible as bi, isEvmosChain as bj, getConfigWithDefaults as bk, randomIntFromInterval as bl, getTokensForChain as bm, getFirstAvailableChainId as bn, fetchHighestBalanceToken as bo, getInitialOrDefaultTokenAddressForChain as bp, getInitialTokenAddressForChain as bq, filterTokensForDestination as br, getInitialChainIdFromConfig as bs, getCosmosKey as bt, getKeysSettled as bu, getAllKeysForSupportedCosmosChains as bv, isCosmosAddressValid as bw, getCosmosSigningClient as bx, getCosmosChainInfosObject as by, connectCosmosWallet as bz, chainTypeToNativeTokenAddressMap as c, addTokenToWallet as c$, formatTokenAmount as c0, formatUsdAmount as c1, trimExtraDecimals as c2, getNumericValue as c3, cleanAmount as c4, convertTokenAmountToUSD as c5, convertUSDToTokenAmount as c6, calculateTotal24hChange as c7, getRouteExpiry as c8, searchTokens as c9, isChainflipBridgeTransaction as cA, isOnChainTxData as cB, isDepositWithSignatureTxData as cC, getHistoryTransactionId as cD, getStepStatuses as cE, getHalfSuccessState as cF, getStepsInfos as cG, getSwapTxStatusRefetchInterval as cH, getSendTxStatusRefetchInterval as cI, chainflipMultihopBridgeType as cJ, getBridgeType as cK, getTransactionStatus as cL, getTransactionEndStatus as cM, isHistoryTransactionPending as cN, isHistoryTransactionFailed as cO, isHistoryTransactionWarning as cP, isHistoryTransactionEnded as cQ, formatHash as cR, isWalletAddressValid as cS, redirectToExtensionsStore as cT, accessProperty as cU, populateWallets as cV, getDefaultChain as cW, sortWallets as cX, areSameAddress as cY, sortAddressBook as cZ, calculateTotalUsdBalanceUSD as c_, filterSolanaWallets as ca, isSolanaAddressValid as cb, executeSolanaSwap as cc, executeSolanaTransfer as cd, isStellarAddressValid as ce, getStellarNetwork as cf, stellarAddressToScVal as cg, getStellarTrustLineAsset as ch, isStellarToken as ci, isStellarIssuedToken as cj, getStellarHorizonApiUrl as ck, isValidIssuedAsset as cl, isValidHorizonAsset as cm, formatTransactionHistoryDate as cn, getAxelarExplorerTxUrl as co, getSourceExplorerTxUrl as cp, getMainExplorerUrl as cq, formatDistance as cr, formatSeconds as cs, formatSwapTxStatusResponseForStorage as ct, simplifyRouteAction as cu, fetchSwapTransactionStatus as cv, compareTransactionIds as cw, isCoralBridgeAction as cx, sleep as cy, isDepositRoute as cz, definedInWindow as d, isEvmChainNotSupportedError as d0, getWalletSupportedChainTypes as d1, getConnectorForChainType as d2, walletSupportsChainType as d3, connectWallet as d4, cancelConnectWallet as d5, isProblematicConnector as d6, mergeWallets as d7, isXionSmartContractAddress as d8, isXrplAddressValid as d9, buildXrplTrustSetTx as da, getXrplNetwork as db, parseXrplPaymentTx as dc, parseXrplTokenAddress as dd, er as e, formatBNToReadable as f, DEFAULT_ROUTE_REFETCH_INTERVAL as g, destinationAddressResetValue as h, fallbackAddressResetValue as i, nativeCosmosTokenAddress as j, nativeEvmTokenAddress as k, nativeSolanaTokenAddress as l, nativeStellarTokenAddress as m, nativeBitcoinTokenAddress as n, nativeSuiTokenAddress as o, nativeXrplTokenAddress as p, CosmosProvider as q, SendTransactionStatus as r, TransactionStatus as s, useTrackSearchEmpty as t, useCosmosContext as u, useSquidChains as v, walletIconBaseUrl as w, useClient as x, useCosmosForChain as y, useHederaTokenAssociations as z };
|
|
37195
|
+
//# sourceMappingURL=index-z1TwF4-p.js.map
|