Proxy Contract Spec

V1 Contracts Spec

Contract Interfaces

DexTradingInterface.sol
DexTradingWithCollectionInterface.sol
ApprovalHandlerInterface.sol
contract DexTradingInterface {
function trade(
IERC20 from,
IERC20 to,
uint256 fromAmount,
address[] memory exchanges,
address[] memory approvals,
bytes memory data,
uint256[] memory offsets,
uint256[] memory etherValues,
uint256 limitAmount
) public payable;
function executeTrades(
IERC20 from,
address[] memory exchanges,
address[] memory approvals,
bytes memory data,
uint256[] memory offsets,
uint256[] memory etherValues) internal
function transferOwnership(address newOwner) public onlyOwner;
function approve(IERC20 erc, address approvee) internal;
function viewBalance(IERC20 erc, address owner) internal view returns(uint256);
function sendFunds(IERC20 erc, address payable receiver, uint256 funds) internal;
function external_call(address destination, uint value, uint dataOffset, uint dataLength, bytes memory data) internal returns (bool);
}
contract DexTradingWithCollectionInterface {
function trade(
IERC20 fromToken,
IERC20 toToken,
uint256 tokensAmount,
address[] memory callAddresses,
address[] memory approvals,
bytes memory callDataConcat,
uint256[] memory starts,
uint256[] memory values,
uint256 minTokensAmount
) public payable;
function transferOwnership(address newOwner) public onlyOwner;
function setBasisPoints(uint256 _basisPoints) external onlyOwner;
function setBeneficiary(address payable _beneficiary) external onlyOwner;
function setDexag(address payable _dexag) external;
function approve(IERC20 erc, address approvee) internal;
function viewBalance(IERC20 erc, address owner) internal view returns(uint256);
function sendFunds(IERC20 erc, address payable receiver, uint256 funds) internal;
function sendCollectionAmount(IERC20 erc, uint256 tradeReturn) internal;
function external_call(address destination, uint value, uint dataOffset, uint dataLength, bytes memory data) internal returns (bool);
}
contract ApprovalHandlerInterface {
function transferFrom(IERC20 erc, address sender, address receiver, uint256 numTokens) external onlyOwner;
}

Function Details

  • DexTradingWithCollection.sol/DexTrading.sol

    • Contract implements OpenZeppelin's Ownable.sol, which can be found here.

    • Functions

      • External

        • trade()

          • Main function that handles trade execution

          • Passes in solidity call data and values to be called on Exchange contract

          • Requires token approval on Handler contract for ERC20s

          • User calls trade() -> either send Ether in call or Handler claims tokens from User -> trade() forwards data and values to Exchange(s) -> trade executed, fees withdrawn and received tokens are sent to user

        • transferOwnership()

          • transfers Ownership of the contract to a specified address

        • setBasisPoints() - DexTradingWithCollection.sol only

          • Sets basisPoints variable, which calculates how much of the collection amount is taken from a trade.

          • if basisPoints is set to 10000, represents 100%, if basisPoints is set to 10, represents 0.1%

          • Collection Amounts are split 80/20 between platform and DEX.AG

          • only callable by Owner of the contract

        • setBeneficiary - DexTradingWithCollection.sol only

          • sets address where collection amounts are collected

        • setDexag() - DexTradingWithCollection.sol only

          • sets address where DEX.AG fees are collected

          • only callable by DEX.AG

        • approve()

          • sets approval for Exchanges to pull tokens from Trading contract

          • called in trade() to set approval automatically if needed for Exchange

      • Internal

        • viewBalance()

          • returns token or ETH balance at an address

        • executeTrade()

          • executes trade data on given exchanges

        • sendFunds()

          • transfers token or ETH to address

        • external_call()

          • calls function using tx.data on an external contract

        • sendCollectionAmounts()

          • splits collection amounts and sends them to the designated addresses, collection amounts are taken out of the trade result

      • Getters

        • approvalHandler()

          • returns ApprovalHandler for this contract

        • basisPoints() - only on DexTradingWithCollection.sol

          • return fee for this contract

        • beneficiary() - only on DexTradingWithCollection.sol

          • return beneficiary address where fees are sent

        • dexag() - only on DexTradingWithCollection.sol

          • return secondary fee address if applicable

  • ApprovalHandler.sol

    • Created when a contract is deployed, handles claiming ERC20s from user

    • A user must call approve() on this contract for tokens they wish to trade

    • You can find the ApprovalHandler address for a DexTradingWithCollection.sol/DexTrading.sol contract by calling approvalHandler() on the contract.

    • Functions

      • transferFrom()

        • only callable by the contract itself - pulls tokens from user and sends to the contract, called in trade() function