Transaction Data Automation
This module provides functions to automate the generation of transaction data for various token swapping and bridging scenarios across different networks.
Table of Contents
Introduction
This code module facilitates the creation of transaction data required for token swapping and bridging between different networks. It includes functions to construct transaction data for different scenarios, such as direct token swaps and token bridging.
Installation
- Clone this repository to your local environment.
- Make sure you have Node.js and npm installed.
- Install the required packages by running:
npm install axios ethers
Usage
This module exports three main functions:
swapTxnData
async function swapTxnData(fromCoin, toCoin, networkId, fromTokenAmount, address)
This function generates transaction data for a token swap between fromCoin and toCoin on a specified network. It calculates the required parameters and returns a transaction object.
bridgeTxnData
async function bridgeTxnData(fromCoin, toCoin, fromNetworkId, destNetworkId, receiverAddress, fromTokenAmount)
This function constructs transaction data for bridging tokens from fromCoin on fromNetworkId to toCoin on destNetworkId. It creates the necessary transaction parameters for the bridging process and returns a transaction object.
autoDetectTxnData
async function autoDetectTxnData(fromToken, destToken, fromNetworkId, destNetworkId, fromTokenAmount, receiverAddress)
This function automates the transaction data generation process based on different scenarios. It determines whether to perform a direct token swap or a token bridging operation based on the input parameters. The function returns an object containing the appropriate transaction data for the determined scenario.
Token Scheme
Tokens passed into the functions should adhere to the following scheme:
-
name
: The name of the token. -
symbol
: The token symbol. -
address
: The token's contract address. -
graphAddress
: The address of the token on a graph network. -
decimals
: The number of decimals the token uses. -
chainId
: The ID of the blockchain network. -
logoURI
: A URL or string representing the token's logo. -
coinId
: The unique identifier for the token.
Dependencies
This module relies on the following dependencies:
-
axios
: Used for making HTTP requests to external APIs. -
ethers
: A library for interacting with Ethereum and Ethereum-like networks.
Contributing
Contributions are welcome! If you find any issues or want to add new features, feel free to open a pull request.
License
Feel free to copy and paste this Markdown code into your readme.md
file. This code will ensure proper formatting and highlighting of the content.