From 1a2801c943559478fcf0593f26bccff9d9cd243b Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 31 Jan 2024 10:15:25 +0800 Subject: [PATCH] add polygon bsc arbitrum and linea --- apollo/.env.prod | 5 + .../aggregation/aggregation.history.graphql | 2 +- apollo/src/aggregation/aggregation.module.ts | 5 +- .../src/aggregation/aggregation.resolver.ts | 4 +- apollo/src/aggregation/aggregation.service.ts | 58 +++++--- apollo/src/graphql.ts | 2 +- apollo/src/lnv3/transfer.service.ts | 136 +++++++++++++++++- 7 files changed, 189 insertions(+), 23 deletions(-) diff --git a/apollo/.env.prod b/apollo/.env.prod index 7f66bdf1..d82473f5 100644 --- a/apollo/.env.prod +++ b/apollo/.env.prod @@ -25,4 +25,9 @@ LN_BASE_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-b 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 +POLYGON_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-polygon/v1.0.0 +ARBITRUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-arbitrum/v1.0.0 +BSC_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-bsc/v1.0.0 +LINEA_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv3/linea + CHAIN_TYPE=formal diff --git a/apollo/src/aggregation/aggregation.history.graphql b/apollo/src/aggregation/aggregation.history.graphql index 38b13b70..842d5422 100644 --- a/apollo/src/aggregation/aggregation.history.graphql +++ b/apollo/src/aggregation/aggregation.history.graphql @@ -95,7 +95,7 @@ type Query { firstHistoryRecord(fromChain: String, toChain: String, bridge: String, results: [Int], relayer: String, token: String, order: String): HistoryRecord queryDailyStatistics(timepast: Int!, first: Int, from: String, to: String, bridge: String, token: String): [DailyStatistics] historyRecords(sender: String, recipient: String, relayer: String, needWithdrawLiquidity: Boolean, fromChains: [String], toChains: [String], bridges: [String], row: Int, page: Int, results: [Int], recvTokenAddress: String, order: String): HistoryRecords - checkLnBridgeExist(fromChainId: Int, toChainId: Int, fromToken: String, toToken: String): Boolean + checkLnBridgeExist(fromChainId: Int, toChainId: Int, fromToken: String, toToken: String, version: String): Boolean tasksHealthCheck(name: String): [HealthInfo] queryGuardNeedSignature(fromChain: String, toChain: String, bridge: String, guardAddress: String, row: Int): HistoryRecords queryRelayRecords(fromChain: String, toChain: String, bridge: String, relayer: String, row: Int): HistoryRecords diff --git a/apollo/src/aggregation/aggregation.module.ts b/apollo/src/aggregation/aggregation.module.ts index 57fb5fcd..1224d017 100644 --- a/apollo/src/aggregation/aggregation.module.ts +++ b/apollo/src/aggregation/aggregation.module.ts @@ -3,11 +3,12 @@ import { AggregationService } from './aggregation.service'; import { AggregationResolver } from './aggregation.resolver'; import { TasksModule } from '../tasks/tasks.module'; import { GuardService } from '../guard/guard.service'; -import { TransferService } from '../lnbridgev20/transfer.service'; +import { TransferService as Lnv2Service } from '../lnbridgev20/transfer.service'; +import { TransferService as Lnv3Service} from '../lnv3/transfer.service'; @Module({ imports: [TasksModule], - providers: [AggregationService, AggregationResolver, GuardService, TransferService], + providers: [AggregationService, AggregationResolver, GuardService, Lnv2Service, Lnv3Service], exports: [AggregationService], }) export class AggregationModule {} diff --git a/apollo/src/aggregation/aggregation.resolver.ts b/apollo/src/aggregation/aggregation.resolver.ts index 092ee14f..2cf340e8 100644 --- a/apollo/src/aggregation/aggregation.resolver.ts +++ b/apollo/src/aggregation/aggregation.resolver.ts @@ -192,13 +192,15 @@ export class AggregationResolver { @Args('fromChainId') fromChainId: number, @Args('toChainId') toChainId: number, @Args('fromToken') fromToken: string, - @Args('toToken') toToken: string + @Args('toToken') toToken: string, + @Args('version') version: string ) { return this.aggregationService.checkLnBridgeConfigure({ sourceChainId: fromChainId, targetChainId: toChainId, sourceToken: fromToken, targetToken: toToken, + version: version, }); } diff --git a/apollo/src/aggregation/aggregation.service.ts b/apollo/src/aggregation/aggregation.service.ts index 1b9b654a..5aee5c86 100644 --- a/apollo/src/aggregation/aggregation.service.ts +++ b/apollo/src/aggregation/aggregation.service.ts @@ -3,7 +3,8 @@ import { DailyStatistics, HistoryRecord, Prisma, PrismaClient } from '@prisma/cl import { HistoryRecords, LnBridgeRelayInfo, LnBridgeRelayInfos } from '../graphql'; import { GuardService } from '../guard/guard.service'; // export lnbridge service configure -import { TransferService } from '../lnbridgev20/transfer.service'; +import { TransferService as Lnv2Service } from '../lnbridgev20/transfer.service'; +import { TransferService as Lnv3Service} from '../lnv3/transfer.service'; import { TasksService } from '../tasks/tasks.service'; @Injectable() @@ -16,7 +17,8 @@ export class AggregationService extends PrismaClient implements OnModuleInit { constructor( private guardService: GuardService, - private lnService: TransferService, + private lnv2Service: Lnv2Service, + private lnv3Service: Lnv3Service, private tasksService: TasksService ) { super(); @@ -252,23 +254,45 @@ export class AggregationService extends PrismaClient implements OnModuleInit { targetChainId: number; sourceToken: string; targetToken: string; + version: string; }): boolean { - const { sourceChainId, targetChainId, sourceToken, targetToken } = params; - const bridge = this.lnService.transfers.find((item) => item.chainId === sourceChainId); - if (bridge === undefined) { - return false; - } - const tokenBridge = bridge.tokens.find( - (item) => item.fromAddress.toLowerCase() === sourceToken.toLowerCase() - ); - if (tokenBridge === undefined) { - return false; + const { sourceChainId, targetChainId, sourceToken, targetToken, version } = params; + if (version === 'lnv2') { + const bridge = this.lnv2Service.transfers.find((item) => item.chainId === sourceChainId); + if (bridge === undefined) { + return false; + } + const tokenBridge = bridge.tokens.find( + (item) => item.fromAddress.toLowerCase() === sourceToken.toLowerCase() + ); + if (tokenBridge === undefined) { + return false; + } + const targetInfo = tokenBridge.remoteInfos.find( + (item) => + item.toChain === targetChainId && item.toAddress.toLowerCase() === targetToken.toLowerCase() + ); + return targetInfo !== undefined; + } else { + const lnv3SourceBridge = this.lnv3Service.transfers.find((item) => item.chainId === sourceChainId); + if (lnv3SourceBridge === undefined) { + return false; + } + const sourceSymbol = lnv3SourceBridge.symbols.find( + (item) => item.address.toLowerCase() === sourceToken.toLowerCase() + ); + if (sourceSymbol === undefined) { + return false; + } + const lnv3TargetBridge = this.lnv3Service.transfers.find((item) => item.chainId === targetChainId); + if (lnv3TargetBridge === undefined) { + return false; + } + const targetSymbol = lnv3TargetBridge.symbols.find( + (item) => item.address.toLowerCase() === targetToken.toLowerCase() + ); + return targetSymbol === undefined; } - const targetInfo = tokenBridge.remoteInfos.find( - (item) => - item.toChain === targetChainId && item.toAddress.toLowerCase() === targetToken.toLowerCase() - ); - return targetInfo !== undefined; } async queryDailyStatisticsFirst( diff --git a/apollo/src/graphql.ts b/apollo/src/graphql.ts index b61f369d..ec3f5a1c 100644 --- a/apollo/src/graphql.ts +++ b/apollo/src/graphql.ts @@ -25,7 +25,7 @@ export abstract class IQuery { abstract historyRecords(sender?: Nullable, recipient?: Nullable, relayer?: Nullable, needWithdrawLiquidity?: Nullable, fromChains?: Nullable[]>, toChains?: Nullable[]>, bridges?: Nullable[]>, row?: Nullable, page?: Nullable, results?: Nullable[]>, recvTokenAddress?: Nullable, order?: Nullable): Nullable | Promise>; - abstract checkLnBridgeExist(fromChainId?: Nullable, toChainId?: Nullable, fromToken?: Nullable, toToken?: Nullable): Nullable | Promise>; + abstract checkLnBridgeExist(fromChainId?: Nullable, toChainId?: Nullable, fromToken?: Nullable, toToken?: Nullable, version?: Nullable): Nullable | Promise>; abstract tasksHealthCheck(name?: Nullable): Nullable[]> | Promise[]>>; diff --git a/apollo/src/lnv3/transfer.service.ts b/apollo/src/lnv3/transfer.service.ts index 055ef5da..a5e5125c 100644 --- a/apollo/src/lnv3/transfer.service.ts +++ b/apollo/src/lnv3/transfer.service.ts @@ -8,8 +8,142 @@ export class TransferService extends BaseTransferServiceT2 { private readonly ethereumEndpoint = this.configService.get('ETHEREUM_LNV3_ENDPOINT'); private readonly arbitrumEndpoint = this.configService.get('ARBITRUM_LNV3_ENDPOINT'); private readonly zksyncEndpoint = this.configService.get('ZKSYNC_LNV3_ENDPOINT'); + private readonly polygonEndpoint = this.configService.get('POLYGON_LNV3_ENDPOINT'); + private readonly bscEndpoint = this.configService.get('BSC_LNV3_ENDPOINT'); + private readonly lineaEndpoint = this.configService.get('LINEA_LNV3_ENDPOINT'); - formalChainTransfers: PartnerT2[] = []; + formalChainTransfers: PartnerT2[] = [ + { + chainId: 137, + chain: 'polygon', + url: this.polygonEndpoint, + bridge: 'lnv3', + symbols: [ + { + key: 'RING', + symbol: 'RING', + address: '0x9C1C23E60B72Bc88a043bf64aFdb16A02540Ae8f', + protocolFee: 30000000000000000000, + decimals: 18, + }, + { + key: 'USDT', + symbol: 'USDT', + address: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F', + protocolFee: 100000, + decimals: 6, + } + ], + channels: [ + { + chain: 'arbitrum', + channel: 'layerzero', + }, + { + chain: 'bsc', + channel: 'layerzero', + }, + { + chain: 'linea', + channel: 'layerzero', + } + ] + }, + { + chainId: 42161, + chain: 'arbitrum', + url: this.arbitrumEndpoint, + bridge: 'lnv3', + symbols: [ + { + key: 'RING', + symbol: 'RING', + address: '0x9e523234D36973f9e38642886197D023C88e307e', + protocolFee: 30000000000000000000, + decimals: 18, + }, + { + key: 'USDT', + symbol: 'USDT', + address: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', + protocolFee: 100000, + decimals: 6, + } + ], + channels: [ + { + chain: 'polygon', + channel: 'layerzero', + }, + { + chain: 'bsc', + channel: 'layerzero', + }, + { + chain: 'linea', + channel: 'layerzero', + } + ] + }, + { + chainId: 56, + chain: 'bsc', + url: this.bscEndpoint, + bridge: 'lnv3', + symbols: [ + { + key: 'USDT', + symbol: 'USDT', + address: '0x55d398326f99059fF775485246999027B3197955', + protocolFee: 100000000000000000, + decimals: 18, + } + ], + channels: [ + { + chain: 'polygon', + channel: 'layerzero', + }, + { + chain: 'arbitrum', + channel: 'layerzero', + }, + { + chain: 'linea', + channel: 'layerzero', + } + ] + }, + { + chainId: 59144, + chain: 'linea', + url: this.lineaEndpoint, + bridge: 'lnv3', + symbols: [ + { + key: 'USDT', + symbol: 'USDT', + address: '0xA219439258ca9da29E9Cc4cE5596924745e12B93', + protocolFee: 100000, + decimals: 6, + } + ], + channels: [ + { + chain: 'polygon', + channel: 'layerzero', + }, + { + chain: 'bsc', + channel: 'layerzero', + }, + { + chain: 'arbitrum', + channel: 'layerzero', + } + ] + } + ]; testChainTransfers: PartnerT2[] = [ {