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: refactor evm indexer #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

tcar121293
Copy link

No description provided.

@tcar121293 tcar121293 requested review from mpetrunic, mpetrun5, MakMuftic and mj52951 and removed request for mj52951 October 22, 2024 07:15
})
.setBlockRange({ from: domain.startBlock })
.setFinalityConfirmation(domain.blockConfirmations)
.setFields({
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was my mistake. This .setFields should be removed as it is not exported anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

but isn't that used when using subsquid data lake to fetch only logs?
https://docs.sqd.dev/tron-indexing/tron-batch-processor/field-selection/#set-fields

Obviously when using rpc it's useless

Copy link
Collaborator

@mj52951 mj52951 Oct 22, 2024

Choose a reason for hiding this comment

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

getProcessor function returns EvmBatchProcessor but if we want to export any of the fields it should return EvmBatchProcessor<definedFields>.
Also, log-topics is by default true. But that leads to a possible future optimization of setting other unused "default true" fields to "false" to improve performance (should be checked if there are any).

this.provider = api;
}

public parseDestination(hexData: string, resourceType: ResourceType): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this called anywhere? Purpose of this is when an EVM deposit is made to a Substrate network, Substrate destination address is correctly parsed.

}
}

private generateTransferID(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, but maybe put this as a helper function accessible to all parsers as this is universally how a transferID is generated for every network type (both EVM and Substrate).

): Promise<void>;
}

export class Indexer {
Copy link
Collaborator

@mj52951 mj52951 Oct 22, 2024

Choose a reason for hiding this comment

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

Will need to think about this whole file and the whole interface approach (maybe also test it out) because e.g. in Substrate the ctx type is different, and in blocks Log types are not fetched but Event types etc. So I think some change of the logic will be needed.

Copy link
Author

Choose a reason for hiding this comment

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

I think if we define fields like Fields = EvmBatchProcessorFields<EvmBatchProcessor> | SubstrateBatchProcessorFields<SubstrateBatchProcessor> ; it should work?

return evmProcessor;
}

public async processDeposits(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also ran into this now. Not sure should processing deposits/executions/failedExec be domain-specific nor network-specific. Because while parsing we can store all data into same types and make processing just communication of the database with "the universal types".


export const getSharedConfig = async (): Promise<SharedConfig> => {
try {
const sharedConfigURL = process.env.SHARED_CONFIG_URL!;
Copy link
Member

Choose a reason for hiding this comment

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

have you considered file where you will load all envs and validate them? Might be easier to maintain them later on.

return (await response.json()) as SharedConfig;
} catch (e) {
logger.error(`Failed to fetch config for ${process.env.STAGE || ""}`, e);
return Promise.reject(e);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return Promise.reject(e);
throw e

);
}
const resource = fromDomain.resources.find(
(resource) => resource.resourceId == event.resourceID,
Copy link
Member

Choose a reason for hiding this comment

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

should we do case insensitive comparison here?

depositNonce: event.depositNonce,
txHash: transaction.hash,
message: ethers.decodeBytes32String(
"0x" + Buffer.from(event.lowLevelData).subarray(-64).toString(),
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +212 to +218
const token = this.getContract(
provider,
fee.tokenAddress,
ContractType.ERC20,
);
tokenSymbol = (await token.symbol()) as string;
decimals = Number(await token.decimals());
Copy link
Member

Choose a reason for hiding this comment

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

we should probably cache this as those are at least two rpc calls. Like can we get all sygma supported erc20 tokens and store their details?

Copy link
Member

Choose a reason for hiding this comment

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

caching should be done on init

})
.setBlockRange({ from: domain.startBlock })
.setFinalityConfirmation(domain.blockConfirmations)
.setFields({
Copy link
Member

Choose a reason for hiding this comment

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

but isn't that used when using subsquid data lake to fetch only logs?
https://docs.sqd.dev/tron-indexing/tron-batch-processor/field-selection/#set-fields

Obviously when using rpc it's useless

ResourceType,
Domain as DomainSDK,
Resource,
} from "@buildwithsygma/sygma-sdk-core";
Copy link
Member

Choose a reason for hiding this comment

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

updated types can be used from @buildwithsygma/core, @buildwithsygma/evm and @buildwithsygma/substrate packages, this version of SDK is deprecated

}
};

export const getRpcMap = (): Map<number, string> => {
Copy link
Member

Choose a reason for hiding this comment

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

better to index RPC w.r.t caipId

sharedConfig: SharedConfig,
rpcUrl: Map<number, string>,
): Map<number, DomainConfig> {
const domainConfig = new Map<number, DomainConfig>();
Copy link
Member

Choose a reason for hiding this comment

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

index w.r.t caipId

case ResourceType.PERMISSIONLESS_GENERIC:
{
// 32 + 2 + 1 + 1 + 20 + 20
const lenExecuteFuncSignature = Number(
Copy link
Member

Choose a reason for hiding this comment

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

this logic can be extracted to a static function like decodeGenericCall

Comment on lines +212 to +218
const token = this.getContract(
provider,
fee.tokenAddress,
ContractType.ERC20,
);
tokenSymbol = (await token.symbol()) as string;
decimals = Number(await token.decimals());
Copy link
Member

Choose a reason for hiding this comment

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

caching should be done on init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants