diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bfcfb7d7..ed7d3963 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,6 +8,9 @@ on: # on: # pull_request: +env: + DOCKER_REGISTRY: ghcr.io + jobs: publish-apollo: name: Publish apollo @@ -18,9 +21,9 @@ jobs: - name: Docker login uses: docker/login-action@v1 with: - username: ${{ secrets.QUAY_IO_BOT_USERNAME }} - password: ${{ secrets.QUAY_IO_BOT_PASSWORD }} - registry: quay.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ${{ env.DOCKER_REGISTRY }} - uses: benjlevesque/short-sha@v1.2 id: short-sha @@ -31,10 +34,11 @@ jobs: id: tag-name - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: - file: apollo/Dockerfile push: true + #context: apollo + file: apollo/Dockerfile tags: | - quay.io/helix-bridge/apollo:sha-${{ steps.short-sha.outputs.sha }} - quay.io/helix-bridge/apollo:${{ steps.tag-name.outputs.tag }} + ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}:sha-${{ steps.short-sha.outputs.sha }} + ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}:${{ steps.tag-name.outputs.tag }} diff --git a/apollo/.env.prod b/apollo/.env.prod index e1fc354b..84849e86 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -37,9 +37,15 @@ SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1. DARWINIA_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv3/darwinia BLAST_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-blast/v1.0.0 -XTOKEN_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia +XTOKEN_DARWINIA_CRAB_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-backing +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/darwinia-ethereum-backing +XTOKEN_DARWINIA_ETHEREUM_ISSUING=https://api.studio.thegraph.com/query/59403/xtoken-dar-ethereum-issuing/v1.0.2 XTOKEN_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab XTOKEN_DISPATCH_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/darwinia XTOKEN_DISPATCH_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/crab +XTOKEN_DISPATCH_ETHEREUM=https://api.studio.thegraph.com/query/59403/xtoken-dispatch-ethereum/v1.0.0 CHAIN_TYPE=formal diff --git a/apollo/.env.test b/apollo/.env.test index bd30b356..9b6c9d32 100644 --- a/apollo/.env.test +++ b/apollo/.env.test @@ -26,7 +26,7 @@ ZKSYNC_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-zksepolia/ BERA_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/bera TAIKO_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/taiko -XTOKEN_DARWINIA = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokentransfer/pangolin -XTOKEN_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.3 +XTOKEN_DARWINIA_ETHEREUM_BACKING = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokentransfer/pangolin +XTOKEN_DARWINIA_ETHEREUM_ISSUING = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.8 XTOKEN_DISPATCH_DARWINIA = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokendispatch/pangolin -XTOKEN_DISPATCH_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-dispatch-sepolia/v1.1.3 +XTOKEN_DISPATCH_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-dispatch-sepolia/v1.1.4 diff --git a/apollo/Dockerfile b/apollo/Dockerfile index a3ab621b..987426d1 100644 --- a/apollo/Dockerfile +++ b/apollo/Dockerfile @@ -3,7 +3,7 @@ FROM node:14-alpine COPY . /opt/indexer RUN cd /opt/indexer/apollo && \ - npm i && \ + yarn install && \ npx prisma generate WORKDIR /opt/indexer/apollo @@ -14,4 +14,4 @@ ENV VERSION_MODE prod # CMD [ "node", "index.js" ] -ENTRYPOINT /opt/indexer/apollo/scripts/entrypoint.sh ${VERSION_MODE} +ENTRYPOINT /opt/indexer/apollo/scripts/entrypoint.sh ${VERSION_MODE} \ No newline at end of file diff --git a/apollo/prisma/migrations/20240325130656_init/migration.sql b/apollo/prisma/migrations/20240325130656_init/migration.sql new file mode 100644 index 00000000..c391cfbb --- /dev/null +++ b/apollo/prisma/migrations/20240325130656_init/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "HistoryRecord" ADD COLUMN "extData" TEXT; diff --git a/apollo/prisma/migrations/20240327060430_init/migration.sql b/apollo/prisma/migrations/20240327060430_init/migration.sql new file mode 100644 index 00000000..357d5431 --- /dev/null +++ b/apollo/prisma/migrations/20240327060430_init/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "HistoryRecord" ADD COLUMN "recvOuterTokenAddress" TEXT, +ADD COLUMN "sendOuterTokenAddress" TEXT; diff --git a/apollo/prisma/schema.prisma b/apollo/prisma/schema.prisma index 75a0fac8..14ee97c2 100644 --- a/apollo/prisma/schema.prisma +++ b/apollo/prisma/schema.prisma @@ -35,12 +35,15 @@ model HistoryRecord { messageNonce String sendTokenAddress String recvTokenAddress String? + sendOuterTokenAddress String? + recvOuterTokenAddress String? guardSignatures String? relayer String? endTxHash String? confirmedBlocks String? needWithdrawLiquidity Boolean? lastRequestWithdraw BigInt? + extData String? } model DailyStatistics { diff --git a/apollo/src/aggregation/aggregation.history.graphql b/apollo/src/aggregation/aggregation.history.graphql index fc768b02..042a8754 100644 --- a/apollo/src/aggregation/aggregation.history.graphql +++ b/apollo/src/aggregation/aggregation.history.graphql @@ -24,12 +24,15 @@ type HistoryRecord { messageNonce: String sendTokenAddress: String recvTokenAddress: String + sendOuterTokenAddress: String + recvOuterTokenAddress: String guardSignatures: String relayer: String endTxHash: String confirmedBlocks: String needWithdrawLiquidity: Boolean lastRequestWithdraw: BigInt + extData: String } type DailyStatistics { diff --git a/apollo/src/aggregation/aggregation.service.ts b/apollo/src/aggregation/aggregation.service.ts index 618acb7f..8477ac26 100644 --- a/apollo/src/aggregation/aggregation.service.ts +++ b/apollo/src/aggregation/aggregation.service.ts @@ -127,8 +127,8 @@ export class AggregationService extends PrismaClient implements OnModuleInit { BigInt(last(record.id.split('-'))).toString(), record.endTime.toString(), record.recvTokenAddress, - record.recipient, record.recvAmount, + record.extData, signature ); if (!guard) { diff --git a/apollo/src/app.module.ts b/apollo/src/app.module.ts index 5bb7d514..33c00a4c 100644 --- a/apollo/src/app.module.ts +++ b/apollo/src/app.module.ts @@ -44,9 +44,9 @@ export class BigIntScalar extends BigInt {} AggregationModule, StatisticModule, //XcmModule, - Sub2ethv2Module, - LnbridgeModule, - S2sv21Module, + //Sub2ethv2Module, + //LnbridgeModule, + //S2sv21Module, Lnbridgev20Module, xTokenModule, Lnv3Module, diff --git a/apollo/src/base/TransferServiceT2.ts b/apollo/src/base/TransferServiceT2.ts index 6b132205..4c23292d 100644 --- a/apollo/src/base/TransferServiceT2.ts +++ b/apollo/src/base/TransferServiceT2.ts @@ -35,6 +35,7 @@ export interface PartnerSymbol { key: string; symbol: string; address: string; + outerAddress: string; protocolFee: number; decimals: number; } diff --git a/apollo/src/graphql.ts b/apollo/src/graphql.ts index b01ee6cc..44d0bf4f 100644 --- a/apollo/src/graphql.ts +++ b/apollo/src/graphql.ts @@ -65,12 +65,15 @@ export class HistoryRecord { messageNonce?: Nullable; sendTokenAddress?: Nullable; recvTokenAddress?: Nullable; + sendOuterTokenAddress?: Nullable; + recvOuterTokenAddress?: Nullable; guardSignatures?: Nullable; relayer?: Nullable; endTxHash?: Nullable; confirmedBlocks?: Nullable; needWithdrawLiquidity?: Nullable; lastRequestWithdraw?: Nullable; + extData?: Nullable; } export class DailyStatistics { diff --git a/apollo/src/guard/guard.service.ts b/apollo/src/guard/guard.service.ts index e564def9..fec78588 100644 --- a/apollo/src/guard/guard.service.ts +++ b/apollo/src/guard/guard.service.ts @@ -19,16 +19,32 @@ export class GuardService { toChain: 'sepolia', bridge: 'xtoken-pangolin-dvm', chainId: 11155111, - depositor: '0x371019523b25Ff4F26d977724f976566b08bf741', - contract: '0x3f200d3b6DA62bcA2F8a93F663b172A7f1AaE9ba', + depositor: '0x1aeC008Af5c604be3525d0bB70fFcc4D7281f30C', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'sepolia', + toChain: 'pangolin-dvm', + bridge: 'xtoken-sepolia', + chainId: 43, + depositor: '0x24f8a04F0cA0730F4b8eC3241F15aCc6b3f8Da0a', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', }, { fromChain: 'darwinia-dvm', toChain: 'ethereum', - bridge: 'helix-sub2ethv2(lock)', + bridge: 'xtoken-darwinia-dvm', chainId: 1, - depositor: null, - contract: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1', + depositor: '0xDc0C760c0fB4672D06088515F6446a71Df0c64C1', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'ethereum', + toChain: 'darwinia-dvm', + bridge: 'xtoken-ethereum', + chainId: 46, + depositor: '0x2B496f19A420C02490dB859fefeCCD71eDc2c046', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', } ]; @@ -39,8 +55,8 @@ export class GuardService { transferId: string, timestamp: string, token: string, - recipient: string, amount: string, + extData: string, sig: string ): string | null { const info = this.guardConfig.find((info) => { @@ -54,8 +70,8 @@ export class GuardService { transferId, timestamp, token, - recipient, amount, + extData, info.chainId, info.contract ); @@ -67,24 +83,17 @@ export class GuardService { transferId: string, timestamp: string, token: string, - recipient: string, amount: string, + extData: string, chainId: number, contractAddress: string ): string { - const claimSign = depositor === null ? - this.web3.eth.abi.encodeFunctionSignature( - 'claim(uint256,uint256,address,address,uint256,bytes[])' - ) : this.web3.eth.abi.encodeFunctionSignature( - 'claim(address,uint256,uint256,address,address,uint256,bytes[])' + const claimSign = this.web3.eth.abi.encodeFunctionSignature( + 'claim(address,uint256,uint256,address,uint256,bytes,bytes[])' ); - const param = depositor === null ? - this.web3.eth.abi.encodeParameters( - ['uint256', 'uint256', 'address', 'address', 'uint256'], - [transferId, timestamp, token, recipient, amount] - ) : this.web3.eth.abi.encodeParameters( - ['address', 'uint256', 'uint256', 'address', 'address', 'uint256'], - [depositor, transferId, timestamp, token, recipient, amount] + const param = this.web3.eth.abi.encodeParameters( + ['address', 'uint256', 'uint256', 'address', 'uint256', 'bytes'], + [depositor, transferId, timestamp, token, amount, extData] ); const message = this.web3.eth.abi.encodeParameters(['bytes4', 'bytes'], [claimSign, param]); const structHash = this.web3.utils.keccak256(message); diff --git a/apollo/src/lnbridgev20/lnbridgev20.service.ts b/apollo/src/lnbridgev20/lnbridgev20.service.ts index 51007495..737b65c2 100644 --- a/apollo/src/lnbridgev20/lnbridgev20.service.ts +++ b/apollo/src/lnbridgev20/lnbridgev20.service.ts @@ -505,6 +505,16 @@ export class Lnbridgev20Service implements OnModuleInit { }; } + transferDecimals(value: string, decimals: number): string { + 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'; + } + } + async fetchMarginInfoFromTarget(transfer: PartnerT3, indexInfo: BridgeIndexInfo) { const index = indexInfo.index; let latestNonce = this.fetchCache[index].latestRelayerInfoTargetNonce; @@ -561,8 +571,7 @@ export class Lnbridgev20Service implements OnModuleInit { const relayerInfo = await this.aggregationService.queryLnBridgeRelayInfoById({ id: id, }); - const sourceMargin = - Number(record.margin) * Math.pow(10, tokenPair.fromDecimals - tokenPair.toDecimals); + const sourceMargin = this.transferDecimals(record.margin, tokenPair.fromDecimals - tokenPair.toDecimals); if (relayerInfo) { // transfer target margin to source margin const updateData = { @@ -620,7 +629,7 @@ export class Lnbridgev20Service implements OnModuleInit { ); } } catch (error) { - this.logger.warn(`fetch lnv2 relay records failed, error ${error}`); + this.logger.warn(`fetchMarginInfoFromTarget failed, error ${error}`); } } @@ -727,7 +736,7 @@ export class Lnbridgev20Service implements OnModuleInit { ); } } catch (error) { - this.logger.warn(`fetch lnv2 relay records failed, error ${error}`); + this.logger.warn(`fetchFeeInfoFromSource failed, error ${error}`); } } @@ -845,7 +854,7 @@ export class Lnbridgev20Service implements OnModuleInit { ); } } catch (error) { - this.logger.warn(`fetch lnv2 relay records failed, error ${error}`); + this.logger.warn(`fetchRelayInfo failed, error ${error}`); } } } diff --git a/apollo/src/lnv3/transfer.service.ts b/apollo/src/lnv3/transfer.service.ts index 926cdb3d..c44bd19b 100644 --- a/apollo/src/lnv3/transfer.service.ts +++ b/apollo/src/lnv3/transfer.service.ts @@ -31,6 +31,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'RING', symbol: 'RING', address: '0x9C1C23E60B72Bc88a043bf64aFdb16A02540Ae8f', + outerAddress: '0x9C1C23E60B72Bc88a043bf64aFdb16A02540Ae8f', protocolFee: 30000000000000000000, decimals: 18, }, @@ -38,6 +39,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F', + outerAddress: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F', protocolFee: 100000, decimals: 6, } @@ -87,6 +89,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'RING', symbol: 'RING', address: '0x9e523234D36973f9e38642886197D023C88e307e', + outerAddress: '0x9e523234D36973f9e38642886197D023C88e307e', protocolFee: 30000000000000000000, decimals: 18, }, @@ -94,6 +97,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', + outerAddress: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', protocolFee: 100000, decimals: 6, }, @@ -101,6 +105,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'ETH', symbol: 'ETH', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 10000000000000, decimals: 18, } @@ -154,6 +159,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x55d398326f99059fF775485246999027B3197955', + outerAddress: '0x55d398326f99059fF775485246999027B3197955', protocolFee: 100000000000000000, decimals: 18, } @@ -199,6 +205,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0xA219439258ca9da29E9Cc4cE5596924745e12B93', + outerAddress: '0xA219439258ca9da29E9Cc4cE5596924745e12B93', protocolFee: 100000, decimals: 6, }, @@ -206,6 +213,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'ETH', symbol: 'ETH', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 10000000000000, decimals: 18, } @@ -251,6 +259,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58', + outerAddress: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58', protocolFee: 100000, decimals: 6, } @@ -296,6 +305,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6', + outerAddress: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6', protocolFee: 100000, decimals: 6, } @@ -341,6 +351,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE', + outerAddress: '0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE', protocolFee: 100000, decimals: 6, } @@ -386,6 +397,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df', + outerAddress: '0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df', protocolFee: 100000, decimals: 6, } @@ -431,6 +443,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'RING', symbol: 'RING', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 30000000000000000000, decimals: 18, } @@ -456,6 +469,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'ETH', symbol: 'ETH', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 10000000000000, decimals: 18, } @@ -481,6 +495,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDC', symbol: 'USDC', address: '0x0ac58Df0cc3542beC4cDa71B16D06C3cCc39f405', + outerAddress: '0x0ac58Df0cc3542beC4cDa71B16D06C3cCc39f405', protocolFee: 10000000000000000, decimals: 18, }, @@ -488,6 +503,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x876A4f6eCF13EEb101F9E75FCeF58f19Ff383eEB', + outerAddress: '0x876A4f6eCF13EEb101F9E75FCeF58f19Ff383eEB', protocolFee: 10000000000000000, decimals: 18, }, @@ -495,6 +511,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'ETH', symbol: 'ETH', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 1000000000000000, decimals: 18, }, @@ -520,6 +537,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDC', symbol: 'USDC', address: '0x8A87497488073307E1a17e8A12475a94Afcb413f', + outerAddress: '0x8A87497488073307E1a17e8A12475a94Afcb413f', protocolFee: 10000000000000000, decimals: 18, }, @@ -527,6 +545,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x3b8Bb7348D4F581e67E2498574F73e4B9Fc51855', + outerAddress: '0x3b8Bb7348D4F581e67E2498574F73e4B9Fc51855', protocolFee: 10000000000000000, decimals: 18, }, @@ -534,6 +553,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'ETH', symbol: 'ETH', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 1000000000000000, decimals: 18, }, @@ -567,6 +587,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDC', symbol: 'USDC', address: '0x253adBFE99Fcd096B9b5502753F96CF78D42eaD0', + outerAddress: '0x253adBFE99Fcd096B9b5502753F96CF78D42eaD0', protocolFee: 10000, decimals: 6, }, @@ -574,6 +595,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x3350f1ef046e21E052dCbA60Fc575919CCaFEdeb', + outerAddress: '0x3350f1ef046e21E052dCbA60Fc575919CCaFEdeb', protocolFee: 10000, decimals: 6, }, @@ -581,6 +603,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'ETH', symbol: 'ETH', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 1000000000000000, decimals: 18, }, @@ -606,6 +629,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDC', symbol: 'USDC', address: '0x3F7DF5866591e7E48D18C8EbeAE61Bc343a63283', + outerAddress: '0x3F7DF5866591e7E48D18C8EbeAE61Bc343a63283', protocolFee: 1000000000000000, decimals: 18, }, @@ -613,6 +637,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae', + outerAddress: '0x89AF830781A2C1d3580Db930bea11094F55AfEae', protocolFee: 1000000000000000, decimals: 18, }, @@ -634,6 +659,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDC', symbol: 'USDC', address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae', + outerAddress: '0x89AF830781A2C1d3580Db930bea11094F55AfEae', protocolFee: 1000000000000000, decimals: 18, }, @@ -641,6 +667,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'USDT', symbol: 'USDT', address: '0x463D1730a8527CA58d48EF70C7460B9920346567', + outerAddress: '0x463D1730a8527CA58d48EF70C7460B9920346567', protocolFee: 1000000000000000, decimals: 18, }, diff --git a/apollo/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 9e7a2c29..34d8ad34 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -5,9 +5,15 @@ import { AddressTokenMap } from '../base/AddressToken'; @Injectable() export class TransferService extends BaseTransferServiceT2 { - private readonly darwainiaUrl = this.configService.get('XTOKEN_DARWINIA'); - private readonly crabUrl = this.configService.get('XTOKEN_CRAB'); - private readonly ethereumUrl = this.configService.get('XTOKEN_ETHEREUM'); + private readonly darwainiaCrabBackingUrl = this.configService.get('XTOKEN_DARWINIA_CRAB_BACKING'); + private readonly darwainiaCrabIssuingUrl = this.configService.get('XTOKEN_DARWINIA_CRAB_ISSUING'); + private readonly crabDarwiniaBackingUrl = this.configService.get('XTOKEN_CRAB_DARWINIA_BACKING'); + private readonly crabDarwiniaIssuingUrl = this.configService.get('XTOKEN_CRAB_DARWINIA_ISSUING'); + private readonly darwainiaEthereumBackingUrl = this.configService.get('XTOKEN_DARWINIA_ETHEREUM_BACKING'); + private readonly darwainiaEthereumIssuingUrl = this.configService.get('XTOKEN_DARWINIA_ETHEREUM_ISSUING'); + + private readonly darwiniaEthereumBackingUrl = this.configService.get('XTOKEN_DARWINIA_ETHEREUM_BACKING'); + private readonly darwiniaEthereumIssuingUrl = this.configService.get('XTOKEN_DARWINIA_ETHEREUM_ISSUING') private readonly darwiniaDispatchSubgraph = this.configService.get('XTOKEN_DISPATCH_DARWINIA'); private readonly crabDispatchSubgraph = this.configService.get('XTOKEN_DISPATCH_CRAB'); private readonly ethereumDispatchSubgraph = this.configService.get('XTOKEN_DISPATCH_ETHEREUM'); @@ -16,20 +22,58 @@ export class TransferService extends BaseTransferServiceT2 { { chainId: 46, chain: 'darwinia-dvm', - url: this.darwainiaUrl, - bridge: 'xtokenbridge', + url: this.darwainiaCrabBackingUrl, + bridge: 'xtoken-darwinia-crab', symbols: [ { key: 'RING', symbol: 'RING', - address: '0x0000000000000000000000000000000000000000', + address: '0xE7578598Aac020abFB918f33A20faD5B71d670b4', + outerAddress: '0x0000000000000000000000000000000000000000', + protocolFee: 0, + decimals: 18, + } + ], + channels: [ + { + chain: 'crab-dvm', + channel: 'msgport' + } + ] + }, + { + chainId: 44, + chain: 'crab-dvm', + url: this.darwainiaCrabIssuingUrl, + bridge: 'xtoken-darwinia-crab', + symbols: [ + { + key: 'RING', + symbol: 'xWRING', + address: '0x273131F7CB50ac002BDd08cA721988731F7e1092', + outerAddress: '0x273131F7CB50ac002BDd08cA721988731F7e1092', protocolFee: 0, decimals: 18, }, + ], + channels: [ + { + chain: 'darwinia-dvm', + channel: 'msgport' + } + ] + }, + { + chainId: 46, + chain: 'darwinia-dvm', + url: this.crabDarwiniaIssuingUrl, + bridge: 'xtoken-crab-darwinia', + symbols: [ { key: 'CRAB', symbol: 'xWCRAB', address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305', + outerAddress: '0x656567Eb75b765FC320783cc6EDd86bD854b2305', protocolFee: 0, decimals: 18, } @@ -44,20 +88,74 @@ export class TransferService extends BaseTransferServiceT2 { { chainId: 44, chain: 'crab-dvm', - url: this.crabUrl, - bridge: 'xtokenbridge', + url: this.crabDarwiniaBackingUrl, + bridge: 'xtoken-crab-darwinia', + symbols: [ + { + key: 'CRAB', + symbol: 'CRAB', + address: '0x2D2b97EA380b0185e9fDF8271d1AFB5d2Bf18329', + outerAddress: '0x0000000000000000000000000000000000000000', + protocolFee: 0, + decimals: 18, + } + ], + channels: [ + { + chain: 'darwinia-dvm', + channel: 'msgport' + } + ] + }, + { + chainId: 46, + chain: 'darwinia-dvm', + url: this.darwainiaEthereumBackingUrl, + bridge: 'xtoken-darwinia-ethereum', symbols: [ { key: 'RING', - symbol: 'xWRING', - address: '0x273131F7CB50ac002BDd08cA721988731F7e1092', + symbol: 'RING', + address: '0xE7578598Aac020abFB918f33A20faD5B71d670b4', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, }, { - key: 'CRAB', - symbol: 'CRAB', - address: '0x0000000000000000000000000000000000000000', + key: 'KTON', + symbol: 'KTON', + address: '0x0000000000000000000000000000000000000402', + outerAddress: '0x0000000000000000000000000000000000000402', + protocolFee: 0, + decimals: 18, + }, + ], + channels: [ + { + chain: 'ethereum', + channel: 'msgport' + } + ] + }, + { + chainId: 1, + chain: 'ethereum', + url: this.darwainiaEthereumIssuingUrl, + bridge: 'xtoken-darwinia-ethereum', + symbols: [ + { + key: 'RING', + symbol: 'RING', + address: '0x81e32d4652Be82AE225DEdd1bD0bf3BCba8FEE07', + outerAddress: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', + protocolFee: 0, + decimals: 18, + }, + { + key: 'KTON', + symbol: 'KTON', + address: '0x9F284E1337A815fe77D2Ff4aE46544645B20c5ff', + outerAddress: '0x9F284E1337A815fe77D2Ff4aE46544645B20c5ff', protocolFee: 0, decimals: 18, } @@ -68,21 +166,21 @@ export class TransferService extends BaseTransferServiceT2 { channel: 'msgport' } ] - - } + }, ]; testChainTransfers: PartnerT2[] = [ { chainId: 43, chain: 'pangolin-dvm', - url: this.darwainiaUrl, + url: this.darwiniaEthereumBackingUrl, bridge: 'xtokenbridge', symbols: [ { key: 'PRING', symbol: 'PRING', - address: '0x0000000000000000000000000000000000000000', + address: '0x617E55f692FA2feFfdD5D9C513782A479cC1FF57', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, }, @@ -97,13 +195,14 @@ export class TransferService extends BaseTransferServiceT2 { { chainId: 11155111, chain: 'sepolia', - url: this.ethereumUrl, + url: this.darwiniaEthereumIssuingUrl, bridge: 'xtokenbridge', symbols: [ { key: 'PRING', symbol: 'xPRING', - address: '0xBC43cb6175FcC8E577a0846256eA699b87eFcEE5', + address: '0x3beb2cf5c2c050bc575350671aa5f06e589386e8', + outerAddress: '0xdE64c6d8b24eeB16D864841d2873aB7a379c45b6', protocolFee: 0, decimals: 18, }, diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index 294a04ea..195277f4 100644 --- a/apollo/src/xtoken/xtoken.service.ts +++ b/apollo/src/xtoken/xtoken.service.ts @@ -90,7 +90,7 @@ export class xTokenService implements OnModuleInit { chain.symbols.find( (item) => item.key === symbolOrAddress || - symbolOrAddress.toLowerCase() === item.address.toLowerCase() + symbolOrAddress?.toLowerCase() === item.address.toLowerCase() ) ?? null ); } @@ -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 } }`; + 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, { @@ -123,6 +139,7 @@ export class xTokenService implements OnModuleInit { }) .then((res) => res.data?.data?.transferRecords); + let added = 0; if (records && records.length > 0) { for (const record of records) { const toChain = this.getDestChain(record.remoteChainId.toString(), transfer.bridge); @@ -130,16 +147,18 @@ export class xTokenService implements OnModuleInit { if (record.direction === 'lock') { sendTokenInfo = this.getToken(transfer, record.token); - recvTokenInfo = this.getToken(toChain, sendTokenInfo.key); + recvTokenInfo = this.getToken(toChain, sendTokenInfo?.key); } else { recvTokenInfo = this.getToken(toChain, record.token); - sendTokenInfo = this.getToken(transfer, recvTokenInfo.key); + sendTokenInfo = this.getToken(transfer, recvTokenInfo?.key); } if (sendTokenInfo == null) { + latestNonce += 1; continue; } if (recvTokenInfo == null) { + latestNonce += 1; continue; } @@ -169,14 +188,18 @@ export class xTokenService implements OnModuleInit { reason: '', sendTokenAddress: sendTokenInfo.address.toLowerCase(), recvTokenAddress: recvTokenInfo.address.toLowerCase(), + sendOuterTokenAddress: sendTokenInfo.outerAddress.toLowerCase(), + recvOuterTokenAddress: recvTokenInfo.outerAddress.toLowerCase(), endTxHash: '', confirmedBlocks: '', + extData: record.extData, }); latestNonce += 1; + added += 1; } this.logger.log( - `save new send record succeeded ${transfer.chain}, nonce: ${latestNonce}, added: ${records.length}` + `save new send record succeeded ${transfer.chain}, nonce: ${latestNonce}, added: ${added}/${records.length}` ); this.fetchCache[index].latestNonce = latestNonce; } @@ -186,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({ @@ -193,6 +222,7 @@ export class xTokenService implements OnModuleInit { take: this.baseConfigure.takeEachTime, where: { fromChain: transfer.chain, + toChain: partner.chain, bridge: `xtoken-${transfer.chain}`, responseTxHash: '', }, @@ -213,6 +243,7 @@ export class xTokenService implements OnModuleInit { variables: null, }) .then((res) => res.data?.data?.messageDispatchedResult); + if (node === undefined || node === null || node.result === null) { continue; } diff --git a/subgraph/xtoken/messageDispatcher/abis/Guard.json b/subgraph/xtoken/messageDispatcher/abis/Guard.json index e3ce93ab..237a56ef 100644 --- a/subgraph/xtoken/messageDispatcher/abis/Guard.json +++ b/subgraph/xtoken/messageDispatcher/abis/Guard.json @@ -6,6 +6,11 @@ "name": "_guards", "type": "address[]" }, + { + "internalType": "address", + "name": "_operator", + "type": "address" + }, { "internalType": "uint256", "name": "_threshold", @@ -112,17 +117,17 @@ "name": "token", "type": "address" }, - { - "indexed": false, - "internalType": "address", - "name": "recipient", - "type": "address" - }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "data", + "type": "bytes" } ], "name": "TokenDeposit", @@ -227,37 +232,37 @@ "inputs": [ { "internalType": "address", - "name": "from", + "name": "_from", "type": "address" }, { "internalType": "uint256", - "name": "id", + "name": "_id", "type": "uint256" }, { "internalType": "uint256", - "name": "timestamp", + "name": "_timestamp", "type": "uint256" }, { "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "address", - "name": "recipient", + "name": "_token", "type": "address" }, { "internalType": "uint256", - "name": "amount", + "name": "_amount", "type": "uint256" }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" + }, { "internalType": "bytes[]", - "name": "signatures", + "name": "_signatures", "type": "bytes[]" } ], @@ -270,38 +275,33 @@ "inputs": [ { "internalType": "address", - "name": "from", + "name": "_from", "type": "address" }, { "internalType": "uint256", - "name": "id", + "name": "_id", "type": "uint256" }, { "internalType": "uint256", - "name": "timestamp", + "name": "_timestamp", "type": "uint256" }, { "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "address", - "name": "recipient", + "name": "_token", "type": "address" }, { "internalType": "uint256", - "name": "amount", + "name": "_amount", "type": "uint256" }, { - "internalType": "bool", - "name": "isNative", - "type": "bool" + "internalType": "bytes", + "name": "_extData", + "type": "bytes" } ], "name": "claimByTimeout", @@ -313,71 +313,38 @@ "inputs": [ { "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "uint256", - "name": "id", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - }, - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "address", - "name": "recipient", + "name": "", "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, + } + ], + "name": "depositors", + "outputs": [ { - "internalType": "bytes[]", - "name": "signatures", - "type": "bytes[]" + "internalType": "bool", + "name": "", + "type": "bool" } ], - "name": "claimNative", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", - "name": "id", + "name": "", "type": "uint256" - }, - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "address", - "name": "recipient", - "type": "address" - }, + } + ], + "name": "deposits", + "outputs": [ { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "bytes32", + "name": "", + "type": "bytes32" } ], - "name": "deposit", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { @@ -412,6 +379,30 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "bytes", + "name": "extData", + "type": "bytes" + } + ], + "name": "encodeExtData", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "pure", + "type": "function" + }, { "inputs": [], "name": "getChainId", @@ -455,7 +446,7 @@ "inputs": [ { "internalType": "bytes", - "name": "value", + "name": "_value", "type": "bytes" } ], @@ -580,12 +571,40 @@ "inputs": [ { "internalType": "address", - "name": "depositor", + "name": "_token", + "type": "address" + }, + { + "internalType": "address", + "name": "_recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes[]", + "name": "_signatures", + "type": "bytes[]" + } + ], + "name": "rescueFunds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_depositor", "type": "address" }, { "internalType": "bool", - "name": "enable", + "name": "_enable", "type": "bool" } ], @@ -600,6 +619,11 @@ "internalType": "uint256", "name": "_maxUnclaimableTime", "type": "uint256" + }, + { + "internalType": "bytes[]", + "name": "_signatures", + "type": "bytes[]" } ], "name": "setMaxUnclaimableTime", @@ -611,12 +635,12 @@ "inputs": [ { "internalType": "address", - "name": "newOperator", + "name": "_operator", "type": "address" }, { "internalType": "bytes[]", - "name": "signatures", + "name": "_signatures", "type": "bytes[]" } ], @@ -625,6 +649,25 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -659,5 +702,37 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_transferId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_xToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" + } + ], + "name": "xTokenCallback", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" } ] diff --git a/subgraph/xtoken/messageDispatcher/generate.sh b/subgraph/xtoken/messageDispatcher/generate.sh index 4894721d..98b10e45 100644 --- a/subgraph/xtoken/messageDispatcher/generate.sh +++ b/subgraph/xtoken/messageDispatcher/generate.sh @@ -65,7 +65,7 @@ echo " - kind: ethereum/contract - name: Guard file: ./abis/Guard.json eventHandlers: - - event: TokenDeposit(address,uint256,uint256,address,address,uint256) + - event: TokenDeposit(address,uint256,uint256,address,uint256,bytes) handler: handleTokenDeposit - event: TokenClaimed(uint256) handler: handleTokenClaimed diff --git a/subgraph/xtoken/messageDispatcher/package.json b/subgraph/xtoken/messageDispatcher/package.json index f1666356..b9827217 100644 --- a/subgraph/xtoken/messageDispatcher/package.json +++ b/subgraph/xtoken/messageDispatcher/package.json @@ -4,10 +4,11 @@ "scripts": { "codegen": "graph codegen", "build": "graph build", - "build-pangolin": "sh generate.sh dispatch pangolin 2298283 0x0000000005d961F950adA391C1511c92bbc64D9F 0xf7F461728DC89de5EF6615715678b5f5b12bb98A && graph codegen && graph build", - "build-sepolia": "sh generate.sh dispatch sepolia 5229494 0x0000000005d961F950adA391C1511c92bbc64D9F 0xf7F461728DC89de5EF6615715678b5f5b12bb98A && sh generate.sh guard sepolia 0x3f200d3b6DA62bcA2F8a93F663b172A7f1AaE9ba 5229494 && graph codegen && graph build", - "build-darwinia": "sh generate.sh dispatch darwinia2 2013793 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", - "build-crab": "sh generate.sh dispatch crab2 2239020 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", + "build-pangolin": "sh generate.sh dispatch pangolin 2551918 0x0000000005d961F950adA391C1511c92bbc64D9F 0xf7F461728DC89de5EF6615715678b5f5b12bb98A && sh generate.sh guard pangolin 0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7 2551918 && graph codegen && graph build", + "build-sepolia": "sh generate.sh dispatch sepolia 5537287 0x0000000005d961F950adA391C1511c92bbc64D9F 0xf7F461728DC89de5EF6615715678b5f5b12bb98A && sh generate.sh guard sepolia 0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7 5537287 && graph codegen && graph build", + "build-darwinia": "sh generate.sh dispatch darwinia2 2358855 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && sh generate.sh guard darwinia2 0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7 2358855 && graph codegen && graph build", + "build-crab": "sh generate.sh dispatch crab2 2515876 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", + "build-ethereum": "sh generate.sh dispatch mainnet 19537485 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && sh generate.sh guard mainnet 0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7 19537485 && 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}", diff --git a/subgraph/xtoken/transfer/abis/xTokenBacking.json b/subgraph/xtoken/transfer/abis/xTokenBacking.json index 37272756..33ddb768 100644 --- a/subgraph/xtoken/transfer/abis/xTokenBacking.json +++ b/subgraph/xtoken/transfer/abis/xTokenBacking.json @@ -1,49 +1,4 @@ [ - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "dailyLimit", - "type": "uint256" - } - ], - "name": "DailyLimitChange", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -120,47 +75,10 @@ "name": "recipient", "type": "address" }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "fee", - "type": "uint256" - } - ], - "name": "TokenLocked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "bytes32", - "name": "transferId", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "remoteChainId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "token", - "type": "address" - }, { "indexed": false, "internalType": "address", - "name": "recipient", + "name": "rollbackAccount", "type": "address" }, { @@ -168,900 +86,21 @@ "internalType": "uint256", "name": "amount", "type": "uint256" - } - ], - "name": "TokenUnlocked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "bytes32", - "name": "transferId", - "type": "bytes32" }, { "indexed": false, "internalType": "uint256", - "name": "remoteChainId", + "name": "fee", "type": "uint256" }, { "indexed": false, - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "TokenUnlockedForFailed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "inputs": [], - "name": "LASTDAY_BIT_LENGTH", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "SPEND_BIT_LENGTH", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_DELIVERED", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_REFUNDED", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TRANSFER_UNFILLED", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "_slotReserved", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "acceptOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - } - ], - "name": "calcMaxWithdraw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "dailyLimit", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "dao", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originalSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "encodeIssuexToken", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originalSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "encodeIssuingForUnlockFailureFromRemote", - "outputs": [ - { "internalType": "bytes", - "name": "", + "name": "extData", "type": "bytes" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "filledTransfers", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_targetChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originalSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - } - ], - "name": "getTransferId", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "name": "guard", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originalSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "handleUnlockForIssuingFailureFromRemote", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_dao", - "type": "address" - }, - { - "internalType": "string", - "name": "_version", - "type": "string" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extParams", - "type": "bytes" - } - ], - "name": "lockAndRemoteIssuing", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "messagers", - "outputs": [ - { - "internalType": "address", - "name": "sendService", - "type": "address" - }, - { - "internalType": "address", - "name": "receiveService", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "operator", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "originalToken2xTokens", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pendingDao", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "protocolFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "protocolFeeReserved", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_xToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_dailyLimit", - "type": "uint256" - } - ], - "name": "registerOriginalToken", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "requestInfos", - "outputs": [ - { - "internalType": "bool", - "name": "isRequested", - "type": "bool" - }, - { - "internalType": "bool", - "name": "hasRefundForFailed", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originalSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extParams", - "type": "bytes" - } - ], - "name": "requestRemoteIssuingForUnlockFailure", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_dailyLimit", - "type": "uint256" - } - ], - "name": "setDailyLimit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_operator", - "type": "address" - } - ], - "name": "setOperator", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_protocolFee", - "type": "uint256" - } - ], - "name": "setProtocolFee", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_remoteBridge", - "type": "address" - }, - { - "internalType": "address", - "name": "_service", - "type": "address" - } - ], - "name": "setReceiveService", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_remoteBridge", - "type": "address" - }, - { - "internalType": "address", - "name": "_service", - "type": "address" - } - ], - "name": "setSendService", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_wtoken", - "type": "address" - } - ], - "name": "setwToken", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "spentToday", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_dao", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_remoteChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "unlockFromRemote", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "unpause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_guard", - "type": "address" - } - ], - "name": "updateGuard", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "version", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "wToken", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_receiver", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - } - ], - "name": "withdrawProtocolFee", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" + "name": "TokenLocked", + "type": "event" } ] diff --git a/subgraph/xtoken/transfer/abis/xTokenIssuing.json b/subgraph/xtoken/transfer/abis/xTokenIssuing.json index d49e7a2b..cecd7314 100644 --- a/subgraph/xtoken/transfer/abis/xTokenIssuing.json +++ b/subgraph/xtoken/transfer/abis/xTokenIssuing.json @@ -49,9 +49,15 @@ "internalType": "uint256", "name": "fee", "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "extData", + "type": "bytes" } ], - "name": "BurnAndRemoteUnlocked", + "name": "BurnAndXUnlocked", "type": "event" }, { @@ -189,7 +195,7 @@ "type": "uint256" } ], - "name": "RemoteUnlockForIssuingFailureRequested", + "name": "RollbackLockAndXIssueRequested", "type": "event" }, { @@ -390,7 +396,7 @@ "type": "address" } ], - "name": "acceptxTokenOwnership", + "name": "acceptXTokenOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -407,6 +413,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -417,14 +428,25 @@ "name": "_nonce", "type": "uint256" }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" + }, { "internalType": "bytes", "name": "_extParams", "type": "bytes" } ], - "name": "burnAndRemoteUnlock", - "outputs": [], + "name": "burnAndXUnlock", + "outputs": [ + { + "internalType": "bytes32", + "name": "transferId", + "type": "bytes32" + } + ], "stateMutability": "payable", "type": "function" }, @@ -496,6 +518,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -507,7 +534,7 @@ "type": "uint256" } ], - "name": "encodeUnlockForIssuingFailureFromRemote", + "name": "encodeRollbackLockAndXIssue", "outputs": [ { "internalType": "bytes", @@ -535,6 +562,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -544,9 +576,14 @@ "internalType": "uint256", "name": "_nonce", "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" } ], - "name": "encodeUnlockFromRemote", + "name": "encodeXUnlock", "outputs": [ { "internalType": "bytes", @@ -583,6 +620,11 @@ "name": "_nonce", "type": "uint256" }, + { + "internalType": "uint256", + "name": "_sourceChainId", + "type": "uint256" + }, { "internalType": "uint256", "name": "_targetChainId", @@ -603,6 +645,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -633,44 +680,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_originalChainId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_originalToken", - "type": "address" - }, - { - "internalType": "address", - "name": "_originalSender", - "type": "address" - }, - { - "internalType": "address", - "name": "_recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "handleIssuingForUnlockFailureFromRemote", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -711,6 +720,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -720,9 +734,14 @@ "internalType": "uint256", "name": "_nonce", "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" } ], - "name": "issuexToken", + "name": "issue", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -885,7 +904,7 @@ "type": "uint256" } ], - "name": "registerxToken", + "name": "registerXToken", "outputs": [ { "internalType": "address", @@ -942,6 +961,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -951,16 +975,11 @@ "internalType": "uint256", "name": "_nonce", "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extParams", - "type": "bytes" } ], - "name": "requestRemoteUnlockForIssuingFailure", + "name": "rollbackBurnAndXUnlock", "outputs": [], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -1098,7 +1117,7 @@ "type": "address" } ], - "name": "transferxTokenOwnership", + "name": "transferXTokenOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1141,7 +1160,7 @@ "type": "address" } ], - "name": "updatexToken", + "name": "updateXToken", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1177,6 +1196,54 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_originalChainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_originalToken", + "type": "address" + }, + { + "internalType": "address", + "name": "_originalSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_recipient", + "type": "address" + }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_nonce", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_extParams", + "type": "bytes" + } + ], + "name": "xRollbackLockAndXIssue", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, { "inputs": [ { diff --git a/subgraph/xtoken/transfer/generate.sh b/subgraph/xtoken/transfer/generate.sh index 0638942f..8086f7b3 100644 --- a/subgraph/xtoken/transfer/generate.sh +++ b/subgraph/xtoken/transfer/generate.sh @@ -24,7 +24,7 @@ echo " - kind: ethereum/contract - name: xTokenBacking file: ./abis/xTokenBacking.json eventHandlers: - - event: TokenLocked(bytes32,uint256,uint256,address,address,address,uint256,uint256) + - event: TokenLocked(bytes32,uint256,uint256,address,address,address,address,uint256,uint256,bytes) handler: handleTokenLocked receipt: true - event: RemoteIssuingFailure(bytes32,address,address,uint256,uint256) @@ -46,17 +46,17 @@ echo " - kind: ethereum/contract apiVersion: 0.0.7 language: wasm/assemblyscript entities: - - BurnAndRemoteUnlocked - - RemoteUnlockForIssuingFailureRequested + - BurnAndXUnlocked + - RollbackLockAndXIssueRequested abis: - name: xTokenIssuing file: ./abis/xTokenIssuing.json eventHandlers: - - event: BurnAndRemoteUnlocked(bytes32,uint256,uint256,address,address,address,uint256,uint256) - handler: handleBurnAndRemoteUnlocked + - event: BurnAndXUnlocked(bytes32,uint256,uint256,address,address,address,uint256,uint256,bytes) + handler: handleBurnAndXUnlocked receipt: true - - event: RemoteUnlockForIssuingFailureRequested(bytes32,address,address,uint256,uint256) - handler: handleRemoteUnlockForIssuingFailureRequested + - event: RollbackLockAndXIssueRequested(bytes32,address,address,uint256,uint256) + handler: handleRollbackLockAndXIssueRequested receipt: true file: ./src/xTokenIssuing.ts" >> subgraph.yaml } diff --git a/subgraph/xtoken/transfer/package.json b/subgraph/xtoken/transfer/package.json index 96745782..0094a8a4 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -4,14 +4,18 @@ "scripts": { "codegen": "graph codegen", "build": "graph build", - "build-pangolin": "sh generate.sh init && sh generate.sh backing pangolin 0x94eAb0CB67AB7edaf9A280aCa097F70e4BD780ac 2298437 && graph codegen && graph build", - "build-sepolia": "sh generate.sh init && sh generate.sh issuing sepolia 0x371019523b25Ff4F26d977724f976566b08bf741 5230232 && graph codegen && graph build", - "build-darwinia": "sh generate.sh init && sh generate.sh backing darwinia2 0xFd626a860F4d4bDB94aF200c218ce62c9647c8b2 2020384 && sh generate.sh issuing darwinia2 0xf16d9682c4883415aee6e78eb0d6ae3507014e42 2020389 && graph codegen && graph build", - "build-crab": "sh generate.sh init && sh generate.sh backing crab2 0xFd626a860F4d4bDB94aF200c218ce62c9647c8b2 2239742 && sh generate.sh issuing crab2 0xf16d9682c4883415aee6e78eb0d6ae3507014e42 2239808 && graph codegen && graph build", + "build-pangolin": "sh generate.sh init && sh generate.sh backing pangolin 0x24f8a04F0cA0730F4b8eC3241F15aCc6b3f8Da0a 2579332 && graph codegen && graph build", + "build-sepolia": "sh generate.sh init && sh generate.sh issuing sepolia 0x1aeC008Af5c604be3525d0bB70fFcc4D7281f30C 5570673 && graph codegen && graph build", + "build-darwinia-crab-backing": "sh generate.sh init && sh generate.sh backing darwinia2 0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0 2358855 && graph codegen && graph build", + "build-crab-darwinia-issuing": "sh generate.sh init && sh generate.sh issuing darwinia2 0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd 2358855 && graph codegen && graph build", + "build-crab-darwinia-backing": "sh generate.sh init && sh generate.sh backing crab2 0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0 2515876 && graph codegen && graph build", + "build-darwinia-crab-issuing": "sh generate.sh init && sh generate.sh issuing crab2 0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd 2515876 && graph codegen && graph build", + "build-darwinia-ethereum-backing": "sh generate.sh init && sh generate.sh backing darwinia2 0x2B496f19A420C02490dB859fefeCCD71eDc2c046 2365403 && graph codegen && graph build", + "build-darwinia-ethereum-issuing": "sh generate.sh init && sh generate.sh issuing mainnet 0xDc0C760c0fB4672D06088515F6446a71Df0c64C1 19537485 && graph codegen && graph build", "create-remote-dev": "graph create --access-token ${KEY} --node https://thegraph-g2.darwinia.network/helix/deploy/ xtokentransfer/${NETWORK}", "deploy-remote-dev": "graph deploy --access-token $KEY --node https://thegraph-g2.darwinia.network/helix/deploy/ --ipfs https://ipfs.network.thegraph.com xtokentransfer/$NETWORK", "create-remote-pro": "graph create --access-token ${KEY} --node https://thegraph.darwinia.network/helix/deploy/ xtokentransfer/${NETWORK}", - "deploy-remote-pro": "graph deploy --access-token $KEY --node https://thegraph.darwinia.network/helix/deploy/ --ipfs https://ipfs.network.thegraph.com xtokentransfer/$NETWORK" + "deploy-remote-pro": "graph deploy --access-token $KEY --node https://thegraph-g1.darwinia.network/helix/deploy/ --ipfs https://ipfs.network.thegraph.com xtokentransfer/$NETWORK" }, "dependencies": { "@graphprotocol/graph-cli": "0.31.1", diff --git a/subgraph/xtoken/transfer/schema.graphql b/subgraph/xtoken/transfer/schema.graphql index aee13107..e5fb9149 100644 --- a/subgraph/xtoken/transfer/schema.graphql +++ b/subgraph/xtoken/transfer/schema.graphql @@ -10,13 +10,14 @@ type TransferRecord @entity { remoteChainId: Int! nonce: BigInt! sender: Bytes! - receiver: Bytes! + receiver: String! token: Bytes! amount: BigInt! timestamp: BigInt! transactionHash: Bytes! fee: BigInt userNonce: String! + extData: String! } type RefundTransferRecord @entity { diff --git a/subgraph/xtoken/transfer/src/xTokenBacking.ts b/subgraph/xtoken/transfer/src/xTokenBacking.ts index b0593b7b..fcb4a5bd 100644 --- a/subgraph/xtoken/transfer/src/xTokenBacking.ts +++ b/subgraph/xtoken/transfer/src/xTokenBacking.ts @@ -1,4 +1,4 @@ -import { BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts" import { TokenLocked, RemoteIssuingFailure, @@ -17,9 +17,22 @@ function isMsglineAcceptEvent(event: ethereum.Log): boolean { isMsglineContract(event); } -function isMsglineDeliveryEvent(event: ethereum.Log): boolean { - return event.topics[0].toHexString() == '0x62b1dc20fd6f1518626da5b6f9897e8cd4ebadbad071bb66dc96a37c970087a8' && - isMsglineContract(event); +function isXRingConvertor(address: string): boolean { + return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa" || address == '0xc29dcb1f12a1618262ef9fba673b77140adc02d6'; +} + +function isGuardAddress(address: string): boolean { + return address == "0x4ca75992d2750bec270731a72dfdede6b9e71cc7"; // testnet +} + +// abi.encode(address, bytes) +function parseExtData(extData: string): string { + const address = '0x' + extData.substring(26, 66); + if (isXRingConvertor(address)) { + return '0x' + extData.substring(194, 234); + } else { + return address; + } } export function handleTokenLocked(event: TokenLocked): void { @@ -40,14 +53,23 @@ export function handleTokenLocked(event: TokenLocked): void { entity.direction = 'lock'; entity.remoteChainId = event.params.remoteChainId.toI32(); entity.nonce = counter.count; - entity.sender = event.params.sender; - entity.receiver = event.params.recipient; + entity.sender = event.transaction.from; + const recipient = event.params.recipient.toHexString(); + entity.receiver = recipient; entity.token = event.params.token; entity.amount = event.params.amount; entity.transactionHash = event.transaction.hash; entity.timestamp = event.block.timestamp; entity.fee = event.params.fee; entity.userNonce = event.params.nonce.toHexString(); + const extData = event.params.extData.toHexString(); + entity.extData = extData; + + if (isGuardAddress(recipient)) { + entity.receiver = parseExtData(extData); + } else if (isXRingConvertor(recipient)) { + entity.receiver = extData; + } var messageId: string; // find the messageId @@ -58,7 +80,6 @@ export function handleTokenLocked(event: TokenLocked): void { for (var idx = 0; idx < logs.length; idx++) { if (isMsglineAcceptEvent(logs[idx])) { messageId = logs[idx].topics[1].toHexString(); - break; } } } diff --git a/subgraph/xtoken/transfer/src/xTokenIssuing.ts b/subgraph/xtoken/transfer/src/xTokenIssuing.ts index 8893b002..14595e8f 100644 --- a/subgraph/xtoken/transfer/src/xTokenIssuing.ts +++ b/subgraph/xtoken/transfer/src/xTokenIssuing.ts @@ -1,7 +1,7 @@ -import { BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts" import { - BurnAndRemoteUnlocked, - RemoteUnlockForIssuingFailureRequested, + BurnAndXUnlocked, + RollbackLockAndXIssueRequested, } from "../generated/xTokenIssuing/xTokenIssuing" import { xTokenNonceOrder, TransferRecord, RefundTransferRecord } from "../generated/schema" @@ -17,12 +17,28 @@ function isMsglineAcceptEvent(event: ethereum.Log): boolean { isMsglineContract(event); } -function isMsglineDeliveryEvent(event: ethereum.Log): boolean { - return event.topics[0].toHexString() == '0x62b1dc20fd6f1518626da5b6f9897e8cd4ebadbad071bb66dc96a37c970087a8' && - isMsglineContract(event); +function isGuardAddress(address: string): boolean { + return address == "0x4ca75992d2750bec270731a72dfdede6b9e71cc7"; // testnet +} + +function isWTokenConvertor(address: string): boolean { + return address == "0xb3a8db63d6fbe0f50a3d4977c3e892543d772c4a" || // testnet + address == "0xa8d0e9a45249ec839c397fa0f371f5f64ecab7f7" || + address == "0x004d0de211bc148c3ce696c51cbc85bd421727e9" || + address == "0x092e19c46c9daab7824393f1cd9c22f5bea13560"; +} + +// abi.encode(address, bytes) +function parseExtData(extData: string): string { + const address = '0x' + extData.substring(26, 66); + if (isWTokenConvertor(address)) { + return '0x' + extData.substring(194, 234); + } else { + return address; + } } -export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void { +export function handleBurnAndXUnlocked(event: BurnAndXUnlocked): void { let message_id = event.params.transferId.toHexString(); let entity = TransferRecord.load(message_id); if (entity == null) { @@ -40,14 +56,23 @@ export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void entity.direction = 'burn'; entity.remoteChainId = event.params.remoteChainId.toI32(); entity.nonce = counter.count; - entity.sender = event.params.sender; - entity.receiver = event.params.recipient; + entity.sender = event.transaction.from; + const recipient = event.params.recipient.toHexString(); + entity.receiver = recipient; entity.token = event.params.originalToken; entity.amount = event.params.amount; entity.transactionHash = event.transaction.hash; entity.timestamp = event.block.timestamp; entity.fee = event.params.fee; entity.userNonce = event.params.nonce.toHexString(); + const extData = event.params.extData.toHexString(); + entity.extData = extData; + + if (isGuardAddress(recipient)) { + entity.receiver = parseExtData(extData); + } else if (isWTokenConvertor(recipient)) { + entity.receiver = extData; + } var messageId: string; // find the messageId @@ -58,7 +83,6 @@ export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void for (var idx = 0; idx < logs.length; idx++) { if (isMsglineAcceptEvent(logs[idx])) { messageId = logs[idx].topics[1].toHexString(); - break; } } } @@ -70,7 +94,7 @@ export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void } // refund txs -export function handleRemoteUnlockForIssuingFailureRequested(event: RemoteUnlockForIssuingFailureRequested): void { +export function handleRollbackLockAndXIssueRequested(event: RollbackLockAndXIssueRequested): void { var messageId = ''; if (event.receipt == null) { return;