Created
August 14, 2024 11:15
-
-
Save gevffy/50a744cbc7144d3f100f5188e3f9032c to your computer and use it in GitHub Desktop.
auto-bid-infpass
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
/** | |
* project link https://www.influpia.com/passauction | |
* system requirements: nodejs >= 18, ehters.js | |
* npm install [email protected] | |
* node passauction.mjs | |
*/ | |
import { ethers } from 'ethers' | |
const provider = new ethers.WebSocketProvider('wss://ws.bitlayer-rpc.com', { | |
chainId: 200901, | |
name: 'Bitlayer Mainnet' | |
}) | |
class Wallet { | |
makerAddress = '0x078061d35b03913e8fb8e506c456adc9db728603' | |
makerABI = ['error AddressEmptyCode(address target)', 'error AddressInsufficientBalance(address account)', 'error ERC1967InvalidImplementation(address implementation)', 'error ERC1967NonPayable()', 'error FailedInnerCall()', 'error InvalidInitialization()', 'error NotInitializing()', 'error OwnableInvalidOwner(address owner)', 'error OwnableUnauthorizedAccount(address account)', 'error SafeERC20FailedOperation(address token)', 'error UNAUTHORIZED()', 'error UUPSUnauthorizedCallContext()', 'error UUPSUnsupportedProxiableUUID(bytes32 slot)', 'event BidPlaced(address indexed user, uint256 round, uint256 amount)', 'event Initialized(uint64 version)', 'event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)', 'event Upgraded(address indexed implementation)', 'function UPGRADE_INTERFACE_VERSION() view returns (string)', 'function auctions(uint256 round) view returns (uint256 firstWinTime, uint256 winGapTime, uint256 limitGapTime, address winner, uint256 bidPrice, uint256 winTime)', 'function currentRound() view returns (uint256)', 'function expectingWinTime() view returns (uint256)', 'function floorPrice() view returns (uint256)', 'function getBidPrice() view returns (uint256 price)', 'function getImplementation() view returns (address)', 'function influpiaToken() view returns (address)', 'function initialize(address influpiaToken_, address treasury_, uint256 floorPrice_)', 'function makeBid() payable', 'function operator() view returns (address)', 'function owner() view returns (address)', 'function proxiableUUID() view returns (bytes32)', 'function renounceOwnership()', 'function setOperator(address addr)', 'function startAuction(uint256 firstEndingGap, uint256 winGapTime, uint256 limitGapTime)', 'function startingTime() view returns (uint256)', 'function transferOwnership(address newOwner)', 'function treasury() view returns (address)', 'function upgradeToAndCall(address newImplementation, bytes data) payable', 'function withdrawTreasury()'] | |
wallet = null | |
contractMaker = null | |
status = 'done' | |
MIN_PRICE = null | |
MAX_PRICE = null | |
constructor(privateKey, minPrice, maxPrice) { | |
try { | |
this.wallet = new ethers.Wallet(privateKey, provider) | |
} catch (e) { | |
throw new Error('Invalid private key.') | |
} | |
this.contractMaker = new ethers.Contract(this.makerAddress, this.makerABI, this.wallet) | |
if (maxPrice) { | |
this.MAX_PRICE = maxPrice | |
} | |
if (minPrice) { | |
this.MIN_PRICE = minPrice | |
} | |
this.listen() | |
} | |
listen() { | |
this.contractMaker.on(this.contractMaker.filters.BidPlaced, (user, round, amount) => { | |
// not self | |
console.log(user, round, amount) | |
if (user.toLocaleLowerCase() !== this.wallet.address.toLocaleLowerCase() && this.status === 'done') { | |
this.makeBid() | |
} | |
}) | |
} | |
async getBalance() { | |
return provider.getBalance(this.wallet) | |
} | |
async makeBid() { | |
const balance = ethers.formatEther(await provider.getBalance(this.wallet)) | |
const bidPrice = await this.contractMaker.getBidPrice() | |
const bidPriceParse = ethers.formatEther(bidPrice) | |
console.log(`wallet balance: ${balance} BTC, bid price: ${bidPrice} BTC`) | |
if (bidPriceParse <= balance) { | |
console.log('skip, balance not enough') | |
return false | |
} | |
if ((this.MAX_PRICE && bidPriceParse > this.MAX_PRICE) || (this.MIN_PRICE && bidPriceParse < this.MIN_PRICE)) { | |
console.log('skip, bid price not in range') | |
return false | |
} | |
const tx = { | |
to: this.makerAddress, | |
value: bidPrice, | |
data: this.contractMaker.interface.encodeFunctionData('makeBid', []) | |
} | |
console.log('transaction data', tx) | |
try { | |
this.status = 'pending' | |
const receipt = await this.wallet.sendTransaction(tx) | |
const res = await receipt.wait() | |
this.status = 'done' | |
console.log(receipt) | |
return res | |
} catch (error) { | |
this.status = 'done' | |
if (error.code === 'INSUFFICIENT_FUNDS') { | |
console.error('Error: insufficient funds') | |
} else { | |
console.error('Error:', error.shortMessage) | |
} | |
} | |
return false | |
} | |
} | |
async function start() { | |
// 1. change YOUR_WALLET_PRIVATE_KEY to your wallet private key | |
// 2. change 0.0007 to your min price, 0.02 to your max price | |
const ins = new Wallet('YOUR_WALLET_PRIVATE_KEY', 0.0007, 0.02) | |
let lastRound = 0 | |
console.log(`address: ${ins.wallet.address} balance: ${ethers.formatEther(await ins.getBalance())}`) | |
setInterval(async () => { | |
const round = await ins.contractMaker.currentRound() | |
if (round > lastRound) { | |
console.log(`new round: ${round}`) | |
lastRound = round | |
} | |
}, 1500) | |
} | |
start() | |
process.stdin.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment