@oydual31/more-vaults-sdk 1.1.24 → 1.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1308,6 +1308,16 @@ var UnsupportedAssetError = class extends MoreVaultsError {
1308
1308
  }
1309
1309
  };
1310
1310
 
1311
+ // src/common/gasBuffer.ts
1312
+ var DEFAULT_GAS_BUFFER_BPS = 4000n;
1313
+ var BPS_DENOMINATOR = 10000n;
1314
+ var currentDefaultBps = DEFAULT_GAS_BUFFER_BPS;
1315
+ function applyGasBuffer(estimate, bufferBps) {
1316
+ const bps = currentDefaultBps;
1317
+ if (bps < 0n) throw new RangeError(`gas buffer bps must be >= 0, got ${bps}`);
1318
+ return estimate * (BPS_DENOMINATOR + bps) / BPS_DENOMINATOR;
1319
+ }
1320
+
1311
1321
  // src/viem/utils.ts
1312
1322
  async function waitForTx(publicClient, hash, maxRetries = 3) {
1313
1323
  const timeouts = [6e4, 12e4, 18e4];
@@ -2225,7 +2235,7 @@ async function depositAsync(walletClient, publicClient, addresses, assets, recei
2225
2235
  } catch (err) {
2226
2236
  parseContractError(err, vault, account.address);
2227
2237
  }
2228
- const gas = gasEstimate * 130n / 100n;
2238
+ const gas = applyGasBuffer(gasEstimate);
2229
2239
  const txHash = await walletClient.writeContract({
2230
2240
  address: vault,
2231
2241
  abi: BRIDGE_ABI,
@@ -2306,7 +2316,7 @@ async function redeemAsync(walletClient, publicClient, addresses, shares, receiv
2306
2316
  } catch (err) {
2307
2317
  parseContractError(err, vault, account.address);
2308
2318
  }
2309
- const gas = gasEstimate * 130n / 100n;
2319
+ const gas = applyGasBuffer(gasEstimate);
2310
2320
  const txHash = await walletClient.writeContract({
2311
2321
  address: vault,
2312
2322
  abi: BRIDGE_ABI,
@@ -2983,13 +2993,26 @@ async function submitActions(walletClient, publicClient, vault, actions) {
2983
2993
  } catch (err) {
2984
2994
  parseContractError(err, v, account.address);
2985
2995
  }
2996
+ let gasLimit;
2997
+ try {
2998
+ const estimated = await publicClient.estimateContractGas({
2999
+ address: v,
3000
+ abi: MULTICALL_ABI,
3001
+ functionName: "submitActions",
3002
+ args: [actions],
3003
+ account: account.address
3004
+ });
3005
+ gasLimit = applyGasBuffer(estimated);
3006
+ } catch {
3007
+ }
2986
3008
  const txHash = await walletClient.writeContract({
2987
3009
  address: v,
2988
3010
  abi: MULTICALL_ABI,
2989
3011
  functionName: "submitActions",
2990
3012
  args: [actions],
2991
3013
  account,
2992
- chain: walletClient.chain
3014
+ chain: walletClient.chain,
3015
+ gas: gasLimit
2993
3016
  });
2994
3017
  const nextNonce = await publicClient.readContract({
2995
3018
  address: v,
@@ -3013,13 +3036,26 @@ async function executeActions(walletClient, publicClient, vault, nonce) {
3013
3036
  } catch (err) {
3014
3037
  parseContractError(err, v, account.address);
3015
3038
  }
3039
+ let gasLimit;
3040
+ try {
3041
+ const estimated = await publicClient.estimateContractGas({
3042
+ address: v,
3043
+ abi: MULTICALL_ABI,
3044
+ functionName: "executeActions",
3045
+ args: [nonce],
3046
+ account: account.address
3047
+ });
3048
+ gasLimit = applyGasBuffer(estimated);
3049
+ } catch {
3050
+ }
3016
3051
  const txHash = await walletClient.writeContract({
3017
3052
  address: v,
3018
3053
  abi: MULTICALL_ABI,
3019
3054
  functionName: "executeActions",
3020
3055
  args: [nonce],
3021
3056
  account,
3022
- chain: walletClient.chain
3057
+ chain: walletClient.chain,
3058
+ gas: gasLimit
3023
3059
  });
3024
3060
  return { txHash };
3025
3061
  }