-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtransfer.ts
126 lines (105 loc) · 3.18 KB
/
transfer.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {Connection} from "@solana/web3.js";
import * as anchor from "@project-serum/anchor";
import {TokenSwapLayout} from "./token_swap/layouts";
const axios = require("axios");
const fs = require("fs");
const {BN} = require('bn.js');
const {LAMPORTS_PER_SOL} = require("@solana/web3.js");
const tokenMint = "CKfatsPMUf8SkiURsDXs7eK6GWb4Jsd6UDbs7twMCWxo";
// const TOTAL_SEND = 2286.7;
const TOTAL_SEND = 3692;
const MINT_SUPPLY = 1025632817;
const PER_TOKEN = TOTAL_SEND / MINT_SUPPLY;
async function main() {
let holders = await getAllTokenHolders();
const poolHolders = await getTokenPoolAccounts().catch(e => {
console.error(e)
});
let totalRewards = 0;
let totalBern = 0;
let currentHolders = holders.map(holder => {
if (poolHolders[holder.address.toString()]) {
console.log("Holder Address: ", holder.address)
return //Pool address
}
let bernAmount = holder.amount / Math.pow(10, 5);
totalBern += bernAmount;
let solReward = (PER_TOKEN * bernAmount) * LAMPORTS_PER_SOL;
totalRewards += solReward;
return {
...holder,
bernAmount: bernAmount,
perToken: PER_TOKEN,
solReward: solReward,
}
});
let list = {
"wallets": currentHolders
};
console.log(list);
console.log(`holder count: ${currentHolders.length}`);
console.log(`total rewards: ${totalRewards}`);
console.log(`total bern: ${totalBern}`);
let data = JSON.stringify(list, null, 2);
fs.writeFileSync('currentHolders.json', data);
}
async function getAllTokenHolders() {
let page = 0;
let currentHolders = [];
let moreResults = true;
while (moreResults) {
let url = `https://api.fluxbeam.xyz/v1/tokens/${tokenMint}/holders?page=${page}&limit=1000`;
console.log(url);
const resp = await axios.get(`https://api.fluxbeam.xyz/v1/tokens/${tokenMint}/holders?page=${page}&limit=1000`);
// currentHolders = currentHolders.concat(resp.data);
// moreResults = false;
if (resp.data.length === 0) {
moreResults = false;
} else {
currentHolders = currentHolders.concat(resp.data);
page++;
}
}
return currentHolders;
}
async function getTokenPoolAccounts() {
const pools = await getSwapPools(tokenMint)
const pMap = {}
for (let i = 0; i < pools.length; i++) {
pMap[pools[i].account.tokenAccountA.toString()] = true
pMap[pools[i].account.tokenAccountB.toString()] = true
}
return pMap
}
async function getSwapPools(tokenA) {
const SWAP_PROGRAM_ID = new anchor.web3.PublicKey("FLUXubRmkEi2q6K3Y9kBPg9248ggaZVsoSFhtJHSrm1X")
const connection = new Connection("https://rpc.hellomoon.io/f197c876-52d7-4566-bc4c-af4405029777", "confirmed")
const resp = await connection.getProgramAccounts(SWAP_PROGRAM_ID, {
commitment: 'confirmed',
filters: [
{
memcmp: {
offset: 1 + 1 + 1 + 32 + 32 + 32 + 32,
bytes: tokenA.toString(),
},
},
],
})
const respInverse = await connection.getProgramAccounts(SWAP_PROGRAM_ID, {
commitment: 'confirmed',
filters: [
{
memcmp: {
offset: 1 + 1 + 1 + 32 + 32 + 32 + 32 + 32,
bytes: tokenA.toString(),
},
},
],
})
//@ts-ignore
return resp.concat(respInverse).map((m) => {
console.log("Pools", m.pubkey.toString())
return {pubkey: m.pubkey, account: TokenSwapLayout.decode(m.account.data)}
})
}
main();