Skip to content

Commit

Permalink
Merge pull request #145 from helix-bridge/xiaoch05-reconstruct-lnbridge
Browse files Browse the repository at this point in the history
reconstruct lnbridge
  • Loading branch information
xiaoch05 authored Oct 19, 2023
2 parents 77946da + 926ccb8 commit 3e1a87f
Show file tree
Hide file tree
Showing 30 changed files with 11,254 additions and 1,144 deletions.
3 changes: 3 additions & 0 deletions apollo/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ L2_ARBITRUM_URL=https://thegraph.darwinia.network/helix/subgraphs/name/l2arbitru
ETHEREUM_A2E_LNV2_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv2target/ethereum
ARBITRUM_A2E_LNV2_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv2source/arbitrum

LN_ETHEREUM_OPPOSITE_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnopposite/ethereum
LN_ARBITRUM_OPPOSITE_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnopposite/arbitrum

CHAIN_TYPE=formal
28 changes: 10 additions & 18 deletions apollo/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@ SUB2ETH_ISSUING=https://thegraph.darwinia.network/ethv2/subgraphs/name/sub2ethis
SUB2ETH_INBOUND=https://thegraph.darwinia.network/ethv2/subgraphs/name/sub2ethinboundLane
GOERLI_A2E_LN_ENDPOINT=http://localhost:8000/subgraphs/name/arbi2ethln/ethereum
ARBITRUM_A2E_LN_ENDPOINT=http://localhost:8000/subgraphs/name/arbi2ethln/arbitrum
ETHEREUM_A2E_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnarb2eth/ethereum
ARBITRUM_A2E_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnarb2eth/arbitrum
ETHEREUM_E2A_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lneth2arb/ethereum
ARBITRUM_E2A_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lneth2arb/arbitrum
ETHEREUM_ETH2ZK_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lneth2zk/ethereum
ZKSYNC_ETH2ZK_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lneth2zk/zksync
ETHEREUM_ZK2ETH_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnzk2eth/ethereum
ZKSYNC_ZK2ETH_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnzk2eth/zksync
LINEA_LINEA2ETH_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnlinea2eth/linea
ETHEREUM_LINEA2ETH_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnlinea2eth/ethereum
LINEA_ETH2LINEA_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lneth2linea/linea
ETHEREUM_ETH2LINEA_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lneth2linea/ethereum

ARBITRUM_ARB2LINEA_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnarb2linea/arbitrum
LINEA_ARB2LINEA_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnarb2linea/linea
ARBITRUM_ARB2ZK_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnarb2zk/arbitrum
ZKSYNC_ARB2ZK_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnarb2zk/zksync
ZKSYNC_ZK2LINEA_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnzk2linea/zksync
LINEA_ZK2LINEA_LNV2_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnzk2linea/linea
LN_ETHEREUM_DEFAULT_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lndefault/goerli
LN_ETHEREUM_OPPOSITE_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnopposite/goerli
LN_LINEA_DEFAULT_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lndefault/lineagoerli
LN_LINEA_OPPOSITE_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnopposite/lineagoerli
LN_MANTLE_DEFAULT_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lndefault/mantlegoerli
LN_MANTLE_OPPOSITE_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnopposite/mantlegoerli
LN_ARBITRUM_DEFAULT_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lndefault/arbigoerli
LN_ARBITRUM_OPPOSITE_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnopposite/arbigoerli
LN_ZKSYNC_DEFAULT_ENDPOINT = https://thegraph-g2.darwinia.network/helix/subgraphs/name/lndefault/zkgoerli

12 changes: 12 additions & 0 deletions apollo/prisma/migrations/20230921123506_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- Added the required column `cost` to the `Lnv20RelayInfo` table without a default value. This is not possible if the table is not empty.
- Added the required column `heartbeatTimestamp` to the `Lnv20RelayInfo` table without a default value. This is not possible if the table is not empty.
- Added the required column `profit` to the `Lnv20RelayInfo` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Lnv20RelayInfo" ADD COLUMN "cost" BIGINT NOT NULL,
ADD COLUMN "heartbeatTimestamp" INTEGER NOT NULL,
ADD COLUMN "profit" BIGINT NOT NULL;
3 changes: 3 additions & 0 deletions apollo/prisma/migrations/20230921131509_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Lnv20RelayInfo" ALTER COLUMN "cost" SET DATA TYPE TEXT,
ALTER COLUMN "profit" SET DATA TYPE TEXT;
8 changes: 8 additions & 0 deletions apollo/prisma/migrations/20231011073505_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `protocolFee` to the `Lnv20RelayInfo` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Lnv20RelayInfo" ADD COLUMN "protocolFee" TEXT NOT NULL;
8 changes: 8 additions & 0 deletions apollo/prisma/migrations/20231011080135_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `messageChannel` to the `Lnv20RelayInfo` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Lnv20RelayInfo" ADD COLUMN "messageChannel" TEXT NOT NULL;
5 changes: 5 additions & 0 deletions apollo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ model Lnv20RelayInfo {
transaction_hash String
timestamp Int
margin String
protocolFee String
baseFee String
liquidityFeeRate Int
slashCount Int
lastTransferId String
cost String
profit String
heartbeatTimestamp Int
messageChannel String
}

8 changes: 7 additions & 1 deletion apollo/src/aggregation/aggregation.history.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ type Lnv20RelayInfo {
transaction_hash: String!
timestamp: Int!
margin: String
protocolFee: String
baseFee: String
liquidityFeeRate: Int
slashCount: Int
withdrawNonce: BigInt
lastTransferId: String
cost: String
profit: String
heartbeatTimestamp: Int
messageChannel: String
}

type Lnv20RelayInfos {
Expand All @@ -76,12 +81,13 @@ type Query {
historyRecords(sender: String, recipient: String, fromChains: [String], toChains: [String], bridges: [String], row: Int, page: Int, results: [Int], recvTokenAddress: String, order: String): HistoryRecords
queryGuardNeedSignature(fromChain: String, toChain: String, bridge: String, guardAddress: String, row: Int): HistoryRecords
queryRelayRecords(fromChain: String, toChain: String, bridge: String, relayer: String, row: Int): HistoryRecords
queryLnv20RelayInfos(fromChain: String, toChain: String, bridge: String, row: Int, page: Int): Lnv20RelayInfos
queryLnv20RelayInfos(fromChain: String, toChain: String, bridge: String, relayer: String, row: Int, page: Int): Lnv20RelayInfos
sortedLnv20RelayInfos(fromChain: String, toChain: String, bridge: String, token: String, row: Int, amount: String, decimals: Int): [Lnv20RelayInfo]
}

type Mutation {
addGuardSignature(id: String, dataHash: String, signature: String): String
updateConfirmedBlock(id: String, block: String): String
lnBridgeHeartBeat(fromChainId: String, toChainId: String, relayer: String, tokenAddress: String): String
}

29 changes: 24 additions & 5 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,34 @@ export class AggregationResolver {
}

@Mutation()
async updateConfirmedBlock(
@Args('id') id: string,
@Args('block') block: string
) {
async updateConfirmedBlock(@Args('id') id: string, @Args('block') block: string) {
await this.aggregationService.updateConfirmedBlock({
where: { id: id },
block: block,
});
}

@Mutation()
async lnBridgeHeartBeat(
@Args('fromChainId') fromChainId: string,
@Args('toChainId') toChainId: string,
@Args('relayer') relayer: string,
@Args('tokenAddress') tokenAddress: string
) {
const id = `lnv20-${fromChainId}-${toChainId}-${relayer.toLowerCase()}-${tokenAddress.toLowerCase()}`;
try {
await this.aggregationService.updateLnv20RelayInfo({
where: { id: id },
data: {
heartbeatTimestamp: Math.floor(Date.now() / 1000),
},
});
} catch (e) {
console.log(`heart beat failed ${id}, exception: ${e}`);
return;
}
}

@Query()
async queryGuardNeedSignature(
@Args('fromChain') fromChain: string,
Expand Down Expand Up @@ -210,12 +228,13 @@ export class AggregationResolver {
@Args('fromChain') fromChain: string,
@Args('toChain') toChain: string,
@Args('bridge') bridge: string,
@Args('relayer') relayer: string,
@Args('row') row: number,
@Args('page') page: number
) {
const skip = row * page || 0;
const take = row || 10;
const baseFilters = { fromChain, toChain, bridge };
const baseFilters = { fromChain, toChain, bridge, relayer };

const where = {
...baseFilters,
Expand Down
6 changes: 4 additions & 2 deletions apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
}

async queryLnv20RelayInfoFirst(
lnv20RelayInfoWhereInput: Prisma.Lnv20RelayInfoWhereInput
lnv20RelayInfoWhereInput: Prisma.Lnv20RelayInfoWhereInput,
orderBy?: Prisma.Enumerable<Prisma.Lnv20RelayInfoOrderByWithRelationAndSearchRelevanceInput>
): Promise<Lnv20RelayInfo | null> {
return this.lnv20RelayInfo.findFirst({
where: lnv20RelayInfoWhereInput,
orderBy: { nonce: 'desc' },
orderBy,
//orderBy: { nonce: 'desc' },
});
}

Expand Down
2 changes: 0 additions & 2 deletions apollo/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AggregationModule } from './aggregation/aggregation.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TasksModule } from './tasks/tasks.module';
import { CbridgeModule } from './cbridge/cbridge.module';
import { StatisticModule } from './statistic/statistic.module';
import { XcmModule } from './xcm/xcm.module';
import { Sub2ethv2Module } from './sub2ethv2/sub2ethv2.module';
Expand Down Expand Up @@ -42,7 +41,6 @@ export class BigIntScalar extends BigInt {}
ScheduleModule.forRoot(),
TasksModule,
AggregationModule,
//CbridgeModule,
StatisticModule,
//XcmModule,
Sub2ethv2Module,
Expand Down
21 changes: 21 additions & 0 deletions apollo/src/base/TransferServiceT2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,32 @@ export enum RecordStatus {
failed,
}

export interface FetchCacheInfo {
latestNonce: number;
isSyncingHistory: boolean;
skip: number;
}

export interface BridgeBaseConfigure {
name: string;
fetchHistoryDataFirst: number;
fetchSendDataInterval: number;
takeEachTime: number;
}

export interface PartnerSymbol {
symbol: string;
address: string;
protocolFee: number;
decimals: number;
}

export interface PartnerT2 {
chainId: number;
chain: string;
url: string; // record api endpoint
bridge: string;
symbols: PartnerSymbol[];
}

export abstract class BaseTransferServiceT2 extends AddressToken {
Expand Down
11 changes: 0 additions & 11 deletions apollo/src/cbridge/cbridge.module.ts

This file was deleted.

Loading

0 comments on commit 3e1a87f

Please sign in to comment.