-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.js
More file actions
51 lines (44 loc) · 1.38 KB
/
bot.js
File metadata and controls
51 lines (44 loc) · 1.38 KB
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
import 'dotenv/config'
import { setTimeout } from 'node:timers/promises'
import { discoverSushiswapRouter } from '../lib/swap.js'
import { initializeConfig, ensureApproval } from '../lib/config.js'
import { processAuctions } from '../lib/auction.js'
const config = await initializeConfig(process.env)
const sushiswapRouterAddress = await discoverSushiswapRouter({
chainId: config.chainId,
tokenIn: config.usdfcAddress,
sender: config.account.address,
})
if (!sushiswapRouterAddress && config.chainId === 314) {
console.error(
'Error: Could not discover Sushiswap router address on Filecoin mainnet.',
)
process.exit(1)
}
if (sushiswapRouterAddress) {
await ensureApproval({
publicClient: config.publicClient,
walletClient: config.walletClient,
account: config.account,
tokenAddress: config.usdfcAddress,
spenderAddress: /** @type {import('viem').Address} */ (
sushiswapRouterAddress
),
})
}
console.log()
console.log('Starting auction monitoring...')
console.log()
while (true) {
console.log(`Starting auction check...`)
try {
await processAuctions({ ...config, sushiswapRouterAddress })
} catch (error) {
const err = /** @type {Error} */ (error)
console.log()
console.error(`Error during auction check: ${err.message}`)
}
console.log(`Waiting ${config.delay}ms until next check...`)
console.log()
await setTimeout(config.delay)
}