Skip to content

Commit

Permalink
Add description of how to use the yield router in README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
gigileungyingchi committed Oct 9, 2023
1 parent a8065e2 commit 078373e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,28 @@ The architecture is as follows:
- Each destination is expected to be a PDA that then distributes the yield to the climate project
according to their own rules. For example, the Offset Bridge bridges the funds to Polygon, buys
NCT etc.

## Usage (latest version -- Yield Router)
There is a state account owned by the yield controller program which stores the following data:
- `sunrise_state`: public key of a state account; from which the input yield account, which holds funds to be sent to PDAs that will transfer fund to various climate projects (e.g. the offset bridge), can be derived
- `update_authority`: public key of the account having the authority to update the state account
- `output_yield_accounts`: a vector holding public keys of the PDAs that will transfer funds to various climate project
- `spend_proportions`: a vector holding the proportions of funds to be sent to each elements in `output_yield_accounts`, the proportions must sum up to 100
- `spend_threshold`: minimum amount of fund existing in `sunrise_state` account before transfer of funds to `output_yield_accounts` is allowed
- `total_spent`: total amount of fund sent to various climate projects

This state account needs to be first registered on chain, this only needs to be performed once for a yield controller program. To do so, one can use the `register_state` instruction by calling the `packages/yield-router/registerState.ts` script as follow:
```ANCHOR_PROVIDER_URL=<anchor_provider_url> STATE_ADDRESS=<state_address> OUTPUT_YIELD_ADDRESS=[output_yield_address] yarn ts-node packages/yield-router/registerState.ts```
where `state_address` is the public key of the state account from which the input yield account can ebe derived and `output_yield_address` is the address of the public key of the first PDA of a climate project.

When using the `packages/yield-router/registerState.ts` script to register the state, currently it only supports registering the state first with only one output yield account address. To update it with multiple output yield accounts (or any other updates in terms of removing certain yield accounts or changing the proportions between the various output yield accounts), one can use the `update_state` instruction by calling the `packages/yield-router/updateState.ts` script as follow:
```ANCHOR_PROVIDER_URL=<anchor_provider_url> yarn ts-node packages/yield-router/updateState.ts```
one will first be prompted to enter a new update authority address, this is to be skipped when it is not wished to update the update authority. Afterwards, the new output yield addresses and the associated spending proportions will be prompted to be input one by one, the proportions must sum up to 100.

To send funds from the input yield account (`sunrise_state`) to the `output_yield_accounts` with the specified `spend_threshold`, one needs to simply use the `allocate_yield` instruction by calling `packages/yield-router/allocateYield.ts` script as follow:
```ANCHOR_PROVIDER_URL=<anchor_provider_url> AMOUNT=<amount> yarn ts-node packages/yield-router/allocateYield.ts```
where amount is the amount of funds to be sent.

To check the current status of the yield controller, one can call the `packages/yield-router/getState.ts` script as follow:
```ANCHOR_PROVIDER_URL=<anchor_provide_url> yarn ts-node packages/yield-router/getState.ts```
This script contains various instructions and will return the state account address, the state account data, the balance of the input yield account and the balance of the output yield account.

0 comments on commit 078373e

Please sign in to comment.