Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
AggregatorConnector
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {
ISwapConnector, SwapParams
} from "contracts/interfaces/ISwapConnector.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
struct AggregatorExtraData {
bytes data;
}
contract AggregatorConnector is ISwapConnector {
error AggregatorSwapFailed(bytes error);
error NotImplemented();
error InvalidInputValue();
error InsufficientOutputAmount(uint256 received, uint256 minRequired);
error InvalidOutputToken();
event SwapExecuted(
address indexed router,
address indexed tokenIn,
address indexed tokenOut,
uint256 amountIn,
uint256 desiredAmountOut,
uint256 minAmountOut,
uint256 actualAmountOut
);
function swapExactTokensForTokens(
SwapParams memory swap
) external override {
if (swap.tokenIn == swap.tokenOut) {
revert InvalidOutputToken();
}
AggregatorExtraData memory extraData =
abi.decode(swap.extraData, (AggregatorExtraData));
// For swaps to ETH, tokenOut is address(0)
bool isETHOut = swap.tokenOut == address(0);
uint256 balanceBefore = isETHOut
? address(this).balance
: IERC20(swap.tokenOut).balanceOf(address(this));
(bool success, bytes memory error) = swap.router.call(extraData.data);
if (!success) {
revert AggregatorSwapFailed(error);
}
uint256 balanceAfter = isETHOut
? address(this).balance
: IERC20(swap.tokenOut).balanceOf(address(this));
uint256 amountReceived = balanceAfter - balanceBefore;
if (amountReceived < swap.minAmountOut) {
revert InsufficientOutputAmount(amountReceived, swap.minAmountOut);
}
emit SwapExecuted(
swap.router,
swap.tokenIn,
swap.tokenOut,
swap.amountIn,
swap.desiredAmountOut,
swap.minAmountOut,
amountReceived
);
}
function swapExactETHForTokens(
SwapParams memory swap
) external override {
AggregatorExtraData memory extraData =
abi.decode(swap.extraData, (AggregatorExtraData));
// For ETH to token swaps, tokenOut should be a valid token
if (swap.tokenOut == address(0)) {
revert InvalidOutputToken();
}
uint256 balanceBefore = IERC20(swap.tokenOut).balanceOf(address(this));
(bool success, bytes memory error) =
swap.router.call{ value: swap.amountIn }(extraData.data);
if (!success) {
revert AggregatorSwapFailed(error);
}
uint256 balanceAfter = IERC20(swap.tokenOut).balanceOf(address(this));
uint256 amountReceived = balanceAfter - balanceBefore;
if (amountReceived < swap.minAmountOut) {
revert InsufficientOutputAmount(amountReceived, swap.minAmountOut);
}
emit SwapExecuted(
swap.router,
swap.tokenIn,
swap.tokenOut,
swap.amountIn,
swap.desiredAmountOut,
swap.minAmountOut,
amountReceived
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { SwapParams } from "contracts/structs/SwapStructs.sol";
interface ISwapConnector {
function swapExactTokensForTokens(
SwapParams memory swap
) external;
function swapExactETHForTokens(
SwapParams memory swap
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
struct SwapParams {
address tokenApproval;
address router;
uint256 amountIn;
uint256 desiredAmountOut;
uint256 minAmountOut;
address tokenIn;
address tokenOut;
bytes extraData;
}{
"remappings": [
"solmate/=lib/solmate/src/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@morpho-blue/=lib/morpho-blue/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"morpho-blue/=lib/morpho-blue/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"bytes","name":"error","type":"bytes"}],"name":"AggregatorSwapFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"received","type":"uint256"},{"internalType":"uint256","name":"minRequired","type":"uint256"}],"name":"InsufficientOutputAmount","type":"error"},{"inputs":[],"name":"InvalidInputValue","type":"error"},{"inputs":[],"name":"InvalidOutputToken","type":"error"},{"inputs":[],"name":"NotImplemented","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"router","type":"address"},{"indexed":true,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"desiredAmountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"actualAmountOut","type":"uint256"}],"name":"SwapExecuted","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"tokenApproval","type":"address"},{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"desiredAmountOut","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"internalType":"struct SwapParams","name":"swap","type":"tuple"}],"name":"swapExactETHForTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenApproval","type":"address"},{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"desiredAmountOut","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"internalType":"struct SwapParams","name":"swap","type":"tuple"}],"name":"swapExactTokensForTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b5061094c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806353ef91201461003b578063e697fa5314610050575b600080fd5b61004e6100493660046106e8565b610063565b005b61004e61005e3660046106e8565b61032d565b8060c001516001600160a01b03168160a001516001600160a01b03160361009c576040516231010160e51b815260040160405180910390fd5b60008160e001518060200190518101906100b691906107dc565b60c08301519091506001600160a01b0316156000816101425760c08401516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610119573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061013d9190610887565b610144565b475b905060008085602001516001600160a01b0316856000015160405161016991906108a0565b6000604051808303816000865af19150503d80600081146101a6576040519150601f19603f3d011682016040523d82523d6000602084013e6101ab565b606091505b5091509150816101d9578060405163bf91046160e01b81526004016101d091906108bc565b60405180910390fd5b6000846102535760c08701516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa15801561022a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061024e9190610887565b610255565b475b9050600061026385836108ef565b9050876080015181101561029a57608088015160405163d28d3eb560e01b81526101d0918391600401918252602082015260400190565b8760c001516001600160a01b03168860a001516001600160a01b031689602001516001600160a01b03167f43415e25edb52db0638ec44209302ce9df6ab6fa46a2233aee34f9c75471ea268b604001518c606001518d608001518760405161031b949392919093845260208401929092526040830152606082015260800190565b60405180910390a45050505050505050565b60008160e0015180602001905181019061034791906107dc565b60c08301519091506001600160a01b0316610374576040516231010160e51b815260040160405180910390fd5b60c08201516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156103bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103e39190610887565b905060008084602001516001600160a01b03168560400151856000015160405161040d91906108a0565b60006040518083038185875af1925050503d806000811461044a576040519150601f19603f3d011682016040523d82523d6000602084013e61044f565b606091505b509150915081610474578060405163bf91046160e01b81526004016101d091906108bc565b60c08501516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156104bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104e39190610887565b905060006104f185836108ef565b9050866080015181101561052857608087015160405163d28d3eb560e01b81526101d0918391600401918252602082015260400190565b8660c001516001600160a01b03168760a001516001600160a01b031688602001516001600160a01b03167f43415e25edb52db0638ec44209302ce9df6ab6fa46a2233aee34f9c75471ea268a604001518b606001518c60800151876040516105a9949392919093845260208401929092526040830152606082015260800190565b60405180910390a450505050505050565b634e487b7160e01b600052604160045260246000fd5b604051610100810167ffffffffffffffff811182821017156105f4576105f46105ba565b60405290565b6040516020810167ffffffffffffffff811182821017156105f4576105f46105ba565b604051601f8201601f1916810167ffffffffffffffff81118282101715610646576106466105ba565b604052919050565b80356001600160a01b038116811461066557600080fd5b919050565b600067ffffffffffffffff821115610684576106846105ba565b50601f01601f191660200190565b600082601f8301126106a357600080fd5b81356106b66106b18261066a565b61061d565b8181528460208386010111156106cb57600080fd5b816020850160208301376000918101602001919091529392505050565b6000602082840312156106fa57600080fd5b813567ffffffffffffffff8082111561071257600080fd5b90830190610100828603121561072757600080fd5b61072f6105d0565b6107388361064e565b81526107466020840161064e565b602082015260408301356040820152606083013560608201526080830135608082015261077560a0840161064e565b60a082015261078660c0840161064e565b60c082015260e08301358281111561079d57600080fd5b6107a987828601610692565b60e08301525095945050505050565b60005b838110156107d35781810151838201526020016107bb565b50506000910152565b6000602082840312156107ee57600080fd5b815167ffffffffffffffff8082111561080657600080fd5b908301906020828603121561081a57600080fd5b6108226105fa565b82518281111561083157600080fd5b80840193505085601f84011261084657600080fd5b825191506108566106b18361066a565b82815286602084860101111561086b57600080fd5b61087c8360208301602087016107b8565b815295945050505050565b60006020828403121561089957600080fd5b5051919050565b600082516108b28184602087016107b8565b9190910192915050565b60208152600082518060208401526108db8160408501602087016107b8565b601f01601f19169190910160400192915050565b8181038181111561091057634e487b7160e01b600052601160045260246000fd5b9291505056fea2646970667358221220ca745e2c2437eadcf6d8953eab10d4a15e9fcd78e4a35780f4b5189cccca7a7e64736f6c63430008130033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100365760003560e01c806353ef91201461003b578063e697fa5314610050575b600080fd5b61004e6100493660046106e8565b610063565b005b61004e61005e3660046106e8565b61032d565b8060c001516001600160a01b03168160a001516001600160a01b03160361009c576040516231010160e51b815260040160405180910390fd5b60008160e001518060200190518101906100b691906107dc565b60c08301519091506001600160a01b0316156000816101425760c08401516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610119573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061013d9190610887565b610144565b475b905060008085602001516001600160a01b0316856000015160405161016991906108a0565b6000604051808303816000865af19150503d80600081146101a6576040519150601f19603f3d011682016040523d82523d6000602084013e6101ab565b606091505b5091509150816101d9578060405163bf91046160e01b81526004016101d091906108bc565b60405180910390fd5b6000846102535760c08701516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa15801561022a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061024e9190610887565b610255565b475b9050600061026385836108ef565b9050876080015181101561029a57608088015160405163d28d3eb560e01b81526101d0918391600401918252602082015260400190565b8760c001516001600160a01b03168860a001516001600160a01b031689602001516001600160a01b03167f43415e25edb52db0638ec44209302ce9df6ab6fa46a2233aee34f9c75471ea268b604001518c606001518d608001518760405161031b949392919093845260208401929092526040830152606082015260800190565b60405180910390a45050505050505050565b60008160e0015180602001905181019061034791906107dc565b60c08301519091506001600160a01b0316610374576040516231010160e51b815260040160405180910390fd5b60c08201516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156103bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103e39190610887565b905060008084602001516001600160a01b03168560400151856000015160405161040d91906108a0565b60006040518083038185875af1925050503d806000811461044a576040519150601f19603f3d011682016040523d82523d6000602084013e61044f565b606091505b509150915081610474578060405163bf91046160e01b81526004016101d091906108bc565b60c08501516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156104bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104e39190610887565b905060006104f185836108ef565b9050866080015181101561052857608087015160405163d28d3eb560e01b81526101d0918391600401918252602082015260400190565b8660c001516001600160a01b03168760a001516001600160a01b031688602001516001600160a01b03167f43415e25edb52db0638ec44209302ce9df6ab6fa46a2233aee34f9c75471ea268a604001518b606001518c60800151876040516105a9949392919093845260208401929092526040830152606082015260800190565b60405180910390a450505050505050565b634e487b7160e01b600052604160045260246000fd5b604051610100810167ffffffffffffffff811182821017156105f4576105f46105ba565b60405290565b6040516020810167ffffffffffffffff811182821017156105f4576105f46105ba565b604051601f8201601f1916810167ffffffffffffffff81118282101715610646576106466105ba565b604052919050565b80356001600160a01b038116811461066557600080fd5b919050565b600067ffffffffffffffff821115610684576106846105ba565b50601f01601f191660200190565b600082601f8301126106a357600080fd5b81356106b66106b18261066a565b61061d565b8181528460208386010111156106cb57600080fd5b816020850160208301376000918101602001919091529392505050565b6000602082840312156106fa57600080fd5b813567ffffffffffffffff8082111561071257600080fd5b90830190610100828603121561072757600080fd5b61072f6105d0565b6107388361064e565b81526107466020840161064e565b602082015260408301356040820152606083013560608201526080830135608082015261077560a0840161064e565b60a082015261078660c0840161064e565b60c082015260e08301358281111561079d57600080fd5b6107a987828601610692565b60e08301525095945050505050565b60005b838110156107d35781810151838201526020016107bb565b50506000910152565b6000602082840312156107ee57600080fd5b815167ffffffffffffffff8082111561080657600080fd5b908301906020828603121561081a57600080fd5b6108226105fa565b82518281111561083157600080fd5b80840193505085601f84011261084657600080fd5b825191506108566106b18361066a565b82815286602084860101111561086b57600080fd5b61087c8360208301602087016107b8565b815295945050505050565b60006020828403121561089957600080fd5b5051919050565b600082516108b28184602087016107b8565b9190910192915050565b60208152600082518060208401526108db8160408501602087016107b8565b601f01601f19169190910160400192915050565b8181038181111561091057634e487b7160e01b600052601160045260246000fd5b9291505056fea2646970667358221220ca745e2c2437eadcf6d8953eab10d4a15e9fcd78e4a35780f4b5189cccca7a7e64736f6c63430008130033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.