import { BigNumber } from "bignumber.js"; import { Coin } from "./TransactionHelpers/Coin"; import { Msg } from "./TransactionHelpers/Msg"; import { MsgBeginRedelegate } from "./TransactionHelpers/MsgBeginRedelegate"; import { MsgDelegate } from "./TransactionHelpers/MsgDelegate"; import { MsgSend } from "./TransactionHelpers/MsgSend"; import { MsgUndelegate } from "./TransactionHelpers/MsgUndelegate"; import { MsgWithdrawDelegatorReward } from "./TransactionHelpers/MsgWithdrawDelegatorReward"; import { TxBody } from "./TransactionHelpers/TxBody"; export const buildTransactionBody = (from: string, to: string, amount: string, memo: string) => { //////////// Transaction Body //////////// let amountBN = new BigNumber(amount); amountBN = amountBN.times(new BigNumber(1000000)); //Build amount to send Structure const amountC = new Coin("uatom", amountBN.toFixed()); //Build send message const msgSend = new MsgSend( from, //from to, //to [amountC] //array de amounts ); //Package send message const msgSendAny = new Msg( "/cosmos.bank.v1beta1.MsgSend", msgSend.encode(null).finish() ); //Get transaction body return new TxBody([msgSendAny], memo); }; export const buildDelegateTransactionBody = (from: string, to: string, amount: string, memo: string) => { //////////// Transaction Body //////////// let amountBN = new BigNumber(amount); amountBN = amountBN.times(new BigNumber(1000000)); //Build amount to delegate Structure const amountC = new Coin("uatom", amountBN.toFixed()); //Build delegate message const msgDelegate = new MsgDelegate( from, //delegator_address to, //validator_address amountC //amount ); //Package delegate message const msgDelegateAny = new Msg( "/cosmos.staking.v1beta1.MsgDelegate", msgDelegate.encode(null).finish() ); //Get transaction body return new TxBody([msgDelegateAny], memo); }; export const buildUndelegateTransactionBody = (from: string, to: string, amount: string, memo: string) => { //////////// Transaction Body //////////// let amountBN = new BigNumber(amount); amountBN = amountBN.times(new BigNumber(1000000)); //Build amount to indelegate Structure const amountC = new Coin("uatom", amountBN.toFixed()); //Build undelegate message const msgUndelegate = new MsgUndelegate( from, //delegator_address to, //validator_address amountC //amount ); //Package undelegate message const msgUndelegateAny = new Msg( "/cosmos.staking.v1beta1.MsgUndelegate", msgUndelegate.encode(null).finish() ); //Get transaction body return new TxBody([msgUndelegateAny], memo); }; export const buildBeginRedelegateTransactionBody = (from: string, srcValidator: string, dstValidator: string, amount: string, memo: string) => { //////////// Transaction Body //////////// let amountBN = new BigNumber(amount); amountBN = amountBN.times(new BigNumber(1000000)); //Build amount to redelegate Structure const amountC = new Coin("uatom", amountBN.toFixed()); //Build redelegate message const msgBeginRedelegate = new MsgBeginRedelegate( from, //delegator_address srcValidator, //source_validator_address dstValidator, //destination_validator_address amountC //amount ); //Package redelegate message const msgBeginRedelegateAny = new Msg( "/cosmos.staking.v1beta1.MsgBeginRedelegate", msgBeginRedelegate.encode(null).finish() ); //Get transaction body return new TxBody([msgBeginRedelegateAny], memo); }; export const buildClaimRewardTransactionBody = (from: string, validator: string, memo: string) => { //////////// Transaction Body //////////// //Build withdraw reward message const msgWithdrawDelegatorReward = new MsgWithdrawDelegatorReward( from, //delegator_address validator, //validator_address ); //Package withdraw reward message const msgWithdrawDelegatorRewardAny = new Msg( "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", msgWithdrawDelegatorReward.encode(null).finish() ); //Get transaction body return new TxBody([msgWithdrawDelegatorRewardAny], memo); }; export const buildCompoundRewardTransactionBody = (from: string, validator: string, amount: string, memo: string) => { //////////// Transaction Body //////////// //Build withdraw message const msgWithdrawDelegatorReward = new MsgWithdrawDelegatorReward( from, //delegator_address validator, //validator_address ); //Package withdraw message const msgWithdrawDelegatorRewardAny = new Msg( "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", msgWithdrawDelegatorReward.encode(null).finish() ); let amountBN = new BigNumber(amount); amountBN = amountBN.times(new BigNumber(1000000)); //Build amount to delegate Structure const amountC = new Coin("uatom", amountBN.toFixed()); //Build delegate message const msgDelegate = new MsgDelegate( from, //delegator_address validator, //validator_address amountC //amount ); //Package delegate message const msgDelegateAny = new Msg( "/cosmos.staking.v1beta1.MsgDelegate", msgDelegate.encode(null).finish() ); //Get transaction body return new TxBody([msgWithdrawDelegatorRewardAny, msgDelegateAny], memo); };