Skip to content

Commit 2455536

Browse files
committed
Sign the lighter transfer amount and allow to withdraw the borrow amount
1 parent af06451 commit 2455536

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

chains/lighter/message/lighter.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ func (h *LighterMessageHandler) HandleMessage(m *message.Message) (*proposal.Pro
9090
return nil, err
9191
}
9292

93-
if err = h.verifyWithdrawal(tx); err != nil {
93+
if err = h.verifyWithdrawal(tx, data.BorrowAmount); err != nil {
9494
data.ErrChn <- err
9595
return nil, err
9696
}
9797

9898
data.ErrChn <- nil
9999

100-
calldata, err := h.calldata(tx)
100+
calldata, err := h.calldata(tx, data.BorrowAmount)
101101
if err != nil {
102102
return nil, err
103103
}
@@ -137,7 +137,7 @@ func (h *LighterMessageHandler) HandleMessage(m *message.Message) (*proposal.Pro
137137
return nil, nil
138138
}
139139

140-
func (h *LighterMessageHandler) verifyWithdrawal(tx *lighter.LighterTx) error {
140+
func (h *LighterMessageHandler) verifyWithdrawal(tx *lighter.LighterTx, borrowAmount *big.Int) error {
141141
if tx.Type != lighter.TxTypeL2Transfer {
142142
return errors.New("invalid transaction type")
143143
}
@@ -146,15 +146,19 @@ func (h *LighterMessageHandler) verifyWithdrawal(tx *lighter.LighterTx) error {
146146
return errors.New("transfer account index invalid")
147147
}
148148

149+
if borrowAmount.Cmp(new(big.Int).SetUint64(tx.Transfer.USDCAmount)) != -1 {
150+
return errors.New("borrow amount higher transfer amount")
151+
}
152+
149153
return nil
150154
}
151155

152-
func (h *LighterMessageHandler) calldata(tx *lighter.LighterTx) ([]byte, error) {
156+
func (h *LighterMessageHandler) calldata(tx *lighter.LighterTx, borrowAmount *big.Int) ([]byte, error) {
153157
return consts.LighterABI.Pack(
154158
"withdraw",
155159
common.HexToHash(tx.Hash),
156160
common.HexToAddress(tx.L1Address),
157-
new(big.Int).SetUint64(tx.Transfer.USDCAmount))
161+
borrowAmount)
158162
}
159163

160164
func (h *LighterMessageHandler) Listen(ctx context.Context) {

0 commit comments

Comments
 (0)