@0xsquid/react-hooks 6.4.0-beta.1 → 6.4.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/dist/core/abis/ics20.json +128 -0
- package/dist/core/externalLinks.d.ts +1 -1
- package/dist/core/externalLinks.js +1 -1
- package/dist/core/externalLinks.js.map +1 -1
- package/dist/core/queries/queries-keys.d.ts +1 -7
- package/dist/core/queries/queries-keys.js +0 -24
- package/dist/core/queries/queries-keys.js.map +1 -1
- package/dist/core/types/error.d.ts +0 -5
- package/dist/core/types/error.js.map +1 -1
- package/dist/core/types/index.d.ts +0 -1
- package/dist/core/wagmiConfig.js +27 -16
- package/dist/core/wagmiConfig.js.map +1 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/swap/useSwap.d.ts +0 -1
- package/dist/hooks/swap/useSwap.js +0 -2
- package/dist/hooks/swap/useSwap.js.map +1 -1
- package/dist/hooks/transaction/useApproval.js +74 -20
- package/dist/hooks/transaction/useApproval.js.map +1 -1
- package/dist/hooks/transaction/{useAllowance.d.ts → useErc20Allowance.d.ts} +8 -7
- package/dist/hooks/transaction/{useAllowance.js → useErc20Allowance.js} +12 -16
- package/dist/hooks/transaction/useErc20Allowance.js.map +1 -0
- package/dist/hooks/transaction/useExecuteTransaction.js +5 -1
- package/dist/hooks/transaction/useExecuteTransaction.js.map +1 -1
- package/dist/hooks/transaction/useGetRoute.js +27 -10
- package/dist/hooks/transaction/useGetRoute.js.map +1 -1
- package/dist/hooks/transaction/useIcs20Allowance.d.ts +88 -0
- package/dist/hooks/transaction/useIcs20Allowance.js +40 -0
- package/dist/hooks/transaction/useIcs20Allowance.js.map +1 -0
- package/dist/hooks/user/useHistory.js +0 -1
- package/dist/hooks/user/useHistory.js.map +1 -1
- package/dist/hooks/user/useUserParams.d.ts +0 -1
- package/dist/hooks/user/useUserParams.js +1 -2
- package/dist/hooks/user/useUserParams.js.map +1 -1
- package/dist/hooks/wallet/useEns.d.ts +1 -0
- package/dist/hooks/wallet/useEns.js +13 -1
- package/dist/hooks/wallet/useEns.js.map +1 -1
- package/dist/hooks/wallet/useMultiChainWallet.d.ts +2 -13
- package/dist/hooks/wallet/useMultiChainWallet.js +2 -2
- package/dist/hooks/wallet/useMultiChainWallet.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/internal/assetsService.d.ts +10 -3
- package/dist/services/internal/assetsService.js +96 -14
- package/dist/services/internal/assetsService.js.map +1 -1
- package/dist/services/internal/evmService.d.ts +2 -0
- package/dist/services/internal/evmService.js +6 -0
- package/dist/services/internal/evmService.js.map +1 -1
- package/dist/services/internal/walletService.d.ts +0 -2
- package/dist/services/internal/walletService.js +1 -25
- package/dist/services/internal/walletService.js.map +1 -1
- package/dist/tests/assetsService.test.js +26 -13
- package/dist/tests/assetsService.test.js.map +1 -1
- package/package.json +3 -5
- package/dist/core/types/onramps/index.d.ts +0 -1
- package/dist/core/types/onramps/index.js +0 -2
- package/dist/core/types/onramps/index.js.map +0 -1
- package/dist/core/types/onramps/onramp.d.ts +0 -112
- package/dist/core/types/onramps/onramp.js +0 -2
- package/dist/core/types/onramps/onramp.js.map +0 -1
- package/dist/core/types/onramps/revolut.d.ts +0 -92
- package/dist/core/types/onramps/revolut.js +0 -2
- package/dist/core/types/onramps/revolut.js.map +0 -1
- package/dist/hooks/onramp/useFiatToCrypto.d.ts +0 -48
- package/dist/hooks/onramp/useFiatToCrypto.js +0 -145
- package/dist/hooks/onramp/useFiatToCrypto.js.map +0 -1
- package/dist/hooks/store/useFiatTransactionStore.d.ts +0 -20
- package/dist/hooks/store/useFiatTransactionStore.js +0 -36
- package/dist/hooks/store/useFiatTransactionStore.js.map +0 -1
- package/dist/hooks/transaction/useAllowance.js.map +0 -1
- package/dist/hooks/utils/useUtils.d.ts +0 -7
- package/dist/hooks/utils/useUtils.js +0 -20
- package/dist/hooks/utils/useUtils.js.map +0 -1
- package/dist/services/external/index.d.ts +0 -3
- package/dist/services/external/index.js +0 -4
- package/dist/services/external/index.js.map +0 -1
- package/dist/services/external/onramperClientAdapter.d.ts +0 -14
- package/dist/services/external/onramperClientAdapter.js +0 -136
- package/dist/services/external/onramperClientAdapter.js.map +0 -1
- package/dist/services/external/revolutClientAdapter.d.ts +0 -31
- package/dist/services/external/revolutClientAdapter.js +0 -228
- package/dist/services/external/revolutClientAdapter.js.map +0 -1
- package/dist/services/internal/fiatToCryptoService.d.ts +0 -21
- package/dist/services/internal/fiatToCryptoService.js +0 -41
- package/dist/services/internal/fiatToCryptoService.js.map +0 -1
- package/dist/tests/revolutClientAdapter.test.d.ts +0 -1
- package/dist/tests/revolutClientAdapter.test.js +0 -181
- package/dist/tests/revolutClientAdapter.test.js.map +0 -1
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
export class OnramperAdapter {
|
|
3
|
-
key = "onramper";
|
|
4
|
-
label = "Onramper";
|
|
5
|
-
supportedPaymentMethods = ["credit_card", "bank_transfer"];
|
|
6
|
-
baseUrl = "https://api.onramper.com";
|
|
7
|
-
apiKey = "ONRAMPER_API_KEY";
|
|
8
|
-
getHeaders() {
|
|
9
|
-
return {
|
|
10
|
-
Authorization: this.apiKey,
|
|
11
|
-
"Content-Type": "application/json",
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
async getQuote(fiatCurrency, cryptoCurrency, amount) {
|
|
15
|
-
try {
|
|
16
|
-
const { data } = await axios.get(`${this.baseUrl}/quotes/${fiatCurrency.toLowerCase()}/${cryptoCurrency.toLowerCase()}`, {
|
|
17
|
-
params: {
|
|
18
|
-
amount,
|
|
19
|
-
paymentMethod: "creditcard",
|
|
20
|
-
},
|
|
21
|
-
headers: this.getHeaders(),
|
|
22
|
-
});
|
|
23
|
-
// Get the best quote from available options
|
|
24
|
-
const bestQuote = data[0];
|
|
25
|
-
if (!bestQuote) {
|
|
26
|
-
throw new Error("No quotes available from Onramper");
|
|
27
|
-
}
|
|
28
|
-
const totalFees = bestQuote.networkFee + bestQuote.transactionFee;
|
|
29
|
-
const percentageFee = (totalFees / amount) * 100;
|
|
30
|
-
return {
|
|
31
|
-
fiatCurrency: fiatCurrency.toUpperCase(),
|
|
32
|
-
cryptoCurrencyID: cryptoCurrency.toUpperCase(),
|
|
33
|
-
amount,
|
|
34
|
-
fees: {
|
|
35
|
-
fixed: totalFees,
|
|
36
|
-
percentage: percentageFee,
|
|
37
|
-
},
|
|
38
|
-
cryptoAmount: bestQuote.payout,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
if (axios.isAxiosError(error)) {
|
|
43
|
-
throw new Error(error.response?.data?.message || "Failed to get quote from Onramper");
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async getTransactionStatus(transactionId) {
|
|
49
|
-
try {
|
|
50
|
-
const { data } = await axios.get(`${this.baseUrl}/transactions/${transactionId}`, {
|
|
51
|
-
headers: this.getHeaders(),
|
|
52
|
-
});
|
|
53
|
-
const statusMap = {
|
|
54
|
-
pending: "processing",
|
|
55
|
-
completed: "completed",
|
|
56
|
-
failed: "failed",
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
transactionId: data.transactionId,
|
|
60
|
-
status: statusMap[data.status] || "processing",
|
|
61
|
-
createdAt: data.statusDate,
|
|
62
|
-
updatedAt: data.statusDate,
|
|
63
|
-
errorMessage: null,
|
|
64
|
-
transactionHash: data.transactionHash || undefined,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
if (axios.isAxiosError(error)) {
|
|
69
|
-
throw new Error(error.response?.data?.message ||
|
|
70
|
-
"Failed to get transaction status from Onramper");
|
|
71
|
-
}
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async executeQuote(executeQuoteRequest) {
|
|
76
|
-
try {
|
|
77
|
-
const { data } = await axios.post(`${this.baseUrl}/checkout/intent`, {
|
|
78
|
-
onramp: "onramper",
|
|
79
|
-
source: executeQuoteRequest.fiatCurrency.toLowerCase(),
|
|
80
|
-
destination: executeQuoteRequest.cryptoCurrencyID.toLowerCase(),
|
|
81
|
-
amount: executeQuoteRequest.amount,
|
|
82
|
-
type: "buy",
|
|
83
|
-
paymentMethod: executeQuoteRequest.paymentMethod === "credit_card"
|
|
84
|
-
? "creditcard"
|
|
85
|
-
: "bank",
|
|
86
|
-
network: this.getCryptoNetwork(executeQuoteRequest.cryptoCurrencyID),
|
|
87
|
-
// partnerContext: executeQuoteRequest.orderId,
|
|
88
|
-
metaData: {
|
|
89
|
-
// quoteId: executeQuoteRequest.orderId,
|
|
90
|
-
},
|
|
91
|
-
wallet: {
|
|
92
|
-
address: executeQuoteRequest.walletAddress,
|
|
93
|
-
},
|
|
94
|
-
}, { headers: this.getHeaders() });
|
|
95
|
-
return {
|
|
96
|
-
orderId: data.message.transactionInformation.transactionId,
|
|
97
|
-
redirectUrl: data.message.transactionInformation.redirectUrl,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (axios.isAxiosError(error)) {
|
|
102
|
-
throw new Error(error.response?.data?.message || "Failed to execute quote");
|
|
103
|
-
}
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
getCryptoNetwork(cryptoCurrency) {
|
|
108
|
-
const networkMap = {
|
|
109
|
-
BTC: "bitcoin",
|
|
110
|
-
ETH: "ethereum",
|
|
111
|
-
SOL: "solana",
|
|
112
|
-
};
|
|
113
|
-
return networkMap[cryptoCurrency.toUpperCase()] || "ethereum";
|
|
114
|
-
}
|
|
115
|
-
async getConfiguration() {
|
|
116
|
-
try {
|
|
117
|
-
const { data } = await axios.get(`${this.baseUrl}/config`, {
|
|
118
|
-
headers: this.getHeaders(),
|
|
119
|
-
});
|
|
120
|
-
return {
|
|
121
|
-
supportedCountries: data.supportedCountries || [],
|
|
122
|
-
supportedCurrencies: data.supportedCurrencies || [],
|
|
123
|
-
supportedPaymentMethods: [...this.supportedPaymentMethods],
|
|
124
|
-
supportedTokens: data.supportedTokens || [],
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
if (axios.isAxiosError(error)) {
|
|
129
|
-
throw new Error(error.response?.data?.message ||
|
|
130
|
-
"Failed to fetch Onramper configuration");
|
|
131
|
-
}
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=onramperClientAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onramperClientAdapter.js","sourceRoot":"","sources":["../../../src/services/external/onramperClientAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,MAAM,OAAO,eAAe;IACjB,GAAG,GAAG,UAAU,CAAC;IAEjB,KAAK,GAAG,UAAU,CAAC;IAEnB,uBAAuB,GAAG,CAAC,aAAa,EAAE,eAAe,CAAU,CAAC;IAE5D,OAAO,GAAW,0BAA0B,CAAC;IAE7C,MAAM,GAAW,kBAAkB,CAAC;IAE7C,UAAU;QAChB,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,MAAM;YAC1B,cAAc,EAAE,kBAAkB;SACnC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,YAAoB,EACpB,cAAsB,EACtB,MAAc;QAEd,IAAI;YACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,IAAI,CAAC,OAAO,WAAW,YAAY,CAAC,WAAW,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,EAAE,EACtF;g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C,CAAC;aACH;YACD,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ChainData, Token } from "@0xsquid/squid-types";
|
|
2
|
-
import { ExecuteFiatQuoteResult, ExecuteQuoteClient, FiatToCryptoConfig, FiatToCryptoProvider, OnRampQuoteResponse, OnRampTransactionStatus } from "../../core/types/onramps/onramp";
|
|
3
|
-
import { RevolutConfig, RevolutQuoteResponse } from "../../core/types/onramps/revolut";
|
|
4
|
-
export declare class RevolutClientAdapter implements FiatToCryptoProvider {
|
|
5
|
-
readonly key = "revolut";
|
|
6
|
-
readonly label = "Revolut";
|
|
7
|
-
readonly supportedPaymentMethods: readonly ["card", "revolut", "apple-pay", "google-pay"];
|
|
8
|
-
private readonly baseUrl;
|
|
9
|
-
private getCountryData;
|
|
10
|
-
private getCurrencyData;
|
|
11
|
-
private findMatchingChain;
|
|
12
|
-
private findMatchingToken;
|
|
13
|
-
private filterAndMapTokens;
|
|
14
|
-
mapConfigResponse(data: RevolutConfig, squidConfig: {
|
|
15
|
-
chains: ChainData[];
|
|
16
|
-
tokens: Token[];
|
|
17
|
-
}): FiatToCryptoConfig;
|
|
18
|
-
mapQuoteResponse(data: RevolutQuoteResponse, fiatCurrency: string, cryptoCurrencyID: string, originalAmount: number): OnRampQuoteResponse;
|
|
19
|
-
mapPaymentMethod(method: string): string;
|
|
20
|
-
calculateTotalFees(data: RevolutQuoteResponse, amount: number): {
|
|
21
|
-
totalFees: number;
|
|
22
|
-
percentageFee: number;
|
|
23
|
-
};
|
|
24
|
-
getQuote(fiatCurrency: string, cryptoCurrencyID: string, amount: number, paymentMethod?: string, region?: string): Promise<OnRampQuoteResponse>;
|
|
25
|
-
getTransactionStatus(transactionId: string, walletAddress: string): Promise<OnRampTransactionStatus>;
|
|
26
|
-
executeQuote(params: ExecuteQuoteClient): Promise<ExecuteFiatQuoteResult>;
|
|
27
|
-
getConfiguration(squidConfig: {
|
|
28
|
-
chains: ChainData[];
|
|
29
|
-
tokens: Token[];
|
|
30
|
-
}): Promise<FiatToCryptoConfig>;
|
|
31
|
-
}
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { countries } from "countries-list";
|
|
3
|
-
import getSymbolFromCurrency from "currency-symbol-map";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
import { nativeEvmTokenAddress } from "../../core/constants";
|
|
6
|
-
export class RevolutClientAdapter {
|
|
7
|
-
key = "revolut";
|
|
8
|
-
label = "Revolut";
|
|
9
|
-
supportedPaymentMethods = [
|
|
10
|
-
"card",
|
|
11
|
-
"revolut",
|
|
12
|
-
"apple-pay",
|
|
13
|
-
"google-pay",
|
|
14
|
-
];
|
|
15
|
-
baseUrl = "https://squid-app-v2-git-feat-api-fiat-onramp-0xsquid.vercel.app/api/fiat-to-crypto/revolut";
|
|
16
|
-
// ================================
|
|
17
|
-
// DATA MAPPING FUNCTIONS
|
|
18
|
-
// ================================
|
|
19
|
-
getCountryData(countryCode) {
|
|
20
|
-
try {
|
|
21
|
-
if (!countries)
|
|
22
|
-
return null;
|
|
23
|
-
const countryCodeUpper = countryCode.toUpperCase();
|
|
24
|
-
const countryData = countries[countryCodeUpper];
|
|
25
|
-
return countryData ? { ...countryData, code: countryCodeUpper } : null;
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
getCurrencyData(currencyCode) {
|
|
32
|
-
try {
|
|
33
|
-
const symbol = getSymbolFromCurrency(currencyCode);
|
|
34
|
-
return {
|
|
35
|
-
denomination: currencyCode,
|
|
36
|
-
symbol: symbol ?? currencyCode,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
findMatchingChain(revolutBlockchain, chains) {
|
|
44
|
-
return chains.find((c) => c.networkIdentifier.toUpperCase() === revolutBlockchain);
|
|
45
|
-
}
|
|
46
|
-
findMatchingToken(params) {
|
|
47
|
-
const { revolutToken, chain, tokens } = params;
|
|
48
|
-
// Filter tokens by chain first
|
|
49
|
-
const chainTokens = tokens.filter((t) => t.chainId === chain.chainId);
|
|
50
|
-
if (revolutToken.smartContractAddress) {
|
|
51
|
-
// For tokens with contract address (EVM tokens)
|
|
52
|
-
return chainTokens.find((t) => t.address?.toLowerCase() ===
|
|
53
|
-
revolutToken.smartContractAddress?.toLowerCase());
|
|
54
|
-
}
|
|
55
|
-
// For native tokens (BTC, ETH, etc.)
|
|
56
|
-
return chainTokens.find((t) => t.address?.toLowerCase() === nativeEvmTokenAddress &&
|
|
57
|
-
t.symbol.toUpperCase() === revolutToken.currency.toUpperCase());
|
|
58
|
-
}
|
|
59
|
-
filterAndMapTokens(revolutTokens, squidConfig) {
|
|
60
|
-
return revolutTokens
|
|
61
|
-
.map((revolutToken) => {
|
|
62
|
-
try {
|
|
63
|
-
const chain = this.findMatchingChain(revolutToken.blockchain, squidConfig.chains);
|
|
64
|
-
if (!chain)
|
|
65
|
-
return null;
|
|
66
|
-
const token = this.findMatchingToken({
|
|
67
|
-
revolutToken,
|
|
68
|
-
chain,
|
|
69
|
-
tokens: squidConfig.tokens,
|
|
70
|
-
});
|
|
71
|
-
if (!token)
|
|
72
|
-
return null;
|
|
73
|
-
return { ...token, cryptoCurrencyID: revolutToken.id };
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
.filter((token) => token !== null);
|
|
80
|
-
}
|
|
81
|
-
mapConfigResponse(data, squidConfig) {
|
|
82
|
-
try {
|
|
83
|
-
// Transform country codes into enhanced country info
|
|
84
|
-
const supportedCountries = data.countries
|
|
85
|
-
.map((code) => this.getCountryData(code))
|
|
86
|
-
.filter((country) => country !== null);
|
|
87
|
-
// Transform currencies with additional data
|
|
88
|
-
const currencies = (data.fiat || [])
|
|
89
|
-
.map((fc) => {
|
|
90
|
-
const currencyData = this.getCurrencyData(fc.currency);
|
|
91
|
-
if (!currencyData)
|
|
92
|
-
return null;
|
|
93
|
-
return {
|
|
94
|
-
...currencyData,
|
|
95
|
-
minLimit: fc.min_limit,
|
|
96
|
-
maxLimit: fc.max_limit,
|
|
97
|
-
};
|
|
98
|
-
})
|
|
99
|
-
.filter((currency) => currency !== null);
|
|
100
|
-
// Filter and map tokens that exist in both systems
|
|
101
|
-
const allowedTokens = this.filterAndMapTokens(data.crypto, squidConfig);
|
|
102
|
-
return {
|
|
103
|
-
supportedCountries,
|
|
104
|
-
supportedCurrencies: currencies,
|
|
105
|
-
supportedPaymentMethods: data.payment_methods,
|
|
106
|
-
supportedTokens: allowedTokens,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
console.error("[Revolut Adapter] Error mapping config response:", error);
|
|
111
|
-
// Return empty but valid config instead of throwing
|
|
112
|
-
return {
|
|
113
|
-
supportedCountries: [],
|
|
114
|
-
supportedCurrencies: [],
|
|
115
|
-
supportedPaymentMethods: [],
|
|
116
|
-
supportedTokens: [],
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
mapQuoteResponse(data, fiatCurrency, cryptoCurrencyID, originalAmount) {
|
|
121
|
-
const { totalFees, percentageFee } = this.calculateTotalFees(data, originalAmount);
|
|
122
|
-
return {
|
|
123
|
-
fiatCurrency,
|
|
124
|
-
cryptoCurrencyID,
|
|
125
|
-
amount: originalAmount,
|
|
126
|
-
fees: {
|
|
127
|
-
fixed: totalFees,
|
|
128
|
-
percentage: percentageFee,
|
|
129
|
-
},
|
|
130
|
-
cryptoAmount: data.crypto.amount,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
mapPaymentMethod(method) {
|
|
134
|
-
const methodMap = {
|
|
135
|
-
credit_card: "card",
|
|
136
|
-
bank_transfer: "revolut",
|
|
137
|
-
apple_pay: "apple-pay",
|
|
138
|
-
google_pay: "google-pay",
|
|
139
|
-
};
|
|
140
|
-
return methodMap[method] || "card";
|
|
141
|
-
}
|
|
142
|
-
calculateTotalFees(data, amount) {
|
|
143
|
-
const totalFees = Number((data.service_fee.amount +
|
|
144
|
-
data.network_fee.amount +
|
|
145
|
-
data.partner_fee.amount).toFixed(2));
|
|
146
|
-
const percentageFee = Number(((totalFees / amount) * 100).toFixed(2));
|
|
147
|
-
return { totalFees, percentageFee };
|
|
148
|
-
}
|
|
149
|
-
async getQuote(fiatCurrency, cryptoCurrencyID, amount, paymentMethod = "card", region = "GB") {
|
|
150
|
-
try {
|
|
151
|
-
const { data } = await axios.get(`${this.baseUrl}/quote`, {
|
|
152
|
-
params: {
|
|
153
|
-
fiatCurrency,
|
|
154
|
-
cryptoCurrencyID,
|
|
155
|
-
amount,
|
|
156
|
-
paymentMethod: this.mapPaymentMethod(paymentMethod),
|
|
157
|
-
region,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
const { totalFees, percentageFee } = this.calculateTotalFees(data, amount);
|
|
161
|
-
return {
|
|
162
|
-
fiatCurrency,
|
|
163
|
-
cryptoCurrencyID,
|
|
164
|
-
amount,
|
|
165
|
-
fees: {
|
|
166
|
-
fixed: totalFees,
|
|
167
|
-
percentage: percentageFee,
|
|
168
|
-
},
|
|
169
|
-
cryptoAmount: data.crypto.amount,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
throw new Error("Failed to get quote from Revolut");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
async getTransactionStatus(transactionId, walletAddress) {
|
|
177
|
-
try {
|
|
178
|
-
const { data } = await axios.get(`${this.baseUrl}/status/${transactionId}`, {
|
|
179
|
-
params: {
|
|
180
|
-
wallet: walletAddress,
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
return {
|
|
184
|
-
transactionId: data.transactionId,
|
|
185
|
-
status: data.status,
|
|
186
|
-
createdAt: data.createdAt,
|
|
187
|
-
updatedAt: data.updatedAt,
|
|
188
|
-
transactionHash: data.transactionHash,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
throw new Error("Failed to get transaction status");
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async executeQuote(params) {
|
|
196
|
-
try {
|
|
197
|
-
const orderId = uuidv4();
|
|
198
|
-
const serverParams = {
|
|
199
|
-
orderId,
|
|
200
|
-
fiatCurrency: params.fiatCurrency,
|
|
201
|
-
cryptoCurrencyID: params.cryptoCurrencyID,
|
|
202
|
-
amount: params.amount,
|
|
203
|
-
walletAddress: params.walletAddress,
|
|
204
|
-
paymentMethod: this.mapPaymentMethod(params.paymentMethod),
|
|
205
|
-
region: params.region || "GB",
|
|
206
|
-
// partnerRedirectUrl: "",
|
|
207
|
-
};
|
|
208
|
-
const { data } = await axios.post(`${this.baseUrl}/execute`, serverParams);
|
|
209
|
-
return {
|
|
210
|
-
redirectUrl: data.redirectUrl,
|
|
211
|
-
orderId,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
throw new Error("Failed to execute quote");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
async getConfiguration(squidConfig) {
|
|
219
|
-
try {
|
|
220
|
-
const { data } = await axios.get(`${this.baseUrl}/config`);
|
|
221
|
-
return this.mapConfigResponse(data, squidConfig);
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
throw new Error("Failed to fetch Revolut configuration");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=revolutClientAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"revolutClientAdapter.js","sourceRoot":"","sources":["../../../src/services/external/revolutClientAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,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us } from "../../core/types/onramps/onramp";
|
|
2
|
-
import { ChainData, Token } from "@0xsquid/squid-types";
|
|
3
|
-
import { ICountry } from "countries-list";
|
|
4
|
-
export declare class FiatToCryptoService {
|
|
5
|
-
private provider;
|
|
6
|
-
constructor(provider: FiatToCryptoProvider | undefined);
|
|
7
|
-
static getProviderInfo(provider: FiatToCryptoProvider): {
|
|
8
|
-
key: string | undefined;
|
|
9
|
-
label: string | undefined;
|
|
10
|
-
supportedPaymentMethods: readonly string[] | undefined;
|
|
11
|
-
};
|
|
12
|
-
getQuote(fiatCurrency: string, cryptoCurrencyID: string, amount: number, paymentMethod?: string, region?: string): Promise<OnRampQuoteResponse>;
|
|
13
|
-
getTransactionStatus(transactionId: string, walletAddress: string): Promise<OnRampTransactionStatus>;
|
|
14
|
-
executeQuote(executeQuoteRequest: ExecuteQuoteClient): Promise<ExecuteFiatQuoteResult>;
|
|
15
|
-
getConfiguration(squidConfig: {
|
|
16
|
-
chains: ChainData[];
|
|
17
|
-
tokens: Token[];
|
|
18
|
-
}): Promise<FiatToCryptoConfig>;
|
|
19
|
-
getCountryData(countryCode: string): ICountry;
|
|
20
|
-
getCurrencyData(currencyCode: string): FiatCurrencyEnhanced;
|
|
21
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import getSymbolFromCurrency from "currency-symbol-map";
|
|
2
|
-
import { countries } from "countries-list";
|
|
3
|
-
export class FiatToCryptoService {
|
|
4
|
-
provider;
|
|
5
|
-
constructor(provider) {
|
|
6
|
-
if (!provider) {
|
|
7
|
-
throw new Error("Provider is required");
|
|
8
|
-
}
|
|
9
|
-
this.provider = provider;
|
|
10
|
-
}
|
|
11
|
-
static getProviderInfo(provider) {
|
|
12
|
-
return {
|
|
13
|
-
key: provider.key,
|
|
14
|
-
label: provider.label,
|
|
15
|
-
supportedPaymentMethods: provider.supportedPaymentMethods,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
async getQuote(fiatCurrency, cryptoCurrencyID, amount, paymentMethod = "card", region = "GB") {
|
|
19
|
-
return this.provider.getQuote(fiatCurrency, cryptoCurrencyID, amount, paymentMethod, region);
|
|
20
|
-
}
|
|
21
|
-
async getTransactionStatus(transactionId, walletAddress) {
|
|
22
|
-
return this.provider.getTransactionStatus(transactionId, walletAddress);
|
|
23
|
-
}
|
|
24
|
-
async executeQuote(executeQuoteRequest) {
|
|
25
|
-
return this.provider.executeQuote(executeQuoteRequest);
|
|
26
|
-
}
|
|
27
|
-
async getConfiguration(squidConfig) {
|
|
28
|
-
return this.provider.getConfiguration(squidConfig);
|
|
29
|
-
}
|
|
30
|
-
getCountryData(countryCode) {
|
|
31
|
-
const countryCodeUpper = countryCode.toUpperCase();
|
|
32
|
-
return countries[countryCodeUpper];
|
|
33
|
-
}
|
|
34
|
-
getCurrencyData(currencyCode) {
|
|
35
|
-
return {
|
|
36
|
-
denomination: currencyCode,
|
|
37
|
-
symbol: getSymbolFromCurrency(currencyCode) ?? "",
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=fiatToCryptoService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fiatToCryptoService.js","sourceRoot":"","sources":["../../../src/services/internal/fiatToCryptoService.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,qBAAqB,CAAC;AAYxD,OAAO,EAAE,SAAS,EAAY,MAAM,gBAAgB,CAAC;AAErD,MAAM,OAAO,mBAAmB;IACtB,QAAQ,CAAuB;IAEvC,YAAY,QAA0C;QACpD,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACzC;QACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,QAA8B;QACnD,OAAO;YACL,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,uBAAuB,EAAE,QAAQ,CAAC,uBAAuB;SAC1D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,YAAoB,EACpB,gBAAwB,EACxB,MAAc,EACd,gBAAwB,MAAM,EAC9B,SAAiB,IAAI;QAErB,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAC3B,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,aAAa,EACb,MAAM,CACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,aAAqB,EACrB,aAAqB;QAErB,OAAO,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,mBAAuC;QAEvC,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,WAGtB;QACC,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC;IAED,cAAc,CAAC,WAAmB;QAChC,MAAM,gBAAgB,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;QACnD,OAAO,SAAS,CAAC,gBAA0C,CAAC,CAAC;IAC/D,CAAC;IAED,eAAe,CAAC,YAAoB;QAClC,OAAO;YACL,YAAY,EAAE,YAAY;YAC1B,MAAM,EAAE,qBAAqB,CAAC,YAAY,CAAC,IAAI,EAAE;SAClD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { RevolutClientAdapter } from "../services/external/revolutClientAdapter";
|
|
2
|
-
import { fetchNativeSquidData } from "./fetchSquidData";
|
|
3
|
-
describe("RevolutClientAdapter", () => {
|
|
4
|
-
let adapter;
|
|
5
|
-
let realSquid = undefined;
|
|
6
|
-
let REAL_CHAINS = [];
|
|
7
|
-
let REAL_TOKENS = [];
|
|
8
|
-
beforeAll(async () => {
|
|
9
|
-
realSquid = await fetchNativeSquidData();
|
|
10
|
-
REAL_CHAINS = realSquid?.chains ?? [];
|
|
11
|
-
REAL_TOKENS = realSquid?.tokens ?? [];
|
|
12
|
-
});
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
adapter = new RevolutClientAdapter();
|
|
15
|
-
});
|
|
16
|
-
describe("calculateTotalFees", () => {
|
|
17
|
-
test("should correctly calculate total fees and percentage for EUR quote", () => {
|
|
18
|
-
const mockQuoteResponse = {
|
|
19
|
-
service_fee: {
|
|
20
|
-
amount: 25.33,
|
|
21
|
-
currency: "EUR",
|
|
22
|
-
},
|
|
23
|
-
network_fee: {
|
|
24
|
-
amount: 0.29,
|
|
25
|
-
currency: "EUR",
|
|
26
|
-
},
|
|
27
|
-
crypto: {
|
|
28
|
-
amount: 1009.278933,
|
|
29
|
-
currencyId: "USDC-ETH",
|
|
30
|
-
},
|
|
31
|
-
partner_fee: {
|
|
32
|
-
amount: 9.74,
|
|
33
|
-
currency: "EUR",
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
const amount = 1000; // Original amount in EUR
|
|
37
|
-
const { totalFees, percentageFee } = adapter.calculateTotalFees(mockQuoteResponse, amount);
|
|
38
|
-
// Total fees should be 25.33 + 0.29 + 9.74 = 35.36
|
|
39
|
-
expect(totalFees).toBe(35.36);
|
|
40
|
-
// Percentage should be (35.36 / 1000) * 100 = 3.54%
|
|
41
|
-
expect(percentageFee).toBe(3.54);
|
|
42
|
-
});
|
|
43
|
-
test("should handle zero fees", () => {
|
|
44
|
-
const mockQuoteResponse = {
|
|
45
|
-
service_fee: {
|
|
46
|
-
amount: 0,
|
|
47
|
-
currency: "EUR",
|
|
48
|
-
},
|
|
49
|
-
network_fee: {
|
|
50
|
-
amount: 0,
|
|
51
|
-
currency: "EUR",
|
|
52
|
-
},
|
|
53
|
-
crypto: {
|
|
54
|
-
amount: 1000,
|
|
55
|
-
currencyId: "USDC-ETH",
|
|
56
|
-
},
|
|
57
|
-
partner_fee: {
|
|
58
|
-
amount: 0,
|
|
59
|
-
currency: "EUR",
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const amount = 1000;
|
|
63
|
-
const { totalFees, percentageFee } = adapter.calculateTotalFees(mockQuoteResponse, amount);
|
|
64
|
-
expect(totalFees).toBe(0);
|
|
65
|
-
expect(percentageFee).toBe(0);
|
|
66
|
-
});
|
|
67
|
-
test("should handle very small fees", () => {
|
|
68
|
-
const mockQuoteResponse = {
|
|
69
|
-
service_fee: {
|
|
70
|
-
amount: 0.001,
|
|
71
|
-
currency: "EUR",
|
|
72
|
-
},
|
|
73
|
-
network_fee: {
|
|
74
|
-
amount: 0.002,
|
|
75
|
-
currency: "EUR",
|
|
76
|
-
},
|
|
77
|
-
crypto: {
|
|
78
|
-
amount: 100,
|
|
79
|
-
currencyId: "USDC-ETH",
|
|
80
|
-
},
|
|
81
|
-
partner_fee: {
|
|
82
|
-
amount: 0.003,
|
|
83
|
-
currency: "EUR",
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
const amount = 100;
|
|
87
|
-
const { totalFees, percentageFee } = adapter.calculateTotalFees(mockQuoteResponse, amount);
|
|
88
|
-
expect(totalFees).toBe(0.01); // 0.001 + 0.002 + 0.003 = 0.006, rounded to 0.01
|
|
89
|
-
expect(percentageFee).toBe(0.01); // (0.01 / 100) * 100 = 0.01%
|
|
90
|
-
});
|
|
91
|
-
test("should handle different currencies with same calculation", () => {
|
|
92
|
-
const mockQuoteResponse = {
|
|
93
|
-
service_fee: {
|
|
94
|
-
amount: 25.33,
|
|
95
|
-
currency: "USD", // Changed to USD
|
|
96
|
-
},
|
|
97
|
-
network_fee: {
|
|
98
|
-
amount: 0.29,
|
|
99
|
-
currency: "USD",
|
|
100
|
-
},
|
|
101
|
-
crypto: {
|
|
102
|
-
amount: 1009.278933,
|
|
103
|
-
currencyId: "USDC-ETH",
|
|
104
|
-
},
|
|
105
|
-
partner_fee: {
|
|
106
|
-
amount: 9.74,
|
|
107
|
-
currency: "USD",
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
const amount = 1000;
|
|
111
|
-
const { totalFees, percentageFee } = adapter.calculateTotalFees(mockQuoteResponse, amount);
|
|
112
|
-
expect(totalFees).toBe(35.36);
|
|
113
|
-
expect(percentageFee).toBe(3.54);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe("mapConfigResponse", () => {
|
|
117
|
-
test("should correctly map Revolut config to internal format", () => {
|
|
118
|
-
const mockRevolutConfig = {
|
|
119
|
-
version: "2.0",
|
|
120
|
-
countries: ["GB", "FR", "DE"],
|
|
121
|
-
fiat: [
|
|
122
|
-
{ currency: "EUR", min_limit: 10, max_limit: 1000 },
|
|
123
|
-
{ currency: "USD", min_limit: 10, max_limit: 1000 },
|
|
124
|
-
],
|
|
125
|
-
crypto: [
|
|
126
|
-
{
|
|
127
|
-
id: "ETH",
|
|
128
|
-
currency: "ETH",
|
|
129
|
-
blockchain: "ETHEREUM",
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
id: "USDC-ETH",
|
|
133
|
-
currency: "USDC",
|
|
134
|
-
blockchain: "ETHEREUM",
|
|
135
|
-
smartContractAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
payment_methods: ["card", "revolut"],
|
|
139
|
-
};
|
|
140
|
-
const result = adapter.mapConfigResponse(mockRevolutConfig, {
|
|
141
|
-
chains: REAL_CHAINS,
|
|
142
|
-
tokens: REAL_TOKENS,
|
|
143
|
-
});
|
|
144
|
-
expect(result.supportedCountries).toHaveLength(3);
|
|
145
|
-
expect(result.supportedCurrencies).toHaveLength(2);
|
|
146
|
-
expect(result.supportedTokens).toHaveLength(2);
|
|
147
|
-
expect(result.supportedPaymentMethods).toEqual(["card", "revolut"]);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
describe("findMatchingToken", () => {
|
|
151
|
-
test("should match both EVM native tokens and tokens with contract addresses", () => {
|
|
152
|
-
const mockRevolutConfig = {
|
|
153
|
-
version: "2.0",
|
|
154
|
-
countries: ["GB"],
|
|
155
|
-
fiat: [{ currency: "USD", min_limit: 10, max_limit: 1000 }],
|
|
156
|
-
crypto: [
|
|
157
|
-
{
|
|
158
|
-
id: "ETH",
|
|
159
|
-
currency: "ETH",
|
|
160
|
-
blockchain: "ETHEREUM",
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
id: "USDC-ETH",
|
|
164
|
-
currency: "USDC",
|
|
165
|
-
blockchain: "ETHEREUM",
|
|
166
|
-
smartContractAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
payment_methods: ["card"],
|
|
170
|
-
};
|
|
171
|
-
const result = adapter.mapConfigResponse(mockRevolutConfig, {
|
|
172
|
-
chains: REAL_CHAINS,
|
|
173
|
-
tokens: REAL_TOKENS,
|
|
174
|
-
});
|
|
175
|
-
expect(result.supportedTokens).toHaveLength(2);
|
|
176
|
-
expect(result.supportedTokens.find((t) => t.symbol === "ETH")).toBeDefined();
|
|
177
|
-
expect(result.supportedTokens.find((t) => t.symbol === "USDC")).toBeDefined();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
//# sourceMappingURL=revolutClientAdapter.test.js.map
|