Skip to content

Commit

Permalink
Fix debridge
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Aug 30, 2024
1 parent 06e941a commit 5c9772e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
52 changes: 28 additions & 24 deletions src/adapters/debridgedln/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,48 @@ 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<ApiSolanaEvent[]> => {
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<EventData[]> => {
// Performance optimization: deBridge does not have any orders from Solana prior this block
if (toBlock < solanaBlockNumberFirstUsedByDebridge) {
return [];
}

const events = await fetchSolanaEvents(fromBlock, toBlock)

return events.map((event) => (<EventData>{
...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) =>
<EventData>{
...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 = {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -661,6 +661,7 @@ export const runAdapterHistorical = async (
}
block = endBlockForQuery;
}

console.log(`finished inserting all transactions for ${bridgeID}`);
};

Expand Down

0 comments on commit 5c9772e

Please sign in to comment.