Skip to content

Commit

Permalink
Merge pull request #156 from helix-bridge/xiaoch05-for-xtoken
Browse files Browse the repository at this point in the history
xtokenv3 indexer
  • Loading branch information
xiaoch05 authored Apr 2, 2024
2 parents 11aec31 + f5d314a commit e7ce0fa
Show file tree
Hide file tree
Showing 27 changed files with 642 additions and 1,210 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
# on:
# pull_request:

env:
DOCKER_REGISTRY: ghcr.io

jobs:
publish-apollo:
name: Publish apollo
Expand All @@ -18,9 +21,9 @@ jobs:
- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.QUAY_IO_BOT_USERNAME }}
password: ${{ secrets.QUAY_IO_BOT_PASSWORD }}
registry: quay.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.DOCKER_REGISTRY }}

- uses: benjlevesque/[email protected]
id: short-sha
Expand All @@ -31,10 +34,11 @@ jobs:
id: tag-name

- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
file: apollo/Dockerfile
push: true
#context: apollo
file: apollo/Dockerfile
tags: |
quay.io/helix-bridge/apollo:sha-${{ steps.short-sha.outputs.sha }}
quay.io/helix-bridge/apollo:${{ steps.tag-name.outputs.tag }}
${{ env.DOCKER_REGISTRY }}/${{ github.repository }}:sha-${{ steps.short-sha.outputs.sha }}
${{ env.DOCKER_REGISTRY }}/${{ github.repository }}:${{ steps.tag-name.outputs.tag }}
8 changes: 7 additions & 1 deletion apollo/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ SCROLL_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/59403/lnv3-scroll/v1.
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

XTOKEN_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia
XTOKEN_DARWINIA_CRAB_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-backing
XTOKEN_DARWINIA_CRAB_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-issuing
XTOKEN_CRAB_DARWINIA_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-backing
XTOKEN_CRAB_DARWINIA_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-issuing
XTOKEN_DARWINIA_ETHEREUM_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-ethereum-backing
XTOKEN_DARWINIA_ETHEREUM_ISSUING=https://api.studio.thegraph.com/query/59403/xtoken-dar-ethereum-issuing/v1.0.2
XTOKEN_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab
XTOKEN_DISPATCH_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/darwinia
XTOKEN_DISPATCH_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/crab
XTOKEN_DISPATCH_ETHEREUM=https://api.studio.thegraph.com/query/59403/xtoken-dispatch-ethereum/v1.0.0

CHAIN_TYPE=formal
6 changes: 3 additions & 3 deletions apollo/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ZKSYNC_LNV3_ENDPOINT=https://api.studio.thegraph.com/query/61328/lnv3-zksepolia/
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

XTOKEN_DARWINIA = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokentransfer/pangolin
XTOKEN_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-sepolia/v1.1.3
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
XTOKEN_DISPATCH_DARWINIA = https://thegraph-g2.darwinia.network/helix/subgraphs/name/xtokendispatch/pangolin
XTOKEN_DISPATCH_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-dispatch-sepolia/v1.1.3
XTOKEN_DISPATCH_ETHEREUM = https://api.studio.thegraph.com/query/61328/xtoken-dispatch-sepolia/v1.1.4
4 changes: 2 additions & 2 deletions apollo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM node:14-alpine
COPY . /opt/indexer

RUN cd /opt/indexer/apollo && \
npm i && \
yarn install && \
npx prisma generate

WORKDIR /opt/indexer/apollo
Expand All @@ -14,4 +14,4 @@ ENV VERSION_MODE prod

# CMD [ "node", "index.js" ]

ENTRYPOINT /opt/indexer/apollo/scripts/entrypoint.sh ${VERSION_MODE}
ENTRYPOINT /opt/indexer/apollo/scripts/entrypoint.sh ${VERSION_MODE}
2 changes: 2 additions & 0 deletions apollo/prisma/migrations/20240325130656_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "HistoryRecord" ADD COLUMN "extData" TEXT;
3 changes: 3 additions & 0 deletions apollo/prisma/migrations/20240327060430_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "HistoryRecord" ADD COLUMN "recvOuterTokenAddress" TEXT,
ADD COLUMN "sendOuterTokenAddress" TEXT;
3 changes: 3 additions & 0 deletions apollo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ model HistoryRecord {
messageNonce String
sendTokenAddress String
recvTokenAddress String?
sendOuterTokenAddress String?
recvOuterTokenAddress String?
guardSignatures String?
relayer String?
endTxHash String?
confirmedBlocks String?
needWithdrawLiquidity Boolean?
lastRequestWithdraw BigInt?
extData String?
}

model DailyStatistics {
Expand Down
3 changes: 3 additions & 0 deletions apollo/src/aggregation/aggregation.history.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ type HistoryRecord {
messageNonce: String
sendTokenAddress: String
recvTokenAddress: String
sendOuterTokenAddress: String
recvOuterTokenAddress: String
guardSignatures: String
relayer: String
endTxHash: String
confirmedBlocks: String
needWithdrawLiquidity: Boolean
lastRequestWithdraw: BigInt
extData: String
}

type DailyStatistics {
Expand Down
2 changes: 1 addition & 1 deletion apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
BigInt(last(record.id.split('-'))).toString(),
record.endTime.toString(),
record.recvTokenAddress,
record.recipient,
record.recvAmount,
record.extData,
signature
);
if (!guard) {
Expand Down
6 changes: 3 additions & 3 deletions apollo/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export class BigIntScalar extends BigInt {}
AggregationModule,
StatisticModule,
//XcmModule,
Sub2ethv2Module,
LnbridgeModule,
S2sv21Module,
//Sub2ethv2Module,
//LnbridgeModule,
//S2sv21Module,
Lnbridgev20Module,
xTokenModule,
Lnv3Module,
Expand Down
1 change: 1 addition & 0 deletions apollo/src/base/TransferServiceT2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface PartnerSymbol {
key: string;
symbol: string;
address: string;
outerAddress: string;
protocolFee: number;
decimals: number;
}
Expand Down
3 changes: 3 additions & 0 deletions apollo/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ export class HistoryRecord {
messageNonce?: Nullable<string>;
sendTokenAddress?: Nullable<string>;
recvTokenAddress?: Nullable<string>;
sendOuterTokenAddress?: Nullable<string>;
recvOuterTokenAddress?: Nullable<string>;
guardSignatures?: Nullable<string>;
relayer?: Nullable<string>;
endTxHash?: Nullable<string>;
confirmedBlocks?: Nullable<string>;
needWithdrawLiquidity?: Nullable<boolean>;
lastRequestWithdraw?: Nullable<BigInt>;
extData?: Nullable<string>;
}

export class DailyStatistics {
Expand Down
49 changes: 29 additions & 20 deletions apollo/src/guard/guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ export class GuardService {
toChain: 'sepolia',
bridge: 'xtoken-pangolin-dvm',
chainId: 11155111,
depositor: '0x371019523b25Ff4F26d977724f976566b08bf741',
contract: '0x3f200d3b6DA62bcA2F8a93F663b172A7f1AaE9ba',
depositor: '0x1aeC008Af5c604be3525d0bB70fFcc4D7281f30C',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'sepolia',
toChain: 'pangolin-dvm',
bridge: 'xtoken-sepolia',
chainId: 43,
depositor: '0x24f8a04F0cA0730F4b8eC3241F15aCc6b3f8Da0a',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'darwinia-dvm',
toChain: 'ethereum',
bridge: 'helix-sub2ethv2(lock)',
bridge: 'xtoken-darwinia-dvm',
chainId: 1,
depositor: null,
contract: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1',
depositor: '0xDc0C760c0fB4672D06088515F6446a71Df0c64C1',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
},
{
fromChain: 'ethereum',
toChain: 'darwinia-dvm',
bridge: 'xtoken-ethereum',
chainId: 46,
depositor: '0x2B496f19A420C02490dB859fefeCCD71eDc2c046',
contract: '0x4CA75992d2750BEC270731A72DfDedE6b9E71cC7',
}
];

Expand All @@ -39,8 +55,8 @@ export class GuardService {
transferId: string,
timestamp: string,
token: string,
recipient: string,
amount: string,
extData: string,
sig: string
): string | null {
const info = this.guardConfig.find((info) => {
Expand All @@ -54,8 +70,8 @@ export class GuardService {
transferId,
timestamp,
token,
recipient,
amount,
extData,
info.chainId,
info.contract
);
Expand All @@ -67,24 +83,17 @@ export class GuardService {
transferId: string,
timestamp: string,
token: string,
recipient: string,
amount: string,
extData: string,
chainId: number,
contractAddress: string
): string {
const claimSign = depositor === null ?
this.web3.eth.abi.encodeFunctionSignature(
'claim(uint256,uint256,address,address,uint256,bytes[])'
) : this.web3.eth.abi.encodeFunctionSignature(
'claim(address,uint256,uint256,address,address,uint256,bytes[])'
const claimSign = this.web3.eth.abi.encodeFunctionSignature(
'claim(address,uint256,uint256,address,uint256,bytes,bytes[])'
);
const param = depositor === null ?
this.web3.eth.abi.encodeParameters(
['uint256', 'uint256', 'address', 'address', 'uint256'],
[transferId, timestamp, token, recipient, amount]
) : this.web3.eth.abi.encodeParameters(
['address', 'uint256', 'uint256', 'address', 'address', 'uint256'],
[depositor, transferId, timestamp, token, recipient, amount]
const param = this.web3.eth.abi.encodeParameters(
['address', 'uint256', 'uint256', 'address', 'uint256', 'bytes'],
[depositor, transferId, timestamp, token, amount, extData]
);
const message = this.web3.eth.abi.encodeParameters(['bytes4', 'bytes'], [claimSign, param]);
const structHash = this.web3.utils.keccak256(message);
Expand Down
19 changes: 14 additions & 5 deletions apollo/src/lnbridgev20/lnbridgev20.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ export class Lnbridgev20Service implements OnModuleInit {
};
}

transferDecimals(value: string, decimals: number): string {
if (decimals > 0) {
return value.padEnd(value.length + decimals);
} else if (value.length + decimals > 0) {
return value.substr(0, value.length + decimals);
} else {
return '0';
}
}

async fetchMarginInfoFromTarget(transfer: PartnerT3, indexInfo: BridgeIndexInfo) {
const index = indexInfo.index;
let latestNonce = this.fetchCache[index].latestRelayerInfoTargetNonce;
Expand Down Expand Up @@ -561,8 +571,7 @@ export class Lnbridgev20Service implements OnModuleInit {
const relayerInfo = await this.aggregationService.queryLnBridgeRelayInfoById({
id: id,
});
const sourceMargin =
Number(record.margin) * Math.pow(10, tokenPair.fromDecimals - tokenPair.toDecimals);
const sourceMargin = this.transferDecimals(record.margin, tokenPair.fromDecimals - tokenPair.toDecimals);
if (relayerInfo) {
// transfer target margin to source margin
const updateData = {
Expand Down Expand Up @@ -620,7 +629,7 @@ export class Lnbridgev20Service implements OnModuleInit {
);
}
} catch (error) {
this.logger.warn(`fetch lnv2 relay records failed, error ${error}`);
this.logger.warn(`fetchMarginInfoFromTarget failed, error ${error}`);
}
}

Expand Down Expand Up @@ -727,7 +736,7 @@ export class Lnbridgev20Service implements OnModuleInit {
);
}
} catch (error) {
this.logger.warn(`fetch lnv2 relay records failed, error ${error}`);
this.logger.warn(`fetchFeeInfoFromSource failed, error ${error}`);
}
}

Expand Down Expand Up @@ -845,7 +854,7 @@ export class Lnbridgev20Service implements OnModuleInit {
);
}
} catch (error) {
this.logger.warn(`fetch lnv2 relay records failed, error ${error}`);
this.logger.warn(`fetchRelayInfo failed, error ${error}`);
}
}
}
Loading

0 comments on commit e7ce0fa

Please sign in to comment.