Skip to content

decentramall/contracts

Repository files navigation

Contracts

This section contains the Ethereum smart contracts for the Decentramall Project. We use Truffle as a development environment for compiling, testing, and deploying our contracts. They were written in Solidity.

Build Status

About

The idea is for an owner to purchase a retail SPACE whose price follows a bonding curve. An owner can only own one SPACE token, preventing anyone from gaining control of the entire mall by purchasing all the SPACE available

Breakdown

🌌 SPACE Token

The price of SPACE tokens follow a Sigmoid function curve. This is because we want the price to increase rapidly near the beginning, but stabilize at the end. This means that if you are an early adopter, you will be rewarded. This also benefits late comers as they will not suffer an insane price that comes with quadratic curves. Each space is unique to and only one owner can own ONE(1) SPACE. This is to avoid monopolies. Since the SPACE tokens have to be minted only when a buyer exists, the bonding curve requires a slight modification to its implementation. It allows for continuous minting of tokens but only up to a certain threshold which is declared during initialization under currentLimit.

To achieve the unique one-of-a-kind ownership and restriction, the ERC721 tokenID is based a keccak256 hash of the owner's address, making it impossible for an owner to mint an ERC721 token twice.

💵 Staking & Rental

For a SPACE to be made available to rent, it has to be deposited and staked for a period of time. During this stake period, renters will be able to rent as long as they want until the final block number as found in maxRentableBlock. The minimum stake duration is 2 months, roughly 375428 blocks. For rents, the minimum duration is 1 month, roughtly 187714. This is to avoid the issue where a SPACE becomes ineligible for rent after roughly 14 seconds (1 block).

To find the price of rent, we can refer to the equation below. Generally, rent will cost 1/10 the price to purchase a new SPACE per year.

rentPrice = (rentDuration * buyPrice) / (2252571 * 10)

where 2252571 is roughly 1 year with a 14 second block time

Installation

$ npm install

Usage

To start a local network and deploy contracts, using npm run devenv should be enough, but in case it fails, you can start it by hand doing the following.

First start a Ganache network with npx ganache-cli --mnemonic "hood return pride refuse resemble connect initial" --gasLimit 0xfffffffffff --networkId 1337 --port 8545.

Leave that running and deploy the contracts with npx truffle deploy --network development --reset.

In order to make it work with the webui, you also need to run npm run generate-types, because the UI uses types for easier and safer development.

Test & Coverage

To run tests, make sure to use the ForTesting.sol!

$ npm run test
$ npm run coverage

Testnet Contract Address

  • Rinkeby
    • FixedMath.sol (Custom int256 library to handle fixed point numbers & square root. Some inspiration drawn from FixidityLib)
      • Contract Address: 0x6985897120ca08f1CEAC3C8F909F6bfC9D6F4aa7
    • DAI.sol (Custom DAI to try out purchasing SPACE)
      • Contract Address: 0xe7e8F9a8648581433710105C380cE71771422d08
    • Decentramall.sol (The real deal)
      • Contract Address: 0x31263af02f40Aa9479eCb7e1c890999863b69725