Skip to content

Commit

Permalink
fix: checks
Browse files Browse the repository at this point in the history
  • Loading branch information
EdSDR committed Oct 7, 2024
1 parent 35fe41a commit d92410a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 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 @@ -50,8 +51,8 @@ export async function upsertSubnetData(subnets: Subnet[]) {
maxRegistrationsPerInterval: s.maxRegistrationsPerInterval,
minValidatorStake: s.minValidatorStake,
maxAllowedValidators: s.maxAllowedValidators,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
atBlock: s.atBlock,

})),
)
.onConflictDoUpdate({
Expand Down
45 changes: 28 additions & 17 deletions apps/commune-worker/src/db/type-transformations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { SubspaceModule, NetworkSubnetConfig } from "@commune-ts/types";
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import type { NetworkSubnetConfig, SubspaceModule } from "@commune-ts/types";

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

Expand All @@ -25,8 +28,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 @@ -39,25 +44,31 @@ export function SubnetToDatabase(subnet: NetworkSubnetConfig, atBlock: number):
founderShare: subnet.founderShare,
incentiveRatio: subnet.incentiveRatio,
trustRatio: subnet.trustRatio,
maxWeightAge: subnet.maxWeightAge,
maxWeightAge: String(subnet.maxWeightAge),
bondsMa: subnet.bondsMovingAverage ?? null,
maximumSetWeightCallsPerEpoch: subnet.maximumSetWeightCallsPerEpoch ?? null,
minValidatorStake: subnet.minValidatorStake ?? null,
minValidatorStake: BigInt(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,
proposalCost: subnet.subnetGovernanceConfig.proposalCost,
minBurn: BigInt(subnet.moduleBurnConfig.minBurn),
maxBurn: BigInt(subnet.moduleBurnConfig.maxBurn),
adjustmentAlpha: String(subnet.moduleBurnConfig.adjustmentAlpha),
targetRegistrationsInterval:
subnet.moduleBurnConfig.targetRegistrationsInterval,
maxRegistrationsPerInterval:
subnet.moduleBurnConfig.maxRegistrationsPerInterval,
proposalCost: BigInt(subnet.subnetGovernanceConfig.proposalCost),
proposalExpiration: subnet.subnetGovernanceConfig.proposalExpiration,
maxProposalRewardTreasuryAllocation: subnet.subnetGovernanceConfig.maxProposalRewardTreasuryAllocation,
proposalRewardTreasuryAllocation: subnet.subnetGovernanceConfig.proposalRewardTreasuryAllocation,
proposalRewardInterval: subnet.subnetGovernanceConfig.proposalRewardInterval,
targetRegistrationsPerInterval: subnet.moduleBurnConfig.targetRegistrationsPerInterval,
subnetEmission: subnet.subnetEmission,
maxProposalRewardTreasuryAllocation: BigInt(
subnet.subnetGovernanceConfig.maxProposalRewardTreasuryAllocation,
),
proposalRewardTreasuryAllocation:
subnet.subnetGovernanceConfig.proposalRewardTreasuryAllocation,
proposalRewardInterval:
subnet.subnetGovernanceConfig.proposalRewardInterval,
targetRegistrationsPerInterval:
subnet.moduleBurnConfig.targetRegistrationsPerInterval,
atBlock: atBlock,
voteMode: subnet.subnetGovernanceConfig.voteMode,
};
}
}
2 changes: 1 addition & 1 deletion apps/commune-worker/src/workers/subnet-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function subnetFetcherWorker(props: WorkerProps) {
SubnetToDatabase(subnet, props.lastBlock.blockNumber),
);
log(
`Block ${props.lastBlock.blockNumber}: upserting ${subnetData.length} modules`,
`Block ${props.lastBlock.blockNumber}: upserting ${subnetData.length} subnets`,
);
await upsertSubnetData(subnetData);

Expand Down
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,7 +103,10 @@ 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(),
Expand All @@ -129,7 +132,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 All @@ -142,6 +148,7 @@ export const subnetDataSchema = createTable(
// Additional fields
minValidatorStake: bigint("min_validator_stake", { mode: "bigint" }),
maxAllowedValidators: integer("max_allowed_validators"),
// subnetEmission: bigint("subnet_emission", { mode: "bigint" }),
createdAt: timestamp("created_at").defaultNow().notNull(),
deletedAt: timestamp("deleted_at").default(sql`null`),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const buttonVariants = cva(
variant: {
base: "border",
default:
"hover:bg-background-green border border-white/20 bg-[#898989]/5 bg-background text-white hover:border-green-500 hover:text-green-500 active:bg-green-500/40",
"border border-white/20 bg-[#898989]/5 bg-background text-white hover:border-green-500 hover:bg-background-green hover:text-green-500 active:bg-green-500/40",
destructive:
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
ghost: "hover:bg-accent hover:text-accent-foreground",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SelectTrigger = React.forwardRef<
<SelectPrimitive.Trigger
ref={ref}
className={cn(
"hover:bg-background-green flex h-9 w-full items-center justify-between whitespace-nowrap border border-input border-white/20 bg-background px-3 py-2 text-sm shadow-sm ring-offset-background transition duration-200 placeholder:text-muted-foreground hover:border-green-500 hover:text-green-500 focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
"flex h-9 w-full items-center justify-between whitespace-nowrap border border-input border-white/20 bg-background px-3 py-2 text-sm shadow-sm ring-offset-background transition duration-200 placeholder:text-muted-foreground hover:border-green-500 hover:bg-background-green hover:text-green-500 focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
className,
)}
{...props}
Expand Down

0 comments on commit d92410a

Please sign in to comment.