Skip to content

Commit a9b6912

Browse files
committed
kinda fix
1 parent 231a05b commit a9b6912

File tree

3 files changed

+13
-57
lines changed

3 files changed

+13
-57
lines changed

sdk/src/earn_auth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export class EarnAuthority {
5353
return new PublicKey(this.global.admin);
5454
}
5555

56+
async getAllEarners(): Promise<Earner[]> {
57+
const accounts = await this.program.account.earner.all();
58+
return accounts.map((a) => new Earner(this.connection, a.publicKey, a.account, this.program.programId));
59+
}
60+
5661
async buildClaimInstruction(earner: Earner): Promise<TransactionInstruction | null> {
5762
if (earner.data.lastClaimIndex.gte(this.global.index!)) {
5863
this.logger.warn('Earner already claimed', {

services/yield-bot/devnet.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EarnAuthority, EXT_PROGRAM_ID, Logger, PROGRAM_ID } from '@m0-foundation/solana-m-sdk';
1+
import { EarnAuthority, Logger } from '@m0-foundation/solana-m-sdk';
22
import { MongoClient } from 'mongodb';
33
import { ParsedOptions } from './main';
44
import { PublicKey } from '@solana/web3.js';
@@ -7,19 +7,19 @@ export async function persistDevnetIndex(opt: ParsedOptions, logger: Logger, pid
77
if (!opt.isDevnet) {
88
throw new Error('This function should only be called on devnet');
99
}
10-
if (!pid.equals(PROGRAM_ID) && !pid.equals(EXT_PROGRAM_ID)) {
10+
if (pid.toBase58() !== 'wMXX1K1nca5W4pZr1piETe78gcAVVrEFi9f4g46uXko') {
1111
return;
1212
}
1313

14-
const auth = await EarnAuthority.load(opt.connection, opt.evmClient, pid, logger);
14+
const auth = await EarnAuthority.load(opt.connection, pid, logger);
1515
const earner = (await auth.getAllEarners())[0];
1616

1717
const indexUpdates = [];
1818
const transactions = [];
1919

2020
for (const [index, ts] of [
2121
[earner.data.lastClaimIndex, earner.data.lastClaimTimestamp],
22-
[auth['earnGlobal'].index, auth['earnGlobal'].timestamp],
22+
[auth['global'].index, auth['global'].timestamp],
2323
]) {
2424
// dummy signature
2525
const sig = Array.from(crypto.getRandomValues(new Uint8Array(16)))
@@ -33,7 +33,7 @@ export async function persistDevnetIndex(opt: ParsedOptions, logger: Logger, pid
3333
index: index.toNumber(),
3434
instruction: 'PropagateIndex',
3535
max_yield: '1000',
36-
program_id: PROGRAM_ID.toBase58(),
36+
program_id: 'mz2vDzjbQDUDXBH6FPF5s4odCJ4y8YLE5QWaZ8XdZ9Z',
3737
signature: sig,
3838
token_supply: 1000000,
3939
ts: date,

services/yield-bot/main.ts

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from 'commander';
2-
import { Registrar, EarnAuthority, WinstonLogger, PROGRAM_ID, TransactionBuilder } from '@m0-foundation/solana-m-sdk';
2+
import { EarnAuthority, WinstonLogger, TransactionBuilder } from '@m0-foundation/solana-m-sdk';
33
import {
44
ComputeBudgetProgram,
55
PublicKey,
@@ -46,13 +46,11 @@ export interface ParsedOptions extends EnvOptions {
4646

4747
// all programs and extensions that require yield distribution
4848
const programsMainnet = [
49-
PROGRAM_ID,
5049
new PublicKey('wMXX1K1nca5W4pZr1piETe78gcAVVrEFi9f4g46uXko'), // wM
5150
new PublicKey('extMahs9bUFMYcviKCvnSRaXgs5PcqmMzcnHRtTqE85'), // USDKY
5251
];
5352

5453
const programsDevnet = [
55-
PROGRAM_ID,
5654
new PublicKey('wMXX1K1nca5W4pZr1piETe78gcAVVrEFi9f4g46uXko'), // wM
5755
new PublicKey('3PskKTHgboCbUSQPMcCAZdZNFHbNvSoZ8zEFYANCdob7'), // USDKY
5856
new PublicKey('extUkDFf3HLekkxbcZ3XRUizMjbxMJgKBay3p9xGVmg'), // Fuse USD
@@ -81,9 +79,6 @@ export async function yieldCLI() {
8179

8280
if (!options.isDevnet) await validation(options);
8381

84-
// pre-yield actions
85-
await removeEarners(options);
86-
8782
// distribute yield for each program
8883
for (const pid of env.isDevnet ? programsDevnet : programsMainnet) {
8984
logger.addMetaField('programId', pid.toBase58());
@@ -97,9 +92,6 @@ export async function yieldCLI() {
9792
// wait interval to ensure transactions from previous steps have landed
9893
await new Promise((resolve) => setTimeout(resolve, 5000));
9994
}
100-
101-
// post-yield actions
102-
await addEarners(options);
10395
} catch (error: any) {
10496
logger.error(error);
10597
slackMessage.level = 'error';
@@ -111,12 +103,12 @@ export async function yieldCLI() {
111103
}
112104

113105
async function validation(opt: ParsedOptions) {
114-
const auth = await EarnAuthority.load(opt.connection, opt.evmClient, PROGRAM_ID, logger);
106+
const auth = await EarnAuthority.load(opt.connection, programsMainnet[0], logger);
115107
await validateDatabaseData(auth, opt.apiEnvornment);
116108
}
117109

118110
async function distributeYield(opt: ParsedOptions, programID: PublicKey): Promise<void> {
119-
const auth = await EarnAuthority.load(opt.connection, opt.evmClient, programID, logger);
111+
const auth = await EarnAuthority.load(opt.connection, programID, logger);
120112

121113
if (auth['global'].claimComplete) {
122114
logger.info('claim cycle already complete');
@@ -156,14 +148,9 @@ async function distributeYield(opt: ParsedOptions, programID: PublicKey): Promis
156148
});
157149
}
158150

159-
// complete cycle after distribution if applicable
160-
const completeClaimIx = await auth.buildCompleteClaimCycleInstruction();
161-
if (completeClaimIx) ixs.push(completeClaimIx);
162-
163151
logger.info('distribution instructions', {
164152
claimIxs,
165153
hasSync: !!syncIndexIx,
166-
hasComplete: !!completeClaimIx,
167154
});
168155

169156
// send transaction
@@ -173,42 +160,6 @@ async function distributeYield(opt: ParsedOptions, programID: PublicKey): Promis
173160
return;
174161
}
175162

176-
async function addEarners(opt: ParsedOptions) {
177-
logger.info('adding earners');
178-
const registrar = new Registrar(opt.connection, opt.evmClient, logger);
179-
180-
const signer = opt.squads ? opt.squads.squadsVault : opt.signerPubkey;
181-
const instructions = await registrar.buildMissingEarnersInstructions(signer, opt.merkleTreeAddress);
182-
183-
if (instructions.length === 0) {
184-
logger.info('no earners to add');
185-
return;
186-
}
187-
188-
const signature = await buildAndSendTransaction(opt, instructions, 10, 'adding earners');
189-
logger.info('added earners', { signature, earners: instructions.length });
190-
slackMessage.messages.push(`Added ${instructions.length} earners`);
191-
}
192-
193-
async function removeEarners(opt: ParsedOptions) {
194-
logger.info('removing earners');
195-
const registrar = new Registrar(opt.connection, opt.evmClient, logger);
196-
197-
const signer = opt.squads ? opt.squads.squadsVault : opt.signerPubkey;
198-
const instructions = await registrar.buildRemovedEarnersInstructions(signer, opt.merkleTreeAddress);
199-
200-
if (instructions.length === 0) {
201-
logger.info('no earners to remove');
202-
return;
203-
}
204-
205-
const signature = await buildAndSendTransaction(opt, instructions, 10, 'removing earners');
206-
logger.info('removed earners', { signature, earners: instructions.length });
207-
slackMessage.messages.push(`Removed ${instructions.length} earners`);
208-
209-
return;
210-
}
211-
212163
async function buildAndSendTransaction(
213164
opt: ParsedOptions,
214165
ixs: TransactionInstruction[],

0 commit comments

Comments
 (0)