rubic-sdk
Version:
Simplify dApp creation
76 lines • 3.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrbiterTronBridgeTrade = void 0;
const tron_web3_pure_1 = require("../../../../../../core/blockchain/web3-pure/typed-web3-pure/tron-web3-pure/tron-web3-pure");
const cross_chain_trade_type_1 = require("../../../models/cross-chain-trade-type");
const bridge_type_1 = require("../../common/models/bridge-type");
const tron_cross_chain_trade_1 = require("../../common/tron-cross-chain-trade/tron-cross-chain-trade");
const orbiter_router_v3_abi_1 = require("../constants/orbiter-router-v3-abi");
const orbiter_contract_addresses_1 = require("../models/orbiter-contract-addresses");
const orbiter_utils_1 = require("../services/orbiter-utils");
class OrbiterTronBridgeTrade extends tron_cross_chain_trade_1.TronCrossChainTrade {
get fromBlockchain() {
return this.from.blockchain;
}
get fromContractAddress() {
return orbiter_contract_addresses_1.orbiterContractAddresses[this.fromBlockchain];
}
get methodName() {
throw new Error('Not implemented');
}
constructor(params) {
super(params.providerAddress, params.routePath, params.useProxy);
/**ABSTRACT PROPS */
this.type = cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.ORBITER_BRIDGE;
this.isAggregator = false;
this.onChainSubtype = { from: undefined, to: undefined };
this.bridgeType = bridge_type_1.BRIDGE_TYPE.ORBITER_BRIDGE;
this.to = params.crossChainTrade.to;
this.from = params.crossChainTrade.from;
this.toTokenAmountMin = params.crossChainTrade.toTokenAmountMin;
this.feeInfo = params.crossChainTrade.feeInfo;
this.gasData = params.crossChainTrade.gasData;
this.priceImpact = params.crossChainTrade.priceImpact;
this.quoteConfig = params.crossChainTrade.quoteConfig;
}
async getContractParams(_options) {
throw new Error('Not implemented');
}
async getTransactionConfigAndAmount(receiverAddress) {
// Orbiter deposit address to send funds money to receiverWalletAddress after transfer confirmation
const orbiterTokensDispenser = this.quoteConfig.endpoint;
// const transferAmount = this.from.stringWeiAmount;
const transferAmount = orbiter_utils_1.OrbiterUtils.getFromAmountWithoutFeeWithCode(this.from, this.feeInfo, this.quoteConfig);
const encodedReceiverAndCode = orbiter_utils_1.OrbiterUtils.getHexDataArg(this.quoteConfig.vc, receiverAddress || this.walletAddress);
const methodName = this.from.isNative ? 'transfer' : 'transferToken';
const methodArgs = this.from.isNative
? [
{ type: 'address', value: orbiterTokensDispenser },
{ type: 'bytes', value: encodedReceiverAndCode }
]
: [
{ type: 'address', value: this.from.address },
{ type: 'address', value: orbiterTokensDispenser },
{ type: 'uint256', value: transferAmount },
{ type: 'bytes', value: encodedReceiverAndCode }
];
// this.from.address, orbiterTokensDispenser, transferAmount, encodedReceiverAndCode
const value = this.from.isNative ? transferAmount : '0';
const config = tron_web3_pure_1.TronWeb3Pure.encodeMethodCall(orbiter_contract_addresses_1.orbiterContractAddresses[this.fromBlockchain], orbiter_router_v3_abi_1.ORBITER_ROUTER_V3_ABI, methodName, methodArgs, Number(value));
return {
config,
amount: this.to.stringWeiAmount
};
}
getTradeInfo() {
return {
estimatedGas: null,
feeInfo: this.feeInfo,
priceImpact: this.priceImpact,
slippage: 0,
routePath: this.routePath
};
}
}
exports.OrbiterTronBridgeTrade = OrbiterTronBridgeTrade;
//# sourceMappingURL=orbiter-tron-bridge-trade.js.map