@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
79 lines (78 loc) • 4.22 kB
JavaScript
import { getFullContractState, resolveTvmAddress } from '@broxus/js-core';
import { tonNativeProxyV3Contract } from '../../models/ton-native-proxy/contracts';
export class TonNativeProxyV3Utils {
static async getExpectedTokenFeeAddress(connection, proxyAddress, tokenAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, proxyAddress);
const result = await tonNativeProxyV3Contract(connection, proxyAddress)
.methods.getExpectedTokenFeeAddress({
_token: resolveTvmAddress(tokenAddress),
answerId: 0,
})
.call({ cachedState: state, responsible: true });
return result.value0;
}
static async getDailyLimits(connection, proxyAddress, tokenAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, proxyAddress);
const result = await tonNativeProxyV3Contract(connection, proxyAddress)
.methods.getDailyLimits({
_token: resolveTvmAddress(tokenAddress),
answerId: 0,
})
.call({ cachedState: state, responsible: true });
return {
dailyIncomingVolume: result.value0.dailyIncomingVolume,
dailyOutgoingVolume: result.value0.dailyOutgoingVolume,
dayStartTimestamp: Number(result.value0.dayStartTimestamp),
incomingLimit: result.value0.incomingLimit,
outgoingLimit: result.value0.outgoingLimit,
};
}
static async getTvmDefaultFee(connection, proxyAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, proxyAddress);
return tonNativeProxyV3Contract(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 tonNativeProxyV3Contract(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 tonNativeProxyV3Contract(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 tonNativeProxyV3Contract(connection, proxyAddress)
.methods.getConfiguration({ answerId: 0 })
.call({ cachedState: state, responsible: true });
}
static async getTonEvmConfiguration(connection, proxyAddress, cachedState) {
const result = await TonNativeProxyV3Utils.getConfiguration(connection, proxyAddress, cachedState);
return result.value0.tvmConfiguration;
}
static async getDexMiddleware(connection, proxyAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, proxyAddress);
const result = await tonNativeProxyV3Contract(connection, proxyAddress)
.methods.dex_middleware()
.call({ cachedState: state });
return result.dex_middleware;
}
static decodeEvent(connection, proxyAddress, args) {
return tonNativeProxyV3Contract(connection, proxyAddress).decodeEvent(args);
}
static decodeTransaction(connection, proxyAddress, args) {
return tonNativeProxyV3Contract(connection, proxyAddress).decodeTransaction(args);
}
static decodeTransactionEvents(connection, proxyAddress, transaction) {
return tonNativeProxyV3Contract(connection, proxyAddress).decodeTransactionEvents({ transaction });
}
}