文件 1 的 16:AccessControl.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../utils/Context.sol";
abstract contract AccessControl is Context {
using EnumerableSet for EnumerableSet.AddressSet;
using Address for address;
struct RoleData {
EnumerableSet.AddressSet members;
bytes32 adminRole;
}
mapping (bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) public view returns (bool) {
return _roles[role].members.contains(account);
}
function getRoleMemberCount(bytes32 role) public view returns (uint256) {
return _roles[role].members.length();
}
function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
return _roles[role].members.at(index);
}
function getRoleAdmin(bytes32 role) public view returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
_roles[role].adminRole = adminRole;
}
function _grantRole(bytes32 role, address account) private {
if (_roles[role].members.add(account)) {
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (_roles[role].members.remove(account)) {
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 16:Address.sol
pragma solidity >=0.6.2 <0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 3 的 16:AugustusStorage.sol
pragma solidity 0.7.5;
import "./ITokenTransferProxy.sol";
contract AugustusStorage {
struct FeeStructure {
uint256 partnerShare;
bool noPositiveSlippage;
bool positiveSlippageToUser;
uint16 feePercent;
string partnerId;
bytes data;
}
ITokenTransferProxy internal tokenTransferProxy;
address payable internal feeWallet;
mapping(address => FeeStructure) internal registeredPartners;
mapping(bytes4 => address) internal selectorVsRouter;
mapping(bytes32 => bool) internal adapterInitialized;
mapping(bytes32 => bytes) internal adapterVsData;
mapping(bytes32 => bytes) internal routerData;
mapping(bytes32 => bool) internal routerInitialized;
bytes32 public constant WHITELISTED_ROLE = keccak256("WHITELISTED_ROLE");
bytes32 public constant ROUTER_ROLE = keccak256("ROUTER_ROLE");
}
文件 4 的 16:AugustusSwapper.sol
pragma solidity 0.7.5;
pragma abicoder v2;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "./routers/IRouter.sol";
import "./adapters/IAdapter.sol";
import "./TokenTransferProxy.sol";
import "./ITokenTransferProxy.sol";
import "./AugustusStorage.sol";
contract AugustusSwapper is AugustusStorage, AccessControl {
using SafeMath for uint256;
using SafeERC20 for IERC20;
event AdapterInitialized(address indexed adapter);
event RouterInitialized(address indexed router);
modifier onlyAdmin() {
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "caller is not the admin");
_;
}
constructor(address payable _feeWallet) public {
TokenTransferProxy lTokenTransferProxy = new TokenTransferProxy();
tokenTransferProxy = ITokenTransferProxy(lTokenTransferProxy);
feeWallet = _feeWallet;
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
receive() external payable {}
fallback() external payable {
bytes4 selector = msg.sig;
address implementation = getImplementation(selector);
if (implementation == address(0)) {
_revertWithData(abi.encodeWithSelector(bytes4(keccak256("NotImplementedError(bytes4)")), selector));
}
(bool success, bytes memory resultData) = implementation.delegatecall(msg.data);
if (!success) {
_revertWithData(resultData);
}
_returnWithData(resultData);
}
function initializeAdapter(address adapter, bytes calldata data) external onlyAdmin {
require(hasRole(WHITELISTED_ROLE, adapter), "Exchange not whitelisted");
(bool success, ) = adapter.delegatecall(abi.encodeWithSelector(IAdapter.initialize.selector, data));
require(success, "Failed to initialize adapter");
emit AdapterInitialized(adapter);
}
function initializeRouter(address router, bytes calldata data) external onlyAdmin {
require(hasRole(ROUTER_ROLE, router), "Router not whitelisted");
(bool success, ) = router.delegatecall(abi.encodeWithSelector(IRouter.initialize.selector, data));
require(success, "Failed to initialize router");
emit RouterInitialized(router);
}
function getImplementation(bytes4 selector) public view returns (address) {
return selectorVsRouter[selector];
}
function getVersion() external pure returns (string memory) {
return "5.0.0";
}
function getPartnerFeeStructure(address partner) public view returns (FeeStructure memory) {
return registeredPartners[partner];
}
function getFeeWallet() external view returns (address) {
return feeWallet;
}
function setFeeWallet(address payable _feeWallet) external onlyAdmin {
require(_feeWallet != address(0), "Invalid address");
feeWallet = _feeWallet;
}
function registerPartner(
address partner,
uint256 _partnerShare,
bool _noPositiveSlippage,
bool _positiveSlippageToUser,
uint16 _feePercent,
string calldata partnerId,
bytes calldata _data
) external onlyAdmin {
require(partner != address(0), "Invalid partner");
FeeStructure storage feeStructure = registeredPartners[partner];
require(feeStructure.partnerShare == 0, "Already registered");
require(_partnerShare > 0 && _partnerShare < 10000, "Invalid values");
require(_feePercent <= 10000, "Invalid values");
feeStructure.partnerShare = _partnerShare;
feeStructure.noPositiveSlippage = _noPositiveSlippage;
feeStructure.positiveSlippageToUser = _positiveSlippageToUser;
feeStructure.partnerId = partnerId;
feeStructure.feePercent = _feePercent;
feeStructure.data = _data;
}
function setImplementation(bytes4 selector, address implementation) external onlyAdmin {
require(hasRole(ROUTER_ROLE, implementation), "Router is not whitelisted");
selectorVsRouter[selector] = implementation;
}
function transferTokens(
address token,
address payable destination,
uint256 amount
) external onlyAdmin {
if (amount > 0) {
if (token == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)) {
(bool result, ) = destination.call{ value: amount, gas: 10000 }("");
require(result, "Failed to transfer Ether");
} else {
IERC20(token).safeTransfer(destination, amount);
}
}
}
function isAdapterInitialized(bytes32 key) public view returns (bool) {
return adapterInitialized[key];
}
function getAdapterData(bytes32 key) public view returns (bytes memory) {
return adapterVsData[key];
}
function isRouterInitialized(bytes32 key) public view returns (bool) {
return routerInitialized[key];
}
function getRouterData(bytes32 key) public view returns (bytes memory) {
return routerData[key];
}
function getTokenTransferProxy() public view returns (address) {
return address(tokenTransferProxy);
}
function _revertWithData(bytes memory data) private pure {
assembly {
revert(add(data, 32), mload(data))
}
}
function _returnWithData(bytes memory data) private pure {
assembly {
return(add(data, 32), mload(data))
}
}
}
文件 5 的 16:Context.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 6 的 16:EnumerableSet.sol
pragma solidity >=0.6.0 <0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping (bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
bytes32 lastvalue = set._values[lastIndex];
set._values[toDeleteIndex] = lastvalue;
set._indexes[lastvalue] = toDeleteIndex + 1;
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
文件 7 的 16:IAdapter.sol
pragma solidity 0.7.5;
pragma abicoder v2;
import "../lib/Utils.sol";
interface IAdapter {
function initialize(bytes calldata data) external;
function swap(
IERC20 fromToken,
IERC20 toToken,
uint256 fromAmount,
uint256 networkFee,
Utils.Route[] calldata route
) external payable;
}
文件 8 的 16:IBalancerV2Vault.sol
pragma solidity 0.7.5;
pragma abicoder v2;
import "../Utils.sol";
interface IBalancerV2Vault {
enum SwapKind {
GIVEN_IN,
GIVEN_OUT
}
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
address assetIn;
address assetOut;
uint256 amount;
bytes userData;
}
struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
) external payable returns (uint256);
function batchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
address[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external payable returns (int256[] memory);
}
文件 9 的 16:IERC20.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 10 的 16:IRouter.sol
pragma solidity 0.7.5;
interface IRouter {
function initialize(bytes calldata data) external;
function getKey() external pure returns (bytes32);
event SwappedV3(
bytes16 uuid,
address partner,
uint256 feePercent,
address initiator,
address indexed beneficiary,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
uint256 expectedAmount
);
event BoughtV3(
bytes16 uuid,
address partner,
uint256 feePercent,
address initiator,
address indexed beneficiary,
address indexed srcToken,
address indexed destToken,
uint256 srcAmount,
uint256 receivedAmount,
uint256 expectedAmount
);
}
文件 11 的 16:ITokenTransferProxy.sol
pragma solidity 0.7.5;
interface ITokenTransferProxy {
function transferFrom(
address token,
address from,
address to,
uint256 amount
) external;
}
文件 12 的 16:Ownable.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 13 的 16:SafeERC20.sol
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 14 的 16:SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
文件 15 的 16:TokenTransferProxy.sol
pragma solidity 0.7.5;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "./ITokenTransferProxy.sol";
contract TokenTransferProxy is Ownable, ITokenTransferProxy {
using SafeERC20 for IERC20;
using Address for address;
function transferFrom(
address token,
address from,
address to,
uint256 amount
) external override onlyOwner {
require(from == tx.origin || from.isContract(), "Invalid from address");
IERC20(token).safeTransferFrom(from, to, amount);
}
}
文件 16 的 16:Utils.sol
pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "../ITokenTransferProxy.sol";
import { IBalancerV2Vault } from "./balancerv2/IBalancerV2Vault.sol";
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
interface IERC20PermitLegacy {
function permit(
address holder,
address spender,
uint256 nonce,
uint256 expiry,
bool allowed,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
library Utils {
using SafeMath for uint256;
using SafeERC20 for IERC20;
address private constant ETH_ADDRESS = address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
uint256 private constant MAX_UINT = type(uint256).max;
enum CurveSwapType {
EXCHANGE,
EXCHANGE_UNDERLYING,
EXCHANGE_GENERIC_FACTORY_ZAP
}
struct SellData {
address fromToken;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
address payable beneficiary;
Utils.Path[] path;
address payable partner;
uint256 feePercent;
bytes permit;
uint256 deadline;
bytes16 uuid;
}
struct BuyData {
address adapter;
address fromToken;
address toToken;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
address payable beneficiary;
Utils.Route[] route;
address payable partner;
uint256 feePercent;
bytes permit;
uint256 deadline;
bytes16 uuid;
}
struct MegaSwapSellData {
address fromToken;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
address payable beneficiary;
Utils.MegaSwapPath[] path;
address payable partner;
uint256 feePercent;
bytes permit;
uint256 deadline;
bytes16 uuid;
}
struct SimpleData {
address fromToken;
address toToken;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
address[] callees;
bytes exchangeData;
uint256[] startIndexes;
uint256[] values;
address payable beneficiary;
address payable partner;
uint256 feePercent;
bytes permit;
uint256 deadline;
bytes16 uuid;
}
struct DirectUniV3 {
address fromToken;
address toToken;
address exchange;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
uint256 feePercent;
uint256 deadline;
address payable partner;
bool isApproved;
address payable beneficiary;
bytes path;
bytes permit;
bytes16 uuid;
}
struct DirectCurveV1 {
address fromToken;
address toToken;
address exchange;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
uint256 feePercent;
int128 i;
int128 j;
address payable partner;
bool isApproved;
CurveSwapType swapType;
address payable beneficiary;
bool needWrapNative;
bytes permit;
bytes16 uuid;
}
struct DirectCurveV2 {
address fromToken;
address toToken;
address exchange;
address poolAddress;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
uint256 feePercent;
uint256 i;
uint256 j;
address payable partner;
bool isApproved;
CurveSwapType swapType;
address payable beneficiary;
bool needWrapNative;
bytes permit;
bytes16 uuid;
}
struct DirectBalancerV2 {
IBalancerV2Vault.BatchSwapStep[] swaps;
address[] assets;
IBalancerV2Vault.FundManagement funds;
int256[] limits;
uint256 fromAmount;
uint256 toAmount;
uint256 expectedAmount;
uint256 deadline;
uint256 feePercent;
address vault;
address payable partner;
bool isApproved;
address payable beneficiary;
bytes permit;
bytes16 uuid;
}
struct Adapter {
address payable adapter;
uint256 percent;
uint256 networkFee;
Route[] route;
}
struct Route {
uint256 index;
address targetExchange;
uint256 percent;
bytes payload;
uint256 networkFee;
}
struct MegaSwapPath {
uint256 fromAmountPercent;
Path[] path;
}
struct Path {
address to;
uint256 totalNetworkFee;
Adapter[] adapters;
}
function ethAddress() internal pure returns (address) {
return ETH_ADDRESS;
}
function maxUint() internal pure returns (uint256) {
return MAX_UINT;
}
function approve(
address addressToApprove,
address token,
uint256 amount
) internal {
if (token != ETH_ADDRESS) {
IERC20 _token = IERC20(token);
uint256 allowance = _token.allowance(address(this), addressToApprove);
if (allowance < amount) {
_token.safeApprove(addressToApprove, 0);
_token.safeIncreaseAllowance(addressToApprove, MAX_UINT);
}
}
}
function transferTokens(
address token,
address payable destination,
uint256 amount
) internal {
if (amount > 0) {
if (token == ETH_ADDRESS) {
(bool result, ) = destination.call{ value: amount, gas: 10000 }("");
require(result, "Failed to transfer Ether");
} else {
IERC20(token).safeTransfer(destination, amount);
}
}
}
function tokenBalance(address token, address account) internal view returns (uint256) {
if (token == ETH_ADDRESS) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
function permit(address token, bytes memory permit) internal {
if (permit.length == 32 * 7) {
(bool success, ) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
require(success, "Permit failed");
}
if (permit.length == 32 * 8) {
(bool success, ) = token.call(abi.encodePacked(IERC20PermitLegacy.permit.selector, permit));
require(success, "Permit failed");
}
}
function transferETH(address payable destination, uint256 amount) internal {
if (amount > 0) {
(bool result, ) = destination.call{ value: amount, gas: 10000 }("");
require(result, "Transfer ETH failed");
}
}
}
{
"compilationTarget": {
"contracts/AugustusSwapper.sol": "AugustusSwapper"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 1000000
},
"remappings": []
}
[{"inputs":[{"internalType":"address payable","name":"_feeWallet","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"}],"name":"AdapterInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"router","type":"address"}],"name":"RouterInitialized","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROUTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WHITELISTED_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getAdapterData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFeeWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"}],"name":"getImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"partner","type":"address"}],"name":"getPartnerFeeStructure","outputs":[{"components":[{"internalType":"uint256","name":"partnerShare","type":"uint256"},{"internalType":"bool","name":"noPositiveSlippage","type":"bool"},{"internalType":"bool","name":"positiveSlippageToUser","type":"bool"},{"internalType":"uint16","name":"feePercent","type":"uint16"},{"internalType":"string","name":"partnerId","type":"string"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct AugustusStorage.FeeStructure","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"getRouterData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTokenTransferProxy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVersion","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"initializeAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"initializeRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"isAdapterInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"isRouterInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"partner","type":"address"},{"internalType":"uint256","name":"_partnerShare","type":"uint256"},{"internalType":"bool","name":"_noPositiveSlippage","type":"bool"},{"internalType":"bool","name":"_positiveSlippageToUser","type":"bool"},{"internalType":"uint16","name":"_feePercent","type":"uint16"},{"internalType":"string","name":"partnerId","type":"string"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"registerPartner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_feeWallet","type":"address"}],"name":"setFeeWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"},{"internalType":"address","name":"implementation","type":"address"}],"name":"setImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address payable","name":"destination","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]