Skip to content

Commit

Permalink
Merge pull request #231 from G7DAO/fix-missing-withdrawls
Browse files Browse the repository at this point in the history
Update withdrawl logic for l2->l1.
  • Loading branch information
Andrei-Dolgolev authored Dec 6, 2024
2 parents d53bc20 + 42d2338 commit 27e144d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 100 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protocol-api",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const bridgeConfig: {
addressL2GatewayRouter: string;
addressL1GatewayRouter: string;
addressArbitrumOutBox: string;
addressArbOSL2: string;
addressArbOS: string;
addressL1Inbox: string;
l3TableName: string;
l2TableName: string;
Expand All @@ -88,7 +88,7 @@ export const bridgeConfig: {
addressL2GatewayRouter: "9fDD1C4E4AA24EEc1d913FABea925594a20d43C7", // Arbitrum L2ERC20Gateway address
addressL1GatewayRouter: "cE18836b233C83325Cc8848CA4487e94C6288264", // Ethereum deposit address
addressArbitrumOutBox: "64105c6C3D494469D5F21323F0E917563489d9f5", // Arbitrum outbox address ??
addressArbOSL2: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address
addressArbOS: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address
addressL1Inbox: "aAe29B0366299461418F5324a79Afc425BE5ae21", // Ethereum inbox address
l3TableName: "game7_testnet_labels",
l2TableName: "arbitrum_sepolia_labels",
Expand All @@ -100,14 +100,14 @@ export const bridgeConfig: {
l1Token: "0x0000000000000000000000000000000000000000", // l1 l3 token
nativeToken: "0x0000000000000000000000000000000000000000" // native token
},
"game7": { //0x096760F208390250649E3e8763348E783AEF5562 L2CustomGateway 0xe80eb0238029333e368e0bDDB7acDf1b9cb28278 L2GatewayRouter
"game7": {
addressERC20Inbox: "B1146A7eb098ECF46e8AAf695f4A960A963948d6", // Arbitrum Deposit contract address
addressEthereumOutbox: "0B9857ae2D4A3DBe74ffE1d7DF045bb7F96E4840", // Ethereum L1ERC20Gateway address
addressL2ERC20Gateway: "096760F208390250649E3e8763348E783AEF5562", // Arbitrum L2ERC20Gateway address L1OrbitERC20Gateway
addressL2GatewayRouter: "5288c571Fd7aD117beA99bF60FE0846C4E84F933", // Arbitrum L2ERC20Gateway address L1OrbitGatewayRouter
addressL1GatewayRouter: "72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef", // Ethereum deposit address
addressArbitrumOutBox: "fbe537816d181888fAbE52338a5D921eE131E9Db", // Arbitrum outbox address ??
addressArbOSL2: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address
addressArbOS: "0000000000000000000000000000000000000064", // Game7 ArbOS L2 address
addressL1Inbox: "4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f", // Ethereum inbox address
l3TableName: "game7_labels",
l2TableName: "arbitrum_one_labels",
Expand Down
175 changes: 81 additions & 94 deletions api/src/services/bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,96 +106,84 @@ export async function getTransactionHistory(chain: string, address: string, limi
*
FROM
game7_withdrawal_failed
), arbitrum_withdraw as (
), withdrawal_calls_arbitrum AS (
SELECT
'Withdrawal' AS type,
label_data->'args'->>'_l2ToL1Id' 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,
label_data->'args'->>'_from' AS from_address,
label_data->'args'->>'_to' AS to_address,
3600 AS challengePeriod,
block_timestamp + 3600 AS claimableTimestamp,
label_data->'args'->>'l1Token' AS token,
block_timestamp AS block_timestamp
transaction_hash,
COALESCE(label_data -> 'args' ->> '_l1Token', '${bridgeConfig[chain].nativeToken}') 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].l2TableName}
${bridgeConfig[chain].l2TableName} AS labels
WHERE
label = 'seer'
AND label_type = 'event'
AND label_name = 'WithdrawalInitiated'
AND ADDRESS = DECODE($3, 'hex') -- '6e244cD02BBB8a6dbd7F626f05B2ef82151Ab502' -- Arbitrum L2ERC20Gateway address
), ethereum_claims as (
(address, label_name) IN (
(DECODE($1, 'hex'), 'withdrawEth'),
(DECODE($4, 'hex'), 'outboundTransfer')
)
), withdrawal_events_arbitrum 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,
'claim' AS type,
block_number,
block_timestamp
FROM ${bridgeConfig[chain].l1TableName}
transaction_hash,
label_data -> 'args' ->> 'position' AS position,
label_data -> 'args' ->> 'callvalue' AS amount,
label_data -> 'args' ->> 'destination' AS to_address
FROM
${bridgeConfig[chain].l2TableName}
WHERE
label = 'seer' AND
label_type = 'event' AND
label_name = 'OutBoxTransactionExecuted' AND
address = DECODE($4, 'hex') -- '902b3e5f8f19571859f4ab1003b960a5df693aff' -- Ethereum L1ERC20Gateway address
), faild_arbitrum_withdraw as (
SELECT
'WITHDRAWAL' AS type,
null 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,
label_data->'args'->>'caller' AS from_address,
label_data->'args'->>'_to' as to_address,
3600 AS challengePeriod,
block_timestamp + 3600 AS claimableTimestamp,
label_data->'args'->>'_l1Token' 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].l2TableName}
WHERE
label = 'seer' AND
label_type = 'tx_call' AND
label_name = 'outboundTransfer' AND
ADDRESS = DECODE($5, 'hex') AND -- '0x9fDD1C4E4AA24EEc1d913FABea925594a20d43C7' -- Arbitrum L2ERC20Gateway address
label_data->>'status' = '0'
), l2_to_l1_withdraw as (
address = DECODE($1, 'hex')
AND label_name = 'L2ToL1Tx'
), arbitrum_withdraw AS (
SELECT
'WITHDRAWAL' AS type,
we.position AS position,
coalesce(wc.amount, we.amount) AS amount,
${bridgeConfig[chain].l2rleationship.parentNetworkChainId} AS parentNetworkChainId,
${bridgeConfig[chain].l2rleationship.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
withdrawal_calls_arbitrum wc
JOIN withdrawal_events_arbitrum we ON we.transaction_hash = wc.transaction_hash
), ethereum_claims AS (
SELECT
'WITHDRAWAL' AS type,
arbitrum_withdraw.position AS position,
arbitrum_withdraw.amount AS amount,
arbitrum_withdraw.parentNetworkChainId AS parentNetworkChainId,
arbitrum_withdraw.childNetworkChainId AS childNetworkChainId,
arbitrum_withdraw.childNetworkHash AS childNetworkHash,
arbitrum_withdraw.childNetworkTimestamp AS childNetworkTimestamp,
arbitrum_withdraw.from_address AS from_address,
arbitrum_withdraw.to_address AS to_address,
arbitrum_withdraw.challengePeriod AS challengePeriod,
arbitrum_withdraw.claimableTimestamp AS claimableTimestamp,
arbitrum_withdraw.token as token,
ethereum_claims.block_timestamp AS completionTimestamp,
ethereum_claims.block_timestamp AS parentNetworkTimestamp,
ethereum_claims.transaction_hash AS parentNetworkHash,
true AS status,
arbitrum_withdraw.block_timestamp AS block_timestamp
FROM arbitrum_withdraw
LEFT JOIN ethereum_claims ON arbitrum_withdraw.position = ethereum_claims.position
union
ALL
'CLAIM' AS type,
label_data -> 'args' ->> 'transactionIndex' AS position,
transaction_hash,
block_timestamp
FROM
${bridgeConfig[chain].l1TableName}
WHERE
label_name = 'OutBoxTransactionExecuted'
AND address = DECODE($3, 'hex')
), l2_to_l1_withdraw AS (
SELECT
*
FROM faild_arbitrum_withdraw
'WITHDRAWAL' AS type,
aw.position AS position,
aw.amount AS amount,
aw.parentNetworkChainId AS parentNetworkChainId,
aw.childNetworkChainId AS childNetworkChainId,
aw.childNetworkHash AS childNetworkHash,
aw.childNetworkTimestamp AS childNetworkTimestamp,
aw.from_address AS from_address,
aw.to_address AS to_address,
aw.challengePeriod AS challengePeriod,
aw.claimableTimestamp AS claimableTimestamp,
aw.token AS token,
ec.block_timestamp AS completionTimestamp,
ec.block_timestamp AS parentNetworkTimestamp,
ec.transaction_hash AS parentNetworkHash,
aw.status AS status,
aw.block_timestamp AS block_timestamp
FROM
arbitrum_withdraw aw
LEFT JOIN ethereum_claims ec ON aw.position = ec.position
), l2_to_l3_desposits as (
SELECT
'DEPOSIT' AS type,
Expand All @@ -219,7 +207,7 @@ export async function getTransactionHistory(chain: string, address: string, limi
label = 'seer'
AND label_type = 'tx_call'
AND label_name = 'depositERC20'
AND address = DECODE($6, 'hex') -- e6470bb72291c39073aed67a30ff93b69c1f47de -- Arbitrum addressERC20Inbox
AND address = DECODE($5, 'hex') -- e6470bb72291c39073aed67a30ff93b69c1f47de -- Arbitrum addressERC20Inbox
), l1_to_l2_deposit as (
select * from (
SELECT
Expand All @@ -244,7 +232,7 @@ export async function getTransactionHistory(chain: string, address: string, limi
label = 'seer'
AND label_type = 'tx_call'
AND label_name = 'outboundTransfer'
AND ADDRESS = DECODE($7, 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit
AND ADDRESS = DECODE($6, 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit
UNION ALL
SELECT
'DEPOSIT' AS type,
Expand All @@ -268,7 +256,7 @@ export async function getTransactionHistory(chain: string, address: string, limi
label = 'seer'
AND label_type = 'tx_call'
AND label_name = 'depositEth'
AND ADDRESS = DECODE($8, 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit
AND ADDRESS = DECODE($7, 'hex') -- cE18836b233C83325Cc8848CA4487e94C6288264 -- Ethereum addressDeposit
) as a
), full_history as (
SELECT
Expand Down Expand Up @@ -367,18 +355,17 @@ export async function getTransactionHistory(chain: string, address: string, limi
FROM
full_history
WHERE
from_address = $9
or from_address = '0x' || ENCODE(DECODE(SUBSTRING($9 FROM 3), 'hex'), 'hex')
or to_address = $9
or to_address = '0x' || ENCODE(DECODE(SUBSTRING($9 FROM 3), 'hex'), 'hex')
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')
ORDER BY
block_timestamp DESC
OFFSET $10
LIMIT $11
OFFSET $9
LIMIT $10
`;
const result = await pool.query(query, [bridgeConfig[chain].addressArbOSL2,
const result = await pool.query(query, [bridgeConfig[chain].addressArbOS,
bridgeConfig[chain].addressArbitrumOutBox,
bridgeConfig[chain].addressL2ERC20Gateway,
bridgeConfig[chain].addressEthereumOutbox,
bridgeConfig[chain].addressL2GatewayRouter,
bridgeConfig[chain].addressERC20Inbox,
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const connectionString = process.env.PROTOCOL_API_MOONSTREAM_V3_LABELS_DATABASE_

export const pool = new Pool({
connectionString: connectionString,
statement_timeout: 5000, // 5 seconds timeout for each query
statement_timeout: 10000, // 5 seconds timeout for each query
connectionTimeoutMillis: 3000, // 3 seconds timeout for establishing a connection
max: 20, // Maximum number of connections
idleTimeoutMillis: 4000, // 1 second timeout before closing an idle connection
Expand Down

0 comments on commit 27e144d

Please sign in to comment.