Skip to content

Commit

Permalink
feat(BAPP-790): Devcon discount validator (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieraykatz authored Nov 12, 2024
1 parent 99b491e commit 7f031de
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apps/web/src/addresses/usernames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ export const BASE_WORLD_DISCOUNT_VALIDATORS: AddressMap = {
[baseSepolia.id]: '0xFa69f6167F40247fe3EFF2d8375B25C5d7834c48',
[base.id]: '0xfEb00a4EfF372a307fDc556Cf4359f7D679E4d11',
};

export const DEVCON_DISCOUNT_VALIDATORS: AddressMap = {
[baseSepolia.id]: '0x5c81c392C22Cba477a70D809DE6d6Cd362A1c3DE',
[base.id]: '0xFca2EB54EaB56085e25a32BfF30fe8C452216c5F',
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import summerPassLvl3 from './images/summer-pass-lvl-3.svg';
import cbidVerification from './images/cbid-verification.svg';
import BNSOwnership from './images/bns.jpg';
import BaseNFT from './images/base-nft.svg';
import DevconPNG from './images/devcon.png';
import TalentProtocolIcon from './images/TalentProtocol.svg';
import coinbaseOneVerification from './images/coinbase-one-verification.svg';
import coinbaseVerification from './images/coinbase-verification.svg';
Expand Down Expand Up @@ -95,6 +96,13 @@ const DISCOUNT_ITEMS: DiscountItem[] = [
label: 'Base around the world NFT',
tooltipContent: 'Available for anyone holding one of the Base around the world NFTs',
},
{
discount: Discount.DEVCON,
icon: DevconPNG,
alt: 'icon of Devcon',
label: 'Devcon attendance NFT',
tooltipContent: 'Available for anyone holding one of the Base Devcon NFTs',
},
];

export default function RegistrationLearnMoreModal({
Expand Down
13 changes: 12 additions & 1 deletion apps/web/src/hooks/useAggregatedDiscountValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useCheckCBIDAttestations,
useCheckCoinbaseAttestations,
useCheckEAAttestations,
useDevconAttestations,
useDiscountCodeAttestations,
useSummerPassAttestations,
useTalentProtocolAttestations,
Expand Down Expand Up @@ -58,6 +59,7 @@ export function useAggregatedDiscountValidators(code?: string) {
const { data: TalentProtocolData, loading: loadingTalentProtocolAttestations } =
useTalentProtocolAttestations();
const { data: BaseWorldData, loading: loadingBaseWorld } = useBaseWorldAttestations();
const { data: DevconData, loading: loadingDevcon } = useDevconAttestations();

const loadingDiscounts =
loadingCoinbaseAttestations ||
Expand All @@ -71,7 +73,8 @@ export function useAggregatedDiscountValidators(code?: string) {
loadingBNS ||
loadingDiscountCode ||
loadingTalentProtocolAttestations ||
loadingBaseWorld;
loadingBaseWorld ||
loadingDevcon;

const discountsToAttestationData = useMemo<MappedDiscountData>(() => {
const discountMapping: MappedDiscountData = {};
Expand Down Expand Up @@ -153,6 +156,13 @@ export function useAggregatedDiscountValidators(code?: string) {
discountKey: validator.key,
};
}

if (DevconData && validator.discountValidator === DevconData.discountValidatorAddress) {
discountMapping[Discount.DEVCON] = {
...DevconData,
discountKey: validator.key,
};
}
});

return discountMapping;
Expand All @@ -169,6 +179,7 @@ export function useAggregatedDiscountValidators(code?: string) {
DiscountCodeData,
TalentProtocolData,
BaseWorldData,
DevconData,
]);

return {
Expand Down
37 changes: 37 additions & 0 deletions apps/web/src/hooks/useAttestations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
BASE_DOT_ETH_ERC721_DISCOUNT_VALIDATOR,
BASE_WORLD_DISCOUNT_VALIDATORS,
BUILDATHON_ERC721_DISCOUNT_VALIDATOR,
DEVCON_DISCOUNT_VALIDATORS,
TALENT_PROTOCOL_DISCOUNT_VALIDATORS,
USERNAME_1155_DISCOUNT_VALIDATORS,
} from 'apps/web/src/addresses/usernames';
Expand Down Expand Up @@ -638,3 +639,39 @@ export function useBaseWorldAttestations() {

return { data: null, loading: isLoading, error };
}

const devconTokenIds = [BigInt(100), BigInt(101)];

export function useDevconAttestations() {
const { address } = useAccount();
const { basenameChain } = useBasenameChain();

const discountValidatorAddress = DEVCON_DISCOUNT_VALIDATORS[basenameChain.id];

const readContractArgs = useMemo(() => {
if (!address) {
return {};
}
return {
address: discountValidatorAddress,
abi: ERC1155DiscountValidatorV2,
functionName: 'isValidDiscountRegistration',
args: [address, encodeAbiParameters([{ type: 'uint256[]' }], [devconTokenIds])],
};
}, [address, discountValidatorAddress]);

const { data: isValid, isLoading, error } = useReadContract({ ...readContractArgs, query: {} });
if (isValid && address) {
return {
data: {
discountValidatorAddress,
discount: Discount.DEVCON,
validationData: encodeAbiParameters([{ type: 'uint256[]' }], [devconTokenIds]),
},
loading: false,
error: null,
};
}

return { data: null, loading: isLoading, error };
}
1 change: 1 addition & 0 deletions apps/web/src/utils/usernames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export enum Discount {
DISCOUNT_CODE = 'DISCOUNT_CODE',
TALENT_PROTOCOL = 'TALENT_PROTOCOL',
BASE_WORLD = 'BASE_WORLD',
DEVCON = 'DEVCON',
}

export function isValidDiscount(key: string): key is keyof typeof Discount {
Expand Down

0 comments on commit 7f031de

Please sign in to comment.