You Can Do It!

At Balancer we recently finished a pretty major release and it was probably the most stressful release Iโ€™ve been involved in with there so far. I wanted to write this as a kind of log of a cool thing I helped build but also as a reminder that its possible to get through the tough times and come succesfully out the other side!

The release was actually two pretty major things – first there was the launch of Balancers MetaStable pools, and second was a partnership with Lido. MetaStable pools allow pools of tokens with highly correlated prices, for example cDAI and DAI and Lido were making use of a MetaStable pool to launch an incentivised WETH/wstETH pool. We integrated Lido pretty deeply and the goal was to support trades in stETH by using a Relayer contract to wrap/unwrap automatically, this meant we also had to take into account the stETH/wstETH exchange rates for calcualtions and display. We also wanted to make use of the deep WETH/Stable liquidity Balancer has and allow stable <> Lido trades, this was a slight issue because it involved a two hop trade (i.e. USDC > DAI > WETH > wstETH) which the SOR doesn’t currently support so we had to add static routes for those.

There was a lot going on across all the different teams in Balancer with some fairly tight/strict deadlines. At the time (and actually still now) there’s no Product Manager at Balancer so there wasn’t really someone managing the project. Because of this it very much felt like cat herding and some of the communication could have been better. Also things were changing a lot quite close to the deadline which made things pretty stressful for someone like me who likes to try and get things done early! The last mistake was the deployments of everything happened over the weekend for a Monday launch which wasn’t ideal. These are all things that are being addressed now that we’ve had some retrospectives – Balancer always seem good at continuously trying to improve.

A lot of this probably won’t make a great deal of sense but some of the things that I touched during the work:

  • SOR Hardcoded paths
  • SOR MarketSP support
  • Swap amount via query
  • Stable pool issues due to invariant
  • Subgraph update and rollout
  • Kovan test deployment:
    • stETH + wstETH token on Kovan
    • Faucet for wstETH
    • Correct pools
    • Relayer
  • Relayer – authorisation and approval debug
  • Relayer join/exits being canned after I spent time on them,
  • Limits on front-end
  • Front-end using correct stETH/wstETH exchange

And there was a whole bunch of other stuff being worked on across other teams.

And at the end of it all we made it! The launch went ahead smoothly and on time. The Lido pools are already some of the largest in the Balancer Vault and there haven’t been any major issues so far. I certainly learned a lot and enjoyed working with some team members I haven’t been involved with before. And although it was really stressful and tough at times, the old cliche of breaking down something large into smaller pieces and just working through them is true. Phew!

Update:

Kristen, the Balancer COO, posted a tweet about Impostor Syndrome from Just Kan that I thought was pretty pertinent.

“You will always feel like you are drowning. Even when you are succeeding, it feels like you are drowning because you are constantly being forced to do something new that you haven’t had experience in. While figuring this stuff out on the fly, you’re going to feel like you’re failing and that you’re an impostor.”

Photo by Ava Sol on Unsplash

SITIR 9

๐Ÿ˜ฝ Example of a Flashbot bundle to rescure a cryptokitty from a compromised wallet.

๐Ÿ’ก Another UMA post – they keep posting interesting use cases that I’m always interested to dive into but never have the time to do (I think this is maybe part of their problem). Keeping it logged here as a bookmark!

Really good advice (especially given the latest massive correction and volatility) from Ari Paul ๐Ÿฆ‰

I rarely have good ideas. To overcome this limitation, I think about one topic (like habits) for an unreasonable amount of time. Then, I revise, revise, revise until only the best stuff remains. Itโ€™s slow, but it works. You can either be a genius or you can be patient.

James Clear

๐Ÿ“ท Using a camera and TinyML to read a physical meter and convert it into an API.

๐Ÿ”ง Multicall pattern in Solidity using Delegatecall. Tweet from Austin.

๐Ÿ‘จโ€๐Ÿ’ป Interesting details about running your own ETH node in the cloud.

๐Ÿ˜Ž And this seems like something useful you could do with a node – eth_call any contract with an arbitrary code to access storage values without corresponding public views.

๐Ÿ‘ฎ Why I Did Not Go To Jail by Ben Horowitz – just a good example of doing the right, difficult thing.

โš–๏ธ A cool write up explaining what we’ve been working on at Balancer for V2.

โญ Not sure if this description of path to fame and fortune within Ethereum is meant to have a negative connotation but I’m on step 2!

๐Ÿคฃ Marshawn Lynch at Applebee’s – funny! But I like this guys attitude toward money from what I’ve read.

๐Ÿงฐ What problems do people solve with strace? – Could be handy some day.

๐Ÿง  This was cool – post by samczsun giving a guided walkthrough for swap, the hardest challenge in Paradigm CTF 2021.

๐Ÿงฎ I like what @adlrocha is doing with the Improving my math intuition series and the first part about Network Applications of Bloom Filters was really interesting.

โ‚ฟ Bitcoin is Dead! Quite a fun site, particularly at this time.

You’re not that good. Yet. ๐Ÿง˜โ€โ™‚๏ธ

๐Ÿ‘ This was a nice tweet storm about Balancer V2 and how Coinbase employees were going to invest in it. Not sure it came true but the V2 stuff is!

๐Ÿ“บ zkPorter seems like a novel tech and this explainer video was good.

๐Ÿ’ƒ Taylor Swift and NFTS, what’s not to like?

If working at Balancer ever gets non-fun then I imagine I’d like to do something like this. Also cool way to recruit. ๐Ÿค”

๐Ÿ‘ด๐Ÿผ How to Keep Your Edge as You Get Older – good podcast with ideas for me!

๐Ÿ”ฉ Etherscan & Tx Logs – some nice detail on how to walk these for info.

๐Ÿฆ Eth staking and Warren Buffet. It’s all about where you stand.

๐Ÿคฏ Uncovering a Four Year Old Bug. A glimpse into how samczsuns brain works hunting down a bug.

๐Ÿ”Œ Teardown of a PC power supply – always wanted to get a breakdown of a PSU and this is a really accessible one. Better than the majority of my Uni lectures!!

Photo by Ben White on Unsplash

SITIR 8

โ›“๏ธ Interesting Tweet from a project dev about writing his own code rather than use TheGraph. Covalent was mentioned as alternative – get events by topic hash or get events by contract address to fetch fully decoded log events for any contract.

๐Ÿ‘ Rules of thumb that simplify decisions

An explanation ๐Ÿค‘ about the different ways to make money with Options.

๐Ÿง™ Seems like good advice – 1/3 (networth) for the house, 1/6 to deal with expense / taxes, 1/2 rocket fuel.

โš’๏ธ Glitch – Build fast, full-stack web apps in your browser. Seems interesting and could be good for demos, docs or learning quickly.

Valentines isn’t far past so love โค๏ธ is in the air – 36 Questions That Lead To Love

โฑ๏ธ Time Billionaire – Is a pretty cool idea.

๐Ÿ” Pretty useful security tip – How to Ensure Youโ€™re Running the Legitimate Version of MetaMask

๐Ÿณ Wow – a wallet showing how the whales do it! ๐Ÿ’ต

Some more options craziness โ‚ฟ

More Burniske wisdom – it’s all waves man ๐Ÿ„โ€โ™‚๏ธ

๐Ÿคช Can’t get any crazier than 2020 – funny but not funny!

Getting In Good ๐Ÿƒ – Really interesting thread with examples of when to double down.

๐ŸŽง Bitcoin Vs Altcoins with Dan Held & Erik Voorhees – this was a great listen. Erik Voorhees is so articulate and I really like his logical and reasonable approach.

These Book Nooks are SO cool ๐Ÿค“

A case for the long BTC HODL ๐Ÿ’ช

โš ๏ธ Tail-end events are all that matter – a very tough lesson.

The Margin Loan – Interesting tradfi example of using leverage and the benefits of doing it ๐Ÿค”

And a DeFi version of above – FollowTheChain โ›“๏ธ & RicBurton demonstrating how using a MakerDAO vault to live of DAI and avoid selling your Eth during the Bear market.

Maker Vaults wouldn’t work with Liquidators ๐Ÿฆพ and this is a nice intro.

๐Ÿงฐ I’ve been working on Fleek and Cloudflare lately and it’s been fun – Fleek Makes Deploying and Maintaining an ENS+IPFS Website Easier than Ever

Photo by Antonio DiCaterina on Unsplash

SITIR 7

โ›ฝ GasTokens are pretty interesting and this was a good article.

๐Ÿ†’ Pretty cool (but expensive) screen project here.

Have a plan! Some good advice in this tweet. Particularly like – “But who really gives a shit about the “top” if you know exactly how much you need to retire and you get there well before the “top”? You just hit that number and you exit the game with a grin…Draw up your expenses… calculate how much you’ll have leftover after you pay taxes on some huge ass crypto gains. Then, assume about 5-7% a year in income thanks to some “safe” dividend stocks, maybe an annuity and some cefi stablecoin income…” ๐Ÿฆ‰

๐Ÿง˜ Also some good advice – On Despair and the Imagination.

โš ๏ธ Interesting tweet about BTC yield. Info about risks – > 50% flash crash risk >wBTC custodial risk > AAVE risks > Yearn/Curve risks, USDT risk too using 3pool. And how to maximise %, i.e. If using AAVE you borrow TUSD at 1.5% then swap to USDT. If using Compound you borrow DAI but receive COMP for overall around 0%.

๐ŸŽจ Some, cool, colourful and reasonably priced artwork.

๐Ÿ˜ข The Girl In The Window – wow, that was a hard hitting read.

๐ŸŽธ Long live Rock And Roll! Our โ€˜Lostโ€™ Weekend With Van Halen – A pretty amusing story that’s also a bit shocking in the way it shows how times have changed.

๐Ÿ–ผ๏ธ Some more cool art – this time Crypto Art (but a horrible website!)

๐Ÿ˜ฑ Big liquidation event on Compound because of DAI Oracle price. Pretty scary lesson learned here.

โ“ Good questions for the dinner table from Polina Marinovas newsletter – What was the most formative event in your life that you believe shaped who you are today? and What is one belief you hold that you would be afraid to share in public?

๐Ÿงฐ Recommended by rabmarut as an easier to use alternative to Metamask – Frame.

๐Ÿˆ Some of the Huddle Up posts are really good. “Equity Deals Only” about DeAndre Hopkins was worth a read.

Photo by Kyle Glenn on Unsplash

Etherscan API

Etherscan is a really useful website but fairly recently I discovered they also have a pretty handy Developer API. I used it to analyse gas a contract was using over a period of time and thought it might be useful to record.

Getting Started

First of all an API key is required and this can be created for free by logging in and going to: https://etherscan.io/myapikey.

I’m going to paste my code with comments which should be easy enough to follow. The API covers a whole lot of other end point such as Logs, Tokens, etc that I didn’t use but the docs are good and worth a scan.

Example

Photo by Markus Spiske on Unsplash

SITIR 6

๐Ÿค Eth Network Discord Community – I liked the idea about this from DeFi Dudes tweet.

๐Ÿฅง I’ve used RaspberryPi a lot and the new Pi 400 seems cool.

๐ŸŽง Uncommon Core seems like a good podcast to add to the list and this was an interesting thread discussing some of points made in the last episode.

๐Ÿง‘โ€๐Ÿ’ป Then new Ethereum.org dev portal was released and is probably a go to resource now.

๐Ÿฅช Mmmmmhhhh sandwiches!

๐Ÿ‘ฉโ€๐Ÿซ 40 things I learned by age 40 by Sunday Soother has some really good advice worth re-reading every now and then.

I don’t really know much about yield curves and things but fixed rate lending/borrowing on Ethereum would be ๐Ÿ‘Œ

And along similar lines this Rise of the Cryptodollar article from Bankless discusses savings rates for crypto dollars.

๐ŸŒ๏ธโ€โ™‚๏ธ Didn’t realise half this stuff about the Masters finances and thought it was pretty interesting.

๐Ÿง˜ This so true:

Working on a problem reduces the fear of it.

Itโ€™s hard to fear a problem when you are making progress on itโ€”even if progress is imperfect and slow.

Action relieves anxiety.

James Clear 3-2-1

SITIR 5

๐Ÿ‘ท Hardhat & Tenderly are two super useful smart contract dev tools and this guide shows how to get them setup together.

๐Ÿง˜ James Clear 3-2-1 Newsletter is probably the most consistently good one I read, it almost always makes you think. On kindness, real wealth, and earning love and respect is a really good one.

๐Ÿ‘ฉโ€๐Ÿซ Good learning in Falsehoods that Ethereum programmers believe.

I read about Ocean Farming ages ago and haven’t been able to shake the crazy idea that this would be a cool thing to do. ๐ŸŸ

๐ŸŽฅ I was pretty proud of this ๐Ÿฆš feels like I’ve done a circle and gone from hacker to judge, was also very cool to appear on the schedule next to the big names:

๐Ÿ“– Bookmarked for the future – Ethereum Developer Interview Questions.

Look- here’s a table covered with red cloth. On it is a cage the size of a small fish aquarium. In the cage is a white rabbit with a pink nose and pink-rimmed eyes.

On its back, clearly marked in blue ink, is the numeral 8. [โ€ฆ] The most interesting thing here isn’t even the carrot-munching rabbit in the cage, but the number on its back. Not a six, not a four, not nineteen-point-five. It’s an eight. This is what we’re looking at, and we all see it. I didn’t tell you. You didn’t ask me. I never opened my mouth and you never opened yours.

We’re not even in the same year together, let alone the same roomโ€ฆ except we are together. We are close. We’re having a meeting of the minds. We’ve engaged in an act of telepathy. No mythy-mountain shit; real telepathy.

Stephen King – Books are portable magic. ๐Ÿง™โ€โ™‚๏ธ

โš–๏ธ Clearing out some old bookmarks and this Tweet and this AMA with Bankless are from back when it all got started with Balancer!

Can rely on Chris Burniske tweets to reset the sentiment on a bad day ๐Ÿ“‰

Photo by Artur Tumasjan on Unsplash

SITIR 4

๐Ÿ‘พ Dark Forest was a pretty fun game to play on the Ethereum network that used xkSNARKs and they did a pretty interesting intro to zk proofs.

No Edinburgh Festival this year ๐Ÿ˜ฅ but people are still trying and here’s a celebration of the city.

๐Ÿ›น Jackass was a big part of my younger days and Steve O was one of my main men. Demise and Rise is pretty inspiring, how he turns his life around should give hope.

Shared a lot but Ethereum is a Dark Forest and the follow up, Escaping The Dark Forest were pretty good – the mempool is cool ๐Ÿ˜Ž!

Following up on โ˜๏ธ this dives into front-running Bots. Also cool how its a ‘story of block 1088…’.

โš’๏ธ Graphtage: A New Semantic Diffing Tool – could be a handy tool.

TxStreet.com – Love this โค๏ธโ€๐Ÿ”ฅ a live cryptocurrency transaction visualizer featuring Bitcoin, Ethereum and Bitcoin Cash.

๐Ÿ’ธ Pretty useful cheat sheet for seeing IL vs Fees vs Price action on Uniswap.

๐Ÿ“ป I’ve been enjoying listening to Justin Kans podcast, The Quest, lately – tech, happiness and the meaning of life!

โ›ฝ Vitalik explains Gas costs.

๐Ÿฑ I didn’t love the whole food farming thing but it was pretty wild and will go down in Ethereum history. Here’s some food for thought (๐Ÿคฆ).

๐Ÿ‘จโ€๐Ÿ’ป How to re-send a transaction with higher gas price using ethers.js – Something that might be useful.

Options are interesting and I’ve played a bit with Opyn. Some interesting Buidling ideas.๐Ÿ’ก

๐Ÿ“– Perpetual Contracts are another finance instrument thats new to me and here’s a bit of an explainer.

๐Ÿ‘ One of the few posts I’ve seen that shows examples for EIP712. Also goes into meta-txs.

Photo by Clever Visuals on Unsplash

SITIR 3

๐Ÿˆ The Athlete That Gave Up Millions To Build A Sports Media Empire ๐Ÿ’ฐ – Been enjoying the Huddle Up newsletter and this was an awesome story (the YouTube at the end was cool).

โš–๏ธ Proof Of Liquidity, Joel Moegro. I’ve been thinking about uses of Balancer Pool Tokens (BPT) and it was interesting to see this – When you add assets to a pool, you receive ERC-20 BPT tokens in that pool proportional to your contribution. In Joels example you use these tokens to stake. The staking service can ‘look through’ the BPT to see how much of the required token you’re staking. In the meantime the pooled tokens are providing liquidity and the stakers assets remain balanced to the original pool weights. Seems like a lot can be done with this kind of idea…

I’m an NHS doctor โ€“ and I’ve had enough of people clapping for me – Strange, confusing times and this captures a bit of how I feel.

6 JavaScript console methods like Taylor Swift folklore lyrics – Twilio have some decent dev articles and this one had some nice new info I hadn’t heard.

โš–๏ธ “Honestly, there’s another way to look at it from the low cap perspective. If you hold onto the low cap, and it moons on very low volume/liquidity, then you likely won’t even be able to sell it at the top. There just won’t be enough liquidity. But if you provide liquidity in a pool, and your pool comprises most of the global liquidity for that low-cap token, then when it moons you can simply withdraw your liquidity and you’ll have way more ETH or USDC or whatever than you started with. It’s basically a unique way of selling a bunch of those tokens on the way up whereas you may not have even been able to do that if you were trading on someone else’s illiquid market.

โฌ†๏ธ Balancer community member, @rabmurat posted that message on Discord and it provided some interesting confirmation for something I had been thinking –

  • Assume stable DAI price
  • ๐Ÿ“ˆ๐Ÿ’ฉโฌ†๏ธ Market shitcoin price goes up 10%
  • ๐Ÿ‘€ Arbitrageur sees opportunity
  • ๐Ÿ’ฒโžก๏ธโš– ๏ธโžก๏ธ๐Ÿ’ฉ DAI in to pool shitcoin out
  • โš–๏ธ๐Ÿ’ฉโฌ‡๏ธ Bal pool shitcoin price goes up to market price
  • Pool now has more token and less DAI
  • How to choose weights? High shit % means keep more shit but high % also means less of pair (DAI) required
  • Compared to HODL?
    • Impermanent loss does happen but remember HODL only works if you can actually sell at that price – is there liquidity/volume/slippage, etc?

Along similar lines this tweet was an interesting way to think about the BAL incentive mechanism – “…people can deposit their illiquid shitcoins and convert it to a new coin which might be better…”

How to create an Ethereum DeFi realtime dashboard – I didn’t realise Google scripting was so advanced.

๐Ÿ‚ This was a good Tweet storm by Chris Burniske with some tips on how to handle the Bull market (if it comes…)

๐Ÿ‚ Also some more good Bull market/general advice from Taylor Monahan.

Ballet is so cool ๐Ÿฉฐ and this from Ballet Opera de Paris shows that working from home is easier for some!

An explainer video about the Opyn hack that shows some useful tooling. Opyn handled it pretty well I thought but also thought it kind of showed they don’t have much traction.

Memeconomics – thought this summed up the current situation pretty well but I guess time will tell.

Photo by Patrick Tomasso on Unsplash

Buidler, Waffle & Ethers

Lately at Balancer we’ve moved from the Truffle development environment to using Buidler, Waffle and Ethers. The main benefit is being able to use console.log in Solidity during debugging – it’s amazing how much of a difference this makes and for this alone the change over is worth it. Here’s some notes I made during the switch over.

Ethers

The ethers.js library aims to be a complete and compact library for interacting with the Ethereum Blockchain and its ecosystem.

Documentation is here: https://docs.ethers.io and this Web3.js vs Ethers.js guide was useful.

The following gist demonstrates some basic usage of Ethers that creates an instance of a deployed contract and then running some calls against it:

Buidler & Waffle

Buidler is described as a ‘task runner’. I think its easiest to see it as a swap for Truffle/Ganache. It has lots of different plugins that make it really useful and its documentation was refreshingly good.

The Quickstart shows you how to install and how to run common tasks. It also uses Waffle for testing. Waffle is a simple smart contract testing library built on top of Ethers.js. Tests in Waffle are written using Mocha alongside with Chai and from my experience everything just worked. The docs are here. And its worth digging in to see some of the useful things it offers such as Chai Matchers which allow you to test things like reverts, events, etc.

Buidler commands I found I used a lot:

  • Run the local Buidler EVM: $ npx buidler node
  • Compile project contracts: $ npx buidler compile
  • Run tests: $ npx buidler test ./test/testfile.ts

Here’s an example test file I used that demonstrates a few useful things:

Static Calls

let poolAddr = await factory.callStatic.newBPool(); – The contract callStatic pretends that a call is not state-changing and returns the result. This does not actually change any state and is free.

Connecting Different Accounts

await _pools[1].connect(newUserSigner).approve(PROXY, MAX); – Using contract connect(signer) calls the contract via the signer specified.

Gas Costs

await proxy.connect(newUserSigner).exitswapExternAmountOut(
            _POOLS[1],
            MKR,
            amountOut,
            startingBptBalance,
            {
              gasPrice: 0
            }
        );

Setting the gasPrice to 0 like above allows me to run the transaction without spending any Eth on it. This was useful when checking Eth balance changes without having to worry about gas costs.

Custom accounts & balances

const config: BuidlerConfig = {
  solc: {
    version: "0.5.12",
    optimizer: {
      enabled: true,
      runs: 200,
    },
  },
  networks: {
    buidlerevm: {
      blockGasLimit: 20000000,
      accounts: [
        { privateKey: '0xPrefixedPrivateKey1', balance: '1000000000000000000000000000000' },
        { privateKey: '0xPrefixedPrivateKey2', balance: '1000000000000000000000000000000' }
      ]
    },
  },
};

I needed the test accounts to have more than the 1000Eth balance set by default. In buidler.config.ts you can add accounts with custom balances like above.

Deploying

Deploying is done using scripts. First I updated my buidler.config.ts with the account/key for Kovan that will be used to deploy (i.e. must have Eth):

const config: BuidlerConfig = {
  solc: {
    version: "0.5.12",
    optimizer: {
      enabled: true,
      runs: 200,
    },
  },
  networks: {
    buidlerevm: {
      blockGasLimit: 20000000,
    }
    kovan: {
      url: `https://kovan.infura.io/v3/${process.env.INFURA}`,
      accounts: [`${process.env.KEY}`]
    }
  },
};

Then I wrote a deploy-script.js:

async function main() {
  // We get the contract to deploy
  const ExchangeProxy = await ethers.getContractFactory("ExchangeProxy");
  const WETH = '0xd0A1E359811322d97991E03f863a0C30C2cF029C';
  const exchangeProxy = await ExchangeProxy.deploy(WETH);

  await exchangeProxy.deployed();

  console.log("Proxy deployed to:", exchangeProxy.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

Then run this using: npx buidler run --network kovan deploy-script.js

๐ŸŽ‰ Console Logging ๐ŸŽ‰

One of the holy grails of Solidity development and so easy to setup in this case! There are also Solidity stack traces and error messages but unfortunately there was a bug that caused this not to work for our contracts.

To get this going all you need to do is add: import "@nomiclabs/buidler/console.sol"; at the top of your contract then use console.log. More details on what kind of outputs, etc it supports are here. Lifesaver!

Hope some of this was helpful and you enjoy using it as much as me.

(Photo by Kevin Jarrett on Unsplash)