diff --git a/README.md b/README.md index fbb9cda..0279525 100644 --- a/README.md +++ b/README.md @@ -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= STATE_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 be 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= 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= 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= 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.