Skip to content

Commit

Permalink
add cost and profit for lnv3
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Jan 26, 2024
1 parent 1f26e8a commit 4dea42f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 3 additions & 3 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export class AggregationResolver {
const isValid = (item) =>
!Object.values(item).some((value) => isUndefined(value) || isNull(value) || value === '');

const accFilters = [{ sender }, { recipient }].filter(isValid);
const relayerFilters = [{ relayer }, { needWithdrawLiquidity }].filter(isValid);
const accFilters = [{ sender: sender.toLowerCase() }, { recipient }].filter(isValid);
const relayerFilters = [{ relayer: relayer.toLowerCase() }, { needWithdrawLiquidity }].filter(isValid);
const accountCondition = accFilters.length ? { OR: accFilters } : {};
const relayerCondition = relayerFilters.length ? { AND: relayerFilters } : {};
const resultCondition = results && results.length ? { result: { in: results } } : {};
Expand All @@ -89,7 +89,7 @@ export class AggregationResolver {
const toChainCondition = toChains && toChains.length ? { toChain: { in: toChains } } : {};
const bridgeCondition = bridges && bridges.length ? { bridge: { in: bridges } } : {};
const recvTokenCondition =
recvTokenAddress && recvTokenAddress.length ? { recvTokenAddress: recvTokenAddress } : {};
recvTokenAddress && recvTokenAddress.length ? { recvTokenAddress: recvTokenAddress.toLowerCase() } : {};
const chainConditions = {
AND: {
...resultCondition,
Expand Down
21 changes: 20 additions & 1 deletion apollo/src/lnv3/lnv3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class Lnv3Service implements OnModuleInit {

if (record.endTxHash === '') {
const toChain = this.getDestChain(dstChainId);
const query = `query { lnv3RelayRecord(id: "${transferId}") { id, relayer, timestamp, transactionHash, slashed, requestWithdrawTimestamp }}`;
const query = `query { lnv3RelayRecord(id: "${transferId}") { id, relayer, timestamp, transactionHash, slashed, requestWithdrawTimestamp, fee }}`;
const relayRecord = await axios
.post(toChain.url, {
query: query,
Expand Down Expand Up @@ -216,6 +216,25 @@ export class Lnv3Service implements OnModuleInit {
where: { id: record.id },
data: updateData,
});

const cost = relayRecord.slashed ? relayRecord.fee : 0;
const profit = relayRecord.slashed ? record.fee : 0;
const providerId = this.genRelayInfoID(
transfer.chainId,
toChain.chainId,
record.relayer,
record.sendTokenAddress
);
const relayerInfo = await this.aggregationService.queryLnBridgeRelayInfoById({
id: providerId,
});
await this.aggregationService.updateLnBridgeRelayInfo({
where: { id: providerId },
data: {
cost: (BigInt(relayerInfo.cost) + BigInt(cost)).toString(),
profit: (BigInt(relayerInfo.profit) + BigInt(profit)).toString(),
},
});

this.logger.log(
`lnv3 [${transfer.chain}->${toChain.chain}] new status id: ${record.id} relayed responseTxHash: ${relayRecord.transactionHash}`
Expand Down

0 comments on commit 4dea42f

Please sign in to comment.