Skip to content

Commit

Permalink
bridge lib add relayer functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed Oct 13, 2023
1 parent 8cc127b commit 72d2b98
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/apps/src/bridges/lnbridge-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,57 @@ export class LnBridgeDefault extends LnBridgeBase {
return this.publicClient.waitForTransactionReceipt({ hash });
}
}

async depositMargin(margin: bigint) {
if ((await this.publicClient?.getChainId()) !== this.targetChain?.id) {
throw new Error("Wrong network");
}

if (
this.contract &&
this.sourceChain &&
this.sourceToken &&
this.targetToken &&
this.publicClient &&
this.walletClient
) {
const abi = (await import(`../abi/lnbridgev20-default.json`)).default;

const hash = await this.walletClient.writeContract({
address: this.contract.targetAddress,
abi,
functionName: "depositProviderMargin",
args: [BigInt(this.sourceChain.id), this.sourceToken.address, this.targetToken.address, margin],
value: this.sourceToken.type === "native" ? margin : undefined,
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
}
}

async setFeeAndRate(baseFee: bigint, feeRate: number) {
if ((await this.publicClient?.getChainId()) !== this.sourceChain?.id) {
throw new Error("Wrong network");
}

if (
this.contract &&
this.targetChain &&
this.sourceToken &&
this.targetToken &&
this.publicClient &&
this.walletClient
) {
const abi = (await import(`../abi/lnbridgev20-default.json`)).default;

const hash = await this.walletClient.writeContract({
address: this.contract.sourceAddress,
abi,
functionName: "setProviderFee",
args: [BigInt(this.targetChain.id), this.sourceToken.address, this.targetToken.address, baseFee, feeRate],
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
}
}
}
34 changes: 34 additions & 0 deletions packages/apps/src/bridges/lnbridge-opposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,38 @@ export class LnBridgeOpposite extends LnBridgeBase {
return this.publicClient.waitForTransactionReceipt({ hash });
}
}

async updateFeeAndMargin(margin: bigint, baseFee: bigint, feeRate: number) {
if ((await this.publicClient?.getChainId()) !== this.sourceChain?.id) {
throw new Error("Wrong network");
}

if (
this.contract &&
this.targetChain &&
this.sourceToken &&
this.targetToken &&
this.publicClient &&
this.walletClient
) {
const abi = (await import(`../abi/lnbridgev20-opposite.json`)).default;

const hash = await this.walletClient.writeContract({
address: this.contract.sourceAddress,
abi,
functionName: "updateProviderFeeAndMargin",
args: [
BigInt(this.targetChain.id),
this.sourceToken.address,
this.targetToken.address,
margin,
baseFee,
feeRate,
],
value: this.sourceToken.type === "native" ? margin : undefined,
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
}
}
}

0 comments on commit 72d2b98

Please sign in to comment.