diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index 60667584..a8968488 100644 --- a/apollo/src/xtoken/xtoken.service.ts +++ b/apollo/src/xtoken/xtoken.service.ts @@ -77,6 +77,14 @@ export class xTokenService implements OnModuleInit { ); } + private toMessageNonce(messageId: string, nonce: string): string { + return `${nonce}-${messageId}`; + } + + private toMessageId(messageNonce: string): string { + return last(messageNonce.split('-')); + } + private getToken(chain: PartnerT2, symbolOrAddress: string): PartnerSymbol | null { return ( chain.symbols.find( @@ -106,7 +114,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, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee } }`; + 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 } }`; const records = await axios .post(transfer.url, { @@ -143,7 +151,7 @@ export class xTokenService implements OnModuleInit { fromChain: transfer.chain, toChain: toChain.chain, bridge: 'xtoken-' + transfer.chain, - messageNonce: record.messageId, + messageNonce: this.toMessageNonce(record.messageId, record.userNonce), nonce: latestNonce + 1, requestTxHash: record.transactionHash, sender: record.sender, @@ -198,7 +206,7 @@ export class xTokenService implements OnModuleInit { for (const uncheckedRecord of uncheckedRecords) { const sourceId = this.nodeIdToTransferId(uncheckedRecord.id); - const messageId = uncheckedRecord.messageNonce; + const messageId = this.toMessageId(uncheckedRecord.messageNonce); const node = await axios .post(this.transferService.dispatchEndPoints[uncheckedRecord.toChain], { query: `query { messageDispatchedResult (id: \"${messageId}\") { id, token, transactionHash, result, timestamp }}`, diff --git a/subgraph/xtoken/transfer/schema.graphql b/subgraph/xtoken/transfer/schema.graphql index 3360658c..aee13107 100644 --- a/subgraph/xtoken/transfer/schema.graphql +++ b/subgraph/xtoken/transfer/schema.graphql @@ -16,6 +16,7 @@ type TransferRecord @entity { timestamp: BigInt! transactionHash: Bytes! fee: BigInt + userNonce: String! } type RefundTransferRecord @entity { diff --git a/subgraph/xtoken/transfer/src/xTokenBacking.ts b/subgraph/xtoken/transfer/src/xTokenBacking.ts index ebb6e4c3..6e5c0de2 100644 --- a/subgraph/xtoken/transfer/src/xTokenBacking.ts +++ b/subgraph/xtoken/transfer/src/xTokenBacking.ts @@ -47,6 +47,7 @@ export function handleTokenLocked(event: TokenLocked): void { entity.transactionHash = event.transaction.hash; entity.timestamp = event.block.timestamp; entity.fee = event.params.fee; + entity.userNonce = event.params.nonce.toHexString(); var messageId: string; // find the messageId diff --git a/subgraph/xtoken/transfer/src/xTokenIssuing.ts b/subgraph/xtoken/transfer/src/xTokenIssuing.ts index c2e23dd2..e849b976 100644 --- a/subgraph/xtoken/transfer/src/xTokenIssuing.ts +++ b/subgraph/xtoken/transfer/src/xTokenIssuing.ts @@ -47,6 +47,7 @@ export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void entity.transactionHash = event.transaction.hash; entity.timestamp = event.block.timestamp; entity.fee = event.params.fee; + entity.userNonce = event.params.nonce.toHexString(); var messageId: string; // find the messageId