Skip to content

Commit 02a64f8

Browse files
committed
feat: add events
1 parent fe08f9d commit 02a64f8

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

src/Gateway.sol

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ contract GatewayUpgradeable is OwnableUpgradeable {
327327
}
328328
}
329329

330+
event BridgeIn(address indexed depositorAddress, bytes16 indexed instanceId, uint64 indexed peginAmountSats);
331+
330332
function postPeginData(
331333
bytes16 instanceId,
332334
BitvmTxParser.BitcoinTx calldata rawPeginTx,
@@ -375,6 +377,8 @@ contract GatewayUpgradeable is OwnableUpgradeable {
375377
depositorAddress,
376378
Converter.amountFromSats(peginAmountSats)
377379
);
380+
381+
emit BridgeIn(depositorAddress, instanceId, peginAmountSats);
378382
}
379383

380384
function postOperatorData(
@@ -409,6 +413,10 @@ contract GatewayUpgradeable is OwnableUpgradeable {
409413
}
410414
}
411415

416+
event InitWithdraw(
417+
bytes16 indexed instanceId, bytes16 indexed graphId, address indexed operatorAddress, uint64 withdrawAmountSats
418+
);
419+
412420
function initWithdraw(bytes16 instanceId, bytes16 graphId) external {
413421
WithdrawData storage withdrawData = withdrawDataMap[graphId];
414422
require(
@@ -438,8 +446,12 @@ contract GatewayUpgradeable is OwnableUpgradeable {
438446
withdrawData.status = WithdrawStatus.Initialized;
439447
withdrawData.instanceId = instanceId;
440448
withdrawData.lockAmount = lockAmount;
449+
450+
emit InitWithdraw(instanceId, graphId, withdrawData.operatorAddress, peginData.peginAmount);
441451
}
442452

453+
event CancelWithdraw(bytes16 indexed instanceId, bytes16 indexed graphId, address indexed triggerAddress);
454+
443455
function cancelWithdraw(
444456
bytes16 graphId
445457
) external onlyRelayerOrOperator(graphId) {
@@ -452,8 +464,12 @@ contract GatewayUpgradeable is OwnableUpgradeable {
452464
withdrawData.status = WithdrawStatus.Canceled;
453465
pegBTC.transfer(msg.sender, withdrawData.lockAmount);
454466
peginData.status = PeginStatus.Withdrawbale;
467+
468+
emit CancelWithdraw(withdrawData.instanceId, graphId, msg.sender);
455469
}
456470

471+
event ProceedWithdraw(bytes16 indexed instanceId, bytes16 indexed graphId, bytes32 kickoffTxid);
472+
457473
// post kickoff tx
458474
function proceedWithdraw(
459475
bytes16 graphId,
@@ -465,7 +481,6 @@ contract GatewayUpgradeable is OwnableUpgradeable {
465481
) external onlyRelayerOrOperator(graphId) {
466482
WithdrawData storage withdrawData = withdrawDataMap[graphId];
467483
bytes16 instanceId = withdrawData.instanceId;
468-
PeginData storage peginData = peginDataMap[instanceId];
469484
require(
470485
withdrawData.status == WithdrawStatus.Initialized,
471486
"invalid withdraw index: not at init stage"
@@ -492,8 +507,12 @@ contract GatewayUpgradeable is OwnableUpgradeable {
492507

493508
// burn pegBTC
494509
pegBTC.burn(withdrawData.lockAmount);
510+
511+
emit ProceedWithdraw(instanceId, graphId, kickoffTxid);
495512
}
496513

514+
event WithdrawHappyPath(bytes16 indexed instanceId, bytes16 indexed graphId, bytes32 take1Txid);
515+
497516
function finishWithdrawHappyPath(
498517
bytes16 graphId,
499518
BitvmTxParser.BitcoinTx calldata rawTake1Tx,
@@ -527,8 +546,12 @@ contract GatewayUpgradeable is OwnableUpgradeable {
527546

528547
peginData.status = PeginStatus.Claimed;
529548
withdrawData.status = WithdrawStatus.Complete;
549+
550+
emit WithdrawHappyPath(instanceId, graphId, take1Txid);
530551
}
531552

553+
event WithdrawUnhappyPath(bytes16 indexed instanceId, bytes16 indexed graphId, bytes32 take2Txid);
554+
532555
function finishWithdrawUnhappyPath(
533556
bytes16 graphId,
534557
BitvmTxParser.BitcoinTx calldata rawTake2Tx,
@@ -559,8 +582,12 @@ contract GatewayUpgradeable is OwnableUpgradeable {
559582

560583
peginData.status = PeginStatus.Claimed;
561584
withdrawData.status = WithdrawStatus.Complete;
585+
586+
emit WithdrawUnhappyPath(instanceId, graphId, take2Txid);
562587
}
563588

589+
event WithdrawDisproved(bytes16 indexed instanceId, bytes16 indexed graphId, bytes32 disproveTxid);
590+
564591
function finishWithdrawDisproved(
565592
bytes16 graphId,
566593
BitvmTxParser.BitcoinTx calldata rawDisproveTx,
@@ -571,7 +598,6 @@ contract GatewayUpgradeable is OwnableUpgradeable {
571598
) external onlyRelayerOrOperator(graphId) {
572599
WithdrawData storage withdrawData = withdrawDataMap[graphId];
573600
bytes16 instanceId = withdrawData.instanceId;
574-
PeginData storage peginData = peginDataMap[instanceId];
575601
// Malicious operator may skip initWithdraw & procceedWithdraw
576602

577603
OperatorData storage operatorData = operatorDataMap[graphId];
@@ -591,6 +617,8 @@ contract GatewayUpgradeable is OwnableUpgradeable {
591617
);
592618

593619
withdrawData.status = WithdrawStatus.Disproved;
620+
621+
emit WithdrawDisproved(instanceId, graphId, disproveTxid);
594622
}
595623

596624
function parseBtcBlockHeader(

0 commit comments

Comments
 (0)