Skip to content

Latest commit

 

History

History

stockpaydividend

Stock Pay Dividend Sample

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 are 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 stockholders involved
  • Use of TokenSelection.generateMove() and MoveTokensUtilitiesKt.addMoveTokens() to generate move of tokens
  • Adding observers in token transactions with TokenSDK

*Note: Some date constraints(e.g. payday) is being commented out to make sure the sample can be run 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.

Pre-Requisites

Set up for CorDapp development

Usage

Running the nodes

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

Interacting with the nodes

When started via the command line, each node will display an interactive shell:

Welcome to the Corda interactive shell.
Useful commands include 'help' to see what is available, and 'bye' to shut down the node.

Tue July 09 11:58:13 GMT 2019>>>

You can use this shell to interact with your node.

1. 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

2. IssueStock - Stock Issuer

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

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

3. 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

4. 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"

5. ClaimDividendReceivable - Shareholder

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

On shareholder node, execute
start ClaimDividendReceivable symbol: TEST

6. PayDividend - Company

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

On WayneCo node, execute
start PayDividend

7. 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 case

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

Useful links

Documentations

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