Skip to content

Commit

Permalink
bugfix:softtransferlimit
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Apr 12, 2024
1 parent 9bffc96 commit 5b493b1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,17 @@ export class AggregationResolver {
let updateData = {
heartbeatTimestamp: Math.floor(Date.now() / 1000),
};

if (softTransferLimit !== undefined && softTransferLimit !== '0') {
updateData['softTransferLimit'] = softTransferLimit;
// the softTransferLimit is on target chain, transfer it to source chain
const transferLimit = this.aggregationService.targetAmountToSourceAmount({
amount: softTransferLimit,
sourceChainId: Number(fromChainId),
targetChainId: Number(toChainId),
sourceToken: tokenAddress,
version
});
updateData['softTransferLimit'] = transferLimit;
}

try {
Expand Down Expand Up @@ -395,7 +404,7 @@ export class AggregationResolver {
continue;
}
const point = await this.aggregationService.calculateLnBridgeRelayerPoint(
token,
sendToken,
BigInt(amount),
decimals,
record
Expand Down
52 changes: 52 additions & 0 deletions apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,58 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
return this.tasksService.queryHealthChecks();
}

targetAmountToSourceAmount(params: {
amount: string;
sourceChainId: number;
targetChainId: number;
sourceToken: string;
version: string;
}): string {
const { amount, sourceChainId, targetChainId, sourceToken, version } = params;
let transferDecimals = (value: string, decimals: number) => {
if (decimals > 0) {
return value.padEnd(value.length + decimals);
} else if (value.length + decimals > 0) {
return value.substr(0, value.length + decimals);
} else {
return '0';
}
}

if (version === 'lnv2') {
const sourceNode = this.lnv2Service.transfers.find((item) => item.chainId === sourceChainId);
const sourceTokenInfo = sourceNode?.tokens.find(
(item) => item.fromAddress.toLowerCase() === sourceToken.toLowerCase()
);
if (sourceTokenInfo === undefined) {
return '0';
}
const targetNode = this.lnv2Service.transfers.find((item) => item.chainId === targetChainId);
const targetTokenInfo = targetNode?.tokens.find(
(item) => item.key === sourceTokenInfo.key
);
if (targetTokenInfo === undefined) {
return '0';
}

return transferDecimals(amount, sourceTokenInfo.decimals - targetTokenInfo.decimals);
} else {
const lnv3SourceBridge = this.lnv3Service.transfers.find((item) => item.chainId === sourceChainId);
const sourceSymbol = lnv3SourceBridge?.symbols.find(
(item) => item.address.toLowerCase() === sourceToken.toLowerCase()
);
if (sourceSymbol === undefined) {
return '0';
}
const lnv3TargetBridge = this.lnv3Service.transfers.find((item) => item.chainId === targetChainId);
const targetSymbol = lnv3TargetBridge?.symbols.find(
(item) => item.key === sourceSymbol.key
);

return transferDecimals(amount, sourceSymbol.decimals - targetSymbol.decimals);
}
}

checkLnBridgeConfigure(params: {
sourceChainId: number;
targetChainId: number;
Expand Down

0 comments on commit 5b493b1

Please sign in to comment.