# Dutch Auction Smart Contract

## Overview

This Solidity smart contract implements a Dutch Auction, a type of auction where the price starts high and gradually
decreases until a buyer accepts the current price. The contract supports multiple auction items with customizable
parameters.

## Function

1. Constructor
   Initializes the contract with the specified parameters, creating a list of auction items.

2. getCurrentPrice
   Returns the current price of the current auction item.

3. buy
   Buys the current auction item.

4. getStartTimestamp
   Returns the start timestamp of the current auction item.

5. recoverFunds
   Recuperates the funds of the auction items.

## Deployment

1. Compile the smart contract using truffle

```shell
truffle compile
```

2. Deploy the smart contract to a local blockchain

```shell
truffle migrate --network ganache
```

3. Interact with the smart contract using truffle console

```shell
truffle console --network ganache
```

Recuperate the contract instance

```javascript
let dutchAuction = await DutchAuction.deployed()
```

Recuperate the current price

```javascript
let getAllAuctionItems = await dutchAuction.getAllAuctionItems.call();
console.log("getAllAuctionItems:", getAllAuctionItems.toString());
```

Buy the item at the current price

```javascript
let currentPrice = await dutchAuction.getCurrentPrice.call();
console.log("Current Price:", currentPrice.toString());

let buyer = accounts[0];
let buyingPrice = currentPrice;
await dutchAuction.buy({from: buyer, value: buyingPrice});
```

Recuperate the current price

```javascript
currentPrice = await dutchAuction.getCurrentPrice.call();
console.log("Current Price:", currentPrice.toString());
```

Buy the item at the current price

```javascript
buyingPrice = currentPrice;
await dutchAuction.buy({from: buyer, value: buyingPrice});
```

Recuverate the funds

```javascript
let vendor = accounts[0];
await dutchAuction.recoverFunds({from: vendor});
```

### Testing

1. Run the tests

```shell
truffle test
```

![Tests](./../images/test.png)