Skip to content

Commit

Permalink
Merge pull request #162 from helix-bridge/xiaoch05-support-morph
Browse files Browse the repository at this point in the history
support morph testnet
  • Loading branch information
xiaoch05 authored Apr 12, 2024
2 parents 0f06c95 + 4e5f7b3 commit 726d13b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 8 deletions.
8 changes: 4 additions & 4 deletions apollo/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ LN_ETHEREUM_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefau
LN_ARBITRUM_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-arbitrum/v2.0.0
LN_MANTLE_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/mantle
LN_POLYGON_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-polygon/v2.0.0
LN_ZKSYNC_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-zksync/version/latest
LN_SCROLL_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-scroll/version/latest
LN_ZKSYNC_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-zksync/v1.0.0
LN_SCROLL_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-scroll/1.0.0
LN_DARWINIA_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/darwinia
LN_DARWINIA_OPPOSITE_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnopposite/darwinia
LN_CRAB_DEFAULT_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lndefault/crab
LN_BSC_DEFAULT_ENDPOINT=https://api.thegraph.com/subgraphs/name/helix-bridge/lndefault-bsc
LN_BASE_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-base/version/latest
LN_BASE_DEFAULT_ENDPOINT=https://api.studio.thegraph.com/query/59403/lndefault-base/v1.0.0
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

Expand All @@ -33,7 +33,7 @@ LINEA_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/ln
OP_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-op/v1.0.0
GNOSIS_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-gnosis/v1.0.0
MANTLE_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv3/mantle
SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1.0.0
SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1.0.1
DARWINIA_LNV3_ENDPOINT=https://thegraph-g1.darwinia.network/helix/subgraphs/name/lnv3/darwinia
BLAST_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-blast/v1.0.0
ASTAR_ZKEVM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-astar-zkevm/v1.0.0
Expand Down
1 change: 1 addition & 0 deletions apollo/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ARBITRUM_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-arbitrum
ZKSYNC_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-zksepolia/v1.0.5
BERA_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/bera
TAIKO_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/taiko
MORPH_LNV3_ENDPOINT=https://thegraph-g2.darwinia.network/helix/subgraphs/name/lnv3/morph

XTOKEN_DARWINIA_ETHEREUM_BACKING = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokentransfer/pangolin
XTOKEN_DARWINIA_ETHEREUM_ISSUING = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.8
Expand Down
13 changes: 11 additions & 2 deletions apollo/src/aggregation/aggregation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,17 @@ export class AggregationResolver {
let updateData = {
heartbeatTimestamp: Math.floor(Date.now() / 1000),
};

if (softTransferLimit !== undefined && softTransferLimit !== '0') {
updateData['softTransferLimit'] = softTransferLimit;
// the softTransferLimit is on target chain, transfer it to source chain
const transferLimit = this.aggregationService.targetAmountToSourceAmount({
amount: softTransferLimit,
sourceChainId: Number(fromChainId),
targetChainId: Number(toChainId),
sourceToken: tokenAddress,
version
});
updateData['softTransferLimit'] = transferLimit;
}

try {
Expand Down Expand Up @@ -395,7 +404,7 @@ export class AggregationResolver {
continue;
}
const point = await this.aggregationService.calculateLnBridgeRelayerPoint(
token,
sendToken,
BigInt(amount),
decimals,
record
Expand Down
52 changes: 52 additions & 0 deletions apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,58 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
return this.tasksService.queryHealthChecks();
}

targetAmountToSourceAmount(params: {
amount: string;
sourceChainId: number;
targetChainId: number;
sourceToken: string;
version: string;
}): string {
const { amount, sourceChainId, targetChainId, sourceToken, version } = params;
let transferDecimals = (value: string, decimals: number) => {
if (decimals > 0) {
return value.padEnd(value.length + decimals, '0');
} else if (value.length + decimals > 0) {
return value.substr(0, value.length + decimals);
} else {
return '0';
}
}

if (version === 'lnv2') {
const sourceNode = this.lnv2Service.transfers.find((item) => item.chainId === sourceChainId);
const sourceTokenInfo = sourceNode?.tokens.find(
(item) => item.fromAddress.toLowerCase() === sourceToken.toLowerCase()
);
if (sourceTokenInfo === undefined) {
return '0';
}
const targetNode = this.lnv2Service.transfers.find((item) => item.chainId === targetChainId);
const targetTokenInfo = targetNode?.tokens.find(
(item) => item.key === sourceTokenInfo.key
);
if (targetTokenInfo === undefined) {
return '0';
}

return transferDecimals(amount, sourceTokenInfo.decimals - targetTokenInfo.decimals);
} else {
const lnv3SourceBridge = this.lnv3Service.transfers.find((item) => item.chainId === sourceChainId);
const sourceSymbol = lnv3SourceBridge?.symbols.find(
(item) => item.address.toLowerCase() === sourceToken.toLowerCase()
);
if (sourceSymbol === undefined) {
return '0';
}
const lnv3TargetBridge = this.lnv3Service.transfers.find((item) => item.chainId === targetChainId);
const targetSymbol = lnv3TargetBridge?.symbols.find(
(item) => item.key === sourceSymbol.key
);

return transferDecimals(amount, sourceSymbol.decimals - targetSymbol.decimals);
}
}

checkLnBridgeConfigure(params: {
sourceChainId: number;
targetChainId: number;
Expand Down
10 changes: 9 additions & 1 deletion apollo/src/lnbridgev20/lnbridgev20.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export class Lnbridgev20Service implements OnModuleInit {

transferDecimals(value: string, decimals: number): string {
if (decimals > 0) {
return value.padEnd(value.length + decimals);
return value.padEnd(value.length + decimals, '0');
} else if (value.length + decimals > 0) {
return value.substr(0, value.length + decimals);
} else {
Expand Down Expand Up @@ -659,6 +659,10 @@ export class Lnbridgev20Service implements OnModuleInit {
this.logger.warn(`query fee update failed err ${err}`);
});

if (records === undefined) {
this.logger.warn(`query record failed, url: ${indexInfo.url}, query: ${query}`);
return;
}
// query nonce big then latestNonce
for (const record of records) {
// query by relayer
Expand Down Expand Up @@ -767,6 +771,10 @@ export class Lnbridgev20Service implements OnModuleInit {
this.logger.warn(`query relay update record failed err ${err}`);
});

if (records === undefined) {
this.logger.warn(`query record failed, url: ${indexInfo.url}, query: ${query}`);
return;
}
// query nonce big then latestNonce
for (const record of records) {
// query by relayer
Expand Down
6 changes: 6 additions & 0 deletions apollo/src/lnv3/lnv3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ export class Lnv3Service implements OnModuleInit {
this.logger.warn(`query relay update record failed err ${err}`);
});

// maybe this query is archived and can't access
if (records === undefined) {
this.logger.warn(`query record failed, url: ${transfer.url}, query: ${query}`);
return;
}

// query nonce big then latestNonce
for (const record of records) {
// query by relayer
Expand Down
36 changes: 35 additions & 1 deletion apollo/src/lnv3/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class TransferService extends BaseTransferServiceT2 {
private readonly beraEndpoint = this.configService.get<string>('BERA_LNV3_ENDPOINT');
private readonly taikoEndpoint = this.configService.get<string>('TAIKO_LNV3_ENDPOINT');
private readonly astarZkEVMEndpoint = this.configService.get<string>('ASTAR_ZKEVM_LNV3_ENDPOINT');
private readonly morphEndpoint = this.configService.get<string>('MORPH_LNV3_ENDPOINT');

formalChainTransfers: PartnerT2[] = [
{
Expand Down Expand Up @@ -601,6 +602,10 @@ export class TransferService extends BaseTransferServiceT2 {
chain: 'bera',
channel: 'layerzero',
},
{
chain: 'morph',
channel: 'layerzero',
},
],
},
{
Expand Down Expand Up @@ -705,7 +710,36 @@ export class TransferService extends BaseTransferServiceT2 {
},
],
},

{
chainId: 2710,
chain: 'morph',
url: this.morphEndpoint,
bridge: 'lnv3',
symbols: [
{
key: 'USDC',
symbol: 'USDC',
address: '0x89AF830781A2C1d3580Db930bea11094F55AfEae',
outerAddress: '0x89AF830781A2C1d3580Db930bea11094F55AfEae',
protocolFee: 1000000000000000,
decimals: 18,
},
{
key: 'USDT',
symbol: 'USDT',
address: '0x463D1730a8527CA58d48EF70C7460B9920346567',
outerAddress: '0x463D1730a8527CA58d48EF70C7460B9920346567',
protocolFee: 1000000000000000,
decimals: 18,
},
],
channels: [
{
chain: 'arbitrum-sepolia',
channel: 'layerzero',
},
],
},
];

readonly addressToTokenInfo: { [key: string]: AddressTokenMap } = {};
Expand Down
1 change: 1 addition & 0 deletions subgraph/lnv3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build-zksync-sepolia": "sh generate.sh zksync-era-sepolia 0xDc55fF59F82AA50D8A4A61dB8CcaDffD26Fb7dD2 76772 && graph codegen && graph build",
"build-bera-testnet": "sh generate.sh bera 0x00e7EFf0826dfCDf2AA5945dFF710B48f4AA7E64 1006527 && graph codegen && graph build",
"build-taiko-testnet": "sh generate.sh taiko 0x00e7EFf0826dfCDf2AA5945dFF710B48f4AA7E64 501744 && graph codegen && graph build",
"build-morph-testnet": "sh generate.sh morph 0xD476650e03a45E70202b0bcAfa04E1513920f83a 1420941 && graph codegen && graph build",
"build-polygon-pos": "sh generate.sh matic 0xbA5D580B18b6436411562981e02c8A9aA1776D10 52848029 && graph codegen && graph build",
"build-arbitrum-one": "sh generate.sh arbitrum-one 0xbA5D580B18b6436411562981e02c8A9aA1776D10 175050634 && graph codegen && graph build",
"build-bsc": "sh generate.sh bsc 0xbA5D580B18b6436411562981e02c8A9aA1776D10 35684060 && graph codegen && graph build",
Expand Down

0 comments on commit 726d13b

Please sign in to comment.