UNPKG

@broxus/js-core

Version:

MobX-based JavaScript Core library

203 lines (202 loc) 9.14 kB
import { ZeroAddress } from '../../constants'; import { dexGasValuesContract, dexGasValuesV22Contract, legacyDexGasValuesContract, } from '../../models/dex-gas-values/contracts'; import { getFullContractState, resolveTvmAddress } from '../../utils'; export class DexGasValuesUtils { static async getDeployAccountGas(connection, dexGasValuesAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await dexGasValuesContract(connection, dexGasValuesAddress) .methods.getDeployAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await dexGasValuesV22Contract(connection, dexGasValuesAddress) .methods.getDeployAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await legacyDexGasValuesContract(connection, dexGasValuesAddress) .methods.getDeployAccountGas() .call({ cachedState: state }); return result.value0; } static async getDepositToAccountGas(connection, dexGasValuesAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await dexGasValuesContract(connection, dexGasValuesAddress) .methods.getDepositToAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await dexGasValuesV22Contract(connection, dexGasValuesAddress) .methods.getDepositToAccountGas() .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await legacyDexGasValuesContract(connection, dexGasValuesAddress) .methods.getDepositToAccountGas() .call({ cachedState: state }); return result.value0; } static async getAccountWithdrawGas(connection, dexGasValuesAddress, params, cachedState) { const state = cachedState ?? await getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await 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 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 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 getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await dexGasValuesV22Contract(connection, dexGasValuesAddress) .methods.getAccountDepositGas({ autoChange: params.autoChange, N: params.tokenCount, referrer: params.referrerAddress ? resolveTvmAddress(params.referrerAddress) : ZeroAddress, }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 try { const result = await dexGasValuesV22Contract(connection, dexGasValuesAddress) .methods.getAccountDepositGas({ autoChange: params.autoChange, N: params.tokenCount, referrer: params.referrerAddress ? resolveTvmAddress(params.referrerAddress) : ZeroAddress, }) .call({ cachedState: state }); return result.value0; } catch { } // Fallback request for ABI v2.2 (Everscale) const result = await legacyDexGasValuesContract(connection, dexGasValuesAddress) .methods.getAccountDepositGas({ N: params.tokenCount, referrer: params.referrerAddress ? resolveTvmAddress(params.referrerAddress) : 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 getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await 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 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 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 getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await 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 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 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 getFullContractState(connection, dexGasValuesAddress); // Request for ABI v2.7 try { const result = await 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 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 legacyDexGasValuesContract(connection, dexGasValuesAddress) .methods.getPoolDirectNoFeeWithdrawGas({ deployWalletValue: params.deployWalletValue, N: params.tokenCount, }) .call({ cachedState: state }); return result.value0; } }