Skip to content

Commit 60adad7

Browse files
committed
Fix bugs with relay adapter
1 parent 23c506a commit 60adad7

File tree

4 files changed

+190
-33
lines changed

4 files changed

+190
-33
lines changed

src/adapters/relay/index.ts

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,58 @@ const retry = require("async-retry");
1111
*
1212
*/
1313

14+
const startingBlocks: Record<string, number> = {
15+
1: 18976112,
16+
10: 114647896,
17+
56: 39739873,
18+
100: 33619680,
19+
137: 55172593,
20+
185: 3417903,
21+
288: 2353048,
22+
324: 25006838,
23+
360: 2691201,
24+
480: 3466510,
25+
690: 254553,
26+
1101: 12491343,
27+
1135: 761002,
28+
1329: 118912096,
29+
2741: 4116,
30+
2911: 2136055,
31+
4321: 138647,
32+
5000: 72911632,
33+
5112: 1462668,
34+
7560: 896262,
35+
8333: 144055,
36+
8453: 9046270,
37+
17071: 58343,
38+
33139: 636958,
39+
33979: 238923,
40+
34443: 7297896,
41+
42161: 169028419,
42+
42170: 38963884,
43+
43114: 44583244,
44+
55244: 30,
45+
57073: 275058,
46+
59144: 1814719,
47+
60808: 275964,
48+
70700: 19,
49+
70701: 1543,
50+
81457: 216675,
51+
534352: 5560094,
52+
543210: 1282,
53+
660279: 4759873,
54+
984122: 2655107,
55+
7777777: 9094029,
56+
8253038: 865885,
57+
9286185: 17617195,
58+
666666666: 1310814,
59+
792703809: 279758248,
60+
888888888: 1278785,
61+
1380012617: 205727,
62+
};
63+
1464
const convertRequestToEvent = (
15-
request: NonNullable<RelayRequestsResponse["requests"]>["0"],
16-
blockNumber: number
65+
request: NonNullable<RelayRequestsResponse["requests"]>["0"]
1766
): { deposit?: EventData; withdraw?: EventData; depositChainId?: number; withdrawChainId?: number } => {
1867
const deposit = request.data?.metadata?.currencyIn;
1968
const withdraw = request.data?.metadata?.currencyOut;
@@ -23,31 +72,33 @@ const convertRequestToEvent = (
2372

2473
return {
2574
depositChainId: depositTx?.chainId,
26-
deposit: depositTx
27-
? {
28-
blockNumber: blockNumber, //MISSING: going to just fudge it for now
29-
txHash: depositTx.hash as string,
30-
from: (depositTx.data as any).to,
31-
to: (depositTx.data as any).from,
32-
token: deposit?.currency?.address!,
33-
amount: deposit?.amountUsd as any,
34-
isDeposit: true,
35-
isUSDVolume: true,
36-
}
37-
: undefined,
75+
deposit:
76+
depositTx && depositTx.data && deposit
77+
? {
78+
blockNumber: depositTx.block!,
79+
txHash: depositTx.hash as string,
80+
from: (depositTx.data as any).to,
81+
to: (depositTx.data as any).from,
82+
token: deposit?.currency?.address!,
83+
amount: deposit?.amountUsd as any,
84+
isDeposit: true,
85+
isUSDVolume: true,
86+
}
87+
: undefined,
3888
withdrawChainId: withdrawTx?.chainId,
39-
withdraw: withdrawTx
40-
? {
41-
blockNumber: blockNumber, //MISSING: going to just fudge it for now
42-
txHash: withdrawTx.hash!,
43-
from: (withdrawTx.data as unknown as any).from,
44-
to: (withdrawTx.data as unknown as any).to,
45-
token: withdraw?.currency?.address!,
46-
amount: withdraw?.amountUsd as any,
47-
isDeposit: false,
48-
isUSDVolume: true,
49-
}
50-
: undefined,
89+
withdraw:
90+
withdrawTx && withdrawTx.data && withdraw
91+
? {
92+
blockNumber: withdrawTx.block!,
93+
txHash: withdrawTx.hash!,
94+
from: (withdrawTx.data as unknown as any).from,
95+
to: (withdrawTx.data as unknown as any).to,
96+
token: withdraw?.currency?.address!,
97+
amount: withdraw?.amountUsd as any,
98+
isDeposit: false,
99+
isUSDVolume: true,
100+
}
101+
: undefined,
51102
};
52103
};
53104

@@ -77,7 +128,7 @@ const fetchAllRequests = async (
77128
let maxRequests = 10000;
78129
let requestCount = 0;
79130
while (continuation !== undefined && requestCount < maxRequests) {
80-
const response = await fetchRequests(chainId, fromBlock, toBlock);
131+
const response = await fetchRequests(chainId, fromBlock, toBlock, continuation);
81132
continuation = response.continuation;
82133
allRequests = [...allRequests, ...(response.requests ?? [])];
83134
}
@@ -86,10 +137,15 @@ const fetchAllRequests = async (
86137

87138
const constructParams = (chainId: number) => {
88139
return async (fromBlock: number, toBlock: number): Promise<EventData[]> => {
140+
//Performance optimization to limit empty requests
141+
const startingBlock = startingBlocks[chainId];
142+
if (startingBlock !== undefined && toBlock < startingBlock) {
143+
return [];
144+
}
89145
const requests = await fetchAllRequests(chainId, fromBlock, toBlock);
90146
const events: EventData[] = [];
91147
requests?.forEach((request) => {
92-
const event = convertRequestToEvent(request, fromBlock);
148+
const event = convertRequestToEvent(request);
93149
if (event.depositChainId === chainId && event.deposit) {
94150
events.push(event.deposit);
95151
}

src/adapters/relay/type.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export type RelayRequestsResponse = {
22
requests?: {
33
id?: string;
4+
/**
5+
* @description Note that fallback is returned in the case of a refund
6+
* @enum {string}
7+
*/
48
status?: "refund" | "delayed" | "waiting" | "failure" | "pending" | "success";
59
user?: string;
610
recipient?: string;
@@ -13,8 +17,11 @@ export type RelayRequestsResponse = {
1317
| "DEPOSIT_CHAIN_MISMATCH"
1418
| "N/A";
1519
fees?: {
20+
/** @description Estimated gas cost required for execution, in wei */
1621
gas?: string;
22+
/** @description The fixed fee which is always added to execution, in wei */
1723
fixed?: string;
24+
/** @description The dynamic fee which is a result of the chain and the amount, in wei */
1825
price?: string;
1926
};
2027
feesUsd?: {
@@ -23,10 +30,13 @@ export type RelayRequestsResponse = {
2330
price?: string;
2431
};
2532
inTxs?: {
33+
/** @description Total fees in wei */
2634
fee?: string;
2735
data?: unknown;
2836
stateChanges?: unknown;
2937
hash?: string;
38+
block?: number;
39+
/** @description The type of transaction, always set to onchain */
3040
type?: string;
3141
chainId?: number;
3242
timestamp?: number;
@@ -57,6 +67,26 @@ export type RelayRequestsResponse = {
5767
isNative?: boolean;
5868
};
5969
};
70+
/**
71+
* @example {
72+
* "currency": {
73+
* "chainId": 8453,
74+
* "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
75+
* "symbol": "USDC",
76+
* "name": "USD Coin",
77+
* "decimals": 6,
78+
* "metadata": {
79+
* "logoURI": "https://ethereum-optimism.github.io/data/USDC/logo.png",
80+
* "verified": false,
81+
* "isNative": false
82+
* }
83+
* },
84+
* "amount": "30754920",
85+
* "amountFormatted": "30.75492",
86+
* "amountUsd": "30.901612",
87+
* "minimumAmount": "30454920"
88+
* }
89+
*/
6090
refundCurrencyData?: {
6191
currency?: {
6292
chainId?: number;
@@ -82,6 +112,26 @@ export type RelayRequestsResponse = {
82112
metadata?: {
83113
sender?: string;
84114
recipient?: string;
115+
/**
116+
* @example {
117+
* "currency": {
118+
* "chainId": 8453,
119+
* "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
120+
* "symbol": "USDC",
121+
* "name": "USD Coin",
122+
* "decimals": 6,
123+
* "metadata": {
124+
* "logoURI": "https://ethereum-optimism.github.io/data/USDC/logo.png",
125+
* "verified": false,
126+
* "isNative": false
127+
* }
128+
* },
129+
* "amount": "30754920",
130+
* "amountFormatted": "30.75492",
131+
* "amountUsd": "30.901612",
132+
* "minimumAmount": "30454920"
133+
* }
134+
*/
85135
currencyIn?: {
86136
currency?: {
87137
chainId?: number;
@@ -100,6 +150,26 @@ export type RelayRequestsResponse = {
100150
amountUsd?: string;
101151
minimumAmount?: string;
102152
};
153+
/**
154+
* @example {
155+
* "currency": {
156+
* "chainId": 8453,
157+
* "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
158+
* "symbol": "USDC",
159+
* "name": "USD Coin",
160+
* "decimals": 6,
161+
* "metadata": {
162+
* "logoURI": "https://ethereum-optimism.github.io/data/USDC/logo.png",
163+
* "verified": false,
164+
* "isNative": false
165+
* }
166+
* },
167+
* "amount": "30754920",
168+
* "amountFormatted": "30.75492",
169+
* "amountUsd": "30.901612",
170+
* "minimumAmount": "30454920"
171+
* }
172+
*/
103173
currencyOut?: {
104174
currency?: {
105175
chainId?: number;
@@ -124,10 +194,13 @@ export type RelayRequestsResponse = {
124194
usesExternalLiquidity?: boolean;
125195
timeEstimate?: number;
126196
outTxs?: {
197+
/** @description Total fees in wei */
127198
fee?: string;
128199
data?: unknown;
129200
stateChanges?: unknown;
130201
hash?: string;
202+
block?: number;
203+
/** @description The type of transaction, always set to onchain */
131204
type?: string;
132205
chainId?: number;
133206
timestamp?: number;

src/data/bridgeNetworkData.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,18 +1762,46 @@ export default [
17621762
chains: [
17631763
"Ethereum",
17641764
"Optimism",
1765+
"BNB",
1766+
"Gnosis",
17651767
"Polygon",
1768+
"Mint",
1769+
"Boba",
1770+
"Zksync",
1771+
"Shape",
1772+
"World Chain",
1773+
"Redstone",
1774+
"Polygon Zkevm",
1775+
"Lisk",
1776+
"Sei",
1777+
"Hychain",
1778+
"Mantle",
1779+
"Ham",
1780+
"Cyber",
1781+
"B3",
1782+
"Base",
17661783
"Arbitrum",
17671784
"Arbitrum Nova",
17681785
"Avalanche",
1769-
"Mint",
1786+
"Superposition",
17701787
"Linea",
1771-
"Base",
1788+
"Bob",
1789+
"Apex",
1790+
"Boss",
17721791
"Blast",
17731792
"Scroll",
1793+
"Zero Network",
1794+
"Xai",
17741795
"Solana",
1775-
"Boba",
1776-
"Polygon zkEVM",
1796+
"Ancient8",
1797+
"Rari",
1798+
"Bitcoin",
1799+
"Eclipse",
1800+
"Degen",
1801+
"Funki",
1802+
"Mode",
1803+
"Proof of Play",
1804+
"Proof of Play Boss",
17771805
],
17781806
},
17791807
] as BridgeNetwork[];

src/utils/adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ export const runAdapterHistorical = async (
513513

514514
let solanaTimestampsMap = {} as { [blockNumber: number]: number };
515515

516-
if (chain === "solana" && !["debridgedln", "portal"].includes(bridgeDbName)) {
516+
if (chain === "solana" && !["debridgedln", "portal", "relay"].includes(bridgeDbName)) {
517517
latestSolanaBlock = await getLatestBlock("solana");
518518
const connection = getConnection();
519519

0 commit comments

Comments
 (0)