Skip to content

Commit

Permalink
withdraw conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Oct 11, 2024
1 parent d930cdd commit 8c016f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@composedb/client": "0.5.0",
"@composedb/types": "0.5.0",
"@helixbridge/helixconf": "1.1.15",
"@helixbridge/helixconf": "1.1.17",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/dataworker/dataworker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export class DataworkerService implements OnModuleInit {
return feeUsed;
}

// MUST: countThreshold <= 40 ELSE invalid threshold
async queryLiquidity(
url: string,
fromChain: string,
Expand Down
27 changes: 17 additions & 10 deletions src/relayer/relayer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import { SingleService } from "../base/safe-service/single.service";
import { SafeGlobalService } from "../base/safe-service/safeglobal.service";
import { SafeService } from "../base/safe-service/safe.service";

const kMaxWithdrawTransferCount = 16;
export const kMaxWithdrawTransferAmount: bigint = BigInt(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);

export class ChainInfo {
chainName: string;
rpcs: string[];
Expand Down Expand Up @@ -225,8 +230,7 @@ export class RelayerService implements OnModuleInit {
txHashCache: "",
checkTimes: 0,
lendMarket: lendMarket ?? [],
//multicall: new MulticallContract(chainInfo.multicallAddress, provider),
multicall: new MulticallContract("0xcA11bde05977b3631167028862bE2a173976CA11", provider),
multicall: new MulticallContract(chainInfo.additional.multicallAddress, provider),
},
];
})
Expand Down Expand Up @@ -885,19 +889,22 @@ export class RelayerService implements OnModuleInit {
lockInfo
);
if (Number(txStatus) === 1) {
filterTransferIds.push(needWithdrawRecords.transferIds[index]);
if (filterTransferIds.length < kMaxWithdrawTransferCount) {
filterTransferIds.push(needWithdrawRecords.transferIds[index]);
}
totalAmount += amountWithFeeAndPenalty;
}
index++;
if (filterTransferIds.length >= 16) {
break;
}
}
let countThreshold = lnProvider.withdrawLiquidityCountThreshold;
if (!countThreshold) {
countThreshold = 0;
if (!countThreshold || countThreshold > kMaxWithdrawTransferCount) {
countThreshold = kMaxWithdrawTransferCount;
}
let amountThreshold = kMaxWithdrawTransferAmount;
if (lnProvider.withdrawLiquidityAmountThreshold) {
amountThreshold = BigInt(lnProvider.withdrawLiquidityAmountThreshold);
}
if (filterTransferIds.length >= countThreshold) {
if (filterTransferIds.length >= countThreshold || totalAmount >= amountThreshold) {
// token transfer direction fromChain -> toChain
// withdrawLiquidity message direction toChain -> fromChain
const fromChannelAddress = this.configureService.getMessagerAddress(
Expand Down Expand Up @@ -946,7 +953,7 @@ export class RelayerService implements OnModuleInit {
this.logger.log(
`withdrawLiquidity ${fromChainInfo.chainId}->${
toChainInfo.chainId
}, info: ${JSON.stringify(needWithdrawRecords)}, fee: ${
}, info: ${JSON.stringify(filterTransferIds)}, fee: ${
params.fee
}`
);
Expand Down

0 comments on commit 8c016f3

Please sign in to comment.