Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m3s
CI/CD Pipeline / Security Scanning (push) Successful in 2m18s
CI/CD Pipeline / Lint and Format (push) Failing after 34s
CI/CD Pipeline / Terraform Validation (push) Failing after 20s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 22s
Deploy ChainID 138 / Deploy ChainID 138 (push) Failing after 40s
HYBX OMNL TypeScript & anchor / token-aggregation build + reconcile artifact (push) Failing after 49s
OMNL reconcile anchor / Run omnl:reconcile and upload artifacts (push) Failing after 21s
Validation / validate-genesis (push) Successful in 25s
Validation / validate-terraform (push) Failing after 21s
Validation / validate-kubernetes (push) Failing after 8s
Validation / validate-smart-contracts (push) Failing after 8s
Validation / validate-security (push) Failing after 1m11s
Validation / validate-documentation (push) Failing after 14s
Verify Deployment / Verify Deployment (push) Failing after 45s
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 <cursoragent@cursor.com>
84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import { ethers } from 'ethers';
|
|
import {
|
|
buildMerkleRoot,
|
|
effectiveTokenOrNativeWei,
|
|
paymentLeafV1Hash,
|
|
} from '@dbis/checkpoint-core';
|
|
import type { PaymentLeaf } from './ingress/types';
|
|
|
|
export function effectiveValue(leaf: PaymentLeaf): bigint {
|
|
return effectiveTokenOrNativeWei(leaf);
|
|
}
|
|
|
|
export function leafHashes(chainId: number, leaves: PaymentLeaf[]): string[] {
|
|
return leaves.map((l) =>
|
|
paymentLeafV1Hash(chainId, {
|
|
txHash: l.txHash,
|
|
from: l.from,
|
|
to: l.to,
|
|
value: effectiveValue(l),
|
|
blockNumber: l.blockNumber,
|
|
blockTimestamp: l.blockTimestamp,
|
|
gasUsed: l.gasUsed,
|
|
success: l.success,
|
|
})
|
|
);
|
|
}
|
|
|
|
export function paymentsRoot(chainId: number, leaves: PaymentLeaf[]): string {
|
|
return buildMerkleRoot(leafHashes(chainId, leaves));
|
|
}
|
|
|
|
const PAYMENT_LEAF_TUPLE =
|
|
'tuple(bytes32,address,address,uint256,uint256,uint64,uint256,bool)';
|
|
|
|
export function leavesToTuples(leaves: PaymentLeaf[]): [
|
|
string,
|
|
string,
|
|
string,
|
|
bigint,
|
|
bigint,
|
|
bigint,
|
|
bigint,
|
|
boolean,
|
|
][] {
|
|
return leaves.map((l) => [
|
|
l.txHash,
|
|
l.from,
|
|
l.to,
|
|
effectiveValue(l),
|
|
BigInt(l.blockNumber),
|
|
BigInt(l.blockTimestamp),
|
|
l.gasUsed,
|
|
l.success,
|
|
]);
|
|
}
|
|
|
|
export function encodeExtensionLeavesV1(leaves: PaymentLeaf[]): string {
|
|
return ethers.AbiCoder.defaultAbiCoder().encode(
|
|
[PAYMENT_LEAF_TUPLE + '[]'],
|
|
[leavesToTuples(leaves)]
|
|
);
|
|
}
|
|
|
|
export function encodeExtensionLeavesV2(leaves: PaymentLeaf[]): string {
|
|
const PAYMENT_LEAF_V2_TUPLE =
|
|
'tuple(bytes32,address,address,address,uint256,uint256,uint64,uint256,bool,uint32)';
|
|
const tuples = leaves.map((l) => [
|
|
l.txHash,
|
|
l.from,
|
|
l.to,
|
|
l.token ?? ethers.ZeroAddress,
|
|
effectiveValue(l),
|
|
BigInt(l.blockNumber),
|
|
BigInt(l.blockTimestamp),
|
|
l.gasUsed,
|
|
l.success,
|
|
l.tokenLogIndex ?? 0,
|
|
]);
|
|
return ethers.AbiCoder.defaultAbiCoder().encode(
|
|
['bytes1', PAYMENT_LEAF_V2_TUPLE + '[]'],
|
|
[ethers.toBeHex(0x02, 1), tuples]
|
|
);
|
|
}
|