Skip to content

Commit

Permalink
feat: add BuyBack contracts page
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Dec 25, 2024
1 parent fa68cb4 commit b2d3a21
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Navigate, Route, Routes } from 'react-router-dom';
import { NetworkLayout } from '@layouts/NetworkLayout';
import { AssetsPage } from '@pages/AssetsPage/AssetsPage.tsx';
import { Vesting } from '@pages/AssetsPage/Vesting.tsx';
import { BuyBacksPage } from '@pages/BuyBackPage/BuyBackPage.tsx';
import { DashboardPage } from '@pages/DashboardPage/DashboardPage.tsx';
import { DelegationsPage } from '@pages/DelegationsPage/DelegationsPage.tsx';
import { Gateway } from '@pages/GatewaysPage/Gateway.tsx';
Expand Down Expand Up @@ -43,6 +44,9 @@ export const AppRoutes = () => {
<Route element={<Gateway backPath="/portals" />} path=":peerId" />
</Route>
<Route path="/gateways" element={<Navigate to="/portals" replace={true} />} />
<Route path="/buyback">
<Route element={<BuyBacksPage />} index />
</Route>
<Route element={<Navigate to="/dashboard" replace={true} />} path="*" />
</Route>
</Routes>
Expand Down
72 changes: 72 additions & 0 deletions src/api/contracts/subsquid.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ export const arbMulticallAbi = [
},
] as const

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BuyBack
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

export const buyBackAbi = [
{
type: 'function',
inputs: [{ name: 'amount', internalType: 'uint256', type: 'uint256' }],
name: 'deposit',
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
inputs: [
{ name: 'receiver', internalType: 'address', type: 'address' },
{ name: 'amount', internalType: 'uint256', type: 'uint256' },
],
name: 'withdraw',
outputs: [],
stateMutability: 'nonpayable',
},
] as const

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GatewayRegistry
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -664,6 +688,54 @@ export const useReadArbMulticallGetL1BlockNumber =
functionName: 'getL1BlockNumber',
})

/**
* Wraps __{@link useWriteContract}__ with `abi` set to __{@link buyBackAbi}__
*/
export const useWriteBuyBack = /*#__PURE__*/ createUseWriteContract({
abi: buyBackAbi,
})

/**
* Wraps __{@link useWriteContract}__ with `abi` set to __{@link buyBackAbi}__ and `functionName` set to `"deposit"`
*/
export const useWriteBuyBackDeposit = /*#__PURE__*/ createUseWriteContract({
abi: buyBackAbi,
functionName: 'deposit',
})

/**
* Wraps __{@link useWriteContract}__ with `abi` set to __{@link buyBackAbi}__ and `functionName` set to `"withdraw"`
*/
export const useWriteBuyBackWithdraw = /*#__PURE__*/ createUseWriteContract({
abi: buyBackAbi,
functionName: 'withdraw',
})

/**
* Wraps __{@link useSimulateContract}__ with `abi` set to __{@link buyBackAbi}__
*/
export const useSimulateBuyBack = /*#__PURE__*/ createUseSimulateContract({
abi: buyBackAbi,
})

/**
* Wraps __{@link useSimulateContract}__ with `abi` set to __{@link buyBackAbi}__ and `functionName` set to `"deposit"`
*/
export const useSimulateBuyBackDeposit =
/*#__PURE__*/ createUseSimulateContract({
abi: buyBackAbi,
functionName: 'deposit',
})

/**
* Wraps __{@link useSimulateContract}__ with `abi` set to __{@link buyBackAbi}__ and `functionName` set to `"withdraw"`
*/
export const useSimulateBuyBackWithdraw =
/*#__PURE__*/ createUseSimulateContract({
abi: buyBackAbi,
functionName: 'withdraw',
})

/**
* Wraps __{@link useReadContract}__ with `abi` set to __{@link gatewayRegistryAbi}__
*/
Expand Down
3 changes: 3 additions & 0 deletions src/network/useContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function useContracts(): {
SQD_TOKEN: string;
CHAIN_ID_L1: number;
MULTICALL: `0x${string}`;
BUYBACK: `0x${string}`;
} {
const network = getSubsquidNetwork();

Expand All @@ -31,6 +32,7 @@ export function useContracts(): {
ROUTER: '0xD2093610c5d27c201CD47bCF1Df4071610114b64',
CHAIN_ID_L1: sepolia.id,
MULTICALL: '0x7eCfBaa8742fDf5756DAC92fbc8b90a19b8815bF',
BUYBACK: '0xe34189ad45044e93d3af7d93ac520d02651faf72',
};
}
case NetworkName.Mainnet: {
Expand All @@ -46,6 +48,7 @@ export function useContracts(): {
ROUTER: '0x67F56D27dab93eEb07f6372274aCa277F49dA941',
CHAIN_ID_L1: mainnet.id,
MULTICALL: '0x7eCfBaa8742fDf5756DAC92fbc8b90a19b8815bF',
BUYBACK: '0x4efab28e320ef16907930a06e2a5aaadb7425b48',
};
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/pages/BuyBackPage/BuyBackName.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { addressFormatter } from '@lib/formatters/formatters';
import { Box, Stack, styled, Typography } from '@mui/material';

import { Avatar } from '@components/Avatar';
import { CopyToClipboard } from '@components/CopyToClipboard';

const Name = styled(Box, {
name: 'Name',
})(({ theme }) => ({
marginBottom: theme.spacing(0.25),
whiteSpace: 'nowrap',
}));

export function SourceWalletName({ source }: { source: { id: string } }) {
return (
<Stack direction="row" spacing={2} alignItems="center">
<Avatar name={source.id.slice(2)} colorDiscriminator={source.id} />
<Box>
<Name>Contract</Name>
<Typography variant="caption">
<CopyToClipboard text={source.id} content={addressFormatter(source.id, true)} />
</Typography>
</Box>
</Stack>
);
}
81 changes: 81 additions & 0 deletions src/pages/BuyBackPage/BuyBackPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Warning } from '@mui/icons-material';
import { Alert, Box, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material';
import { Outlet } from 'react-router-dom';

import { useSourcesQuery, useSquid } from '@api/subsquid-network-squid';
import SquaredChip from '@components/Chip/SquaredChip';
import { DashboardTable, NoItems } from '@components/Table';
import { CenteredPageWrapper } from '@layouts/NetworkLayout';
import { ConnectedWalletRequired } from '@network/ConnectedWalletRequired';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts';

import { SourceWalletName } from './BuyBackName';
import { DepositButton } from './DepositButton';

export function OtcContracts() {
const account = useAccount();
const squid = useSquid();

const { data: sourcesQuery, isLoading: isSourcesQueryLoading } = useSourcesQuery(squid, {
address: account.address as `0x${string}`,
});
const { BUYBACK } = useContracts();

const BUYBACKs = [BUYBACK];
const sources = sourcesQuery?.accounts;

const isLoading = isSourcesQueryLoading;

return (
<DashboardTable loading={isLoading} title={<SquaredChip label="Buy Back" color="primary" />}>
<TableHead>
<TableRow>
<TableCell>Contract</TableCell>
<TableCell></TableCell>
</TableRow>
</TableHead>
<TableBody>
{BUYBACKs.length ? (
<>
{BUYBACKs.map(address => {
return (
<TableRow key={address}>
<TableCell>
<SourceWalletName source={{ id: address }} />
</TableCell>
<TableCell>
<Box display="flex" justifyContent="flex-end">
<DepositButton address={address} sources={sources} />
</Box>
</TableCell>
</TableRow>
);
})}
</>
) : (
<NoItems>
<span>No vesting was found</span>
</NoItems>
)}
</TableBody>
</DashboardTable>
);
}

export function BuyBacksPage() {
return (
<CenteredPageWrapper className="wide">
<ConnectedWalletRequired>
<Alert sx={{ mb: 2 }} color="warning" icon={<Warning color="warning" />}>
<Typography>
Please do not deposit tokens until you know what you are doing. It will not be possible
to return them back!
</Typography>
</Alert>
<OtcContracts />
</ConnectedWalletRequired>
<Outlet />
</CenteredPageWrapper>
);
}
Loading

0 comments on commit b2d3a21

Please sign in to comment.