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

Add SRC20 deployment functionality from the airdrop itself #24

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7086443
migrate smart contract
naz3eh Sep 18, 2024
12ca222
add hooks
naz3eh Sep 18, 2024
75b7465
Update .env.example
naz3eh Sep 18, 2024
6833a97
implement `/airdrop` route & add `useGetAirdropDaa` hook
naz3eh Sep 18, 2024
cae5fa7
Add `/create` route
naz3eh Sep 18, 2024
b830dac
Add `/claim` route
naz3eh Sep 18, 2024
e9f9586
fixed routing and move toolchain file to the root
naz3eh Sep 19, 2024
d750be4
add rust tests
naz3eh Sep 19, 2024
19e7ba1
fix test errors
naz3eh Sep 19, 2024
bf9a26b
add TS test
naz3eh Sep 19, 2024
2d7a3d5
Add airdrop env variables in `preview.yml`
naz3eh Sep 24, 2024
2306c2f
Merge branch 'master' into airdrop-v2
naz3eh Sep 24, 2024
444286d
fix build errors
naz3eh Sep 24, 2024
5289063
update lock file
naz3eh Sep 24, 2024
0ebe729
migrate project to vite
naz3eh Sep 24, 2024
603bfd4
update workflow and add `build-all` script
naz3eh Sep 24, 2024
1384f34
Merge branch 'airdrop-v2' of https://github.com/FuelLabs/sway-example…
naz3eh Sep 24, 2024
d952d51
Update create.lazy.tsx
naz3eh Sep 24, 2024
db8d674
Update pnpm-lock.yaml
naz3eh Sep 24, 2024
42da72b
fix build errors
naz3eh Sep 24, 2024
34d085b
remove sway-api from git-ignore
naz3eh Sep 24, 2024
66bf336
Update vite.config.ts
naz3eh Sep 24, 2024
d84aa27
chore: Commons bump (#19)
calldelegation Sep 25, 2024
97486b5
update routes
naz3eh Sep 25, 2024
e86552a
Merge branch 'airdrop-v2' of https://github.com/FuelLabs/sway-example…
naz3eh Sep 25, 2024
97dc5c2
fix build
naz3eh Sep 25, 2024
7b09cef
initialize configurables while deploying
naz3eh Sep 26, 2024
f027583
pass all the values of the configurables
naz3eh Sep 27, 2024
adbed92
add shadcn
naz3eh Oct 22, 2024
1ded1dc
change all the components to shadcn
naz3eh Oct 22, 2024
3dcafa2
update rust package
naz3eh Oct 22, 2024
291354d
update forc.toml
naz3eh Oct 22, 2024
2f0b074
fix vitest config
naz3eh Oct 23, 2024
04a9481
add coverage
naz3eh Oct 23, 2024
39f4d53
add initialise functionality
naz3eh Oct 23, 2024
792e983
show onwer
naz3eh Oct 23, 2024
f5cc424
Add setPause
naz3eh Oct 24, 2024
09bde35
fix invalid endDate format
naz3eh Oct 24, 2024
8cdc717
fix end date format
naz3eh Oct 24, 2024
8433776
fix number of leaves issue
naz3eh Oct 24, 2024
da25bac
init'
matt-user Oct 24, 2024
5fcb094
log `root` and `tree` while claiming
naz3eh Oct 25, 2024
4961c17
update `getLeafData` function
naz3eh Oct 25, 2024
d4df918
update homepage
naz3eh Oct 28, 2024
bc8b744
add `isInitialized` method
naz3eh Oct 28, 2024
922537e
update `createMerkleTree` function
naz3eh Oct 29, 2024
b1972f3
update `strigifyObj` function
naz3eh Oct 29, 2024
37a2661
fix merkle proof verification
naz3eh Oct 29, 2024
483415d
fix build errors
naz3eh Oct 29, 2024
9247fd6
Update vite.config.ts
naz3eh Oct 29, 2024
906d80b
Update pnpm-lock.yaml
naz3eh Oct 29, 2024
3ff7cb0
update `@mui/material` version
naz3eh Oct 29, 2024
d8d6c58
add base url to tanstack query
naz3eh Oct 29, 2024
b621f52
Update lib.ts
naz3eh Oct 29, 2024
eb75fd1
truncate addresses
naz3eh Oct 29, 2024
745364a
greyed out ineligible airdrops
naz3eh Nov 19, 2024
2f0c9dc
Add new navbar
naz3eh Nov 20, 2024
fb002c7
Add loading indicators
naz3eh Nov 21, 2024
6d9548e
truncate addresses and initialise airdrop after the contract creation
naz3eh Nov 21, 2024
ff4cd5c
truncate all the addresses
naz3eh Nov 21, 2024
ce52253
fix build errors
naz3eh Nov 22, 2024
388c6c0
add ts-expect-error for the wagmiConfig type issue
naz3eh Nov 22, 2024
940991c
comment `AppProvider`
naz3eh Nov 22, 2024
37b8d2c
fix faucet route
naz3eh Nov 22, 2024
0aa067c
use shadcn button
naz3eh Nov 22, 2024
fe79293
Update create.lazy.tsx
naz3eh Nov 22, 2024
108d35d
Fix initialize flow
naz3eh Nov 27, 2024
02f47b0
implement src20 contract deployment
naz3eh Nov 27, 2024
e171645
add configurable constants
naz3eh Nov 27, 2024
b616ea7
Fix undefined values
naz3eh Nov 27, 2024
78fa57c
Merge branch 'master' into src20-airdrop
naz3eh Dec 11, 2024
49466d7
merge `master`
naz3eh Dec 11, 2024
7c61d31
Add Src20 deployment
naz3eh Dec 12, 2024
63eb8ce
implement src20 token initialisation and minting
naz3eh Dec 12, 2024
fe29a2c
enhance styling
naz3eh Dec 12, 2024
07364e0
store tokenId of the deployed src20 in queryparams and use it at crea…
naz3eh Dec 13, 2024
921dc14
maintain fuel theme
naz3eh Dec 13, 2024
9782507
fix build
naz3eh Dec 16, 2024
99af8de
Add theme
naz3eh Dec 17, 2024
f5014c9
Fix color
naz3eh Dec 17, 2024
25ba543
remove `userBurnerWallet` and `useBrowserWallet` hook
naz3eh Dec 17, 2024
199745b
fix button text colors
naz3eh Dec 17, 2024
34c7c6b
cleanup
naz3eh Dec 18, 2024
b6212fd
Update useClaimAirdrop.ts
naz3eh Dec 18, 2024
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
2 changes: 1 addition & 1 deletion airdrop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@fuel-ts/merkle": "^0.96.1",
"@fuel-ts/merkle": "^0.97.0",
"@fuels/connectors": "^0.36.0",
"@fuels/react": "^0.36.0",
"@mui/material": "^5.16.5",
Expand Down
2 changes: 1 addition & 1 deletion airdrop/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const Layout = ({ children }: { children: React.ReactNode }) => {
return (
<div className="w-full">
<Toaster />
<div className="flex flex-col w-['100vw'] bg-black text-white">
<div className="flex flex-col w-['100vw'] bg-background text-foreground">
<NavMenu />
<div className="min-h-screen items-center p-24 flex flex-col gap-6">
{children}
Expand Down
15 changes: 12 additions & 3 deletions airdrop/src/components/NavMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Link } from "./Link";
import { WalletDisplay } from "./WalletDisplay";
import { useTheme } from "./theme-provider";
import { Button } from "./ui/button";
import { ModeToggle } from "./mode-toggle";

export const NavMenu = () => {
const { isMobile } = useBreakpoints();
Expand Down Expand Up @@ -62,7 +63,8 @@ export const NavMenu = () => {

{!isMobile && (
<Button
className="bg-gray-500"
variant="outline"
className="hover:bg-secondary/80"
onClick={() => {
if (!isConnected)
return toast.error(
Expand Down Expand Up @@ -92,13 +94,20 @@ export const NavMenu = () => {
</Button>
)}
{isConnected && !isMobile && (
<Button className="bg-red-600" onClick={() => disconnect()}>
<Button
variant="destructive"
className="hover:bg-destructive/90 hover:dark:text-white"
onClick={() => disconnect()}
>
Disconnect
</Button>
)}
{!isConnected && !isMobile && (
<Button onClick={connect}>Connect Wallet</Button>
<Button variant="outline" onClick={connect}>
Connect Wallet
</Button>
)}
<ModeToggle />
</nav>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion airdrop/src/components/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type TextProps = TypographyProps;

export const Text = ({ children, className, ...props }: TextProps) => {
return (
<Typography {...props} className={`text-white font-sans ${className}`}>
<Typography {...props} className={`text-foreground font-sans ${className}`}>
{children}
</Typography>
);
Expand Down
36 changes: 36 additions & 0 deletions airdrop/src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
)
}

export { Badge, badgeVariants }
2 changes: 1 addition & 1 deletion airdrop/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const buttonVariants = cva(
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
"bg-secondary text-secondary-foreground hover:bg-secondary/80 dark:hover:text-white",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
Expand Down
79 changes: 79 additions & 0 deletions airdrop/src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as React from "react"

import { cn } from "@/lib/utils"

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
className
)}
{...props}
/>
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
5 changes: 4 additions & 1 deletion airdrop/src/components/ui/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
interface DatePickerProps {
className?: string;
onChangeHandler?: (date: Date | undefined) => void;
disabled?: boolean;
}

export function DatePicker({ className, onChangeHandler }: DatePickerProps) {
export function DatePicker({ className, onChangeHandler, disabled }: DatePickerProps) {
const [date, setDate] = React.useState<Date>();

const handleDateChange = (selectedDate: Date | undefined) => {
Expand All @@ -36,6 +37,7 @@ export function DatePicker({ className, onChangeHandler }: DatePickerProps) {
!date && "text-muted-foreground",
className
)}
disabled={disabled}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{date ? format(date, "PPP") : <span>Pick a date</span>}
Expand All @@ -47,6 +49,7 @@ export function DatePicker({ className, onChangeHandler }: DatePickerProps) {
selected={date}
onSelect={handleDateChange}
initialFocus
disabled={disabled}
/>
</PopoverContent>
</Popover>
Expand Down
27 changes: 2 additions & 25 deletions airdrop/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from "react";

import { cn } from "@/lib/utils";

export interface InputProps
Expand All @@ -11,9 +10,8 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<input
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className,
inputStyle
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
Expand All @@ -24,24 +22,3 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
Input.displayName = "Input";

export { Input };

import clsx from "clsx";

export const inputStyle = [
"mt-1",
"shrink",
"basis-2/3",
"rounded-lg",
"border-2",
"border-solid",
"border-zinc-500/25",
"p-1",
"font-sans",
"outline-none",
"md:-ml-2",
"md:mt-2",
"md:p-2",
"bg-transparent",
"placeholder:text-zinc-400",
"text-white",
];
34 changes: 34 additions & 0 deletions airdrop/src/hooks/src20Hooks/useDeploySrc20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Src20Factory } from "@/sway-api";
import { useWallet } from "@fuels/react";
import { useMutation } from "@tanstack/react-query";
import { DeployContractOptions } from "fuels";
import toast from "react-hot-toast";

export type Src20Args = {
options?: DeployContractOptions;
};
export const useDeploySrc20 = () => {
const { wallet } = useWallet();
const mutation = useMutation({
mutationFn: async (args: Src20Args) => {
if (!wallet) {
throw new Error("Wallet not connected!");
}

const { options } = args;
const result = await Src20Factory.deploy(wallet, options);
const { contract, transactionResult } = await result.waitForResult();

return { contract, transactionResult };
},
onSuccess: () => {
toast.success(`SRC20 Contract deployed successfully!`);
},
onError: (err) => {
console.error("Error deploying contract:", err);
toast.error(err.message);
},
});

return mutation;
};
16 changes: 16 additions & 0 deletions airdrop/src/hooks/src20Hooks/useGetSrc20Balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AirdropQueryKeys } from "@/queryKeys";
import { useWallet } from "@fuels/react";
import { useQuery } from "@tanstack/react-query";

export const useGetSrc20Balance = (assetId: string) => {
const { wallet } = useWallet();
const query = useQuery({
queryKey: [AirdropQueryKeys.src20Balance],
queryFn: async () => {
if (!wallet || !assetId || assetId.trim() === "") return;
const balance = await wallet.getBalance(assetId);
return balance;
},
});
return query;
};
37 changes: 37 additions & 0 deletions airdrop/src/hooks/src20Hooks/useInitializeOwner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Src20 } from "@/sway-api";
import { useWallet } from "@fuels/react";
import { useMutation } from "@tanstack/react-query";
import { bn } from "fuels";
import toast from "react-hot-toast";

export type InitializeOwnerArgs = {
contractId: string;
};

export const useInitializeOwner = () => {
const { wallet } = useWallet();
const mutation = useMutation({
mutationFn: async (args: InitializeOwnerArgs) => {
if (!wallet) {
throw new Error("Wallet not connected!");
}

const owner = { Address: { bits: wallet.address.toB256() } };

const contract = new Src20(args.contractId, wallet);

const result = await contract.functions.constructor(owner).call();
const transactionResult = await result.waitForResult();
return transactionResult;
},
onSuccess: () => {
toast.success("Owner initialized successfully!");
},
onError: (err) => {
console.error("Error initializing owner:", err);
toast.error(err.message);
},
});

return mutation;
};
44 changes: 44 additions & 0 deletions airdrop/src/hooks/src20Hooks/useMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Src20 } from "@/sway-api";
import { useWallet } from "@fuels/react";
import { useMutation } from "@tanstack/react-query";
import { bn } from "fuels";
import toast from "react-hot-toast";

export type Src20MintArgs = {
amount: number;
contractId: string;
subId: string;
};

export const useMint = () => {
const { wallet } = useWallet();
const mutation = useMutation({
mutationFn: async (args: Src20MintArgs) => {
if (!wallet) {
throw new Error("Wallet not connected!");
}

const { amount, contractId, subId } = args;

const recipient = { Address: { bits: wallet.address.toB256() } };

const contract = new Src20(contractId, wallet);

// Passing DEFAULT_SUB_ID as its a single asset contract
const result = await contract.functions
.mint(recipient, subId, bn(amount))
.call();
const transactionResult = await result.waitForResult();
return transactionResult;
},
onSuccess: () => {
toast.success("Successfully minted Src20!");
},
onError: (err) => {
console.error("Error minting Src20:", err);
toast.error(err.message);
},
});

return mutation;
};
Loading
Loading