Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Uniswap integration #160

Closed
wants to merge 86 commits into from
Closed

Uniswap integration #160

wants to merge 86 commits into from

Conversation

liamzebedee
Copy link
Contributor

@liamzebedee liamzebedee commented Jun 9, 2019

Closes #105, closes #129

This deploys a private Uniswap Factory/Exchange as part of a Truffle migration, as well as implementing onchain liquidation.

It also refactors some liquidation code, introducing startLiquidation. There is also some changes to the liquidation logic, which are discussed in #105

  • deploy uniswap
  • integrate uniswap deployment into truffle
  • test uniswap deployment
  • add tbtc token
  • add uniswap Solidity interfaces
  • test e2e uniswap trade with tbtc
  • flesh out test for attemptToLiquidateOnchain
  • implement attemptToLiquidateOnchain with uniswap exchange
  • flesh out test for startSignerFraudLiquidation
  • flesh out test for startSignerAbortLiquidation
  • make changes to fraud/abort liquidation logic, auctionTBTCAmount
  • add stub uniswap factory/exchanges
  • add stub DepositLiquidation
  • test for remaining eth after liquidation in attemptToLiquidateOnchain
  • refactor liquidation common logic into startLiquidation
  • test redemption/non-redemption flows
  • integrate real uniswap deployment in tests
  • fix all broken tests

--

Implementor: @liamzebedee
Feature buddy: @mhluongo

@mhluongo
Copy link
Member

@liamzebedee does this also touch #129? Looks like you're deploying non-stub versions of Uniswap 😃

Copy link
Member

@mhluongo mhluongo left a comment

Choose a reason for hiding this comment

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

Eine kleine Frage

const child_process = require('child_process')

async function deployUniswap() {
if(uniswap.getDeployments().Factory != "") {
Copy link
Member

Choose a reason for hiding this comment

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

Is this enough to test for a deployment on mainnet, or just testnet? If so, we need to make sure we have a repeatable build, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally for testnet - this was just intended to work with unit tests (since Truffle redeploys for every test). Will get back to you on how suitable it is for mainnet.

@liamzebedee
Copy link
Contributor Author

@liamzebedee does this also touch #129? Looks like you're deploying non-stub versions of Uniswap 😃

Haha was that not the intention? In which case, it would be closing #129 too. 🌳

@mhluongo
Copy link
Member

@liamzebedee where are we on a non-draft PR? This is on my list for tomorrow.

@prestwich can you give this another look? I'm going to double check on your requestor reward question

@liamzebedee
Copy link
Contributor Author

@mhluongo last touches/cleanups, give it one hour. ⏳

@liamzebedee
Copy link
Contributor Author

liamzebedee commented Jul 19, 2019

Ready for design review.

Couple things still before we can undraft the PR:

Copy link
Member

@mhluongo mhluongo left a comment

Choose a reason for hiding this comment

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

A couple JS changes, but the big issue is removing the unrelated stuff from the PR that's making review difficult- eg around funding proofs, pulling in the token contract, etc. Has enough of that stuff been merged to master for a clean-up rebase? If not, is there another branch that's a better base for this PR?


static getDeadline() {
const DEADLINE_FROM_NOW = 300 // TX expires in 300 seconds (5 minutes)
const deadline = Math.ceil(Date.now() / 1000) + DEADLINE_FROM_NOW
Copy link
Member

Choose a reason for hiding this comment

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

This is a little obtuse- it looks like you're converting Date.now() to seconds to get a future deadline in seconds, but considering the proliferation of date, time, and math libs and approaches in JS I'd leave a comment about what deadline means

Copy link
Contributor Author

@liamzebedee liamzebedee Jul 24, 2019

Choose a reason for hiding this comment

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

Mmmm true. Will doc it returns a seconds-since-epoch timestamp


export class AssertBalanceHelpers {
constructor(tbtc) {
this.tbtcInstance = tbtc
Copy link
Member

Choose a reason for hiding this comment

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

The difference in constructor param name vs instance var name.. irks

Copy link
Member

Choose a reason for hiding this comment

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

I also don't personally think using the suffix instance anywhere is useful unless you're distinguishing it from a constructor, factory, or collection, though maybe in this case tbtcInstance is a lazy pseudo "type", reminding me sadly of Hungarian notation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely Hungarian. Renaming constructor param sounds good.

/**


Some notes on the cryptoeconomics of Uniswap and TBTC, time arbitrage between chains
Copy link
Member

Choose a reason for hiding this comment

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

Oh my, I hope we have a better place for some of this- low discoverability

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it'd be better to contribute to the Uniswap docs in that case. Had to read the Uniswap frontend JS to even get to this understanding... 😮

a. Uniswap 100% of ETH
b. Uniswap 50% ETH and 50% falling price auction

I think it's worth documenting the additional complexity stemming from automatic liquidation. 3a won't necessarily buy up enough TBTC to burn, depending on the pool size, but the arbitrage incentives are going to keep the price stable to its price-oracle reported value (with a little delta).
Copy link
Member

Choose a reason for hiding this comment

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

3a won't necessarily buy up enough TBTC to burn, depending on the pool size

The plan was to only Uniswap if we can buy up enough TBTC to burn, otherwise to go 100% for the falling-price auction. Thoughts?



tbtcExchange = await IUniswapExchange.at(tbtcExchangeAddr)
/* eslint-enable no-unused-vars */
Copy link
Member

Choose a reason for hiding this comment

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

Why uh.. why?

If you just need the side-effect can't you await as a statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to create the contract from the interface ABI. IUniswapExchange is the interface contract. :)

@mhluongo
Copy link
Member

Ready for design review.

I'll circle back to this when it's a little tidier- don't want to stick you with a bunch of irrelevant comments

@mhluongo
Copy link
Member

@gakonst you might find this interesting

@gakonst
Copy link
Contributor

gakonst commented Aug 15, 2019

What's the status of this PR?

@mhluongo
Copy link
Member

Languishing while we finish up https://github.com/keep-network/tbtc-dapp @gakonst - would love review

@mhluongo mhluongo requested a review from gakonst August 15, 2019 17:15
@liamzebedee
Copy link
Contributor Author

@gakonst warning, this one's a bit of a nakamofo. Design (esp tests) needs to be reduced down a bit more.

@pdyraga
Copy link
Member

pdyraga commented Aug 19, 2019

It looks like we have some rebase work to be done here. Can we do that before anyone jumps into review?

@gakonst
Copy link
Contributor

gakonst commented Aug 22, 2019

Ping, please let me know when I should review this PR (@pdyraga mentions above that it should first be rebased)

@pdyraga
Copy link
Member

pdyraga commented Aug 22, 2019

@mhluongo Also interested if this is affected by the recent oracle discussions - should we review/merge or do we need something completely else?

@mhluongo
Copy link
Member

mhluongo commented Aug 23, 2019

This should not be impacted by the new oracle design. Let's rebase and clean up so @gakonst can review @liamzebedee

@liamzebedee
Copy link
Contributor Author

Yep going to give this a cleanup on the plane today and we can push forward

@liamzebedee liamzebedee mentioned this pull request Aug 27, 2019
@liamzebedee
Copy link
Contributor Author

Ok @gakonst this issue spiralled out into a couple different changes, which I'm splitting into multiple PR's.

The 1st is the Uniswap deployment, which is ready for review here #263. The 2nd will include the rest of liquidation implementation. Was a bit sick, hence the delay.

@liamzebedee
Copy link
Contributor Author

Closing this PR - the rest of work has been split into #265, which so far is a much simpler implementation with hindsight applied 😉

nkuba added a commit that referenced this pull request Sep 19, 2019
This issue breaks away work from #160 into something more deliverable:

- introduces a script to deploy external systems, based on discussions in #270. Uniswap is deployed from a newly-created package at https://github.com/keep-network/uniswap
- updates README with respect to this
- includes Uniswap Solidity interfaces
- separates unit and integration testing into two suites, new circleci flows for this
- includes an E2E test with our TBTCToken of a Uniswap trade
@liamzebedee liamzebedee deleted the onchain-liquidation branch September 26, 2019 16:36
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.

More realistic Uniswap deployment on testnet Implement on-chain liquidation
5 participants