Skip to content

rndlabs/openbzz-exchange-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenBZZ 🌐🐝 exchange contracts

A front-end contract for interacting with the Ethereum Swarm bonding curve for buying and selling BZZ.

Please note that contracts within this repository are experimental and unaudited.

Features

  • Gasless approve for DAI -> BZZ exchange (uses DAI permit function).

  • Bridging to Gnosis Chain

    • Send direct to a bee node's wallet
    • Direct top-up of a postage batch
  • Fee collection for maintenance / development (see deployed site for more information).

Tests

This a foundry forge project. You can run tests:

forge test -f http://url.to.archive.node:8545 -vvv

To also generate coverage information use forge coverage instead.

Linting

This repo currently uses forge as the linter. It can be called through forge:

forge fmt

Typechain

To generate typechain bindings use:

npx typechain --target ethers-v5 --out-dir ./typechain './out/**/*.json'

This will generate the typechain bindings in the typechain/ directory. This requires typechain to be installed and is actually best done in the consuming package (web app).

Deployments

Swap is deployed on the following networks:

Network Name Contract
Mainnet Exchange 0x69defd0bdcdca696042ed75b00c10276c6d32a33
Gnosis BzzRouter 0xEd469d6aa0658b71B9dE75c2fe401924FCf0534d

Overview

Exchange

Exchange is a simple contract that interacts with the bonding curve, allowing buying or selling of BZZ from/to the curve.

Approvals

The Exchange contract interacts with DAI and BZZ. Therefore the following approve methods are available:

  • DAI: approve() and permit()
  • BZZ: approve()

Therefore, when transacting from DAI to BZZ, it is possible to do single transactions without requiring an approval.

NOTE: It may appear similar to there being two transactions, but the first is actually a signing request for signing the DAI permit, with the second pop-up being the actual transaction.

Bridging

As Swarm mainnet's incentive contracts / accounting layer runs on the Gnosis Chain blockchain, and the bonding curve presides on Ethereum mainnet, there is a potential need for bridging between mainnet and Gnosis Chain.

For example, if a user wanted to purchase BZZ from the Bonding Curve to top-up a stamp, they would have to:

  1. Approve DAI for use on the bonding curve to purchase BZZ.
  2. Exchange DAI for BZZ on the bonding curve.
  3. Approve the Gnosis Chain omnibridge for spending BZZ for bridging.
  4. Bridge BZZ from mainnet to Gnosis Chain using the omnibridge.
  5. Transfer the BZZ to their node's wallet.
  6. Execute the top up transaction from their node.

This exchange contract drastically streamlines the user experience, allowing a single transaction to complete all of the above.

Depending on the bridge_cd parameter passed to the buy function, a user may:

  1. Purchase BZZ tokens and send them directly to an address on Gnosis Chain.
  2. Purchase BZZ tokens, send them to Gnosis Chain and directly top-up a stamp.

BZZ Router

BzzRouter is a small utility contract that resides on Gnosis Chain and is responsible for redirecting BZZ. This router will:

  1. Redirect BZZ that has been bridged, using the onTokenBridged callback from HomeBridge.
  2. Redirect BZZ that has been transferred, using the onTokenTransfer callback for ERC677 transfers.

No fees are deducted by this utility contract.