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>
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import { ethers } from 'ethers';
|
|
import {
|
|
usdStringToE8,
|
|
mapPaymentLeafToCanonical,
|
|
type CanonicalPaymentMessage,
|
|
} from '@dbis/checkpoint-core';
|
|
import type { PaymentLeaf } from './ingress/types';
|
|
import { effectiveValue } from './leafCodec';
|
|
|
|
const REGISTRY_V2_ABI = [
|
|
'function recordBatch(uint64 batchId, tuple(bytes32 txHash,address from,address to,uint256 valueWei,uint256 blockNumber138,uint64 blockTimestamp138,uint64 valueUsdE8,uint32 logCount,bytes32 receiptHash,bytes32 instructionId,bytes32 endToEndIdHash,bytes32 uetr,bytes32 payloadHash,uint8 msgTypeCode,bytes32 debtorRefHash,bytes32 creditorRefHash,bytes32 purposeHash)[] records) external',
|
|
'function recorded(bytes32) view returns (bool)',
|
|
];
|
|
|
|
function isoRecord(leaf: PaymentLeaf, iso: CanonicalPaymentMessage) {
|
|
const usd = leaf.totalTransfersUsd ?? leaf.valueUsd ?? leaf.nativeValueUsd ?? '0';
|
|
return {
|
|
txHash: leaf.txHash,
|
|
from: leaf.from,
|
|
to: leaf.to,
|
|
valueWei: effectiveValue(leaf),
|
|
blockNumber138: BigInt(leaf.blockNumber),
|
|
blockTimestamp138: BigInt(leaf.blockTimestamp),
|
|
valueUsdE8: usdStringToE8(usd),
|
|
logCount: leaf.logCount ?? 0,
|
|
receiptHash: leaf.receiptHash ?? ethers.ZeroHash,
|
|
instructionId: iso.instructionIdBytes32,
|
|
endToEndIdHash: iso.endToEndIdHash,
|
|
uetr: iso.uetrBytes32,
|
|
payloadHash: iso.payloadHash,
|
|
msgTypeCode: iso.msgTypeCode,
|
|
debtorRefHash: iso.debtorRefHash,
|
|
creditorRefHash: iso.creditorRefHash,
|
|
purposeHash: iso.purposeHash,
|
|
};
|
|
}
|
|
|
|
export async function recordIsoAttestationBatch(
|
|
wallet: ethers.Wallet,
|
|
registryV2Address: string,
|
|
batchId: bigint,
|
|
leaves: PaymentLeaf[]
|
|
): Promise<string | null> {
|
|
if (!registryV2Address || leaves.length === 0) return null;
|
|
const registry = new ethers.Contract(registryV2Address, REGISTRY_V2_ABI, wallet);
|
|
const pending: Array<{ leaf: PaymentLeaf; iso: CanonicalPaymentMessage }> = [];
|
|
for (const leaf of leaves) {
|
|
if (!leaf.txHash) continue;
|
|
try {
|
|
if (await registry.recorded(leaf.txHash)) continue;
|
|
} catch {
|
|
/* continue */
|
|
}
|
|
const iso = leaf.iso20022 ?? mapPaymentLeafToCanonical(leaf);
|
|
pending.push({ leaf, iso });
|
|
}
|
|
if (pending.length === 0) return null;
|
|
const records = pending.map(({ leaf, iso }) => isoRecord(leaf, iso));
|
|
const tx = await registry.recordBatch(batchId, records, { gasLimit: 3_500_000n });
|
|
await tx.wait();
|
|
return tx.hash as string;
|
|
}
|