Skip to content

Commit

Permalink
support guardV3
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Dec 27, 2023
1 parent d481b42 commit ffdd213
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
3 changes: 2 additions & 1 deletion apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HistoryRecords, Lnv20RelayInfo, Lnv20RelayInfos } from '../graphql';
import { GuardService } from '../guard/guard.service';
// export lnbridge service configure
import { TransferService } from '../lnbridgev20/transfer.service';
import { last } from 'lodash';

@Injectable()
export class AggregationService extends PrismaClient implements OnModuleInit {
Expand Down Expand Up @@ -115,7 +116,7 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
record.fromChain,
record.toChain,
record.bridge,
BigInt(record.messageNonce).toString(),
BigInt(last(record.id.split('-'))).toString(),
record.endTime.toString(),
record.recvTokenAddress,
record.recipient,
Expand Down
27 changes: 12 additions & 15 deletions apollo/src/guard/guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class GuardInfo {
toChain: string;
bridge: string;
chainId: number;
depositor: string;
contract: string;
}

Expand All @@ -14,18 +15,12 @@ export class GuardService {

private readonly guardConfig: GuardInfo[] = [
{
fromChain: 'pangolin-dvm',
toChain: 'goerli',
bridge: 'helix-sub2ethv2(lock)',
chainId: 5,
contract: '0x8C986EC362A38cA4A6a3fd4188C5318c689A187d',
},
{
fromChain: 'darwinia-dvm',
toChain: 'ethereum',
bridge: 'helix-sub2ethv2(lock)',
chainId: 1,
contract: '0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1',
fromChain: 'crab-dvm',
toChain: 'sepolia',
bridge: 'xtoken-crab-dvm',
chainId: 11155111,
depositor: '0xf22D0bb66b39745Ae6e3fEa3E5859d7f0b367Fd1',
contract: '0xcc357d5A8E5dBD52bC508E0FE491137d912F6bc8',
},
];

Expand All @@ -47,6 +42,7 @@ export class GuardService {
return null;
}
const dataHash = this.generateDataHash(
info.depositor,
transferId,
timestamp,
token,
Expand All @@ -59,6 +55,7 @@ export class GuardService {
}

private generateDataHash(
depositor: string,
transferId: string,
timestamp: string,
token: string,
Expand All @@ -68,11 +65,11 @@ export class GuardService {
contractAddress: string
): string {
const claimSign = this.web3.eth.abi.encodeFunctionSignature(
'claim(uint256,uint256,address,address,uint256,bytes[])'
'claim(address,uint256,uint256,address,address,uint256,bytes[])'
);
const param = this.web3.eth.abi.encodeParameters(
['uint256', 'uint256', 'address', 'address', 'uint256'],
[transferId, timestamp, token, recipient, amount]
['address', 'uint256', 'uint256', 'address', 'address', 'uint256'],
[depositor, transferId, timestamp, token, recipient, amount]
);
const message = this.web3.eth.abi.encodeParameters(['bytes4', 'bytes'], [claimSign, param]);
const structHash = this.web3.utils.keccak256(message);
Expand Down
2 changes: 1 addition & 1 deletion apollo/src/xtoken/transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TransferService extends BaseTransferServiceT2 {
{
originalSymbol: 'CRAB',
symbol: 'xCRAB',
address: '0xe8835bB0735fbfD5ECAC1e20835D5B7C39622ba3',
address: '0x9Da7E18441f26515CC713290BE846E726d41781d',
protocolFee: 0,
decimals: 18,
},
Expand Down
2 changes: 1 addition & 1 deletion apollo/src/xtoken/xtoken.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class xTokenService implements OnModuleInit {
sendToken: sendTokenInfo.symbol,
recvToken: recvTokenInfo.symbol,
sendAmount: record.amount,
recvAmount: '0',
recvAmount: record.amount,
startTime: Number(record.timestamp),
endTime: endTime,
result: result,
Expand Down

0 comments on commit ffdd213

Please sign in to comment.