Skip to content

Commit

Permalink
xtoken refund
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Dec 25, 2023
1 parent cc16d81 commit d8d70d2
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 229 deletions.
11 changes: 6 additions & 5 deletions apollo/src/xtoken/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { AddressTokenMap } from '../base/AddressToken';
export class TransferService extends BaseTransferServiceT2 {
private readonly darwainiaUrl = this.configService.get<string>('XTOKEN_DARWINIA');
private readonly ethereumUrl = this.configService.get<string>('XTOKEN_ETHEREUM');
private readonly dispatchSubgraph = this.configService.get<string>('XTOKEN_DISPATCH');
private readonly darwiniaDispatchSubgraph = this.configService.get<string>('XTOKEN_DISPATCH_DARWINIA');
private readonly ethereumDispatchSubgraph = this.configService.get<string>('XTOKEN_DISPATCH_ETHEREUM');

formalChainTransfers: PartnerT2[] = [];

Expand Down Expand Up @@ -45,10 +46,10 @@ export class TransferService extends BaseTransferServiceT2 {
];

dispatchEndPoints = {
'crab-dvm': this.dispatchSubgraph + '/crab',
sepolia: this.dispatchSubgraph + '/sepolia',
darwinia: this.dispatchSubgraph + '/darwinia',
ethereum: this.dispatchSubgraph + '/ethereum',
'crab-dvm': this.darwiniaDispatchSubgraph,
sepolia: this.ethereumDispatchSubgraph,
darwinia: this.darwiniaDispatchSubgraph,
ethereum: this.ethereumDispatchSubgraph,
};
addressToTokenInfo: { [key: string]: AddressTokenMap } = {};

Expand Down
15 changes: 8 additions & 7 deletions apollo/src/xtoken/xtoken.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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, 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, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee } }`;

const records = await axios
.post(transfer.url, {
Expand Down Expand Up @@ -143,7 +143,7 @@ export class xTokenService implements OnModuleInit {
fromChain: transfer.chain,
toChain: toChain.chain,
bridge: 'xtoken-' + transfer.chain,
messageNonce: record.nonce,
messageNonce: record.messageId,
nonce: latestNonce + 1,
requestTxHash: record.transactionHash,
sender: record.sender,
Expand Down Expand Up @@ -197,14 +197,15 @@ export class xTokenService implements OnModuleInit {
}

for (const uncheckedRecord of uncheckedRecords) {
const id = this.nodeIdToTransferId(uncheckedRecord.id);
const sourceId = this.nodeIdToTransferId(uncheckedRecord.id);
const messageId = uncheckedRecord.messageNonce;
const node = await axios
.post(this.transferService.dispatchEndPoints[uncheckedRecord.toChain], {
query: `query { messageDispatchedResult (id: \"${id}\") { id, token, transactionHash, result, timestamp }}`,
query: `query { messageDispatchedResult (id: \"${messageId}\") { id, token, transactionHash, result, timestamp }}`,
variables: null,
})
.then((res) => res.data?.data?.messageDispatchedResult);
if (node === undefined || node.result === null) {
if (node === undefined || node === null || node.result === null) {
continue;
}
let result = uncheckedRecord.result;
Expand All @@ -229,7 +230,7 @@ export class xTokenService implements OnModuleInit {
if (uncheckedRecord.result === RecordStatus.pending || uncheckedRecord.result === RecordStatus.pendingToClaim) {
if (result !== uncheckedRecord.result) {
this.logger.log(
`${this.baseConfigure.name} [${uncheckedRecord.fromChain}-${uncheckedRecord.toChain}] status updated, id: ${id}, status ${uncheckedRecord.result}->${result}`
`${this.baseConfigure.name} [${uncheckedRecord.fromChain}-${uncheckedRecord.toChain}] status updated, id: ${sourceId}, status ${uncheckedRecord.result}->${result}`
);
await this.aggregationService.updateHistoryRecord({
where: { id: uncheckedRecord.id },
Expand All @@ -255,7 +256,7 @@ export class xTokenService implements OnModuleInit {
// all refund requests
const nodes = await axios
.post(destChain.url, {
query: `query { refundTransferRecords (where: {sourceId: "${id}"}) { id, sourceId, transactionHash, timestamp }}`,
query: `query { refundTransferRecords (where: {sourceId: "${sourceId}"}) { id, sourceId, transactionHash, timestamp }}`,
variables: null,
})
.then((res) => res.data?.data?.refundTransferRecords);
Expand Down
105 changes: 94 additions & 11 deletions subgraph/xtoken/messageDispatcher/abis/Guard.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
"internalType": "uint256",
"name": "_maxUnclaimableTime",
"type": "uint256"
},
{
"internalType": "address",
"name": "_depositor",
"type": "address"
}
],
"stateMutability": "nonpayable",
Expand Down Expand Up @@ -93,12 +88,24 @@
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
Expand Down Expand Up @@ -218,6 +225,11 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "uint256",
"name": "id",
Expand Down Expand Up @@ -256,6 +268,11 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "uint256",
"name": "id",
Expand All @@ -280,6 +297,11 @@
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bool",
"name": "isNative",
"type": "bool"
}
],
"name": "claimByTimeout",
Expand All @@ -289,11 +311,21 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"internalType": "address",
"name": "token",
Expand All @@ -308,24 +340,44 @@
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bytes[]",
"name": "signatures",
"type": "bytes[]"
}
],
"name": "deposit",
"name": "claimNative",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "depositor",
"outputs": [
"inputs": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "address",
"name": "",
"name": "token",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"stateMutability": "view",
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
Expand Down Expand Up @@ -524,6 +576,37 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "depositor",
"type": "address"
},
{
"internalType": "bool",
"name": "enable",
"type": "bool"
}
],
"name": "setDepositor",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_maxUnclaimableTime",
"type": "uint256"
}
],
"name": "setMaxUnclaimableTime",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
57 changes: 0 additions & 57 deletions subgraph/xtoken/messageDispatcher/abis/MsglineMessager.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
"name": "srcAppChainId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "transferId",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bool",
Expand All @@ -49,12 +43,6 @@
"name": "srcAppChainId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "transferId",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "address",
Expand Down Expand Up @@ -85,51 +73,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "latestRecvMessageId",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "latestSentMessageId",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "messageId",
"type": "bytes32"
}
],
"name": "messageDelivered",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
5 changes: 3 additions & 2 deletions subgraph/xtoken/messageDispatcher/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ dataSources:
- name: MsglineMessager
file: ./abis/MsglineMessager.json
eventHandlers:
- event: CallResult(uint256,bytes32,bool)
- event: CallResult(uint256,bool)
handler: handleCallResult
receipt: true
file: ./src/dispatch.ts" > subgraph.yaml
}

Expand All @@ -64,7 +65,7 @@ echo " - kind: ethereum/contract
- name: Guard
file: ./abis/Guard.json
eventHandlers:
- event: TokenDeposit(uint256,address,address,uint256)
- event: TokenDeposit(address,uint256,uint256,address,address,uint256)
handler: handleTokenDeposit
- event: TokenClaimed(uint256)
handler: handleTokenClaimed
Expand Down
4 changes: 2 additions & 2 deletions subgraph/xtoken/messageDispatcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"build-crab": "sh generate.sh dispatch crab 1877745 0x000000000EFcBAdA3793cC59c62D79b9f56Ae48F 0xCAb1f69C671f1548fd3dE5d63852E9B9181a0D0E && graph codegen && graph build",
"build-sepolia": "sh generate.sh dispatch sepolia 4865695 0x000000000EFcBAdA3793cC59c62D79b9f56Ae48F 0x527B67a61C6E1344C359Af2e241aAFeb0c3a9DE9 && sh generate.sh guard sepolia 0x2e8B5408Ec891AbdeE9CDeDCe407217c5e47196d 4865695 && graph codegen && graph build",
"build-crab": "sh generate.sh dispatch crab 1962560 0x0000000000D2de3e2444926c4577b0A59F1DD8BC 0xf85638B61E0425D6BB91981190B73246e3AF3CA9 && graph codegen && graph build",
"build-sepolia": "sh generate.sh dispatch sepolia 4952560 0x0000000000D2de3e2444926c4577b0A59F1DD8BC 0xc876D0873e4060472334E297b2db200Ca10cc806 && sh generate.sh guard sepolia 0x2e8B5408Ec891AbdeE9CDeDCe407217c5e47196d 4952560 && graph codegen && graph build",
"create-remote-dev": "graph create --access-token ${KEY} --node https://thegraph-g2.darwinia.network/helix/deploy/ xtokendispatch/${NETWORK}",
"deploy-remote-dev": "graph deploy --access-token $KEY --node https://thegraph-g2.darwinia.network/helix/deploy/ --ipfs https://ipfs.network.thegraph.com xtokendispatch/$NETWORK",
"create-remote-pro": "graph create --access-token ${KEY} --node https://thegraph.darwinia.network/helix/deploy/ xtokendispatch/${NETWORK}",
Expand Down
Loading

0 comments on commit d8d70d2

Please sign in to comment.