@broxus/js-core
Version:
MobX-based JavaScript Core library
71 lines (70 loc) • 3.73 kB
JavaScript
import { ZeroAddress } from '../../constants';
import { dexGasValuesContract } 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);
const result = await dexGasValuesContract(connection, dexGasValuesAddress)
.methods.getDeployAccountGas()
.call({ cachedState: state });
return result.value0;
}
static async getDepositToAccountGas(connection, dexGasValuesAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, dexGasValuesAddress);
const result = await dexGasValuesContract(connection, dexGasValuesAddress)
.methods.getDepositToAccountGas()
.call({ cachedState: state });
return result.value0;
}
static async getAccountWithdrawGas(connection, dexGasValuesAddress, params, cachedState) {
const state = cachedState ?? await getFullContractState(connection, dexGasValuesAddress);
const result = await dexGasValuesContract(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);
const result = await dexGasValuesContract(connection, dexGasValuesAddress)
.methods.getAccountDepositGas({
autoChange: params.autoChange,
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);
const result = await dexGasValuesContract(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);
const result = await dexGasValuesContract(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);
const result = await dexGasValuesContract(connection, dexGasValuesAddress)
.methods.getPoolDirectNoFeeWithdrawGas({
deployWalletValue: params.deployWalletValue,
N: params.tokenCount,
})
.call({ cachedState: state });
return result.value0;
}
}