GithubHelp home page GithubHelp logo

1inch / 1inchprotocol Goto Github PK

View Code? Open in Web Editor NEW
559.0 39.0 309.0 1.66 MB

1inch Protocol – fully on-chain DeFi aggregation protocol

License: MIT License

JavaScript 2.24% Solidity 97.37% Shell 0.39%

1inchprotocol's Introduction

[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.

1inchprotocol's People

Contributors

ayrobi avatar bugduino avatar cryptodevtrader avatar deacix avatar dependabot[bot] avatar k06a avatar krboktv avatar mesozoic-technology avatar pengiundev avatar zzomrot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

1inchprotocol's Issues

Always getting “Gas Estimation failed” in Remix when testing 1inch swap function

I am trying to test 1inch swap function from the contract deployed via Remix on a Ganache fork of the Ethereum Mainnet. When calling this function I always get the "Gas estimation failed" error and "VM Exception while processing transaction: revert" error in Remix. My contract has enough sold off token (USDC) and Ether.

The contract:

contract TradeBot {
// OneSplit Config
    address ONE_SPLIT_ADDRESS = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E;
    uint256 PARTS = uint256(10);
    uint256 FLAGS = uint256(0);

   function oneSplitSwap(address _from, address _to, uint256 _amount, uint256 _minReturn, 
                        uint256[] memory _distribution) public payable {
        _oneSplitSwap(_from, _to, _amount, _minReturn, _distribution);
    }

   function _oneSplitSwap(address _from, address _to, uint256 _amount, uint256 _minReturn, 
                          uint256[] memory _distribution) internal {
        // Setup contracts
        IERC20 _fromIERC20 = IERC20(_from);
        IERC20 _toIERC20 = IERC20(_to);
        IOneSplit _oneSplitContract = IOneSplit(ONE_SPLIT_ADDRESS);
        // Approve tokens
        _fromIERC20.approve(ONE_SPLIT_ADDRESS, _amount);
        // Swap tokens: give _from, get _to
        _oneSplitContract.swap(_fromIERC20, _toIERC20, _amount, _minReturn, _distribution, 
                               FLAGS);
        // Reset approval
        _fromIERC20.approve(ONE_SPLIT_ADDRESS, 0);
}

I test the function with the following parameters:

fromToken: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 // USDC
toToken:   0x6B175474E89094C44Da98b954EedeAC495271d0F // DAI
amount:    100000000
minReturn: 10 
distribution: [0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0]

Can't figure out why this does not work. All parameters seem to be correct and the contract has enough USDC. Am I using the correct 1split contract address or you have a new implementation? Any ideas how to fix this?

getExpectedReturnWithGas and swapWithReferral is not available in contract address

Hi, I am trying to use getExpectedReturnWithGas and swapWithReferral methods from the contract address in the documentation which is 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E. And I get error calling these methods.

And when I checked the address's source code I couldn't see these methods. So what happened to these methods?

Thanks

Definition of transitional token

Hi,
I think the term 'transitional token' in the README.md could use a definition. At least it is not clear to me what it means from just reading the doc.

After reading in code I think it means:

After reading some code I think, it means instead of doing a direct swap:
WrappedTokenA --swap-> WrappedTokenB

It would do a wrap/unwrap first:
WrappedTokenA --unwrap-> TokenA --swap-> TokenB --wrap-> WrappedTokenB

Is that correct? It can be changed to use "direct swap" by setting FLAG_DISABLE_ALL_WRAP_SOURCES? The default behavior is the transition to underling token?

Thanks for the help.

Try Withdrawing from 1inch/Eth farming stake and it shows balance is Zero!!!!! Most troubling.

Try Withdrawing from 1inch/Eth stake (not claim, just withdraw the LP tokens from the farming stake) and it shows balance is Zero!!!!! so, therefore no can do. LOCKED! Most troubling! My money is now stuck inside the farming stake and it shows zero balance for withdrawing, Then, there is also Zero My Liquidity in the LP too (after I put it into farming.) Should not be the case. You should make LP fees plus the 1-inch stake rewards.. This is horrible. So Many errors. Cannot believe you launched like this.

Wrong value in getExpectedReturn call

I am getting returned amount different from what is displayed on the 1inchprotocol web site when converting from cryptos other than ether (I mean drastically different). I am using a code example from the readme doc. Should I process the return value somehow to get the correct result?

One Split Audit on Kovan?

I'm looking for the Kovan version of the OneSplitAudit contract. Does it exist? where can i find it?

1inch Challenge 3 - Liquidations Bot

1inch Challenge 3 - Liquidations Bot

Prize Bounty

Up to 1k$ worth in CHI Token

Challenge Description

Use 1inch API within a liqudiations Bot. 1inch API supports tokens swaps by liquidating positions on AAVE. You can use this feature to build your own liquidation bot.

Submission Requirements

We require a working demo and a solid MVP.
The best/most creative submission will declared the winner. If you are unsure about whether your hack project suits the bounty topic please present your idea to us via our discord channel.

Please make Open-Source your project at the end of the hackathon.

Judging Criteria

Creativity and Usefulness.
We will also do a code review to ensure code quality to make the final decision.

Winner Announcement Date

Dec 10 — Workshop
Dec 24 — Submission Deadline
From Dec 25 — Judging
Jan 2 — Winners Announcement
Jan 3 — Payouts

For help: Feel free to contact us on Discord or leave a comment below.
Good success and have fun, BUIDLers!

This issue is part of Gitcoin Grants R8 Hackathon:

Look at other bounties:
Github
gr8 1inch bounties list

Chat with us:
discord channel
Telegram group

1inch Challenge 1 - Take Profit and Stop Loss Limit Orders

1inch Challenge 1 - Take Profit and Stop Loss Limit Orders

Prize Bounty

Up to 1k$ worth in CHI Token

Challenge Description

BUIDL a dApp (writing smart contracts is required) which allows DeFi users to set limit orders with take profit and stop loss by using the 1inch liquidity protocol Mooniswap: https://mooniswap.exchange/#/swap.
The system should use directional spot price of our liquidity protocol Mooniswap. The price can't be manipulated in a positive direction because of our special architecture. See our white paper and Research paper by @snjax

Submission Requirements

We require a working demo and a solid MVP.
The best/most creative submission will declared the winner. If you are unsure about whether your hack project suits the bounty topic please present your idea to us via our discord channel.

Open-Source your project at the end of the hackathon a requirement.

Judging Criteria

Creativity and Usefulness.
We will also do a code review to ensure code quality to make the final decision.

Winner Announcement Date

Dec 10 — Workshop
Dec 24 — Submission Deadline
From Dec 25 — Judging
Jan 2 — Winners Announcement
Jan 3 — Payouts

For help: Feel free to contact us on Discord or leave a comment below.
Good success and have fun, BUIDLers!

This issue is part of Gitcoin Grants R8 Hackathon:

Look at other bounties:
Github 1inch list of bounties
Gitcoin gr8 1inch bounties

Chat with us:
discord channel
Telegram group

revert SafeERC20: low-level call failed

I am using 1splitaudit to swap with these address : 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E and 0x50FDA034C0Ce7a8f7EFDAebDA7Aa7cA21CC1267e . the both addresses having show same error : Error: Returned error: VM Exception while processing transaction: revert SafeERC20: low-level call failed -- Reason given: SafeERC20: low-level
call failed
. token used to DAI to TUSD please help

1inch Challenge 4 - Flow Chart for Swap Paths

1inch Challenge 4 - Flow Chart for Swap Paths

Prize Bounty

Up to 1k$ worth in CHI Token

Challenge Description

Create an awesome flow chart that shows complex 1inch swap paths based on executed transactions from etherscan. Essentially a reverse engineering of the swap path.

Submission Requirements

We require a working demo and a solid MVP.
The best/most creative submission will declared the winner. If you are unsure about whether your hack project suits the bounty topic please present your idea to us via our discord channel.

Please make Open-Source your project at the end of the hackathon.

Judging Criteria

Creativity and Usefulness.
We will also do a code review to ensure code quality to make the final decision.

Winner Announcement Date

Dec 10 — Workshop
Dec 24 — Submission Deadline
From Dec 25 — Judging
Jan 2 — Winners Announcement
Jan 3 — Payouts

For help: Feel free to contact us on Discord or leave a comment below.
Good success and have fun, BUIDLers!

This issue is part of Gitcoin Grants R8 Hackathon:

Look at other bounties:
Github
gr8 1inch bounties list

Chat with us:
discord channel
Telegram group

Error: overflow (fault="overflow", operation="toNumber")

Hi guys, I follow the readme guide, but stuck with this error when calling getExpectedReturnWithGas, for destTokenEthPriceTimesGasPrice arg, it always return error with something like

Error: overflow (fault="overflow", operation="toNumber", value="925003271924762633938248194741364019606826595687598837055279805260905", code=NUMERIC_FAULT, version=bignumber/5.0.5)

Guide says arg destTokenEthPriceTimesGasPrice is returnAmount * gas_price, where returnAmount is result of getExpectedReturn(fromToken, destToken, amount, parts, flags), how do i get into this error? Please help me , Thank you very much.

Example code:

const { returnAmount, distribution } = await contract.methods.getExpectedReturn(
  '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  daiAddress,
  web3.utils.toWei('100', 'ether'),
  parts,
  0x00,
).call();
console.log('expected return -> ', returnAmount);
const destTokenEthPriceTimesGasPrice = web3.utils.toBN(returnAmount).mul(web3.utils.toBN(200*Math.pow(10, 9)));

const { returnAmount: a, estimateGasAmount,  distribution: b} = await contract.methods.getExpectedReturnWithGas(
  '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  daiAddress,
  web3.utils.toWei('100', 'ether'),
  parts,
  0x00,
  destTokenEthPriceTimesGasPrice,
).call();
console.log(a);

PS: i'm using [email protected]

Not enough allowance. Amount: xxxx. Allowance: 0. Spender: xxxxxx

This error occurred when I tried to exchange USDT for ETH。

https://api.1inch.exchange/v3.0/1/swap?fromTokenAddress=0xdac17f958d2ee523a2206206994597c13d831ec7&toTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&amount=100000000&fromAddress=0xE242271f229E4A7e3F3D555d5B0F86A412F24123&slippage=1

Error message:
{
"statusCode": 500,
"message": "Not enough allowance. Amount: 100000000. Allowance: 0. Spender: 0x11111112542d85b3ef69ae05771c2dccff4faa26",
"error": "Internal Server Error"
}

Frontend Bug/Feature Request/Cancel problems.

Sorry, a lazy bug filling. But because you don't have many issues, that's the way.

  1. A frontend bug, wrong coin names used in Ratio, I think it takes the coin names from the coin in the swap form above.
  2. A feature request, can you make the table sortable?
  3. I did try to cancel some orders, no luck. But this was some time ago, before the gas price was so high. And it was a SAI order, maybe did not work, because of SAI sunsetting. I can write you the failing tx on dm somewhere.

frontendbug2

1inch Challenge 2 - Arbitrage bot

1inch Challenge 2 - Arbitrage bot

Prize Bounty

Up to 1k$ worth in CHI Token

Challenge Description

BUIDL an arbitrage bot for example with nodejs or python that uses 1inch API to fill 0x limit orders from 1inch users.
API swagger reference

Example

Find an 0x order from the Mesh network (which was created by one of our users) and fill it by using your own ETH and 1inch API to fill it and swap back into ETH with profit.

If you see limit order of swapping M XXX tokens to N YYY tokens try to:

  • Flash borrow N YYY tokens somewhere (optional, you can just use own funds)
  • Fill the order and get M XXX tokens
  • Swap M XXX orders to YYY tokens
  • Repay N YYY tokens flash loan (optional, you can just use own funds)
  • Get the rest, take gas fees into account to make profitable transactions.
  • Earn $1k (just kidding, get the bounty)

Submission Requirements

We require a working demo and a solid MVP.
The best/most creative submission will declared the winner. If you are unsure about whether your hack project suits the bounty topic please present your idea to us via our discord channel.

Please make Open-Source your project at the end of the hackathon.

Judging Criteria

Creativity and Usefulness.
We will also do a code review to ensure code quality to make the final decision.

Winner Announcement Date

Dec 10 — Workshop
Dec 24 — Submission Deadline
From Dec 25 — Judging
Jan 2 — Winners Announcement
Jan 3 — Payouts

For help: Feel free to contact us on Discord or leave a comment below.
Good success and have fun, BUIDLers!

Look at other bounties:
Github
gr8 1inch bounties list

Chat with us:
discord channel
Telegram group

1inch Challenge 6 - UI for 1inch API

UI for 1inch API

Prize Bounty

Up to 3k DAI

Challenge Description

Create a user-friendly UI for using the 1inch API.

Submission Requirements

Working Demo and Solid MVP.

Judging Criteria

Creativity, Usefulness, Beauty

Winner Announcement Date

Jan 2.

Create npm package for interacting with 1inch Protocol methods to enable dApps to easily integrate 1inch swaps.

From my recent experience of integrating the OneSplit contracts to perform ETH -> sUSD swaps, I believe that it will greatly benefit dApp developers if they could use the features of 1inch by installing a npm package that handles all the configurations and only exposes the essential and easy to read methods.

If the core contributors do not want to implement such a feature themselves, I can help build out this feature via a gitcoin grant. 😊

Create fully onchain split, get price, and trade smart contracts

A fully onchain DEX aggrator will allow DeFi building blocks for cotrader.com and others.

Prices should be competitive with other DEX aggregator options..

Users can get prices and execute a split trade that gets the max tokens possible at the lowest prices available by using a combination of dexs, especially AMM Swap DEXs including Kyber, Bancor, Uniswap, Oasis.

Swap of DAI to USDT, DAI to USDC results in - Fail with error 'SafeERC20: low-level call failed'

Hello,

I am trying to use the Swap function from OneSplit Contract -
0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E

I was able to successfully perform the swap from DAI to TUSD and from TUSD back to DAI. Both have 18 decimal places.

However, the same does not work for DAI to USDT, or DAI to USDC. (USDT, USDC has got 6 decimal places and I have accounted for 6 decimal places in the code in JS file).

I have tested on testnet using ganache (live fork) and truffle. I get the follow error in this setup.

VM Exception while processing transaction: revert

I tried this on the mainnet too. On the mainnet, I get the following error.

Fail with error 'SafeERC20: low-level call failed'

What am I doing wrong? Hope get this this solved.

Regards,
Harish

Deprecation

Could the team explain why this was deprecated?

1inch Challenge 5 - VWAP Oracles

VWAP Oracles

Prize Bounty

Up to 3k DAI

Challenge Description

Use Volume Weighted Price Oracles to do some CRAZZZY stuff.

Submission Requirements

Working Demo and Solid MVP

Judging Criteria

CREATIVITY

Winner Announcement Date

Jan 2.

Add "getExpectedInput" to calculate token input amount

Uniswap (both v1 and v2) allows developers to calculate how many input tokens should be sent for a certain amount of output tokens.

It would be helpful to include a similar feature here, especially if you intend to integrate Uni V2 once it's launched.

Failure to call 1inch getExpectedReturn function from the Solidity contract

I am trying to test 1inch getExpectedReturn function from my Solidity contract. I deploy my contract on the Mainnet forked with Ganache via Remix. The entire contract is pretty simple and looks as follows:

pragma solidity ^0.5.0;
    pragma experimental ABIEncoderV2;
    
    interface IERC20 {
        function totalSupply() external view returns (uint256);
        function balanceOf(address account) external view returns (uint256);
        function transfer(address recipient, uint256 amount) external returns (bool);
        function allowance(address owner, address spender) external view returns (uint256);
        function approve(address spender, uint256 amount) external returns (bool);
        function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
        event Transfer(address indexed from, address indexed to, uint256 value);
        event Approval(address indexed owner, address indexed spender, uint256 value);
    }
    
    contract IOneSplit {
        function getExpectedReturn(
            IERC20 fromToken,
            IERC20 toToken,
            uint256 amount,
            uint256 parts,
            uint256 disableFlags
        )
            public
            view
            returns(
                uint256 returnAmount,
                uint256[] memory distribution
            );
    }
    
    contract TradingBot  {
    
        // OneSplit Config
        address ONE_SPLIT_ADDRESS = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E;
        uint256 PARTS = 10;
        uint256 FLAGS = 0;
    
        // Allow the contract to receive Ether
        function () external payable  {}
    
        function getreturn (address _from, address _to, uint256 _amount) public view returns(uint returnAmount, uint[] memory distribution) {
            IERC20 _fromIERC20 = IERC20(_from);
            IERC20 _toIERC20 = IERC20(_to);
            IOneSplit _oneSplitContract = IOneSplit(ONE_SPLIT_ADDRESS);
            (returnAmount, distribution) = _oneSplitContract.getExpectedReturn(_fromIERC20, _toIERC20, _amount, PARTS, FLAGS);
        } 
    }

The contract compiles well but after deployment and running the getreturn function I always get the cryptic "VM Exception while processing transaction: revert" error. I also tried to use the call function:

function getreturn_test () public {
        
        ONE_SPLIT_ADDRESS.call(abi.encodeWithSignature(
                                    "getExpectedReturn(address,address,uint256,uint256,uint256)",
                                                        0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
                                                        0x6B175474E89094C44Da98b954EedeAC495271d0F,
                                                        uint(100), uint(10), uint(0)));
        }

It does not work either. I can't find any explanation why this does not work in my contract. Are these functions implemented correctly?

Limit order not showing but still active, warning on ui?

i had an old limit order which was no longer showing on the 1inch exchange ui, get executed after i transferred into my wallet some of the asset that was the 'maker' asset from the old limit order. I know of only 2 possibilities why it wasnt showing on the ui, someone from the team probably knows more, 1) because i previously transferred out the maker asset from the wallet, or 2) because i previously revoked approvals for spending the token using approved.zone, then reapproved.

I had no way to cancel the old limit order prior to transferring in the asset(weth in this case), which was trading at a much higher value than it was at the time i placed the limit order, a lot of money was lost. I want to recommend to the 1inch team, to possibly put some kind of warning on the limit order ui, warning that limit orders will not be cancelable if you transfer out the maker asset from your wallet, or revoke approvals, and to cancel them beforehand, because they will remain active. Or even better, to continue showing the limit orders so long as they remain active, to allow users to cancel them.

pairs for which the /quote api endpoint returns data return no data for /swap or /swapQuote

I am trying to get a quote for the DAI/ETH pair on a specifc (single) decentralized exchange. I can pass this information to the /quote endpoint, but when I change 'quote' in the url to 'swap' I get 'message:"Error"'. Why does this happen? I am excluding all exchanges but one, but this also occurs when I have no exchanges disabled. Also, why is there not a more explanatory error code?

MM

Hey Guys,

U did amazing project, but haven't bought MM to pump the coin price? Lol. Come one, what a lame, nice and usable project, but no MM - its BS. If you ain't gonna do something with your coin price (pump, eh?) it will end up somewhere in the garbage...

1inch Challenge 5 - 1inch Widget

1inch Challenge 5 - 1inch Widget

Prize Bounty

Up to 1k$ worth in CHI Token

Challenge Description

BUIDL a widget for token swaps which can be embedded on any website. Project could use it to offer buying and selling own tokens on own project page.

Submission Requirements

We require a working demo and a solid MVP.
The best/most creative submission will declared the winner. If you are unsure about whether your hack project suits the bounty topic please present your idea to us via our discord channel.

Please make Open-Source your project at the end of the hackathon.

Judging Criteria

Creativity and Usefulness.
We will also do a code review to ensure code quality to make the final decision.

Winner Announcement Date

Dec 10 — Workshop
Dec 24 — Submission Deadline
From Dec 25 — Judging
Jan 2 — Winners Announcement
Jan 3 — Payouts

For help: Feel free to contact us on Discord or leave a comment below.
Good success and have fun, BUIDLers!

Look at other bounties:
Github
gr8 1inch bounties list

Chat with us:
discord channel
Telegram group

Current 1split version

What is the current version of 1split contract available? Last transaction on etherscan on"0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E" is before 70 days.
image

Testnet deployment

Hello! it's been almost two years since the first proposition of putting 1inch on a testnet #15 and I was wondering if you'd thought any more about implementing it on something like the Kovan Network. You could start with Uniswap, Sushi, and Balancer just as an experiment. It would obviously help with running test contracts as well as help the network's tokens achieve a relative equilibrium- for example, 1 ETH on Sushi swaps for 123983 USDC whereas 1 ETH on Balancer swaps for 7569.25 USDC. It'd be putting 1inch's aggregation/arbitrage to the "test".

Testnet deployments

I have some contracts almost ready for deployment to mainnet, but want to run some tests on a public test network.

Is 1split deployed to ropsten or another test network?

1inch Challenge 1 - Token Launches on Mooni

1inch Challenge 1 - Token Launches on Mooni

This issue is part of Gitcoin Grants R8 Hackathon:

Prize Bounty

Up to 3k$ worth in image CHI Token

Challenge Description

UX Tools to help people launch tokens on Mooniswap w/ an emphasis on it being better for initial liquidity providers.

Submission Requirements

A working demo and solid MVP. The demo should be included in the submission.
Open-source is appreciated.

Judging Criteria

Creativity and Usefulness.

Winner Announcement Date

2 Jan 2021

For help: Feel free to contact us on Discord or leave a comment below.
Good luck, have fun, BUIDLers!

This issue is part of Gitcoin Grants R8 Hackathon:

Look at other bounties:
[Github 1inch list of bountirshttps://github.com/1inch-exchange/1inchProtocol/labels/Gitcoin)
Gitcoin gr8 1inch bounties

1inch Challenge 6 - Open Track

1inch Challenge 6 - Open Track

Prize Bounty

Up to 1k$ worth in CHI Token

Challenge Description

Just BUILD on top of our services what ever you want!

Submission Requirements

We require a working demo and a solid MVP.
The best/most creative submission will declared the winner. If you are unsure about whether your hack project suits the bounty topic please present your idea to us via our discord channel.

Please make Open-Source your project at the end of the hackathon.

Judging Criteria

Creativity and Usefulness.
We will also do a code review to ensure code quality to make the final decision.

Winner Announcement Date

Dec 10 — Workshop
Dec 24 — Submission Deadline
From Dec 25 — Judging
Jan 2 — Winners Announcement
Jan 3 — Payouts

For help: Feel free to contact us on Discord or leave a comment below.
Good success and have fun, BUIDLers!

Look at other bounties:
Github
gr8 1inch bounties list

Chat with us:
discord channel
Telegram group

1inch Challenge 9 - Charitable Swaps

1inch Challege 9 - Charitable Swaps

Prize Bounty

Up to 500 Dai.

Challenge Description

Create a way to automatically donate part of a swap transaction to a charity.

Submission Requirements

Solid Demo and Working MVP.

Judging Criteria

Creativity and Usefulness

Winner Announcement Date

Jan 2.

"Send" tab

Send ETH and tokens using CHI gas token.

Add support for DMM

The interface is very similar to compound. All mTokens have the same number of decimals as their underlying counterpart. The exchangeRate is always a number with 18 decimal places, regardless of the token.

Master Controller - 0x4CB120Dd1D33C9A3De8Bc15620C7Cd43418d77E2

  • You can call #getDmmTokenIds to get all of the tokens by their ID and iterate through them, if you want. There are the respective functions in there for getting the underlying token by address or querying on the mToken address if you only have the underlying (eg DAI --> mDAI) underlyingTokenAddressToDmmTokenIdMap

mDAI -0x06301057D77D54B6e14c7FafFB11Ffc7Cab4eaa7
mETH - 0xdF9307DFf0a1B57660F60f9457D32027a55ca0B2
mUSDC - 0x3564ad35b9E95340E5Ace2D6251dbfC76098669B

Minting is as simple as calling mint(uint underlyingAmount) where underlyingAmount is the amount of underlying you want to send into the contract. Note, a token approval is needed for calling mint on the underlying contract, where the spender is set to the mToken contract address.

Redeeming mTokens for underlying, plus interest, is done through redeem(uint amount) where amount is the amount of mTokens to be sent to the contract and redeemed. Note, no token approvals are required to redeem mTokens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.