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

feat: viem wrapper with readContract and base methods #25

Merged
merged 4 commits into from
Jul 19, 2024

Conversation

0xnigir1
Copy link
Collaborator

🤖 Linear

Closes ZKS-67 ZKS-94 ZKS-93

Description

Create a Viem library wrapper service with base methods functionality:

  • getBalance
  • getBlockNumber
  • getGasPrice
  • getStorageAt
  • readContract

readContract allows to perform an eth_call for view/pure functions in a type-safe way by providing the contract ABI

@0xnigir1 0xnigir1 requested review from 0xkenj1 and 0xyaco July 19, 2024 04:44
Copy link

linear bot commented Jul 19, 2024

ZKS-67 Base

Just nest create library

ZKS-94 EVM Provider - Base

Base should include a readContract method, which signature should be

readContract(to: string, data:string)

Also add non-contract related function, for example: getBalance

ZKS-93 EVM Provider - Read contract

Implement readContract()

Resource: https://viem.sh/docs/contract/readContract.html

Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

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

GJ ser! Just a few changes :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

IEvmProvider interface is not needed imo, given that we are not going to have many implementations of EvmProvider

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also notice that readContract() has a very specific signature coupled to viem types. Probably a better approach for interfaces, in case are needed, would be segregation, having 2 different interfaces for example, IEvmProvider and IContractReader

* Acts as a wrapper around Viem library to provide methods to interact with an EVM-based blockchain.
*/
@Injectable()
export class ViemProviderService implements IEvmProvider {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rename this ViemProviderService to EvmProviderService

Comment on lines 60 to 66
/**
* Retrieves the value from a storage slot at a given address.
* @param {Address} address The address of the contract.
* @param {number} slot The slot number to read.
* @returns {Promise<Hex>} A Promise that resolves to the value of the storage slot.
* @throws {InvalidArgumentException} If the slot is not a positive integer.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a suggestion here. When you are implementing an interface i think you can inherit the natspec from it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ooaa nice jajaja

http: jest.fn(),
}));

describe("ViemProviderService", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename here also

Comment on lines 11 to 12
providers: [EvmProviderService, ViemProviderService],
exports: [EvmProviderService, ViemProviderService],
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can get rid of EvmProviderService. Here should be just 1 providers item and 1 exports item

Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

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

dismiss this comment

@0xnigir1 0xnigir1 requested a review from 0xkenj1 July 19, 2024 13:49
Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

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

I think packages directory is no longer used. Lets remove it on this pr pls :)

@0xnigir1 0xnigir1 requested a review from 0xkenj1 July 19, 2024 14:13
@0xnigir1 0xnigir1 merged commit b7de26e into dev Jul 19, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/evm-provider-lib branch July 19, 2024 14:45
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.

3 participants