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

Add script to swap ERC-20 token balances in Gitcoin Fee address to ETH using Uniswap #4517

Merged
merged 8 commits into from
Oct 23, 2019

Conversation

acolytec3
Copy link
Contributor

Description

Pulls ERC-20 token balances associated with fee address and converts to ETH using Uniswap.
Notes:

Do-over of #4229 and #4383 (cuz my git skillz are lacking)
On Rinkeby testnet, Uniswap trading request only currently works for BAT Uniswap exchange but not OMG or MKR exchanges (using my on test account)

Refers/Fixes

Fixes #4150

Testing

Test included

@acolytec3
Copy link
Contributor Author

@owocki @danlipert @SaptakS @thelostone-mc Redo of #4229 and #4383 with clean commit history. Sorry for multiple do-overs.

@codecov
Copy link

codecov bot commented May 30, 2019

Codecov Report

Merging #4517 into master will increase coverage by 0.05%.
The diff coverage is 42.4%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4517      +/-   ##
==========================================
+ Coverage   30.02%   30.08%   +0.05%     
==========================================
  Files         209      214       +5     
  Lines       16886    17011     +125     
  Branches     2278     2292      +14     
==========================================
+ Hits         5070     5117      +47     
- Misses      11619    11694      +75     
- Partials      197      200       +3
Impacted Files Coverage Δ
app/feeswapper/views.py 0% <0%> (ø)
app/feeswapper/apps.py 0% <0%> (ø)
app/app/settings.py 78.81% <100%> (+0.15%) ⬆️
app/feeswapper/models.py 100% <100%> (ø)
app/feeswapper/admin.py 100% <100%> (ø)
app/feeswapper/management/commands/feeSwapper.py 35.23% <35.23%> (ø)
app/dashboard/embed.py 28.16% <0%> (-3.45%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c31bc1f...bf85c9f. Read the comment docs.

@codecov
Copy link

codecov bot commented May 30, 2019

Codecov Report

Merging #4517 into master will increase coverage by 0.29%.
The diff coverage is 70.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4517      +/-   ##
==========================================
+ Coverage   29.83%   30.13%   +0.29%     
==========================================
  Files         233      237       +4     
  Lines       19453    19590     +137     
  Branches     2782     2795      +13     
==========================================
+ Hits         5804     5903      +99     
- Misses      13410    13442      +32     
- Partials      239      245       +6
Impacted Files Coverage Δ
app/feeswapper/apps.py 0% <0%> (ø)
app/app/settings.py 79.49% <100%> (+0.37%) ⬆️
app/feeswapper/models.py 100% <100%> (ø)
app/feeswapper/admin.py 100% <100%> (ø)
app/feeswapper/management/commands/feeSwapper.py 67.82% <67.82%> (ø)
app/gas/utils.py 38.46% <0%> (+3.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8b7bd2...c0ec9d2. Read the comment docs.

@acolytec3
Copy link
Contributor Author

@danlipert @thelostone-mc @SaptakS Checking in on this one. Any chance of getting it reviewed now that I've got the commit history cleaned up? As a reminder, it's the same code as now closed PRs #4229 and #4383. I believe what got mucked up before was my attempt at squashing accidentally included a bunch of commits from the master branch that somehow got roped into my PR when I was rebasing the branch per the contributor guidelines and I could never untangle them in the commit history.

app/feeswapper/management/commands/feeSwapper.py Outdated Show resolved Hide resolved
app/feeswapper/management/commands/feeSwapper.py Outdated Show resolved Hide resolved
app/feeswapper/management/commands/feeSwapper.py Outdated Show resolved Hide resolved
app/feeswapper/management/commands/feeSwapper.py Outdated Show resolved Hide resolved
app/feeswapper/management/commands/feeSwapper.py Outdated Show resolved Hide resolved
app/feeswapper/management/commands/feeSwapper.py Outdated Show resolved Hide resolved
@acolytec3
Copy link
Contributor Author

@danlipert Pause on the review of this. I was digging back through this with fresh eyes after a weekend away and noted some improvements and also some new insights for some unit tests. I'll try to knock out the changes in the next couple of days and give you a heads up on Slack when it's ready to revisit.

@acolytec3 acolytec3 changed the title Add script to swap ERC-20 token balances in Gitcoin Fee address to ETH using Uniswap WIP - Add script to swap ERC-20 token balances in Gitcoin Fee address to ETH using Uniswap Jun 17, 2019
@danlipert
Copy link
Contributor

@danlipert Pause on the review of this. I was digging back through this with fresh eyes after a weekend away and noted some improvements and also some new insights for some unit tests. I'll try to knock out the changes in the next couple of days and give you a heads up on Slack when it's ready to revisit.

Sounds good! Appreciate all your hard work on this and the desire for more and better testing and improvements :)

@acolytec3 acolytec3 changed the title WIP - Add script to swap ERC-20 token balances in Gitcoin Fee address to ETH using Uniswap Add script to swap ERC-20 token balances in Gitcoin Fee address to ETH using Uniswap Jun 21, 2019
@danlipert
Copy link
Contributor

@acolytec3 nice! appreciate the extra tests! Can you squash it down to 1 commit and rebase on master? Thanks!

@acolytec3
Copy link
Contributor Author

@danlipert Squashed and rebased.

@acolytec3
Copy link
Contributor Author

@danlipert @owocki Just checking in on this. Is there anything additional you're looking for on this one?

@owocki
Copy link
Contributor

owocki commented Jul 3, 2019

no i dont think so. we'll get it into the review queue. thanks again for the hard work on this :)

@acolytec3
Copy link
Contributor Author

Not trying to be obnoxious but is there any chance of getting this either approved or else any other feedback? It's been sitting for quite a while.

app/app/local.env Outdated Show resolved Hide resolved

# Gitcoin Bounty Funding Fee settings
FEE_ADDRESS = env('FEE_ADDRESS', default='')
FEE_ADDRESS_PRIVATE_KEY = env('FEE_ADDRESS_PRIVATE_KEY', default='')
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to test this on the mainnet, a la FEE_ADDRESS_NETWORK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, though I don't think you need to specify a special network setting in .env for that. You would just need to put an address and key with some mainnet ERC-20 balance in it, set the overall network in the .env for Mainnet, and then run the management command from the docker shell.

@owocki
Copy link
Contributor

owocki commented Jul 25, 2019

just left a few comments.. cc @danlipert on final approval

danlipert
danlipert previously approved these changes Jul 26, 2019
Copy link
Contributor

@danlipert danlipert left a comment

Choose a reason for hiding this comment

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

Looks great man! Just one small question but otherwise approved!

app/feeswapper/tests.py Outdated Show resolved Hide resolved
"balance":"10000000"
},
{
"symbol":"WEENUS",
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is a real token I'm giving up 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, it's real which means I'm a rich man. 🤘

@danlipert
Copy link
Contributor

@octavioamu @thelostone-mc can y'all take a look and lets get this deployed this week! 👍

@owocki
Copy link
Contributor

owocki commented Oct 16, 2019

@danlipert can we get this on the merge list for the next release pls??

@gitcoinbot
Copy link
Member

⚡️ A tip worth 0.30000 ETH (52.95 USD @ $176.5/ETH) has been granted to @acolytec3 for this issue from @owocki. ⚡️

Nice work @acolytec3! Your tip has automatically been deposited in the ETH address we have on file.

@gitcoinbot
Copy link
Member

Magical Unicorn ⚡️ A *Magical Unicorn* Kudos has been sent to @acolytec3 for this issue from @owocki. ⚡️

Nice work @acolytec3!
Your Kudos has automatically been sent in the ETH address we have on file.

@danlipert danlipert merged commit 6566a82 into gitcoinco:master Oct 23, 2019
@owocki
Copy link
Contributor

owocki commented Nov 1, 2019

hey @acolytec3 i setup the fee swapper on 0xee2303c55f024bf094b2c5ef41002d28f73d144a

and deposited 10 STORJ into that account for testing.. but the feeswapper script still reutrns

(gitcoin-37) ubuntu@ip-172-31-1-57:~/gitcoin/coin/app$ ./manage.py feeSwapper
INFO 2019-11-01 16:46:48,527 connectionpool 14259 140054417635072 Starting new HTTPS connection (1): gitcoin-storage-fz4cb2.s3.us-west-2.amazonaws.com
INFO 2019-11-01 16:46:49,512 feeSwapper 14259 140054417635072 {"status": "0", "result": [], "message": "No tokens found"}
{}

what am i doing wrong? pls advise

@owocki
Copy link
Contributor

owocki commented Nov 1, 2019

storj is def a token supported by uniswap http://bits.owocki.com/aa2e0194b66f/Screen%20Shot%202019-11-01%20at%2010.48.53%20AM.png

@acolytec3
Copy link
Contributor Author

acolytec3 commented Nov 1, 2019 via email

@owocki
Copy link
Contributor

owocki commented Nov 1, 2019

i just got this email 51 minutes ago (the initial fail was 2 hours ago tho)

STORJ conversion to ETH failed previously so no conversion was attempted.

@owocki
Copy link
Contributor

owocki commented Nov 1, 2019

@acolytec3 looks like th escript did at some point send a tx to the mainnet! https://etherscan.io/tx/0xf5b72d8fbee40cd6c5fe883ba32a0b49ba79eaab90c33961e6007dc055dd2efa

@owocki
Copy link
Contributor

owocki commented Nov 1, 2019

ah looks like i got a 'STORJ conversion to ETH failed' email to

@acolytec3
Copy link
Contributor Author

acolytec3 commented Nov 1, 2019 via email

@owocki
Copy link
Contributor

owocki commented Nov 11, 2019

any luck? as it stands all this script is doing is sending me an email every hour telling me its not working lol

@acolytec3
Copy link
Contributor Author

acolytec3 commented Nov 11, 2019 via email

@acolytec3
Copy link
Contributor Author

Initial research indicates that there is indeed something wrong with the parameters I'm using in the Uniswap function call in the script. I also discovered that they released a JavaScript sdk since I wrote the initial code so will do a line by line comparison and see what's different and see if I can find the source of the issue that way. Barring that, will work further on deploying to ganache and trying to recreate.

@acolytec3
Copy link
Contributor Author

acolytec3 commented Nov 17, 2019

I've been back over the parameters and they match the Uniswap guidelines exactly as far as I can tell so not seeing anything new. I've also compared how I structure the transaction to the Uniswap Python Wrapper function that calls the TokenToEthSwapInput method on the Uniswap contract and here again, structure appears to match exactly.

And, to top it all off, Blockscout discontinued their Rinkeby explorer/API so I can't even run the script in Debug mode anymore so...need a rethink on how to approach this. Any opinions?

@owocki
Copy link
Contributor

owocki commented Nov 20, 2019

@acolytec3 maybe test on mainnet? i can send you a few tokens if that unblocks you

@acolytec3
Copy link
Contributor Author

acolytec3 commented Nov 20, 2019 via email

@danlipert
Copy link
Contributor

@acolytec3 - the additional dependency is fine with me 👍

@acolytec3
Copy link
Contributor Author

Further experimentation says that this library is out of date (of course). Will see if it's a simple fix to make it work for our purposes.

@owocki
Copy link
Contributor

owocki commented Dec 1, 2019 via email

@acolytec3
Copy link
Contributor Author

Sorry for radio silence, holidays and other business got in the way. I've spent a fair bit more time experimenting with this and I confess I'm completely at a loss. The python-uniswap wrapper library is obsolete at this point and didn't provide any insights in its underlying code since it's doing the same thing that my script does when constructing the transactions. I extracted the part of the PR that interacts with the Uniswap exchange into it's own script so I could just run transactions and had the same experience as I reported when building the code base originally (i.e. the script works with the Rinkeby BAT Uniswap exchange, but not other ones).

  1. 0xb28f88baa687a770cf45e2f460ef1047d4fb2579b6898fcf61e434774127656b is a successful transaction to sell BAT on Rinkeby using the script.
  2. 0x8187c613f0ce6b315ab77e825e6ddfd8176b0cffa33e8525bd9b3313d22d0c47 is a never-ending pending transaction trying to sell OMG on Rinkeby using the exact same code.

@owocki
Copy link
Contributor

owocki commented Dec 19, 2019

@acolytec3 thanks for trying..

if we post another task that moves the token transfers to a diff uniswap wrapper library would that help?

have you tried posting a github issue to ask the maintainer for help? https://github.com/shanefontaine/uniswap-python/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants