Skip to content

Commit

Permalink
Merge pull request #15 from connext/event-signatures
Browse files Browse the repository at this point in the history
Event signatures
  • Loading branch information
Rahul Sethuram authored Jul 7, 2021
2 parents fb89542 + 4619988 commit 1a682f0
Show file tree
Hide file tree
Showing 47 changed files with 1,449 additions and 856 deletions.
50 changes: 39 additions & 11 deletions packages/contracts/contracts/TransactionManager.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.4;

import "./interfaces/IFulfillHelper.sol";
import "./interfaces/ITransactionManager.sol";
import "./lib/LibAsset.sol";
import "./lib/LibERC20.sol";
import "./interpreters/MultisendInterpreter.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

Expand Down Expand Up @@ -72,14 +72,10 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
/// @dev The chain id of the contract, is passed in to avoid any evm issues
uint256 public immutable chainId;

/// @dev Address of the deployed multisending interpreter contract
address public immutable iMultisend;

/// @dev Minimum timeout (will be the lowest on the receiving chain)
uint256 public constant MIN_TIMEOUT = 24 hours;

constructor(address _iMultisend, uint256 _chainId) {
iMultisend = _iMultisend;
constructor(uint256 _chainId) {
chainId = _chainId;
}

Expand Down Expand Up @@ -267,6 +263,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
sendingAssetId: invariantData.sendingAssetId,
receivingAssetId: invariantData.receivingAssetId,
sendingChainFallback: invariantData.sendingChainFallback,
callTo: invariantData.callTo,
receivingAddress: invariantData.receivingAddress,
callDataHash: invariantData.callDataHash,
transactionId: invariantData.transactionId,
Expand All @@ -276,7 +273,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
expiry: expiry,
preparedBlockNumber: block.number
});
emit TransactionPrepared(txData, msg.sender, encryptedCallData, encodedBid, bidSignature);
emit TransactionPrepared(txData.user, txData.router, txData.transactionId, txData, msg.sender, encryptedCallData, encodedBid, bidSignature);
return txData;
}

Expand Down Expand Up @@ -370,7 +367,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
}

// Handle receiver chain external calls if needed
if (txData.callDataHash == keccak256(new bytes(0))) {
if (txData.callTo == address(0)) {
// No external calls, send directly to receiving address
require(
LibAsset.transferAsset(txData.receivingAssetId, payable(txData.receivingAddress), toSend),
Expand All @@ -380,8 +377,38 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
// Handle external calls with a fallback to the receiving
// address in case the call fails so the funds dont remain
// locked.

// First, approve the funds to the helper if needed
if (LibAsset.isEther(txData.receivingAssetId) && toSend > 0) {
require(LibERC20.approve(txData.receivingAssetId, txData.callTo, toSend), "fulfill: APPROVAL_FAILED");
}

// Next, call `addFunds` on the helper. Helpers should internally
// track funds to make sure no one user is able to take all funds
// for tx
if (toSend > 0) {
try
IFulfillHelper(txData.callTo).addFunds{ value: LibAsset.isEther(txData.receivingAssetId) ? toSend : 0}(
txData.user,
txData.transactionId,
txData.receivingAssetId,
toSend
)
{} catch {
// Regardless of error within the callData execution, send funds
// to the predetermined fallback address
require(
LibAsset.transferAsset(txData.receivingAssetId, payable(txData.receivingAddress), toSend),
"fulfill: TRANSFER_FAILED"
);
}
}

// Call `execute` on the helper
try
MultisendInterpreter(iMultisend).execute{value: LibAsset.isEther(txData.receivingAssetId) ? toSend : 0}(
IFulfillHelper(txData.callTo).execute(
txData.user,
txData.transactionId,
txData.receivingAssetId,
toSend,
callData
Expand All @@ -398,7 +425,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
}

// Emit event
emit TransactionFulfilled(txData, relayerFee, signature, callData, msg.sender);
emit TransactionFulfilled(txData.user, txData.router, txData.transactionId, txData, relayerFee, signature, callData, msg.sender);

return txData;
}
Expand Down Expand Up @@ -507,7 +534,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
}

// Emit event
emit TransactionCancelled(txData, relayerFee, msg.sender);
emit TransactionCancelled(txData.user, txData.router, txData.transactionId, txData, relayerFee, msg.sender);

// Return
return txData;
Expand Down Expand Up @@ -592,6 +619,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
sendingAssetId: txData.sendingAssetId,
receivingAssetId: txData.receivingAssetId,
sendingChainFallback: txData.sendingChainFallback,
callTo: txData.callTo,
receivingAddress: txData.receivingAddress,
sendingChainId: txData.sendingChainId,
receivingChainId: txData.receivingChainId,
Expand Down
19 changes: 19 additions & 0 deletions packages/contracts/contracts/interfaces/IFulfillHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.4;

interface IFulfillHelper {
function addFunds(
address user,
bytes32 transactionId,
address assetId,
uint256 amount
) external payable;

function execute(
address user,
bytes32 transactionId,
address assetId,
uint256 amount,
bytes calldata callData
) external;
}
10 changes: 0 additions & 10 deletions packages/contracts/contracts/interfaces/IMultisendInterpreter.sol

This file was deleted.

37 changes: 32 additions & 5 deletions packages/contracts/contracts/interfaces/ITransactionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface ITransactionManager {
address receivingAssetId;
address sendingChainFallback; // funds sent here on cancel
address receivingAddress;
address callTo;
uint256 sendingChainId;
uint256 receivingChainId;
bytes32 callDataHash; // hashed to prevent free option
Expand All @@ -37,6 +38,7 @@ interface ITransactionManager {
address receivingAssetId;
address sendingChainFallback;
address receivingAddress;
address callTo;
bytes32 callDataHash;
bytes32 transactionId;
uint256 sendingChainId;
Expand Down Expand Up @@ -65,11 +67,36 @@ interface ITransactionManager {
event LiquidityRemoved(address router, address assetId, uint256 amount, address recipient);

// Transaction events
event TransactionPrepared(TransactionData txData, address caller, bytes encryptedCallData, bytes encodedBid, bytes bidSignature);

event TransactionFulfilled(TransactionData txData, uint256 relayerFee, bytes signature, bytes callData, address caller);

event TransactionCancelled(TransactionData txData, uint256 relayerFee, address caller);
event TransactionPrepared(
address user,
address router,
bytes32 transactionId,
TransactionData txData,
address caller,
bytes encryptedCallData,
bytes encodedBid,
bytes bidSignature
);

event TransactionFulfilled(
address user,
address router,
bytes32 transactionId,
TransactionData txData,
uint256 relayerFee,
bytes signature,
bytes callData,
address caller
);

event TransactionCancelled(
address user,
address router,
bytes32 transactionId,
TransactionData txData,
uint256 relayerFee,
address caller
);

// Router only methods
function addLiquidity(uint256 amount, address assetId) external payable;
Expand Down
39 changes: 0 additions & 39 deletions packages/contracts/contracts/interpreters/MultisendInterpreter.sol

This file was deleted.

13 changes: 1 addition & 12 deletions packages/contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment): Promise<voi
}
console.log("deployer: ", deployer);

const multisend = await hre.deployments.deploy("MultiSendCallOnly", {
from: deployer,
log: true,
});

const interpreter = await hre.deployments.deploy("MultisendInterpreter", {
from: deployer,
args: [multisend.address],
log: true,
});

await hre.deployments.deploy("TransactionManager", {
from: deployer,
args: [interpreter.address, chainId],
args: [chainId],
log: true,
});

Expand Down
50 changes: 25 additions & 25 deletions packages/contracts/deployments/goerli/TestERC20.json

Large diffs are not rendered by default.

Loading

0 comments on commit 1a682f0

Please sign in to comment.