This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: buy with eth * nit * fix * pay with eth fixes * fix: display eth * fix * fix * fix * fix * nits * add eth balance * nits * default to eth
- Loading branch information
1 parent
b30cc66
commit d181c92
Showing
11 changed files
with
413 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
export const creatorTokenSwapRouterAbi = [ | ||
{ | ||
inputs: [ | ||
{ internalType: "address", name: "_universalRouter", type: "address" }, | ||
{ internalType: "address", name: "_wethAddress", type: "address" }, | ||
{ internalType: "address", name: "_usdcAddress", type: "address" }, | ||
], | ||
stateMutability: "nonpayable", | ||
type: "constructor", | ||
}, | ||
{ | ||
inputs: [], | ||
name: "USDC_ADDRESS", | ||
outputs: [{ internalType: "address", name: "", type: "address" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [], | ||
name: "WETH_ADDRESS", | ||
outputs: [{ internalType: "address", name: "", type: "address" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: "address", name: "_creatorToken", type: "address" }, | ||
{ internalType: "uint256", name: "_numOfTokens", type: "uint256" }, | ||
{ internalType: "uint256", name: "_maxPayment", type: "uint256" }, | ||
], | ||
name: "bulkBuyWithEth", | ||
outputs: [{ internalType: "uint256", name: "_amountOut", type: "uint256" }], | ||
stateMutability: "payable", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: "address", name: "_creatorToken", type: "address" }, | ||
{ internalType: "address", name: "_to", type: "address" }, | ||
{ internalType: "uint256", name: "_numOfTokens", type: "uint256" }, | ||
{ internalType: "uint256", name: "_maxPayment", type: "uint256" }, | ||
], | ||
name: "bulkBuyWithEth", | ||
outputs: [{ internalType: "uint256", name: "_amountOut", type: "uint256" }], | ||
stateMutability: "payable", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: "address", name: "_creatorToken", type: "address" }, | ||
{ internalType: "address", name: "_to", type: "address" }, | ||
{ internalType: "uint256", name: "_maxPayment", type: "uint256" }, | ||
], | ||
name: "buyWithEth", | ||
outputs: [{ internalType: "uint256", name: "_amountOut", type: "uint256" }], | ||
stateMutability: "payable", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: "address", name: "_creatorToken", type: "address" }, | ||
{ internalType: "uint256", name: "_maxPayment", type: "uint256" }, | ||
], | ||
name: "buyWithEth", | ||
outputs: [{ internalType: "uint256", name: "_amountOut", type: "uint256" }], | ||
stateMutability: "payable", | ||
type: "function", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import QuoterAbi from "@uniswap/v3-periphery/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json"; | ||
import useSWR from "swr"; | ||
|
||
import { Logger } from "app/lib/logger"; | ||
import { publicClient } from "app/lib/wallet-public-client"; | ||
|
||
import { | ||
quoterv2Address, | ||
usdcAddress, | ||
wETHAddress, | ||
} from "../creator-token/utils"; | ||
|
||
export const getETHForUSDC = (params?: { amount: bigint }) => | ||
params ? "getETHForUSDC" + params.amount : ""; | ||
|
||
export const useGetETHForUSDC = (params?: { amount: bigint }) => { | ||
const res = useSWR( | ||
getETHForUSDC(params), | ||
async () => { | ||
if (params?.amount) { | ||
const req = { | ||
tokenIn: wETHAddress, | ||
tokenOut: usdcAddress, | ||
fee: 500, | ||
amount: params.amount + 500000n, | ||
sqrtPriceLimitX96: 0, | ||
}; | ||
|
||
const res: any = await publicClient.readContract({ | ||
address: quoterv2Address, | ||
abi: QuoterAbi.abi, | ||
functionName: "quoteExactOutputSingle", | ||
args: [req], | ||
}); | ||
|
||
console.log("res ", res); | ||
return { | ||
value: res[0], | ||
displayValue: (Number(res[0]) / 10 ** 18).toFixed(6), | ||
}; | ||
} | ||
}, | ||
{ | ||
refreshInterval: 10_000, | ||
revalidateOnMount: true, | ||
} | ||
); | ||
|
||
return res; | ||
}; |
Oops, something went wrong.