Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make referrer address configurable for 1Inch #459

Merged
merged 2 commits into from
Aug 22, 2022

Conversation

MartinquaXD
Copy link
Contributor

The 1Inch solver is costing a lot of money to run because it keeps positive slippage. One way to reduce the cost a bit is to participate in 1Inch's referral program.
This program rewards referrers some amount of 1INCH tokens for every trade referred to 1Inch. The rewards can be claimed "approximately once per week" [0]. The 1Inch DAO can vote how much of the fees get rewarded for the referral [1].

new CLI argument:

        --one-inch-referrer-address <ONE_INCH_REFERRER_ADDRESS>
            Which address should receive the rewards for referring trades to 1Inch

            [env: ONE_INCH_REFERRER_ADDRESS=]

logs for CLI argument:

...
one_inch_url: https://api.1inch.exchange/
one_inch_referrer_address: 0x6c642cafcbd9d8383250bb25f67ae409147f78b2
disabled_zeroex_sources: []
...

Test Plan

Updated and ran automated and relevant ignored unit tests
Local test with the orderbook and solver to verify that both the OneInchEstimator and OneInchSolver append the referrer address to their queries.

logs from solver:

...
2022-08-18T07:10:55.795Z DEBUG auction{id=21994 run=0}: shared::oneinch_api: Query 1inch API for url https://api.1inch.exchange/v4.1/1/swap?fromTokenAddress=0x3f382dbd960e3a9bbceae22651e88158d2791550&toTokenAddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&amount=321827029307309282465&fromAddress=0x9008d19f58aabd9ed0d60971565aa8510560ab41&slippage=0.1&protocols=UNISWAP_V1%2CUNISWAP_V2%2CSUSHI%2CMOONISWAP%2CBALANCER%2CCOMPOUND%2CCURVE%2CCURVE_V2_SPELL_2_ASSET%2CCURVE_V2_SGT_2_ASSET%2CCURVE_V2_THRESHOLDNETWORK_2_ASSET%2CCHAI%2COASIS%2CKYBER%2CAAVE%2CIEARN%2CBANCOR%2CCREAMSWAP%2CSWERVE%2CBLACKHOLESWAP%2CDODO%2CDODO_V2%2CVALUELIQUID%2CSHELL%2CDEFISWAP%2CSAKESWAP%2CLUASWAP%2CMINISWAP%2CMSTABLE%2CPMM2%2CSYNTHETIX%2CAAVE_V2%2CST_ETH%2CONE_INCH_LP%2CONE_INCH_LP_1_1%2CLINKSWAP%2CS_FINANCE%2CPSM%2CPOWERINDEX%2CXSIGMA%2CCREAM_LENDING%2CSMOOTHY_FINANCE%2CSADDLE%2CPMM4%2CKYBER_DMM%2CBALANCER_V2%2CUNISWAP_V3%2CSETH_WRAPPER%2CCURVE_V2%2CCURVE_V2_EURS_2_ASSET%2CCURVE_V2_EURT_2_ASSET%2CCURVE_V2_XAUT_2_ASSET%2CCURVE_V2_ETH_CRV%2CCURVE_V2_ETH_CVX%2CCONVERGENCE_X%2CONE_INCH_LIMIT_ORDER%2CONE_INCH_LIMIT_ORDER_V2%2CDFX_FINANCE%2CFIXED_FEE_SWAP%2CDXSWAP%2CCLIPPER%2CSHIBASWAP%2CUNIFI%2CPSM_PAX%2CWSTETH%2CDEFI_PLAZA%2CFIXED_FEE_SWAP_V3%2CSYNTHETIX_WRAPPER%2CSYNAPSE%2CCURVE_V2_YFI_2_ASSET%2CCURVE_V2_ETH_PAL%2CPOOLTOGETHER%2CETH_BANCOR_V3%2CELASTICSWAP%2CBALANCER_V2_WRAPPER%2CSYNTHETIX_ATOMIC%2CFRAXSWAP%2CRADIOSHACK%2CKYBERSWAP_ELASTIC%2CCURVE_V2_TWO_CRYPTO%2CSTABLE_PLAZA%2CZEROX_LIMIT_ORDER&disableEstimate=true&referrerAddress=0x6c642cafcbd9d8383250bb25f67ae409147f78b2&allowPartialFill=false
2022-08-18T07:10:55.955Z DEBUG auction{id=21994 run=0}: shared::oneinch_api: Response from 1inch API: Ok("{\"fromToken\":{\"symbol\":\"GHST\",\"name\":\"Aavegotchi GHST Token\",\"decimals\":18,\"address\":\"0x3f382dbd960e3a9bbceae22651e88158d2791550\",\"logoURI\":\"https://tokens.1inch.io/0x3f382dbd960e3a9bbceae22651e88158d2791550.png\",\"tags\":[\"tokens\"]},\"toToken\":{\"symbol\":\"USDC\",\"name\":\"USD Coin\",\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"decimals\":6,\"logoURI\":\"https://tokens.1inch.io/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png\",\"eip2612\":true,\"domainVersion\":\"2\",\"tags\":[\"tokens\"]},\"toTokenAmount\":\"407243367\",\"fromTokenAmount\":\"321827029307309282465\",\"protocols\":[[[{\"name\":\"UNISWAP_V3\",\"part\":100,\"fromTokenAddress\":\"0x3f382dbd960e3a9bbceae22651e88158d2791550\",\"toTokenAddress\":\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"}],[{\"name\":\"UNISWAP_V3\",\"part\":100,\"fromTokenAddress\":\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\"toTokenAddress\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\"}]]],\"tx\":{\"from\":\"0x9008d19f58aabd9ed0d60971565aa8510560ab41\",\"to\":\"0x1111111254fb6c44bac0bed2854e76f90643097d\",\"data\":\"0xe449022e000000000000000000000000000000000000000000000011723f4a0ad565d4a100000000000000000000000000000000000000000000000000000000183fd39b00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fba31f01058db09573a383f26a088f23774d4e5d80000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640cfee7c08\",\"value\":\"0\",\"gas\":0,\"maxFeePerGas\":\"11312815143\",\"maxPriorityFeePerGas\":\"5449322350\"}}")

logs from estimator:

...
2022-08-18T07:31:38.872Z DEBUG request{id=1}: shared::oneinch_api: Query 1inch API for url https://api.1inch.exchange/v4.1/1/quote?fromTokenAddress=0xdac17f958d2ee523a2206206994597c13d831ec7&toTokenAddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&amount=1000000000&protocols=UNISWAP_V1%2CUNISWAP_V2%2CSUSHI%2CMOONISWAP%2CBALANCER%2CCOMPOUND%2CCURVE%2CCURVE_V2_SPELL_2_ASSET%2CCURVE_V2_SGT_2_ASSET%2CCURVE_V2_THRESHOLDNETWORK_2_ASSET%2CCHAI%2COASIS%2CKYBER%2CAAVE%2CIEARN%2CBANCOR%2CCREAMSWAP%2CSWERVE%2CBLACKHOLESWAP%2CDODO%2CDODO_V2%2CVALUELIQUID%2CSHELL%2CDEFISWAP%2CSAKESWAP%2CLUASWAP%2CMINISWAP%2CMSTABLE%2CPMM2%2CSYNTHETIX%2CAAVE_V2%2CST_ETH%2CONE_INCH_LP%2CONE_INCH_LP_1_1%2CLINKSWAP%2CS_FINANCE%2CPSM%2CPOWERINDEX%2CXSIGMA%2CCREAM_LENDING%2CSMOOTHY_FINANCE%2CSADDLE%2CPMM4%2CKYBER_DMM%2CBALANCER_V2%2CUNISWAP_V3%2CSETH_WRAPPER%2CCURVE_V2%2CCURVE_V2_EURS_2_ASSET%2CCURVE_V2_EURT_2_ASSET%2CCURVE_V2_XAUT_2_ASSET%2CCURVE_V2_ETH_CRV%2CCURVE_V2_ETH_CVX%2CCONVERGENCE_X%2CONE_INCH_LIMIT_ORDER%2CONE_INCH_LIMIT_ORDER_V2%2CDFX_FINANCE%2CFIXED_FEE_SWAP%2CDXSWAP%2CCLIPPER%2CSHIBASWAP%2CUNIFI%2CPSM_PAX%2CWSTETH%2CDEFI_PLAZA%2CFIXED_FEE_SWAP_V3%2CSYNTHETIX_WRAPPER%2CSYNAPSE%2CCURVE_V2_YFI_2_ASSET%2CCURVE_V2_ETH_PAL%2CPOOLTOGETHER%2CETH_BANCOR_V3%2CELASTICSWAP%2CBALANCER_V2_WRAPPER%2CSYNTHETIX_ATOMIC%2CFRAXSWAP%2CRADIOSHACK%2CKYBERSWAP_ELASTIC%2CCURVE_V2_TWO_CRYPTO%2CSTABLE_PLAZA%2CZEROX_LIMIT_ORDER&referrerAddress=0x6c642cafcbd9d8383250bb25f67ae409147f78b2
2022-08-18T07:31:38.926Z DEBUG maintenance{block=15363722}: shared::event_handling: updating events in block range Specific(15363671)..=Latest(15363723)
2022-08-18T07:31:38.945Z DEBUG maintenance{block=15363722}: shared::event_handling: updating events in block range Specific(15363671)..=Latest(15363723)
2022-08-18T07:31:39.052Z DEBUG request{id=1}: shared::oneinch_api: Response from 1inch API: Ok("{\"fromToken\":{\"symbol\":\"USDT\",\"name\":\"Tether USD\",\"address\":\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\"decimals\":6,\"logoURI\":\"https://tokens.1inch.io/0xdac17f958d2ee523a2206206994597c13d831ec7.png\",\"tags\":[\"tokens\"]},\"toToken\":{\"symbol\":\"USDC\",\"name\":\"USD Coin\",\"address\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\"decimals\":6,\"logoURI\":\"https://tokens.1inch.io/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png\",\"eip2612\":true,\"domainVersion\":\"2\",\"tags\":[\"tokens\"]},\"toTokenAmount\":\"1000034052\",\"fromTokenAmount\":\"1000000000\",\"protocols\":[[[{\"name\":\"UNISWAP_V3\",\"part\":100,\"fromTokenAddress\":\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\"toTokenAddress\":\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\"}]]],\"estimatedGas\":238614}")

@MartinquaXD MartinquaXD requested a review from a team as a code owner August 18, 2022 07:54
@@ -270,6 +274,9 @@ impl Display for Arguments {
self.disabled_one_inch_protocols
)?;
writeln!(f, "one_inch_url: {}", self.one_inch_url)?;
write!(f, "one_inch_referrer_address: ")?;
display_option(&self.one_inch_referrer_address.map(|a| format!("{a:?}")), f)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed because the Display implementation of H160 prints something like 0x123...abc which is not very helpful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, you can also use {:#x}.

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@MartinquaXD MartinquaXD enabled auto-merge (squash) August 22, 2022 06:06
@MartinquaXD MartinquaXD merged commit 0705b49 into main Aug 22, 2022
@MartinquaXD MartinquaXD deleted the one-inch-referrer-address branch August 22, 2022 06:10
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2022
@fleupold
Copy link
Contributor

Nice! Too bad that it missed the release by a few hours and therefore will take another week to be in production 😞. Last week we would have gained $1k from this change ($5k total slippage).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants