Return funds if no winners are present

This commit is contained in:
IshaVenikar 2024-10-24 17:18:41 +05:30
parent 8dc9da3ca0
commit df6a492d07

View File

@ -213,7 +213,7 @@ export class Service {
const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId); const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId);
// Return remaining amount to owner // Return remaining amount to owner
await this.returnCreatorFundsByProjectId(deployment.projectId); await this.returnCreatorFundsByProjectId(deployment.projectId, true);
await this.db.updateProjectById(deployment.projectId, { await this.db.updateProjectById(deployment.projectId, {
fundsReleased, fundsReleased,
@ -312,6 +312,9 @@ export class Service {
if (!deployerRecords) { if (!deployerRecords) {
log(`No winning deployer for auction ${project!.auctionId}`); log(`No winning deployer for auction ${project!.auctionId}`);
// Return all funds to the owner
await this.returnCreatorFundsByProjectId(project.id, false)
} else { } else {
const deployers = await this.saveDeployersByDeployerRecords(deployerRecords); const deployers = await this.saveDeployersByDeployerRecords(deployerRecords);
for (const deployer of deployers) { for (const deployer of deployers) {
@ -1329,7 +1332,7 @@ export class Service {
return false; return false;
} }
async returnCreatorFundsByProjectId(projectId: string) { async returnCreatorFundsByProjectId(projectId: string, winningDeployersPresent: boolean) {
const project = await this.db.getProjectById(projectId); const project = await this.db.getProjectById(projectId);
if (!project || !project.auctionId) { if (!project || !project.auctionId) {
@ -1339,7 +1342,13 @@ export class Service {
} }
const auction = await this.getAuctionData(project.auctionId); const auction = await this.getAuctionData(project.auctionId);
const amountToBeReturned = auction.winnerPrice * auction.numProviders
let amountToBeReturned;
if (winningDeployersPresent) {
amountToBeReturned = auction.winnerPrice * auction.numProviders;
} else {
amountToBeReturned = auction.maxPrice * auction.numProviders;
}
await this.laconicRegistry.sendTokensToAccount( await this.laconicRegistry.sendTokensToAccount(
project.paymentAddress, project.paymentAddress,