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

Commit

Permalink
fix: gas estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
intergalacticspacehighway committed Oct 31, 2023
1 parent 54f9ce8 commit 11f437d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
9 changes: 2 additions & 7 deletions packages/app/hooks/creator-token/use-creator-token-approve.ts
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

0 comments on commit 11f437d

Please sign in to comment.