Skip to content

Commit

Permalink
feat(NFT-reward): add support for fee overrides (#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomiOhl authored Dec 13, 2024
1 parent cab98a2 commit 7a90943
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const CollectNftButton = ({
})

const amount = useWatch<CollectNftForm>({ name: "amount" })
const { guildFee } = useGuildFee(chain)
const { guildFee } = useGuildFee(chain, nftAddress)
const { fee, isLoading: isNftDetailsLoading } = useNftDetails(chain, nftAddress)

const { isLoading: isNftBalanceLoading } = useGuildRewardNftBalanceByUserId({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const NftFeesTable = ({ ...rest }: StackProps) => {
})
const claimAmount = claimAmountFromForm ?? 1

const { guildFee } = useGuildFee(chain)
const { guildFee } = useGuildFee(chain, nftAddress)
const formattedGuildFee = guildFee
? Number(formatUnits(guildFee, CHAIN_CONFIG[chain].nativeCurrency.decimals)) *
claimAmount
Expand Down
2 changes: 1 addition & 1 deletion src/components/[guild]/collect/hooks/useCollectNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const useCollectNft = () => {
useCollectNftContext()
const { setTxHash, setTxError, setTxSuccess } = useTransactionStatusContext() ?? {}

const { guildFee } = useGuildFee(chain)
const { guildFee } = useGuildFee(chain, nftAddress)
const { fee, name, refetch: refetchNftDetails } = useNftDetails(chain, nftAddress)

const { refetch: refetchBalance } = useGuildRewardNftBalanceByUserId({
Expand Down
21 changes: 19 additions & 2 deletions src/components/[guild]/collect/hooks/useGuildFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@ import guildRewardNFTFactoryAbi from "static/abis/guildRewardNFTFactory"
import { useReadContract } from "wagmi"
import { Chain, Chains } from "wagmiConfig/chains"

// TODO: remove this once we deploy the contracts on all chains
const chainsWithOverrides = [
"BASE_MAINNET",
"BSC",
"ARBITRUM",
"OPTIMISM",
"POLYGON",
]

const useGuildFee = (
chain: Chain
chain: Chain,
contractAddress?: `0x${string}`
): { guildFee: bigint; isLoading: boolean; error: any } => {
const {
data: guildFee,
Expand All @@ -14,7 +24,14 @@ const useGuildFee = (
abi: guildRewardNFTFactoryAbi,
chainId: Chains[chain],
address: GUILD_REWARD_NFT_FACTORY_ADDRESSES[chain],
functionName: "fee",
functionName:
contractAddress && chainsWithOverrides.includes(chain)
? "getFeeWithOverrides"
: "fee",
args:
contractAddress && chainsWithOverrides.includes(chain)
? [contractAddress]
: [],
})

return {
Expand Down
36 changes: 36 additions & 0 deletions src/static/abis/guildRewardNFTFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ const guildRewardNFTFacotryAbi = [
name: "FeeChanged",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "tokenAddress",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "newFee",
type: "uint256",
},
],
name: "FeeOverrideChanged",
type: "event",
},
{
anonymous: false,
inputs: [
Expand Down Expand Up @@ -204,6 +223,13 @@ const guildRewardNFTFacotryAbi = [
stateMutability: "view",
type: "function",
},
{
inputs: [{ internalType: "address", name: "tokenAddress", type: "address" }],
name: "getFeeWithOverrides",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address payable", name: "treasuryAddress", type: "address" },
Expand Down Expand Up @@ -256,6 +282,16 @@ const guildRewardNFTFacotryAbi = [
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "tokenAddress", type: "address" },
{ internalType: "uint256", name: "newFee", type: "uint256" },
],
name: "setFeeOverride",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
Expand Down

0 comments on commit 7a90943

Please sign in to comment.