Skip to content

Commit

Permalink
add wormhole
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Nov 27, 2024
1 parent 3b7a80b commit 51662ad
Show file tree
Hide file tree
Showing 12 changed files with 552 additions and 42 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ name: Deploy

on:
push:
branches: [ master ]
branches: [master]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Node.js
uses: actions/setup-node@v1
with:
node-version: '16'
- run: npm ci
- name: Type Check
run: npm run ts
- name: Deploy infrastructure stack
run: npm run deploy:prod
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PSQL_URL: ${{ secrets.PSQL_URL }}
PSQL_USERNAME: ${{ secrets.PSQL_USERNAME }}
PSQL_PW: ${{ secrets.PSQL_PW }}
BSC_RPC: ${{ secrets.BSC_RPC }}
CELO_RPC: ${{ secrets.CELO_RPC }}
ETHEREUM_RPC: ${{ secrets.ETHEREUM_RPC }}
OPTIMISM_RPC: ${{ secrets.OPTIMISM_RPC }}
AURORA_RPC: ${{ secrets.AURORA_RPC }}
ARBITRUM_RPC: ${{ secrets.ARBITRUM_RPC }}
SOLANA_RPC: ${{ secrets.SOLANA_RPC }}
RSK_ARCHIVAL_RPC: ${{ secrets.RSK_ARCHIVAL_RPC }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
- uses: actions/checkout@v2
- name: Get Node.js
uses: actions/setup-node@v1
with:
node-version: "16"
- run: npm ci
- name: Type Check
run: npm run ts
- name: Deploy infrastructure stack
run: npm run deploy:prod
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PSQL_URL: ${{ secrets.PSQL_URL }}
PSQL_USERNAME: ${{ secrets.PSQL_USERNAME }}
PSQL_PW: ${{ secrets.PSQL_PW }}
BSC_RPC: ${{ secrets.BSC_RPC }}
CELO_RPC: ${{ secrets.CELO_RPC }}
ETHEREUM_RPC: ${{ secrets.ETHEREUM_RPC }}
OPTIMISM_RPC: ${{ secrets.OPTIMISM_RPC }}
AURORA_RPC: ${{ secrets.AURORA_RPC }}
ARBITRUM_RPC: ${{ secrets.ARBITRUM_RPC }}
RSK_ARCHIVAL_RPC: ${{ secrets.RSK_ARCHIVAL_RPC }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
ALLIUM_API_KEY: ${{ secrets.ALLIUM_API_KEY }}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"axios": "^0.21.0",
"axios-rate-limit": "^1.3.0",
"bignumber.js": "^9.0.1",
"dayjs": "^1.11.13",
"dotenv": "^8.2.0",
"ethers": "^5",
"graphql": "^16.0.0",
Expand Down
8 changes: 7 additions & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ provider:
OPTIMISM_RPC: ${env:OPTIMISM_RPC}
AURORA_RPC: ${env:AURORA_RPC}
ARBITRUM_RPC: ${env:ARBITRUM_RPC}
SOLANA_RPC: ${env:SOLANA_RPC}
RSK_ARCHIVAL_RPC: ${env:RSK_ARCHIVAL_RPC}
DISCORD_WEBHOOK: ${env:DISCORD_WEBHOOK}
ALLIUM_API_KEY: ${env:ALLIUM_API_KEY}

functions:
bridgeDayStats:
Expand Down Expand Up @@ -177,6 +177,12 @@ functions:
- http:
path: netflows/{period}
method: get
runWormhole:
handler: src/handlers/runWormhole.default
timeout: 900
events:
- schedule: cron(0 * * * ? *)

resources:
# CORS for api gateway errors
- ${file(resources/api-gateway-errors.yml)}
Expand Down
6 changes: 4 additions & 2 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ import fastbtc from "./rootstock-fastbtc-bridge";
import crowdswap from "./crowdswap";
import mint from "./mint";
import suibridge from "./suibridge";
import retrobridge from "./retrobridge"
import layerswap from "./layerswap"
import retrobridge from "./retrobridge";
import layerswap from "./layerswap";
import hyperlane from "./hyperlane";
import wormhole from "./wormhole";

export default {
polygon,
Expand Down Expand Up @@ -147,6 +148,7 @@ export default {
retrobridge,
layerswap,
hyperlane,
wormhole,
} as {
[bridge: string]: BridgeAdapter | AsyncBridgeAdapter;
};
138 changes: 138 additions & 0 deletions src/adapters/wormhole/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import dayjs from "dayjs";
import { queryAllium } from "../../helpers/allium";

type WormholeBridgeEvent = {
block_timestamp: string;
transaction_hash: string;
token_transfer_from_address: string;
token_transfer_to_address: string;
token_address: string;
token_usd_amount: string;
token_amount: string;
source_chain: string;
destination_chain: string;
};

const chains = [
"ethereum",
"avalanche",
"avax",
"bsc",
"polygon",
"arbitrum",
"optimism",
"base",
"zksync",
"scroll",
"aptos",
"sui",
"solana",
"sei",
"mantle",
"fantom",
"injective",
"moonbeam",
"oasis",
"celo",
"kaia",
"near",
"algorand",
"terra",
"terra classic",
"karura",
"acala",
];

export const chainNameMapping: { [key: string]: string } = {
ethereum: "Ethereum",
avalanche: "Avalanche",
avax: "Avalanche",
polygon: "Polygon",
arbitrum: "Arbitrum",
optimism: "Optimism",
fantom: "Fantom",
base: "Base",
solana: "Solana",
sui: "Sui",
aptos: "Aptos",
celo: "Celo",
mantle: "Mantle",
scroll: "Scroll",
algorand: "Algorand",
sei: "Sei",
moonbeam: "Moonbeam",
injective: "Injective",
kaia: "Kaia",
oasis: "Oasis",
BNB_Smart_Chain: "BSC",
bnb_smart_chain: "BSC",
terra: "Terra Classic",
terra2: "Terra",
"terra classic": "Terra Classic",
near: "Near",
};

export function normalizeChainName(chainName: string): string {
const lowercaseChain = chainName.toLowerCase();

const mapping = chainNameMapping[lowercaseChain] || chainNameMapping[chainName];

if (mapping) {
return mapping?.toLowerCase();
}

return chainName?.toLowerCase();
}

export const fetchWormholeEvents = async (
fromTimestamp: number,
toTimestamp: number
): Promise<WormholeBridgeEvent[]> => {
let allResults: WormholeBridgeEvent[] = [];
let currentTimestamp = fromTimestamp;
const BATCH_SIZE = 10000;

while (currentTimestamp < toTimestamp) {
const result = await queryAllium(`
select
BLOCK_TIMESTAMP,
TOKEN_TRANSFER_FROM_ADDRESS,
TOKEN_TRANSFER_TO_ADDRESS,
TOKEN_ADDRESS,
TOKEN_USD_AMOUNT,
TOKEN_AMOUNT,
SOURCE_CHAIN,
DESTINATION_CHAIN,
UNIQUE_ID AS transaction_hash
from org_db__defillama.default.wormhole_token_transfers
where
block_timestamp BETWEEN TO_TIMESTAMP_NTZ(${currentTimestamp}) AND TO_TIMESTAMP_NTZ(${toTimestamp})
and status != 'REFUNDED'
order by block_timestamp
limit ${BATCH_SIZE};
`);

if (result.length === 0) break;

const normalizedBatch = result.map((row: any) => ({
...row,
block_timestamp: dayjs(row.block_timestamp).unix(),
}));

allResults = [...allResults, ...normalizedBatch];
console.log(`Fetched ${allResults.length} Wormhole events.`);

currentTimestamp = normalizedBatch[normalizedBatch.length - 1].block_timestamp + 1;

if (result.length < BATCH_SIZE) break;
}

return allResults;
};

const adapter = chains.reduce((acc: any, chain: string) => {
acc[chain] = true;
return acc;
}, {});

export default adapter;
43 changes: 40 additions & 3 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export default [
// avalanche: "avax",
// },
// },


{
id: 10,
Expand Down Expand Up @@ -1514,7 +1513,7 @@ export default [
bridgeDbName: "retrobridge",
iconLink: "icons:retrobridge",
largeTxThreshold: 10000,
url: 'https://retrobridge.io/',
url: "https://retrobridge.io/",
chains: [
"Ethereum",
"Arbitrum",
Expand Down Expand Up @@ -1573,7 +1572,7 @@ export default [
"Linea",
"Blast",
"Scroll",
"BSC",
"BSC",
"X Layer",
"Taiko",
"ZKsync Era",
Expand Down Expand Up @@ -1689,4 +1688,42 @@ export default [
avalanche: "avax",
},
},
{
id: 77,
displayName: "Wormhole",
bridgeDbName: "wormhole",
iconLink: "icons:portal",
largeTxThreshold: 10000,
url: "https://portalbridge.com/",
chains: [
"Ethereum",
"Polygon",
"Fantom",
"Avalanche",
"Aurora",
"Celo",
"Klaytn",
"BSC",
"Moonbeam",
"Optimism",
"Arbitrum",
"Base",
"Solana",
"Near",
"Aptos",
"Sui",
"Sei",
"Karura",
"Acala",
"Algorand",
"Terra",
"Terra Classic",
"Oasis",
"Celo",
"Kaia",
],
chainMapping: {
avalanche: "avax",
},
},
] as BridgeNetwork[];
Loading

0 comments on commit 51662ad

Please sign in to comment.