Skip to content

Commit

Permalink
add polygon bsc arbitrum and linea
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Jan 31, 2024
1 parent 0b52bca commit 1a2801c
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 23 deletions.
5 changes: 5 additions & 0 deletions apollo/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apollo/src/aggregation/aggregation.history.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions apollo/src/aggregation/aggregation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 3 additions & 1 deletion apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
58 changes: 41 additions & 17 deletions apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion apollo/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export abstract class IQuery {

abstract historyRecords(sender?: Nullable<string>, recipient?: Nullable<string>, relayer?: Nullable<string>, needWithdrawLiquidity?: Nullable<boolean>, fromChains?: Nullable<Nullable<string>[]>, toChains?: Nullable<Nullable<string>[]>, bridges?: Nullable<Nullable<string>[]>, row?: Nullable<number>, page?: Nullable<number>, results?: Nullable<Nullable<number>[]>, recvTokenAddress?: Nullable<string>, order?: Nullable<string>): Nullable<HistoryRecords> | Promise<Nullable<HistoryRecords>>;

abstract checkLnBridgeExist(fromChainId?: Nullable<number>, toChainId?: Nullable<number>, fromToken?: Nullable<string>, toToken?: Nullable<string>): Nullable<boolean> | Promise<Nullable<boolean>>;
abstract checkLnBridgeExist(fromChainId?: Nullable<number>, toChainId?: Nullable<number>, fromToken?: Nullable<string>, toToken?: Nullable<string>, version?: Nullable<string>): Nullable<boolean> | Promise<Nullable<boolean>>;

abstract tasksHealthCheck(name?: Nullable<string>): Nullable<Nullable<HealthInfo>[]> | Promise<Nullable<Nullable<HealthInfo>[]>>;

Expand Down
136 changes: 135 additions & 1 deletion apollo/src/lnv3/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,142 @@ export class TransferService extends BaseTransferServiceT2 {
private readonly ethereumEndpoint = this.configService.get<string>('ETHEREUM_LNV3_ENDPOINT');
private readonly arbitrumEndpoint = this.configService.get<string>('ARBITRUM_LNV3_ENDPOINT');
private readonly zksyncEndpoint = this.configService.get<string>('ZKSYNC_LNV3_ENDPOINT');
private readonly polygonEndpoint = this.configService.get<string>('POLYGON_LNV3_ENDPOINT');
private readonly bscEndpoint = this.configService.get<string>('BSC_LNV3_ENDPOINT');
private readonly lineaEndpoint = this.configService.get<string>('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[] = [
{
Expand Down

0 comments on commit 1a2801c

Please sign in to comment.