0.3.3 • Published 2 years ago

@ericnordelo/cross-chain-bridge-helpers v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Cross-Chain Bridge Helpers

This package is intented to be used alongside the Openzeppelin cross-chain libraries, to create the corresponding required bridge config for multiple bridges.

For now supports only Arbitrum and Optimism.

Usage

  1. Install the package:

    $ yarn add @ericnordelo/cross-chain-bridge-helpers
  2. Import the L2BridgeFactory class, and load the providers after getting the instance:

     import { L2BridgeFactory } from '@ericnordelo/cross-chain-bridge-helpers';
    
     (...)
    
     const bridge = L2BridgeFactory.get('Arbitrum-L1L2');
     await bridge.loadProviders({ l1Provider, l2Provider });
  3. The providers should be loaded separately. This gives you the power to integrate with different frameworks and enviroments, just passing the providers through (ex: hardhat). For now, the library requires using ethers providers. Here is an example:

    import { L2BridgeFactory } from '@ericnordelo/cross-chain-bridge-helpers';
    import { providers } from 'ethers';
    import { config } from 'dotenv';
    
    config({ path: './path/to/.env' });
    
    const l1Provider = new providers.JsonRpcProvider(process.env.ARBITRUM_L1_RPC);
    const l2Provider = new providers.JsonRpcProvider(process.env.ARBITRUM_L2_RPC);
    
    const bridge = L2BridgeFactory.get('Arbitrum-L1L2-Rinkeby');
    await bridge.loadProviders({ l1Provider, l2Provider });
  4. Now, you can use either the getCrossChainTxConfigParameters or the getCrossChainTxConfigBytes helpers, that will return the appropriate parameters from the selected bridge:

     async getCrossChainTxConfigParameters(
       sender: string,
       destAddr: string,
       l2CallDataHex: string,
       l2CallValue: BigNumber,
     ) : Promise<object>;
    
     async getCrossChainTxConfigBytes(
       sender: string,
       destAddr: string,
       l2CallDataHex: string,
       l2CallValue: BigNumber,
     ): Promise<string>;
  5. The getCrossChainTxConfigBytes result, can be used as bridgeConfig in the Openzeppelin library.

  6. These are the accepted bridges in the current version:

    export type Bridge =
      | 'Arbitrum-L1L2'
      | 'Arbitrum-L2L1'
      | 'Optimism-L1L2'
      | 'Optimism-L2L1'
      | 'Arbitrum-L1L2-Rinkeby'
      | 'Arbitrum-L2L1-Rinkeby'
      | 'Optimism-L1L2-Kovan'
      | 'Optimism-L2L1-Kovan';
0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.3.2

2 years ago

0.2.3

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.1.3

2 years ago

0.2.5

2 years ago

0.3.3

2 years ago

0.2.4

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago