UNPKG

@broxus/js-bridge-essentials

Version:

Bridge JavaScript Essentials library

175 lines (174 loc) 9.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EvmTonEventNativeUtils = void 0; const js_core_1 = require("@broxus/js-core"); const contracts_1 = require("../../models/evm-ton-event-native/contracts"); class EvmTonEventNativeUtils { static async approveLimit(provider, eventAddress, args) { return (0, contracts_1.evmTonEventNativeContract)(provider, eventAddress) .methods.approveLimit() .sendDelayed({ bounce: true, ...args }); } static async cancel(provider, eventAddress, params, args) { return (0, contracts_1.evmTonEventNativeContract)(provider, eventAddress) .methods.cancel({ _callback: { payload: params.callback.payload, recipient: params.callback.recipient, strict: params.callback.strict, }, _decimals: params.decimals, _expectedGasReceiver: (0, js_core_1.resolveTvmAddress)(params.expectedGasReceiver), _name: params.name, _newRecipient: params.newRecipient, _remainingGasTo: (0, js_core_1.resolveTvmAddress)(params.remainingGasTo), _symbol: params.symbol, }) .sendDelayed({ bounce: true, ...args }); } static async rejectLimit(provider, eventAddress, expectedGasReceiver, args) { return (0, contracts_1.evmTonEventNativeContract)(provider, eventAddress) .methods.rejectLimit({ _expectedGasReceiver: (0, js_core_1.resolveTvmAddress)(expectedGasReceiver), }) .sendDelayed({ bounce: true, ...args }); } static async retry(provider, eventAddress, args) { return (0, contracts_1.evmTonEventNativeContract)(provider, eventAddress) .methods.retry() .sendDelayed({ bounce: true, ...args }); } static async setBounty(provider, eventAddress, bounty, args) { return (0, contracts_1.evmTonEventNativeContract)(provider, eventAddress) .methods.setBounty({ _bounty: bounty }) .sendDelayed({ bounce: true, ...args }); } static async getDecodedData(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.getDecodedData({ answerId: 0 }) .call({ cachedState: state, responsible: true }); return { amount: result.amount_, expectedGas: result.expectedGas_, payload: result.payload_, proxyAddress: result.proxy_, recipientAddress: result.recipient_, tokenAddress: result.token_, tokenWalletAddress: result.tokenWallet_, value: result.value_, }; } static async getDetails(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.getDetails({ answerId: 0 }) .call({ cachedState: state, responsible: true }); return { balance: result.balance, confirms: result._confirms, empty: result.empty, eventInitData: { chainId: result._eventInitData.chainId, configuration: result._eventInitData.configuration, roundDeployer: result._eventInitData.roundDeployer, voteData: { eventBlock: Number(result._eventInitData.voteData.eventBlock), eventBlockNumber: Number(result._eventInitData.voteData.eventBlockNumber), eventData: result._eventInitData.voteData.eventData, eventIndex: Number(result._eventInitData.voteData.eventIndex), eventTransaction: result._eventInitData.voteData.eventTransaction, }, }, initializer: result._initializer, meta: result._meta, rejects: result._rejects, requiredVotes: Number(result._requiredVotes), status: result._status, }; } static async getEventInitData(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.getEventInitData({ answerId: 0 }) .call({ cachedState: state, responsible: true }); return { chainId: result.value0.chainId, configuration: result.value0.configuration, roundDeployer: result.value0.roundDeployer, voteData: { eventBlock: Number(result.value0.voteData.eventBlock), eventBlockNumber: Number(result.value0.voteData.eventBlockNumber), eventData: result.value0.voteData.eventData, eventIndex: Number(result.value0.voteData.eventIndex), eventTransaction: result.value0.voteData.eventTransaction, }, }; } static async bounty(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.bounty() .call({ cachedState: state }); return result.bounty; } static async eventTokenWallet(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.eventTokenWallet() .call({ cachedState: state }); return result.eventTokenWallet; } static async expectedGas(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.expected_gas() .call({ cachedState: state }); return result.expected_gas; } static async limitApprover(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.limitApprover() .call({ cachedState: state }); return result.limitApprover; } static async nonce(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.nonce() .call({ cachedState: state }); return result.nonce; } static async recipient(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.recipient() .call({ cachedState: state }); return result.recipient; } static async relayRound(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.relay_round() .call({ cachedState: state }); return result.relay_round; } static async roundNumber(connection, eventAddress, cachedState) { const state = cachedState ?? await (0, js_core_1.getFullContractState)(connection, eventAddress); const result = await (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress) .methods.round_number() .call({ cachedState: state }); return Number(result.round_number); } static decodeEvent(connection, eventAddress, args) { return (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress).decodeEvent(args); } static decodeTransaction(connection, eventAddress, args) { return (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress).decodeTransaction(args); } static decodeTransactionEvents(connection, eventAddress, transaction) { return (0, contracts_1.evmTonEventNativeContract)(connection, eventAddress).decodeTransactionEvents({ transaction }); } } exports.EvmTonEventNativeUtils = EvmTonEventNativeUtils;