From e83011595335d271b1e083cf21b089a7ceca7eab Mon Sep 17 00:00:00 2001 From: neokry Date: Tue, 13 Feb 2024 15:32:40 -0800 Subject: [PATCH 1/2] Add referral system --- apps/web/src/data/contract/abis/Auction.ts | 170 ++++++++++++++++++ .../modules/auction/components/Auction.tsx | 2 +- .../CurrentAuction/CurrentAuction.tsx | 22 ++- .../components/CurrentAuction/PlaceBid.tsx | 35 +++- 4 files changed, 218 insertions(+), 11 deletions(-) diff --git a/apps/web/src/data/contract/abis/Auction.ts b/apps/web/src/data/contract/abis/Auction.ts index 9d22284e6..978aef1e7 100644 --- a/apps/web/src/data/contract/abis/Auction.ts +++ b/apps/web/src/data/contract/abis/Auction.ts @@ -6,11 +6,26 @@ export const auctionAbi = [ name: '_manager', type: 'address', }, + { + internalType: 'address', + name: '_rewardsManager', + type: 'address', + }, { internalType: 'address', name: '_weth', type: 'address', }, + { + internalType: 'uint16', + name: '_builderRewardsBPS', + type: 'uint16', + }, + { + internalType: 'uint16', + name: '_referralRewardsBPS', + type: 'uint16', + }, ], stateMutability: 'payable', type: 'constructor', @@ -50,6 +65,11 @@ export const auctionAbi = [ name: 'AUCTION_SETTLED', type: 'error', }, + { + inputs: [], + name: 'CANNOT_CREATE_AUCTION', + type: 'error', + }, { inputs: [], name: 'DELEGATE_CALL_FAILED', @@ -70,6 +90,21 @@ export const auctionAbi = [ name: 'INSOLVENT', type: 'error', }, + { + inputs: [], + name: 'INVALID_REWARDS_BPS', + type: 'error', + }, + { + inputs: [], + name: 'INVALID_REWARDS_RECIPIENT', + type: 'error', + }, + { + inputs: [], + name: 'INVALID_REWARD_TOTAL', + type: 'error', + }, { inputs: [], name: 'INVALID_TARGET', @@ -271,6 +306,31 @@ export const auctionAbi = [ name: 'DurationUpdated', type: 'event', }, + { + anonymous: false, + inputs: [ + { + components: [ + { + internalType: 'address', + name: 'recipient', + type: 'address', + }, + { + internalType: 'uint16', + name: 'percentBps', + type: 'uint16', + }, + ], + indexed: false, + internalType: 'struct AuctionTypesV2.FounderReward', + name: 'reward', + type: 'tuple', + }, + ], + name: 'FounderRewardUpdated', + type: 'event', + }, { anonymous: false, inputs: [ @@ -464,6 +524,19 @@ export const auctionAbi = [ stateMutability: 'view', type: 'function', }, + { + inputs: [], + name: 'builderRewardsBPS', + outputs: [ + { + internalType: 'uint16', + name: '', + type: 'uint16', + }, + ], + stateMutability: 'view', + type: 'function', + }, { inputs: [], name: 'cancelOwnershipTransfer', @@ -497,6 +570,37 @@ export const auctionAbi = [ stateMutability: 'payable', type: 'function', }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + { + internalType: 'address', + name: '_referral', + type: 'address', + }, + ], + name: 'createBidWithReferral', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [], + name: 'currentBidReferral', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, { inputs: [], name: 'duration', @@ -510,6 +614,24 @@ export const auctionAbi = [ stateMutability: 'view', type: 'function', }, + { + inputs: [], + name: 'founderReward', + outputs: [ + { + internalType: 'address', + name: 'recipient', + type: 'address', + }, + { + internalType: 'uint16', + name: 'percentBps', + type: 'uint16', + }, + ], + stateMutability: 'view', + type: 'function', + }, { inputs: [ { @@ -537,6 +659,16 @@ export const auctionAbi = [ name: '_reservePrice', type: 'uint256', }, + { + internalType: 'address', + name: '_founderRewardRecipient', + type: 'address', + }, + { + internalType: 'uint16', + name: '_founderRewardBps', + type: 'uint16', + }, ], name: 'initialize', outputs: [], @@ -615,6 +747,19 @@ export const auctionAbi = [ stateMutability: 'view', type: 'function', }, + { + inputs: [], + name: 'referralRewardsBPS', + outputs: [ + { + internalType: 'uint16', + name: '', + type: 'uint16', + }, + ], + stateMutability: 'view', + type: 'function', + }, { inputs: [], name: 'reservePrice', @@ -654,6 +799,31 @@ export const auctionAbi = [ stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + components: [ + { + internalType: 'address', + name: 'recipient', + type: 'address', + }, + { + internalType: 'uint16', + name: 'percentBps', + type: 'uint16', + }, + ], + internalType: 'struct AuctionTypesV2.FounderReward', + name: 'reward', + type: 'tuple', + }, + ], + name: 'setFounderReward', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { diff --git a/apps/web/src/modules/auction/components/Auction.tsx b/apps/web/src/modules/auction/components/Auction.tsx index e8c3bd87d..8f518fcbf 100644 --- a/apps/web/src/modules/auction/components/Auction.tsx +++ b/apps/web/src/modules/auction/components/Auction.tsx @@ -98,7 +98,7 @@ export const Auction: React.FC = ({ { + const { query } = useRouter() const [isEnded, setIsEnded] = useState(false) const [isEnding, setIsEnding] = useState(false) + const { data: auctionVersion } = useContractRead({ + abi: auctionAbi, + address: auctionAddress, + functionName: 'contractVersion', + }) + const isEndingTimeout = isEnded ? 4000 : null useTimeout(() => { @@ -50,6 +61,12 @@ export const CurrentAuction = ({ const isOver = !!endTime ? dayjs.unix(Date.now() / 1000) >= dayjs.unix(endTime) : true const formattedBid = bid ? ethers.utils.formatEther(bid) : '' + // Set the referral if auction version is != 1 and query.referral is present + const referral = + !auctionVersion?.startsWith('1') && query.referral + ? (query.referral as AddressType) + : undefined + if (isEnded || isOver) { return ( @@ -78,6 +95,7 @@ export const CurrentAuction = ({ chain={chain} tokenId={tokenId} highestBid={bid} + referral={referral} /> diff --git a/apps/web/src/modules/auction/components/CurrentAuction/PlaceBid.tsx b/apps/web/src/modules/auction/components/CurrentAuction/PlaceBid.tsx index 197d6898c..e15cde340 100644 --- a/apps/web/src/modules/auction/components/CurrentAuction/PlaceBid.tsx +++ b/apps/web/src/modules/auction/components/CurrentAuction/PlaceBid.tsx @@ -24,10 +24,17 @@ interface PlaceBidProps { chain: Chain tokenId: string daoName: string + referral?: AddressType highestBid?: bigint } -export const PlaceBid = ({ chain, highestBid, tokenId, daoName }: PlaceBidProps) => { +export const PlaceBid = ({ + chain, + highestBid, + referral, + tokenId, + daoName, +}: PlaceBidProps) => { const { address } = useAccount() const { chain: wagmiChain } = useNetwork() const { data: balance } = useBalance({ address: address, chainId: chain.id }) @@ -92,13 +99,25 @@ export const PlaceBid = ({ chain, highestBid, tokenId, daoName }: PlaceBidProps) try { setCreatingBid(true) - const config = await prepareWriteContract({ - abi: auctionAbi, - address: addresses.auction as Address, - functionName: 'createBid', - args: [BigInt(tokenId)], - value: parseEther(bidAmount), - }) + let config + if (referral) { + config = await prepareWriteContract({ + abi: auctionAbi, + address: addresses.auction as Address, + functionName: 'createBidWithReferral', + args: [BigInt(tokenId), referral], + value: parseEther(bidAmount), + }) + } else { + config = await prepareWriteContract({ + abi: auctionAbi, + address: addresses.auction as Address, + functionName: 'createBid', + args: [BigInt(tokenId)], + value: parseEther(bidAmount), + }) + } + const tx = await writeContract(config) if (tx?.hash) await waitForTransaction({ hash: tx.hash }) From ebe8da978ff4eb34d312f0a120e47063589fd0d4 Mon Sep 17 00:00:00 2001 From: neokry Date: Wed, 14 Feb 2024 09:50:16 -0800 Subject: [PATCH 2/2] Remove abi generation from post install --- apps/web/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/package.json b/apps/web/package.json index 02a15aa7b..d37e094d5 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -9,7 +9,6 @@ "start": "next start", "type-check": "tsc --pretty --noEmit", "lint": "pnpm type-check && next lint", - "postinstall": "pnpm run generate-abis", "test": "vitest run", "test:watch": "vitest", "codegen": "graphql-codegen",