Bridge: SynapseBridge
namespace Bridge exclusively provides the class SynapseBridge, which wraps all necessary interactions with any of the on-chain bridge contracts, which is all that is needed to complete full cross-chain flows.
Currently, Bridge.SynapseBridge wraps the following interactions:
  • Determining if a cross-chain swap between one chain/token to another chain/token is supported
  • Output estimation from one chain/token to another chain/token
  • Initiating Approval & Bridge transactions from any supported chain/token to any supported chain/token

Types

BridgeParams

Param
Type
Description
tokenFrom
Token
Origin token the user would swap to the bridge
tokenTo
Token
Destination token that the user would receive in the cross-chain swap
chainIdTo
number
Chain ID of the destination chain
amountFrom
BigNumber
Amount in native token decimals of tokenFrom that the user would bridge

BridgeOutputEstimate

Value
Type
Description
amountToReceive
BigNumber
Estimated amount to receive from a cross-chain quote, inclusive of fees & slippage.
bridgeFee
BigNumber
Cross-chain fee to bridge & swap, already included in amountToReceive calculations

BridgeTransactionParams extends BridgeParams

Param
Type
Description
amountFrom
BigNumber
Amount in token decimals of BridgeParams.tokenFrom to bridge & swap
amountTo
BigNumber
Minimum amount of BridgeParams.tokenTo to receive on the destination chain
addressTo?
string
Optional, user can provide an address other than the one retrieved from signer to receive tokens on the destination chain.

Functions

swapSupported(tokenFrom, tokenTo, chainIdTo) => [boolean, string]

Returns a bool value denoting whether a bridge from this Bridge's chain to another chain between two tokens is supported, along with a string value denoting the reason for an unsupported swap, if applicable.
Param
Type
Description
tokenFrom
Token
Origin token the user would swap to the bridge
tokenTo
Token
Destination token that the user would receive in the cross-chain swap
chainIdTo
number
Chain ID of the destination chain

async estimateBridgeTokenOutput(BridgeParams) => BridgeOutputEstimate

Returns the estimated output of a given token on the destination chain if a user was to send some amount of another given token on the origin chain.
Params: BridgeParams

buildBridgeTokenTransaction(BridgeTransactionParams) => Promise<PopulatedTransaction>

Returns a populated transaction for initiating a token bridge between this Bridge (the source chain) and the bridge contract on the destination chain. This function does not initiate a signed transaction on its own, instead provides the data signature to pass into web3/ethers.

executeBridgeTokenTransaction(BridgeTransactionParams, signer) => Promise<ContractTransaction>

Starts the Bridge process between this Bridge (the source chain) and the bridge contract on the destination chain. This function does initiate a signed transaction through the users connected wallet provider.
Returns: ContractTransaction

buildApproveTransaction(token, amount?) => Promise<PopulatedTransaction>

Builds an ethers PopulatedTransaction instance for an ERC20 Approve call, approving some amount of a given token to be spent by the Synapse Bridge on its chain.
The returned PopulatedTransaction must then be passed to the user via Web3/Ethers so they can submit the transaction. Approvals must always be called before performing any bridge transactions to ensure they don't revert.
Param
Type
Description
token
Token | string
Instance of Token or valid on-chain address of the token the user will submit to the bridge
amount
BigNumberish
Optional, a specific amount of args.token to approve. By default, this function * builds an Approve call using an "infinite" approval amount.

executeApproveTransaction({token, amount?}, signer) => Promise<ContractTransaction>

Builds a transaction as described above and instantiates a transaction for the user to submit.
Example:
let approveTxn: ContractTransaction = await SYNAPSE_BRIDGE.executeApproveTransaction({
token: TOKEN_IN
}, signer);
// Wait for at least one confirmation on the sending chain, this is an optional
// step and can be either omitted or implemented in a custom manner.
await approveTxn.wait(1);
console.log(`ERC20 Approve transaction hash: ${approveTxn.hash}`);
Copy link
On this page
Types
BridgeParams
BridgeOutputEstimate
BridgeTransactionParams extends BridgeParams
Functions
swapSupported(tokenFrom, tokenTo, chainIdTo) => [boolean, string]
async estimateBridgeTokenOutput(BridgeParams) => BridgeOutputEstimate
buildBridgeTokenTransaction(BridgeTransactionParams) => Promise<PopulatedTransaction>
executeBridgeTokenTransaction(BridgeTransactionParams, signer) => Promise<ContractTransaction>
buildApproveTransaction(token, amount?) => Promise<PopulatedTransaction>
executeApproveTransaction({token, amount?}, signer) => Promise<ContractTransaction>