@helium/helium-admin-cli 0.9.19 → 0.9.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,39 +83,65 @@ function run(args = process.argv) {
83
83
  const instructions = [];
84
84
  const delegations = yield hsdProgram.account.delegatedPositionV0.all();
85
85
  const needsMigration = delegations.filter(d => d.account.expirationTs.isZero());
86
- const positionKeys = needsMigration.map(d => d.account.position);
87
- const coder = hsdProgram.coder.accounts;
86
+ const positionKeys = needsMigration.map((d) => d.account.position);
87
+ const coder = vsrProgram.coder.accounts;
88
88
  const positionAccs = (yield getMultipleAccounts({
89
89
  connection: provider.connection,
90
90
  keys: positionKeys,
91
- })).map(a => coder.decode("positionV0", a.data));
91
+ })).map((a) => a ? coder.decode("PositionV0", a.data) : null);
92
92
  const currTs = yield getSolanaUnixTimestamp(provider);
93
93
  const currTsBN = new anchor.BN(currTs.toString());
94
- const proxyEndTs = (_a = proxyConfig.seasons.find(s => currTsBN.gt(s.start))) === null || _a === void 0 ? void 0 : _a.end;
95
- for (const [delegation, position] of zip(needsMigration, positionAccs)) {
96
- const subDao = delegation.account.subDao;
97
- instructions.push(yield hsdProgram.methods
98
- .addExpirationTs()
99
- .accountsStrict({
100
- payer: wallet.publicKey,
101
- position: delegation.account.position,
102
- delegatedPosition: delegation.publicKey,
103
- registrar: registrarK,
104
- dao,
105
- subDao: delegation.account.subDao,
106
- oldClosingTimeSubDaoEpochInfo: (0, helium_sub_daos_sdk_1.subDaoEpochInfoKey)(subDao, position.lockup.endTs)[0],
107
- closingTimeSubDaoEpochInfo: (0, helium_sub_daos_sdk_1.subDaoEpochInfoKey)(subDao, (0, bn_js_1.min)(position.lockup.endTs, proxyEndTs))[0],
108
- genesisEndSubDaoEpochInfo: (0, helium_sub_daos_sdk_1.subDaoEpochInfoKey)(subDao, position.genesisEnd)[0],
109
- proxyConfig: registrar.proxyConfig,
110
- systemProgram: web3_js_1.SystemProgram.programId,
111
- })
112
- .instruction());
94
+ const proxyEndTs = (_a = proxyConfig.seasons
95
+ .reverse()
96
+ .find((s) => currTsBN.gte(s.start))) === null || _a === void 0 ? void 0 : _a.end;
97
+ console.log(`Processing ${needsMigration.length} delegations`);
98
+ // Process in batches of 10
99
+ const batchSize = 10;
100
+ for (let i = 0; i < needsMigration.length; i += batchSize) {
101
+ // Log progress every 100 positions
102
+ if (i > 0 && i % 100 === 0) {
103
+ console.log(`Processed ${i} delegations`);
104
+ }
105
+ const batch = needsMigration.slice(i, i + batchSize);
106
+ const batchPositions = positionAccs.slice(i, i + batchSize);
107
+ yield Promise.all(batch.map((delegation, j) => __awaiter(this, void 0, void 0, function* () {
108
+ const position = batchPositions[j];
109
+ if (!position) {
110
+ console.log(`Position not found for ${delegation.account.position.toBase58()}`);
111
+ return;
112
+ }
113
+ const subDao = delegation.account.subDao;
114
+ const positionTokenAccount = (yield provider.connection.getTokenLargestAccounts(position.mint)).value[0].address;
115
+ instructions.push(yield hsdProgram.methods
116
+ .extendExpirationTsV0()
117
+ .accountsStrict({
118
+ payer: wallet.publicKey,
119
+ position: delegation.account.position,
120
+ delegatedPosition: delegation.publicKey,
121
+ registrar: registrarK,
122
+ mint: position.mint,
123
+ authority: wallet.publicKey,
124
+ positionTokenAccount,
125
+ dao,
126
+ subDao: delegation.account.subDao,
127
+ oldClosingTimeSubDaoEpochInfo: (0, helium_sub_daos_sdk_1.subDaoEpochInfoKey)(subDao, delegation.account.expirationTs.isZero()
128
+ ? position.lockup.endTs
129
+ : (0, bn_js_1.min)(position.lockup.endTs, delegation.account.expirationTs))[0],
130
+ closingTimeSubDaoEpochInfo: (0, helium_sub_daos_sdk_1.subDaoEpochInfoKey)(subDao, (0, bn_js_1.min)(position.lockup.endTs, proxyEndTs))[0],
131
+ genesisEndSubDaoEpochInfo: (0, helium_sub_daos_sdk_1.subDaoEpochInfoKey)(subDao, position.genesisEnd.lt(currTsBN) ?
132
+ (0, bn_js_1.min)(position.lockup.endTs, proxyEndTs) : position.genesisEnd)[0],
133
+ proxyConfig: registrar.proxyConfig,
134
+ systemProgram: web3_js_1.SystemProgram.programId,
135
+ })
136
+ .instruction());
137
+ })));
113
138
  }
114
- yield (0, spl_utils_1.batchParallelInstructionsWithPriorityFee)(provider, instructions, {
115
- onProgress: (status) => {
116
- console.log(status);
117
- },
139
+ console.log(`Finished processing ${needsMigration.length} delegations`);
140
+ const transactions = yield (0, spl_utils_1.batchInstructionsToTxsWithPriorityFee)(provider, instructions, {
141
+ useFirstEstimateForAll: true,
142
+ computeUnitLimit: 400000,
118
143
  });
144
+ yield (0, spl_utils_1.bulkSendTransactions)(provider, transactions, console.log, 10, [], 100);
119
145
  });
120
146
  }
121
147
  exports.run = run;
@@ -1 +1 @@
1
- {"version":3,"file":"add-expiration-to-delegations.js","sourceRoot":"","sources":["../../src/add-expiration-to-delegations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4C;AAC5C,qEAA0F;AAC1F,yDAA0D;AAC1D,iDAAuF;AACvF,+EAAmE;AACnE,6CAAqH;AACrH,iCAA4B;AAC5B,4CAAoB;AACpB,wDAAgC;AAChC,mCAAsC;AAEtC,SAAsB,GAAG,CAAC,OAAY,OAAO,CAAC,IAAI;;;QAChD,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC,OAAO,CAAC;YAC/B,MAAM,EAAE;gBACN,KAAK,EAAE,GAAG;gBACV,QAAQ,EAAE,uBAAuB;gBACjC,OAAO,EAAE,GAAG,YAAE,CAAC,OAAO,EAAE,yBAAyB;aAClD;YACD,GAAG,EAAE;gBACH,KAAK,EAAE,GAAG;gBACV,OAAO,EAAE,uBAAuB;gBAChC,QAAQ,EAAE,gBAAgB;aAC3B;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,mCAAmC;gBAC7C,OAAO,EAAE,oBAAQ,CAAC,QAAQ,EAAE;aAC7B;SACF,CA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AC,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACnD,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA"}
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.run = void 0;
39
+ const aws_sdk_1 = __importDefault(require("aws-sdk"));
40
+ const fs_1 = __importDefault(require("fs"));
41
+ const pg = __importStar(require("pg"));
42
+ const sequelize_1 = require("sequelize");
43
+ const yargs_1 = __importDefault(require("yargs/yargs"));
44
+ function run(args = process.argv) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const yarg = (0, yargs_1.default)(args).options({
47
+ outputPath: {
48
+ type: "string",
49
+ describe: "The path to the output file",
50
+ default: "vote-markers.json",
51
+ },
52
+ pgUser: {
53
+ default: "postgres",
54
+ },
55
+ pgPassword: {
56
+ type: "string",
57
+ },
58
+ pgDatabase: {
59
+ type: "string",
60
+ },
61
+ pgHost: {
62
+ default: "localhost",
63
+ },
64
+ pgPort: {
65
+ default: "5432",
66
+ },
67
+ awsRegion: {
68
+ default: "us-east-1",
69
+ },
70
+ noSsl: {
71
+ type: "boolean",
72
+ default: false,
73
+ },
74
+ voteMarkerJson: {
75
+ type: "string",
76
+ describe: "The path to the vote marker json file",
77
+ required: true,
78
+ },
79
+ });
80
+ const argv = yield yarg.argv;
81
+ const voteMarkers = JSON.parse(fs_1.default.readFileSync(argv.voteMarkerJson, "utf8"));
82
+ const host = argv.pgHost;
83
+ const port = Number(argv.pgPort);
84
+ const database = new sequelize_1.Sequelize({
85
+ host,
86
+ dialect: "postgres",
87
+ port,
88
+ logging: false,
89
+ dialectModule: pg,
90
+ username: argv.pgUser,
91
+ database: argv.pgDatabase,
92
+ pool: {
93
+ max: 10,
94
+ min: 5,
95
+ acquire: 60000,
96
+ idle: 10000,
97
+ validate: (client) => {
98
+ try {
99
+ client.query("SELECT 1");
100
+ return true;
101
+ }
102
+ catch (err) {
103
+ return false;
104
+ }
105
+ },
106
+ },
107
+ hooks: {
108
+ beforeConnect: (config) => __awaiter(this, void 0, void 0, function* () {
109
+ const isRds = host.includes("rds.amazonaws.com");
110
+ let password = argv.pgPassword;
111
+ if (isRds && !password) {
112
+ const signer = new aws_sdk_1.default.RDS.Signer({
113
+ region: process.env.AWS_REGION,
114
+ hostname: process.env.PGHOST,
115
+ port,
116
+ username: process.env.PGUSER,
117
+ });
118
+ password = yield new Promise((resolve, reject) => signer.getAuthToken({}, (err, token) => {
119
+ if (err) {
120
+ return reject(err);
121
+ }
122
+ resolve(token);
123
+ }));
124
+ config.dialectOptions = {
125
+ ssl: {
126
+ require: false,
127
+ rejectUnauthorized: false,
128
+ },
129
+ };
130
+ }
131
+ config.password = password;
132
+ }),
133
+ },
134
+ });
135
+ class VoteMarker extends sequelize_1.Model {
136
+ }
137
+ VoteMarker.init({
138
+ address: {
139
+ type: sequelize_1.STRING,
140
+ primaryKey: true,
141
+ },
142
+ voter: {
143
+ type: sequelize_1.STRING,
144
+ primaryKey: true,
145
+ },
146
+ registrar: {
147
+ type: sequelize_1.STRING,
148
+ primaryKey: true,
149
+ },
150
+ proposal: {
151
+ type: sequelize_1.STRING,
152
+ primaryKey: true,
153
+ },
154
+ mint: {
155
+ type: sequelize_1.STRING,
156
+ primaryKey: true,
157
+ },
158
+ choices: {
159
+ type: (0, sequelize_1.ARRAY)(sequelize_1.INTEGER),
160
+ },
161
+ weight: {
162
+ type: sequelize_1.DECIMAL.UNSIGNED,
163
+ },
164
+ bumpSeed: {
165
+ type: sequelize_1.INTEGER,
166
+ },
167
+ deprecatedRelinquished: {
168
+ type: sequelize_1.BOOLEAN,
169
+ },
170
+ proxyIndex: {
171
+ type: sequelize_1.INTEGER,
172
+ },
173
+ rentRefund: {
174
+ type: sequelize_1.STRING,
175
+ },
176
+ }, {
177
+ sequelize: database,
178
+ modelName: "vote_marker",
179
+ tableName: "vote_markers",
180
+ underscored: true,
181
+ updatedAt: false,
182
+ });
183
+ yield VoteMarker.bulkCreate(voteMarkers, {
184
+ ignoreDuplicates: true, // ON CONFLICT DO NOTHING
185
+ });
186
+ });
187
+ }
188
+ exports.run = run;
189
+ //# sourceMappingURL=backfill-vote-markers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backfill-vote-markers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;SAClD,CAAC,CAAC;IACL,CAAC;CAAA;AAnKD,kBAmKC"}
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.run = void 0;
39
+ const anchor = __importStar(require("@coral-xyz/anchor"));
40
+ const organization_sdk_1 = require("@helium/organization-sdk");
41
+ const proposal_sdk_1 = require("@helium/proposal-sdk");
42
+ const voter_stake_registry_sdk_1 = require("@helium/voter-stake-registry-sdk");
43
+ const web3_js_1 = require("@solana/web3.js");
44
+ const bs58_1 = __importDefault(require("bs58"));
45
+ const os_1 = __importDefault(require("os"));
46
+ const yargs_1 = __importDefault(require("yargs/yargs"));
47
+ const utils_1 = require("./utils");
48
+ function run(args = process.argv) {
49
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const yarg = (0, yargs_1.default)(args).options({
52
+ wallet: {
53
+ alias: "k",
54
+ describe: "Anchor wallet keypair",
55
+ default: `${os_1.default.homedir()}/.config/solana/id.json`,
56
+ },
57
+ url: {
58
+ alias: "u",
59
+ default: "http://127.0.0.1:8899",
60
+ describe: "The solana url",
61
+ },
62
+ outputPath: {
63
+ type: "string",
64
+ describe: "The path to the output file",
65
+ default: "vote-markers.json",
66
+ },
67
+ });
68
+ const argv = yield yarg.argv;
69
+ process.env.ANCHOR_WALLET = argv.wallet;
70
+ process.env.ANCHOR_PROVIDER_URL = argv.url;
71
+ anchor.setProvider(anchor.AnchorProvider.local(argv.url));
72
+ const provider = anchor.getProvider();
73
+ const wallet = new anchor.Wallet((0, utils_1.loadKeypair)(argv.wallet));
74
+ const hvsrProgram = yield (0, voter_stake_registry_sdk_1.init)(provider);
75
+ const proposalProgram = yield (0, proposal_sdk_1.init)(provider);
76
+ let myOrgs = new Set([
77
+ (0, organization_sdk_1.organizationKey)("Helium")[0],
78
+ (0, organization_sdk_1.organizationKey)("Helium MOBILE")[0],
79
+ (0, organization_sdk_1.organizationKey)("Helium IOT")[0],
80
+ ].map(k => k.toBase58()));
81
+ const proposals = (yield proposalProgram.account.proposalV0.all()).filter(p => myOrgs.has(p.account.namespace.toBase58()));
82
+ // Track votes in a map: proposalKey -> voter marker id --> VoteMarkerV0
83
+ const votesByProposal = new Map();
84
+ for (const proposal of proposals) {
85
+ votesByProposal.set(proposal.publicKey.toBase58(), new Map());
86
+ }
87
+ // Add position cache
88
+ const positionCache = new Map();
89
+ for (const proposal of proposals) {
90
+ console.log(`Getting vote markers for ${proposal.publicKey.toBase58()}`);
91
+ let signatures = [];
92
+ let lastSig = undefined;
93
+ // // Keep fetching until we get all signatures
94
+ while (true) {
95
+ const sigs = yield provider.connection.getSignaturesForAddress(proposal.publicKey, { before: lastSig, limit: 1000 }, "confirmed");
96
+ if (sigs.length === 0)
97
+ break;
98
+ signatures.push(...sigs);
99
+ lastSig = sigs[sigs.length - 1].signature;
100
+ // If we got less than 1000, we've hit the end
101
+ if (sigs.length < 1000)
102
+ break;
103
+ }
104
+ console.log("signatures", signatures.length);
105
+ const hvsrCoder = new anchor.BorshInstructionCoder(hvsrProgram.idl);
106
+ const proposalCoder = new anchor.BorshInstructionCoder(proposalProgram.idl);
107
+ // Process signatures in chunks of 100
108
+ const chunkSize = 100;
109
+ signatures = signatures.reverse();
110
+ for (let i = 0; i < signatures.length; i += chunkSize) {
111
+ const chunk = signatures.slice(i, i + chunkSize);
112
+ const txs = yield provider.connection.getTransactions(chunk.map(sig => sig.signature), { maxSupportedTransactionVersion: 0, commitment: "confirmed" });
113
+ for (const tx of txs) {
114
+ if (!(tx === null || tx === void 0 ? void 0 : tx.meta) || tx.meta.err)
115
+ continue;
116
+ let message = tx.transaction.message;
117
+ let index = -1;
118
+ for (const ix of message.compiledInstructions) {
119
+ index++;
120
+ try {
121
+ // Check if instruction is from VSR program
122
+ if (message.staticAccountKeys[ix.programIdIndex].toBase58() !== hvsrProgram.programId.toBase58())
123
+ continue;
124
+ let decoded = hvsrCoder.decode(Buffer.from(ix.data));
125
+ if (!decoded)
126
+ continue;
127
+ let formatted = hvsrCoder.format(decoded, ix.accountKeyIndexes.map(i => {
128
+ return {
129
+ pubkey: message.staticAccountKeys[i] || web3_js_1.PublicKey.default,
130
+ isSigner: false,
131
+ isWritable: false,
132
+ };
133
+ }));
134
+ if (!formatted)
135
+ continue;
136
+ // Handle vote instruction
137
+ if (decoded.name === "voteV0") {
138
+ const voter = (_a = formatted.accounts.find((acc) => acc.name === "Voter")) === null || _a === void 0 ? void 0 : _a.pubkey;
139
+ const registrar = (_b = formatted.accounts.find((acc) => acc.name === "Registrar")) === null || _b === void 0 ? void 0 : _b.pubkey;
140
+ const mint = (_c = formatted.accounts.find((acc) => acc.name === "Mint")) === null || _c === void 0 ? void 0 : _c.pubkey;
141
+ const proposal = (_d = formatted.accounts.find((acc) => acc.name === "Proposal")) === null || _d === void 0 ? void 0 : _d.pubkey;
142
+ const marker = (_e = formatted.accounts.find((acc) => acc.name === "Marker")) === null || _e === void 0 ? void 0 : _e.pubkey;
143
+ const innerIxs = (_f = tx.meta.innerInstructions) === null || _f === void 0 ? void 0 : _f.find((ix) => ix.index === index);
144
+ const innerVoteIx = innerIxs === null || innerIxs === void 0 ? void 0 : innerIxs.instructions.find((ix) => {
145
+ var _a;
146
+ return ((_a = message.staticAccountKeys[ix.programIdIndex]) === null || _a === void 0 ? void 0 : _a.toBase58()) ===
147
+ proposalProgram.programId.toBase58();
148
+ });
149
+ const innerVoteDecoded = proposalCoder.decode(Buffer.from(bs58_1.default.decode((innerVoteIx === null || innerVoteIx === void 0 ? void 0 : innerVoteIx.data) || "")));
150
+ if (!innerVoteDecoded) {
151
+ console.log("innerVoteDecoded missing", index, tx.meta.innerInstructions, innerVoteIx, innerIxs, chunk);
152
+ }
153
+ ;
154
+ // @ts-ignore
155
+ let { weight, choice } = innerVoteDecoded.data.args;
156
+ let propMap = votesByProposal.get(proposal.toBase58());
157
+ let voteMarker = propMap.get(marker.toBase58());
158
+ if (!voteMarker) {
159
+ voteMarker = {
160
+ address: marker,
161
+ voter,
162
+ registrar,
163
+ proposal,
164
+ mint,
165
+ // @ts-ignore
166
+ choices: [choice],
167
+ weight: weight,
168
+ bumpSeed: 0,
169
+ deprecatedRelinquished: false,
170
+ proxyIndex: 0,
171
+ rentRefund: web3_js_1.PublicKey.default,
172
+ };
173
+ }
174
+ if (!voteMarker.choices.some((c) => c === choice)) {
175
+ voteMarker.choices.push(choice);
176
+ }
177
+ if (!voteMarker.weight.eq(weight)) {
178
+ voteMarker.weight = weight;
179
+ }
180
+ propMap.set(marker.toBase58(), voteMarker);
181
+ }
182
+ else if (decoded.name === "proxiedVoteV0") {
183
+ const voter = (_g = formatted.accounts.find((acc) => acc.name === "Voter")) === null || _g === void 0 ? void 0 : _g.pubkey;
184
+ const position = (_h = formatted.accounts.find((acc) => acc.name === "Position")) === null || _h === void 0 ? void 0 : _h.pubkey;
185
+ const registrar = (_j = formatted.accounts.find((acc) => acc.name === "Registrar")) === null || _j === void 0 ? void 0 : _j.pubkey;
186
+ const proposal = (_k = formatted.accounts.find((acc) => acc.name === "Proposal")) === null || _k === void 0 ? void 0 : _k.pubkey;
187
+ const marker = (_l = formatted.accounts.find((acc) => acc.name === "Marker")) === null || _l === void 0 ? void 0 : _l.pubkey;
188
+ // Use cache for position lookup
189
+ let mint;
190
+ if (position) {
191
+ const positionKey = position.toBase58();
192
+ if (!positionCache.has(positionKey)) {
193
+ const posData = yield hvsrProgram.account.positionV0.fetchNullable(position);
194
+ positionCache.set(positionKey, { mint: (posData === null || posData === void 0 ? void 0 : posData.mint) || web3_js_1.PublicKey.default });
195
+ }
196
+ mint = positionCache.get(positionKey).mint;
197
+ }
198
+ else {
199
+ mint = web3_js_1.PublicKey.default;
200
+ }
201
+ const innerIxs = (_m = tx.meta.innerInstructions) === null || _m === void 0 ? void 0 : _m.find((ix) => ix.index === index);
202
+ const innerVoteIx = innerIxs === null || innerIxs === void 0 ? void 0 : innerIxs.instructions.find((ix) => {
203
+ var _a;
204
+ return ((_a = message.staticAccountKeys[ix.programIdIndex]) === null || _a === void 0 ? void 0 : _a.toBase58()) ===
205
+ proposalProgram.programId.toBase58();
206
+ });
207
+ const innerVoteDecoded = proposalCoder.decode(Buffer.from(bs58_1.default.decode((innerVoteIx === null || innerVoteIx === void 0 ? void 0 : innerVoteIx.data) || "")));
208
+ if (!innerVoteDecoded) {
209
+ console.log("innerVoteDecoded missing", index, tx.meta.innerInstructions, innerVoteIx, innerIxs, chunk);
210
+ }
211
+ // @ts-ignore
212
+ let { weight, choice } = innerVoteDecoded.data.args;
213
+ let propMap = votesByProposal.get(proposal.toBase58());
214
+ let voteMarker = propMap.get(marker.toBase58());
215
+ if (!voteMarker) {
216
+ voteMarker = {
217
+ address: marker,
218
+ voter,
219
+ registrar,
220
+ proposal,
221
+ mint,
222
+ // @ts-ignore
223
+ choices: [choice],
224
+ weight,
225
+ bumpSeed: 0,
226
+ deprecatedRelinquished: false,
227
+ proxyIndex: 0,
228
+ rentRefund: web3_js_1.PublicKey.default,
229
+ };
230
+ }
231
+ if (!voteMarker.choices.some((c) => c === choice)) {
232
+ voteMarker.choices.push(choice);
233
+ }
234
+ if (!voteMarker.weight.eq(weight)) {
235
+ voteMarker.weight = weight;
236
+ }
237
+ propMap.set(marker.toBase58(), voteMarker);
238
+ }
239
+ else if (decoded.name === "relinquishVoteV1" || decoded.name === "proxiedRelinquishVoteV0") {
240
+ const firstIsSigner = message.isAccountSigner(ix.accountKeyIndexes[0]);
241
+ // HACK: At some point we removed rent refund as first account and made it the last account.
242
+ if (firstIsSigner && decoded.name === "relinquishVoteV1") {
243
+ const len = ix.accountKeyIndexes.length;
244
+ let refund = ix.accountKeyIndexes.shift();
245
+ if (len != 12) { // super legacy
246
+ ix.accountKeyIndexes.push(refund);
247
+ }
248
+ decoded = hvsrCoder.decode(Buffer.from(ix.data));
249
+ formatted = hvsrCoder.format(decoded, ix.accountKeyIndexes.map((i) => {
250
+ return {
251
+ pubkey: message.staticAccountKeys[i] || web3_js_1.PublicKey.default,
252
+ isSigner: false,
253
+ isWritable: false,
254
+ };
255
+ }));
256
+ }
257
+ const marker = (_o = formatted.accounts.find((acc) => acc.name === "Marker")) === null || _o === void 0 ? void 0 : _o.pubkey;
258
+ const proposal = (_p = formatted.accounts.find((acc) => acc.name === "Proposal")) === null || _p === void 0 ? void 0 : _p.pubkey;
259
+ const propMap = votesByProposal.get(proposal.toBase58());
260
+ let voteMarker = propMap.get(marker.toBase58());
261
+ if (voteMarker) {
262
+ // @ts-ignore
263
+ voteMarker.choices = voteMarker.choices.filter(c => c !== decoded.data.args.choice);
264
+ if (voteMarker.choices.length === 0) {
265
+ propMap.delete(marker.toBase58());
266
+ }
267
+ else {
268
+ propMap.set(marker.toBase58(), voteMarker);
269
+ }
270
+ }
271
+ }
272
+ }
273
+ catch (e) {
274
+ console.log("error", index, tx.transaction.signatures[0]);
275
+ throw e;
276
+ // Skip instructions that can't be decoded
277
+ continue;
278
+ }
279
+ }
280
+ }
281
+ }
282
+ }
283
+ let flattened = Array.from(votesByProposal.values()).flatMap((markers) => {
284
+ return Array.from(markers.values()).map(marker => ({
285
+ address: marker.address.toBase58(),
286
+ voter: marker.voter.toBase58(),
287
+ registrar: marker.registrar.toBase58(),
288
+ proposal: marker.proposal.toBase58(),
289
+ mint: marker.mint.toBase58(),
290
+ choices: marker.choices,
291
+ weight: marker.weight.toString(),
292
+ bumpSeed: marker.bumpSeed,
293
+ deprecatedRelinquished: marker.deprecatedRelinquished,
294
+ proxyIndex: marker.proxyIndex,
295
+ rentRefund: marker.rentRefund.toBase58(),
296
+ }));
297
+ });
298
+ // Write results to file
299
+ const fs = require('fs');
300
+ fs.writeFileSync(argv.outputPath, JSON.stringify(flattened, null, 2));
301
+ });
302
+ }
303
+ exports.run = run;
304
+ //# sourceMappingURL=dump-vote-markers.js.map