rubic-sdk
Version:
Simplify dApp creation
96 lines • 4.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RetroBridgeTonTrade = void 0;
const errors_1 = require("../../../../../../common/errors");
const blockchains_info_1 = require("../../../../../../core/blockchain/utils/blockchains-info/blockchains-info");
const ton_web3_pure_1 = require("../../../../../../core/blockchain/web3-pure/typed-web3-pure/ton-web3-pure/ton-web3-pure");
const get_from_without_fee_1 = require("../../../../../common/utils/get-from-without-fee");
const cross_chain_trade_type_1 = require("../../../models/cross-chain-trade-type");
const bridge_type_1 = require("../../common/models/bridge-type");
const ton_cross_chain_trade_1 = require("../../common/ton-cross-chain-trade/ton-cross-chain-trade");
const retro_bridge_api_service_1 = require("../services/retro-bridge-api-service");
class RetroBridgeTonTrade extends ton_cross_chain_trade_1.TonCrossChainTrade {
get fromBlockchain() {
return this.from.blockchain;
}
get fromContractAddress() {
throw new Error('Not implemented');
}
get methodName() {
throw new Error('Not implemented');
}
get chainType() {
return blockchains_info_1.BlockchainsInfo.getChainType(this.fromBlockchain);
}
constructor(crossChainTrade, providerAddress, routePath) {
super(providerAddress, routePath, false);
this.type = cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.RETRO_BRIDGE;
this.isAggregator = false;
this.onChainSubtype = { from: undefined, to: undefined };
this.bridgeType = bridge_type_1.BRIDGE_TYPE.RETRO_BRIDGE;
this.retroBridgeId = '';
this.from = crossChainTrade.from;
this.to = crossChainTrade.to;
this.feeInfo = crossChainTrade.feeInfo;
this.slippage = crossChainTrade.slippage;
this.gasData = crossChainTrade.gasData;
this.priceImpact = crossChainTrade.priceImpact;
this.quoteSendParams = crossChainTrade.quoteSendParams;
this.toTokenAmountMin = this.to.tokenAmount.multipliedBy(1 - crossChainTrade.slippage);
this.hotWalletAddress = crossChainTrade.hotWalletAddress;
this.isSimulation = crossChainTrade.isSimulation ? crossChainTrade.isSimulation : false;
}
async getTransactionConfigAndAmount(_receiverAddress) {
throw new Error('Method is not implemented');
}
getTradeInfo() {
return {
estimatedGas: null,
feeInfo: this.feeInfo,
priceImpact: this.priceImpact,
slippage: this.slippage * 100,
routePath: this.routePath
};
}
async swap(options) {
if (!options?.receiverAddress) {
throw new errors_1.WrongReceiverAddressError();
}
const needAuthWallet = await this.needAuthWallet();
if (needAuthWallet) {
throw new errors_1.RubicSdkError('Need to authorize the wallet via authWallet method');
}
let retroBridgeOrder = {
hot_wallet_address: this.hotWalletAddress,
transaction_id: ''
};
if (!this.isSimulation) {
retroBridgeOrder = await retro_bridge_api_service_1.RetroBridgeApiService.createTransaction({
...this.quoteSendParams,
receiver_wallet: options.receiverAddress,
sender_wallet: this.walletAddress
}, this.chainType);
this.retroBridgeId = retroBridgeOrder.transaction_id;
}
const fromWithoutFee = (0, get_from_without_fee_1.getFromWithoutFee)(this.from, this.feeInfo.rubicProxy?.platformFee?.percent);
return this.web3Private.transferAsset(this.from.address, this.walletAddress, this.hotWalletAddress, fromWithoutFee.stringWeiAmount, options?.onConfirm ? { onTransactionHash: options.onConfirm } : {});
}
getContractParams(_options, _skipAmountChangeCheck) {
throw new Error('Not implemented');
}
async needAuthWallet() {
try {
const addresses = await ton_web3_pure_1.TonWeb3Pure.getAllFormatsOfAddress(this.walletAddress);
const msg = await retro_bridge_api_service_1.RetroBridgeApiService.checkWallet(addresses.raw_form, this.chainType);
return msg.toLowerCase() !== 'success';
}
catch {
return true;
}
}
async authWallet() {
console.error('Wallet should be authenticated on connection stage');
}
}
exports.RetroBridgeTonTrade = RetroBridgeTonTrade;
//# sourceMappingURL=retro-bridge-ton-trade.js.map