Created
August 21, 2024 18:31
-
-
Save staccDOTsol/008839be91edd3e395f5fd52b41cd9b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
import bs58check from "bs58check"; | |
// @ts-ignore | |
import TronWeb from "tronweb"; | |
// Create a cache to store processed transactions | |
const processedTxCache = new Set<string>(); | |
const SUNSWAP_ROUTER_ABI = [ | |
{ | |
inputs: [ | |
{ name: "_factory", type: "address" }, | |
{ name: "_WETH", type: "address" }, | |
{ name: "_owner", type: "address" }, | |
{ name: "_operator", type: "address" }, | |
], | |
stateMutability: "Nonpayable", | |
type: "Constructor", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "WETH", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ name: "acceptOnwer", stateMutability: "Nonpayable", type: "Function" }, | |
{ | |
outputs: [ | |
{ name: "amountA", type: "uint256" }, | |
{ name: "amountB", type: "uint256" }, | |
{ name: "liquidity", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "tokenA", type: "address" }, | |
{ name: "tokenB", type: "address" }, | |
{ name: "amountADesired", type: "uint256" }, | |
{ name: "amountBDesired", type: "uint256" }, | |
{ name: "amountAMin", type: "uint256" }, | |
{ name: "amountBMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "addLiquidity", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "amountToken", type: "uint256" }, | |
{ name: "amountETH", type: "uint256" }, | |
{ name: "liquidity", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "amountTokenDesired", type: "uint256" }, | |
{ name: "amountTokenMin", type: "uint256" }, | |
{ name: "amountETHMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "addLiquidityETH", | |
stateMutability: "Payable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "factory", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amountIn", type: "uint256" }], | |
inputs: [ | |
{ name: "amountOut", type: "uint256" }, | |
{ name: "reserveIn", type: "uint256" }, | |
{ name: "reserveOut", type: "uint256" }, | |
], | |
name: "getAmountIn", | |
stateMutability: "Pure", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amountOut", type: "uint256" }], | |
inputs: [ | |
{ name: "amountIn", type: "uint256" }, | |
{ name: "reserveIn", type: "uint256" }, | |
{ name: "reserveOut", type: "uint256" }, | |
], | |
name: "getAmountOut", | |
stateMutability: "Pure", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountOut", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
], | |
name: "getAmountsIn", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountIn", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
], | |
name: "getAmountsOut", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "pair", type: "address" }], | |
inputs: [ | |
{ name: "tokenA", type: "address" }, | |
{ name: "tokenB", type: "address" }, | |
], | |
name: "getPairOffChain", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "bool" }], | |
name: "getPauseState", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "bool" }], | |
inputs: [ | |
{ name: "tokenA", type: "address" }, | |
{ name: "tokenB", type: "address" }, | |
], | |
name: "isAllowedTradingPair", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "bool" }], | |
inputs: [{ name: "token", type: "address" }], | |
name: "isSunPumpToken", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "launchPad", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "operator", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "owner", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "pathLimit", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "bool" }], | |
name: "pause", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ name: "pauseRouter", stateMutability: "Nonpayable", type: "Function" }, | |
{ | |
outputs: [{ type: "address" }], | |
name: "pendingOwner", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amountB", type: "uint256" }], | |
inputs: [ | |
{ name: "amountA", type: "uint256" }, | |
{ name: "reserveA", type: "uint256" }, | |
{ name: "reserveB", type: "uint256" }, | |
], | |
name: "quote", | |
stateMutability: "Pure", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "_token", type: "address" }], | |
name: "removeAllowedTradeToken", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "amountA", type: "uint256" }, | |
{ name: "amountB", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "tokenA", type: "address" }, | |
{ name: "tokenB", type: "address" }, | |
{ name: "liquidity", type: "uint256" }, | |
{ name: "amountAMin", type: "uint256" }, | |
{ name: "amountBMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "removeLiquidity", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "amountToken", type: "uint256" }, | |
{ name: "amountETH", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "liquidity", type: "uint256" }, | |
{ name: "amountTokenMin", type: "uint256" }, | |
{ name: "amountETHMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "removeLiquidityETH", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amountETH", type: "uint256" }], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "liquidity", type: "uint256" }, | |
{ name: "amountTokenMin", type: "uint256" }, | |
{ name: "amountETHMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "removeLiquidityETHSupportingFeeOnTransferTokens", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "amountToken", type: "uint256" }, | |
{ name: "amountETH", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "liquidity", type: "uint256" }, | |
{ name: "amountTokenMin", type: "uint256" }, | |
{ name: "amountETHMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
{ name: "approveMax", type: "bool" }, | |
{ name: "v", type: "uint8" }, | |
{ name: "r", type: "bytes32" }, | |
{ name: "s", type: "bytes32" }, | |
], | |
name: "removeLiquidityETHWithPermit", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amountETH", type: "uint256" }], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "liquidity", type: "uint256" }, | |
{ name: "amountTokenMin", type: "uint256" }, | |
{ name: "amountETHMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
{ name: "approveMax", type: "bool" }, | |
{ name: "v", type: "uint8" }, | |
{ name: "r", type: "bytes32" }, | |
{ name: "s", type: "bytes32" }, | |
], | |
name: "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "amountA", type: "uint256" }, | |
{ name: "amountB", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "tokenA", type: "address" }, | |
{ name: "tokenB", type: "address" }, | |
{ name: "liquidity", type: "uint256" }, | |
{ name: "amountAMin", type: "uint256" }, | |
{ name: "amountBMin", type: "uint256" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
{ name: "approveMax", type: "bool" }, | |
{ name: "v", type: "uint8" }, | |
{ name: "r", type: "bytes32" }, | |
{ name: "s", type: "bytes32" }, | |
], | |
name: "removeLiquidityWithPermit", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ name: "rerunRouter", stateMutability: "Nonpayable", type: "Function" }, | |
{ | |
inputs: [{ name: "_token", type: "address" }], | |
name: "setAllowedTradeToken", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "_launchpad", type: "address" }], | |
name: "setLaunchPad", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "newOperator", type: "address" }], | |
name: "setOperator", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "_newOwner", type: "address" }], | |
name: "setPendingOwner", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountOut", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapETHForExactTokens", | |
stateMutability: "Payable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountOutMin", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapExactETHForTokens", | |
stateMutability: "Payable", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "amountOutMin", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapExactETHForTokensSupportingFeeOnTransferTokens", | |
stateMutability: "Payable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountIn", type: "uint256" }, | |
{ name: "amountOutMin", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapExactTokensForETH", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "amountIn", type: "uint256" }, | |
{ name: "amountOutMin", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapExactTokensForETHSupportingFeeOnTransferTokens", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountIn", type: "uint256" }, | |
{ name: "amountOutMin", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapExactTokensForTokens", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "amountIn", type: "uint256" }, | |
{ name: "amountOutMin", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapExactTokensForTokensSupportingFeeOnTransferTokens", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountOut", type: "uint256" }, | |
{ name: "amountInMax", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapTokensForExactETH", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "amounts", type: "uint256[]" }], | |
inputs: [ | |
{ name: "amountOut", type: "uint256" }, | |
{ name: "amountInMax", type: "uint256" }, | |
{ name: "path", type: "address[]" }, | |
{ name: "to", type: "address" }, | |
{ name: "deadline", type: "uint256" }, | |
], | |
name: "swapTokensForExactTokens", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "bool" }], | |
inputs: [{ type: "address" }], | |
name: "tokenWhiteList", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ stateMutability: "Payable", type: "Receive" }, | |
]; | |
const TRONGRID_API_KEY = ""; | |
const TRONGRID_URL = "https://api.trongrid.io"; | |
const NEW_CONTRAT_ABI = [ | |
{ | |
inputs: [{ name: "token", type: "address" }], | |
name: "LaunchPending", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "oldLauncher", type: "address" }, | |
{ indexed: true, name: "newLauncher", type: "address" }, | |
], | |
name: "LauncherChanged", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ name: "oldFee", type: "uint256" }, | |
{ name: "newFee", type: "uint256" }, | |
], | |
name: "MinTxFeeSet", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ name: "oldFee", type: "uint256" }, | |
{ name: "newFee", type: "uint256" }, | |
], | |
name: "MintFeeSet", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "oldOperator", type: "address" }, | |
{ indexed: true, name: "newOperator", type: "address" }, | |
], | |
name: "OperatorChanged", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "oldOwner", type: "address" }, | |
{ indexed: true, name: "newOwner", type: "address" }, | |
], | |
name: "OwnerChanged", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "oldPendingOwner", type: "address" }, | |
{ indexed: true, name: "newPendingOwner", type: "address" }, | |
], | |
name: "PendingOwnerSet", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ name: "oldFee", type: "uint256" }, | |
{ name: "newFee", type: "uint256" }, | |
], | |
name: "PurchaseFeeSet", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ name: "oldFee", type: "uint256" }, | |
{ name: "newFee", type: "uint256" }, | |
], | |
name: "SaleFeeSet", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ name: "tokenAddress", type: "address" }, | |
{ name: "tokenIndex", type: "uint256" }, | |
{ name: "creator", type: "address" }, | |
], | |
name: "TokenCreate", | |
type: "Event", | |
}, | |
{ | |
inputs: [{ indexed: true, name: "token", type: "address" }], | |
name: "TokenLaunched", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "token", type: "address" }, | |
{ indexed: true, name: "buyer", type: "address" }, | |
{ name: "trxAmount", type: "uint256" }, | |
{ name: "fee", type: "uint256" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
{ name: "tokenReserve", type: "uint256" }, | |
], | |
name: "TokenPurchased", | |
type: "Event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "token", type: "address" }, | |
{ indexed: true, name: "seller", type: "address" }, | |
{ name: "trxAmount", type: "uint256" }, | |
{ name: "fee", type: "uint256" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
], | |
name: "TokenSold", | |
type: "Event", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "LAUNCH_FEE", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "LAUNCH_THRESHOLD", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "LAUNCH_TRX_RESERVE", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "TOKEN_SUPPLY", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "TOTAL_SALE", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "VIRTUAL_TOKEN_RESERVE_AMOUNT", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "VIRTUAL_TRX_RESERVE_AMOUNT", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "proxy", type: "address" }], | |
name: "_becomeNewImplementation", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ name: "acceptOwner", stateMutability: "Nonpayable", type: "Function" }, | |
{ | |
inputs: [ | |
{ name: "name", type: "string" }, | |
{ name: "symbol", type: "string" }, | |
], | |
name: "createAndInitPurchase", | |
stateMutability: "Payable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "deadAddress", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "trxAmount", type: "uint256" }], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
], | |
name: "getExactTokenAmountForPurchase", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "trxAmount", type: "uint256" }, | |
{ name: "fee", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
], | |
name: "getExactTokenAmountForPurchaseWithFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "tokenAmount", type: "uint256" }], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "trxAmount", type: "uint256" }, | |
], | |
name: "getExactTrxAmountForSale", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "tokenAmount", type: "uint256" }, | |
{ name: "fee", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "trxAmount", type: "uint256" }, | |
], | |
name: "getExactTrxAmountForSaleWithFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
inputs: [{ name: "token", type: "address" }], | |
name: "getPrice", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "tokenAmount", type: "uint256" }], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "trxAmount", type: "uint256" }, | |
], | |
name: "getTokenAmountByPurchase", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "tokenAmount", type: "uint256" }, | |
{ name: "fee", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "trxAmount", type: "uint256" }, | |
], | |
name: "getTokenAmountByPurchaseWithFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
inputs: [{ name: "token", type: "address" }], | |
name: "getTokenState", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ name: "trxAmount", type: "uint256" }], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
], | |
name: "getTrxAmountBySale", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "trxAmount", type: "uint256" }, | |
{ name: "fee", type: "uint256" }, | |
], | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
], | |
name: "getTrxAmountBySaleWithFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "implementation", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "_vault", type: "address" }, | |
{ name: "_v2Router", type: "address" }, | |
{ name: "_salefee", type: "uint256" }, | |
{ name: "_purchasefee", type: "uint256" }, | |
], | |
name: "initialize", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "launchFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "token", type: "address" }], | |
name: "launchToDEX", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "launcher", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "maxPurachaseAmount", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "minTxFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "mintFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "operator", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "owner", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "bool" }], | |
name: "pause", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ name: "pausePad", stateMutability: "Nonpayable", type: "Function" }, | |
{ | |
outputs: [{ type: "address" }], | |
name: "pendingImplementation", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "pendingOwner", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "purchaseFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "AmountMin", type: "uint256" }, | |
], | |
name: "purchaseToken", | |
stateMutability: "Payable", | |
type: "Function", | |
}, | |
{ name: "rerunPad", stateMutability: "Nonpayable", type: "Function" }, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "saleFee", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "token", type: "address" }, | |
{ name: "tokenAmount", type: "uint256" }, | |
{ name: "AmountMin", type: "uint256" }, | |
], | |
name: "saleToken", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "newLauncher", type: "address" }], | |
name: "setLauncher", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "newFee", type: "uint256" }], | |
name: "setMinTxFee", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [ | |
{ name: "_newMintFee", type: "uint256" }, | |
{ name: "_newMinTxFee", type: "uint256" }, | |
], | |
name: "setMintAndMinTxFee", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "newFee", type: "uint256" }], | |
name: "setMintFee", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "newOp", type: "address" }], | |
name: "setOperator", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "newPendingOwner", type: "address" }], | |
name: "setPendingOwner", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "_fee", type: "uint256" }], | |
name: "setPurchaseFee", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "_fee", type: "uint256" }], | |
name: "setSaleFee", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
inputs: [{ name: "_addr", type: "address" }], | |
name: "setVault", | |
stateMutability: "Nonpayable", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
inputs: [{ type: "uint256" }], | |
name: "tokenAddress", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "uint256" }], | |
name: "tokenCount", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
inputs: [{ type: "address" }], | |
name: "tokenCreator", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "v2Router", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [{ type: "address" }], | |
name: "vault", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ | |
outputs: [ | |
{ name: "TRXReserve", type: "uint256" }, | |
{ name: "TokenReserve", type: "uint256" }, | |
{ name: "launched", type: "bool" }, | |
], | |
inputs: [{ type: "address" }], | |
name: "virtualPools", | |
stateMutability: "View", | |
type: "Function", | |
}, | |
{ stateMutability: "Payable", type: "Receive" }, | |
]; | |
const APING_AMOUNT = 10000000; // 100 TRX in SUN (1 TRX = 1,000,000 SUN) | |
const PRIVATE_KEY = | |
""; | |
const tronWeb = new TronWeb({ | |
fullHost: TRONGRID_URL, | |
headers: { "TRON-PRO-API-KEY": TRONGRID_API_KEY }, | |
privateKey: PRIVATE_KEY, | |
}); | |
async function apeIntoNewToken( | |
contractAddress: string, | |
amountIn: number, | |
token: string, | |
) { | |
try { | |
const proxyContractAddress = "TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw"; | |
const contract = await tronWeb.contract( | |
NEW_CONTRAT_ABI, | |
proxyContractAddress, | |
); | |
// Create the transaction | |
let transaction = await contract | |
.purchaseToken( | |
token, | |
0, // AmountMin | |
) | |
.send({ | |
callValue: amountIn, | |
feeLimit: 100000000, | |
}); | |
console.log("Ape transaction created:", transaction); | |
// Add the transaction ID to the cache | |
processedTxCache.add(transaction); | |
return null; | |
} catch (error: any) { | |
console.error("Error aping into new token:", error.toString()); | |
return null; | |
} | |
} | |
const tokenAbi = [ | |
{ | |
inputs: [ | |
{ name: "name", internalType: "string", type: "string" }, | |
{ name: "symbol", internalType: "string", type: "string" }, | |
{ name: "totalSupply", internalType: "uint256", type: "uint256" }, | |
], | |
stateMutability: "nonpayable", | |
type: "constructor", | |
}, | |
{ | |
inputs: [ | |
{ | |
indexed: true, | |
name: "owner", | |
internalType: "address", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
name: "spender", | |
internalType: "address", | |
type: "address", | |
}, | |
{ | |
indexed: false, | |
name: "value", | |
internalType: "uint256", | |
type: "uint256", | |
}, | |
], | |
name: "Approval", | |
anonymous: false, | |
type: "event", | |
}, | |
{ | |
inputs: [ | |
{ | |
indexed: true, | |
name: "previousOwner", | |
internalType: "address", | |
type: "address", | |
}, | |
{ | |
indexed: true, | |
name: "newOwner", | |
internalType: "address", | |
type: "address", | |
}, | |
], | |
name: "OwnershipTransferred", | |
anonymous: false, | |
type: "event", | |
}, | |
{ | |
inputs: [ | |
{ indexed: true, name: "from", internalType: "address", type: "address" }, | |
{ indexed: true, name: "to", internalType: "address", type: "address" }, | |
{ | |
indexed: false, | |
name: "value", | |
internalType: "uint256", | |
type: "uint256", | |
}, | |
], | |
name: "Transfer", | |
anonymous: false, | |
type: "event", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [], | |
name: "MODE_NORMAL", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [], | |
name: "MODE_TRANSFER_CONTROLLED", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [], | |
name: "MODE_TRANSFER_RESTRICTED", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [], | |
name: "_mode", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [ | |
{ name: "owner", internalType: "address", type: "address" }, | |
{ name: "spender", internalType: "address", type: "address" }, | |
], | |
name: "allowance", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "bool", type: "bool" }], | |
inputs: [ | |
{ name: "spender", internalType: "address", type: "address" }, | |
{ name: "amount", internalType: "uint256", type: "uint256" }, | |
], | |
name: "approve", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [{ name: "account", internalType: "address", type: "address" }], | |
name: "balanceOf", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint8", type: "uint8" }], | |
inputs: [], | |
name: "decimals", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "bool", type: "bool" }], | |
inputs: [ | |
{ name: "spender", internalType: "address", type: "address" }, | |
{ name: "subtractedValue", internalType: "uint256", type: "uint256" }, | |
], | |
name: "decreaseAllowance", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "bool", type: "bool" }], | |
inputs: [ | |
{ name: "spender", internalType: "address", type: "address" }, | |
{ name: "addedValue", internalType: "uint256", type: "uint256" }, | |
], | |
name: "increaseAllowance", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "string", type: "string" }], | |
inputs: [], | |
name: "name", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "address", type: "address" }], | |
inputs: [], | |
name: "owner", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [], | |
inputs: [], | |
name: "renounceOwnership", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [], | |
inputs: [{ name: "v", internalType: "uint256", type: "uint256" }], | |
name: "setMode", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "string", type: "string" }], | |
inputs: [], | |
name: "symbol", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "uint256", type: "uint256" }], | |
inputs: [], | |
name: "totalSupply", | |
stateMutability: "view", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "bool", type: "bool" }], | |
inputs: [ | |
{ name: "to", internalType: "address", type: "address" }, | |
{ name: "amount", internalType: "uint256", type: "uint256" }, | |
], | |
name: "transfer", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [{ name: "", internalType: "bool", type: "bool" }], | |
inputs: [ | |
{ name: "from", internalType: "address", type: "address" }, | |
{ name: "to", internalType: "address", type: "address" }, | |
{ name: "amount", internalType: "uint256", type: "uint256" }, | |
], | |
name: "transferFrom", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
{ | |
outputs: [], | |
inputs: [{ name: "newOwner", internalType: "address", type: "address" }], | |
name: "transferOwnership", | |
stateMutability: "nonpayable", | |
type: "function", | |
}, | |
]; | |
async function dumpFromToken( | |
contractAddress: string, | |
tokenAmount: number | string, | |
token: string, | |
): Promise<any> { | |
try { | |
// Check and set allowance if necessary | |
const tokenContract = await tronWeb.contract(tokenAbi, token); | |
const proxyContractAddress = "TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw"; | |
// Set allowance to max uint256 value | |
const maxUint256 = | |
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; | |
const approveFunction = tokenContract.approve( | |
proxyContractAddress, | |
maxUint256, | |
); | |
const transaction = await approveFunction.send({ | |
feeLimit: 100000000, | |
}); | |
console.log("Allowance set for token:", token); | |
// Wait for a short time to ensure the allowance transaction is processed | |
await new Promise((resolve) => setTimeout(resolve, 5000)); | |
const contract = await tronWeb.contract( | |
NEW_CONTRAT_ABI, | |
proxyContractAddress, | |
); | |
// Create the transaction | |
let saleTransaction = await contract | |
.saleToken( | |
token, | |
tokenAmount, | |
0, // AmountMin | |
) | |
.send({ | |
feeLimit: 100000000, | |
}); | |
console.log("Dump transaction created:", saleTransaction); | |
// Add the transaction ID to the cache | |
processedTxCache.add(saleTransaction); | |
return saleTransaction; | |
} catch (error: any) { | |
console.error("Error dumping token:", error.toString()); | |
return null; | |
} | |
} | |
// Modify the existing getEvents function to use the cache | |
async function getEvents(contract: any, limit = 40) { | |
try { | |
const url = `${TRONGRID_URL}/v1/contracts/${contract}/events`; | |
const params = { | |
limit: limit, | |
order_by: "block_timestamp,desc", | |
only_confirmed: true, | |
}; | |
const response = await axios.get(url, { headers, params }); | |
// Filter out already processed transactions | |
const newEvents = response.data.data.filter( | |
(event: any) => !processedTxCache.has(event.transaction_id), | |
); | |
return { ...response.data, data: newEvents }; | |
} catch (error: any) { | |
console.error("Error fetching events:", error.message); | |
return null; | |
} | |
} | |
function hexToBase58CheckAddress(hexAddress: string): string { | |
// Ensure that the hex address starts with '41' | |
if (!hexAddress.startsWith("41")) { | |
throw new Error("Invalid TRON address: Must start with 41"); | |
} | |
// Convert hex to buffer | |
const addressBuffer = Buffer.from(hexAddress, "hex"); | |
// Convert to Base58Check format | |
return bs58check.encode(addressBuffer); | |
} | |
// Add the following new function: | |
async function getContractTokens(contractAddress: string) { | |
try { | |
const url = `${TRONGRID_URL}/v1/contracts/${contractAddress}/tokens`; | |
const response = await axios.get(url, { headers }); | |
return response.data; | |
} catch (error: any) { | |
console.error("Error fetching contract tokens:", error.message); | |
return null; | |
} | |
} | |
const headers = { | |
Accept: "application/json", | |
"TRON-PRO-API-KEY": TRONGRID_API_KEY, | |
}; | |
let lastProcessedTimestamp = 0; | |
const newTokenContracts = new Set(["TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw"]); | |
async function getTransactionInfo(txId: any) { | |
try { | |
const url = `${TRONGRID_URL}/wallet/gettransactioninfobyid`; | |
const response = await axios.post(url, { value: txId }, { headers }); | |
return response.data; | |
} catch (error: any) { | |
console.error("Error fetching transaction info:", error.message); | |
return null; | |
} | |
} | |
const winners: any = {}; | |
async function getTokenBalance(tokenAddress: string, walletAddress: string) { | |
try { | |
const contract = await tronWeb.contract().at(tokenAddress); | |
const balance = await contract.balanceOf(walletAddress).call(); | |
return tronWeb.toBigNumber(balance); | |
} catch (error: any) { | |
console.error("Error getting token balance:", error.toString()); | |
return null; | |
} | |
} | |
async function processEvents(events: any, contract: any) { | |
for (const event of events) { | |
try { | |
if (event.event_name === "Approval" && !event._unconfirmed) { | |
processedTxCache.add(event.transaction_id); | |
const approver = hexToBase58CheckAddress( | |
"41" + event.result.owner.slice(2), | |
); | |
if (winners[contract] && winners[contract] === approver) { | |
console.log(`Approval event from winner for token ${contract}:`); | |
console.log(`Approver: ${approver}`); | |
console.log( | |
`Spender: ${hexToBase58CheckAddress("41" + event.result.spender.slice(2))}`, | |
); | |
const routerAddress = "TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB"; // Replace with the actual router address | |
const newTokenAddress = hexToBase58CheckAddress( | |
"41" + event.result.spender.slice(2), | |
); | |
const to = "TY4DodArM8GnRdBQc5nnLGjsorZQHMyD1L"; // Replace with your wallet address | |
const balance = await getTokenBalance(newTokenAddress, to); | |
if (balance && !balance.isZero()) { | |
console.log(`Token balance: ${balance.toString()}`); | |
const contractTokens = await getContractTokens(newTokenAddress); | |
if ( | |
contractTokens && | |
contractTokens.data && | |
contractTokens.data.length > 0 | |
) { | |
let largestTokenBalance = 0; | |
let largestWinner = ""; | |
for (const token of contractTokens.data) { | |
const tokenBalance = Number(Object.values(token)[0]); | |
if (tokenBalance > largestTokenBalance / 10 ** 18) { | |
largestTokenBalance = tokenBalance / 10 ** 18; | |
largestWinner = Object.keys(token)[0]; | |
winners[newTokenAddress] = largestWinner; | |
} | |
} | |
console.log( | |
"Largest Token Balance:", | |
largestTokenBalance.toString(), | |
largestWinner, | |
); | |
} | |
const sellDeadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from now | |
dumpFromToken(newTokenAddress, balance, newTokenAddress); | |
} | |
} | |
} | |
if (event.event_name === "TokenCreate" && !event._unconfirmed) { | |
processedTxCache.add(event.transaction_id); | |
const txInfo = await getTransactionInfo(event.transaction_id); | |
if ( | |
txInfo && | |
txInfo.log && | |
txInfo.log.length > 0 && | |
!newTokenContracts.has( | |
hexToBase58CheckAddress("41" + txInfo.log[0].address), | |
) | |
) { | |
// ... existing code for new token creation ... | |
const tokenCreateLog = txInfo.log.find( | |
(log: any) => | |
log.topics && | |
log.topics[0] === | |
"1ff0a01c8968e3551472812164f233abb579247de887db8cbb18281c149bee7a", | |
); | |
if (tokenCreateLog) { | |
const newTokenAddress = hexToBase58CheckAddress( | |
"41" + tokenCreateLog.data.slice(24, 64), | |
); | |
console.log("New Token Created:", newTokenAddress); | |
console.log("New Token Created:", newTokenAddress); | |
const routerAddress = "TZFs5ch1R1C4mmjwrrmZqeqbUgGpxY1yWB"; // Router address | |
const wethAddress = "891cdb91d149f23b1a45d9c5ca78a88d0cb44c18"; // WETH address | |
const path = [ | |
hexToBase58CheckAddress("41" + wethAddress), | |
newTokenAddress, | |
]; | |
console.log(path); | |
newTokenContracts.add(newTokenAddress); | |
const to = "TY4DodArM8GnRdBQc5nnLGjsorZQHMyD1L"; // Your wallet address | |
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from now | |
apeIntoNewToken( | |
"TQHj5QZA8PaHBcAGkYdi8QxdtuNabuVx5r", | |
APING_AMOUNT, | |
newTokenAddress, | |
); | |
} | |
} | |
} | |
} catch (error: any) { | |
console.error("Error processing events:", error.message); | |
const eventsData = await getEvents(contract); | |
setTimeout(() => { | |
if (eventsData && eventsData.data && eventsData.data.length > 0) { | |
processEvents(eventsData.data, contract).catch(console.error); | |
} | |
}, 5000); // Retry after 5 seconds | |
} | |
} | |
} | |
async function monitorEvents() { | |
async function getAllTokens(address: string) { | |
try { | |
const url = `${TRONGRID_URL}/v1/accounts/${address}`; | |
const response = await axios.get(url, { headers }); | |
if ( | |
response.data && | |
response.data.data && | |
response.data.data[0] && | |
response.data.data[0].trc20 | |
) { | |
return response.data.data[0].trc20; | |
} else { | |
console.log("No TRC20 tokens found for the address"); | |
return []; | |
} | |
} catch (error: any) { | |
console.error("Error fetching tokens:", error.message); | |
return []; | |
} | |
} | |
async function dumpAllTokens(address: string) { | |
const tokens = await getAllTokens(address); | |
for (const t of tokens) { | |
const balanes = Object.values(t); | |
console.log(balanes); | |
const tokenADdresses = Object.keys(t); | |
console.log(tokenADdresses); | |
for (const i in balanes) { | |
const tokenAddress = tokenADdresses[i]; | |
const balance = balanes[i]; | |
console.log(tokenAddress, balance); | |
const tokenBalance = balance; | |
console.log(`Dumping token: ${tokenAddress}, Balance: ${tokenBalance}`); | |
try { | |
await dumpFromToken( | |
tokenAddress, | |
tokenBalance as string, | |
tokenAddress, | |
); | |
console.log(`Successfully dumped token: ${tokenAddress}`); | |
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for 1 second | |
} catch (error) { | |
console.error(`Error dumping token ${tokenAddress}:`, error); | |
} | |
} | |
} | |
} | |
// Dump all tokens for the specified address | |
await dumpAllTokens("TY4DodArM8GnRdBQc5nnLGjsorZQHMyD1L"); | |
while (true) { | |
for (const contract of newTokenContracts.values()) { | |
const eventsData = await getEvents(contract); | |
if (eventsData && eventsData.data && eventsData.data.length > 0) { | |
await processEvents(eventsData.data, contract); | |
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for 1 second before next iteration | |
} | |
} | |
} | |
} | |
monitorEvents().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment