From 42ef5e8acd920e11dcf65855ee205c69662769fe Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 12 Dec 2024 13:53:03 +0200 Subject: [PATCH 1/4] Update l2->l3 withdrawls. --- api/src/config.ts | 3 + api/src/services/bridge.service.ts | 90 ++++++++++++++---------------- 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/api/src/config.ts b/api/src/config.ts index c2387aed..95238834 100644 --- a/api/src/config.ts +++ b/api/src/config.ts @@ -67,6 +67,7 @@ export const bridgeConfig: { addressL2ERC20Gateway: string; addressL2GatewayRouter: string; addressL1GatewayRouter: string; + addressL3GatewayRouter: string; addressArbitrumOutBox: string; addressArbOS: string; addressL1Inbox: string; @@ -87,6 +88,7 @@ export const bridgeConfig: { addressL2ERC20Gateway: "6e244cD02BBB8a6dbd7F626f05B2ef82151Ab502", // Arbitrum L2ERC20Gateway address addressL2GatewayRouter: "9fDD1C4E4AA24EEc1d913FABea925594a20d43C7", // Arbitrum L2ERC20Gateway address addressL1GatewayRouter: "cE18836b233C83325Cc8848CA4487e94C6288264", // Ethereum deposit address + addressL3GatewayRouter: "DA379C01a484fB9F0875730430a418eB8AAFdca2", // L3 Gateway Router address addressArbitrumOutBox: "64105c6C3D494469D5F21323F0E917563489d9f5", // Arbitrum outbox address ?? addressArbOS: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address addressL1Inbox: "aAe29B0366299461418F5324a79Afc425BE5ae21", // Ethereum inbox address @@ -106,6 +108,7 @@ export const bridgeConfig: { addressL2ERC20Gateway: "096760F208390250649E3e8763348E783AEF5562", // Arbitrum L2ERC20Gateway address L1OrbitERC20Gateway addressL2GatewayRouter: "5288c571Fd7aD117beA99bF60FE0846C4E84F933", // Arbitrum L2ERC20Gateway address L1OrbitGatewayRouter addressL1GatewayRouter: "72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef", // Ethereum deposit address + addressL3GatewayRouter: "0000000000000000000000000000000000000000", // L3 Gateway Router address addressArbitrumOutBox: "fbe537816d181888fAbE52338a5D921eE131E9Db", // Arbitrum outbox address ?? addressArbOS: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address addressL1Inbox: "4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f", // Ethereum inbox address diff --git a/api/src/services/bridge.service.ts b/api/src/services/bridge.service.ts index 4c6da442..20ab4f47 100644 --- a/api/src/services/bridge.service.ts +++ b/api/src/services/bridge.service.ts @@ -13,28 +13,51 @@ export async function getTransactionHistory(chain: string, address: string, limi try { const query = ` - WITH game7_withdrawal AS ( + WITH game7_withdrawal_calls AS ( + SELECT + transaction_hash, + COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, + '0x' || encode(origin_address, 'hex') AS origin_address, + label_data -> 'args' ->> '_amount' AS amount, + block_timestamp, + label_data ->> 'status' AS status + FROM + ${bridgeConfig[chain].l3TableName} AS labels + WHERE + (address, label_name) IN ( + (DECODE($1, 'hex'), 'withdrawEth'), + (DECODE($11, 'hex'), 'outboundTransfer') + ) + ), game7_withdrawal_events AS ( + SELECT + transaction_hash, + label_data -> 'args' ->> 'position' AS position, + label_data -> 'args' ->> 'callvalue' AS amount, + label_data -> 'args' ->> 'destination' AS to_address + FROM + ${bridgeConfig[chain].l3TableName} + WHERE + address = DECODE($1, 'hex') + ), game7_withdrawal AS ( SELECT 'WITHDRAWAL' AS type, - label_data->'args'->>'position' AS position, - label_data->'args'->>'callvalue' AS amount, + we.position AS position, + coalesce(wc.amount, we.amount) AS amount, ${bridgeConfig[chain].l3rleationship.parentNetworkChainId} AS parentNetworkChainId, ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, - transaction_hash AS childNetworkHash, - block_timestamp AS childNetworkTimestamp, - label_data->'args'->>'caller' AS from_address, - label_data->'args'->>'destination' AS to_address, + wc.transaction_hash AS childNetworkHash, + wc.block_timestamp AS childNetworkTimestamp, + wc.origin_address AS from_address, + we.to_address AS to_address, 3600 AS challengePeriod, - block_timestamp + 3600 AS claimableTimestamp, - '${bridgeConfig[chain].l3Token}' AS token, - block_timestamp AS block_timestamp - FROM ${bridgeConfig[chain].l3TableName} - WHERE - label = 'seer' AND - address = DECODE($1, 'hex') AND -- '0000000000000000000000000000000000000064' -- Game7 ArbOS L2 address - label_type = 'event' AND - label_name = 'L2ToL1Tx' - ), arbirtrum_claims as ( + (wc.block_timestamp + 3600) AS claimableTimestamp, + wc.block_timestamp AS block_timestamp, + wc.token AS token, + wc.status AS status + FROM + game7_withdrawal_calls wc + JOIN game7_withdrawal_events we ON we.transaction_hash = wc.transaction_hash + ),arbirtrum_claims as ( SELECT 'CLAIM' AS type, transaction_hash, @@ -53,32 +76,6 @@ export async function getTransactionHistory(chain: string, address: string, limi label_type = 'event' AND label_name = 'OutBoxTransactionExecuted' AND address = DECODE($2, 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address - ), game7_withdrawal_failed as ( - SELECT - 'WITHDRAWAL' AS type, - null AS position, - NULL AS amount, - ${bridgeConfig[chain].l3rleationship.parentNetworkChainId} AS parentNetworkChainId, - ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, - transaction_hash AS childNetworkHash, - block_timestamp AS childNetworkTimestamp, - label_data->'args'->>'caller' AS from_address, - null AS to_address, - 3600 AS challengePeriod, - block_timestamp + 3600 AS claimableTimestamp, - '${bridgeConfig[chain].l3Token}' AS token, - NULL::double precision AS completionTimestamp, - NULL::double precision AS parentNetworkTimestamp, - NULL AS parentNetworkHash, - false AS status, - block_timestamp AS block_timestamp - FROM ${bridgeConfig[chain].l3TableName} - WHERE - label = 'seer' AND - label_type = 'tx_call' AND - label_name = 'withdrawEth' AND - ADDRESS = DECODE($1, 'hex') AND -- '0000000000000000000000000000000000000064' -- Game7 ArbOS L2 address - (label_data->>'status' = '0' or label_data->'status' IS NULL) ), withdrawal_l3_l2 as ( SELECT 'WITHDRAWAL' AS type, @@ -101,11 +98,6 @@ export async function getTransactionHistory(chain: string, address: string, limi FROM game7_withdrawal LEFT JOIN arbirtrum_claims ON game7_withdrawal.position = arbirtrum_claims.position - UNION ALL - SELECT - * - FROM - game7_withdrawal_failed ), withdrawal_calls_arbitrum AS ( SELECT transaction_hash, @@ -371,7 +363,7 @@ export async function getTransactionHistory(chain: string, address: string, limi bridgeConfig[chain].addressERC20Inbox, bridgeConfig[chain].addressL1GatewayRouter, bridgeConfig[chain].addressL1Inbox, - address, offset, limit]) + address, offset, limit, bridgeConfig[chain].addressL3GatewayRouter]) // unpack the data from the result const data = result.rows.map((row: any) => row.data); return data; From 2fd3a8375e39f8c3f2fb6a1d1052ced09d464040 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 12 Dec 2024 14:22:54 +0200 Subject: [PATCH 2/4] Fix filter condition. --- api/src/services/bridge.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/services/bridge.service.ts b/api/src/services/bridge.service.ts index 20ab4f47..58376778 100644 --- a/api/src/services/bridge.service.ts +++ b/api/src/services/bridge.service.ts @@ -38,6 +38,7 @@ export async function getTransactionHistory(chain: string, address: string, limi ${bridgeConfig[chain].l3TableName} WHERE address = DECODE($1, 'hex') + AND label_name = 'L2ToL1Tx' ), game7_withdrawal AS ( SELECT 'WITHDRAWAL' AS type, @@ -56,7 +57,7 @@ export async function getTransactionHistory(chain: string, address: string, limi wc.status AS status FROM game7_withdrawal_calls wc - JOIN game7_withdrawal_events we ON we.transaction_hash = wc.transaction_hash + LEFT JOIN game7_withdrawal_events we ON we.transaction_hash = wc.transaction_hash ),arbirtrum_claims as ( SELECT 'CLAIM' AS type, From 52121653679b0fbbd71f62a778d2f008646db3d8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 19 Dec 2024 15:03:28 +0200 Subject: [PATCH 3/4] Add Circle and Symbol field. --- api/src/config.ts | 12 +- api/src/services/bridge.service.ts | 517 ++++++++++++++++++++++++++--- 2 files changed, 490 insertions(+), 39 deletions(-) diff --git a/api/src/config.ts b/api/src/config.ts index 95238834..355697b7 100644 --- a/api/src/config.ts +++ b/api/src/config.ts @@ -71,6 +71,9 @@ export const bridgeConfig: { addressArbitrumOutBox: string; addressArbOS: string; addressL1Inbox: string; + L2OrbitGatewayRouter: string; + AtbitrumCircleTokenMessenger: string; + EthereumCircleTokenMessenger: string; l3TableName: string; l2TableName: string; l1TableName: string; @@ -92,6 +95,9 @@ export const bridgeConfig: { addressArbitrumOutBox: "64105c6C3D494469D5F21323F0E917563489d9f5", // Arbitrum outbox address ?? addressArbOS: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address addressL1Inbox: "aAe29B0366299461418F5324a79Afc425BE5ae21", // Ethereum inbox address + L2OrbitGatewayRouter: "73EeAEEC11473534a2249c851e4b245E61Da8732", // L1 Orbit Gateway Router address + AtbitrumCircleTokenMessenger: "9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5", // Arbitrum Circle Token Messenger address + EthereumCircleTokenMessenger: "9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5", // Ethereum Circle Token Messenger address l3TableName: "game7_testnet_labels", l2TableName: "arbitrum_sepolia_labels", l1TableName: "sepolia_labels", @@ -112,6 +118,9 @@ export const bridgeConfig: { addressArbitrumOutBox: "fbe537816d181888fAbE52338a5D921eE131E9Db", // Arbitrum outbox address ?? addressArbOS: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address addressL1Inbox: "4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f", // Ethereum inbox address + L2OrbitGatewayRouter: "73EeAEEC11473534a2249c851e4b245E61Da8732", // L1 Orbit Gateway Router Deposit + AtbitrumCircleTokenMessenger: "19330d10D9Cc8751218eaf51E8885D058642E08A", // Arbitrum Circle Token Messenger address + EthereumCircleTokenMessenger: "Bd3fa81B58Ba92a82136038B25aDec7066af3155", // Ethereum Circle Token Messenger address l3TableName: "game7_labels", l2TableName: "arbitrum_one_labels", l1TableName: "ethereum_labels", @@ -122,4 +131,5 @@ export const bridgeConfig: { l1Token: "0x0000000000000000000000000000000000000000", // l1 l3 token nativeToken: "0x0000000000000000000000000000000000000000" // native token }, -}; \ No newline at end of file +}; + diff --git a/api/src/services/bridge.service.ts b/api/src/services/bridge.service.ts index 58376778..5dd3e6bc 100644 --- a/api/src/services/bridge.service.ts +++ b/api/src/services/bridge.service.ts @@ -11,13 +11,49 @@ export async function getTransactionHistory(chain: string, address: string, limi } + // Define the protocol queries + + const protocolQueries = { + 'outboundTransfer': ` + SELECT + transaction_hash, + COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, + '0x' || encode(origin_address, 'hex') AS from_address, + label_data -> 'args' ->> '_amount' AS amount, + block_timestamp, + label_data ->> 'status' AS status + FROM + ${bridgeConfig[chain].l3TableName} AS labels + ` + } + + try { const query = ` - WITH game7_withdrawal_calls AS ( + WITH + game7_token_info as ( + SELECT DISTINCT '0x' || ENCODE(address, 'hex') as address, + label_data->'result'->>0 AS symbol + FROM ${bridgeConfig[chain].l3TableName} + WHERE label_name = 'symbol' + ), + arbitrum_token_info as ( + SELECT DISTINCT '0x' || ENCODE(address, 'hex') as address, + label_data->'result'->>0 AS symbol + FROM ${bridgeConfig[chain].l2TableName} + WHERE label_name = 'symbol' + ), + ethereum_token_info as ( + SELECT DISTINCT '0x' || ENCODE(address, 'hex') as address, + label_data->'result'->>0 AS symbol + FROM ${bridgeConfig[chain].l1TableName} + WHERE label_name = 'symbol' + ), + game7_withdrawal_calls AS ( SELECT transaction_hash, COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, - '0x' || encode(origin_address, 'hex') AS origin_address, + '0x' || encode(origin_address, 'hex') AS from_address, label_data -> 'args' ->> '_amount' AS amount, block_timestamp, label_data ->> 'status' AS status @@ -25,8 +61,8 @@ export async function getTransactionHistory(chain: string, address: string, limi ${bridgeConfig[chain].l3TableName} AS labels WHERE (address, label_name) IN ( - (DECODE($1, 'hex'), 'withdrawEth'), - (DECODE($11, 'hex'), 'outboundTransfer') + (DECODE('${bridgeConfig[chain].addressArbOS}', 'hex'), 'withdrawEth'), + (DECODE('${bridgeConfig[chain].addressL3GatewayRouter}', 'hex'), 'outboundTransfer') ) ), game7_withdrawal_events AS ( SELECT @@ -37,7 +73,7 @@ export async function getTransactionHistory(chain: string, address: string, limi FROM ${bridgeConfig[chain].l3TableName} WHERE - address = DECODE($1, 'hex') + address = DECODE('${bridgeConfig[chain].addressL3GatewayRouter}', 'hex') AND label_name = 'L2ToL1Tx' ), game7_withdrawal AS ( SELECT @@ -48,7 +84,7 @@ export async function getTransactionHistory(chain: string, address: string, limi ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, wc.transaction_hash AS childNetworkHash, wc.block_timestamp AS childNetworkTimestamp, - wc.origin_address AS from_address, + wc.from_address AS from_address, we.to_address AS to_address, 3600 AS challengePeriod, (wc.block_timestamp + 3600) AS claimableTimestamp, @@ -76,7 +112,7 @@ export async function getTransactionHistory(chain: string, address: string, limi label = 'seer' AND label_type = 'event' AND label_name = 'OutBoxTransactionExecuted' AND - address = DECODE($2, 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address + address = DECODE('${bridgeConfig[chain].addressArbitrumOutBox}', 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address ), withdrawal_l3_l2 as ( SELECT 'WITHDRAWAL' AS type, @@ -103,7 +139,7 @@ export async function getTransactionHistory(chain: string, address: string, limi SELECT transaction_hash, COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].nativeToken}') AS token, - '0x' || encode(origin_address, 'hex') AS origin_address, + '0x' || encode(origin_address, 'hex') AS from_address, label_data -> 'args' ->> '_amount' AS amount, block_timestamp, label_data ->> 'status' AS status @@ -111,8 +147,8 @@ export async function getTransactionHistory(chain: string, address: string, limi ${bridgeConfig[chain].l2TableName} AS labels WHERE (address, label_name) IN ( - (DECODE($1, 'hex'), 'withdrawEth'), - (DECODE($4, 'hex'), 'outboundTransfer') + (DECODE('${bridgeConfig[chain].addressArbOS}', 'hex'), 'withdrawEth'), + (DECODE('${bridgeConfig[chain].addressL2GatewayRouter}', 'hex'), 'outboundTransfer') ) ), withdrawal_events_arbitrum AS ( SELECT @@ -123,7 +159,7 @@ export async function getTransactionHistory(chain: string, address: string, limi FROM ${bridgeConfig[chain].l2TableName} WHERE - address = DECODE($1, 'hex') + address = DECODE('${bridgeConfig[chain].addressArbOS}', 'hex') AND label_name = 'L2ToL1Tx' ), arbitrum_withdraw AS ( SELECT @@ -134,16 +170,38 @@ export async function getTransactionHistory(chain: string, address: string, limi ${bridgeConfig[chain].l2rleationship.childNetworkChainId} AS childNetworkChainId, wc.transaction_hash AS childNetworkHash, wc.block_timestamp AS childNetworkTimestamp, - wc.origin_address AS from_address, + wc.from_address AS from_address, we.to_address AS to_address, 3600 AS challengePeriod, (wc.block_timestamp + 3600) AS claimableTimestamp, wc.block_timestamp AS block_timestamp, wc.token AS token, - wc.status AS status + wc.status AS status, + false as isCctp FROM withdrawal_calls_arbitrum wc JOIN withdrawal_events_arbitrum we ON we.transaction_hash = wc.transaction_hash + UNION ALL + select + 'WITHDRAWAL' as type, + 'dasd' as position, + label_data->'args'->>'amount' as amount, + ${bridgeConfig[chain].l2rleationship.parentNetworkChainId} AS parentNetworkChainId, + ${bridgeConfig[chain].l2rleationship.childNetworkChainId} AS childNetworkChainId, + transaction_hash AS childNetworkHash, + block_timestamp AS childNetworkTimestamp, + '0x' || ENCODE(origin_address, 'hex') as to_address, + '0x' || ENCODE(origin_address, 'hex') AS from_address, + 3600 AS challengePeriod, + (block_timestamp + 3600) AS claimableTimestamp, + block_timestamp as block_timestamp, + label_data->'args'->>'burnToken' as token, + label_data->>'status' as status, + true as isCctp + from ${bridgeConfig[chain].l2TableName} -- arbitrum_one_labels + where label_name = 'depositForBurn' + and address = DECODE('${bridgeConfig[chain].AtbitrumCircleTokenMessenger}', 'hex') -- '0x00D2d23DEA90243D4f73cf088ea5666690299465' -- Arbitrum CircleTokenMessenger + and label_data->'args'->>'destinationDomain' = '0' -- 0 is the destination domain for the ethereum chain ), ethereum_claims AS ( SELECT 'CLAIM' AS type, @@ -154,7 +212,7 @@ export async function getTransactionHistory(chain: string, address: string, limi ${bridgeConfig[chain].l1TableName} WHERE label_name = 'OutBoxTransactionExecuted' - AND address = DECODE($3, 'hex') + AND address = DECODE('${bridgeConfig[chain].addressEthereumOutbox}', 'hex') ), l2_to_l1_withdraw AS ( SELECT 'WITHDRAWAL' AS type, @@ -173,7 +231,10 @@ export async function getTransactionHistory(chain: string, address: string, limi ec.block_timestamp AS parentNetworkTimestamp, ec.transaction_hash AS parentNetworkHash, aw.status AS status, - aw.block_timestamp AS block_timestamp + aw.block_timestamp AS block_timestamp, + aw.isCctp as isCctp, + ${bridgeConfig[chain].l2rleationship.childNetworkChainId} as originNetworkChainId, + ${bridgeConfig[chain].l2rleationship.parentNetworkChainId} as destinationNetworkChainId FROM arbitrum_withdraw aw LEFT JOIN ethereum_claims ec ON aw.position = ec.position @@ -193,6 +254,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, + true as isCctp, block_timestamp FROM ${bridgeConfig[chain].l2TableName} @@ -200,9 +262,35 @@ export async function getTransactionHistory(chain: string, address: string, limi label = 'seer' AND label_type = 'tx_call' AND label_name = 'depositERC20' - AND address = DECODE($5, 'hex') -- e6470bb72291c39073aed67a30ff93b69c1f47de -- Arbitrum addressERC20Inbox + AND address = DECODE('${bridgeConfig[chain].addressERC20Inbox}', 'hex') -- e6470bb72291c39073aed67a30ff93b69c1f47de -- Arbitrum addressERC20Inbox + UNION ALL + SELECT + 'DEPOSIT' AS type, + label_data -> 'args' ->> '_amount' AS amount, + ${bridgeConfig[chain].l2rleationship.parentNetworkChainId} AS parentNetworkChainId, + ${bridgeConfig[chain].l2rleationship.childNetworkChainId} AS childNetworkChainId, + transaction_hash AS parentNetworkHash, + block_timestamp AS parentNetworkTimestamp, + block_timestamp AS completionTimestamp, + '0x' || ENCODE(origin_address, 'hex') AS from_address, + label_data ->'args'->> '_to' AS to_address, + label_data ->'args' ->> '_token' AS token, + CASE + WHEN label_data ->> 'status' = '1' THEN true + ELSE false + END AS isDeposit, + true as isCctp, + block_timestamp + FROM + ${bridgeConfig[chain].l2TableName} + WHERE + label = 'seer' + AND label_type = 'tx_call' + AND label_name = 'outboundTransfer' + AND ADDRESS = DECODE('${bridgeConfig[chain].addressL1GatewayRouter}', 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit + ), l1_to_l2_deposit as ( - select * from ( + select * from ( SELECT 'DEPOSIT' AS type, label_data -> 'args' ->> '_amount' AS amount, @@ -218,6 +306,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, + true as isCctp, block_timestamp FROM ${bridgeConfig[chain].l1TableName} @@ -225,7 +314,7 @@ export async function getTransactionHistory(chain: string, address: string, limi label = 'seer' AND label_type = 'tx_call' AND label_name = 'outboundTransfer' - AND ADDRESS = DECODE($6, 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit + AND ADDRESS = DECODE('${bridgeConfig[chain].addressL1GatewayRouter}', 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit UNION ALL SELECT 'DEPOSIT' AS type, @@ -242,6 +331,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, + true as isCctp, block_timestamp FROM ${bridgeConfig[chain].l1TableName} @@ -249,7 +339,26 @@ export async function getTransactionHistory(chain: string, address: string, limi label = 'seer' AND label_type = 'tx_call' AND label_name = 'depositEth' - AND ADDRESS = DECODE($7, 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit + AND ADDRESS = DECODE('${bridgeConfig[chain].addressL1GatewayRouter}', 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit + UNION ALL + SELECT + 'DEPOSIT' AS type, + label_data->'args'->>'amount' as amount, + ${bridgeConfig[chain].l2rleationship.parentNetworkChainId} AS parentNetworkChainId, + ${bridgeConfig[chain].l2rleationship.childNetworkChainId} AS childNetworkChainId, + transaction_hash AS parentNetworkHash, + block_timestamp AS parentNetworkTimestamp, + block_timestamp AS completionTimestamp, + '0x' || ENCODE(origin_address, 'hex') AS from_address, + '0x' || ENCODE(origin_address, 'hex') AS to_address, + '${bridgeConfig[chain].nativeToken}' AS token, + true AS isDeposit, + true as isCctp, + block_timestamp + FROM ${bridgeConfig[chain].l1TableName} + WHERE label_name = 'depositForBurn' + and address = DECODE('${bridgeConfig[chain].EthereumCircleTokenMessenger}', 'hex') + and label_data->'args'->>'destinationDomain' = '1' -- 1 is the destination domain for the arbitrum chain ) as a ), full_history as ( SELECT @@ -264,13 +373,16 @@ export async function getTransactionHistory(chain: string, address: string, limi 'from_address', from_address, 'to_address', to_address, 'token', token, - 'isDeposit', isDeposit + 'isDeposit', isDeposit, + 'isCctp', isCctp, + 'symbol', symbol ) AS data, block_timestamp, from_address, to_address FROM l2_to_l3_desposits + left join game7_token_info on l2_to_l3_desposits.token = game7_token_info.address UNION ALL SELECT @@ -285,13 +397,16 @@ export async function getTransactionHistory(chain: string, address: string, limi 'from_address', from_address, 'to_address', to_address, 'token', token, - 'isDeposit', isDeposit + 'isDeposit', isDeposit, + 'isCctp', isCctp, + 'symbol', symbol ) AS data, block_timestamp, from_address, to_address FROM l1_to_l2_deposit + left join arbitrum_token_info on l1_to_l2_deposit.token = arbitrum_token_info.address UNION ALL SELECT json_build_object( @@ -310,13 +425,15 @@ export async function getTransactionHistory(chain: string, address: string, limi 'challengePeriod', challengePeriod, 'claimableTimestamp', claimableTimestamp, 'token', token, - 'status', status + 'status', status, + 'symbol', symbol ) AS data, block_timestamp, from_address, to_address FROM l2_to_l1_withdraw + left join ethereum_token_info on l2_to_l1_withdraw.token = ethereum_token_info.address UNION ALL SELECT json_build_object( @@ -335,36 +452,33 @@ export async function getTransactionHistory(chain: string, address: string, limi 'challengePeriod', challengePeriod, 'claimableTimestamp', claimableTimestamp, 'token', token, - 'status', status + 'status', status, + 'symbol', symbol ) AS data, block_timestamp, from_address, to_address FROM withdrawal_l3_l2 + left join arbitrum_token_info on withdrawal_l3_l2.token = arbitrum_token_info.address ) SELECT data FROM full_history WHERE - from_address = $8 - or from_address = '0x' || ENCODE(DECODE(SUBSTRING($8 FROM 3), 'hex'), 'hex') - or to_address = $8 - or to_address = '0x' || ENCODE(DECODE(SUBSTRING($8 FROM 3), 'hex'), 'hex') + from_address = $1 + or from_address = '0x' || ENCODE(DECODE(SUBSTRING($1 FROM 3), 'hex'), 'hex') + or to_address = $1 + or to_address = '0x' || ENCODE(DECODE(SUBSTRING($1 FROM 3), 'hex'), 'hex') ORDER BY block_timestamp DESC - OFFSET $9 - LIMIT $10 + OFFSET $2 + LIMIT $3 `; - const result = await pool.query(query, [bridgeConfig[chain].addressArbOS, - bridgeConfig[chain].addressArbitrumOutBox, - bridgeConfig[chain].addressEthereumOutbox, - bridgeConfig[chain].addressL2GatewayRouter, - bridgeConfig[chain].addressERC20Inbox, - bridgeConfig[chain].addressL1GatewayRouter, - bridgeConfig[chain].addressL1Inbox, - address, offset, limit, bridgeConfig[chain].addressL3GatewayRouter]) + const result = await pool.query(query, [ + address, offset, limit] + ) // unpack the data from the result const data = result.rows.map((row: any) => row.data); return data; @@ -372,4 +486,331 @@ export async function getTransactionHistory(chain: string, address: string, limi console.error('Error:', error); throw new Error(String(error)); } -} \ No newline at end of file +} + + + +// // 1. Define template snippets for each operation. +// const TX_SNIPPETS = { +// withdrawL3toL2: ` +// SELECT +// 'L3_TO_L2_WITHDRAW' AS flow, +// transaction_hash, +// COALESCE(label_data->'args'->>'_l1Token', '{L3_TOKEN}') AS token, +// label_data->'args'->>'_amount' AS amount, +// '0x' || encode(origin_address, 'hex') AS from_address, +// block_timestamp, +// label_data->>'status' AS status, +// label_data->'args'->>'_to' AS to_address +// FROM {L3_TABLE} +// WHERE (address, label_name) IN ( +// (DECODE($1, 'hex'), 'withdrawEth'), +// (DECODE($2, 'hex'), 'outboundTransfer') +// ) +// `, +// withdrawL2toL1: ` +// SELECT +// 'L2_TO_L1_WITHDRAW' AS flow, +// transaction_hash, +// COALESCE(label_data->'args'->>'_l1Token', '{L2_TOKEN}') AS token, +// label_data->'args'->>'_amount' AS amount, +// '0x' || encode(origin_address, 'hex') AS from_address, +// block_timestamp, +// label_data->>'status' AS status, +// label_data->'args'->>'_to' AS to_address +// FROM {L2_TABLE} +// WHERE (address, label_name) IN ( +// (DECODE($3, 'hex'), 'withdrawEth'), +// (DECODE($4, 'hex'), 'outboundTransfer') +// ) +// `, +// depositL1toL2: ` +// SELECT +// 'L1_TO_L2_DEPOSIT' AS flow, +// transaction_hash, +// label_data->'args'->>'_amount' AS amount, +// label_data->'args'->>'_token' AS token, +// '0x' || encode(origin_address, 'hex') AS from_address, +// label_data->'args'->>'_to' AS to_address, +// block_timestamp, +// CASE WHEN label_data->>'status' = '1' THEN true ELSE false END AS isDeposit +// FROM {L1_TABLE} +// WHERE label_type = 'tx_call' +// AND label_name = 'outboundTransfer' +// `, +// depositL2toL3: ` +// SELECT +// 'L2_TO_L3_DEPOSIT' AS flow, +// transaction_hash, +// label_data->'args'->>'_amount' AS amount, +// label_data->'args'->>'_token' AS token, +// '0x' || encode(origin_address, 'hex') AS from_address, +// label_data->'args'->>'_to' AS to_address, +// block_timestamp, +// CASE WHEN label_data->>'status' = '1' THEN true ELSE false END AS isDeposit +// FROM {L2_TABLE} +// WHERE label_type = 'tx_call' +// AND label_name = 'depositERC20' +// `, +// claimEvent: ` +// SELECT +// 'CLAIM' AS flow, +// transaction_hash, +// block_timestamp, +// label_data->'args'->>'transactionIndex' AS position, +// '0x' || encode(origin_address, 'hex') AS from_address +// FROM {L1_TABLE} +// WHERE label_name = 'OutBoxTransactionExecuted' +// AND address = DECODE($5, 'hex') +// ` +// }; + +// // 2. Construct a function to build a unified query using these snippets. +// function buildFullFlowQuery(config: any) { +// // Insert chain-specific values: +// // e.g., config.l3TableName, config.l2TableName, config.l1TableName, +// // config.l3Token, config.l2Token, etc. +// const withdrawL3toL2SQL = TX_SNIPPETS.withdrawL3toL2 +// .replace('{L3_TABLE}', config.l3TableName) +// .replace('{L3_TOKEN}', config.l3Token); + +// const withdrawL2toL1SQL = TX_SNIPPETS.withdrawL2toL1 +// .replace('{L2_TABLE}', config.l2TableName) +// .replace('{L2_TOKEN}', config.l2Token); + +// const depositL1toL2SQL = TX_SNIPPETS.depositL1toL2 +// .replace('{L1_TABLE}', config.l1TableName); + +// const depositL2toL3SQL = TX_SNIPPETS.depositL2toL3 +// .replace('{L2_TABLE}', config.l2TableName); + +// const claimEventSQL = TX_SNIPPETS.claimEvent +// .replace('{L1_TABLE}', config.l1TableName); + +// // 3. Combine them via WITH + UNION ALL in a final query. +// // Each snippet can be given a CTE name, then we unify them in cte_all. +// const finalQuery = ` +// WITH cte_withdrawL3toL2 AS ( +// ${withdrawL3toL2SQL} +// ), +// cte_withdrawL2toL1 AS ( +// ${withdrawL2toL1SQL} +// ), +// cte_depositL1toL2 AS ( +// ${depositL1toL2SQL} +// ), +// cte_depositL2toL3 AS ( +// ${depositL2toL3SQL} +// ), +// cte_claimEvent AS ( +// ${claimEventSQL} +// ), +// cte_all AS ( +// SELECT * FROM cte_withdrawL3toL2 +// UNION ALL +// SELECT * FROM cte_withdrawL2toL1 +// UNION ALL +// SELECT * FROM cte_depositL1toL2 +// UNION ALL +// SELECT * FROM cte_depositL2toL3 +// UNION ALL +// SELECT * FROM cte_claimEvent +// ) +// SELECT * +// FROM cte_all +// WHERE from_address = $6 +// OR to_address = $6 +// ORDER BY block_timestamp DESC +// OFFSET $7 +// LIMIT $8 +// `; + +// return finalQuery; +// } + + + +// withdraw_arbitrum_calls = ` +// SELECT +// transaction_hash, +// COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, +// '0x' || encode(origin_address, 'hex') AS origin_address, +// label_data -> 'args' ->> '_amount' AS amount, +// block_timestamp, +// label_data ->> 'status' AS status +// FROM +// {bridgeConfig[chain].l3TableName} AS labels +// WHERE +// (address, label_name) IN ( +// (DECODE($1, 'hex'), 'withdrawEth'), +// (DECODE($11, 'hex'), 'outboundTransfer') +// ) + +// ` +// withdraw_arbitrum_events = ` +// SELECT +// transaction_hash, +// label_data -> 'args' ->> 'position' AS position, +// label_data -> 'args' ->> 'callvalue' AS amount, +// label_data -> 'args' ->> 'destination' AS to_address +// FROM +// {bridgeConfig[chain].l3TableName} +// WHERE +// address = DECODE($1, 'hex') +// AND label_name = 'L2ToL1Tx' +// ` + +// withdraw_arbitrum_claims = ` +// SELECT +// 'CLAIM' AS type, +// transaction_hash, +// label_data->'args'->>'transactionIndex' AS position, +// label_data->'args'->>'l2Sender' AS from_address, +// label_data->'args'->>'to' AS to_address, +// '${bridgeConfig[chain].l3Token}' AS token, +// label_data->'args'->>'value' AS amount, +// 'from_l3_to_l2 claim' AS type, +// block_number, +// block_timestamp, +// true AS status +// FROM ${bridgeConfig[chain].l2TableName} +// WHERE +// label = 'seer' AND +// label_type = 'event' AND +// label_name = 'OutBoxTransactionExecuted' AND +// address = DECODE($2, 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address +// ` +// withdraw_arbitrum_withdrawal = ` +// SELECT +// 'WITHDRAWAL' AS type, +// we.position AS position, +// coalesce(wc.amount, we.amount) AS amount, +// ${bridgeConfig[chain].l3rleationship.parentNetworkChainId} AS parentNetworkChainId, +// ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, +// wc.transaction_hash AS childNetworkHash, +// wc.block_timestamp AS childNetworkTimestamp, +// wc.origin_address AS from_address, +// we.to_address AS to_address, +// 3600 AS challengePeriod, +// (wc.block_timestamp + 3600) AS claimableTimestamp, +// wc.block_timestamp AS block_timestamp, +// wc.token AS token, +// wc.status AS status +// FROM +// (withdraw_arbitrum_calls) wc +// LEFT JOIN (withdraw_arbitrum_events) we ON we.transaction_hash = wc.transaction_hash +// ` + +// withdraw_arbitrum = ` +// select +// wc.type, +// wc.transaction_hash, +// wc.token, +// wc.amount, +// wc.from_address, +// wc.to_address, +// wc.status +// wc.block_timestamp, +// wc.parentNetworkChainId, +// wc.childNetworkChainId, +// wc.childNetworkHash, +// wc.childNetworkTimestamp, +// wc.challengePeriod, +// wc.claimableTimestamp, +// we.block_timestamp as completionTimestamp, +// we.block_timestamp as parentNetworkTimestamp, +// we.transaction_hash as parentNetworkHash, +// wc.status, +// wc.block_timestamp as block_timestamp +// from (withdraw_arbitrum_withdrawal) wc +// left join (withdraw_arbitrum_claims) we on we.position = wc.position +// ` + + +// withdrawl_arbitrum = +// `WITH game7_withdrawal_calls AS ( +// SELECT +// transaction_hash, +// COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, +// '0x' || encode(origin_address, 'hex') AS origin_address, +// label_data -> 'args' ->> '_amount' AS amount, +// block_timestamp, +// label_data ->> 'status' AS status +// FROM +// ${bridgeConfig[chain].l3TableName} AS labels +// WHERE +// (address, label_name) IN ( +// (DECODE($1, 'hex'), 'withdrawEth'), +// (DECODE($11, 'hex'), 'outboundTransfer') +// ) +// ), game7_withdrawal_events AS ( +// SELECT +// transaction_hash, +// label_data -> 'args' ->> 'position' AS position, +// label_data -> 'args' ->> 'callvalue' AS amount, +// label_data -> 'args' ->> 'destination' AS to_address +// FROM +// ${bridgeConfig[chain].l3TableName} +// WHERE +// address = DECODE($1, 'hex') +// AND label_name = 'L2ToL1Tx' +// ), game7_withdrawal AS ( +// SELECT +// 'WITHDRAWAL' AS type, +// we.position AS position, +// coalesce(wc.amount, we.amount) AS amount, +// ${bridgeConfig[chain].l3rleationship.parentNetworkChainId} AS parentNetworkChainId, +// ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, +// wc.transaction_hash AS childNetworkHash, +// wc.block_timestamp AS childNetworkTimestamp, +// wc.origin_address AS from_address, +// we.to_address AS to_address, +// 3600 AS challengePeriod, +// (wc.block_timestamp + 3600) AS claimableTimestamp, +// wc.block_timestamp AS block_timestamp, +// wc.token AS token, +// wc.status AS status +// FROM +// game7_withdrawal_calls wc +// LEFT JOIN game7_withdrawal_events we ON we.transaction_hash = wc.transaction_hash +// ),arbirtrum_claims as ( +// SELECT +// 'CLAIM' AS type, +// transaction_hash, +// label_data->'args'->>'transactionIndex' AS position, +// label_data->'args'->>'l2Sender' AS from_address, +// label_data->'args'->>'to' AS to_address, +// '${bridgeConfig[chain].l3Token}' AS token, +// label_data->'args'->>'value' AS amount, +// 'from_l3_to_l2 claim' AS type, +// block_number, +// block_timestamp, +// true AS status +// FROM ${bridgeConfig[chain].l2TableName} +// WHERE +// label = 'seer' AND +// label_type = 'event' AND +// label_name = 'OutBoxTransactionExecuted' AND +// address = DECODE($2, 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address +// ), withdrawal_l3_l2 as ( +// SELECT +// 'WITHDRAWAL' AS type, +// game7_withdrawal.position AS position, +// game7_withdrawal.amount AS amount, +// game7_withdrawal.parentNetworkChainId AS parentNetworkChainId, +// game7_withdrawal.childNetworkChainId AS childNetworkChainId, +// game7_withdrawal.childNetworkHash AS childNetworkHash, +// game7_withdrawal.childNetworkTimestamp AS childNetworkTimestamp, +// game7_withdrawal.from_address AS from_address, +// game7_withdrawal.to_address AS to_address, +// game7_withdrawal.challengePeriod AS challengePeriod, +// game7_withdrawal.claimableTimestamp AS claimableTimestamp, +// game7_withdrawal.token as token, +// arbirtrum_claims.block_timestamp AS completionTimestamp, +// arbirtrum_claims.block_timestamp AS parentNetworkTimestamp, +// arbirtrum_claims.transaction_hash AS parentNetworkHash, +// true AS status, +// game7_withdrawal.block_timestamp AS block_timestamp +// FROM +// game7_withdrawal +// LEFT JOIN arbirtrum_claims ON game7_withdrawal.position = arbirtrum_claims.position` \ No newline at end of file From a512f4a71818b1174fafdd936209395b3e0dbc3f Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 20 Dec 2024 14:26:26 +0200 Subject: [PATCH 4/4] Extent tokens symbols. --- api/package.json | 2 +- api/src/config.ts | 10 +- api/src/services/bridge.service.ts | 381 ++--------------------------- 3 files changed, 35 insertions(+), 358 deletions(-) diff --git a/api/package.json b/api/package.json index 2c2d7f24..1328bac4 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "protocol-api", - "version": "1.0.3", + "version": "1.1.0", "description": "", "main": "index.js", "scripts": { diff --git a/api/src/config.ts b/api/src/config.ts index 355697b7..c8918739 100644 --- a/api/src/config.ts +++ b/api/src/config.ts @@ -82,6 +82,8 @@ export const bridgeConfig: { l3Token: string; l2Token: string; l1Token: string; + l1TokenName: string; + l2TokenName: string; nativeToken: string; }; } = { @@ -105,7 +107,9 @@ export const bridgeConfig: { l2rleationship: { parentNetworkChainId: 11155111, childNetworkChainId: 421614 }, l3Token: "0x10adBf84548F923577Be12146eAc104C899D1E75", // l3 native token l2Token: "0x10adBf84548F923577Be12146eAc104C899D1E75", // l2 l3 token - l1Token: "0x0000000000000000000000000000000000000000", // l1 l3 token + l1Token: "0xe2ef69e4af84dbefb0a75f8491f27a52bf047b01", // l1 l3 token + l1TokenName: "TG7T", + l2TokenName: "TG7T", nativeToken: "0x0000000000000000000000000000000000000000" // native token }, "game7": { @@ -128,7 +132,9 @@ export const bridgeConfig: { l2rleationship: { parentNetworkChainId: 1, childNetworkChainId: 42161 }, l3Token: "F18e4466F26B4cA55bbAb890b314a54976E45B17", // l3 native token l2Token: "F18e4466F26B4cA55bbAb890b314a54976E45B17", // l2 l3 token - l1Token: "0x0000000000000000000000000000000000000000", // l1 l3 token + l1Token: "0x12c88a3c30a7aabc1dd7f2c08a97145f5dccd830", // l1 l3 token + l1TokenName: "G7", + l2TokenName: "G7", nativeToken: "0x0000000000000000000000000000000000000000" // native token }, }; diff --git a/api/src/services/bridge.service.ts b/api/src/services/bridge.service.ts index 5dd3e6bc..9de91352 100644 --- a/api/src/services/bridge.service.ts +++ b/api/src/services/bridge.service.ts @@ -10,24 +10,6 @@ export async function getTransactionHistory(chain: string, address: string, limi chain = 'game7-testnet'; } - - // Define the protocol queries - - const protocolQueries = { - 'outboundTransfer': ` - SELECT - transaction_hash, - COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, - '0x' || encode(origin_address, 'hex') AS from_address, - label_data -> 'args' ->> '_amount' AS amount, - block_timestamp, - label_data ->> 'status' AS status - FROM - ${bridgeConfig[chain].l3TableName} AS labels - ` - } - - try { const query = ` WITH @@ -36,18 +18,32 @@ export async function getTransactionHistory(chain: string, address: string, limi label_data->'result'->>0 AS symbol FROM ${bridgeConfig[chain].l3TableName} WHERE label_name = 'symbol' + UNION ALL + SELECT * FROM ( + VALUES ('${bridgeConfig[chain].nativeToken}', 'ETH') + ) as t(address, symbol) ), arbitrum_token_info as ( SELECT DISTINCT '0x' || ENCODE(address, 'hex') as address, label_data->'result'->>0 AS symbol FROM ${bridgeConfig[chain].l2TableName} WHERE label_name = 'symbol' + UNION ALL + SELECT * FROM ( + VALUES ('${bridgeConfig[chain].l2Token}', '${bridgeConfig[chain].l2TokenName}'), + ('${bridgeConfig[chain].nativeToken}', 'ETH') + ) as t(address, symbol) ), ethereum_token_info as ( SELECT DISTINCT '0x' || ENCODE(address, 'hex') as address, label_data->'result'->>0 AS symbol FROM ${bridgeConfig[chain].l1TableName} WHERE label_name = 'symbol' + UNION ALL + SELECT * FROM ( + VALUES ('${bridgeConfig[chain].l1Token}', '${bridgeConfig[chain].l1TokenName}'), + ('${bridgeConfig[chain].nativeToken}', 'ETH') + ) as t(address, symbol) ), game7_withdrawal_calls AS ( SELECT @@ -73,7 +69,7 @@ export async function getTransactionHistory(chain: string, address: string, limi FROM ${bridgeConfig[chain].l3TableName} WHERE - address = DECODE('${bridgeConfig[chain].addressL3GatewayRouter}', 'hex') + address = DECODE('${bridgeConfig[chain].addressArbOS}', 'hex') AND label_name = 'L2ToL1Tx' ), game7_withdrawal AS ( SELECT @@ -254,7 +250,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, - true as isCctp, + false as isCctp, block_timestamp FROM ${bridgeConfig[chain].l2TableName} @@ -279,7 +275,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, - true as isCctp, + false as isCctp, block_timestamp FROM ${bridgeConfig[chain].l2TableName} @@ -306,7 +302,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, - true as isCctp, + false as isCctp, block_timestamp FROM ${bridgeConfig[chain].l1TableName} @@ -331,7 +327,7 @@ export async function getTransactionHistory(chain: string, address: string, limi WHEN label_data ->> 'status' = '1' THEN true ELSE false END AS isDeposit, - true as isCctp, + false as isCctp, block_timestamp FROM ${bridgeConfig[chain].l1TableName} @@ -382,7 +378,7 @@ export async function getTransactionHistory(chain: string, address: string, limi to_address FROM l2_to_l3_desposits - left join game7_token_info on l2_to_l3_desposits.token = game7_token_info.address + left join arbitrum_token_info on l2_to_l3_desposits.token = arbitrum_token_info.address UNION ALL SELECT @@ -406,7 +402,7 @@ export async function getTransactionHistory(chain: string, address: string, limi to_address FROM l1_to_l2_deposit - left join arbitrum_token_info on l1_to_l2_deposit.token = arbitrum_token_info.address + left join ethereum_token_info on l1_to_l2_deposit.token = ethereum_token_info.address UNION ALL SELECT json_build_object( @@ -426,7 +422,8 @@ export async function getTransactionHistory(chain: string, address: string, limi 'claimableTimestamp', claimableTimestamp, 'token', token, 'status', status, - 'symbol', symbol + 'symbol', symbol, + 'isCctp', isCctp ) AS data, block_timestamp, from_address, @@ -453,7 +450,8 @@ export async function getTransactionHistory(chain: string, address: string, limi 'claimableTimestamp', claimableTimestamp, 'token', token, 'status', status, - 'symbol', symbol + 'symbol', symbol, + 'isCctp', false ) AS data, block_timestamp, from_address, @@ -486,331 +484,4 @@ export async function getTransactionHistory(chain: string, address: string, limi console.error('Error:', error); throw new Error(String(error)); } -} - - - -// // 1. Define template snippets for each operation. -// const TX_SNIPPETS = { -// withdrawL3toL2: ` -// SELECT -// 'L3_TO_L2_WITHDRAW' AS flow, -// transaction_hash, -// COALESCE(label_data->'args'->>'_l1Token', '{L3_TOKEN}') AS token, -// label_data->'args'->>'_amount' AS amount, -// '0x' || encode(origin_address, 'hex') AS from_address, -// block_timestamp, -// label_data->>'status' AS status, -// label_data->'args'->>'_to' AS to_address -// FROM {L3_TABLE} -// WHERE (address, label_name) IN ( -// (DECODE($1, 'hex'), 'withdrawEth'), -// (DECODE($2, 'hex'), 'outboundTransfer') -// ) -// `, -// withdrawL2toL1: ` -// SELECT -// 'L2_TO_L1_WITHDRAW' AS flow, -// transaction_hash, -// COALESCE(label_data->'args'->>'_l1Token', '{L2_TOKEN}') AS token, -// label_data->'args'->>'_amount' AS amount, -// '0x' || encode(origin_address, 'hex') AS from_address, -// block_timestamp, -// label_data->>'status' AS status, -// label_data->'args'->>'_to' AS to_address -// FROM {L2_TABLE} -// WHERE (address, label_name) IN ( -// (DECODE($3, 'hex'), 'withdrawEth'), -// (DECODE($4, 'hex'), 'outboundTransfer') -// ) -// `, -// depositL1toL2: ` -// SELECT -// 'L1_TO_L2_DEPOSIT' AS flow, -// transaction_hash, -// label_data->'args'->>'_amount' AS amount, -// label_data->'args'->>'_token' AS token, -// '0x' || encode(origin_address, 'hex') AS from_address, -// label_data->'args'->>'_to' AS to_address, -// block_timestamp, -// CASE WHEN label_data->>'status' = '1' THEN true ELSE false END AS isDeposit -// FROM {L1_TABLE} -// WHERE label_type = 'tx_call' -// AND label_name = 'outboundTransfer' -// `, -// depositL2toL3: ` -// SELECT -// 'L2_TO_L3_DEPOSIT' AS flow, -// transaction_hash, -// label_data->'args'->>'_amount' AS amount, -// label_data->'args'->>'_token' AS token, -// '0x' || encode(origin_address, 'hex') AS from_address, -// label_data->'args'->>'_to' AS to_address, -// block_timestamp, -// CASE WHEN label_data->>'status' = '1' THEN true ELSE false END AS isDeposit -// FROM {L2_TABLE} -// WHERE label_type = 'tx_call' -// AND label_name = 'depositERC20' -// `, -// claimEvent: ` -// SELECT -// 'CLAIM' AS flow, -// transaction_hash, -// block_timestamp, -// label_data->'args'->>'transactionIndex' AS position, -// '0x' || encode(origin_address, 'hex') AS from_address -// FROM {L1_TABLE} -// WHERE label_name = 'OutBoxTransactionExecuted' -// AND address = DECODE($5, 'hex') -// ` -// }; - -// // 2. Construct a function to build a unified query using these snippets. -// function buildFullFlowQuery(config: any) { -// // Insert chain-specific values: -// // e.g., config.l3TableName, config.l2TableName, config.l1TableName, -// // config.l3Token, config.l2Token, etc. -// const withdrawL3toL2SQL = TX_SNIPPETS.withdrawL3toL2 -// .replace('{L3_TABLE}', config.l3TableName) -// .replace('{L3_TOKEN}', config.l3Token); - -// const withdrawL2toL1SQL = TX_SNIPPETS.withdrawL2toL1 -// .replace('{L2_TABLE}', config.l2TableName) -// .replace('{L2_TOKEN}', config.l2Token); - -// const depositL1toL2SQL = TX_SNIPPETS.depositL1toL2 -// .replace('{L1_TABLE}', config.l1TableName); - -// const depositL2toL3SQL = TX_SNIPPETS.depositL2toL3 -// .replace('{L2_TABLE}', config.l2TableName); - -// const claimEventSQL = TX_SNIPPETS.claimEvent -// .replace('{L1_TABLE}', config.l1TableName); - -// // 3. Combine them via WITH + UNION ALL in a final query. -// // Each snippet can be given a CTE name, then we unify them in cte_all. -// const finalQuery = ` -// WITH cte_withdrawL3toL2 AS ( -// ${withdrawL3toL2SQL} -// ), -// cte_withdrawL2toL1 AS ( -// ${withdrawL2toL1SQL} -// ), -// cte_depositL1toL2 AS ( -// ${depositL1toL2SQL} -// ), -// cte_depositL2toL3 AS ( -// ${depositL2toL3SQL} -// ), -// cte_claimEvent AS ( -// ${claimEventSQL} -// ), -// cte_all AS ( -// SELECT * FROM cte_withdrawL3toL2 -// UNION ALL -// SELECT * FROM cte_withdrawL2toL1 -// UNION ALL -// SELECT * FROM cte_depositL1toL2 -// UNION ALL -// SELECT * FROM cte_depositL2toL3 -// UNION ALL -// SELECT * FROM cte_claimEvent -// ) -// SELECT * -// FROM cte_all -// WHERE from_address = $6 -// OR to_address = $6 -// ORDER BY block_timestamp DESC -// OFFSET $7 -// LIMIT $8 -// `; - -// return finalQuery; -// } - - - -// withdraw_arbitrum_calls = ` -// SELECT -// transaction_hash, -// COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, -// '0x' || encode(origin_address, 'hex') AS origin_address, -// label_data -> 'args' ->> '_amount' AS amount, -// block_timestamp, -// label_data ->> 'status' AS status -// FROM -// {bridgeConfig[chain].l3TableName} AS labels -// WHERE -// (address, label_name) IN ( -// (DECODE($1, 'hex'), 'withdrawEth'), -// (DECODE($11, 'hex'), 'outboundTransfer') -// ) - -// ` -// withdraw_arbitrum_events = ` -// SELECT -// transaction_hash, -// label_data -> 'args' ->> 'position' AS position, -// label_data -> 'args' ->> 'callvalue' AS amount, -// label_data -> 'args' ->> 'destination' AS to_address -// FROM -// {bridgeConfig[chain].l3TableName} -// WHERE -// address = DECODE($1, 'hex') -// AND label_name = 'L2ToL1Tx' -// ` - -// withdraw_arbitrum_claims = ` -// SELECT -// 'CLAIM' AS type, -// transaction_hash, -// label_data->'args'->>'transactionIndex' AS position, -// label_data->'args'->>'l2Sender' AS from_address, -// label_data->'args'->>'to' AS to_address, -// '${bridgeConfig[chain].l3Token}' AS token, -// label_data->'args'->>'value' AS amount, -// 'from_l3_to_l2 claim' AS type, -// block_number, -// block_timestamp, -// true AS status -// FROM ${bridgeConfig[chain].l2TableName} -// WHERE -// label = 'seer' AND -// label_type = 'event' AND -// label_name = 'OutBoxTransactionExecuted' AND -// address = DECODE($2, 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address -// ` -// withdraw_arbitrum_withdrawal = ` -// SELECT -// 'WITHDRAWAL' AS type, -// we.position AS position, -// coalesce(wc.amount, we.amount) AS amount, -// ${bridgeConfig[chain].l3rleationship.parentNetworkChainId} AS parentNetworkChainId, -// ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, -// wc.transaction_hash AS childNetworkHash, -// wc.block_timestamp AS childNetworkTimestamp, -// wc.origin_address AS from_address, -// we.to_address AS to_address, -// 3600 AS challengePeriod, -// (wc.block_timestamp + 3600) AS claimableTimestamp, -// wc.block_timestamp AS block_timestamp, -// wc.token AS token, -// wc.status AS status -// FROM -// (withdraw_arbitrum_calls) wc -// LEFT JOIN (withdraw_arbitrum_events) we ON we.transaction_hash = wc.transaction_hash -// ` - -// withdraw_arbitrum = ` -// select -// wc.type, -// wc.transaction_hash, -// wc.token, -// wc.amount, -// wc.from_address, -// wc.to_address, -// wc.status -// wc.block_timestamp, -// wc.parentNetworkChainId, -// wc.childNetworkChainId, -// wc.childNetworkHash, -// wc.childNetworkTimestamp, -// wc.challengePeriod, -// wc.claimableTimestamp, -// we.block_timestamp as completionTimestamp, -// we.block_timestamp as parentNetworkTimestamp, -// we.transaction_hash as parentNetworkHash, -// wc.status, -// wc.block_timestamp as block_timestamp -// from (withdraw_arbitrum_withdrawal) wc -// left join (withdraw_arbitrum_claims) we on we.position = wc.position -// ` - - -// withdrawl_arbitrum = -// `WITH game7_withdrawal_calls AS ( -// SELECT -// transaction_hash, -// COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].l3Token}') AS token, -// '0x' || encode(origin_address, 'hex') AS origin_address, -// label_data -> 'args' ->> '_amount' AS amount, -// block_timestamp, -// label_data ->> 'status' AS status -// FROM -// ${bridgeConfig[chain].l3TableName} AS labels -// WHERE -// (address, label_name) IN ( -// (DECODE($1, 'hex'), 'withdrawEth'), -// (DECODE($11, 'hex'), 'outboundTransfer') -// ) -// ), game7_withdrawal_events AS ( -// SELECT -// transaction_hash, -// label_data -> 'args' ->> 'position' AS position, -// label_data -> 'args' ->> 'callvalue' AS amount, -// label_data -> 'args' ->> 'destination' AS to_address -// FROM -// ${bridgeConfig[chain].l3TableName} -// WHERE -// address = DECODE($1, 'hex') -// AND label_name = 'L2ToL1Tx' -// ), game7_withdrawal AS ( -// SELECT -// 'WITHDRAWAL' AS type, -// we.position AS position, -// coalesce(wc.amount, we.amount) AS amount, -// ${bridgeConfig[chain].l3rleationship.parentNetworkChainId} AS parentNetworkChainId, -// ${bridgeConfig[chain].l3rleationship.childNetworkChainId} AS childNetworkChainId, -// wc.transaction_hash AS childNetworkHash, -// wc.block_timestamp AS childNetworkTimestamp, -// wc.origin_address AS from_address, -// we.to_address AS to_address, -// 3600 AS challengePeriod, -// (wc.block_timestamp + 3600) AS claimableTimestamp, -// wc.block_timestamp AS block_timestamp, -// wc.token AS token, -// wc.status AS status -// FROM -// game7_withdrawal_calls wc -// LEFT JOIN game7_withdrawal_events we ON we.transaction_hash = wc.transaction_hash -// ),arbirtrum_claims as ( -// SELECT -// 'CLAIM' AS type, -// transaction_hash, -// label_data->'args'->>'transactionIndex' AS position, -// label_data->'args'->>'l2Sender' AS from_address, -// label_data->'args'->>'to' AS to_address, -// '${bridgeConfig[chain].l3Token}' AS token, -// label_data->'args'->>'value' AS amount, -// 'from_l3_to_l2 claim' AS type, -// block_number, -// block_timestamp, -// true AS status -// FROM ${bridgeConfig[chain].l2TableName} -// WHERE -// label = 'seer' AND -// label_type = 'event' AND -// label_name = 'OutBoxTransactionExecuted' AND -// address = DECODE($2, 'hex') -- '64105c6C3D494469D5F21323F0E917563489d9f5' -- Arbitrum outbox address -// ), withdrawal_l3_l2 as ( -// SELECT -// 'WITHDRAWAL' AS type, -// game7_withdrawal.position AS position, -// game7_withdrawal.amount AS amount, -// game7_withdrawal.parentNetworkChainId AS parentNetworkChainId, -// game7_withdrawal.childNetworkChainId AS childNetworkChainId, -// game7_withdrawal.childNetworkHash AS childNetworkHash, -// game7_withdrawal.childNetworkTimestamp AS childNetworkTimestamp, -// game7_withdrawal.from_address AS from_address, -// game7_withdrawal.to_address AS to_address, -// game7_withdrawal.challengePeriod AS challengePeriod, -// game7_withdrawal.claimableTimestamp AS claimableTimestamp, -// game7_withdrawal.token as token, -// arbirtrum_claims.block_timestamp AS completionTimestamp, -// arbirtrum_claims.block_timestamp AS parentNetworkTimestamp, -// arbirtrum_claims.transaction_hash AS parentNetworkHash, -// true AS status, -// game7_withdrawal.block_timestamp AS block_timestamp -// FROM -// game7_withdrawal -// LEFT JOIN arbirtrum_claims ON game7_withdrawal.position = arbirtrum_claims.position` \ No newline at end of file +} \ No newline at end of file