@cryptorubic/web3 0.13.0-alpha.solana-gas.6 → 0.13.0-alpha.solana-gas.7
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
|
@@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js';
|
|
|
6
6
|
import { SolanaRawInstruction } from './models/solana-web3-types';
|
|
7
7
|
import { SolanaTxConfig } from '../../utils/models/solana-transaction-config';
|
|
8
8
|
export declare const NATIVE_SOLANA_MINT_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
9
|
-
export declare const DEFAULT_CU_LIMIT =
|
|
9
|
+
export declare const DEFAULT_CU_LIMIT = 400000;
|
|
10
10
|
export declare class SolanaAdapter extends AbstractAdapter<Connection, Connection, SolanaBlockchainName> {
|
|
11
11
|
private readonly httpClient;
|
|
12
12
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger);
|
|
@@ -12,7 +12,8 @@ const js_base64_1 = require("js-base64");
|
|
|
12
12
|
const solana_tokens_service_1 = require("./utils/solana-utils/solana-tokens-service");
|
|
13
13
|
const timeout_1 = require("./utils/timeout");
|
|
14
14
|
exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
|
|
15
|
-
|
|
15
|
+
/* minimal amount for tx (in lamports) */
|
|
16
|
+
exports.DEFAULT_CU_LIMIT = 400_000;
|
|
16
17
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
17
18
|
httpClient;
|
|
18
19
|
constructor(rpcList, httpClient, logger) {
|
|
@@ -58,17 +59,22 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
58
59
|
});
|
|
59
60
|
const resp = await (0, timeout_1.withTimeout)(simulation, timeout, 'Solana Simulation Timeout!');
|
|
60
61
|
const err = resp.value.err;
|
|
62
|
+
const defineCuLimit = () => {
|
|
63
|
+
const cuLimit = resp.value.unitsConsumed || 0;
|
|
64
|
+
const defaultGreaterEstimated = new bignumber_js_1.default(exports.DEFAULT_CU_LIMIT).gt(cuLimit);
|
|
65
|
+
return new bignumber_js_1.default(defaultGreaterEstimated ? exports.DEFAULT_CU_LIMIT : cuLimit).toFixed(0);
|
|
66
|
+
};
|
|
61
67
|
if (err) {
|
|
62
68
|
if (Array.isArray(err['InstructionError'])) {
|
|
63
69
|
const errorsArr = err['InstructionError'];
|
|
64
70
|
const isBalanceError = errorsArr?.[0] === 2 && errorsArr?.[1].Custom === 1;
|
|
65
71
|
// skip balance error cause on max balance swaps it estimates gas roughly and
|
|
66
72
|
if (isBalanceError)
|
|
67
|
-
return
|
|
73
|
+
return defineCuLimit();
|
|
68
74
|
}
|
|
69
75
|
throw new Error('Transaction simulation failed.');
|
|
70
76
|
}
|
|
71
|
-
return
|
|
77
|
+
return defineCuLimit();
|
|
72
78
|
}
|
|
73
79
|
catch (err) {
|
|
74
80
|
this.logger?.customError('Error while simulating transaction', err);
|