Skip to content

Commit

Permalink
♻️ fixing types and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
PsicoThePato committed Oct 7, 2024
1 parent adcc015 commit e3fca29
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
7 changes: 4 additions & 3 deletions apps/commune-worker/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

export type NewVote = typeof daoVoteSchema.$inferInsert;
export type Module = typeof moduleData.$inferInsert;
export type Subnet = typeof subnetDataSchema.$inferInsert
export type Subnet = typeof subnetDataSchema.$inferInsert;

export type NewNotification = typeof governanceNotificationSchema.$inferInsert;

Expand Down Expand Up @@ -40,7 +40,8 @@ export async function upsertSubnetData(subnets: Subnet[]) {
proposalExpiration: s.proposalExpiration,
voteMode: s.voteMode,
proposalRewardTreasuryAllocation: s.proposalRewardTreasuryAllocation,
maxProposalRewardTreasuryAllocation: s.maxProposalRewardTreasuryAllocation,
maxProposalRewardTreasuryAllocation:
s.maxProposalRewardTreasuryAllocation,
proposalRewardInterval: s.proposalRewardInterval,
minBurn: s.minBurn,
maxBurn: s.maxBurn,
Expand All @@ -51,7 +52,7 @@ export async function upsertSubnetData(subnets: Subnet[]) {
minValidatorStake: s.minValidatorStake,
maxAllowedValidators: s.maxAllowedValidators,
atBlock: s.atBlock,

subnetEmission: s.subnetEmission,
})),
)
.onConflictDoUpdate({
Expand Down
30 changes: 19 additions & 11 deletions apps/commune-worker/src/db/type-transformations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SubspaceModule, NetworkSubnetConfig } from "@commune-ts/types";
import type { NetworkSubnetConfig, SubspaceModule } from "@commune-ts/types";

import type { Module, Subnet } from "./index.js";

Expand All @@ -25,8 +25,10 @@ export function SubspaceModuleToDatabase(
};
}


export function SubnetToDatabase(subnet: NetworkSubnetConfig, atBlock: number): Subnet {
export function SubnetToDatabase(
subnet: NetworkSubnetConfig,
atBlock: number,
): Subnet {
return {
netuid: subnet.netuid,
name: subnet.subnetNames,
Expand All @@ -42,22 +44,28 @@ export function SubnetToDatabase(subnet: NetworkSubnetConfig, atBlock: number):
maxWeightAge: subnet.maxWeightAge,
bondsMa: subnet.bondsMovingAverage ?? null,
maximumSetWeightCallsPerEpoch: subnet.maximumSetWeightCallsPerEpoch ?? null,
minValidatorStake: subnet.minValidatorStake ?? null,
minValidatorStake: subnet.minValidatorStake,
maxAllowedValidators: subnet.maxAllowedValidators ?? null,
subnetMetadata: subnet.subnetMetadata,
minBurn: subnet.moduleBurnConfig.minBurn,
maxBurn: subnet.moduleBurnConfig.maxBurn,
adjustmentAlpha: subnet.moduleBurnConfig.adjustmentAlpha,
targetRegistrationsInterval: subnet.moduleBurnConfig.targetRegistrationsInterval,
maxRegistrationsPerInterval: subnet.moduleBurnConfig.maxRegistrationsPerInterval,
targetRegistrationsInterval:
subnet.moduleBurnConfig.targetRegistrationsInterval,
maxRegistrationsPerInterval:
subnet.moduleBurnConfig.maxRegistrationsPerInterval,
proposalCost: subnet.subnetGovernanceConfig.proposalCost,
proposalExpiration: subnet.subnetGovernanceConfig.proposalExpiration,
maxProposalRewardTreasuryAllocation: subnet.subnetGovernanceConfig.maxProposalRewardTreasuryAllocation,
proposalRewardTreasuryAllocation: subnet.subnetGovernanceConfig.proposalRewardTreasuryAllocation,
proposalRewardInterval: subnet.subnetGovernanceConfig.proposalRewardInterval,
targetRegistrationsPerInterval: subnet.moduleBurnConfig.targetRegistrationsPerInterval,
maxProposalRewardTreasuryAllocation:
subnet.subnetGovernanceConfig.maxProposalRewardTreasuryAllocation,
proposalRewardTreasuryAllocation:
subnet.subnetGovernanceConfig.proposalRewardTreasuryAllocation,
proposalRewardInterval:
subnet.subnetGovernanceConfig.proposalRewardInterval,
targetRegistrationsPerInterval:
subnet.moduleBurnConfig.targetRegistrationsPerInterval,
subnetEmission: subnet.subnetEmission,
atBlock: atBlock,
voteMode: subnet.subnetGovernanceConfig.voteMode,
};
}
}
13 changes: 10 additions & 3 deletions packages/db/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
bigint,
index,
integer,
numeric,
pgEnum,
pgTableCreator,
pgView,
real,
serial,
numeric,
text,
timestamp,
unique,
Expand Down Expand Up @@ -103,14 +103,18 @@ export const subnetDataSchema = createTable(
minAllowedWeights: integer("min_allowed_weights").notNull(),
maxAllowedWeights: integer("max_allowed_weights").notNull(),
maxAllowedUids: integer("max_allowed_uids").notNull(),
maxWeightAge: numeric("max_weight_age", { precision: 20, scale: 0 }).notNull(),
maxWeightAge: numeric("max_weight_age", {
precision: 20,
scale: 0,
}).notNull(),
trustRatio: integer("trust_ratio").notNull(),
founderShare: integer("founder_share").notNull(),
incentiveRatio: integer("incentive_ratio").notNull(),
founder: ss58Address("founder").notNull(),
maximumSetWeightCallsPerEpoch: integer(
"maximum_set_weight_calls_per_epoch",
),
subnetEmission: bigint("subnet_emission", { mode: "bigint" }).notNull(),
bondsMa: integer("bonds_ma"),
immunityPeriod: integer("immunity_period").notNull(),
subnetMetadata: text("subnet_metadata"),
Expand All @@ -129,7 +133,10 @@ export const subnetDataSchema = createTable(
// BurnConfiguration fields
minBurn: bigint("min_burn", { mode: "bigint" }).notNull(),
maxBurn: bigint("max_burn", { mode: "bigint" }).notNull(),
adjustmentAlpha: numeric("adjustment_alpha", { precision: 20, scale: 0 }).notNull(),
adjustmentAlpha: numeric("adjustment_alpha", {
precision: 20,
scale: 0,
}).notNull(),
targetRegistrationsInterval: integer(
"target_registrations_interval",
).notNull(),
Expand Down
16 changes: 8 additions & 8 deletions packages/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,18 @@ export interface UnrewardedProposal {

export type NetworkSubnetConfig = z.infer<typeof NetworkSubnetConfigSchema>;
export const GOVERNANCE_CONFIG_SCHEMA = z.object({
proposalCost: z.coerce.number().int(),
proposalCost: z.coerce.bigint(),
voteMode: z.string(),
maxProposalRewardTreasuryAllocation: z.coerce.number().int(),
maxProposalRewardTreasuryAllocation: z.coerce.bigint(),
proposalRewardInterval: z.coerce.number().int(),
proposalRewardTreasuryAllocation: z.coerce.number(),
proposalExpiration: z.coerce.number().int(),
});

export const MODULE_BURN_CONFIG_SCHEMA = z.object({
minBurn: z.coerce.number().int(),
maxBurn: z.coerce.number().int(),
adjustmentAlpha: z.coerce.number().int(),
minBurn: z.coerce.bigint(),
maxBurn: z.coerce.bigint(),
adjustmentAlpha: z.coerce.string(),
targetRegistrationsInterval: z.coerce.number().int(),
targetRegistrationsPerInterval: z.coerce.number().int(),
maxRegistrationsPerInterval: z.coerce.number().int(),
Expand All @@ -275,14 +275,14 @@ export const NetworkSubnetConfigSchema = z.object({
founderShare: z.coerce.number(),
incentiveRatio: z.coerce.number().int(),
trustRatio: z.coerce.number().int(),
maxWeightAge: z.coerce.number().int(),
maxWeightAge: z.coerce.string(),
bondsMovingAverage: z.coerce.number().int().optional(),
maximumSetWeightCallsPerEpoch: z.coerce.number().int().optional(),
minValidatorStake: z.coerce.number().int(),
minValidatorStake: z.coerce.bigint(),
maxAllowedValidators: z.coerce.number().int().optional(),
moduleBurnConfig: MODULE_BURN_CONFIG_SCHEMA,
subnetGovernanceConfig: GOVERNANCE_CONFIG_SCHEMA,
subnetEmission: z.coerce.number().int(),
subnetEmission: z.coerce.bigint(),
subnetMetadata: z.string().optional(),
});

Expand Down

0 comments on commit e3fca29

Please sign in to comment.