-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.ts
69 lines (61 loc) · 1.77 KB
/
index.ts
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
/**
* LINEA WEEK 9!
*
* Author @3lang3 2023-07-6
* Github: https://github.com/3lang3
*/
import { ethers } from "ethers";
import { cli } from "./utils/cli";
import { Galex } from "./module";
import cfg from "./config";
import { loop, task } from "./utils/utils";
import * as snapshot from "./tasks/snapshot";
import * as twitter from "./tasks/twitter";
import fse from 'fs-extra';
// 领取任务积分
const claim = async (wallet: ethers.Wallet) => {
await task('claim', wallet, async () => {
await loop(async () => {
const account = new Galex({ privateKey: wallet.privateKey });
const r = await account.getPrepareParticipate({
campaignID: cfg.campaignId,
chain: 'ETHEREUM',
});
if (r.prepareParticipate?.disallowReason) {
throw Error(`领取失败: ${r.prepareParticipate?.disallowReason}`);
}
if (r.prepareParticipate?.loyaltyPointsTxResp?.TotalClaimedPoints) {
console.log(`[${wallet.address}]成功领取 ${r.prepareParticipate?.loyaltyPointsTxResp?.TotalClaimedPoints} 分`);
}
})
}, {
force: true
})
};
cli(async ({ action, pks, startIdx, endIdx }) => {
if (!cfg.campaignId || !cfg.w) {
console.error(
"❌ 请在config.ts中配置对应参数",
);
process.exit(1);
}
// 确保根目录有cache文件夹
fse.ensureDirSync('./cache');
for (let k = startIdx; k <= endIdx; k++) {
const pk = pks[k];
const wallet = new ethers.Wallet(pk);
try {
if (action === 'claim') {
await claim(wallet);
}
if (action === 'vote') {
await snapshot.vote(wallet);
}
if (action === 'retweet') {
await twitter.retweet(wallet);
}
} catch (error) {
console.log(error?.reason || error?.message)
}
}
});