forked from fengli08/script_galxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
97 lines (90 loc) · 3.27 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
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
/**
* Galex - A tool for galex campaign action
*
* Author @3lang3 2023-06-21
* Github: https://github.com/3lang3
*/
import fs from 'fs/promises';
import { ethers } from "ethers";
import { cli } from "./utils/cli";
import { Galex } from "./module";
import cfg from "./config";
import { loop } from "./utils/utils";
import { claimPassport } from './claim';
// 领取任务积分
const claim = async (wallet: ethers.Wallet) => {
await loop(async () => {
const account = new Galex({ privateKey: wallet.privateKey });
const r = await account.getPrepareParticipate({
campaignID: cfg.campaignId,
chain: 'ETHEREUM',
});
if (r.prepareParticipate?.disallowReason) {
console.log(`领取失败: ${r.prepareParticipate?.disallowReason}`);
return;
}
if (r.prepareParticipate?.loyaltyPointsTxResp?.TotalClaimedPoints) {
console.log(`成功领取 ${r.prepareParticipate?.loyaltyPointsTxResp?.TotalClaimedPoints} 分`);
}
})
};
// 获取widget containerId
function containerId() {
return "persona-widget-" + new Array(16).fill(void 0).map((function () {
return Math.floor(35 * Math.random()).toString(35)
}
)).join("")
}
// 获取widget url
const getPassportUrl = async (wallet: ethers.Wallet) => {
let data = '';
await loop(async () => {
const account = new Galex({ privateKey: wallet.privateKey });
const signature = await wallet.signMessage(`get_or_create_address_inquiry:${wallet.address.toLocaleLowerCase()}`)
const { getOrCreateInquiryByAddress } = await account.getOrCreateInquiryByAddress({ signature });
if (getOrCreateInquiryByAddress.status === 'Approved') {
data = 'Approved';
return;
}
const { sessionToken, inquiryID } = getOrCreateInquiryByAddress.personaInquiry
if (!sessionToken) throw Error('sessionToken is null, retry')
data = `https://withpersona.com/widget?client-version=4.7.1&container-id=${containerId()}&flow-type=embedded&environment=production&iframe-origin=https%3A%2F%2Fgalxe.com&inquiry-id=${inquiryID}&session-token=${sessionToken}`
})
// 将url存入 urls.txt 文件
await fs.appendFile('urls.txt', `[${wallet.address}] ${data}\n`);
}
cli(async ({ action, pks, startIdx, endIdx }) => {
for (let k = startIdx; k <= endIdx; k++) {
const pk = pks[k];
const wallet = new ethers.Wallet(pk);
try {
if (action === 'claim') {
if (!cfg.campaignId || !cfg.w) {
console.error(
"❌ 请在config.ts中配置对应参数",
);
process.exit(1);
}
console.log(`[${action}] ${wallet.address} 开始执行claim`)
await claim(wallet);
console.log(`[${action}] ${wallet.address} claim执行完毕`)
}
if (action === 'passport') {
console.log(`[${action}] ${wallet.address} 开始获取passport url`)
await getPassportUrl(wallet);
console.log(`[${action}] ${wallet.address} passport url获取完毕`)
}
if (action === 'claimp') {
if (!cfg.passportPwd || !cfg.w) {
console.error(
"❌ 请在config.ts中配置passportPwd和w参数",
);
process.exit(1);
}
await claimPassport(wallet, cfg.passportPwd);
}
} catch (error) {
console.log(error?.reason || error?.message)
}
}
});