Skip to content

Commit

Permalink
Merge pull request #41 from subsquid/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
belopash authored Jan 6, 2025
2 parents 9acbbbe + 5a3ccca commit aef4d5a
Show file tree
Hide file tree
Showing 12 changed files with 757 additions and 234 deletions.
2 changes: 1 addition & 1 deletion graphql.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
overwrite: true,
schema:
process.env.SQUID_API_URL ||
'https://subsquid.squids.live/subsquid-network-testnet/v/v5/graphql',
'https://subsquid.squids.live/subsquid-network-mainnet@v5/api/graphql',
documents: ['src/api/subsquid-network-squid/schema.graphql'],
hooks: {
afterOneFileWrite: ['prettier --write'],
Expand Down
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
571 changes: 342 additions & 229 deletions src/api/subsquid-network-squid/graphql.tsx

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/api/subsquid-network-squid/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ query sourcesWithAssets($address: String!) {
...WorkerBaseFragment
}
}

gatewayStakes(where: { amount_gt: 0 }) {
id
amount
}
}
}

Expand Down Expand Up @@ -193,7 +198,7 @@ query workerDelegationInfo($workerId: String!) {
trafficWeight
}

statistics(limit: 1) {
settings(limit: 1) {
utilizedStake
baseApr
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/subsquid-network-squid/workers-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function useWorkerDelegationInfo({
select: res => {
return {
worker: res.workerById,
info: res.statistics[0],
info: res.settings[0],
};
},
enabled,
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
9 changes: 7 additions & 2 deletions src/pages/AssetsPage/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { useContracts } from '@network/useContracts';
import { ColumnLabel, ColumnValue, SummarySection } from '@pages/DashboardPage/Summary';

import { ClaimButton } from './ClaimButton';
import {demoFeaturesEnabled} from '@hooks/demoFeaturesEnabled';

type TokenBalance = {
name: string;
Expand Down Expand Up @@ -171,7 +172,7 @@ export function MyAssets() {
value: BigNumber(0),
color: theme.palette.text.primary,
background: theme.palette.text.primary,
tip: '',
tip: 'Tokens locked in Portal stake',
};

sourcesQuery?.accounts.forEach(s => {
Expand All @@ -190,6 +191,10 @@ export function MyAssets() {
bonded.value = bonded.value.plus(w.bond);
claimable.value = claimable.value.plus(w.claimableReward);
});

s.gatewayStakes.forEach(gs => {
lockedPortal.value = bonded.value.plus(gs.amount);
});
});

return [transferable, vesting, claimable, bonded, delegated, lockedPortal];
Expand Down Expand Up @@ -281,7 +286,7 @@ export function MyAssets() {
<Stack divider={<Divider flexItem />} spacing={1} flex={1}>
<TokenBalance balance={balances[3]} />
<TokenBalance balance={balances[4]} />
{/* <TokenBalance balance={balances[5]} /> */}
{demoFeaturesEnabled() && <TokenBalance balance={balances[5]} />}
</Stack>
</Stack>
</Grid>
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>
);
}
82 changes: 82 additions & 0 deletions src/pages/BuyBackPage/BuyBackPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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="Buyback" 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>
This is the official Subsquid Labs buyback page. ⚠️Attention: Please only deposit the
contractually agreed amount of SQD Tokens. Deposited SQD cannot be refunded. For
questions, please reach out to [email protected]
</Typography>
</Alert>
<OtcContracts />
</ConnectedWalletRequired>
<Outlet />
</CenteredPageWrapper>
);
}
Loading

0 comments on commit aef4d5a

Please sign in to comment.