Skip to content

Add Source Network Validation in SDK Bridge Operations #16

Description

@BrianSeong99

Summary

Suggestion to add validation at the SDK level to prevent users from attempting to bridge tokens to the same network they're bridging from, before building and sending transactions to the network.

Problem Description

Currently, the bridgeTo() method in the ERC20 class and bridge operations don't validate that the destination network is different from the source network. This validation only happens at the unified bridge contract level, which means Users have to wait for transaction building, gas estimation, and network submission before getting an error

I do know that we are checking if the destination network parameter is not actually source network id in the unified bridge contract, but thinking it would be nice if we can do the checking at the sdk level already, before building the transaction and sends to the network?

Current Code Context

In src/native/tokens/erc20.ts, the bridgeTo() method:

async bridgeTo(
  destinationNetwork: number,
  destinationAddress: string,
  amount: string,
  from?: string,
  options: BridgeOptions = {}
): Promise<TransactionParams> {
  ValidationUtils.validateAddress(destinationAddress, 'Destination address');
  ValidationUtils.validateAmount(amount, 'Amount');

  const bridge = this.getBridge();

  return bridge.buildBridgeAsset(
    {
      destinationNetwork,
      destinationAddress,
      amount,
      token: this.tokenAddress,
      forceUpdateGlobalExitRoot: options.forceUpdateGlobalExitRoot ?? true,
      permitData: options.permitData || '0x',
    },
    from
  );
}

The method validates address and amount but doesn't check if destinationNetwork is the same as the current network (this.config.chainId).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions