Inspiration

Currently, many platforms support payments with fiat money, which could be used for investing, payroll, purchases, etc. Nevertheless, these platforms encounter several shortcomings, including:

  • Lack of automation: Most platforms do not allow periodic automation of payments. Instead, users must manually transfer the money, even for recurring payments.
  • Trust-related risk: Workers have to depend on their employers to keep their promises and always stand a risk of wage theft. Inversely, labor hirers might risk low-quality work, for example, if payment is made in advance.
  • Delay time: Workers have to wait for a specific date to receive/use the money, usually every month or after the contract ends.
  • Most platforms do not support payment with tokens.

Thus, to solve these issues, we have made use of blockchain and (the application of) tokens to create a multi-functional crypto streaming protocol on Polygon.

At Calamus Finance, we aim to facilitate the process of constant payments transparently and securely.

The protocol is currently available on Polygon, Tron and Evmos blockchains.

What it does

Calamus Finance is a decentralized crypto streaming protocol that allows people to send/receive payments on any time basis and vest tokens automatically. It can function well from small payments like subscriptions or allowances to bigger ones like company's payroll or startup vesting.

Calamus Finance supports all ERC-20 tokens and the native token - MATIC.

Main functions:

  • Payroll: Pay your employees by the second quickly. Company will have complete control over frequency, liquidity amount and duration. Cancellation is possible at any time by the payer and/or payee.
  • Token Vesting: Reward your team, advisors and investors with tokens automatically without any fear of foul-play
  • Multisig wallet (coming soon): Wallet is owned by many people and transactions are only made under agreements from multiple owners.

Potential use cases:

  • Subscription/Membership: Pay-as-you-use. Cancel anytime when you do not need the service/product anymore. Low entry barrier.
  • Airdrop: Airdrop streams reduce the volatility of new tokens and enhance community loyalty.
  • Stream Collateral: Streams can be used as collateral for lending and borrowing in Defi protocols.

Users can:

  • Connect their wallet (i.e., MetaMask) with the app
  • Choose any available token on their wallet, as long as its balance exceeds 0.
  • Configure a payment frequency: per second, minute, hour, day, week, month or year. Most traditional companies would pay their employees by week or month.
  • Set start and end time of payments.
  • Configure advanced settings like cancellation or stream transferring.
  • Set total payment amount.
  • Fill in the recipient's address and extra information like email address, contract title, etc.
  • Cancel stream at any time if mutual consensus is not met.
  • Transfer the stream to a new recipient’s address.
  • Set an initial release amount at cliff date (for startup vesting).
  • Data from these features are validated at DApp and Smart Contract, hence minimizing human risk and improving security.

Terms explanation: Stream explanation

1: Recipient's unlocked amount: calculated from start time to the current time (block.timestamp)

2: Recipient's withdraw amount: the amount that recipient has withdrawn

3: Recipient's remain balance = unlocked amount (1) - withdraw amount (2)

4: Sender balance = total amount (5) - unlocked amount (3)

5: Total stream amount

When a stream is canceled, smart contracts ensure the unlocked amount (1) will be transferred to the recipient account, and the sender balance (4) will be transferred to the sender account.

When a stream is transferred to a new recipient address, smart contracts ensure the unlocked amount (1) will be transferred to the current recipient account, while the sender balance (4) will continue to be streamed to the new recipient.

How we built it

System Diagram

  • All-in-one app for all features and all chains.
  • Every time users change their blockchain, the app will use Network adapters to be able to execute code that matches that chain.
  • Linked to each network adapter is a set of supporting JS libraries to connect to different wallets and call smart contracts.
  • The app uses a cloud database to store user data such as account and connection history. This database helps enhance the customer experience in managing their connected wallets and reduce the number of smart contract calls.
  • The app provides the exact access mechanism as in Web 2. Users can Login/Register via Github account, Google account or email & password.
  • The app architecture is built to scale quickly and adopt more Blockchains without affecting any features running on existing Blockchains.

We divided our journey into 3 phases: Build Smart Contracts, Build DApp and Deploy & Debug. To build Smart Contracts, we use:

  • Solidity version 0.8.0
  • Open Zeppelin

Smart Contracts usage map:

Smart Contracts usage map

Our tech stack:

  • NodeJS, React, NextJS, Redux, Typescript…
  • Shopify Polaris: a React UI component highly suitable for building admin apps.
  • Javascript libraries like Web3 and Ethers to interact with smart contracts and MetaMask wallet. Tronweb Javascript library and Tronlink Javascript Object to interact with TronLink wallet and smart contracts.
  • ChartJS to build reports on the dashboard.
  • Moment JS to process stream time on the Frontend and contribute to data reporting.
  • Mongo Atlas DB to store Recipient’s extra information because storing unnecessary information on-chain will increase fee when creating streams and sometimes exceed the logic limit of a Solidity Smart Contract.
  • Covalenthq API & Tron Scan API to collect user’s token balance on registered wallet address.
  • Binance public API to collect token to USD price information, thus providing an insightful display for users.

To deploy Smart Contracts on Mumbai Testnet, we use Truffle to deploy and debug Smart Contracts.

Challenges we ran into

Throughout the process of building Calamus Finance on multi-chains, we encountered multiple technical problems which take quite some time to solve:

  • All EVMs on the chosen chains have inconsistent technical parameters: typically, data returned from smart contracts have different formats even though they are deployed from the same Solidity code strings. For example, with Polygon, the token data is returned in string format, while Tron supports Hex. We solve this issue by constructing different data converter functions with the output following a certain standard.
  • Scalability and dependency: To ensure that the adoption of more chains in the future will not affect current features and users, we apply Clean Architecture and Facade design pattern to build adapters, and separate the application interface & underlying operating logic. As a result, every time a new chain is added, the developer can freely use the supporting libraries and wallets without interfering with the user experience.
  • Many actions are needed to connect with multiple chains: During the development process, we struggle to get stream data from different chains with different wallet addresses. At first, we ask users to connect with their chains one by one before being able to view the streams. However, this method is not user-friendly, so we have to use Web 2's storage method, which involves a database system that stores accounts and activity history. We create a link between Web 2 accounts and Web 3 addresses.
  • Gas fee and security optimization: This is a complex problem and has not been wholly solved, even though we have followed some recommended best practices. We tried our best to secure and optimize both dApps and Smart Contracts.

In addition, we also have business-related problems that are by no means less challenging:

  • The problem of rounding and handling residuals when creating a stream by the second, minute, hour, day, month and year.
  • The problem of transferring or canceling the stream midway, which interrupts the current stream data.
  • The problem of account security and validation in the process of manipulating streams.

Accomplishments that we're proud of

  • Build a Money Streaming protocol on multiple chains (3 and counting).
  • Overcome technical challenges to accomplish goals.
  • Develop technical functions so that users on Polygon, Evmos and Tron can pay, receive and vest tokens easily.
  • Gain a lot of in-depth knowledge about blockchain and finance.
  • TRON Grand Hackathon 2022: Web3 2nd place 🏅

What we learned

Throughout the journey, we have learned to

  • Build a complete dApp on multiple chains, especially Polygon
  • Understand the Crypto Payment model & usage on a Defi app.
  • General knowledge of libraries and APIs in various languages.
  • Technical knowledge on how to solve existing problems of fiat payment systems.

What’s next for Calamus Finance

  • Go live on Polygon mainnet.
  • Publish Multisig Wallet feature
  • Build Deposit before creating stream mechanism
  • Improve admin tools and interface to become a professional payment platform.
  • Develop API for Developers to easily interact with our data.
  • Integrate more chains
  • Integrate with more wallets, opening more choices for users.
  • Issue tokens and set up tokenomics for Calamus Finance

Built With

Share this project:

Updates