DEV Community

Matteo Leonesi
Matteo Leonesi

Posted on • Updated on

 

Smart Contract that simulate Animal Crossing (nintendo game)

Smart Contracts Automatic Bell Dispenser

Bank System simulation in Animal Crossing Nintendo Game




tests

About The Project

This project is composed by smart contracts that simulate Animal Crossing banking system, Animal Crossing is a social simulation video game series developed and published by Nintendo, where the user can buy and sell things having a bank account.We created smart contracts for 2 tokens inside the game, Bell & Miles (ERC20 standards), and 1 contract to simulate all game's functionalities. We also adding a script for deploy them and tests (obviously).

link Repository, leave a follow please.

Built With

Getting Started with Hardhat

npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
node scripts/TomNookATM.js
npx hardhat help
Enter fullscreen mode Exit fullscreen mode

Functionalities

Bells & Miles (ERC20 standard)

Nook Miles are a type of currency in New Horizons that work similar to airline mileage programs in real life. Players earn Nook Miles from travel and participating in activities around the Deserted Island. Additionally, players can also get Nook Miles from completing tasks and stamp cards in the Nook Miles app section of the NookPhone. Since 500 Nook Miles can be redeemed for a 3,000 Bells voucher in the Nook Stop, 1 Nook Miles is worth 6 Bells.

Bells are the main currency used in the Animal Crossing series. Although most frequently used to purchase items from stores and pay off the player's mortgage, Bells may also be used in several other respects, including trading with villagers and other services.




import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

//Bell.sol

contract Bell is ERC20 {
    constructor() ERC20("Bell", "BLL") {
        _mint(msg.sender, 1000000 * (10**uint256(decimals())));
    }
}

//Miles.sol

contract Miles is ERC20 {
    constructor() ERC20("Miles", "MLS") {
        _mint(msg.sender, 100 * (10**uint256(decimals())));
    }
}


Enter fullscreen mode Exit fullscreen mode

Pay Debts

Mortgages are the number of Bells that the player owes Tom Nook for constructing and expanding their house. There are several mortgages to pay off.




    address payable TomNook;
    mapping(address => uint256) userDebt;

    function payDebts(uint256 _amount) external accountExists {
        if (userDebt[msg.sender] == 0) {
            console.log(
                "extinguished corredebts! Congratulations ! you have finished paying your home loan !  "
            );
        } else {
            //tracking
            claimInterests();
            accounts[msg.sender].balances[address(bell)] -= _amount;
            userDebt[msg.sender] -= _amount;
            bell.transfer(TomNook, _amount);
        }
    }

Enter fullscreen mode Exit fullscreen mode

Bell voucher Dex

The Bell voucher is a new redeemable item in New Horizons. They can be redeemed from the Nook Stop in the Resident Services Tent or Building. They cost 500 Nook Miles, and are sold for 3,000 Bells. They have no uses other than as a way to convert Nook Miles into Bells.




    function BellVaucherDex(uint256 _amount) external {
        accounts[msg.sender].balances[address(miles)] -= _amount; 
        bell.transferFrom(TomNook, msg.sender, _amount * 6);
    }
Enter fullscreen mode Exit fullscreen mode

Automatic Bell Dispenser

interest is deposited into the player's savings on the first of each month 0.5% (0.05% in New Horizons). The ABD was first added in City Folk, and has appeared in all main series games since then.






    function claimInterests() public {
        uint256 rate = ((block.timestamp -
            accounts[msg.sender].timestampForInterests) * 100) / 1 days;
        uint256 interests = (accounts[msg.sender].balances[address(bell)] *
            rate) / 600_000;   
        bell.transferFrom(TomNook, msg.sender, interests);
    }
Enter fullscreen mode Exit fullscreen mode

Other Functionalities Added

  • Create Account
  • Close Account
  • Deposit
  • Withdraw
  • Get Balance for each token
  • accountExists, onlyValidTokens, OnlyMilesForVaucher Modifiers

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again! ❤️

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Top comments (0)

12 APIs That You Will Love

Free and easy to use APIs for your next project, learning a new technology, or building a new feature.