Skip to content

Commit c88560e

Browse files
authored
Fix Mayan volume issues (#417)
* set up mayan adapter * Add Mayan adapter and integrate event fetching and volume calculation * Refactor Mayan event fetching to use API key and improve error handling; streamline volume calculation logic * deleted pnpm lock yaml * removed old comment * Refactor Mayan event fetching to use secure API endpoint and improve error handling; update handler export for scheduled execution * added missing filters to process batch * fixed double counting txs, removed pricing from mayan's API and added correct chain assignments
1 parent d608031 commit c88560e

File tree

3 files changed

+57
-90
lines changed

3 files changed

+57
-90
lines changed

src/adapters/mayan/index.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,18 @@ type WormholeBridgeEvent = {
1313
};
1414

1515
const chains = [
16+
"solana",
1617
"ethereum",
17-
"avalanche",
18-
"avax",
19-
"bsc",
20-
"polygon",
18+
"base",
2119
"arbitrum",
2220
"optimism",
23-
"base",
24-
"zksync",
25-
"scroll",
26-
"aptos",
21+
"polygon",
22+
"avalanche",
23+
"bsc",
2724
"sui",
28-
"solana",
29-
"sei",
30-
"mantle",
31-
"fantom",
32-
"injective",
33-
"moonbeam",
34-
"oasis",
35-
"celo",
36-
"kaia",
37-
"near",
38-
"algorand",
39-
"terra",
40-
"terra classic",
41-
"karura",
42-
"acala",
43-
"wormchain",
25+
"unichain",
26+
"aptos",
27+
"linea",
4428
];
4529

4630
export const chainNameMapping: { [key: string]: string } = {
@@ -145,9 +129,6 @@ export const fetchMayanEvents = async (fromTimestamp: number, toTimestamp: numbe
145129
const sourceChain = wormholeChainMap[row.originChain] || row.originChain || "unknown";
146130
const destChain = wormholeChainMap[row.chain] || row.chain || "unknown";
147131

148-
// For deposits, swap source/dest (deposit means going FROM origin TO current chain)
149-
const [source, dest] = row.isDeposit ? [sourceChain, destChain] : [destChain, sourceChain];
150-
151132
// Parse USD amount
152133
const usdAmount = parseFloat(row.amountUsd || "0") || 0;
153134

@@ -159,8 +140,8 @@ export const fetchMayanEvents = async (fromTimestamp: number, toTimestamp: numbe
159140
token_address: row.token || "",
160141
token_usd_amount: String(usdAmount),
161142
token_amount: row.amount || "0",
162-
source_chain: source,
163-
destination_chain: dest,
143+
source_chain: sourceChain,
144+
destination_chain: destChain,
164145
is_deposit: row.isDeposit, // Include deposit flag for filtering in handler
165146
};
166147
});

src/data/bridgeNetworkData.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ export default [
24922492
"Plume",
24932493
"ZKsync Era",
24942494
"Metis",
2495-
"Sei"
2495+
"Sei",
24962496
],
24972497
chainMapping: {
24982498
"World Chain": "wc",
@@ -2546,27 +2546,27 @@ export default [
25462546
"hyperliquid": "hyperliquid", // Identity mapping
25472547
},
25482548
},
2549-
// {
2550-
// id: 99,
2551-
// displayName: "Mayan",
2552-
// bridgeDbName: "mayan",
2553-
// slug: "mayan",
2554-
// iconLink: "icons:mayana",
2555-
// largeTxThreshold: 10000,
2556-
// url: "https://swap.mayan.finance/",
2557-
// chains: [
2558-
// "Solana",
2559-
// "Ethereum",
2560-
// "Base",
2561-
// "Arbitrum",
2562-
// "Optimism",
2563-
// "Polygon",
2564-
// "Avalanche",
2565-
// "BSC",
2566-
// "Sui",
2567-
// "Unichain",
2568-
// "Aptos",
2569-
// "Linea",
2570-
// ],
2571-
// },
2549+
{
2550+
id: 99,
2551+
displayName: "Mayan",
2552+
bridgeDbName: "mayan",
2553+
slug: "mayan",
2554+
iconLink: "icons:mayan",
2555+
largeTxThreshold: 10000,
2556+
url: "https://swap.mayan.finance/",
2557+
chains: [
2558+
"Solana",
2559+
"Ethereum",
2560+
"Base",
2561+
"Arbitrum",
2562+
"Optimism",
2563+
"Polygon",
2564+
"Avalanche",
2565+
"BSC",
2566+
"Sui",
2567+
"Unichain",
2568+
"Aptos",
2569+
"Linea",
2570+
],
2571+
},
25722572
] as BridgeNetwork[];

src/handlers/runMayan.ts

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export const handler = async () => {
3434

3535
const processBatch = async (sql: any, batch: any[]) => {
3636
const start = dayjs().unix();
37-
const sourceTransactions = [];
38-
const destinationTransactions = [];
37+
const transactions = [];
3938

4039
for (const event of batch) {
4140
const {
@@ -44,60 +43,45 @@ export const handler = async () => {
4443
token_transfer_from_address,
4544
token_transfer_to_address,
4645
token_address,
47-
token_usd_amount,
46+
token_amount,
4847
source_chain,
4948
destination_chain,
49+
is_deposit,
5050
} = event;
5151

5252
const sourceChain = normalizeChainName(source_chain);
5353
const destinationChain = normalizeChainName(destination_chain);
5454

55-
if (bridgeIds[sourceChain]) {
56-
sourceTransactions.push({
57-
bridge_id: bridgeIds[sourceChain],
58-
chain: sourceChain,
55+
// Determine the correct chain to use for the bridge_id based on deposit status
56+
const transactionChain = is_deposit ? destinationChain : sourceChain;
57+
const originChain = is_deposit ? sourceChain : null;
58+
59+
// Only create one transaction per event, using the appropriate chain's bridge_id
60+
if (bridgeIds[transactionChain]) {
61+
transactions.push({
62+
bridge_id: bridgeIds[transactionChain],
63+
chain: transactionChain,
5964
tx_hash: transaction_hash,
6065
ts: parseInt(block_timestamp) * 1000,
6166
tx_block: null,
6267
tx_from: token_transfer_from_address ?? "0x",
6368
tx_to: token_transfer_to_address ?? "0x",
6469
token: token_address ?? "0x0000000000000000000000000000000000000000",
65-
amount: token_usd_amount || "0",
66-
is_deposit: true,
67-
is_usd_volume: true,
68-
txs_counted_as: 1,
69-
origin_chain: null,
70-
});
71-
}
72-
73-
if (bridgeIds[destinationChain]) {
74-
destinationTransactions.push({
75-
bridge_id: bridgeIds[destinationChain],
76-
chain: destinationChain,
77-
tx_hash: `${transaction_hash}_destination`,
78-
ts: parseInt(block_timestamp) * 1000,
79-
tx_block: null,
80-
tx_from: token_transfer_to_address ?? "0x",
81-
tx_to: token_transfer_from_address ?? "0x",
82-
token: token_address ?? "0x0000000000000000000000000000000000000000",
83-
amount: token_usd_amount || "0",
84-
is_deposit: false,
85-
is_usd_volume: true,
70+
amount: token_amount ?? "0",
71+
is_deposit: is_deposit,
72+
is_usd_volume: false,
8673
txs_counted_as: 1,
87-
origin_chain: null,
74+
origin_chain: originChain,
8875
});
8976
}
9077
}
9178

9279
try {
93-
if (sourceTransactions.length > 0) {
94-
await insertTransactionRows(sql, true, sourceTransactions, "upsert");
95-
}
96-
if (destinationTransactions.length > 0) {
97-
await insertTransactionRows(sql, true, destinationTransactions, "upsert");
80+
if (transactions.length > 0) {
81+
await insertTransactionRows(sql, true, transactions, "upsert");
9882
}
9983
} catch (error) {
100-
console.error(`Error inserting Wormhole batch:`, error);
84+
console.error(`Error inserting Mayan batch:`, error);
10185
throw error;
10286
}
10387

@@ -124,7 +108,7 @@ export const handler = async () => {
124108
const amount = parseFloat(curr.token_usd_amount || "0");
125109

126110
// Skip transactions over $1M (outliers from API issues. Mayan's API pricing isn't perfectly reliable, a majority of the outliers are caught with this)
127-
if (amount > 1000000) {
111+
if (amount > 1_000_000) {
128112
return acc;
129113
}
130114

@@ -143,4 +127,6 @@ export const handler = async () => {
143127
}
144128
};
145129

146-
export default wrapScheduledLambda(handler);
130+
// export default wrapScheduledLambda(handler);
131+
132+
handler().then(() => process.exit(0));

0 commit comments

Comments
 (0)