From 07406932cb5edec17fb35ba65f48720d2cb657ae Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 11 Apr 2024 10:33:43 +0800 Subject: [PATCH 1/4] support morph testnet --- apollo/.env.test | 1 + apollo/src/lnv3/transfer.service.ts | 36 ++++++++++++++++++++++++++++- subgraph/lnv3/package.json | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/apollo/.env.test b/apollo/.env.test index 9b6c9d32..785907f6 100644 --- a/apollo/.env.test +++ b/apollo/.env.test @@ -25,6 +25,7 @@ ARBITRUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-arbitrum ZKSYNC_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-zksepolia/v1.0.5 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 +MORPH_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/morph 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 diff --git a/apollo/src/lnv3/transfer.service.ts b/apollo/src/lnv3/transfer.service.ts index 9d20767f..2258f3d1 100644 --- a/apollo/src/lnv3/transfer.service.ts +++ b/apollo/src/lnv3/transfer.service.ts @@ -20,6 +20,7 @@ export class TransferService extends BaseTransferServiceT2 { private readonly beraEndpoint = this.configService.get('BERA_LNV3_ENDPOINT'); private readonly taikoEndpoint = this.configService.get('TAIKO_LNV3_ENDPOINT'); private readonly astarZkEVMEndpoint = this.configService.get('ASTAR_ZKEVM_LNV3_ENDPOINT'); + private readonly morphEndpoint = this.configService.get('MORPH_LNV3_ENDPOINT'); formalChainTransfers: PartnerT2[] = [ { @@ -601,6 +602,10 @@ export class TransferService extends BaseTransferServiceT2 { chain: 'bera', channel: 'layerzero', }, + { + chain: 'morph', + channel: 'layerzero', + }, ], }, { @@ -705,7 +710,36 @@ export class TransferService extends BaseTransferServiceT2 { }, ], }, - + { + chainId: 2710, + chain: 'morph', + url: this.morphEndpoint, + bridge: 'lnv3', + symbols: [ + { + key: 'USDC', + symbol: 'USDC', + address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae', + outerAddress: '0x89AF830781A2C1d3580Db930bea11094F55AfEae', + protocolFee: 1000000000000000, + decimals: 18, + }, + { + key: 'USDT', + symbol: 'USDT', + address: '0x463D1730a8527CA58d48EF70C7460B9920346567', + outerAddress: '0x463D1730a8527CA58d48EF70C7460B9920346567', + protocolFee: 1000000000000000, + decimals: 18, + }, + ], + channels: [ + { + chain: 'arbitrum-sepolia', + channel: 'layerzero', + }, + ], + }, ]; readonly addressToTokenInfo: { [key: string]: AddressTokenMap } = {}; diff --git a/subgraph/lnv3/package.json b/subgraph/lnv3/package.json index d258f6c0..401cfd72 100644 --- a/subgraph/lnv3/package.json +++ b/subgraph/lnv3/package.json @@ -9,6 +9,7 @@ "build-zksync-sepolia": "sh generate.sh zksync-era-sepolia 0xDc55fF59F82AA50D8A4A61dB8CcaDffD26Fb7dD2 76772 && graph codegen && graph build", "build-bera-testnet": "sh generate.sh bera 0x00e7EFf0826dfCDf2AA5945dFF710B48f4AA7E64 1006527 && graph codegen && graph build", "build-taiko-testnet": "sh generate.sh taiko 0x00e7EFf0826dfCDf2AA5945dFF710B48f4AA7E64 501744 && graph codegen && graph build", + "build-morph-testnet": "sh generate.sh morph 0xD476650e03a45E70202b0bcAfa04E1513920f83a 1420941 && graph codegen && graph build", "build-polygon-pos": "sh generate.sh matic 0xbA5D580B18b6436411562981e02c8A9aA1776D10 52848029 && graph codegen && graph build", "build-arbitrum-one": "sh generate.sh arbitrum-one 0xbA5D580B18b6436411562981e02c8A9aA1776D10 175050634 && graph codegen && graph build", "build-bsc": "sh generate.sh bsc 0xbA5D580B18b6436411562981e02c8A9aA1776D10 35684060 && graph codegen && graph build", From 9bffc968dc38945db9f0abca4849c372844222cb Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 11 Apr 2024 13:59:23 +0800 Subject: [PATCH 2/4] some archived graphql --- apollo/.env.prod | 8 ++++---- apollo/src/lnbridgev20/lnbridgev20.service.ts | 8 ++++++++ apollo/src/lnv3/lnv3.service.ts | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apollo/.env.prod b/apollo/.env.prod index 82ebd01f..6a093683 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -16,13 +16,13 @@ LN_ETHEREUM_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefau LN_ARBITRUM_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-arbitrum/v2.0.0 LN_MANTLE_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/mantle LN_POLYGON_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-polygon/v2.0.0 -LN_ZKSYNC_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-zksync/version/latest -LN_SCROLL_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-scroll/version/latest +LN_ZKSYNC_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-zksync/v1.0.0 +LN_SCROLL_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-scroll/1.0.0 LN_DARWINIA_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/darwinia LN_DARWINIA_OPPOSITE_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnopposite/darwinia LN_CRAB_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/crab LN_BSC_DEFAULT_ENDPOINT=https://api.thegraph.com/subgraphs/name/helix-bridge/lndefault-bsc -LN_BASE_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-base/version/latest +LN_BASE_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-base/v1.0.0 LN_OP_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-optimism/v2.0.0 LN_LINEA_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/linea @@ -33,7 +33,7 @@ LINEA_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/ln OP_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-op/v1.0.0 GNOSIS_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-gnosis/v1.0.0 MANTLE_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv3/mantle -SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1.0.0 +SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1.0.1 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 ASTAR_ZKEVM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-astar-zkevm/v1.0.0 diff --git a/apollo/src/lnbridgev20/lnbridgev20.service.ts b/apollo/src/lnbridgev20/lnbridgev20.service.ts index 737b65c2..fc4f5680 100644 --- a/apollo/src/lnbridgev20/lnbridgev20.service.ts +++ b/apollo/src/lnbridgev20/lnbridgev20.service.ts @@ -659,6 +659,10 @@ export class Lnbridgev20Service implements OnModuleInit { this.logger.warn(`query fee update failed err ${err}`); }); + if (records === undefined) { + this.logger.warn(`query record failed, url: ${indexInfo.url}, query: ${query}`); + return; + } // query nonce big then latestNonce for (const record of records) { // query by relayer @@ -767,6 +771,10 @@ export class Lnbridgev20Service implements OnModuleInit { this.logger.warn(`query relay update record failed err ${err}`); }); + if (records === undefined) { + this.logger.warn(`query record failed, url: ${indexInfo.url}, query: ${query}`); + return; + } // query nonce big then latestNonce for (const record of records) { // query by relayer diff --git a/apollo/src/lnv3/lnv3.service.ts b/apollo/src/lnv3/lnv3.service.ts index 8616f8c8..430adfc3 100644 --- a/apollo/src/lnv3/lnv3.service.ts +++ b/apollo/src/lnv3/lnv3.service.ts @@ -322,6 +322,12 @@ export class Lnv3Service implements OnModuleInit { this.logger.warn(`query relay update record failed err ${err}`); }); + // maybe this query is archived and can't access + if (records === undefined) { + this.logger.warn(`query record failed, url: ${transfer.url}, query: ${query}`); + return; + } + // query nonce big then latestNonce for (const record of records) { // query by relayer From 5b493b16dc098e48561b4a9fb20cee49f2a8928d Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Fri, 12 Apr 2024 16:17:39 +0800 Subject: [PATCH 3/4] bugfix:softtransferlimit --- .../src/aggregation/aggregation.resolver.ts | 13 ++++- apollo/src/aggregation/aggregation.service.ts | 52 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/apollo/src/aggregation/aggregation.resolver.ts b/apollo/src/aggregation/aggregation.resolver.ts index f22ebeaf..308833d7 100644 --- a/apollo/src/aggregation/aggregation.resolver.ts +++ b/apollo/src/aggregation/aggregation.resolver.ts @@ -178,8 +178,17 @@ export class AggregationResolver { let updateData = { heartbeatTimestamp: Math.floor(Date.now() / 1000), }; + if (softTransferLimit !== undefined && softTransferLimit !== '0') { - updateData['softTransferLimit'] = softTransferLimit; + // the softTransferLimit is on target chain, transfer it to source chain + const transferLimit = this.aggregationService.targetAmountToSourceAmount({ + amount: softTransferLimit, + sourceChainId: Number(fromChainId), + targetChainId: Number(toChainId), + sourceToken: tokenAddress, + version + }); + updateData['softTransferLimit'] = transferLimit; } try { @@ -395,7 +404,7 @@ export class AggregationResolver { continue; } const point = await this.aggregationService.calculateLnBridgeRelayerPoint( - token, + sendToken, BigInt(amount), decimals, record diff --git a/apollo/src/aggregation/aggregation.service.ts b/apollo/src/aggregation/aggregation.service.ts index 8477ac26..28c7248e 100644 --- a/apollo/src/aggregation/aggregation.service.ts +++ b/apollo/src/aggregation/aggregation.service.ts @@ -250,6 +250,58 @@ export class AggregationService extends PrismaClient implements OnModuleInit { return this.tasksService.queryHealthChecks(); } + targetAmountToSourceAmount(params: { + amount: string; + sourceChainId: number; + targetChainId: number; + sourceToken: string; + version: string; + }): string { + const { amount, sourceChainId, targetChainId, sourceToken, version } = params; + let transferDecimals = (value: string, decimals: number) => { + 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'; + } + } + + if (version === 'lnv2') { + const sourceNode = this.lnv2Service.transfers.find((item) => item.chainId === sourceChainId); + const sourceTokenInfo = sourceNode?.tokens.find( + (item) => item.fromAddress.toLowerCase() === sourceToken.toLowerCase() + ); + if (sourceTokenInfo === undefined) { + return '0'; + } + const targetNode = this.lnv2Service.transfers.find((item) => item.chainId === targetChainId); + const targetTokenInfo = targetNode?.tokens.find( + (item) => item.key === sourceTokenInfo.key + ); + if (targetTokenInfo === undefined) { + return '0'; + } + + return transferDecimals(amount, sourceTokenInfo.decimals - targetTokenInfo.decimals); + } else { + const lnv3SourceBridge = this.lnv3Service.transfers.find((item) => item.chainId === sourceChainId); + const sourceSymbol = lnv3SourceBridge?.symbols.find( + (item) => item.address.toLowerCase() === sourceToken.toLowerCase() + ); + if (sourceSymbol === undefined) { + return '0'; + } + const lnv3TargetBridge = this.lnv3Service.transfers.find((item) => item.chainId === targetChainId); + const targetSymbol = lnv3TargetBridge?.symbols.find( + (item) => item.key === sourceSymbol.key + ); + + return transferDecimals(amount, sourceSymbol.decimals - targetSymbol.decimals); + } + } + checkLnBridgeConfigure(params: { sourceChainId: number; targetChainId: number; From 4e5f7b3b82010dbe8f8e3be7c06c7386bcf5c8b2 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Fri, 12 Apr 2024 16:37:14 +0800 Subject: [PATCH 4/4] bugfix:decimals --- apollo/src/aggregation/aggregation.service.ts | 2 +- apollo/src/lnbridgev20/lnbridgev20.service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apollo/src/aggregation/aggregation.service.ts b/apollo/src/aggregation/aggregation.service.ts index 28c7248e..01808706 100644 --- a/apollo/src/aggregation/aggregation.service.ts +++ b/apollo/src/aggregation/aggregation.service.ts @@ -260,7 +260,7 @@ export class AggregationService extends PrismaClient implements OnModuleInit { const { amount, sourceChainId, targetChainId, sourceToken, version } = params; let transferDecimals = (value: string, decimals: number) => { if (decimals > 0) { - return value.padEnd(value.length + decimals); + return value.padEnd(value.length + decimals, '0'); } else if (value.length + decimals > 0) { return value.substr(0, value.length + decimals); } else { diff --git a/apollo/src/lnbridgev20/lnbridgev20.service.ts b/apollo/src/lnbridgev20/lnbridgev20.service.ts index fc4f5680..42b22c12 100644 --- a/apollo/src/lnbridgev20/lnbridgev20.service.ts +++ b/apollo/src/lnbridgev20/lnbridgev20.service.ts @@ -507,7 +507,7 @@ export class Lnbridgev20Service implements OnModuleInit { transferDecimals(value: string, decimals: number): string { if (decimals > 0) { - return value.padEnd(value.length + decimals); + return value.padEnd(value.length + decimals, '0'); } else if (value.length + decimals > 0) { return value.substr(0, value.length + decimals); } else {