Documentation ¶
Index ¶
- Constants
- Variables
- func BjjToString(bjj babyjub.PublicKeyComp) string
- func CalcFeeAmount(amount *big.Int, feeSel FeeSelector) (*big.Int, error)
- func CbStringToBJJ(bjjStr, name string) (*babyjub.PublicKeyComp, error)
- func CbStringToEthAddr(addrStr, name string) (*ethCommon.Address, error)
- func EthAddrToCb(addr ethCommon.Address) string
- func IdxToCb(idx Idx, tokenSymbol string) string
- func IsErrDone(err error) bool
- func StringToEthAddr(ethAddrStr string) (*ethCommon.Address, error)
- type Account
- type AccountCreationAuth
- func (a *AccountCreationAuth) HashToSign(chainID uint16, chainbingContractAddr ethCommon.Address) ([]byte, error)
- func (a *AccountCreationAuth) Sign(signHash func(hash []byte) ([]byte, error), chainID uint16, ...) error
- func (a *AccountCreationAuth) VerifySignature(chainID uint16, chainbingContractAddr ethCommon.Address) (bool, error)
- type AccountUpdate
- type AtomicGroup
- type AtomicGroupID
- type AuctionConstants
- type AuctionData
- type AuctionVariables
- type Batch
- type BatchData
- type BatchNum
- type Bid
- type BidCoordinator
- type Block
- type BlockData
- type BucketParams
- type BucketUpdate
- type Coordinator
- type ExitInfo
- type FeeSelector
- type Idx
- type IdxNonce
- type L2Tx
- type Nonce
- type QueryAccount
- type RecommendedFee
- type RollupConstants
- type RollupData
- type RollupVariables
- type RollupVerifierStruct
- type SCConsts
- type SCVariables
- type SCVariablesPtr
- type Slot
- type StrBigInt
- type StrCbBJJ
- type StrCbEthAddr
- type StrCbIdx
- type TokenExchange
- type WDelayerData
- type WDelayerTransfer
- type WithdrawInfo
Constants ¶
const ( // NLeafElems is the number of elements for a leaf NLeafElems = 4 // IdxBytesLen idx bytes IdxBytesLen = 6 // UserThreshold determines the threshold from the User Idxs can be UserThreshold = 256 // IdxUserThreshold is a Idx type value that determines the threshold // from the User Idxs can be IdxUserThreshold = Idx(UserThreshold) )
const ( // AccountCreationAuthMsg is the message that is signed to authorize a // Chainbing account creation AccountCreationAuthMsg = "Account creation" // EIP712Version is the used version of the EIP-712 EIP712Version = "1" // EIP712Provider defines the Provider for the EIP-712 EIP712Provider = "Chainbing Network" )
const ( // RollupConstMaxFeeIdxCoordinator is the maximum number of tokens the // coordinator can use to collect fees (determines the number of tokens // that the coordinator can collect fees from). This value is // determined by the circuit. RollupConstMaxFeeIdxCoordinator = 64 // RollupConstReservedIDx First 256 indexes reserved, first user index will be the 256 RollupConstReservedIDx = 255 // RollupConstExitIDx IDX 1 is reserved for exits RollupConstExitIDx = 1 // RollupConstLimitTokens Max number of tokens allowed to be registered inside the rollup RollupConstLimitTokens = (1 << 32) //nolint:gomnd // RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] // compressedSignature RollupConstL1CoordinatorTotalBytes = 101 // RollupConstL1UserTotalBytes [20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 // bytes] fromIdx + [5 bytes] depositAmountFloat40 + [5 bytes] amountFloat40 + [4 bytes] // tokenId + [6 bytes] toIdx RollupConstL1UserTotalBytes = 78 // RollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch RollupConstMaxL1UserTx = 128 // RollupConstMaxL1Tx Maximum L1 transactions allowed to be queued in a batch RollupConstMaxL1Tx = 256 // RollupConstInputSHAConstantBytes [6 bytes] lastIdx + [6 bytes] newLastIdx + [32 bytes] // stateRoot + [32 bytes] newStRoot + [32 bytes] newExitRoot + [_MAX_L1_TX * // _L1_USER_TOTALBYTES bytes] l1TxsData + totalL2TxsDataLength + feeIdxCoordinatorLength + // [2 bytes] chainID = 18542 bytes + totalL2TxsDataLength + feeIdxCoordinatorLength RollupConstInputSHAConstantBytes = 18546 // RollupConstMaxWithdrawalDelay max withdrawal delay in seconds RollupConstMaxWithdrawalDelay = 2 * 7 * 24 * 60 * 60 // RollupConstExchangeMultiplier exchange multiplier RollupConstExchangeMultiplier = 1e14 )
const AtomicGroupIDLen = 32
AtomicGroupIDLen is the length of a Chainbing network atomic group
const ( // AuctionErrMsgCannotForge is the message returned in forge with the // address cannot forge AuctionErrMsgCannotForge = "ChainbingAuctionProtocol::forge: CANNOT_FORGE" )
const MaxFeePlan = 256
MaxFeePlan is the maximum value of the FeePlan
Variables ¶
var ( // FFAddr is used to check if an ethereum address is 0xff..ff FFAddr = ethCommon.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff") // EmptyAddr is used to check if an ethereum address is 0 EmptyAddr = ethCommon.HexToAddress("0x0000000000000000000000000000000000000000") )
var (
// RollupConstLimitDepositAmount Max deposit amount allowed (depositAmount: L1 --> L2)
RollupConstLimitDepositAmount, _ = new(big.Int).SetString(
"340282366920938463463374607431768211456", 10)
// RollupConstLimitL2TransferAmount Max amount allowed (amount L2 --> L2)
RollupConstLimitL2TransferAmount, _ = new(big.Int).SetString(
"6277101735386680763835789423207666416102355444464034512896", 10)
// RollupConstEthAddressInternalOnly This ethereum address is used internally for rollup
// accounts that don't have ethereum address, only Babyjubjub.
// This non-ethereum accounts can be created by the coordinator and allow users to have a
// rollup account without needing an ethereum address
RollupConstEthAddressInternalOnly = ethCommon.HexToAddress(
"0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF")
// RollupConstRfield Modulus zkSNARK
RollupConstRfield, _ = new(big.Int).SetString(
"21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
// RollupConstERC1820 ERC1820Registry address
RollupConstERC1820 = ethCommon.HexToAddress("0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24")
// RollupConstRecipientInterfaceHash ERC777 recipient interface hash
RollupConstRecipientInterfaceHash = crypto.Keccak256([]byte("ERC777TokensRecipient"))
// RollupConstPerformL1UserTxSignature the signature of the function that can be called thru
// an ERC777 `send`
RollupConstPerformL1UserTxSignature = crypto.Keccak256([]byte(
"addL1Transaction(uint256,uint48,uint16,uint16,uint32,uint48)"))
// RollupConstAddTokenSignature the signature of the function that can be called thru an
// ERC777 `send`
RollupConstAddTokenSignature = crypto.Keccak256([]byte("addToken(address)"))
// RollupConstSendSignature ERC777 Signature
RollupConstSendSignature = crypto.Keccak256([]byte("send(address,uint256,bytes)"))
// RollupConstERC777Granularity ERC777 Signature
RollupConstERC777Granularity = crypto.Keccak256([]byte("granularity()"))
// RollupConstWithdrawalDelayerDeposit This constant are used to deposit tokens from ERC77
// tokens into withdrawal delayer
RollupConstWithdrawalDelayerDeposit = crypto.Keccak256([]byte("deposit(address,address,uint192)"))
// RollupConstTransferSignature This constant is used in the _safeTransfer internal method
// in order to safe GAS.
RollupConstTransferSignature = crypto.Keccak256([]byte("transfer(address,uint256)"))
// RollupConstTransferFromSignature This constant is used in the _safeTransfer internal
// method in order to safe GAS.
RollupConstTransferFromSignature = crypto.Keccak256([]byte(
"transferFrom(address,address,uint256)"))
// RollupConstApproveSignature This constant is used in the _safeTransfer internal method in
// order to safe GAS.
RollupConstApproveSignature = crypto.Keccak256([]byte("approve(address,uint256)"))
// RollupConstERC20Signature ERC20 decimals signature
RollupConstERC20Signature = crypto.Keccak256([]byte("decimals()"))
)
var EmptyAtomicGroupID = AtomicGroupID([32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
EmptyAtomicGroupID represents an empty Chainbing network atomic group identifier
var ( // EmptyEthSignature is an ethereum signature of all zeroes EmptyEthSignature = make([]byte, 65) )
var ErrBatchQueueEmpty = errors.New("BatchQueue empty")
ErrBatchQueueEmpty is used when the coordinator.BatchQueue.Pop() is called and has no elements
var ErrDone = errors.New("done")
ErrDone is used when a function returns earlier due to a cancelled context
var ErrIdxOverflow = errors.New("Idx overflow, max value: 2**48 -1")
ErrIdxOverflow is used when a given nonce overflows the maximum capacity of the Idx (2**48-1)
var ErrNonceOverflow = errors.New("Nonce overflow, max value: 2**40 -1")
ErrNonceOverflow is used when a given nonce overflows the maximum capacity of the Nonce (2**40-1)
var ErrNotInFF = errors.New("BigInt not inside the Finite Field")
ErrNotInFF is used when the *big.Int does not fit inside the Finite Field
var ErrNumOverflow = errors.New("Value overflows the type")
ErrNumOverflow is used when a given value overflows the maximum capacity of the parameter
var ErrTODO = errors.New("TODO")
ErrTODO is used when a function is not yet implemented
var FeeFactorLsh60 [256]*big.Int
FeeFactorLsh60 is the feeFactor << 60
var FeePlan = [MaxFeePlan]float64{}
FeePlan represents the fee model, a position in the array indicates the percentage of tokens paid in concept of fee for a transaction
Functions ¶
func BjjToString ¶
func BjjToString(bjj babyjub.PublicKeyComp) string
BjjToString converts baby jub jub public key to string
func CalcFeeAmount ¶
CalcFeeAmount calculates the fee amount in tokens from an amount and feeSelector (fee index).
func CbStringToBJJ ¶
func CbStringToBJJ(bjjStr, name string) (*babyjub.PublicKeyComp, error)
CbStringToBJJ converts cb ethereum address string to bjj
func CbStringToEthAddr ¶
CbStringToEthAddr converts cb ethereum address to ethereum address
func EthAddrToCb ¶
EthAddrToCb converts ethereum address to chainbing ethereum address
Types ¶
type Account ¶
type Account struct { Idx Idx `meddler:"idx"` TokenID TokenID `meddler:"token_id"` BatchNum BatchNum `meddler:"batch_num"` BJJ babyjub.PublicKeyComp `meddler:"bjj"` EthAddr ethCommon.Address `meddler:"eth_addr"` Nonce Nonce `meddler:"-"` // max of 40 bits used Balance *big.Int `meddler:"-"` // max of 192 bits used }
Account is a struct that gives information of the holdings of an address and a specific token. Is the data structure that generates the Value stored in the leaf of the MerkleTree
func AccountFromBigInts ¶
func AccountFromBigInts(e [NLeafElems]*big.Int) (*Account, error)
AccountFromBigInts returns a Account from a [5]*big.Int
func AccountFromBytes ¶
func AccountFromBytes(b [32 * NLeafElems]byte) (*Account, error)
AccountFromBytes returns a Account from a byte array
func (*Account) BigInts ¶
func (a *Account) BigInts() ([NLeafElems]*big.Int, error)
BigInts returns the [5]*big.Int, where each *big.Int is inside the Finite Field
func (*Account) Bytes ¶
func (a *Account) Bytes() ([32 * NLeafElems]byte, error)
Bytes returns the bytes representing the Account, in a way that each BigInt is represented by 32 bytes, in spite of the BigInt could be represented in less bytes (due a small big.Int), so in this way each BigInt is always 32 bytes and can be automatically parsed from a byte array.
type AccountCreationAuth ¶
type AccountCreationAuth struct { EthAddr ethCommon.Address `meddler:"eth_addr"` BJJ babyjub.PublicKeyComp `meddler:"bjj"` Signature []byte `meddler:"signature"` Timestamp time.Time `meddler:"timestamp,utctime"` }
AccountCreationAuth authorizations sent by users to the L2DB, to be used for account creations when necessary
func (*AccountCreationAuth) HashToSign ¶
func (a *AccountCreationAuth) HashToSign(chainID uint16, chainbingContractAddr ethCommon.Address) ([]byte, error)
HashToSign returns the hash to be signed by the Ethereum address to authorize the account creation, which follows the EIP-712 encoding
func (*AccountCreationAuth) Sign ¶
func (a *AccountCreationAuth) Sign(signHash func(hash []byte) ([]byte, error), chainID uint16, chainbingContractAddr ethCommon.Address) error
Sign signs the account creation authorization message using the provided `signHash` function, and stores the signature in `a.Signature`. `signHash` should do an ethereum signature using the account corresponding to `a.EthAddr`. The `signHash` function is used to make signing flexible: in tests we sign directly using the private key, outside tests we sign using the keystore (which never exposes the private key). Sign follows the EIP-712 encoding.
func (*AccountCreationAuth) VerifySignature ¶
func (a *AccountCreationAuth) VerifySignature(chainID uint16, chainbingContractAddr ethCommon.Address) (bool, error)
VerifySignature ensures that the Signature is done with the EthAddr, for the chainID and chainbingContractAddress passed by parameter. VerifySignature follows the EIP-712 encoding.
type AccountUpdate ¶
type AccountUpdate struct { EthBlockNum int64 `meddler:"eth_block_num"` BatchNum BatchNum `meddler:"batch_num"` Idx Idx `meddler:"idx"` Nonce Nonce `meddler:"nonce"` Balance *big.Int `meddler:"balance,bigint"` }
AccountUpdate represents an account balance and/or nonce update after a processed batch
type AtomicGroup ¶
type AtomicGroup struct { ID AtomicGroupID `json:"atomicGroupId"` Txs []PoolL2Tx `json:"transactions"` }
AtomicGroup represents a set of atomic transactions
func (AtomicGroup) IsAtomicGroupIDValid ¶
func (ag AtomicGroup) IsAtomicGroupIDValid() bool
IsAtomicGroupIDValid return false if the atomic group ID that is set doesn't match with the calculated
func (*AtomicGroup) SetAtomicGroupID ¶
func (ag *AtomicGroup) SetAtomicGroupID()
SetAtomicGroupID set the atomic group ID for an atomic group that already has Txs
type AtomicGroupID ¶
type AtomicGroupID [AtomicGroupIDLen]byte
AtomicGroupID is the identifier of a Chainbing network atomic group
func CalculateAtomicGroupID ¶
func CalculateAtomicGroupID(txIDs []TxID) AtomicGroupID
CalculateAtomicGroupID calculates the atomic group ID given the identifiers of the transactions that conform the atomic group
func NewAtomicGroupIDFromString ¶
func NewAtomicGroupIDFromString(idStr string) (AtomicGroupID, error)
NewAtomicGroupIDFromString returns a string hexadecimal representation of the AtomicGroupID
func (AtomicGroupID) MarshalText ¶
func (agid AtomicGroupID) MarshalText() ([]byte, error)
MarshalText marshals a AtomicGroupID
func (*AtomicGroupID) Scan ¶
func (agid *AtomicGroupID) Scan(src interface{}) error
Scan implements Scanner for database/sql.
func (AtomicGroupID) String ¶
func (agid AtomicGroupID) String() string
String returns a string hexadecimal representation of the AtomicGroupID
func (*AtomicGroupID) UnmarshalText ¶
func (agid *AtomicGroupID) UnmarshalText(data []byte) error
UnmarshalText unmarshalls a AtomicGroupID
type AuctionConstants ¶
type AuctionConstants struct { // Blocks per slot BlocksPerSlot uint8 `json:"blocksPerSlot"` // Minimum bid when no one has bid yet InitialMinimalBidding *big.Int `json:"initialMinimalBidding"` // First block where the first slot begins GenesisBlockNum int64 `json:"genesisBlockNum"` // ERC777 token with which the bids will be made TokenCB ethCommon.Address `json:"tokenCB"` // ChainbingRollup smartcontract address ChainbingRollup ethCommon.Address `json:"chainbingRollup"` // Chainbing Governanze Token smartcontract address who controls some parameters and collects CB fee GovernanceAddress ethCommon.Address `json:"governanceAddress"` }
AuctionConstants are the constants of the Rollup Smart Contract
func (*AuctionConstants) RelativeBlock ¶
func (c *AuctionConstants) RelativeBlock(blockNum int64) int64
RelativeBlock returns the relative block number within the slot where the block number belongs
func (*AuctionConstants) SlotBlocks ¶
func (c *AuctionConstants) SlotBlocks(slotNum int64) (int64, int64)
SlotBlocks returns the first and the last block numbers included in that slot
func (*AuctionConstants) SlotNum ¶
func (c *AuctionConstants) SlotNum(blockNum int64) int64
SlotNum returns the slot number of a block number
type AuctionData ¶
type AuctionData struct { Bids []Bid Coordinators []Coordinator Vars *AuctionVariables }
AuctionData contains information returned by the Action smart contract
func NewAuctionData ¶
func NewAuctionData() AuctionData
NewAuctionData creates an empty AuctionData with the slices initialized.
type AuctionVariables ¶
type AuctionVariables struct { EthBlockNum int64 `meddler:"eth_block_num"` // Donation Address DonationAddress ethCommon.Address `meddler:"donation_address" validate:"required"` // Boot Coordinator Address BootCoordinator ethCommon.Address `meddler:"boot_coordinator" validate:"required"` // Boot Coordinator URL BootCoordinatorURL string `meddler:"boot_coordinator_url" validate:"required"` // The minimum bid value in a series of 6 slots DefaultSlotSetBid [6]*big.Int `meddler:"default_slot_set_bid,json" validate:"required"` // SlotNum at which the new default_slot_set_bid applies DefaultSlotSetBidSlotNum int64 `meddler:"default_slot_set_bid_slot_num"` // Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min ) ClosedAuctionSlots uint16 `meddler:"closed_auction_slots" validate:"required"` // Distance (#slots) to the farthest slot to which you can bid (30 days = 4320 slots ) OpenAuctionSlots uint16 `meddler:"open_auction_slots" validate:"required"` // How the CB tokens deposited by the slot winner are distributed (Burn: 40% - Donation: // 40% - HGT: 20%) AllocationRatio [3]uint16 `meddler:"allocation_ratio,json" validate:"required"` // Minimum outbid (percentage) over the previous one to consider it valid Outbidding uint16 `meddler:"outbidding" validate:"required"` // Number of blocks at the end of a slot in which any coordinator can forge if the winner // has not forged one before SlotDeadline uint8 `meddler:"slot_deadline" validate:"required"` }
AuctionVariables are the variables of the Auction Smart Contract
func (*AuctionVariables) Copy ¶
func (v *AuctionVariables) Copy() *AuctionVariables
Copy returns a deep copy of the Variables
type Batch ¶
type Batch struct { BatchNum BatchNum `meddler:"batch_num"` EthTxHash ethCommon.Hash `meddler:"eth_tx_hash"` // Ethereum block in which the batch is forged EthBlockNum int64 `meddler:"eth_block_num"` ForgerAddr ethCommon.Address `meddler:"forger_addr"` CollectedFees map[TokenID]*big.Int `meddler:"fees_collected,json"` FeeIdxsCoordinator []Idx `meddler:"fee_idxs_coordinator,json"` StateRoot *big.Int `meddler:"state_root,bigint"` NumAccounts int `meddler:"num_accounts"` LastIdx int64 `meddler:"last_idx"` ExitRoot *big.Int `meddler:"exit_root,bigint"` // ForgeL1TxsNum is optional, Only when the batch forges L1 txs. Identifier that corresponds // to the group of L1 txs forged in the current batch. ForgeL1TxsNum *int64 `meddler:"forge_l1_txs_num"` SlotNum int64 `meddler:"slot_num"` // Slot in which the batch is forged TotalFeesUSD *float64 `meddler:"total_fees_usd"` }
Batch is a struct that represents Chainbing network batch
type BatchData ¶
type BatchData struct { L1Batch bool // TODO: Remove once Batch.ForgeL1TxsNum is a pointer // L1UserTxs that were forged in the batch L1UserTxs []L1Tx L1CoordinatorTxs []L1Tx L2Txs []L2Tx CreatedAccounts []Account UpdatedAccounts []AccountUpdate ExitTree []ExitInfo Batch Batch }
BatchData contains the information of a Batch
func NewBatchData ¶
func NewBatchData() *BatchData
NewBatchData creates an empty BatchData with the slices initialized.
type BatchNum ¶
type BatchNum int64
BatchNum identifies a batch
func BatchNumFromBytes ¶
BatchNumFromBytes returns BatchNum from a []byte
type Bid ¶
type Bid struct { SlotNum int64 `meddler:"slot_num"` BidValue *big.Int `meddler:"bid_value,bigint"` EthBlockNum int64 `meddler:"eth_block_num"` Bidder ethCommon.Address `meddler:"bidder_addr"` // Coordinator reference }
Bid is a struct that represents one bid in the PoH
type BidCoordinator ¶
type BidCoordinator struct { SlotNum int64 `meddler:"slot_num"` DefaultSlotSetBid [6]*big.Int `meddler:"default_slot_set_bid,json"` BidValue *big.Int `meddler:"bid_value,bigint"` Bidder ethCommon.Address `meddler:"bidder_addr"` // address of the bidder Forger ethCommon.Address `meddler:"forger_addr"` // address of the forger URL string `meddler:"url"` // URL of the coordinators API }
BidCoordinator contains the coordinator info of a bid, along with the bid value
type Block ¶
type Block struct { Num int64 `meddler:"eth_block_num"` Timestamp time.Time `meddler:"timestamp,utctime"` Hash ethCommon.Hash `meddler:"hash"` ParentHash ethCommon.Hash `meddler:"-" json:"-"` }
Block represents of an Ethereum block
type BlockData ¶
type BlockData struct { Block Block Rollup RollupData Auction AuctionData WDelayer WDelayerData }
BlockData contains the information of a Block
type BucketParams ¶
type BucketParams struct { CeilUSD *big.Int BlockStamp *big.Int Withdrawals *big.Int RateBlocks *big.Int RateWithdrawals *big.Int MaxWithdrawals *big.Int }
BucketParams are the parameter variables of each Bucket of Rollup Smart Contract
type BucketUpdate ¶
type BucketUpdate struct { EthBlockNum int64 `meddler:"eth_block_num"` NumBucket int `meddler:"num_bucket"` BlockStamp int64 `meddler:"block_stamp"` Withdrawals *big.Int `meddler:"withdrawals,bigint"` }
BucketUpdate are the bucket updates (tracking the withdrawals value changes) in Rollup Smart Contract
type Coordinator ¶
type Coordinator struct { // Bidder is the address of the bidder Bidder ethCommon.Address `meddler:"bidder_addr"` // Forger is the address of the forger Forger ethCommon.Address `meddler:"forger_addr"` // EthBlockNum is the block in which the coordinator was registered EthBlockNum int64 `meddler:"eth_block_num"` // URL of the coordinators API URL string `meddler:"url"` }
Coordinator represents a Chainbing network coordinator who wins an auction for an specific slot WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot.
type ExitInfo ¶
type ExitInfo struct { BatchNum BatchNum `meddler:"batch_num"` AccountIdx Idx `meddler:"account_idx"` MerkleProof *merkletree.CircomVerifierProof `meddler:"merkle_proof,json"` Balance *big.Int `meddler:"balance,bigint"` // InstantWithdrawn is the ethBlockNum in which the exit is withdrawn // instantly. nil means this hasn't happened. InstantWithdrawn *int64 `meddler:"instant_withdrawn"` // DelayedWithdrawRequest is the ethBlockNum in which the exit is // requested to be withdrawn from the delayedWithdrawn smart contract. // nil means this hasn't happened. DelayedWithdrawRequest *int64 `meddler:"delayed_withdraw_request"` // DelayedWithdrawn is the ethBlockNum in which the exit is withdrawn // from the delayedWithdrawn smart contract. nil means this hasn't // happened. DelayedWithdrawn *int64 `meddler:"delayed_withdrawn"` }
ExitInfo represents the ExitTree Leaf data
type FeeSelector ¶
type FeeSelector uint8
FeeSelector is used to select a percentage from the FeePlan.
func (FeeSelector) Percentage ¶
func (f FeeSelector) Percentage() float64
Percentage returns the associated percentage of the FeeSelector
type Idx ¶
type Idx uint64
Idx represents the account Index in the MerkleTree
func IdxFromBigInt ¶
IdxFromBigInt converts a *big.Int to Idx type
func IdxFromBytes ¶
IdxFromBytes returns Idx from a byte array
type L2Tx ¶
type L2Tx struct { // Stored in DB: mandatory fields TxID TxID `meddler:"id"` BatchNum BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. Position int `meddler:"position"` FromIdx Idx `meddler:"from_idx"` ToIdx Idx `meddler:"to_idx"` // TokenID is filled by the TxProcessor TokenID TokenID `meddler:"token_id"` Amount *big.Int `meddler:"amount,bigint"` Fee FeeSelector `meddler:"fee"` // Nonce is filled by the TxProcessor Nonce Nonce `meddler:"nonce"` Type TxType `meddler:"type"` // EthBlockNum in which this L2Tx was added to the queue EthBlockNum int64 `meddler:"eth_block_num"` }
L2Tx is a struct that represents an already forged L2 tx
func L2TxFromBytesDataAvailability ¶
L2TxFromBytesDataAvailability decodes a L2Tx from []byte (Data Availability)
func NewL2Tx ¶
NewL2Tx returns the given L2Tx with the TxId & Type parameters calculated from the L2Tx values
func (L2Tx) BytesDataAvailability ¶
BytesDataAvailability encodes a L2Tx into []byte for the Data Availability [ fromIdx | toIdx | amountFloat40 | Fee ]
func (L2Tx) CalculateTxID ¶
CalculateTxID returns the TxID of the transaction. This method is used to set the TxID for L2Tx and for PoolL2Tx.
func (L2Tx) PoolL2Tx ¶
func (tx L2Tx) PoolL2Tx() *PoolL2Tx
PoolL2Tx returns the data structure of PoolL2Tx with the parameters of a L2Tx filled
type Nonce ¶
type Nonce uint64
Nonce represents the nonce value in a uint64, which has the method Bytes that returns a byte array of length 5 (40 bits).
func NonceFromBytes ¶
NonceFromBytes returns Nonce from a [5]byte
type QueryAccount ¶
QueryAccount is a representation of an account with accountIndex and its token symbol
func StringToIdx ¶
func StringToIdx(idxStr, name string) (QueryAccount, error)
StringToIdx converts string to account index
type RecommendedFee ¶
type RecommendedFee struct { ExistingAccount float64 `json:"existingAccount"` CreatesAccount float64 `json:"createAccount"` CreatesAccountInternal float64 `json:"createAccountInternal"` }
RecommendedFee is the recommended fee to pay in USD per transaction set by the coordinator according to the tx type (if the tx requires to create an account and register, only register or he account already esists)
type RollupConstants ¶
type RollupConstants struct { AbsoluteMaxL1L2BatchTimeout int64 `json:"absoluteMaxL1L2BatchTimeout"` TokenCB ethCommon.Address `json:"tokenCB"` Verifiers []RollupVerifierStruct `json:"verifiers"` ChainbingAuctionContract ethCommon.Address `json:"chainbingAuctionContract"` ChainbingGovernanceAddress ethCommon.Address `json:"chainbingGovernanceAddress"` WithdrawDelayerContract ethCommon.Address `json:"withdrawDelayerContract"` }
RollupConstants are the constants of the Rollup Smart Contract
func (*RollupConstants) FindVerifierIdx ¶
func (c *RollupConstants) FindVerifierIdx(MaxTx, NLevels int64) (int, error)
FindVerifierIdx tries to find a matching verifier in the RollupConstants and returns its index
type RollupData ¶
type RollupData struct { // L1UserTxs that were submitted in the block L1UserTxs []L1Tx Batches []BatchData AddedTokens []Token Withdrawals []WithdrawInfo UpdateBucketWithdraw []BucketUpdate TokenExchanges []TokenExchange Vars *RollupVariables }
RollupData contains information returned by the Rollup smart contract
func NewRollupData ¶
func NewRollupData() RollupData
NewRollupData creates an empty RollupData with the slices initialized.
type RollupVariables ¶
type RollupVariables struct { EthBlockNum int64 `meddler:"eth_block_num"` FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"` ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"` WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"` Buckets []BucketParams `meddler:"buckets,json"` SafeMode bool `meddler:"safe_mode"` }
RollupVariables are the variables of the Rollup Smart Contract
func (*RollupVariables) Copy ¶
func (v *RollupVariables) Copy() *RollupVariables
Copy returns a deep copy of the Variables
type RollupVerifierStruct ¶
RollupVerifierStruct is the information about verifiers of the Rollup Smart Contract
type SCConsts ¶
type SCConsts struct { Rollup RollupConstants Auction AuctionConstants WDelayer WDelayerConstants }
SCConsts joins all the smart contract constants in a single struct
type SCVariables ¶
type SCVariables struct { Rollup RollupVariables `validate:"required"` Auction AuctionVariables `validate:"required"` WDelayer WDelayerVariables `validate:"required"` }
SCVariables joins all the smart contract variables in a single struct
func (*SCVariables) AsPtr ¶
func (v *SCVariables) AsPtr() *SCVariablesPtr
AsPtr returns the SCVariables as a SCVariablesPtr using pointers to the original SCVariables
type SCVariablesPtr ¶
type SCVariablesPtr struct { Rollup *RollupVariables `validate:"required"` Auction *AuctionVariables `validate:"required"` WDelayer *WDelayerVariables `validate:"required"` }
SCVariablesPtr joins all the smart contract variables as pointers in a single struct
type Slot ¶
type Slot struct { SlotNum int64 DefaultSlotBid *big.Int StartBlock int64 EndBlock int64 ForgerCommitment bool // BatchesLen int BidValue *big.Int BootCoord bool // Bidder, Forger and URL correspond to the winner of the slot (which is // not always the highest bidder). These are the values of the // coordinator that is able to forge exclusively before the deadline. Bidder ethCommon.Address Forger ethCommon.Address URL string }
Slot contains relevant information of a slot
type StrBigInt ¶
StrBigInt is used to unmarshal BigIntStr directly into an alias of big.Int
func (*StrBigInt) UnmarshalText ¶
UnmarshalText unmarshals a StrBigInt
type StrCbBJJ ¶
type StrCbBJJ babyjub.PublicKeyComp
StrCbBJJ is used to unmarshal CbBJJ directly into an alias of babyjub.PublicKeyComp
func (*StrCbBJJ) UnmarshalText ¶
UnmarshalText unmarshalls a StrCbBJJ
type StrCbEthAddr ¶
StrCbEthAddr is used to unmarshal CbEthAddr directly into an alias of ethCommon.Address
func (*StrCbEthAddr) UnmarshalText ¶
func (s *StrCbEthAddr) UnmarshalText(text []byte) error
UnmarshalText unmarshals a StrCbEthAddr
type StrCbIdx ¶
StrCbIdx is used to unmarshal CbIdx directly into an alias of Idx
func (*StrCbIdx) UnmarshalText ¶
UnmarshalText unmarshals a StrCbIdx
type TokenExchange ¶
type TokenExchange struct { EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` Address ethCommon.Address `json:"address" meddler:"eth_addr"` ValueUSD int64 `json:"valueUSD" meddler:"value_usd"` }
TokenExchange are the exchange value for tokens registered in the Rollup Smart Contract
type WDelayerData ¶
type WDelayerData struct { Vars *WDelayerVariables Deposits []WDelayerTransfer // We use an array because there can be multiple deposits in a single eth transaction DepositsByTxHash map[ethCommon.Hash][]*WDelayerTransfer Withdrawals []WDelayerTransfer EscapeHatchWithdrawals []WDelayerEscapeHatchWithdrawal }
WDelayerData contains information returned by the WDelayer smart contract
func NewWDelayerData ¶
func NewWDelayerData() WDelayerData
NewWDelayerData creates an empty WDelayerData.
type WDelayerTransfer ¶
WDelayerTransfer represents a transfer (either deposit or withdrawal) in the WDelayer smart contract