From 41d5f4383871633694e54b9add22c46e0c0dc6d6 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 25 Mar 2024 22:06:08 +0800 Subject: [PATCH 01/23] xtoke on testnet --- apollo/.env.test | 4 +- .../20240325130656_init/migration.sql | 2 + apollo/prisma/schema.prisma | 1 + .../aggregation/aggregation.history.graphql | 1 + apollo/src/aggregation/aggregation.service.ts | 2 +- apollo/src/graphql.ts | 1 + apollo/src/guard/guard.service.ts | 35 +-- apollo/src/xtoken/transfer.service.ts | 4 +- apollo/src/xtoken/xtoken.service.ts | 4 +- .../xtoken/messageDispatcher/abis/Guard.json | 247 ++++++++++++------ subgraph/xtoken/messageDispatcher/generate.sh | 2 +- .../xtoken/messageDispatcher/package.json | 4 +- .../xtoken/transfer/abis/xTokenBacking.json | 189 +++++++++----- .../xtoken/transfer/abis/xTokenIssuing.json | 179 +++++++++---- subgraph/xtoken/transfer/generate.sh | 14 +- subgraph/xtoken/transfer/package.json | 4 +- subgraph/xtoken/transfer/schema.graphql | 1 + subgraph/xtoken/transfer/src/xTokenBacking.ts | 69 ++++- subgraph/xtoken/transfer/src/xTokenIssuing.ts | 68 ++++- 19 files changed, 573 insertions(+), 258 deletions(-) create mode 100644 apollo/prisma/migrations/20240325130656_init/migration.sql diff --git a/apollo/.env.test b/apollo/.env.test index bd30b356..415ca2a4 100644 --- a/apollo/.env.test +++ b/apollo/.env.test @@ -27,6 +27,6 @@ BERA_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv 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_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.6 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/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/schema.prisma b/apollo/prisma/schema.prisma index 75a0fac8..907e312b 100644 --- a/apollo/prisma/schema.prisma +++ b/apollo/prisma/schema.prisma @@ -41,6 +41,7 @@ model HistoryRecord { 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 8575be29..077e4329 100644 --- a/apollo/src/aggregation/aggregation.history.graphql +++ b/apollo/src/aggregation/aggregation.history.graphql @@ -30,6 +30,7 @@ type HistoryRecord { 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/graphql.ts b/apollo/src/graphql.ts index c2fbec0a..48c9433f 100644 --- a/apollo/src/graphql.ts +++ b/apollo/src/graphql.ts @@ -69,6 +69,7 @@ export class HistoryRecord { 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..3d768812 100644 --- a/apollo/src/guard/guard.service.ts +++ b/apollo/src/guard/guard.service.ts @@ -19,8 +19,16 @@ export class GuardService { toChain: 'sepolia', bridge: 'xtoken-pangolin-dvm', chainId: 11155111, - depositor: '0x371019523b25Ff4F26d977724f976566b08bf741', - contract: '0x3f200d3b6DA62bcA2F8a93F663b172A7f1AaE9ba', + depositor: '0x3B36c2Db4CC5E92Af015Eb572A1C95C95599a8bF', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'sepolia', + toChain: 'pangolin-dvm', + bridge: 'xtoken-sepolia', + chainId: 43, + depositor: '0x7E3105E3A13D55d824b6322cbD2049f098a097F6', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', }, { fromChain: 'darwinia-dvm', @@ -39,8 +47,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 +62,8 @@ export class GuardService { transferId, timestamp, token, - recipient, amount, + extData, info.chainId, info.contract ); @@ -67,24 +75,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/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 9e7a2c29..5afc286e 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -82,7 +82,7 @@ export class TransferService extends BaseTransferServiceT2 { { key: 'PRING', symbol: 'PRING', - address: '0x0000000000000000000000000000000000000000', + address: '0x617E55f692FA2feFfdD5D9C513782A479cC1FF57', protocolFee: 0, decimals: 18, }, @@ -103,7 +103,7 @@ export class TransferService extends BaseTransferServiceT2 { { key: 'PRING', symbol: 'xPRING', - address: '0xBC43cb6175FcC8E577a0846256eA699b87eFcEE5', + address: '0xF874fad204757588e67EE55cE93D654b6f5C39C6', protocolFee: 0, decimals: 18, }, diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index 294a04ea..3c0bf9e6 100644 --- a/apollo/src/xtoken/xtoken.service.ts +++ b/apollo/src/xtoken/xtoken.service.ts @@ -114,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, userNonce, 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, extData } }`; const records = await axios .post(transfer.url, { @@ -171,6 +171,7 @@ export class xTokenService implements OnModuleInit { recvTokenAddress: recvTokenInfo.address.toLowerCase(), endTxHash: '', confirmedBlocks: '', + extData: record.extData, }); latestNonce += 1; } @@ -213,6 +214,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..b4bf7f43 100644 --- a/subgraph/xtoken/messageDispatcher/package.json +++ b/subgraph/xtoken/messageDispatcher/package.json @@ -4,8 +4,8 @@ "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-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 2013793 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", "build-crab": "sh generate.sh dispatch crab2 2239020 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", "create-remote-dev": "graph create --access-token ${KEY} --node https://thegraph-g2.darwinia.network/helix/deploy/ xtokendispatch/${NETWORK}", diff --git a/subgraph/xtoken/transfer/abis/xTokenBacking.json b/subgraph/xtoken/transfer/abis/xTokenBacking.json index 37272756..be0f0bbe 100644 --- a/subgraph/xtoken/transfer/abis/xTokenBacking.json +++ b/subgraph/xtoken/transfer/abis/xTokenBacking.json @@ -120,6 +120,12 @@ "name": "recipient", "type": "address" }, + { + "indexed": false, + "internalType": "address", + "name": "rollbackAccount", + "type": "address" + }, { "indexed": false, "internalType": "uint256", @@ -131,6 +137,12 @@ "internalType": "uint256", "name": "fee", "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "extData", + "type": "bytes" } ], "name": "TokenLocked", @@ -382,6 +394,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -393,7 +410,7 @@ "type": "uint256" } ], - "name": "encodeIssuexToken", + "name": "encodeRollbackBurnAndXUnlock", "outputs": [ { "internalType": "bytes", @@ -421,6 +438,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -430,9 +452,14 @@ "internalType": "uint256", "name": "_nonce", "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" } ], - "name": "encodeIssuingForUnlockFailureFromRemote", + "name": "encodeXIssue", "outputs": [ { "internalType": "bytes", @@ -469,6 +496,11 @@ "name": "_nonce", "type": "uint256" }, + { + "internalType": "uint256", + "name": "_sourceChainId", + "type": "uint256" + }, { "internalType": "uint256", "name": "_targetChainId", @@ -489,6 +521,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -519,44 +556,6 @@ "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": [ { @@ -592,6 +591,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -602,14 +606,25 @@ "name": "_nonce", "type": "uint256" }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" + }, { "internalType": "bytes", "name": "_extParams", "type": "bytes" } ], - "name": "lockAndRemoteIssuing", - "outputs": [], + "name": "lockAndXIssue", + "outputs": [ + { + "internalType": "bytes32", + "name": "transferId", + "type": "bytes32" + } + ], "stateMutability": "payable", "type": "function" }, @@ -802,6 +817,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -811,16 +831,11 @@ "internalType": "uint256", "name": "_nonce", "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extParams", - "type": "bytes" } ], - "name": "requestRemoteIssuingForUnlockFailure", + "name": "rollbackLockAndXIssue", "outputs": [], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -913,19 +928,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "_wtoken", - "type": "address" - } - ], - "name": "setwToken", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -980,6 +982,11 @@ "name": "_recipient", "type": "address" }, + { + "internalType": "address", + "name": "_rollbackAccount", + "type": "address" + }, { "internalType": "uint256", "name": "_amount", @@ -989,9 +996,14 @@ "internalType": "uint256", "name": "_nonce", "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_extData", + "type": "bytes" } ], - "name": "unlockFromRemote", + "name": "unlock", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1030,34 +1042,69 @@ "type": "function" }, { - "inputs": [], - "name": "wToken", - "outputs": [ + "inputs": [ { "internalType": "address", - "name": "", + "name": "_receiver", "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" } ], - "stateMutability": "view", + "name": "withdrawProtocolFee", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ + { + "internalType": "uint256", + "name": "_remoteChainId", + "type": "uint256" + }, { "internalType": "address", - "name": "_receiver", + "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": "withdrawProtocolFee", + "name": "xRollbackBurnAndXUnlock", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { 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..57ec857f 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -4,8 +4,8 @@ "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-pangolin": "sh generate.sh init && sh generate.sh backing pangolin 0x7E3105E3A13D55d824b6322cbD2049f098a097F6 2567131 && graph codegen && graph build", + "build-sepolia": "sh generate.sh init && sh generate.sh issuing sepolia 0x3B36c2Db4CC5E92Af015Eb572A1C95C95599a8bF 5556101 && 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", "create-remote-dev": "graph create --access-token ${KEY} --node https://thegraph-g2.darwinia.network/helix/deploy/ xtokentransfer/${NETWORK}", diff --git a/subgraph/xtoken/transfer/schema.graphql b/subgraph/xtoken/transfer/schema.graphql index aee13107..5fde9746 100644 --- a/subgraph/xtoken/transfer/schema.graphql +++ b/subgraph/xtoken/transfer/schema.graphql @@ -17,6 +17,7 @@ type TransferRecord @entity { 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..214af2bc 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, @@ -22,6 +22,39 @@ function isMsglineDeliveryEvent(event: ethereum.Log): boolean { isMsglineContract(event); } +function isWTokenConvertor(address: string): boolean { + return address == "0x3aceb55aad4cdfe1531a9c6f6416753e6a7bdd49"; // testnet +} + +function isXRingConvertor(address: string): boolean { + return address == "0x917cb26bfcf9f6be65f387903aa9180613a40f41"; +} + +function isGuardAddress(address: string): boolean { + return address == "0x4ca75992d2750bec270731a72dfdede6b9e71cc7"; // testnet +} + +function isWTokenConvertorEvent(event: ethereum.Log): boolean { + return isWTokenConvertor(event.address.toHexString()) && + event.topics[0].toHexString() == '0xad1c9774020375f95af619204dbe4efc0279cc649e1480865004e3443b0d13a0'; +} + +function parseEventParams(types: string, input: Bytes): ethereum.Value | null { + const tuplePrefix = ByteArray.fromHexString( + '0x0000000000000000000000000000000000000000000000000000000000000020' + ); + const functionInputAsTuple = new Uint8Array( + tuplePrefix.length + input.length + ); + functionInputAsTuple.set(tuplePrefix, 0); + functionInputAsTuple.set(input, tuplePrefix.length); + const tupleInputBytes = Bytes.fromUint8Array(functionInputAsTuple); + return ethereum.decode( + types, + tupleInputBytes + ); +} + export function handleTokenLocked(event: TokenLocked): void { let message_id = event.params.transferId.toHexString(); let entity = TransferRecord.load(message_id); @@ -48,6 +81,7 @@ export function handleTokenLocked(event: TokenLocked): void { entity.timestamp = event.block.timestamp; entity.fee = event.params.fee; entity.userNonce = event.params.nonce.toHexString(); + entity.extData = event.params.extData.toHexString(); var messageId: string; // find the messageId @@ -58,7 +92,38 @@ 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; + } else if (isWTokenConvertorEvent(logs[idx])) { + //event LockAndXIssue(uint256 transferId, address sender, address recipient, uint256 amount, bytes extData); + const decoded = parseEventParams( + '(uint256,address,address,uint256,bytes)', + logs[idx].data + ); + if (decoded === null) { + break; + } + const txParams = decoded.toTuple(); + entity.sender = txParams[1].toAddress(); + + const recepientAddress = txParams[2].toAddress(); + if (isGuardAddress(recepientAddress.toHexString())) { + const decodedExtdata = parseEventParams( + '(address,bytes)', + txParams[4].toBytes() + ); + if (decodedExtdata === null) { + entity.receiver = recepientAddress; + break; + } + const extData = decodedExtdata.toTuple(); + const nextRecipient = extData[0].toAddress(); + if (isXRingConvertor(nextRecipient.toHexString())) { + entity.receiver = extData[1].toBytes(); + } else { + entity.receiver = nextRecipient; + } + } else { + entity.receiver = recepientAddress; + } } } } diff --git a/subgraph/xtoken/transfer/src/xTokenIssuing.ts b/subgraph/xtoken/transfer/src/xTokenIssuing.ts index 8893b002..5c47d6f5 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" @@ -22,7 +22,40 @@ function isMsglineDeliveryEvent(event: ethereum.Log): boolean { isMsglineContract(event); } -export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void { +function isGuardAddress(address: string): boolean { + return address == "0x4ca75992d2750bec270731a72dfdede6b9e71cc7"; // testnet +} + +function isWTokenConvertor(address: string): boolean { + return address == "0x3aceb55aad4cdfe1531a9c6f6416753e6a7bdd49"; // testnet +} + +function isXRingConvertor(address: string): boolean { + return address == "0x917cb26bfcf9f6be65f387903aa9180613a40f41"; +} + +function isXRingConvertorEvent(event: ethereum.Log): boolean { + return isXRingConvertor(event.address.toHexString()) && + event.topics[0].toHexString() == '0xe23676e6691ce6138d353b843afbe1e188c54bf9d04e99942c0a810b433da0ba'; +} + +function parseEventParams(types: string, input: Bytes): ethereum.Value | null { + const tuplePrefix = ByteArray.fromHexString( + '0x0000000000000000000000000000000000000000000000000000000000000020' + ); + const functionInputAsTuple = new Uint8Array( + tuplePrefix.length + input.length + ); + functionInputAsTuple.set(tuplePrefix, 0); + functionInputAsTuple.set(input, tuplePrefix.length); + const tupleInputBytes = Bytes.fromUint8Array(functionInputAsTuple); + return ethereum.decode( + types, + tupleInputBytes + ); +} + +export function handleBurnAndXUnlocked(event: BurnAndXUnlocked): void { let message_id = event.params.transferId.toHexString(); let entity = TransferRecord.load(message_id); if (entity == null) { @@ -40,14 +73,34 @@ 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; + 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(); + entity.extData = event.params.extData.toHexString(); + + if (isGuardAddress(recipient.toHexString())) { + const decodedExtdata = parseEventParams( + '(address,bytes)', + event.params.extData + ) + if (decodedExtdata !== null) { + const extData = decodedExtdata.toTuple(); + const nextRecipient = extData[0].toAddress(); + if (isWTokenConvertor(nextRecipient.toHexString())) { + entity.receiver = extData[1].toBytes(); + } else { + entity.receiver = nextRecipient; + } + } + } else if (isWTokenConvertor(recipient.toHexString())) { + entity.receiver = event.params.extData; + } var messageId: string; // find the messageId @@ -58,7 +111,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 +122,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; From 444d8ab4254bb6999fd2b638b005840fd902024f Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 27 Mar 2024 10:44:36 +0800 Subject: [PATCH 02/23] fix float error --- apollo/src/lnbridgev20/lnbridgev20.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apollo/src/lnbridgev20/lnbridgev20.service.ts b/apollo/src/lnbridgev20/lnbridgev20.service.ts index 51007495..4bdda337 100644 --- a/apollo/src/lnbridgev20/lnbridgev20.service.ts +++ b/apollo/src/lnbridgev20/lnbridgev20.service.ts @@ -691,8 +691,8 @@ export class Lnbridgev20Service implements OnModuleInit { transactionHash: record.transactionHash, timestamp: Number(record.timestamp), margin: '0', - protocolFee: BigInt(tokenPair.protocolFee).toString(), - baseFee: BigInt(record.baseFee).toString(), + protocolFee: BigInt(tokenPair.protocolFee.toFixed()).toString(), + baseFee: BigInt(record.baseFee.toFixed()).toString(), liquidityFeeRate: Number(record.liquidityFeeRate), slashCount: 0, targetNonce: 0, @@ -713,7 +713,7 @@ export class Lnbridgev20Service implements OnModuleInit { baseFee: BigInt(relayerInfo.baseFee).toString(), liquidityFeeRate: relayerInfo.liquidityFeeRate, }; - updateData.baseFee = BigInt(record.baseFee).toString(); + updateData.baseFee = BigInt(record.baseFee.toFixed()).toString(); updateData.liquidityFeeRate = Number(record.liquidityFeeRate); await this.aggregationService.updateLnBridgeRelayInfo({ where: { id: id }, From 8f4df6614cd1d0c652e18e2f4ea6e7d5bb56e552 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 27 Mar 2024 13:16:58 +0800 Subject: [PATCH 03/23] fix float error --- apollo/src/lnbridgev20/lnbridgev20.service.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apollo/src/lnbridgev20/lnbridgev20.service.ts b/apollo/src/lnbridgev20/lnbridgev20.service.ts index 4bdda337..38330c4d 100644 --- a/apollo/src/lnbridgev20/lnbridgev20.service.ts +++ b/apollo/src/lnbridgev20/lnbridgev20.service.ts @@ -562,7 +562,7 @@ export class Lnbridgev20Service implements OnModuleInit { id: id, }); const sourceMargin = - Number(record.margin) * Math.pow(10, tokenPair.fromDecimals - tokenPair.toDecimals); + (Number(record.margin) * Math.pow(10, tokenPair.fromDecimals - tokenPair.toDecimals)).toFixed(); if (relayerInfo) { // transfer target margin to source margin const updateData = { @@ -620,7 +620,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}`); } } @@ -691,8 +691,8 @@ export class Lnbridgev20Service implements OnModuleInit { transactionHash: record.transactionHash, timestamp: Number(record.timestamp), margin: '0', - protocolFee: BigInt(tokenPair.protocolFee.toFixed()).toString(), - baseFee: BigInt(record.baseFee.toFixed()).toString(), + protocolFee: BigInt(tokenPair.protocolFee).toString(), + baseFee: BigInt(record.baseFee).toString(), liquidityFeeRate: Number(record.liquidityFeeRate), slashCount: 0, targetNonce: 0, @@ -713,7 +713,7 @@ export class Lnbridgev20Service implements OnModuleInit { baseFee: BigInt(relayerInfo.baseFee).toString(), liquidityFeeRate: relayerInfo.liquidityFeeRate, }; - updateData.baseFee = BigInt(record.baseFee.toFixed()).toString(); + updateData.baseFee = BigInt(record.baseFee).toString(); updateData.liquidityFeeRate = Number(record.liquidityFeeRate); await this.aggregationService.updateLnBridgeRelayInfo({ where: { id: id }, @@ -727,7 +727,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 +845,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}`); } } } From 6e81229663281c9d10b78d5e3408b833d1eee9b0 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 27 Mar 2024 13:36:24 +0800 Subject: [PATCH 04/23] fix expvalue --- apollo/src/lnbridgev20/lnbridgev20.service.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apollo/src/lnbridgev20/lnbridgev20.service.ts b/apollo/src/lnbridgev20/lnbridgev20.service.ts index 38330c4d..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)).toFixed(); + const sourceMargin = this.transferDecimals(record.margin, tokenPair.fromDecimals - tokenPair.toDecimals); if (relayerInfo) { // transfer target margin to source margin const updateData = { From 5c96fd09eed1e535394b3b2b379dcb862ec2de9e Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 27 Mar 2024 14:06:43 +0800 Subject: [PATCH 05/23] add outer token address --- .../20240327060430_init/migration.sql | 3 +++ apollo/prisma/schema.prisma | 2 ++ .../aggregation/aggregation.history.graphql | 2 ++ apollo/src/base/TransferServiceT2.ts | 1 + apollo/src/graphql.ts | 2 ++ apollo/src/lnv3/transfer.service.ts | 27 +++++++++++++++++++ apollo/src/xtoken/transfer.service.ts | 6 +++++ apollo/src/xtoken/xtoken.service.ts | 2 ++ 8 files changed, 45 insertions(+) create mode 100644 apollo/prisma/migrations/20240327060430_init/migration.sql 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 907e312b..14ee97c2 100644 --- a/apollo/prisma/schema.prisma +++ b/apollo/prisma/schema.prisma @@ -35,6 +35,8 @@ model HistoryRecord { messageNonce String sendTokenAddress String recvTokenAddress String? + sendOuterTokenAddress String? + recvOuterTokenAddress String? guardSignatures String? relayer String? endTxHash String? diff --git a/apollo/src/aggregation/aggregation.history.graphql b/apollo/src/aggregation/aggregation.history.graphql index 077e4329..3a67fe19 100644 --- a/apollo/src/aggregation/aggregation.history.graphql +++ b/apollo/src/aggregation/aggregation.history.graphql @@ -24,6 +24,8 @@ type HistoryRecord { messageNonce: String sendTokenAddress: String recvTokenAddress: String + sendOuterTokenAddress: String + recvOuterTokenAddress: String guardSignatures: String relayer: String endTxHash: String 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 48c9433f..44e5eeba 100644 --- a/apollo/src/graphql.ts +++ b/apollo/src/graphql.ts @@ -63,6 +63,8 @@ export class HistoryRecord { messageNonce?: Nullable; sendTokenAddress?: Nullable; recvTokenAddress?: Nullable; + sendOuterTokenAddress?: Nullable; + recvOuterTokenAddress?: Nullable; guardSignatures?: Nullable; relayer?: Nullable; endTxHash?: Nullable; 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 5afc286e..186ae2c5 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -23,6 +23,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'RING', symbol: 'RING', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, }, @@ -30,6 +31,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'CRAB', symbol: 'xWCRAB', address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305', + outerAddress: '0x656567Eb75b765FC320783cc6EDd86bD854b2305', protocolFee: 0, decimals: 18, } @@ -51,6 +53,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'RING', symbol: 'xWRING', address: '0x273131F7CB50ac002BDd08cA721988731F7e1092', + outerAddress: '0x273131F7CB50ac002BDd08cA721988731F7e1092', protocolFee: 0, decimals: 18, }, @@ -58,6 +61,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'CRAB', symbol: 'CRAB', address: '0x0000000000000000000000000000000000000000', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, } @@ -83,6 +87,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'PRING', symbol: 'PRING', address: '0x617E55f692FA2feFfdD5D9C513782A479cC1FF57', + outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, }, @@ -104,6 +109,7 @@ export class TransferService extends BaseTransferServiceT2 { key: 'PRING', symbol: 'xPRING', address: '0xF874fad204757588e67EE55cE93D654b6f5C39C6', + outerAddress: '0xBD50868F36Eb46355eC5a153AbD3a7eA094A5c37', protocolFee: 0, decimals: 18, }, diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index 3c0bf9e6..4e133cbf 100644 --- a/apollo/src/xtoken/xtoken.service.ts +++ b/apollo/src/xtoken/xtoken.service.ts @@ -169,6 +169,8 @@ 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, From 4fbcd173fe325c8de5e09bcd8fae84a36526a157 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 27 Mar 2024 18:01:01 +0800 Subject: [PATCH 06/23] redeploy xtoken on testnet --- apollo/.env.test | 2 +- apollo/src/xtoken/transfer.service.ts | 4 ++-- subgraph/xtoken/transfer/package.json | 4 ++-- subgraph/xtoken/transfer/src/xTokenBacking.ts | 4 ++-- subgraph/xtoken/transfer/src/xTokenIssuing.ts | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apollo/.env.test b/apollo/.env.test index 415ca2a4..12f014ec 100644 --- a/apollo/.env.test +++ b/apollo/.env.test @@ -27,6 +27,6 @@ BERA_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv 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.6 +XTOKEN_ETHEREUM = 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.4 diff --git a/apollo/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 186ae2c5..692f1cc3 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -108,8 +108,8 @@ export class TransferService extends BaseTransferServiceT2 { { key: 'PRING', symbol: 'xPRING', - address: '0xF874fad204757588e67EE55cE93D654b6f5C39C6', - outerAddress: '0xBD50868F36Eb46355eC5a153AbD3a7eA094A5c37', + address: '0x3beb2cf5c2c050bc575350671aa5f06e589386e8', + outerAddress: '0xdE64c6d8b24eeB16D864841d2873aB7a379c45b6', protocolFee: 0, decimals: 18, }, diff --git a/subgraph/xtoken/transfer/package.json b/subgraph/xtoken/transfer/package.json index 57ec857f..6042686d 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -4,8 +4,8 @@ "scripts": { "codegen": "graph codegen", "build": "graph build", - "build-pangolin": "sh generate.sh init && sh generate.sh backing pangolin 0x7E3105E3A13D55d824b6322cbD2049f098a097F6 2567131 && graph codegen && graph build", - "build-sepolia": "sh generate.sh init && sh generate.sh issuing sepolia 0x3B36c2Db4CC5E92Af015Eb572A1C95C95599a8bF 5556101 && 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": "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", "create-remote-dev": "graph create --access-token ${KEY} --node https://thegraph-g2.darwinia.network/helix/deploy/ xtokentransfer/${NETWORK}", diff --git a/subgraph/xtoken/transfer/src/xTokenBacking.ts b/subgraph/xtoken/transfer/src/xTokenBacking.ts index 214af2bc..1bf893b5 100644 --- a/subgraph/xtoken/transfer/src/xTokenBacking.ts +++ b/subgraph/xtoken/transfer/src/xTokenBacking.ts @@ -23,11 +23,11 @@ function isMsglineDeliveryEvent(event: ethereum.Log): boolean { } function isWTokenConvertor(address: string): boolean { - return address == "0x3aceb55aad4cdfe1531a9c6f6416753e6a7bdd49"; // testnet + return address == "0xb3a8db63d6fbe0f50a3d4977c3e892543d772c4a"; // testnet } function isXRingConvertor(address: string): boolean { - return address == "0x917cb26bfcf9f6be65f387903aa9180613a40f41"; + return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa"; } function isGuardAddress(address: string): boolean { diff --git a/subgraph/xtoken/transfer/src/xTokenIssuing.ts b/subgraph/xtoken/transfer/src/xTokenIssuing.ts index 5c47d6f5..c2914682 100644 --- a/subgraph/xtoken/transfer/src/xTokenIssuing.ts +++ b/subgraph/xtoken/transfer/src/xTokenIssuing.ts @@ -27,11 +27,11 @@ function isGuardAddress(address: string): boolean { } function isWTokenConvertor(address: string): boolean { - return address == "0x3aceb55aad4cdfe1531a9c6f6416753e6a7bdd49"; // testnet + return address == "0xb3a8db63d6fbe0f50a3d4977c3e892543d772c4a"; // testnet } function isXRingConvertor(address: string): boolean { - return address == "0x917cb26bfcf9f6be65f387903aa9180613a40f41"; + return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa"; } function isXRingConvertorEvent(event: ethereum.Log): boolean { From f8f053ad106e105bda93731488c033984a64f7b3 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 27 Mar 2024 18:17:46 +0800 Subject: [PATCH 07/23] update deposit address --- apollo/src/guard/guard.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apollo/src/guard/guard.service.ts b/apollo/src/guard/guard.service.ts index 3d768812..58524c8d 100644 --- a/apollo/src/guard/guard.service.ts +++ b/apollo/src/guard/guard.service.ts @@ -19,7 +19,7 @@ export class GuardService { toChain: 'sepolia', bridge: 'xtoken-pangolin-dvm', chainId: 11155111, - depositor: '0x3B36c2Db4CC5E92Af015Eb572A1C95C95599a8bF', + depositor: '0x1aeC008Af5c604be3525d0bB70fFcc4D7281f30C', contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', }, { @@ -27,7 +27,7 @@ export class GuardService { toChain: 'pangolin-dvm', bridge: 'xtoken-sepolia', chainId: 43, - depositor: '0x7E3105E3A13D55d824b6322cbD2049f098a097F6', + depositor: '0x24f8a04F0cA0730F4b8eC3241F15aCc6b3f8Da0a', contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', }, { From 3f9050c433f998c301f87fb0fdeb12b9ed71cbd4 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 28 Mar 2024 15:49:41 +0800 Subject: [PATCH 08/23] update darwinia<>crab xtoken --- apollo/src/xtoken/transfer.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apollo/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 692f1cc3..6f015dd0 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -22,7 +22,7 @@ export class TransferService extends BaseTransferServiceT2 { { key: 'RING', symbol: 'RING', - address: '0x0000000000000000000000000000000000000000', + address: '0xE7578598Aac020abFB918f33A20faD5B71d670b4', outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, @@ -60,7 +60,7 @@ export class TransferService extends BaseTransferServiceT2 { { key: 'CRAB', symbol: 'CRAB', - address: '0x0000000000000000000000000000000000000000', + address: '0x2D2b97EA380b0185e9fDF8271d1AFB5d2Bf18329', outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, From fc4b0866def66d105d431a6b3bb6df837db3f375 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 28 Mar 2024 15:55:05 +0800 Subject: [PATCH 09/23] update darwinia<>crab address --- subgraph/xtoken/messageDispatcher/package.json | 4 ++-- subgraph/xtoken/transfer/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/subgraph/xtoken/messageDispatcher/package.json b/subgraph/xtoken/messageDispatcher/package.json index b4bf7f43..f90a8fcd 100644 --- a/subgraph/xtoken/messageDispatcher/package.json +++ b/subgraph/xtoken/messageDispatcher/package.json @@ -6,8 +6,8 @@ "build": "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 2013793 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", - "build-crab": "sh generate.sh dispatch crab2 2239020 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", + "build-darwinia": "sh generate.sh dispatch darwinia2 2358855 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && graph codegen && graph build", + "build-crab": "sh generate.sh dispatch crab2 2515876 0x0000000005d961F950adA391C1511c92bbc64D9F 0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0 && 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/package.json b/subgraph/xtoken/transfer/package.json index 6042686d..6806c2ce 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -6,8 +6,8 @@ "build": "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": "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-darwinia": "sh generate.sh init && sh generate.sh backing darwinia2 0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0 2358855 && sh generate.sh issuing darwinia2 0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd 2358855 && graph codegen && graph build", + "build-crab": "sh generate.sh init && sh generate.sh backing crab2 0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0 2515876 && sh generate.sh issuing crab2 0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd 2515876 && 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}", From 8f6e574c81b18aac97bdccb53212b169de408099 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 28 Mar 2024 18:00:39 +0800 Subject: [PATCH 10/23] rmv unused module --- apollo/src/app.module.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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, From cd9e7acb10b03bf630381c31004839ed7155a11e Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 28 Mar 2024 23:04:32 +0800 Subject: [PATCH 11/23] split backing and issuing --- apollo/.env.prod | 5 +- apollo/.env.test | 4 +- apollo/src/xtoken/transfer.service.ts | 67 +- apollo/src/xtoken/xtoken.service.ts | 12 +- .../xtoken/transfer/abis/xTokenBacking.json | 1008 ----------------- subgraph/xtoken/transfer/package.json | 8 +- subgraph/xtoken/transfer/schema.graphql | 2 +- subgraph/xtoken/transfer/src/xTokenBacking.ts | 82 +- subgraph/xtoken/transfer/src/xTokenIssuing.ts | 65 +- 9 files changed, 106 insertions(+), 1147 deletions(-) diff --git a/apollo/.env.prod b/apollo/.env.prod index e1fc354b..fbef6516 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -37,7 +37,10 @@ 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_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 diff --git a/apollo/.env.test b/apollo/.env.test index 12f014ec..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.8 +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.4 diff --git a/apollo/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 6f015dd0..1789b556 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -5,9 +5,13 @@ 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 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,8 +20,8 @@ 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', @@ -26,14 +30,6 @@ export class TransferService extends BaseTransferServiceT2 { outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, - }, - { - key: 'CRAB', - symbol: 'xWCRAB', - address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305', - outerAddress: '0x656567Eb75b765FC320783cc6EDd86bD854b2305', - protocolFee: 0, - decimals: 18, } ], channels: [ @@ -46,8 +42,8 @@ export class TransferService extends BaseTransferServiceT2 { { chainId: 44, chain: 'crab-dvm', - url: this.crabUrl, - bridge: 'xtokenbridge', + url: this.darwainiaCrabIssuingUrl, + bridge: 'xtoken-darwinia-crab', symbols: [ { key: 'RING', @@ -57,6 +53,42 @@ export class TransferService extends BaseTransferServiceT2 { 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, + } + ], + channels: [ + { + chain: 'crab-dvm', + channel: 'msgport' + } + ] + }, + { + chainId: 44, + chain: 'crab-dvm', + url: this.crabDarwiniaBackingUrl, + bridge: 'xtoken-crab-darwinia', + symbols: [ { key: 'CRAB', symbol: 'CRAB', @@ -72,7 +104,6 @@ export class TransferService extends BaseTransferServiceT2 { channel: 'msgport' } ] - } ]; @@ -80,7 +111,7 @@ export class TransferService extends BaseTransferServiceT2 { { chainId: 43, chain: 'pangolin-dvm', - url: this.darwainiaUrl, + url: this.darwiniaEthereumBackingUrl, bridge: 'xtokenbridge', symbols: [ { @@ -102,7 +133,7 @@ export class TransferService extends BaseTransferServiceT2 { { chainId: 11155111, chain: 'sepolia', - url: this.ethereumUrl, + url: this.darwiniaEthereumIssuingUrl, bridge: 'xtokenbridge', symbols: [ { diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index 4e133cbf..8bcfffaa 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 ); } @@ -123,6 +123,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 +131,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; } @@ -176,10 +179,11 @@ export class xTokenService implements OnModuleInit { 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; } diff --git a/subgraph/xtoken/transfer/abis/xTokenBacking.json b/subgraph/xtoken/transfer/abis/xTokenBacking.json index be0f0bbe..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": [ @@ -147,968 +102,5 @@ ], "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", - "type": "address" - }, - { - "indexed": false, - "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", - "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": "address", - "name": "_rollbackAccount", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "encodeRollbackBurnAndXUnlock", - "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": "address", - "name": "_rollbackAccount", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extData", - "type": "bytes" - } - ], - "name": "encodeXIssue", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "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": "_sourceChainId", - "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": "address", - "name": "_rollbackAccount", - "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": "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": "address", - "name": "_rollbackAccount", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extData", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "_extParams", - "type": "bytes" - } - ], - "name": "lockAndXIssue", - "outputs": [ - { - "internalType": "bytes32", - "name": "transferId", - "type": "bytes32" - } - ], - "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": "address", - "name": "_rollbackAccount", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - } - ], - "name": "rollbackLockAndXIssue", - "outputs": [], - "stateMutability": "nonpayable", - "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": "", - "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": "address", - "name": "_rollbackAccount", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extData", - "type": "bytes" - } - ], - "name": "unlock", - "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": [ - { - "internalType": "address", - "name": "_receiver", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - } - ], - "name": "withdrawProtocolFee", - "outputs": [], - "stateMutability": "nonpayable", - "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": "address", - "name": "_rollbackAccount", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_nonce", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_extParams", - "type": "bytes" - } - ], - "name": "xRollbackBurnAndXUnlock", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" } ] diff --git a/subgraph/xtoken/transfer/package.json b/subgraph/xtoken/transfer/package.json index 6806c2ce..a4e5df28 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -6,12 +6,14 @@ "build": "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": "sh generate.sh init && sh generate.sh backing darwinia2 0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0 2358855 && sh generate.sh issuing darwinia2 0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd 2358855 && graph codegen && graph build", - "build-crab": "sh generate.sh init && sh generate.sh backing crab2 0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0 2515876 && sh generate.sh issuing crab2 0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd 2515876 && 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", "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 5fde9746..e5fb9149 100644 --- a/subgraph/xtoken/transfer/schema.graphql +++ b/subgraph/xtoken/transfer/schema.graphql @@ -10,7 +10,7 @@ type TransferRecord @entity { remoteChainId: Int! nonce: BigInt! sender: Bytes! - receiver: Bytes! + receiver: String! token: Bytes! amount: BigInt! timestamp: BigInt! diff --git a/subgraph/xtoken/transfer/src/xTokenBacking.ts b/subgraph/xtoken/transfer/src/xTokenBacking.ts index 1bf893b5..40f48472 100644 --- a/subgraph/xtoken/transfer/src/xTokenBacking.ts +++ b/subgraph/xtoken/transfer/src/xTokenBacking.ts @@ -17,15 +17,6 @@ function isMsglineAcceptEvent(event: ethereum.Log): boolean { isMsglineContract(event); } -function isMsglineDeliveryEvent(event: ethereum.Log): boolean { - return event.topics[0].toHexString() == '0x62b1dc20fd6f1518626da5b6f9897e8cd4ebadbad071bb66dc96a37c970087a8' && - isMsglineContract(event); -} - -function isWTokenConvertor(address: string): boolean { - return address == "0xb3a8db63d6fbe0f50a3d4977c3e892543d772c4a"; // testnet -} - function isXRingConvertor(address: string): boolean { return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa"; } @@ -34,25 +25,14 @@ function isGuardAddress(address: string): boolean { return address == "0x4ca75992d2750bec270731a72dfdede6b9e71cc7"; // testnet } -function isWTokenConvertorEvent(event: ethereum.Log): boolean { - return isWTokenConvertor(event.address.toHexString()) && - event.topics[0].toHexString() == '0xad1c9774020375f95af619204dbe4efc0279cc649e1480865004e3443b0d13a0'; -} - -function parseEventParams(types: string, input: Bytes): ethereum.Value | null { - const tuplePrefix = ByteArray.fromHexString( - '0x0000000000000000000000000000000000000000000000000000000000000020' - ); - const functionInputAsTuple = new Uint8Array( - tuplePrefix.length + input.length - ); - functionInputAsTuple.set(tuplePrefix, 0); - functionInputAsTuple.set(input, tuplePrefix.length); - const tupleInputBytes = Bytes.fromUint8Array(functionInputAsTuple); - return ethereum.decode( - types, - tupleInputBytes - ); +// 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 { @@ -73,15 +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(); - entity.extData = event.params.extData.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 @@ -92,38 +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(); - } else if (isWTokenConvertorEvent(logs[idx])) { - //event LockAndXIssue(uint256 transferId, address sender, address recipient, uint256 amount, bytes extData); - const decoded = parseEventParams( - '(uint256,address,address,uint256,bytes)', - logs[idx].data - ); - if (decoded === null) { - break; - } - const txParams = decoded.toTuple(); - entity.sender = txParams[1].toAddress(); - - const recepientAddress = txParams[2].toAddress(); - if (isGuardAddress(recepientAddress.toHexString())) { - const decodedExtdata = parseEventParams( - '(address,bytes)', - txParams[4].toBytes() - ); - if (decodedExtdata === null) { - entity.receiver = recepientAddress; - break; - } - const extData = decodedExtdata.toTuple(); - const nextRecipient = extData[0].toAddress(); - if (isXRingConvertor(nextRecipient.toHexString())) { - entity.receiver = extData[1].toBytes(); - } else { - entity.receiver = nextRecipient; - } - } else { - entity.receiver = recepientAddress; - } } } } diff --git a/subgraph/xtoken/transfer/src/xTokenIssuing.ts b/subgraph/xtoken/transfer/src/xTokenIssuing.ts index c2914682..994f5d7c 100644 --- a/subgraph/xtoken/transfer/src/xTokenIssuing.ts +++ b/subgraph/xtoken/transfer/src/xTokenIssuing.ts @@ -17,42 +17,24 @@ 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 -} - -function isXRingConvertor(address: string): boolean { - return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa"; + return address == "0xb3a8db63d6fbe0f50a3d4977c3e892543d772c4a" || // testnet + address == "0xa8d0e9a45249ec839c397fa0f371f5f64ecab7f7" || + address == "0x004d0de211bc148c3ce696c51cbc85bd421727e9"; } -function isXRingConvertorEvent(event: ethereum.Log): boolean { - return isXRingConvertor(event.address.toHexString()) && - event.topics[0].toHexString() == '0xe23676e6691ce6138d353b843afbe1e188c54bf9d04e99942c0a810b433da0ba'; -} - -function parseEventParams(types: string, input: Bytes): ethereum.Value | null { - const tuplePrefix = ByteArray.fromHexString( - '0x0000000000000000000000000000000000000000000000000000000000000020' - ); - const functionInputAsTuple = new Uint8Array( - tuplePrefix.length + input.length - ); - functionInputAsTuple.set(tuplePrefix, 0); - functionInputAsTuple.set(input, tuplePrefix.length); - const tupleInputBytes = Bytes.fromUint8Array(functionInputAsTuple); - return ethereum.decode( - types, - tupleInputBytes - ); +// 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 handleBurnAndXUnlocked(event: BurnAndXUnlocked): void { @@ -74,7 +56,7 @@ export function handleBurnAndXUnlocked(event: BurnAndXUnlocked): void { entity.remoteChainId = event.params.remoteChainId.toI32(); entity.nonce = counter.count; entity.sender = event.transaction.from; - const recipient = event.params.recipient; + const recipient = event.params.recipient.toHexString(); entity.receiver = recipient; entity.token = event.params.originalToken; entity.amount = event.params.amount; @@ -82,24 +64,13 @@ export function handleBurnAndXUnlocked(event: BurnAndXUnlocked): void { entity.timestamp = event.block.timestamp; entity.fee = event.params.fee; entity.userNonce = event.params.nonce.toHexString(); - entity.extData = event.params.extData.toHexString(); + const extData = event.params.extData.toHexString(); + entity.extData = extData; - if (isGuardAddress(recipient.toHexString())) { - const decodedExtdata = parseEventParams( - '(address,bytes)', - event.params.extData - ) - if (decodedExtdata !== null) { - const extData = decodedExtdata.toTuple(); - const nextRecipient = extData[0].toAddress(); - if (isWTokenConvertor(nextRecipient.toHexString())) { - entity.receiver = extData[1].toBytes(); - } else { - entity.receiver = nextRecipient; - } - } - } else if (isWTokenConvertor(recipient.toHexString())) { - entity.receiver = event.params.extData; + if (isGuardAddress(recipient)) { + entity.receiver = parseExtData(extData); + } else if (isWTokenConvertor(recipient)) { + entity.receiver = extData; } var messageId: string; From 505b2d82e1329f7abad365120c6911af3fa4eb8e Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 11:37:23 +0800 Subject: [PATCH 12/23] deploy on darwinia<>ethereum mainnet --- apollo/.env.prod | 3 ++ apollo/src/xtoken/transfer.service.ts | 48 ++++++++++++++++++- .../xtoken/messageDispatcher/package.json | 3 +- subgraph/xtoken/transfer/package.json | 2 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/apollo/.env.prod b/apollo/.env.prod index fbef6516..3b94bd7e 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -41,8 +41,11 @@ 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_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 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/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 1789b556..88adc90e 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -9,6 +9,8 @@ export class TransferService extends BaseTransferServiceT2 { 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') @@ -104,7 +106,51 @@ export class TransferService extends BaseTransferServiceT2 { channel: 'msgport' } ] - } + }, + { + chainId: 46, + chain: 'darwinia-dvm', + url: this.darwainiaEthereumBackingUrl, + bridge: 'xtoken-darwinia-ethereum', + symbols: [ + { + key: 'RING', + symbol: 'RING', + address: '0xE7578598Aac020abFB918f33A20faD5B71d670b4', + outerAddress: '0x0000000000000000000000000000000000000000', + 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: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', + outerAddress: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', + protocolFee: 0, + decimals: 18, + } + ], + channels: [ + { + chain: 'darwinia-dvm', + channel: 'msgport' + } + ] + }, ]; testChainTransfers: PartnerT2[] = [ diff --git a/subgraph/xtoken/messageDispatcher/package.json b/subgraph/xtoken/messageDispatcher/package.json index f90a8fcd..b9827217 100644 --- a/subgraph/xtoken/messageDispatcher/package.json +++ b/subgraph/xtoken/messageDispatcher/package.json @@ -6,8 +6,9 @@ "build": "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 && 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/package.json b/subgraph/xtoken/transfer/package.json index a4e5df28..21420a8a 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -10,6 +10,8 @@ "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 backing 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}", From 06cd6e6bd9ace61215e9320613bf407b2e9fb191 Mon Sep 17 00:00:00 2001 From: fewensa <37804932+fewensa@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:08:03 +0800 Subject: [PATCH 13/23] Use yarn --- apollo/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo/Dockerfile b/apollo/Dockerfile index a3ab621b..080db5c4 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 From 2b73d77bccdbbb8ca0b4b9aad949f78826ffde2a Mon Sep 17 00:00:00 2001 From: fewensa <37804932+fewensa@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:16:56 +0800 Subject: [PATCH 14/23] Minimise image size --- .github/workflows/publish.yml | 5 +++-- apollo/Dockerfile | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bfcfb7d7..8820f4b8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,10 +31,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 }} diff --git a/apollo/Dockerfile b/apollo/Dockerfile index a3ab621b..59480a28 100644 --- a/apollo/Dockerfile +++ b/apollo/Dockerfile @@ -1,12 +1,12 @@ FROM node:14-alpine -COPY . /opt/indexer +COPY . /opt/app -RUN cd /opt/indexer/apollo && \ - npm i && \ +RUN cd /opt/app && \ + yarn install && \ npx prisma generate -WORKDIR /opt/indexer/apollo +WORKDIR /opt/app EXPOSE 4002 @@ -14,4 +14,4 @@ ENV VERSION_MODE prod # CMD [ "node", "index.js" ] -ENTRYPOINT /opt/indexer/apollo/scripts/entrypoint.sh ${VERSION_MODE} +ENTRYPOINT /opt/app/scripts/entrypoint.sh ${VERSION_MODE} From a6cf69d5e9f5dcdd63957d1d53701f60cda4dff3 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 13:34:01 +0800 Subject: [PATCH 15/23] add guard contract address --- apollo/src/guard/guard.service.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apollo/src/guard/guard.service.ts b/apollo/src/guard/guard.service.ts index 58524c8d..fec78588 100644 --- a/apollo/src/guard/guard.service.ts +++ b/apollo/src/guard/guard.service.ts @@ -33,10 +33,18 @@ export class GuardService { { 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', } ]; From 265f475b91e6d26d00bf75a589e6fcea0ba35307 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 14:57:34 +0800 Subject: [PATCH 16/23] repair dar->eth records --- apollo/.env.prod | 2 +- apollo/src/xtoken/xtoken.service.ts | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) 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: '', }, From fd1d886a9c7d4f8c046fe04ffdb71ce2e1f6dbaa Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 15:06:11 +0800 Subject: [PATCH 17/23] update etherum issuing --- apollo/.env.prod | 2 +- subgraph/xtoken/transfer/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apollo/.env.prod b/apollo/.env.prod index 301bb80a..e1cbbfba 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -42,7 +42,7 @@ XTOKEN_DARWINIA_CRAB_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/n 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.0 +XTOKEN_DARWINIA_ETHEREUM_ISSUING=https://api.studio.thegraph.com/query/59403/xtoken-dar-ethereum-issuing/v1.0.1 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 diff --git a/subgraph/xtoken/transfer/package.json b/subgraph/xtoken/transfer/package.json index 21420a8a..0094a8a4 100644 --- a/subgraph/xtoken/transfer/package.json +++ b/subgraph/xtoken/transfer/package.json @@ -11,7 +11,7 @@ "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 backing mainnet 0xDc0C760c0fB4672D06088515F6446a71Df0c64C1 19537485 && 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}", From e02c649c2700beba33570481bca91f2774f4be32 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 15:23:51 +0800 Subject: [PATCH 18/23] update xRING addrss --- apollo/src/xtoken/transfer.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index 88adc90e..d84db990 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -138,7 +138,7 @@ export class TransferService extends BaseTransferServiceT2 { { key: 'RING', symbol: 'RING', - address: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', + address: '0x81e32d4652Be82AE225DEdd1bD0bf3BCba8FEE07', outerAddress: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', protocolFee: 0, decimals: 18, From 93d3a9c1ef8f02b3da4f7e415da2120bc5d29b80 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 17:05:28 +0800 Subject: [PATCH 19/23] update ethereum issuing --- apollo/.env.prod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo/.env.prod b/apollo/.env.prod index e1cbbfba..84849e86 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -42,7 +42,7 @@ XTOKEN_DARWINIA_CRAB_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/n 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.1 +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 From 90b05b9765a7fa28a42bc7821903477840dbf4ef Mon Sep 17 00:00:00 2001 From: fewensa <37804932+fewensa@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:56:17 +0800 Subject: [PATCH 20/23] Use ghcr --- .github/workflows/publish.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8820f4b8..cbdcb3bf 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 @@ -37,5 +40,5 @@ jobs: 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 }} From e1909a2f47d70fb15245439c9ba2a4c6c54c7d68 Mon Sep 17 00:00:00 2001 From: fewensa <37804932+fewensa@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:03:31 +0800 Subject: [PATCH 21/23] Revert folder --- .github/workflows/publish.yml | 2 +- apollo/Dockerfile | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cbdcb3bf..ed7d3963 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -37,7 +37,7 @@ jobs: uses: docker/build-push-action@v3 with: push: true - context: apollo + #context: apollo file: apollo/Dockerfile tags: | ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}:sha-${{ steps.short-sha.outputs.sha }} diff --git a/apollo/Dockerfile b/apollo/Dockerfile index 59480a28..987426d1 100644 --- a/apollo/Dockerfile +++ b/apollo/Dockerfile @@ -1,12 +1,12 @@ FROM node:14-alpine -COPY . /opt/app +COPY . /opt/indexer -RUN cd /opt/app && \ +RUN cd /opt/indexer/apollo && \ yarn install && \ npx prisma generate -WORKDIR /opt/app +WORKDIR /opt/indexer/apollo EXPOSE 4002 @@ -14,4 +14,4 @@ ENV VERSION_MODE prod # CMD [ "node", "index.js" ] -ENTRYPOINT /opt/app/scripts/entrypoint.sh ${VERSION_MODE} +ENTRYPOINT /opt/indexer/apollo/scripts/entrypoint.sh ${VERSION_MODE} \ No newline at end of file From 8d1c27bdf74d3e7f36d2be88c614ac6f9b942874 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 19:34:52 +0800 Subject: [PATCH 22/23] xtoken receiver --- subgraph/xtoken/transfer/src/xTokenBacking.ts | 2 +- subgraph/xtoken/transfer/src/xTokenIssuing.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/subgraph/xtoken/transfer/src/xTokenBacking.ts b/subgraph/xtoken/transfer/src/xTokenBacking.ts index 40f48472..fcb4a5bd 100644 --- a/subgraph/xtoken/transfer/src/xTokenBacking.ts +++ b/subgraph/xtoken/transfer/src/xTokenBacking.ts @@ -18,7 +18,7 @@ function isMsglineAcceptEvent(event: ethereum.Log): boolean { } function isXRingConvertor(address: string): boolean { - return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa"; + return address == "0x4cdfe9915d2c72506f4fc2363a8eae032e82d1aa" || address == '0xc29dcb1f12a1618262ef9fba673b77140adc02d6'; } function isGuardAddress(address: string): boolean { diff --git a/subgraph/xtoken/transfer/src/xTokenIssuing.ts b/subgraph/xtoken/transfer/src/xTokenIssuing.ts index 994f5d7c..14595e8f 100644 --- a/subgraph/xtoken/transfer/src/xTokenIssuing.ts +++ b/subgraph/xtoken/transfer/src/xTokenIssuing.ts @@ -24,7 +24,8 @@ function isGuardAddress(address: string): boolean { function isWTokenConvertor(address: string): boolean { return address == "0xb3a8db63d6fbe0f50a3d4977c3e892543d772c4a" || // testnet address == "0xa8d0e9a45249ec839c397fa0f371f5f64ecab7f7" || - address == "0x004d0de211bc148c3ce696c51cbc85bd421727e9"; + address == "0x004d0de211bc148c3ce696c51cbc85bd421727e9" || + address == "0x092e19c46c9daab7824393f1cd9c22f5bea13560"; } // abi.encode(address, bytes) From f5d314ac5da7aa54466fd9187a4ea7db7b52d95d Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 1 Apr 2024 20:15:41 +0800 Subject: [PATCH 23/23] add KTON --- apollo/src/xtoken/transfer.service.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apollo/src/xtoken/transfer.service.ts b/apollo/src/xtoken/transfer.service.ts index d84db990..34d8ad34 100644 --- a/apollo/src/xtoken/transfer.service.ts +++ b/apollo/src/xtoken/transfer.service.ts @@ -120,7 +120,15 @@ export class TransferService extends BaseTransferServiceT2 { outerAddress: '0x0000000000000000000000000000000000000000', protocolFee: 0, decimals: 18, - } + }, + { + key: 'KTON', + symbol: 'KTON', + address: '0x0000000000000000000000000000000000000402', + outerAddress: '0x0000000000000000000000000000000000000402', + protocolFee: 0, + decimals: 18, + }, ], channels: [ { @@ -142,6 +150,14 @@ export class TransferService extends BaseTransferServiceT2 { outerAddress: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', protocolFee: 0, decimals: 18, + }, + { + key: 'KTON', + symbol: 'KTON', + address: '0x9F284E1337A815fe77D2Ff4aE46544645B20c5ff', + outerAddress: '0x9F284E1337A815fe77D2Ff4aE46544645B20c5ff', + protocolFee: 0, + decimals: 18, } ], channels: [