Skip to content

Commit

Permalink
Token minimum deposit + versions on protocol page (#192)
Browse files Browse the repository at this point in the history
* Token minimum deposit
* protocol version in protocol page

---------

Co-authored-by: 0xdavinchee <0xdavinchee@gmail.com>
  • Loading branch information
Mikkoun and 0xdavinchee committed Oct 6, 2023
1 parent e2ff7b6 commit f46fa37
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 7 deletions.
38 changes: 38 additions & 0 deletions src/pages/[_network]/protocol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
List,
ListItem,
ListItemText,
Skeleton,
Stack,
Tooltip,
Typography,
Expand All @@ -23,6 +24,8 @@ import NetworkTabs from "../../components/NetworkTabs";
import { useNetworkContext } from "../../contexts/NetworkContext";
import { Network, networks } from "../../redux/networks";
import protocolContracts from "../../redux/protocolContracts";
import { rpcApi } from "../../redux/store";
import { pseudoAddressToVersionString } from "../../utils/versionUtils";

interface AddressListItemProps {
title: string;
Expand Down Expand Up @@ -76,6 +79,10 @@ const Protocol: NextPage = () => {
const network = useNetworkContext();
const router = useRouter();

const protocolVersionResponse = rpcApi.useProtocolVersionQuery({
chainId: network.chainId,
});

const onTabChange = (newValue: string) =>
router.replace({
query: {
Expand Down Expand Up @@ -299,6 +306,37 @@ const Protocol: NextPage = () => {
/>
</List>
</Card>
<Typography
variant="h5"
component="h2"
sx={{
px: 2,
mt: 4,
mb: 2,
}}
>
Versions
</Typography>
<Card>
<CardContent>
<ListItemText
data-cy={"protocol-contracts"}
primary="Protocol Contracts"
secondary={
<>
{protocolVersionResponse.data ? (
pseudoAddressToVersionString(
protocolVersionResponse.data
)
) : (
<Skeleton sx={{ width: "200px" }} />
)}
<InfoTooltipBtn title="The version format is {major}.{minor}.{patch}-{gitRevision}." />
</>
}
/>
</CardContent>
</Card>
</TabPanel>
))}
</TabContext>
Expand Down
24 changes: 21 additions & 3 deletions src/pages/[_network]/supertokens/[_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ import EventList from "../../../components/EventList";
import FlowingBalance from "../../../components/FlowingBalance";
import InfoTooltipBtn from "../../../components/InfoTooltipBtn";
import NetworkDisplay from "../../../components/NetworkDisplay";
import SkeletonAddress from "../../../components/skeletons/SkeletonAddress";
import SkeletonTokenName from "../../../components/skeletons/SkeletonTokenName";
import SubgraphQueryLink from "../../../components/SubgraphQueryLink";
import SuperTokenIndexes from "../../../components/SuperTokenIndexes";
import SuperTokenStreams from "../../../components/SuperTokenStreams";
import SkeletonAddress from "../../../components/skeletons/SkeletonAddress";
import SkeletonTokenName from "../../../components/skeletons/SkeletonTokenName";
import IdContext from "../../../contexts/IdContext";
import { useNetworkContext } from "../../../contexts/NetworkContext";
import { useAppSelector } from "../../../redux/hooks";
import { streamGranularityInSeconds } from "../../../redux/slices/appPreferences.slice";
import { sfSubgraph } from "../../../redux/store";
import { rpcApi, sfSubgraph } from "../../../redux/store";

const SuperTokenPage: NextPage = () => {
const network = useNetworkContext();
Expand All @@ -53,6 +53,11 @@ const SuperTokenPage: NextPage = () => {

const superToken: Token | null | undefined = tokenQuery.data;

const minimumDepositQuery = rpcApi.useMinimumDepositQuery({
chainId: network.chainId,
tokenAddress: address,
});

const tokenStatisticsQuery = sfSubgraph.useTokenStatisticQuery({
chainId: network.chainId,
id: address,
Expand Down Expand Up @@ -483,6 +488,19 @@ const SuperTokenPage: NextPage = () => {
}
/>
</ListItem>

<ListItem>
<ListItemText
secondary="Minimum deposit"
primary={
minimumDepositQuery.data ? (
<EtherFormatted wei={minimumDepositQuery.data} />
) : (
<Skeleton sx={{ width: "200px" }} />
)
}
/>
</ListItem>
</List>
</Card>

Expand Down
52 changes: 52 additions & 0 deletions src/redux/adhocRpcEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Address } from "@superfluid-finance/sdk-core";
import {
RpcEndpointBuilder,
getFramework,
} from "@superfluid-finance/sdk-redux";

export const adhocRpcEndpoints = {
endpoints: (builder: RpcEndpointBuilder) => ({
minimumDeposit: builder.query<
string,
{ tokenAddress: Address; chainId: number }
>({
queryFn: async ({ tokenAddress, chainId }) => {
const framework = await getFramework(chainId);

const minimumDeposit = await framework.governance.getMinimumDeposit({
token: tokenAddress,
providerOrSigner: framework.settings.provider,
});

return {
data: minimumDeposit,
};
},
providesTags: (_result, _error, arg) => [
{
type: "GENERAL",
id: arg.chainId, // TODO(KK): Could be made more specific.
},
],
}),
protocolVersion: builder.query<string, { chainId: number }>({
queryFn: async ({ chainId }) => {
const framework = await getFramework(chainId);

const protocolVersion = await framework.contracts.resolver
.connect(framework.settings.provider)
.get("versionString.v1");

return {
data: protocolVersion,
};
},
providesTags: (_result, _error, arg) => [
{
type: "GENERAL",
id: arg.chainId, // TODO(KK): Could be made more specific.
},
],
}),
}),
};
8 changes: 4 additions & 4 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import { networks } from "./networks";
import { addressBookSlice } from "./slices/addressBook.slice";
import { themePreferenceSlice } from "./slices/appPreferences.slice";
import { ensApi } from "./slices/ensResolver.slice";
import { adhocRpcEndpoints } from "./adhocRpcEndpoints";

export const rpcApi = initializeRpcApiSlice(
createApiWithReactHooks
).injectEndpoints(balanceRpcApiEndpoints);
export const rpcApi = initializeRpcApiSlice(createApiWithReactHooks)
.injectEndpoints(balanceRpcApiEndpoints)
.injectEndpoints(adhocRpcEndpoints);

export const sfSubgraph = initializeSubgraphApiSlice(
createApiWithReactHooks
Expand Down Expand Up @@ -64,7 +65,6 @@ export const makeStore = wrapMakeStore(() => {
addressBookSlice.reducer
);


const store = configureStore({
reducer: {
[rpcApi.reducerPath]: rpcApi.reducer,
Expand Down
23 changes: 23 additions & 0 deletions src/utils/versionUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Takes a `pseudoAddress` and returns the `versionString`.
* @param pseudoAddress format: 0x000000000000000000${major}${minor}${patch}${gitRevision}
* @returns `versionString` with format: major.minor.patch-rrrrrrrrrrrrrrrr, r: 16-digit git revision (hex)
*/
export function pseudoAddressToVersionString(pseudoAddress: string) {
const str = pseudoAddress.replace(/^0x/, "").toLowerCase(); // remove leading 0x
const major = parseInt(str.slice(18, 20), 10);
const minor = parseInt(str.slice(20, 22), 10);
const patch = parseInt(str.slice(22, 24), 10);
const revision = str.slice(24);

if (
!str.startsWith("000000000000000000") ||
isNaN(major) ||
isNaN(minor) ||
isNaN(patch)
) {
return undefined;
}

return `${major}.${minor}.${patch}-${revision}`;
}

1 comment on commit f46fa37

@vercel
Copy link

@vercel vercel bot commented on f46fa37 Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.