UNPKG

@broxus/js-core

Version:

MobX-based JavaScript Core library

207 lines (206 loc) 9.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DexGasValuesUtils = void 0; const constants_1 = require("../../constants"); const contracts_1 = require("../../models/dex-gas-values/contracts"); const utils_1 = require("../../utils"); class DexGasValuesUtils { static async getDeployAccountGas(connection, dexGasValuesAddress, cachedState) { const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesContract)(connection, dexGasValuesAddress) .methods.getDeployAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getDeployAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getDeployAccountGas() .call({ cachedState: state }); return result.value0; } static async getDepositToAccountGas(connection, dexGasValuesAddress, cachedState) { const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesContract)(connection, dexGasValuesAddress) .methods.getDepositToAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getDepositToAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getDepositToAccountGas() .call({ cachedState: state }); return result.value0; } static async getAccountWithdrawGas(connection, dexGasValuesAddress, params, cachedState) { const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesContract)(connection, dexGasValuesAddress) .methods.getAccountWithdrawGas({ deployWalletValue: params.deployWalletValue }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getAccountWithdrawGas({ deployWalletValue: params.deployWalletValue }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getAccountWithdrawGas({ deployWalletValue: params.deployWalletValue }) .call({ cachedState: state }); return result.value0; } static async getAccountDepositGas(connection, dexGasValuesAddress, params, cachedState) { const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getAccountDepositGas({ autoChange: params.autoChange, N: params.tokenCount, referrer: params.referrerAddress ? (0, utils_1.resolveTvmAddress)(params.referrerAddress) : constants_1.ZeroAddress, }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getAccountDepositGas({ autoChange: params.autoChange, N: params.tokenCount, referrer: params.referrerAddress ? (0, utils_1.resolveTvmAddress)(params.referrerAddress) : constants_1.ZeroAddress, }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getAccountDepositGas({ N: params.tokenCount, referrer: params.referrerAddress ? (0, utils_1.resolveTvmAddress)(params.referrerAddress) : constants_1.ZeroAddress, }) .call({ cachedState: state }); return result.value0; } static async getAddPoolGas(connection, dexGasValuesAddress, params, cachedState) { if (params.tokenCount < 2) { throw new Error('Tokens count can`t be lower than 2'); } const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesContract)(connection, dexGasValuesAddress) .methods.getAddPoolGas({ N: params.tokenCount }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getAddPoolGas({ N: params.tokenCount }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getAddPoolGas({ N: params.tokenCount }) .call({ cachedState: state }); return result.value0; } static async getDeployPoolGas(connection, dexGasValuesAddress, params, cachedState) { if (params.tokenCount < 2) { throw new Error('Tokens count can`t be lower than 2'); } const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesContract)(connection, dexGasValuesAddress) .methods.getDeployPoolGas({ N: params.tokenCount }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getDeployPoolGas({ N: params.tokenCount }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getDeployPoolGas({ N: params.tokenCount }) .call({ cachedState: state }); return result.value0; } static async getPoolDirectNoFeeWithdrawGas(connection, dexGasValuesAddress, params, cachedState) { if (params.tokenCount < 2) { throw new Error('Tokens count can`t be lower than 2'); } const state = cachedState ?? await (0, utils_1.getFullContractState)(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await (0, contracts_1.dexGasValuesContract)(connection, dexGasValuesAddress) .methods.getPoolDirectNoFeeWithdrawGas({ deployWalletValue: params.deployWalletValue, N: params.tokenCount, }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await (0, contracts_1.dexGasValuesV22Contract)(connection, dexGasValuesAddress) .methods.getPoolDirectNoFeeWithdrawGas({ deployWalletValue: params.deployWalletValue, N: params.tokenCount, }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await (0, contracts_1.legacyDexGasValuesContract)(connection, dexGasValuesAddress) .methods.getPoolDirectNoFeeWithdrawGas({ deployWalletValue: params.deployWalletValue, N: params.tokenCount, }) .call({ cachedState: state }); return result.value0; } } exports.DexGasValuesUtils = DexGasValuesUtils;