@brydge-network/direct-nft-protocol

1.9.1 • Public • Published

Brydge - Multichain Portal

Brydge is a multichain protocol built on top of Stargate and LayerZero that enables users to buy digital assets and invest in DeFi using any token from any chain.

Setup

  • include MNEMONIC in a .env file
  • yarn install

Testing

yarn test
yarn test:integration

Design

  • See Docs for more detailed overview
  • There are two primary contracts deployed on each chain that handle cross-chain transactions: MultichainPortal and MultichainRouter.
    • MultichainPortal contains all the logic to swap tokens, send transactions cross chain, and execute functionality on the destination chain.
    • MultichainRouter handles all direct interactions and approvals - transfering tokens and subsequently calling functions present in MultichainPortal. The router contract was introduced to handle a specific vulnerability that was exploited here

Functions

Four main functions house all functionality needed to support purchasing digital assets using any token on any chain:

function swapERC20AndCall(
    address tokenIn,
    uint256 amountIn,
    address user,
    address swapRouter,
    bytes calldata swapArguments,
    Types.ICall[] calldata calls
) external;

function swapNativeAndCall(
    address swapRouter,
    bytes calldata swapArguments,
    Types.ICall[] calldata calls
) external payable;

function swapERC20AndSend(
    uint amountIn,
    uint amountUSDC,
    address user,
    address tokenIn,
    address swapRouter,
    bytes calldata swapArguments,
    StargateArgs memory stargateArgs
) external payable;

function swapNativeAndSend(
    uint amountIn,
    uint amountUSDC,
    uint lzFee,
    address user,
    address swapRouter,
    bytes calldata swapArguments,
    IMultichainPortal.StargateArgs memory stargateArgs
) external payable;

All four functions are present both in MultichainPortal.sol and MultichainRouter.sol. They are intended to be called by users (through our widget) in MultichainRouter.sol which forwards the call to MultichainPortal.sol where the primary logic is stored. The first two functions (swapERC20AndCall and swapNativeAndCall) are utilized when a user has any arbitrary token and wants to purchase/interact with a dapp on the same chain. Information in order to perform the swap into the desired token is passed in through arguments swapRouter and swapArguments and any subsequent contract interactions are encoded and passed as an array of calldata that is looped through and executed. The last two functions (swapERC20AndSend and swapNativeAndSend) are utilized when a user has any arbitrary token but wants to purchase/interact with a dapp on a different chain. Here we utilized Stargate's cross-chain usdc pools and messaging protocol in order to:

  1. Swap tokens into usdc on the source chain
  2. Use stargate to send them (and a payload) cross chain to our MultichainPortal contract deployed on the destination chain, and
  3. Decode the payload into arguments in order to call swapERC20AndCall on the destination cahin.

LICENSING

The primary license for Brydge is the Business Source License 1.1 (BUSL-1.1). see LICENSE.

Readme

Keywords

none

Package Sidebar

Install

npm i @brydge-network/direct-nft-protocol

Weekly Downloads

36

Version

1.9.1

License

none

Unpacked Size

482 kB

Total Files

47

Last publish

Collaborators

  • maxkatzman
  • benmacnaughton
  • zachrosen
  • kasahenry
  • alexletu