0% found this document useful (0 votes)
4 views24 pages

Project Progress Report

The project report details the development of a Token Staking Decentralized Application (DApp) aimed at enhancing user engagement in decentralized finance (DeFi) through secure and transparent staking mechanisms. Utilizing Solidity smart contracts, the DApp allows users to stake ERC20 tokens and earn rewards, with features including real-time reward calculations and a user-friendly interface. The report outlines the project's objectives, methodology, and future plans, emphasizing its innovative approach to address existing challenges in the DeFi ecosystem.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views24 pages

Project Progress Report

The project report details the development of a Token Staking Decentralized Application (DApp) aimed at enhancing user engagement in decentralized finance (DeFi) through secure and transparent staking mechanisms. Utilizing Solidity smart contracts, the DApp allows users to stake ERC20 tokens and earn rewards, with features including real-time reward calculations and a user-friendly interface. The report outlines the project's objectives, methodology, and future plans, emphasizing its innovative approach to address existing challenges in the DeFi ecosystem.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

A Project Progress Report

On
Token Staking Decentralized Application

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND DESIGN

Submitted by:

SANKAR NAYAK (12031521050)


ANUPAM NANDI (12031521051)

Under the guidance of


Prof. Nasim Anjum Hoque
(Assistant Professor, CSD)

DEPT. OF COMPUTER SCIENCE & DESIGN


DR. B.C. ROY ENGINEERING COLLEGE

1
CERTIFICATE OF APPROVAL

This is to certify that the project report titled “Token Staking Decentralized Application,”
submitted by: SANKAR NAYAK (12031521050), ANUPAM NANDI (12031521051) has
been carried out under my guidance and supervision in partial fulfilment of the
requirements for the degree of Bachelor of Technology in Computer Science and Design at
Dr. B.C. Roy Engineering College.

____________________ _____________________
Prof. Nasim Anjum Hoque Dr. Raj Kumar Samanta
(Assistant Professor, CSD) (Head of Department, CSD)

2
UNDERTAKING

We, the undersigned, hereby declare that the work presented in this project report titled
“Token Staking dApp” is our original work and has not been submitted elsewhere in any
form. We further declare that all sources of information used in this project have been duly
acknowledged.

_________________________________

SANKAR NAYAK (12031521050)

________________________________

ANUPAM NANDI (12031521051)

3
ACKNOWLEDGEMENT

We express our deepest gratitude to Prof. Nasim Anjum Hoque (Assistant Professor) for
his invaluable guidance, support, and encouragement throughout the development of this
staking DApp project. His expertise and insights have played a pivotal role in shaping our
understanding of blockchain principles and the execution of this project.

We also extend our heartfelt thanks to our Head of the Department, Dr. Raj Kumar
Samanta, for providing us with the opportunity to embark on this innovative project. His
unwavering motivation and approval of our ideas have inspired us to explore the
transformative potential of decentralized applications in the DeFi space.

We sincerely acknowledge the resources and support extended by our department, which
have been instrumental in enabling us to address challenges in the staking and rewards
ecosystem through this project.

Lastly, we are thankful to our peers and faculty members for their constructive suggestions
and feedback, which have greatly contributed to the refinement and success of this project.
The completion of this initiative is a testament to the collective efforts of everyone
involved, and we deeply appreciate their contributions.

4
ABSTRACT

Blockchain technology has revolutionized traditional financial systems by enabling


decentralized and trustless environments. This project focuses on the development of a
decentralized token staking application, leveraging smart contracts written in Solidity. The
DApp allows users to stake ERC20 tokens (StakeToken) in exchange for rewards in a
separate ERC20 token (RewardToken). The smart contract incorporates functionalities for
secure staking, reward distribution, and token withdrawals, ensuring user funds are
managed transparently and efficiently. Key features include real-time reward calculations
based on staked amounts and time, utilizing the OpenZeppelin library for security and the
SafeMath utility for accurate computation. The DApp's frontend facilitates a user-friendly
interface for interacting with the staking system, ensuring seamless user experience. The
project highlights the use of blockchain principles to enhance transparency, reduce
intermediaries, and automate trust in reward-based systems. This report explores the
technical design, implementation pipeline, and future enhancements for scalability and
integration with decentralized finance (DeFi) ecosystems.

5
INDEX

1. Introduction.......................................................................................... Page No. 8 - 9


2. Overview and Proposed Work................................................................ Page No. 10
3. Related Work........................................................................................... Page No. 11
4. Methodology.................................................................................... Page No. 12 - 18
5. Proposed Method............................................................................. Page No. 19 - 20
6. Future Plans..................................................................................... Page No. 21 - 23
7. References............................................................................................... Page No. 24

6
LIST OF FIGURES

Fig 1: Smart Contract Interaction In RemixIde .................................................. Page No. 15

Fig 2: Frontend Development ............................................................................ Page No. 16

Fig 3: Abi Integration ......................................................................................... Page No. 17

Fig 4: MetaMask Wallet ..................................................................................... Page No. 18

7
1. INTRODUCTION

Blockchain technology has ushered in a new era of decentralized finance (DeFi), where
financial systems operate transparently and without central intermediaries. Among the
many innovations brought about by DeFi, staking platforms have emerged as a crucial
component, allowing users to earn rewards by participating actively in network security
and consensus mechanisms. This project focuses on the development of a staking smart
contract—a key infrastructure enabling token holders to lock up their tokens and earn
rewards in a decentralized and trustless manner.

1.1 Background
With the rapid adoption of blockchain technology, decentralized applications (DApps)
have emerged as a cornerstone of trustless systems, offering efficiency, transparency, and
security. Among these, token staking has gained popularity in decentralized finance (DeFi)
for enabling users to earn rewards by committing tokens to a protocol. Traditional
financial systems often fail to provide such open, accessible, and automated opportunities.
This project addresses these gaps by developing a secure, efficient, and user-friendly
staking application utilizing Solidity smart contracts.

By offering an ERC20-based staking mechanism, the system allows users to stake tokens
(StakeToken) and earn rewards (RewardToken) based on their contributions and staking
duration. OpenZeppelin libraries ensure security, while advanced computational
techniques like real-time reward calculation improve user interaction and accuracy.

1.2 Significance of the Project


Staking platforms represent a pivotal shift in decentralized finance by:

• By allowing token holders to actively engage with the ecosystem, staking increases
the token’s intrinsic utility and promotes user participation.
• Staking locks up tokens, reducing circulating supply and contributing to price
stability, while also encouraging user involvement in blockchain projects.

8
• ERC20 token standards ensure compatibility with wallets and exchanges, offering
users an integrated experience across DeFi applications.
• Real-time reward calculations improve transparency, providing users with clear
insights into their staking outcomes.
• Security mechanisms such as OpenZeppelin’s ReentrancyGuard ensure robust
protection against common vulnerabilities like reentrancy attacks.
• It fosters a trustless and transparent ecosystem where users can interact directly
with smart contracts, eliminating intermediaries.

Through the implementation of this staking system, the project aims to address key
challenges in current DeFi platforms, such as security risks, high gas fees, and limited
scalability, to provide a user-friendly and efficient solution.

1.3 Objectives
The project aims to:
• Develop a secure and transparent ERC20 token staking and reward distribution
system.
• Implement dynamic reward calculation mechanisms based on staking time and
token contributions.
• Leverage OpenZeppelin libraries for robust security features and efficient token
handling.
• Create a responsive and intuitive frontend interface for seamless user interaction
with the staking platform.
• Ensure scalability and compatibility within decentralized ecosystems.

9
2. OVERVIEW AND PROPOSED WORK

2.1 Project Scope


The goal of the staking decentralized application (DApp) is to provide a transparent and
user-friendly platform for token staking and reward distribution. Current staking platforms
often face challenges like lack of transparency, inefficient gas usage, and limited flexibility
for users. Our proposed work seeks to address these challenges by:
• Providing a secure and efficient token staking mechanism.
• Integrating customizable reward systems to incentivize long-term engagement.
• Offering users real-time visibility into their staking performance and rewards.

2.2 Core Components


a) Transparent and Secure Smart Contracts
The backbone of the platform lies in its Solidity-based smart contracts. These contracts
handle staking logic, reward distribution, and withdrawal processes securely, ensuring trust
and preventing vulnerabilities. All transactions and data are logged on-chain for complete
transparency.
b) Dynamic Reward Mechanism
The DApp features a flexible reward system that calculates and distributes rewards
dynamically based on staking duration and user contributions. This encourages active
participation while maintaining gas efficiency.
c) Real-Time Performance Tracking
Users have access to a dashboard where they can monitor staking activity and view
accrued rewards. The integration of frontend frameworks like [Link] ensures a
responsive and seamless user experience.
d) Scalability and Extensibility
The project is designed with scalability in mind, enabling future upgrades to support
additional tokens, multichain compatibility, or governance features. These improvements
will ensure the platform adapts to evolving user needs and market trends.
In conclusion, the staking DApp combines cutting-edge blockchain principles and a user-
centric design to create a robust and transparent platform. This approach not only enhances
the DeFi staking ecosystem but also lays the foundation for ongoing innovation.

10
3. RELATED WORK

The concept of token staking has been explored extensively in the blockchain ecosystem,
with various projects implementing staking mechanisms for decentralization, network
security, and user engagement. Platforms such as Ethereum 2.0, Cardano, and Polkadot
leverage staking to incentivize users for contributing to consensus and network operations.
However, these systems are primarily infrastructure-level staking solutions and lack an
application-specific focus.

DeFi platforms such as Aave, Uniswap, and Compound incorporate staking features to
reward liquidity providers, creating a foundation for user-driven ecosystems. However,
these solutions often involve complex interactions with multiple protocols, potentially
leading to higher gas fees and usability challenges for newcomers to blockchain.
Furthermore, vulnerabilities like reentrancy attacks, seen in infamous incidents such as the
DAO hack, underscore the critical importance of robust security measures in smart
contract design.

Existing studies suggest that the integration of OpenZeppelin libraries for standardized
ERC20 token implementation and security features offers reliable solutions against
common smart contract vulnerabilities. Utilizing these libraries for staking smart contracts
ensures greater code transparency and reusability, fostering user confidence in the
application.

The novelty of this project lies in its focus on combining real-time reward calculations
with dynamic updates on user staking and withdrawal actions, ensuring both performance
efficiency and scalability. Unlike general-purpose staking mechanisms, this DApp targets
a tailored user base by providing an intuitive interface, seamless user interactions, and
highly accurate reward tracking without incurring significant computational overheads.

Additionally, while most staking projects require high-level technical understanding for
interaction, our project emphasizes user accessibility by providing a front-end interface
designed with straightforward navigation and comprehensive feedback mechanisms. This
focus on user experience, combined with robust backend security measures, positions the
project as a practical solution in the DeFi space.

11
4. METHODOLOGY

The methodology of developing the token staking DApp involves carefully designing and
implementing a system that allows users to stake tokens, earn rewards, and withdraw their
holdings through an efficient and secure decentralized application. Here's the step-by-step
explanation of the core process:

4.1 Smart Contract Development

• Core Contract Design:

The primary smart contract, Staking, is written in Solidity and deployed on the
Ethereum blockchain. It uses OpenZeppelin libraries for security and efficiency,
such as SafeMath for safe arithmetic operations and ReentrancyGuard to prevent
reentrancy attacks.

• Contract Components:

The contract includes logic for staking (stake), withdrawing staked tokens
(withdrawStakedTokens), and claiming rewards (getReward). Reward calculation
is handled using formulas based on a predefined reward rate (REWARD_RATE)
and staked balances of users.

• Custom Tokens:

Two ERC20-compliant tokens (StakeToken and RewardToken) are created to


represent the tokens for staking and rewards. These tokens are based on
OpenZeppelin's ERC20 implementation for standard token functionality.

• Reward Calculation Algorithm:

This section provides a comprehensive explanation of the methodology used to


calculate staking rewards, ensuring a transparent, fair, and proportional reward
allocation among users based on their stake and the elapsed time.

1. Reward Per Token Formula: The rewardPerToken formula


calculates the total rewards distributed per token in the system since the last

12
update. This value reflects how much reward is allocated for each staked
token during a specific period.
Formula:

Total Rewards Distributed:

Example Scenario:
▪ Reward Rate (REWARD_RATE): 10 tokens/hour
▪ Total Staked Tokens: 100 tokens
▪ Elapsed Time: 2 hours since the last update
▪ Previous rewardPerTokenStored: 0

Step-by-step calculation:

1. Calculate the total rewards distributed over the elapsed time:

2. Distribute the rewards among all staked tokens:

3. Update the rewards per token:

Thus, each token staked in the system is now eligible for 0.2 tokens in rewards.

2. Individual Rewards Earned: The rewards earned by an individual


staker are calculated based on their contribution to the total staked tokens,
multiplied by the current rewards per token. This ensures a proportional
allocation of rewards.
Formula:

Example Scenario:
▪ A user stakes 20 tokens out of 100 total staked tokens.
▪ Reward Per Token: 0.2 tokens (from the previous calculation).

13
▪ Previous Rewards: 0 (no rewards claimed yet).

Step-by-step calculation:

Multiply the user’s staked amount by the reward per token:

Add any previously earned rewards:

Thus, this user has earned 4 tokens in rewards for their staked amount.

3. Update Mechanism: The updateReward modifier is a critical


component of the reward calculation process. It ensures that the reward
system remains up-to-date and fair during staking, withdrawal, or reward
claiming operations.
It performs the following tasks:
1. Updates the rewardPerTokenStored: Reflects the latest rewards per
token based on the current system state.
2. Records the lastUpdateTime: Tracks when rewards were last
distributed, ensuring accuracy in future calculations.
3. Adjusts user-specific rewards: Updates each user’s rewards to
account for changes in the reward rates
4. Combined Real-World Example: To illustrate the system’s
operation:
Assume three users stake tokens:
▪ Alice: 50 tokens
▪ Bob: 30 tokens
▪ Charlie: 20 tokens
▪ Total staked tokens = 100 tokens

Reward Rate: 10 tokens/hour

Elapsed Time: 2 hours

Step 1: Calculate rewards per token:

14
Step 2: Calculate individual rewards:

▪ Alice’s Rewards: 50×0.2=10 tokens


▪ Bob’s Rewards: 30×0.2=6 tokens
▪ Charlie’s Rewards: 20×0.2=4 tokens

Step 3: Verify total rewards:

10+6+4=20 tokens (matches the total rewards distributed).

This reward calculation mechanism ensures accuracy, fairness, and transparency in


distributing rewards to stakers based on their contributions to the total staked
tokens and the duration of their stake.

Fig 1: Smart Contract Interaction In RemixIde

15
4.2 Frontend Development ([Link]):

• User Interface:

A [Link]-based frontend is designed to provide an intuitive user experience. Key


components include:

▪ Input fields and buttons for staking tokens, withdrawing tokens, and
claiming rewards.

▪ Display of real-time data, such as the user’s current staked balance,


earned rewards, and wallet connection status.

• Integration with Blockchain:

Users connect to the application via wallets like MetaMask. React hooks manage
wallet state and synchronize with the blockchain.

Fig 2: Frontend Development ([Link])

16
4.3 Integration using [Link]:

• ABI Integration:

The Application Binary Interface (ABI) of the Staking smart contract serves as a
bridge between the [Link] frontend and the deployed contract. The ABI contains
function signatures and data structure details necessary for interacting with the
contract.

For example, the ABI allows the frontend to call the stake() function on the
blockchain by passing the staking amount and user address.

• Contract Interaction:

[Link] enables smooth communication with the Ethereum network by:

▪ Connecting to the Ethereum provider (e.g., MetaMask).

▪ Creating a contract instance using the ABI and the contract’s address.

▪ Sending transactions (e.g., stake() and getReward()) and reading on-


chain data (e.g., staked balance, rewards earned).

Fig 3: ABI Integration

17
4.4 Wallet Integration:

• Users can seamlessly connect their wallet through the frontend. Once connected,
the app retrieves the user’s wallet address and integrates it into transactions.

• Token allowances are managed using the approve function of the staking token.
This step ensures that the smart contract has permission to transfer tokens from the
user’s wallet.

Fig 4: MetaMask Wallet

18
5. PROPOSED METHOD

Our proposed method for the staking DApp project extends conventional decentralized
applications by integrating secure smart contract workflows, dynamic reward mechanisms,
and a user-friendly web interface.

5.1 Smart Contract Design

• Stake and Reward Logic:

The core of the staking DApp revolves around the staking functionality and reward
calculation. The staking smart contract is designed to accept ERC20-compliant
StakeToken deposits from users, keep track of staking balances, and dynamically
distribute RewardToken based on staking duration and contribution percentage.

• Security Features:

Preventing common vulnerabilities, such as reentrancy attacks and


overflow/underflow errors, is prioritized using OpenZeppelin’s libraries. Access
control mechanisms ensure only authorized actions are performed on sensitive
functions like reward minting and staking initialization.

5.2 Backend Integration and Logging

• Transparent Workflow:

Every staking, withdrawal, and reward distribution transaction is recorded on the


blockchain, ensuring full transparency and traceability for users.

• Logging Mechanisms:

Events such as deposit, withdrawal, and reward disbursement are logged using
Solidity’s event system. These logs enable users to track their interactions and
developers to debug more effectively.

19
5.3 Frontend Implementation

• User Interface Features:

A streamlined web-based interface is designed using [Link] for user-friendly


interaction. Key features include: Real-time token staking, withdrawal, and reward
information.

• [Link] Integration:

MetaMask integration is leveraged for wallet connectivity, allowing users to


manage tokens securely and easily.

• Responsive Design:

The UI adapts seamlessly to various devices, ensuring accessibility across


desktops, tablets, and mobile platforms.

5.4 Advanced Reward System

• Dynamic Calculation:

Rewards are calculated continuously, based on parameters like total staking pool
size, individual user contribution, and staking duration. Reward distribution uses a
gas-efficient algorithm to reduce transaction costs.

5.5 Development Environment and Tools

• Development Stack:

The entire application is built using Solidity, Remix Ide, and [Link].

• Cross-Network Deployment:

The staking DApp is designed for deployment on Ethereum-compatible networks,


with flexibility to integrate scaling solutions such as Layer 2 (e.g., Optimism or
Arbitrum).

20
6. FUTURE PLANS AND CONCLUSION

To ensure the security, efficiency, and long-term viability of our staking DApp, we have
outlined detailed plans for testing and validation. These plans focus on creating a robust
testing framework using the Foundry development environment, with specific attention to
multiple types of tests to cover various use cases and scenarios.

6.1 Comprehensive Testing Framework


The core of our future efforts will revolve around implementing a multi-layered testing
framework that ensures both individual functionalities and their interactions work
seamlessly. This involves the following key testing approaches:

a) Unit Testing
• Objective: Verify the behaviour of individual functions in isolation.
• Scope:
o Test basic functionalities such as staking tokens, unstaking tokens, and
claiming rewards.
o Verify contract calculations for reward distribution based on staking
durations and amounts.
o Validate access control mechanisms (e.g., only authorized addresses can
call admin functions).
• Implementation:
o Mock dependencies where necessary to focus on the target function.
o Use Foundry’s built-in tools to assert expected outputs under specific
conditions.

b) Integration Testing
• Objective: Ensure that different contract functions and components interact
correctly in end-to-end workflows.
• Scope:
o Simulate user journeys, such as staking tokens, waiting for rewards to
accumulate, and then claiming them.

21
o Validate interactions between the staking contract and ERC20 tokens (stake
and reward tokens).
o Check boundary conditions, such as maximum staking capacity or contract
balance.
• Implementation:
o Run tests with real ERC20 tokens to mimic real-world conditions.
o Deploy temporary contracts in a test environment to validate scenarios end-
to-end.

c) Fuzz Testing
• Objective: Identify vulnerabilities by testing the smart contracts with randomized
or unexpected input data.
• Scope:
o Test input parameters (e.g., invalid token addresses, very large staking
amounts, or negative values).
o Simulate unusual sequences of function calls, such as staking and
immediately unstaking repeatedly.
• Implementation:
o Use Foundry’s fuzzing capabilities to automate the process of generating
random data.
o Define property-based assertions to ensure contract invariants (e.g., the total
staked amount should never exceed the contract’s balance).

22
6.2 Conclusion:
The development of the staking decentralized application (DApp) represents a significant
advancement in leveraging blockchain technology to provide a seamless, transparent, and
efficient platform for token staking and reward distribution. By combining secure smart
contracts, a dynamic reward system, and an intuitive user interface, the project addresses
key challenges in building trust and engagement within decentralized finance (DeFi).

This project successfully established a foundational framework for token staking, allowing
users to participate in a decentralized ecosystem while earning rewards for their
contributions. Key features, such as real-time staking updates, gas-efficient calculations,
and a secure backend, demonstrate the practicality and scalability of the solution.

Future improvements will focus on incorporating user feedback, introducing advanced


features like staking pool diversification, and integrating governance mechanisms to
empower the community. Moreover, scalability solutions, such as Layer 2 integration and
multichain support, will ensure the DApp remains efficient and accessible as it grows.

In conclusion, the staking DApp not only offers a valuable tool for fostering engagement
within blockchain networks but also highlights the potential of decentralized applications
to transform traditional financial systems. This project serves as a stepping stone toward
creating innovative, user-centric blockchain solutions that meet the needs of a rapidly
evolving DeFi landscape.

23
7. REFERENCES

1. Buterin, V. "A Next-Generation Smart Contract and Decentralized Application


Platform." Ethereum Whitepaper (2013), [Link]

2. OpenZeppelin Documentation Team. "Solidity Smart Contract Security Best Practices."


OpenZeppelin Docs (2024), [Link]

3. Edstrom, R. "Programming Ethereum Smart Contracts for Absolute Beginners." Apress


(2020), ISBN: 978-1-4842-5425-7.

4. ConsenSys Blog Team. "Introduction to Smart Contract Development with Solidity and
Foundry." ConsenSys Blog (2023), [Link]

5. Chainlink Research. "Decentralized Automation Using Chainlink Keepers." Chainlink


Documentation (2023), [Link]

6. Ethernaut CTF Team. "Exploring Ethereum Security through Smart Contract


Challenges." Ethernaut Game Documentation (2023), [Link]

7. Brownie Framework Team. "Unit Testing and Automation for Smart Contract
Development." Brownie Documentation (2024), [Link]

8. Paradigm Team. "Writing Effective Smart Contract Tests Using Foundry." Paradigm
Blog (2024), [Link]

9. Ganache Development. "Local Ethereum Blockchain for Testing Smart Contracts."


Ganache Documentation (2023), [Link]

10. Alchemix Protocol Team. "Implementing Stake and Reward Mechanisms on


Ethereum." Alchemix Blog (2024), [Link]

11. Solidity Team. "Solidity Documentation: Comprehensive Guide to Writing Secure


Contracts." Solidity Official Docs (2024), [Link]

24

You might also like