• Stars
    star
    542
  • Rank 79,441 (Top 2 %)
  • Language
    Solidity
  • License
    MIT License
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

1inch Protocol – fully on-chain DeFi aggregation protocol

[DEPRECATED]

1inchProtocol was deprecated. We recommend to use API instead of 1inchProtocol.

1inch on-chain DeFi aggregation protocol

First ever fully on-chain DEX aggregator protocol by 1inch

Build Status Coverage Status Built-with openzeppelin

Integration

Latest version is always accessible at 1split.eth (beta on 1proto.eth)

Start with checking out solidity interface: IOneSplit.sol

How it works

This smart contract allows to get best price for tokens by aggregating prices from several DEXes.

So far the service works with 2 types of exchages: split and wrap.

List of split exchanges:

let splitExchanges = [
    "Uniswap",
    "Kyber",
    "Bancor",
    "Oasis",
    "Curve Compound",
    "Curve USDT",
    "Curve Y",
    "Curve Binance",
    "Curve Synthetix",
    "Uniswap Compound",
    "Uniswap CHAI",
    "Uniswap Aave",
    "Mooniswap",
    "Uniswap V2",
    "Uniswap V2 ETH",
    "Uniswap V2 DAI",
    "Uniswap V2 USDC",
    "Curve Pax",
    "Curve renBTC",
    "Curve tBTC",
    "Dforce XSwap",
    "Shell",
    "mStable mUSD",
    "Curve sBTC",
    "Balancer 1",
    "Balancer 2",
    "Balancer 3",
    "Kyber 1",
    "Kyber 2",
    "Kyber 3",
    "Kyber 4"
]

List of wrap exchanges:

let wrapExchanges = [
    "CHAI",
    "BDAI",
    "Aave",
    "Fulcrum",
    "Compound",
    "Iearn",
    "Idle",
    "WETH",
    "mUSD"
]

How it works

How to use it

To use this service you have to call methods at OneSplitAudit

How to use it

To swap tokens you have to figure out way from left to right points by one of paths on scheme above.

For example, first of all call method getExpectedReturn (see methods section), it returns distribution array. Each element of this array matches element of splitExchanges (see above) and represents fraction of trading volume.
Then call getExpectedReturnWithGas to take into account gas when splitting. This method returns more profitable distribution array for exchange.
Then call method swap or swapWithReferral (see methods section) with param distribution which was recieved earlier from method getExpectedReturn.

Swap may be customized by flags (see flags section). There are 2 types of swap: direct swap and swap over transitional token.

In case of direct swap each element of distribution array matches element of splitExchanges and represents fraction of trading off token as alerady described above.

In case of swap with transitional token each element of distribution (256 bits) matches 2 swaps: second bytes are equal to swap to transitional token, lowest bytes are equal to swap to the desired token.

Supported DEXes

Methods

If you need Ether instead of any token use address(0) or address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) as param fromToken/destToken

getExpectedReturn

function getExpectedReturn(
    IERC20 fromToken,
    IERC20 destToken,
    uint256 amount,
    uint256 parts,
    uint256 flags
)
    public
    view
    returns(
        uint256 returnAmount,
        uint256[] memory distribution
    )

Calculate expected returning amount of desired token

Params Type Description
fromToken IERC20 Address of trading off token
destToken IERC20 Address of desired token
amount uint256 Amount for fromToken
parts uint256 Number of pieces source volume could be splitted (Works like granularity, higly affects gas usage. Should be called offchain, but could be called onchain if user swaps not his own funds, but this is still considered as not safe)
flags uint256 Flags for enabling and disabling some features (default: 0), see flags description

Return values:

Params Type Description
returnAmount uint256 Expected returning amount of desired token
distribution uint256[] Array of weights for volume distribution

Notice: This method is equal to getExpectedReturnWithGas(fromToken, destToken, amount, parts, flags, 0)

Example:

let Web3 = require('web3')

let provider = new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/YOUR_TOKEN')
let web3 = new Web3(provider)

let ABI = [{"inputs":[{"internalType":"contract IOneSplitMulti","name":"impl","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newImpl","type":"address"}],"name":"ImplementationUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"fromToken","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"destToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"destTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minReturn","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"indexed":false,"internalType":"address","name":"referral","type":"address"},{"indexed":false,"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"Swapped","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":true,"inputs":[],"name":"chi","outputs":[{"internalType":"contract IFreeFromUpTo","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimAsset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"parts","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"}],"name":"getExpectedReturn","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"parts","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"},{"internalType":"uint256","name":"destTokenEthPriceTimesGasPrice","type":"uint256"}],"name":"getExpectedReturnWithGas","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256","name":"estimateGasAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256[]","name":"parts","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"internalType":"uint256[]","name":"destTokenEthPriceTimesGasPrices","type":"uint256[]"}],"name":"getExpectedReturnWithGasMulti","outputs":[{"internalType":"uint256[]","name":"returnAmounts","type":"uint256[]"},{"internalType":"uint256","name":"estimateGasAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"oneSplitImpl","outputs":[{"internalType":"contract IOneSplitMulti","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IOneSplitMulti","name":"impl","type":"address"}],"name":"setNewImpl","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256","name":"flags","type":"uint256"}],"name":"swap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"}],"name":"swapMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256","name":"flags","type":"uint256"},{"internalType":"address","name":"referral","type":"address"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"swapWithReferral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"internalType":"address","name":"referral","type":"address"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"swapWithReferralMulti","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
let CONTRACT_ADDRESS = "0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E"

let contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS)
contract.methods.getExpectedReturn(
    "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
    "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359",
    100,
    10, 
    0
).call().then(data => {
    console.log(`returnAmount: ${data.returnAmount.toString()}`)
    console.log(`distribution: ${JSON.stringify(data.distribution)}`)
}).catch(error => {
    // TO DO: ...
});

getExpectedReturnWithGas

function getExpectedReturnWithGas(
    IERC20 fromToken,
    IERC20 destToken,
    uint256 amount,
    uint256 parts,
    uint256 flags,
    uint256 destTokenEthPriceTimesGasPrice
)
    public
    view
    returns(
        uint256 returnAmount,
        uint256 estimateGasAmount,
        uint256[] memory distribution
    )

Calculate expected returning amount of desired token taking into account how gas protocols affect price

Params Type Description
fromToken IERC20 Address of trading off token
destToken IERC20 Address of desired token
amount uint256 Amount for fromToken
parts uint256 Number of pieces source volume could be splitted (Works like granularity, higly affects gas usage. Should be called offchain, but could be called onchain if user swaps not his own funds, but this is still considered as not safe)
flags uint256 Flags for enabling and disabling some features (default: 0), see flags description
destTokenEthPriceTimesGasPrice uint256 returnAmount * gas_price, where returnAmount is result of getExpectedReturn(fromToken, destToken, amount, parts, flags)

Return values:

Params Type Description
returnAmount uint256 Expected returning amount of desired token
estimateGasAmount uint256 Expected gas amount of exchange
distribution uint256[] Array of weights for volume distribution

Example:

 // TO DO: ...

getExpectedReturnWithGasMulti

function getExpectedReturnWithGasMulti(
    IERC20[] memory tokens,
    uint256 amount,
    uint256[] memory parts,
    uint256[] memory flags,
    uint256[] memory destTokenEthPriceTimesGasPrices
)
    public
    view
    returns(
        uint256[] memory returnAmounts,
        uint256 estimateGasAmount,
        uint256[] memory distribution
    )

Calculate expected returning amount of first tokens element to last tokens element through and the middle tokens with corresponding parts, flags and destTokenEthPriceTimesGasPrices array values of each step.
The length of each array (parts, flags and destTokenEthPriceTimesGasPrices) should be 1 element less than tokens array length. Each element from parts, flags and destTokenEthPriceTimesGasPrices corresponds to 2 neighboring elements from tokens array.

Params Type Description
tokens IERC20[] The sequence of tokens swaps (tokens[0] -> tokens[1] -> ...)
amount uint256 Amount for tokens[0]
parts uint256[] The sequence of number of pieces source volume could be splitted (Works like granularity, higly affects gas usage. Should be called offchain, but could be called onchain if user swaps not his own funds, but this is still considered as not safe)
flags uint256[] The sequence of flags for enabling and disabling some features (default: 0), see flags description
destTokenEthPriceTimesGasPrice uint256[] The sequence of numbers returnAmount * gas_price, where returnAmount is result of getExpectedReturn(fromToken, destToken, amount, parts, flags)

Return values:

Params Type Description
returnAmount uint256[] Expected returning amounts of desired tokens in tokens array
estimateGasAmount uint256 Expected gas amount of exchange
distribution uint256[] Array of weights for volume distribution

Example:

 // TO DO: ...

swap

function swap(
    IERC20 fromToken,
    IERC20 destToken,
    uint256 amount,
    uint256 minReturn,
    uint256[] memory distribution,
    uint256 flags
) public payable returns(uint256)

Swap amount of fromToken to destToken

Params Type Description
fromToken IERC20 Address of trading off token
destToken IERC20 Address of desired token
amount uint256 Amount for fromToken
minReturn uint256 Minimum expected return, else revert transaction
distribution uint256[] Array of weights for volume distribution (returned by getExpectedReturn)
flags uint256 Flags for enabling and disabling some features (default: 0), see flags description

Notice: Make sure the flags param coincides flags param in getExpectedReturn method if you want the same result

Notice: This method is equal to swapWithReferral(fromToken, destToken, amount, minReturn, distribution, flags, address(0), 0)

Return values:

Params Type Description
returnAmount uint256 Recieved amount of desired token

Example:

 // TO DO: ...

swapMulti

function swapMulti(
    IERC20[] memory tokens,
    uint256 amount,
    uint256 minReturn,
    uint256[] memory distribution,
    uint256[] memory flags
) public payable returns(uint256)

Swap amount of first element of tokens to the latest element.
The length of flags array should be 1 element less than tokens array length. Each element from flags array corresponds to 2 neighboring elements from tokens array.

Params Type Description
tokens IERC20[] Addresses of tokens or address(0) for Ether
amount uint256 Amount for tokens[0]
minReturn uint256 Minimum expected return, else revert transaction
distribution uint256[] Array of weights for volume distribution (returned by getExpectedReturn)
flags uint256[] The sequence of flags for enabling and disabling some features (default: 0), see flags description

Notice: Make sure the flags param coincides flags param in getExpectedReturnWithGasMulti method if you want the same result

Notice: This method is equal to swapWithReferralMulti(fromToken, destToken, amount, minReturn, distribution, flags, address(0), 0)

Return values:

Params Type Description
returnAmount uint256 Recieved amount of desired token

Example:

 // TO DO: ...

swapWithReferral

function swapWithReferral(
    IERC20 fromToken,
    IERC20 destToken,
    uint256 amount,
    uint256 minReturn,
    uint256[] memory distribution,
    uint256 flags,
    address referral,
    uint256 feePercent
) public payable returns(uint256)

Swap amount of fromToken to destToken

Params Type Description
fromToken IERC20 Address of trading off token
destToken IERC20 Address of desired token
amount uint256 Amount for fromToken
minReturn uint256 Minimum expected return, else revert transaction
distribution uint256[] Array of weights for volume distribution (returned by getExpectedReturn)
flags uint256 Flags for enabling and disabling some features (default: 0), see flags description
referral address Referrer's address (exception with flag FLAG_ENABLE_REFERRAL_GAS_SPONSORSHIP)
feePercent uint256 Fees percents normalized to 1e18, limited to 0.03e18 (3%)

Notice: Make sure the flags param coincides flags param in getExpectedReturn method if you want the same result

Return values:

Params Type Description
returnAmount uint256 Recieved amount of desired token

Example:

 // TO DO: ...

swapWithReferralMulti

function swapWithReferralMulti(
    IERC20[] memory tokens,
    uint256 amount,
    uint256 minReturn,
    uint256[] memory distribution,
    uint256[] memory flags,
    address referral,
    uint256 feePercent
) public payable returns(uint256 returnAmount)

Swap amount of first element of tokens to the latest element.
The length of flags array should be 1 element less than tokens array length. Each element from flags array corresponds to 2 neighboring elements from tokens array.

Params Type Description
tokens IERC20[] Addresses of tokens or address(0) for Ether
amount uint256 Amount for tokens[0]
minReturn uint256 Minimum expected return, else revert transaction
distribution uint256[] Array of weights for volume distribution (returned by getExpectedReturn)
flags uint256[] The sequence of flags for enabling and disabling some features (default: 0), see flags description
referral address Referrer's address (exception with flag FLAG_ENABLE_REFERRAL_GAS_SPONSORSHIP)
feePercent uint256 Fees percents normalized to 1e18, limited to 0.03e18 (3%)

Notice: Make sure the flags param coincides flags param in getExpectedReturnWithGasMulti method if you want the same result

Return values:

Params Type Description
returnAmount uint256 Recieved amount of desired token

Example:

 // TO DO: ...

makeGasDiscount

function makeGasDiscount(
    uint256 gasSpent,
    uint256 returnAmount,
    bytes calldata msgSenderCalldata
)

In case developer wants to manage burning GAS or CHI tokens with developer's own smartcontract one should implement this method and use FLAG_ENABLE_REFERRAL_GAS_SPONSORSHIP flag. 1proto.eth will call makeGasDiscount in developer's smartcontract.

Params Type Description
gasSpent uint256 How many gas was spent
returnAmount uint256 Recieved amount of desired token
msgSenderCalldata bytes Arguments from swap, swapWithReferral or swapWithReferralMulti method

Notice: There is no such method in 1proto.eth.

Flags

Flag types

There are basically 3 types of flags:

  1. Exchange switch
    This flags allow 1split.eth to enable or disable using exchange pools for swap. This can be applied for exchanges in genereral, for example: split, wrap, or this can be applied for a specific exchange type, for example: bancor, oasis.
    This flags may be used in any combination.

  2. Transitional token selector
    This flags provide to swap from fromToken to destToken using transitional token.
    This flags cann't be used in combination with the same type.

  3. Functional flags
    This flags provide some additional features.
    This flags may be used in any combination.

Flags description

flags param in 1split.eth methods is sum of flags values, for example:

flags = FLAG_DISABLE_UNISWAP + FLAG_DISABLE_KYBER + ...
  • Exchange switch (Split exchanges)

    Flag Value Description
    FLAG_DISABLE_UNISWAP 0x01 Exclude Uniswap exchange from swap
    FLAG_ENABLE_KYBER_UNISWAP_RESERVE 0x100000000 Permit Kyber use Uniswap, by default it is forbidden
    FLAG_ENABLE_KYBER_OASIS_RESERVE 0x200000000 Permit Kyber use Oasis, by default it is forbidden
    FLAG_ENABLE_KYBER_BANCOR_RESERVE 0x400000000 Permit Kyber use Bancor, by default it is forbidden
    FLAG_DISABLE_BANCOR 0x04 Exclude Bancor exchange from swap
    FLAG_DISABLE_OASIS 0x08 Exclude Oasis exchange from swap
    FLAG_DISABLE_CURVE_COMPOUND 0x1000 Exclude CurveCompound exchange from swap
    FLAG_DISABLE_CURVE_USDT 0x2000 Exclude CurveUsdt exchange from swap
    FLAG_DISABLE_CURVE_Y 0x4000 Exclude CurveY exchange from swap
    FLAG_DISABLE_CURVE_BINANCE 0x8000 Exclude CurveBinance exchange from swap
    FLAG_DISABLE_CURVE_SYNTHETIX 0x40000 Exclude CurveSynthetix exchange from swap
    FLAG_DISABLE_UNISWAP_COMPOUND 0x100000 Forbid Uniswap use Compound, by default it is permitted. Works only when one of assets is ETH
    FLAG_DISABLE_UNISWAP_CHAI 0x200000 Forbid Uniswap use Chai, by default it is permitted. Works only when ETH<>DAI
    FLAG_DISABLE_UNISWAP_AAVE 0x400000 Forbid Uniswap use Aave, by default it is permitted. Works only when one of assets is ETH
    FLAG_DISABLE_MOONISWAP 0x1000000 Exclude Mooniswap exchange from swap
    FLAG_DISABLE_UNISWAP_V2_ALL 0x1E000000 Exclude all exchanges with UniswapV2 prefix from swap
    FLAG_DISABLE_UNISWAP_V2 0x2000000 Exclude UniswapV2 exchange from swap
    FLAG_DISABLE_UNISWAP_V2_ETH 0x4000000 Exclude UniswapV2ETH exchange from swap
    FLAG_DISABLE_UNISWAP_V2_DAI 0x8000000 Exclude UniswapV2DAI exchange from swap
    FLAG_DISABLE_UNISWAP_V2_USDC 0x10000000 Exclude UniswapV2USDC exchange from swap
    FLAG_DISABLE_ALL_SPLIT_SOURCES 0x20000000 Exclude all split exchages from swap. Inverts split tokens flag values
    FLAG_DISABLE_CURVE_PAX 0x80000000 Exclude CurvePax exchange from swap
    FLAG_DISABLE_CURVE_RENBTC 0x100000000 Exclude CurveRenBtc exchange from swap
    FLAG_DISABLE_CURVE_TBTC 0x200000000 Exclude CurveTBtc exchange from swap
    FLAG_DISABLE_DFORCE_SWAP 0x4000000000 Exclude DforceSwap exchange from swap
    FLAG_DISABLE_SHELL 0x8000000000 Exclude Shellexchangers exchange from swap
    FLAG_DISABLE_MSTABLE_MUSD 0x20000000000 Exclude pool MUSD in mStable exchange from swap
    FLAG_DISABLE_CURVE_SBTC 0x40000000000 Exclude pool SBTC in Curve exchange from swap
    FLAG_DISABLE_DMM 0x80000000000 Exclude DMM exchange from swap
    FLAG_DISABLE_UNISWAP_ALL 0x100000000000 Exclude all pools in Uniswap exchange from swap
    FLAG_DISABLE_CURVE_ALL 0x200000000000 Exclude all pools in Curve exchange from swap
    FLAG_DISABLE_BALANCER_ALL 0x1000000000000 Exclude all pools in Balancer exchange from swap
    FLAG_DISABLE_BALANCER_1 0x2000000000000 Exclude the first best pool in Balancer exchange from swap
    FLAG_DISABLE_BALANCER_2 0x4000000000000 Exclude the second best pool in Balancer exchange from swap
    FLAG_DISABLE_BALANCER_3 0x8000000000000 Exclude the third best pool in Balancer exchange from swap
    FLAG_DISABLE_KYBER_ALL 0x200000000000000 Exclude all pools in Kyber exchange from swap
    FLAG_DISABLE_KYBER_1 0x400000000000000 Exclude the first multi-token Kyber reserve (exchange of any token to any is possible) from swap (see KyberReserves)
    FLAG_DISABLE_KYBER_2 0x800000000000000 Exclude the second multi-token Kyber reserve (exchange of any token to any is possible) from swap (see KyberReserves)
    FLAG_DISABLE_KYBER_3 0x1000000000000000 Exclude the third multi-token Kyber reserve (exchange of any token to any is possible) from swap (see KyberReserves)
    FLAG_DISABLE_KYBER_4 0x2000000000000000 Exclude the single-token Kyber reserve (single-token reserves does not intersect and the one that fits is selected) from swap (see KyberReserves)

    Example:

    let Web3 = require('web3')
    
    let provider = new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/YOUR_TOKEN')
    let web3 = new Web3(provider)
    
    let ABI = [{"inputs":[{"internalType":"contract IOneSplitMulti","name":"impl","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newImpl","type":"address"}],"name":"ImplementationUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"fromToken","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"destToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"destTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minReturn","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"indexed":false,"internalType":"address","name":"referral","type":"address"},{"indexed":false,"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"Swapped","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":true,"inputs":[],"name":"chi","outputs":[{"internalType":"contract IFreeFromUpTo","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimAsset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"parts","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"}],"name":"getExpectedReturn","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"parts","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"},{"internalType":"uint256","name":"destTokenEthPriceTimesGasPrice","type":"uint256"}],"name":"getExpectedReturnWithGas","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256","name":"estimateGasAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256[]","name":"parts","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"internalType":"uint256[]","name":"destTokenEthPriceTimesGasPrices","type":"uint256[]"}],"name":"getExpectedReturnWithGasMulti","outputs":[{"internalType":"uint256[]","name":"returnAmounts","type":"uint256[]"},{"internalType":"uint256","name":"estimateGasAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"oneSplitImpl","outputs":[{"internalType":"contract IOneSplitMulti","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IOneSplitMulti","name":"impl","type":"address"}],"name":"setNewImpl","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256","name":"flags","type":"uint256"}],"name":"swap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"}],"name":"swapMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256","name":"flags","type":"uint256"},{"internalType":"address","name":"referral","type":"address"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"swapWithReferral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"internalType":"address","name":"referral","type":"address"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"swapWithReferralMulti","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
    let CONTRACT_ADDRESS = "0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E"
    
    let splitExchanges = [
        "Uniswap", "Kyber", "Bancor", "Oasis", "CurveCompound", "CurveUsdt", "CurveY", "CurveBinance", "CurveSynthetix", "UniswapCompound", "UniswapChai", "UniswapAave", "Mooniswap", "UniswapV2", "UniswapV2ETH", "UniswapV2DAI", "UniswapV2USDC", "CurvePax", "CurveRenBtc", "CurveTBtc", "DforceSwap", "Shellexchangers"
    ]
    
    let parts = 10
    
    let contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS)
    contract.methods.getExpectedReturn(
        "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
        "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359",
        100,
        parts, 
        0x04
    ).call().then(data => {
    
        data.distribution.forEach(function(value, index) {
            console.log(`${splitExchanges[index]}: ${value*100/parts}%`)
        })
    }).catch(error => {
        // TO DO: ...
    });
    
  • Exchange switch (Wrap exchanges)

    Flag Value Description
    FLAG_DISABLE_COMPOUND 0x10 Exclude Compound exchange from swap
    FLAG_DISABLE_FULCRUM 0x20 Exclude Fulcrum exchange from swap
    FLAG_DISABLE_CHAI 0x40 Exclude Chai exchange from swap
    FLAG_DISABLE_AAVE 0x80 Exclude Aave exchange from swap
    FLAG_DISABLE_SMART_TOKEN 0x100 Exclude SmartToken exchange from swap
    FLAG_DISABLE_BDAI 0x400 Exclude Bdai exchange from swap
    FLAG_DISABLE_IEARN 0x800 Exclude Iearn exchange from swap
    FLAG_DISABLE_WETH 0x80000 Exclude Weth exchange from swap
    FLAG_DISABLE_IDLE 0x800000 Exclude Idle exchange from swap
    FLAG_DISABLE_ALL_WRAP_SOURCES 0x40000000 Exclude all wrap exchages from swap. Inverts wrap tokens flag values
  • Transitional token selector

    Flag Value Description
    FLAG_DISABLE_UNISWAP_COMPOUND 0x100000 Exclude Uniswap pools with cTokens
    FLAG_DISABLE_UNISWAP_CHAI 0x200000 Exclude Uniswap pools with Chai
    FLAG_DISABLE_UNISWAP_AAVE 0x400000 Exclude Uniswap pools with aTokens
  • Functional flags

    Flag Value Description
    FLAG_ENABLE_CHI_BURN 0x10000000000 Burns CHI token to save gas. Make sure to approve CHI token to 1split.eth smart contract
    FLAG_ENABLE_CHI_BURN_BY_ORIGIN 0x4000000000000000 This flag extends the functionality of FLAG_ENABLE_CHI_BURN flag. Burns CHI token from address which sign swap transaction instead of address which call swap method
    FLAG_ENABLE_REFERRAL_GAS_SPONSORSHIP 0x80000000000000 Turning on this flag means that parameter referral (methods swapWithReferral and swapWithReferralMulti) matches the address of the user smartcontract which has makeGasDiscount method. So this method can burn GAS token, CHI token by itself or it can add other functionality.

More Repositories

1

shieldy

@shieldy_bot Telegram bot repository
TypeScript
793
star
2

spot-price-aggregator

Liquidity-weighted dex price oracle for offchain price discovery
JavaScript
163
star
3

limit-order-protocol

JavaScript
152
star
4

solidity-utils

TypeScript
121
star
5

1inch-token

Solidity
114
star
6

mooniswap

Mooniswap
JavaScript
108
star
7

chi

Chi Gastoken by 1inch
Solidity
98
star
8

farming

JavaScript
97
star
9

multicall

TypeScript
82
star
10

liquidity-protocol

JavaScript
81
star
11

1inch-v2-contracts

Solidity
63
star
12

merkle-distribution

JavaScript
53
star
13

token-plugins

JavaScript
48
star
14

1IPs

48
star
15

limit-order-protocol-utils

TypeScript
43
star
16

1inch-docs

CSS
41
star
17

1inch-audits

38
star
18

limit-order-settlement

JavaScript
36
star
19

gDAI.io

gDAI - Gas less DAI transfers by using GSN, Fulcrum and KyberNetwork
TypeScript
32
star
20

gnosis.1inch.exchange

Gnosis 1inch dApp
TypeScript
31
star
21

fusion-sdk

TypeScript
25
star
22

permit-signed-approvals-utils

TypeScript
25
star
23

dexcandles

DEX trades candles (5m/15m/1h/4h/1d/1w)
TypeScript
21
star
24

evm-helpers

Solidity
16
star
25

solidity-dispatcher-miner

Rust
16
star
26

QRToken

Token Drop in Real World
TypeScript
10
star
27

1lend.io

Cryptocurrency lending aggregator
TypeScript
9
star
28

BEARROWING

Borrowing aggregator
Solidity
9
star
29

solidity-audit-checklist

9
star
30

approved.zone

Ethereum smart contracts approvals dashboard
TypeScript
9
star
31

1x.ag

Leverage aggregator
TypeScript
8
star
32

fixed-rate-swap

JavaScript
8
star
33

fusion-resolver-example

TypeScript
8
star
34

embedded-widget

TypeScript
7
star
35

ERC3652

Solidity
7
star
36

governance-contracts

JavaScript
7
star
37

st1inch

Solidity
7
star
38

MultiKyber

Kyber smart contract wrapper for cTokens, iTokens and sTokens native support
Solidity
6
star
39

fusion-101

1inch Fusion 101: Basic how-to examples for public workshops
TypeScript
6
star
40

delegating

JavaScript
6
star
41

evm-trace

JavaScript
6
star
42

1inch-uni-addresses

5
star
43

calldata-compressor

JavaScript
5
star
44

address-token-miner

Rust
5
star
45

penetration-tools

Tools repository for penetration tools
5
star
46

1hop

CDP migration aggregator
TypeScript
5
star
47

address-token

JavaScript
4
star
48

nuTube.network

Incentivized, decentralized livestream p2p network
TypeScript
4
star
49

desktop-dapp

Desktop version of app.1inch.io
TypeScript
4
star
50

candles-subgraph

TypeScript
4
star
51

LimitSwapSubgraph

TypeScript
3
star
52

limit-order-sdk-py

1inch Limit Order Protocol v4 SDK Python
Python
3
star
53

limit-order-parser

TypeScript
3
star
54

jobocar

Self Sharing Car - Jobocar
TypeScript
2
star
55

solidity-selector-miner

Rust
2
star
56

1inch-airdrop

Python
2
star
57

fee-collector

JavaScript
2
star
58

VIC.cards

Β«Very Important Contact CardsΒ» to prioritise you communications
TypeScript
2
star
59

BalancerRegistry

0x65e67cbc342712df67494acefc06fe951ee93982
Solidity
2
star
60

Donatocracy

JavaScript
1
star
61

dev-portal-101

101 for developer portal
TypeScript
1
star
62

paymaster-zksync

JavaScript
1
star
63

1inch-liquidity-protocol-audits

1
star
64

Arweavify

Chrome plugin for Arweave relayers verification
JavaScript
1
star
65

vested-token

Solidity
1
star
66

dev-portal-apis-examples

We are giving you a hands-on experience of how the Web3 APIs can be used to create engaging and dynamic decentralized applications.
1
star