Skip to content

Latest commit

History

247 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

[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 StatusCoverage StatusBuilt-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

ParamsTypeDescription
fromTokenIERC20Address of trading off token
destTokenIERC20Address of desired token
amountuint256Amount for fromToken
partsuint256Number 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)
flagsuint256Flags for enabling and disabling some features (default: 0), see flags description

Return values:

ParamsTypeDescription
returnAmountuint256Expected returning amount of desired token
distributionuint256[]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

ParamsTypeDescription
fromTokenIERC20Address of trading off token
destTokenIERC20Address of desired token
amountuint256Amount for fromToken
partsuint256Number 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)
flagsuint256Flags for enabling and disabling some features (default: 0), see flags description
destTokenEthPriceTimesGasPriceuint256returnAmount * gas_price, where returnAmount is result of getExpectedReturn(fromToken, destToken, amount, parts, flags)

Return values:

ParamsTypeDescription
returnAmountuint256Expected returning amount of desired token
estimateGasAmountuint256Expected gas amount of exchange
distributionuint256[]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.

ParamsTypeDescription
tokensIERC20[]The sequence of tokens swaps (tokens[0] -> tokens[1] -> ...)
amountuint256Amount for tokens[0]
partsuint256[]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)
flagsuint256[]The sequence of flags for enabling and disabling some features (default: 0), see flags description
destTokenEthPriceTimesGasPriceuint256[]The sequence of numbers returnAmount * gas_price, where returnAmount is result of getExpectedReturn(fromToken, destToken, amount, parts, flags)

Return values:

ParamsTypeDescription
returnAmountuint256[]Expected returning amounts of desired tokens in tokens array
estimateGasAmountuint256Expected gas amount of exchange
distributionuint256[]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

ParamsTypeDescription
fromTokenIERC20Address of trading off token
destTokenIERC20Address of desired token
amountuint256Amount for fromToken
minReturnuint256Minimum expected return, else revert transaction
distributionuint256[]Array of weights for volume distribution (returned by getExpectedReturn)
flagsuint256Flags 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:

ParamsTypeDescription
returnAmountuint256Recieved 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.

ParamsTypeDescription
tokensIERC20[]Addresses of tokens or address(0) for Ether
amountuint256Amount for tokens[0]
minReturnuint256Minimum expected return, else revert transaction
distributionuint256[]Array of weights for volume distribution (returned by getExpectedReturn)
flagsuint256[]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:

ParamsTypeDescription
returnAmountuint256Recieved 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

ParamsTypeDescription
fromTokenIERC20Address of trading off token
destTokenIERC20Address of desired token
amountuint256Amount for fromToken
minReturnuint256Minimum expected return, else revert transaction
distributionuint256[]Array of weights for volume distribution (returned by getExpectedReturn)
flagsuint256Flags for enabling and disabling some features (default: 0), see flags description
referraladdressReferrer's address (exception with flag FLAG_ENABLE_REFERRAL_GAS_SPONSORSHIP)
feePercentuint256Fees 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:

ParamsTypeDescription
returnAmountuint256Recieved 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.

ParamsTypeDescription
tokensIERC20[]Addresses of tokens or address(0) for Ether
amountuint256Amount for tokens[0]
minReturnuint256Minimum expected return, else revert transaction
distributionuint256[]Array of weights for volume distribution (returned by getExpectedReturn)
flagsuint256[]The sequence of flags for enabling and disabling some features (default: 0), see flags description
referraladdressReferrer's address (exception with flag FLAG_ENABLE_REFERRAL_GAS_SPONSORSHIP)
feePercentuint256Fees 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:

ParamsTypeDescription
returnAmountuint256Recieved 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.

ParamsTypeDescription
gasSpentuint256How many gas was spent
returnAmountuint256Recieved amount of desired token
msgSenderCalldatabytesArguments 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)

    FlagValueDescription
    FLAG_DISABLE_UNISWAP0x01Exclude Uniswap exchange from swap
    FLAG_ENABLE_KYBER_UNISWAP_RESERVE0x100000000Permit Kyber use Uniswap, by default it is forbidden
    FLAG_ENABLE_KYBER_OASIS_RESERVE0x200000000Permit Kyber use Oasis, by default it is forbidden
    FLAG_ENABLE_KYBER_BANCOR_RESERVE0x400000000Permit Kyber use Bancor, by default it is forbidden
    FLAG_DISABLE_BANCOR0x04Exclude Bancor exchange from swap
    FLAG_DISABLE_OASIS0x08Exclude Oasis exchange from swap
    FLAG_DISABLE_CURVE_COMPOUND0x1000Exclude CurveCompound exchange from swap
    FLAG_DISABLE_CURVE_USDT0x2000Exclude CurveUsdt exchange from swap
    FLAG_DISABLE_CURVE_Y0x4000Exclude CurveY exchange from swap
    FLAG_DISABLE_CURVE_BINANCE0x8000Exclude CurveBinance exchange from swap
    FLAG_DISABLE_CURVE_SYNTHETIX0x40000Exclude CurveSynthetix exchange from swap
    FLAG_DISABLE_UNISWAP_COMPOUND0x100000Forbid Uniswap use Compound, by default it is permitted. Works only when one of assets is ETH
    FLAG_DISABLE_UNISWAP_CHAI0x200000Forbid Uniswap use Chai, by default it is permitted. Works only when ETH<>DAI
    FLAG_DISABLE_UNISWAP_AAVE0x400000Forbid Uniswap use Aave, by default it is permitted. Works only when one of assets is ETH
    FLAG_DISABLE_MOONISWAP0x1000000Exclude Mooniswap exchange from swap
    FLAG_DISABLE_UNISWAP_V2_ALL0x1E000000Exclude all exchanges with UniswapV2 prefix from swap
    FLAG_DISABLE_UNISWAP_V20x2000000Exclude UniswapV2 exchange from swap
    FLAG_DISABLE_UNISWAP_V2_ETH0x4000000Exclude UniswapV2ETH exchange from swap
    FLAG_DISABLE_UNISWAP_V2_DAI0x8000000Exclude UniswapV2DAI exchange from swap
    FLAG_DISABLE_UNISWAP_V2_USDC0x10000000Exclude UniswapV2USDC exchange from swap
    FLAG_DISABLE_ALL_SPLIT_SOURCES0x20000000Exclude all split exchages from swap. Inverts split tokens flag values
    FLAG_DISABLE_CURVE_PAX0x80000000Exclude CurvePax exchange from swap
    FLAG_DISABLE_CURVE_RENBTC0x100000000Exclude CurveRenBtc exchange from swap
    FLAG_DISABLE_CURVE_TBTC0x200000000Exclude CurveTBtc exchange from swap
    FLAG_DISABLE_DFORCE_SWAP0x4000000000Exclude DforceSwap exchange from swap
    FLAG_DISABLE_SHELL0x8000000000Exclude Shellexchangers exchange from swap
    FLAG_DISABLE_MSTABLE_MUSD0x20000000000Exclude pool MUSD in mStable exchange from swap
    FLAG_DISABLE_CURVE_SBTC0x40000000000Exclude pool SBTC in Curve exchange from swap
    FLAG_DISABLE_DMM0x80000000000Exclude DMM exchange from swap
    FLAG_DISABLE_UNISWAP_ALL0x100000000000Exclude all pools in Uniswap exchange from swap
    FLAG_DISABLE_CURVE_ALL0x200000000000Exclude all pools in Curve exchange from swap
    FLAG_DISABLE_BALANCER_ALL0x1000000000000Exclude all pools in Balancer exchange from swap
    FLAG_DISABLE_BALANCER_10x2000000000000Exclude the first best pool in Balancer exchange from swap
    FLAG_DISABLE_BALANCER_20x4000000000000Exclude the second best pool in Balancer exchange from swap
    FLAG_DISABLE_BALANCER_30x8000000000000Exclude the third best pool in Balancer exchange from swap
    FLAG_DISABLE_KYBER_ALL0x200000000000000Exclude all pools in Kyber exchange from swap
    FLAG_DISABLE_KYBER_10x400000000000000Exclude the first multi-token Kyber reserve (exchange of any token to any is possible) from swap (see KyberReserves)
    FLAG_DISABLE_KYBER_20x800000000000000Exclude the second multi-token Kyber reserve (exchange of any token to any is possible) from swap (see KyberReserves)
    FLAG_DISABLE_KYBER_30x1000000000000000Exclude the third multi-token Kyber reserve (exchange of any token to any is possible) from swap (see KyberReserves)
    FLAG_DISABLE_KYBER_40x2000000000000000Exclude 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)

    FlagValueDescription
    FLAG_DISABLE_COMPOUND0x10Exclude Compound exchange from swap
    FLAG_DISABLE_FULCRUM0x20Exclude Fulcrum exchange from swap
    FLAG_DISABLE_CHAI0x40Exclude Chai exchange from swap
    FLAG_DISABLE_AAVE0x80Exclude Aave exchange from swap
    FLAG_DISABLE_SMART_TOKEN0x100Exclude SmartToken exchange from swap
    FLAG_DISABLE_BDAI0x400Exclude Bdai exchange from swap
    FLAG_DISABLE_IEARN0x800Exclude Iearn exchange from swap
    FLAG_DISABLE_WETH0x80000Exclude Weth exchange from swap
    FLAG_DISABLE_IDLE0x800000Exclude Idle exchange from swap
    FLAG_DISABLE_ALL_WRAP_SOURCES0x40000000Exclude all wrap exchages from swap. Inverts wrap tokens flag values
  • Transitional token selector

    FlagValueDescription
    FLAG_DISABLE_UNISWAP_COMPOUND0x100000Exclude Uniswap pools with cTokens
    FLAG_DISABLE_UNISWAP_CHAI0x200000Exclude Uniswap pools with Chai
    FLAG_DISABLE_UNISWAP_AAVE0x400000Exclude Uniswap pools with aTokens
  • Functional flags

    FlagValueDescription
    FLAG_ENABLE_CHI_BURN0x10000000000Burns CHI token to save gas. Make sure to approve CHI token to 1split.eth smart contract
    FLAG_ENABLE_CHI_BURN_BY_ORIGIN0x4000000000000000This 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_SPONSORSHIP0x80000000000000Turning 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.

About

1inch Protocol – fully on-chain DeFi aggregation protocol

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages