### Composer Receiver Contract Example Source: https://docs.stargate.finance/developers/protocol-docs/composability An example of a smart contract that implements `ILayerZeroComposer`. It emits a `ComposeAcknowledged` event and increments a counter upon receiving a composed message. ```solidity pragma solidity ^0.8.19; import { ILayerZeroComposer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroComposer.sol"; contract ComposerReceiver is ILayerZeroComposer { event ComposeAcknowledged(address indexed _from, bytes32 indexed _guid, bytes _message, address _executor, bytes _extraData); uint256 public acknowledgedCount; function lzCompose( address _from, bytes32 _guid, bytes calldata _message, address _executor, bytes calldata _extraData ) external payable { acknowledgedCount++; emit ComposeAcknowledged(_from, _guid, _message, _executor, _extraData); } fallback() external payable {} receive() external payable {} } ``` -------------------------------- ### Stargate API Quotes Request Example (URL) Source: https://docs.stargate.finance/developers/api-docs/transfer-quotes Example of a GET request to the Stargate API quotes endpoint. This URL includes all necessary parameters for a specific cross-chain transfer quote. ```http https://stargate.finance/api/v1/quotes?srcToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&srcChainKey=ethereum&dstToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&dstChainKey=arbitrum&srcAddress=0x1234567890abcdef1234567890abcdef12345678&dstAddress=0xabcdef1234567890abcdef1234567890abcdef12&srcAmount=1000000000000000000&dstAmountMin=950000000000000000 ``` -------------------------------- ### Get All Available Tokens Source: https://docs.stargate.finance/developers/api-docs/tokens Use this endpoint to fetch a list of all tokens supported by the Stargate protocol. This list is automatically updated when new tokens are added. ```HTTP GET /tokens ``` ```curl curl -X GET "https://stargate.finance/api/v1/tokens" ``` -------------------------------- ### Get List of Supported Tokens Source: https://docs.stargate.finance/developers/api-docs/overview Retrieve a list of all supported tokens by the Stargate API. ```APIDOC ## GET /api/v1/tokens ### Description Get list of supported tokens. ### Method GET ### Endpoint /api/v1/tokens ### Response #### Success Response (200) - **tokens** (array) - A list of supported token objects, each containing token details. ``` -------------------------------- ### Get List of Supported Chains Source: https://docs.stargate.finance/developers/api-docs/overview Retrieve a list of all supported chains by the Stargate API. ```APIDOC ## GET /api/v1/chains ### Description Get list of supported chains. ### Method GET ### Endpoint /api/v1/chains ### Response #### Success Response (200) - **chains** (array) - A list of supported chain objects, each containing chain details. ``` -------------------------------- ### Chains API Response Example Source: https://docs.stargate.finance/developers/api-docs/chains Example JSON response structure for the /chains endpoint, detailing the properties of supported blockchain networks and their native currencies. ```json { "chains": [ { "chainKey": "ethereum", "chainType": "evm", "chainId": 1, "shortName": "Ethereum", "name": "Ethereum", "nativeCurrency": { "chainKey": "ethereum", "name": "ETH", "symbol": "ETH", "decimals": 18, "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" } }, { "chainKey": "arbitrum", "chainType": "evm", "chainId": 42161, "shortName": "Arbitrum", "name": "Arbitrum", "nativeCurrency": { "chainKey": "arbitrum", "name": "ETH", "symbol": "ETH", "decimals": 18, "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" } }, ... ] } ``` -------------------------------- ### Get ERC20 Quotes for EVM Transfer Source: https://docs.stargate.finance/developers/tutorials/evm Use this endpoint to get quote information for transferring ERC20 tokens between EVM chains. Ensure all parameters, including token addresses, chain keys, and amounts, are correctly specified. ```bash curl -X GET "https://stargate.finance/api/v1/quotes?srcToken=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&dstToken=0x3c499c542cef5e3811e1192ce70d8cc03d5c3359&srcAddress=0x0C0d18aa99B02946C70EAC6d47b8009b993c9BfF&dstAddress=0x0C0d18aa99B02946C70EAC6d47b8009b993c9BfF&srcChainKey=ethereum&dstChainKey=polygon&srcAmount=10000000&dstAmountMin=9000000" ``` -------------------------------- ### Get Supported Chains Source: https://docs.stargate.finance/developers/api-docs/chains This endpoint returns a comprehensive list of all blockchain networks currently supported by the Stargate protocol. Use this endpoint to discover available networks for token transfers and to retrieve their configuration parameters. ```APIDOC ## GET /chains ### Description This endpoint returns a comprehensive list of all blockchain networks currently supported by the Stargate protocol. Use this endpoint to discover available networks for token transfers and to retrieve their configuration parameters. ### Method GET ### Endpoint /chains ### Response #### Success Response (200) - **chains** (array) - Array of chain objects supported by the Stargate protocol. - **chainKey** (string) - Unique identifier for the blockchain. - **chainType** (string) - Type of blockchain. - **chainId** (number) - Numeric chain identifier. - **shortName** (string) - Short display name for the chain. - **name** (string) - Full name of the blockchain. - **nativeCurrency** (object) - Information about the chain’s native currency. - **chainKey** (string) - Chain identifier for the native currency. - **name** (string) - Full name of the native currency. - **symbol** (string) - Symbol of the native currency. - **decimals** (number) - Number of decimal places for the native currency. - **address** (string) - Contract address of the native currency. ### Request Example ```curl curl -X GET "https://stargate.finance/api/v1/chains" ``` ### Response Example ```json { "chains": [ { "chainKey": "ethereum", "chainType": "evm", "chainId": 1, "shortName": "Ethereum", "name": "Ethereum", "nativeCurrency": { "chainKey": "ethereum", "name": "ETH", "symbol": "ETH", "decimals": 18, "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" } }, { "chainKey": "arbitrum", "chainType": "evm", "chainId": 42161, "shortName": "Arbitrum", "name": "Arbitrum", "nativeCurrency": { "chainKey": "arbitrum", "name": "ETH", "symbol": "ETH", "decimals": 18, "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" } } ] } ``` ``` -------------------------------- ### Stargate API Quotes Request Example (cURL) Source: https://docs.stargate.finance/developers/api-docs/transfer-quotes cURL command to fetch transfer quotes from the Stargate API. This demonstrates how to construct the request with all required query parameters. ```bash curl -X GET 'https://stargate.finance/api/v1/quotes?'\ 'srcToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&'\ 'srcChainKey=ethereum&'\ 'dstToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&'\ 'dstChainKey=arbitrum&'\ 'srcAddress=0x1234567890abcdef1234567890abcdef12345678&'\ 'dstAddress=0xabcdef1234567890abcdef1234567890abcdef12&'\ 'srcAmount=1000000000000000000&'\ 'dstAmountMin=950000000000000000' ``` -------------------------------- ### Enforce lzReceive Gas Limit for OFTs Source: https://docs.stargate.finance/ecosystem/list-on-stargate Specify enforcedOptions for lzReceive msgType 1 to set a gas limit, preventing out-of-gas issues on the source chain. This example sets a 60000 gas limit. ```solidity _options = 0x0003010011010000000000000000000000000000ea60; ``` -------------------------------- ### Get Quotes for Cross-Chain Token Transfer Source: https://docs.stargate.finance/developers/api-docs/overview Use this endpoint to retrieve quotes for a desired token transfer between chains. Ensure you provide valid token addresses, chain keys, and amounts. The `dstAmountMin` parameter helps estimate the minimum amount to receive after fees. ```javascript const response = await axios.get('https://stargate.finance/api/v1/quotes', { params: { srcToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on Ethereum dstToken: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', // USDC on Polygon srcAddress: '0x1504482b4D3E5ec88acc21bdBE0e8632d8408840', dstAddress: '0x1504482b4D3E5ec88acc21bdBE0e8632d8408840', srcChainKey: 'ethereum', dstChainKey: 'polygon', srcAmount: '1000000', // 1 USDC (6 decimals) dstAmountMin: '990000', // Amount to receive deducted by Stargate fees (max 0.15%) }, }); ``` -------------------------------- ### Initiate Immediate Omni-chain Transaction (Taxi) Source: https://docs.stargate.finance/primitives/concepts/transport This code snippet demonstrates how to initiate an immediate omnichain transaction after preparing the necessary parameters using `prepareTakeTaxi`. ```solidity StargateIntegration integration = new StargateIntegration(); // as Alice ERC20(sourceChainPoolToken).approve(stargate, amount); (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) = integration.prepareTakeTaxi(stargate, destinationEndpointId, amount, alice); IStargate(stargate).sendToken{ value: valueToSend }(sendParam, messagingFee, ALICE); ``` -------------------------------- ### Prepare Cross-Chain Send with Stargate and Compose Source: https://docs.stargate.finance/developers/protocol-docs/composability Prepares parameters for sending tokens via Stargate, including custom message payloads for cross-chain execution. Use this to set up a cross-chain transaction that includes a message for a LayerZero Composer on the destination. ```Solidity pragma solidity ^0.8.19; import { IStargate, Ticket } from "@stargatefinance/stg-evm-v2/src/interfaces/IStargate.sol"; import { MessagingFee, OFTReceipt, SendParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol"; import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol"; contract StargateIntegrationWithCompose { using OptionsBuilder for bytes; function prepareTakeTaxiAndAMMSwap( address _stargate, uint32 _dstEid, uint256 _amount, address _composer, bytes memory _composeMsg ) external view returns (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) { bytes memory extraOptions = _composeMsg.length > 0 ? OptionsBuilder.newOptions().addExecutorLzComposeOption(0, 200_000, 0) // compose gas limit : bytes(""); sendParam = SendParam({ dstEid: _dstEid, to: addressToBytes32(_composer), amountLD: _amount, minAmountLD: _amount, extraOptions: extraOptions, composeMsg: _composeMsg, oftCmd: "" }); IStargate stargate = IStargate(_stargate); (, , OFTReceipt memory receipt) = stargate.quoteOFT(sendParam); sendParam.minAmountLD = receipt.amountReceivedLD; messagingFee = stargate.quoteSend(sendParam, false); valueToSend = messagingFee.nativeFee; if (stargate.token() == address(0x0)) { valueToSend += sendParam.amountLD; } } function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } } ``` -------------------------------- ### Get Quotes Source: https://docs.stargate.finance/developers/tutorials/evm Request the Stargate API to get quotes for a transfer operation. This is the first step in initiating a cross-chain transfer. ```APIDOC ## GET /api/v1/quotes ### Description Requests quotes for a cross-chain transfer operation. ### Method GET ### Endpoint https://stargate.finance/api/v1/quotes ### Parameters #### Query Parameters - **srcToken** (string) - Required - The contract address of the source token. - **dstToken** (string) - Required - The contract address of the destination token. - **srcAddress** (string) - Required - The sender's address on the source chain. - **dstAddress** (string) - Required - The recipient's address on the destination chain. - **srcChainKey** (string) - Required - The key of the source chain (e.g., 'ethereum'). - **dstChainKey** (string) - Required - The key of the destination chain (e.g., 'polygon'). - **srcAmount** (string) - Required - The amount of the source token to transfer. - **dstAmountMin** (string) - Required - The minimum acceptable amount of the destination token. ### Request Example ``` https://stargate.finance/api/v1/quotes?srcToken=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&dstToken=0x3c499c542cef5e3811e1192ce70d8cc03d5c3359&srcAddress=0x0C0d18aa99B02946C70EAC6d47b8009b993c9BfF&dstAddress=0x0C0d18aa99B02946C70EAC6d47b8009b993c9BfF&srcChainKey=ethereum&dstChainKey=polygon&srcAmount=10000000&dstAmountMin=9000000 ``` ``` -------------------------------- ### Prepare Immediate Omni-chain Transaction (Taxi) Source: https://docs.stargate.finance/primitives/concepts/transport Use this function to prepare parameters for an immediate omnichain transaction. It quotes fees and calculates the amount to send, including native fees. ```solidity pragma solidity ^0.8.19; import { IStargate } from "@stargatefinance/stg-evm-v2/src/interfaces/IStargate.sol"; import { MessagingFee, OFTReceipt, SendParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol"; contract StargateIntegration { function prepareTakeTaxi( address _stargate, uint32 _dstEid, uint256 _amount, address _receiver ) external view returns (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) { sendParam = SendParam({ dstEid: _dstEid, to: addressToBytes32(_receiver), amountLD: _amount, minAmountLD: _amount, extraOptions: new bytes(0), composeMsg: new bytes(0), oftCmd: "" }); IStargate stargate = IStargate(_stargate); (, , OFTReceipt memory receipt) = stargate.quoteOFT(sendParam); sendParam.minAmountLD = receipt.amountReceivedLD; messagingFee = stargate.quoteSend(sendParam, false); valueToSend = messagingFee.nativeFee; if (stargate.token() == address(0x0)) { valueToSend += sendParam.amountLD; } } function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } } ``` -------------------------------- ### Initiate Omni-chain Transaction (Bus Mode) Source: https://docs.stargate.finance/primitives/concepts/transport This code snippet shows how to initiate an omnichain transaction in 'bus' mode after preparing the arguments using `prepareRideBus`. Note that bus transactions are batched and not instant. ```solidity StargateIntegration integration = new StargateIntegration(); // as Alice ERC20(sourceChainPoolToken).approve(stargate, amount); (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) = integration.prepareRideBus(stargate, destinationEndpointId, amount, alice); IStargate(stargate).sendToken{ value: valueToSend }(sendParam, messagingFee, ALICE); ``` -------------------------------- ### List Supported Chains Source: https://docs.stargate.finance/developers/api-docs/chains Retrieve a list of all blockchain networks supported by the Stargate protocol. This includes their configuration parameters necessary for token transfers. ```bash curl -X GET "https://stargate.finance/api/v1/chains" ``` -------------------------------- ### Quote Taxi Transfer Fee Source: https://docs.stargate.finance/developers/protocol-docs/fees This function is part of the ITokenMessaging interface and is used to get a fee quote for a token transfer using Taxi parameters. ```Solidity function quoteTaxi( TaxiParams calldata _params, bool _payInLzToken ) external view returns (MessagingFee memory fee); ``` -------------------------------- ### OftCmdHelper Library for Transport Modes Source: https://docs.stargate.finance/primitives/concepts/transport Provides helper functions to define transport modes for Stargate. Use `taxi()` for immediate transfers, `bus()` for batched transfers, and `drive()` to specify passengers for driving the bus. ```solidity pragma solidity ^0.8.22; library OftCmdHelper { function taxi() internal pure returns (bytes memory) { return ""; } function bus() internal pure returns (bytes memory) { return new bytes(1); } function drive(bytes memory _passengers) internal pure returns (bytes memory) { return _passengers; } } ``` -------------------------------- ### Get Quotes for Cross-Chain Token Transfers Source: https://docs.stargate.finance/developers/api-docs/overview Retrieve quotes for desired token transfers across different chains. This endpoint helps in planning and estimating cross-chain transactions. ```APIDOC ## GET /api/v1/quotes ### Description Get quotes for cross-chain token transfers. ### Method GET ### Endpoint /api/v1/quotes ### Parameters #### Query Parameters - **srcToken** (string) - Required - The source token address. - **dstToken** (string) - Required - The destination token address. - **srcAddress** (string) - Required - The source wallet address. - **dstAddress** (string) - Required - The destination wallet address. - **srcChainKey** (string) - Required - The key of the source chain. - **dstChainKey** (string) - Required - The key of the destination chain. - **srcAmount** (string) - Required - The amount of the source token to transfer. - **dstAmountMin** (string) - Required - The minimum amount of the destination token to receive, after fees. ### Request Example ```javascript //Get quotes for a USDC ETHEREUM -> USDC POLYGON transfer const response = await axios.get('https://stargate.finance/api/v1/quotes', { params: { srcToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on Ethereum dstToken: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', // USDC on Polygon srcAddress: '0x1504482b4D3E5ec88acc21bdBE0e8632d8408840', dstAddress: '0x1504482b4D3E5ec88acc21bdBE0e8632d8408840', srcChainKey: 'ethereum', dstChainKey: 'polygon', srcAmount: '1000000', // 1 USDC (6 decimals) dstAmountMin: '990000', // Amount to receive deducted by Stargate fees (max 0.15%) }, }); ``` ### Response #### Success Response (200) - **quotes** (array) - An array of available quotes for the transfer. - **transactions** (array) - An array of transactions that need to be signed and executed sequentially. ``` -------------------------------- ### Signing Raw EVM Transactions Source: https://docs.stargate.finance/developers/tutorials/evm This JavaScript code illustrates how to create and sign raw EVM transactions using a private key. It shows the process for both 'approve' and 'bridge' transaction steps obtained from the Stargate API. ```javascript // Create and sign the transaction const tx = Transaction.fromTxData( { to: approveTransaction.to, value: approveTransaction.value, data: approveTransaction.data, nonce: approveTransaction.nonce, gasLimit: approveTransaction.gasLimit, gasPrice: approveTransaction.gasPrice, }, ... ); // Sign the transaction const signedTx = tx.sign(privateKeyBuffer); // Do the same for the bridge transaction ... ``` -------------------------------- ### Prepare Omni-chain Transaction (Bus Mode) Source: https://docs.stargate.finance/primitives/concepts/transport Use this function to prepare parameters for an omnichain transaction using the 'bus' mode, which involves batched transfers. It quotes fees and calculates the amount to send. ```solidity pragma solidity ^0.8.19; import { IStargate } from "@stargatefinance/stg-evm-v2/src/interfaces/IStargate.sol"; import { MessagingFee, OFTReceipt, SendParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol"; contract StargateIntegration { function prepareRideBus( address _stargate, uint32 _dstEid, uint256 _amount, address _receiver ) external view returns (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) { sendParam = SendParam({ dstEid: _dstEid, to: addressToBytes32(_receiver), amountLD: _amount, minAmountLD: _amount, extraOptions: new bytes(0), composeMsg: new bytes(0), oftCmd: new bytes(1) }); IStargate stargate = IStargate(_stargate); (, , OFTReceipt memory receipt) = stargate.quoteOFT(sendParam); sendParam.minAmountLD = receipt.amountReceivedLD; messagingFee = stargate.quoteSend(sendParam, false); valueToSend = messagingFee.nativeFee; if (stargate.token() == address(0x0)) { valueToSend += sendParam.amountLD; } } function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } } ``` -------------------------------- ### Get ERC20 Transfer Quotes Source: https://docs.stargate.finance/developers/api-docs/transfer-quotes Use this endpoint to retrieve available quotes for cross-chain token transfers via the Stargate protocol. Ensure all required parameters are correctly formatted. ```http GET /quotes ``` -------------------------------- ### Stargate Internal Send Compose Call Source: https://docs.stargate.finance/developers/protocol-docs/composability This is how Stargate internally calls LayerZero's `Endpoint.sendCompose` on the destination chain. It passes the receiver, GUID, compose index, and the composed message. ```solidity endpoint.sendCompose(_payload.receiver, _guid, _payload.composeIdx, composeMsg); ``` -------------------------------- ### Convert SendParam to TaxiParams Source: https://docs.stargate.finance/developers/protocol-docs/fees Demonstrates how to programmatically convert a SendParam object to TaxiParams using a helper function and a conversion rate. ```Solidity using MessagingHelper for SendParam; // ... function _ld2sd(uint256 _amountLD) internal view returns (uint64 amountSD) { unchecked { amountSD = SafeCast.toUint64(_amountLD / convertRate); } } // ... uint64 amountSD = _ld2sd(sendParam.amountLD); sendParam.toTaxiParams(amountSD) ``` -------------------------------- ### Get Transfer Quotes Source: https://docs.stargate.finance/developers/api-docs/transfer-quotes The ERC20 Routes endpoint returns a list of available quotes containing the required transactions needed to complete a cross-chain transfer between supported networks using the Stargate protocol. Note: The Stargate API is being deprecated. Please migrate to the new LayerZero Value Transfer API. ```APIDOC ## GET /quotes ### Description Retrieves a list of available quotes for cross-chain token transfers. ### Method GET ### Endpoint /quotes ### Parameters #### Query Parameters - **srcToken** (string) - Required - Token contract address on the source chain. - **dstToken** (string) - Required - Token contract address on the destination chain. - **srcAddress** (string) - Required - Your wallet address on the source chain. - **dstAddress** (string) - Required - Your wallet address on the destination chain. - **srcChainKey** (string) - Required - Identifier for the source blockchain (e.g., `arbitrum`, `optimism`, `ethereum`). - **dstChainKey** (string) - Required - Identifier for the destination blockchain. - **srcAmount** (string) - Required - The amount of tokens you wish to transfer (in smallest unit). - **dstAmountMin** (string) - Required - The minimum amount expected on the destination chain after fees. ### Request Example ``` https://stargate.finance/api/v1/quotes?srcToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&srcChainKey=ethereum&dstToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&dstChainKey=arbitrum&srcAddress=0x1234567890abcdef1234567890abcdef12345678&dstAddress=0xabcdef1234567890abcdef1234567890abcdef12&srcAmount=1000000000000000000&dstAmountMin=950000000000000000 ``` ### Response #### Success Response (200) - **quotes** (array) - Required - Array of available transfer quote objects. - **bridge** (string) - Required - Bridge protocol identifier (e.g., "StargateV1Bridge:taxi"). - **srcAddress** (string) - Required - Source wallet address. - **dstAddress** (string) - Required - Destination wallet address. - **srcChainKey** (string) - Required - Source blockchain identifier. - **dstChainKey** (string) - Required - Destination blockchain identifier. - **error** (string) - Required - Error message if route is invalid, null otherwise. - **srcToken** (string) - Required - Token address on source chain. - **dstToken** (string) - Required - Token address on destination chain. - **srcAmount** (string) - Required - Amount to transfer in wei format. - **srcAmountMax** (string) - Required - Maximum amount that can be transferred. - **dstAmount** (string) - Required - Expected amount to receive on destination chain. - **dstAmountMin** (string) - Required - Minimum amount to receive on destination chain. - **duration** (object) - Required - Transfer duration information. - **estimated** (number) - Required - Estimated transfer time in seconds. - **allowance** (string) - Required - Current token allowance for the bridge contract. - **dstNativeAmount** (string) - Required - Amount of native tokens on destination chain. - **fees** (array) - Required - Array of fee objects for the transfer. - **steps** (array) - Required - Array of transaction steps required for the transfer. ### Response Example ```json { "quotes": [ { "bridge": "StargateV1Bridge:taxi", "srcAddress": "0x1234567890abcdef1234567890abcdef12345678", "dstAddress": "0xabcdef1234567890abcdef1234567890abcdef12", "srcChainKey": "ethereum", "dstChainKey": "arbitrum", "error": null, "srcToken": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "dstToken": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "srcAmount": "1000000000000000000", "srcAmountMax": "1000000000000000000", "dstAmount": "980000000000000000", "dstAmountMin": "950000000000000000", "duration": { "estimated": 120 }, "allowance": "1000000000000000000", "dstNativeAmount": "50000000000000000", "fees": [ { "type": "StargateFee", "amount": "10000000000000000" } ], "steps": [ { "action": "approve", "token": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "owner": "0x1234567890abcdef1234567890abcdef12345678", "spender": "0xStargateBridgeAddress", "amount": "1000000000000000000" }, { "action": "transfer", "from": "0x1234567890abcdef1234567890abcdef12345678", "to": "0xStargateBridgeAddress", "amount": "1000000000000000000" } ] } ] } ``` -------------------------------- ### List Available Tokens Source: https://docs.stargate.finance/developers/api-docs/tokens Retrieves a list of all tokens supported by the Stargate protocol, including details on their bridgeability, chain, contract address, decimals, symbol, name, and price. ```APIDOC ## GET /tokens ### Description This endpoint returns a list of tokens available for cross-chain transfers via the Stargate protocol. It provides token details, bridging capabilities, contract addresses, and current price information across supported blockchains. ### Method GET ### Endpoint /tokens ### Parameters #### Query Parameters - **srcChainKey** (string) - Optional - Filter tokens by source chain identifier ("ethereum", "arbitrum"). - **srcToken** (string) - Optional - Filter by token address on the source chain. Returns only tokens with available transfer routes from the specified token. ### Request Example ```bash curl -X GET "https://stargate.finance/api/v1/tokens" ``` ### Response #### Success Response (200) - **tokens** (array) - Required - Array of token objects supported by the Stargate protocol. - **isBridgeable** (boolean) - Required - Indicates whether the token can be bridged across chains. - **chainKey** (string) - Required - Unique identifier for the blockchain (e.g., “ethereum”, “arbitrum”). - **address** (string) - Required - Contract address of the token. - **decimals** (number) - Required - Number of decimal places for the token. - **symbol** (string) - Required - Symbol of the token (e.g., “ETH”, “USDC”). - **name** (string) - Required - Full name of the token. - **price** (object) - Required - Current price information for the token. - **price.usd** (number) - Required - Current price in USD. #### Response Example ```json { "tokens": [ { "isBridgeable": true, "chainKey": "ethereum", "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "decimals": 18, "symbol": "ETH", "name": "ETH", "price": { "usd": 2516.72546608367 } }, { "isBridgeable": false, "chainKey": "ethereum", "address": "0xfcb42A0e352a08AbD50b8EE68d01f581B6Dfd80A", "decimals": 18, "symbol": "S*ETH", "name": "ETH-LP", "price": { "usd": 2516.72546608367 } }, { "isBridgeable": false, "chainKey": "ethereum", "address": "0x5DaAee9EF143faFF495B581e9863570e83F99d31", "decimals": 6, "symbol": "S*USDC", "name": "USDC-LP", "price": { "usd": 0.9998755200373645 } }, ... ] } ``` ``` -------------------------------- ### Prepare Stargate Take Taxi Transaction Source: https://docs.stargate.finance/developers/protocol-docs/transfer Prepares an omnichain transaction for immediate asset bridging. Ensure all necessary imports and contract addresses are correctly set up. ```solidity pragma solidity ^0.8.19; import { IStargate } from "@stargatefinance/stg-evm-v2/src/interfaces/IStargate.sol"; import { MessagingFee, OFTReceipt, SendParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol"; contract StargateIntegration { function prepareTakeTaxi( address _stargate, uint32 _dstEid, uint256 _amount, address _receiver ) external view returns (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) { sendParam = SendParam({ dstEid: _dstEid, to: addressToBytes32(_receiver), amountLD: _amount, minAmountLD: _amount, // Will be updated with quote extraOptions: new bytes(0), // Default, can be customized composeMsg: new bytes(0), // Default, can be customized oftCmd: "" // Empty for taxi mode }); IStargate stargate = IStargate(_stargate); // Get accurate minimum amount from quote (, , OFTReceipt memory receipt) = stargate.quoteOFT(sendParam); sendParam.minAmountLD = receipt.amountReceivedLD; // Get messaging fee messagingFee = stargate.quoteSend(sendParam, false); // false for not paying with ZRO valueToSend = messagingFee.nativeFee; // If sending native gas token, add amount to valueToSend if (stargate.token() == address(0x0)) { valueToSend += sendParam.amountLD; } } function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } } ``` -------------------------------- ### Execute Cross-Chain Send Transaction Source: https://docs.stargate.finance/developers/protocol-docs/composability Executes the cross-chain send transaction using the parameters prepared by `prepareTakeTaxiAndAMMSwap`. Ensure the `valueToSend` correctly accounts for native fees and token amounts. ```Solidity bytes memory _composeMsg = abi.encode(_tokenReceiver, _oftOnDestination, _tokenOut, _amountOutMinDest, _deadline); (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) = integration.prepareTakeTaxiAndAMMSwap(stargate, destinationEndpointId, amount, address(composer), _composeMsg); IStargate stargate = IStargate(stargate); IStargate(stargate).sendToken{ value: valueToSend }(sendParam, messagingFee, refundAddress); ``` -------------------------------- ### Prepare Omnichain Transfer in Bus Mode Source: https://docs.stargate.finance/developers/protocol-docs/transfer Prepares parameters for an omnichain transfer using Stargate's bus mode. This function calculates the required native fee and sets up the send parameters, including specifying 'bus mode' with `oftCmd: bytes(1)`. ```solidity pragma solidity ^0.8.19; import { IStargate } from "@stargatefinance/stg-evm-v2/src/interfaces/IStargate.sol"; import { MessagingFee, OFTReceipt, SendParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol"; contract StargateIntegration { function prepareRideBus( address _stargate, uint32 _dstEid, uint256 _amount, address _receiver ) external view returns (uint256 valueToSend, SendParam memory sendParam, MessagingFee memory messagingFee) { sendParam = SendParam({ dstEid: _dstEid, to: addressToBytes32(_receiver), amountLD: _amount, minAmountLD: _amount, // Will be updated with quote extraOptions: new bytes(0), // Default, can be customized composeMsg: new bytes(0), // Default, can be customized oftCmd: new bytes(1) // bytes(1) for bus mode }); IStargate stargate = IStargate(_stargate); // Get accurate minimum amount from quote (, , OFTReceipt memory receipt) = stargate.quoteOFT(sendParam); sendParam.minAmountLD = receipt.amountReceivedLD; // Get messaging fee messagingFee = stargate.quoteSend(sendParam, false); // false for not paying with ZRO valueToSend = messagingFee.nativeFee; // If sending native gas token, add amount to valueToSend if (stargate.token() == address(0x0)) { valueToSend += sendParam.amountLD; } } function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } } ``` -------------------------------- ### SendParam Struct for OFT Send Operation Source: https://docs.stargate.finance/primitives/concepts/transport Details the parameters required for an OFT send operation, including destination, recipient, amounts, and optional fields for LayerZero messages and OFT commands. Pay close attention to extraOptions and oftCmd for Stargate-specific transport modes. ```solidity /** * @dev Struct representing token parameters for the OFT send() operation. */ struct SendParam { uint32 dstEid; // Destination endpoint ID. bytes32 to; // Recipient address. uint256 amountLD; // Amount to send in local decimals. uint256 minAmountLD; // Minimum amount to send in local decimals. bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message. bytes composeMsg; // The composed message for the send() operation. bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations. } ``` -------------------------------- ### Query Available Transfer Quotes Source: https://docs.stargate.finance/developers/api-docs/overview This snippet demonstrates how to fetch available transfer quotes using the Stargate API. It's a prerequisite for creating and signing transactions. ```javascript const quotes = await axios.get("https://stargate.finance/api/v1/quotes", { ... }); ``` -------------------------------- ### Add Executor Lz Compose Option Source: https://docs.stargate.finance/developers/protocol-docs/composability Use `OptionsBuilder` to add an executor Lz Compose option when the `composeMsg` is non-empty. This option specifies the gas limit for the compose call. ```solidity bytes memory extraOptions = _composeMsg.length > 0 ? OptionsBuilder.newOptions().addExecutorLzComposeOption(0, 200_000, 0) // compose gas limit : bytes(""); ``` -------------------------------- ### OftCmdHelper Library for Transportation Modes Source: https://docs.stargate.finance/developers/protocol-docs/transfer Provides helper functions to define the `oftCmd` for Stargate's transportation modes. Use empty bytes for 'taxi' mode, `bytes(1)` for 'bus' mode, or a bytes array of passengers to 'drive' the bus. ```solidity pragma solidity ^0.8.22; library OftCmdHelper { function taxi() internal pure returns (bytes memory) { return ""; // Empty bytes for "taxi" } function bus() internal pure returns (bytes memory) { return new bytes(1); // bytes(1) for riding a bus } function drive(bytes memory _passengers) internal pure returns (bytes memory) { return _passengers; // bytes array of _passengers to drive a bus } } ``` -------------------------------- ### quoteSend Source: https://docs.stargate.finance/developers/protocol-docs/fees Calculates the total fee for a given send() operation. It reverts with InvalidAmount if the send mode is drive but a value is specified. ```APIDOC ## quoteSend ### Description This method provides a way to calculate the total fee for a given `send()` operation. It reverts with `InvalidAmount` if the send mode is drive but a value is specified. ### Method `quoteSend` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * `_sendParam` (SendParam) - Required - The parameters for the send operation. See `quoteOFT` for `SendParam` details. * `_payInLzToken` (bool) - Required - A boolean indicating whether to pay the fee in LayerZero token. ### Request Example None provided in source. ### Response #### Success Response (200) * `fee` (MessagingFee) - The messaging fee details. * `nativeFee` (uint256) - The fee in the native token. * `lzTokenFee` (uint256) - The fee in LayerZero token. #### Response Example ```json { "nativeFee": "1000000000000000000", "lzTokenFee": "500000000000000000" } ``` ```