文件 1 的 35:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
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);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 35:AddressUpgradeable.sol
pragma solidity ^0.8.1;
library AddressUpgradeable {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
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);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 3 的 35:IComposableOFTCoreUpgradeable.sol
pragma solidity >=0.5.0;
import "../IOFTCoreUpgradeable.sol";
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);
}
文件 4 的 35:ICrossChainDispatcher.sol
pragma solidity 0.8.9;
import "../dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/composable/IOFTReceiverUpgradeable.sol";
import "../dependencies/stargate-protocol/interfaces/IStargateReceiver.sol";
import "../dependencies/stargate-protocol/interfaces/IStargateRouter.sol";
import "../dependencies/stargate-protocol/interfaces/IStargateComposer.sol";
import "./IProxyOFT.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);
}
文件 5 的 35:IDebtToken.sol
pragma solidity 0.8.9;
import "../dependencies/openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";
import "./ISyntheticToken.sol";
interface IDebtToken is IERC20Metadata {
function lastTimestampAccrued() external view returns (uint256);
function isActive() external view returns (bool);
function syntheticToken() external view returns (ISyntheticToken);
function accrueInterest() external;
function debtIndex() external returns (uint256 debtIndex_);
function burn(address from_, uint256 amount_) external;
function issue(uint256 amount_, address to_) external returns (uint256 _issued, uint256 _fee);
function flashIssue(address to_, uint256 amount_) external returns (uint256 _issued, uint256 _fee);
function mint(address to_, uint256 amount_) external;
function repay(address onBehalfOf_, uint256 amount_) external returns (uint256 _repaid, uint256 _fee);
function repayAll(address onBehalfOf_) external returns (uint256 _repaid, uint256 _fee);
function quoteIssueIn(uint256 amountToIssue_) external view returns (uint256 _amount, uint256 _fee);
function quoteIssueOut(uint256 amount_) external view returns (uint256 _amountToIssue, uint256 _fee);
function quoteRepayIn(uint256 amountToRepay_) external view returns (uint256 _amount, uint256 _fee);
function quoteRepayOut(uint256 amount_) external view returns (uint256 _amountToRepay, uint256 _fee);
function updateMaxTotalSupply(uint256 newMaxTotalSupply_) external;
function updateInterestRate(uint256 newInterestRate_) external;
function maxTotalSupply() external view returns (uint256);
function interestRate() external view returns (uint256);
function interestRatePerSecond() external view returns (uint256);
function toggleIsActive() external;
}
文件 6 的 35:IDepositToken.sol
pragma solidity 0.8.9;
import "../dependencies/openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";
interface IDepositToken is IERC20Metadata {
function underlying() external view returns (IERC20);
function collateralFactor() external view returns (uint256);
function unlockedBalanceOf(address account_) external view returns (uint256);
function lockedBalanceOf(address account_) external view returns (uint256);
function flashWithdraw(address account_, uint256 amount_) external returns (uint256 _withdrawn, uint256 _fee);
function deposit(uint256 amount_, address onBehalfOf_) external returns (uint256 _deposited, uint256 _fee);
function quoteDepositIn(uint256 amountToDeposit_) external view returns (uint256 _amount, uint256 _fee);
function quoteDepositOut(uint256 amount_) external view returns (uint256 _amountToDeposit, uint256 _fee);
function quoteWithdrawIn(uint256 amountToWithdraw_) external view returns (uint256 _amount, uint256 _fee);
function quoteWithdrawOut(uint256 amount_) external view returns (uint256 _amountToWithdraw, uint256 _fee);
function withdraw(uint256 amount_, address to_) external returns (uint256 _withdrawn, uint256 _fee);
function seize(address from_, address to_, uint256 amount_) external;
function updateCollateralFactor(uint128 newCollateralFactor_) external;
function isActive() external view returns (bool);
function toggleIsActive() external;
function maxTotalSupply() external view returns (uint256);
function updateMaxTotalSupply(uint256 newMaxTotalSupply_) external;
function withdrawFrom(address from_, uint256 amount_) external returns (uint256 _withdrawn, uint256 _fee);
}
文件 7 的 35:IERC165Upgradeable.sol
pragma solidity ^0.8.0;
interface IERC165Upgradeable {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 8 的 35:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 9 的 35:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 10 的 35:IFeeProvider.sol
pragma solidity 0.8.9;
interface IFeeProvider {
struct LiquidationFees {
uint128 liquidatorIncentive;
uint128 protocolFee;
}
function defaultSwapFee() external view returns (uint256);
function depositFee() external view returns (uint256);
function issueFee() external view returns (uint256);
function liquidationFees() external view returns (uint128 liquidatorIncentive, uint128 protocolFee);
function repayFee() external view returns (uint256);
function swapFeeFor(address account_) external view returns (uint256);
function withdrawFee() external view returns (uint256);
}
文件 11 的 35:IGovernable.sol
pragma solidity 0.8.9;
interface IGovernable {
function governor() external view returns (address _governor);
function transferGovernorship(address _proposedGovernor) external;
}
文件 12 的 35:IManageable.sol
pragma solidity 0.8.9;
import "./IPool.sol";
interface IManageable {
function pool() external view returns (IPool _pool);
}
文件 13 的 35:IMasterOracle.sol
pragma solidity 0.8.9;
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);
}
文件 14 的 35:INativeTokenGateway.sol
pragma solidity 0.8.9;
import "./IPool.sol";
interface INativeTokenGateway {
function deposit(IPool pool_) external payable;
function withdraw(IPool pool_, uint256 amount_) external;
}
文件 15 的 35:IOFTCoreUpgradeable.sol
pragma solidity ^0.8.2;
import "../../../../../openzeppelin-upgradeable/utils/introspection/IERC165Upgradeable.sol";
interface IOFTCoreUpgradeable is IERC165Upgradeable {
function estimateSendFee(
uint16 _dstChainId,
bytes calldata _toAddress,
uint _amount,
bool _useZro,
bytes calldata _adapterParams
) external view returns (uint nativeFee, uint zroFee);
function sendFrom(
address _from,
uint16 _dstChainId,
bytes calldata _toAddress,
uint _amount,
address payable _refundAddress,
address _zroPaymentAddress,
bytes calldata _adapterParams
) external payable;
function circulatingSupply() external view returns (uint);
function token() external view returns (address);
event SendToChain(uint16 indexed _dstChainId, address indexed _from, bytes _toAddress, uint _amount);
event ReceiveFromChain(uint16 indexed _srcChainId, address indexed _to, uint _amount);
event SetUseCustomAdapterParams(bool _useCustomAdapterParams);
}
文件 16 的 35:IOFTReceiverUpgradeable.sol
pragma solidity >=0.5.0;
interface IOFTReceiverUpgradeable {
function onOFTReceived(
uint16 _srcChainId,
bytes calldata _srcAddress,
uint64 _nonce,
bytes calldata _from,
uint _amount,
bytes calldata _payload
) external;
}
文件 17 的 35:IPauseable.sol
pragma solidity 0.8.9;
interface IPauseable {
function paused() external view returns (bool);
function everythingStopped() external view returns (bool);
}
文件 18 的 35:IPool.sol
pragma solidity 0.8.9;
import "./IDepositToken.sol";
import "./IDebtToken.sol";
import "./ITreasury.sol";
import "./IRewardsDistributor.sol";
import "./IPoolRegistry.sol";
import "./IFeeProvider.sol";
import "./ISmartFarmingManager.sol";
import "./external/ISwapper.sol";
import "../interfaces/IFeeProvider.sol";
interface IPool is IPauseable, IGovernable {
function debtFloorInUsd() external view returns (uint256);
function feeCollector() external view returns (address);
function feeProvider() external view returns (IFeeProvider);
function maxLiquidable() external view returns (uint256);
function doesSyntheticTokenExist(ISyntheticToken syntheticToken_) external view returns (bool);
function doesDebtTokenExist(IDebtToken debtToken_) external view returns (bool);
function doesDepositTokenExist(IDepositToken depositToken_) external view returns (bool);
function depositTokenOf(IERC20 underlying_) external view returns (IDepositToken);
function debtTokenOf(ISyntheticToken syntheticToken_) external view returns (IDebtToken);
function getDepositTokens() external view returns (address[] memory);
function getDebtTokens() external view returns (address[] memory);
function getRewardsDistributors() external view returns (address[] memory);
function debtOf(address account_) external view returns (uint256 _debtInUsd);
function depositOf(address account_) external view returns (uint256 _depositInUsd, uint256 _issuableLimitInUsd);
function debtPositionOf(
address account_
)
external
view
returns (
bool _isHealthy,
uint256 _depositInUsd,
uint256 _debtInUsd,
uint256 _issuableLimitInUsd,
uint256 _issuableInUsd
);
function liquidate(
ISyntheticToken syntheticToken_,
address account_,
uint256 amountToRepay_,
IDepositToken depositToken_
) external returns (uint256 _totalSeized, uint256 _toLiquidator, uint256 _fee);
function quoteLiquidateIn(
ISyntheticToken syntheticToken_,
uint256 totalToSeized_,
IDepositToken depositToken_
) external view returns (uint256 _amountToRepay, uint256 _toLiquidator, uint256 _fee);
function quoteLiquidateMax(
ISyntheticToken syntheticToken_,
address account_,
IDepositToken depositToken_
) external view returns (uint256 _maxAmountToRepay);
function quoteLiquidateOut(
ISyntheticToken syntheticToken_,
uint256 amountToRepay_,
IDepositToken depositToken_
) external view returns (uint256 _totalSeized, uint256 _toLiquidator, uint256 _fee);
function quoteSwapIn(
ISyntheticToken syntheticTokenIn_,
ISyntheticToken syntheticTokenOut_,
uint256 amountOut_
) external view returns (uint256 _amountIn, uint256 _fee);
function quoteSwapOut(
ISyntheticToken syntheticTokenIn_,
ISyntheticToken syntheticTokenOut_,
uint256 amountIn_
) external view returns (uint256 _amountOut, uint256 _fee);
function swap(
ISyntheticToken syntheticTokenIn_,
ISyntheticToken syntheticTokenOut_,
uint256 amountIn_
) external returns (uint256 _amountOut, uint256 _fee);
function treasury() external view returns (ITreasury);
function masterOracle() external view returns (IMasterOracle);
function poolRegistry() external view returns (IPoolRegistry);
function addToDepositTokensOfAccount(address account_) external;
function removeFromDepositTokensOfAccount(address account_) external;
function addToDebtTokensOfAccount(address account_) external;
function removeFromDebtTokensOfAccount(address account_) external;
function getDepositTokensOfAccount(address account_) external view returns (address[] memory);
function getDebtTokensOfAccount(address account_) external view returns (address[] memory);
function isSwapActive() external view returns (bool);
function smartFarmingManager() external view returns (ISmartFarmingManager);
}
文件 19 的 35:IPoolRegistry.sol
pragma solidity 0.8.9;
import "./external/IMasterOracle.sol";
import "./IPauseable.sol";
import "./IGovernable.sol";
import "./ISyntheticToken.sol";
import "./external/ISwapper.sol";
import "./IQuoter.sol";
import "./ICrossChainDispatcher.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);
}
文件 20 的 35:IProxyOFT.sol
pragma solidity 0.8.9;
import "../dependencies/@layerzerolabs/solidity-examples/contracts-upgradeable/token/oft/composable/IComposableOFTCoreUpgradeable.sol";
interface IProxyOFT is IComposableOFTCoreUpgradeable {
function getProxyOFTOf(uint16 chainId_) external view returns (address _proxyOFT);
}
文件 21 的 35:IQuoter.sol
pragma solidity 0.8.9;
import "./IPoolRegistry.sol";
import "./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_);
}
文件 22 的 35:IRewardsDistributor.sol
pragma solidity 0.8.9;
import "../dependencies/openzeppelin/token/ERC20/IERC20.sol";
interface IRewardsDistributor {
function rewardToken() external view returns (IERC20);
function tokenSpeeds(IERC20 token_) external view returns (uint256);
function tokensAccruedOf(address account_) external view returns (uint256);
function updateBeforeMintOrBurn(IERC20 token_, address account_) external;
function updateBeforeTransfer(IERC20 token_, address from_, address to_) external;
function claimable(address account_) external view returns (uint256 _claimable);
function claimable(address account_, IERC20 token_) external view returns (uint256 _claimable);
function claimRewards(address account_) external;
function claimRewards(address account_, IERC20[] memory tokens_) external;
function claimRewards(address[] memory accounts_, IERC20[] memory tokens_) external;
function updateTokenSpeed(IERC20 token_, uint256 newSpeed_) external;
function updateTokenSpeeds(IERC20[] calldata tokens_, uint256[] calldata speeds_) external;
function tokens(uint256) external view returns (IERC20);
function tokenStates(IERC20) external view returns (uint224 index, uint32 timestamp);
function accountIndexOf(IERC20, address) external view returns (uint256);
}
文件 23 的 35:ISmartFarmingManager.sol
pragma solidity 0.8.9;
import "./IManageable.sol";
import "./IDepositToken.sol";
import "./IDebtToken.sol";
interface ISmartFarmingManager {
function flashRepay(
ISyntheticToken syntheticToken_,
IDepositToken depositToken_,
uint256 withdrawAmount_,
uint256 repayAmountMin_
) external returns (uint256 _withdrawn, uint256 _repaid);
function crossChainFlashRepay(
ISyntheticToken syntheticToken_,
IDepositToken depositToken_,
uint256 withdrawAmount_,
IERC20 bridgeToken_,
uint256 bridgeTokenAmountMin_,
uint256 swapAmountOutMin_,
uint256 repayAmountMin_,
bytes calldata lzArgs_
) external payable;
function crossChainLeverage(
IERC20 tokenIn_,
IDepositToken depositToken_,
ISyntheticToken syntheticToken_,
uint256 amountIn_,
uint256 leverage_,
uint256 swapAmountOutMin_,
uint256 depositAmountMin_,
bytes calldata lzArgs_
) external payable;
function crossChainLeverageCallback(uint256 id_, uint256 swapAmountOut_) external returns (uint256 _deposited);
function crossChainFlashRepayCallback(uint256 id_, uint256 swapAmountOut_) external returns (uint256 _repaid);
function leverage(
IERC20 tokenIn_,
IDepositToken depositToken_,
ISyntheticToken syntheticToken_,
uint256 amountIn_,
uint256 leverage_,
uint256 depositAmountMin_
) external returns (uint256 _deposited, uint256 _issued);
}
文件 24 的 35:IStargateComposer.sol
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);
}
文件 25 的 35:IStargateReceiver.sol
pragma solidity 0.8.9;
interface IStargateReceiver {
function sgReceive(
uint16 _chainId,
bytes memory _srcAddress,
uint256 _nonce,
address _token,
uint256 amountLD,
bytes memory payload
) external;
}
文件 26 的 35:IStargateRouter.sol
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);
}
文件 27 的 35:ISwapper.sol
pragma solidity 0.8.9;
interface ISwapper {
function swapExactInput(
address tokenIn_,
address tokenOut_,
uint256 amountIn_,
uint256 amountOutMin_,
address receiver_
) external returns (uint256 _amountOut);
}
文件 28 的 35:ISyntheticToken.sol
pragma solidity 0.8.9;
import "../dependencies/openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";
import "./IDebtToken.sol";
import "./IPoolRegistry.sol";
import "../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);
}
文件 29 的 35:ITreasury.sol
pragma solidity 0.8.9;
interface ITreasury {
function pull(address to_, uint256 amount_) external;
function migrateTo(address newTreasury_) external;
}
文件 30 的 35:IWETH.sol
pragma solidity 0.8.9;
import "../../dependencies/openzeppelin/token/ERC20/IERC20.sol";
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256) external;
}
文件 31 的 35:Initializable.sol
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
abstract contract Initializable {
uint8 private _initialized;
bool private _initializing;
event Initialized(uint8 version);
modifier initializer() {
bool isTopLevelCall = _setInitializedVersion(1);
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
modifier reinitializer(uint8 version) {
bool isTopLevelCall = _setInitializedVersion(version);
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(version);
}
}
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
function _disableInitializers() internal virtual {
_setInitializedVersion(type(uint8).max);
}
function _setInitializedVersion(uint8 version) private returns (bool) {
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;
}
}
}
文件 32 的 35:NativeTokenGateway.sol
pragma solidity 0.8.9;
import "./utils/ReentrancyGuard.sol";
import "./utils/TokenHolder.sol";
import "./interfaces/external/IWETH.sol";
import "./interfaces/INativeTokenGateway.sol";
import "./interfaces/IDepositToken.sol";
error SenderIsNotGovernor();
error SenderIsNotNativeToken();
error UnregisteredPool();
contract NativeTokenGateway is ReentrancyGuard, TokenHolder, INativeTokenGateway {
using SafeERC20 for IERC20;
using SafeERC20 for IWETH;
using SafeERC20 for IDepositToken;
IPoolRegistry public immutable poolRegistry;
IWETH public immutable nativeToken;
modifier onlyGovernor() {
if (poolRegistry.governor() != msg.sender) revert SenderIsNotGovernor();
_;
}
constructor(IPoolRegistry poolRegistry_, IWETH nativeToken_) initializer {
__ReentrancyGuard_init();
poolRegistry = poolRegistry_;
nativeToken = nativeToken_;
}
function deposit(IPool pool_) external payable override {
if (!poolRegistry.isPoolRegistered(address(pool_))) revert UnregisteredPool();
nativeToken.deposit{value: msg.value}();
IDepositToken _depositToken = pool_.depositTokenOf(nativeToken);
nativeToken.safeApprove(address(_depositToken), 0);
nativeToken.safeApprove(address(_depositToken), msg.value);
_depositToken.deposit(msg.value, msg.sender);
}
function withdraw(IPool pool_, uint256 amount_) external override nonReentrant {
if (!poolRegistry.isPoolRegistered(address(pool_))) revert UnregisteredPool();
IDepositToken _depositToken = pool_.depositTokenOf(nativeToken);
_depositToken.safeTransferFrom(msg.sender, address(this), amount_);
(uint256 _withdrawn, ) = _depositToken.withdraw(amount_, address(this));
nativeToken.withdraw(_withdrawn);
Address.sendValue(payable(msg.sender), _withdrawn);
}
function _requireCanSweep() internal view override onlyGovernor {}
receive() external payable override {
if (msg.sender != address(nativeToken)) revert SenderIsNotNativeToken();
}
}
文件 33 的 35:ReentrancyGuard.sol
pragma solidity ^0.8.0;
import "../dependencies/openzeppelin-upgradeable/proxy/utils/Initializable.sol";
abstract contract ReentrancyGuard is Initializable {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 34 的 35:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 35 的 35:TokenHolder.sol
pragma solidity 0.8.9;
import "../dependencies/openzeppelin/token/ERC20/utils/SafeERC20.sol";
error FallbackIsNotAllowed();
error ReceiveIsNotAllowed();
abstract contract TokenHolder {
using SafeERC20 for IERC20;
fallback() external payable {
revert FallbackIsNotAllowed();
}
receive() external payable virtual {
revert ReceiveIsNotAllowed();
}
function sweep(IERC20 token_, address to_, uint256 amount_) external {
_requireCanSweep();
if (address(token_) == address(0)) {
Address.sendValue(payable(to_), amount_);
} else {
token_.safeTransfer(to_, amount_);
}
}
function _requireCanSweep() internal view virtual;
}
{
"compilationTarget": {
"contracts/NativeTokenGateway.sol": "NativeTokenGateway"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"contract IPoolRegistry","name":"poolRegistry_","type":"address"},{"internalType":"contract IWETH","name":"nativeToken_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"FallbackIsNotAllowed","type":"error"},{"inputs":[],"name":"SenderIsNotGovernor","type":"error"},{"inputs":[],"name":"SenderIsNotNativeToken","type":"error"},{"inputs":[],"name":"UnregisteredPool","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"contract IPool","name":"pool_","type":"address"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"nativeToken","outputs":[{"internalType":"contract IWETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolRegistry","outputs":[{"internalType":"contract IPoolRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token_","type":"address"},{"internalType":"address","name":"to_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IPool","name":"pool_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]