Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 21049851 | 546 days ago | Contract Creation | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
RangoSatelliteFacet
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 10000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
import "../../interfaces/IWETH.sol";
import "../../interfaces/IRangoSatellite.sol";
import "../../interfaces/IRango.sol";
import "../../interfaces/IAxelarGateway.sol";
import "../../interfaces/IAxelarGasService.sol";
import "../../interfaces/IUniswapV2.sol";
import "../../interfaces/IRangoMessageReceiver.sol";
import "../../interfaces/Interchain.sol";
import "../../libraries/LibInterchain.sol";
import "../../utils/LibTransform.sol";
import "../../utils/ReentrancyGuard.sol";
import "../../libraries/LibDiamond.sol";
import "../../libraries/LibPausable.sol";
/// @title The root contract that handles Rango's interaction with satellite
/// @author 0xiden
/// @dev This facet should be added to diamond. This facet doesn't and shouldn't receive messages. Handling messages is done through middleware.
contract RangoSatelliteFacet is IRango, ReentrancyGuard, IRangoSatellite {
/// Storage ///
bytes32 internal constant SATELLITE_NAMESPACE = keccak256("exchange.rango.facets.satellite");
struct SatelliteStorage {
/// @notice The address of satellite contract
address gatewayAddress;
/// @notice The address of satellite gas service contract
address gasService;
}
/// @notice Emitted when the satellite gateway address is updated
/// @param _oldAddress The previous address
/// @param _newAddress The new address
event SatelliteGatewayAddressUpdated(address _oldAddress, address _newAddress);
/// @notice Emitted when the satellite gasService address is updated
/// @param _oldAddress The previous address
/// @param _newAddress The new address
event SatelliteGasServiceAddressUpdated(address _oldAddress, address _newAddress);
/// @notice Initialize the contract.
/// @param addresses The addresses of whitelist contracts for bridge
function initSatellite(SatelliteStorage calldata addresses) external {
LibDiamond.enforceIsContractOwner();
updateSatelliteGatewayInternal(addresses.gatewayAddress);
updateSatelliteGasServiceInternal(addresses.gasService);
}
/// @notice Updates the address of satellite gateway contract
/// @param _address The new address of satellite gateway contract
function updateSatelliteGatewayAddress(address _address) public {
LibDiamond.enforceIsContractOwner();
updateSatelliteGatewayInternal(_address);
}
/// @notice Updates the address of satellite gasService contract
/// @param _address The new address of satellite gasService contract
function updateSatelliteGasServiceAddress(address _address) public {
LibDiamond.enforceIsContractOwner();
updateSatelliteGasServiceInternal(_address);
}
/// @notice Emitted when an ERC20 token (non-native) bridge request is sent to satellite bridge
/// @param _dstChainId The network id of destination chain, ex: 56 for BSC
/// @param _token The requested token to bridge
/// @param _receiver The receiver address in the destination chain
/// @param _amount The requested amount to bridge
event SatelliteSendTokenCalled(uint256 _dstChainId, address _token, string _receiver, uint256 _amount);
/// @notice Executes a DEX (arbitrary) call + a Satellite bridge call
/// @param request The general swap request containing from/to token and fee/affiliate rewards
/// @param calls The list of DEX calls, if this list is empty, it means that there is no DEX call and we are only bridging
/// @param bridgeRequest required data for the bridging step, including the destination chain and recipient wallet address
function satelliteSwapAndBridge(
LibSwapper.SwapRequest memory request,
LibSwapper.Call[] calldata calls,
SatelliteBridgeRequest memory bridgeRequest
) external payable nonReentrant {
LibPausable.enforceNotPaused();
uint bridgeAmount;
// if toToken is native coin and the user has not paid fee in msg.value,
// then the user can pay bridge fee using output of swap.
if (request.toToken == LibSwapper.ETH && msg.value == 0) {
bridgeAmount = LibSwapper.onChainSwapsPreBridge(request, calls, 0) - bridgeRequest.relayerGas;
}
else {
bridgeAmount = LibSwapper.onChainSwapsPreBridge(request, calls, bridgeRequest.relayerGas);
}
doSatelliteBridge(bridgeRequest, request.toToken, bridgeAmount);
// event emission
emit RangoBridgeInitiated(
request.requestId,
request.toToken,
bridgeAmount,
LibTransform.stringToAddress(bridgeRequest.receiver),
bridgeRequest.toChainId,
bridgeRequest.bridgeType == SatelliteBridgeType.TRANSFER_WITH_MESSAGE,
false,
uint8(BridgeType.Axelar),
request.dAppTag,
request.dAppName
);
}
/// @notice Executes a bridging via satellite
/// @param request The extra fields required by the satellite bridge
function satelliteBridge(
SatelliteBridgeRequest memory request,
RangoBridgeRequest memory bridgeRequest
) external payable nonReentrant {
LibPausable.enforceNotPaused();
uint amount = bridgeRequest.amount;
address token = bridgeRequest.token;
uint amountWithFee = amount + LibSwapper.sumFees(bridgeRequest);
// transfer tokens if necessary
if (token != LibSwapper.ETH) {
SafeERC20.safeTransferFrom(IERC20(token), msg.sender, address(this), amountWithFee);
require(msg.value >= request.relayerGas);
} else {
require(msg.value >= amountWithFee + request.relayerGas);
}
LibSwapper.collectFees(bridgeRequest);
doSatelliteBridge(request, token, amount);
// event emission
emit RangoBridgeInitiated(
bridgeRequest.requestId,
token,
amount,
LibTransform.stringToAddress(request.receiver),
request.toChainId,
request.bridgeType == SatelliteBridgeType.TRANSFER_WITH_MESSAGE,
false,
uint8(BridgeType.Axelar),
bridgeRequest.dAppTag,
bridgeRequest.dAppName
);
}
/// @notice Executes a bridging via satellite
/// @param request The extra fields required by the satellite bridge
/// @param token The requested token to bridge
/// @param amount The requested amount to bridge
function doSatelliteBridge(
SatelliteBridgeRequest memory request,
address token,
uint256 amount
) internal {
SatelliteStorage storage s = getSatelliteStorage();
uint dstChainId = request.toChainId;
require(s.gatewayAddress != LibSwapper.ETH, 'Satellite gateway address not set');
require(block.chainid != dstChainId, 'Invalid destination Chain! Cannot bridge to the same network.');
LibSwapper.BaseSwapperStorage storage baseStorage = LibSwapper.getBaseSwapperStorage();
address bridgeToken = token;
address refAddress = request.srcGasRefundAddress;
if (token == LibSwapper.ETH) {
bridgeToken = baseStorage.WETH;
IWETH(bridgeToken).deposit{value : amount}();
}
if (refAddress == LibSwapper.ETH) {
refAddress = msg.sender;
}
require(bridgeToken != LibSwapper.ETH, 'Source token address is null! Not supported by axelar!');
LibSwapper.approveMax(bridgeToken, s.gatewayAddress, amount);
if (request.bridgeType == SatelliteBridgeType.TRANSFER) {
require(request.relayerGas == 0, 'No relayerGas for sendToken');
IAxelarGateway(s.gatewayAddress).sendToken(request.toChain, request.receiver, request.symbol, amount);
emit SatelliteSendTokenCalled(dstChainId, bridgeToken, request.receiver, amount);
} else {
require(s.gasService != LibSwapper.ETH, 'Satellite gasService address not set');
require(request.relayerGas > 0, 'axelar needs native fee for relayer');
bytes memory payload = request.bridgeType == SatelliteBridgeType.TRANSFER_WITH_MESSAGE
? request.imMessage
: new bytes(0);
IAxelarGasService(s.gasService).payNativeGasForContractCallWithToken{value : request.relayerGas}(
address(this),
request.toChain,
request.receiver,
payload,
request.symbol,
amount,
refAddress
);
IAxelarGateway(s.gatewayAddress).callContractWithToken(
request.toChain,
request.receiver,
payload,
request.symbol,
amount
);
}
}
function updateSatelliteGatewayInternal(address _address) private {
require(_address != address(0), "Invalid Gateway Address");
SatelliteStorage storage s = getSatelliteStorage();
address oldAddress = s.gatewayAddress;
s.gatewayAddress = _address;
emit SatelliteGatewayAddressUpdated(oldAddress, _address);
}
function updateSatelliteGasServiceInternal(address _address) private {
require(_address != address(0), "Invalid GasService Address");
SatelliteStorage storage s = getSatelliteStorage();
address oldAddress = s.gasService;
s.gasService = _address;
emit SatelliteGasServiceAddressUpdated(oldAddress, _address);
}
/// @dev fetch local storage
function getSatelliteStorage() private pure returns (SatelliteStorage storage s) {
bytes32 namespace = SATELLITE_NAMESPACE;
// solhint-disable-next-line no-inline-assembly
assembly {
s.slot := namespace
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
bytes memory returndata = address(token).functionCall(abi.encodeCall(token.transfer, (to, value)));
if (address(token)!=0xa614f803B6FD780986A42c78Ec9c7f77e6DeD13C && returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
// _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// 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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import './IUpgradable.sol';
// This should be owned by the microservice that is paying for gas.
interface IAxelarGasService is IUpgradable {
error NothingReceived();
error TransferFailed();
error InvalidAddress();
error NotCollector();
error InvalidAmounts();
event GasPaidForContractCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForContractCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForContractCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForContractCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
uint256 gasFeeAmount,
address refundAddress
);
event GasAdded(bytes32 indexed txHash, uint256 indexed logIndex, address gasToken, uint256 gasFeeAmount, address refundAddress);
event NativeGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, uint256 gasFeeAmount, address refundAddress);
// This is called on the source chain before calling the gateway to execute a remote contract.
function payGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
// This is called on the source chain before calling the gateway to execute a remote contract.
function payGasForContractCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
// This is called on the source chain before calling the gateway to execute a remote contract.
function payNativeGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;
// This is called on the source chain before calling the gateway to execute a remote contract.
function payNativeGasForContractCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address refundAddress
) external payable;
function addGas(
bytes32 txHash,
uint256 txIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
function addNativeGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable;
function collectFees(
address payable receiver,
address[] calldata tokens,
uint256[] calldata amounts
) external;
function refund(
address payable receiver,
address token,
uint256 amount
) external;
function gasCollector() external returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
interface IAxelarGateway {
function sendToken(
string calldata destinationChain,
string calldata destinationAddress,
string calldata symbol,
uint256 amount
) external;
function callContract(
string calldata destinationChain,
string calldata contractAddress,
bytes calldata payload
) external;
function callContractWithToken(
string calldata destinationChain,
string calldata contractAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount
) external;
function validateContractCall(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash
) external returns (bool);
function validateContractCallAndMint(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash,
string calldata symbol,
uint256 amount
) external returns (bool);
function tokenAddresses(string memory symbol) external view returns (address);
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.25;
/// @dev based on Curve router contract https://github.com/curvefi/curve-router-ng/blob/master/contracts/Router.vy
interface ICurve {
function exchange(
address [11] calldata _route,
uint256 [5][5] calldata _swap_params,
uint256 _amount,
uint256 _expected,
address [5] calldata _pools,
address _receiver
) external payable returns (uint256 amountOut);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
interface IDiamondCut {
enum FacetCutAction {
Add,
Replace,
Remove
}
// Add=0, Replace=1, Remove=2
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
/// @notice Add/replace/remove any number of functions and optionally execute
/// a function with delegatecall
/// @param _diamondCut Contains the facet addresses and function selectors
/// @param _init The address of the contract or facet to execute _calldata
/// @param _calldata A function call, including function selector and arguments
/// _calldata is executed with delegatecall on _init
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external;
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
/// @title An interface to interchain message types
/// @author Uchiha Sasuke
interface Interchain {
enum ActionType { NO_ACTION, UNI_V2, UNI_V3, CALL, CURVE }
enum CallSubActionType { WRAP, UNWRAP, NO_ACTION }
struct RangoInterChainMessage {
address requestId;
uint64 dstChainId;
// @dev bridgeRealOutput is only used to disambiguate receipt of WETH and ETH and SHOULD NOT be used anywhere else!
address bridgeRealOutput;
address toToken;
address originalSender;
address recipient;
ActionType actionType;
bytes action;
CallSubActionType postAction;
uint16 dAppTag;
// Extra message
bytes dAppMessage;
address dAppSourceContract;
address dAppDestContract;
}
struct UniswapV2Action {
address dexAddress;
uint amountOutMin;
address[] path;
uint deadline;
}
struct UniswapV3ActionExactInputParams {
address dexAddress;
address tokenIn;
address tokenOut;
bytes encodedPath;
uint256 deadline;
uint256 amountOutMinimum;
bool isRouter2;
}
/// @notice The requested call data which is computed off-chain and passed to the contract
/// @param target The dex contract address that should be called
/// @param overwriteAmount if true, by using startIndexForAmount actual value will be used for swap
/// @param startIndexForAmount if overwriteAmount is false, this parameter will be ignored. must be byte number
/// @param callData The required data field that should be give to the dex contract to perform swap
struct CallAction {
address tokenIn;
address spender;
CallSubActionType preAction;
address payable target;
bool overwriteAmount;
uint256 startIndexForAmount;
bytes callData;
}
/// @notice the data needed to call `exchange` method for swap via Curve
struct CurveAction {
address routerContractAddress;
address [11] routes;
uint256 [5][5] swap_params;
uint256 expected;
address [5] pools;
address toToken;
}
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
interface IRango {
struct RangoBridgeRequest {
address requestId;
address token;
uint amount;
uint platformFee;
uint affiliateFee;
address payable affiliatorAddress;
uint destinationExecutorFee;
uint16 dAppTag;
string dAppName;
}
enum BridgeType {
Across,
CBridge,
Hop,
Hyphen,
Multichain,
Stargate,
Synapse,
Thorchain,
Symbiosis,
Axelar,
Voyager,
Poly,
OptimismBridge,
ArbitrumBridge,
Wormhole,
AllBridge,
CCTP,
Connext,
NitroAssetForwarder,
DeBridge,
YBridge,
Swft,
Orbiter,
ChainFlip
}
/// @notice Status of cross-chain swap
/// @param Succeeded The whole process is success and end-user received the desired token in the destination
/// @param RefundInSource Bridge was out of liquidity and middle asset (ex: USDC) is returned to user on source chain
/// @param RefundInDestination Our handler on dest chain this.executeMessageWithTransfer failed and we send middle asset (ex: USDC) to user on destination chain
/// @param SwapFailedInDestination Everything was ok, but the final DEX on destination failed (ex: Market price change and slippage)
enum CrossChainOperationStatus {
Succeeded,
RefundInSource,
RefundInDestination,
SwapFailedInDestination
}
event RangoBridgeInitiated(
address indexed requestId,
address bridgeToken,
uint256 bridgeAmount,
address receiver,
uint destinationChainId,
bool hasInterchainMessage,
bool hasDestinationSwap,
uint8 indexed bridgeId,
uint16 indexed dAppTag,
string dAppName
);
event RangoBridgeCompleted(
address indexed requestId,
address indexed token,
address indexed originalSender,
address receiver,
uint amount,
CrossChainOperationStatus status,
uint16 dAppTag
);
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
interface IRangoMessageReceiver {
enum ProcessStatus { SUCCESS, REFUND_IN_SOURCE, REFUND_IN_DESTINATION }
function handleRangoMessage(
address token,
uint amount,
ProcessStatus status,
bytes memory message
) external;
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
interface IRangoMiddlewareWhitelists {
function addWhitelist(address contractAddress) external;
function removeWhitelist(address contractAddress) external;
function isContractWhitelisted(address _contractAddress) external view returns (bool);
function isMessagingContractWhitelisted(address _messagingContract) external view returns (bool);
function updateWeth(address _weth) external;
function getWeth() external view returns (address);
function getRangoDiamond() external view returns (address);
function isMiddlewaresPaused(address _middleware) external view returns (bool);
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
import "./Interchain.sol";
import "./IRango.sol";
import "../libraries/LibSwapper.sol";
/// @title An interface to RangoSatellite.sol contract to improve type hinting
/// @author 0xiden
interface IRangoSatellite {
enum SatelliteBridgeType {TRANSFER, TRANSFER_WITH_MESSAGE}
/// @dev symbol is case sensitive
/// @param receiver The receiver address in the destination chain
/// @param toChainId The network id of destination chain, ex: 56 for BSC
/// @param toChain The name of the network, 'binance' for BSC
/// @param symbol The name of token, 'axlUSDC'
/// @param relayerGas The amount of native token to provide to relayer
/// @param refundAddress The address to receive extra gas
struct SatelliteBridgeRequest {
SatelliteBridgeType bridgeType;
string receiver;
uint256 toChainId;
string toChain;
string symbol;
uint256 relayerGas;
address srcGasRefundAddress;
bytes imMessage;
}
function satelliteSwapAndBridge(
LibSwapper.SwapRequest memory request,
LibSwapper.Call[] calldata calls,
IRangoSatellite.SatelliteBridgeRequest memory bridgeRequest
) external payable;
function satelliteBridge(
SatelliteBridgeRequest memory request,
IRango.RangoBridgeRequest memory bridgeRequest
) external payable;
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.25;
/// @dev based on swap router of uniswap v2 https://docs.uniswap.org/protocol/V2/reference/smart-contracts/router-02#swapexactethfortokens
interface IUniswapV2 {
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
// For pangolin and trader joe
function swapExactAVAXForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.25;
/// @dev based on IswapRouter of UniswapV3 https://docs.uniswap.org/protocol/reference/periphery/interfaces/ISwapRouter
interface IUniswapV3 {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
struct ExactInputParamsRouter2 {
bytes path;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
function exactInput(ExactInputParamsRouter2 calldata params) external payable returns (uint256 amountOut);
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.25;
// General interface for upgradable contracts
interface IUpgradable {
error NotOwner();
error InvalidOwner();
error InvalidCodeHash();
error InvalidImplementation();
error SetupFailed();
error NotProxy();
event Upgraded(address indexed newImplementation);
event OwnershipTransferred(address indexed newOwner);
// Get current owner
function owner() external view returns (address);
function contractId() external pure returns (bytes32);
function implementation() external view returns (address);
function upgrade(
address newImplementation,
bytes32 newImplementationCodeHash,
bytes calldata params
) external;
function setup(bytes calldata data) external;
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.25;
interface IWETH {
function deposit() external payable;
function withdraw(uint256) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { IDiamondCut } from "../interfaces/IDiamondCut.sol";
/// Implementation of EIP-2535 Diamond Standard
/// https://eips.ethereum.org/EIPS/eip-2535
library LibDiamond {
/// Storage ///
bytes32 internal constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage");
// Diamond specific errors
error IncorrectFacetCutAction();
error NoSelectorsInFacet();
error FunctionAlreadyExists();
error FacetAddressIsZero();
error FacetAddressIsNotZero();
error FacetContainsNoCode();
error FunctionDoesNotExist();
error FunctionIsImmutable();
error InitZeroButCalldataNotEmpty();
error CalldataEmptyButInitNotZero();
error InitReverted();
// ----------------
struct FacetAddressAndPosition {
address facetAddress;
uint96 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array
}
struct FacetFunctionSelectors {
bytes4[] functionSelectors;
uint256 facetAddressPosition; // position of facetAddress in facetAddresses array
}
struct DiamondStorage {
// maps function selector to the facet address and
// the position of the selector in the facetFunctionSelectors.selectors array
mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition;
// maps facet addresses to function selectors
mapping(address => FacetFunctionSelectors) facetFunctionSelectors;
// facet addresses
address[] facetAddresses;
// Used to query if a contract implements an interface.
// Used to implement ERC-165.
mapping(bytes4 => bool) supportedInterfaces;
// owner of the contract
address contractOwner;
}
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
// solhint-disable-next-line no-inline-assembly
assembly {
ds.slot := position
}
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function setContractOwner(address _newOwner) internal {
DiamondStorage storage ds = diamondStorage();
address previousOwner = ds.contractOwner;
ds.contractOwner = _newOwner;
emit OwnershipTransferred(previousOwner, _newOwner);
}
function contractOwner() internal view returns (address contractOwner_) {
contractOwner_ = diamondStorage().contractOwner;
}
function enforceIsContractOwner() internal view {
require(msg.sender == diamondStorage().contractOwner, "LibDiamond: Must be contract owner");
}
event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);
// Internal function version of diamondCut
function diamondCut(
IDiamondCut.FacetCut[] memory _diamondCut,
address _init,
bytes memory _calldata
) internal {
for (uint256 facetIndex; facetIndex < _diamondCut.length; ) {
IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action;
if (action == IDiamondCut.FacetCutAction.Add) {
addFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors);
} else if (action == IDiamondCut.FacetCutAction.Replace) {
replaceFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors);
} else if (action == IDiamondCut.FacetCutAction.Remove) {
removeFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors);
} else {
revert IncorrectFacetCutAction();
}
unchecked {
++facetIndex;
}
}
emit DiamondCut(_diamondCut, _init, _calldata);
initializeDiamondCut(_init, _calldata);
}
function addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {
if (_facetAddress == address(0)) {
revert FacetAddressIsZero();
}
if (_functionSelectors.length == 0) {
revert NoSelectorsInFacet();
}
DiamondStorage storage ds = diamondStorage();
uint96 selectorPosition = uint96(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length);
// add new facet address if it does not exist
if (selectorPosition == 0) {
addFacet(ds, _facetAddress);
}
for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; ) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress;
if (oldFacetAddress != address(0)) {
revert FunctionAlreadyExists();
}
addFunction(ds, selector, selectorPosition, _facetAddress);
unchecked {
++selectorPosition;
++selectorIndex;
}
}
}
function replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {
if (_functionSelectors.length == 0) {
revert NoSelectorsInFacet();
}
if (_facetAddress == address(0)) {
revert FacetAddressIsZero();
}
DiamondStorage storage ds = diamondStorage();
uint96 selectorPosition = uint96(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length);
// add new facet address if it does not exist
if (selectorPosition == 0) {
addFacet(ds, _facetAddress);
}
for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; ) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress;
if (oldFacetAddress == _facetAddress) {
revert FunctionAlreadyExists();
}
removeFunction(ds, oldFacetAddress, selector);
addFunction(ds, selector, selectorPosition, _facetAddress);
unchecked {
++selectorPosition;
++selectorIndex;
}
}
}
function removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {
if (_functionSelectors.length == 0) {
revert NoSelectorsInFacet();
}
DiamondStorage storage ds = diamondStorage();
// if function does not exist then do nothing and return
if (_facetAddress != address(0)) {
revert FacetAddressIsNotZero();
}
for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; ) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress;
removeFunction(ds, oldFacetAddress, selector);
unchecked {
++selectorIndex;
}
}
}
function addFacet(DiamondStorage storage ds, address _facetAddress) internal {
enforceHasContractCode(_facetAddress);
ds.facetFunctionSelectors[_facetAddress].facetAddressPosition = ds.facetAddresses.length;
ds.facetAddresses.push(_facetAddress);
}
function addFunction(
DiamondStorage storage ds,
bytes4 _selector,
uint96 _selectorPosition,
address _facetAddress
) internal {
ds.selectorToFacetAndPosition[_selector].functionSelectorPosition = _selectorPosition;
ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(_selector);
ds.selectorToFacetAndPosition[_selector].facetAddress = _facetAddress;
}
function removeFunction(
DiamondStorage storage ds,
address _facetAddress,
bytes4 _selector
) internal {
if (_facetAddress == address(0)) {
revert FunctionDoesNotExist();
}
// an immutable function is a function defined directly in a diamond
if (_facetAddress == address(this)) {
revert FunctionIsImmutable();
}
// replace selector with last selector, then delete last selector
uint256 selectorPosition = ds.selectorToFacetAndPosition[_selector].functionSelectorPosition;
uint256 lastSelectorPosition = ds.facetFunctionSelectors[_facetAddress].functionSelectors.length - 1;
// if not the same then replace _selector with lastSelector
if (selectorPosition != lastSelectorPosition) {
bytes4 lastSelector = ds.facetFunctionSelectors[_facetAddress].functionSelectors[lastSelectorPosition];
ds.facetFunctionSelectors[_facetAddress].functionSelectors[selectorPosition] = lastSelector;
ds.selectorToFacetAndPosition[lastSelector].functionSelectorPosition = uint96(selectorPosition);
}
// delete the last selector
ds.facetFunctionSelectors[_facetAddress].functionSelectors.pop();
delete ds.selectorToFacetAndPosition[_selector];
// if no more selectors for facet address then delete the facet address
if (lastSelectorPosition == 0) {
// replace facet address with last facet address and delete last facet address
uint256 lastFacetAddressPosition = ds.facetAddresses.length - 1;
uint256 facetAddressPosition = ds.facetFunctionSelectors[_facetAddress].facetAddressPosition;
if (facetAddressPosition != lastFacetAddressPosition) {
address lastFacetAddress = ds.facetAddresses[lastFacetAddressPosition];
ds.facetAddresses[facetAddressPosition] = lastFacetAddress;
ds.facetFunctionSelectors[lastFacetAddress].facetAddressPosition = facetAddressPosition;
}
ds.facetAddresses.pop();
delete ds.facetFunctionSelectors[_facetAddress].facetAddressPosition;
}
}
function initializeDiamondCut(address _init, bytes memory _calldata) internal {
if (_init == address(0)) {
if (_calldata.length != 0) {
revert InitZeroButCalldataNotEmpty();
}
} else {
if (_calldata.length == 0) {
revert CalldataEmptyButInitNotZero();
}
if (_init != address(this)) {
enforceHasContractCode(_init);
}
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory error) = _init.delegatecall(_calldata);
if (!success) {
if (error.length > 0) {
// bubble up the error
revert(string(error));
} else {
revert InitReverted();
}
}
}
}
function enforceHasContractCode(address _contract) internal view {
uint256 contractSize;
// solhint-disable-next-line no-inline-assembly
assembly {
contractSize := extcodesize(_contract)
}
if (contractSize == 0) {
revert FacetContainsNoCode();
}
}
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IUniswapV2.sol";
import "../interfaces/IUniswapV3.sol";
import "../interfaces/ICurve.sol";
import "../interfaces/IWETH.sol";
import "../interfaces/Interchain.sol";
import "../interfaces/IRangoMessageReceiver.sol";
import "../interfaces/IRangoMiddlewareWhitelists.sol";
import "./LibSwapper.sol";
library LibInterchain {
/// Storage ///
bytes32 internal constant LIBINTERCHAIN_CONTRACT_NAMESPACE = keccak256("exchange.rango.library.interchain");
struct BaseInterchainStorage {
address whitelistsStorageContract;
}
/// @notice This event indicates that a dApp used Rango messaging (dAppMessage field) and we delivered the message to it
/// @param _receiverContract The address of dApp's contract that was called
/// @param _token The address of the token that is sent to the dApp, ETH for native token
/// @param _amount The amount of the token sent to them
/// @param _status The status of operation, informing the dApp that the whole process was a success or refund
/// @param _appMessage The custom message that the dApp asked Rango to deliver
/// @param success Indicates that the function call to the dApp encountered error or not
/// @param failReason If success = false, failReason will be the string reason of the failure (aka message of require)
event CrossChainMessageCalled(
address _receiverContract,
address _token,
uint _amount,
IRangoMessageReceiver.ProcessStatus _status,
bytes _appMessage,
bool success,
string failReason
);
event ActionDone(Interchain.ActionType actionType, address contractAddress, bool success, string reason);
event SubActionDone(Interchain.CallSubActionType subActionType, address contractAddress, bool success, string reason);
event WhitelistStorageAddressUpdated(address _oldAddress, address _newAddress);
/// @notice is used to check if a contract is whitelisted or not
/// @param _contractAddress the address of the contract to be checked
/// @return true if contract is whitelisted
function isContractWhitelisted(address _contractAddress) internal view returns(bool) {
address whitelistsContractAddress = getLibInterchainStorage().whitelistsStorageContract;
return IRangoMiddlewareWhitelists(whitelistsContractAddress).isContractWhitelisted(_contractAddress);
}
/// @notice is used to check if a DApp is whitelisted or not
/// @param _messagingContract the address of the DApp to be checked
/// @return true if DApp is whitelisted
function isMessagingContractWhitelisted(address _messagingContract) internal view returns(bool) {
address s = getLibInterchainStorage().whitelistsStorageContract;
return IRangoMiddlewareWhitelists(s).isMessagingContractWhitelisted(_messagingContract);
}
/// @notice updates the address of whitelists storage
/// @param _storageContract new address
function updateWhitelistsContractAddress(address _storageContract) internal {
require(_storageContract != address(0), "Invalid storage contract address");
BaseInterchainStorage storage baseStorage = getLibInterchainStorage();
address oldAddress = baseStorage.whitelistsStorageContract;
baseStorage.whitelistsStorageContract = _storageContract;
emit WhitelistStorageAddressUpdated(oldAddress, _storageContract);
}
function handleDestinationMessage(
address _token,
uint _amount,
Interchain.RangoInterChainMessage memory m
) internal returns (address, uint256 dstAmount, IRango.CrossChainOperationStatus status) {
address sourceToken = m.bridgeRealOutput == LibSwapper.ETH && _token == getWeth() ? LibSwapper.ETH : _token;
bool ok = true;
address receivedToken = sourceToken;
dstAmount = _amount;
if (m.actionType == Interchain.ActionType.UNI_V2)
(ok, dstAmount, receivedToken) = _handleUniswapV2(sourceToken, _amount, m);
else if (m.actionType == Interchain.ActionType.UNI_V3)
(ok, dstAmount, receivedToken) = _handleUniswapV3(sourceToken, _amount, m);
else if (m.actionType == Interchain.ActionType.CALL)
(ok, dstAmount, receivedToken) = _handleCall(sourceToken, _amount, m);
else if (m.actionType == Interchain.ActionType.CURVE)
(ok, dstAmount, receivedToken) = _handleCurve(sourceToken, _amount, m);
else if (m.actionType != Interchain.ActionType.NO_ACTION)
revert("Unsupported actionType");
if (ok && m.postAction != Interchain.CallSubActionType.NO_ACTION) {
(ok, dstAmount, receivedToken) = _handlePostAction(receivedToken, dstAmount, m.postAction);
}
status = ok ? IRango.CrossChainOperationStatus.Succeeded : IRango.CrossChainOperationStatus.RefundInDestination;
IRangoMessageReceiver.ProcessStatus dAppStatus = ok
? IRangoMessageReceiver.ProcessStatus.SUCCESS
: IRangoMessageReceiver.ProcessStatus.REFUND_IN_DESTINATION;
_sendTokenWithDApp(receivedToken, dstAmount, m.recipient, m.dAppMessage, m.dAppDestContract, dAppStatus);
return (receivedToken, dstAmount, status);
}
/// @notice Performs a uniswap-v2 operation
/// @param _message The interchain message that contains the swap info
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handleUniswapV2(
address _token,
uint _amount,
Interchain.RangoInterChainMessage memory _message
) private returns (bool ok, uint256 amountOut, address outToken) {
Interchain.UniswapV2Action memory action = abi.decode((_message.action), (Interchain.UniswapV2Action));
address weth = getWeth();
if (isContractWhitelisted(action.dexAddress) != true) {
// "Dex address is not whitelisted"
return (false, _amount, _token);
}
if (action.path.length < 2) {
// "Invalid uniswap-V2 path"
return (false, _amount, _token);
}
bool shouldDeposit = _token == LibSwapper.ETH && action.path[0] == weth;
if (!shouldDeposit) {
if (_token != action.path[0]) {
// "bridged token must be the same as the first token in destination swap path"
return (false, _amount, _token);
}
} else {
IWETH(weth).deposit{value : _amount}();
}
LibSwapper.approve(action.path[0], action.dexAddress, _amount);
address toToken = action.path[action.path.length - 1];
uint toBalanceBefore = LibSwapper.getBalanceOf(toToken);
try
IUniswapV2(action.dexAddress).swapExactTokensForTokens(
_amount,
action.amountOutMin,
action.path,
address(this),
action.deadline
)
returns (uint256[] memory) {
emit ActionDone(Interchain.ActionType.UNI_V2, action.dexAddress, true, "");
// Note: instead of using return amounts of swapExactTokensForTokens,
// we get the diff balance of before and after. This prevents errors for tokens with transfer fees
uint toBalanceAfter = LibSwapper.getBalanceOf(toToken);
SafeERC20.forceApprove(IERC20(action.path[0]), action.dexAddress, 0);
return (true, toBalanceAfter - toBalanceBefore, toToken);
} catch {
emit ActionDone(Interchain.ActionType.UNI_V2, action.dexAddress, false, "Uniswap-V2 call failed");
SafeERC20.forceApprove(IERC20(action.path[0]), action.dexAddress, 0);
return (false, _amount, shouldDeposit ? weth : _token);
}
}
/// @notice Performs a uniswap-v3 operation
/// @param _message The interchain message that contains the swap info
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handleUniswapV3(
address _token,
uint _amount,
Interchain.RangoInterChainMessage memory _message
) private returns (bool, uint256, address) {
Interchain.UniswapV3ActionExactInputParams memory action = abi
.decode((_message.action), (Interchain.UniswapV3ActionExactInputParams));
if (isContractWhitelisted(action.dexAddress) != true) {
// "Dex address is not whitelisted"
return (false, _amount, _token);
}
address toToken = action.tokenOut;
{
bytes memory encodedPath = action.encodedPath;
address toTokenFromPath;
uint256 encodedPathLen = action.encodedPath.length;
assembly {
toTokenFromPath := mload(add(encodedPath, encodedPathLen))
}
if (toTokenFromPath != toToken) {
// swap output token address mismatch
return (false, _amount, _token);
}
}
address weth = getWeth();
bool shouldDeposit = _token == LibSwapper.ETH && action.tokenIn == weth;
if (!shouldDeposit) {
if (_token != action.tokenIn) {
// "bridged token must be the same as the tokenIn in uniswapV3"
return (false, _amount, _token);
}
} else {
IWETH(weth).deposit{value : _amount}();
}
LibSwapper.approve(action.tokenIn, action.dexAddress, _amount);
uint toBalanceBefore = LibSwapper.getBalanceOf(toToken);
if (action.isRouter2 == false) {
try
IUniswapV3(action.dexAddress).exactInput(IUniswapV3.ExactInputParams({
path : action.encodedPath,
recipient : address(this),
deadline : action.deadline,
amountIn : _amount,
amountOutMinimum : action.amountOutMinimum
}))
returns (uint) {
emit ActionDone(Interchain.ActionType.UNI_V3, action.dexAddress, true, "");
// Note: instead of using return amounts of exactInput,
// we get the diff balance of before and after. This prevents errors for tokens with transfer fees.
uint toBalanceAfter = LibSwapper.getBalanceOf(toToken);
SafeERC20.forceApprove(IERC20(action.tokenIn), action.dexAddress, 0);
return (true, toBalanceAfter - toBalanceBefore, toToken);
} catch {
emit ActionDone(Interchain.ActionType.UNI_V3, action.dexAddress, false, "Uniswap-V3 call failed");
SafeERC20.forceApprove(IERC20(action.tokenIn), action.dexAddress, 0);
return (false, _amount, shouldDeposit ? weth : _token);
}
}
else {
try
IUniswapV3(action.dexAddress).exactInput(IUniswapV3.ExactInputParamsRouter2({
path : action.encodedPath,
recipient : address(this),
amountIn : _amount,
amountOutMinimum : action.amountOutMinimum
}))
returns (uint) {
emit ActionDone(Interchain.ActionType.UNI_V3, action.dexAddress, true, "");
// Note: instead of using return amounts of exactInput,
// we get the diff balance of before and after. This prevents errors for tokens with transfer fees.
uint toBalanceAfter = LibSwapper.getBalanceOf(toToken);
SafeERC20.forceApprove(IERC20(action.tokenIn), action.dexAddress, 0);
return (true, toBalanceAfter - toBalanceBefore, toToken);
} catch {
emit ActionDone(Interchain.ActionType.UNI_V3, action.dexAddress, false, "Uniswap-V3 call failed");
SafeERC20.forceApprove(IERC20(action.tokenIn), action.dexAddress, 0);
return (false, _amount, shouldDeposit ? weth : _token);
}
}
}
/// @notice Performs a contract call operation
/// @param _message The interchain message that contains the swap info
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handleCall(
address _token,
uint _amount,
Interchain.RangoInterChainMessage memory _message
) private returns (bool ok, uint256 amountOut, address outToken) {
Interchain.CallAction memory action = abi.decode((_message.action), (Interchain.CallAction));
if (isContractWhitelisted(action.target) != true) {
// "Action.target is not whitelisted"
return (false, _amount, _token);
}
if (isContractWhitelisted(action.spender) != true) {
// "Action.spender is not whitelisted"
return (false, _amount, _token);
}
address sourceToken = _token;
if (action.preAction == Interchain.CallSubActionType.WRAP) {
if (_token != LibSwapper.ETH) {
// "Cannot wrap non-native"
return (false, _amount, _token);
}
if (action.tokenIn != getWeth()) {
// "action.tokenIn must be WETH"
return (false, _amount, _token);
}
(ok, amountOut, sourceToken) = _handleWrap(_token, _amount);
} else if (action.preAction == Interchain.CallSubActionType.UNWRAP) {
if (_token != getWeth()) {
// "Cannot unwrap non-WETH"
return (false, _amount, _token);
}
if (action.tokenIn != LibSwapper.ETH) {
// "action.tokenIn must be ETH"
return (false, _amount, _token);
}
(ok, amountOut, sourceToken) = _handleUnwrap(_token, _amount);
} else {
ok = true;
if (action.tokenIn != _token) {
// "_message.tokenIn mismatch in call"
return (false, _amount, _token);
}
}
if (!ok)
return (false, _amount, _token);
if (sourceToken != LibSwapper.ETH)
LibSwapper.approve(sourceToken, action.spender, _amount);
uint value = sourceToken == LibSwapper.ETH ? _amount : 0;
uint toBalanceBefore = LibSwapper.getBalanceOf(_message.toToken);
if (action.overwriteAmount == true) {
bytes memory data = action.callData;
uint256 index = action.startIndexForAmount;
// Avoid malicious overwriting of function sig or invalid location:
if (index < 4 || data.length < 32 || index > (data.length - 32))
return (false, _amount, _token);
assembly {
mstore(add(data, add(index,32)), _amount)
}
}
(bool success, bytes memory ret) = action.target.call{value: value}(action.callData);
if (sourceToken != LibSwapper.ETH)
SafeERC20.forceApprove(IERC20(sourceToken), action.spender, 0);
if (success) {
emit ActionDone(Interchain.ActionType.CALL, action.target, true, "");
uint toBalanceAfter = LibSwapper.getBalanceOf(_message.toToken);
return (true, toBalanceAfter - toBalanceBefore, _message.toToken);
} else {
emit ActionDone(Interchain.ActionType.CALL, action.target, false, LibSwapper._getRevertMsg(ret));
return (false, _amount, sourceToken);
}
}
/// @notice Performs a swap operation using Curve fi
/// @param _message The interchain message that contains the swap info
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handleCurve(
address _token,
uint _amount,
Interchain.RangoInterChainMessage memory _message
) private returns (bool ok, uint256 amountOut, address outToken) {
Interchain.CurveAction memory action = abi.decode((_message.action), (Interchain.CurveAction));
if (isContractWhitelisted(action.routerContractAddress) != true) {
// "Dex address is not whitelisted"
return (false, _amount, _token);
}
uint value = 0;
if (_token == LibSwapper.ETH) {
if (action.routes[0] != address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)) {
return (false, _amount, _token);
}
value = _amount;
} else {
if (_token != action.routes[0]) {
return (false, _amount, _token);
}
LibSwapper.approve(_token, action.routerContractAddress, _amount);
}
address toToken = action.toToken;
uint toBalanceBefore = LibSwapper.getBalanceOf(toToken);
try
ICurve(action.routerContractAddress).exchange{value: value}(
action.routes,
action.swap_params,
_amount,
action.expected,
action.pools,
address(this)
)
returns (uint256) {
emit ActionDone(Interchain.ActionType.CURVE, action.routerContractAddress, true, "");
uint toBalanceAfter = LibSwapper.getBalanceOf(toToken);
if (_token != LibSwapper.ETH) {
SafeERC20.forceApprove(IERC20(_token), action.routerContractAddress, 0);
}
return (true, toBalanceAfter - toBalanceBefore, toToken);
} catch {
emit ActionDone(Interchain.ActionType.CURVE, action.routerContractAddress, false, "Curve call failed");
if (_token != LibSwapper.ETH) {
SafeERC20.forceApprove(IERC20(_token), action.routerContractAddress, 0);
}
return (false, _amount, _token);
}
}
/// @notice Performs a post action operation
/// @param _postAction The type of action to perform such as WRAP, UNWRAP
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handlePostAction(
address _token,
uint _amount,
Interchain.CallSubActionType _postAction
) private returns (bool ok, uint256 amountOut, address outToken) {
if (_postAction == Interchain.CallSubActionType.WRAP) {
if (_token != LibSwapper.ETH) {
// "Cannot wrap non-native"
return (false, _amount, _token);
}
(ok, amountOut, outToken) = _handleWrap(_token, _amount);
} else if (_postAction == Interchain.CallSubActionType.UNWRAP) {
if (_token != getWeth()) {
// "Cannot unwrap non-WETH"
return (false, _amount, _token);
}
(ok, amountOut, outToken) = _handleUnwrap(_token, _amount);
} else {
// revert("Unsupported post-action");
return (false, _amount, _token);
}
if (!ok)
return (false, _amount, _token);
return (ok, amountOut, outToken);
}
/// @notice Performs a WETH.deposit operation
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handleWrap(
address _token,
uint _amount
) private returns (bool ok, uint256 amountOut, address outToken) {
if (_token != LibSwapper.ETH) {
// "Cannot wrap non-ETH tokens"
return (false, _amount, _token);
}
address weth = getWeth();
IWETH(weth).deposit{value: _amount}();
emit SubActionDone(Interchain.CallSubActionType.WRAP, weth, true, "");
return (true, _amount, weth);
}
/// @notice Performs a WETH.deposit operation
/// @param _amount The amount of input token
/// @return ok Indicates that the swap operation was success or fail
/// @return amountOut If ok = true, amountOut is the output amount of the swap
function _handleUnwrap(
address _token,
uint _amount
) private returns (bool ok, uint256 amountOut, address outToken) {
address weth = getWeth();
if (_token != weth)
// revert("Non-WETH tokens unwrapped");
return (false, _amount, _token);
IWETH(weth).withdraw(_amount);
emit SubActionDone(Interchain.CallSubActionType.UNWRAP, weth, true, "");
return (true, _amount, LibSwapper.ETH);
}
/// @notice An internal function to send a token from the current contract to another contract or wallet
/// @dev This function also can convert WETH to ETH before sending if _withdraw flat is set to true
/// @dev To send native token _nativeOut param should be set to true, otherwise we assume it's an ERC20 transfer
/// @dev If there is a message from a dApp it sends the money to the contract instead of the end-user and calls its handleRangoMessage
/// @param _token The token that is going to be sent to a wallet, ZERO address for native
/// @param _amount The sent amount
/// @param _receiver The receiver wallet address or contract
function _sendTokenWithDApp(
address _token,
uint256 _amount,
address _receiver,
bytes memory _dAppMessage,
address _dAppReceiverContract,
IRangoMessageReceiver.ProcessStatus processStatus
) internal {
bool thereIsAMessage = _dAppReceiverContract != LibSwapper.ETH;
address immediateReceiver = thereIsAMessage ? _dAppReceiverContract : _receiver;
emit LibSwapper.SendToken(_token, _amount, immediateReceiver);
if (_token == LibSwapper.ETH) {
LibSwapper._sendNative(immediateReceiver, _amount);
} else {
SafeERC20.safeTransfer(IERC20(_token), immediateReceiver, _amount);
}
if (thereIsAMessage) {
require(
isMessagingContractWhitelisted(_dAppReceiverContract),
"3rd-party contract not whitelisted"
);
try IRangoMessageReceiver(_dAppReceiverContract)
.handleRangoMessage(_token, _amount, processStatus, _dAppMessage)
{
emit CrossChainMessageCalled(_dAppReceiverContract, _token, _amount, processStatus, _dAppMessage, true, "");
} catch Error(string memory reason) {
emit CrossChainMessageCalled(_dAppReceiverContract, _token, _amount, processStatus, _dAppMessage, false, reason);
} catch (bytes memory lowLevelData) {
emit CrossChainMessageCalled(_dAppReceiverContract, _token, _amount, processStatus, _dAppMessage, false, LibSwapper._getRevertMsg(lowLevelData));
}
}
}
/// @notice get wrapped token address on the current chain from shared storage contract
/// @return WETH address
function getWeth() internal view returns(address) {
address whitelistsContractAddress = getLibInterchainStorage().whitelistsStorageContract;
return IRangoMiddlewareWhitelists(whitelistsContractAddress).getWeth();
}
/// @notice returns whether a middleware is in paused state
/// @param _middleware The middleware address to change the pause state.
/// @return middlewaresPaused bool true if middlewares are paused.
function isMiddlewaresPaused(address _middleware) internal view returns (bool) {
address whitelistsContractAddress = getLibInterchainStorage().whitelistsStorageContract;
return IRangoMiddlewareWhitelists(whitelistsContractAddress).isMiddlewaresPaused(_middleware);
}
/// @notice A utility function to fetch storage from a predefined random slot using assembly
/// @return s The storage object
function getLibInterchainStorage() internal pure returns (BaseInterchainStorage storage s) {
bytes32 namespace = LIBINTERCHAIN_CONTRACT_NAMESPACE;
// solhint-disable-next-line no-inline-assembly
assembly {
s.slot := namespace
}
}
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
/// @title Pausable Library
/// @author 0xiDen
/// @notice This library provides pausable feature across entire diamond protected methods. Be advised only methods that call `enforceNotPaused` will be protected!
library LibPausable {
/// Storage ///
bytes32 private constant NAMESPACE = keccak256("exchange.rango.library.pausable");
/// Types ///
struct PausableStorage {
bool isPaused;
}
/// Events ///
/// @notice Notifies that Rango's paused state is updated
/// @param _oldPausedState The previous paused state
/// @param _newPausedState The new fee wallet address
event PausedStateUpdated(bool _oldPausedState, bool _newPausedState);
/// Errors ///
/// Constants ///
/// Modifiers ///
/// Internal Methods ///
/// @notice Sets the isPaused state for Rango
/// @param _paused The receiver wallet address
function updatePauseState(bool _paused) internal {
PausableStorage storage pausableStorage = getPausableStorage();
bool oldState = pausableStorage.isPaused;
pausableStorage.isPaused = _paused;
emit PausedStateUpdated(oldState, _paused);
}
function enforceNotPaused() internal view {
PausableStorage storage pausableStorage = getPausableStorage();
require(pausableStorage.isPaused == false, "Paused");
}
/// Private Methods ///
/// @dev fetch local storage
function getPausableStorage() private pure returns (PausableStorage storage data) {
bytes32 position = NAMESPACE;
// solhint-disable-next-line no-inline-assembly
assembly {
data.slot := position
}
}
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IWETH.sol";
import "../interfaces/IRango.sol";
/// @title BaseSwapper
/// @author 0xiden
/// @notice library to provide swap functionality
library LibSwapper {
bytes32 internal constant BASE_SWAPPER_NAMESPACE = keccak256("exchange.rango.library.swapper");
address payable constant ETH = payable(0x0000000000000000000000000000000000000000);
struct BaseSwapperStorage {
address payable feeContractAddress;
address WETH;
mapping(address => bool) whitelistContracts;
mapping(address => mapping(bytes4 => bool)) whitelistMethods;
}
/// @notice Emitted if any fee transfer was required
/// @param token The address of received token, address(0) for native
/// @param affiliatorAddress The address of affiliate wallet
/// @param platformFee The amount received as platform fee
/// @param destinationExecutorFee The amount received to execute transaction on destination (only for cross chain txs)
/// @param affiliateFee The amount received by affiliate
/// @param dAppTag Optional identifier to make tracking easier.
event FeeInfo(
address token,
address indexed affiliatorAddress,
uint platformFee,
uint destinationExecutorFee,
uint affiliateFee,
uint16 indexed dAppTag
);
/// @notice A call to another dex or contract done and here is the result
/// @param target The address of dex or contract that is called
/// @param success A boolean indicating that the call was success or not
/// @param returnData The response of function call
event CallResult(address target, bool success, bytes returnData);
/// @notice A swap request is done and we also emit the output
/// @param requestId Optional parameter to make tracking of transaction easier
/// @param fromToken Input token address to be swapped from
/// @param toToken Output token address to be swapped to
/// @param amountIn Input amount of fromToken that is being swapped
/// @param dAppTag Optional identifier to make tracking easier
/// @param outputAmount The output amount of the swap, measured by the balance change before and after the swap
/// @param receiver The address to receive the output of swap. Can be address(0) when swap is before a bridge action
/// @param dAppName The human readable name of the dApp
event RangoSwap(
address indexed requestId,
address fromToken,
address toToken,
uint amountIn,
uint minimumAmountExpected,
uint16 indexed dAppTag,
uint outputAmount,
address receiver,
string dAppName
);
/// @notice Output amount of a dex calls is logged
/// @param _token The address of output token, ZERO address for native
/// @param amount The amount of output
event DexOutput(address _token, uint amount);
/// @notice The output money (ERC20/Native) is sent to a wallet
/// @param _token The token that is sent to a wallet, ZERO address for native
/// @param _amount The sent amount
/// @param _receiver The receiver wallet address
event SendToken(address _token, uint256 _amount, address _receiver);
/// @notice Notifies that Rango's fee receiver address updated
/// @param _oldAddress The previous fee wallet address
/// @param _newAddress The new fee wallet address
event FeeContractAddressUpdated(address _oldAddress, address _newAddress);
/// @notice Notifies that WETH address is updated
/// @param _oldAddress The previous weth address
/// @param _newAddress The new weth address
event WethContractAddressUpdated(address _oldAddress, address _newAddress);
/// @notice Notifies that admin manually refunded some money
/// @param _token The address of refunded token, 0x000..00 address for native token
/// @param _amount The amount that is refunded
event Refunded(address _token, uint _amount);
/// @notice The requested call data which is computed off-chain and passed to the contract
/// @dev swapFromToken and amount parameters are only helper params and the actual amount and
/// token are set in callData
/// @param spender The contract which the approval is given to if swapFromToken is not native.
/// @param target The dex contract address that should be called
/// @param swapFromToken Token address of to be used in the swap.
/// @param amount The amount to be approved or native amount sent.
/// @param callData The required data field that should be give to the dex contract to perform swap
struct Call {
address spender;
address payable target;
address swapFromToken;
address swapToToken;
bool needsTransferFromUser;
uint amount;
bytes callData;
}
/// @notice General swap request which is given to us in all relevant functions
/// @param requestId The request id passed to make tracking transactions easier
/// @param fromToken The source token that is going to be swapped (in case of simple swap or swap + bridge) or the briding token (in case of solo bridge)
/// @param toToken The output token of swapping. This is the output of DEX step and is also input of bridging step
/// @param amountIn The amount of input token to be swapped
/// @param platformFee The amount of fee charged by platform
/// @param destinationExecutorFee The amount of fee required for relayer execution on the destination
/// @param affiliateFee The amount of fee charged by affiliator dApp
/// @param affiliatorAddress The wallet address that the affiliator fee should be sent to
/// @param minimumAmountExpected The minimum amount of toToken expected after executing Calls
/// @param feeFromInputToken If set to true, the fees will be taken from input token and otherwise, from output token. (platformFee,destinationExecutorFee,affiliateFee)
/// @param dAppTag An optional parameter
/// @param dAppName The Name of the dApp
struct SwapRequest {
address requestId;
address fromToken;
address toToken;
uint amountIn;
uint platformFee;
uint destinationExecutorFee;
uint affiliateFee;
address payable affiliatorAddress;
uint minimumAmountExpected;
bool feeFromInputToken;
uint16 dAppTag;
string dAppName;
}
/// @notice initializes the base swapper and sets the init params (such as Wrapped token address)
/// @param _weth Address of wrapped token (WETH, WBNB, etc.) on the current chain
function setWeth(address _weth) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
address oldAddress = baseStorage.WETH;
baseStorage.WETH = _weth;
require(_weth != address(0), "Invalid WETH!");
emit WethContractAddressUpdated(oldAddress, _weth);
}
/// @notice Sets the wallet that receives Rango's fees from now on
/// @param _address The receiver wallet address
function updateFeeContractAddress(address payable _address) internal {
BaseSwapperStorage storage baseSwapperStorage = getBaseSwapperStorage();
address oldAddress = baseSwapperStorage.feeContractAddress;
baseSwapperStorage.feeContractAddress = _address;
emit FeeContractAddressUpdated(oldAddress, _address);
}
/// Whitelist ///
/// @notice Adds a contract to the whitelisted DEXes that can be called
/// @param contractAddress The address of the DEX
function addWhitelist(address contractAddress) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
baseStorage.whitelistContracts[contractAddress] = true;
}
/// @notice Adds a method of contract to the whitelisted DEXes that can be called
/// @param contractAddress The address of the DEX
/// @param methodIds The method of the DEX
function addMethodWhitelists(address contractAddress, bytes4[] calldata methodIds) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
baseStorage.whitelistContracts[contractAddress] = true;
for (uint i = 0; i < methodIds.length; i++)
baseStorage.whitelistMethods[contractAddress][methodIds[i]] = true;
}
/// @notice Adds a method of contract to the whitelisted DEXes that can be called
/// @param contractAddress The address of the DEX
/// @param methodId The method of the DEX
function addMethodWhitelist(address contractAddress, bytes4 methodId) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
baseStorage.whitelistContracts[contractAddress] = true;
baseStorage.whitelistMethods[contractAddress][methodId] = true;
}
/// @notice Removes a contract from the whitelisted DEXes
/// @param contractAddress The address of the DEX or dApp
function removeWhitelist(address contractAddress) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
delete baseStorage.whitelistContracts[contractAddress];
}
/// @notice Removes a method of contract from the whitelisted DEXes
/// @param contractAddress The address of the DEX or dApp
/// @param methodId The method of the DEX
function removeMethodWhitelist(address contractAddress, bytes4 methodId) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
delete baseStorage.whitelistMethods[contractAddress][methodId];
}
function onChainSwapsPreBridge(
SwapRequest memory request,
Call[] calldata calls,
uint extraFee
) internal returns (uint out) {
uint minimumRequiredValue = getPreBridgeMinAmount(request) + extraFee;
require(msg.value >= minimumRequiredValue, 'Send more ETH to cover input amount + fee');
(, out) = onChainSwapsInternal(request, calls, extraFee);
// when there is a bridge after swap, set the receiver in swap event to address(0)
emitSwapEvent(request, out, ETH);
return out;
}
/// @notice Internal function to compute output amount of DEXes
/// @param request The general swap request containing from/to token and fee/affiliate rewards
/// @param calls The list of DEX calls
/// @param extraNativeFee The amount of native tokens to keep and not return to user as excess amount.
/// @return The response of all DEX calls and the output amount of the whole process
function onChainSwapsInternal(
SwapRequest memory request,
Call[] calldata calls,
uint256 extraNativeFee
) internal returns (bytes[] memory, uint) {
uint toBalanceBefore = getBalanceOf(request.toToken);
uint fromBalanceBefore = getBalanceOf(request.fromToken);
uint256[] memory initialBalancesList = getInitialBalancesList(calls);
// transfer tokens from user for SwapRequest and Calls that require transfer from user.
transferTokensFromUserForSwapRequest(request);
transferTokensFromUserForCalls(calls);
bytes[] memory result = callSwapsAndFees(request, calls);
// check if any extra tokens were taken from contract and return excess tokens if any.
returnExcessAmounts(request, calls, initialBalancesList);
// get balance after returning excesses.
uint fromBalanceAfter = getBalanceOf(request.fromToken);
// check over-expense of fromToken and return excess if any.
if (request.fromToken != ETH) {
require(fromBalanceAfter >= fromBalanceBefore, "Source token balance on contract must not decrease after swap");
if (fromBalanceAfter > fromBalanceBefore)
_sendToken(request.fromToken, fromBalanceAfter - fromBalanceBefore, msg.sender);
}
else {
require(fromBalanceAfter >= fromBalanceBefore - msg.value + extraNativeFee, "Source token balance on contract must not decrease after swap");
// When we are keeping extraNativeFee for bridgingFee, we should consider it in calculations.
if (fromBalanceAfter > fromBalanceBefore - msg.value + extraNativeFee)
_sendToken(request.fromToken, fromBalanceAfter + msg.value - fromBalanceBefore - extraNativeFee, msg.sender);
}
uint toBalanceAfter = getBalanceOf(request.toToken);
uint secondaryBalance = toBalanceAfter - toBalanceBefore;
require(secondaryBalance >= request.minimumAmountExpected, "Output is less than minimum expected");
return (result, secondaryBalance);
}
/// @notice Private function to handle fetching money from wallet to contract, reduce fee/affiliate, perform DEX calls
/// @param request The general swap request containing from/to token and fee/affiliate rewards
/// @param calls The list of DEX calls
/// @dev It checks the whitelisting of all DEX addresses + having enough msg.value as input
/// @return The bytes of all DEX calls response
function callSwapsAndFees(SwapRequest memory request, Call[] calldata calls) private returns (bytes[] memory) {
BaseSwapperStorage storage baseSwapperStorage = getBaseSwapperStorage();
for (uint256 i = 0; i < calls.length; i++) {
require(baseSwapperStorage.whitelistContracts[calls[i].spender], "Contract spender not whitelisted");
require(baseSwapperStorage.whitelistContracts[calls[i].target], "Contract target not whitelisted");
bytes4 sig = bytes4(calls[i].callData[: 4]);
require(baseSwapperStorage.whitelistMethods[calls[i].target][sig], "Unauthorized call data!");
}
// Get Fees Before swap
collectFeesBeforeSwap(request);
// Execute swap Calls
bytes[] memory returnData = new bytes[](calls.length);
address tmpSwapFromToken;
for (uint256 i = 0; i < calls.length; i++) {
tmpSwapFromToken = calls[i].swapFromToken;
bool isTokenNative = tmpSwapFromToken == ETH;
if (isTokenNative == false)
approveMax(tmpSwapFromToken, calls[i].spender, calls[i].amount);
(bool success, bytes memory ret) = isTokenNative
? calls[i].target.call{value : calls[i].amount}(calls[i].callData)
: calls[i].target.call(calls[i].callData);
emit CallResult(calls[i].target, success, ret);
if (!success)
revert(_getRevertMsg(ret));
returnData[i] = ret;
}
// Get Fees After swap
collectFeesAfterSwap(request);
return returnData;
}
/// @notice Approves an ERC20 token to a contract to transfer from the current contract
/// @param token The address of an ERC20 token
/// @param spender The contract address that should be approved
/// @param value The amount that should be approved
function approve(address token, address spender, uint value) internal {
SafeERC20.forceApprove(IERC20(token), spender, value);
}
/// @notice Approves an ERC20 token to a contract to transfer from the current contract, approves for inf value
/// @param token The address of an ERC20 token
/// @param spender The contract address that should be approved
/// @param value The desired allowance. If current allowance is less than this value, infinite allowance will be given
function approveMax(address token, address spender, uint value) internal {
uint256 currentAllowance = IERC20(token).allowance(address(this), spender);
if (currentAllowance < value) {
SafeERC20.forceApprove(IERC20(token), spender, type(uint256).max);
}
}
function _sendToken(address _token, uint256 _amount, address _receiver) internal {
(_token == ETH) ? _sendNative(_receiver, _amount) : SafeERC20.safeTransfer(IERC20(_token), _receiver, _amount);
}
function sumFees(IRango.RangoBridgeRequest memory request) internal pure returns (uint256) {
return request.platformFee + request.affiliateFee + request.destinationExecutorFee;
}
function sumFees(SwapRequest memory request) internal pure returns (uint256) {
return request.platformFee + request.affiliateFee + request.destinationExecutorFee;
}
function getPreBridgeMinAmount(SwapRequest memory request) internal pure returns (uint256) {
bool isNative = request.fromToken == ETH;
if (request.feeFromInputToken) {
return (isNative ? request.platformFee + request.affiliateFee + request.amountIn + request.destinationExecutorFee : 0);
}
return (isNative ? request.amountIn : 0);
}
function collectFeesForSwap(SwapRequest memory request) internal {
BaseSwapperStorage storage baseSwapperStorage = getBaseSwapperStorage();
// Get Platform fee
bool hasPlatformFee = request.platformFee > 0;
bool hasDestExecutorFee = request.destinationExecutorFee > 0;
bool hasAffiliateFee = request.affiliateFee > 0;
address feeToken = request.feeFromInputToken ? request.fromToken : request.toToken;
if (hasPlatformFee || hasDestExecutorFee) {
require(baseSwapperStorage.feeContractAddress != ETH, "Fee contract address not set");
_sendToken(feeToken, request.platformFee + request.destinationExecutorFee, baseSwapperStorage.feeContractAddress, false);
}
// Get affiliate fee
if (hasAffiliateFee) {
require(request.affiliatorAddress != ETH, "Invalid affiliatorAddress");
_sendToken(feeToken, request.affiliateFee, request.affiliatorAddress, false);
}
// emit Fee event
if (hasPlatformFee || hasDestExecutorFee || hasAffiliateFee) {
emit FeeInfo(
feeToken,
request.affiliatorAddress,
request.platformFee,
request.destinationExecutorFee,
request.affiliateFee,
request.dAppTag
);
}
}
function collectFees(IRango.RangoBridgeRequest memory request) internal {
// Get Platform fee
bool hasPlatformFee = request.platformFee > 0;
bool hasDestExecutorFee = request.destinationExecutorFee > 0;
bool hasAffiliateFee = request.affiliateFee > 0;
bool hasAnyFee = hasPlatformFee || hasDestExecutorFee || hasAffiliateFee;
if (!hasAnyFee) {
return;
}
BaseSwapperStorage storage baseSwapperStorage = getBaseSwapperStorage();
if (hasPlatformFee || hasDestExecutorFee) {
require(baseSwapperStorage.feeContractAddress != ETH, "Fee contract address not set");
_sendToken(request.token, request.platformFee + request.destinationExecutorFee, baseSwapperStorage.feeContractAddress, false);
}
// Get affiliate fee
if (hasAffiliateFee) {
require(request.affiliatorAddress != ETH, "Invalid affiliatorAddress");
_sendToken(request.token, request.affiliateFee, request.affiliatorAddress, false);
}
// emit Fee event
emit FeeInfo(
request.token,
request.affiliatorAddress,
request.platformFee,
request.destinationExecutorFee,
request.affiliateFee,
request.dAppTag
);
}
function collectFeesBeforeSwap(SwapRequest memory request) internal {
if (request.feeFromInputToken) {
collectFeesForSwap(request);
}
}
function collectFeesAfterSwap(SwapRequest memory request) internal {
if (!request.feeFromInputToken) {
collectFeesForSwap(request);
}
}
function collectFeesFromSender(IRango.RangoBridgeRequest memory request) internal {
// Get Platform fee
bool hasPlatformFee = request.platformFee > 0;
bool hasDestExecutorFee = request.destinationExecutorFee > 0;
bool hasAffiliateFee = request.affiliateFee > 0;
bool hasAnyFee = hasPlatformFee || hasDestExecutorFee || hasAffiliateFee;
if (!hasAnyFee) {
return;
}
bool isSourceNative = request.token == ETH;
BaseSwapperStorage storage baseSwapperStorage = getBaseSwapperStorage();
if (hasPlatformFee || hasDestExecutorFee) {
require(baseSwapperStorage.feeContractAddress != ETH, "Fee contract address not set");
if (isSourceNative)
_sendToken(request.token, request.platformFee + request.destinationExecutorFee, baseSwapperStorage.feeContractAddress, false);
else
SafeERC20.safeTransferFrom(
IERC20(request.token),
msg.sender,
baseSwapperStorage.feeContractAddress,
request.platformFee + request.destinationExecutorFee
);
}
// Get affiliate fee
if (hasAffiliateFee) {
require(request.affiliatorAddress != ETH, "Invalid affiliatorAddress");
if (isSourceNative)
_sendToken(request.token, request.affiliateFee, request.affiliatorAddress, false);
else
SafeERC20.safeTransferFrom(
IERC20(request.token),
msg.sender,
request.affiliatorAddress,
request.affiliateFee
);
}
// emit Fee event
emit FeeInfo(
request.token,
request.affiliatorAddress,
request.platformFee,
request.destinationExecutorFee,
request.affiliateFee,
request.dAppTag
);
}
/// @notice An internal function to send a token from the current contract to another contract or wallet
/// @dev This function also can convert WETH to ETH before sending if _withdraw flat is set to true
/// @dev To send native token _token param should be set to address zero, otherwise we assume it's an ERC20 transfer
/// @param _token The token that is going to be sent to a wallet, ZERO address for native
/// @param _amount The sent amount
/// @param _receiver The receiver wallet address or contract
/// @param _withdraw If true, indicates that we should swap WETH to ETH before sending the money and _nativeOut must also be true
function _sendToken(
address _token,
uint256 _amount,
address _receiver,
bool _withdraw
) internal {
BaseSwapperStorage storage baseStorage = getBaseSwapperStorage();
emit SendToken(_token, _amount, _receiver);
bool nativeOut = _token == LibSwapper.ETH;
if (_withdraw) {
require(_token == baseStorage.WETH, "token mismatch");
IWETH(baseStorage.WETH).withdraw(_amount);
nativeOut = true;
}
if (nativeOut) {
_sendNative(_receiver, _amount);
} else {
SafeERC20.safeTransfer(IERC20(_token), _receiver, _amount);
}
}
/// @notice An internal function to send native token to a contract or wallet
/// @param _receiver The address that will receive the native token
/// @param _amount The amount of the native token that should be sent
function _sendNative(address _receiver, uint _amount) internal {
(bool sent,) = _receiver.call{value : _amount}("");
require(sent, "failed to send native");
}
/// @notice A utility function to fetch storage from a predefined random slot using assembly
/// @return s The storage object
function getBaseSwapperStorage() internal pure returns (BaseSwapperStorage storage s) {
bytes32 namespace = BASE_SWAPPER_NAMESPACE;
// solhint-disable-next-line no-inline-assembly
assembly {
s.slot := namespace
}
}
/// @notice To extract revert message from a DEX/contract call to represent to the end-user in the blockchain
/// @param _returnData The resulting bytes of a failed call to a DEX or contract
/// @return A string that describes what was the error
function _getRevertMsg(bytes memory _returnData) internal pure returns (string memory) {
// If the _res length is less than 68, then the transaction failed silently (without a revert message)
if (_returnData.length < 68) return 'Transaction reverted silently';
assembly {
// Slice the sighash.
_returnData := add(_returnData, 0x04)
}
return abi.decode(_returnData, (string));
// All that remains is the revert string
}
function getBalanceOf(address token) internal view returns (uint) {
return token == ETH ? address(this).balance : IERC20(token).balanceOf(address(this));
}
/// @notice Fetches the balances of swapToTokens.
/// @dev this fetches the balances for swapToToken of swap Calls. If native eth is received, the balance has already increased so we subtract msg.value.
function getInitialBalancesList(Call[] calldata calls) internal view returns (uint256[] memory) {
uint callsLength = calls.length;
uint256[] memory balancesList = new uint256[](callsLength);
address token;
for (uint256 i = 0; i < callsLength; i++) {
token = calls[i].swapToToken;
balancesList[i] = getBalanceOf(token);
if (token == ETH)
balancesList[i] -= msg.value;
}
return balancesList;
}
/// This function transfers tokens from users based on the SwapRequest, it transfers amountIn + fees.
function transferTokensFromUserForSwapRequest(SwapRequest memory request) private {
uint transferAmount = request.amountIn + (request.feeFromInputToken ? sumFees(request) : 0);
if (request.fromToken != ETH)
SafeERC20.safeTransferFrom(IERC20(request.fromToken), msg.sender, address(this), transferAmount);
else
require(msg.value >= transferAmount);
}
/// This function iterates on calls and if needsTransferFromUser, transfers tokens from user
function transferTokensFromUserForCalls(Call[] calldata calls) private {
uint callsLength = calls.length;
Call calldata call;
address token;
for (uint256 i = 0; i < callsLength; i++) {
call = calls[i];
token = call.swapFromToken;
if (call.needsTransferFromUser && token != ETH)
SafeERC20.safeTransferFrom(IERC20(call.swapFromToken), msg.sender, address(this), call.amount);
}
}
/// @dev returns any excess token left by the contract.
/// We iterate over `swapToToken`s because each swapToToken is either the request.toToken or is the output of
/// another `Call` in the list of swaps which itself either has transferred tokens from user,
/// or is a middle token that is the output of another `Call`.
function returnExcessAmounts(
SwapRequest memory request,
Call[] calldata calls,
uint256[] memory initialBalancesList) internal {
uint excessAmountToToken;
address tmpSwapToToken;
uint currentBalanceTo;
for (uint256 i = 0; i < calls.length; i++) {
tmpSwapToToken = calls[i].swapToToken;
currentBalanceTo = getBalanceOf(tmpSwapToToken);
excessAmountToToken = currentBalanceTo - initialBalancesList[i];
if (excessAmountToToken > 0 && tmpSwapToToken != request.toToken) {
_sendToken(tmpSwapToToken, excessAmountToToken, msg.sender);
}
}
}
function emitSwapEvent(SwapRequest memory request, uint output, address receiver) internal {
emit RangoSwap(
request.requestId,
request.fromToken,
request.toToken,
request.amountIn,
request.minimumAmountExpected,
request.dAppTag,
output,
receiver,
request.dAppName
);
}
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
library LibTransform {
function addressToString(address a) internal pure returns (string memory) {
bytes memory data = abi.encodePacked(a);
bytes memory characters = '0123456789abcdef';
bytes memory byteString = new bytes(2 + data.length * 2);
byteString[0] = '0';
byteString[1] = 'x';
for (uint256 i; i < data.length; ++i) {
byteString[2 + i * 2] = characters[uint256(uint8(data[i] >> 4))];
byteString[3 + i * 2] = characters[uint256(uint8(data[i] & 0x0f))];
}
return string(byteString);
}
function bytesToAddress(bytes memory bs) internal pure returns (address addr) {
return address(uint160(bytes20(bs)));
}
function addressToBytes32LeftPadded(address addr) internal pure returns (bytes32) {
return bytes32(uint256(uint160(addr)));
}
function bytes32LeftPaddedToAddress(bytes32 b) internal pure returns (address){
return address(uint160(uint256(b)));
}
function stringToBytes(string memory s) internal pure returns (bytes memory){
bytes memory b3 = bytes(s);
return b3;
}
function stringToAddress(string memory s) internal pure returns (address){
return bytesToAddress(stringToBytes(s));
}
function extractAddressFromEndOfBytes(bytes calldata bs) internal pure returns (address){
if (bs.length < 20)
return bytesToAddress(bs);
return bytesToAddress(bs[bs.length - 20 :]);
}
function extractAddressWithOffsetFromEnd(bytes calldata bs, uint256 offset) internal pure returns (address){
if (bs.length < 20 || bs.length < offset)
return bytesToAddress(bs);
return bytesToAddress(bs[bs.length - offset :]);
}
}// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.25;
/// @title Reentrancy Guard
/// @author
/// @notice Abstract contract to provide protection against reentrancy
abstract contract ReentrancyGuard {
/// Storage ///
bytes32 private constant NAMESPACE = keccak256("exchange.rango.reentrancyguard");
/// Types ///
struct ReentrancyStorage {
uint256 status;
}
/// Errors ///
error ReentrancyError();
/// Constants ///
uint256 private constant _NOT_ENTERED = 0;
uint256 private constant _ENTERED = 1;
/// Modifiers ///
modifier nonReentrant() {
ReentrancyStorage storage s = reentrancyStorage();
if (s.status == _ENTERED) revert ReentrancyError();
s.status = _ENTERED;
_;
s.status = _NOT_ENTERED;
}
/// Private Methods ///
/// @dev fetch local storage
function reentrancyStorage() private pure returns (ReentrancyStorage storage data) {
bytes32 position = NAMESPACE;
// solhint-disable-next-line no-inline-assembly
assembly {
data.slot := position
}
}
}{
"optimizer": {
"enabled": true,
"runs": 10000
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"ReentrancyError","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"bytes","name":"returnData","type":"bytes"}],"name":"CallResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"affiliatorAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"platformFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"destinationExecutorFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"affiliateFee","type":"uint256"},{"indexed":true,"internalType":"uint16","name":"dAppTag","type":"uint16"}],"name":"FeeInfo","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"requestId","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"originalSender","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"enum IRango.CrossChainOperationStatus","name":"status","type":"uint8"},{"indexed":false,"internalType":"uint16","name":"dAppTag","type":"uint16"}],"name":"RangoBridgeCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"requestId","type":"address"},{"indexed":false,"internalType":"address","name":"bridgeToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"bridgeAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":false,"internalType":"bool","name":"hasInterchainMessage","type":"bool"},{"indexed":false,"internalType":"bool","name":"hasDestinationSwap","type":"bool"},{"indexed":true,"internalType":"uint8","name":"bridgeId","type":"uint8"},{"indexed":true,"internalType":"uint16","name":"dAppTag","type":"uint16"},{"indexed":false,"internalType":"string","name":"dAppName","type":"string"}],"name":"RangoBridgeInitiated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"requestId","type":"address"},{"indexed":false,"internalType":"address","name":"fromToken","type":"address"},{"indexed":false,"internalType":"address","name":"toToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minimumAmountExpected","type":"uint256"},{"indexed":true,"internalType":"uint16","name":"dAppTag","type":"uint16"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"string","name":"dAppName","type":"string"}],"name":"RangoSwap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"SatelliteGasServiceAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"SatelliteGatewayAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_dstChainId","type":"uint256"},{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"string","name":"_receiver","type":"string"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"SatelliteSendTokenCalled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_receiver","type":"address"}],"name":"SendToken","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"gatewayAddress","type":"address"},{"internalType":"address","name":"gasService","type":"address"}],"internalType":"struct RangoSatelliteFacet.SatelliteStorage","name":"addresses","type":"tuple"}],"name":"initSatellite","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"enum IRangoSatellite.SatelliteBridgeType","name":"bridgeType","type":"uint8"},{"internalType":"string","name":"receiver","type":"string"},{"internalType":"uint256","name":"toChainId","type":"uint256"},{"internalType":"string","name":"toChain","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"relayerGas","type":"uint256"},{"internalType":"address","name":"srcGasRefundAddress","type":"address"},{"internalType":"bytes","name":"imMessage","type":"bytes"}],"internalType":"struct IRangoSatellite.SatelliteBridgeRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address","name":"requestId","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"platformFee","type":"uint256"},{"internalType":"uint256","name":"affiliateFee","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"},{"internalType":"uint256","name":"destinationExecutorFee","type":"uint256"},{"internalType":"uint16","name":"dAppTag","type":"uint16"},{"internalType":"string","name":"dAppName","type":"string"}],"internalType":"struct IRango.RangoBridgeRequest","name":"bridgeRequest","type":"tuple"}],"name":"satelliteBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"requestId","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"platformFee","type":"uint256"},{"internalType":"uint256","name":"destinationExecutorFee","type":"uint256"},{"internalType":"uint256","name":"affiliateFee","type":"uint256"},{"internalType":"address payable","name":"affiliatorAddress","type":"address"},{"internalType":"uint256","name":"minimumAmountExpected","type":"uint256"},{"internalType":"bool","name":"feeFromInputToken","type":"bool"},{"internalType":"uint16","name":"dAppTag","type":"uint16"},{"internalType":"string","name":"dAppName","type":"string"}],"internalType":"struct LibSwapper.SwapRequest","name":"request","type":"tuple"},{"components":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"address payable","name":"target","type":"address"},{"internalType":"address","name":"swapFromToken","type":"address"},{"internalType":"address","name":"swapToToken","type":"address"},{"internalType":"bool","name":"needsTransferFromUser","type":"bool"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct LibSwapper.Call[]","name":"calls","type":"tuple[]"},{"components":[{"internalType":"enum IRangoSatellite.SatelliteBridgeType","name":"bridgeType","type":"uint8"},{"internalType":"string","name":"receiver","type":"string"},{"internalType":"uint256","name":"toChainId","type":"uint256"},{"internalType":"string","name":"toChain","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"relayerGas","type":"uint256"},{"internalType":"address","name":"srcGasRefundAddress","type":"address"},{"internalType":"bytes","name":"imMessage","type":"bytes"}],"internalType":"struct IRangoSatellite.SatelliteBridgeRequest","name":"bridgeRequest","type":"tuple"}],"name":"satelliteSwapAndBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateSatelliteGasServiceAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"updateSatelliteGatewayAddress","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
6080604052348015600f57600080fd5b506133a88061001f6000396000f3fe60806040526004361061005a5760003560e01c8063661553751161004357806366155375146100945780638e6eea55146100a7578063d9f03f29146100c757600080fd5b806359c94b371461005f5780635a18f94114610081575b600080fd5b34801561006b57600080fd5b5061007f61007a36600461283d565b6100e7565b005b61007f61008f366004612b5c565b6100fb565b61007f6100a2366004612cb8565b610282565b3480156100b357600080fd5b5061007f6100c2366004612dbb565b610420565b3480156100d357600080fd5b5061007f6100e236600461283d565b610455565b6100ef610466565b6100f88161050f565b50565b7f4fe94118b1030ac5f570795d403ee5116fd91b8f0b5d11f2487377c2b0ab255980547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01610176576040517f29f745a700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181556101826105ff565b60408501516000906001600160a01b031615801561019e575034155b156101c6578260a001516101b58787876000610672565b6101bf9190612e02565b90506101d9565b6101d68686868660a00151610672565b90505b6101e883876040015183610726565b61014086015161ffff16600960ff1687600001516001600160a01b03167f012c155f3836c4edb9222305b909a109f9efa46288efffe40a0e66da3a9a98008960400151856102398960200151610d28565b60408a015160018b51600181111561025357610253612e15565b1460008f610160015160405161026f9796959493929190612eb2565b60405180910390a4506000905550505050565b7f4fe94118b1030ac5f570795d403ee5116fd91b8f0b5d11f2487377c2b0ab255980547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff016102fd576040517f29f745a700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181556103096105ff565b60408201516020830151600061031e85610d39565b6103289084612f07565b90506001600160a01b0382161561035b5761034582333084610d5e565b8560a0015134101561035657600080fd5b610376565b60a086015161036a9082612f07565b34101561037657600080fd5b61037f85610de0565b61038a868385610726565b60e085015161ffff16600960ff1686600001516001600160a01b03167f012c155f3836c4edb9222305b909a109f9efa46288efffe40a0e66da3a9a980085876103d68c60200151610d28565b60408d015160018e5160018111156103f0576103f0612e15565b1460008e610100015160405161040c9796959493929190612eb2565b60405180910390a450506000909155505050565b610428610466565b61043d610438602083018361283d565b61050f565b6100f8610450604083016020840161283d565b610fd4565b61045d610466565b6100f881610fd4565b7fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c600401546001600160a01b0316331461050d5760405162461bcd60e51b815260206004820152602260248201527f4c69624469616d6f6e643a204d75737420626520636f6e7472616374206f776e60448201527f657200000000000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b565b6001600160a01b0381166105655760405162461bcd60e51b815260206004820152601760248201527f496e76616c6964204761746577617920416464726573730000000000000000006044820152606401610504565b7fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a6f80546001600160a01b038381167fffffffffffffffffffffffff000000000000000000000000000000000000000083168117845560408051929093168083526020830191909152917fc5474af28634e5155be634ccaea8d3e9e77344679b451d664aef7e190a1ba17e91015b60405180910390a1505050565b7f322c2f1d9209969f334c8955443b224cadc85f453939eb2b4ffb8af019944ece805460ff16156100f85760405162461bcd60e51b815260206004820152600660248201527f50617573656400000000000000000000000000000000000000000000000000006044820152606401610504565b6000808261067f876110de565b6106899190612f07565b9050803410156107015760405162461bcd60e51b815260206004820152602960248201527f53656e64206d6f72652045544820746f20636f76657220696e70757420616d6f60448201527f756e74202b2066656500000000000000000000000000000000000000000000006064820152608401610504565b61070d86868686611156565b925061071d9050868360006113f3565b50949350505050565b60408301517fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a6f80549091906001600160a01b03166107cc5760405162461bcd60e51b815260206004820152602160248201527f536174656c6c69746520676174657761792061646472657373206e6f7420736560448201527f74000000000000000000000000000000000000000000000000000000000000006064820152608401610504565b8046036108415760405162461bcd60e51b815260206004820152603d60248201527f496e76616c69642064657374696e6174696f6e20436861696e212043616e6e6f60448201527f742062726964676520746f207468652073616d65206e6574776f726b2e0000006064820152608401610504565b60c08501517f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a9085906001600160a01b0382166108e7578260010160009054906101000a90046001600160a01b03169150816001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b1580156108cd57600080fd5b505af11580156108e1573d6000803e3d6000fd5b50505050505b6001600160a01b0381166108f85750335b6001600160a01b0382166109745760405162461bcd60e51b815260206004820152603660248201527f536f7572636520746f6b656e2061646472657373206973206e756c6c21204e6f60448201527f7420737570706f72746564206279206178656c617221000000000000000000006064820152608401610504565b845461098b9083906001600160a01b031688611469565b6000885160018111156109a0576109a0612e15565b03610aca5760a0880151156109f75760405162461bcd60e51b815260206004820152601b60248201527f4e6f2072656c6179657247617320666f722073656e64546f6b656e00000000006044820152606401610504565b8454606089015160208a015160808b01516040517f26ef699d0000000000000000000000000000000000000000000000000000000081526001600160a01b03909416936326ef699d93610a5293909290918c90600401612f1a565b600060405180830381600087803b158015610a6c57600080fd5b505af1158015610a80573d6000803e3d6000fd5b505050507f675fd9e5424c5cee2cedf832b1b0cc06c164d6fa74b75ce1e7c9359e7446316384838a6020015189604051610abd9493929190612f65565b60405180910390a1610d1e565b60018501546001600160a01b0316610b495760405162461bcd60e51b8152602060048201526024808201527f536174656c6c69746520676173536572766963652061646472657373206e6f7460448201527f20736574000000000000000000000000000000000000000000000000000000006064820152608401610504565b60008860a0015111610bc35760405162461bcd60e51b815260206004820152602360248201527f6178656c6172206e65656473206e61746976652066656520666f722072656c6160448201527f79657200000000000000000000000000000000000000000000000000000000006064820152608401610504565b6000600189516001811115610bda57610bda612e15565b14610bf357604080516000815260208101909152610bf9565b8860e001515b90508560010160009054906101000a90046001600160a01b03166001600160a01b031663c62c20028a60a00151308c606001518d60200151868f608001518e8a6040518963ffffffff1660e01b8152600401610c5b9796959493929190612f9e565b6000604051808303818588803b158015610c7457600080fd5b505af1158015610c88573d6000803e3d6000fd5b5050885460608d015160208e015160808f01516040517fb54170840000000000000000000000000000000000000000000000000000000081526001600160a01b03909416965063b54170849550610cea94509192909187918e90600401613018565b600060405180830381600087803b158015610d0457600080fd5b505af1158015610d18573d6000803e3d6000fd5b50505050505b5050505050505050565b6000610d338261152b565b92915050565b60008160c0015182608001518360600151610d549190612f07565b610d339190612f07565b6040516001600160a01b038481166024830152838116604483015260648201839052610dda9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061153f565b50505050565b606081015160c082015160808301519115159190151590151560008380610e045750825b80610e0c5750815b905080610e1a575050505050565b7f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a8480610e445750835b15610ece5780546001600160a01b0316610ea05760405162461bcd60e51b815260206004820152601c60248201527f46656520636f6e74726163742061646472657373206e6f7420736574000000006044820152606401610504565b610ece86602001518760c001518860600151610ebc9190612f07565b83546001600160a01b031660006115c0565b8215610f475760a08601516001600160a01b0316610f2e5760405162461bcd60e51b815260206004820152601960248201527f496e76616c696420616666696c6961746f7241646472657373000000000000006044820152606401610504565b610f47866020015187608001518860a0015160006115c0565b8560e0015161ffff168660a001516001600160a01b03167ff14fbd8b6e3ad3ae34babfa1f3b6a099f57643662f4cfc24eb335ae8718f534b886020015189606001518a60c001518b60800151604051610fc494939291906001600160a01b0394909416845260208401929092526040830152606082015260800190565b60405180910390a3505050505050565b6001600160a01b03811661102a5760405162461bcd60e51b815260206004820152601a60248201527f496e76616c6964204761735365727669636520416464726573730000000000006044820152606401610504565b7fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a7080546001600160a01b038381167fffffffffffffffffffffffff000000000000000000000000000000000000000083168117909355604080519190921680825260208201939093527fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a6f92917f92e582258b051d853fc828c6d04995b357ec8508517b4e55eced0fd2281191cc91016105f2565b60208101516101208201516000916001600160a01b0316159015611141578061110857600061113a565b8260a0015183606001518460c0015185608001516111269190612f07565b6111309190612f07565b61113a9190612f07565b9392505050565b8061114d57600061113a565b50506060015190565b60606000806111688760400151611743565b905060006111798860200151611743565b9050600061118788886117e1565b9050611192896118e0565b61119c8888611942565b60006111a98a8a8a6119d8565b90506111b78a8a8a85612019565b60006111c68b60200151611743565b60208c01519091506001600160a01b03161561127857838110156112525760405162461bcd60e51b815260206004820152603d60248201527f536f7572636520746f6b656e2062616c616e6365206f6e20636f6e747261637460448201527f206d757374206e6f7420646563726561736520616674657220737761700000006064820152608401610504565b838111156112735760208b01516112739061126d8684612e02565b336120ce565b611347565b876112833486612e02565b61128d9190612f07565b8110156113025760405162461bcd60e51b815260206004820152603d60248201527f536f7572636520746f6b656e2062616c616e6365206f6e20636f6e747261637460448201527f206d757374206e6f7420646563726561736520616674657220737761700000006064820152608401610504565b8761130d3486612e02565b6113179190612f07565b8111156113475760208b01516113479089866113333486612f07565b61133d9190612e02565b61126d9190612e02565b60006113568c60400151611743565b905060006113648783612e02565b90508c61010001518110156113e05760405162461bcd60e51b8152602060048201526024808201527f4f7574707574206973206c657373207468616e206d696e696d756d206578706560448201527f63746564000000000000000000000000000000000000000000000000000000006064820152608401610504565b929c929b50919950505050505050505050565b82610140015161ffff1683600001516001600160a01b03167f0e9201911743fd4d03e146f00ad23945dc8f3ffc200906eff25179a52b726f1785602001518660400151876060015188610100015188888b610160015160405161145c9796959493929190613078565b60405180910390a3505050565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156114d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f691906130be565b905081811015610dda57610dda84847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6120f2565b6000611536826130d7565b60601c92915050565b60006115546001600160a01b038416836121b0565b905080516000141580156115795750808060200190518101906115779190613127565b155b156115bb576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0384166004820152602401610504565b505050565b604080516001600160a01b0386811682526020820186905284168183015290517f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a917fdf4363408b2d9811d1e5c23efdb5bae0b7a68bd9de2de1cbae18a11be3e67ef5919081900360600190a16001600160a01b03851615821561171b5760018201546001600160a01b0387811691161461169d5760405162461bcd60e51b815260206004820152600e60248201527f746f6b656e206d69736d617463680000000000000000000000000000000000006044820152606401610504565b60018201546040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018790526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b1580156116fe57600080fd5b505af1158015611712573d6000803e3d6000fd5b50505050600190505b80156117305761172b84866121be565b61173b565b61173b868587612261565b505050505050565b60006001600160a01b038216156117da576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa1580156117b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d591906130be565b610d33565b4792915050565b60608160008167ffffffffffffffff8111156117ff576117ff61285a565b604051908082528060200260200182016040528015611828578160200160208202803683370190505b5090506000805b838110156118d55786868281811061184957611849613144565b905060200281019061185b9190613173565b61186c90608081019060600161283d565b915061187782611743565b83828151811061188957611889613144565b60209081029190910101526001600160a01b0382166118cd57348382815181106118b5576118b5613144565b602002602001018181516118c99190612e02565b9052505b60010161182f565b509095945050505050565b60008161012001516118f35760006118fc565b6118fc82612375565b826060015161190b9190612f07565b60208301519091506001600160a01b031615611935576119318260200151333084610d5e565b5050565b8034101561193157600080fd5b80366000805b8381101561173b5785858281811061196257611962613144565b90506020028101906119749190613173565b9250611986606084016040850161283d565b915061199860a08401608085016131b1565b80156119ac57506001600160a01b03821615155b156119d0576119d06119c4606085016040860161283d565b33308660a00135610d5e565b600101611948565b60607f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a60005b83811015611c7557816002016000868684818110611a1e57611a1e613144565b9050602002810190611a309190613173565b611a3e90602081019061283d565b6001600160a01b0316815260208101919091526040016000205460ff16611aa75760405162461bcd60e51b815260206004820181905260248201527f436f6e7472616374207370656e646572206e6f742077686974656c69737465646044820152606401610504565b816002016000868684818110611abf57611abf613144565b9050602002810190611ad19190613173565b611ae290604081019060200161283d565b6001600160a01b0316815260208101919091526040016000205460ff16611b4b5760405162461bcd60e51b815260206004820152601f60248201527f436f6e747261637420746172676574206e6f742077686974656c6973746564006044820152606401610504565b6000858583818110611b5f57611b5f613144565b9050602002810190611b719190613173565b611b7f9060c08101906131ce565b611b8e91600491600091613233565b611b979161325d565b9050826003016000878785818110611bb157611bb1613144565b9050602002810190611bc39190613173565b611bd490604081019060200161283d565b6001600160a01b03168152602080820192909252604090810160009081207fffffffff000000000000000000000000000000000000000000000000000000008516825290925290205460ff16611c6c5760405162461bcd60e51b815260206004820152601760248201527f556e617574686f72697a65642063616c6c2064617461210000000000000000006044820152606401610504565b506001016119fe565b50611c7f85612390565b60008367ffffffffffffffff811115611c9a57611c9a61285a565b604051908082528060200260200182016040528015611ccd57816020015b6060815260200190600190039081611cb85790505b5090506000805b8581101561200557868682818110611cee57611cee613144565b9050602002810190611d009190613173565b611d1190606081019060400161283d565b91506001600160a01b038216156000819003611d8a57611d8a83898985818110611d3d57611d3d613144565b9050602002810190611d4f9190613173565b611d5d90602081019061283d565b8a8a86818110611d6f57611d6f613144565b9050602002810190611d819190613173565b60a00135611469565b60008082611e5857898985818110611da457611da4613144565b9050602002810190611db69190613173565b611dc790604081019060200161283d565b6001600160a01b03168a8a86818110611de257611de2613144565b9050602002810190611df49190613173565b611e029060c08101906131ce565b604051611e109291906132a5565b6000604051808303816000865af19150503d8060008114611e4d576040519150601f19603f3d011682016040523d82523d6000602084013e611e52565b606091505b50611f42565b898985818110611e6a57611e6a613144565b9050602002810190611e7c9190613173565b611e8d90604081019060200161283d565b6001600160a01b03168a8a86818110611ea857611ea8613144565b9050602002810190611eba9190613173565b60a001358b8b87818110611ed057611ed0613144565b9050602002810190611ee29190613173565b611ef09060c08101906131ce565b604051611efe9291906132a5565b60006040518083038185875af1925050503d8060008114611f3b576040519150601f19603f3d011682016040523d82523d6000602084013e611f40565b606091505b505b915091507f2fc0d44e6ef6b3e7707cacd3cc326511198c3d1598c65dd54be5a9e37ce02f128a8a86818110611f7957611f79613144565b9050602002810190611f8b9190613173565b611f9c90604081019060200161283d565b8383604051611fad939291906132b5565b60405180910390a181611fdc57611fc3816123a4565b60405162461bcd60e51b815260040161050491906132df565b80868581518110611fef57611fef613144565b6020908102919091010152505050600101611cd4565b5061200f87612403565b5095945050505050565b60008080805b85811015610d1e5786868281811061203957612039613144565b905060200281019061204b9190613173565b61205c90608081019060600161283d565b925061206783611743565b915084818151811061207b5761207b613144565b60200260200101518261208e9190612e02565b93506000841180156120b6575087604001516001600160a01b0316836001600160a01b031614155b156120c6576120c68385336120ce565b60010161201f565b6001600160a01b038316156120e8576115bb838284612261565b6115bb81836121be565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790526121718482612416565b610dda576040516001600160a01b038481166024830152600060448301526121a691869182169063095ea7b390606401610d93565b610dda848261153f565b606061113a838360006124be565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461220b576040519150601f19603f3d011682016040523d82523d6000602084013e612210565b606091505b50509050806115bb5760405162461bcd60e51b815260206004820152601560248201527f6661696c656420746f2073656e64206e617469766500000000000000000000006044820152606401610504565b604080516001600160a01b03848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526000916122e791908616906121b0565b905073a614f803b6fd780986a42c78ec9c7f77e6ded13c6001600160a01b038516148015906123165750805115155b80156123335750808060200190518101906123319190613127565b155b15610dda576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610504565b60008160a001518260c001518360800151610d549190612f07565b806101200151156100f8576100f881612574565b60606044825110156123e957505060408051808201909152601d81527f5472616e73616374696f6e2072657665727465642073696c656e746c79000000602082015290565b60048201915081806020019051810190610d3391906132f2565b8061012001516100f8576100f881612574565b6000806000846001600160a01b0316846040516124339190613360565b6000604051808303816000865af19150503d8060008114612470576040519150601f19603f3d011682016040523d82523d6000602084013e612475565b606091505b509150915081801561249f57508051158061249f57508080602001905181019061249f9190613127565b80156124b557506000856001600160a01b03163b115b95945050505050565b6060814710156124fc576040517fcd786059000000000000000000000000000000000000000000000000000000008152306004820152602401610504565b600080856001600160a01b031684866040516125189190613360565b60006040518083038185875af1925050503d8060008114612555576040519150601f19603f3d011682016040523d82523d6000602084013e61255a565b606091505b509150915061256a868383612761565b9695505050505050565b608081015160a082015160c08301516101208401517f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a931515921515911515906000906125c55785604001516125cb565b85602001515b905083806125d65750825b1561265c5784546001600160a01b03166126325760405162461bcd60e51b815260206004820152601c60248201527f46656520636f6e74726163742061646472657373206e6f7420736574000000006044820152606401610504565b61265c818760a00151886080015161264a9190612f07565b87546001600160a01b031660006115c0565b81156126d15760e08601516001600160a01b03166126bc5760405162461bcd60e51b815260206004820152601960248201527f496e76616c696420616666696c6961746f7241646472657373000000000000006044820152606401610504565b6126d1818760c001518860e0015160006115c0565b83806126da5750825b806126e25750815b1561173b5785610140015161ffff168660e001516001600160a01b03167ff14fbd8b6e3ad3ae34babfa1f3b6a099f57643662f4cfc24eb335ae8718f534b8389608001518a60a001518b60c00151604051610fc494939291906001600160a01b0394909416845260208401929092526040830152606082015260800190565b60608261277657612771826127d6565b61113a565b815115801561278d57506001600160a01b0384163b155b156127cf576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610504565b508061113a565b8051156127e65780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03811681146100f857600080fd5b803561283881612818565b919050565b60006020828403121561284f57600080fd5b813561113a81612818565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610100810167ffffffffffffffff811182821017156128ad576128ad61285a565b60405290565b604051610180810167ffffffffffffffff811182821017156128ad576128ad61285a565b604051610120810167ffffffffffffffff811182821017156128ad576128ad61285a565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156129425761294261285a565b604052919050565b80151581146100f857600080fd5b80356128388161294a565b803561ffff8116811461283857600080fd5b600067ffffffffffffffff82111561298f5761298f61285a565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600082601f8301126129cc57600080fd5b81356129df6129da82612975565b6128fb565b8181528460208386010111156129f457600080fd5b816020850160208301376000918101602001919091529392505050565b60008083601f840112612a2357600080fd5b50813567ffffffffffffffff811115612a3b57600080fd5b6020830191508360208260051b8501011115612a5657600080fd5b9250929050565b80356002811061283857600080fd5b60006101008284031215612a7f57600080fd5b612a87612889565b9050612a9282612a5d565b8152602082013567ffffffffffffffff80821115612aaf57600080fd5b612abb858386016129bb565b6020840152604084013560408401526060840135915080821115612ade57600080fd5b612aea858386016129bb565b60608401526080840135915080821115612b0357600080fd5b612b0f858386016129bb565b608084015260a084013560a0840152612b2a60c0850161282d565b60c084015260e0840135915080821115612b4357600080fd5b50612b50848285016129bb565b60e08301525092915050565b60008060008060608587031215612b7257600080fd5b843567ffffffffffffffff80821115612b8a57600080fd5b908601906101808289031215612b9f57600080fd5b612ba76128b3565b612bb08361282d565b8152612bbe6020840161282d565b6020820152612bcf6040840161282d565b6040820152606083013560608201526080830135608082015260a083013560a082015260c083013560c0820152612c0860e0840161282d565b60e08201526101008381013590820152610120612c26818501612958565b90820152610140612c38848201612963565b908201526101608381013583811115612c5057600080fd5b612c5c8b8287016129bb565b828401525050809650506020870135915080821115612c7a57600080fd5b612c8688838901612a11565b90955093506040870135915080821115612c9f57600080fd5b50612cac87828801612a6c565b91505092959194509250565b60008060408385031215612ccb57600080fd5b823567ffffffffffffffff80821115612ce357600080fd5b612cef86838701612a6c565b93506020850135915080821115612d0557600080fd5b908401906101208287031215612d1a57600080fd5b612d226128d7565b612d2b8361282d565b8152612d396020840161282d565b6020820152604083013560408201526060830135606082015260808301356080820152612d6860a0840161282d565b60a082015260c083013560c0820152612d8360e08401612963565b60e08201526101008084013583811115612d9c57600080fd5b612da8898287016129bb565b8284015250508093505050509250929050565b600060408284031215612dcd57600080fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610d3357610d33612dd3565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60005b83811015612e5f578181015183820152602001612e47565b50506000910152565b60008151808452612e80816020860160208601612e44565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60006001600160a01b03808a168352886020840152808816604084015250856060830152841515608083015283151560a083015260e060c0830152612efa60e0830184612e68565b9998505050505050505050565b80820180821115610d3357610d33612dd3565b608081526000612f2d6080830187612e68565b8281036020840152612f3f8187612e68565b90508281036040840152612f538186612e68565b91505082606083015295945050505050565b8481526001600160a01b0384166020820152608060408201526000612f8d6080830185612e68565b905082606083015295945050505050565b60006001600160a01b03808a16835260e06020840152612fc160e084018a612e68565b8381036040850152612fd3818a612e68565b90508381036060850152612fe78189612e68565b90508381036080850152612ffb8188612e68565b60a0850196909652509290921660c0909101525095945050505050565b60a08152600061302b60a0830188612e68565b828103602084015261303d8188612e68565b905082810360408401526130518187612e68565b905082810360608401526130658186612e68565b9150508260808301529695505050505050565b60006001600160a01b03808a168352808916602084015287604084015286606084015285608084015280851660a08401525060e060c0830152612efa60e0830184612e68565b6000602082840312156130d057600080fd5b5051919050565b6000815160208301517fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008082169350601483101561311f5780818460140360031b1b83161693505b505050919050565b60006020828403121561313957600080fd5b815161113a8161294a565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff218336030181126131a757600080fd5b9190910192915050565b6000602082840312156131c357600080fd5b813561113a8161294a565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261320357600080fd5b83018035915067ffffffffffffffff82111561321e57600080fd5b602001915036819003821315612a5657600080fd5b6000808585111561324357600080fd5b8386111561325057600080fd5b5050820193919092039150565b7fffffffff00000000000000000000000000000000000000000000000000000000813581811691600485101561329d5780818660040360031b1b83161692505b505092915050565b8183823760009101908152919050565b6001600160a01b038416815282151560208201526060604082015260006124b56060830184612e68565b60208152600061113a6020830184612e68565b60006020828403121561330457600080fd5b815167ffffffffffffffff81111561331b57600080fd5b8201601f8101841361332c57600080fd5b805161333a6129da82612975565b81815285602083850101111561334f57600080fd5b6124b5826020830160208601612e44565b600082516131a7818460208701612e4456fea2646970667358221220ec16253f7cf982d67770f15026b1ccf48b12e3ecd789f255b5f1f9a5406b455c64736f6c63430008190033
Deployed Bytecode
0x60806040526004361061005a5760003560e01c8063661553751161004357806366155375146100945780638e6eea55146100a7578063d9f03f29146100c757600080fd5b806359c94b371461005f5780635a18f94114610081575b600080fd5b34801561006b57600080fd5b5061007f61007a36600461283d565b6100e7565b005b61007f61008f366004612b5c565b6100fb565b61007f6100a2366004612cb8565b610282565b3480156100b357600080fd5b5061007f6100c2366004612dbb565b610420565b3480156100d357600080fd5b5061007f6100e236600461283d565b610455565b6100ef610466565b6100f88161050f565b50565b7f4fe94118b1030ac5f570795d403ee5116fd91b8f0b5d11f2487377c2b0ab255980547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01610176576040517f29f745a700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181556101826105ff565b60408501516000906001600160a01b031615801561019e575034155b156101c6578260a001516101b58787876000610672565b6101bf9190612e02565b90506101d9565b6101d68686868660a00151610672565b90505b6101e883876040015183610726565b61014086015161ffff16600960ff1687600001516001600160a01b03167f012c155f3836c4edb9222305b909a109f9efa46288efffe40a0e66da3a9a98008960400151856102398960200151610d28565b60408a015160018b51600181111561025357610253612e15565b1460008f610160015160405161026f9796959493929190612eb2565b60405180910390a4506000905550505050565b7f4fe94118b1030ac5f570795d403ee5116fd91b8f0b5d11f2487377c2b0ab255980547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff016102fd576040517f29f745a700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181556103096105ff565b60408201516020830151600061031e85610d39565b6103289084612f07565b90506001600160a01b0382161561035b5761034582333084610d5e565b8560a0015134101561035657600080fd5b610376565b60a086015161036a9082612f07565b34101561037657600080fd5b61037f85610de0565b61038a868385610726565b60e085015161ffff16600960ff1686600001516001600160a01b03167f012c155f3836c4edb9222305b909a109f9efa46288efffe40a0e66da3a9a980085876103d68c60200151610d28565b60408d015160018e5160018111156103f0576103f0612e15565b1460008e610100015160405161040c9796959493929190612eb2565b60405180910390a450506000909155505050565b610428610466565b61043d610438602083018361283d565b61050f565b6100f8610450604083016020840161283d565b610fd4565b61045d610466565b6100f881610fd4565b7fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c600401546001600160a01b0316331461050d5760405162461bcd60e51b815260206004820152602260248201527f4c69624469616d6f6e643a204d75737420626520636f6e7472616374206f776e60448201527f657200000000000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b565b6001600160a01b0381166105655760405162461bcd60e51b815260206004820152601760248201527f496e76616c6964204761746577617920416464726573730000000000000000006044820152606401610504565b7fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a6f80546001600160a01b038381167fffffffffffffffffffffffff000000000000000000000000000000000000000083168117845560408051929093168083526020830191909152917fc5474af28634e5155be634ccaea8d3e9e77344679b451d664aef7e190a1ba17e91015b60405180910390a1505050565b7f322c2f1d9209969f334c8955443b224cadc85f453939eb2b4ffb8af019944ece805460ff16156100f85760405162461bcd60e51b815260206004820152600660248201527f50617573656400000000000000000000000000000000000000000000000000006044820152606401610504565b6000808261067f876110de565b6106899190612f07565b9050803410156107015760405162461bcd60e51b815260206004820152602960248201527f53656e64206d6f72652045544820746f20636f76657220696e70757420616d6f60448201527f756e74202b2066656500000000000000000000000000000000000000000000006064820152608401610504565b61070d86868686611156565b925061071d9050868360006113f3565b50949350505050565b60408301517fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a6f80549091906001600160a01b03166107cc5760405162461bcd60e51b815260206004820152602160248201527f536174656c6c69746520676174657761792061646472657373206e6f7420736560448201527f74000000000000000000000000000000000000000000000000000000000000006064820152608401610504565b8046036108415760405162461bcd60e51b815260206004820152603d60248201527f496e76616c69642064657374696e6174696f6e20436861696e212043616e6e6f60448201527f742062726964676520746f207468652073616d65206e6574776f726b2e0000006064820152608401610504565b60c08501517f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a9085906001600160a01b0382166108e7578260010160009054906101000a90046001600160a01b03169150816001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b1580156108cd57600080fd5b505af11580156108e1573d6000803e3d6000fd5b50505050505b6001600160a01b0381166108f85750335b6001600160a01b0382166109745760405162461bcd60e51b815260206004820152603660248201527f536f7572636520746f6b656e2061646472657373206973206e756c6c21204e6f60448201527f7420737570706f72746564206279206178656c617221000000000000000000006064820152608401610504565b845461098b9083906001600160a01b031688611469565b6000885160018111156109a0576109a0612e15565b03610aca5760a0880151156109f75760405162461bcd60e51b815260206004820152601b60248201527f4e6f2072656c6179657247617320666f722073656e64546f6b656e00000000006044820152606401610504565b8454606089015160208a015160808b01516040517f26ef699d0000000000000000000000000000000000000000000000000000000081526001600160a01b03909416936326ef699d93610a5293909290918c90600401612f1a565b600060405180830381600087803b158015610a6c57600080fd5b505af1158015610a80573d6000803e3d6000fd5b505050507f675fd9e5424c5cee2cedf832b1b0cc06c164d6fa74b75ce1e7c9359e7446316384838a6020015189604051610abd9493929190612f65565b60405180910390a1610d1e565b60018501546001600160a01b0316610b495760405162461bcd60e51b8152602060048201526024808201527f536174656c6c69746520676173536572766963652061646472657373206e6f7460448201527f20736574000000000000000000000000000000000000000000000000000000006064820152608401610504565b60008860a0015111610bc35760405162461bcd60e51b815260206004820152602360248201527f6178656c6172206e65656473206e61746976652066656520666f722072656c6160448201527f79657200000000000000000000000000000000000000000000000000000000006064820152608401610504565b6000600189516001811115610bda57610bda612e15565b14610bf357604080516000815260208101909152610bf9565b8860e001515b90508560010160009054906101000a90046001600160a01b03166001600160a01b031663c62c20028a60a00151308c606001518d60200151868f608001518e8a6040518963ffffffff1660e01b8152600401610c5b9796959493929190612f9e565b6000604051808303818588803b158015610c7457600080fd5b505af1158015610c88573d6000803e3d6000fd5b5050885460608d015160208e015160808f01516040517fb54170840000000000000000000000000000000000000000000000000000000081526001600160a01b03909416965063b54170849550610cea94509192909187918e90600401613018565b600060405180830381600087803b158015610d0457600080fd5b505af1158015610d18573d6000803e3d6000fd5b50505050505b5050505050505050565b6000610d338261152b565b92915050565b60008160c0015182608001518360600151610d549190612f07565b610d339190612f07565b6040516001600160a01b038481166024830152838116604483015260648201839052610dda9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061153f565b50505050565b606081015160c082015160808301519115159190151590151560008380610e045750825b80610e0c5750815b905080610e1a575050505050565b7f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a8480610e445750835b15610ece5780546001600160a01b0316610ea05760405162461bcd60e51b815260206004820152601c60248201527f46656520636f6e74726163742061646472657373206e6f7420736574000000006044820152606401610504565b610ece86602001518760c001518860600151610ebc9190612f07565b83546001600160a01b031660006115c0565b8215610f475760a08601516001600160a01b0316610f2e5760405162461bcd60e51b815260206004820152601960248201527f496e76616c696420616666696c6961746f7241646472657373000000000000006044820152606401610504565b610f47866020015187608001518860a0015160006115c0565b8560e0015161ffff168660a001516001600160a01b03167ff14fbd8b6e3ad3ae34babfa1f3b6a099f57643662f4cfc24eb335ae8718f534b886020015189606001518a60c001518b60800151604051610fc494939291906001600160a01b0394909416845260208401929092526040830152606082015260800190565b60405180910390a3505050505050565b6001600160a01b03811661102a5760405162461bcd60e51b815260206004820152601a60248201527f496e76616c6964204761735365727669636520416464726573730000000000006044820152606401610504565b7fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a7080546001600160a01b038381167fffffffffffffffffffffffff000000000000000000000000000000000000000083168117909355604080519190921680825260208201939093527fe97496d8273588711c444d166dc378e07de45d7ba4c6f83debe0eaef953c5a6f92917f92e582258b051d853fc828c6d04995b357ec8508517b4e55eced0fd2281191cc91016105f2565b60208101516101208201516000916001600160a01b0316159015611141578061110857600061113a565b8260a0015183606001518460c0015185608001516111269190612f07565b6111309190612f07565b61113a9190612f07565b9392505050565b8061114d57600061113a565b50506060015190565b60606000806111688760400151611743565b905060006111798860200151611743565b9050600061118788886117e1565b9050611192896118e0565b61119c8888611942565b60006111a98a8a8a6119d8565b90506111b78a8a8a85612019565b60006111c68b60200151611743565b60208c01519091506001600160a01b03161561127857838110156112525760405162461bcd60e51b815260206004820152603d60248201527f536f7572636520746f6b656e2062616c616e6365206f6e20636f6e747261637460448201527f206d757374206e6f7420646563726561736520616674657220737761700000006064820152608401610504565b838111156112735760208b01516112739061126d8684612e02565b336120ce565b611347565b876112833486612e02565b61128d9190612f07565b8110156113025760405162461bcd60e51b815260206004820152603d60248201527f536f7572636520746f6b656e2062616c616e6365206f6e20636f6e747261637460448201527f206d757374206e6f7420646563726561736520616674657220737761700000006064820152608401610504565b8761130d3486612e02565b6113179190612f07565b8111156113475760208b01516113479089866113333486612f07565b61133d9190612e02565b61126d9190612e02565b60006113568c60400151611743565b905060006113648783612e02565b90508c61010001518110156113e05760405162461bcd60e51b8152602060048201526024808201527f4f7574707574206973206c657373207468616e206d696e696d756d206578706560448201527f63746564000000000000000000000000000000000000000000000000000000006064820152608401610504565b929c929b50919950505050505050505050565b82610140015161ffff1683600001516001600160a01b03167f0e9201911743fd4d03e146f00ad23945dc8f3ffc200906eff25179a52b726f1785602001518660400151876060015188610100015188888b610160015160405161145c9796959493929190613078565b60405180910390a3505050565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156114d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f691906130be565b905081811015610dda57610dda84847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6120f2565b6000611536826130d7565b60601c92915050565b60006115546001600160a01b038416836121b0565b905080516000141580156115795750808060200190518101906115779190613127565b155b156115bb576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0384166004820152602401610504565b505050565b604080516001600160a01b0386811682526020820186905284168183015290517f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a917fdf4363408b2d9811d1e5c23efdb5bae0b7a68bd9de2de1cbae18a11be3e67ef5919081900360600190a16001600160a01b03851615821561171b5760018201546001600160a01b0387811691161461169d5760405162461bcd60e51b815260206004820152600e60248201527f746f6b656e206d69736d617463680000000000000000000000000000000000006044820152606401610504565b60018201546040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018790526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b1580156116fe57600080fd5b505af1158015611712573d6000803e3d6000fd5b50505050600190505b80156117305761172b84866121be565b61173b565b61173b868587612261565b505050505050565b60006001600160a01b038216156117da576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa1580156117b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d591906130be565b610d33565b4792915050565b60608160008167ffffffffffffffff8111156117ff576117ff61285a565b604051908082528060200260200182016040528015611828578160200160208202803683370190505b5090506000805b838110156118d55786868281811061184957611849613144565b905060200281019061185b9190613173565b61186c90608081019060600161283d565b915061187782611743565b83828151811061188957611889613144565b60209081029190910101526001600160a01b0382166118cd57348382815181106118b5576118b5613144565b602002602001018181516118c99190612e02565b9052505b60010161182f565b509095945050505050565b60008161012001516118f35760006118fc565b6118fc82612375565b826060015161190b9190612f07565b60208301519091506001600160a01b031615611935576119318260200151333084610d5e565b5050565b8034101561193157600080fd5b80366000805b8381101561173b5785858281811061196257611962613144565b90506020028101906119749190613173565b9250611986606084016040850161283d565b915061199860a08401608085016131b1565b80156119ac57506001600160a01b03821615155b156119d0576119d06119c4606085016040860161283d565b33308660a00135610d5e565b600101611948565b60607f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a60005b83811015611c7557816002016000868684818110611a1e57611a1e613144565b9050602002810190611a309190613173565b611a3e90602081019061283d565b6001600160a01b0316815260208101919091526040016000205460ff16611aa75760405162461bcd60e51b815260206004820181905260248201527f436f6e7472616374207370656e646572206e6f742077686974656c69737465646044820152606401610504565b816002016000868684818110611abf57611abf613144565b9050602002810190611ad19190613173565b611ae290604081019060200161283d565b6001600160a01b0316815260208101919091526040016000205460ff16611b4b5760405162461bcd60e51b815260206004820152601f60248201527f436f6e747261637420746172676574206e6f742077686974656c6973746564006044820152606401610504565b6000858583818110611b5f57611b5f613144565b9050602002810190611b719190613173565b611b7f9060c08101906131ce565b611b8e91600491600091613233565b611b979161325d565b9050826003016000878785818110611bb157611bb1613144565b9050602002810190611bc39190613173565b611bd490604081019060200161283d565b6001600160a01b03168152602080820192909252604090810160009081207fffffffff000000000000000000000000000000000000000000000000000000008516825290925290205460ff16611c6c5760405162461bcd60e51b815260206004820152601760248201527f556e617574686f72697a65642063616c6c2064617461210000000000000000006044820152606401610504565b506001016119fe565b50611c7f85612390565b60008367ffffffffffffffff811115611c9a57611c9a61285a565b604051908082528060200260200182016040528015611ccd57816020015b6060815260200190600190039081611cb85790505b5090506000805b8581101561200557868682818110611cee57611cee613144565b9050602002810190611d009190613173565b611d1190606081019060400161283d565b91506001600160a01b038216156000819003611d8a57611d8a83898985818110611d3d57611d3d613144565b9050602002810190611d4f9190613173565b611d5d90602081019061283d565b8a8a86818110611d6f57611d6f613144565b9050602002810190611d819190613173565b60a00135611469565b60008082611e5857898985818110611da457611da4613144565b9050602002810190611db69190613173565b611dc790604081019060200161283d565b6001600160a01b03168a8a86818110611de257611de2613144565b9050602002810190611df49190613173565b611e029060c08101906131ce565b604051611e109291906132a5565b6000604051808303816000865af19150503d8060008114611e4d576040519150601f19603f3d011682016040523d82523d6000602084013e611e52565b606091505b50611f42565b898985818110611e6a57611e6a613144565b9050602002810190611e7c9190613173565b611e8d90604081019060200161283d565b6001600160a01b03168a8a86818110611ea857611ea8613144565b9050602002810190611eba9190613173565b60a001358b8b87818110611ed057611ed0613144565b9050602002810190611ee29190613173565b611ef09060c08101906131ce565b604051611efe9291906132a5565b60006040518083038185875af1925050503d8060008114611f3b576040519150601f19603f3d011682016040523d82523d6000602084013e611f40565b606091505b505b915091507f2fc0d44e6ef6b3e7707cacd3cc326511198c3d1598c65dd54be5a9e37ce02f128a8a86818110611f7957611f79613144565b9050602002810190611f8b9190613173565b611f9c90604081019060200161283d565b8383604051611fad939291906132b5565b60405180910390a181611fdc57611fc3816123a4565b60405162461bcd60e51b815260040161050491906132df565b80868581518110611fef57611fef613144565b6020908102919091010152505050600101611cd4565b5061200f87612403565b5095945050505050565b60008080805b85811015610d1e5786868281811061203957612039613144565b905060200281019061204b9190613173565b61205c90608081019060600161283d565b925061206783611743565b915084818151811061207b5761207b613144565b60200260200101518261208e9190612e02565b93506000841180156120b6575087604001516001600160a01b0316836001600160a01b031614155b156120c6576120c68385336120ce565b60010161201f565b6001600160a01b038316156120e8576115bb838284612261565b6115bb81836121be565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790526121718482612416565b610dda576040516001600160a01b038481166024830152600060448301526121a691869182169063095ea7b390606401610d93565b610dda848261153f565b606061113a838360006124be565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461220b576040519150601f19603f3d011682016040523d82523d6000602084013e612210565b606091505b50509050806115bb5760405162461bcd60e51b815260206004820152601560248201527f6661696c656420746f2073656e64206e617469766500000000000000000000006044820152606401610504565b604080516001600160a01b03848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526000916122e791908616906121b0565b905073a614f803b6fd780986a42c78ec9c7f77e6ded13c6001600160a01b038516148015906123165750805115155b80156123335750808060200190518101906123319190613127565b155b15610dda576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610504565b60008160a001518260c001518360800151610d549190612f07565b806101200151156100f8576100f881612574565b60606044825110156123e957505060408051808201909152601d81527f5472616e73616374696f6e2072657665727465642073696c656e746c79000000602082015290565b60048201915081806020019051810190610d3391906132f2565b8061012001516100f8576100f881612574565b6000806000846001600160a01b0316846040516124339190613360565b6000604051808303816000865af19150503d8060008114612470576040519150601f19603f3d011682016040523d82523d6000602084013e612475565b606091505b509150915081801561249f57508051158061249f57508080602001905181019061249f9190613127565b80156124b557506000856001600160a01b03163b115b95945050505050565b6060814710156124fc576040517fcd786059000000000000000000000000000000000000000000000000000000008152306004820152602401610504565b600080856001600160a01b031684866040516125189190613360565b60006040518083038185875af1925050503d8060008114612555576040519150601f19603f3d011682016040523d82523d6000602084013e61255a565b606091505b509150915061256a868383612761565b9695505050505050565b608081015160a082015160c08301516101208401517f43da06808a8e54e76a41d6f7b48ddfb23969b1387a8710ef6241423a5aefe64a931515921515911515906000906125c55785604001516125cb565b85602001515b905083806125d65750825b1561265c5784546001600160a01b03166126325760405162461bcd60e51b815260206004820152601c60248201527f46656520636f6e74726163742061646472657373206e6f7420736574000000006044820152606401610504565b61265c818760a00151886080015161264a9190612f07565b87546001600160a01b031660006115c0565b81156126d15760e08601516001600160a01b03166126bc5760405162461bcd60e51b815260206004820152601960248201527f496e76616c696420616666696c6961746f7241646472657373000000000000006044820152606401610504565b6126d1818760c001518860e0015160006115c0565b83806126da5750825b806126e25750815b1561173b5785610140015161ffff168660e001516001600160a01b03167ff14fbd8b6e3ad3ae34babfa1f3b6a099f57643662f4cfc24eb335ae8718f534b8389608001518a60a001518b60c00151604051610fc494939291906001600160a01b0394909416845260208401929092526040830152606082015260800190565b60608261277657612771826127d6565b61113a565b815115801561278d57506001600160a01b0384163b155b156127cf576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610504565b508061113a565b8051156127e65780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03811681146100f857600080fd5b803561283881612818565b919050565b60006020828403121561284f57600080fd5b813561113a81612818565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610100810167ffffffffffffffff811182821017156128ad576128ad61285a565b60405290565b604051610180810167ffffffffffffffff811182821017156128ad576128ad61285a565b604051610120810167ffffffffffffffff811182821017156128ad576128ad61285a565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156129425761294261285a565b604052919050565b80151581146100f857600080fd5b80356128388161294a565b803561ffff8116811461283857600080fd5b600067ffffffffffffffff82111561298f5761298f61285a565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600082601f8301126129cc57600080fd5b81356129df6129da82612975565b6128fb565b8181528460208386010111156129f457600080fd5b816020850160208301376000918101602001919091529392505050565b60008083601f840112612a2357600080fd5b50813567ffffffffffffffff811115612a3b57600080fd5b6020830191508360208260051b8501011115612a5657600080fd5b9250929050565b80356002811061283857600080fd5b60006101008284031215612a7f57600080fd5b612a87612889565b9050612a9282612a5d565b8152602082013567ffffffffffffffff80821115612aaf57600080fd5b612abb858386016129bb565b6020840152604084013560408401526060840135915080821115612ade57600080fd5b612aea858386016129bb565b60608401526080840135915080821115612b0357600080fd5b612b0f858386016129bb565b608084015260a084013560a0840152612b2a60c0850161282d565b60c084015260e0840135915080821115612b4357600080fd5b50612b50848285016129bb565b60e08301525092915050565b60008060008060608587031215612b7257600080fd5b843567ffffffffffffffff80821115612b8a57600080fd5b908601906101808289031215612b9f57600080fd5b612ba76128b3565b612bb08361282d565b8152612bbe6020840161282d565b6020820152612bcf6040840161282d565b6040820152606083013560608201526080830135608082015260a083013560a082015260c083013560c0820152612c0860e0840161282d565b60e08201526101008381013590820152610120612c26818501612958565b90820152610140612c38848201612963565b908201526101608381013583811115612c5057600080fd5b612c5c8b8287016129bb565b828401525050809650506020870135915080821115612c7a57600080fd5b612c8688838901612a11565b90955093506040870135915080821115612c9f57600080fd5b50612cac87828801612a6c565b91505092959194509250565b60008060408385031215612ccb57600080fd5b823567ffffffffffffffff80821115612ce357600080fd5b612cef86838701612a6c565b93506020850135915080821115612d0557600080fd5b908401906101208287031215612d1a57600080fd5b612d226128d7565b612d2b8361282d565b8152612d396020840161282d565b6020820152604083013560408201526060830135606082015260808301356080820152612d6860a0840161282d565b60a082015260c083013560c0820152612d8360e08401612963565b60e08201526101008084013583811115612d9c57600080fd5b612da8898287016129bb565b8284015250508093505050509250929050565b600060408284031215612dcd57600080fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610d3357610d33612dd3565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60005b83811015612e5f578181015183820152602001612e47565b50506000910152565b60008151808452612e80816020860160208601612e44565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60006001600160a01b03808a168352886020840152808816604084015250856060830152841515608083015283151560a083015260e060c0830152612efa60e0830184612e68565b9998505050505050505050565b80820180821115610d3357610d33612dd3565b608081526000612f2d6080830187612e68565b8281036020840152612f3f8187612e68565b90508281036040840152612f538186612e68565b91505082606083015295945050505050565b8481526001600160a01b0384166020820152608060408201526000612f8d6080830185612e68565b905082606083015295945050505050565b60006001600160a01b03808a16835260e06020840152612fc160e084018a612e68565b8381036040850152612fd3818a612e68565b90508381036060850152612fe78189612e68565b90508381036080850152612ffb8188612e68565b60a0850196909652509290921660c0909101525095945050505050565b60a08152600061302b60a0830188612e68565b828103602084015261303d8188612e68565b905082810360408401526130518187612e68565b905082810360608401526130658186612e68565b9150508260808301529695505050505050565b60006001600160a01b03808a168352808916602084015287604084015286606084015285608084015280851660a08401525060e060c0830152612efa60e0830184612e68565b6000602082840312156130d057600080fd5b5051919050565b6000815160208301517fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008082169350601483101561311f5780818460140360031b1b83161693505b505050919050565b60006020828403121561313957600080fd5b815161113a8161294a565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff218336030181126131a757600080fd5b9190910192915050565b6000602082840312156131c357600080fd5b813561113a8161294a565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261320357600080fd5b83018035915067ffffffffffffffff82111561321e57600080fd5b602001915036819003821315612a5657600080fd5b6000808585111561324357600080fd5b8386111561325057600080fd5b5050820193919092039150565b7fffffffff00000000000000000000000000000000000000000000000000000000813581811691600485101561329d5780818660040360031b1b83161692505b505092915050565b8183823760009101908152919050565b6001600160a01b038416815282151560208201526060604082015260006124b56060830184612e68565b60208152600061113a6020830184612e68565b60006020828403121561330457600080fd5b815167ffffffffffffffff81111561331b57600080fd5b8201601f8101841361332c57600080fd5b805161333a6129da82612975565b81815285602083850101111561334f57600080fd5b6124b5826020830160208601612e44565b600082516131a7818460208701612e4456fea2646970667358221220ec16253f7cf982d67770f15026b1ccf48b12e3ecd789f255b5f1f9a5406b455c64736f6c63430008190033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 32 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.