UNPKG

@broxus/js-bridge-essentials

Version:

Bridge JavaScript Essentials library

84 lines (83 loc) 4.52 kB
import { DEFAULT_NATIVE_CURRENCY_DECIMALS, getFullContractState, resolveTvmAddress, toInt } from '@broxus/js-core'; import { nativeProxyV7Contract } from '../../models/native-proxy/contracts'; export class NativeProxyV7Utils { static async deployTokenFee(provider, proxyAddress, params, args) { return nativeProxyV7Contract(provider, proxyAddress) .methods.deployTokenFee({ _remainingGasTo: resolveTvmAddress(params.remainingGasTo), _token: resolveTvmAddress(params.tokenAddress), }) .sendDelayed({ amount: toInt(6.6, DEFAULT_NATIVE_CURRENCY_DECIMALS), bounce: true, from: resolveTvmAddress(params.remainingGasTo), ...args, }); } static async getExpectedTokenFeeAddress(connection, proxyAddress, tokenAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, proxyAddress); const result = await nativeProxyV7Contract(connection, proxyAddress) .methods.getExpectedTokenFeeAddress({ _token: resolveTvmAddress(tokenAddress), answerId: 0, }) .call({ cachedState: state, responsible: true }); return result.value0; } static async getTvmDefaultFee(connection, proxyAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, proxyAddress); return nativeProxyV7Contract(connection, proxyAddress) .methods.getTvmDefaultFee({ answerId: 0 }) .call({ cachedState: state, responsible: true }); } static async getTvmFees(connection, proxyAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, proxyAddress); const result = await nativeProxyV7Contract(connection, proxyAddress) .methods.getTvmFees({ answerId: 0 }) .call({ cachedState: state, responsible: true }); return new Map(result.value0.flat(0).map(([addr, value]) => [addr.toString(), value])); } static async getTvmTokenFee(connection, proxyAddress, tokenAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, proxyAddress); return nativeProxyV7Contract(connection, proxyAddress) .methods.getTvmTokenFee({ _token: resolveTvmAddress(tokenAddress), answerId: 0, }) .call({ cachedState: state, responsible: true }); } static async getConfiguration(connection, proxyAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, proxyAddress); return nativeProxyV7Contract(connection, proxyAddress) .methods.getConfiguration({ answerId: 0 }) .call({ cachedState: state, responsible: true }); } static async getTvmEvmConfiguration(connection, proxyAddress, cachedState) { const result = await NativeProxyV7Utils.getConfiguration(connection, proxyAddress, cachedState); return result.value0.everscaleConfiguration; } static async getSolTvmConfiguration(connection, proxyAddress, cachedState) { const result = await NativeProxyV7Utils.getConfiguration(connection, proxyAddress, cachedState); return result.value1.solanaConfiguration; } static async getTvmSolConfiguration(connection, proxyAddress, cachedState) { const result = await NativeProxyV7Utils.getConfiguration(connection, proxyAddress, cachedState); return result.value1.everscaleConfiguration; } static async getDexMiddleware(connection, proxyAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, proxyAddress); const result = await nativeProxyV7Contract(connection, proxyAddress) .methods.dex_middleware() .call({ cachedState: state }); return result.dex_middleware; } static decodeEvent(connection, eventConfigurationAddress, args) { return nativeProxyV7Contract(connection, eventConfigurationAddress).decodeEvent(args); } static decodeTransaction(connection, eventConfigurationAddress, args) { return nativeProxyV7Contract(connection, eventConfigurationAddress).decodeTransaction(args); } static decodeTransactionEvents(connection, eventConfigurationAddress, transaction) { return nativeProxyV7Contract(connection, eventConfigurationAddress).decodeTransactionEvents({ transaction }); } }