Skip to content

Commit

Permalink
Merge pull request #45 from helix-bridge/xiaoch05-different-relayer
Browse files Browse the repository at this point in the history
support different relayer accounts on source and target
  • Loading branch information
xiaoch05 authored Oct 25, 2024
2 parents 7d508de + ec38799 commit a658d77
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@composedb/client": "0.5.0",
"@composedb/types": "0.5.0",
"@helixbridge/helixconf": "1.1.17",
"@helixbridge/helixconf": "1.1.18",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
Expand Down
17 changes: 14 additions & 3 deletions src/base/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export interface RelayArgs {
transferParameter: TransferParameter;
remoteChainId: number;
expectedTransferId: string;
relayBySelf: boolean;
}

export interface TransferParameterV3 {
Expand All @@ -212,6 +213,7 @@ export interface TransferParameterV3 {
export interface RelayArgsV3 {
transferParameter: TransferParameterV3;
expectedTransferId: string;
relayBySelf: boolean;
}

export interface LnProviderFeeInfo {
Expand Down Expand Up @@ -433,6 +435,9 @@ export class LnBridgeContract extends EthereumContract {
args: RelayArgs | RelayArgsV3,
gasLimit: bigint | null = null
): Promise<string> | null {
if (!args.relayBySelf) {
throw Error("Lnv2 donot support relay by others");
}
const argsV2 = args as RelayArgs;
var value = null;
const parameter = argsV2.transferParameter;
Expand Down Expand Up @@ -461,6 +466,9 @@ export class LnBridgeContract extends EthereumContract {
}

relayRawData(args: RelayArgs | RelayArgsV3): RelayRawData {
if (!args.relayBySelf) {
throw Error("Lnv2 donot support relay by others");
}
var value = null;
const argsV2 = args as RelayArgs;
const parameter = argsV2.transferParameter;
Expand Down Expand Up @@ -489,6 +497,9 @@ export class LnBridgeContract extends EthereumContract {
nonce: number | null = null,
gasLimit: bigint | null = null
): Promise<TransactionResponse> {
if (!args.relayBySelf) {
throw Error("Lnv2 donot support relay by others");
}
var value = null;
const argsV2 = args as RelayArgs;
const parameter = argsV2.transferParameter;
Expand Down Expand Up @@ -772,7 +783,7 @@ export class Lnv3BridgeContract extends EthereumContract {
parameter.timestamp,
],
argsV3.expectedTransferId,
true,
argsV3.relayBySelf,
],
false,
value,
Expand All @@ -799,7 +810,7 @@ export class Lnv3BridgeContract extends EthereumContract {
parameter.timestamp,
],
argsV3.expectedTransferId,
true,
argsV3.relayBySelf,
]);
return { data, value };
}
Expand Down Expand Up @@ -830,7 +841,7 @@ export class Lnv3BridgeContract extends EthereumContract {
parameter.timestamp,
],
argsV3.expectedTransferId,
true,
argsV3.relayBySelf,
],
gas,
value,
Expand Down
7 changes: 4 additions & 3 deletions src/base/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ export class EthereumProvider {
const feeInfo: EIP1559Fee = {
// maxFeePerGas is not accurate
//maxFeePerGas: fee.maxFeePerGas,
maxFeePerGas: maxFeePerGas * stretchScale / BigInt(100),
maxPriorityFeePerGas: fee.maxPriorityFeePerGas * stretchScale / BigInt(100),
maxFeePerGas: (maxFeePerGas * stretchScale) / BigInt(100),
maxPriorityFeePerGas:
(fee.maxPriorityFeePerGas * stretchScale) / BigInt(100),
};
return {
eip1559fee: feeInfo,
Expand All @@ -137,7 +138,7 @@ export class EthereumProvider {
return {
isEip1559: false,
fee: {
gasPrice: fee.gasPrice * stretchScale / BigInt(100),
gasPrice: (fee.gasPrice * stretchScale) / BigInt(100),
},
eip1559fee: null,
};
Expand Down
5 changes: 4 additions & 1 deletion src/base/safewallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export class SafeWallet {
readyExecute ? "ready" : "waiting"
} to execute, tx ${safeTxHash} on chain ${chainId}`
);
const newSignatures = signatureInfo.size >= this.threshold ? signatureInfo.signatures : signatureInfo.signatures + signature.data.substring(2);
const newSignatures =
signatureInfo.size >= this.threshold
? signatureInfo.signatures
: signatureInfo.signatures + signature.data.substring(2);
return {
...propose,
readyExecute: readyExecute,
Expand Down
1 change: 1 addition & 0 deletions src/configure/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class BaseConfigService {
HelixChain.base,
HelixChain.avalanche,
HelixChain.zircuit,
HelixChain.morph,
],
};
testConfigure: BaseConfigure = {
Expand Down
3 changes: 3 additions & 0 deletions src/configure/configure.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export interface TokenInfo {

export interface BridgeInfo {
direction: string;
// specify the provider address on source chain
// if undefined, it's the same as relayer
providerAddress: string | undefined;
encryptedPrivateKey: string;
encryptedCeramicKey: string | undefined;
feeLimit: number;
Expand Down
2 changes: 1 addition & 1 deletion src/dataworker/dataworker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class DataworkerService implements OnModuleInit {
let feeUsed: bigint;
if (gasPrice.isEip1559) {
let maxFeePerGas = new GWei(gasPrice.eip1559fee.maxFeePerGas).mul(
1.00
1.0
).Number;
const maxPriorityFeePerGas = new GWei(
gasPrice.eip1559fee.maxPriorityFeePerGas
Expand Down
28 changes: 19 additions & 9 deletions src/liquidity/lend/aave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ export class AddressBookConfigure {
isNativeWrapped: false,
index: 5,
},
]
}
]
],
},
],
};

aaveTestConfigure: AddressBook = {
Expand Down Expand Up @@ -517,13 +517,15 @@ export class AddressBookConfigure {
const configures = {
formalConfigure: {
aave: this.aaveFormalConfigure,
spark: this.sparkFormalConfigure
spark: this.sparkFormalConfigure,
},
testConfigure: {
aave: this.aaveTestConfigure,
}
},
};
const configure = isTest ? configures.testConfigure : configures.formalConfigure;
const configure = isTest
? configures.testConfigure
: configures.formalConfigure;
return configure[name];
}
}
Expand All @@ -550,7 +552,10 @@ export class Aave extends LendMarket {
tokens: LendTokenInfo[],
signer: EthereumConnectedWallet | EthereumProvider
) {
const addressBook = new AddressBookConfigure().addressBook(isTest, marketName);
const addressBook = new AddressBookConfigure().addressBook(
isTest,
marketName
);
const bookInfo = addressBook?.chains.find((e) => e.name == chainName);
if (!bookInfo) {
throw new Error(`[Lend-${marketName}]Chain ${chainName} Not Support`);
Expand Down Expand Up @@ -630,7 +635,9 @@ export class Aave extends LendMarket {

// https://github.com/aave/aave-v3-core/blob/v1.19.4/contracts/protocol/libraries/types/DataTypes.sol#L65-L67
public isCollateral(userConfig: bigint, token: CollateralToken): boolean {
return Number((userConfig >> BigInt(token.index * 2 + 1)) & BigInt(1)) === 1;
return (
Number((userConfig >> BigInt(token.index * 2 + 1)) & BigInt(1)) === 1
);
}

// suppose the pool is big enough
Expand Down Expand Up @@ -683,7 +690,10 @@ export class Aave extends LendMarket {
}
const userConfigure = await this.poolContract.getUserConfigure(account);
// maybe user deposit this asset but not as collateralToken
const assetCollateralEnabled = this.isCollateral(userConfigure[0], collateralToken);
const assetCollateralEnabled = this.isCollateral(
userConfigure[0],
collateralToken
);

// the deposited asset
const aTokenBalance = await collateralToken.aTokenContract.balanceOf(
Expand Down
Loading

0 comments on commit a658d77

Please sign in to comment.