Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

fix: gas est #2475

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,24 @@ export const useApproveToken = () => {
);

if (res < maxPrice) {
const { gasPrice } = await publicClient.estimateFeesPerGas({
type: "legacy",
});
const { maxFeePerGas, maxPriorityFeePerGas } =
await publicClient.estimateFeesPerGas({
type: "eip1559",
});

console.log("gas price approve", {
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
});
if (gasPrice && maxFeePerGas) {
if (maxFeePerGas) {
const { request } = await publicClient.simulateContract({
address: usdcAddress,
account: walletAddress,
abi: erc20Abi,
functionName: "approve",
args: [creatorTokenContract, maxPrice],
chain: chain,
maxFeePerGas:
maxFeePerGas > gasPrice * 2n ? maxFeePerGas : gasPrice * 2n,
maxFeePerGas,
maxPriorityFeePerGas,
});

Expand Down
12 changes: 3 additions & 9 deletions packages/app/hooks/creator-token/use-creator-token-buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,16 @@ export const useCreatorTokenBuy = (params: {
baseChain?.rpcUrls.default.http[0]
);

const { gasPrice } = await publicClient.estimateFeesPerGas({
type: "legacy",
});
const { maxFeePerGas, maxPriorityFeePerGas } =
await publicClient.estimateFeesPerGas({
type: "eip1559",
});

console.log("gas price buy", {
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
});
if (gasPrice && maxFeePerGas) {
if (maxFeePerGas) {
if (tokenAmount === 1) {
const { request } = await publicClient.simulateContract({
address: profileData?.data?.profile.creator_token.address,
Expand All @@ -96,8 +92,7 @@ export const useCreatorTokenBuy = (params: {
args: [priceToBuyNext.data?.totalPrice],
chain: baseChain,
type: "eip1559",
maxFeePerGas:
maxFeePerGas > gasPrice * 2n ? maxFeePerGas : gasPrice * 2n,
maxFeePerGas,
maxPriorityFeePerGas,
});
requestPayload = request;
Expand All @@ -111,8 +106,7 @@ export const useCreatorTokenBuy = (params: {
args: [tokenAmount, priceToBuyNext.data?.totalPrice],
chain: baseChain,
type: "eip1559",
maxFeePerGas:
maxFeePerGas > gasPrice * 2n ? maxFeePerGas : gasPrice * 2n,
maxFeePerGas,
maxPriorityFeePerGas,
});
console.log("bulk buy request", request);
Expand Down
Loading