diff --git a/apollo/.env.prod b/apollo/.env.prod index 3b94bd7e..301bb80a 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -41,7 +41,7 @@ XTOKEN_DARWINIA_CRAB_BACKING=https://thegraph.darwinia.network/helix/subgraphs/n XTOKEN_DARWINIA_CRAB_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-issuing XTOKEN_CRAB_DARWINIA_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-backing XTOKEN_CRAB_DARWINIA_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-issuing -XTOKEN_DARWINIA_ETHEREUM_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/build-darwinia-ethereum-backing +XTOKEN_DARWINIA_ETHEREUM_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-ethereum-backing XTOKEN_DARWINIA_ETHEREUM_ISSUING=https://api.studio.thegraph.com/query/59403/xtoken-dar-ethereum-issuing/v1.0.0 XTOKEN_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab XTOKEN_DISPATCH_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/darwinia diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index 8bcfffaa..195277f4 100644 --- a/apollo/src/xtoken/xtoken.service.ts +++ b/apollo/src/xtoken/xtoken.service.ts @@ -99,7 +99,22 @@ export class xTokenService implements OnModuleInit { return `${from}2${to}-${this.baseConfigure.name}(${direction})-${id}`; } + findPartner(transfer: PartnerT2): PartnerT2 { + return ( + this.transferService.transfers.find( + (target) => + target.bridge === transfer.bridge && target.chainId !== transfer.chainId + ) ?? null + ); + } + async fetchRecords(transfer: PartnerT2, index: number) { + const partner = this.findPartner(transfer); + if (partner === null) { + this.logger.error(`xtoken can't find partner ${transfer.chainId}, ${transfer.bridge}`); + return; + } + // the nonce of cBridge message is not increased let latestNonce = this.fetchCache[index].latestNonce; try { @@ -107,6 +122,7 @@ export class xTokenService implements OnModuleInit { const firstRecord = await this.aggregationService.queryHistoryRecordFirst( { fromChain: transfer.chain, + toChain: partner.chain, bridge: 'xtoken-' + transfer.chain, }, { nonce: 'desc' } @@ -114,7 +130,7 @@ export class xTokenService implements OnModuleInit { latestNonce = firstRecord ? Number(firstRecord.nonce) : 0; } - const query = `query { transferRecords(first: ${this.baseConfigure.fetchHistoryDataFirst}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, direction, remoteChainId, nonce, userNonce, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee, extData } }`; + const query = `query { transferRecords(where: {remoteChainId: ${partner.chainId}}, first: ${this.baseConfigure.fetchHistoryDataFirst}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, direction, remoteChainId, nonce, userNonce, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee, extData } }`; const records = await axios .post(transfer.url, { @@ -193,6 +209,12 @@ export class xTokenService implements OnModuleInit { } async fetchStatus(transfer: PartnerT2, index: number) { + const partner = this.findPartner(transfer); + if (partner === null) { + this.logger.error(`xtoken can't find partner ${transfer.chainId}, ${transfer.bridge}`); + return; + } + try { const uncheckedRecords = await this.aggregationService .queryHistoryRecords({ @@ -200,6 +222,7 @@ export class xTokenService implements OnModuleInit { take: this.baseConfigure.takeEachTime, where: { fromChain: transfer.chain, + toChain: partner.chain, bridge: `xtoken-${transfer.chain}`, responseTxHash: '', },