Skip to content

v1.3 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged

v1.3 #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .yarn/install-state.gz
Binary file not shown.
6 changes: 3 additions & 3 deletions SHASUMS256
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
deploy 867bf606c3bd68cd55ee18373de793e5132957869b3b6763f3577e5d32d4a8e3
bot 8e66dd03297ff2f643c803d1ddae3d2f98dbe3e2f4e62bfab438166fff6d1fae
calculator b914e262b18525d140dbfc7ed6e8c1848bc2adb164bf1c4993b7530736653ec7
deploy 5e4d6d8535cb9a66f2c2c19d58dce2f3f8dbacfb80a255b8fa582111093d0ab6
bot e1f463d5ec53f4c3a677f9565aafc459264d19be39cb39f7ff61f1d326695f22
calculator adce30bfa62cde5603907807c637d90f44bc6443fc8fafe4b84a6c525a580d75
scripts 3f095b61090b40b85ea8924cadf0c08d3abed0f8434a029ba2ee61ca96490529
8 changes: 4 additions & 4 deletions bot/__test__/bot.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { activateNotary, runOnTeardown, sudo, teardown, TestMainchain, TestNotary } from '@argonprotocol/testing';
import { MiningRotations, mnemonicGenerate } from '@argonprotocol/mainchain';
import * as BiddingCalculator from '@argonprotocol/commander-calculator';
import { FrameCalculator, mnemonicGenerate } from '@argonprotocol/mainchain';
import { afterAll, afterEach, expect, it, vi } from 'vitest';
import * as fs from 'node:fs';
import Path from 'node:path';
import Bot from '../src/Bot.ts';
import * as BiddingCalculator from '@argonprotocol/commander-calculator';

afterEach(teardown);
afterAll(teardown);
Expand Down Expand Up @@ -54,7 +54,7 @@ it('can autobid and store stats', async () => {
const unsubscribe = await client.query.miningSlot.activeMinersCount(async x => {
if (x.toNumber() > 0) {
unsubscribe();
firstCohort = await client.query.miningSlot.nextCohortId().then(x => x.toNumber() - 1);
firstCohort = await client.query.miningSlot.nextFrameId().then(x => x.toNumber() - 1);
resolve(x);
}
});
Expand All @@ -70,7 +70,7 @@ it('can autobid and store stats', async () => {
lastFinalizedBlockNumber = x.number.toNumber();
if (isVoteBlock) {
console.log(`Block ${x.number} is vote block`);
const frameId = await new MiningRotations().getForHeader(client, x);
const frameId = await new FrameCalculator().getForHeader(client, x);
if (frameId !== undefined) cohortActivatingFrameIdsWithEarnings.add(frameId);
voteBlocks++;
if (voteBlocks > 5) {
Expand Down
4 changes: 2 additions & 2 deletions bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"main": "src/index.ts",
"dependencies": {
"@argonprotocol/commander-calculator": "workspace:*",
"@argonprotocol/mainchain": "1.1.0",
"@argonprotocol/mainchain": "1.3.2",
"cors": "^2.8.5",
"express": "^5.1.0",
"tiny-lru": "^11.2.11",
"tsx": "^4.19.3"
},
"devDependencies": {
"@argonprotocol/testing": "1.1.0",
"@argonprotocol/testing": "1.3.2",
"@types/cors": "^2.8.17",
"@types/express": "^5.0.1",
"typescript": "^5.8.3",
Expand Down
8 changes: 4 additions & 4 deletions bot/src/AutoBidder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AutoBidder {

async restart() {
if (this.activeBidder) {
const cohortActivatingFrameId = this.activeBidder.cohortId;
const cohortActivatingFrameId = this.activeBidder.cohortFrameId;
await this.stopBidder();
await this.onBiddingStart(cohortActivatingFrameId);
}
Expand All @@ -51,12 +51,12 @@ export class AutoBidder {

private async onBiddingEnd(cohortActivatingFrameId: number): Promise<void> {
console.log(`Bidding for frame ${cohortActivatingFrameId} ended`);
if (this.activeBidder?.cohortId !== cohortActivatingFrameId) return;
if (this.activeBidder?.cohortFrameId !== cohortActivatingFrameId) return;
await this.stopBidder();
}

private async onBiddingStart(cohortActivatingFrameId: number) {
if (this.activeBidder?.cohortId === cohortActivatingFrameId) return;
if (this.activeBidder?.cohortFrameId === cohortActivatingFrameId) return;
const params = await createBidderParams(cohortActivatingFrameId, await this.accountset.client, this.biddingRules);
if (params.maxSeats === 0) return;

Expand Down Expand Up @@ -97,7 +97,7 @@ export class AutoBidder {
const activeBidder = this.activeBidder;
if (!activeBidder) return;
this.activeBidder = undefined;
const cohortActivatingFrameId = activeBidder.cohortId;
const cohortActivatingFrameId = activeBidder.cohortFrameId;
const stats = await activeBidder.stop();
console.log('Bidding stopped', { cohortActivatingFrameId, ...stats });
}
Expand Down
16 changes: 8 additions & 8 deletions bot/src/BlockSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getAuthorFromHeader,
getTickFromHeader,
type Header,
MiningRotations,
FrameCalculator,
type SpRuntimeDispatchError,
type Vec,
} from '@argonprotocol/mainchain';
Expand Down Expand Up @@ -132,7 +132,7 @@ export class BlockSync {

this.accountMiners = new AccountMiners(
this.accountset,
startingMinerState.filter(x => x.cohortId !== undefined) as any,
startingMinerState.filter(x => x.seat !== undefined) as any,
);

// catchup now
Expand Down Expand Up @@ -250,7 +250,7 @@ export class BlockSync {
const client = this.getRpcClient(header);
const api = await client.at(header.hash);
const events = await api.query.system.events();
const { rotation: _r, ...cohortEarningsAtFrameId } = await this.accountMiners.onBlock(
const { duringFrameId: _r, ...cohortEarningsAtFrameId } = await this.accountMiners.onBlock(
header,
{ tick, author },
events.map(x => x.event),
Expand Down Expand Up @@ -365,7 +365,7 @@ export class BlockSync {
}

private async getFrameIdFromHeader(header: Header): Promise<number> {
const currentFrameId = await new MiningRotations().getForHeader(this.localClient, header);
const currentFrameId = await new FrameCalculator().getForHeader(this.localClient, header);
if (currentFrameId === undefined) {
throw new Error(`Error getting frame id for header ${header.number.toNumber()}`);
}
Expand All @@ -378,9 +378,9 @@ export class BlockSync {
const headerTick = getTickFromHeader(client, header);

const blockNumber = header.number.toNumber();
const cohortActivatingFrameId = await api.query.miningSlot.nextCohortId().then(x => x.toNumber());
const cohortActivatingFrameId = await api.query.miningSlot.nextFrameId().then(x => x.toNumber());
const bidsFile = this.storage.bidsFile(cohortActivatingFrameId);
const nextCohort = await api.query.miningSlot.nextSlotCohort();
const nextCohort = await api.query.miningSlot.bidsForNextSlotCohort();

let didChangeBiddings = false;
if (this.previousNextCohortJson !== nextCohort.toJSON()) {
Expand Down Expand Up @@ -451,8 +451,8 @@ export class BlockSync {
if (phase.isFinalization && client.events.miningSlot.NewMiners.is(event)) {
console.log('New miners event', event.data.toJSON());
let hasMiningSeats = false;
const [_startIndex, newMiners, _released, cohortActivatingFrameId] = event.data;
await this.storage.bidsFile(cohortActivatingFrameId.toNumber()).mutate(x => {
const { frameId, newMiners } = event.data;
await this.storage.bidsFile(frameId.toNumber()).mutate(x => {
x.seatsWon = 0;
x.microgonsBidTotal = 0n;
x.winningBids = [];
Expand Down
38 changes: 18 additions & 20 deletions bot/src/CohortBidder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class CohortBidder {

constructor(
public accountset: Accountset,
public cohortId: number,
public cohortFrameId: number,
public subaccounts: { index: number; isRebid: boolean; address: string }[],
public options: {
minBid: bigint;
Expand All @@ -46,7 +46,7 @@ export class CohortBidder {
tipPerTransaction?: bigint;
},
) {
this.history = new CohortBidderHistory(cohortId, subaccounts);
this.history = new CohortBidderHistory(cohortFrameId, subaccounts);
this.subaccounts.forEach(x => {
this.myAddresses.add(x.address);
});
Expand All @@ -55,17 +55,17 @@ export class CohortBidder {
public async stop(): Promise<CohortBidder['stats']> {
if (this.isStopped) return this.stats;
this.isStopped = true;
console.log('Stopping bidder for cohort', this.cohortId);
console.log('Stopping bidder for cohort', this.cohortFrameId);
clearTimeout(this.retryTimeout);
if (this.unsubscribe) {
this.unsubscribe();
}
const client = await this.client;
const [nextCohortId, isBiddingOpen] = await client.queryMulti<[u64, Bool]>([
client.query.miningSlot.nextCohortId as any,
const [nextFrameId, isBiddingOpen] = await client.queryMulti<[u64, Bool]>([
client.query.miningSlot.nextFrameId as any,
client.query.miningSlot.isNextSlotBiddingOpen,
]);
if (nextCohortId.toNumber() === this.cohortId && isBiddingOpen.isTrue) {
if (nextFrameId.toNumber() === this.cohortFrameId && isBiddingOpen.isTrue) {
console.log('Bidding is still open, waiting for it to close');
await new Promise<void>(async resolve => {
const unsub = await client.query.miningSlot.isNextSlotBiddingOpen(isOpen => {
Expand All @@ -83,19 +83,19 @@ export class CohortBidder {
let header = await client.rpc.chain.getHeader();
while (true) {
const api = await client.at(header.hash);
const cohortId = await api.query.miningSlot.nextCohortId();
if (cohortId.toNumber() === this.cohortId) {
const frameId = await api.query.miningSlot.nextFrameId();
if (frameId.toNumber() === this.cohortFrameId) {
break;
}
header = await client.rpc.chain.getHeader(header.parentHash);
}
const api = await client.at(header.hash);
const tick = await api.query.ticks.currentTick().then(x => x.toNumber());
const cohort = await api.query.miningSlot.nextSlotCohort();
const cohort = await api.query.miningSlot.bidsForNextSlotCohort();

this.history.trackChange(cohort, header.number.toNumber(), tick, true);
console.log('Bidder stopped', {
cohortId: this.cohortId,
cohortId: this.cohortFrameId,
blockNumber: header.number.toNumber(),
tick,
cohort: cohort.map(x => ({
Expand All @@ -108,7 +108,7 @@ export class CohortBidder {
}

public async start() {
console.log(`Starting cohort ${this.cohortId} bidder`, {
console.log(`Starting cohort ${this.cohortFrameId} bidder`, {
maxBid: formatArgons(this.options.maxBid),
minBid: formatArgons(this.options.minBid),
bidIncrement: formatArgons(this.options.bidIncrement),
Expand All @@ -122,9 +122,9 @@ export class CohortBidder {
this.millisPerTick ??= await client.query.ticks.genesisTicker().then(x => x.tickDurationMillis.toNumber());

this.unsubscribe = await client.queryMulti<[Vec<ArgonPrimitivesBlockSealMiningRegistration>, u64]>(
[client.query.miningSlot.nextSlotCohort as any, client.query.miningSlot.nextCohortId as any],
async ([next, nextCohortId]) => {
if (nextCohortId.toNumber() === this.cohortId) {
[client.query.miningSlot.bidsForNextSlotCohort as any, client.query.miningSlot.nextFrameId as any],
async ([next, nextFrameId]) => {
if (nextFrameId.toNumber() === this.cohortFrameId) {
await this.checkSeats(next);
}
},
Expand Down Expand Up @@ -159,7 +159,7 @@ export class CohortBidder {
}
console.log(
'Checking bids for cohort',
this.cohortId,
this.cohortFrameId,
this.subaccounts.map(x => x.index),
);

Expand Down Expand Up @@ -192,7 +192,6 @@ export class CohortBidder {
const fakeTx = await this.accountset.createMiningBidTx({
subaccounts: this.subaccounts,
bidAmount: nextBid,
sendRewardsToSeed: true,
});
let availableBalanceForBids = await api.query.system
.account(this.accountset.txSubmitterPair.address)
Expand All @@ -219,7 +218,7 @@ export class CohortBidder {
}

if (nextBid - lowestBid < MIN_INCREMENT) {
console.log(`Can't make any more bids for ${this.cohortId} with given constraints.`, {
console.log(`Can't make any more bids for ${this.cohortFrameId} with given constraints.`, {
lowestCurrentBid: formatArgons(lowestBid),
nextAttemptedBid: formatArgons(nextBid),
maxBid: formatArgons(this.options.maxBid),
Expand Down Expand Up @@ -285,7 +284,6 @@ export class CohortBidder {
const submitter = await this.accountset.createMiningBidTx({
subaccounts,
bidAmount: bidPerSeat,
sendRewardsToSeed: true,
});
const tip = this.options.tipPerTransaction ?? 0n;
const txResult = await submitter.submit({
Expand Down Expand Up @@ -319,7 +317,7 @@ export class CohortBidder {
if (bidError) throw bidError;
} catch (err) {
this.lastBidTime = prevLastBidTime;
console.error(`Error bidding for cohort ${this.cohortId}:`, err);
console.error(`Error bidding for cohort ${this.cohortFrameId}:`, err);
clearTimeout(this.retryTimeout);
this.retryTimeout = setTimeout(() => void this.checkCurrentSeats(), 1000);
} finally {
Expand All @@ -334,7 +332,7 @@ export class CohortBidder {

private async checkCurrentSeats() {
const client = await this.client;
const next = await client.query.miningSlot.nextSlotCohort();
const next = await client.query.miningSlot.bidsForNextSlotCohort();
await this.checkSeats(next);
}
}
2 changes: 1 addition & 1 deletion calculator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"type": "module",
"main": "src/index.ts",
"dependencies": {
"@argonprotocol/mainchain": "^1.1.0"
"@argonprotocol/mainchain": "1.3.2"
}
}
9 changes: 2 additions & 7 deletions calculator/src/Mainchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,8 @@ export class Mainchain {
public async fetchPreviousDayWinningBids(): Promise<bigint[]> {
const client = await this.client;
const currentFrameId = calculateCurrentFrameIdFromSystemTime();
const activeMiners = await client.query.miningSlot.activeMinersByIndex.entries();
const yesterdayWinningBids = activeMiners.filter(
([_, x]: [any, Option<ArgonPrimitivesBlockSealMiningRegistration>]) => {
return x.isSome && x.unwrap().cohortId.toNumber() === currentFrameId;
},
);
return yesterdayWinningBids.map(([_, bid]) => bid.unwrap().bid.toBigInt());
const yesterdayWinningBids = await client.query.miningSlot.minersByCohort(currentFrameId);
return yesterdayWinningBids.map(bid => bid.bid.toBigInt());
}
}

Expand Down
2 changes: 1 addition & 1 deletion deploy/.env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BITCOIN_CONFIG=/etc/bitcoin/bitcoin.conf
BITCOIN_CHAIN=mainnet
BITCOIN_VERSION=28.1
# must match docker version
ARGON_VERSION=v1.1.0
ARGON_VERSION=v1.3.2
ARGON_DATA_FOLDER=${DATA_FOLDER}/argon
ARGON_CHAIN=mainnet
ARGON_ARCHIVE_NODE=wss://rpc.argon.network
Expand Down
2 changes: 1 addition & 1 deletion deploy/.env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BITCOIN_CONFIG=/etc/bitcoin/bitcoin-signet.conf
BITCOIN_CHAIN=signet
BITCOIN_VERSION=28.1

ARGON_VERSION=v1.1.0
ARGON_VERSION=v1.3.2
ARGON_DATA_FOLDER=${DATA_FOLDER}/argon-test
ARGON_CHAIN=testnet
ARGON_ARCHIVE_NODE=wss://rpc.testnet.argonprotocol.org
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
},
"dependencies": {
"@argonprotocol/commander-calculator": "workspace:*",
"@argonprotocol/mainchain": "1.1.0",
"@argonprotocol/mainchain": "1.3.2",
"@chenfengyuan/vue-countdown": "^2.1.3",
"@headlessui/vue": "^1.7.23",
"@heroicons/vue": "^2.2.0",
"@polkadot/api": "^15.5.2",
"@tailwindcss/vite": "^4.0.3",
"@tauri-apps/api": "^2.2.0",
"@tauri-apps/plugin-dialog": "~2",
Expand Down
2 changes: 1 addition & 1 deletion src-vue/lib/StatsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class StatsFetcher {
const { data } = await SSH.runHttpGet<IBidsHistory>(`/bid-history`);

return data.map(x => ({
cohortId: x.cohortId,
cohortStartingFrameId: x.cohortStartingFrameId,
blockNumber: x.blockNumber,
tick: x.tick,
bidChanges: x.bidChanges.map(y => ({
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true
},
"include": ["src-vue/**/*.ts", "src-vue/**/*.d.ts", "src-vue/**/*.tsx", "src-vue/**/*.vue", "calculator"],
"include": ["src-vue/**/*.ts", "src-vue/**/*.d.ts", "src-vue/**/*.tsx", "src-vue/**/*.vue", "calculator", "bot"],
"references": [{ "path": "./tsconfig.node.json"} ]
}
Loading