Quoter

Description:

Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "settings": {
    "evmVersion": "cancun",
    "metadata": {
      "bytecodeHash": "ipfs",
      "useLiteralContent": true
    },
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "remappings": [],
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  },
  "sources": {
    "contracts/Quoter.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {Initializable} from "./dependencies/openzeppelin-upgradeable/proxy/utils/Initializable.sol";
import {IStargateRouter} from "./dependencies/stargate-protocol/interfaces/IStargateRouter.sol";
import {QuoterStorageV1} from "./storage/QuoterStorage.sol";
import {CrossChainLib} from "./lib/CrossChainLib.sol";
import {SynthContext} from "./utils/SynthContext.sol";
import {IStargateBridge} from "./interfaces/external/IStargateBridge.sol";
import {IPoolRegistry} from "./interfaces/IPoolRegistry.sol";
import {IProxyOFT} from "./interfaces/IProxyOFT.sol";
import {ICrossChainDispatcher} from "./interfaces/ICrossChainDispatcher.sol";

error AddressIsNull();
error NotAvailableOnThisChain();

/**
 * @title Quoter contract
 */
contract Quoter is SynthContext, Initializable, QuoterStorageV1 {
    string public constant VERSION = "1.3.2";

    /**
     * @dev LayerZero adapter param version
     * See more: https://layerzero.gitbook.io/docs/evm-guides/advanced/relayer-adapter-parameters
     */
    uint16 public constant LZ_ADAPTER_PARAMS_VERSION = 2;

    /**
     * @dev Stargate swap function type
     * See more: https://stargateprotocol.gitbook.io/stargate/developers/function-types
     */
    uint8 public constant SG_TYPE_SWAP_REMOTE = 1;

    /**
     * @dev OFT packet type
     */
    uint16 public constant PT_SEND_AND_CALL = 1;

    constructor() {
        _disableInitializers();
    }

    function initialize(IPoolRegistry poolRegistry_) external initializer {
        if (address(poolRegistry_) == address(0)) revert AddressIsNull();
        _poolRegistry = poolRegistry_;
    }

    /**
     * @notice Get LZ args for the swap and callback's trigger execution
     * @dev Must be called on the chain where the swap will be executed (a.k.a. destination chain)
     * @param srcChainId_ Source chain's LZ id (i.e. user-facing chain)
     * @param dstChainId_ Destination chain's LZ id (i.e. chain used for swap)
     */
    function getFlashRepaySwapAndCallbackLzArgs(
        uint16 srcChainId_,
        uint16 dstChainId_
    ) external view returns (bytes memory _lzArgs) {
        return
            CrossChainLib.encodeLzArgs({
                dstChainId_: dstChainId_,
                callbackNativeFee_: quoteFlashRepayCallbackNativeFee(srcChainId_),
                swapTxGasLimit_: _getCrossChainDispatcher().flashRepaySwapTxGasLimit()
            });
    }

    /**
     * @notice Get LZ args for the swap and callback's trigger execution
     * @dev Must be called on the chain where the swap will be executed (a.k.a. destination chain)
     * @param srcChainId_ Source chain's LZ id (i.e. user-facing chain)
     * @param dstChainId_ Destination chain's LZ id (i.e. chain used for swap)
     */
    function getLeverageSwapAndCallbackLzArgs(
        uint16 srcChainId_,
        uint16 dstChainId_
    ) external view returns (bytes memory _lzArgs) {
        return
            CrossChainLib.encodeLzArgs({
                dstChainId_: dstChainId_,
                callbackNativeFee_: quoteLeverageCallbackNativeFee(srcChainId_),
                swapTxGasLimit_: _getCrossChainDispatcher().leverageSwapTxGasLimit()
            });
    }

    /**
     * @notice Get the LZ (native) fee for the `crossChainLeverageCallback()` call
     * @param srcChainId_ Source chain's LZ id (i.e. user-facing chain)
     * @return _callbackTxNativeFee The fee in native coin
     */
    function quoteLeverageCallbackNativeFee(uint16 srcChainId_) public view returns (uint256 _callbackTxNativeFee) {
        ICrossChainDispatcher _crossChainDispatcher = _getCrossChainDispatcher();
        (_callbackTxNativeFee, ) = _crossChainDispatcher.stargateComposer().quoteLayerZeroFee({
            _dstChainId: srcChainId_,
            _functionType: SG_TYPE_SWAP_REMOTE,
            _toAddress: abi.encodePacked(address(type(uint160).max)),
            _transferAndCallPayload: CrossChainLib.encodeLeverageCallbackPayload(
                address(type(uint160).max),
                type(uint256).max
            ),
            _lzTxParams: IStargateRouter.lzTxObj({
                dstGasForCall: _crossChainDispatcher.leverageCallbackTxGasLimit(),
                dstNativeAmount: 0,
                dstNativeAddr: ""
            })
        });
    }

    /**
     * @notice Get the LZ (native) fee for the `crossChainFlashRepayCallback()` call
     * @param srcChainId_ Source chain's LZ id (i.e. user-facing chain)
     * @return _callbackTxNativeFee The fee in native coin
     */
    function quoteFlashRepayCallbackNativeFee(uint16 srcChainId_) public view returns (uint256 _callbackTxNativeFee) {
        ICrossChainDispatcher _crossChainDispatcher = _getCrossChainDispatcher();
        uint64 _callbackTxGasLimit = _crossChainDispatcher.flashRepayCallbackTxGasLimit();

        bytes memory _lzPayload = abi.encode(
            PT_SEND_AND_CALL,
            abi.encodePacked(_msgSender()),
            abi.encodePacked(address(type(uint160).max)),
            type(uint256).max,
            CrossChainLib.encodeFlashRepayCallbackPayload(
                address(type(uint160).max),
                address(type(uint160).max),
                type(uint256).max
            ),
            _callbackTxGasLimit
        );

        (_callbackTxNativeFee, ) = IStargateBridge(_crossChainDispatcher.stargateComposer().stargateBridge())
            .layerZeroEndpoint()
            .estimateFees(
                srcChainId_,
                address(this),
                _lzPayload,
                false,
                abi.encodePacked(
                    LZ_ADAPTER_PARAMS_VERSION,
                    uint256(_crossChainDispatcher.lzBaseGasLimit() + _callbackTxGasLimit),
                    uint256(0),
                    address(0)
                )
            );
    }

    /**
     * @notice Get the LZ (native) fee for the `triggerFlashRepay()` call
     * @param proxyOFT_ The synthetic token's Proxy OFT contract
     * @param lzArgs_ The LZ args for swap transaction (See: `getFlashRepaySwapAndCallbackLzArgs()`)
     * @return _nativeFee The fee in native coin
     */
    function quoteCrossChainFlashRepayNativeFee(
        IProxyOFT proxyOFT_,
        bytes calldata lzArgs_
    ) external view returns (uint256 _nativeFee) {
        (uint16 _dstChainId, uint256 _callbackTxNativeFee, uint64 _swapTxGasLimit_) = CrossChainLib.decodeLzArgs(
            lzArgs_
        );

        bytes memory _dstProxyOFT = abi.encodePacked(proxyOFT_.getProxyOFTOf(_dstChainId));

        (_nativeFee, ) = _getCrossChainDispatcher().stargateComposer().quoteLayerZeroFee({
            _dstChainId: _dstChainId,
            _functionType: SG_TYPE_SWAP_REMOTE,
            _toAddress: _dstProxyOFT,
            _transferAndCallPayload: CrossChainLib.encodeFlashRepaySwapPayload(
                address(type(uint160).max),
                address(type(uint160).max),
                type(uint256).max,
                address(type(uint160).max),
                type(uint256).max,
                type(uint256).max
            ),
            _lzTxParams: IStargateRouter.lzTxObj({
                dstGasForCall: _swapTxGasLimit_,
                dstNativeAmount: _callbackTxNativeFee,
                dstNativeAddr: _dstProxyOFT
            })
        });
    }

    /**
     * @notice Get the LZ (native) fee for the `triggerLeverageSwap()` call
     * @param proxyOFT_ The synthetic token's Proxy OFT contract
     * @param lzArgs_ The LZ args for swap transaction (See: `getLeverageSwapAndCallbackLzArgs()`)
     * @return _nativeFee The fee in native coin
     */
    function quoteCrossChainLeverageNativeFee(
        IProxyOFT proxyOFT_,
        bytes calldata lzArgs_
    ) public view returns (uint256 _nativeFee) {
        uint16 _dstChainId;
        address _dstProxyOFT;
        bytes memory _payload;
        bytes memory _adapterParams;
        uint64 _swapTxGasLimit;
        {
            _payload = CrossChainLib.encodeLeverageSwapPayload(
                address(type(uint160).max),
                address(type(uint160).max),
                type(uint256).max,
                type(uint256).max,
                address(type(uint160).max),
                type(uint256).max,
                type(uint256).max
            );

            uint256 _callbackTxNativeFee;
            (_dstChainId, _callbackTxNativeFee, _swapTxGasLimit) = CrossChainLib.decodeLzArgs(lzArgs_);

            _dstProxyOFT = proxyOFT_.getProxyOFTOf(_dstChainId);

            _adapterParams = abi.encodePacked(
                LZ_ADAPTER_PARAMS_VERSION,
                uint256(_getCrossChainDispatcher().lzBaseGasLimit() + _swapTxGasLimit),
                _callbackTxNativeFee,
                _dstProxyOFT
            );
        }

        (_nativeFee, ) = proxyOFT_.estimateSendAndCallFee({
            _dstChainId: _dstChainId,
            _toAddress: abi.encodePacked(_dstProxyOFT),
            _amount: type(uint256).max,
            _payload: _payload,
            _dstGasForCall: _swapTxGasLimit,
            _useZro: false,
            _adapterParams: _adapterParams
        });
    }

    function _getCrossChainDispatcher() private view returns (ICrossChainDispatcher) {
        return _poolRegistry.crossChainDispatcher();
    }

    /// @inheritdoc SynthContext
    function poolRegistry() public view override returns (IPoolRegistry) {
        return _poolRegistry;
    }
}
"
    },
    "contracts/dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/IOFTCoreUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity ^0.8.2;

import "../../../../../openzeppelin-upgradeable/utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev Interface of the IOFT core standard
 */
interface IOFTCoreUpgradeable is IERC165Upgradeable {
    /**
     * @dev estimate send token `_tokenId` to (`_dstChainId`, `_toAddress`)
     * _dstChainId - L0 defined chain id to send tokens too
     * _toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain
     * _amount - amount of the tokens to transfer
     * _useZro - indicates to use zro to pay L0 fees
     * _adapterParam - flexible bytes array to indicate messaging adapter services in L0
     */
    function estimateSendFee(
        uint16 _dstChainId,
        bytes calldata _toAddress,
        uint _amount,
        bool _useZro,
        bytes calldata _adapterParams
    ) external view returns (uint nativeFee, uint zroFee);

    /**
     * @dev send `_amount` amount of token to (`_dstChainId`, `_toAddress`) from `_from`
     * `_from` the owner of token
     * `_dstChainId` the destination chain identifier
     * `_toAddress` can be any size depending on the `dstChainId`.
     * `_amount` the quantity of tokens in wei
     * `_refundAddress` the address LayerZero refunds if too much message fee is sent
     * `_zroPaymentAddress` set to address(0x0) if not paying in ZRO (LayerZero Token)
     * `_adapterParams` is a flexible bytes array to indicate messaging adapter services
     */
    function sendFrom(
        address _from,
        uint16 _dstChainId,
        bytes calldata _toAddress,
        uint _amount,
        address payable _refundAddress,
        address _zroPaymentAddress,
        bytes calldata _adapterParams
    ) external payable;

    /**
     * @dev returns the circulating amount of tokens on current chain
     */
    function circulatingSupply() external view returns (uint);

    /**
     * @dev returns the address of the ERC20 token
     */
    function token() external view returns (address);

    /**
     * @dev Emitted when `_amount` tokens are moved from the `_sender` to (`_dstChainId`, `_toAddress`)
     * `_nonce` is the outbound nonce
     */
    event SendToChain(uint16 indexed _dstChainId, address indexed _from, bytes _toAddress, uint _amount);

    /**
     * @dev Emitted when `_amount` tokens are received from `_srcChainId` into the `_toAddress` on the local chain.
     * `_nonce` is the inbound nonce.
     */
    event ReceiveFromChain(uint16 indexed _srcChainId, address indexed _to, uint _amount);

    event SetUseCustomAdapterParams(bool _useCustomAdapterParams);
}
"
    },
    "contracts/dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/composable/IComposableOFTCoreUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import "../IOFTCoreUpgradeable.sol";

/**
 * @dev Interface of the composable OFT core standard
 */
interface IComposableOFTCoreUpgradeable is IOFTCoreUpgradeable {
    function estimateSendAndCallFee(
        uint16 _dstChainId,
        bytes calldata _toAddress,
        uint _amount,
        bytes calldata _payload,
        uint64 _dstGasForCall,
        bool _useZro,
        bytes calldata _adapterParams
    ) external view returns (uint nativeFee, uint zroFee);

    function sendAndCall(
        address _from,
        uint16 _dstChainId,
        bytes calldata _toAddress,
        uint _amount,
        bytes calldata _payload,
        uint64 _dstGasForCall,
        address payable _refundAddress,
        address _zroPaymentAddress,
        bytes calldata _adapterParams
    ) external payable;

    function retryOFTReceived(
        uint16 _srcChainId,
        bytes calldata _srcAddress,
        uint64 _nonce,
        bytes calldata _from,
        address _to,
        uint _amount,
        bytes calldata _payload
    ) external;

    event CallOFTReceivedFailure(
        uint16 indexed _srcChainId,
        bytes _srcAddress,
        uint64 _nonce,
        bytes _from,
        address indexed _to,
        uint _amount,
        bytes _payload,
        bytes _reason
    );

    event CallOFTReceivedSuccess(uint16 indexed _srcChainId, bytes _srcAddress, uint64 _nonce, bytes32 _hash);

    event RetryOFTReceivedSuccess(bytes32 _messageHash);

    event NonContractAddress(address _address);
}
"
    },
    "contracts/dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/composable/IOFTReceiverUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

interface IOFTReceiverUpgradeable {
    /**
     * @dev Called by the OFT contract when tokens are received from source chain.
     * @param _srcChainId The chain id of the source chain.
     * @param _srcAddress The address of the OFT token contract on the source chain.
     * @param _nonce The nonce of the transaction on the source chain.
     * @param _from The address of the account who calls the sendAndCall() on the source chain.
     * @param _amount The amount of tokens to transfer.
     * @param _payload Additional data with no specified format.
     */
    function onOFTReceived(
        uint16 _srcChainId,
        bytes calldata _srcAddress,
        uint64 _nonce,
        bytes calldata _from,
        uint _amount,
        bytes calldata _payload
    ) external;
}
"
    },
    "contracts/dependencies/@layerzerolabs/solidity-examples/interfaces/ILayerZeroEndpoint.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import "./ILayerZeroUserApplicationConfig.sol";

interface ILayerZeroEndpoint is ILayerZeroUserApplicationConfig {
    // @notice send a LayerZero message to the specified address at a LayerZero endpoint.
    // @param _dstChainId - the destination chain identifier
    // @param _destination - the address on destination chain (in bytes). address length/format may vary by chains
    // @param _payload - a custom bytes payload to send to the destination contract
    // @param _refundAddress - if the source transaction is cheaper than the amount of value passed, refund the additional amount to this address
    // @param _zroPaymentAddress - the address of the ZRO token holder who would pay for the transaction
    // @param _adapterParams - parameters for custom functionality. e.g. receive airdropped native gas from the relayer on destination
    function send(
        uint16 _dstChainId,
        bytes calldata _destination,
        bytes calldata _payload,
        address payable _refundAddress,
        address _zroPaymentAddress,
        bytes calldata _adapterParams
    ) external payable;

    // @notice used by the messaging library to publish verified payload
    // @param _srcChainId - the source chain identifier
    // @param _srcAddress - the source contract (as bytes) at the source chain
    // @param _dstAddress - the address on destination chain
    // @param _nonce - the unbound message ordering nonce
    // @param _gasLimit - the gas limit for external contract execution
    // @param _payload - verified payload to send to the destination contract
    function receivePayload(
        uint16 _srcChainId,
        bytes calldata _srcAddress,
        address _dstAddress,
        uint64 _nonce,
        uint _gasLimit,
        bytes calldata _payload
    ) external;

    // @notice get the inboundNonce of a lzApp from a source chain which could be EVM or non-EVM chain
    // @param _srcChainId - the source chain identifier
    // @param _srcAddress - the source chain contract address
    function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint64);

    // @notice get the outboundNonce from this source chain which, consequently, is always an EVM
    // @param _srcAddress - the source chain contract address
    function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64);

    // @notice gets a quote in source native gas, for the amount that send() requires to pay for message delivery
    // @param _dstChainId - the destination chain identifier
    // @param _userApplication - the user app address on this EVM chain
    // @param _payload - the custom message to send over LayerZero
    // @param _payInZRO - if false, user app pays the protocol fee in native token
    // @param _adapterParam - parameters for the adapter service, e.g. send some dust native token to dstChain
    function estimateFees(
        uint16 _dstChainId,
        address _userApplication,
        bytes calldata _payload,
        bool _payInZRO,
        bytes calldata _adapterParam
    ) external view returns (uint nativeFee, uint zroFee);

    // @notice get this Endpoint's immutable source identifier
    function getChainId() external view returns (uint16);

    // @notice the interface to retry failed message on this Endpoint destination
    // @param _srcChainId - the source chain identifier
    // @param _srcAddress - the source chain contract address
    // @param _payload - the payload to be retried
    function retryPayload(uint16 _srcChainId, bytes calldata _srcAddress, bytes calldata _payload) external;

    // @notice query if any STORED payload (message blocking) at the endpoint.
    // @param _srcChainId - the source chain identifier
    // @param _srcAddress - the source chain contract address
    function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);

    // @notice query if the _libraryAddress is valid for sending msgs.
    // @param _userApplication - the user app address on this EVM chain
    function getSendLibraryAddress(address _userApplication) external view returns (address);

    // @notice query if the _libraryAddress is valid for receiving msgs.
    // @param _userApplication - the user app address on this EVM chain
    function getReceiveLibraryAddress(address _userApplication) external view returns (address);

    // @notice query if the non-reentrancy guard for send() is on
    // @return true if the guard is on. false otherwise
    function isSendingPayload() external view returns (bool);

    // @notice query if the non-reentrancy guard for receive() is on
    // @return true if the guard is on. false otherwise
    function isReceivingPayload() external view returns (bool);

    // @notice get the configuration of the LayerZero messaging library of the specified version
    // @param _version - messaging library version
    // @param _chainId - the chainId for the pending config change
    // @param _userApplication - the contract address of the user application
    // @param _configType - type of configuration. every messaging library has its own convention.
    function getConfig(
        uint16 _version,
        uint16 _chainId,
        address _userApplication,
        uint _configType
    ) external view returns (bytes memory);

    // @notice get the send() LayerZero messaging library version
    // @param _userApplication - the contract address of the user application
    function getSendVersion(address _userApplication) external view returns (uint16);

    // @notice get the lzReceive() LayerZero messaging library version
    // @param _userApplication - the contract address of the user application
    function getReceiveVersion(address _userApplication) external view returns (uint16);
}
"
    },
    "contracts/dependencies/@layerzerolabs/solidity-examples/interfaces/ILayerZeroUserApplicationConfig.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

interface ILayerZeroUserApplicationConfig {
    // @notice set the configuration of the LayerZero messaging library of the specified version
    // @param _version - messaging library version
    // @param _chainId - the chainId for the pending config change
    // @param _configType - type of configuration. every messaging library has its own convention.
    // @param _config - configuration in the bytes. can encode arbitrary content.
    function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external;

    // @notice set the send() LayerZero messaging library version to _version
    // @param _version - new messaging library version
    function setSendVersion(uint16 _version) external;

    // @notice set the lzReceive() LayerZero messaging library version to _version
    // @param _version - new messaging library version
    function setReceiveVersion(uint16 _version) external;

    // @notice Only when the UA needs to resume the message flow in blocking mode and clear the stored payload
    // @param _srcChainId - the chainId of the source chain
    // @param _srcAddress - the contract address of the source contract at the source chain
    function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external;
}
"
    },
    "contracts/dependencies/openzeppelin-upgradeable/proxy/utils/Initializable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = _setInitializedVersion(1);
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        bool isTopLevelCall = _setInitializedVersion(version);
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(version);
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        _setInitializedVersion(type(uint8).max);
    }

    function _setInitializedVersion(uint8 version) private returns (bool) {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
        // of initializers, because in other contexts the contract may have been reentered.
        if (_initializing) {
            require(
                version == 1 && !AddressUpgradeable.isContract(address(this)),
                "Initializable: contract is already initialized"
            );
            return false;
        } else {
            require(_initialized < version, "Initializable: contract is already initialized");
            _initialized = version;
            return true;
        }
    }
}
"
    },
    "contracts/dependencies/openzeppelin-upgradeable/utils/AddressUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
"
    },
    "contracts/dependencies/openzeppelin-upgradeable/utils/introspection/IERC165Upgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165Upgradeable {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
"
    },
    "contracts/dependencies/openzeppelin/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
"
    },
    "contracts/dependencies/openzeppelin/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
"
    },
    "contracts/dependencies/openzeppelin/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
"
    },
    "contracts/dependencies/stargate-protocol/interfaces/IStargateComposer.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.9;

import "./IStargateRouter.sol";

interface IStargateComposer {
    function swap(
        uint16 _dstChainId,
        uint256 _srcPoolId,
        uint256 _dstPoolId,
        address payable _refundAddress,
        uint256 _amountLD,
        uint256 _minAmountLD,
        IStargateRouter.lzTxObj memory _lzTxParams,
        bytes calldata _to,
        bytes calldata _payload
    ) external payable;

    function factory() external view returns (address);

    function stargateBridge() external view returns (address);

    function stargateRouter() external view returns (IStargateRouter);

    function quoteLayerZeroFee(
        uint16 _dstChainId,
        uint8 _functionType,
        bytes calldata _toAddress,
        bytes calldata _transferAndCallPayload,
        IStargateRouter.lzTxObj memory _lzTxParams
    ) external view returns (uint256, uint256);

    function peers(uint16 _chainId) external view returns (address);

    function payloadHashes(
        uint16 _srcChainId,
        bytes calldata _srcAddress,
        uint256 _nonce
    ) external view returns (bytes32);

    function clearCachedSwap(
        uint16 _srcChainId,
        bytes calldata _srcAddress,
        uint64 _nonce,
        address _receiver,
        bytes calldata _sgReceiveCallData
    ) external;
}
"
    },
    "contracts/dependencies/stargate-protocol/interfaces/IStargateReceiver.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.9;

interface IStargateReceiver {
    function sgReceive(
        uint16 _chainId,
        bytes memory _srcAddress,
        uint256 _nonce,
        address _token,
        uint256 amountLD,
        bytes memory payload
    ) external;
}
"
    },
    "contracts/dependencies/stargate-protocol/interfaces/IStargateRouter.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.9;

interface IStargateRouter {
    struct lzTxObj {
        uint256 dstGasForCall;
        uint256 dstNativeAmount;
        bytes dstNativeAddr;
    }

    function addLiquidity(uint256 _poolId, uint256 _amountLD, address _to) external;

    function swap(
        uint16 _dstChainId,
        uint256 _srcPoolId,
        uint256 _dstPoolId,
        address payable _refundAddress,
        uint256 _amountLD,
        uint256 _minAmountLD,
        lzTxObj memory _lzTxParams,
        bytes calldata _to,
        bytes calldata _payload
    ) external payable;

    function redeemRemote(
        uint16 _dstChainId,
        uint256 _srcPoolId,
        uint256 _dstPoolId,
        address payable _refundAddress,
        uint256 _amountLP,
        uint256 _minAmountLD,
        bytes calldata _to,
        lzTxObj memory _lzTxParams
    ) external payable;

    function instantRedeemLocal(uint16 _srcPoolId, uint256 _amountLP, address _to) external returns (uint256);

    function redeemLocal(
        uint16 _dstChainId,
        uint256 _srcPoolId,
        uint256 _dstPoolId,
        address payable _refundAddress,
        uint256 _amountLP,
        bytes calldata _to,
        lzTxObj memory _lzTxParams
    ) external payable;

    function sendCredits(
        uint16 _dstChainId,
        uint256 _srcPoolId,
        uint256 _dstPoolId,
        address payable _refundAddress
    ) external payable;

    function quoteLayerZeroFee(
        uint16 _dstChainId,
        uint8 _functionType,
        bytes calldata _toAddress,
        bytes calldata _transferAndCallPayload,
        lzTxObj memory _lzTxParams
    ) external view returns (uint256, uint256);

    function clearCachedSwap(uint16 _srcChainId, bytes calldata _srcAddress, uint256 _nonce) external;

    function factory() external view returns (address);

    function bridge() external view returns (address);

    function cachedSwapLookup(
        uint16 _chainId_,
        bytes calldata _srcAddress,
        uint256 _nonce
    ) external view returns (address token, uint256 amountLD, address to, bytes memory payload);
}
"
    },
    "contracts/interfaces/ICrossChainDispatcher.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IOFTReceiverUpgradeable} from "../dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/composable/IOFTReceiverUpgradeable.sol";
import {IStargateReceiver} from "../dependencies/stargate-protocol/interfaces/IStargateReceiver.sol";
import {IStargateComposer} from "../dependencies/stargate-protocol/interfaces/IStargateComposer.sol";

interface ICrossChainDispatcher is IStargateReceiver, IOFTReceiverUpgradeable {
    function crossChainDispatcherOf(uint16 chainId_) external view returns (address);

    function triggerFlashRepaySwap(
        uint256 id_,
        address payable account_,
        address tokenIn_,
        address tokenOut_,
        uint256 amountIn_,
        uint256 amountOutMin_,
        bytes calldata lzArgs_
    ) external payable;

    function triggerLeverageSwap(
        uint256 id_,
        address payable account_,
        address tokenIn_,
        address tokenOut_,
        uint256 amountIn_,
        uint256 amountOutMin,
        bytes calldata lzArgs_
    ) external payable;

    function isBridgingActive() external view returns (bool);

    function flashRepayCallbackTxGasLimit() external view returns (uint64);

    function flashRepaySwapTxGasLimit() external view returns (uint64);

    function leverageCallbackTxGasLimit() external view returns (uint64);

    function leverageSwapTxGasLimit() external view returns (uint64);

    function lzBaseGasLimit() external view returns (uint256);

    function stargateComposer() external view returns (IStargateComposer);

    function stargateSlippage() external view returns (uint256);

    function stargatePoolIdOf(address token_) external view returns (uint256);

    function isDestinationChainSupported(uint16 dstChainId_) external view returns (bool);
}
"
    },
    "contracts/interfaces/IGovernable.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

/**
 * @notice Governable interface
 */
interface IGovernable {
    function governor() external view returns (address _governor);

    function transferGovernorship(address _proposedGovernor) external;
}
"
    },
    "contracts/interfaces/IOperator.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

interface IOperator {
    struct Call {
        address target;
        uint256 value;
        bytes callData;
    }

    function getActualMsgSender() external view returns (address);

    function execute(Call[] calldata calls_) external payable returns (bytes[] memory _returnData);
}
"
    },
    "contracts/interfaces/IPauseable.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

interface IPauseable {
    function paused() external view returns (bool);

    function everythingStopped() external view returns (bool);
}
"
    },
    "contracts/interfaces/IPoolRegistry.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IMasterOracle} from "./external/IMasterOracle.sol";
import {IPauseable} from "./IPauseable.sol";
import {IGovernable} from "./IGovernable.sol";
import {ISyntheticToken} from "./ISyntheticToken.sol";
import {ISwapper} from "./external/ISwapper.sol";
import {IQuoter} from "./IQuoter.sol";
import {ICrossChainDispatcher} from "./ICrossChainDispatcher.sol";
import {IOperator} from "./IOperator.sol";

interface IPoolRegistry is IPauseable, IGovernable {
    function feeCollector() external view returns (address);

    function isPoolRegistered(address pool_) external view returns (bool);

    function nativeTokenGateway() external view returns (address);

    function getPools() external view returns (address[] memory);

    function registerPool(address pool_) external;

    function unregisterPool(address pool_) external;

    function masterOracle() external view returns (IMasterOracle);

    function updateFeeCollector(address newFeeCollector_) external;

    function idOfPool(address pool_) external view returns (uint256);

    function nextPoolId() external view returns (uint256);

    function swapper() external view returns (ISwapper);

    function quoter() external view returns (IQuoter);

    function crossChainDispatcher() external view returns (ICrossChainDispatcher);

    function doesSyntheticTokenExist(ISyntheticToken syntheticToken_) external view returns (bool _exists);

    function operator() external view returns (IOperator);

    function isGuardian(address) external view returns (bool);

    function isCrossChainFlashRepayActive() external view returns (bool);
}
"
    },
    "contracts/interfaces/IProxyOFT.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IComposableOFTCoreUpgradeable} from "../dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/composable/IComposableOFTCoreUpgradeable.sol";

interface IProxyOFT is IComposableOFTCoreUpgradeable {
    function getProxyOFTOf(uint16 chainId_) external view returns (address _proxyOFT);
}
"
    },
    "contracts/interfaces/IQuoter.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IProxyOFT} from "./IProxyOFT.sol";

interface IQuoter {
    function quoteCrossChainFlashRepayNativeFee(
        IProxyOFT proxyOFT_,
        bytes calldata lzArgs_
    ) external view returns (uint256 _nativeFee);

    function quoteCrossChainLeverageNativeFee(
        IProxyOFT proxyOFT_,
        bytes calldata lzArgs_
    ) external view returns (uint256 _nativeFee);

    function quoteLeverageCallbackNativeFee(uint16 dstChainId_) external view returns (uint256 _callbackTxNativeFee);

    function quoteFlashRepayCallbackNativeFee(uint16 dstChainId_) external view returns (uint256 _callbackTxNativeFee);

    function getFlashRepaySwapAndCallbackLzArgs(
        uint16 srcChainId_,
        uint16 dstChainId_
    ) external view returns (bytes memory lzArgs_);

    function getLeverageSwapAndCallbackLzArgs(
        uint16 srcChainId_,
        uint16 dstChainId_
    ) external view returns (bytes memory lzArgs_);
}
"
    },
    "contracts/interfaces/ISyntheticToken.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IERC20Metadata} from "../dependencies/openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";
import {IPoolRegistry} from "./IPoolRegistry.sol";
import {IProxyOFT} from "../interfaces/IProxyOFT.sol";

interface ISyntheticToken is IERC20Metadata {
    function isActive() external view returns (bool);

    function mint(address to_, uint256 amount_) external;

    function burn(address from_, uint256 amount) external;

    function poolRegistry() external view returns (IPoolRegistry);

    function toggleIsActive() external;

    function seize(address from_, address to_, uint256 amount_) external;

    function updateMaxTotalSupply(uint256 newMaxTotalSupply_) external;

    function updateProxyOFT(IProxyOFT newProxyOFT_) external;

    function maxTotalSupply() external view returns (uint256);

    function proxyOFT() external view returns (IProxyOFT);

    function amoSupply() external view returns (uint256);
}
"
    },
    "contracts/interfaces/external/IMasterOracle.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

interface IMasterOracle {
    function quoteTokenToUsd(address _asset, uint256 _amount) external view returns (uint256 _amountInUsd);

    function quoteUsdToToken(address _asset, uint256 _amountInUsd) external view returns (uint256 _amount);

    function quote(address _assetIn, address _assetOut, uint256 _amountIn) external view returns (uint256 _amountOut);
}
"
    },
    "contracts/interfaces/external/IStargateBridge.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {ILayerZeroEndpoint} from "../../dependencies/@layerzerolabs/solidity-examples/interfaces/ILayerZeroEndpoint.sol";

interface IStargateBridge {
    function layerZeroEndpoint() external view returns (ILayerZeroEndpoint _lzEndpoint);
}
"
    },
    "contracts/interfaces/external/ISwapper.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

interface ISwapper {
    function swapExactInput(
        address tokenIn_,
        address tokenOut_,
        uint256 amountIn_,
        uint256 amountOutMin_,
        address receiver_
    ) external returns (uint256 _amountOut);
}
"
    },
    "contracts/lib/CrossChainLib.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

library CrossChainLib {
    /**
     * @notice Supported cross-chain operations
     */
    uint8 public constant LEVERAGE = 1;
    uint8 public constant FLASH_REPAY = 2;

    function getOperationType(bytes memory payload_) internal pure returns (uint8 _op) {
        (_op, ) = abi.decode(payload_, (uint8, bytes));
    }

    function encodeLeverageCallbackPayload(
        address srcSmartFarmingManager_,
        uint256 requestId_
    ) internal pure returns (bytes memory _payload) {
        return abi.encode(LEVERAGE, abi.encode(srcSmartFarmingManager_, requestId_));
    }

    function decodeLeverageCallbackPayload(
        bytes memory payload_
    ) internal pure returns (address _srcSmartFarmingManager, uint256 _requestId) {
        (, payload_) = abi.decode(payload_, (uint8, bytes));
        return abi.decode(payload_, (address, uint256));
    }

    function encodeFlashRepayCallbackPayload(
        address srcProxyOFT_,
        address srcSmartFarmingManager_,
        uint256 requestId_
    ) internal pure returns (bytes memory _payload) {
        return abi.encode(FLASH_REPAY, abi.encode(srcProxyOFT_, srcSmartFarmingManager_, requestId_));
    }

    function decodeFlashRepayCallbackPayload(
        bytes memory payload_
    ) internal pure returns (address srcProxyOFT_, address _srcSmartFarmingManager, uint256 _requestId) {
        (, payload_) = abi.decode(payload_, (uint8, bytes));
        return abi.decode(payload_, (address, address, uint256));
    }

    function encodeFlashRepaySwapPayload(
        address srcSmartFarmingManager_,
        address dstProxyOFT_,
        uint256 requestId_,
        address account_,
        uint256 amountOutMin_,
        uint256 callbackTxNativeFee_
    ) internal pure returns (bytes memory _payload) {
        return
            abi.encode(
                FLASH_REPAY,
                abi.encode(
                    srcSmartFarmingManager_,
                    dstProxyOFT_,
                    requestId_,
                    account_,
                    amountOutMin_,
                    callbackTxNativeFee_
                )
            );
    }

    function decodeFlashRepaySwapPayload(
        bytes memory payload_
    )
        internal
        pure
        returns (
            address _srcSmartFarmingManager,
            address _dstProxyOFT,
            uint256 _requestId,
            address _account,
            uint256 _amountOutMin,
            uint256 _callbackTxNativeFee
        )
    {
        (, payload_) = abi.decode(payload_, (uint8, bytes));
        return abi.decode(payload_, (address, address, uint256, address, uint256, uint256));
    }

    function encodeLeverageSwapPayload(
        address srcSmartFarmingManager_,
        address dstProxyOFT_,
        uint256 requestId_,
        uint256 sgPoolId_,
        address account_,
        uint256 amountOutMin_,
        uint256 callbackTxNativeFee_
    ) internal pure returns (bytes memory _payload) {
        return
            abi.encode(
                LEVERAGE,
                abi.encode(
                    srcSmartFarmingManager_,
                    dstProxyOFT_,
                    requestId_,
                    sgPoolId_,
                    account_,
                    amountOutMin_,
                    callbackTxNativeFee_
                )
            );
    }

    function decodeLeverageSwapPayload(
        bytes memory payload_
    )
        internal
        pure
        returns (
            address _srcSmartFarmingManager,
            address _dstProxyOFT,
            uint256 _requestId,
            uint256 _sgPoolId,
            address _account,
            uint256 _amountOutMin,
            uint256 _callbackTxNativeFee
        )
    {
        (, payload_) = abi.decode(payload_, (uint8, bytes));
        return abi.decode(payload_, (address, address, uint256, uint256, address, uint256, uint256));
    }

    function encodeLzArgs(
        uint16 dstChainId_,
        uint256 callbackNativeFee_,
        uint64 swapTxGasLimit_
    ) internal pure returns (bytes memory _lzArgs) {
        return abi.encode(dstChainId_, callbackNativeFee_, swapTxGasLimit_);
    }

    function decodeLzArgs(
        bytes memory lzArgs_
    ) internal pure returns (uint16 _dstChainId, uint256 _callbackNativeFee, uint64 _swapTxGasLimit) {
        return abi.decode(lzArgs_, (uint16, uint256, uint64));
    }
}
"
    },
    "contracts/storage/QuoterStorage.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IPoolRegistry} from "../interfaces/IPoolRegistry.sol";
import {IQuoter} from "../interfaces/IQuoter.sol";

abstract contract QuoterStorageV1 is IQuoter {
    /**
     * @notice The pool registry contract
     */
    IPoolRegistry internal _poolRegistry;
}
"
    },
    "contracts/utils/SynthContext.sol": {
      "content": "// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {Context} from "../dependencies/openzeppelin/utils/Context.sol";
import {IOperator} from "../interfaces/IOperator.sol";
import {IPoolRegistry} from "../interfaces/IPoolRegistry.sol";

abstract contract SynthContext is Context {
    /// @notice Get pool registry contract
    function poolRegistry() public view virtual returns (IPoolRegistry);

    /// @inheritdoc Context
    function _msgSender() internal view virtual override returns (address) {
        IPoolRegistry _poolRegistry = poolRegistry();
        if (address(_poolRegistry) != address(0)) {
            IOperator _operator = _poolRegistry.operator();
            if (msg.sender == address(_operator)) {
                return _operator.getActualMsgSender();
            }
        }

        return msg.sender;
    }
}
"
    }
  }
}}

Tags:
ERC20, ERC165, Proxy, Mintable, Burnable, Swap, Upgradeable, Factory|addr:0x5f6c71f41232a1aeae2623c4ac7b111c38406834|verified:true|block:23726536|tx:0x40cf2e355431ef184a716d6270e5758a8582acd3485a2cb43c961cbff9eb408f|first_check:1762269943

Submitted on: 2025-11-04 16:25:45

Comments

Log in to comment.

No comments yet.