Skip to content

Commit a9db6c4

Browse files
committed
cloud_functions: handle bigint amount
1 parent b2f4b82 commit a9db6c4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cloud_functions/src/alarmFastTransfer.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export async function alarmFastTransfer(req: any, res: any) {
5454
// This cloud function is scheduled to run every 30 minutes.
5555
const alertOrders: DisplayRow[] = await getDelayedOrders();
5656
for (const order of alertOrders) {
57-
const formattedAmountIn = (Number(order.amountIn) / 1_000_000).toFixed(2);
58-
const formattedAmountOut = (Number(order.amountOut) / 1_000_000).toFixed(2);
57+
const formattedAmountIn = formatBigInt(order.amountIn);
58+
const formattedAmountOut = formatBigInt(order.amountOut);
5959
alarmSlackInfo.msg =
6060
`🚨 Delayed Order Alert!\n` +
6161
`Source Chain: ${order.sourceChain}\n` +
@@ -77,6 +77,11 @@ export async function alarmFastTransfer(req: any, res: any) {
7777
return;
7878
}
7979

80+
const formatBigInt = (amt: bigint) => {
81+
const str = (amt / 10_000n).toString().padStart(3, '0');
82+
return str.substring(0, str.length - 2) + '.' + str.substring(str.length - 2);
83+
};
84+
8085
async function getDelayedOrders(): Promise<DisplayRow[]> {
8186
console.log('getDelayedOrders');
8287
const result = await pg
@@ -112,11 +117,11 @@ async function getDelayedOrders(): Promise<DisplayRow[]> {
112117

113118
type DisplayRow = {
114119
sourceChain: number; // from fast_vaa_id
115-
sequence: BigInt; // from fast_vaa_id
120+
sequence: bigint; // from fast_vaa_id
116121
status: string; // from MarketOrder
117122
market_order_timestamp: Date; // from MarketOrder
118123
destinationChain: number; // from MarketOrder
119124
executionTime: number; // execution_time - market_order_timestamp
120-
amountIn: BigInt; // from MarketOrder
121-
amountOut: BigInt; // from FastTransferExecutions
125+
amountIn: bigint; // from MarketOrder
126+
amountOut: bigint; // from FastTransferExecutions
122127
};

0 commit comments

Comments
 (0)