Skip to content

Commit e3eed57

Browse files
committed
feat: convert to mainchain 1.3
1 parent d8aa56f commit e3eed57

File tree

15 files changed

+305
-277
lines changed

15 files changed

+305
-277
lines changed

.yarn/install-state.gz

18.9 KB
Binary file not shown.

SHASUMS256

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
deploy 867bf606c3bd68cd55ee18373de793e5132957869b3b6763f3577e5d32d4a8e3
2-
bot 8e66dd03297ff2f643c803d1ddae3d2f98dbe3e2f4e62bfab438166fff6d1fae
3-
calculator b914e262b18525d140dbfc7ed6e8c1848bc2adb164bf1c4993b7530736653ec7
1+
deploy 5e4d6d8535cb9a66f2c2c19d58dce2f3f8dbacfb80a255b8fa582111093d0ab6
2+
bot e1f463d5ec53f4c3a677f9565aafc459264d19be39cb39f7ff61f1d326695f22
3+
calculator adce30bfa62cde5603907807c637d90f44bc6443fc8fafe4b84a6c525a580d75
44
scripts 3f095b61090b40b85ea8924cadf0c08d3abed0f8434a029ba2ee61ca96490529

bot/__test__/bot.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { activateNotary, runOnTeardown, sudo, teardown, TestMainchain, TestNotary } from '@argonprotocol/testing';
2-
import { MiningRotations, mnemonicGenerate } from '@argonprotocol/mainchain';
3-
import * as BiddingCalculator from '@argonprotocol/commander-calculator';
2+
import { FrameCalculator, mnemonicGenerate } from '@argonprotocol/mainchain';
43
import { afterAll, afterEach, expect, it, vi } from 'vitest';
54
import * as fs from 'node:fs';
65
import Path from 'node:path';
76
import Bot from '../src/Bot.ts';
7+
import * as BiddingCalculator from '@argonprotocol/commander-calculator';
88

99
afterEach(teardown);
1010
afterAll(teardown);
@@ -54,7 +54,7 @@ it('can autobid and store stats', async () => {
5454
const unsubscribe = await client.query.miningSlot.activeMinersCount(async x => {
5555
if (x.toNumber() > 0) {
5656
unsubscribe();
57-
firstCohort = await client.query.miningSlot.nextCohortId().then(x => x.toNumber() - 1);
57+
firstCohort = await client.query.miningSlot.nextFrameId().then(x => x.toNumber() - 1);
5858
resolve(x);
5959
}
6060
});
@@ -70,7 +70,7 @@ it('can autobid and store stats', async () => {
7070
lastFinalizedBlockNumber = x.number.toNumber();
7171
if (isVoteBlock) {
7272
console.log(`Block ${x.number} is vote block`);
73-
const frameId = await new MiningRotations().getForHeader(client, x);
73+
const frameId = await new FrameCalculator().getForHeader(client, x);
7474
if (frameId !== undefined) cohortActivatingFrameIdsWithEarnings.add(frameId);
7575
voteBlocks++;
7676
if (voteBlocks > 5) {

bot/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"main": "src/index.ts",
1212
"dependencies": {
1313
"@argonprotocol/commander-calculator": "workspace:*",
14-
"@argonprotocol/mainchain": "1.1.0",
14+
"@argonprotocol/mainchain": "1.3.2",
1515
"cors": "^2.8.5",
1616
"express": "^5.1.0",
1717
"tiny-lru": "^11.2.11",
1818
"tsx": "^4.19.3"
1919
},
2020
"devDependencies": {
21-
"@argonprotocol/testing": "1.1.0",
21+
"@argonprotocol/testing": "1.3.2",
2222
"@types/cors": "^2.8.17",
2323
"@types/express": "^5.0.1",
2424
"typescript": "^5.8.3",

bot/src/AutoBidder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class AutoBidder {
3737

3838
async restart() {
3939
if (this.activeBidder) {
40-
const cohortActivatingFrameId = this.activeBidder.cohortId;
40+
const cohortActivatingFrameId = this.activeBidder.cohortFrameId;
4141
await this.stopBidder();
4242
await this.onBiddingStart(cohortActivatingFrameId);
4343
}
@@ -51,12 +51,12 @@ export class AutoBidder {
5151

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

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

@@ -97,7 +97,7 @@ export class AutoBidder {
9797
const activeBidder = this.activeBidder;
9898
if (!activeBidder) return;
9999
this.activeBidder = undefined;
100-
const cohortActivatingFrameId = activeBidder.cohortId;
100+
const cohortActivatingFrameId = activeBidder.cohortFrameId;
101101
const stats = await activeBidder.stop();
102102
console.log('Bidding stopped', { cohortActivatingFrameId, ...stats });
103103
}

bot/src/BlockSync.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getAuthorFromHeader,
88
getTickFromHeader,
99
type Header,
10-
MiningRotations,
10+
FrameCalculator,
1111
type SpRuntimeDispatchError,
1212
type Vec,
1313
} from '@argonprotocol/mainchain';
@@ -132,7 +132,7 @@ export class BlockSync {
132132

133133
this.accountMiners = new AccountMiners(
134134
this.accountset,
135-
startingMinerState.filter(x => x.cohortId !== undefined) as any,
135+
startingMinerState.filter(x => x.seat !== undefined) as any,
136136
);
137137

138138
// catchup now
@@ -250,7 +250,7 @@ export class BlockSync {
250250
const client = this.getRpcClient(header);
251251
const api = await client.at(header.hash);
252252
const events = await api.query.system.events();
253-
const { rotation: _r, ...cohortEarningsAtFrameId } = await this.accountMiners.onBlock(
253+
const { duringFrameId: _r, ...cohortEarningsAtFrameId } = await this.accountMiners.onBlock(
254254
header,
255255
{ tick, author },
256256
events.map(x => x.event),
@@ -365,7 +365,7 @@ export class BlockSync {
365365
}
366366

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

380380
const blockNumber = header.number.toNumber();
381-
const cohortActivatingFrameId = await api.query.miningSlot.nextCohortId().then(x => x.toNumber());
381+
const cohortActivatingFrameId = await api.query.miningSlot.nextFrameId().then(x => x.toNumber());
382382
const bidsFile = this.storage.bidsFile(cohortActivatingFrameId);
383-
const nextCohort = await api.query.miningSlot.nextSlotCohort();
383+
const nextCohort = await api.query.miningSlot.bidsForNextSlotCohort();
384384

385385
let didChangeBiddings = false;
386386
if (this.previousNextCohortJson !== nextCohort.toJSON()) {
@@ -451,8 +451,8 @@ export class BlockSync {
451451
if (phase.isFinalization && client.events.miningSlot.NewMiners.is(event)) {
452452
console.log('New miners event', event.data.toJSON());
453453
let hasMiningSeats = false;
454-
const [_startIndex, newMiners, _released, cohortActivatingFrameId] = event.data;
455-
await this.storage.bidsFile(cohortActivatingFrameId.toNumber()).mutate(x => {
454+
const { frameId, newMiners } = event.data;
455+
await this.storage.bidsFile(frameId.toNumber()).mutate(x => {
456456
x.seatsWon = 0;
457457
x.microgonsBidTotal = 0n;
458458
x.winningBids = [];

bot/src/CohortBidder.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class CohortBidder {
3535

3636
constructor(
3737
public accountset: Accountset,
38-
public cohortId: number,
38+
public cohortFrameId: number,
3939
public subaccounts: { index: number; isRebid: boolean; address: string }[],
4040
public options: {
4141
minBid: bigint;
@@ -46,7 +46,7 @@ export class CohortBidder {
4646
tipPerTransaction?: bigint;
4747
},
4848
) {
49-
this.history = new CohortBidderHistory(cohortId, subaccounts);
49+
this.history = new CohortBidderHistory(cohortFrameId, subaccounts);
5050
this.subaccounts.forEach(x => {
5151
this.myAddresses.add(x.address);
5252
});
@@ -55,17 +55,17 @@ export class CohortBidder {
5555
public async stop(): Promise<CohortBidder['stats']> {
5656
if (this.isStopped) return this.stats;
5757
this.isStopped = true;
58-
console.log('Stopping bidder for cohort', this.cohortId);
58+
console.log('Stopping bidder for cohort', this.cohortFrameId);
5959
clearTimeout(this.retryTimeout);
6060
if (this.unsubscribe) {
6161
this.unsubscribe();
6262
}
6363
const client = await this.client;
64-
const [nextCohortId, isBiddingOpen] = await client.queryMulti<[u64, Bool]>([
65-
client.query.miningSlot.nextCohortId as any,
64+
const [nextFrameId, isBiddingOpen] = await client.queryMulti<[u64, Bool]>([
65+
client.query.miningSlot.nextFrameId as any,
6666
client.query.miningSlot.isNextSlotBiddingOpen,
6767
]);
68-
if (nextCohortId.toNumber() === this.cohortId && isBiddingOpen.isTrue) {
68+
if (nextFrameId.toNumber() === this.cohortFrameId && isBiddingOpen.isTrue) {
6969
console.log('Bidding is still open, waiting for it to close');
7070
await new Promise<void>(async resolve => {
7171
const unsub = await client.query.miningSlot.isNextSlotBiddingOpen(isOpen => {
@@ -83,19 +83,19 @@ export class CohortBidder {
8383
let header = await client.rpc.chain.getHeader();
8484
while (true) {
8585
const api = await client.at(header.hash);
86-
const cohortId = await api.query.miningSlot.nextCohortId();
87-
if (cohortId.toNumber() === this.cohortId) {
86+
const frameId = await api.query.miningSlot.nextFrameId();
87+
if (frameId.toNumber() === this.cohortFrameId) {
8888
break;
8989
}
9090
header = await client.rpc.chain.getHeader(header.parentHash);
9191
}
9292
const api = await client.at(header.hash);
9393
const tick = await api.query.ticks.currentTick().then(x => x.toNumber());
94-
const cohort = await api.query.miningSlot.nextSlotCohort();
94+
const cohort = await api.query.miningSlot.bidsForNextSlotCohort();
9595

9696
this.history.trackChange(cohort, header.number.toNumber(), tick, true);
9797
console.log('Bidder stopped', {
98-
cohortId: this.cohortId,
98+
cohortId: this.cohortFrameId,
9999
blockNumber: header.number.toNumber(),
100100
tick,
101101
cohort: cohort.map(x => ({
@@ -108,7 +108,7 @@ export class CohortBidder {
108108
}
109109

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

124124
this.unsubscribe = await client.queryMulti<[Vec<ArgonPrimitivesBlockSealMiningRegistration>, u64]>(
125-
[client.query.miningSlot.nextSlotCohort as any, client.query.miningSlot.nextCohortId as any],
126-
async ([next, nextCohortId]) => {
127-
if (nextCohortId.toNumber() === this.cohortId) {
125+
[client.query.miningSlot.bidsForNextSlotCohort as any, client.query.miningSlot.nextFrameId as any],
126+
async ([next, nextFrameId]) => {
127+
if (nextFrameId.toNumber() === this.cohortFrameId) {
128128
await this.checkSeats(next);
129129
}
130130
},
@@ -159,7 +159,7 @@ export class CohortBidder {
159159
}
160160
console.log(
161161
'Checking bids for cohort',
162-
this.cohortId,
162+
this.cohortFrameId,
163163
this.subaccounts.map(x => x.index),
164164
);
165165

@@ -192,7 +192,6 @@ export class CohortBidder {
192192
const fakeTx = await this.accountset.createMiningBidTx({
193193
subaccounts: this.subaccounts,
194194
bidAmount: nextBid,
195-
sendRewardsToSeed: true,
196195
});
197196
let availableBalanceForBids = await api.query.system
198197
.account(this.accountset.txSubmitterPair.address)
@@ -219,7 +218,7 @@ export class CohortBidder {
219218
}
220219

221220
if (nextBid - lowestBid < MIN_INCREMENT) {
222-
console.log(`Can't make any more bids for ${this.cohortId} with given constraints.`, {
221+
console.log(`Can't make any more bids for ${this.cohortFrameId} with given constraints.`, {
223222
lowestCurrentBid: formatArgons(lowestBid),
224223
nextAttemptedBid: formatArgons(nextBid),
225224
maxBid: formatArgons(this.options.maxBid),
@@ -285,7 +284,6 @@ export class CohortBidder {
285284
const submitter = await this.accountset.createMiningBidTx({
286285
subaccounts,
287286
bidAmount: bidPerSeat,
288-
sendRewardsToSeed: true,
289287
});
290288
const tip = this.options.tipPerTransaction ?? 0n;
291289
const txResult = await submitter.submit({
@@ -319,7 +317,7 @@ export class CohortBidder {
319317
if (bidError) throw bidError;
320318
} catch (err) {
321319
this.lastBidTime = prevLastBidTime;
322-
console.error(`Error bidding for cohort ${this.cohortId}:`, err);
320+
console.error(`Error bidding for cohort ${this.cohortFrameId}:`, err);
323321
clearTimeout(this.retryTimeout);
324322
this.retryTimeout = setTimeout(() => void this.checkCurrentSeats(), 1000);
325323
} finally {
@@ -334,7 +332,7 @@ export class CohortBidder {
334332

335333
private async checkCurrentSeats() {
336334
const client = await this.client;
337-
const next = await client.query.miningSlot.nextSlotCohort();
335+
const next = await client.query.miningSlot.bidsForNextSlotCohort();
338336
await this.checkSeats(next);
339337
}
340338
}

calculator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"type": "module",
77
"main": "src/index.ts",
88
"dependencies": {
9-
"@argonprotocol/mainchain": "^1.1.0"
9+
"@argonprotocol/mainchain": "1.3.2"
1010
}
1111
}

calculator/src/Mainchain.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,8 @@ export class Mainchain {
239239
public async fetchPreviousDayWinningBids(): Promise<bigint[]> {
240240
const client = await this.client;
241241
const currentFrameId = calculateCurrentFrameIdFromSystemTime();
242-
const activeMiners = await client.query.miningSlot.activeMinersByIndex.entries();
243-
const yesterdayWinningBids = activeMiners.filter(
244-
([_, x]: [any, Option<ArgonPrimitivesBlockSealMiningRegistration>]) => {
245-
return x.isSome && x.unwrap().cohortId.toNumber() === currentFrameId;
246-
},
247-
);
248-
return yesterdayWinningBids.map(([_, bid]) => bid.unwrap().bid.toBigInt());
242+
const yesterdayWinningBids = await client.query.miningSlot.minersByCohort(currentFrameId);
243+
return yesterdayWinningBids.map(bid => bid.bid.toBigInt());
249244
}
250245
}
251246

deploy/.env.mainnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BITCOIN_CONFIG=/etc/bitcoin/bitcoin.conf
44
BITCOIN_CHAIN=mainnet
55
BITCOIN_VERSION=28.1
66
# must match docker version
7-
ARGON_VERSION=v1.1.0
7+
ARGON_VERSION=v1.3.2
88
ARGON_DATA_FOLDER=${DATA_FOLDER}/argon
99
ARGON_CHAIN=mainnet
1010
ARGON_ARCHIVE_NODE=wss://rpc.argon.network

0 commit comments

Comments
 (0)