import { types } from '@binance-chain/javascript-sdk'; import Big from 'big.js'; import { BBC_BASE_DECIMAL } from '../constants'; import { prepareForBbc } from '../send/prepareForBbc'; import { BbcSdk } from '../send/prepareForBbc/bbcSdk'; import { INetwork, ISideChainId } from '../types'; export interface IPrepareToUndelegate { network: INetwork; address: string; validatorAddress: string; amount: string; sideChainId: ISideChainId; } export const prepareToUndelegate = async (data: IPrepareToUndelegate) => { const { network, amount, sideChainId } = data; const symbol = 'BNB'; const bbc = new BbcSdk({ network }); const fee = await (await bbc.getGasPrice()).undelegate; const message = new types.BscUndelegateMsg({ delegator_addr: data.address, validator_addr: data.validatorAddress, amount: { denom: symbol, amount: Number(new Big(amount).mul(BBC_BASE_DECIMAL).toFixed()), }, side_chain_id: sideChainId, }); return await prepareForBbc({ from: data.address, to: '', fee, network, value: amount, message, asset: { networkSymbol: symbol, decimals: 18, }, }); };