Integrate SP auctions for app deployment #2

Merged
nabarun merged 42 commits from ng-integrate-auction into main 2024-10-18 12:37:01 +00:00
7 changed files with 51 additions and 25 deletions
Showing only changes of commit 0e0e5e888f - Show all commits

View File

@ -36,9 +36,16 @@
bondId = "" bondId = ""
authority = "" authority = ""
[registryConfig.fee] [registryConfig.fee]
gas = "200000" gas = ""
fees = "200000alnt" fees = ""
gasPrice = "" gasPrice = "1"
[auction]
commitFee = 1000
commitsDuration = 60s
revealFee = 1000
revealsDuration = 60s
denom = alnt
[misc] [misc]
projectDomain = "apps.snowballtools.com" projectDomain = "apps.snowballtools.com"

View File

@ -42,6 +42,14 @@ export interface RegistryConfig {
}; };
} }
export interface AuctionConfig {
commitFee: string;
commitsDuration: string;
revealFee: string;
revealsDuration: string;
denom: string;
}
export interface MiscConfig { export interface MiscConfig {
projectDomain: string; projectDomain: string;
} }
@ -51,6 +59,7 @@ export interface Config {
database: DatabaseConfig; database: DatabaseConfig;
gitHub: GitHubConfig; gitHub: GitHubConfig;
registryConfig: RegistryConfig; registryConfig: RegistryConfig;
auction: AuctionConfig;
misc: MiscConfig; misc: MiscConfig;
turnkey: { turnkey: {
apiBaseUrl: string; apiBaseUrl: string;

View File

@ -28,17 +28,13 @@ export enum DeploymentStatus {
Deleting = 'Deleting', Deleting = 'Deleting',
} }
export interface ApplicationDeploymentAuction {
application: string;
auction: string;
type: string;
}
export interface ApplicationDeploymentRequest { export interface ApplicationDeploymentRequest {
type: string; type: string;
version: string; version: string;
name: string; name: string;
application: string; application: string;
lrn?: string;
auction?: string;
config: string; config: string;
meta: string; meta: string;
} }

View File

@ -15,6 +15,12 @@ import { Organization } from './Organization';
import { ProjectMember } from './ProjectMember'; import { ProjectMember } from './ProjectMember';
import { Deployment } from './Deployment'; import { Deployment } from './Deployment';
export interface ApplicationDeploymentAuction {
application: string;
auction: string;
type: string;
}
@Entity() @Entity()
export class Project { export class Project {
@PrimaryGeneratedColumn('uuid') @PrimaryGeneratedColumn('uuid')
@ -46,6 +52,15 @@ export class Project {
@Column('text', { default: '' }) @Column('text', { default: '' })
description!: string; 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 // TODO: Compute template & framework in import repository
@Column('varchar', { nullable: true }) @Column('varchar', { nullable: true })
template!: string | null; template!: string | null;

View File

@ -10,11 +10,11 @@ import {
ApplicationRecord, ApplicationRecord,
Deployment, Deployment,
ApplicationDeploymentRequest, ApplicationDeploymentRequest,
ApplicationDeploymentRemovalRequest, ApplicationDeploymentRemovalRequest
ApplicationDeploymentAuction
} from './entity/Deployment'; } from './entity/Deployment';
import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionData, PackageJSON } from './types'; 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'); const log = debug('snowball:registry');
@ -168,16 +168,17 @@ export class Registry {
throw new Error(`No record found for ${lrn}`); 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); const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
// TODO: Take auction params from user
const auctionResult = await this.registry.createProviderAuction( const auctionResult = await this.registry.createProviderAuction(
{ {
commitFee: auctionData.commitFee, commitFee: auctionConfig.commitFee,
commitsDuration: auctionData.commitsDuration, commitsDuration: auctionConfig.commitsDuration,
revealFee: auctionData.revealFee, revealFee: auctionConfig.revealFee,
revealsDuration: auctionData.revealsDuration, revealsDuration: auctionConfig.revealsDuration,
denom: auctionData.denom, denom: auctionConfig.denom,
maxPrice: auctionData.maxPrice, maxPrice: auctionData.maxPrice,
numProviders: auctionData.numProviders, numProviders: auctionData.numProviders,
}, },

View File

@ -529,6 +529,7 @@ export class Service {
userId: string, userId: string,
octokit: Octokit, octokit: Octokit,
data: DeepPartial<Deployment>, data: DeepPartial<Deployment>,
lrn?: string
): Promise<Deployment> { ): Promise<Deployment> {
assert(data.project?.repository, 'Project repository not found'); assert(data.project?.repository, 'Project repository not found');
log( log(
@ -633,6 +634,7 @@ export class Service {
deployment: newDeployment, deployment: newDeployment,
appName: repo, appName: repo,
repository: repoUrl, repository: repoUrl,
lrn,
environmentVariables: environmentVariablesObj, environmentVariables: environmentVariablesObj,
dns: `${newDeployment.project.name}-${newDeployment.id}`, dns: `${newDeployment.project.name}-${newDeployment.id}`,
}); });
@ -814,7 +816,7 @@ export class Service {
repository: gitRepo.data.full_name, repository: gitRepo.data.full_name,
// TODO: Set selected template // TODO: Set selected template
template: 'webapp', template: 'webapp',
}, auctionData); }, '', auctionData);
if (!project || !project.id) { if (!project || !project.id) {
throw new Error('Failed to create project from template'); throw new Error('Failed to create project from template');
@ -831,6 +833,7 @@ export class Service {
user: User, user: User,
organizationSlug: string, organizationSlug: string,
data: DeepPartial<Project>, data: DeepPartial<Project>,
lrn?: string,
auctiondata?: AuctionData auctiondata?: AuctionData
): Promise<Project | undefined> { ): Promise<Project | undefined> {
const organization = await this.db.getOrganization({ const organization = await this.db.getOrganization({
@ -868,7 +871,7 @@ export class Service {
const deployment = auctiondata const deployment = auctiondata
? await this.createDeploymentFromAuction(user.id, octokit, deploymentData, 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); await this.createRepoHook(octokit, project);

View File

@ -71,11 +71,6 @@ export interface AddProjectFromTemplateInput {
} }
export interface AuctionData { export interface AuctionData {
commitFee: string,
commitsDuration: string,
revealFee: string,
revealsDuration: string,
denom: string,
maxPrice: string, maxPrice: string,
numProviders: number, numProviders: number,
} }