From b2fb9d7d571b27b0d218e0e98e69d3a5c6a74d5f Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Fri, 12 Apr 2024 17:50:49 +0800 Subject: [PATCH 1/4] add notsumbited field --- .../aggregation/aggregation.history.graphql | 2 +- .../src/aggregation/aggregation.resolver.ts | 21 ++++++++++++------- apollo/src/graphql.ts | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/apollo/src/aggregation/aggregation.history.graphql b/apollo/src/aggregation/aggregation.history.graphql index 042a8754..3e8d7f76 100644 --- a/apollo/src/aggregation/aggregation.history.graphql +++ b/apollo/src/aggregation/aggregation.history.graphql @@ -102,7 +102,7 @@ type HealthInfo { type Query { historyRecordById(id: String): HistoryRecord historyRecordByTxHash(txHash: String): HistoryRecord - firstHistoryRecord(fromChain: String, toChain: String, bridge: String, results: [Int], relayer: String, token: String, order: String): HistoryRecord + firstHistoryRecord(fromChain: String, toChain: String, bridge: String, results: [Int], relayer: String, token: String, order: String, notsubmited: Boolean): 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, version: String): Boolean diff --git a/apollo/src/aggregation/aggregation.resolver.ts b/apollo/src/aggregation/aggregation.resolver.ts index 308833d7..5e9c34a6 100644 --- a/apollo/src/aggregation/aggregation.resolver.ts +++ b/apollo/src/aggregation/aggregation.resolver.ts @@ -31,7 +31,8 @@ export class AggregationResolver { @Args('results') results: number[], @Args('relayer') relayer: string, @Args('token') token: string, - @Args('order') order: string + @Args('order') order: string, + @Args('notsubmited') notsubmited: boolean, ) { const orderCondition = order?.split('_'); const orderBy = @@ -39,6 +40,8 @@ export class AggregationResolver { ? { [orderCondition[0]]: orderCondition[1] } : { startTime: Prisma.SortOrder.desc }; const resultCondition = results && results.length ? { result: { in: results } } : {}; + const submitCondition = notsubmited ? { confirmedBlocks: { search: '!0x' } } : {}; + return this.aggregationService.queryHistoryRecordFirst( { AND: { @@ -47,6 +50,7 @@ export class AggregationResolver { bridge: bridge, relayer: relayer, sendTokenAddress: token, + ...submitCondition, ...resultCondition, }, }, @@ -395,14 +399,18 @@ export class AggregationResolver { console.log(`get softTransferLimit failed ${record.id}, exception: ${e}`); continue; } - const providerFee = BigInt(amount) * BigInt(record.liquidityFeeRate) / BigInt(100000) + BigInt(record.baseFee); - if (limit < BigInt(amount) + providerFee + BigInt(record.protocolFee) || record.paused) { - continue; - } // offline if (record.heartbeatTimestamp + this.heartbeatTimeout < now) { continue; } + + if (limit > transferLimit) { + transferLimit = limit; + } + const providerFee = BigInt(amount) * BigInt(record.liquidityFeeRate) / BigInt(100000) + BigInt(record.baseFee); + if (limit < BigInt(amount) + providerFee + BigInt(record.protocolFee) || record.paused) { + continue; + } const point = await this.aggregationService.calculateLnBridgeRelayerPoint( sendToken, BigInt(amount), @@ -412,9 +420,6 @@ export class AggregationResolver { if (point == null) { continue; } - if (limit > transferLimit) { - transferLimit = limit; - } sortedRelayers.push({ record, point }); } return { diff --git a/apollo/src/graphql.ts b/apollo/src/graphql.ts index 44d0bf4f..66b44bae 100644 --- a/apollo/src/graphql.ts +++ b/apollo/src/graphql.ts @@ -19,7 +19,7 @@ export abstract class IQuery { abstract historyRecordByTxHash(txHash?: Nullable): Nullable | Promise>; - abstract firstHistoryRecord(fromChain?: Nullable, toChain?: Nullable, bridge?: Nullable, results?: Nullable[]>, relayer?: Nullable, token?: Nullable, order?: Nullable): Nullable | Promise>; + abstract firstHistoryRecord(fromChain?: Nullable, toChain?: Nullable, bridge?: Nullable, results?: Nullable[]>, relayer?: Nullable, token?: Nullable, order?: Nullable, notsubmited?: Nullable): Nullable | Promise>; abstract queryDailyStatistics(timepast: number, first?: Nullable, from?: Nullable, to?: Nullable, bridge?: Nullable, token?: Nullable): Nullable[]> | Promise[]>>; From 66410ffdc8273bf979bfbe157bce314806793e6e Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 15 Apr 2024 15:35:16 +0800 Subject: [PATCH 2/4] update search condition --- apollo/src/aggregation/aggregation.resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo/src/aggregation/aggregation.resolver.ts b/apollo/src/aggregation/aggregation.resolver.ts index 5e9c34a6..4efff0a3 100644 --- a/apollo/src/aggregation/aggregation.resolver.ts +++ b/apollo/src/aggregation/aggregation.resolver.ts @@ -40,7 +40,7 @@ export class AggregationResolver { ? { [orderCondition[0]]: orderCondition[1] } : { startTime: Prisma.SortOrder.desc }; const resultCondition = results && results.length ? { result: { in: results } } : {}; - const submitCondition = notsubmited ? { confirmedBlocks: { search: '!0x' } } : {}; + const submitCondition = notsubmited ? { confirmedBlocks: { search: '-0x' } } : {}; return this.aggregationService.queryHistoryRecordFirst( { From 6cddcb74217a87ed8b1e72387df2b837e320cc42 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 15 Apr 2024 17:20:58 +0800 Subject: [PATCH 3/4] update subgraph url --- apollo/.env.test | 10 +++++----- apollo/src/aggregation/aggregation.resolver.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apollo/.env.test b/apollo/.env.test index 785907f6..1f5f3a8b 100644 --- a/apollo/.env.test +++ b/apollo/.env.test @@ -14,11 +14,11 @@ SUB2ETH_INBOUND=https://thegraph.darwinia.network/ethv2/subgraphs/name/sub2ethin GOERLI_A2E_LN_ENDPOINT=http://localhost:8000/subgraphs/name/arbi2ethln/ethereum ARBITRUM_A2E_LN_ENDPOINT=http://localhost:8000/subgraphs/name/arbi2ethln/arbitrum -LN_ETHEREUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-sepolia/version/latest -LN_ETHEREUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-sepolia/version/latest -LN_ARBITRUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-arbisepolia/version/latest -LN_ARBITRUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-arbisepolia/version/latest -LN_ZKSYNC_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-zksepolia/version/latest +LN_ETHEREUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-sepolia/v1.0.1 +LN_ETHEREUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-sepolia/v1.0.1 +LN_ARBITRUM_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-arbisepolia/v1.0.1 +LN_ARBITRUM_OPPOSITE_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-opposite-arbisepolia/v1.0.1 +LN_ZKSYNC_DEFAULT_ENDPOINT = https://api.studio.thegraph.com/query/61328/ln-default-zksepolia/v1.0.1 ETHEREUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-sepolia/v1.0.5 ARBITRUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-arbitrum-sepolia/v1.0.5 diff --git a/apollo/src/aggregation/aggregation.resolver.ts b/apollo/src/aggregation/aggregation.resolver.ts index 4efff0a3..873bb215 100644 --- a/apollo/src/aggregation/aggregation.resolver.ts +++ b/apollo/src/aggregation/aggregation.resolver.ts @@ -40,7 +40,7 @@ export class AggregationResolver { ? { [orderCondition[0]]: orderCondition[1] } : { startTime: Prisma.SortOrder.desc }; const resultCondition = results && results.length ? { result: { in: results } } : {}; - const submitCondition = notsubmited ? { confirmedBlocks: { search: '-0x' } } : {}; + const submitCondition = notsubmited ? { confirmedBlocks: { not: { contains: '0x' } } } : {}; return this.aggregationService.queryHistoryRecordFirst( { From bf122bcf4bbade2b6ee4684cd1121d4525e48517 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 15 Apr 2024 17:51:04 +0800 Subject: [PATCH 4/4] add crab<>darwinia guard --- apollo/src/guard/guard.service.ts | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apollo/src/guard/guard.service.ts b/apollo/src/guard/guard.service.ts index 2b0f09f1..1618e6c7 100644 --- a/apollo/src/guard/guard.service.ts +++ b/apollo/src/guard/guard.service.ts @@ -45,6 +45,38 @@ export class GuardService { chainId: 46, depositor: '0x2B496f19A420C02490dB859fefeCCD71eDc2c046', contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'darwinia-dvm', + toChain: 'crab-dvm', + bridge: 'xtoken-darwinia-crab', + chainId: 44, + depositor: '0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'crab-dvm', + toChain: 'darwinia-dvm', + bridge: 'xtoken-darwinia-crab', + chainId: 46, + depositor: '0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'darwinia-dvm', + toChain: 'crab-dvm', + bridge: 'xtoken-crab-darwinia', + chainId: 44, + depositor: '0xa64D1c284280b22f921E7B2A55040C7bbfD4d9d0', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', + }, + { + fromChain: 'crab-dvm', + toChain: 'darwinia-dvm', + bridge: 'xtoken-crab-darwinia', + chainId: 46, + depositor: '0xf6372ab2d35B32156A19F2d2F23FA6dDeFBE58bd', + contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7', } ];