Skip to content

Commit

Permalink
pay contract: add events for completed vs. bounced actions
Browse files Browse the repository at this point in the history
Actions that have a call may have failed calls, emit ActionBounced to track those easily.
  • Loading branch information
nalinbhardwaj committed Oct 2, 2024
1 parent c267906 commit 185b387
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 94 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contract/script/DeployCrepeFastCCTP.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract DeployCrepeFastCCTPScript is Script {
console.log("using handoff factory at", handoffFactory);

address fastCCTP = CREATE3.deploy(
keccak256("CrepeFastCCTP-test3"),
keccak256("CrepeFastCCTP-test4"),
abi.encodePacked(
type(CrepeFastCCTP).creationCode,
abi.encode(tokenMinter, tokenMessenger, handoffFactory)
Expand Down
4 changes: 2 additions & 2 deletions packages/contract/script/deployV2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ set -e

SCRIPTS=(
# "script/DeployCrepeHandoffFactory.s.sol"
# "script/DeployCrepeFastCCTP.s.sol"
"script/DeployCrepeFastCCTP.s.sol"
# "script/DeployFlexSwapper.s.sol"
# "script/DeployCCTPBridger.s.sol"
# "script/DeployAccountFactoryV2.s.sol"
# "script/DeployTestAccountV2.s.sol"

# SWAPBOT (ensure private key is swapbot EOA)
# "script/DeploySwapbotLP.s.sol"
"script/DeployCrepeBotLP.s.sol"
# "script/DeployCrepeBotLP.s.sol"
)
CHAINS=(
# MAINNETS
Expand Down
37 changes: 33 additions & 4 deletions packages/contract/src/CrepeFastCCTP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ contract CrepeFastCCTP {
Destination destination
);

// When the action is completed as expected, emit this event
event ActionCompleted(
address indexed handoffAddr,
address indexed destinationAddress
);

// When the action is a call that fails, we bounce the funds to the
// specified refund address and emit this event
event ActionBounced(
address indexed handoffAddr,
address indexed refundAddress
);

constructor(
ITokenMinter _tokenMinter,
ICCTPTokenMessenger _cctpMessenger,
Expand Down Expand Up @@ -169,7 +182,7 @@ contract CrepeFastCCTP {
address(this),
destination.mintToken.amount
);
completeAction(destination, swapCall);
completeAction(handoffAddr, destination, swapCall);

emit FastFinish({
handoffAddr: handoffAddr,
Expand Down Expand Up @@ -203,7 +216,7 @@ contract CrepeFastCCTP {
recipient = destination.finalCall.to;

handoffToRecipient[address(handoff)] = recipient;
completeAction(destination, swapCall);
completeAction(address(handoff), destination, swapCall);
} else {
// Otherwise, the LP fastFinished the action, give them the recieved
// amount.
Expand All @@ -224,6 +237,7 @@ contract CrepeFastCCTP {
// Then, if an action is a call, make the action call with the given token
// approved. Otherwise, transfer the token to the action address.
function completeAction(
address handoffAddr,
Destination calldata destination,
Call calldata swapCall
) internal {
Expand Down Expand Up @@ -261,21 +275,36 @@ contract CrepeFastCCTP {
value: destination.finalCall.value
}(destination.finalCall.data);

// If the intent fails, refund the final tokens
if (!success) {
if (success) {
emit ActionCompleted({
handoffAddr: handoffAddr,
destinationAddress: destination.finalCall.to
});
} else {
CrepeTokenUtils.transfer(
destination.finalCallToken.addr,
payable(destination.refundAddress),
destination.finalCallToken.amount
);

emit ActionBounced({
handoffAddr: handoffAddr,
refundAddress: destination.refundAddress
});
}
} else {
// If the final call is a transfer, transfer the token
// Transfers can never bounce.
CrepeTokenUtils.transfer(
destination.finalCallToken.addr,
payable(destination.finalCall.to),
destination.finalCallToken.amount
);

emit ActionCompleted({
handoffAddr: handoffAddr,
destinationAddress: destination.finalCall.to
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/contract/test/CrepeFastCCTP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ contract CrepeFastCCTPTest is Test {
nonce: _nonce
});

vm.expectEmit();
emit CrepeFastCCTP.ActionCompleted(HANDOFF_ADDR, _bob);
fc.fastFinishAction({
destination: destination,
swapCall: Call({to: address(0), value: 0, data: ""})
Expand Down
38 changes: 38 additions & 0 deletions packages/daimo-contract/src/codegen/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,44 @@ export const crepeFastCctpAbi = [
],
stateMutability: 'view',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'handoffAddr',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'refundAddress',
internalType: 'address',
type: 'address',
indexed: true,
},
],
name: 'ActionBounced',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'handoffAddr',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'destinationAddress',
internalType: 'address',
type: 'address',
indexed: true,
},
],
name: 'ActionCompleted',
},
{
type: 'event',
anonymous: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/daimo-contract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const daimoFastCctpAddrs: Address[] = [

/** Daimo Pay FastCCTP address */
export const crepeFastCctpAddress =
"0x1C19B74cF09BBbb80AdE88F33F053bd09872Ac6F";
"0x5575a46Ad9930e6E8C3327CEA8325878ba533d05";
/** Daimo Pay factory address */
export const crepeHandoffFactoryAddress =
"0x8B7bB875169B6fd583A7AD36f5025Af970818E02";
Expand Down

0 comments on commit 185b387

Please sign in to comment.