@cryptorubic/web3 0.13.0-alpha.solana-gas.4 → 0.13.0-alpha.solana-gas.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "0.13.0-alpha.solana-gas.4",
3
+ "version": "0.13.0-alpha.solana-gas.6",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -49,14 +49,23 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
49
49
  const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
50
50
  tx.message.recentBlockhash = blockhash;
51
51
  const simulation = this.public.simulateTransaction(tx, {
52
- replaceRecentBlockhash: false,
52
+ replaceRecentBlockhash: true,
53
+ commitment: 'confirmed',
53
54
  accounts: {
54
55
  encoding: 'base64',
55
56
  addresses: [config.walletAddress]
56
57
  }
57
58
  });
58
59
  const resp = await (0, timeout_1.withTimeout)(simulation, timeout, 'Solana Simulation Timeout!');
59
- if (resp.value.err) {
60
+ const err = resp.value.err;
61
+ if (err) {
62
+ if (Array.isArray(err['InstructionError'])) {
63
+ const errorsArr = err['InstructionError'];
64
+ const isBalanceError = errorsArr?.[0] === 2 && errorsArr?.[1].Custom === 1;
65
+ // skip balance error cause on max balance swaps it estimates gas roughly and
66
+ if (isBalanceError)
67
+ return new bignumber_js_1.default(resp.value.unitsConsumed || exports.DEFAULT_CU_LIMIT).toFixed(0);
68
+ }
60
69
  throw new Error('Transaction simulation failed.');
61
70
  }
62
71
  return new bignumber_js_1.default(resp.value.unitsConsumed || exports.DEFAULT_CU_LIMIT).toFixed(0);