Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/cre-sdk-examples/src/workflows/proof-of-reserve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface PORResponse {

interface ReserveInfo {
lastUpdated: Date;
totalReserve: bigint;
totalReserve: number;
}

// Utility function to safely stringify objects with bigints
Expand Down Expand Up @@ -79,7 +79,7 @@ const fetchReserveInfo = (

return {
lastUpdated: new Date(porResp.updatedAt),
totalReserve: BigInt(Math.floor(porResp.totalToken * 1e18)), // Scale to 18 decimals
totalReserve: porResp.totalToken
};
};

Expand Down Expand Up @@ -240,16 +240,17 @@ const updateReserves = (
})
.result();

const txHash = resp.txHash;
// TODO: Why does the writeReport fail with an "execution reverted" error?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ernest-nowacki I can't tell if the abi function is not correct or if the Go side is doing something tricky here. I can run through this step in Go, but here I always get an "execution reverted" error. How did you generate the writeReportFromUpdateReserves call in abi.ts?

const txHash = resp.txHash || Uint8Array.from('0x000000000000000000000000000000')

if (!txHash) {
throw new Error("Failed to write report");
throw new Error(`Failed to write report: ${resp.errorMessage}`)
}

runtime.log(
`Write report transaction succeeded at txHash: ${txHash.toString()}`
`Write report transaction succeeded at txHash: ${bytesToHex(txHash)}`
);
return txHash.toString();
return txHash.toString()
};

const doPOR = (runtime: Runtime<Config>): string => {
Expand All @@ -272,8 +273,7 @@ const doPOR = (runtime: Runtime<Config>): string => {
const totalSupply = getTotalSupply(runtime);
runtime.log(`TotalSupply ${totalSupply.toString()}`);

const totalReserveScaled = (reserveInfo as unknown as ReserveInfo)
.totalReserve;
const totalReserveScaled = BigInt(reserveInfo.totalReserve * 1e18);
Copy link
Contributor Author

@jeffrifwaldsmartcontract jeffrifwaldsmartcontract Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scale here to 18 decimals instead of in fetchReserveInfo to match the Go workflow

runtime.log(`TotalReserveScaled ${totalReserveScaled.toString()}`);

const nativeTokenBalance = fetchNativeTokenBalance(
Expand All @@ -293,7 +293,7 @@ const doPOR = (runtime: Runtime<Config>): string => {

updateReserves(runtime, totalSupply, totalReserveScaled);

return totalReserveScaled.toString();
return reserveInfo.totalReserve.toString();
};

const getLastMessage = (
Expand Down Expand Up @@ -356,6 +356,8 @@ const onCronTrigger = (
throw new Error("Scheduled execution time is required");
}

runtime.log('Running CronTrigger');

return doPOR(runtime);
};

Expand Down Expand Up @@ -397,11 +399,11 @@ const onHTTPTrigger = (
return doPOR(runtime);
}

// Log the raw JSON for debugging
runtime.log("Payload bytes");
// Log the raw JSON for debugging (human-readable).
runtime.log(`Payload bytes payloadBytes ${payload.input.toString()}`)

try {
runtime.log("Parsed HTTP trigger received");
runtime.log(`Parsed HTTP trigger received payload ${payload.input.toString()}`);
return doPOR(runtime);
} catch (error) {
runtime.log("Failed to parse HTTP trigger payload");
Expand All @@ -412,7 +414,6 @@ const onHTTPTrigger = (
const initWorkflow = (config: Config) => {
const cronTrigger = new cre.capabilities.CronCapability();
const httpTrigger = new cre.capabilities.HTTPCapability();

const network = getNetwork({
chainFamily: "evm",
chainSelectorName: config.evms[0].chainSelectorName,
Expand Down