From 0e0e5e888f5f88808e9e8847d22db0263bc0f279 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 4 Oct 2024 09:29:13 +0530 Subject: [PATCH] Take auction params from config --- .../backend/environments/local.toml.example | 13 ++++++++++--- packages/backend/src/config.ts | 9 +++++++++ packages/backend/src/entity/Deployment.ts | 8 ++------ packages/backend/src/entity/Project.ts | 15 +++++++++++++++ packages/backend/src/registry.ts | 19 ++++++++++--------- packages/backend/src/service.ts | 7 +++++-- packages/backend/src/types.ts | 5 ----- 7 files changed, 51 insertions(+), 25 deletions(-) diff --git a/packages/backend/environments/local.toml.example b/packages/backend/environments/local.toml.example index 25ba34cd..8c7374ef 100644 --- a/packages/backend/environments/local.toml.example +++ b/packages/backend/environments/local.toml.example @@ -36,9 +36,16 @@ bondId = "" authority = "" [registryConfig.fee] - gas = "200000" - fees = "200000alnt" - gasPrice = "" + gas = "" + fees = "" + gasPrice = "1" + +[auction] + commitFee = 1000 + commitsDuration = 60s + revealFee = 1000 + revealsDuration = 60s + denom = alnt [misc] projectDomain = "apps.snowballtools.com" diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index e326f9b0..b4a70c95 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -42,6 +42,14 @@ export interface RegistryConfig { }; } +export interface AuctionConfig { + commitFee: string; + commitsDuration: string; + revealFee: string; + revealsDuration: string; + denom: string; +} + export interface MiscConfig { projectDomain: string; } @@ -51,6 +59,7 @@ export interface Config { database: DatabaseConfig; gitHub: GitHubConfig; registryConfig: RegistryConfig; + auction: AuctionConfig; misc: MiscConfig; turnkey: { apiBaseUrl: string; diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index 3e3caaa6..39485ba5 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -28,17 +28,13 @@ export enum DeploymentStatus { Deleting = 'Deleting', } -export interface ApplicationDeploymentAuction { - application: string; - auction: string; - type: string; -} - export interface ApplicationDeploymentRequest { type: string; version: string; name: string; application: string; + lrn?: string; + auction?: string; config: string; meta: string; } diff --git a/packages/backend/src/entity/Project.ts b/packages/backend/src/entity/Project.ts index b46c219a..f7e23402 100644 --- a/packages/backend/src/entity/Project.ts +++ b/packages/backend/src/entity/Project.ts @@ -15,6 +15,12 @@ import { Organization } from './Organization'; import { ProjectMember } from './ProjectMember'; import { Deployment } from './Deployment'; +export interface ApplicationDeploymentAuction { + application: string; + auction: string; + type: string; +} + @Entity() export class Project { @PrimaryGeneratedColumn('uuid') @@ -46,6 +52,15 @@ export class Project { @Column('text', { default: '' }) description!: string; + @Column('varchar', { nullable: true }) + applicationDeploymentAuctionId?: string | null; + + @Column('simple-json', { nullable: true }) + applicationDeploymentAuctionData?: ApplicationDeploymentAuction | null; + + @Column('varchar', { nullable: true }) + deployerLrn?: string[] | null; + // TODO: Compute template & framework in import repository @Column('varchar', { nullable: true }) template!: string | null; diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 743c052d..6bf751e4 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -10,11 +10,11 @@ import { ApplicationRecord, Deployment, ApplicationDeploymentRequest, - ApplicationDeploymentRemovalRequest, - ApplicationDeploymentAuction + ApplicationDeploymentRemovalRequest } from './entity/Deployment'; import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionData, PackageJSON } from './types'; -import { sleep } from './utils'; +import { getConfig, sleep } from './utils'; +import { ApplicationDeploymentAuction } from './entity/Project'; const log = debug('snowball:registry'); @@ -168,16 +168,17 @@ export class Registry { throw new Error(`No record found for ${lrn}`); } + const config = await getConfig(); + const auctionConfig = config.auction; const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees); - // TODO: Take auction params from user const auctionResult = await this.registry.createProviderAuction( { - commitFee: auctionData.commitFee, - commitsDuration: auctionData.commitsDuration, - revealFee: auctionData.revealFee, - revealsDuration: auctionData.revealsDuration, - denom: auctionData.denom, + commitFee: auctionConfig.commitFee, + commitsDuration: auctionConfig.commitsDuration, + revealFee: auctionConfig.revealFee, + revealsDuration: auctionConfig.revealsDuration, + denom: auctionConfig.denom, maxPrice: auctionData.maxPrice, numProviders: auctionData.numProviders, }, diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 14361d5f..fb2b849c 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -529,6 +529,7 @@ export class Service { userId: string, octokit: Octokit, data: DeepPartial, + lrn?: string ): Promise { assert(data.project?.repository, 'Project repository not found'); log( @@ -633,6 +634,7 @@ export class Service { deployment: newDeployment, appName: repo, repository: repoUrl, + lrn, environmentVariables: environmentVariablesObj, dns: `${newDeployment.project.name}-${newDeployment.id}`, }); @@ -814,7 +816,7 @@ export class Service { repository: gitRepo.data.full_name, // TODO: Set selected template template: 'webapp', - }, auctionData); + }, '', auctionData); if (!project || !project.id) { throw new Error('Failed to create project from template'); @@ -831,6 +833,7 @@ export class Service { user: User, organizationSlug: string, data: DeepPartial, + lrn?: string, auctiondata?: AuctionData ): Promise { const organization = await this.db.getOrganization({ @@ -868,7 +871,7 @@ export class Service { const deployment = auctiondata ? await this.createDeploymentFromAuction(user.id, octokit, deploymentData, auctiondata) - : await this.createDeployment(user.id, octokit, deploymentData); + : await this.createDeployment(user.id, octokit, deploymentData, lrn); await this.createRepoHook(octokit, project); diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 66b10783..5f368c0b 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -71,11 +71,6 @@ export interface AddProjectFromTemplateInput { } export interface AuctionData { - commitFee: string, - commitsDuration: string, - revealFee: string, - revealsDuration: string, - denom: string, maxPrice: string, numProviders: number, }