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

chore: add symbol override #133

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Changes from all commits
Commits
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
22 changes: 18 additions & 4 deletions apps/maestro/src/server/routers/erc20/getERC20TokenDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { ExtendedWagmiChainConfig } from "~/config/evm-chains";
import { hex40Literal } from "~/lib/utils/validation";
import { publicProcedure } from "~/server/trpc";

//TODO: migrate to kv store?
const overrides: Record<`0x${string}`, Record<string, string>> = {
"0x4200000000000000000000000000000000000042": {
symbol: "axlOP",
},
};

export const getERC20TokenDetails = publicProcedure
.input(
z.object({
Expand All @@ -32,7 +39,11 @@ export const getERC20TokenDetails = publicProcedure
);

try {
const details = await getTokenPublicDetails(client, config);
const details = await getTokenPublicDetails(
client,
config,
input.tokenAddress
);

if (details) {
return details;
Expand All @@ -55,7 +66,7 @@ export const getERC20TokenDetails = publicProcedure
input.tokenAddress
);

return getTokenPublicDetails(client, chainConfig);
return getTokenPublicDetails(client, chainConfig, input.tokenAddress);
} catch (error) {
// If we get a TRPC error, we throw it
if (error instanceof TRPCError) {
Expand All @@ -71,7 +82,8 @@ export const getERC20TokenDetails = publicProcedure

async function getTokenPublicDetails(
client: IERC20BurnableMintableClient,
chainConfig: ExtendedWagmiChainConfig
chainConfig: ExtendedWagmiChainConfig,
tokenAddress: `0x${string}`
) {
invariant(client.chain, "client.chain must be defined");

Expand All @@ -83,13 +95,15 @@ async function getTokenPublicDetails(
client.read("pendingOwner").catch(always(null)),
]);

const override = overrides[tokenAddress];

return {
chainId: client.chain.id,
chainName: client.chain.name,
axelarChainId: chainConfig.axelarChainId,
axelarChainName: chainConfig.axelarChainName,
name,
symbol,
symbol: override?.symbol ?? symbol,
decimals,
owner,
pendingOwner,
Expand Down