DEX.AG
Search…
Proxy Contract Spec
V1 Contracts Spec

Contract Interfaces

DexTradingInterface.sol
DexTradingWithCollectionInterface.sol
ApprovalHandlerInterface.sol
1
contract DexTradingInterface {
2
function trade(
3
IERC20 from,
4
IERC20 to,
5
uint256 fromAmount,
6
address[] memory exchanges,
7
address[] memory approvals,
8
bytes memory data,
9
uint256[] memory offsets,
10
uint256[] memory etherValues,
11
uint256 limitAmount
12
) public payable;
13
function tradeAndSend(
14
IERC20 from,
15
IERC20 to,
16
address payable recipient,
17
uint256 fromAmount,
18
address[] memory exchanges,
19
address[] memory approvals,
20
bytes memory data,
21
uint256[] memory offsets,
22
uint256[] memory etherValues,
23
uint256 limitAmount,
24
uint256 tradeType
25
) public payable;
26
function executeTrades(
27
IERC20 from,
28
address[] memory exchanges,
29
address[] memory approvals,
30
bytes memory data,
31
uint256[] memory offsets,
32
uint256[] memory etherValues) internal
33
function transferOwnership(address newOwner) public onlyOwner;
34
function approve(IERC20 erc, address approvee) internal;
35
function viewBalance(IERC20 erc, address owner) internal view returns(uint256);
36
function sendFunds(IERC20 erc, address payable receiver, uint256 funds) internal;
37
function external_call(address destination, uint value, uint dataOffset, uint dataLength, bytes memory data) internal returns (bool);
38
}
Copied!
1
contract DexTradingWithCollectionInterface {
2
function trade(
3
IERC20 fromToken,
4
IERC20 toToken,
5
uint256 tokensAmount,
6
address[] memory callAddresses,
7
address[] memory approvals,
8
bytes memory callDataConcat,
9
uint256[] memory starts,
10
uint256[] memory values,
11
uint256 minTokensAmount
12
) public payable;
13
function tradeAndSend(
14
IERC20 from,
15
IERC20 to,
16
address payable recipient,
17
uint256 fromAmount,
18
address[] memory exchanges,
19
address[] memory approvals,
20
bytes memory data,
21
uint256[] memory offsets,
22
uint256[] memory etherValues,
23
uint256 limitAmount,
24
uint256 tradeType
25
) public payable;
26
function transferOwnership(address newOwner) public onlyOwner;
27
function setBasisPoints(uint256 _basisPoints) external onlyOwner;
28
function setBeneficiary(address payable _beneficiary) external onlyOwner;
29
function setDexag(address payable _dexag) external;
30
function approve(IERC20 erc, address approvee) internal;
31
function viewBalance(IERC20 erc, address owner) internal view returns(uint256);
32
function sendFunds(IERC20 erc, address payable receiver, uint256 funds) internal;
33
function sendCollectionAmount(IERC20 erc, uint256 tradeReturn) internal;
34
function external_call(address destination, uint value, uint dataOffset, uint dataLength, bytes memory data) internal returns (bool);
35
}
Copied!
1
contract ApprovalHandlerInterface {
2
function transferFrom(IERC20 erc, address sender, address receiver, uint256 numTokens) external onlyOwner;
3
}
Copied!

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
        • tradeAndSend()
          • Same as trade(), but allows the the specification of an address to send the trade output to
        • 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
Last modified 1yr ago