The Stargate Facet works by forwarding Stargate specific calls to a token specific router contract or to a composer contract if destination calls are involved. Stargate is a community-driven organization building the first fully composable native asset bridge, and the first dApp built on LayerZero. Stargate's vision is to make cross-chain liquidity transfer a seamless, single transaction process. Stargate is the first bridge to solve the bridging trilemma.
graph LR;
D{LiFiDiamond}-- DELEGATECALL -->A[StargateFacet]
A -- CALL --> USDC(StargateRouter)
function initStargate(ChainIdConfig[] calldata chainIdConfigs)
- Initializer method. Sets layerzero chain ids for chains.
function startBridgeTokensViaStargate(BridgeData memory _bridgeData, StargateData calldata _stargateData)
- Simply bridges tokens using Stargate
function swapAndStartBridgeTokensViaStargate(BridgeData memory _bridgeData, SwapData[] calldata _swapData, StargateData calldata _stargateData)
- Performs swap(s) before bridging tokens using Stargate
function quoteLayerZeroFee(uint256 _destinationChainId, StargateData calldata _stargateData)
- Returns a required amount for native gas fee
You need to send native gas fee that the Stargate needs to pay for the cross chain message.
To get the Cross Chain Swap Fee, you can simply call quoteLayerZeroFee
of StargateFacet contract with _stargateData
.
Some of the methods listed above take a variable labeled _stargateData
.
To populate _stargateData
you will need to get the chain ID and pool ID you are bridging from. You can visit the LayerZero Chain IDs and Pool IDs to get the list.
This data is specific to Stargate and is represented as the following struct type:
/// @param srcPoolId Source pool id.
/// @param dstPoolId Dest pool id.
/// @param minAmountLD The min qty you would accept on the destination.
/// @param dstGasForCall Additional gas fee for extra call on the destination.
/// @param refundAddress Refund address. Extra gas (if any) is returned to this address
/// @param lzFee Estimated message fee.
/// @param callTo The address to send the tokens to on the destination.
/// @param callData Additional payload.
struct StargateData {
uint256 srcPoolId;
uint256 dstPoolId;
uint256 minAmountLD;
uint256 dstGasForCall;
uint256 lzFee;
address payable refundAddress;
bytes callTo;
bytes callData;
}
Some methods accept a SwapData _swapData
parameter.
Swapping is performed by a swap specific library that expects an array of calldata to can be run on various DEXs (i.e. Uniswap) to make one or multiple swaps before performing another action.
The swap library can be found here.
Some methods accept a BridgeData _bridgeData
parameter.
This parameter is strictly for analytics purposes. It's used to emit events that we can later track and index in our subgraphs and provide data on how our contracts are being used. BridgeData
and the events we can emit can be found here.
In the following some sample calls are shown that allow you to retrieve a populated transaction that can be sent to our contract via your wallet.
All examples use our /quote endpoint to retrieve a quote which contains a transactionRequest
. This request can directly be sent to your wallet to trigger the transaction.
The quote result looks like the following:
const quoteResult = {
id: '0x...', // quote id
type: 'lifi', // the type of the quote (all lifi contract calls have the type "lifi")
tool: 'stargate', // the bridge tool used for the transaction
action: {}, // information about what is going to happen
estimate: {}, // information about the estimated outcome of the call
includedSteps: [], // steps that are executed by the contract as part of this transaction, e.g. a swap step and a cross step
transactionRequest: {
// the transaction that can be sent using a wallet
data: '0x...',
to: '0x...',
value: '0x00',
from: '{YOUR_WALLET_ADDRESS}',
chainId: 100,
gasLimit: '0x...',
gasPrice: '0x...',
},
}
A detailed explanation of how to use the /quote endpoint and how to trigger the transaction can be found here.
Hint: Don't forget to replace {YOUR_WALLET_ADDRESS}
with your real wallet address in the examples.
To get a transaction for a transfer from 20 USDC on Polygon to USDC on Fantom you can execute the following request:
curl 'https://li.quest/v1/quote?fromChain=POL&fromAmount=20000000&fromToken=USDC&toChain=FTM&toToken=USDC&slippage=0.03&allowBridges=stargate&fromAddress={YOUR_WALLET_ADDRESS}'
To get a transaction for a transfer from 10 USDT on Polygon to USDC on Fantom you can execute the following request:
curl 'https://li.quest/v1/quote?fromChain=POL&fromAmount=10000000&fromToken=USDT&toChain=FTM&toToken=USDC&slippage=0.03&allowBridges=stargate&fromAddress={YOUR_WALLET_ADDRESS}'