forked from chain-bots/opensea-bid-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
120 lines (103 loc) · 3.78 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const OpenSea = require('opensea-js');
const fs = require('fs');
const HDWalletProvider = require("os-wallet-provider");
const config = require('./config.json');
const HttpsProxyAgent = require('https-proxy-agent');
const network = OpenSea.Network.Main;
const DEBUG_LEVEL = 1;
function debug(level, message)
{
var time = new Date();
var f_time = time.getHours().toString().padStart(2,'0') + ":" + time.getMinutes().toString().padStart(2,'0') + ":" + time.getSeconds().toString().padStart(2,'0');
if (DEBUG_LEVEL >= level) { console.log(`[${f_time}] ${message}`); }
}
var proxies = [];
if (config.proxied)
{
const data = fs.readFileSync('proxies.txt', 'utf8');
data.split('\n').forEach(line => {
if (line.length > 3){ proxies.push(`http://${line}`); }
});
debug(2, `loaded ${proxies.length} proxies`)
}
const fetch = global.fetch;
global.fetch = function() {
var url = arguments[0];
var options = arguments[1];
if (config.proxied) {
var proxy = proxies.shift();
proxies.push(proxy);
arguments[1].agent = new HttpsProxyAgent(proxy);
console.log(proxy)
}
debug(3, `opensea-sdk : ${url}`);
return new Promise((resolve, reject) => {
fetch.apply(this, arguments)
.then((response) => {
resolve(response);
})
.catch((error) => {
reject(error);
})
});
}
var providers = [];
var assets = [];
var rpc_index = 0;
config.mnemonics.forEach(mnemonic => {
var provider = new HDWalletProvider({
mnemonic: {
phrase: mnemonic
},
providerOrUrl: config.rpc_urls[rpc_index]
});
var seaport = new OpenSea.OpenSeaPort(provider, {networkName: network});
providers.push({"provider":provider,"seaport":seaport});
seaport.addListener(OpenSea.EventType.CreateOrder, ({ order, accountAddress }) => {
debug(1, `order created ${accountAddress} : ${order.hash} (asset /${order.metadata.asset.id})`);
});
rpc_index++;
if(rpc_index == config.mnemonics.length) {rpc_index = 0;};
})
config.privateKeys.forEach(privateKey => {
var provider = new HDWalletProvider({
privateKeys: [privateKey],
providerOrUrl: config.rpc_urls[rpc_index]
});
var seaport = new OpenSea.OpenSeaPort(provider, {networkName: network});
providers.push({"provider":provider,"seaport":seaport});
seaport.addListener(OpenSea.EventType.CreateOrder, ({ order, accountAddress }) => {
debug(1, `order created ${accountAddress} : ${order.hash} (asset /${order.metadata.asset.id})`);
});
rpc_index++;
if(rpc_index == config.mnemonics.length) {rpc_index = 0;};
})
async function providerThread(_provider)
{
var provider = _provider.provider;
var seaport = _provider.seaport;
var _asset = assets.shift();
if (_asset != undefined) {
const offer = await seaport.createBuyOrder({
asset: {
tokenId:_asset.tokenId,
tokenAddress:_asset.address
},
accountAddress:provider.getAddress(),
startAmount: config.bid_price,
expirationTime:Math.round(Date.now() / 1000 + 60 * 60 * config.expiration)
}).catch(err => {debug(3, 'bidding failed, pushing asset back into array'); assets.push(_asset);});
}
setTimeout(providerThread, config.timeout, _provider);
}
config.targets.forEach(target => {
var current_id = 0;
while (current_id < target.supply){
assets.push({"tokenId":String(current_id),"address":target.address});
current_id++;
}
})
providers.forEach(provider => {
debug(2, `starting provider ${provider.provider.getAddress()}`);
providerThread(provider);
});