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.
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 :
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
- Basic usage of TokenSDK
- How the state of stock (ie. EvolvableToken) updates independently without stockholders involved
- Use of
TokenSelection.generateMove()
andMoveTokensUtilitiesKt.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
- 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.
Set up for CorDapp development
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
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.
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
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
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
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"
Shareholders find the dividend is announced and claims the dividends base on the owning stock.
On shareholder node, execute
start ClaimDividendReceivable symbol: TEST
On the payday, the company pay off the stock with fiat currencies.
On WayneCo node, execute
start PayDividend
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
You can also find the flow and example data from the test class FlowTests.kt.
Token-SDK tutorial
Token-SDK design document
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