Skip to content

Commit

Permalink
Merge pull request #242 from roger-new/master
Browse files Browse the repository at this point in the history
add adapter for oooo.money
  • Loading branch information
vrtnd authored Jul 11, 2024
2 parents 0abba83 + 884e6fd commit 725c665
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 1 deletion.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import xswap from "./xswap";
import owlto from "./owlto";
import zkbridge from "./zkbridge";
import helixbridge from "./helixbridge"
import oooo from "./oooo";
import memebridge from "./memebridge"

export default {
Expand All @@ -78,6 +79,7 @@ export default {
portal,
binancepeg,
xdai,
oooo,
"avalanche-btc": avalanchebtc,
axelar,
rainbowbridge,
Expand Down
104 changes: 104 additions & 0 deletions src/adapters/oooo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { BigNumber } from 'ethers';

import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
import { constructTransferParams } from "../../helpers/eventParams";
import { Chain } from "@defillama/sdk/build/general";
import { EventData } from "../../utils/types";
import { getTxsBlockRangeEtherscan, wait } from "../../helpers/etherscan";
import { getTxsBlockRangeBtrScan } from "../../helpers/btr";
import { getTxsBlockRangeL2Scan } from "../../helpers/l2scan";

export const bridgesAddress = {
arbitrum: ["0xfe07bc6cb1fc0bf79716ab35c42763e4232e96c8"],
bsc: ["0xfe07bc6cb1fc0bf79716ab35c42763e4232e96c8"],
merlin: ["0xfe07bc6cb1fc0bf79716ab35c42763e4232e96c8"],
"b2-mainnet": ["0xfe07bc6cb1fc0bf79716ab35c42763e4232e96c8"],
btr: ["0xfe07bc6cb1fc0bf79716ab35c42763e4232e96c8"],
"rsk": ["0xfe07bc6cb1fc0bf79716ab35c42763e4232e96c8"]
} as const;

const nativeTokens: Record<string, string> = {
arbitrum: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
bsc: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
merlin: "0xF6D226f9Dc15d9bB51182815b320D3fBE324e1bA",
"b2-mainnet": "0x8dbf84c93727c85DB09478C83a8621e765D20eC2",
btr: "0xff204e2681a6fa0e2c3fade68a1b28fb90e4fc5f",
"rsk": "0x542FDA317318eBf1d3DeAF76E0B632741a7e677d",
};

type SupportedChains = keyof typeof bridgesAddress;

const constructParams = (chain: SupportedChains) => {
const bridgeAddress = bridgesAddress[chain];

let eventParams = [] as any;
bridgeAddress.map((address: string) => {
const transferWithdrawalParams: PartialContractEventParams = constructTransferParams(address, false);
const transferDepositParams: PartialContractEventParams = constructTransferParams(address, true);
eventParams.push(transferWithdrawalParams, transferDepositParams);
});

if (nativeTokens.hasOwnProperty(chain)) {
return async (fromBlock: number, toBlock: number) => {
const eventLogData = await getTxDataFromEVMEventLogs("oooo", chain as Chain, fromBlock, toBlock, eventParams);

const nativeEvents = await Promise.all([
...bridgeAddress.map(async (address: string, i: number) => {
await wait(300 * i); // for etherscan
let txs: any[] = [];
if (chain === "merlin" || chain === "b2-mainnet") {
txs = await getTxsBlockRangeL2Scan(chain, address, fromBlock, toBlock, {
includeSignatures: ["0x", "0x88d695b2"],
});
} else if(chain === "btr") {
txs = await getTxsBlockRangeBtrScan(address, fromBlock, toBlock, {
includeSignatures: ["0x", "0x88d695b2"],
})
} else {
txs = await getTxsBlockRangeEtherscan(chain, address, fromBlock, toBlock, {
includeSignatures: ["0x", "0x88d695b2"],
});
}
const eventsRes: EventData[] = txs.map((tx: any) => {
const event: EventData = {
txHash: tx.hash,
blockNumber: +tx.blockNumber,
from: tx.from,
to: tx.to,
token: nativeTokens[chain],
amount: BigNumber.from(tx.value),
isDeposit: address.toLowerCase() === tx.to,
};
return event;
});

return eventsRes;
}),
]
);

const allEvents = [...eventLogData, ...nativeEvents.flat()];
return allEvents;
};
} else {
return async (fromBlock: number, toBlock: number) =>
getTxDataFromEVMEventLogs("oooo", chain as Chain, fromBlock, toBlock, eventParams);
}
}

const adapter: BridgeAdapter = {
arbitrum: constructParams("arbitrum"),
bsc: constructParams("bsc"),
merlin: constructParams("merlin"),
bsquared: constructParams("b2-mainnet"),
bitlayer: constructParams("btr"),
// rootstock: constructParams("rsk"),
// bevm
// bevm_canary
// btc
// bob
// alienx
};

export default adapter;
21 changes: 21 additions & 0 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1308,4 +1308,25 @@ export default [
bitlayer: "btr",
},
},
{
id: 66,
displayName: "oooo",
bridgeDbName: "oooo",
iconLink: "icons:oooo",
largeTxThreshold: 10000,
url: "https://oooo.money",
chains: [
"Arbitrum",
"BSC",
"Merlin",
"BSquared",
"Bitlayer",
// "Rootstock",
],
chainMapping: {
bsquared: "b2-mainnet",
bitlayer: "btr",
rootstock: "rsk",
},
},
] as BridgeNetwork[];
2 changes: 1 addition & 1 deletion src/helpers/btr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const getBlockTXbyAddress = async (
//filter by address
const txList: any[] = data.result;
return txList;
}else if(data.includes('error')) {
}else if(data.hasOwnProperty('error')) {
console.error(JSON.stringify(data.error.json.message));
}
return []
Expand Down
70 changes: 70 additions & 0 deletions src/helpers/l2scan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { FunctionSignatureFilter } from "./bridgeAdapter.type";
const axios = require("axios");
const retry = require("async-retry");

const endpoints = {
merlin: "https://scan.merlinchain.io",
"b2-mainnet": "https://explorer.bsquared.network",
} as { [chain: string]: string };

export const getTxsBlockRangeL2Scan = async (
chain: string,
address: string,
startBlock: number,
endBlock: number,
functionSignatureFilter?: FunctionSignatureFilter
) => {
let txList: any[] = await getBlockTXbyAddress(chain, address, startBlock, endBlock);
// console.log(JSON.stringify(txList));
if (txList.length > 0) {
const filteredResults = txList.filter((tx: any) => {
if (functionSignatureFilter) {
const signature = tx.input.slice(0, 10);
if (
functionSignatureFilter.includeSignatures &&
!functionSignatureFilter.includeSignatures.includes(signature)
) {
return false;
}
if (
functionSignatureFilter.excludeSignatures &&
functionSignatureFilter.excludeSignatures.includes(signature)
) {
return false;
}
}
return true;
});
return filteredResults;
} else {
console.info(`No txs found for address ${address}.`);
return [];
}
};

const getBlockTXbyAddress = async (
chain: string,
address: string,
startBlock: number,
endBlock: number,
) => {
const endpoint = endpoints[chain];
let txList: any[] = []
let page = 1
while(true) {
let res = await retry(
() =>
axios.get(
`${endpoint}/api?module=account&action=txlist&address=${address}&endblock=${endBlock}&sort=asc&startblock=${startBlock}&offset=1000&page=${page}`
),
{ factor: 1, retries: 3 }
)
if (res.data.message == 'OK' && res.data.result.length != 0) {
txList = txList.concat(res.data.result)
} else {
break;
}
page++
}
return txList;
}

0 comments on commit 725c665

Please sign in to comment.