Skip to content

Commit

Permalink
Merge pull request #7 from imashok02/ft-auction-contract-interaction
Browse files Browse the repository at this point in the history
feat: auction contract interaction
  • Loading branch information
imashok02 authored Mar 23, 2024
2 parents ea29784 + 408d1ec commit 62a3d73
Show file tree
Hide file tree
Showing 33 changed files with 1,121 additions and 87 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- ./:/app
- /app/node_modules
restart: 'unless-stopped'
entrypoint: [ "/app/wait-for.sh", "postgres:5432", "--", "sh", "-c", "node_modules/.bin/sequelize-cli db:migrate --env=test --config=/etc/secrets/db-config.json --migrations-path=src/migrations && npm run start:dev"]
entrypoint: [ "/app/wait-for.sh", "postgres:5432", "--", "sh", "-c", "node_modules/.bin/sequelize-cli db:migrate --env=production --config=/etc/secrets/db-config.json --migrations-path=src/migrations && npm run start:dev"]
networks:
- eth-network
depends_on:
Expand Down
99 changes: 99 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"ethers": "^6.11.1",
"express": "^4.18.3",
"joi": "^17.12.2",
"luxon": "^3.4.4",
"passport-jwt": "^4.0.1",
"pg": "^8.11.3",
"reflect-metadata": "^0.2.0",
Expand Down
19 changes: 19 additions & 0 deletions secrets_example/config/database.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"development": {
"username": "ashok",
"password": "secret",
"database": "eth",
"host": "localhost",
"dialect": "postgres",
"port": 5432
},
"production": {
"username": "ashok",
"password": "secret",
"database": "eth",
"host": "postgres",
"dialect": "postgres",
"port": 5432
}

}
3 changes: 3 additions & 0 deletions secrets_example/database.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_DB=eth
POSTGRES_USER=ashok
POSTGRES_PASSWORD=secret
29 changes: 29 additions & 0 deletions secrets_example/env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

NODE_ENV=production #DO NOT CHANGE

PORT=4000
VERSION=v1
ORIGIN=*

DB_USER=ashok
DB_PASSWORD=secret
DB_DATABASE=eth
DB_PORT=5432

DB_HOST=postgres #DO NOT CHANGE

JWT_SECRET=7LdPnw30KauR9jg63TJpw2BXixqrgo1j
JWT_EXPIRY=1d

LOCAL_NODE_PROVIDER_URL=http://127.0.0.1:8545

INFURA_API_KEY=
INFURA_PROJECT_ID=
INFURA_PROJECT_SECRET=

NETWORK_NAME=sepolia
CHAIN_ID=11155111


AUCTION_CONTRACT_ADDRESS=0x23436F18efEEcf9AB7210626940963F3d2549053 #Auction contract deployed on Sepolia testnet
# Contract url => https://sepolia.etherscan.io/address/0x23436F18efEEcf9AB7210626940963F3d2549053
16 changes: 12 additions & 4 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ import * as Joi from 'joi';
import { ConfigModule } from '@nestjs/config';
import { DatabaseModule } from './database/database.module';
import { UserModule } from './user/user.module';
import { AuthModule } from 'auth/auth.module';
import { AuthModule } from 'src/auth/auth.module';
import { AuctionModule } from './auction/auction.module';

@Module({
imports: [
ConfigModule.forRoot({
validationSchema: Joi.object({
NODE_ENV: Joi.string()
.required()
.valid('development', 'production', 'staging', 'provision')
.valid('development', 'production', 'test')
.default('development'),
PORT: Joi.number().required().default(3000),
VERSION: Joi.string().required().default(''),
PORT: Joi.number().required().default(4000),
INFURA_PROJECT_ID: Joi.string().required().default(''),
INFURA_PROJECT_SECRET: Joi.string().required().default(''),
NETWORK_NAME: Joi.string().required().default('sepolia'),
CHAIN_ID: Joi.string().required().default(11155111),
AUCTION_CONTRACT_ADDRESS: Joi.string()
.required()
.default('0x23436F18efEEcf9AB7210626940963F3d2549053'),
}),
}),
DatabaseModule,
AuthModule,
UserModule,
AuctionModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
114 changes: 114 additions & 0 deletions src/auction/auction.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';

import { AuctionService } from './auction.service';
import { JwtAuthGuard } from 'src/common/guards/jwt-auth.guard';
import {
AuctionBalanceDto,
AuctionBeneficiary,
AuctionEndTimeDto,
AuctionHighestBid,
AuctionHighestBidder,
AuctionStatsDto,
AuctionStatusDto,
BidDto,
} from './dto/auction-response-dto';
import { CurrentUser } from 'src/common/decorator/current-user.decorator';
import { User } from 'src/user/models/user.model';
import { PaginationDto } from 'src/common/dto/pagination.dto';

@ApiTags('Auction')
@Controller('auction')
export class AuctionController {
constructor(private readonly auctionService: AuctionService) {}

@Get('me')
@UseGuards(JwtAuthGuard)
async getMe() {
return {
id: 1,
name: 'ss',
email: 'asdsad',
};
}

@Get('beneficiary')
async auction(): Promise<AuctionBeneficiary> {
return this.auctionService.getBeneficiary();
}

@Get('interface')
async getAuctionInterface() {
return this.auctionService.getAuctionInterface();
}

@Get('highest-bid')
async getHighestBid(): Promise<AuctionHighestBid> {
return this.auctionService.getHighestBid();
}

@Get('highest-bidder')
async getHighestBidder(): Promise<AuctionHighestBidder> {
return this.auctionService.getHighestBidder();
}

@Get('end-time')
async getAuctionEndTime(): Promise<AuctionEndTimeDto> {
return this.auctionService.getAuctionEndTime();
}

@Get('status')
@UseGuards(JwtAuthGuard)
@ApiOkResponse({
description: 'To know the status of the auction',
type: AuctionStatusDto,
})
async auctionStatus(): Promise<AuctionStatusDto> {
return this.auctionService.auctionStatus();
}

@Get('balance')
@UseGuards(JwtAuthGuard)
@ApiOkResponse({
description: 'To know the available balance of the contract',
type: AuctionBalanceDto,
})
async auctionBalance(): Promise<AuctionBalanceDto> {
return this.auctionService.auctionBalance();
}

@Get('stats')
@ApiOkResponse({
description: 'To know the stats of the auction',
type: AuctionStatsDto,
})
async auctionStats(): Promise<AuctionStatsDto> {
return this.auctionService.auctionStats();
}

@Get('history')
@UseGuards(JwtAuthGuard)
async auctionHistory(@Query() paginationDto: PaginationDto) {
return this.auctionService.auctionHistory(paginationDto);
}

@Post('bid')
@UseGuards(JwtAuthGuard)
async bid(@CurrentUser() user: User, @Body() bidDto: BidDto) {
return this.auctionService.bid(user, bidDto);
}

@Get('balance')
async getBalance() {
return this.auctionService.getBalance();
}

@Get('my-balance')
@UseGuards(JwtAuthGuard)
async getMyBalance(
@CurrentUser() user: User,
@Query('address') address: string,
) {
return this.auctionService.getMyBalance(user, address);
}
}
16 changes: 16 additions & 0 deletions src/auction/auction.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';

import { AuctionController } from './auction.controller';
import { AuctionService } from './auction.service';
import { SequelizeModule } from '@nestjs/sequelize';
import { User } from 'src/user/models/user.model';
import { Bid } from './models/bid.model';

@Module({
imports: [SequelizeModule.forFeature([User, Bid]), ConfigModule],
controllers: [AuctionController],
providers: [AuctionService],
exports: [AuctionService],
})
export class AuctionModule {}
Loading

0 comments on commit 62a3d73

Please sign in to comment.