Skip to content

Commit

Permalink
Merge branch 'main' into fix/versions
Browse files Browse the repository at this point in the history
  • Loading branch information
SGiaccobasso authored Aug 20, 2024
2 parents 2919b2f + 35bd4f6 commit d0b993a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-jeans-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@axelarjs/maestro": patch
---

Change search erc20 query config so it does not retry on error, make RPC calls in getERC20TokenDetails and searchInterchainToken methods concurrent..
44 changes: 29 additions & 15 deletions apps/maestro/src/server/routers/erc20/getERC20TokenDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,45 @@ export const getERC20TokenDetails = publicProcedure
);

if (!chainConfig) {
for (const config of chainConfigs) {
const promises = chainConfigs.map((config) => {
const client = ctx.contracts.createERC20Client(
config,
input.tokenAddress
);

try {
const details = await getTokenPublicDetails(
client,
return getTokenPublicDetails(client, config, input.tokenAddress)
.then((details) => ({
success: true,
details,
config,
input.tokenAddress
);
}))
.catch(() => ({
success: false,
config,
details: null,
}));
});

const results = await Promise.all(promises);

const successfulResult = results.find((result) => result.success);

if (details) {
return details;
}
} catch (error) {
console.log(
`Token ${input.tokenAddress} not found on ${config.name}`
if (successfulResult) {
return successfulResult.details;
}

// Log errors
results.forEach((result) => {
if (!result.success) {
console.error(
`Token ${input.tokenAddress} not found on chain: ${result.config.axelarChainName}`
);
}
}
});

throw new TRPCError({
code: "BAD_REQUEST",
message: `Invalid chainId: ${input.chainId}`,
code: "NOT_FOUND",
message: `Token not found on any chain.`,
});
}

Expand All @@ -76,6 +89,7 @@ export const getERC20TokenDetails = publicProcedure
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Failed to get ERC20 token details for ${input.tokenAddress} on ${input.chainId}`,
cause: error,
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,34 @@ async function scanChains(
tokenAddress: `0x${string}`,
ctx: Context
) {
for (const chainConfig of chainConfigs) {
const tokenDetails = await getTokenDetails(chainConfig, tokenAddress, ctx);

if (tokenDetails) {
const result = getInterchainToken(
tokenDetails,
chainConfig,
chainConfigs,
ctx
);
const promises = chainConfigs.map((chainConfig) => {
getTokenDetails(chainConfig, tokenAddress, ctx)
.then((tokenDetails) => {
if (tokenDetails) {
const result = getInterchainToken(
tokenDetails,
chainConfig,
chainConfigs,
ctx
);
if (result) {
return result;
}
return null;
}
})
.catch(() => {
console.log(
`Token not found for chain: ${chainConfig.axelarChainName}`
);
return null;
});
});

if (result) {
return result;
}
}
}
const results = await Promise.all(promises);
const validResult = results.find((result) => result !== null);

return null;
return validResult || null;
}

async function getTokenDetails(
Expand Down
1 change: 1 addition & 0 deletions apps/maestro/src/services/erc20/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function useERC20TokenDetailsQuery(input: {
},
{
enabled: isAddress(input.tokenAddress ?? ""),
retry: false,
staleTime: 1000 * 60 * 60 * 24, // 24 hours
refetchOnWindowFocus: false,
}
Expand Down

0 comments on commit d0b993a

Please sign in to comment.