Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NFT-reward): add support for fee overrides #1583

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading