-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe504fe
commit f88b054
Showing
9 changed files
with
96 additions
and
66 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
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
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,37 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { Address, parseEventLogs } from "viem"; | ||
import { usePublicClient } from "wagmi"; | ||
import { abis } from "~~/contracts/abis"; | ||
import { useScaffoldWriteContract } from "~~/hooks/scaffold-eth"; | ||
|
||
type CreatePoolPayload = { | ||
name: string; | ||
symbol: string; | ||
}; | ||
|
||
export const useCreatePool = () => { | ||
const { writeContractAsync: bCoWFactory } = useScaffoldWriteContract("BCoWFactory"); | ||
const publicClient = usePublicClient(); | ||
|
||
const createPool = async ({ name, symbol }: CreatePoolPayload): Promise<Address> => { | ||
if (!publicClient) throw new Error("No public client"); | ||
const hash = await bCoWFactory({ | ||
functionName: "newBPool", | ||
args: [name, symbol], | ||
}); | ||
if (!hash) throw new Error("No pool creation transaction hash"); | ||
const txReceipt = await publicClient.getTransactionReceipt({ hash }); | ||
const logs = parseEventLogs({ | ||
abi: abis.CoW.BCoWFactory, | ||
logs: txReceipt.logs, | ||
}); | ||
const newPool = (logs[0].args as { caller: string; bPool: string }).bPool; | ||
console.log("New pool address from txReceipt logs:", newPool); | ||
|
||
return newPool; | ||
}; | ||
|
||
return useMutation({ | ||
mutationFn: (payload: CreatePoolPayload) => createPool(payload), | ||
}); | ||
}; |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from "./useReadToken"; | ||
export * from "./useWriteToken"; | ||
export * from "./useApproveToken"; | ||
export * from "./useFetchTokenList"; | ||
export * from "./useFetchTokenPrices"; | ||
export * from "./types"; |
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