mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #329 from hermeznetwork/feature/deposit-amount
Rename load amount to deposit amount
This commit is contained in:
@@ -13,7 +13,7 @@ type rollupConstants struct {
|
||||
MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"`
|
||||
ReservedIdx int `json:"reservedIdx"`
|
||||
ExitIdx int `json:"exitIdx"`
|
||||
LimitLoadAmount *big.Int `json:"limitLoadAmount"`
|
||||
LimitDepositAmount *big.Int `json:"limitDepositAmount"`
|
||||
LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"`
|
||||
LimitTokens int `json:"limitTokens"`
|
||||
L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"`
|
||||
@@ -32,7 +32,7 @@ func newRollupConstants(publicConstants common.RollupConstants) *rollupConstants
|
||||
MaxFeeIdxCoordinator: common.RollupConstMaxFeeIdxCoordinator,
|
||||
ReservedIdx: common.RollupConstReservedIDx,
|
||||
ExitIdx: common.RollupConstExitIDx,
|
||||
LimitLoadAmount: common.RollupConstLimitLoadAmount,
|
||||
LimitDepositAmount: common.RollupConstLimitDepositAmount,
|
||||
LimitL2TransferAmount: common.RollupConstLimitL2TransferAmount,
|
||||
LimitTokens: common.RollupConstLimitTokens,
|
||||
L1CoordinatorTotalBytes: common.RollupConstL1CoordinatorTotalBytes,
|
||||
|
||||
@@ -1745,12 +1745,12 @@ components:
|
||||
userOrigin:
|
||||
type: boolean
|
||||
description: True if the transaction was sent by a user. False if it was sent by a coordinator.
|
||||
loadAmount:
|
||||
depositAmount:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/BigInt'
|
||||
- description: Tokens transfered from L1 to L2.
|
||||
- example: "4900000000000000000"
|
||||
historicLoadAmountUSD:
|
||||
historicDepositAmountUSD:
|
||||
type: number
|
||||
description: Load amount in USD, at the moment the transaction was made.
|
||||
example: 3.897
|
||||
@@ -1763,8 +1763,8 @@ components:
|
||||
required:
|
||||
- toForgeL1TransactionsNum
|
||||
- userOrigin
|
||||
- loadAmount
|
||||
- historicLoadAmountUSD
|
||||
- depositAmount
|
||||
- historicDepositAmountUSD
|
||||
- ethereumBlockNum
|
||||
additionalProperties: false
|
||||
L2Info:
|
||||
@@ -1790,8 +1790,8 @@ components:
|
||||
example:
|
||||
L1Info:
|
||||
ethereumBlockNum: 1
|
||||
historicLoadAmountUSD: 232.47
|
||||
loadAmount: '261'
|
||||
historicDepositAmountUSD: 232.47
|
||||
depositAmount: '261'
|
||||
toForgeL1TransactionsNum: 10
|
||||
userOrigin: true
|
||||
L1orL2: L1
|
||||
@@ -1854,8 +1854,8 @@ components:
|
||||
transactions:
|
||||
- L1Info:
|
||||
ethereumBlockNum: 3
|
||||
historicLoadAmountUSD:
|
||||
loadAmount: '0'
|
||||
historicDepositAmountUSD:
|
||||
depositAmount: '0'
|
||||
toForgeL1TransactionsNum: 7
|
||||
userOrigin: true
|
||||
L1orL2: L1
|
||||
@@ -1946,8 +1946,8 @@ components:
|
||||
type: Exit
|
||||
- L1Info:
|
||||
ethereumBlockNum: 3
|
||||
historicLoadAmountUSD: 14099.9999859
|
||||
loadAmount: '33333333300000000000'
|
||||
historicDepositAmountUSD: 14099.9999859
|
||||
depositAmount: '33333333300000000000'
|
||||
toForgeL1TransactionsNum: 2
|
||||
userOrigin: true
|
||||
L1orL2: L1
|
||||
@@ -2480,7 +2480,7 @@ components:
|
||||
example:
|
||||
accounts:
|
||||
- accountIndex: hez:ETH:259
|
||||
balance: '2590000000'
|
||||
balance: '2590000000000000000'
|
||||
bjj: hez:W6x4TZOAZ9mAqdOb3Xm_hKDLspaXfEfMMN4tXOkinS-W
|
||||
hezEthereumAddress: hez:0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
|
||||
itemId: 4
|
||||
@@ -2954,7 +2954,7 @@ components:
|
||||
type: integer
|
||||
description: Account index used to indicate that a transaction is an `exit` or `force exit`.
|
||||
example: 1
|
||||
limitLoadAmount:
|
||||
limitDepositAmount:
|
||||
type: integer
|
||||
description: Maximum load amount (L1 to L2) allowed.
|
||||
example: 321
|
||||
@@ -2972,7 +2972,7 @@ components:
|
||||
example: 101
|
||||
l1UserTotalBytes:
|
||||
type: integer
|
||||
description: Number of bytes that a L1 user transaction has ([20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx + [2 bytes] loadAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx).
|
||||
description: Number of bytes that a L1 user transaction has ([20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx + [2 bytes] depositAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx).
|
||||
example: 72
|
||||
maxL1UserTx:
|
||||
type: integer
|
||||
@@ -3002,7 +3002,7 @@ components:
|
||||
- publicConstants
|
||||
- reservedIdx
|
||||
- exitIdx
|
||||
- limitLoadAmount
|
||||
- limitDepositAmount
|
||||
- limitL2TransferAmount
|
||||
- limitTokens
|
||||
- l1CoordinatorTotalBytes
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
type testL1Info struct {
|
||||
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
|
||||
UserOrigin bool `json:"userOrigin"`
|
||||
LoadAmount string `json:"loadAmount"`
|
||||
HistoricLoadAmountUSD *float64 `json:"historicLoadAmountUSD"`
|
||||
DepositAmount string `json:"depositAmount"`
|
||||
HistoricDepositAmountUSD *float64 `json:"historicDepositAmountUSD"`
|
||||
EthBlockNum int64 `json:"ethereumBlockNum"`
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func genTestTxs(
|
||||
L1Info: &testL1Info{
|
||||
ToForgeL1TxsNum: l1.ToForgeL1TxsNum,
|
||||
UserOrigin: l1.UserOrigin,
|
||||
LoadAmount: l1.LoadAmount.String(),
|
||||
DepositAmount: l1.DepositAmount.String(),
|
||||
EthBlockNum: l1.EthBlockNum,
|
||||
},
|
||||
Token: token,
|
||||
@@ -160,11 +160,11 @@ func genTestTxs(
|
||||
if usd != 0 {
|
||||
tx.HistoricUSD = &usd
|
||||
}
|
||||
laf := new(big.Float).SetInt(l1.LoadAmount)
|
||||
loadAmountFloat, _ := laf.Float64()
|
||||
loadUSD := *token.USD * loadAmountFloat / math.Pow(10, float64(token.Decimals))
|
||||
if loadAmountFloat != 0 {
|
||||
tx.L1Info.HistoricLoadAmountUSD = &loadUSD
|
||||
laf := new(big.Float).SetInt(l1.DepositAmount)
|
||||
depositAmountFloat, _ := laf.Float64()
|
||||
loadUSD := *token.USD * depositAmountFloat / math.Pow(10, float64(token.Decimals))
|
||||
if depositAmountFloat != 0 {
|
||||
tx.L1Info.HistoricDepositAmountUSD = &loadUSD
|
||||
}
|
||||
}
|
||||
txs = append(txs, tx)
|
||||
@@ -474,7 +474,7 @@ func assertTxs(t *testing.T, expected, actual []testTx) {
|
||||
if expected[i].L2Info != nil {
|
||||
test.AssertUSD(t, expected[i].L2Info.HistoricFeeUSD, actual[i].L2Info.HistoricFeeUSD)
|
||||
} else {
|
||||
test.AssertUSD(t, expected[i].L1Info.HistoricLoadAmountUSD, actual[i].L1Info.HistoricLoadAmountUSD)
|
||||
test.AssertUSD(t, expected[i].L1Info.HistoricDepositAmountUSD, actual[i].L1Info.HistoricDepositAmountUSD)
|
||||
}
|
||||
assert.Equal(t, expected[i], actual[i])
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ const (
|
||||
// RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature
|
||||
RollupConstL1CoordinatorTotalBytes = 101
|
||||
// RollupConstL1UserTotalBytes [20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx +
|
||||
// [2 bytes] loadAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx
|
||||
// [2 bytes] depositAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx
|
||||
RollupConstL1UserTotalBytes = 72
|
||||
// RollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch
|
||||
RollupConstMaxL1UserTx = 128
|
||||
@@ -87,8 +87,8 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// RollupConstLimitLoadAmount Max load amount allowed (loadAmount: L1 --> L2)
|
||||
RollupConstLimitLoadAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10)
|
||||
// RollupConstLimitDepositAmount Max load 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)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ type L1Tx struct {
|
||||
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
|
||||
Position int `meddler:"position"`
|
||||
UserOrigin bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
|
||||
FromIdx Idx `meddler:"from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
FromIdx Idx `meddler:"from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.DepositAmount (deposit)
|
||||
FromEthAddr ethCommon.Address `meddler:"from_eth_addr,zeroisnull"`
|
||||
FromBJJ *babyjub.PublicKey `meddler:"from_bjj,zeroisnull"`
|
||||
ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
|
||||
@@ -40,9 +40,9 @@ type L1Tx struct {
|
||||
Amount *big.Int `meddler:"amount,bigint"`
|
||||
// EffectiveAmount only applies to L1UserTx.
|
||||
EffectiveAmount *big.Int `meddler:"effective_amount,bigintnull"`
|
||||
LoadAmount *big.Int `meddler:"load_amount,bigint"`
|
||||
// EffectiveLoadAmount only applies to L1UserTx.
|
||||
EffectiveLoadAmount *big.Int `meddler:"effective_load_amount,bigintnull"`
|
||||
DepositAmount *big.Int `meddler:"deposit_amount,bigint"`
|
||||
// EffectiveDepositAmount only applies to L1UserTx.
|
||||
EffectiveDepositAmount *big.Int `meddler:"effective_deposit_amount,bigintnull"`
|
||||
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
Type TxType `meddler:"type"`
|
||||
BatchNum *BatchNum `meddler:"batch_num"`
|
||||
@@ -67,7 +67,7 @@ func NewL1Tx(l1Tx *L1Tx) (*L1Tx, error) {
|
||||
} else if l1Tx.ToIdx == Idx(1) {
|
||||
txType = TxTypeForceExit
|
||||
} else if l1Tx.ToIdx >= IdxUserThreshold {
|
||||
if l1Tx.LoadAmount.Int64() == int64(0) {
|
||||
if l1Tx.DepositAmount.Int64() == int64(0) {
|
||||
txType = TxTypeForceTransfer
|
||||
} else {
|
||||
txType = TxTypeDepositTransfer
|
||||
@@ -140,13 +140,13 @@ func (tx L1Tx) Tx() Tx {
|
||||
UserOrigin: userOrigin,
|
||||
FromEthAddr: tx.FromEthAddr,
|
||||
FromBJJ: tx.FromBJJ,
|
||||
LoadAmount: tx.EffectiveLoadAmount,
|
||||
DepositAmount: tx.EffectiveDepositAmount,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
}
|
||||
if tx.LoadAmount != nil {
|
||||
lf := new(big.Float).SetInt(tx.LoadAmount)
|
||||
loadAmountFloat, _ := lf.Float64()
|
||||
genericTx.LoadAmountFloat = &loadAmountFloat
|
||||
if tx.DepositAmount != nil {
|
||||
lf := new(big.Float).SetInt(tx.DepositAmount)
|
||||
depositAmountFloat, _ := lf.Float64()
|
||||
genericTx.DepositAmountFloat = &depositAmountFloat
|
||||
}
|
||||
return genericTx
|
||||
}
|
||||
@@ -257,11 +257,11 @@ func (tx *L1Tx) BytesGeneric() ([]byte, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[52:58], fromIdxBytes[:])
|
||||
loadAmountFloat16, err := NewFloat16(tx.LoadAmount)
|
||||
depositAmountFloat16, err := NewFloat16(tx.DepositAmount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[58:60], loadAmountFloat16.Bytes())
|
||||
copy(b[58:60], depositAmountFloat16.Bytes())
|
||||
amountFloat16, err := NewFloat16(tx.Amount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
@@ -328,7 +328,7 @@ func L1UserTxFromBytes(b []byte) (*L1Tx, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
tx.FromIdx = fromIdx
|
||||
tx.LoadAmount = Float16FromBytes(b[58:60]).BigInt()
|
||||
tx.DepositAmount = Float16FromBytes(b[58:60]).BigInt()
|
||||
tx.Amount = Float16FromBytes(b[60:62]).BigInt()
|
||||
tx.TokenID, err = TokenIDFromBytes(b[62:66])
|
||||
if err != nil {
|
||||
@@ -375,7 +375,7 @@ func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, hermezAddress ethCommo
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
tx.Amount = big.NewInt(0)
|
||||
tx.LoadAmount = big.NewInt(0)
|
||||
tx.DepositAmount = big.NewInt(0)
|
||||
if int(v) > 0 {
|
||||
// L1CoordinatorTX ETH
|
||||
// Ethereum adds 27 to v
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestNewL1UserTx(t *testing.T) {
|
||||
ToIdx: 301,
|
||||
TokenID: 5,
|
||||
Amount: big.NewInt(1),
|
||||
LoadAmount: big.NewInt(2),
|
||||
DepositAmount: big.NewInt(2),
|
||||
FromIdx: Idx(300),
|
||||
}
|
||||
l1Tx, err := NewL1Tx(l1Tx)
|
||||
@@ -40,7 +40,7 @@ func TestNewL1CoordinatorTx(t *testing.T) {
|
||||
ToIdx: 301,
|
||||
TokenID: 5,
|
||||
Amount: big.NewInt(1),
|
||||
LoadAmount: big.NewInt(2),
|
||||
DepositAmount: big.NewInt(2),
|
||||
FromIdx: Idx(300),
|
||||
BatchNum: &batchNum,
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func TestL1userTxByteParsers(t *testing.T) {
|
||||
ToIdx: 3,
|
||||
TokenID: 5,
|
||||
Amount: big.NewInt(1),
|
||||
LoadAmount: big.NewInt(2),
|
||||
DepositAmount: big.NewInt(2),
|
||||
FromIdx: 2,
|
||||
FromBJJ: pk,
|
||||
FromEthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
|
||||
@@ -164,13 +164,13 @@ func TestL1TxByteParsersCompatibility(t *testing.T) {
|
||||
pk, err := pkComp.Decompress()
|
||||
require.Nil(t, err)
|
||||
|
||||
loadAmount := new(big.Int)
|
||||
loadAmount.SetString("100000000000000000000", 10)
|
||||
depositAmount := new(big.Int)
|
||||
depositAmount.SetString("100000000000000000000", 10)
|
||||
l1Tx := &L1Tx{
|
||||
ToIdx: 87865485,
|
||||
TokenID: 2098076,
|
||||
Amount: big.NewInt(2400000000000000000),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
FromIdx: Idx(29767899),
|
||||
FromBJJ: pk,
|
||||
FromEthAddr: ethCommon.HexToAddress("0x85dab5b9e2e361d0c208d77be90efcc0439b0a53"),
|
||||
@@ -231,7 +231,7 @@ func TestL1CoordinatorTxByteParsers(t *testing.T) {
|
||||
FromBJJ: pk,
|
||||
FromEthAddr: fromEthAddr,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
}
|
||||
|
||||
bytesCoordinatorL1, err := l1Tx.BytesCoordinatorTx(signature)
|
||||
|
||||
@@ -33,8 +33,8 @@ type PoolL2Tx struct {
|
||||
Signature babyjub.SignatureComp `meddler:"signature"` // tx signature
|
||||
Timestamp time.Time `meddler:"timestamp,utctime"` // time when added to the tx pool
|
||||
// Stored in DB: optional fileds, may be uninitialized
|
||||
RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.DepositAmount (deposit)
|
||||
RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.DepositAmount (deposit)
|
||||
RqToEthAddr ethCommon.Address `meddler:"rq_to_eth_addr,zeroisnull"`
|
||||
RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
|
||||
RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"`
|
||||
|
||||
10
common/tx.go
10
common/tx.go
@@ -144,9 +144,9 @@ type Tx struct {
|
||||
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
|
||||
FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
|
||||
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
|
||||
LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
|
||||
LoadAmountFloat *float64 `meddler:"load_amount_f"`
|
||||
LoadAmountUSD *float64 `meddler:"load_amount_usd"`
|
||||
DepositAmount *big.Int `meddler:"deposit_amount,bigintnull"`
|
||||
DepositAmountFloat *float64 `meddler:"deposit_amount_f"`
|
||||
DepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
|
||||
// L2
|
||||
Fee *FeeSelector `meddler:"fee"`
|
||||
FeeUSD *float64 `meddler:"fee_usd"`
|
||||
@@ -165,7 +165,7 @@ func (tx *Tx) String() string {
|
||||
if tx.Type == TxTypeDeposit ||
|
||||
tx.Type == TxTypeDepositTransfer ||
|
||||
tx.Type == TxTypeCreateAccountDepositTransfer {
|
||||
fmt.Fprintf(buf, "LoadAmount: %d, ", tx.LoadAmount)
|
||||
fmt.Fprintf(buf, "DepositAmount: %d, ", tx.DepositAmount)
|
||||
}
|
||||
if tx.Type != TxTypeDeposit {
|
||||
fmt.Fprintf(buf, "Amount: %s, ", tx.Amount)
|
||||
@@ -193,7 +193,7 @@ func (tx *Tx) L1Tx() (*L1Tx, error) {
|
||||
ToIdx: tx.ToIdx,
|
||||
TokenID: tx.TokenID,
|
||||
Amount: tx.Amount,
|
||||
LoadAmount: tx.LoadAmount,
|
||||
DepositAmount: tx.DepositAmount,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
Type: tx.Type,
|
||||
BatchNum: tx.BatchNum,
|
||||
|
||||
@@ -106,8 +106,8 @@ type ZKInputs struct {
|
||||
//
|
||||
// NewAccount boolean (0/1) flag set 'true' when L1 tx creates a new account (fromIdx==0)
|
||||
NewAccount []*big.Int `json:"newAccount"` // bool, len: [nTx]
|
||||
// LoadAmountF encoded as float16
|
||||
LoadAmountF []*big.Int `json:"loadAmountF"` // uint16, len: [nTx]
|
||||
// DepositAmountF encoded as float16
|
||||
DepositAmountF []*big.Int `json:"loadAmountF"` // uint16, len: [nTx]
|
||||
// FromEthAddr
|
||||
FromEthAddr []*big.Int `json:"fromEthAddr"` // ethCommon.Address, len: [nTx]
|
||||
// FromBJJCompressed boolean encoded where each value is a *big.Int
|
||||
@@ -310,7 +310,7 @@ func NewZKInputs(nTx, maxL1Tx, maxTx, maxFeeIdxs, nLevels uint32, currentNumBatc
|
||||
zki.NewAccount = newSlice(nTx)
|
||||
|
||||
// L1
|
||||
zki.LoadAmountF = newSlice(nTx)
|
||||
zki.DepositAmountF = newSlice(nTx)
|
||||
zki.FromEthAddr = newSlice(nTx)
|
||||
zki.FromBJJCompressed = make([][256]*big.Int, nTx)
|
||||
for i := 0; i < len(zki.FromBJJCompressed); i++ {
|
||||
|
||||
@@ -767,23 +767,23 @@ func (hdb *HistoryDB) GetAllAccounts() ([]common.Account, error) {
|
||||
return db.SlicePtrsToSlice(accs).([]common.Account), tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
// AddL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx.
|
||||
// AddL1Txs inserts L1 txs to the DB. USD and DepositAmountUSD will be set automatically before storing the tx.
|
||||
// If the tx is originated by a coordinator, BatchNum must be provided. If it's originated by a user,
|
||||
// BatchNum should be null, and the value will be setted by a trigger when a batch forges the tx.
|
||||
// EffectiveAmount and EffectiveLoadAmount are seted with default values by the DB.
|
||||
// EffectiveAmount and EffectiveDepositAmount are seted with default values by the DB.
|
||||
func (hdb *HistoryDB) AddL1Txs(l1txs []common.L1Tx) error { return hdb.addL1Txs(hdb.db, l1txs) }
|
||||
|
||||
// addL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx.
|
||||
// addL1Txs inserts L1 txs to the DB. USD and DepositAmountUSD will be set automatically before storing the tx.
|
||||
// If the tx is originated by a coordinator, BatchNum must be provided. If it's originated by a user,
|
||||
// BatchNum should be null, and the value will be setted by a trigger when a batch forges the tx.
|
||||
// EffectiveAmount and EffectiveLoadAmount are seted with default values by the DB.
|
||||
// EffectiveAmount and EffectiveDepositAmount are seted with default values by the DB.
|
||||
func (hdb *HistoryDB) addL1Txs(d meddler.DB, l1txs []common.L1Tx) error {
|
||||
txs := []txWrite{}
|
||||
for i := 0; i < len(l1txs); i++ {
|
||||
af := new(big.Float).SetInt(l1txs[i].Amount)
|
||||
amountFloat, _ := af.Float64()
|
||||
laf := new(big.Float).SetInt(l1txs[i].LoadAmount)
|
||||
loadAmountFloat, _ := laf.Float64()
|
||||
laf := new(big.Float).SetInt(l1txs[i].DepositAmount)
|
||||
depositAmountFloat, _ := laf.Float64()
|
||||
txs = append(txs, txWrite{
|
||||
// Generic
|
||||
IsL1: true,
|
||||
@@ -802,8 +802,8 @@ func (hdb *HistoryDB) addL1Txs(d meddler.DB, l1txs []common.L1Tx) error {
|
||||
UserOrigin: &l1txs[i].UserOrigin,
|
||||
FromEthAddr: &l1txs[i].FromEthAddr,
|
||||
FromBJJ: l1txs[i].FromBJJ,
|
||||
LoadAmount: l1txs[i].LoadAmount,
|
||||
LoadAmountFloat: &loadAmountFloat,
|
||||
DepositAmount: l1txs[i].DepositAmount,
|
||||
DepositAmountFloat: &depositAmountFloat,
|
||||
})
|
||||
}
|
||||
return hdb.addTxs(d, txs)
|
||||
@@ -857,8 +857,8 @@ func (hdb *HistoryDB) addTxs(d meddler.DB, txs []txWrite) error {
|
||||
user_origin,
|
||||
from_eth_addr,
|
||||
from_bjj,
|
||||
load_amount,
|
||||
load_amount_f,
|
||||
deposit_amount,
|
||||
deposit_amount_f,
|
||||
fee,
|
||||
nonce
|
||||
) VALUES %s;`,
|
||||
@@ -887,7 +887,7 @@ func (hdb *HistoryDB) GetHistoryTx(txID common.TxID) (*TxAPI, error) {
|
||||
hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj,
|
||||
tx.amount, tx.token_id, tx.amount_usd,
|
||||
tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin,
|
||||
tx.load_amount, tx.load_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
|
||||
tx.deposit_amount, tx.deposit_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
|
||||
token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block,
|
||||
token.eth_addr, token.name, token.symbol, token.decimals, token.usd,
|
||||
token.usd_update, block.timestamp
|
||||
@@ -916,7 +916,7 @@ func (hdb *HistoryDB) GetHistoryTxs(
|
||||
hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj,
|
||||
tx.amount, tx.token_id, tx.amount_usd,
|
||||
tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin,
|
||||
tx.load_amount, tx.load_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
|
||||
tx.deposit_amount, tx.deposit_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
|
||||
token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block,
|
||||
token.eth_addr, token.name, token.symbol, token.decimals, token.usd,
|
||||
token.usd_update, block.timestamp, count(*) OVER() AS total_items
|
||||
@@ -1169,7 +1169,7 @@ func (hdb *HistoryDB) GetAllL1UserTxs() ([]common.L1Tx, error) {
|
||||
`SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin,
|
||||
tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id,
|
||||
tx.amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.amount_success THEN tx.amount ELSE '\x' END) AS effective_amount,
|
||||
tx.load_amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.load_amount_success THEN tx.load_amount ELSE '\x' END) AS effective_load_amount,
|
||||
tx.deposit_amount, (CASE WHEN tx.batch_num IS NULL THEN NULL WHEN tx.deposit_amount_success THEN tx.deposit_amount ELSE '\x' END) AS effective_deposit_amount,
|
||||
tx.eth_block_num, tx.type, tx.batch_num
|
||||
FROM tx WHERE is_l1 = TRUE AND user_origin = TRUE;`,
|
||||
)
|
||||
@@ -1186,7 +1186,7 @@ func (hdb *HistoryDB) GetAllL1CoordinatorTxs() ([]common.L1Tx, error) {
|
||||
`SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin,
|
||||
tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id,
|
||||
tx.amount, tx.amount AS effective_amount,
|
||||
tx.load_amount, tx.load_amount AS effective_load_amount,
|
||||
tx.deposit_amount, tx.deposit_amount AS effective_deposit_amount,
|
||||
tx.eth_block_num, tx.type, tx.batch_num
|
||||
FROM tx WHERE is_l1 = TRUE AND user_origin = FALSE;`,
|
||||
)
|
||||
@@ -1214,7 +1214,7 @@ func (hdb *HistoryDB) GetUnforgedL1UserTxs(toForgeL1TxsNum int64) ([]common.L1Tx
|
||||
`SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin,
|
||||
tx.from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, tx.token_id,
|
||||
tx.amount, NULL AS effective_amount,
|
||||
tx.load_amount, NULL AS effective_load_amount,
|
||||
tx.deposit_amount, NULL AS effective_deposit_amount,
|
||||
tx.eth_block_num, tx.type, tx.batch_num
|
||||
FROM tx WHERE batch_num IS NULL AND to_forge_l1_txs_num = $1;`,
|
||||
toForgeL1TxsNum,
|
||||
@@ -1298,7 +1298,7 @@ func (hdb *HistoryDB) SetInitialSCVars(rollup *common.RollupVariables,
|
||||
return tracerr.Wrap(txn.Commit())
|
||||
}
|
||||
|
||||
// setL1UserTxEffectiveAmounts sets the EffectiveAmount and EffectiveLoadAmount
|
||||
// setL1UserTxEffectiveAmounts sets the EffectiveAmount and EffectiveDepositAmount
|
||||
// of the given l1UserTxs (with an UPDATE)
|
||||
func (hdb *HistoryDB) setL1UserTxEffectiveAmounts(d sqlx.Ext, txs []common.L1Tx) error {
|
||||
// Effective amounts are stored as success flags in the DB, with true value by default
|
||||
@@ -1307,7 +1307,7 @@ func (hdb *HistoryDB) setL1UserTxEffectiveAmounts(d sqlx.Ext, txs []common.L1Tx)
|
||||
type txUpdate struct {
|
||||
ID common.TxID `db:"id"`
|
||||
AmountSuccess bool `db:"amount_success"`
|
||||
LoadAmountSuccess bool `db:"load_amount_success"`
|
||||
DepositAmountSuccess bool `db:"deposit_amount_success"`
|
||||
}
|
||||
txUpdates := []txUpdate{}
|
||||
equal := func(a *big.Int, b *big.Int) bool {
|
||||
@@ -1315,23 +1315,23 @@ func (hdb *HistoryDB) setL1UserTxEffectiveAmounts(d sqlx.Ext, txs []common.L1Tx)
|
||||
}
|
||||
for i := range txs {
|
||||
amountSuccess := equal(txs[i].Amount, txs[i].EffectiveAmount)
|
||||
loadAmountSuccess := equal(txs[i].LoadAmount, txs[i].EffectiveLoadAmount)
|
||||
if !amountSuccess || !loadAmountSuccess {
|
||||
depositAmountSuccess := equal(txs[i].DepositAmount, txs[i].EffectiveDepositAmount)
|
||||
if !amountSuccess || !depositAmountSuccess {
|
||||
txUpdates = append(txUpdates, txUpdate{
|
||||
ID: txs[i].TxID,
|
||||
AmountSuccess: amountSuccess,
|
||||
LoadAmountSuccess: loadAmountSuccess,
|
||||
DepositAmountSuccess: depositAmountSuccess,
|
||||
})
|
||||
}
|
||||
}
|
||||
const query string = `
|
||||
UPDATE tx SET
|
||||
amount_success = tx_update.amount_success,
|
||||
load_amount_success = tx_update.load_amount_success
|
||||
deposit_amount_success = tx_update.deposit_amount_success
|
||||
FROM (VALUES
|
||||
(NULL::::BYTEA, NULL::::BOOL, NULL::::BOOL),
|
||||
(:id, :amount_success, :load_amount_success)
|
||||
) as tx_update (id, amount_success, load_amount_success)
|
||||
(:id, :amount_success, :deposit_amount_success)
|
||||
) as tx_update (id, amount_success, deposit_amount_success)
|
||||
WHERE tx.id = tx_update.id
|
||||
`
|
||||
if len(txUpdates) > 0 {
|
||||
@@ -1414,7 +1414,7 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) {
|
||||
for i := range blockData.Rollup.Batches {
|
||||
batch := &blockData.Rollup.Batches[i]
|
||||
|
||||
// Set the EffectiveAmount and EffectiveLoadAmount of all the
|
||||
// Set the EffectiveAmount and EffectiveDepositAmount of all the
|
||||
// L1UserTxs that have been forged in this batch
|
||||
if len(batch.L1UserTxs) > 0 {
|
||||
if err = hdb.setL1UserTxEffectiveAmounts(txn, batch.L1UserTxs); err != nil {
|
||||
|
||||
@@ -517,16 +517,16 @@ func TestTxs(t *testing.T) {
|
||||
assert.Equal(t, true, dbL1Txs[9].UserOrigin)
|
||||
|
||||
// Load Amount
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[0].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[1].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(20), dbL1Txs[2].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[3].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[4].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[5].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), dbL1Txs[6].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), dbL1Txs[7].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[8].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[9].LoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[0].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[1].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(20), dbL1Txs[2].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[3].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[4].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[5].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), dbL1Txs[6].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), dbL1Txs[7].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[8].DepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), dbL1Txs[9].DepositAmount)
|
||||
|
||||
// Check saved txID's batch_num is not nil
|
||||
assert.Equal(t, txID, dbL1Txs[len(dbL1Txs)-2].TxID)
|
||||
@@ -736,12 +736,12 @@ func TestSetL1UserTxEffectiveAmounts(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Set the Effective{Amount,LoadAmount} of the L1UserTxs that are forged in the second block
|
||||
// Set the Effective{Amount,DepositAmount} of the L1UserTxs that are forged in the second block
|
||||
l1Txs := blocks[1].Rollup.Batches[0].L1UserTxs
|
||||
require.Equal(t, 3, len(l1Txs))
|
||||
// Change some values to test all cases
|
||||
l1Txs[1].EffectiveAmount = big.NewInt(0)
|
||||
l1Txs[2].EffectiveLoadAmount = big.NewInt(0)
|
||||
l1Txs[2].EffectiveDepositAmount = big.NewInt(0)
|
||||
l1Txs[2].EffectiveAmount = big.NewInt(0)
|
||||
err = historyDB.setL1UserTxEffectiveAmounts(historyDB.db, l1Txs)
|
||||
require.NoError(t, err)
|
||||
@@ -749,18 +749,18 @@ func TestSetL1UserTxEffectiveAmounts(t *testing.T) {
|
||||
dbL1Txs, err := historyDB.GetAllL1UserTxs()
|
||||
require.NoError(t, err)
|
||||
for i, tx := range dbL1Txs {
|
||||
log.Infof("%d %v %v", i, tx.EffectiveAmount, tx.EffectiveLoadAmount)
|
||||
log.Infof("%d %v %v", i, tx.EffectiveAmount, tx.EffectiveDepositAmount)
|
||||
assert.NotNil(t, tx.EffectiveAmount)
|
||||
assert.NotNil(t, tx.EffectiveLoadAmount)
|
||||
assert.NotNil(t, tx.EffectiveDepositAmount)
|
||||
switch tx.TxID {
|
||||
case l1Txs[0].TxID:
|
||||
assert.Equal(t, l1Txs[0].LoadAmount, tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, l1Txs[0].DepositAmount, tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, l1Txs[0].Amount, tx.EffectiveAmount)
|
||||
case l1Txs[1].TxID:
|
||||
assert.Equal(t, l1Txs[1].LoadAmount, tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, l1Txs[1].DepositAmount, tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
case l1Txs[2].TxID:
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ type TxAPI struct {
|
||||
// L1
|
||||
ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
|
||||
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
|
||||
LoadAmount *apitypes.BigIntStr `meddler:"load_amount"`
|
||||
HistoricLoadAmountUSD *float64 `meddler:"load_amount_usd"`
|
||||
DepositAmount *apitypes.BigIntStr `meddler:"deposit_amount"`
|
||||
HistoricDepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
|
||||
// L2
|
||||
Fee *common.FeeSelector `meddler:"fee"`
|
||||
HistoricFeeUSD *float64 `meddler:"fee_usd"`
|
||||
@@ -93,8 +93,8 @@ func (tx TxAPI) MarshalJSON() ([]byte, error) {
|
||||
jsonTx["L1Info"] = map[string]interface{}{
|
||||
"toForgeL1TransactionsNum": tx.ToForgeL1TxsNum,
|
||||
"userOrigin": tx.UserOrigin,
|
||||
"loadAmount": tx.LoadAmount,
|
||||
"historicLoadAmountUSD": tx.HistoricLoadAmountUSD,
|
||||
"depositAmount": tx.DepositAmount,
|
||||
"historicDepositAmountUSD": tx.HistoricDepositAmountUSD,
|
||||
"ethereumBlockNum": tx.EthBlockNum,
|
||||
}
|
||||
} else {
|
||||
@@ -129,8 +129,8 @@ type txWrite struct {
|
||||
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
|
||||
FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
|
||||
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
|
||||
LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
|
||||
LoadAmountFloat *float64 `meddler:"load_amount_f"`
|
||||
DepositAmount *big.Int `meddler:"deposit_amount,bigintnull"`
|
||||
DepositAmountFloat *float64 `meddler:"deposit_amount_f"`
|
||||
// L2
|
||||
Fee *common.FeeSelector `meddler:"fee"`
|
||||
Nonce *common.Nonce `meddler:"nonce"`
|
||||
|
||||
@@ -135,14 +135,14 @@ FOR EACH ROW EXECUTE PROCEDURE set_token_usd_update();
|
||||
|
||||
CREATE SEQUENCE tx_item_id;
|
||||
|
||||
-- important note about "amount_success" and "load_amount_success" (only relevant to L1 user txs):
|
||||
-- important note about "amount_success" and "deposit_amount_success" (only relevant to L1 user txs):
|
||||
-- The behaviour should be:
|
||||
-- When tx is not forged: amount_success = false, load_amount_success = false
|
||||
-- When tx is not forged: amount_success = false, deposit_amount_success = false
|
||||
-- When tx is forged:
|
||||
-- amount_success = false if the "effective amount" is 0, else true
|
||||
-- load_amount_success = false if the "effective load amount" is 0, else true
|
||||
-- deposit_amount_success = false if the "effective load amount" is 0, else true
|
||||
--
|
||||
-- However, in order to reduce the amount of updates, by default amount_success and load_amount_success will be set to true (when tx is unforged)
|
||||
-- However, in order to reduce the amount of updates, by default amount_success and deposit_amount_success will be set to true (when tx is unforged)
|
||||
-- whne they should be false. This can be worked around at a query level by checking if "batch_num IS NULL" (which indicates that the tx is unforged).
|
||||
CREATE TABLE tx (
|
||||
-- Generic TX
|
||||
@@ -167,10 +167,10 @@ CREATE TABLE tx (
|
||||
-- L1
|
||||
to_forge_l1_txs_num BIGINT,
|
||||
user_origin BOOLEAN,
|
||||
load_amount BYTEA,
|
||||
load_amount_success BOOLEAN NOT NULL DEFAULT true,
|
||||
load_amount_f NUMERIC,
|
||||
load_amount_usd NUMERIC,
|
||||
deposit_amount BYTEA,
|
||||
deposit_amount_success BOOLEAN NOT NULL DEFAULT true,
|
||||
deposit_amount_f NUMERIC,
|
||||
deposit_amount_usd NUMERIC,
|
||||
-- L2
|
||||
fee INT,
|
||||
fee_usd NUMERIC,
|
||||
@@ -463,8 +463,8 @@ BEGIN
|
||||
IF NEW.user_origin IS NULL OR
|
||||
NEW.from_eth_addr IS NULL OR
|
||||
NEW.from_bjj IS NULL OR
|
||||
NEW.load_amount IS NULL OR
|
||||
NEW.load_amount_f IS NULL OR
|
||||
NEW.deposit_amount IS NULL OR
|
||||
NEW.deposit_amount_f IS NULL OR
|
||||
(NOT NEW.user_origin AND NEW.batch_num IS NULL) THEN -- If is Coordinator L1, must include batch_num
|
||||
RAISE EXCEPTION 'Invalid L1 tx: %', NEW;
|
||||
END IF;
|
||||
@@ -493,8 +493,8 @@ BEGIN
|
||||
NEW."fee_usd" = (SELECT NEW."amount_usd" * fee_percentage(NEW.fee::NUMERIC));
|
||||
END IF;
|
||||
END IF;
|
||||
IF NEW."is_l1" AND NEW."load_amount_f" > 0.0 THEN
|
||||
NEW."load_amount_usd" = (SELECT _value * NEW.load_amount_f);
|
||||
IF NEW."is_l1" AND NEW."deposit_amount_f" > 0.0 THEN
|
||||
NEW."deposit_amount_usd" = (SELECT _value * NEW.deposit_amount_f);
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
@@ -455,11 +455,11 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx)
|
||||
s.zki.OnChain[s.i] = big.NewInt(1)
|
||||
|
||||
// L1Txs
|
||||
loadAmountF16, err := common.NewFloat16(tx.LoadAmount)
|
||||
depositAmountF16, err := common.NewFloat16(tx.DepositAmount)
|
||||
if err != nil {
|
||||
return nil, nil, false, nil, tracerr.Wrap(err)
|
||||
}
|
||||
s.zki.LoadAmountF[s.i] = big.NewInt(int64(loadAmountF16))
|
||||
s.zki.DepositAmountF[s.i] = big.NewInt(int64(depositAmountF16))
|
||||
s.zki.FromEthAddr[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
|
||||
if tx.FromBJJ != nil {
|
||||
s.zki.FromBJJCompressed[s.i] = BJJCompressedTo256BigInts(tx.FromBJJ.Compress())
|
||||
@@ -660,7 +660,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
|
||||
account := &common.Account{
|
||||
TokenID: tx.TokenID,
|
||||
Nonce: 0,
|
||||
Balance: tx.EffectiveLoadAmount,
|
||||
Balance: tx.EffectiveDepositAmount,
|
||||
PublicKey: tx.FromBJJ,
|
||||
EthAddr: tx.FromEthAddr,
|
||||
}
|
||||
@@ -676,7 +676,7 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
|
||||
s.zki.Sign1[s.i] = big.NewInt(1)
|
||||
}
|
||||
s.zki.Ay1[s.i] = tx.FromBJJ.Y
|
||||
s.zki.Balance1[s.i] = tx.EffectiveLoadAmount
|
||||
s.zki.Balance1[s.i] = tx.EffectiveDepositAmount
|
||||
s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
|
||||
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
|
||||
if p.IsOld0 {
|
||||
@@ -704,12 +704,12 @@ func (s *StateDB) applyCreateAccount(tx *common.L1Tx) error {
|
||||
// andTransfer parameter is set to true, the method will also apply the
|
||||
// Transfer of the L1Tx/DepositTransfer
|
||||
func (s *StateDB) applyDeposit(tx *common.L1Tx, transfer bool) error {
|
||||
// deposit the tx.EffectiveLoadAmount into the sender account
|
||||
// deposit the tx.EffectiveDepositAmount into the sender account
|
||||
accSender, err := s.GetAccount(tx.FromIdx)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
accSender.Balance = new(big.Int).Add(accSender.Balance, tx.EffectiveLoadAmount)
|
||||
accSender.Balance = new(big.Int).Add(accSender.Balance, tx.EffectiveDepositAmount)
|
||||
|
||||
// in case that the tx is a L1Tx>DepositTransfer
|
||||
var accReceiver *common.Account
|
||||
@@ -883,7 +883,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error {
|
||||
accSender := &common.Account{
|
||||
TokenID: tx.TokenID,
|
||||
Nonce: 0,
|
||||
Balance: tx.EffectiveLoadAmount,
|
||||
Balance: tx.EffectiveDepositAmount,
|
||||
PublicKey: tx.FromBJJ,
|
||||
EthAddr: tx.FromEthAddr,
|
||||
}
|
||||
@@ -908,7 +908,7 @@ func (s *StateDB) applyCreateAccountDepositTransfer(tx *common.L1Tx) error {
|
||||
s.zki.Sign1[s.i] = big.NewInt(1)
|
||||
}
|
||||
s.zki.Ay1[s.i] = tx.FromBJJ.Y
|
||||
s.zki.Balance1[s.i] = tx.EffectiveLoadAmount
|
||||
s.zki.Balance1[s.i] = tx.EffectiveDepositAmount
|
||||
s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
|
||||
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(p.Siblings)
|
||||
if p.IsOld0 {
|
||||
@@ -1039,20 +1039,20 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
if !tx.UserOrigin {
|
||||
// case where the L1Tx is generated by the Coordinator
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
|
||||
tx.EffectiveAmount = tx.Amount
|
||||
tx.EffectiveLoadAmount = tx.LoadAmount
|
||||
tx.EffectiveDepositAmount = tx.DepositAmount
|
||||
if tx.Type == common.TxTypeCreateAccountDeposit {
|
||||
return
|
||||
}
|
||||
|
||||
if tx.ToIdx >= common.UserThreshold && tx.FromIdx == common.Idx(0) {
|
||||
// CreateAccountDepositTransfer case
|
||||
cmp := tx.LoadAmount.Cmp(tx.Amount)
|
||||
if cmp == -1 { // LoadAmount<Amount
|
||||
cmp := tx.DepositAmount.Cmp(tx.Amount)
|
||||
if cmp == -1 { // DepositAmount<Amount
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
@@ -1061,24 +1061,24 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
|
||||
accSender, err := s.GetAccount(tx.FromIdx)
|
||||
if err != nil {
|
||||
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: can not get account for tx.FromIdx: %d", tx.FromIdx)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.FromIdx: %d", tx.FromIdx)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
|
||||
// check that tx.TokenID corresponds to the Sender account TokenID
|
||||
if tx.TokenID != accSender.TokenID {
|
||||
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: tx.TokenID (%d) !=sender account TokenID (%d)", tx.TokenID, accSender.TokenID)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx.TokenID (%d) !=sender account TokenID (%d)", tx.TokenID, accSender.TokenID)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
|
||||
// check that Sender has enough balance
|
||||
bal := accSender.Balance
|
||||
if tx.LoadAmount != nil {
|
||||
bal = new(big.Int).Add(bal, tx.EffectiveLoadAmount)
|
||||
if tx.DepositAmount != nil {
|
||||
bal = new(big.Int).Add(bal, tx.EffectiveDepositAmount)
|
||||
}
|
||||
cmp := bal.Cmp(tx.Amount)
|
||||
if cmp == -1 {
|
||||
@@ -1090,8 +1090,8 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
// check that the tx.FromEthAddr is the same than the EthAddress of the
|
||||
// Sender
|
||||
if !bytes.Equal(tx.FromEthAddr.Bytes(), accSender.EthAddr.Bytes()) {
|
||||
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of the sender account by the Idx (%s)", tx.FromEthAddr.Hex(), accSender.EthAddr.Hex())
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx.FromEthAddr (%s) must be the same EthAddr of the sender account by the Idx (%s)", tx.FromEthAddr.Hex(), accSender.EthAddr.Hex())
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
@@ -1104,14 +1104,14 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
||||
// check that TokenID is the same for Sender & Receiver account
|
||||
accReceiver, err := s.GetAccount(tx.ToIdx)
|
||||
if err != nil {
|
||||
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
if accSender.TokenID != accReceiver.TokenID {
|
||||
log.Debugf("EffectiveAmount & EffectiveLoadAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accSender.TokenID)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accSender.TokenID)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
FromIdx: 256,
|
||||
ToIdx: 257,
|
||||
Amount: big.NewInt(10),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
FromEthAddr: tc.Users["A"].Addr,
|
||||
UserOrigin: true,
|
||||
}
|
||||
sdb.computeEffectiveAmounts(&tx)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not enough funds
|
||||
@@ -74,12 +74,12 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
FromIdx: 256,
|
||||
ToIdx: 257,
|
||||
Amount: big.NewInt(11),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
FromEthAddr: tc.Users["A"].Addr,
|
||||
UserOrigin: true,
|
||||
}
|
||||
sdb.computeEffectiveAmounts(&tx)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
|
||||
// expect no-error due not enough funds in a
|
||||
@@ -88,11 +88,11 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
FromIdx: 0,
|
||||
ToIdx: 257,
|
||||
Amount: big.NewInt(10),
|
||||
LoadAmount: big.NewInt(10),
|
||||
DepositAmount: big.NewInt(10),
|
||||
UserOrigin: true,
|
||||
}
|
||||
sdb.computeEffectiveAmounts(&tx)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not enough funds in a CreateAccountDepositTransfer
|
||||
@@ -101,11 +101,11 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
FromIdx: 0,
|
||||
ToIdx: 257,
|
||||
Amount: big.NewInt(11),
|
||||
LoadAmount: big.NewInt(10),
|
||||
DepositAmount: big.NewInt(10),
|
||||
UserOrigin: true,
|
||||
}
|
||||
sdb.computeEffectiveAmounts(&tx)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(10), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not same TokenID
|
||||
@@ -113,12 +113,12 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
FromIdx: 256,
|
||||
ToIdx: 258,
|
||||
Amount: big.NewInt(5),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
FromEthAddr: tc.Users["A"].Addr,
|
||||
UserOrigin: true,
|
||||
}
|
||||
sdb.computeEffectiveAmounts(&tx)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
|
||||
// expect error due not same EthAddr
|
||||
@@ -126,12 +126,12 @@ func TestCheckL1TxInvalidData(t *testing.T) {
|
||||
FromIdx: 256,
|
||||
ToIdx: 257,
|
||||
Amount: big.NewInt(8),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
FromEthAddr: tc.Users["B"].Addr,
|
||||
UserOrigin: true,
|
||||
}
|
||||
sdb.computeEffectiveAmounts(&tx)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveLoadAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveDepositAmount)
|
||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@ func TestProcessTxsRootTestVectors(t *testing.T) {
|
||||
l1Txs := []common.L1Tx{
|
||||
{
|
||||
FromIdx: 0,
|
||||
LoadAmount: big.NewInt(16000000),
|
||||
DepositAmount: big.NewInt(16000000),
|
||||
Amount: big.NewInt(0),
|
||||
TokenID: 1,
|
||||
FromBJJ: bjj0,
|
||||
@@ -612,7 +612,7 @@ func TestCircomTest(t *testing.T) {
|
||||
l1Txs := []common.L1Tx{
|
||||
{
|
||||
FromIdx: 0,
|
||||
LoadAmount: big.NewInt(16000000),
|
||||
DepositAmount: big.NewInt(16000000),
|
||||
Amount: big.NewInt(0),
|
||||
TokenID: 1,
|
||||
FromBJJ: bjj0,
|
||||
@@ -701,7 +701,7 @@ func TestZKInputsHashTestVector0(t *testing.T) {
|
||||
l1Txs := []common.L1Tx{
|
||||
{
|
||||
FromIdx: 0,
|
||||
LoadAmount: big.NewInt(16000000),
|
||||
DepositAmount: big.NewInt(16000000),
|
||||
Amount: big.NewInt(0),
|
||||
TokenID: 1,
|
||||
FromBJJ: bjj0,
|
||||
@@ -778,8 +778,8 @@ func TestZKInputsHashTestVector1(t *testing.T) {
|
||||
l1Txs := []common.L1Tx{
|
||||
{
|
||||
FromIdx: 0,
|
||||
// LoadAmount: big.NewInt(10400),
|
||||
LoadAmount: big.NewInt(16000000),
|
||||
// DepositAmount: big.NewInt(10400),
|
||||
DepositAmount: big.NewInt(16000000),
|
||||
Amount: big.NewInt(0),
|
||||
TokenID: 1,
|
||||
FromBJJ: bjj0,
|
||||
@@ -790,7 +790,7 @@ func TestZKInputsHashTestVector1(t *testing.T) {
|
||||
},
|
||||
{
|
||||
FromIdx: 0,
|
||||
LoadAmount: big.NewInt(16000000),
|
||||
DepositAmount: big.NewInt(16000000),
|
||||
Amount: big.NewInt(0),
|
||||
TokenID: 1,
|
||||
FromBJJ: bjj1,
|
||||
|
||||
@@ -218,8 +218,8 @@ type RollupInterface interface {
|
||||
RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error)
|
||||
RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error)
|
||||
|
||||
RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
|
||||
RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error)
|
||||
RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
|
||||
RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error)
|
||||
|
||||
// Governance Public Functions
|
||||
RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error)
|
||||
@@ -409,7 +409,7 @@ func (c *RollupClient) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC20ETH is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
|
||||
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
@@ -423,7 +423,7 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
||||
}
|
||||
fromIdxBig := big.NewInt(fromIdx)
|
||||
toIdxBig := big.NewInt(toIdx)
|
||||
loadAmountF, err := common.NewFloat16(loadAmount)
|
||||
depositAmountF, err := common.NewFloat16(depositAmount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -432,10 +432,10 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
if tokenID == 0 {
|
||||
auth.Value = loadAmount
|
||||
auth.Value = depositAmount
|
||||
}
|
||||
var permit []byte
|
||||
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
|
||||
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(depositAmountF),
|
||||
uint16(amountF), tokenID, toIdxBig, permit)
|
||||
},
|
||||
); err != nil {
|
||||
@@ -445,7 +445,7 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
@@ -459,7 +459,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
|
||||
}
|
||||
fromIdxBig := big.NewInt(fromIdx)
|
||||
toIdxBig := big.NewInt(toIdx)
|
||||
loadAmountF, err := common.NewFloat16(loadAmount)
|
||||
depositAmountF, err := common.NewFloat16(depositAmount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -468,7 +468,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
if tokenID == 0 {
|
||||
auth.Value = loadAmount
|
||||
auth.Value = depositAmount
|
||||
}
|
||||
owner := c.client.account.Address
|
||||
spender := c.address
|
||||
@@ -481,7 +481,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
|
||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, amount, nonce, deadline, tokenName)
|
||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
||||
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
|
||||
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(depositAmountF),
|
||||
uint16(amountF), tokenID, toIdxBig, permit)
|
||||
},
|
||||
); err != nil {
|
||||
|
||||
@@ -267,18 +267,18 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -287,7 +287,7 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -299,18 +299,18 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
|
||||
key := genKeysBjj(1)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenHEZID),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -319,7 +319,7 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -331,18 +331,18 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
|
||||
key := genKeysBjj(3)
|
||||
fromIdxInt64 := int64(0)
|
||||
toIdxInt64 := int64(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: key.BJJPublicKey,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -351,7 +351,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -363,18 +363,18 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
|
||||
fromIdxInt64 := int64(256)
|
||||
toIdxInt64 := int64(0)
|
||||
tokenIDUint32 := uint32(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: nil,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -382,7 +382,7 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -393,18 +393,18 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fromIdxInt64 := int64(257)
|
||||
toIdxInt64 := int64(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromBJJ: nil,
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenHEZID),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -412,7 +412,7 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -423,17 +423,17 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fromIdxInt64 := int64(258)
|
||||
toIdxInt64 := int64(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: big.NewInt(0),
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -441,7 +441,7 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -453,18 +453,18 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
|
||||
fromIdxInt64 := int64(256)
|
||||
toIdxInt64 := int64(257)
|
||||
tokenIDUint32 := uint32(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
amount, _ := new(big.Int).SetString("100000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -472,7 +472,7 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -483,18 +483,18 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fromIdxInt64 := int64(257)
|
||||
toIdxInt64 := int64(258)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
amount, _ := new(big.Int).SetString("100000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenHEZID),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -502,7 +502,7 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -513,18 +513,18 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fromIdxInt64 := int64(258)
|
||||
toIdxInt64 := int64(259)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
amount, _ := new(big.Int).SetString("100000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -532,7 +532,7 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -544,18 +544,18 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
|
||||
fromIdxInt64 := int64(256)
|
||||
toIdxInt64 := int64(257)
|
||||
tokenIDUint32 := uint32(0)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
amount, _ := new(big.Int).SetString("20000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -563,7 +563,7 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -574,18 +574,18 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fromIdxInt64 := int64(257)
|
||||
toIdxInt64 := int64(258)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
amount, _ := new(big.Int).SetString("30000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenHEZID),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -593,7 +593,7 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -604,18 +604,18 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
fromIdxInt64 := int64(258)
|
||||
toIdxInt64 := int64(259)
|
||||
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
depositAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
|
||||
amount, _ := new(big.Int).SetString("40000000000000000000", 10)
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -623,7 +623,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -639,13 +639,13 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -653,7 +653,7 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -668,13 +668,13 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
TokenID: common.TokenID(tokenHEZID),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -682,7 +682,7 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -697,13 +697,13 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -711,7 +711,7 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -727,13 +727,13 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
TokenID: common.TokenID(tokenIDUint32),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -741,7 +741,7 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -756,13 +756,13 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
TokenID: common.TokenID(tokenHEZID),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -770,7 +770,7 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
@@ -787,13 +787,13 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
|
||||
l1Tx := common.L1Tx{
|
||||
FromIdx: common.Idx(fromIdxInt64),
|
||||
ToIdx: common.Idx(toIdxInt64),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
TokenID: common.TokenID(tokenIDERC777),
|
||||
Amount: amount,
|
||||
}
|
||||
L1UserTxs = append(L1UserTxs, l1Tx)
|
||||
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.DepositAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
|
||||
require.NoError(t, err)
|
||||
|
||||
currentBlockNum, err := rollupClient.client.EthLastBlock()
|
||||
@@ -801,7 +801,7 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
|
||||
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
|
||||
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
|
||||
assert.Equal(t, l1Tx.DepositAmount, rollupEvents.L1UserTx[0].L1UserTx.DepositAmount)
|
||||
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
|
||||
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
|
||||
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
|
||||
|
||||
@@ -81,13 +81,13 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBloc
|
||||
dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs()
|
||||
require.Nil(t, err)
|
||||
// Ignore BatchNum in syncBlock.L1UserTxs because this value is set by
|
||||
// the HistoryDB. Also ignore EffectiveAmount & EffectiveLoadAmount
|
||||
// the HistoryDB. Also ignore EffectiveAmount & EffectiveDepositAmount
|
||||
// because this value is set by StateDB.ProcessTxs.
|
||||
for i := range syncBlock.Rollup.L1UserTxs {
|
||||
syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum
|
||||
syncBlock.Rollup.L1UserTxs[i].EffectiveAmount = block.Rollup.L1UserTxs[i].EffectiveAmount
|
||||
syncBlock.Rollup.L1UserTxs[i].EffectiveLoadAmount =
|
||||
block.Rollup.L1UserTxs[i].EffectiveLoadAmount
|
||||
syncBlock.Rollup.L1UserTxs[i].EffectiveDepositAmount =
|
||||
block.Rollup.L1UserTxs[i].EffectiveDepositAmount
|
||||
}
|
||||
assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs)
|
||||
for _, tx := range block.Rollup.L1UserTxs {
|
||||
@@ -102,7 +102,7 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBloc
|
||||
}
|
||||
}
|
||||
tx.EffectiveAmount = tx.Amount
|
||||
tx.EffectiveLoadAmount = tx.LoadAmount
|
||||
tx.EffectiveDepositAmount = tx.DepositAmount
|
||||
assert.Equal(t, &tx, dbTx) //nolint:gosec
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ func ethAddBlocks(t *testing.T, blocks []common.BlockData,
|
||||
}
|
||||
for _, tx := range block.Rollup.L1UserTxs {
|
||||
client.CtlSetAddr(tx.FromEthAddr)
|
||||
_, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount, tx.Amount,
|
||||
_, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount, tx.Amount,
|
||||
uint32(tx.TokenID), int64(tx.ToIdx))
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -716,7 +716,7 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet")
|
||||
// }
|
||||
|
||||
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
|
||||
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
log.Error("TODO")
|
||||
return nil, tracerr.Wrap(errTODO)
|
||||
}
|
||||
@@ -725,7 +725,7 @@ func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx i
|
||||
func (c *Client) RollupL1UserTxERC20ETH(
|
||||
fromBJJ *babyjub.PublicKey,
|
||||
fromIdx int64,
|
||||
loadAmount *big.Int,
|
||||
depositAmount *big.Int,
|
||||
amount *big.Int,
|
||||
tokenID uint32,
|
||||
toIdx int64,
|
||||
@@ -739,7 +739,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
_, err = common.NewFloat16(loadAmount)
|
||||
_, err = common.NewFloat16(depositAmount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -764,7 +764,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
||||
FromEthAddr: *c.addr,
|
||||
FromBJJ: fromBJJ,
|
||||
Amount: amount,
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenID),
|
||||
ToIdx: common.Idx(toIdx),
|
||||
ToForgeL1TxsNum: &toForgeL1TxsNum,
|
||||
@@ -783,7 +783,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
@@ -161,9 +161,9 @@ func TestClientRollup(t *testing.T) {
|
||||
FromBJJ: keys[i].BJJPublicKey,
|
||||
TokenID: common.TokenID(0),
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(10 + int64(i)),
|
||||
DepositAmount: big.NewInt(10 + int64(i)),
|
||||
}
|
||||
_, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount,
|
||||
_, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount,
|
||||
tx.Amount, uint32(tx.TokenID), int64(tx.ToIdx))
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func GenL1Txs(
|
||||
UserOrigin: i%2 == 0,
|
||||
TokenID: token.TokenID,
|
||||
Amount: amount,
|
||||
LoadAmount: amount,
|
||||
DepositAmount: amount,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
}
|
||||
if tx.UserOrigin {
|
||||
|
||||
@@ -68,7 +68,7 @@ type Instruction struct {
|
||||
From string
|
||||
To string
|
||||
Amount *big.Int
|
||||
LoadAmount *big.Int
|
||||
DepositAmount *big.Int
|
||||
Fee uint8
|
||||
TokenID common.TokenID
|
||||
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
|
||||
@@ -94,7 +94,7 @@ func (i Instruction) String() string {
|
||||
if i.Typ == common.TxTypeDeposit ||
|
||||
i.Typ == common.TxTypeDepositTransfer ||
|
||||
i.Typ == common.TxTypeCreateAccountDepositTransfer {
|
||||
fmt.Fprintf(buf, "LoadAmount: %d, ", i.LoadAmount)
|
||||
fmt.Fprintf(buf, "DepositAmount: %d, ", i.DepositAmount)
|
||||
}
|
||||
if i.Typ != common.TxTypeDeposit {
|
||||
fmt.Fprintf(buf, "Amount: %d, ", i.Amount)
|
||||
@@ -123,7 +123,7 @@ func (i Instruction) raw() string {
|
||||
if i.Typ == common.TxTypeDeposit ||
|
||||
i.Typ == common.TxTypeDepositTransfer ||
|
||||
i.Typ == common.TxTypeCreateAccountDepositTransfer {
|
||||
fmt.Fprintf(buf, "%d", i.LoadAmount)
|
||||
fmt.Fprintf(buf, "%d", i.DepositAmount)
|
||||
}
|
||||
if i.Typ != common.TxTypeDeposit {
|
||||
fmt.Fprintf(buf, "%d", i.Amount)
|
||||
@@ -439,13 +439,13 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
|
||||
// deposit case
|
||||
_, lit = p.scanIgnoreWhitespace()
|
||||
c.Literal += lit
|
||||
loadAmount, ok := new(big.Int).SetString(lit, 10)
|
||||
depositAmount, ok := new(big.Int).SetString(lit, 10)
|
||||
if !ok {
|
||||
line, _ := p.s.r.ReadString('\n')
|
||||
c.Literal += line
|
||||
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for LoadAmount"))
|
||||
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for DepositAmount"))
|
||||
}
|
||||
c.LoadAmount = loadAmount
|
||||
c.DepositAmount = depositAmount
|
||||
if err := p.expectChar(c, ","); err != nil {
|
||||
return c, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -460,7 +460,7 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
|
||||
}
|
||||
if c.Typ == common.TxTypeDeposit ||
|
||||
c.Typ == common.TxTypeCreateAccountDeposit {
|
||||
c.LoadAmount = amount
|
||||
c.DepositAmount = amount
|
||||
} else {
|
||||
c.Amount = amount
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestParseBlockchainTxs(t *testing.T) {
|
||||
assert.Equal(t, TxTypeCreateAccountDepositCoordinator, instructions.instructions[7].Typ)
|
||||
assert.Equal(t, TypeNewBatch, instructions.instructions[11].Typ)
|
||||
assert.Equal(t, "Deposit(1)User0:20", instructions.instructions[16].raw())
|
||||
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, LoadAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
|
||||
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, DepositAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
|
||||
assert.Equal(t, "Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n", instructions.instructions[19].String())
|
||||
assert.Equal(t, "Transfer(2)A-B:15(1)", instructions.instructions[15].raw())
|
||||
assert.Equal(t, "Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n", instructions.instructions[15].String())
|
||||
|
||||
@@ -203,7 +203,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
|
||||
}
|
||||
testTx := L1Tx{
|
||||
@@ -223,7 +223,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: inst.LoadAmount,
|
||||
DepositAmount: inst.DepositAmount,
|
||||
Type: inst.Typ,
|
||||
}
|
||||
if inst.Typ == common.TxTypeCreateAccountDepositTransfer {
|
||||
@@ -250,7 +250,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
tx := common.L1Tx{
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: inst.LoadAmount,
|
||||
DepositAmount: inst.DepositAmount,
|
||||
Type: inst.Typ,
|
||||
}
|
||||
if inst.Typ == common.TxTypeDepositTransfer {
|
||||
@@ -293,7 +293,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
tx := common.L1Tx{
|
||||
TokenID: inst.TokenID,
|
||||
Amount: inst.Amount,
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeForceTransfer,
|
||||
}
|
||||
testTx := L1Tx{
|
||||
@@ -335,7 +335,7 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
ToIdx: common.Idx(1), // as is an Exit
|
||||
TokenID: inst.TokenID,
|
||||
Amount: inst.Amount,
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeForceExit,
|
||||
}
|
||||
testTx := L1Tx{
|
||||
@@ -747,7 +747,7 @@ func (tc *Context) FillBlocksL1UserTxsBatchNum(blocks []common.BlockData) {
|
||||
|
||||
// FillBlocksForgedL1UserTxs fills the L1UserTxs of a batch with the L1UserTxs
|
||||
// that are forged in that batch. It always sets `EffectiveAmount` = `Amount`
|
||||
// and `EffectiveLoadAmount` = `LoadAmount`.
|
||||
// and `EffectiveDepositAmount` = `DepositAmount`.
|
||||
func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
||||
for i := range blocks {
|
||||
block := &blocks[i]
|
||||
@@ -761,7 +761,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
||||
tx := &batch.L1UserTxs[k]
|
||||
*tx = queue[k].L1Tx
|
||||
tx.EffectiveAmount = tx.Amount
|
||||
tx.EffectiveLoadAmount = tx.LoadAmount
|
||||
tx.EffectiveDepositAmount = tx.DepositAmount
|
||||
tx.BatchNum = &batchNum
|
||||
_tx, err := common.NewL1Tx(tx)
|
||||
if err != nil {
|
||||
@@ -786,7 +786,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EthBlockNum
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].Position
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveAmount
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveLoadAmount
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveDepositAmount
|
||||
// - blocks[].Rollup.Batch.L2Txs[].TxID
|
||||
// - blocks[].Rollup.Batch.L2Txs[].Position
|
||||
// - blocks[].Rollup.Batch.L2Txs[].Nonce
|
||||
@@ -869,7 +869,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
|
||||
tx.Position = position
|
||||
position++
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
nTx, err := common.NewL1Tx(tx)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
|
||||
@@ -141,7 +141,7 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
|
||||
}
|
||||
|
||||
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
|
||||
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
|
||||
assert.Equal(t, typ, tx.Type)
|
||||
if tx.FromIdx != common.Idx(0) {
|
||||
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
|
||||
@@ -151,8 +151,8 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy
|
||||
if tx.ToIdx != common.Idx(0) {
|
||||
assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
|
||||
}
|
||||
if loadAmount != nil {
|
||||
assert.Equal(t, loadAmount, tx.LoadAmount)
|
||||
if depositAmount != nil {
|
||||
assert.Equal(t, depositAmount, tx.DepositAmount)
|
||||
}
|
||||
if amount != nil {
|
||||
assert.Equal(t, amount, tx.Amount)
|
||||
@@ -432,14 +432,14 @@ func TestGenerateFromInstructions(t *testing.T) {
|
||||
TokenID: 1,
|
||||
})
|
||||
i++
|
||||
la := big.NewInt(10)
|
||||
da := big.NewInt(10)
|
||||
setInst = append(setInst, Instruction{
|
||||
LineNum: i,
|
||||
// Literal: "CreateAccountDeposit(1) A: 10",
|
||||
Typ: common.TxTypeCreateAccountDeposit,
|
||||
From: "A",
|
||||
TokenID: 1,
|
||||
LoadAmount: la,
|
||||
DepositAmount: da,
|
||||
})
|
||||
i++
|
||||
setInst = append(setInst, Instruction{
|
||||
|
||||
@@ -165,7 +165,7 @@ func (txsel *TxSelector) GetL1L2TxSelection(coordIdxs []common.Idx, batchNum com
|
||||
FromEthAddr: accAuth.EthAddr,
|
||||
FromBJJ: accAuth.BJJ,
|
||||
TokenID: l2TxsRaw[i].TokenID,
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeCreateAccountDeposit,
|
||||
}
|
||||
positionL1++
|
||||
@@ -190,7 +190,7 @@ func (txsel *TxSelector) GetL1L2TxSelection(coordIdxs []common.Idx, batchNum com
|
||||
FromEthAddr: l2TxsRaw[i].ToEthAddr,
|
||||
FromBJJ: l2TxsRaw[i].ToBJJ,
|
||||
TokenID: l2TxsRaw[i].TokenID,
|
||||
LoadAmount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeCreateAccountDeposit,
|
||||
}
|
||||
positionL1++
|
||||
|
||||
Reference in New Issue
Block a user