Skip to content

Commit

Permalink
Merge pull request #18 from blooo-io/docs/LDG-302-documentation
Browse files Browse the repository at this point in the history
fix(comments): Added comments for each functions, removed unused vari…
  • Loading branch information
GuilaneDen authored Oct 16, 2023
2 parents 644bd8e + d827b95 commit cec21f0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
6 changes: 0 additions & 6 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ const uint8_t *const STAKEKIT_SELECTORS[NUM_STAKEKIT_SELECTORS] = {
STAKEKIT_YEARN_VAULT_WITHDRAW_3_SELECTOR,
};

// Indicate the Ethereum chain ID
const uint8_t ETH_CHAIN_ID[CHAIN_ID_LENGTH] = {0x01};

// Indicate the BSC chain ID
const uint8_t BSC_CHAIN_ID[CHAIN_ID_LENGTH] = {0x38};

// Null address
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
6 changes: 6 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "stakekit_plugin.h"

// Sets the deposit ticker as the token symbol
// Look into the STAKEKIT_SUPPORTED_YEARN_VAULT array to find the corresponding token symbol.
// If found, set the ticker and decimals. Then return true.
// If not found, return false.
static bool set_ticker_deposit_for_mapped_token(plugin_parameters_t *context,
ethPluginFinalize_t *msg) {
for (size_t i = 0; i < NUM_SUPPORTED_SMART_CONTRACT; i++) {
Expand All @@ -21,6 +24,9 @@ static bool set_ticker_deposit_for_mapped_token(plugin_parameters_t *context,
return false;
}
// Sets the withdraw ticker as the token symbol
// Look into the STAKEKIT_SUPPORTED_YEARN_VAULT array to find the corresponding token symbol.
// If found, set the ticker and decimals. Then return true.
// If not found, return false.
static bool set_ticker_withdraw_for_mapped_token(plugin_parameters_t *context,
ethPluginFinalize_t *msg) {
for (size_t i = 0; i < NUM_SUPPORTED_SMART_CONTRACT; i++) {
Expand Down
26 changes: 26 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "stakekit_plugin.h"

// Save two amounts in the context.
// The first amount is the amount received saved in amount_received.
// The second amount is the amount sent saved in amount_sent.
static void handle_swap_from(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case AMOUNT_RECEIVED:
Expand All @@ -18,6 +20,8 @@ static void handle_swap_from(ethPluginProvideParameter_t *msg, plugin_parameters
}

// Save 1 amount and 1 recipient in the context.
// The amount is the amount sent saved in amount_sent.
// The second param is the recipient saved in recipient.
static void handle_amount_recipient(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
Expand All @@ -36,6 +40,8 @@ static void handle_amount_recipient(ethPluginProvideParameter_t *msg,
}

// Save 1 amount and 1 recipient in the context.
// The first param is the recipient saved in recipient.
// The second param is the amount sent saved in amount_sent.
static void handle_recipient_amount_sent(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
Expand All @@ -54,6 +60,9 @@ static void handle_recipient_amount_sent(ethPluginProvideParameter_t *msg,
}

// Save 1 amount and 1 recipient and 1 token address in the context.
// The first param is the token address which help to fetch the token info later.
// The second param is the recipient saved in recipient.
// The third param is the amount sent saved in amount_sent.
static void handle_morpho_supply_1_3(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
Expand All @@ -80,6 +89,8 @@ static void handle_morpho_supply_1_3(ethPluginProvideParameter_t *msg,
}

// Save 1 amount and 1 token address in the context.
// The first param is the token address which help to fetch the token info later.
// The second param is the amount sent saved in amount_sent.
static void handle_morpho_supply_2(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case TOKEN_SENT:
Expand All @@ -98,6 +109,8 @@ static void handle_morpho_supply_2(ethPluginProvideParameter_t *msg, plugin_para
}

// Save 1 amount and 1 token address in the context.
// The first param is the token address which help to fetch the token info later.
// The second param is the amount received saved in amount_received.
static void handle_morpho_withdraw_1(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
Expand All @@ -120,6 +133,9 @@ static void handle_morpho_withdraw_1(ethPluginProvideParameter_t *msg,
}

// Save 1 amount and 1 recipient and 1 token address in the context.
// The first param is the token address which help to fetch the token info later.
// The second param is the amount received saved in amount_received.
// The third param is the recipient saved in recipient.
static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
Expand All @@ -146,6 +162,9 @@ static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg,
}

// Save 2 recipients in the context.
// The first param is the recipient as we have 2 recipient and the storage has a
// limitation, we need to save it in another variable which is contract_address.
// The second param is the second recipient saved in recipient.
static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case RECIPIENT: // Put the Comet protocol address in contract_address
Expand All @@ -166,6 +185,10 @@ static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_paramete
}

// Save 1 amount and 3 recipients in the context.
// The first param is the second recipient saved in recipient.
// The second param is the amount sent saved in amount_sent.
// The third and fourth param are the recipients as we have 3 recipient and the storage has a
// limitation, we need to save it in other variables which are contract_address and amount_received.
static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case RECIPIENT:
Expand Down Expand Up @@ -200,6 +223,9 @@ static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_paramete
}

// Save 1 amount and 1 recipient and 1 token address in the context.
// The first param is the token address which help to fetch the token info later.
// The second param is the amount sent saved in amount_sent.
// The third param is the recipient saved in recipient.
static void handle_aave_supply(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case TOKEN_SENT:
Expand Down
1 change: 1 addition & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stakekit_plugin.h"

// Function to display the method name on the device.
void handle_query_contract_id(void *parameters) {
ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters;
plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext;
Expand Down
39 changes: 26 additions & 13 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stakekit_plugin.h"

// Set UI for the "Send" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case DEPOSIT_SELF_APECOIN:
Expand Down Expand Up @@ -59,7 +60,7 @@ static void set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context)
PRINTF("AMOUNT SENT: %s\n", msg->msg);
}

// Same as the "set_send_ui" function. Howerver the value is extracted from the pluginSharedRO.
// Same as the "set_send_ui" function. However the value is extracted from the pluginSharedRO.
static void set_send_value_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case STAKE:
Expand All @@ -82,6 +83,7 @@ static void set_send_value_ui(ethQueryContractUI_t *msg, plugin_parameters_t *co
}

// Set UI for "Receive" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_receive_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case WITHDRAW_SELF_APECOIN:
Expand Down Expand Up @@ -128,6 +130,7 @@ static void print_address(ethQueryContractUI_t *msg, uint8_t *address) {
}

// Set UI for "Recipient" screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case SUBMIT_MATIC_LIDO:
Expand Down Expand Up @@ -173,6 +176,7 @@ static void set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *con

// Set UI for "Recipient 2" screen. When having more than one recipient.
// The recipient address is saved in the contract_address
// Each methods sets the title and the message to be displayed on the screen.
static void set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case COMET_CLAIM:
Expand All @@ -193,6 +197,7 @@ static void set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *c

// Set UI for "Recipient 2" screen. When having more than two recipients.
// The recipient address is saved in the amount_received
// Each methods sets the title and the message to be displayed on the screen.
static void set_recipient_3_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case VOTE:
Expand All @@ -209,6 +214,7 @@ static void set_recipient_3_ui(ethQueryContractUI_t *msg, plugin_parameters_t *c
}

// Set UI for smart contract address screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case CLAIM_SELF_APECOIN:
Expand All @@ -232,6 +238,7 @@ static void set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t
}

// Set UI for unbound nonce boolean screen.
// Each methods sets the title and the message to be displayed on the screen.
static void set_unbound_nonce_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) {
switch (context->selectorIndex) {
case UNSTAKE_CLAIM_TOKENS_NEW:
Expand All @@ -256,6 +263,7 @@ static void set_warning_ui(ethQueryContractUI_t *msg,
strlcpy(msg->msg, "Unknown token", msg->msgLength);
}

// Set UI for the methods needing a send screen.
static screens_t get_screen_amount_sent(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand All @@ -266,6 +274,7 @@ static screens_t get_screen_amount_sent(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a receive screen.
static screens_t get_screen_receive(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand All @@ -276,16 +285,7 @@ static screens_t get_screen_receive(ethQueryContractUI_t *msg,
}
}

static screens_t get_screen_submit_eth_lido(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
case 0:
return RECIPIENT_SCREEN;
default:
return ERROR;
}
}

// Set UI for the methods needing a send and recipient screens.
static screens_t get_screen_amount_sent_recipient(ethQueryContractUI_t *msg,
plugin_parameters_t *context
__attribute__((unused))) {
Expand All @@ -299,6 +299,8 @@ static screens_t get_screen_amount_sent_recipient(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a send and recipient screens.
// If the token is not found, we need an additional screen to display a warning message.
static screens_t get_screen_supply(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
bool token_sent_found = context->tokens_found & TOKEN_SENT_FOUND;
Expand Down Expand Up @@ -327,6 +329,8 @@ static screens_t get_screen_supply(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a receive and recipient screens.
// If the token is not found, we need an additional screen to display a warning message.
static screens_t get_screen_morpho_withdraw(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
bool token_received_found = context->tokens_found & TOKEN_RECEIVED_FOUND;
Expand Down Expand Up @@ -355,6 +359,7 @@ static screens_t get_screen_morpho_withdraw(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing 2 recipients screens.
static screens_t get_screen_comet_claim(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand All @@ -367,6 +372,7 @@ static screens_t get_screen_comet_claim(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a send and receive screens.
static screens_t get_screen_amount_sent_receive(ethQueryContractUI_t *msg,
plugin_parameters_t *context
__attribute__((unused))) {
Expand All @@ -380,6 +386,7 @@ static screens_t get_screen_amount_sent_receive(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a send Value screen.
static screens_t get_screen_value_sent(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand All @@ -390,6 +397,7 @@ static screens_t get_screen_value_sent(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a recipient screen.
static screens_t get_screen_recipient(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand All @@ -400,6 +408,7 @@ static screens_t get_screen_recipient(ethQueryContractUI_t *msg,
}
}

// Set UI for the methods needing a smart contract screen.
static screens_t get_screen_smart_contract_address(ethQueryContractUI_t *msg,
plugin_parameters_t *context
__attribute__((unused))) {
Expand All @@ -411,6 +420,8 @@ static screens_t get_screen_smart_contract_address(ethQueryContractUI_t *msg,
}
}

// Set UI for the Vote and Revoke methods.
// These methods need 4 screens.
static screens_t get_screen_vote_revoke(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand All @@ -427,6 +438,8 @@ static screens_t get_screen_vote_revoke(ethQueryContractUI_t *msg,
}
}

// Set UI for the UnstakeClaim method.
// This method needs to display the unbound nonce boolean.
static screens_t get_screen_unstake_claim(ethQueryContractUI_t *msg,
plugin_parameters_t *context __attribute__((unused))) {
switch (msg->screenIndex) {
Expand Down Expand Up @@ -458,9 +471,8 @@ static screens_t get_screen(ethQueryContractUI_t *msg,
return get_screen_receive(msg, context);
case GRT_UNDELEGATE:
case GRT_WITHDRAW_DELEGATED:
return get_screen_recipient(msg, context);
case SUBMIT_ETH_LIDO:
return get_screen_submit_eth_lido(msg, context);
return get_screen_recipient(msg, context);
case SUBMIT_MATIC_LIDO:
case REQUEST_WITHDRAW:
case PARASPACE_DEPOSIT:
Expand Down Expand Up @@ -508,6 +520,7 @@ static screens_t get_screen(ethQueryContractUI_t *msg,
return ERROR;
}

// Set the UI according to the screen that needs to be displayed.
void handle_query_contract_ui(void *parameters) {
ethQueryContractUI_t *msg = (ethQueryContractUI_t *) parameters;
plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext;
Expand Down
2 changes: 0 additions & 2 deletions src/stakekit_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ extern const tokenSymbolAndDecimals_t STAKEKIT_SUPPORTED_YEARN_VAULT[NUM_SUPPORT
#define CHAIN_ID_LENGTH 1

extern const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH];
extern const uint8_t ETH_CHAIN_ID[CHAIN_ID_LENGTH];
extern const uint8_t BSC_CHAIN_ID[CHAIN_ID_LENGTH];

// Returns 1 if corresponding address is the address for the chain token (ETH, BNB, MATIC,...)
#define ADDRESS_IS_NETWORK_TOKEN(_addr) !memcmp(_addr, NULL_ETH_ADDRESS, ADDRESS_LENGTH)
Expand Down

0 comments on commit cec21f0

Please sign in to comment.