Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Indexer #281

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

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

60 changes: 22 additions & 38 deletions src/adapters/allbridge-classic/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Chain } from "@defillama/sdk/build/general";
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { constructTransferParams } from "../../helpers/eventParams";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { ContractEventParamsV2, } from "../../helpers/bridgeAdapter.type";
import { processEVMLogsExport } from "../../helpers/processTransactions";

const bridgeAddresses = {
ethereum: "0xBBbD1BbB4f9b936C3604906D7592A644071dE884",
Expand All @@ -11,46 +9,32 @@ const bridgeAddresses = {
polygon: "0xBBbD1BbB4f9b936C3604906D7592A644071dE884",
} as { [chain: string]: string };

const constructParams = (chain: string) => {
let eventParams = [] as PartialContractEventParams[];
const bridgeAddress = bridgeAddresses[chain];
const depositParams = constructTransferParams(bridgeAddress, true, {
excludeFrom: [bridgeAddress],
});
// const withdrawParams = constructTransferParams(bridgeAddress, false, {
// excludeTo: [bridgeAddress],
// });
const withdrawParams = {
const adapter = {} as any

Object.entries(bridgeAddresses).forEach(([chain, bridgeAddress]) => {
const withdrawParams: ContractEventParamsV2 = {
target: bridgeAddress,
topic: "Received(address,address,uint256,uint128,bytes4)",
abi: [
"event Received(address indexed recipient, address token, uint256 amount, uint128 indexed lockId, bytes4 source)",
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
amount: "amount",
token: "token",
to: "recipient",
},
abi: "event Received(address indexed to, address token, uint256 amount, uint128 indexed lockId, bytes4 source)",
fixedEventData: {
from: bridgeAddress,
},
isDeposit: false,
};
eventParams.push(depositParams, withdrawParams);
return async (fromBlock: number, toBlock: number) =>
getTxDataFromEVMEventLogs("allbridge-classic", chain as Chain, fromBlock, toBlock, eventParams);
};
const depositParams: ContractEventParamsV2 = {
target: bridgeAddress,
abi: "event Sent (bytes4 tokenSource, bytes32 tokenSourceAddress, address from, bytes32 indexed recipient, uint256 amount, uint128 indexed lockId, bytes4 destination)",
fixedEventData: {
to: bridgeAddress,
},
isDeposit: true,
transformLog: (log: any) => {
log.token = '0x'+log.args.tokenSourceAddress.slice(0, 40)
return log;
}
};

adapter[chain] = processEVMLogsExport([withdrawParams, depositParams]);
})

const adapter: BridgeAdapter = {
ethereum: constructParams("ethereum"),
polygon: constructParams("polygon"),
fantom: constructParams("fantom"),
avalanche: constructParams("avax"),
bsc: constructParams("bsc"),
};

export default adapter;
138 changes: 0 additions & 138 deletions src/adapters/allbridge-core/eventParsing.ts

This file was deleted.

104 changes: 10 additions & 94 deletions src/adapters/allbridge-core/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import axios, { AxiosResponse } from 'axios';
import { BigNumber } from 'ethers';
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { Chain } from "@defillama/sdk/build/general";
import { BridgeAdapter, ContractEventParamsV2, } from "../../helpers/bridgeAdapter.type";
import { EventData } from '../../utils/types';
import { fromHex } from 'tron-format-address';
import { getConnection } from '../../helpers/solana';
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { getTxDataFromTronEventLogs } from './eventParsing';
import { processEVMLogsExport } from "../../helpers/processTransactions";

const adapterName = "allbridge-core";

const lpAddresses = {
bsc: [
Expand Down Expand Up @@ -50,55 +46,30 @@ const lpAddresses = {
};

const constructParams = (chain: string) => {
let eventParams = [] as PartialContractEventParams[];
let eventParams = [] as ContractEventParamsV2[];
const lps = lpAddresses[chain];

for (const lpAddress of Object.values(lps)) {
const depositParams: PartialContractEventParams = {
for (const lpAddress of lps) {
const depositParams: ContractEventParamsV2 = {
target: lpAddress,
topic: "SwappedToVUsd(address,address,uint256,uint256,uint256)",
abi: [
"event SwappedToVUsd(address sender, address token, uint amount, uint vUsdAmount, uint fee)"
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash"
},
argKeys: {
from: "sender",
token: "token",
amount: "amount"
},
abi: "event SwappedToVUsd(address from, address token, uint amount, uint vUsdAmount, uint fee)",
fixedEventData: {
to: lpAddress,
},
isDeposit: true
};

const withdrawParams = {
const withdrawParams: ContractEventParamsV2 = {
target: lpAddress,
topic: "SwappedFromVUsd(address,address,uint256,uint256,uint256)",
abi: [
"event SwappedFromVUsd(address recipient, address token, uint256 vUsdAmount, uint256 amount, uint256 fee)",
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash",
},
argKeys: {
amount: "amount",
token: "token",
to: "recipient",
},
abi: "event SwappedFromVUsd(address to, address token, uint256 vUsdAmount, uint256 amount, uint256 fee)",
fixedEventData: {
from: lpAddress,
},
isDeposit: false,
};
eventParams.push(depositParams, withdrawParams);
eventParams.push(depositParams, withdrawParams)
}
return async (fromBlock: number, toBlock: number) =>
getTxDataFromEVMEventLogs(adapterName, chain as Chain, fromBlock, toBlock, eventParams);
return processEVMLogsExport(eventParams)
};

interface SolanaEvent {
Expand Down Expand Up @@ -148,61 +119,6 @@ const getSolanaEvents = async (fromSlot: number, toSlot: number): Promise<EventD
}));
};

function constructTronParams() {
const chain = "tron";
const eventParams: any[] = [];
const lps = lpAddresses[chain];
for (const lpAddress of Object.values(lps)) {
const depositParams = {
target: lpAddress,
eventName: "SwappedToVUsd",
logKeys: {
blockNumber: "block_number",
txHash: "transaction_id",
},
argKeys: {
from: "sender",
token: "token",
amount: "amount"
},
argGetters: {
amount: (log: any) => BigNumber.from(log.amount),
from: (log: any) => fromHex(log.sender),
token: (log: any) => fromHex(log.token),
},
fixedEventData: {
to: lpAddress,
},
isDeposit: true,
}
const withdrawParams = {
target: lpAddress,
eventName: "SwappedFromVUsd",
logKeys: {
blockNumber: "block_number",
txHash: "transaction_id",
},
argKeys: {
amount: "amount",
token: "token",
to: "recipient",
},
argGetters: {
amount: (log: any) => BigNumber.from(log.amount),
to: (log: any) => fromHex(log.recipient),
token: (log: any) => fromHex(log.token),
},
fixedEventData: {
from: lpAddress,
},
isDeposit: false,
}
eventParams.push(depositParams, withdrawParams);
}
return async (fromBlock: number, toBlock: number) =>
getTxDataFromTronEventLogs(adapterName, fromBlock, toBlock, eventParams);
}

const adapter: BridgeAdapter = {
ethereum: constructParams("ethereum"),
polygon: constructParams("polygon"),
Expand Down
Loading