Files
smom-dbis-138/contracts/mainnet-checkpoint/libraries/CheckpointPaymentsLib.sol
T
defiQUGandCursor 651fb59786 Add mainnet checkpoint stack: ISO attestation, participant Etherscan surface, and services.
Ship AddressActivityRegistry V1/V2, ISO20022IntakeGateway, Chain138ParticipantSurface,
checkpoint hub contracts, checkpoint-core package, aggregator/indexer/sdk services,
relay profile guards, M00 diamond bridge facet, and OMNL compliance contracts.

Co-authored-by: Cursor <[email protected]>
2026-06-24 21:54:05 -07:00

43 lines
1.8 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {CheckpointLeaf} from "./CheckpointLeaf.sol";
import {CheckpointErrors} from "./CheckpointErrors.sol";
/// @notice External library to keep hub implementation under 24KB (EIP-170).
library CheckpointPaymentsLib {
function assertPaymentsRootV1(
uint64 chainId,
bytes32 paymentsRoot,
CheckpointLeaf.PaymentLeafV1[] calldata leaves
) external pure {
if (leaves.length == 0) revert CheckpointErrors.LeavesEmpty();
bytes32[] memory hashes = new bytes32[](leaves.length);
for (uint256 i = 0; i < leaves.length; i++) {
hashes[i] = CheckpointLeaf.paymentLeafV1(chainId, leaves[i]);
}
if (CheckpointLeaf.buildMerkleRoot(hashes) != paymentsRoot) revert CheckpointErrors.RootMismatch();
}
function assertPaymentsRootV2(
uint64 chainId,
bytes32 paymentsRoot,
CheckpointLeaf.PaymentLeafV2[] calldata leaves
) external pure {
if (leaves.length == 0) revert CheckpointErrors.LeavesEmpty();
bytes32[] memory hashes = new bytes32[](leaves.length);
for (uint256 i = 0; i < leaves.length; i++) {
hashes[i] = CheckpointLeaf.paymentLeafV2(chainId, leaves[i]);
}
if (CheckpointLeaf.buildMerkleRoot(hashes) != paymentsRoot) revert CheckpointErrors.RootMismatch();
}
function enforceMinPaymentValueV1(bytes calldata extensionData, uint256 minWei) external pure {
if (minWei == 0 || extensionData.length == 0) return;
CheckpointLeaf.PaymentLeafV1[] memory leaves = abi.decode(extensionData, (CheckpointLeaf.PaymentLeafV1[]));
for (uint256 i = 0; i < leaves.length; i++) {
if (leaves[i].value < minWei) revert CheckpointErrors.BelowMinPayment();
}
}
}