@cryptorubic/web3 0.13.0-alpha.solana-gas.9 → 0.13.0-alpha.solana-gas.10

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.9",
3
+ "version": "0.13.0-alpha.solana-gas.10",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -16,6 +16,8 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, Connectio
16
16
  multicallByContract<T>(_contracts: MulticallParameters, _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
17
17
  multicallByAddress<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[][], _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
18
18
  simulateTransaction(config: SolanaTxConfig, timeout?: number): Promise<string>;
19
+ private getFailedIxProgramId;
20
+ private getAddressLookupTableAccounts;
19
21
  checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
20
22
  getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
21
23
  /**
@@ -67,7 +67,9 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
67
67
  if (Array.isArray(err['InstructionError'])) {
68
68
  const [failedInstructionIdx, errorData] = err['InstructionError'];
69
69
  const failedIxProgrammId = tx.message.staticAccountKeys[failedInstructionIdx];
70
- this.logger?.customLog('FAILED INSTRUCTION PROGRAM ID', failedIxProgrammId.toBase58());
70
+ const failedInstructionProgramId = await this.getFailedIxProgramId(tx, failedInstructionIdx);
71
+ this.logger?.customLog('FAILED INSTRUCTION PROGRAM ID 1', failedIxProgrammId.toBase58());
72
+ this.logger?.customLog('FAILED INSTRUCTION PROGRAM ID 2', failedInstructionProgramId);
71
73
  const weirdError = errorData?.Custom === 1;
72
74
  if (weirdError)
73
75
  return defineCuLimit();
@@ -81,6 +83,28 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
81
83
  throw err;
82
84
  }
83
85
  }
86
+ async getFailedIxProgramId(tx, failedInstructionIdx) {
87
+ const lutKeys = (tx.message.addressTableLookups ?? []).map((l) => l.accountKey.toBase58());
88
+ const lutAccounts = lutKeys.length ? await this.getAddressLookupTableAccounts(lutKeys) : [];
89
+ const decompiled = web3_js_1.TransactionMessage.decompile(tx.message, { addressLookupTableAccounts: lutAccounts });
90
+ const programId = decompiled.instructions[failedInstructionIdx].programId;
91
+ return programId.toBase58();
92
+ }
93
+ async getAddressLookupTableAccounts(keys) {
94
+ const result = [];
95
+ const infos = await this.public.getMultipleAccountsInfo(keys.map((k) => new web3_js_1.PublicKey(k)));
96
+ keys.forEach((address, i) => {
97
+ const ai = infos[i];
98
+ if (ai) {
99
+ const alt = new web3_js_1.AddressLookupTableAccount({
100
+ key: new web3_js_1.PublicKey(address),
101
+ state: web3_js_1.AddressLookupTableAccount.deserialize(ai.data)
102
+ });
103
+ result.push(alt);
104
+ }
105
+ });
106
+ return result;
107
+ }
84
108
  async checkEnoughBalance(token, walletAddress) {
85
109
  const balance = await this.getBalance(walletAddress, token.address);
86
110
  return balance.gte(token.tokenAmount);