Skip to content

Commit

Permalink
Merge pull request #437 from ourzora/create-referral-system
Browse files Browse the repository at this point in the history
Add referral system
  • Loading branch information
neokry authored Feb 15, 2024
2 parents c00eda4 + ebe8da9 commit 9351723
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 12 deletions.
1 change: 0 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
170 changes: 170 additions & 0 deletions apps/web/src/data/contract/abis/Auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -50,6 +65,11 @@ export const auctionAbi = [
name: 'AUCTION_SETTLED',
type: 'error',
},
{
inputs: [],
name: 'CANNOT_CREATE_AUCTION',
type: 'error',
},
{
inputs: [],
name: 'DELEGATE_CALL_FAILED',
Expand All @@ -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',
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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: [
{
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/modules/auction/components/Auction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const Auction: React.FC<AuctionControllerProps> = ({
<CurrentAuction
chain={chain}
tokenId={queriedTokenId}
auctionAddress={auctionAddress}
auctionAddress={auctionAddress as AddressType}
daoName={token.dao.name}
bid={highestBid}
owner={highestBidder}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import dayjs from 'dayjs'
import { ethers } from 'ethers'
import { useRouter } from 'next/router'
import React, { Fragment, useState } from 'react'
import { useContractRead } from 'wagmi'

import { auctionAbi } from 'src/data/contract/abis'
import { AuctionBidFragment } from 'src/data/subgraph/sdk.generated'
import { useTimeout } from 'src/hooks/useTimeout'
import { Chain } from 'src/typings'
import { AddressType, Chain } from 'src/typings'

import { AuctionDetails } from '../AuctionDetails'
import { BidAmount } from '../BidAmount'
Expand All @@ -18,6 +21,7 @@ import { Settle } from './Settle'
export const CurrentAuction = ({
chain,
tokenId,
auctionAddress,
daoName,
bid,
owner,
Expand All @@ -26,16 +30,23 @@ export const CurrentAuction = ({
}: {
chain: Chain
tokenId: string
auctionAddress: string
auctionAddress: AddressType
daoName: string
bid?: bigint
owner?: string
endTime?: number
bids: AuctionBidFragment[]
}) => {
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(() => {
Expand All @@ -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 (
<Fragment>
Expand Down Expand Up @@ -78,6 +95,7 @@ export const CurrentAuction = ({
chain={chain}
tokenId={tokenId}
highestBid={bid}
referral={referral}
/>
</ActionsWrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })

Expand Down

0 comments on commit 9351723

Please sign in to comment.