Skip to content

Commit

Permalink
supported chains interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Mar 12, 2024
1 parent 7890b88 commit 31b0b55
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 1 deletion.
8 changes: 8 additions & 0 deletions apollo/prisma/migrations/20240312025824_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `tokenKey` to the `LnBridgeRelayInfo` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "LnBridgeRelayInfo" ADD COLUMN "tokenKey" TEXT NOT NULL;
1 change: 1 addition & 0 deletions apollo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ model LnBridgeRelayInfo {
bridge String
relayer String
sendToken String
tokenKey String
transactionHash String
timestamp Int
margin String
Expand Down
7 changes: 7 additions & 0 deletions apollo/src/aggregation/aggregation.history.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type LnBridgeRelayInfo {
bridge: String!
relayer: String!
sendToken: String
tokenKey: String
transactionHash: String!
timestamp: Int!
margin: String
Expand Down Expand Up @@ -85,6 +86,11 @@ type SortedLnBridgeRelayInfos {
records: [LnBridgeRelayInfo]
}

type SupportChains {
fromChain: String!
toChains: [String]
}

type HealthInfo {
name: String
callTimes: Int
Expand All @@ -102,6 +108,7 @@ type Query {
queryRelayRecords(fromChain: String, toChain: String, bridge: String, relayer: String, row: Int): HistoryRecords
queryLnBridgeRelayInfos(fromChain: String, toChain: String, version: String, bridge: String, relayer: String, row: Int, page: Int): LnBridgeRelayInfos
sortedLnBridgeRelayInfos(fromChain: String, toChain: String, version: String, bridge: String, token: String, row: Int, amount: String, decimals: Int): SortedLnBridgeRelayInfos
queryLnBridgeSupportChains(tokenKey: String): [SupportChains]
}

type Mutation {
Expand Down
32 changes: 32 additions & 0 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,38 @@ export class AggregationResolver {
return records;
}

@Query()
async queryLnBridgeSupportChains(
@Args('tokenKey') tokenKey: string
) {
const baseFilters = {
tokenKey,
paused: false,
OR: [{transferLimit: { not: '0' }}, {margin: { not: '0' }}]
};

const where = {
...baseFilters,
};

const records = await this.aggregationService.queryLnBridgeRelayInfos({
where,
});
let supportChains = new Map();
for (const record of records.records) {
let toChains = supportChains.get(record.fromChain);
if (!toChains) {
supportChains.set(record.fromChain, [ record.toChain ]);
} else {
toChains.push(record.toChain);
}
}
return Array.from(supportChains, ([fromChain, toChains]) => ({
fromChain,
toChains,
}));
}

@Query()
async sortedLnBridgeRelayInfos(
@Args('fromChain') fromChain: string,
Expand Down
1 change: 1 addition & 0 deletions apollo/src/base/TransferServiceT3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface RemoteInfo {
}

export interface Token {
key: string;
fromSymbol: string;
fromAddress: string;
decimals: number;
Expand Down
8 changes: 8 additions & 0 deletions apollo/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export abstract class IQuery {
abstract queryLnBridgeRelayInfos(fromChain?: Nullable<string>, toChain?: Nullable<string>, version?: Nullable<string>, bridge?: Nullable<string>, relayer?: Nullable<string>, row?: Nullable<number>, page?: Nullable<number>): Nullable<LnBridgeRelayInfos> | Promise<Nullable<LnBridgeRelayInfos>>;

abstract sortedLnBridgeRelayInfos(fromChain?: Nullable<string>, toChain?: Nullable<string>, version?: Nullable<string>, bridge?: Nullable<string>, token?: Nullable<string>, row?: Nullable<number>, amount?: Nullable<string>, decimals?: Nullable<number>): Nullable<SortedLnBridgeRelayInfos> | Promise<Nullable<SortedLnBridgeRelayInfos>>;

abstract queryLnBridgeSupportChains(tokenKey?: Nullable<string>): Nullable<Nullable<SupportChains>[]> | Promise<Nullable<Nullable<SupportChains>[]>>;
}

export class HistoryRecord {
Expand Down Expand Up @@ -94,6 +96,7 @@ export class LnBridgeRelayInfo {
bridge: string;
relayer: string;
sendToken?: Nullable<string>;
tokenKey?: Nullable<string>;
transactionHash: string;
timestamp: number;
margin?: Nullable<string>;
Expand Down Expand Up @@ -122,6 +125,11 @@ export class SortedLnBridgeRelayInfos {
records?: Nullable<Nullable<LnBridgeRelayInfo>[]>;
}

export class SupportChains {
fromChain: string;
toChains?: Nullable<Nullable<string>[]>;
}

export class HealthInfo {
name?: Nullable<string>;
callTimes?: Nullable<number>;
Expand Down
5 changes: 5 additions & 0 deletions apollo/src/lnbridgev20/lnbridgev20.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface BridgeIndexInfo {
}

export interface TokenPairInfo {
key: string;
fromSymbol: string;
toSymbol: string;
fromDecimals: number;
Expand Down Expand Up @@ -494,6 +495,7 @@ export class Lnbridgev20Service implements OnModuleInit {
return null;
}
return {
key: sourceInfo.key,
fromSymbol: sourceInfo.fromSymbol,
fromDecimals: sourceInfo.decimals,
toSymbol: targetInfo?.toSymbol,
Expand Down Expand Up @@ -592,6 +594,7 @@ export class Lnbridgev20Service implements OnModuleInit {
withdrawNonce: Number(record.withdrawNonce),
relayer: record.provider,
sendToken: record.sourceToken,
tokenKey: tokenPair.key,
transactionHash: record.transactionHash,
timestamp: Number(record.timestamp),
margin: BigInt(sourceMargin).toString(),
Expand Down Expand Up @@ -684,6 +687,7 @@ export class Lnbridgev20Service implements OnModuleInit {
withdrawNonce: 0,
relayer: record.provider,
sendToken: record.sourceToken,
tokenKey: tokenPair.key,
transactionHash: record.transactionHash,
timestamp: Number(record.timestamp),
margin: '0',
Expand Down Expand Up @@ -790,6 +794,7 @@ export class Lnbridgev20Service implements OnModuleInit {
nonce: latestNonce,
relayer: record.provider,
sendToken: record.sourceToken,
tokenKey: tokenPair.key,
transactionHash: record.transactionHash,
timestamp: Number(record.timestamp),
margin: margin,
Expand Down
28 changes: 28 additions & 0 deletions apollo/src/lnbridgev20/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: this.lnEthereumOppositeEndpoint,
tokens: [
{
key: 'RING',
fromSymbol: 'RING',
fromAddress: '0x9469D013805bFfB7D3DEBe5E7839237e535ec483',
decimals: 18,
Expand All @@ -81,6 +82,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: this.lnArbitrumOppositeEndpoint,
tokens: [
{
key: 'RING',
fromSymbol: 'RING',
fromAddress: '0x9e523234D36973f9e38642886197D023C88e307e',
decimals: 18,
Expand Down Expand Up @@ -115,6 +117,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
decimals: 6,
Expand Down Expand Up @@ -158,6 +161,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8',
decimals: 6,
Expand Down Expand Up @@ -191,6 +195,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x201eba5cc46d216ce6dc03f6a759e8e766e956ae',
decimals: 6,
Expand Down Expand Up @@ -225,6 +230,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9',
decimals: 6,
Expand Down Expand Up @@ -258,6 +264,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'RING',
fromSymbol: 'RING',
fromAddress: '0x9c1c23e60b72bc88a043bf64afdb16a02540ae8f',
decimals: 18,
Expand All @@ -282,6 +289,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x493257fd37edb34451f62edf8d2a0c418852ba4c',
decimals: 6,
Expand Down Expand Up @@ -324,6 +332,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df',
decimals: 6,
Expand All @@ -349,6 +358,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4',
decimals: 6,
Expand Down Expand Up @@ -382,6 +392,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'RING',
fromSymbol: 'RING',
fromAddress: '0x0000000000000000000000000000000000000000',
decimals: 18,
Expand All @@ -407,6 +418,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'CRAB',
fromSymbol: 'xWCRAB',
fromAddress: '0x656567Eb75b765FC320783cc6EDd86bD854b2305',
decimals: 18,
Expand All @@ -431,6 +443,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'CRAB',
fromSymbol: 'CRAB',
fromAddress: '0x0000000000000000000000000000000000000000',
decimals: 18,
Expand All @@ -447,6 +460,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'RING',
fromSymbol: 'xWRING',
fromAddress: '0x273131F7CB50ac002BDd08cA721988731F7e1092',
decimals: 18,
Expand All @@ -471,6 +485,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x55d398326f99059fF775485246999027B3197955',
decimals: 18,
Expand Down Expand Up @@ -505,6 +520,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d',
decimals: 18,
Expand All @@ -529,6 +545,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
decimals: 6,
Expand All @@ -553,6 +570,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58',
decimals: 6,
Expand All @@ -577,6 +595,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0xA219439258ca9da29E9Cc4cE5596924745e12B93',
decimals: 6,
Expand Down Expand Up @@ -613,6 +632,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: this.lnEthereumOppositeEndpoint,
tokens: [
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x0ac58Df0cc3542beC4cDa71B16D06C3cCc39f405',
decimals: 18,
Expand All @@ -638,6 +658,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x876A4f6eCF13EEb101F9E75FCeF58f19Ff383eEB',
decimals: 18,
Expand All @@ -663,6 +684,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'ETH',
fromSymbol: 'ETH',
fromAddress: '0x0000000000000000000000000000000000000000',
decimals: 18,
Expand Down Expand Up @@ -696,6 +718,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: this.lnArbitrumOppositeEndpoint,
tokens: [
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x8A87497488073307E1a17e8A12475a94Afcb413f',
decimals: 18,
Expand All @@ -721,6 +744,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x3b8Bb7348D4F581e67E2498574F73e4B9Fc51855',
decimals: 18,
Expand All @@ -746,6 +770,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'ETH',
fromSymbol: 'ETH',
fromAddress: '0x0000000000000000000000000000000000000000',
decimals: 18,
Expand Down Expand Up @@ -779,6 +804,7 @@ export class TransferService extends BaseTransferServiceT3 {
oppositeEndpoint: null,
tokens: [
{
key: 'USDC',
fromSymbol: 'USDC',
fromAddress: '0x253adBFE99Fcd096B9b5502753F96CF78D42eaD0',
decimals: 6,
Expand All @@ -804,6 +830,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'USDT',
fromSymbol: 'USDT',
fromAddress: '0x3350f1ef046e21E052dCbA60Fc575919CCaFEdeb',
decimals: 6,
Expand All @@ -829,6 +856,7 @@ export class TransferService extends BaseTransferServiceT3 {
],
},
{
key: 'ETH',
fromSymbol: 'ETH',
fromAddress: '0x0000000000000000000000000000000000000000',
decimals: 18,
Expand Down
Loading

0 comments on commit 31b0b55

Please sign in to comment.