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 = ""
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"

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 {
projectDomain: string;
}
@ -51,6 +59,7 @@ export interface Config {
database: DatabaseConfig;
gitHub: GitHubConfig;
registryConfig: RegistryConfig;
auction: AuctionConfig;
misc: MiscConfig;
turnkey: {
apiBaseUrl: string;

View File

@ -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;
}

View File

@ -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;

View File

@ -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,
},

View File

@ -529,6 +529,7 @@ export class Service {
userId: string,
octokit: Octokit,
data: DeepPartial<Deployment>,
lrn?: string
): Promise<Deployment> {
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<Project>,
lrn?: string,
auctiondata?: AuctionData
): Promise<Project | undefined> {
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);

View File

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