thirdweb 5.72.0-nightly-393d0cfb504401d6449a75cbe8422946d157fc93-20241202000349 → 5.72.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/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/utils.js +27 -0
- package/dist/cjs/transaction/utils.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.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/utils.js +26 -0
- package/dist/esm/transaction/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.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/utils.d.ts +2 -0
- package/dist/types/transaction/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +1 -1
- 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/utils.ts +33 -0
- package/src/version.ts +1 -1
@@ -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;AACzE,mGAA2F;AAE3F,qFAA+E;AAC/E,uFAAiF;AACjF,wHAAyH;AAIzH,qDAAwE;AAsFxE;;;;;;;;;;;;GAYG;AACH,SAAgB,sBAAsB,CAAC,IAKtC;IACC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC5D,IAAI,QAAQ,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC;IAEpC,OAAO,IAAA,yBAAW,EAAC;QACjB,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;YACvB,yBAAyB;YACzB,IAAI,MAAM,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC;gBACpD,MAAM,WAAW,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC5B,8DAA8D;gBAC9D,QAAQ,GAAG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AAC,MAAM,CAAC,CAAC;wBAC7D,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;wBAC9C,MAAM,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;wBAE3C,MAAM,eAAe,GACnB,CAAC,UAAU,GAAG,EAAE;4BACd,YAAY;4BACZ,YAAY,CAAC,KAAK,GAAG,UAAU,CAAC;4BAClC,CAAC,UAAU,GAAG,EAAE,IAAI,aAAa,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC;wBAExD,IAAI,eAAe,EAAE,CAAC;4BACpB,YAAY,CAAC;gCACX,EAAE;gCACF,MAAM;gCACN,QAAQ,EAAE,MAAM;gCAChB,SAAS,EAAE,OAAO;6BACnB,CAAC,CAAC;wBACL,CAAC;6BAAM,CAAC;4BACN,MAAM,EAAE,CAAC;wBACX,CAAC;oBACH,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;wBAC5C,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,6CAA6C;IAC7C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,GASzC,CAAC;IACJ,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,CAAC,GAAG,CAAC;YACV,IAAA,gDAAoB,EAAC,WAAW,CAAC,KAAK,CAAC;YACvC,IAAA,gDAAoB,EAAC,WAAW,CAAC,UAAU,CAAC;YAC5C,IAAA,gDAAoB,EAAC,WAAW,CAAC,EAAE,CAAC;YACpC,IAAA,kBAAM,EAAC,WAAW,CAAC;SACpB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE;YACxC,aAAa,CAAC;gBACZ,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE;gBACxB,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE;gBAC7C,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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"}
|
@@ -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
package/dist/cjs/version.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
2
|
-
import { getGasPrice } from "../../../../gas/get-gas-price.js";
|
3
|
-
import { estimateGasCost } from "../../../../transaction/actions/estimate-gas-cost.js";
|
4
2
|
import { sendTransaction } from "../../../../transaction/actions/send-transaction.js";
|
3
|
+
import { getTransactionGasCost } from "../../../../transaction/utils.js";
|
5
4
|
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
|
6
5
|
import { getTokenBalance } from "../../../../wallets/utils/getTokenBalance.js";
|
7
6
|
import { getWalletBalance } from "../../../../wallets/utils/getWalletBalance.js";
|
@@ -95,7 +94,7 @@ export function useSendTransactionCore(args) {
|
|
95
94
|
tokenAddress: _erc20Value.tokenAddress,
|
96
95
|
})
|
97
96
|
: undefined,
|
98
|
-
|
97
|
+
getTransactionGasCost(tx, account.address),
|
99
98
|
]);
|
100
99
|
const gasSponsored = hasSponsoredTransactionsEnabled(wallet);
|
101
100
|
const txGasCost = gasSponsored ? 0n : gasCost;
|
@@ -126,34 +125,4 @@ export function useSendTransactionCore(args) {
|
|
126
125
|
},
|
127
126
|
});
|
128
127
|
}
|
129
|
-
async function getTotalTxCostForBuy(tx, from) {
|
130
|
-
try {
|
131
|
-
const gasCost = await estimateGasCost({
|
132
|
-
transaction: tx,
|
133
|
-
from,
|
134
|
-
});
|
135
|
-
const bufferCost = gasCost.wei / 10n;
|
136
|
-
// Note: get tx.value AFTER estimateGasCost
|
137
|
-
const txValue = await resolvePromisedValue(tx.value);
|
138
|
-
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
139
|
-
return gasCost.wei + bufferCost + (txValue || 0n);
|
140
|
-
}
|
141
|
-
catch {
|
142
|
-
if (from) {
|
143
|
-
// try again without passing from
|
144
|
-
return await getTotalTxCostForBuy(tx);
|
145
|
-
}
|
146
|
-
// fallback if both fail, use the tx value + 2M * gas price
|
147
|
-
const value = await resolvePromisedValue(tx.value);
|
148
|
-
const gasPrice = await getGasPrice({
|
149
|
-
client: tx.client,
|
150
|
-
chain: tx.chain,
|
151
|
-
});
|
152
|
-
const buffer = 2000000n * gasPrice;
|
153
|
-
if (!value) {
|
154
|
-
return 0n + buffer;
|
155
|
-
}
|
156
|
-
return value + buffer;
|
157
|
-
}
|
158
|
-
}
|
159
128
|
//# sourceMappingURL=useSendTransaction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSendTransaction.js","sourceRoot":"","sources":["../../../../../../src/react/core/hooks/transaction/useSendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
1
|
+
{"version":3,"file":"useSendTransaction.js","sourceRoot":"","sources":["../../../../../../src/react/core/hooks/transaction/useSendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAM5E,OAAO,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAGtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+CAA+C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,0EAA0E,CAAC;AAIzH,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAsFxE;;;;;;;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 -4,9 +4,8 @@ import { getChainMetadata } from "../../../../../../../chains/utils.js";
|
|
4
4
|
import { NATIVE_TOKEN_ADDRESS } from "../../../../../../../constants/addresses.js";
|
5
5
|
import { getContract } from "../../../../../../../contract/contract.js";
|
6
6
|
import { getCurrencyMetadata } from "../../../../../../../extensions/erc20/read/getCurrencyMetadata.js";
|
7
|
-
import { getGasPrice } from "../../../../../../../gas/get-gas-price.js";
|
8
7
|
import { encode } from "../../../../../../../transaction/actions/encode.js";
|
9
|
-
import {
|
8
|
+
import { getTransactionGasCost } from "../../../../../../../transaction/utils.js";
|
10
9
|
import { resolvePromisedValue } from "../../../../../../../utils/promise/resolve-promised-value.js";
|
11
10
|
import { getWalletBalance } from "../../../../../../../wallets/utils/getWalletBalance.js";
|
12
11
|
export function useTransactionCostAndData(args) {
|
@@ -111,28 +110,4 @@ export function useTransactionCostAndData(args) {
|
|
111
110
|
},
|
112
111
|
});
|
113
112
|
}
|
114
|
-
async function getTransactionGasCost(tx, from) {
|
115
|
-
try {
|
116
|
-
const gasCost = await estimateGasCost({
|
117
|
-
transaction: tx,
|
118
|
-
from,
|
119
|
-
});
|
120
|
-
const bufferCost = gasCost.wei / 10n;
|
121
|
-
// Note: get tx.value AFTER estimateGasCost
|
122
|
-
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
123
|
-
return gasCost.wei + bufferCost;
|
124
|
-
}
|
125
|
-
catch {
|
126
|
-
if (from) {
|
127
|
-
// try again without passing from
|
128
|
-
return await getTransactionGasCost(tx);
|
129
|
-
}
|
130
|
-
// fallback if both fail, use the tx value + 2M * gas price
|
131
|
-
const gasPrice = await getGasPrice({
|
132
|
-
client: tx.client,
|
133
|
-
chain: tx.chain,
|
134
|
-
});
|
135
|
-
return 2000000n * gasPrice;
|
136
|
-
}
|
137
|
-
}
|
138
113
|
//# 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":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"useBuyTxStates.js","sourceRoot":"","sources":["../../../../../../../../../src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,EAAE,MAAM,EAAE,MAAM,oDAAoD,CAAC;AAE5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAElF,OAAO,EAAE,oBAAoB,EAAE,MAAM,8DAA8D,CAAC;AAEpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAC;AAI1F,MAAM,UAAU,yBAAyB,CAAC,IAIzC;IACC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,IAAI,CAAC;IAC7D,6CAA6C;IAC7C,MAAM,CAAC,UAAU,EAAE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AC3B,CAAC;gBACF,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC;gBACnC,qBAAqB,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC;aACrD,CAAC,CAAC;YACL,MAAM,aAAa,GAAG,mBAAmB,CAAC;YAC1C,MAAM,mBAAmB,GACvB,CAAC,MAAM,oBAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;YACxD,OAAO;gBACL,KAAK,EAAE;oBACL,OAAO,EAAE,oBAAoB;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"}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { getGasPrice } from "../gas/get-gas-price.js";
|
2
|
+
import { estimateGasCost } from "./actions/estimate-gas-cost.js";
|
1
3
|
/**
|
2
4
|
* @internal
|
3
5
|
*/
|
@@ -7,4 +9,28 @@ export function isAbiFunction(item) {
|
|
7
9
|
"type" in item &&
|
8
10
|
item.type === "function");
|
9
11
|
}
|
12
|
+
export async function getTransactionGasCost(tx, from) {
|
13
|
+
try {
|
14
|
+
const gasCost = await estimateGasCost({
|
15
|
+
transaction: tx,
|
16
|
+
from,
|
17
|
+
});
|
18
|
+
const bufferCost = gasCost.wei / 10n;
|
19
|
+
// Note: get tx.value AFTER estimateGasCost
|
20
|
+
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
21
|
+
return gasCost.wei + bufferCost;
|
22
|
+
}
|
23
|
+
catch {
|
24
|
+
if (from) {
|
25
|
+
// try again without passing from
|
26
|
+
return await getTransactionGasCost(tx);
|
27
|
+
}
|
28
|
+
// fallback if both fail, use the tx value + 1M * gas price
|
29
|
+
const gasPrice = await getGasPrice({
|
30
|
+
client: tx.client,
|
31
|
+
chain: tx.chain,
|
32
|
+
});
|
33
|
+
return 1000000n * gasPrice;
|
34
|
+
}
|
35
|
+
}
|
10
36
|
//# 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":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGjE;;GAEG;AACH,MAAM,UAAU,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;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,EAAuB,EACvB,IAAa;IAEb,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;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,WAAW,CAAC;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/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export const version = "5.72.0
|
1
|
+
export const version = "5.72.0";
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/dist/esm/version.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSendTransaction.d.ts","sourceRoot":"","sources":["../../../../../../src/react/core/hooks/transaction/useSendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAe,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;
|
1
|
+
{"version":3,"file":"useSendTransaction.d.ts","sourceRoot":"","sources":["../../../../../../src/react/core/hooks/transaction/useSendTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAe,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,KA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I,EAAE,QAAQ,CAAC;QACf,MAAM,EAAE,mBAAmB,CAAC;KAC7B,GACD;QACE,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,iBAAiB,CAAC;KAC3B,KACF,IAAI,CAAC;CACX,GACD,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,QAAQ,CAAC,EAAE,6BAA6B,CAAC;IAEzC;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,mBAAmB,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,SAAS,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAClD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,GAAG,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,mBAAmB,CAAC,CA8HvE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useBuyTxStates.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"useBuyTxStates.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAInG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mDAAmD,CAAC;AAEjF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAGjF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE;IAC9C,WAAW,EAAE,mBAAmB,CAAC;IACjC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,qBAAqB,EAAE,uBAAuB,CAAC;CAChD;;;;;;;;;;;UAsHA"}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import type { AbiFunction } from "abitype";
|
2
|
+
import type { PreparedTransaction } from "./prepare-transaction.js";
|
2
3
|
/**
|
3
4
|
* @internal
|
4
5
|
*/
|
5
6
|
export declare function isAbiFunction(item: unknown): item is AbiFunction;
|
7
|
+
export declare function getTransactionGasCost(tx: PreparedTransaction, from?: string): Promise<bigint>;
|
6
8
|
//# sourceMappingURL=utils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/transaction/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/transaction/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,WAAW,CAOhE;AAED,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,mBAAmB,EACvB,IAAI,CAAC,EAAE,MAAM,mBA0Bd"}
|
package/dist/types/version.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const version = "5.72.0
|
1
|
+
export declare const version = "5.72.0";
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/package.json
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
import { type UseMutationResult, useMutation } from "@tanstack/react-query";
|
2
2
|
import type { Chain } from "../../../../chains/types.js";
|
3
|
-
import { getGasPrice } from "../../../../gas/get-gas-price.js";
|
4
3
|
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
|
5
4
|
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
|
6
5
|
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
|
7
|
-
import { estimateGasCost } from "../../../../transaction/actions/estimate-gas-cost.js";
|
8
6
|
import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
|
9
7
|
import { sendTransaction } from "../../../../transaction/actions/send-transaction.js";
|
10
8
|
import type { WaitForReceiptOptions } from "../../../../transaction/actions/wait-for-tx-receipt.js";
|
11
9
|
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
|
10
|
+
import { getTransactionGasCost } from "../../../../transaction/utils.js";
|
12
11
|
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
|
13
12
|
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
|
14
13
|
import { getTokenBalance } from "../../../../wallets/utils/getTokenBalance.js";
|
@@ -215,7 +214,7 @@ export function useSendTransactionCore(args: {
|
|
215
214
|
tokenAddress: _erc20Value.tokenAddress,
|
216
215
|
})
|
217
216
|
: undefined,
|
218
|
-
|
217
|
+
getTransactionGasCost(tx, account.address),
|
219
218
|
]);
|
220
219
|
|
221
220
|
const gasSponsored = hasSponsoredTransactionsEnabled(wallet);
|
@@ -248,39 +247,3 @@ export function useSendTransactionCore(args: {
|
|
248
247
|
},
|
249
248
|
});
|
250
249
|
}
|
251
|
-
|
252
|
-
async function getTotalTxCostForBuy(tx: PreparedTransaction, from?: string) {
|
253
|
-
try {
|
254
|
-
const gasCost = await estimateGasCost({
|
255
|
-
transaction: tx,
|
256
|
-
from,
|
257
|
-
});
|
258
|
-
|
259
|
-
const bufferCost = gasCost.wei / 10n;
|
260
|
-
|
261
|
-
// Note: get tx.value AFTER estimateGasCost
|
262
|
-
const txValue = await resolvePromisedValue(tx.value);
|
263
|
-
|
264
|
-
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
265
|
-
return gasCost.wei + bufferCost + (txValue || 0n);
|
266
|
-
} catch {
|
267
|
-
if (from) {
|
268
|
-
// try again without passing from
|
269
|
-
return await getTotalTxCostForBuy(tx);
|
270
|
-
}
|
271
|
-
// fallback if both fail, use the tx value + 2M * gas price
|
272
|
-
const value = await resolvePromisedValue(tx.value);
|
273
|
-
|
274
|
-
const gasPrice = await getGasPrice({
|
275
|
-
client: tx.client,
|
276
|
-
chain: tx.chain,
|
277
|
-
});
|
278
|
-
|
279
|
-
const buffer = 2_000_000n * gasPrice;
|
280
|
-
|
281
|
-
if (!value) {
|
282
|
-
return 0n + buffer;
|
283
|
-
}
|
284
|
-
return value + buffer;
|
285
|
-
}
|
286
|
-
}
|
@@ -4,10 +4,9 @@ import { getChainMetadata } from "../../../../../../../chains/utils.js";
|
|
4
4
|
import { NATIVE_TOKEN_ADDRESS } from "../../../../../../../constants/addresses.js";
|
5
5
|
import { getContract } from "../../../../../../../contract/contract.js";
|
6
6
|
import { getCurrencyMetadata } from "../../../../../../../extensions/erc20/read/getCurrencyMetadata.js";
|
7
|
-
import { getGasPrice } from "../../../../../../../gas/get-gas-price.js";
|
8
7
|
import { encode } from "../../../../../../../transaction/actions/encode.js";
|
9
|
-
import { estimateGasCost } from "../../../../../../../transaction/actions/estimate-gas-cost.js";
|
10
8
|
import type { PreparedTransaction } from "../../../../../../../transaction/prepare-transaction.js";
|
9
|
+
import { getTransactionGasCost } from "../../../../../../../transaction/utils.js";
|
11
10
|
import type { Hex } from "../../../../../../../utils/encoding/hex.js";
|
12
11
|
import { resolvePromisedValue } from "../../../../../../../utils/promise/resolve-promised-value.js";
|
13
12
|
import type { Account } from "../../../../../../../wallets/interfaces/wallet.js";
|
@@ -138,30 +137,3 @@ export function useTransactionCostAndData(args: {
|
|
138
137
|
},
|
139
138
|
});
|
140
139
|
}
|
141
|
-
|
142
|
-
async function getTransactionGasCost(tx: PreparedTransaction, from?: string) {
|
143
|
-
try {
|
144
|
-
const gasCost = await estimateGasCost({
|
145
|
-
transaction: tx,
|
146
|
-
from,
|
147
|
-
});
|
148
|
-
|
149
|
-
const bufferCost = gasCost.wei / 10n;
|
150
|
-
|
151
|
-
// Note: get tx.value AFTER estimateGasCost
|
152
|
-
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
153
|
-
return gasCost.wei + bufferCost;
|
154
|
-
} catch {
|
155
|
-
if (from) {
|
156
|
-
// try again without passing from
|
157
|
-
return await getTransactionGasCost(tx);
|
158
|
-
}
|
159
|
-
// fallback if both fail, use the tx value + 2M * gas price
|
160
|
-
const gasPrice = await getGasPrice({
|
161
|
-
client: tx.client,
|
162
|
-
chain: tx.chain,
|
163
|
-
});
|
164
|
-
|
165
|
-
return 2_000_000n * gasPrice;
|
166
|
-
}
|
167
|
-
}
|
package/src/transaction/utils.ts
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
import type { AbiFunction } from "abitype";
|
2
|
+
import { getGasPrice } from "../gas/get-gas-price.js";
|
3
|
+
import { estimateGasCost } from "./actions/estimate-gas-cost.js";
|
4
|
+
import type { PreparedTransaction } from "./prepare-transaction.js";
|
2
5
|
|
3
6
|
/**
|
4
7
|
* @internal
|
@@ -11,3 +14,33 @@ export function isAbiFunction(item: unknown): item is AbiFunction {
|
|
11
14
|
item.type === "function"
|
12
15
|
);
|
13
16
|
}
|
17
|
+
|
18
|
+
export async function getTransactionGasCost(
|
19
|
+
tx: PreparedTransaction,
|
20
|
+
from?: string,
|
21
|
+
) {
|
22
|
+
try {
|
23
|
+
const gasCost = await estimateGasCost({
|
24
|
+
transaction: tx,
|
25
|
+
from,
|
26
|
+
});
|
27
|
+
|
28
|
+
const bufferCost = gasCost.wei / 10n;
|
29
|
+
|
30
|
+
// Note: get tx.value AFTER estimateGasCost
|
31
|
+
// add 10% extra gas cost to the estimate to ensure user buys enough to cover the tx cost
|
32
|
+
return gasCost.wei + bufferCost;
|
33
|
+
} catch {
|
34
|
+
if (from) {
|
35
|
+
// try again without passing from
|
36
|
+
return await getTransactionGasCost(tx);
|
37
|
+
}
|
38
|
+
// fallback if both fail, use the tx value + 1M * gas price
|
39
|
+
const gasPrice = await getGasPrice({
|
40
|
+
client: tx.client,
|
41
|
+
chain: tx.chain,
|
42
|
+
});
|
43
|
+
|
44
|
+
return 1_000_000n * gasPrice;
|
45
|
+
}
|
46
|
+
}
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.72.0
|
1
|
+
export const version = "5.72.0";
|