thirdweb 5.72.0-nightly-8aa454cbbbc2079749fa8250102ab0307d1b33af-20241202003724 → 5.73.0-nightly-ea855c66cb940d1adafefaad6dd689227701d277-20241203000359
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/cjs/exports/pay.js +5 -1
- package/dist/cjs/exports/pay.js.map +1 -1
- package/dist/cjs/pay/convert/cryptoToFiat.js +73 -0
- package/dist/cjs/pay/convert/cryptoToFiat.js.map +1 -0
- package/dist/cjs/pay/convert/fiatToCrypto.js +73 -0
- package/dist/cjs/pay/convert/fiatToCrypto.js.map +1 -0
- package/dist/cjs/pay/utils/definitions.js +5 -1
- package/dist/cjs/pay/utils/definitions.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +2 -33
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +3 -28
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
- package/dist/cjs/transaction/actions/zksync/send-eip712-transaction.js +3 -1
- package/dist/cjs/transaction/actions/zksync/send-eip712-transaction.js.map +1 -1
- package/dist/cjs/transaction/utils.js +27 -0
- package/dist/cjs/transaction/utils.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/exports/pay.js +2 -0
- package/dist/esm/exports/pay.js.map +1 -1
- package/dist/esm/pay/convert/cryptoToFiat.js +70 -0
- package/dist/esm/pay/convert/cryptoToFiat.js.map +1 -0
- package/dist/esm/pay/convert/fiatToCrypto.js +70 -0
- package/dist/esm/pay/convert/fiatToCrypto.js.map +1 -0
- package/dist/esm/pay/utils/definitions.js +2 -0
- package/dist/esm/pay/utils/definitions.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +2 -33
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +1 -26
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
- package/dist/esm/transaction/actions/zksync/send-eip712-transaction.js +3 -1
- package/dist/esm/transaction/actions/zksync/send-eip712-transaction.js.map +1 -1
- package/dist/esm/transaction/utils.js +26 -0
- package/dist/esm/transaction/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/exports/pay.d.ts +2 -0
- package/dist/types/exports/pay.d.ts.map +1 -1
- package/dist/types/pay/convert/cryptoToFiat.d.ts +54 -0
- package/dist/types/pay/convert/cryptoToFiat.d.ts.map +1 -0
- package/dist/types/pay/convert/fiatToCrypto.d.ts +55 -0
- package/dist/types/pay/convert/fiatToCrypto.d.ts.map +1 -0
- package/dist/types/pay/utils/definitions.d.ts +2 -0
- package/dist/types/pay/utils/definitions.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts.map +1 -1
- package/dist/types/transaction/actions/zksync/send-eip712-transaction.d.ts.map +1 -1
- package/dist/types/transaction/utils.d.ts +2 -0
- package/dist/types/transaction/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +19 -19
- package/src/exports/pay.ts +10 -0
- package/src/pay/convert/cryptoToFiat.test.ts +95 -0
- package/src/pay/convert/cryptoToFiat.ts +111 -0
- package/src/pay/convert/fiatToCrypto.test.ts +96 -0
- package/src/pay/convert/fiatToCrypto.ts +110 -0
- package/src/pay/utils/definitions.ts +6 -0
- package/src/react/core/hooks/transaction/useSendTransaction.ts +2 -39
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts +1 -29
- package/src/transaction/actions/zksync/send-eip712-transaction.ts +5 -1
- package/src/transaction/utils.ts +33 -0
- package/src/version.ts +1 -1
package/dist/cjs/exports/pay.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isSwapRequiredPostOnramp = exports.getBuyHistory = exports.getPostOnRampQuote = exports.getBuyWithFiatHistory = exports.getBuyWithFiatStatus = exports.getBuyWithFiatQuote = exports.getBuyWithCryptoHistory = exports.getBuyWithCryptoStatus = exports.getBuyWithCryptoTransfer = exports.getBuyWithCryptoQuote = void 0;
|
3
|
+
exports.convertCryptoToFiat = exports.convertFiatToCrypto = exports.isSwapRequiredPostOnramp = exports.getBuyHistory = exports.getPostOnRampQuote = exports.getBuyWithFiatHistory = exports.getBuyWithFiatStatus = exports.getBuyWithFiatQuote = exports.getBuyWithCryptoHistory = exports.getBuyWithCryptoStatus = exports.getBuyWithCryptoTransfer = exports.getBuyWithCryptoQuote = void 0;
|
4
4
|
var getQuote_js_1 = require("../pay/buyWithCrypto/getQuote.js");
|
5
5
|
Object.defineProperty(exports, "getBuyWithCryptoQuote", { enumerable: true, get: function () { return getQuote_js_1.getBuyWithCryptoQuote; } });
|
6
6
|
var getTransfer_js_1 = require("../pay/buyWithCrypto/getTransfer.js");
|
@@ -22,4 +22,8 @@ var getBuyHistory_js_1 = require("../pay/getBuyHistory.js");
|
|
22
22
|
Object.defineProperty(exports, "getBuyHistory", { enumerable: true, get: function () { return getBuyHistory_js_1.getBuyHistory; } });
|
23
23
|
var isSwapRequiredPostOnramp_js_1 = require("../pay/buyWithFiat/isSwapRequiredPostOnramp.js");
|
24
24
|
Object.defineProperty(exports, "isSwapRequiredPostOnramp", { enumerable: true, get: function () { return isSwapRequiredPostOnramp_js_1.isSwapRequiredPostOnramp; } });
|
25
|
+
var fiatToCrypto_js_1 = require("../pay/convert/fiatToCrypto.js");
|
26
|
+
Object.defineProperty(exports, "convertFiatToCrypto", { enumerable: true, get: function () { return fiatToCrypto_js_1.convertFiatToCrypto; } });
|
27
|
+
var cryptoToFiat_js_1 = require("../pay/convert/cryptoToFiat.js");
|
28
|
+
Object.defineProperty(exports, "convertCryptoToFiat", { enumerable: true, get: function () { return cryptoToFiat_js_1.convertCryptoToFiat; } });
|
25
29
|
//# sourceMappingURL=pay.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../src/exports/pay.ts"],"names":[],"mappings":";;;AAAA,gEAI0C;AAHxC,oHAAA,qBAAqB,OAAA;AAKvB,sEAI6C;AAH3C,0HAAA,wBAAwB,OAAA;AAU1B,kEAI2C;AAHzC,sHAAA,sBAAsB,OAAA;AAKxB,oEAI4C;AAH1C,wHAAA,uBAAuB,OAAA;AAKzB,wDAAwD;AAExD,8DAIwC;AAHtC,kHAAA,mBAAmB,OAAA;AAKrB,gEAIyC;AAHvC,oHAAA,oBAAoB,OAAA;AAKtB,kEAI0C;AAHxC,sHAAA,qBAAqB,OAAA;AAKvB,kFAGkD;AAFhD,2HAAA,kBAAkB,OAAA;AAIpB,4DAIiC;AAH/B,iHAAA,aAAa,OAAA;AAKf,8FAA0F;AAAjF,uIAAA,wBAAwB,OAAA"}
|
1
|
+
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../src/exports/pay.ts"],"names":[],"mappings":";;;AAAA,gEAI0C;AAHxC,oHAAA,qBAAqB,OAAA;AAKvB,sEAI6C;AAH3C,0HAAA,wBAAwB,OAAA;AAU1B,kEAI2C;AAHzC,sHAAA,sBAAsB,OAAA;AAKxB,oEAI4C;AAH1C,wHAAA,uBAAuB,OAAA;AAKzB,wDAAwD;AAExD,8DAIwC;AAHtC,kHAAA,mBAAmB,OAAA;AAKrB,gEAIyC;AAHvC,oHAAA,oBAAoB,OAAA;AAKtB,kEAI0C;AAHxC,sHAAA,qBAAqB,OAAA;AAKvB,kFAGkD;AAFhD,2HAAA,kBAAkB,OAAA;AAIpB,4DAIiC;AAH/B,iHAAA,aAAa,OAAA;AAKf,8FAA0F;AAAjF,uIAAA,wBAAwB,OAAA;AASjC,kEAGwC;AAFtC,sHAAA,mBAAmB,OAAA;AAIrB,kEAGwC;AAFtC,sHAAA,mBAAmB,OAAA"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.convertCryptoToFiat = convertCryptoToFiat;
|
4
|
+
const addresses_js_1 = require("../../constants/addresses.js");
|
5
|
+
const get_bytecode_js_1 = require("../../contract/actions/get-bytecode.js");
|
6
|
+
const contract_js_1 = require("../../contract/contract.js");
|
7
|
+
const address_js_1 = require("../../utils/address.js");
|
8
|
+
const fetch_js_1 = require("../../utils/fetch.js");
|
9
|
+
const definitions_js_1 = require("../utils/definitions.js");
|
10
|
+
/**
|
11
|
+
* Get a price of a token (using tokenAddress + chainId) in fiat.
|
12
|
+
* Only USD is supported at the moment.
|
13
|
+
* @example
|
14
|
+
* ### Basic usage
|
15
|
+
* For native token (non-ERC20), you should use NATIVE_TOKEN_ADDRESS as the value for `tokenAddress`
|
16
|
+
* ```ts
|
17
|
+
* import { convertCryptoToFiat } from "thirdweb/pay";
|
18
|
+
*
|
19
|
+
* // Get Ethereum price
|
20
|
+
* const result = convertCryptoToFiat({
|
21
|
+
* fromTokenAddress: NATIVE_TOKEN_ADDRESS,
|
22
|
+
* to: "USD",
|
23
|
+
* chain: ethereum,
|
24
|
+
* fromAmount: 1,
|
25
|
+
* });
|
26
|
+
*
|
27
|
+
* // Result: `{ result: 3404.11 }`
|
28
|
+
* ```
|
29
|
+
* @buyCrypto
|
30
|
+
* @returns a number representing the price (in selected fiat) of "x" token, with "x" being the `fromAmount`.
|
31
|
+
*/
|
32
|
+
async function convertCryptoToFiat(options) {
|
33
|
+
const { client, fromTokenAddress, to, chain, fromAmount } = options;
|
34
|
+
if (Number(fromAmount) === 0) {
|
35
|
+
return { result: 0 };
|
36
|
+
}
|
37
|
+
// Testnets just don't work with our current provider(s)
|
38
|
+
if (chain.testnet === true) {
|
39
|
+
throw new Error(`Cannot fetch price for a testnet (chainId: ${chain.id})`);
|
40
|
+
}
|
41
|
+
// Some provider that we are using will return `0` for unsupported token
|
42
|
+
// so we should do some basic input validations before sending the request
|
43
|
+
// Make sure it's a valid EVM address
|
44
|
+
if (!(0, address_js_1.isAddress)(fromTokenAddress)) {
|
45
|
+
throw new Error("Invalid fromTokenAddress. Expected a valid EVM contract address");
|
46
|
+
}
|
47
|
+
// Make sure it's either a valid contract or a native token address
|
48
|
+
if (fromTokenAddress.toLowerCase() !== addresses_js_1.NATIVE_TOKEN_ADDRESS.toLowerCase()) {
|
49
|
+
const bytecode = await (0, get_bytecode_js_1.getBytecode)((0, contract_js_1.getContract)({
|
50
|
+
address: fromTokenAddress,
|
51
|
+
chain,
|
52
|
+
client,
|
53
|
+
})).catch(() => undefined);
|
54
|
+
if (!bytecode || bytecode === "0x") {
|
55
|
+
throw new Error(`Error: ${fromTokenAddress} on chainId: ${chain.id} is not a valid contract address.`);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
const params = {
|
59
|
+
fromTokenAddress,
|
60
|
+
to,
|
61
|
+
chainId: String(chain.id),
|
62
|
+
fromAmount: String(fromAmount),
|
63
|
+
};
|
64
|
+
const queryString = new URLSearchParams(params).toString();
|
65
|
+
const url = `${(0, definitions_js_1.getPayConvertCryptoToFiatEndpoint)()}?${queryString}`;
|
66
|
+
const response = await (0, fetch_js_1.getClientFetch)(client)(url);
|
67
|
+
if (!response.ok) {
|
68
|
+
throw new Error(`Failed to fetch ${to} value for token (${fromTokenAddress}) on chainId: ${chain.id}`);
|
69
|
+
}
|
70
|
+
const data = await response.json();
|
71
|
+
return data;
|
72
|
+
}
|
73
|
+
//# sourceMappingURL=cryptoToFiat.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cryptoToFiat.js","sourceRoot":"","sources":["../../../../src/pay/convert/cryptoToFiat.ts"],"names":[],"mappings":";;AA0DA,kDAoDC;AA3GD,+DAAoE;AACpE,4EAAqE;AACrE,4DAAyD;AACzD,uDAAmD;A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AAM,CAAC,UAAU,CAAC;KAC/B,CAAC;IACF,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,MAAM,GAAG,GAAG,GAAG,IAAA,kDAAiC,GAAE,IAAI,WAAW,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAc,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,mBAAmB,EAAE,qBAAqB,gBAAgB,iBAAiB,KAAK,CAAC,EAAE,EAAE,CACtF,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAuB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.convertFiatToCrypto = convertFiatToCrypto;
|
4
|
+
const addresses_js_1 = require("../../constants/addresses.js");
|
5
|
+
const get_bytecode_js_1 = require("../../contract/actions/get-bytecode.js");
|
6
|
+
const contract_js_1 = require("../../contract/contract.js");
|
7
|
+
const address_js_1 = require("../../utils/address.js");
|
8
|
+
const fetch_js_1 = require("../../utils/fetch.js");
|
9
|
+
const definitions_js_1 = require("../utils/definitions.js");
|
10
|
+
/**
|
11
|
+
* Convert a fiat value to a token.
|
12
|
+
* Currently only USD is supported.
|
13
|
+
* @example
|
14
|
+
* ### Basic usage
|
15
|
+
* ```ts
|
16
|
+
* import { convertFiatToCrypto } from "thirdweb/pay";
|
17
|
+
*
|
18
|
+
* // Convert 2 cents to ETH
|
19
|
+
* const result = await convertFiatToCrypto({
|
20
|
+
* from: "USD",
|
21
|
+
* // the token address. For native token, use NATIVE_TOKEN_ADDRESS
|
22
|
+
* to: "0x...",
|
23
|
+
* // the chain (of the chain where the token belong to)
|
24
|
+
* chain: ethereum,
|
25
|
+
* // 2 cents
|
26
|
+
* fromAmount: 0.02,
|
27
|
+
* });
|
28
|
+
* ```
|
29
|
+
* Result: `{ result: 0.0000057 }`
|
30
|
+
* @buyCrypto
|
31
|
+
*/
|
32
|
+
async function convertFiatToCrypto(options) {
|
33
|
+
const { client, from, to, chain, fromAmount } = options;
|
34
|
+
if (Number(fromAmount) === 0) {
|
35
|
+
return { result: 0 };
|
36
|
+
}
|
37
|
+
// Testnets just don't work with our current provider(s)
|
38
|
+
if (chain.testnet === true) {
|
39
|
+
throw new Error(`Cannot fetch price for a testnet (chainId: ${chain.id})`);
|
40
|
+
}
|
41
|
+
// Some provider that we are using will return `0` for unsupported token
|
42
|
+
// so we should do some basic input validations before sending the request
|
43
|
+
// Make sure it's a valid EVM address
|
44
|
+
if (!(0, address_js_1.isAddress)(to)) {
|
45
|
+
throw new Error("Invalid `to`. Expected a valid EVM contract address");
|
46
|
+
}
|
47
|
+
// Make sure it's either a valid contract or a native token
|
48
|
+
if (to.toLowerCase() !== addresses_js_1.NATIVE_TOKEN_ADDRESS.toLowerCase()) {
|
49
|
+
const bytecode = await (0, get_bytecode_js_1.getBytecode)((0, contract_js_1.getContract)({
|
50
|
+
address: to,
|
51
|
+
chain,
|
52
|
+
client,
|
53
|
+
})).catch(() => undefined);
|
54
|
+
if (!bytecode || bytecode === "0x") {
|
55
|
+
throw new Error(`Error: ${to} on chainId: ${chain.id} is not a valid contract address.`);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
const params = {
|
59
|
+
from,
|
60
|
+
to,
|
61
|
+
chainId: String(chain.id),
|
62
|
+
fromAmount: String(fromAmount),
|
63
|
+
};
|
64
|
+
const queryString = new URLSearchParams(params).toString();
|
65
|
+
const url = `${(0, definitions_js_1.getPayConvertFiatToCryptoEndpoint)()}?${queryString}`;
|
66
|
+
const response = await (0, fetch_js_1.getClientFetch)(client)(url);
|
67
|
+
if (!response.ok) {
|
68
|
+
throw new Error(`Failed to convert ${to} value to token (${to}) on chainId: ${chain.id}`);
|
69
|
+
}
|
70
|
+
const data = await response.json();
|
71
|
+
return data;
|
72
|
+
}
|
73
|
+
//# sourceMappingURL=fiatToCrypto.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"fiatToCrypto.js","sourceRoot":"","sources":["../../../../src/pay/convert/fiatToCrypto.ts"],"names":[],"mappings":";;AA2DA,kDAkDC;AA1GD,+DAAoE;AACpE,4EAAqE;AACrE,4DAAyD;AACzD,uDAAmD;AACnD,mDAAsD;AACtD,4DAA4E;AA6B5E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,mBAAmB,CACvC,OAAkC;IAElC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACxD,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACvB,CAAC;IACD,wDAAwD;IACxD,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,8CAA8C,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;IAC7E,CAAC;IACD,wEAAwE;IACxE,0EAA0E;IAE1E,qCAAqC;IACrC,IAAI,CAAC,IAAA,sBAAS,EAAC,EAAE,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,2DAA2D;IAC3D,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,mCAAoB,CAAC,WAAW,EAAE,EAAE,CAAC;QAC5D,MAAM,QAAQ,GAAG,MAAM,IAAA,6BAAW,EAChC,IAAA,yBAAW,EAAC;YACV,OAAO,EAAE,EAAE;YACX,KAAK;YACL,MAAM;SACP,CAAC,CACH,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzB,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,UAAU,EAAE,gBAAgB,KAAK,CAAC,EAAE,mCAAmC,CACxE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG;QACb,IAAI;QACJ,EAAE;QACF,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;KAC/B,CAAC;IACF,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,MAAM,GAAG,GAAG,GAAG,IAAA,kDAAiC,GAAE,IAAI,WAAW,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAc,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,KAAK,CAAC,EAAE,EAAE,CACzE,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAuB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getPayBuyHistoryEndpoint = exports.getPaySupportedSources = exports.getPaySupportedDestinations = exports.getPayBuyWithCryptoHistoryEndpoint = exports.getPayBuyWithFiatHistoryEndpoint = exports.getPayBuyWithFiatStatusEndpoint = exports.getPayBuyWithFiatQuoteEndpoint = exports.getPayBuyWithCryptoTransferEndpoint = exports.getPayBuyWithCryptoQuoteEndpoint = exports.getPayBuyWithCryptoStatusUrl = void 0;
|
3
|
+
exports.getPayConvertCryptoToFiatEndpoint = exports.getPayConvertFiatToCryptoEndpoint = exports.getPayBuyHistoryEndpoint = exports.getPaySupportedSources = exports.getPaySupportedDestinations = exports.getPayBuyWithCryptoHistoryEndpoint = exports.getPayBuyWithFiatHistoryEndpoint = exports.getPayBuyWithFiatStatusEndpoint = exports.getPayBuyWithFiatQuoteEndpoint = exports.getPayBuyWithCryptoTransferEndpoint = exports.getPayBuyWithCryptoQuoteEndpoint = exports.getPayBuyWithCryptoStatusUrl = void 0;
|
4
4
|
const domains_js_1 = require("../../utils/domains.js");
|
5
5
|
const getPayBaseUrl = () => {
|
6
6
|
const payDomain = (0, domains_js_1.getThirdwebDomains)().pay;
|
@@ -69,4 +69,8 @@ exports.getPaySupportedSources = getPaySupportedSources;
|
|
69
69
|
*/
|
70
70
|
const getPayBuyHistoryEndpoint = () => `${getPayBaseUrl()}/wallet/history/v1`;
|
71
71
|
exports.getPayBuyHistoryEndpoint = getPayBuyHistoryEndpoint;
|
72
|
+
const getPayConvertFiatToCryptoEndpoint = () => `${getPayBaseUrl()}/convert/fiat-to-crypto/v1`;
|
73
|
+
exports.getPayConvertFiatToCryptoEndpoint = getPayConvertFiatToCryptoEndpoint;
|
74
|
+
const getPayConvertCryptoToFiatEndpoint = () => `${getPayBaseUrl()}/convert/crypto-to-fiat/v1`;
|
75
|
+
exports.getPayConvertCryptoToFiatEndpoint = getPayConvertCryptoToFiatEndpoint;
|
72
76
|
//# sourceMappingURL=definitions.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../src/pay/utils/definitions.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAE5D,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,SAAS,GAAW,IAAA,+BAAkB,GAAE,CAAC,GAAG,CAAC;IACnD,OAAO,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC;QACtC,CAAC,CAAC,UAAU,SAAS,EAAE;QACvB,CAAC,CAAC,WAAW,S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{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../../../src/pay/utils/definitions.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAE5D,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,SAAS,GAAW,IAAA,+BAAkB,GAAE,CAAC,GAAG,CAAC;IACnD,OAAO,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC;QACtC,CAAC,CAAC,UAAU,SAAS,EAAE;QACvB,CAAC,CAAC,WAAW,SAAS,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,4BAA4B,GAAG,GAAG,EAAE,CAC/C,GAAG,aAAa,EAAE,4BAA4B,CAAC;AADpC,QAAA,4BAA4B,gCACQ;AACjD;;;GAGG;AACI,MAAM,gCAAgC,GAAG,GAAG,EAAE,CACnD,GAAG,aAAa,EAAE,2BAA2B,CAAC;AADnC,QAAA,gCAAgC,oCACG;AAEhD;;;GAGG;AACI,MAAM,mCAAmC,GAAG,GAAG,EAAE,CACtD,GAAG,aAAa,EAAE,8BAA8B,CAAC;AADtC,QAAA,mCAAmC,uCACG;AAEnD;;;GAGG;AACI,MAAM,8BAA8B,GAAG,GAAG,EAAE,CACjD,GAAG,aAAa,EAAE,yBAAyB,CAAC;AADjC,QAAA,8BAA8B,kCACG;AAE9C;;;GAGG;AACI,MAAM,+BAA+B,GAAG,GAAG,EAAE,CAClD,GAAG,aAAa,EAAE,0BAA0B,CAAC;AADlC,QAAA,+BAA+B,mCACG;AAE/C;;;GAGG;AACI,MAAM,gCAAgC,GAAG,GAAG,EAAE,CACnD,GAAG,aAAa,EAAE,2BAA2B,CAAC;AADnC,QAAA,gCAAgC,oCACG;AAEhD;;;GAGG;AACI,MAAM,kCAAkC,GAAG,GAAG,EAAE,CACrD,GAAG,aAAa,EAAE,6BAA6B,CAAC;AADrC,QAAA,kCAAkC,sCACG;AAElD;;;GAGG;AACI,MAAM,2BAA2B,GAAG,GAAG,EAAE,CAC9C,GAAG,aAAa,EAAE,wBAAwB,CAAC;AADhC,QAAA,2BAA2B,+BACK;AAE7C;;;GAGG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE,CACzC,GAAG,aAAa,EAAE,mCAAmC,CAAC;AAD3C,QAAA,sBAAsB,0BACqB;AAExD;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAC3C,GAAG,aAAa,EAAE,oBAAoB,CAAC;AAD5B,QAAA,wBAAwB,4BACI;AAElC,MAAM,iCAAiC,GAAG,GAAG,EAAE,CACpD,GAAG,aAAa,EAAE,4BAA4B,CAAC;AADpC,QAAA,iCAAiC,qCACG;AAE1C,MAAM,iCAAiC,GAAG,GAAG,EAAE,CACpD,GAAG,aAAa,EAAE,4BAA4B,CAAC;AADpC,QAAA,iCAAiC,qCACG"}
|
@@ -2,9 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.useSendTransactionCore = useSendTransactionCore;
|
4
4
|
const react_query_1 = require("@tanstack/react-query");
|
5
|
-
const get_gas_price_js_1 = require("../../../../gas/get-gas-price.js");
|
6
|
-
const estimate_gas_cost_js_1 = require("../../../../transaction/actions/estimate-gas-cost.js");
|
7
5
|
const send_transaction_js_1 = require("../../../../transaction/actions/send-transaction.js");
|
6
|
+
const utils_js_1 = require("../../../../transaction/utils.js");
|
8
7
|
const resolve_promised_value_js_1 = require("../../../../utils/promise/resolve-promised-value.js");
|
9
8
|
const getTokenBalance_js_1 = require("../../../../wallets/utils/getTokenBalance.js");
|
10
9
|
const getWalletBalance_js_1 = require("../../../../wallets/utils/getWalletBalance.js");
|
@@ -98,7 +97,7 @@ function useSendTransactionCore(args) {
|
|
98
97
|
tokenAddress: _erc20Value.tokenAddress,
|
99
98
|
})
|
100
99
|
: undefined,
|
101
|
-
|
100
|
+
(0, utils_js_1.getTransactionGasCost)(tx, account.address),
|
102
101
|
]);
|
103
102
|
const gasSponsored = (0, wallet_js_1.hasSponsoredTransactionsEnabled)(wallet);
|
104
103
|
const txGasCost = gasSponsored ? 0n : gasCost;
|
@@ -129,34 +128,4 @@ function useSendTransactionCore(args) {
|
|
129
128
|
},
|
130
129
|
});
|
131
130
|
}
|
132
|
-
async function getTotalTxCostForBuy(tx, from) {
|
133
|
-
try {
|
134
|
-
const gasCost = await (0, estimate_gas_cost_js_1.estimateGasCost)({
|
135
|
-
transaction: tx,
|
136
|
-
from,
|
137
|
-
});
|
138
|
-
const bufferCost = gasCost.wei / 10n;
|
139
|
-
// Note: get tx.value AFTER estimateGasCost
|
140
|
-
const txValue = await (0, resolve_promised_value_js_1.resolvePromisedValue)(tx.value);
|
141
|
-
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
142
|
-
return gasCost.wei + bufferCost + (txValue || 0n);
|
143
|
-
}
|
144
|
-
catch {
|
145
|
-
if (from) {
|
146
|
-
// try again without passing from
|
147
|
-
return await getTotalTxCostForBuy(tx);
|
148
|
-
}
|
149
|
-
// fallback if both fail, use the tx value + 2M * gas price
|
150
|
-
const value = await (0, resolve_promised_value_js_1.resolvePromisedValue)(tx.value);
|
151
|
-
const gasPrice = await (0, get_gas_price_js_1.getGasPrice)({
|
152
|
-
client: tx.client,
|
153
|
-
chain: tx.chain,
|
154
|
-
});
|
155
|
-
const buffer = 2000000n * gasPrice;
|
156
|
-
if (!value) {
|
157
|
-
return 0n + buffer;
|
158
|
-
}
|
159
|
-
return value + buffer;
|
160
|
-
}
|
161
|
-
}
|
162
131
|
//# sourceMappingURL=useSendTransaction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSendTransaction.js","sourceRoot":"","sources":["../../../../../../src/react/core/hooks/transaction/useSendTransaction.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"useSendTransaction.js","sourceRoot":"","sources":["../../../../../../src/react/core/hooks/transaction/useSendTransaction.ts"],"names":[],"mappings":";;AAqHA,wDAmIC;AAxPD,uDAA4E;AAM5E,6FAAsF;AAGtF,+DAAyE;AACz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5C,kBAAkB;wBAClB,MAAM,EAAE,CAAC;oBACX,CAAC;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
@@ -7,9 +7,8 @@ const utils_js_1 = require("../../../../../../../chains/utils.js");
|
|
7
7
|
const addresses_js_1 = require("../../../../../../../constants/addresses.js");
|
8
8
|
const contract_js_1 = require("../../../../../../../contract/contract.js");
|
9
9
|
const getCurrencyMetadata_js_1 = require("../../../../../../../extensions/erc20/read/getCurrencyMetadata.js");
|
10
|
-
const get_gas_price_js_1 = require("../../../../../../../gas/get-gas-price.js");
|
11
10
|
const encode_js_1 = require("../../../../../../../transaction/actions/encode.js");
|
12
|
-
const
|
11
|
+
const utils_js_2 = require("../../../../../../../transaction/utils.js");
|
13
12
|
const resolve_promised_value_js_1 = require("../../../../../../../utils/promise/resolve-promised-value.js");
|
14
13
|
const getWalletBalance_js_1 = require("../../../../../../../wallets/utils/getWalletBalance.js");
|
15
14
|
function useTransactionCostAndData(args) {
|
@@ -59,7 +58,7 @@ function useTransactionCostAndData(args) {
|
|
59
58
|
client: transaction.client,
|
60
59
|
}),
|
61
60
|
}),
|
62
|
-
getTransactionGasCost(transaction, account?.address),
|
61
|
+
(0, utils_js_2.getTransactionGasCost)(transaction, account?.address),
|
63
62
|
]);
|
64
63
|
const transactionValueWei = erc20Value.amountWei;
|
65
64
|
const walletBalance = tokenBalance;
|
@@ -87,7 +86,7 @@ function useTransactionCostAndData(args) {
|
|
87
86
|
client: transaction.client,
|
88
87
|
}),
|
89
88
|
(0, utils_js_1.getChainMetadata)(transaction.chain),
|
90
|
-
getTransactionGasCost(transaction, account?.address),
|
89
|
+
(0, utils_js_2.getTransactionGasCost)(transaction, account?.address),
|
91
90
|
]);
|
92
91
|
const walletBalance = nativeWalletBalance;
|
93
92
|
const transactionValueWei = (await (0, resolve_promised_value_js_1.resolvePromisedValue)(transaction.value)) || 0n;
|
@@ -114,28 +113,4 @@ function useTransactionCostAndData(args) {
|
|
114
113
|
},
|
115
114
|
});
|
116
115
|
}
|
117
|
-
async function getTransactionGasCost(tx, from) {
|
118
|
-
try {
|
119
|
-
const gasCost = await (0, estimate_gas_cost_js_1.estimateGasCost)({
|
120
|
-
transaction: tx,
|
121
|
-
from,
|
122
|
-
});
|
123
|
-
const bufferCost = gasCost.wei / 10n;
|
124
|
-
// Note: get tx.value AFTER estimateGasCost
|
125
|
-
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
126
|
-
return gasCost.wei + bufferCost;
|
127
|
-
}
|
128
|
-
catch {
|
129
|
-
if (from) {
|
130
|
-
// try again without passing from
|
131
|
-
return await getTransactionGasCost(tx);
|
132
|
-
}
|
133
|
-
// fallback if both fail, use the tx value + 2M * gas price
|
134
|
-
const gasPrice = await (0, get_gas_price_js_1.getGasPrice)({
|
135
|
-
client: tx.client,
|
136
|
-
chain: tx.chain,
|
137
|
-
});
|
138
|
-
return 2000000n * gasPrice;
|
139
|
-
}
|
140
|
-
}
|
141
116
|
//# sourceMappingURL=useBuyTxStates.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useBuyTxStates.js","sourceRoot":"","sources":["../../../../../../../../../src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"useBuyTxStates.js","sourceRoot":"","sources":["../../../../../../../../../src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts"],"names":[],"mappings":";;AAgBA,8DA0HC;AA1ID,uDAAiD;AACjD,iCAA4C;AAC5C,mEAAwE;AACxE,8EAAmF;AACnF,2EAAwE;AACxE,8GAAwG;AACxG,kFAA4E;AAE5E,wEAAkF;AAElF,4GAAoG;AAEpG,gGAA0F;AAI1F,SAAgB,yBAAyB,CAAC,IAIzC;IACC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC;IAC7D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AgB,EAAC;oBACf,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,KAAK,EAAE,WAAW,CAAC,KAAK;oBACxB,MAAM,EAAE,WAAW,CAAC,MAAM;iBAC3B,CAAC;gBACF,IAAA,2BAAgB,EAAC,WAAW,CAAC,KAAK,CAAC;gBACnC,IAAA,gCAAqB,EAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC;aACrD,CAAC,CAAC;YACL,MAAM,aAAa,GAAG,mBAAmB,CAAC;YAC1C,MAAM,mBAAmB,GACvB,CAAC,MAAM,IAAA,gDAAoB,EAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;YACxD,OAAO;gBACL,KAAK,EAAE;oBACL,OAAO,EAAE,mCAAoB;oBAC7B,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,IAAI;oBACvC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,MAAM;oBAC3C,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG;iBAC9B;gBACD,QAAQ,EAAE,EAAE;gBACZ,aAAa;gBACb,UAAU;gBACV,mBAAmB;aACa,CAAC;QACrC,CAAC;QACD,OAAO,EAAE,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,UAAU;QACtC,eAAe,EAAE,GAAG,EAAE;YACpB,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;gBAC3B,+CAA+C;gBAC/C,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
@@ -118,7 +118,9 @@ async function getZkGasFees(args) {
|
|
118
118
|
(0, resolve_promised_value_js_1.resolvePromisedValue)(transaction.eip712),
|
119
119
|
]);
|
120
120
|
let gasPerPubdata = eip712?.gasPerPubdata;
|
121
|
-
if (
|
121
|
+
if (gas === undefined ||
|
122
|
+
maxFeePerGas === undefined ||
|
123
|
+
maxPriorityFeePerGas === undefined) {
|
122
124
|
const rpc = (0, rpc_js_1.getRpcClient)(transaction);
|
123
125
|
const params = await formatTransaction({ transaction, from });
|
124
126
|
const result = (await rpc({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"send-eip712-transaction.js","sourceRoot":"","sources":["../../../../../src/transaction/actions/zksync/send-eip712-transaction.ts"],"names":[],"mappings":";;AA0CA,sDAqBC;AAED,sDAmBC;AAOD,8DAwBC;AAgDD,
|
1
|
+
{"version":3,"file":"send-eip712-transaction.js","sourceRoot":"","sources":["../../../../../src/transaction/actions/zksync/send-eip712-transaction.ts"],"names":[],"mappings":";;AA0CA,sDAqBC;AAED,sDAmBC;AAOD,8DAwBC;AAgDD,oCA8CC;AAjND,+BAAyC;AACzC,8FAAwF;AACxF,gDAAmD;AACnD,0DAAqE;AACrE,wDAAoE;AACpE,iFAA0E;AAC1E,2DAAiE;AACjE,gGAAwF;AAGxF,4CAAsC;AACtC,sFAA8E;AAE9E,6DAI8B;AAS9B;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,qBAAqB,CACzC,OAAqC;IAErC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEzC,MAAM,iBAAiB,GAAG,MAAM,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEnE,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC;QACvC,OAAO;QACP,iBAAiB;QACjB,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE;KAC9B,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,WAAW,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,MAAM,IAAA,kDAAsB,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEvD,OAAO;QACL,eAAe,EAAE,MAAM;QACvB,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,MAAM,EAAE,WAAW,CAAC,MAAM;KAC3B,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,OAI3C;IACC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,MAAM,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO;QACL,GAAG;QACH,YAAY;QACZ,oBAAoB;QACpB,aAAa;KACd,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,IAGhC;IACC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACnC,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAClD,IAAA,kBAAM,EAAC,WAAW,CAAC;QACnB,IAAA,gDAAoB,EAAC,WAAW,CAAC,EAAE,CAAC;QACpC,IAAA,gDAAoB,EAAC,WAAW,CAAC,KAAK,CAAC;QACvC,IAAA,gDAAoB,EAAC,WAAW,CAAC,MAAM,CAAC;KACzC,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,CAAC;IAC5C,OAAO;QACL,IAAI;QACJ,EAAE;QACF,IAAI;QACJ,KAAK;QACL,aAAa;QACb,UAAU,EAAE;YACV,GAAG,MAAM;YACT,aAAa,EAAE,aAAa,IAAI,MAAM;YACtC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAC5C,KAAK,CAAC,IAAI,CAAC,IAAA,iBAAU,EAAC,GAAG,CAAC,CAAC,CAC5B;SACF;QACD,IAAI,EAAE,MAAM;KACb,CAAC;AACJ,CAAC"}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.isAbiFunction = isAbiFunction;
|
4
|
+
exports.getTransactionGasCost = getTransactionGasCost;
|
5
|
+
const get_gas_price_js_1 = require("../gas/get-gas-price.js");
|
6
|
+
const estimate_gas_cost_js_1 = require("./actions/estimate-gas-cost.js");
|
4
7
|
/**
|
5
8
|
* @internal
|
6
9
|
*/
|
@@ -10,4 +13,28 @@ function isAbiFunction(item) {
|
|
10
13
|
"type" in item &&
|
11
14
|
item.type === "function");
|
12
15
|
}
|
16
|
+
async function getTransactionGasCost(tx, from) {
|
17
|
+
try {
|
18
|
+
const gasCost = await (0, estimate_gas_cost_js_1.estimateGasCost)({
|
19
|
+
transaction: tx,
|
20
|
+
from,
|
21
|
+
});
|
22
|
+
const bufferCost = gasCost.wei / 10n;
|
23
|
+
// Note: get tx.value AFTER estimateGasCost
|
24
|
+
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
25
|
+
return gasCost.wei + bufferCost;
|
26
|
+
}
|
27
|
+
catch {
|
28
|
+
if (from) {
|
29
|
+
// try again without passing from
|
30
|
+
return await getTransactionGasCost(tx);
|
31
|
+
}
|
32
|
+
// fallback if both fail, use the tx value + 1M * gas price
|
33
|
+
const gasPrice = await (0, get_gas_price_js_1.getGasPrice)({
|
34
|
+
client: tx.client,
|
35
|
+
chain: tx.chain,
|
36
|
+
});
|
37
|
+
return 1000000n * gasPrice;
|
38
|
+
}
|
39
|
+
}
|
13
40
|
//# sourceMappingURL=utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transaction/utils.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transaction/utils.ts"],"names":[],"mappings":";;AAQA,sCAOC;AAED,sDA4BC;AA5CD,8DAAsD;AACtD,yEAAiE;AAGjE;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAa;IACzC,OAAO,CAAC,CAAC,CACP,IAAI;QACJ,OAAO,IAAI,KAAK,QAAQ;QACxB,MAAM,IAAI,IAAI;QACd,IAAI,CAAC,IAAI,KAAK,UAAU,CACzB,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,qBAAqB,CACzC,EAAuB,EACvB,IAAa;IAEb,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,IAAA,sCAAe,EAAC;YACpC,WAAW,EAAE,EAAE;YACf,IAAI;SACL,CAAC,CAAC;QAEH,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;QAErC,2CAA2C;QAC3C,yFAAyF;QACzF,OAAO,OAAO,CAAC,GAAG,GAAG,UAAU,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,IAAI,EAAE,CAAC;YACT,iCAAiC;YACjC,OAAO,MAAM,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,2DAA2D;QAC3D,MAAM,QAAQ,GAAG,MAAM,IAAA,8BAAW,EAAC;YACjC,MAAM,EAAE,EAAE,CAAC,MAAM;YACjB,KAAK,EAAE,EAAE,CAAC,KAAK;SAChB,CAAC,CAAC;QAEH,OAAO,QAAU,GAAG,QAAQ,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
package/dist/cjs/version.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.version = void 0;
|
4
|
-
exports.version = "5.
|
4
|
+
exports.version = "5.73.0-nightly-ea855c66cb940d1adafefaad6dd689227701d277-20241203000359";
|
5
5
|
//# sourceMappingURL=version.js.map
|
package/dist/esm/exports/pay.js
CHANGED
@@ -9,4 +9,6 @@ export { getBuyWithFiatHistory, } from "../pay/buyWithFiat/getHistory.js";
|
|
9
9
|
export { getPostOnRampQuote, } from "../pay/buyWithFiat/getPostOnRampQuote.js";
|
10
10
|
export { getBuyHistory, } from "../pay/getBuyHistory.js";
|
11
11
|
export { isSwapRequiredPostOnramp } from "../pay/buyWithFiat/isSwapRequiredPostOnramp.js";
|
12
|
+
export { convertFiatToCrypto, } from "../pay/convert/fiatToCrypto.js";
|
13
|
+
export { convertCryptoToFiat, } from "../pay/convert/cryptoToFiat.js";
|
12
14
|
//# sourceMappingURL=pay.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../src/exports/pay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAGtB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,wBAAwB,GAGzB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EACL,sBAAsB,GAGvB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,uBAAuB,GAGxB,MAAM,oCAAoC,CAAC;AAE5C,wDAAwD;AAExD,OAAO,EACL,mBAAmB,GAGpB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,qBAAqB,GAGtB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,kBAAkB,GAEnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACL,aAAa,GAGd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC"}
|
1
|
+
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../src/exports/pay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAGtB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,wBAAwB,GAGzB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EACL,sBAAsB,GAGvB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,uBAAuB,GAGxB,MAAM,oCAAoC,CAAC;AAE5C,wDAAwD;AAExD,OAAO,EACL,mBAAmB,GAGpB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,qBAAqB,GAGtB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,kBAAkB,GAEnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACL,aAAa,GAGd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAS1F,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC"}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
|
2
|
+
import { getBytecode } from "../../contract/actions/get-bytecode.js";
|
3
|
+
import { getContract } from "../../contract/contract.js";
|
4
|
+
import { isAddress } from "../../utils/address.js";
|
5
|
+
import { getClientFetch } from "../../utils/fetch.js";
|
6
|
+
import { getPayConvertCryptoToFiatEndpoint } from "../utils/definitions.js";
|
7
|
+
/**
|
8
|
+
* Get a price of a token (using tokenAddress + chainId) in fiat.
|
9
|
+
* Only USD is supported at the moment.
|
10
|
+
* @example
|
11
|
+
* ### Basic usage
|
12
|
+
* For native token (non-ERC20), you should use NATIVE_TOKEN_ADDRESS as the value for `tokenAddress`
|
13
|
+
* ```ts
|
14
|
+
* import { convertCryptoToFiat } from "thirdweb/pay";
|
15
|
+
*
|
16
|
+
* // Get Ethereum price
|
17
|
+
* const result = convertCryptoToFiat({
|
18
|
+
* fromTokenAddress: NATIVE_TOKEN_ADDRESS,
|
19
|
+
* to: "USD",
|
20
|
+
* chain: ethereum,
|
21
|
+
* fromAmount: 1,
|
22
|
+
* });
|
23
|
+
*
|
24
|
+
* // Result: `{ result: 3404.11 }`
|
25
|
+
* ```
|
26
|
+
* @buyCrypto
|
27
|
+
* @returns a number representing the price (in selected fiat) of "x" token, with "x" being the `fromAmount`.
|
28
|
+
*/
|
29
|
+
export async function convertCryptoToFiat(options) {
|
30
|
+
const { client, fromTokenAddress, to, chain, fromAmount } = options;
|
31
|
+
if (Number(fromAmount) === 0) {
|
32
|
+
return { result: 0 };
|
33
|
+
}
|
34
|
+
// Testnets just don't work with our current provider(s)
|
35
|
+
if (chain.testnet === true) {
|
36
|
+
throw new Error(`Cannot fetch price for a testnet (chainId: ${chain.id})`);
|
37
|
+
}
|
38
|
+
// Some provider that we are using will return `0` for unsupported token
|
39
|
+
// so we should do some basic input validations before sending the request
|
40
|
+
// Make sure it's a valid EVM address
|
41
|
+
if (!isAddress(fromTokenAddress)) {
|
42
|
+
throw new Error("Invalid fromTokenAddress. Expected a valid EVM contract address");
|
43
|
+
}
|
44
|
+
// Make sure it's either a valid contract or a native token address
|
45
|
+
if (fromTokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS.toLowerCase()) {
|
46
|
+
const bytecode = await getBytecode(getContract({
|
47
|
+
address: fromTokenAddress,
|
48
|
+
chain,
|
49
|
+
client,
|
50
|
+
})).catch(() => undefined);
|
51
|
+
if (!bytecode || bytecode === "0x") {
|
52
|
+
throw new Error(`Error: ${fromTokenAddress} on chainId: ${chain.id} is not a valid contract address.`);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
const params = {
|
56
|
+
fromTokenAddress,
|
57
|
+
to,
|
58
|
+
chainId: String(chain.id),
|
59
|
+
fromAmount: String(fromAmount),
|
60
|
+
};
|
61
|
+
const queryString = new URLSearchParams(params).toString();
|
62
|
+
const url = `${getPayConvertCryptoToFiatEndpoint()}?${queryString}`;
|
63
|
+
const response = await getClientFetch(client)(url);
|
64
|
+
if (!response.ok) {
|
65
|
+
throw new Error(`Failed to fetch ${to} value for token (${fromTokenAddress}) on chainId: ${chain.id}`);
|
66
|
+
}
|
67
|
+
const data = await response.json();
|
68
|
+
return data;
|
69
|
+
}
|
70
|
+
//# sourceMappingURL=cryptoToFiat.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cryptoToFiat.js","sourceRoot":"","sources":["../../../../src/pay/convert/cryptoToFiat.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,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AAC,KAAK,CAAC,EAAE,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;KAC/B,CAAC;IACF,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,MAAM,GAAG,GAAG,GAAG,iCAAiC,EAAE,IAAI,WAAW,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,mBAAmB,EAAE,qBAAqB,gBAAgB,iBAAiB,KAAK,CAAC,EAAE,EAAE,CACtF,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAuB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
|
2
|
+
import { getBytecode } from "../../contract/actions/get-bytecode.js";
|
3
|
+
import { getContract } from "../../contract/contract.js";
|
4
|
+
import { isAddress } from "../../utils/address.js";
|
5
|
+
import { getClientFetch } from "../../utils/fetch.js";
|
6
|
+
import { getPayConvertFiatToCryptoEndpoint } from "../utils/definitions.js";
|
7
|
+
/**
|
8
|
+
* Convert a fiat value to a token.
|
9
|
+
* Currently only USD is supported.
|
10
|
+
* @example
|
11
|
+
* ### Basic usage
|
12
|
+
* ```ts
|
13
|
+
* import { convertFiatToCrypto } from "thirdweb/pay";
|
14
|
+
*
|
15
|
+
* // Convert 2 cents to ETH
|
16
|
+
* const result = await convertFiatToCrypto({
|
17
|
+
* from: "USD",
|
18
|
+
* // the token address. For native token, use NATIVE_TOKEN_ADDRESS
|
19
|
+
* to: "0x...",
|
20
|
+
* // the chain (of the chain where the token belong to)
|
21
|
+
* chain: ethereum,
|
22
|
+
* // 2 cents
|
23
|
+
* fromAmount: 0.02,
|
24
|
+
* });
|
25
|
+
* ```
|
26
|
+
* Result: `{ result: 0.0000057 }`
|
27
|
+
* @buyCrypto
|
28
|
+
*/
|
29
|
+
export async function convertFiatToCrypto(options) {
|
30
|
+
const { client, from, to, chain, fromAmount } = options;
|
31
|
+
if (Number(fromAmount) === 0) {
|
32
|
+
return { result: 0 };
|
33
|
+
}
|
34
|
+
// Testnets just don't work with our current provider(s)
|
35
|
+
if (chain.testnet === true) {
|
36
|
+
throw new Error(`Cannot fetch price for a testnet (chainId: ${chain.id})`);
|
37
|
+
}
|
38
|
+
// Some provider that we are using will return `0` for unsupported token
|
39
|
+
// so we should do some basic input validations before sending the request
|
40
|
+
// Make sure it's a valid EVM address
|
41
|
+
if (!isAddress(to)) {
|
42
|
+
throw new Error("Invalid `to`. Expected a valid EVM contract address");
|
43
|
+
}
|
44
|
+
// Make sure it's either a valid contract or a native token
|
45
|
+
if (to.toLowerCase() !== NATIVE_TOKEN_ADDRESS.toLowerCase()) {
|
46
|
+
const bytecode = await getBytecode(getContract({
|
47
|
+
address: to,
|
48
|
+
chain,
|
49
|
+
client,
|
50
|
+
})).catch(() => undefined);
|
51
|
+
if (!bytecode || bytecode === "0x") {
|
52
|
+
throw new Error(`Error: ${to} on chainId: ${chain.id} is not a valid contract address.`);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
const params = {
|
56
|
+
from,
|
57
|
+
to,
|
58
|
+
chainId: String(chain.id),
|
59
|
+
fromAmount: String(fromAmount),
|
60
|
+
};
|
61
|
+
const queryString = new URLSearchParams(params).toString();
|
62
|
+
const url = `${getPayConvertFiatToCryptoEndpoint()}?${queryString}`;
|
63
|
+
const response = await getClientFetch(client)(url);
|
64
|
+
if (!response.ok) {
|
65
|
+
throw new Error(`Failed to convert ${to} value to token (${to}) on chainId: ${chain.id}`);
|
66
|
+
}
|
67
|
+
const data = await response.json();
|
68
|
+
return data;
|
69
|
+
}
|
70
|
+
//# sourceMappingURL=fiatTo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