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

Wormhole integration #719

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft

Conversation

artur-abliazimov
Copy link
Contributor

@artur-abliazimov artur-abliazimov commented Aug 27, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new submodule for the "wormhole-relayer-engine," enhancing modularity and integration of external code.
    • Added comprehensive configuration files for TypeScript, ESLint, Prettier, and Docker, optimizing the development environment.
    • Implemented a structured approach for managing token transfers and interactions within the Wormhole protocol on Solana.
    • Established robust error handling and state management for smart contracts, improving reliability and security.
  • Documentation

    • Added documentation for environment variables required for configuring the relayer application.
    • Introduced README files detailing setup and usage instructions for developers.
  • Chores

    • Created .gitignore files to streamline version control by excluding unnecessary files.
    • Added configuration files for development tools to enhance code quality and maintainability.

@artur-abliazimov artur-abliazimov self-assigned this Aug 27, 2024
@artur-abliazimov artur-abliazimov marked this pull request as draft August 27, 2024 08:26
Copy link

Hey @artur-abliazimov and thank you for opening this pull request! 👋🏼

It looks like you forgot to add a changelog entry for your changes. Make sure to add a changelog entry in the 'CHANGELOG.md' file.

@github-actions github-actions bot removed the protocol label Aug 27, 2024
Copy link
Contributor

coderabbitai bot commented Aug 27, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The changes introduce a new submodule configuration for the "wormhole-relayer-engine," optimize linting and TypeScript settings in the relayers directory, implement ESLint and Prettier configurations, and establish a Dockerfile for building a Node.js application. Additionally, new Rust smart contract functionalities are added for the Wormhole protocol, including token transfer mechanisms and error handling in the Solana ecosystem, alongside comprehensive testing and documentation updates.

Changes

File(s) Change Summary
.gitmodules Added configuration for the new submodule "wormhole-relayer-engine" with a specified path and URL.
relayers/.eslintignore, relayers/tsconfig.json, relayers/.eslintrc.yml Introduced ESLint configuration and TypeScript settings, including ignore patterns and compiler options for improved development practices.
relayers/.gitignore, relayers/.prettierrc.yml, relayers/.vscode/settings.json Created configuration files for Git ignore patterns, Prettier formatting rules, and VS Code settings to manage code style and exclude unnecessary files.
relayers/Dockerfile Implemented a multi-stage Docker build for the "wormhole-relayer" service.
relayers/README.md Added documentation for environment variables required to configure the @warden/wormhole-relayer application.
relayers/justfile, relayers/package.json Introduced a Justfile for managing build commands and a package.json file for defining project dependencies and scripts for development.
relayers/packages/wormhole/contracts/cosmwasm/... Added multiple Rust files defining smart contract structures for the Wormhole ecosystem, including token transfer functionalities, error handling, and testing suites.
relayers/packages/wormhole/contracts/solana/... Introduced configuration and context files for Solana smart contracts focusing on token transfers, including wrapped and native tokens, with associated error handling and feature implementations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Relayer
    participant TokenBridge
    participant Wormhole

    User->>Relayer: Initiate Token Transfer
    Relayer->>TokenBridge: Validate Transfer
    TokenBridge->>Wormhole: Process Transfer
    Wormhole->>TokenBridge: Confirm Transfer
    TokenBridge->>Relayer: Transfer Confirmation
    Relayer->>User: Notify Transfer Success
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Aug 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
warden-help-center ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 8:28am

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Outside diff range, codebase verification and nitpick comments (5)
relayers/package.json (1)

1-8: Fill in the author field.

The author field is currently empty. It is recommended to provide the author's name or organization for better maintainability.

-  "author": "",
+  "author": "Your Name or Organization",
relayers/README.md (1)

3-32: Improve grammar and clarity.

The environment variables section is correctly set up, but some grammatical improvements can be made for better clarity.

-# example below
+# Example below:
relayers/packages/wormhole/src/utils.ts (1)

33-87: Remove commented-out code.

The commented-out code should be removed if it is not needed.

Remove the commented-out code to keep the codebase clean.

relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/send_wrapped_tokens_with_payload.rs (1)

Line range hint 17-165: Add comments for all accounts.

The struct should include comments for all accounts to ensure clarity and maintainability.

Apply this diff to add comments:

 pub struct SendWrappedTokensWithPayload<'info> {
+  /// Payer will pay Wormhole fee to transfer tokens and create temporary
+  /// token account.
   #[account(mut)]
   pub payer: Signer<'info>,

   #[account(
       seeds = [SenderConfig::SEED_PREFIX],
       bump
   )]
   /// Sender Config account. Acts as the Token Bridge sender PDA. Mutable.
   pub config: Box<Account<'info, SenderConfig>>,

   #[account(
       seeds = [
           ForeignContract::SEED_PREFIX,
           &recipient_chain.to_le_bytes()[..]
       ],
       bump,
   )]
   /// Foreign Contract account. Send tokens to the contract specified in this
   /// account. The Token Bridge program does not have any requirements for outbound
   /// transfers for the recipient chain to be registered. This account provides
   /// extra protection against sending tokens to an unregistered Wormhole chain ID.
   /// Read-only.
   pub foreign_contract: Box<Account<'info, ForeignContract>>,

   #[account(
       mut,
       seeds = [
           token_bridge::WrappedMint::SEED_PREFIX,
           &token_bridge_wrapped_meta.chain.to_be_bytes(),
           &token_bridge_wrapped_meta.token_address
       ],
       bump,
       seeds::program = token_bridge_program
   )]
   /// Token Bridge wrapped mint info. This is the SPL token that will be
   /// bridged to the foreign contract. The wrapped mint PDA must agree
   /// with the native token's metadata. Mutable.
   pub token_bridge_wrapped_mint: Box<Account<'info, token_bridge::WrappedMint>>,

   #[account(
       mut,
       associated_token::mint = token_bridge_wrapped_mint,
       associated_token::authority = payer,
   )]
   pub from_token_account: Account<'info, TokenAccount>,

   #[account(
       init,
       payer = payer,
       seeds = [
           SEED_PREFIX_TMP,
           token_bridge_wrapped_mint.key().as_ref(),
       ],
       bump,
       token::mint = token_bridge_wrapped_mint,
       token::authority = config,
   )]
   pub tmp_token_account: Box<Account<'info, TokenAccount>>,

   /// Wormhole program.
   pub wormhole_program: Program<'info, wormhole::program::Wormhole>,

   /// Token Bridge program.
   pub token_bridge_program: Program<'info, token_bridge::program::TokenBridge>,

   #[account(
       seeds = [
           token_bridge::WrappedMeta::SEED_PREFIX,
           token_bridge_wrapped_mint.key().as_ref()
       ],
       bump,
       seeds::program = token_bridge_program
   )]
   /// Token Bridge program's wrapped metadata stores info about the token from its native chain:
   /// Wormhole Chain ID, Token's native contract address, Token's native decimals
   pub token_bridge_wrapped_meta: Account<'info, token_bridge::WrappedMeta>,

   #[account(
       mut,
       address = config.token_bridge.config @ GmpWithTokenError::InvalidTokenBridgeConfig
   )]
   /// Token Bridge config. Mutable.
   pub token_bridge_config: Account<'info, token_bridge::Config>,

   #[account(
       address = config.token_bridge.authority_signer @ GmpWithTokenError::InvalidTokenBridgeAuthoritySigner
   )]
   /// CHECK: Token Bridge authority signer. Read-only.
   pub token_bridge_authority_signer: UncheckedAccount<'info>,

   #[account(
       mut,
       address = config.token_bridge.wormhole_bridge @ GmpWithTokenError::InvalidWormholeBridge,
   )]
   /// Wormhole bridge data. Mutable.
   pub wormhole_bridge: Box<Account<'info, wormhole::BridgeData>>,

   #[account(
       mut,
       seeds = [
           SEED_PREFIX_BRIDGED,
           &token_bridge_sequence.next_value().to_le_bytes()[..]
       ],
       bump,
   )]
   /// CHECK: Wormhole Message. Token Bridge program writes info about the
   /// tokens transferred in this account.
   pub wormhole_message: UncheckedAccount<'info>,

   #[account(
       mut,
       address = config.token_bridge.emitter @ GmpWithTokenError::InvalidTokenBridgeEmitter
   )]
   /// CHECK: Token Bridge emitter. Read-only.
   pub token_bridge_emitter: UncheckedAccount<'info>,

   #[account(
       mut,
       address = config.token_bridge.sequence @ GmpWithTokenError::InvalidTokenBridgeSequence
   )]
   /// CHECK: Token Bridge sequence. Mutable.
   pub token_bridge_sequence: Account<'info, wormhole::SequenceTracker>,

   #[account(
       mut,
       address = config.token_bridge.wormhole_fee_collector @ GmpWithTokenError::InvalidWormholeFeeCollector
   )]
   /// Wormhole fee collector. Mutable.
   pub wormhole_fee_collector: Account<'info, wormhole::FeeCollector>,

   /// System program.
   pub system_program: Program<'info, System>,

   /// Token program.
   pub token_program: Program<'info, Token>,

   /// Associated Token program.
   pub associated_token_program: Program<'info, AssociatedToken>,

   /// Clock sysvar.
   pub clock: Sysvar<'info, Clock>,

   /// Rent sysvar.
   pub rent: Sysvar<'info, Rent>,
 }
relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/send_native_tokens_with_payload.rs (1)

17-165: Add comments for all accounts.

The struct should include comments for all accounts to ensure clarity and maintainability.

Apply this diff to add comments:

 pub struct SendNativeTokensWithPayload<'info> {
+  /// Payer will pay Wormhole fee to transfer tokens and create temporary
+  /// token account.
   #[account(mut)]
   pub payer: Signer<'info>,

   #[account(
       seeds = [SenderConfig::SEED_PREFIX],
       bump
   )]
   /// Sender Config account. Acts as the signer for the Token Bridge token
   /// transfer. Read-only.
   pub config: Box<Account<'info, SenderConfig>>,

   #[account(
       seeds = [
           ForeignContract::SEED_PREFIX,
           &recipient_chain.to_le_bytes()[..]
       ],
       bump,
   )]
   /// Foreign Contract account. Send tokens to the contract specified in this
   /// account. The Token Bridge program does not have any requirements for outbound
   /// transfers for the recipient chain to be registered. This account provides
   /// extra protection against sending tokens to an unregistered Wormhole chain ID.
   /// Read-only.
   pub foreign_contract: Box<Account<'info, ForeignContract>>,

   #[account(mut)]
   /// Mint info. This is the SPL token that will be bridged over to the
   /// foreign contract. Mutable.
   pub mint: Box<Account<'info, Mint>>,

   #[account(
       mut,
       associated_token::mint = mint,
       associated_token::authority = payer,
   )]
   /// Payer's associated token account. We may want to make this a generic
   /// token account in the future.
   pub from_token_account: Account<'info, TokenAccount>,

   #[account(
       init,
       payer = payer,
       seeds = [
           SEED_PREFIX_TMP,
           mint.key().as_ref(),
       ],
       bump,
       token::mint = mint,
       token::authority = config,
   )]
   /// Program's temporary token account. This account is created before the
   /// instruction is invoked to temporarily take custody of the payer's
   /// tokens. When the tokens are finally bridged out, the token account
   /// will have zero balance and can be closed.
   pub tmp_token_account: Box<Account<'info, TokenAccount>>,

   /// Wormhole program.
   pub wormhole_program: Program<'info, wormhole::program::Wormhole>,

   /// Token Bridge program.
   pub token_bridge_program: Program<'info, token_bridge::program::TokenBridge>,

   #[account(
       address = config.token_bridge.config @ GmpWithTokenError::InvalidTokenBridgeConfig
   )]
   /// Token Bridge config. Read-only.
   pub token_bridge_config: Account<'info, token_bridge::Config>,

   #[account(
       mut,
       seeds = [mint.key().as_ref()],
       bump,
       seeds::program = token_bridge_program
   )]
   /// CHECK: Token Bridge custody. This is the Token Bridge program's token
   /// account that holds this mint's balance. This account needs to be
   /// unchecked because a token account may not have been created for this
   /// mint yet. Mutable.
   pub token_bridge_custody: UncheckedAccount<'info>,

   #[account(
       address = config.token_bridge.authority_signer @ GmpWithTokenError::InvalidTokenBridgeAuthoritySigner
   )]
   /// CHECK: Token Bridge authority signer. Read-only.
   pub token_bridge_authority_signer: UncheckedAccount<'info>,

   #[account(
       address = config.token_bridge.custody_signer @ GmpWithTokenError::InvalidToken

</blockquote></details>

</blockquote></details>

<details>
<summary>Review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**

<details>
<summary>Commits</summary>

Files that changed from the base of the PR and between 6a439128480a89394fb761e863f51fb14a673aba and 1232deb20595ae74f6d39c05ac09d998d1c9cc4a.

</details>
<details>
<summary>Files ignored due to path filters (3)</summary>

* `relayers/packages/wormhole/contracts/cosmwasm/Cargo.lock` is excluded by `!**/*.lock`
* `relayers/packages/wormhole/contracts/solana/Cargo.lock` is excluded by `!**/*.lock`
* `relayers/yarn.lock` is excluded by `!**/yarn.lock`, `!**/*.lock`

</details>

<details>
<summary>Files selected for processing (63)</summary>

* .gitmodules (1 hunks)
* relayers/.eslintignore (1 hunks)
* relayers/.eslintrc.yml (1 hunks)
* relayers/.gitignore (1 hunks)
* relayers/.prettierrc.yml (1 hunks)
* relayers/.vscode/settings.json (1 hunks)
* relayers/Dockerfile (1 hunks)
* relayers/README.md (1 hunks)
* relayers/justfile (1 hunks)
* relayers/package.json (1 hunks)
* relayers/packages/wormhole-relayer-engine (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/.gitignore (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/Cargo.toml (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/.cargo/config (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/Cargo.toml (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/bin/schema.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/contract.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/error.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/lib.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/methods.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/msg.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/state.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/tests.rs (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/justfile (1 hunks)
* relayers/packages/wormhole/contracts/cosmwasm/scripts/optimizer.sh (1 hunks)
* relayers/packages/wormhole/contracts/solana/.gitignore (1 hunks)
* relayers/packages/wormhole/contracts/solana/Anchor.toml (1 hunks)
* relayers/packages/wormhole/contracts/solana/Cargo.toml (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/Cargo.toml (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/Xargo.toml (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/constants.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/initialize.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/mod.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/redeem_native_transfer_with_payload.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/redeem_wrapped_transfer_with_payload.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/register_foreign_contract.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/send_native_tokens_with_payload.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/send_wrapped_tokens_with_payload.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/update_relayer_fee.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/error.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/lib.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/message.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/foreign_contract.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/mod.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/redeemer_config.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/sender_config.rs (1 hunks)
* relayers/packages/wormhole/contracts/solana/rust-toolchain (1 hunks)
* relayers/packages/wormhole/package.json (1 hunks)
* relayers/packages/wormhole/scripts/structure.sql (1 hunks)
* relayers/packages/wormhole/src/clients/solanaGmpWithTokenClient.ts (1 hunks)
* relayers/packages/wormhole/src/clients/types/gatewayPayload.ts (1 hunks)
* relayers/packages/wormhole/src/clients/types/gatewayTransferWithPayload.ts (1 hunks)
* relayers/packages/wormhole/src/config/env.ts (1 hunks)
* relayers/packages/wormhole/src/config/schema.ts (1 hunks)
* relayers/packages/wormhole/src/database/entity/index.ts (1 hunks)
* relayers/packages/wormhole/src/database/entity/wormholeGmpRequestStatus.ts (1 hunks)
* relayers/packages/wormhole/src/database/entity/wormholeRequestType.ts (1 hunks)
* relayers/packages/wormhole/src/database/wormholeDataSource.ts (1 hunks)
* relayers/packages/wormhole/src/index.ts (1 hunks)
* relayers/packages/wormhole/src/processors/relayProcessor.ts (1 hunks)
* relayers/packages/wormhole/src/utils.ts (1 hunks)
* relayers/packages/wormhole/tsconfig.json (1 hunks)
* relayers/tsconfig.json (1 hunks)

</details>






<details>
<summary>Files skipped from review due to trivial changes (18)</summary>

* .gitmodules
* relayers/.eslintignore
* relayers/.gitignore
* relayers/.prettierrc.yml
* relayers/.vscode/settings.json
* relayers/packages/wormhole/contracts/cosmwasm/.gitignore
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/.cargo/config
* relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/bin/schema.rs
* relayers/packages/wormhole/contracts/solana/.gitignore
* relayers/packages/wormhole/contracts/solana/Cargo.toml
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/Xargo.toml
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/constants.rs
* relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/mod.rs
* relayers/packages/wormhole/contracts/solana/rust-toolchain
* relayers/packages/wormhole/src/database/entity/index.ts
* relayers/packages/wormhole/src/database/entity/wormholeGmpRequestStatus.ts
* relayers/packages/wormhole/tsconfig.json
* relayers/tsconfig.json

</details>



<details>
<summary>Additional context used</summary>

<details>
<summary>Path-based instructions (1)</summary><blockquote>

<details>
<summary>relayers/README.md (1)</summary>

Pattern `**/*.md`: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"


</details>

</blockquote></details>

<details>
<summary>Shellcheck</summary><blockquote>

<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/scripts/optimizer.sh</summary><blockquote>

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

</blockquote></details>

</blockquote></details>
<details>
<summary>Gitleaks</summary><blockquote>

<details>
<summary>relayers/packages/wormhole/contracts/solana/Anchor.toml</summary><blockquote>

13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

</blockquote></details>

</blockquote></details>

</details>
<details>
<summary>Additional comments not posted (144)</summary><blockquote>

<details>
<summary>relayers/packages/wormhole-relayer-engine (1)</summary><blockquote>

`1-1`: **LGTM!**

The subproject commit is correctly referenced.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/lib.rs (2)</summary><blockquote>

`1-6`: **LGTM!**

The module declarations are correctly implemented.

The code changes are approved.

---

`8-8`: **LGTM!**

The public use statement is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/clients/types/gatewayPayload.ts (2)</summary><blockquote>

`1-1`: **LGTM!**

The import statement is correctly implemented.

The code changes are approved.

---

`3-5`: **LGTM!**

The interface declaration is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/justfile (4)</summary><blockquote>

`1-2`: **LGTM!**

The command is correctly implemented.

The code changes are approved.

---

`4-6`: **LGTM!**

The command is correctly implemented.

The code changes are approved.

---

`8-10`: **LGTM!**

The command is correctly implemented.

The code changes are approved.

---

`12-13`: **LGTM!**

The command is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/scripts/optimizer.sh (2)</summary><blockquote>

`3-12`: **LGTM!**

The variable declarations are correctly implemented.

The code changes are approved.

---

`13-16`: **LGTM!**

The Docker run command is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/Anchor.toml (6)</summary><blockquote>

`1-3`: **LGTM!**

The `[features]` section is correctly implemented.

The code changes are approved.

---

`5-9`: **LGTM!**

The `[workspace]` section is correctly implemented.

The code changes are approved.

---

`11-13`: **LGTM!**

The `[programs.localnet]` section is correctly implemented.

The code changes are approved.

<details>
<summary>Tools</summary>

<details>
<summary>Gitleaks</summary><blockquote>

13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

</blockquote></details>

</details>

---

`12-13`: **Address potential exposure of a generic API key.**

The Gitleaks hint indicates a potential exposure of a generic API key. Ensure that sensitive information is not exposed.

Do you want me to help with securing this information or open a GitHub issue to track this task?

<details>
<summary>Tools</summary>

<details>
<summary>Gitleaks</summary><blockquote>

13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

</blockquote></details>

</details>

---

`15-16`: **LGTM!**

The `[registry]` section is correctly implemented.

The code changes are approved.

---

`18-20`: **LGTM!**

The `[provider]` section is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/Dockerfile (3)</summary><blockquote>

`1-2`: **LGTM!**

The base image and build tools installation are appropriate for building Node.js applications.

The code changes are approved.

---

`3-6`: **LGTM!**

The working directory, source code copy, dependency installation, and build commands are appropriate for the build stage.

The code changes are approved.

---

`8-13`: **LGTM!**

The base image, working directory, file copy, and start command are appropriate for the final stage.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/clients/types/gatewayTransferWithPayload.ts (2)</summary><blockquote>

`1-2`: **LGTM!**

The import statement is appropriate and necessary for defining the `GatewayTransferWithPayload` interface.

The code changes are approved.

---

`3-9`: **LGTM!**

The `GatewayTransferWithPayload` interface is well-defined with appropriate types and useful comments.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/scripts/structure.sql (3)</summary><blockquote>

`1-2`: **LGTM!**

The table name and `Hash` column definition are appropriate.

The code changes are approved.

---

`3-9`: **LGTM!**

The column definitions are appropriate with suitable data types and constraints.

The code changes are approved.

---

`11-12`: **LGTM!**

Defining the primary key on the `Hash` column is appropriate for ensuring uniqueness.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/database/wormholeDataSource.ts (2)</summary><blockquote>

`1-5`: **LGTM!**

The imports are correctly implemented.

The code changes are approved.

---

`7-19`: **Verify and validate configuration values.**

Ensure that the configuration values (DB_HOST, DB_PORT, etc.) are correctly set and validated to avoid runtime errors.

</blockquote></details>
<details>
<summary>relayers/.eslintrc.yml (3)</summary><blockquote>

`1-5`: **LGTM!**

Extending recommended ESLint and TypeScript rules, and Prettier ensures code quality and consistency.

The code changes are approved.

---

`6-8`: **LGTM!**

Using the TypeScript parser and specifying a project file is necessary for TypeScript linting.

The code changes are approved.

---

`9-21`: **LGTM!**

The plugins and rules configuration is well-defined and addresses common TypeScript issues.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/mod.rs (2)</summary><blockquote>

`1-8`: **LGTM!**

Re-exporting modules helps in organizing and managing the codebase.

The code changes are approved.

---

`10-17`: **LGTM!**

Declaring modules is necessary for organizing and managing the codebase.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/foreign_contract.rs (5)</summary><blockquote>

`1-3`: **LGTM!**

The imports are appropriate for the functionality provided in the file.

The code changes are approved.

---

`5-11`: **LGTM!**

The `ForeignContract` struct is well-defined with appropriate field types.

The code changes are approved.

---

`13-17`: **LGTM!**

The `MAXIMUM_SIZE` constant is correctly calculated and accounts for all fields.

The code changes are approved.

---

`19-19`: **LGTM!**

The `SEED_PREFIX` constant is appropriately defined for use in PDA derivation.

The code changes are approved.

---

`21-23`: **LGTM!**

The `verify` method is correctly implemented and performs the necessary checks.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/config/env.ts (2)</summary><blockquote>

`1-1`: **LGTM!**

The import statement is appropriate for the functionality provided in the file.

The code changes are approved.

---

`3-30`: **LGTM!**

The `Env` interface is well-defined and covers all necessary configuration properties.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/Cargo.toml (4)</summary><blockquote>

`1-4`: **LGTM!**

The package metadata is correctly defined.

The code changes are approved.

---

`6-8`: **LGTM!**

The library configuration is correctly defined.

The code changes are approved.

---

`10-18`: **LGTM!**

The features section is correctly defined and covers all necessary features.

The code changes are approved.

---

`20-24`: **LGTM!**

The dependencies section is correctly defined and includes all necessary dependencies.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/justfile (2)</summary><blockquote>

`3-9`: **LGTM!**

The schema generation script is correctly implemented.

The code changes are approved.

---

`10-18`: **LGTM!**

The contract compilation script is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/error.rs (1)</summary><blockquote>

`1-26`: **LGTM!**

The custom error types are well-defined and use the `thiserror` crate for error handling. The error messages are clear and provide useful information.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/update_relayer_fee.rs (1)</summary><blockquote>

`1-24`: **LGTM!**

The accounts and their attributes are well-defined. The `owner` account is unchecked but has a clear explanation. The `config` account uses seeds and a bump for security.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/package.json (3)</summary><blockquote>

`9-11`: **LGTM!**

The workspaces section is correctly set up.

The code changes are approved.

---

`12-16`: **LGTM!**

The scripts section is correctly set up.

The code changes are approved.

---

`17-27`: **LGTM!**

The devDependencies section is correctly set up.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/README.md (1)</summary><blockquote>

`1-2`: **LGTM!**

The title and introductory section are correctly set up.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/package.json (5)</summary><blockquote>

`1-6`: **LGTM!**

The metadata section is correctly set up.

The code changes are approved.

---

`7-9`: **LGTM!**

The files section is correctly set up.

The code changes are approved.

---

`10-13`: **LGTM!**

The scripts section is correctly set up.

The code changes are approved.

---

`14-26`: **LGTM!**

The dependencies section is correctly set up.

The code changes are approved.

---

`27-33`: **LGTM!**

The devDependencies and resolutions section is correctly set up.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/Cargo.toml (5)</summary><blockquote>

`1-6`: **LGTM!**

The package metadata is correctly defined.

The code changes are approved.

---

`8-9`: **LGTM!**

The crate types are correctly defined.

The code changes are approved.

---

`11-14`: **LGTM!**

The optional features are correctly defined.

The code changes are approved.

---

`16-29`: **LGTM!**

The dependencies are correctly defined.

The code changes are approved.

---

`31-34`: **LGTM!**

The development dependencies are correctly defined.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/database/entity/wormholeRequestType.ts (4)</summary><blockquote>

`1-3`: **LGTM!**

The imports are correctly defined.

The code changes are approved.

---

`5-5`: **LGTM!**

The table name is correctly defined.

The code changes are approved.

---

`7-8`: **LGTM!**

The primary key column is correctly defined.

The code changes are approved.

---

`6-30`: **LGTM!**

The class is correctly defined.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/Cargo.toml (6)</summary><blockquote>

`1-5`: **LGTM!**

The workspace members and resolver are correctly defined.

The code changes are approved.

---

`7-8`: **LGTM!**

The version is correctly defined.

The code changes are approved.

---

`10-24`: **LGTM!**

The dependencies are correctly defined.

The code changes are approved.

---

`26-28`: **LGTM!**

The `gmp-with-token` dependency is correctly defined.

The code changes are approved.

---

`30-32`: **LGTM!**

The release profile settings for the `gmp-with-token` package are correctly defined.

The code changes are approved.

---

`34-40`: **LGTM!**

The release profile settings for the workspace are correctly defined.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/redeemer_config.rs (2)</summary><blockquote>

`4-9`: **LGTM!**

The struct `InboundTokenBridgeAddresses` is correctly defined.

The code changes are approved.

---

`11-20`: **LGTM!**

The struct `RedeemerConfig` is correctly defined.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/message.rs (3)</summary><blockquote>

`7-10`: **LGTM!**

The enum `GmpMessage` is correctly defined.

The code changes are approved.

---

`12-21`: **LGTM!**

The implementation of `AnchorSerialize` for `GmpMessage` is correct.

The code changes are approved.

---

`23-35`: **LGTM!**

The implementation of `AnchorDeserialize` for `GmpMessage` is correct.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/state/sender_config.rs (3)</summary><blockquote>

`4-14`: **LGTM!**

The struct `OutboundTokenBridgeAddresses` is correctly defined.

The code changes are approved.

---

`16-24`: **LGTM!**

The struct `SenderConfig` is correctly defined.

The code changes are approved.

---

`26-39`: **LGTM!**

The implementation block for `SenderConfig` is correct.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/config/schema.ts (3)</summary><blockquote>

`1-3`: **LGTM!**

The import statements are necessary and correctly implemented.

The code changes are approved.

---

`5-50`: **LGTM!**

The schema correctly defines the required environment variables and their properties.

The code changes are approved.

---

`53-56`: **LGTM!**

The schema validation is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/state.rs (4)</summary><blockquote>

`1-6`: **LGTM!**

The import statements are necessary and correctly implemented.

The code changes are approved.

---

`8-22`: **LGTM!**

The constants are necessary for the Wormhole protocol and are correctly defined.

The code changes are approved.

---

`24-41`: **LGTM!**

The structs are necessary for the Wormhole protocol and are correctly defined.

The code changes are approved.


Also applies to: 51-59

---

`43-49`: **LGTM!**

The enums are necessary for the Wormhole protocol and are correctly defined.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/msg.rs (5)</summary><blockquote>

`1-3`: **LGTM!**

The import statements are necessary and correctly implemented.

The code changes are approved.

---

`5-8`: **LGTM!**

The `MsgReplyId` enum is necessary for message reply IDs and is correctly defined.

The code changes are approved.

---

`10-14`: **LGTM!**

The `MsgTransferResponse` struct is necessary for message transfer responses and is correctly defined.

The code changes are approved.

---

`19-26`: **LGTM!**

The `InstantiateMsg` struct is necessary for instantiating the contract and is correctly defined.

The code changes are approved.

---

`28-48`: **LGTM!**

The `ExecuteMsg`, `QueryMsg`, `GatewayIbcTokenBridgePayload`, and `SudoMsg` enums are necessary for executing, querying, and handling messages in the Wormhole protocol and are correctly defined.

The code changes are approved.


Also applies to: 50-56, 58-67, 69-86

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/register_foreign_contract.rs (2)</summary><blockquote>

`1-5`: **LGTM!**

The imports are correct and necessary for the functionality provided in the file.

The code changes are approved.

---

`7-57`: **LGTM!**

The struct definition and attributes are correct and follow best practices for Solana programs.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/index.ts (3)</summary><blockquote>

`1-18`: **LGTM!**

The imports are correct and necessary for the functionality provided in the file.

The code changes are approved.

---

`19-30`: **LGTM!**

The logger setup is correct and follows best practices for logging in Node.js applications.

The code changes are approved.

---

`32-100`: **LGTM!**

The main function and application initialization are correct and follow best practices for setting up a Node.js application with Redis and other dependencies.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/error.rs (2)</summary><blockquote>

`1-2`: **LGTM!**

The imports are correct and necessary for the functionality provided in the file.

The code changes are approved.

---

`3-111`: **LGTM!**

The error code definitions are correct and follow best practices for defining errors in Solana programs.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/utils.ts (3)</summary><blockquote>

`5-5`: **LGTM!**

The `delay` function is correctly implemented using `promisify`.

The code changes are approved.

---

`7-18`: **LGTM!**

The `getWormholeContractsNetwork` function is correctly implemented.

The code changes are approved.

---

`20-31`: **LGTM!**

The `getWormholeSdkNetwork` function is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/initialize.rs (1)</summary><blockquote>

`6-113`: **LGTM!**

The `Initialize` structure is correctly implemented with appropriate account attributes.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/contract.rs (6)</summary><blockquote>

`20-28`: **LGTM!**

The `instantiate` function is correctly implemented.

The code changes are approved.

---

`30-33`: **LGTM!**

The `migrate` function is correctly implemented.

The code changes are approved.

---

`35-70`: **LGTM!**

The `execute` function is correctly implemented.

The code changes are approved.

---

`73-91`: **LGTM!**

The `query` function is correctly implemented.

The code changes are approved.

---

`94-121`: **LGTM!**

The `sudo` function is correctly implemented.

The code changes are approved.

---

`124-133`: **LGTM!**

The `reply` function is correctly implemented.

The code changes are approved.

</blockquote></details>
<details>
<summary>relayers/packages/wormhole/src/processors/relayProcessor.ts (1)</summary><blockquote>

`16-32`: **Ensure correct type for `chainStartSequences` values.**

The values in `chainStartSequences` should be of type `bigint`. Ensure that the parsed values are correctly converted.

Apply this diff to ensure the correct type:

```diff
 for (const startSequence of startSequences) {
-  this.chainStartSequences[startSequence[0]] = startSequence[1];
+  this.chainStartSequences[startSequence[0]] = BigInt(startSequence[1]);
 }
relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/redeem_native_transfer_with_payload.rs (5)

1-12: LGTM!

The imports and initial struct definition are correct and necessary for the functionality.

The code changes are approved.


13-24: LGTM!

The constraints ensure that the payer's token account is valid. The unchecked account is justified with a comment.

The code changes are approved.


25-45: LGTM!

The constraints ensure the validity of the foreign contract and the configuration. The seeds are correctly used.

The code changes are approved.


46-66: LGTM!

The constraints ensure the validity of the recipient's token account. The unchecked account is justified with a comment.

The code changes are approved.


67-153: LGTM!

The constraints and seeds ensure the validity of these accounts. The unchecked accounts are justified with comments.

The code changes are approved.

relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/context/redeem_wrapped_transfer_with_payload.rs (5)

1-12: LGTM!

The imports and initial struct definition are correct and necessary for the functionality.

The code changes are approved.


13-24: LGTM!

The constraints ensure that the payer's token account is valid. The unchecked account is justified with a comment.

The code changes are approved.


25-45: LGTM!

The constraints ensure the validity of the foreign contract and the configuration. The seeds are correctly used.

The code changes are approved.


46-73: LGTM!

The constraints ensure the validity of the recipient's token account. The unchecked account is justified with a comment.

The code changes are approved.


74-165: LGTM!

The constraints and seeds ensure the validity of these accounts. The unchecked accounts are justified with comments.

The code changes are approved.

relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/tests.rs (4)

1-56: LGTM!

The test correctly verifies the initialization process.

The code changes are approved.


58-104: LGTM!

The test correctly verifies the scenarios for setting the chain emitter.

The code changes are approved.


106-182: LGTM!

The test correctly verifies the message posting process and IBC transfer.

The code changes are approved.


184-247: LGTM!

The test correctly verifies the scenarios for receiving a message.

The code changes are approved.

relayers/packages/wormhole/contracts/cosmwasm/contracts/gmp_with_token/src/methods.rs (9)

20-41: LGTM!

The execute_instantiate function is correctly implemented. It initializes the contract with the provided parameters and sets the admin address and Wormhole IBC configuration.

The code changes are approved.


43-58: LGTM!

The execute_set_chain_emitter function is correctly implemented. It checks for admin privileges and saves the emitter for the specified chain ID.

The code changes are approved.


60-82: LGTM!

The execute_receive_message function is correctly implemented. It validates the sender and constructs a response.

The code changes are approved.


85-148: LGTM!

The execute_post_message function is correctly implemented. It validates the message and constructs an IBC transfer message.

The code changes are approved.


151-200: LGTM!

The execute_post_message_reply function is correctly implemented. It processes the reply and updates the message status.

The code changes are approved.


202-240: LGTM!

The execute_receive_lifecycle_completion function is correctly implemented. It processes the lifecycle completion and updates the message status.

The code changes are approved.


242-254: LGTM!

The execute_recover_funds function is correctly implemented. It constructs a bank message to send the recovered funds.

The code changes are approved.


256-280: LGTM!

The execute_update_wormhole_config function is correctly implemented. It checks for admin privileges and updates the configuration.

The code changes are approved.


283-305: LGTM!

The derive_intermediate_sender function is correctly implemented. It derives the intermediate sender address using SHA-256 hashing and Bech32 encoding.

The code changes are approved.

relayers/packages/wormhole/src/clients/solanaGmpWithTokenClient.ts (7)

50-55: LGTM!

The constructor is correctly implemented. It initializes the client with the provided contract address and configuration, and decodes the admin keypair from the provided private key.

The code changes are approved.


57-80: LGTM!

The initialize function is correctly implemented. It constructs and sends a transaction to initialize the contract with the provided relayer fee and precision.

The code changes are approved.


82-120: LGTM!

The registerForeignContract function is correctly implemented. It constructs and sends a transaction to register the foreign contract with the provided chain ID and contract address.

The code changes are approved.


122-175: LGTM!

The sendNative function is correctly implemented. It constructs and sends a transaction to send native tokens with a payload to a specified chain.

The code changes are approved.


177-189: LGTM!

The postVaa function is correctly implemented. It constructs and sends a transaction to post the VAA to the Solana blockchain.

The code changes are approved.


191-260: LGTM!

The redeemWrapped function is correctly implemented. It constructs and sends a transaction to redeem wrapped tokens with a VAA.

The code changes are approved.


263-275: LGTM!

The createProgram function is correctly implemented. It initializes the connection and program objects with the provided parameters.

The code changes are approved.

relayers/packages/wormhole/contracts/solana/programs/gmp_with_token/src/lib.rs (5)

20-67: LGTM!

The initialize function is correctly implemented. It initializes the contract with the provided relayer fee and precision, and sets the owner and token bridge configurations.

The code changes are approved.


69-85: LGTM!

The register_foreign_contract function is correctly implemented. It registers the foreign contract with the provided chain ID and address, and sets the configuration.

The code changes are approved.


88-102: LGTM!

The update_relayer_fee function is correctly implemented. It updates the relayer fee and precision, and sets the new values in the configuration.

The code changes are approved.


105-227: LGTM!

The send_native_tokens_with_payload function is correctly implemented. It constructs and sends a transaction to send native tokens with a payload to a specified chain.

The code changes are approved.


229-344: LGTM!

The redeem_native_transfer_with_payload function is correctly implemented. It constructs and sends a transaction to redeem native tokens with a payload.

The code changes are approved.

@@ -0,0 +1,16 @@
:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a shebang.

Adding a shebang improves portability and ensures the script runs with the correct shell.

Apply this diff to add a shebang:

+#!/bin/bash
:
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
:
#!/bin/bash
:
Tools
Shellcheck

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

Comment on lines +7 to +19
export const WormholeDataSource = new DataSource({
type: 'mysql',
host: config.DB_HOST,
port: config.DB_PORT,
username: config.DB_USERNAME,
password: config.DB_PASSWORD,
database: config.DB_NAME,
synchronize: false,
logging: false,
entities: [GmpRequest],
migrations: [],
subscribers: [],
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure secure handling of sensitive information.

Database credentials and other sensitive information should be handled securely. Consider using environment variables or a secrets management service.

Comment on lines +10 to +29
@Column({ name: 'EmitterChain', type: 'int', nullable: false })
emitterChain: number;

@Column({ name: 'EmitterAddress', type: 'nvarchar', nullable: false })
emitterAddress: string;

@Column({ name: 'Sequence', type: 'bigint', nullable: false })
sequence: string;

@Column({ name: 'Timestamp', type: 'bigint', nullable: false })
timestamp: string;

@Column({ name: 'Status', type: 'enum', enum: WormholeRequestStatus, nullable: false })
status: WormholeRequestStatus;

@Column({ name: 'ErrorReason', type: 'text', nullable: true })
errorReason?: string | null;

@Column({ name: 'Vaa', type: 'text', nullable: false })
vaa: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider changing the types of sequence and timestamp to number.

The sequence and timestamp columns are defined as bigint but are assigned string types in TypeScript. This might cause issues during runtime. Consider changing their types to number.

Apply this diff to change the types of sequence and timestamp to number:

 @Column({ name: 'Sequence', type: 'bigint', nullable: false })
-sequence: string;
+sequence: number;

 @Column({ name: 'Timestamp', type: 'bigint', nullable: false })
-timestamp: string;
+timestamp: number;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Column({ name: 'EmitterChain', type: 'int', nullable: false })
emitterChain: number;
@Column({ name: 'EmitterAddress', type: 'nvarchar', nullable: false })
emitterAddress: string;
@Column({ name: 'Sequence', type: 'bigint', nullable: false })
sequence: string;
@Column({ name: 'Timestamp', type: 'bigint', nullable: false })
timestamp: string;
@Column({ name: 'Status', type: 'enum', enum: WormholeRequestStatus, nullable: false })
status: WormholeRequestStatus;
@Column({ name: 'ErrorReason', type: 'text', nullable: true })
errorReason?: string | null;
@Column({ name: 'Vaa', type: 'text', nullable: false })
vaa: string;
@Column({ name: 'EmitterChain', type: 'int', nullable: false })
emitterChain: number;
@Column({ name: 'EmitterAddress', type: 'nvarchar', nullable: false })
emitterAddress: string;
@Column({ name: 'Sequence', type: 'bigint', nullable: false })
sequence: number;
@Column({ name: 'Timestamp', type: 'bigint', nullable: false })
timestamp: number;
@Column({ name: 'Status', type: 'enum', enum: WormholeRequestStatus, nullable: false })
status: WormholeRequestStatus;
@Column({ name: 'ErrorReason', type: 'text', nullable: true })
errorReason?: string | null;
@Column({ name: 'Vaa', type: 'text', nullable: false })
vaa: string;

Comment on lines +22 to +36
impl RedeemerConfig {
pub const MAXIMUM_SIZE: usize = 8 // discriminator
+ 32 // owner
+ 1 // bump
+ 32 // config
+ 32 // custody_signer
+ 32 // mint_authority
+ 4 // relayer_fee
+ 4; // relayer_fee_precision

pub const SEED_PREFIX: &'static [u8; 8] = token_bridge::SEED_PREFIX_REDEEMER;

pub fn compute_relayer_amount(&self, amount: u64) -> u64 {
(amount * self.relayer_fee as u64) / self.relayer_fee_precision as u64
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refactoring for readability.

The method compute_relayer_amount can be optimized for readability by using intermediate variables.

pub fn compute_relayer_amount(&self, amount: u64) -> u64 {
-    (amount * self.relayer_fee as u64) / self.relayer_fee_precision as u64
+    let fee = self.relayer_fee as u64;
+    let precision = self.relayer_fee_precision as u64;
+    (amount * fee) / precision
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
impl RedeemerConfig {
pub const MAXIMUM_SIZE: usize = 8 // discriminator
+ 32 // owner
+ 1 // bump
+ 32 // config
+ 32 // custody_signer
+ 32 // mint_authority
+ 4 // relayer_fee
+ 4; // relayer_fee_precision
pub const SEED_PREFIX: &'static [u8; 8] = token_bridge::SEED_PREFIX_REDEEMER;
pub fn compute_relayer_amount(&self, amount: u64) -> u64 {
(amount * self.relayer_fee as u64) / self.relayer_fee_precision as u64
}
impl RedeemerConfig {
pub const MAXIMUM_SIZE: usize = 8 // discriminator
+ 32 // owner
+ 1 // bump
+ 32 // config
+ 32 // custody_signer
+ 32 // mint_authority
+ 4 // relayer_fee
+ 4; // relayer_fee_precision
pub const SEED_PREFIX: &'static [u8; 8] = token_bridge::SEED_PREFIX_REDEEMER;
pub fn compute_relayer_amount(&self, amount: u64) -> u64 {
let fee = self.relayer_fee as u64;
let precision = self.relayer_fee_precision as u64;
(amount * fee) / precision
}

Comment on lines +85 to +92
async relayVaas(): Promise<void> {
const repository = WormholeDataSource.getRepository(GmpRequest);

while (true) {
await relayVaa(this.supportedEmitters, repository);
await delay(5000);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a mechanism to stop the infinite loop gracefully.

The method should include a mechanism to stop the infinite loop gracefully to ensure the application can shut down properly.

Consider adding a condition to break the loop based on an external signal or flag.

Comment on lines +95 to +147
async function relayVaa(
supportedEmitters: Map<ChainId, [string, string]>,
repository: Repository<GmpRequest>,
): Promise<void> {
let receivedVaa: GmpRequest | null = null;

try {
for (const [chainId, _] of supportedEmitters) {
receivedVaa = null;

receivedVaa = await repository.findOneBy({
emitterChain: chainId,
status: In([WormholeRequestStatus.ReceivedSignedVaa, WormholeRequestStatus.PostedSignedVaa]),
errorReason: IsNull(),
});

if (receivedVaa === null) {
continue;
}

const vaaBytes = Buffer.from(receivedVaa.vaa, 'base64');
const parsedVaa = parseTokenTransferVaa(vaaBytes);

const targetChainId = toChainId(parsedVaa.toChain);
const targetChain = toChain(parsedVaa.toChain);

if (!supportedEmitters.has(targetChainId)) {
continue;
}

const [_, targetContract] = supportedEmitters.get(targetChainId)!;

if (receivedVaa.status == WormholeRequestStatus.ReceivedSignedVaa && targetChain == 'Solana') {
await new SolanaGmpWithTokenClient(targetContract).postVaa(vaaBytes);
receivedVaa.status = WormholeRequestStatus.PostedSignedVaa;
} else if (receivedVaa.status == WormholeRequestStatus.PostedSignedVaa && targetChain == 'Solana') {
await new SolanaGmpWithTokenClient(targetContract).redeemWrapped(vaaBytes);
receivedVaa.status = WormholeRequestStatus.RedeemedSignedVaa;
} else {
throw new Error(`Chain is not supported: ${targetChain}`);
}

await repository.save(receivedVaa);
}
} catch (error) {
rootLogger.error(error);

if (receivedVaa !== null) {
receivedVaa.errorReason = error.toString();
await repository.save(receivedVaa);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for repository operations.

The function should include error handling for repository operations to ensure robustness.

Apply this diff to add error handling:

 try {
   for (const [chainId, _] of supportedEmitters) {
     receivedVaa = null;

     receivedVaa = await repository.findOneBy({
       emitterChain: chainId,
       status: In([WormholeRequestStatus.ReceivedSignedVaa, WormholeRequestStatus.PostedSignedVaa]),
       errorReason: IsNull(),
     });

     if (receivedVaa === null) {
       continue;
     }

     const vaaBytes = Buffer.from(receivedVaa.vaa, 'base64');
     const parsedVaa = parseTokenTransferVaa(vaaBytes);

     const targetChainId = toChainId(parsedVaa.toChain);
     const targetChain = toChain(parsedVaa.toChain);

     if (!supportedEmitters.has(targetChainId)) {
       continue;
     }

     const [_, targetContract] = supportedEmitters.get(targetChainId)!;

     if (receivedVaa.status == WormholeRequestStatus.ReceivedSignedVaa && targetChain == 'Solana') {
       await new SolanaGmpWithTokenClient(targetContract).postVaa(vaaBytes);
       receivedVaa.status = WormholeRequestStatus.PostedSignedVaa;
     } else if (receivedVaa.status == WormholeRequestStatus.PostedSignedVaa && targetChain == 'Solana') {
       await new SolanaGmpWithTokenClient(targetContract).redeemWrapped(vaaBytes);
       receivedVaa.status = WormholeRequestStatus.RedeemedSignedVaa;
     } else {
       throw new Error(`Chain is not supported: ${targetChain}`);
     }

     await repository.save(receivedVaa);
   }
 } catch (error) {
   rootLogger.error(error);

   if (receivedVaa !== null) {
     receivedVaa.errorReason = error.toString();
     await repository.save(receivedVaa);
   }
 }

Committable suggestion was skipped due to low confidence.

Comment on lines +34 to +82
async listenToVaas(ctx: StandardRelayerContext, next: Next): Promise<void> {
ctx.logger.info(
`Got a VAA from: ${toChain(ctx.vaa?.emitterChain ?? 0)}, ` +
`emitter: ${ctx.vaa?.emitterAddress.toString('hex')}, ` +
`sequence ${ctx.vaa?.sequence}, ` +
`hash: ${ctx.vaa?.hash.toString('hex')}`,
);

if (!isChainId(ctx.vaa!.emitterChain)) {
return await next();
}

if (!this.supportedEmitters.has(ctx.vaa!.emitterChain)) {
return await next();
}

const [_, contract] = this.supportedEmitters.get(ctx.vaa!.emitterChain)!;

const parsedVaa = parseTokenTransferPayload(ctx.vaa!.payload);

if (parsedVaa.payloadType !== TokenBridgePayload.TransferWithPayload) {
return await next();
}

const emitterAddress = parsedVaa.fromAddress?.toString('hex');

if (emitterAddress != encodeEmitterAddress(ctx.vaa!.emitterChain, contract)) {
return await next();
}

const repository = WormholeDataSource.getRepository(GmpRequest);
const existingVaa = await repository.findOneBy({ hash: ctx.vaa!.hash.toString('hex') });

if (existingVaa !== null) {
return await next();
}

await repository.save({
emitterAddress: ctx.vaa!.emitterAddress.toString('hex'),
emitterChain: ctx.vaa!.emitterChain,
hash: ctx.vaa!.hash.toString('hex'),
sequence: ctx.vaa!.sequence.toString(),
status: WormholeRequestStatus.ReceivedSignedVaa,
timestamp: ctx.vaa!.timestamp.toString(),
vaa: ctx.vaaBytes!.toString('base64'),
errorReason: null,
});

return await next();
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for repository operations.

The method should include error handling for repository operations to ensure robustness.

Apply this diff to add error handling:

 try {
   const repository = WormholeDataSource.getRepository(GmpRequest);
   const existingVaa = await repository.findOneBy({ hash: ctx.vaa!.hash.toString('hex') });

   if (existingVaa !== null) {
     return await next();
   }

   await repository.save({
     emitterAddress: ctx.vaa!.emitterAddress.toString('hex'),
     emitterChain: ctx.vaa!.emitterChain,
     hash: ctx.vaa!.hash.toString('hex'),
     sequence: ctx.vaa!.sequence.toString(),
     status: WormholeRequestStatus.ReceivedSignedVaa,
     timestamp: ctx.vaa!.timestamp.toString(),
     vaa: ctx.vaaBytes!.toString('base64'),
     errorReason: null,
   });
 } catch (error) {
   ctx.logger.error(`Failed to process VAA: ${error}`);
 }
 return await next();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async listenToVaas(ctx: StandardRelayerContext, next: Next): Promise<void> {
ctx.logger.info(
`Got a VAA from: ${toChain(ctx.vaa?.emitterChain ?? 0)}, ` +
`emitter: ${ctx.vaa?.emitterAddress.toString('hex')}, ` +
`sequence ${ctx.vaa?.sequence}, ` +
`hash: ${ctx.vaa?.hash.toString('hex')}`,
);
if (!isChainId(ctx.vaa!.emitterChain)) {
return await next();
}
if (!this.supportedEmitters.has(ctx.vaa!.emitterChain)) {
return await next();
}
const [_, contract] = this.supportedEmitters.get(ctx.vaa!.emitterChain)!;
const parsedVaa = parseTokenTransferPayload(ctx.vaa!.payload);
if (parsedVaa.payloadType !== TokenBridgePayload.TransferWithPayload) {
return await next();
}
const emitterAddress = parsedVaa.fromAddress?.toString('hex');
if (emitterAddress != encodeEmitterAddress(ctx.vaa!.emitterChain, contract)) {
return await next();
}
const repository = WormholeDataSource.getRepository(GmpRequest);
const existingVaa = await repository.findOneBy({ hash: ctx.vaa!.hash.toString('hex') });
if (existingVaa !== null) {
return await next();
}
await repository.save({
emitterAddress: ctx.vaa!.emitterAddress.toString('hex'),
emitterChain: ctx.vaa!.emitterChain,
hash: ctx.vaa!.hash.toString('hex'),
sequence: ctx.vaa!.sequence.toString(),
status: WormholeRequestStatus.ReceivedSignedVaa,
timestamp: ctx.vaa!.timestamp.toString(),
vaa: ctx.vaaBytes!.toString('base64'),
errorReason: null,
});
return await next();
try {
const repository = WormholeDataSource.getRepository(GmpRequest);
const existingVaa = await repository.findOneBy({ hash: ctx.vaa!.hash.toString('hex') });
if (existingVaa !== null) {
return await next();
}
await repository.save({
emitterAddress: ctx.vaa!.emitterAddress.toString('hex'),
emitterChain: ctx.vaa!.emitterChain,
hash: ctx.vaa!.hash.toString('hex'),
sequence: ctx.vaa!.sequence.toString(),
status: WormholeRequestStatus.ReceivedSignedVaa,
timestamp: ctx.vaa!.timestamp.toString(),
vaa: ctx.vaaBytes!.toString('base64'),
errorReason: null,
});
} catch (error) {
ctx.logger.error(`Failed to process VAA: ${error}`);
}
return await next();

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.

1 participant