ETH Price: $2,240.27 (-4.49%)
Gas: 39 Gwei

Contract

0x64177fd4dFad1a6CFf95E1ebba403bB73c6A8E41
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Sponsored

Transaction Hash
Method
Block
From
To
Value
0x60a06040161732702022-12-13 4:02:59363 days 9 hrs ago1670904179IN
 Create: SynthetixExchangeAdapter
0 ETH0.006185215

Advanced mode:
Parent Txn Hash Block From To Value
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SynthetixExchangeAdapter

Compiler Version
v0.6.10+commit.00c0fcaf

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Apache-2.0 license
File 3 of 3 : SynthetixExchangeAdapter.sol
/*
    Copyright 2021 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

import { ISynth } from "../../../interfaces/external/ISynth.sol";
import { ISynthetixExchanger } from "../../../interfaces/external/ISynthetixExchanger.sol";

/**
 * @title SynthetixTradeAdapter
 * @author Set Protocol
 *
 * Exchange adapter for Synthetix that returns data for trades
 */
contract SynthetixExchangeAdapter {

    /* ============ Structs ============ */

    /**
     * Struct containing information for trade function
     */
    struct SynthetixTradeInfo {
        bytes32 sourceCurrencyKey;        // Currency key of the token to send
        bytes32 destinationCurrencyKey;   // Currency key the token to receive
    }

    /* ============ State Variables ============ */

    // Address of Synthetix's Exchanger contract
    address public immutable synthetixExchangerAddress;

    /* ============ Constructor ============ */

    /**
     * Set state variables
     *
     * @param _synthetixExchangerAddress    Address of Synthetix's Exchanger contract
     */
    constructor(address _synthetixExchangerAddress) public {
        synthetixExchangerAddress = _synthetixExchangerAddress;
    }

    /* ============ External Getter Functions ============ */

    /**
     * Calculate Synthetix trade encoded calldata. To be invoked on the SetToken.
     *
     * @param  _sourceToken              Address of source token to be sold
     * @param  _destinationToken         Address of destination token to buy
     * @param  _destinationAddress       Address to receive traded tokens
     * @param  _sourceQuantity           Amount of source token to sell
     *
     * @return address                   Target address
     * @return uint256                   Call value
     * @return bytes                     Trade calldata
     */
    function getTradeCalldata(
        address _sourceToken,
        address _destinationToken,
        address _destinationAddress,
        uint256 _sourceQuantity,
        uint256 /* _minDestinationQuantity */,
        bytes calldata /* _data */
    )
        external
        view
        returns (address, uint256, bytes memory)
    {
        SynthetixTradeInfo memory synthetixTradeInfo;

        require(
            _sourceToken != _destinationToken,
            "Source token cannot be same as destination token"
        );

        synthetixTradeInfo.sourceCurrencyKey = _getCurrencyKey(_sourceToken);
        synthetixTradeInfo.destinationCurrencyKey = _getCurrencyKey(_destinationToken);

        // Encode method data for SetToken to invoke
        bytes memory methodData = abi.encodeWithSignature(
            "exchange(address,bytes32,uint256,bytes32,address)",
            _destinationAddress,
            synthetixTradeInfo.sourceCurrencyKey,
            _sourceQuantity,
            synthetixTradeInfo.destinationCurrencyKey,
            _destinationAddress
        );

        return (synthetixExchangerAddress, 0, methodData);
    }

    /**
     * Returns the Synthetix contract address.
     * There is no need to approve to SNX as its a proxy
     *
     * @return address
     */
    function getSpender()
        external
        view
        returns (address)
    {
        return synthetixExchangerAddress;
    }

    /**
     * Returns the amount of destination token received for exchanging a quantity of
     * source token, less fees.
     *
     * @param  _sourceToken        Address of source token to be sold
     * @param  _destinationToken   Address of destination token to buy
     * @param  _sourceQuantity     Amount of source token to sell
     *
     * @return amountReceived      Amount of source token received for exchange
     */
    function getAmountReceivedForExchange(
        address _sourceToken,
        address _destinationToken,
        uint256 _sourceQuantity
    )
        external
        view
        returns (uint256 amountReceived)
    {
        SynthetixTradeInfo memory synthetixTradeInfo;

        synthetixTradeInfo.sourceCurrencyKey = _getCurrencyKey(_sourceToken);
        synthetixTradeInfo.destinationCurrencyKey = _getCurrencyKey(_destinationToken);

        (amountReceived,,) = ISynthetixExchanger(synthetixExchangerAddress).getAmountsForExchange(
            _sourceQuantity,
            synthetixTradeInfo.sourceCurrencyKey,
            synthetixTradeInfo.destinationCurrencyKey
        );
    }

    /* ============ Internal Functions ============ */

    /**
     * Gets the Synthetix currency key for _token
     *
     * @param _token  Address of token to get currency key for
     */
    function _getCurrencyKey(address _token) internal view returns (bytes32) {

        try ISynth(_token).currencyKey() returns (bytes32 key){

            return key;

        } catch (bytes memory /* data */) {

            revert("Invalid Synth token address");
        }
    }
}

File 2 of 3 : ISynth.sol
/*
    Copyright 2021 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;

// https://docs.synthetix.io/contracts/source/interfaces/isynth
interface ISynth {
    function currencyKey() external view returns (bytes32);
}

File 3 of 3 : ISynthetixExchanger.sol
/*
    Copyright 2021 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;

// https://docs.synthetix.io/contracts/source/interfaces/iExchanger
interface ISynthetixExchanger {
    function getAmountsForExchange(
        uint sourceAmount,
        bytes32 sourceCurrencyKey,
        bytes32 destinationCurrencyKey
    )
        external
        view
        returns (
            uint amountReceived,
            uint fee,
            uint exchangeFeeRate
        );

    function exchange(
        address from,
        bytes32 sourceCurrencyKey,
        uint sourceAmount,
        bytes32 destinationCurrencyKey,
        address destinationAddress
    ) external returns (uint amountReceived);
}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_synthetixExchangerAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_sourceToken","type":"address"},{"internalType":"address","name":"_destinationToken","type":"address"},{"internalType":"uint256","name":"_sourceQuantity","type":"uint256"}],"name":"getAmountReceivedForExchange","outputs":[{"internalType":"uint256","name":"amountReceived","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSpender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_sourceToken","type":"address"},{"internalType":"address","name":"_destinationToken","type":"address"},{"internalType":"address","name":"_destinationAddress","type":"address"},{"internalType":"uint256","name":"_sourceQuantity","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"getTradeCalldata","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"synthetixExchangerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a060405234801561001057600080fd5b5060405161071738038061071783398101604081905261002f91610044565b60601b6001600160601b031916608052610072565b600060208284031215610055578081fd5b81516001600160a01b038116811461006b578182fd5b9392505050565b60805160601c61067a61009d6000398060f7528061018b52806102585280610290525061067a6000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c806325bcdf5914610051578063334fc2891461007a578063e171fcab1461008f578063ee405c65146100b1575b600080fd5b61006461005f366004610453565b6100b9565b604051610071919061060d565b60405180910390f35b610082610189565b60405161007191906104d8565b6100a261009d36600461039d565b6101ad565b6040516100719392919061051c565b61008261028e565b60006100c361036f565b6100cc856102b2565b81526100d7846102b2565b602082018190528151604051633d142a8d60e21b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169263f450aa349261012d92889290600401610616565b60606040518083038186803b15801561014557600080fd5b505afa158015610159573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017d91906104ab565b50909695505050505050565b7f000000000000000000000000000000000000000000000000000000000000000090565b60008060606101ba61036f565b896001600160a01b03168b6001600160a01b031614156101f55760405162461bcd60e51b81526004016101ec90610586565b60405180910390fd5b6101fe8b6102b2565b81526102098a6102b2565b60208201819052815160405160609261022c928d9290918d9184906024016104ec565b60408051601f198184030181529190526020810180516001600160e01b0316630a1e187d60e01b1790527f0000000000000000000000000000000000000000000000000000000000000000955060009450925050509750975097945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000816001600160a01b031663dbd06c856040518163ffffffff1660e01b815260040160206040518083038186803b1580156102ed57600080fd5b505afa92505050801561031d575060408051601f3d908101601f1916820190925261031a91810190610493565b60015b610369573d80801561034b576040519150601f19603f3d011682016040523d82523d6000602084013e610350565b606091505b5060405162461bcd60e51b81526004016101ec906105d6565b92915050565b604080518082019091526000808252602082015290565b80356001600160a01b038116811461036957600080fd5b600080600080600080600060c0888a0312156103b7578283fd5b6103c18989610386565b96506103d08960208a01610386565b95506103df8960408a01610386565b9450606088013593506080880135925060a088013567ffffffffffffffff80821115610409578384fd5b818a018b601f82011261041a578485fd5b803592508183111561042a578485fd5b8b602084830101111561043b578485fd5b60208101945050508091505092959891949750929550565b600080600060608486031215610467578283fd5b83356104728161062c565b925060208401356104828161062c565b929592945050506040919091013590565b6000602082840312156104a4578081fd5b5051919050565b6000806000606084860312156104bf578283fd5b8351925060208401519150604084015190509250925092565b6001600160a01b0391909116815260200190565b6001600160a01b039586168152602081019490945260408401929092526060830152909116608082015260a00190565b600060018060a01b038516825260208481840152606060408401528351806060850152825b8181101561055d57858101830151858201608001528201610541565b8181111561056e5783608083870101525b50601f01601f19169290920160800195945050505050565b60208082526030908201527f536f7572636520746f6b656e2063616e6e6f742062652073616d65206173206460408201526f32b9ba34b730ba34b7b7103a37b5b2b760811b606082015260800190565b6020808252601b908201527f496e76616c69642053796e746820746f6b656e20616464726573730000000000604082015260600190565b90815260200190565b9283526020830191909152604082015260600190565b6001600160a01b038116811461064157600080fd5b5056fea26469706673582212208aadfa70b5e4f50fdfe983a100de024bdd6a355f15e0a210b5acbb4a3d5707b264736f6c634300060a0033000000000000000000000000aea0065e146fd75dc24465961a583827284d405a

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061004c5760003560e01c806325bcdf5914610051578063334fc2891461007a578063e171fcab1461008f578063ee405c65146100b1575b600080fd5b61006461005f366004610453565b6100b9565b604051610071919061060d565b60405180910390f35b610082610189565b60405161007191906104d8565b6100a261009d36600461039d565b6101ad565b6040516100719392919061051c565b61008261028e565b60006100c361036f565b6100cc856102b2565b81526100d7846102b2565b602082018190528151604051633d142a8d60e21b81526001600160a01b037f000000000000000000000000aea0065e146fd75dc24465961a583827284d405a169263f450aa349261012d92889290600401610616565b60606040518083038186803b15801561014557600080fd5b505afa158015610159573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017d91906104ab565b50909695505050505050565b7f000000000000000000000000aea0065e146fd75dc24465961a583827284d405a90565b60008060606101ba61036f565b896001600160a01b03168b6001600160a01b031614156101f55760405162461bcd60e51b81526004016101ec90610586565b60405180910390fd5b6101fe8b6102b2565b81526102098a6102b2565b60208201819052815160405160609261022c928d9290918d9184906024016104ec565b60408051601f198184030181529190526020810180516001600160e01b0316630a1e187d60e01b1790527f000000000000000000000000aea0065e146fd75dc24465961a583827284d405a955060009450925050509750975097945050505050565b7f000000000000000000000000aea0065e146fd75dc24465961a583827284d405a81565b6000816001600160a01b031663dbd06c856040518163ffffffff1660e01b815260040160206040518083038186803b1580156102ed57600080fd5b505afa92505050801561031d575060408051601f3d908101601f1916820190925261031a91810190610493565b60015b610369573d80801561034b576040519150601f19603f3d011682016040523d82523d6000602084013e610350565b606091505b5060405162461bcd60e51b81526004016101ec906105d6565b92915050565b604080518082019091526000808252602082015290565b80356001600160a01b038116811461036957600080fd5b600080600080600080600060c0888a0312156103b7578283fd5b6103c18989610386565b96506103d08960208a01610386565b95506103df8960408a01610386565b9450606088013593506080880135925060a088013567ffffffffffffffff80821115610409578384fd5b818a018b601f82011261041a578485fd5b803592508183111561042a578485fd5b8b602084830101111561043b578485fd5b60208101945050508091505092959891949750929550565b600080600060608486031215610467578283fd5b83356104728161062c565b925060208401356104828161062c565b929592945050506040919091013590565b6000602082840312156104a4578081fd5b5051919050565b6000806000606084860312156104bf578283fd5b8351925060208401519150604084015190509250925092565b6001600160a01b0391909116815260200190565b6001600160a01b039586168152602081019490945260408401929092526060830152909116608082015260a00190565b600060018060a01b038516825260208481840152606060408401528351806060850152825b8181101561055d57858101830151858201608001528201610541565b8181111561056e5783608083870101525b50601f01601f19169290920160800195945050505050565b60208082526030908201527f536f7572636520746f6b656e2063616e6e6f742062652073616d65206173206460408201526f32b9ba34b730ba34b7b7103a37b5b2b760811b606082015260800190565b6020808252601b908201527f496e76616c69642053796e746820746f6b656e20616464726573730000000000604082015260600190565b90815260200190565b9283526020830191909152604082015260600190565b6001600160a01b038116811461064157600080fd5b5056fea26469706673582212208aadfa70b5e4f50fdfe983a100de024bdd6a355f15e0a210b5acbb4a3d5707b264736f6c634300060a0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000aea0065e146fd75dc24465961a583827284d405a

-----Decoded View---------------
Arg [0] : _synthetixExchangerAddress (address): 0xaeA0065E146FD75Dc24465961a583827284D405a

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000aea0065e146fd75dc24465961a583827284d405a


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
[ 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.