-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92de717
commit 7b9b235
Showing
6 changed files
with
251 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { LnBridge } from "./ln-bridge"; | ||
export { LnBridge } from "./lnbridge"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Address, Hash, encodeFunctionData, TransactionReceipt } from "viem"; | ||
import { Chain } from "viem"; | ||
import { ConstructorOptions, LnBridge, RelayInfo } from "./lnbridge"; | ||
import { HelixProtocolName } from "@helixbridge/helixconf"; | ||
|
||
export class LnBridgeV2 extends LnBridge { | ||
constructor( | ||
fromChain: Chain, | ||
toChain: Chain, | ||
fromToken: Address, | ||
toToken: Address, | ||
protocol: HelixProtocolName, | ||
options?: ConstructorOptions, | ||
) { | ||
super(fromChain, toChain, fromToken, toToken, protocol, options); | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
transfer(amount: bigint, recipient: Address, totalFee: bigint, relayInfo: RelayInfo): Promise<TransactionReceipt> { | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
async getLayerZeroWithdrawFee() { | ||
const [sendService] = await this.sourcePublicClient.readContract({ | ||
address: this.sourceBridgeContract, | ||
abi: (await import(`./abi/lnv2-default`)).default, | ||
functionName: "messagers", | ||
args: [BigInt(this.targetChain.id)], | ||
}); | ||
const [value] = await this.getLayerZeroFee(sendService, this.targetChain, this.sourcePublicClient); | ||
return { value, token: this.sourceNativeToken }; | ||
} | ||
|
||
async getMsgportWithdrawFee(args: { | ||
transferId: Hash; | ||
withdrawNonce: string; | ||
relayer: Address; | ||
refundAddress: Address; | ||
amount: bigint; | ||
}) { | ||
const message = encodeFunctionData({ | ||
abi: (await import(`./abi/lnv2-default`)).default, | ||
functionName: "withdraw", | ||
args: [ | ||
BigInt(this.sourceChain.id), | ||
args.transferId, | ||
BigInt(args.withdrawNonce), | ||
args.relayer, | ||
this.sourceToken.address, | ||
this.targetToken.address, | ||
args.amount, | ||
], | ||
}); | ||
const feeAndParams = await this.getMsgportFeeAndParams( | ||
message, | ||
args.refundAddress, | ||
this.sourceChain, | ||
this.targetChain, | ||
this.sourceBridgeContract, | ||
this.targetBridgeContract, | ||
this.sourceToken, | ||
this.targetToken, | ||
); | ||
return feeAndParams ? { value: feeAndParams.fee, token: this.sourceNativeToken } : undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.