Skip to content

Commit

Permalink
Merge pull request #252 from nova577metaverse/master
Browse files Browse the repository at this point in the history
fix: fix issue when check internal txs and btr scan
  • Loading branch information
vrtnd authored Jul 12, 2024
2 parents 725c665 + a9337f9 commit 54d8b46
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
17 changes: 7 additions & 10 deletions src/adapters/orbiter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const constructParams = (chain: string) => {

const nativeEvents = await Promise.all(
eoaAddressNative.map(async (address: string, i: number) => {
await wait(300 * i); // for etherscan
await wait(500 * i); // for etherscan
let txs: any[] = [];
if (chain === "merlin") {
txs = await getTxsBlockRangeMerlinScan(address, fromBlock, toBlock, {
Expand Down Expand Up @@ -149,24 +149,21 @@ const constructParams = (chain: string) => {
);
const contractEvents = await Promise.all(
contractsAddress.map(async (address: string, i: number) => {
console.log(address);
await wait(300 * i); // for etherscan
const txs: any[] = await getTxsBlockRangeEtherscan(chain, address, fromBlock, toBlock, {
includeSignatures: padContractSignature,
});
const eventsRes: EventData[] = []
for( const tx of txs) {
let value = BigNumber.from(0);
let isDepositTemp = true;
if(tx.value == '0') {
value = await getPadContractTxValue(chain, tx.hash);
const {internalValue, isDeposit} = await getPadContractTxValue(chain, tx.hash);
value = internalValue;
isDepositTemp = isDeposit;
}
else {
value = tx.value;
}
let isDeposit = true;
if(value.isNegative()){
value.mul(-1)
isDeposit = false;
value = BigNumber.from(tx.value);
}
const event: EventData = {
txHash: tx.hash,
Expand All @@ -175,7 +172,7 @@ const constructParams = (chain: string) => {
to: tx.to,
token: nativeTokens[chain],
amount: value,
isDeposit,
isDeposit: isDepositTemp,
};
eventsRes.push(event);
}
Expand Down
16 changes: 9 additions & 7 deletions src/adapters/orbiter/processTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { getProvider } from "@defillama/sdk/build/general";
import { BigNumber, ethers } from "ethers"
import padAbi from './abi.json' assert { type: 'json' };

export async function getPadContractTxValue(chain: string, txHash: string, ): Promise<BigNumber> {
export async function getPadContractTxValue(chain: string, txHash: string, ): Promise<{internalValue: BigNumber, isDeposit: boolean}> {
console.log(`start getPadContractTxValue, ${txHash}`);
const provider = getProvider(chain);
const txReceipt = await provider.getTransactionReceipt(txHash);
if(!txReceipt){
return BigNumber.from(0);
return { internalValue: BigNumber.from(0), isDeposit: true };
}

const contractInterface = new ethers.utils.Interface(padAbi);
Expand All @@ -18,23 +18,25 @@ export async function getPadContractTxValue(chain: string, txHash: string, ): Pr
}
catch(error) {
const e = error as Error;
console.error(e.message);
return null
console.error("parse log fail:", e.message);
return null;
}
}).filter(log => log != null) as ethers.utils.LogDescription[];

let totalValue = BigNumber.from(0)
let totalValue = BigNumber.from(0);
let isDeposit = true;
for(const parsedLog of parsedLogs) {
let value = BigNumber.from(0);
if(parsedLog.name == 'SuccessfulLaunchMessage') {
//TODO: add contract process
value = parsedLog.args[6]
} else if (parsedLog.name == 'SuccessfulLanding') {
value = BigNumber.from(parsedLog.args[1][8]).mul(-1)
value = BigNumber.from(parsedLog.args[1][8])
isDeposit = false;
} else if (parsedLog.name == 'SuccessfulLaunchMultiMessages') {
value = parsedLog.args[6]
}
totalValue = totalValue.add(value);
}
return totalValue;
return { internalValue: totalValue, isDeposit };
}
26 changes: 13 additions & 13 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,32 +1124,32 @@ export default [
"Blast",
"Arbitrum Nova",
"Scroll",
"Manta",
"Mode",
"zkSync Era",
"Polygon zkEVM",
"Merlin",
"Bitlayer",
"ZkLink",
"X Layer",
"BSC",
"Bouncebit",
"Mantle",
"Zkfair",
"opBNB",
"Taiko",
"BSquared",
// "Mantle",
// "Zkfair",
// "BSquared",
// "Bouncebit",
// "X Layer",
// "opBNB",
// "Mode",
// "Manta",
],
chainMapping: {
"arbitrum nova": "arbitrum_nova",
"zksync era": "era",
"polygon zkevm": "polygon_zkevm",
bsquared: "b2-mainnet",
bitlayer: "btr",
"x layer": "xlayer",
bouncebit: "bouncebit-mainnet",
opbnb: "op_bnb",
taiko: "tko-mainnet"
taiko: "tko-mainnet",
// bsquared: "b2-mainnet",
// "x layer": "xlayer",
// bouncebit: "bouncebit-mainnet",
// opbnb: "op_bnb",
},
},
{
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/btr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ const getBlockTXbyAddress = async (
`https://api.btrscan.com/scan/api?module=account&action=txlist&address=${address}&startBlock=${startBlock}&endBlock=${endBlock}&sort=asc`
)
const data = res.data
if(data.message == 'OK' && data.result.length != 0) {
if(data.message == 'OK' && data.status == 1 &&data.result.length != 0 ) {
//filter by address
const txList: any[] = data.result;
return txList;
}else if(data.hasOwnProperty('error')) {
console.error(JSON.stringify(data.error.json.message));
}
return []
}

0 comments on commit 54d8b46

Please sign in to comment.