diff --git a/src/adapters/debridgedln/index.ts b/src/adapters/debridgedln/index.ts index 5a807978..e9f336b5 100644 --- a/src/adapters/debridgedln/index.ts +++ b/src/adapters/debridgedln/index.ts @@ -96,26 +96,26 @@ const constructParams = (chain: SupportedChains) => { }; type ApiSolanaEvent = { - blockNumber: number, - txHash: string, - from: string, - to: string, - token: string, - amount: string, + blockNumber: number; + txHash: string; + from: string; + to: string; + token: string; + amount: string; isDeposit: boolean; giveAmountUSD: number; blockTimestamp: number; -} +}; const solanaBlockNumberFirstUsedByDebridge = 166833820; const fetchSolanaEvents = async (fromBlock: number, toBlock: number): Promise => { - return retry(() => fetch( - `https://stats-api.dln.trade/api/OrderEvents/solanaDepositsAndWithdrawals?fromBlock=${fromBlock}&toBlock=${toBlock}` - ) - .then(res => res.json()) - ) -} + return retry(() => + fetch( + `https://stats-api.dln.trade/api/OrderEvents/solanaDepositsAndWithdrawals?fromBlock=${fromBlock}&toBlock=${toBlock}` + ).then((res) => res.json()) + ); +}; const getSolanaEvents = async (fromBlock: number, toBlock: number): Promise => { // Performance optimization: deBridge does not have any orders from Solana prior this block @@ -123,17 +123,21 @@ const getSolanaEvents = async (fromBlock: number, toBlock: number): Promise ({ - ...event, - token: event.token === '11111111111111111111111111111111' - ? 'So11111111111111111111111111111111111111112' - : event.token, - amount: ethers.BigNumber.from(Math.round(event.giveAmountUSD)), - isUSDVolume: true, - timestamp: event.blockTimestamp - })); + const events = await fetchSolanaEvents(fromBlock, toBlock); + + return events.map( + (event) => + { + ...event, + token: + event.token === "11111111111111111111111111111111" + ? "So11111111111111111111111111111111111111112" + : event.token, + amount: ethers.BigNumber.from(Math.round(event.giveAmountUSD)), + isUSDVolume: true, + timestamp: event.blockTimestamp * 1000, + } + ); }; const adapter: BridgeAdapter = { diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index 210c7fa0..db1dcfbe 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -502,7 +502,7 @@ export const runAdapterHistorical = async ( let latestSolanaBlock = null; let averageBlockTimestamp = null; - if (chain === "solana") { + if (chain === "solana" && bridgeDbName !== "debridgedln") { latestSolanaBlock = await getLatestBlock("solana"); const connection = getConnection(); const medianBlockNumber = txBlocks?.sort((a, b) => a - b)?.[Math.floor(txBlocks.length / 2)]; @@ -563,7 +563,7 @@ export const runAdapterHistorical = async ( timestamp: realBlockTimestamp, } = log; const bucket = Math.floor(((blockNumber - minBlock) * 9) / blockRange); - const timestamp = blockTimestamps[bucket] * 1000; + const timestamp = (blockTimestamps[bucket] ?? 0) * 1000; let amountString = amount ? amount.toString() : "0"; @@ -661,6 +661,7 @@ export const runAdapterHistorical = async ( } block = endBlockForQuery; } + console.log(`finished inserting all transactions for ${bridgeID}`); };