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

Burn auction #143

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions abi/burnauction.abi
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "beneficiary",
"type": "address"
}
],
"name": "deposit",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
Expand Down
13 changes: 12 additions & 1 deletion abi/depositmanager.abi
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "subtreeID",
"type": "uint256"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "root",
"name": "subtreeRoot",
"type": "bytes32"
}
],
Expand Down Expand Up @@ -137,6 +143,11 @@
"inputs": [],
"name": "dequeueToSubmit",
"outputs": [
{
"internalType": "uint256",
"name": "subtreeID",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "subtreeRoot",
Expand Down
18 changes: 12 additions & 6 deletions abi/rollup.abi
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "subtreeID",
"type": "uint256"
},
{
"indexed": false,
"internalType": "bytes32",
Expand All @@ -84,15 +90,15 @@
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "committer",
"type": "address"
"internalType": "uint256",
"name": "batchID",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
"internalType": "bytes32",
"name": "accountRoot",
"type": "bytes32"
},
{
"indexed": false,
Expand Down
2 changes: 1 addition & 1 deletion aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (a *Aggregator) processAndSubmitBatch(txs []core.Tx) {
lastCommitment := commitments[len(commitments)-1]

// record batch locally
newBatch := core.NewBatch(a.cfg.OperatorAddress, txHash, lastCommitment.BatchType, core.BATCH_BROADCASTED)
newBatch := core.NewBatch(txHash, lastCommitment.BatchType, core.BATCH_BROADCASTED)
batchID, err := a.DB.AddNewBatch(newBatch, commitments)
if err != nil {
a.Logger.Error("Error adding new batch", "error", err)
Expand Down
5 changes: 5 additions & 0 deletions bazooka/bazooka.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
tmLog "github.com/tendermint/tendermint/libs/log"

"github.com/BOPR/contracts/accountregistry"
"github.com/BOPR/contracts/burnauction"
"github.com/BOPR/contracts/create2transfer"
"github.com/BOPR/contracts/depositmanager"
"github.com/BOPR/contracts/massmigration"
Expand Down Expand Up @@ -66,6 +67,7 @@ type (
State *state.State
Transfer *transfer.Transfer
Create2Transfer *create2transfer.Create2transfer
BurnAuction *burnauction.Burnauction
MassMigration *massmigration.Massmigration
AccountRegistry *accountregistry.Accountregistry
DepositManager *depositmanager.Depositmanager
Expand Down Expand Up @@ -356,5 +358,8 @@ func getContractInstances(client *ethclient.Client, cfg config.Configuration) (c
if contracts.TokenRegistry, err = tokenregistry.NewTokenregistry(ethCmn.HexToAddress(cfg.TokenRegistry), client); err != nil {
return contracts, err
}
if contracts.BurnAuction, err = burnauction.NewBurnauction(ethCmn.HexToAddress(cfg.BurnAuction), client); err != nil {
return contracts, err
}
return contracts, nil
}
58 changes: 58 additions & 0 deletions bazooka/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/BOPR/core"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
ethCmn "github.com/ethereum/go-ethereum/common"
)

// CompressTxs compresses all transactions
Expand Down Expand Up @@ -222,3 +223,60 @@ func (b *Bazooka) FetchFromAndToStateIDs(tx core.Tx) (from, to uint64, err error
return 0, 0, errors.New("Did not match any options")
}
}

//
// burn auction
//

// GetCurrentProposer fetches the current proposer from on-chain contract
func (b *Bazooka) GetCurrentProposer() (common.Address, error) {
opts := bind.CallOpts{From: b.operator}
proposer, err := b.SC.BurnAuction.GetProposer(&opts)
if err != nil {
return proposer, err
}

return proposer, nil
}

// GetCurrentSlot fetches the current slot
func (b *Bazooka) GetCurrentSlot() (currentSlot uint32, err error) {
opts := bind.CallOpts{From: b.operator}
slot, err := b.SC.BurnAuction.CurrentSlot(&opts)
if err != nil {
return 0, err
}
return slot, nil
}

// GetBidableSlot fetches the current slot
func (b *Bazooka) GetBidableSlot() (bidableSlot uint32, err error) {
currSlot, err := b.GetCurrentSlot()
if err != nil {
return 0, err
}
return currSlot + 2, nil
}

// GetCurrentBidForSlot fetches the current bid for the slot
func (b *Bazooka) GetCurrentBidForSlot(slot uint32) (proposer ethCmn.Address, amount uint64, isInit bool, err error) {
opts := bind.CallOpts{From: b.operator}
resp, err := b.SC.BurnAuction.Auction(&opts, slot)
if err != nil {
return
}
return resp.Coordinator, resp.Amount.Uint64(), resp.Initialized, nil
}

// GetDeposit fetches the deposit amount for the proposer
func (b *Bazooka) GetDeposit(proposer ethCmn.Address) (uint64, error) {
opts := bind.CallOpts{From: b.operator}
fmt.Println("proposer", proposer)
amount, err := b.SC.BurnAuction.Deposits(&opts, proposer)
if err != nil {
return 0, err
}

fmt.Println("amount", amount)
return amount.Uint64(), nil
}
47 changes: 47 additions & 0 deletions bazooka/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/BOPR/contracts/accountregistry"
"github.com/BOPR/contracts/burnauction"
"github.com/BOPR/contracts/depositmanager"
"github.com/BOPR/contracts/erc20"
"github.com/BOPR/contracts/rollup"
Expand Down Expand Up @@ -425,3 +426,49 @@ func (b *Bazooka) Deposit(pubkey [4]*big.Int, tokenID uint64, amount uint64) (tx
}
return tx.Hash().String(), nil
}

// Bid bids the amount specified for the current coordinator
func (b *Bazooka) Bid(amount uint64) (txHash string, err error) {
burnAuctionABI, err := abi.JSON(strings.NewReader(burnauction.BurnauctionABI))
if err != nil {
return
}
value := big.NewInt(0)
value = value.SetUint64(amount)
data, err := burnAuctionABI.Pack("bid", value)
if err != nil {
b.log.Error("Error packing data for register batch", "err", err)
return
}

tx, err := b.SignAndBroadcast(b.EthClient, ethCmn.HexToAddress(b.Cfg.BurnAuction), value, data)
if err != nil {
b.log.Error("Error bidding for slot", "err", err)
return
}
return tx.Hash().String(), nil
}

// DepositForAuction deposits ETH to be used for bidding to burn auction contract
func (b *Bazooka) DepositForAuction(amountInWei int64, proposer ethCmn.Address) (txHash string, err error) {
burnAuctionABI, err := abi.JSON(strings.NewReader(burnauction.BurnauctionABI))
if err != nil {
return
}

data, err := burnAuctionABI.Pack("deposit", proposer)
if err != nil {
b.log.Error("Error packing data for deposit", "err", err)
return
}

value := big.NewInt(amountInWei)

tx, err := b.SignAndBroadcast(b.EthClient, ethCmn.HexToAddress(b.Cfg.BurnAuction), value, data)
if err != nil {
b.log.Error("Error depositing ETH for auction", "err", err)
return
}

return tx.Hash().String(), nil
}
Loading