Skip to content

Commit

Permalink
chore: cleaned code changed event name
Browse files Browse the repository at this point in the history
  • Loading branch information
leeftk committed Nov 27, 2024
1 parent af46f21 commit 4aa8384
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 192 deletions.
45 changes: 36 additions & 9 deletions src/modules/paymentProcessor/PP_Connext_Crosschain_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {CrossChainBase_v1} from
"src/modules/paymentProcessor/abstracts/CrossChainBase_v1.sol";
import {ICrossChainBase_v1} from
"src/modules/paymentProcessor/interfaces/ICrosschainBase_v1.sol";
import {IPP_Connext_Crosschain_v1} from
"src/modules/paymentProcessor/interfaces/IPP_Connext_Crosschain_v1.sol";
import {IERC20PaymentClientBase_v1} from
"@lm/interfaces/IERC20PaymentClientBase_v1.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
Expand All @@ -16,9 +18,23 @@ import {IOrchestrator_v1} from
"src/orchestrator/interfaces/IOrchestrator_v1.sol";
import {Module_v1} from "src/modules/base/Module_v1.sol";

/// @title PP_Connext_Crosschain_v1
/// @notice Payment processor implementation for cross-chain payments using Connext
/// @dev Extends PP_Crosschain_v1 to handle cross-chain token transfers
/**
* @title Connext Cross-chain Payment Processor
*
* @notice Payment processor implementation for cross-chain payments using the Connext protocol.
*
* @dev This contract implements cross-chain payment processing via Connext and provides:
* - Integration with Connext's EverClear protocol for cross-chain transfers
* - WETH handling for native token wrapping
* - Implementation of bridge-specific transfer logic
* - Payment order processing and validation
* - Bridge data storage and retrieval
* - Support for Base network (chainId: 8453)
*
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to our Security Policy
* at security.inverter.network
*/
contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
IEverclearSpoke public everClearSpoke;
IWETH public weth;
Expand Down Expand Up @@ -50,6 +66,11 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
) internal override returns (bytes memory) {
//@notice call the connextBridgeLogic to execute the bridge transfer
bytes32 intentId = xcall(order, executionData);
if (intentId == bytes32(0)) {
revert Module__PP_Crosschain__MessageDeliveryFailed(
8453, 8453, executionData
);
}
return abi.encode(intentId);
}

Expand All @@ -69,11 +90,14 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
_executeBridgeTransfer(orders[i], executionData);

_bridgeData[i] = bridgeData;
emit PaymentProcessed(
_paymentId,
emit PaymentOrderProcessed(
address(client),
orders[i].recipient,
orders[i].paymentToken,
orders[i].amount
orders[i].amount,
orders[i].start,
orders[i].cliff,
orders[i].end
);
_paymentId++;

Expand Down Expand Up @@ -102,10 +126,13 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
if (order.recipient == address(0)) {
revert ICrossChainBase_v1.Module__CrossChainBase__InvalidRecipient();
}

// Decode the execution data
(uint maxFee, uint ttl) = abi.decode(executionData, (uint, uint));

if (ttl == 0) {
revert ICrossChainBase_v1.Module__CrossChainBase_InvalidTTL();
revert
IPP_Connext_Crosschain_v1
.Module__PP_Connext_Crosschain__InvalidTTL();
}

// Wrap ETH into WETH to send with the xcall
Expand Down Expand Up @@ -143,7 +170,7 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
/// @param paymentId The unique identifier of the payment
/// @return The bridge data associated with the payment (encoded intentId)
function getBridgeData(uint paymentId)
external
public
view
override
returns (bytes memory)
Expand Down
92 changes: 0 additions & 92 deletions src/modules/paymentProcessor/abstracts/CrossChainBase_v1.sol

This file was deleted.

46 changes: 14 additions & 32 deletions src/modules/paymentProcessor/abstracts/CrosschainBase_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ import {IPaymentProcessor_v1} from "@pp/IPaymentProcessor_v1.sol";
import {IERC20PaymentClientBase_v1} from
"@lm/interfaces/IERC20PaymentClientBase_v1.sol";
import {Module_v1} from "src/modules/base/Module_v1.sol";
//import {IPP_CrossChain_v1} from "./IPP_Template_v1.sol";
import {ERC165Upgradeable, Module_v1} from "src/modules/base/Module_v1.sol";
import {ICrossChainBase_v1} from "../interfaces/ICrosschainBase_v1.sol";
/**
* @title Inverter Template Payment Processor
* @title Cross-chain Base Contract
*
* @notice Basic template payment processor used as base for developing new payment processors.
* @notice Abstract base contract providing core cross-chain functionality for payment processors.
*
* @dev This contract is used to showcase a basic setup for a payment processor. The contract showcases the
* following:
* - Inherit from the Module_v1 contract to enable interaction with the Inverter workflow.
* - Use of the IPaymentProcessor_v1 interface to facilitate interaction with a payment client.
* - Implement custom interface which has all the public facing functions, errors, events and structs.
* - Pre-defined layout for all contract functions, modifiers, state variables etc.
* - Use of the ERC165Upgradeable contract to check for interface support.
* @dev This contract implements fundamental cross-chain operations and provides:
* - Bridge data storage and retrieval functionality
* - Abstract interface for bridge transfer execution
* - Integration with the Module_v1 base contract
* - Implementation of ICrossChainBase_v1 interface
* - ERC165 interface support for cross-chain functionality
*
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to our Security Policy
Expand All @@ -32,8 +30,8 @@ import {ICrossChainBase_v1} from "../interfaces/ICrosschainBase_v1.sol";

abstract contract CrossChainBase_v1 is ICrossChainBase_v1, Module_v1 {
mapping(uint => bytes) internal _bridgeData;
/// @inheritdoc ERC165Upgradeable

/// @inheritdoc ERC165Upgradeable
function supportsInterface(bytes4 interfaceId_)
public
view
Expand All @@ -44,18 +42,6 @@ abstract contract CrossChainBase_v1 is ICrossChainBase_v1, Module_v1 {
return interfaceId_ == type(ICrossChainBase_v1).interfaceId
|| super.supportsInterface(interfaceId_);
}
//--------------------------------------------------------------------------
// State

/// @dev The number of payment orders.
uint internal _paymentId;

//--------------------------------------------------------------------------
// Events

event PaymentProcessed(
uint indexed paymentId, address recipient, address token, uint amount
);

//--------------------------------------------------------------------------
// Virtual Functions
Expand All @@ -67,13 +53,10 @@ abstract contract CrossChainBase_v1 is ICrossChainBase_v1, Module_v1 {
function _executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) internal virtual returns (bytes memory) {
emit BridgeTransferExecuted(executionData);
return bytes("");
}
) internal virtual returns (bytes memory) {}

/// @notice Process payments for a given payment client
/// @param client The payment client to process payments for

function processPayments(IERC20PaymentClientBase_v1 client)
external
virtual
Expand All @@ -83,10 +66,9 @@ abstract contract CrossChainBase_v1 is ICrossChainBase_v1, Module_v1 {
/// @param paymentId The ID of the payment to get the bridge data for
/// @return The bridge data for the given payment ID
function getBridgeData(uint paymentId)
external
public
view
virtual
returns (bytes memory)
{
return _bridgeData[paymentId];
}
{}
}
20 changes: 11 additions & 9 deletions src/modules/paymentProcessor/abstracts/PP_Crosschain_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
import {IPP_Crosschain_v1} from "../interfaces/IPP_Crosschain_v1.sol";

/**
* @title Inverter Template Payment Processor
* @title Cross-chain Payment Processor Base Contract
*
* @notice Basic template payment processor used as base for developing new payment processors.
* @notice Abstract base contract for implementing cross-chain payment processing functionality.
*
* @dev This contract is used to showcase a basic setup for a payment processor. The contract showcases the
* following:
* - Inherit from the Module_v1 contract to enable interaction with the Inverter workflow.
* - Use of the IPaymentProcessor_v1 interface to facilitate interaction with a payment client.
* - Implement custom interface which has all the public facing functions, errors, events and structs.
* - Pre-defined layout for all contract functions, modifiers, state variables etc.
* - Use of the ERC165Upgradeable contract to check for interface support.
* @dev This contract serves as the base for cross-chain payment processors and provides:
* - Extension of CrossChainBase_v1 for cross-chain functionality
* - Implementation of IPP_Crosschain_v1 interface
* - Core payment validation logic
* - Basic security checks for payment processing
* - Abstract functions for bridge-specific implementations
*
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to our Security Policy
Expand Down Expand Up @@ -81,6 +80,9 @@ abstract contract PP_Crosschain_v1 is CrossChainBase_v1, IPP_Crosschain_v1 {
/// @dev Gap for possible future upgrades.
uint[50] private __gap;

//@dev paymentId
uint public _paymentId;

//--------------------------------------------------------------------------
// Virtual Functions

Expand Down
28 changes: 15 additions & 13 deletions src/modules/paymentProcessor/interfaces/ICrosschainBase_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ pragma solidity ^0.8.0;
import {IERC20PaymentClientBase_v1} from
"@lm/interfaces/IERC20PaymentClientBase_v1.sol";

/// @title ICrossChainBase_v1
/// @notice Base interface for cross-chain payment processing functionality
interface ICrossChainBase_v1 {
//--------------------------------------------------------------------------
// Structs

/// @notice Struct to hold cross-chain message data
/// @param messageId Unique identifier for the cross-chain message
/// @param sourceChain Address or identifier of the source chain
/// @param targetChain Address or identifier of the target chain
/// @param payload The encoded data being sent across chains
/// @param executed Boolean flag indicating if the message has been processed
struct CrossChainMessage {
uint messageId;
address sourceChain;
Expand All @@ -24,32 +28,30 @@ interface ICrossChainBase_v1 {
// Events

/// @notice Emitted when a bridge transfer is executed
/// @param bridgeData The encoded data of the bridge transfer
event BridgeTransferExecuted(bytes indexed bridgeData);

//--------------------------------------------------------------------------
// Errors

/// @notice Amount can not be zero.
/// @notice Thrown when attempting to process a transfer with zero amount
error Module__CrossChainBase__InvalidAmount();

/// @notice Client is not valid.
/// @notice Thrown when an unauthorized client attempts to interact with the contract
error Module__CrossChainBase__NotValidClient();

/// @notice Message has already been executed
/// @notice Thrown when attempting to execute a message that has already been processed
error Module__CrossChainBase_MessageAlreadyExecuted();

/// @notice Invalid TTL provided
error Module__CrossChainBase_InvalidTTL();

/// @notice Invalid chain ID provided
/// @notice Thrown when an unsupported or invalid chain ID is provided
error Module__CrossChainBase_InvalidChainId();

/// @notice Message verification failed
/// @notice Thrown when the cross-chain message fails verification
error Module__CrossChainBase_MessageVerificationFailed();

/// @notice Invalid execution data
/// @notice Thrown when the provided execution data is malformed or invalid
error Module__CrossChainBase_InvalidExecutionData();

/// @notice Invalid recipient
/// @notice Thrown when the recipient address is invalid or not allowed
error Module__CrossChainBase__InvalidRecipient();
}
13 changes: 0 additions & 13 deletions src/modules/paymentProcessor/interfaces/IPP_Connext_Crosschain.sol

This file was deleted.

Loading

0 comments on commit 4aa8384

Please sign in to comment.