Skip to content

Commit

Permalink
feat: modify setup vault and withdraw to first fetch fee data
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Aug 31, 2024
1 parent b958941 commit c079e13
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "dlc-btc-lib",
"version": "2.2.5",
"version": "2.2.6",
"description": "This library provides a comprehensive set of interfaces and functions for minting dlcBTC tokens on supported blockchains.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
28 changes: 26 additions & 2 deletions src/functions/ethereum/ethereum-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,18 @@ export async function getRawVault(

export async function setupVault(dlcManagerContract: Contract): Promise<any | undefined> {
try {
let transactionOptions = {};
await dlcManagerContract.callStatic.setupVault();
const transaction = await dlcManagerContract.setupVault();
const feeData = await dlcManagerContract.provider.getFeeData();
const { maxPriorityFeePerGas, maxFeePerGas } = feeData;
if (maxPriorityFeePerGas && maxFeePerGas) {
transactionOptions = {
maxPriorityFeePerGas,
maxFeePerGas,
};
}

const transaction = await dlcManagerContract.setupVault(transactionOptions);
return await transaction.wait();
} catch (error) {
throw new EthereumError(`Could not Setup Vault: ${error}`);
Expand All @@ -261,8 +271,22 @@ export async function withdraw(
withdrawAmount: bigint
) {
try {
let transactionOptions = {};
await dlcManagerContract.callStatic.withdraw(vaultUUID, withdrawAmount);
const transaction = await dlcManagerContract.withdraw(vaultUUID, withdrawAmount);
const feeData = await dlcManagerContract.provider.getFeeData();
const { maxPriorityFeePerGas, maxFeePerGas } = feeData;
if (maxPriorityFeePerGas && maxFeePerGas) {
transactionOptions = {
maxPriorityFeePerGas,
maxFeePerGas,
};
}

const transaction = await dlcManagerContract.withdraw(
vaultUUID,
withdrawAmount,
transactionOptions
);
return await transaction.wait();
} catch (error) {
throw new EthereumError(`Could not Withdraw: ${error}`);
Expand Down

0 comments on commit c079e13

Please sign in to comment.