Skip to content

Commit

Permalink
Merge branch 'main' into v3-pool-creation
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Nov 19, 2024
2 parents 03db133 + 46de864 commit f3cca6b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/nextjs/app/cow/_components/PoolConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const PoolConfiguration = () => {
address: undefined,
step: 1,
tokenWeights,
isInitialState: true,
});
}}
/>
Expand Down
8 changes: 7 additions & 1 deletion packages/nextjs/app/cow/_components/PoolCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CHAIN_NAMES } from "~~/hooks/balancer/";
import {
type PoolCreationState,
useBindToken,
useCowFactoryEvents,
useCreatePool,
useFinalizePool,
useReadPool,
Expand All @@ -32,6 +33,8 @@ interface ManagePoolCreationProps {
}

export const PoolCreation = ({ poolCreation, updatePoolCreation, clearPoolCreation }: ManagePoolCreationProps) => {
useCowFactoryEvents();

const searchParams = useSearchParams();
const poolAddress = searchParams.get("address") || poolCreation.address;

Expand Down Expand Up @@ -76,7 +79,7 @@ export const PoolCreation = ({ poolCreation, updatePoolCreation, clearPoolCreati
createPoolError || approve1Error || approve2Error || bind1Error || bind2Error || setSwapFeeError || finalizeError;

useEffect(() => {
if (!poolData) return;
if (!poolData || poolCreation.isInitialState) return;

if (poolData.isFinalized) {
updatePoolCreation({ step: 8 });
Expand Down Expand Up @@ -145,6 +148,9 @@ export const PoolCreation = ({ poolCreation, updatePoolCreation, clearPoolCreati
isPending={isCreatePending}
isDisabled={isCreatePending || isWrongNetwork}
onClick={() => {
// user has officially begun the pool creation process
updatePoolCreation({ isInitialState: false });

createPool(
{ name: poolCreation.name, symbol: poolCreation.symbol },
{
Expand Down
26 changes: 13 additions & 13 deletions packages/nextjs/components/common/PoolStateResetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ export const PoolStateResetModal = ({ setIsModalOpen, clearState, etherscanURL }
<div className="fixed inset-0 bg-black bg-opacity-75 flex justify-center items-center z-50">
<div className="absolute w-full h-full" onClick={() => setIsModalOpen(false)} />
<div className="w-[550px] relative bg-base-300 border border-base-200 rounded-lg p-6">
<div className="flex items-center justify-between mb-5">
<h5 className="font-bold text-2xl mb-0">Are you sure?</h5>
<div className="flex items-center justify-between mb-7">
<h5 className="font-bold text-3xl mb-0">Are you sure?</h5>

<XMarkIcon className="w-6 h-6 hover:cursor-pointer " onClick={() => setIsModalOpen(false)} />
</div>

<div className="text-lg mb-5">If you are having trouble with the pool creation process, please consider:</div>
<div className="text-xl mb-7">If having trouble with pool creation process, please try:</div>
<ol className="list-decimal pl-5 mb-10 text-lg">
<li>
<span className="link cursor-pointer text-info" onClick={() => window.location.reload()}>
Refreshing the page
</span>
</li>
<li>
Reaching out for assistance on{" "}
<Link target="_blank" rel="noreferrer" href="https://discord.balancer.fi/">
<span className="link">discord</span> <ArrowTopRightOnSquareIcon className="w-4 h-4 inline-block" />
<span className="link text-info">discord</span>{" "}
<ArrowTopRightOnSquareIcon className="w-4 h-4 inline-block text-info" />
</Link>
</li>
{etherscanURL && (
<li>
Viewing the pool on a{" "}
Viewing the pool on{" "}
<Link target="_blank" rel="noreferrer" href={etherscanURL}>
<span className="link">block explorer</span>{" "}
<ArrowTopRightOnSquareIcon className="w-4 h-4 inline-block" />
<span className="link text-info">block explorer</span>{" "}
<ArrowTopRightOnSquareIcon className="w-4 h-4 inline-block text-info" />
</Link>
</li>
)}
<li>
Adding pool address to URL search params
<ol className="">
<li className="text-info">https://pool-creator.balancer.fi/cow?address=0x...</li>
</ol>
</li>
</ol>
<div className="flex gap-3 justify-end">
<button
Expand Down
5 changes: 5 additions & 0 deletions packages/nextjs/contracts/externalContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,35 @@ const externalContracts = {
BCoWFactory: {
address: FACTORY_ADDRESSES[scaffoldConfig.targetFork.id],
abi: abis.CoW.BCoWFactory,
fromBlock: 0n,
},
},
11155111: {
BCoWFactory: {
address: FACTORY_ADDRESSES[sepolia.id],
abi: abis.CoW.BCoWFactory,
fromBlock: 6415186n,
},
},
1: {
BCoWFactory: {
address: FACTORY_ADDRESSES[mainnet.id],
abi: abis.CoW.BCoWFactory,
fromBlock: 20432455n,
},
},
100: {
BCoWFactory: {
address: FACTORY_ADDRESSES[gnosis.id],
abi: abis.CoW.BCoWFactory,
fromBlock: 35259725n,
},
},
42161: {
BCoWFactory: {
address: FACTORY_ADDRESSES[arbitrum.id],
abi: abis.CoW.BCoWFactory,
fromBlock: 248291297n,
},
},
} as const;
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/hooks/cow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./useBindToken";
export * from "./useSetSwapFee";
export * from "./getPoolUrl";
export * from "./usePoolCreationStore";
export * from "./useCowFactoryEvents";
28 changes: 28 additions & 0 deletions packages/nextjs/hooks/cow/useCowFactoryEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect } from "react";
import { useAccount } from "wagmi";
import externalContracts from "~~/contracts/externalContracts";
import { usePoolCreationStore } from "~~/hooks/cow/usePoolCreationStore";
import { useScaffoldEventHistory, useTargetNetwork } from "~~/hooks/scaffold-eth";

export const useCowFactoryEvents = () => {
const { address: connectedAddress } = useAccount();
const { targetNetwork } = useTargetNetwork();
const { updatePoolCreation } = usePoolCreationStore();

const { data: events, isLoading: isLoadingEvents } = useScaffoldEventHistory({
contractName: "BCoWFactory",
eventName: "LOG_NEW_POOL",
fromBlock: externalContracts[targetNetwork.id as keyof typeof externalContracts].BCoWFactory.fromBlock,
watch: true,
filters: { caller: connectedAddress },
});

useEffect(() => {
if (!isLoadingEvents && events) {
const pools = events.map(e => e.args.bPool).filter((pool): pool is string => pool !== undefined);
// zero index is the most recently created pool for the user
const mostRecentlyCreated = pools[0];
updatePoolCreation({ address: mostRecentlyCreated });
}
}, [isLoadingEvents, events, updatePoolCreation]);
};
1 change: 1 addition & 0 deletions packages/nextjs/hooks/cow/usePoolCreationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PoolCreationState {
address: Address | undefined; // updated by tx receipt from completion of step 1
step: number;
tokenWeights: "5050" | "8020";
isInitialState: boolean;
}

export const usePoolCreationStore = create(
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type GenericContract = {
abi: Abi;
inheritedFunctions?: InheritedFunctions;
external?: true;
fromBlock?: bigint;
};

export type GenericContractsDeclaration = {
Expand Down

0 comments on commit f3cca6b

Please sign in to comment.