Skip to content

Latest commit

 

History

History

stockpaydividend

stock pay dividend

This CorDapp aims to demonstrate the usage of TokenSDK, especially the concept of EvolvableToken which represents stock. You will find the StockState extends from EvolvableToken which allows the stock details(eg. announcing dividends) to be updated without affecting the parties who own the stock.

Concepts

Parties

This CordApp assumes there are 4 parties:

  • WayneCo - creates and maintains the stock state and pays dividends to shareholders after some time passes.
  • Shareholder - receives dividends base on the owning stock.
  • Bank - issues fiat tokens.
  • Observer - monitors all the stocks by keeping a copy of of transactions whenever a stock is created or updated. (In reality, this might be a financial regulatory authority like the SEC.)

Here's the flows that exist between these parties :

Flow diagram

This Stock Exchange CorDapp includes:

  • A bank issues some money for the final settlement of the dividends.
  • A company/stock issuer(WayneCo) issues and moves stocks to shareholders
  • The company announces dividends for shareholders to claim before execution day
  • Shareholder retrieves the most updated stock information and then claims dividend
  • The company distribute dividends to shareholders

Keys to learn

  • Basic usage of TokenSDK
  • How the state of stock (ie. EvolvableToken) updates independently without stock holders involved
  • Use of TokenSelection.generateMove() and MoveTokensUtilities.addMoveTokens() to generate move of tokens
  • Adding observers in token transactions with TokenSDK

*Note that some date constraint(eg. payday) is being commented out to make sure the sample can be ran smoothly

States

  • StockState - which holds the underlying information of a stock like stock name, symbol, dividend, etc.
  • DividendState - represents the dividend to be paid off by the company to the shareholder.

Usage

Running the CorDapp

Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)

./gradlew clean deployNodes

Then type: (to run the nodes)

./build/nodes/runnodes

Running the sample

To go through the sample flow, execute the commands on the corresponding node

Pre-requisite. IssueMoney - Bank

In order to pay off dividends from the company later, the bank issues some fiat tokens to the WayneCo. This can be executed anytime before step 6.

On bank node, execute
start IssueMoney currency: USD, amount: 500000, recipient: WayneCo

1. IssueStock - Stock Issuer

WayneCo creates a StockState and issues some stock tokens associated to the created StockState.

On company WayneCo's node, execute
start CreateAndIssueStock symbol: TEST, name: "Stock, SP500", currency: USD, price: 7.4, issueVol: 500, notary: Notary

2. MoveStock - Stock Issuer

WayneCo transfers some stock tokens to the Shareholder.

On company WayneCo's node, execute
start MoveStock symbol: TEST, quantity: 100, recipient: Shareholder

Now at the Shareholder's terminal, we can see that it received 100 stock tokens:

On shareholder node, execute
start GetStockBalance symbol: TEST

3. AnnounceDividend - Stock Issuer

WayneCo announces the dividends that will be paid on the payday.

On WayneCo's node, execute
start AnnounceDividend symbol: TEST, dividendPercentage: 0.05, executionDate: "2019-11-22T00:00:00Z", payDate: "2019-11-23T00:00:00Z"

4. ClaimDividendReceivable - Shareholder

Shareholders finds the dividend is announced and claims the dividends base on the owning stock.

On shareholder node, execute
start ClaimDividendReceivable symbol: TEST

5. PayDividend - Company

On the payday, the company pay off the stock with fiat currencies.

On WayneCo node, execute
start PayDividend

6. Get token balances - Any node

Query the balances of different nodes. This can be executed at anytime.

Get stock token balances
start GetStockBalance symbol: TEST

Get fiat token balances
start GetFiatBalance currencyCode: USD

Test cases

You can also find the flow and example data from the test class FlowTests.java.

Useful links

Documentation

Token-SDK tutorial
Token-SDK design document

Other materials

Blog - House trading sample - A less complicated sample of TokenSDK about trading house.
Blog - Introduction to Token SDK in Corda - Provides basic understanding from the ground up.
Sample - TokenSDK with Account An basic sample of how account feature can be integrated with TokenSDK