diff --git a/src/handle_finalize.c b/src/handle_finalize.c index d09079dc..2172b779 100644 --- a/src/handle_finalize.c +++ b/src/handle_finalize.c @@ -1,38 +1,40 @@ #include "origin_plugin.h" void handle_finalize(void *parameters) { - ethPluginFinalize_t *msg = (ethPluginFinalize_t *)parameters; - origin_parameters_t *context = (origin_parameters_t *)msg->pluginContext; - msg->numScreens = 2; - if ((context->selectorIndex == UNISWAP_ROUTER_EXACT_INPUT || - context->selectorIndex == UNISWAP_ROUTER_EXACT_INPUT_SINGLE) && - memcmp(msg->address, context->beneficiary, ADDRESS_LENGTH) != 0) { - msg->numScreens += 1; - } - if ((context->selectorIndex == WRAP || context->selectorIndex == UNWRAP) && - memcmp(msg->address, context->beneficiary, ADDRESS_LENGTH) == 0) { - msg->numScreens -= 1; - } - if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { - // Address is not network token (0xeee...) so we will need to look up the - // token in the CAL. - printf_hex_array("Setting address sent to: ", ADDRESS_LENGTH, - context->contract_address_sent); - msg->tokenLookup1 = context->contract_address_sent; - } else { - sent_network_token(context); - msg->tokenLookup1 = NULL; - } - if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { - // Address is not network token (0xeee...) so we will need to look up the - // token in the CAL. - printf_hex_array("Setting address received to: ", ADDRESS_LENGTH, - context->contract_address_received); - msg->tokenLookup2 = context->contract_address_received; - } else { - received_network_token(context); - msg->tokenLookup2 = NULL; - } - msg->uiType = ETH_UI_TYPE_GENERIC; - msg->result = ETH_PLUGIN_RESULT_OK; + ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters; + origin_parameters_t *context = (origin_parameters_t *) msg->pluginContext; + msg->numScreens = 2; + if ((context->selectorIndex == UNISWAP_ROUTER_EXACT_INPUT || + context->selectorIndex == UNISWAP_ROUTER_EXACT_INPUT_SINGLE) && + memcmp(msg->address, context->beneficiary, ADDRESS_LENGTH) != 0) { + msg->numScreens += 1; + } + if ((context->selectorIndex == WRAP || context->selectorIndex == UNWRAP) && + memcmp(msg->address, context->beneficiary, ADDRESS_LENGTH) == 0) { + msg->numScreens -= 1; + } + if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { + // Address is not network token (0xeee...) so we will need to look up the + // token in the CAL. + printf_hex_array("Setting address sent to: ", + ADDRESS_LENGTH, + context->contract_address_sent); + msg->tokenLookup1 = context->contract_address_sent; + } else { + sent_network_token(context); + msg->tokenLookup1 = NULL; + } + if (!ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { + // Address is not network token (0xeee...) so we will need to look up the + // token in the CAL. + printf_hex_array("Setting address received to: ", + ADDRESS_LENGTH, + context->contract_address_received); + msg->tokenLookup2 = context->contract_address_received; + } else { + received_network_token(context); + msg->tokenLookup2 = NULL; + } + msg->uiType = ETH_UI_TYPE_GENERIC; + msg->result = ETH_PLUGIN_RESULT_OK; } \ No newline at end of file diff --git a/src/handle_init_contract.c b/src/handle_init_contract.c index 00437bb0..1a604063 100644 --- a/src/handle_init_contract.c +++ b/src/handle_init_contract.c @@ -1,106 +1,104 @@ #include "origin_plugin.h" -static int find_selector(uint32_t selector, const uint32_t *selectors, size_t n, - selector_t *out) { - for (selector_t i = 0; i < n; i++) { - if (selector == selectors[i]) { - *out = i; - return 0; +static int find_selector(uint32_t selector, const uint32_t *selectors, size_t n, selector_t *out) { + for (selector_t i = 0; i < n; i++) { + if (selector == selectors[i]) { + *out = i; + return 0; + } } - } - return -1; + return -1; } // Called once to init. void handle_init_contract(void *parameters) { - // Cast the msg to the type of structure we expect (here, - // ethPluginInitContract_t). - ethPluginInitContract_t *msg = (ethPluginInitContract_t *)parameters; + // Cast the msg to the type of structure we expect (here, + // ethPluginInitContract_t). + ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters; - // Make sure we are running a compatible version. - if (msg->interfaceVersion != ETH_PLUGIN_INTERFACE_VERSION_LATEST) { - // If not the case, return the `UNAVAILABLE` status. - msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE; - return; - } + // Make sure we are running a compatible version. + if (msg->interfaceVersion != ETH_PLUGIN_INTERFACE_VERSION_LATEST) { + // If not the case, return the `UNAVAILABLE` status. + msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE; + return; + } - // Double check that the `context_t` struct is not bigger than the maximum - // size (defined by `msg->pluginContextLength`). - if (msg->pluginContextLength < sizeof(origin_parameters_t)) { - PRINTF("Plugin parameters structure is bigger than allowed size\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - } + // Double check that the `context_t` struct is not bigger than the maximum + // size (defined by `msg->pluginContextLength`). + if (msg->pluginContextLength < sizeof(origin_parameters_t)) { + PRINTF("Plugin parameters structure is bigger than allowed size\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } - origin_parameters_t *context = (origin_parameters_t *)msg->pluginContext; + origin_parameters_t *context = (origin_parameters_t *) msg->pluginContext; - // Initialize the context (to 0). - memset(context, 0, sizeof(*context)); + // Initialize the context (to 0). + memset(context, 0, sizeof(*context)); - uint32_t selector = U4BE(msg->selector, 0); - if (find_selector(selector, ORIGIN_SELECTORS, NUM_SELECTORS, - &context->selectorIndex)) { - msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE; - return; - } + uint32_t selector = U4BE(msg->selector, 0); + if (find_selector(selector, ORIGIN_SELECTORS, NUM_SELECTORS, &context->selectorIndex)) { + msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE; + return; + } - // Set `next_param` to be the first field we expect to parse. - // EDIT THIS: Adapt the `cases`, and set the `next_param` to be the first - // parameter you expect to parse. - switch (context->selectorIndex) { - case ZAPPER_DEPOSIT_ETH: - context->next_param = NONE; - break; - case ZAPPER_DEPOSIT_SFRXETH: - context->next_param = AMOUNT_SENT; - break; - case VAULT_MINT: - context->next_param = TOKEN_SENT; - break; - case VAULT_REDEEM: - context->next_param = AMOUNT_SENT; - break; - case CURVE_POOL_EXCHANGE: - case CURVE_POOL_EXCHANGE_UNDERLYING: - if (memcmp(CURVE_OETH_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0 || - memcmp(CURVE_OUSD_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - context->next_param = TOKEN_SENT; - break; - } - PRINTF("Missing selectorIndex: %d\n", context->selectorIndex); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - case CURVE_ROUTER_EXCHANGE_MULTIPLE: - context->next_param = TOKEN_SENT; - break; - case UNISWAP_ROUTER_EXACT_INPUT: - context->skip += 2; - context->next_param = BENEFICIARY; - break; - case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: - context->next_param = TOKEN_SENT; - break; - case FLIPPER_BUY_OUSD_WITH_USDT: - case FLIPPER_SELL_OUSD_FOR_USDT: - case FLIPPER_BUY_OUSD_WITH_DAI: - case FLIPPER_SELL_OUSD_FOR_DAI: - case FLIPPER_BUY_OUSD_WITH_USDC: - case FLIPPER_SELL_OUSD_FOR_USDC: - case WRAP: - case UNWRAP: - context->next_param = AMOUNT_SENT; - break; - // Keep this - default: - PRINTF("Missing selectorIndex: %d\n", context->selectorIndex); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - } + // Set `next_param` to be the first field we expect to parse. + // EDIT THIS: Adapt the `cases`, and set the `next_param` to be the first + // parameter you expect to parse. + switch (context->selectorIndex) { + case ZAPPER_DEPOSIT_ETH: + context->next_param = NONE; + break; + case ZAPPER_DEPOSIT_SFRXETH: + context->next_param = AMOUNT_SENT; + break; + case VAULT_MINT: + context->next_param = TOKEN_SENT; + break; + case VAULT_REDEEM: + context->next_param = AMOUNT_SENT; + break; + case CURVE_POOL_EXCHANGE: + case CURVE_POOL_EXCHANGE_UNDERLYING: + if (memcmp(CURVE_OETH_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0 || + memcmp(CURVE_OUSD_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + context->next_param = TOKEN_SENT; + break; + } + PRINTF("Missing selectorIndex: %d\n", context->selectorIndex); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + case CURVE_ROUTER_EXCHANGE_MULTIPLE: + context->next_param = TOKEN_SENT; + break; + case UNISWAP_ROUTER_EXACT_INPUT: + context->skip += 2; + context->next_param = BENEFICIARY; + break; + case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: + context->next_param = TOKEN_SENT; + break; + case FLIPPER_BUY_OUSD_WITH_USDT: + case FLIPPER_SELL_OUSD_FOR_USDT: + case FLIPPER_BUY_OUSD_WITH_DAI: + case FLIPPER_SELL_OUSD_FOR_DAI: + case FLIPPER_BUY_OUSD_WITH_USDC: + case FLIPPER_SELL_OUSD_FOR_USDC: + case WRAP: + case UNWRAP: + context->next_param = AMOUNT_SENT; + break; + // Keep this + default: + PRINTF("Missing selectorIndex: %d\n", context->selectorIndex); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } - // Return valid status. - msg->result = ETH_PLUGIN_RESULT_OK; + // Return valid status. + msg->result = ETH_PLUGIN_RESULT_OK; } diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index f8993bc5..c83f56ca 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -1,374 +1,355 @@ #include "origin_plugin.h" -static void handle_token_sent(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - memset(context->contract_address_sent, 0, - sizeof(context->contract_address_sent)); +static void handle_token_sent(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + memset(context->contract_address_sent, 0, sizeof(context->contract_address_sent)); - if (context->selectorIndex == CURVE_POOL_EXCHANGE || - context->selectorIndex == CURVE_POOL_EXCHANGE_UNDERLYING) { - if (memcmp(CURVE_OETH_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - switch (msg->parameter[PARAMETER_LENGTH - 1]) { - case 0: - memcpy(context->contract_address_sent, NULL_ETH_ADDRESS, - ADDRESS_LENGTH); - break; - case 1: - memcpy(context->contract_address_sent, OETH_ADDRESS, ADDRESS_LENGTH); - break; - default: - PRINTF("Param not supported\n"); - break; - } - } else if (memcmp(CURVE_OUSD_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - switch (msg->parameter[PARAMETER_LENGTH - 1]) { - case 0: - memcpy(context->contract_address_sent, OUSD_ADDRESS, ADDRESS_LENGTH); - break; - case 1: - memcpy(context->contract_address_sent, DAI_ADDRESS, ADDRESS_LENGTH); - break; - case 2: - memcpy(context->contract_address_sent, USDC_ADDRESS, ADDRESS_LENGTH); - break; - case 3: - memcpy(context->contract_address_sent, USDT_ADDRESS, ADDRESS_LENGTH); - break; - default: - PRINTF("Param not supported\n"); - break; - } + if (context->selectorIndex == CURVE_POOL_EXCHANGE || + context->selectorIndex == CURVE_POOL_EXCHANGE_UNDERLYING) { + if (memcmp(CURVE_OETH_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + switch (msg->parameter[PARAMETER_LENGTH - 1]) { + case 0: + memcpy(context->contract_address_sent, NULL_ETH_ADDRESS, ADDRESS_LENGTH); + break; + case 1: + memcpy(context->contract_address_sent, OETH_ADDRESS, ADDRESS_LENGTH); + break; + default: + PRINTF("Param not supported\n"); + break; + } + } else if (memcmp(CURVE_OUSD_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + switch (msg->parameter[PARAMETER_LENGTH - 1]) { + case 0: + memcpy(context->contract_address_sent, OUSD_ADDRESS, ADDRESS_LENGTH); + break; + case 1: + memcpy(context->contract_address_sent, DAI_ADDRESS, ADDRESS_LENGTH); + break; + case 2: + memcpy(context->contract_address_sent, USDC_ADDRESS, ADDRESS_LENGTH); + break; + case 3: + memcpy(context->contract_address_sent, USDT_ADDRESS, ADDRESS_LENGTH); + break; + default: + PRINTF("Param not supported\n"); + break; + } + } + } else { + memcpy(context->contract_address_sent, + &msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], + ADDRESS_LENGTH); } - } else { - memcpy(context->contract_address_sent, - &msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], ADDRESS_LENGTH); - } - printf_hex_array("TOKEN SENT: ", ADDRESS_LENGTH, - context->contract_address_sent); + printf_hex_array("TOKEN SENT: ", ADDRESS_LENGTH, context->contract_address_sent); } -static void handle_token_received(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - memset(context->contract_address_received, 0, - sizeof(context->contract_address_received)); +static void handle_token_received(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + memset(context->contract_address_received, 0, sizeof(context->contract_address_received)); - // determine token addresses of curve pools based on contract address and - // value of i/j params - if (context->selectorIndex == CURVE_POOL_EXCHANGE || - context->selectorIndex == CURVE_POOL_EXCHANGE_UNDERLYING) { - if (memcmp(CURVE_OETH_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - switch (msg->parameter[PARAMETER_LENGTH - 1]) { - case 0: - memcpy(context->contract_address_received, NULL_ETH_ADDRESS, - ADDRESS_LENGTH); - break; - case 1: - memcpy(context->contract_address_received, OETH_ADDRESS, - ADDRESS_LENGTH); - break; - default: - PRINTF("Param not supported\n"); - break; - } - } else if (memcmp(CURVE_OUSD_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - switch (msg->parameter[PARAMETER_LENGTH - 1]) { - case 0: - memcpy(context->contract_address_received, OUSD_ADDRESS, - ADDRESS_LENGTH); - break; - case 1: - memcpy(context->contract_address_received, DAI_ADDRESS, - ADDRESS_LENGTH); - break; - case 2: - memcpy(context->contract_address_received, USDC_ADDRESS, - ADDRESS_LENGTH); - break; - case 3: - memcpy(context->contract_address_received, USDT_ADDRESS, - ADDRESS_LENGTH); - break; - default: - PRINTF("Param not supported\n"); - break; - } + // determine token addresses of curve pools based on contract address and + // value of i/j params + if (context->selectorIndex == CURVE_POOL_EXCHANGE || + context->selectorIndex == CURVE_POOL_EXCHANGE_UNDERLYING) { + if (memcmp(CURVE_OETH_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + switch (msg->parameter[PARAMETER_LENGTH - 1]) { + case 0: + memcpy(context->contract_address_received, NULL_ETH_ADDRESS, ADDRESS_LENGTH); + break; + case 1: + memcpy(context->contract_address_received, OETH_ADDRESS, ADDRESS_LENGTH); + break; + default: + PRINTF("Param not supported\n"); + break; + } + } else if (memcmp(CURVE_OUSD_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + switch (msg->parameter[PARAMETER_LENGTH - 1]) { + case 0: + memcpy(context->contract_address_received, OUSD_ADDRESS, ADDRESS_LENGTH); + break; + case 1: + memcpy(context->contract_address_received, DAI_ADDRESS, ADDRESS_LENGTH); + break; + case 2: + memcpy(context->contract_address_received, USDC_ADDRESS, ADDRESS_LENGTH); + break; + case 3: + memcpy(context->contract_address_received, USDT_ADDRESS, ADDRESS_LENGTH); + break; + default: + PRINTF("Param not supported\n"); + break; + } + } + } else { + memcpy(context->contract_address_received, + &msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], + ADDRESS_LENGTH); } - } else { - memcpy(context->contract_address_received, - &msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], ADDRESS_LENGTH); - } - printf_hex_array("TOKEN RECEIVED: ", ADDRESS_LENGTH, - context->contract_address_received); + printf_hex_array("TOKEN RECEIVED: ", ADDRESS_LENGTH, context->contract_address_received); } -static void handle_amount_sent(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - memcpy(context->amount_sent, msg->parameter, INT256_LENGTH); +static void handle_amount_sent(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + memcpy(context->amount_sent, msg->parameter, INT256_LENGTH); } static void handle_min_amount_received(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - memcpy(context->min_amount_received, msg->parameter, PARAMETER_LENGTH); + memcpy(context->min_amount_received, msg->parameter, PARAMETER_LENGTH); } -static void handle_beneficiary(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - memset(context->beneficiary, 0, sizeof(context->beneficiary)); - memcpy(context->beneficiary, - &msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], - sizeof(context->beneficiary)); - printf_hex_array("BENEFICIARY: ", ADDRESS_LENGTH, context->beneficiary); +static void handle_beneficiary(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + memset(context->beneficiary, 0, sizeof(context->beneficiary)); + memcpy(context->beneficiary, + &msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], + sizeof(context->beneficiary)); + printf_hex_array("BENEFICIARY: ", ADDRESS_LENGTH, context->beneficiary); } // deposit() static void handle_zapper_deposit_eth(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case NONE: - break; - default: - PRINTF("Param not supported: %d\n", context->next_param); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case NONE: + break; + default: + PRINTF("Param not supported: %d\n", context->next_param); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // depositSFRXETH(uint256 amount,uint256 minOETH) static void handle_zapper_deposit_sfrxeth(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // mint(address _asset,uint256 _amount,uint256 _minimumOusdAmount) -static void handle_vault_mint(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - switch (context->next_param) { - case TOKEN_SENT: - handle_token_sent(msg, context); - context->next_param = AMOUNT_SENT; - break; - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } +static void handle_vault_mint(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + switch (context->next_param) { + case TOKEN_SENT: + handle_token_sent(msg, context); + context->next_param = AMOUNT_SENT; + break; + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // redeem(uint256 _amount,uint256 _minimumUnitAmount) -static void handle_vault_redeem(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - switch (context->next_param) { - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } +static void handle_vault_redeem(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + switch (context->next_param) { + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // exchange(int128 i,int128 j,uint256 _dx,uint256 _min_dy) static void handle_curve_pool_exchange(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case TOKEN_SENT: - handle_token_sent(msg, context); - context->next_param = TOKEN_RECEIVED; - break; - case TOKEN_RECEIVED: - handle_token_received(msg, context); - context->next_param = AMOUNT_SENT; - break; - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case TOKEN_SENT: + handle_token_sent(msg, context); + context->next_param = TOKEN_RECEIVED; + break; + case TOKEN_RECEIVED: + handle_token_received(msg, context); + context->next_param = AMOUNT_SENT; + break; + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // exchange_multiple(address[9] _route,uint256[3][4] _swap_params,uint256 // _amount,uint256 _expected) static void handle_curve_router_exchange(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case TOKEN_SENT: - handle_token_sent(msg, context); - context->next_param = TOKEN_RECEIVED; - break; - case TOKEN_RECEIVED: - PRINTF("Counter: %d\n", context->counter); - context->counter += 1; - if (memcmp(&msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], - NULL_ETH_ADDRESS, ADDRESS_LENGTH) == 0) { - context->skip += 20 - context->counter; - context->counter = 0; - context->next_param = AMOUNT_SENT; - } else { - handle_token_received(msg, context); - context->next_param = TOKEN_RECEIVED; - } - break; - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case TOKEN_SENT: + handle_token_sent(msg, context); + context->next_param = TOKEN_RECEIVED; + break; + case TOKEN_RECEIVED: + PRINTF("Counter: %d\n", context->counter); + context->counter += 1; + if (memcmp(&msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH], + NULL_ETH_ADDRESS, + ADDRESS_LENGTH) == 0) { + context->skip += 20 - context->counter; + context->counter = 0; + context->next_param = AMOUNT_SENT; + } else { + handle_token_received(msg, context); + context->next_param = TOKEN_RECEIVED; + } + break; + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // exactInput(tuple params) static void handle_uniswap_exchange(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case BENEFICIARY: - handle_beneficiary(msg, context); - context->skip += 1; - context->next_param = AMOUNT_SENT; - break; - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = PATH_LENGTH; - break; - case PATH_LENGTH: - context->offset = - U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->offset)); - PRINTF("OFFSET: %d\n", context->offset); - context->next_param = TOKEN_SENT; - break; - case TOKEN_SENT: - // first 20 bytes of path is token sent - memcpy(context->contract_address_sent, msg->parameter, ADDRESS_LENGTH); - printf_hex_array("TOKEN_SENT: ", ADDRESS_LENGTH, - context->contract_address_sent); - context->skip = (context->offset - ADDRESS_LENGTH) / 32 - 1; - context->next_param = TOKEN_RECEIVED; - break; - case TOKEN_RECEIVED: - // address of token received starts at 20 bytes from end of path - memcpy(&context->contract_address_received[0], - &msg->parameter[(context->offset - ADDRESS_LENGTH) % - PARAMETER_LENGTH], - ADDRESS_LENGTH); - context->next_param = TOKEN_RECEIVED_REST; - break; - case TOKEN_RECEIVED_REST: - // copy rest of address in case it overflows into the next param - memcpy( - &context - ->contract_address_received[PARAMETER_LENGTH - - (context->offset - ADDRESS_LENGTH) % - PARAMETER_LENGTH], - &msg->parameter[0], - (context->offset - ADDRESS_LENGTH) % PARAMETER_LENGTH + - ADDRESS_LENGTH - PARAMETER_LENGTH); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case BENEFICIARY: + handle_beneficiary(msg, context); + context->skip += 1; + context->next_param = AMOUNT_SENT; + break; + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = PATH_LENGTH; + break; + case PATH_LENGTH: + context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->offset)); + PRINTF("OFFSET: %d\n", context->offset); + context->next_param = TOKEN_SENT; + break; + case TOKEN_SENT: + // first 20 bytes of path is token sent + memcpy(context->contract_address_sent, msg->parameter, ADDRESS_LENGTH); + printf_hex_array("TOKEN_SENT: ", ADDRESS_LENGTH, context->contract_address_sent); + context->skip = (context->offset - ADDRESS_LENGTH) / 32 - 1; + context->next_param = TOKEN_RECEIVED; + break; + case TOKEN_RECEIVED: + // address of token received starts at 20 bytes from end of path + memcpy(&context->contract_address_received[0], + &msg->parameter[(context->offset - ADDRESS_LENGTH) % PARAMETER_LENGTH], + ADDRESS_LENGTH); + context->next_param = TOKEN_RECEIVED_REST; + break; + case TOKEN_RECEIVED_REST: + // copy rest of address in case it overflows into the next param + memcpy(&context->contract_address_received[PARAMETER_LENGTH - + (context->offset - ADDRESS_LENGTH) % + PARAMETER_LENGTH], + &msg->parameter[0], + (context->offset - ADDRESS_LENGTH) % PARAMETER_LENGTH + ADDRESS_LENGTH - + PARAMETER_LENGTH); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // exactInputSingle(tuple params) static void handle_uniswap_exchange_single(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case TOKEN_SENT: - handle_token_sent(msg, context); - context->next_param = TOKEN_RECEIVED; - break; - case TOKEN_RECEIVED: - handle_token_received(msg, context); - context->skip += 1; - context->next_param = BENEFICIARY; - break; - case BENEFICIARY: - handle_beneficiary(msg, context); - context->skip += 1; - context->next_param = AMOUNT_SENT; - break; - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = MIN_AMOUNT_RECEIVED; - break; - case MIN_AMOUNT_RECEIVED: - handle_min_amount_received(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case TOKEN_SENT: + handle_token_sent(msg, context); + context->next_param = TOKEN_RECEIVED; + break; + case TOKEN_RECEIVED: + handle_token_received(msg, context); + context->skip += 1; + context->next_param = BENEFICIARY; + break; + case BENEFICIARY: + handle_beneficiary(msg, context); + context->skip += 1; + context->next_param = AMOUNT_SENT; + break; + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = MIN_AMOUNT_RECEIVED; + break; + case MIN_AMOUNT_RECEIVED: + handle_min_amount_received(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // buyOusdWithUsdt(uint256 amount) @@ -379,96 +360,94 @@ static void handle_uniswap_exchange_single(ethPluginProvideParameter_t *msg, // sellOusdForUsdc(uint256 amount) static void handle_flipper_exchange(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { - switch (context->next_param) { - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } + switch (context->next_param) { + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } // deposit(uint256 assets,address receiver) // redeem(uint256 shares,address receiver,address owner) -static void handle_wrap(ethPluginProvideParameter_t *msg, - origin_parameters_t *context) { - switch (context->next_param) { - case AMOUNT_SENT: - handle_amount_sent(msg, context); - context->next_param = BENEFICIARY; - break; - case BENEFICIARY: - handle_beneficiary(msg, context); - context->next_param = NONE; - break; - case NONE: - break; - default: - PRINTF("Param not supported\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; - } +static void handle_wrap(ethPluginProvideParameter_t *msg, origin_parameters_t *context) { + switch (context->next_param) { + case AMOUNT_SENT: + handle_amount_sent(msg, context); + context->next_param = BENEFICIARY; + break; + case BENEFICIARY: + handle_beneficiary(msg, context); + context->next_param = NONE; + break; + case NONE: + break; + default: + PRINTF("Param not supported\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } void handle_provide_parameter(void *parameters) { - ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *)parameters; - origin_parameters_t *context = (origin_parameters_t *)msg->pluginContext; - printf_hex_array("oeth plugin provide parameter: ", PARAMETER_LENGTH, - msg->parameter); + ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters; + origin_parameters_t *context = (origin_parameters_t *) msg->pluginContext; + printf_hex_array("oeth plugin provide parameter: ", PARAMETER_LENGTH, msg->parameter); - msg->result = ETH_PLUGIN_RESULT_OK; + msg->result = ETH_PLUGIN_RESULT_OK; - if (context->skip) { - // Skip this step, and don't forget to decrease skipping counter. - context->skip--; - } else { - switch (context->selectorIndex) { - case ZAPPER_DEPOSIT_ETH: - handle_zapper_deposit_eth(msg, context); - break; - case ZAPPER_DEPOSIT_SFRXETH: - handle_zapper_deposit_sfrxeth(msg, context); - break; - case VAULT_MINT: - handle_vault_mint(msg, context); - break; - case VAULT_REDEEM: - handle_vault_redeem(msg, context); - break; - case CURVE_POOL_EXCHANGE: - case CURVE_POOL_EXCHANGE_UNDERLYING: - handle_curve_pool_exchange(msg, context); - break; - case CURVE_ROUTER_EXCHANGE_MULTIPLE: - handle_curve_router_exchange(msg, context); - break; - case UNISWAP_ROUTER_EXACT_INPUT: - handle_uniswap_exchange(msg, context); - break; - case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: - handle_uniswap_exchange_single(msg, context); - break; - case FLIPPER_BUY_OUSD_WITH_USDT: - case FLIPPER_SELL_OUSD_FOR_USDT: - case FLIPPER_BUY_OUSD_WITH_DAI: - case FLIPPER_SELL_OUSD_FOR_DAI: - case FLIPPER_BUY_OUSD_WITH_USDC: - case FLIPPER_SELL_OUSD_FOR_USDC: - handle_flipper_exchange(msg, context); - break; - case WRAP: - case UNWRAP: - handle_wrap(msg, context); - break; - default: - PRINTF("Selector Index %d not supported\n", context->selectorIndex); - msg->result = ETH_PLUGIN_RESULT_ERROR; - break; + if (context->skip) { + // Skip this step, and don't forget to decrease skipping counter. + context->skip--; + } else { + switch (context->selectorIndex) { + case ZAPPER_DEPOSIT_ETH: + handle_zapper_deposit_eth(msg, context); + break; + case ZAPPER_DEPOSIT_SFRXETH: + handle_zapper_deposit_sfrxeth(msg, context); + break; + case VAULT_MINT: + handle_vault_mint(msg, context); + break; + case VAULT_REDEEM: + handle_vault_redeem(msg, context); + break; + case CURVE_POOL_EXCHANGE: + case CURVE_POOL_EXCHANGE_UNDERLYING: + handle_curve_pool_exchange(msg, context); + break; + case CURVE_ROUTER_EXCHANGE_MULTIPLE: + handle_curve_router_exchange(msg, context); + break; + case UNISWAP_ROUTER_EXACT_INPUT: + handle_uniswap_exchange(msg, context); + break; + case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: + handle_uniswap_exchange_single(msg, context); + break; + case FLIPPER_BUY_OUSD_WITH_USDT: + case FLIPPER_SELL_OUSD_FOR_USDT: + case FLIPPER_BUY_OUSD_WITH_DAI: + case FLIPPER_SELL_OUSD_FOR_DAI: + case FLIPPER_BUY_OUSD_WITH_USDC: + case FLIPPER_SELL_OUSD_FOR_USDC: + handle_flipper_exchange(msg, context); + break; + case WRAP: + case UNWRAP: + handle_wrap(msg, context); + break; + default: + PRINTF("Selector Index %d not supported\n", context->selectorIndex); + msg->result = ETH_PLUGIN_RESULT_ERROR; + break; + } } - } } \ No newline at end of file diff --git a/src/handle_provide_token.c b/src/handle_provide_token.c index 20cd6181..2828ac56 100644 --- a/src/handle_provide_token.c +++ b/src/handle_provide_token.c @@ -5,48 +5,47 @@ // `NULL`, this means the ethereum app didn't find any info regarding the // requested tokens! void handle_provide_token(void *parameters) { - ethPluginProvideInfo_t *msg = (ethPluginProvideInfo_t *)parameters; - origin_parameters_t *context = (origin_parameters_t *)msg->pluginContext; - PRINTF("OETH plugin provide token: 0x%p, 0x%p\n", msg->item1, msg->item2); - if (!check_token_sent(context)) { - if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { - sent_network_token(context); - } else if (msg->item1 != NULL) { - context->decimals_sent = msg->item1->token.decimals; - strlcpy(context->ticker_sent, (char *)msg->item1->token.ticker, - sizeof(context->ticker_sent)); - context->tokens_found |= TOKEN_SENT_FOUND; - } else { - // CAL did not find the token and token is not ETH. - context->decimals_sent = DEFAULT_DECIMAL; - strlcpy(context->ticker_sent, DEFAULT_TICKER, - sizeof(context->ticker_sent)); - // // We will need an additional screen to display a warning message. - msg->additionalScreens++; + ethPluginProvideInfo_t *msg = (ethPluginProvideInfo_t *) parameters; + origin_parameters_t *context = (origin_parameters_t *) msg->pluginContext; + PRINTF("OETH plugin provide token: 0x%p, 0x%p\n", msg->item1, msg->item2); + if (!check_token_sent(context)) { + if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { + sent_network_token(context); + } else if (msg->item1 != NULL) { + context->decimals_sent = msg->item1->token.decimals; + strlcpy(context->ticker_sent, + (char *) msg->item1->token.ticker, + sizeof(context->ticker_sent)); + context->tokens_found |= TOKEN_SENT_FOUND; + } else { + // CAL did not find the token and token is not ETH. + context->decimals_sent = DEFAULT_DECIMAL; + strlcpy(context->ticker_sent, DEFAULT_TICKER, sizeof(context->ticker_sent)); + // // We will need an additional screen to display a warning message. + msg->additionalScreens++; + } } - } - if (!check_token_received(context)) { - if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { - received_network_token(context); - } else if (msg->item2 != NULL) { - context->decimals_received = msg->item2->token.decimals; - strlcpy(context->ticker_received, (char *)msg->item2->token.ticker, - sizeof(context->ticker_received)); - context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else if (context->selectorIndex == VAULT_REDEEM) { - context->decimals_received = DEFAULT_DECIMAL; - strlcpy(context->ticker_received, "UNITS", - sizeof(context->ticker_received)); - } else { - // CAL did not find the token and token is not ETH. - context->decimals_received = DEFAULT_DECIMAL; - strlcpy(context->ticker_received, DEFAULT_TICKER, - sizeof(context->ticker_received)); - // // We will need an additional screen to display a warning message. - msg->additionalScreens++; + if (!check_token_received(context)) { + if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { + received_network_token(context); + } else if (msg->item2 != NULL) { + context->decimals_received = msg->item2->token.decimals; + strlcpy(context->ticker_received, + (char *) msg->item2->token.ticker, + sizeof(context->ticker_received)); + context->tokens_found |= TOKEN_RECEIVED_FOUND; + } else if (context->selectorIndex == VAULT_REDEEM) { + context->decimals_received = DEFAULT_DECIMAL; + strlcpy(context->ticker_received, "UNITS", sizeof(context->ticker_received)); + } else { + // CAL did not find the token and token is not ETH. + context->decimals_received = DEFAULT_DECIMAL; + strlcpy(context->ticker_received, DEFAULT_TICKER, sizeof(context->ticker_received)); + // // We will need an additional screen to display a warning message. + msg->additionalScreens++; + } } - } - msg->result = ETH_PLUGIN_RESULT_OK; + msg->result = ETH_PLUGIN_RESULT_OK; } \ No newline at end of file diff --git a/src/handle_query_contract_id.c b/src/handle_query_contract_id.c index 79e86fc5..22d8832a 100644 --- a/src/handle_query_contract_id.c +++ b/src/handle_query_contract_id.c @@ -2,48 +2,47 @@ // Sets the first screen to display. void handle_query_contract_id(void *parameters) { - ethQueryContractID_t *msg = (ethQueryContractID_t *)parameters; - const origin_parameters_t *context = - (const origin_parameters_t *)msg->pluginContext; - // msg->name will be the upper sentence displayed on the screen. - // msg->version will be the lower sentence displayed on the screen. + ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters; + const origin_parameters_t *context = (const origin_parameters_t *) msg->pluginContext; + // msg->name will be the upper sentence displayed on the screen. + // msg->version will be the lower sentence displayed on the screen. - // For the first screen, display the plugin name. - strlcpy(msg->name, PLUGIN_NAME, msg->nameLength); + // For the first screen, display the plugin name. + strlcpy(msg->name, PLUGIN_NAME, msg->nameLength); - switch (context->selectorIndex) { - case ZAPPER_DEPOSIT_ETH: - case ZAPPER_DEPOSIT_SFRXETH: - case VAULT_MINT: - strlcpy(msg->version, "Mint", msg->versionLength); - break; - case VAULT_REDEEM: - strlcpy(msg->version, "Redeem", msg->versionLength); - break; - case CURVE_POOL_EXCHANGE: - case CURVE_POOL_EXCHANGE_UNDERLYING: - case CURVE_ROUTER_EXCHANGE_MULTIPLE: - case UNISWAP_ROUTER_EXACT_INPUT: - case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: - case FLIPPER_BUY_OUSD_WITH_USDT: - case FLIPPER_SELL_OUSD_FOR_USDT: - case FLIPPER_BUY_OUSD_WITH_DAI: - case FLIPPER_SELL_OUSD_FOR_DAI: - case FLIPPER_BUY_OUSD_WITH_USDC: - case FLIPPER_SELL_OUSD_FOR_USDC: - strlcpy(msg->version, "Swap", msg->versionLength); - break; - case WRAP: - strlcpy(msg->version, "Wrap", msg->versionLength); - break; - case UNWRAP: - strlcpy(msg->version, "Unwrap", msg->versionLength); - break; - default: - PRINTF("Selector Index :%d not supported\n", context->selectorIndex); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - } + switch (context->selectorIndex) { + case ZAPPER_DEPOSIT_ETH: + case ZAPPER_DEPOSIT_SFRXETH: + case VAULT_MINT: + strlcpy(msg->version, "Mint", msg->versionLength); + break; + case VAULT_REDEEM: + strlcpy(msg->version, "Redeem", msg->versionLength); + break; + case CURVE_POOL_EXCHANGE: + case CURVE_POOL_EXCHANGE_UNDERLYING: + case CURVE_ROUTER_EXCHANGE_MULTIPLE: + case UNISWAP_ROUTER_EXACT_INPUT: + case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: + case FLIPPER_BUY_OUSD_WITH_USDT: + case FLIPPER_SELL_OUSD_FOR_USDT: + case FLIPPER_BUY_OUSD_WITH_DAI: + case FLIPPER_SELL_OUSD_FOR_DAI: + case FLIPPER_BUY_OUSD_WITH_USDC: + case FLIPPER_SELL_OUSD_FOR_USDC: + strlcpy(msg->version, "Swap", msg->versionLength); + break; + case WRAP: + strlcpy(msg->version, "Wrap", msg->versionLength); + break; + case UNWRAP: + strlcpy(msg->version, "Unwrap", msg->versionLength); + break; + default: + PRINTF("Selector Index :%d not supported\n", context->selectorIndex); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } - msg->result = ETH_PLUGIN_RESULT_OK; + msg->result = ETH_PLUGIN_RESULT_OK; } \ No newline at end of file diff --git a/src/handle_query_contract_ui.c b/src/handle_query_contract_ui.c index 7a25027e..2347b5df 100644 --- a/src/handle_query_contract_ui.c +++ b/src/handle_query_contract_ui.c @@ -1,339 +1,325 @@ #include "origin_plugin.h" -static void set_send_ui(ethQueryContractUI_t *msg, - origin_parameters_t *context) { - // set network ticker (ETH, BNB, etc) if needed - if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { - strlcpy(context->ticker_sent, msg->network_ticker, - sizeof(context->ticker_sent)); - } else if (ADDRESS_IS_OETH(context->contract_address_sent)) { - strlcpy(context->ticker_sent, OETH_TICKER, sizeof(context->ticker_sent)); - } else if (ADDRESS_IS_OUSD(context->contract_address_sent)) { - strlcpy(context->ticker_sent, OUSD_TICKER, sizeof(context->ticker_sent)); - } else if (ADDRESS_IS_DAI(context->contract_address_sent)) { - strlcpy(context->ticker_sent, DAI_TICKER, sizeof(context->ticker_sent)); - } else if (ADDRESS_IS_USDC(context->contract_address_sent)) { - strlcpy(context->ticker_sent, USDC_TICKER, sizeof(context->ticker_sent)); - } else if (ADDRESS_IS_USDT(context->contract_address_sent)) { - strlcpy(context->ticker_sent, USDT_TICKER, sizeof(context->ticker_sent)); - } +static void set_send_ui(ethQueryContractUI_t *msg, origin_parameters_t *context) { + // set network ticker (ETH, BNB, etc) if needed + if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { + strlcpy(context->ticker_sent, msg->network_ticker, sizeof(context->ticker_sent)); + } else if (ADDRESS_IS_OETH(context->contract_address_sent)) { + strlcpy(context->ticker_sent, OETH_TICKER, sizeof(context->ticker_sent)); + } else if (ADDRESS_IS_OUSD(context->contract_address_sent)) { + strlcpy(context->ticker_sent, OUSD_TICKER, sizeof(context->ticker_sent)); + } else if (ADDRESS_IS_DAI(context->contract_address_sent)) { + strlcpy(context->ticker_sent, DAI_TICKER, sizeof(context->ticker_sent)); + } else if (ADDRESS_IS_USDC(context->contract_address_sent)) { + strlcpy(context->ticker_sent, USDC_TICKER, sizeof(context->ticker_sent)); + } else if (ADDRESS_IS_USDT(context->contract_address_sent)) { + strlcpy(context->ticker_sent, USDT_TICKER, sizeof(context->ticker_sent)); + } - context->amount_length = INT256_LENGTH; + context->amount_length = INT256_LENGTH; - strlcpy(msg->title, "Send", msg->titleLength); + strlcpy(msg->title, "Send", msg->titleLength); - switch (context->selectorIndex) { - case ZAPPER_DEPOSIT_ETH: - strlcpy(msg->title, "Deposit", msg->titleLength); - memcpy(context->amount_sent, &msg->pluginSharedRO->txContent->value.value, - msg->pluginSharedRO->txContent->value.length); - context->amount_length = msg->pluginSharedRO->txContent->value.length; - break; - case ZAPPER_DEPOSIT_SFRXETH: - strlcpy(msg->title, "Deposit", msg->titleLength); - strlcpy(context->ticker_sent, SFRXETH_TICKER, - sizeof(context->ticker_sent)); - break; - case VAULT_MINT: - strlcpy(msg->title, "Deposit", msg->titleLength); - break; - case VAULT_REDEEM: - strlcpy(msg->title, "Redeem", msg->titleLength); - if (memcmp(OETH_VAULT_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - strlcpy(context->ticker_sent, OETH_TICKER, - sizeof(context->ticker_sent)); - } else { - strlcpy(context->ticker_sent, OUSD_TICKER, - sizeof(context->ticker_sent)); - } - break; - case CURVE_POOL_EXCHANGE: - break; - case CURVE_POOL_EXCHANGE_UNDERLYING: - break; - case CURVE_ROUTER_EXCHANGE_MULTIPLE: - case UNISWAP_ROUTER_EXACT_INPUT: - case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: - break; - case FLIPPER_BUY_OUSD_WITH_USDT: - strlcpy(context->ticker_sent, USDT_TICKER, sizeof(context->ticker_sent)); - context->decimals_sent = DEFAULT_DECIMAL; - break; - case FLIPPER_BUY_OUSD_WITH_DAI: - strlcpy(context->ticker_sent, DAI_TICKER, sizeof(context->ticker_sent)); - context->decimals_sent = DAI_DECIMALS; - break; - case FLIPPER_BUY_OUSD_WITH_USDC: - strlcpy(context->ticker_sent, USDC_TICKER, sizeof(context->ticker_sent)); - context->decimals_sent = DEFAULT_DECIMAL; - break; - case FLIPPER_SELL_OUSD_FOR_USDT: - case FLIPPER_SELL_OUSD_FOR_DAI: - case FLIPPER_SELL_OUSD_FOR_USDC: - strlcpy(context->ticker_sent, OUSD_TICKER, sizeof(context->ticker_sent)); - context->decimals_sent = OUSD_DECIMALS; - break; - case WRAP: - strlcpy(msg->title, "Wrap", msg->titleLength); - if (memcmp(WOETH_ADDRESS, msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - strlcpy(context->ticker_sent, OETH_TICKER, - sizeof(context->ticker_sent)); - } else { - strlcpy(context->ticker_sent, OUSD_TICKER, - sizeof(context->ticker_sent)); - } - break; - case UNWRAP: - strlcpy(msg->title, "Unwrap", msg->titleLength); - if (memcmp(WOETH_ADDRESS, msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - strlcpy(context->ticker_sent, WOETH_TICKER, - sizeof(context->ticker_sent)); - } else { - strlcpy(context->ticker_sent, WOUSD_TICKER, - sizeof(context->ticker_sent)); - } - break; - default: - PRINTF("Unhandled selector Index: %d\n", context->selectorIndex); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - } + switch (context->selectorIndex) { + case ZAPPER_DEPOSIT_ETH: + strlcpy(msg->title, "Deposit", msg->titleLength); + memcpy(context->amount_sent, + &msg->pluginSharedRO->txContent->value.value, + msg->pluginSharedRO->txContent->value.length); + context->amount_length = msg->pluginSharedRO->txContent->value.length; + break; + case ZAPPER_DEPOSIT_SFRXETH: + strlcpy(msg->title, "Deposit", msg->titleLength); + strlcpy(context->ticker_sent, SFRXETH_TICKER, sizeof(context->ticker_sent)); + break; + case VAULT_MINT: + strlcpy(msg->title, "Deposit", msg->titleLength); + break; + case VAULT_REDEEM: + strlcpy(msg->title, "Redeem", msg->titleLength); + if (memcmp(OETH_VAULT_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + strlcpy(context->ticker_sent, OETH_TICKER, sizeof(context->ticker_sent)); + } else { + strlcpy(context->ticker_sent, OUSD_TICKER, sizeof(context->ticker_sent)); + } + break; + case CURVE_POOL_EXCHANGE: + break; + case CURVE_POOL_EXCHANGE_UNDERLYING: + break; + case CURVE_ROUTER_EXCHANGE_MULTIPLE: + case UNISWAP_ROUTER_EXACT_INPUT: + case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: + break; + case FLIPPER_BUY_OUSD_WITH_USDT: + strlcpy(context->ticker_sent, USDT_TICKER, sizeof(context->ticker_sent)); + context->decimals_sent = DEFAULT_DECIMAL; + break; + case FLIPPER_BUY_OUSD_WITH_DAI: + strlcpy(context->ticker_sent, DAI_TICKER, sizeof(context->ticker_sent)); + context->decimals_sent = DAI_DECIMALS; + break; + case FLIPPER_BUY_OUSD_WITH_USDC: + strlcpy(context->ticker_sent, USDC_TICKER, sizeof(context->ticker_sent)); + context->decimals_sent = DEFAULT_DECIMAL; + break; + case FLIPPER_SELL_OUSD_FOR_USDT: + case FLIPPER_SELL_OUSD_FOR_DAI: + case FLIPPER_SELL_OUSD_FOR_USDC: + strlcpy(context->ticker_sent, OUSD_TICKER, sizeof(context->ticker_sent)); + context->decimals_sent = OUSD_DECIMALS; + break; + case WRAP: + strlcpy(msg->title, "Wrap", msg->titleLength); + if (memcmp(WOETH_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + strlcpy(context->ticker_sent, OETH_TICKER, sizeof(context->ticker_sent)); + } else { + strlcpy(context->ticker_sent, OUSD_TICKER, sizeof(context->ticker_sent)); + } + break; + case UNWRAP: + strlcpy(msg->title, "Unwrap", msg->titleLength); + if (memcmp(WOETH_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + strlcpy(context->ticker_sent, WOETH_TICKER, sizeof(context->ticker_sent)); + } else { + strlcpy(context->ticker_sent, WOUSD_TICKER, sizeof(context->ticker_sent)); + } + break; + default: + PRINTF("Unhandled selector Index: %d\n", context->selectorIndex); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } - // Convert to string. - amountToString(context->amount_sent, context->amount_length, - context->decimals_sent, context->ticker_sent, msg->msg, - msg->msgLength); - PRINTF("AMOUNT SENT: %s\n", msg->msg); + // Convert to string. + amountToString(context->amount_sent, + context->amount_length, + context->decimals_sent, + context->ticker_sent, + msg->msg, + msg->msgLength); + PRINTF("AMOUNT SENT: %s\n", msg->msg); } // Set UI for "Receive" screen. -static void set_receive_ui(ethQueryContractUI_t *msg, - origin_parameters_t *context) { - // set network ticker (ETH, BNB, etc) if needed - if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { - strlcpy(context->ticker_received, msg->network_ticker, - sizeof(context->ticker_received)); - } else if (ADDRESS_IS_OETH(context->contract_address_received)) { - strlcpy(context->ticker_received, OETH_TICKER, - sizeof(context->ticker_received)); - } else if (ADDRESS_IS_OUSD(context->contract_address_received)) { - strlcpy(context->ticker_received, OUSD_TICKER, - sizeof(context->ticker_received)); - } else if (ADDRESS_IS_DAI(context->contract_address_received)) { - strlcpy(context->ticker_received, DAI_TICKER, - sizeof(context->ticker_received)); - } else if (ADDRESS_IS_USDC(context->contract_address_received)) { - strlcpy(context->ticker_received, USDC_TICKER, - sizeof(context->ticker_received)); - } else if (ADDRESS_IS_USDT(context->contract_address_received)) { - strlcpy(context->ticker_received, USDT_TICKER, - sizeof(context->ticker_received)); - } +static void set_receive_ui(ethQueryContractUI_t *msg, origin_parameters_t *context) { + // set network ticker (ETH, BNB, etc) if needed + if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { + strlcpy(context->ticker_received, msg->network_ticker, sizeof(context->ticker_received)); + } else if (ADDRESS_IS_OETH(context->contract_address_received)) { + strlcpy(context->ticker_received, OETH_TICKER, sizeof(context->ticker_received)); + } else if (ADDRESS_IS_OUSD(context->contract_address_received)) { + strlcpy(context->ticker_received, OUSD_TICKER, sizeof(context->ticker_received)); + } else if (ADDRESS_IS_DAI(context->contract_address_received)) { + strlcpy(context->ticker_received, DAI_TICKER, sizeof(context->ticker_received)); + } else if (ADDRESS_IS_USDC(context->contract_address_received)) { + strlcpy(context->ticker_received, USDC_TICKER, sizeof(context->ticker_received)); + } else if (ADDRESS_IS_USDT(context->contract_address_received)) { + strlcpy(context->ticker_received, USDT_TICKER, sizeof(context->ticker_received)); + } - context->amount_length = INT256_LENGTH; + context->amount_length = INT256_LENGTH; - strlcpy(msg->title, "Receive Min", msg->titleLength); + strlcpy(msg->title, "Receive Min", msg->titleLength); - switch (context->selectorIndex) { - case ZAPPER_DEPOSIT_ETH: - memcpy(context->min_amount_received, - &msg->pluginSharedRO->txContent->value.value, - msg->pluginSharedRO->txContent->value.length); - context->amount_length = msg->pluginSharedRO->txContent->value.length; - strlcpy(context->ticker_received, OETH_TICKER, - sizeof(context->ticker_received)); - break; - case ZAPPER_DEPOSIT_SFRXETH: - case VAULT_MINT: - if (memcmp(OETH_VAULT_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - strlcpy(context->ticker_received, OETH_TICKER, - sizeof(context->ticker_received)); - } else { - strlcpy(context->ticker_received, OUSD_TICKER, - sizeof(context->ticker_received)); - } - break; - case VAULT_REDEEM: - if (memcmp(OETH_VAULT_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0) { - strlcpy(context->ticker_received, "LST MIX", - sizeof(context->ticker_received)); - } else { - strlcpy(context->ticker_received, "USD MIX", - sizeof(context->ticker_received)); - } - break; - break; - case CURVE_POOL_EXCHANGE: - break; - case CURVE_POOL_EXCHANGE_UNDERLYING: - break; - case CURVE_ROUTER_EXCHANGE_MULTIPLE: - case UNISWAP_ROUTER_EXACT_INPUT: - case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: - break; - case FLIPPER_BUY_OUSD_WITH_USDT: - case FLIPPER_BUY_OUSD_WITH_DAI: - case FLIPPER_BUY_OUSD_WITH_USDC: - memcpy(context->min_amount_received, context->amount_sent, - sizeof(context->amount_sent)); - strlcpy(context->ticker_received, OUSD_TICKER, - sizeof(context->ticker_received)); - context->decimals_received = OUSD_DECIMALS; - break; - case FLIPPER_SELL_OUSD_FOR_USDT: - memcpy(context->min_amount_received, context->amount_sent, - sizeof(context->amount_sent)); - strlcpy(context->ticker_received, USDT_TICKER, - sizeof(context->ticker_received)); - context->decimals_received = DEFAULT_DECIMAL; - break; - case FLIPPER_SELL_OUSD_FOR_DAI: - memcpy(context->min_amount_received, context->amount_sent, - sizeof(context->amount_sent)); - strlcpy(context->ticker_received, DAI_TICKER, - sizeof(context->ticker_received)); - context->decimals_received = DAI_DECIMALS; - break; - case FLIPPER_SELL_OUSD_FOR_USDC: - memcpy(context->min_amount_received, context->amount_sent, - sizeof(context->amount_sent)); - strlcpy(context->ticker_received, USDC_TICKER, - sizeof(context->ticker_received)); - context->decimals_received = DEFAULT_DECIMAL; - break; - default: - PRINTF("Unhandled selector Index: %d\n", context->selectorIndex); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - } + switch (context->selectorIndex) { + case ZAPPER_DEPOSIT_ETH: + memcpy(context->min_amount_received, + &msg->pluginSharedRO->txContent->value.value, + msg->pluginSharedRO->txContent->value.length); + context->amount_length = msg->pluginSharedRO->txContent->value.length; + strlcpy(context->ticker_received, OETH_TICKER, sizeof(context->ticker_received)); + break; + case ZAPPER_DEPOSIT_SFRXETH: + case VAULT_MINT: + if (memcmp(OETH_VAULT_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + strlcpy(context->ticker_received, OETH_TICKER, sizeof(context->ticker_received)); + } else { + strlcpy(context->ticker_received, OUSD_TICKER, sizeof(context->ticker_received)); + } + break; + case VAULT_REDEEM: + if (memcmp(OETH_VAULT_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { + strlcpy(context->ticker_received, "LST MIX", sizeof(context->ticker_received)); + } else { + strlcpy(context->ticker_received, "USD MIX", sizeof(context->ticker_received)); + } + break; + break; + case CURVE_POOL_EXCHANGE: + break; + case CURVE_POOL_EXCHANGE_UNDERLYING: + break; + case CURVE_ROUTER_EXCHANGE_MULTIPLE: + case UNISWAP_ROUTER_EXACT_INPUT: + case UNISWAP_ROUTER_EXACT_INPUT_SINGLE: + break; + case FLIPPER_BUY_OUSD_WITH_USDT: + case FLIPPER_BUY_OUSD_WITH_DAI: + case FLIPPER_BUY_OUSD_WITH_USDC: + memcpy(context->min_amount_received, + context->amount_sent, + sizeof(context->amount_sent)); + strlcpy(context->ticker_received, OUSD_TICKER, sizeof(context->ticker_received)); + context->decimals_received = OUSD_DECIMALS; + break; + case FLIPPER_SELL_OUSD_FOR_USDT: + memcpy(context->min_amount_received, + context->amount_sent, + sizeof(context->amount_sent)); + strlcpy(context->ticker_received, USDT_TICKER, sizeof(context->ticker_received)); + context->decimals_received = DEFAULT_DECIMAL; + break; + case FLIPPER_SELL_OUSD_FOR_DAI: + memcpy(context->min_amount_received, + context->amount_sent, + sizeof(context->amount_sent)); + strlcpy(context->ticker_received, DAI_TICKER, sizeof(context->ticker_received)); + context->decimals_received = DAI_DECIMALS; + break; + case FLIPPER_SELL_OUSD_FOR_USDC: + memcpy(context->min_amount_received, + context->amount_sent, + sizeof(context->amount_sent)); + strlcpy(context->ticker_received, USDC_TICKER, sizeof(context->ticker_received)); + context->decimals_received = DEFAULT_DECIMAL; + break; + default: + PRINTF("Unhandled selector Index: %d\n", context->selectorIndex); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } - // Convert to string. - amountToString(context->min_amount_received, context->amount_length, - context->decimals_received, context->ticker_received, msg->msg, - msg->msgLength); - PRINTF("AMOUNT RECEIVED: %s\n", msg->msg); + // Convert to string. + amountToString(context->min_amount_received, + context->amount_length, + context->decimals_received, + context->ticker_received, + msg->msg, + msg->msgLength); + PRINTF("AMOUNT RECEIVED: %s\n", msg->msg); } // Set UI for "Warning" screen. static void set_warning_ui(ethQueryContractUI_t *msg, - const origin_parameters_t *context - __attribute__((unused))) { - strlcpy(msg->title, "WARNING", msg->titleLength); - strlcpy(msg->msg, "Unknown token", msg->msgLength); + const origin_parameters_t *context __attribute__((unused))) { + strlcpy(msg->title, "WARNING", msg->titleLength); + strlcpy(msg->msg, "Unknown token", msg->msgLength); } -static void set_beneficiary_ui(ethQueryContractUI_t *msg, - origin_parameters_t *context) { - strlcpy(msg->title, "Beneficiary", msg->titleLength); +static void set_beneficiary_ui(ethQueryContractUI_t *msg, origin_parameters_t *context) { + strlcpy(msg->title, "Beneficiary", msg->titleLength); - msg->msg[0] = '0'; - msg->msg[1] = 'x'; + msg->msg[0] = '0'; + msg->msg[1] = 'x'; - getEthAddressStringFromBinary((uint8_t *)context->beneficiary, msg->msg + 2, - msg->pluginSharedRW->sha3, 0); + getEthAddressStringFromBinary((uint8_t *) context->beneficiary, + msg->msg + 2, + msg->pluginSharedRW->sha3, + 0); } // Helper function that returns the enum corresponding to the screen that should // be displayed. -static screens_t get_screen(const ethQueryContractUI_t *msg, - const origin_parameters_t *context) { - uint8_t index = msg->screenIndex; +static screens_t get_screen(const ethQueryContractUI_t *msg, const origin_parameters_t *context) { + uint8_t index = msg->screenIndex; - bool token_sent_found = context->tokens_found & TOKEN_SENT_FOUND; - bool token_received_found = context->tokens_found & TOKEN_RECEIVED_FOUND; + bool token_sent_found = context->tokens_found & TOKEN_SENT_FOUND; + bool token_received_found = context->tokens_found & TOKEN_RECEIVED_FOUND; - bool both_tokens_found = token_received_found && token_sent_found; - bool both_tokens_not_found = !token_received_found && !token_sent_found; + bool both_tokens_found = token_received_found && token_sent_found; + bool both_tokens_not_found = !token_received_found && !token_sent_found; - bool wrap = - context->selectorIndex == WRAP || context->selectorIndex == UNWRAP; + bool wrap = context->selectorIndex == WRAP || context->selectorIndex == UNWRAP; - switch (index) { - case 0: - if (both_tokens_found) { - return SEND_SCREEN; - } else if (both_tokens_not_found) { - return WARN_SCREEN; - } else if (token_sent_found) { - return SEND_SCREEN; - } else if (token_received_found) { - return WARN_SCREEN; - } - break; - case 1: - if (wrap) { - return BENEFICIARY_SCREEN; - } else if (both_tokens_found) { - return RECEIVE_SCREEN; - } else if (both_tokens_not_found) { - return SEND_SCREEN; - } else if (token_sent_found) { - return WARN_SCREEN; - } else if (token_received_found) { - return SEND_SCREEN; - } - break; - case 2: - if (both_tokens_found) { - return BENEFICIARY_SCREEN; - } else if (both_tokens_not_found) { - return WARN_SCREEN; - } else { - return RECEIVE_SCREEN; - } - case 3: - if (both_tokens_found) { - return ERROR; - } else if (both_tokens_not_found) { - return RECEIVE_SCREEN; - } else { - return BENEFICIARY_SCREEN; - } - break; - case 4: - if (both_tokens_found) { - return ERROR; - } else if (both_tokens_not_found) { - return BENEFICIARY_SCREEN; - } - default: - return ERROR; - break; - } - return ERROR; + switch (index) { + case 0: + if (both_tokens_found) { + return SEND_SCREEN; + } else if (both_tokens_not_found) { + return WARN_SCREEN; + } else if (token_sent_found) { + return SEND_SCREEN; + } else if (token_received_found) { + return WARN_SCREEN; + } + break; + case 1: + if (wrap) { + return BENEFICIARY_SCREEN; + } else if (both_tokens_found) { + return RECEIVE_SCREEN; + } else if (both_tokens_not_found) { + return SEND_SCREEN; + } else if (token_sent_found) { + return WARN_SCREEN; + } else if (token_received_found) { + return SEND_SCREEN; + } + break; + case 2: + if (both_tokens_found) { + return BENEFICIARY_SCREEN; + } else if (both_tokens_not_found) { + return WARN_SCREEN; + } else { + return RECEIVE_SCREEN; + } + case 3: + if (both_tokens_found) { + return ERROR; + } else if (both_tokens_not_found) { + return RECEIVE_SCREEN; + } else { + return BENEFICIARY_SCREEN; + } + break; + case 4: + if (both_tokens_found) { + return ERROR; + } else if (both_tokens_not_found) { + return BENEFICIARY_SCREEN; + } + default: + return ERROR; + break; + } + return ERROR; } void handle_query_contract_ui(void *parameters) { - ethQueryContractUI_t *msg = (ethQueryContractUI_t *)parameters; - origin_parameters_t *context = (origin_parameters_t *)msg->pluginContext; - memset(msg->title, 0, msg->titleLength); - memset(msg->msg, 0, msg->msgLength); - msg->result = ETH_PLUGIN_RESULT_OK; - screens_t screen = get_screen(msg, context); - switch (screen) { - case SEND_SCREEN: - set_send_ui(msg, context); - break; - case RECEIVE_SCREEN: - set_receive_ui(msg, context); - break; - case WARN_SCREEN: - set_warning_ui(msg, context); - break; - case BENEFICIARY_SCREEN: - set_beneficiary_ui(msg, context); - break; - default: - PRINTF("Received an invalid screenIndex\n"); - msg->result = ETH_PLUGIN_RESULT_ERROR; - return; - } + ethQueryContractUI_t *msg = (ethQueryContractUI_t *) parameters; + origin_parameters_t *context = (origin_parameters_t *) msg->pluginContext; + memset(msg->title, 0, msg->titleLength); + memset(msg->msg, 0, msg->msgLength); + msg->result = ETH_PLUGIN_RESULT_OK; + screens_t screen = get_screen(msg, context); + switch (screen) { + case SEND_SCREEN: + set_send_ui(msg, context); + break; + case RECEIVE_SCREEN: + set_receive_ui(msg, context); + break; + case WARN_SCREEN: + set_warning_ui(msg, context); + break; + case BENEFICIARY_SCREEN: + set_beneficiary_ui(msg, context); + break; + default: + PRINTF("Received an invalid screenIndex\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } } diff --git a/src/main.c b/src/main.c index f720e8ec..fba32f77 100644 --- a/src/main.c +++ b/src/main.c @@ -31,9 +31,8 @@ static const uint32_t ZAPPER_DEPOSIT_ETH_SELECTOR = 0xd0e30db0; // deposit(), static const uint32_t ZAPPER_DEPOSIT_SFRXETH_SELECTOR = 0xd443e97d; // depositSFRXETH(uint256 amount,uint256 minOETH) -static const uint32_t VAULT_MINT_SELECTOR = - 0x156e29f6; // mint(address _asset,uint256 _amount,uint256 - // _minimumOusdAmount) +static const uint32_t VAULT_MINT_SELECTOR = 0x156e29f6; // mint(address _asset,uint256 + // _amount,uint256 _minimumOusdAmount) static const uint32_t VAULT_REDEEM_SELECTOR = 0x7cbc2373; // redeem(uint256 _amount,uint256 _minimumUnitAmount) static const uint32_t CURVE_POOL_EXCHANGE_SELECTOR = @@ -44,8 +43,7 @@ static const uint32_t CURVE_POOL_EXCHANGE_UNDERLYING_SELECTOR = static const uint32_t CURVE_ROUTER_EXCHANGE_MULTIPLE_SELECTOR = 0x353ca424; // exchange_multiple(address[9] _route,uint256[3][4] // _swap_params,uint256 _amount,uint256 _expected) -static const uint32_t UNISWAP_ROUTER_EXACT_INPUT_SELECTOR = - 0xc04b8d59; // exactInput(tuple params) +static const uint32_t UNISWAP_ROUTER_EXACT_INPUT_SELECTOR = 0xc04b8d59; // exactInput(tuple params) static const uint32_t UNISWAP_ROUTER_EXACT_INPUT_SINGLE_SELECTOR = 0x414bf389; // exactInputSingle(tuple params) static const uint32_t FLIPPER_BUY_OUSD_WITH_USDT_SELECTOR = @@ -59,9 +57,8 @@ static const uint32_t FLIPPER_SELL_OUSD_FOR_DAI_SELECTOR = static const uint32_t FLIPPER_BUY_OUSD_WITH_USDC_SELECTOR = 0xbfc11ffd; // buyOusdWithUsdc(uint256 amount) static const uint32_t FLIPPER_SELL_OUSD_FOR_USDC_SELECTOR = - 0xc6b68169; // sellOusdForUsdc(uint256 amount) -static const uint32_t WRAP_SELECTOR = - 0x6e553f65; // deposit(uint256 assets,address receiver) + 0xc6b68169; // sellOusdForUsdc(uint256 amount) +static const uint32_t WRAP_SELECTOR = 0x6e553f65; // deposit(uint256 assets,address receiver) static const uint32_t UNWRAP_SELECTOR = 0xba087652; // redeem(uint256 shares,address receiver,address owner) @@ -74,166 +71,165 @@ static const uint32_t UNWRAP_SELECTOR = // Array of all the different boilerplate selectors. Make sure this follows the // same order as the enum defined in `boilerplate_plugin.h` EDIT THIS: Use the // names of the array declared above. -const uint32_t ORIGIN_SELECTORS[NUM_SELECTORS] = { - ZAPPER_DEPOSIT_ETH_SELECTOR, - ZAPPER_DEPOSIT_SFRXETH_SELECTOR, - VAULT_MINT_SELECTOR, - VAULT_REDEEM_SELECTOR, - CURVE_POOL_EXCHANGE_SELECTOR, - CURVE_POOL_EXCHANGE_UNDERLYING_SELECTOR, - CURVE_ROUTER_EXCHANGE_MULTIPLE_SELECTOR, - UNISWAP_ROUTER_EXACT_INPUT_SELECTOR, - UNISWAP_ROUTER_EXACT_INPUT_SINGLE_SELECTOR, - FLIPPER_BUY_OUSD_WITH_USDT_SELECTOR, - FLIPPER_SELL_OUSD_FOR_USDT_SELECTOR, - FLIPPER_BUY_OUSD_WITH_DAI_SELECTOR, - FLIPPER_SELL_OUSD_FOR_DAI_SELECTOR, - FLIPPER_BUY_OUSD_WITH_USDC_SELECTOR, - FLIPPER_SELL_OUSD_FOR_USDC_SELECTOR, - WRAP_SELECTOR, - UNWRAP_SELECTOR}; - -const uint8_t OETH_ADDRESS[ADDRESS_LENGTH] = { - 0x85, 0x6c, 0x4e, 0xfb, 0x76, 0xc1, 0xd1, 0xae, 0x02, 0xe2, - 0x0c, 0xeb, 0x03, 0xa2, 0xa6, 0xa0, 0x8b, 0x0b, 0x8d, 0xc3}; - -const uint8_t STETH_ADDRESS[ADDRESS_LENGTH] = { - 0xae, 0x7a, 0xb9, 0x65, 0x20, 0xde, 0x3a, 0x18, 0xe5, 0xe1, - 0x11, 0xb5, 0xea, 0xab, 0x09, 0x53, 0x12, 0xd7, 0xfe, 0x84}; - -const uint8_t OUSD_ADDRESS[ADDRESS_LENGTH] = { - 0x2a, 0x8e, 0x1e, 0x67, 0x6e, 0xc2, 0x38, 0xd8, 0xa9, 0x92, - 0x30, 0x7b, 0x49, 0x5b, 0x45, 0xb3, 0xfe, 0xaa, 0x5e, 0x86}; - -const uint8_t DAI_ADDRESS[ADDRESS_LENGTH] = { - 0x6b, 0x17, 0x54, 0x74, 0xe8, 0x90, 0x94, 0xc4, 0x4d, 0xa9, - 0x8b, 0x95, 0x4e, 0xed, 0xea, 0xc4, 0x95, 0x27, 0x1d, 0x0f}; - -const uint8_t USDC_ADDRESS[ADDRESS_LENGTH] = { - 0xa0, 0xb8, 0x69, 0x91, 0xc6, 0x21, 0x8b, 0x36, 0xc1, 0xd1, - 0x9d, 0x4a, 0x2e, 0x9e, 0xb0, 0xce, 0x36, 0x06, 0xeb, 0x48}; - -const uint8_t USDT_ADDRESS[ADDRESS_LENGTH] = { - 0xda, 0xc1, 0x7f, 0x95, 0x8d, 0x2e, 0xe5, 0x23, 0xa2, 0x20, - 0x62, 0x06, 0x99, 0x45, 0x97, 0xc1, 0x3d, 0x83, 0x1e, 0xc7}; - -const uint8_t OETH_VAULT_ADDRESS[ADDRESS_LENGTH] = { - 0x39, 0x25, 0x40, 0x33, 0x94, 0x5a, 0xa2, 0xe4, 0x80, 0x9c, - 0xc2, 0x97, 0x7e, 0x70, 0x87, 0xbe, 0xe4, 0x8b, 0xd7, 0xab}; - -const uint8_t WOETH_ADDRESS[ADDRESS_LENGTH] = { - 0xdc, 0xee, 0x70, 0x65, 0x42, 0x61, 0xaf, 0x21, 0xc4, 0x4c, - 0x09, 0x3c, 0x30, 0x0e, 0xd3, 0xbb, 0x97, 0xb7, 0x81, 0x92}; - -const uint8_t CURVE_OETH_POOL_ADDRESS[ADDRESS_LENGTH] = { - 0x94, 0xb1, 0x74, 0x76, 0xa9, 0x3b, 0x32, 0x62, 0xd8, 0x7b, - 0x9a, 0x32, 0x69, 0x65, 0xd1, 0xe9, 0x1f, 0x9c, 0x13, 0xe7}; - -const uint8_t CURVE_OUSD_POOL_ADDRESS[ADDRESS_LENGTH] = { - 0x87, 0x65, 0x0d, 0x7b, 0xbf, 0xc3, 0xa9, 0xf1, 0x05, 0x87, - 0xd7, 0x77, 0x82, 0x06, 0x67, 0x17, 0x19, 0xd9, 0x91, 0x0d}; +const uint32_t ORIGIN_SELECTORS[NUM_SELECTORS] = {ZAPPER_DEPOSIT_ETH_SELECTOR, + ZAPPER_DEPOSIT_SFRXETH_SELECTOR, + VAULT_MINT_SELECTOR, + VAULT_REDEEM_SELECTOR, + CURVE_POOL_EXCHANGE_SELECTOR, + CURVE_POOL_EXCHANGE_UNDERLYING_SELECTOR, + CURVE_ROUTER_EXCHANGE_MULTIPLE_SELECTOR, + UNISWAP_ROUTER_EXACT_INPUT_SELECTOR, + UNISWAP_ROUTER_EXACT_INPUT_SINGLE_SELECTOR, + FLIPPER_BUY_OUSD_WITH_USDT_SELECTOR, + FLIPPER_SELL_OUSD_FOR_USDT_SELECTOR, + FLIPPER_BUY_OUSD_WITH_DAI_SELECTOR, + FLIPPER_SELL_OUSD_FOR_DAI_SELECTOR, + FLIPPER_BUY_OUSD_WITH_USDC_SELECTOR, + FLIPPER_SELL_OUSD_FOR_USDC_SELECTOR, + WRAP_SELECTOR, + UNWRAP_SELECTOR}; + +const uint8_t OETH_ADDRESS[ADDRESS_LENGTH] = {0x85, 0x6c, 0x4e, 0xfb, 0x76, 0xc1, 0xd1, + 0xae, 0x02, 0xe2, 0x0c, 0xeb, 0x03, 0xa2, + 0xa6, 0xa0, 0x8b, 0x0b, 0x8d, 0xc3}; + +const uint8_t STETH_ADDRESS[ADDRESS_LENGTH] = {0xae, 0x7a, 0xb9, 0x65, 0x20, 0xde, 0x3a, + 0x18, 0xe5, 0xe1, 0x11, 0xb5, 0xea, 0xab, + 0x09, 0x53, 0x12, 0xd7, 0xfe, 0x84}; + +const uint8_t OUSD_ADDRESS[ADDRESS_LENGTH] = {0x2a, 0x8e, 0x1e, 0x67, 0x6e, 0xc2, 0x38, + 0xd8, 0xa9, 0x92, 0x30, 0x7b, 0x49, 0x5b, + 0x45, 0xb3, 0xfe, 0xaa, 0x5e, 0x86}; + +const uint8_t DAI_ADDRESS[ADDRESS_LENGTH] = {0x6b, 0x17, 0x54, 0x74, 0xe8, 0x90, 0x94, + 0xc4, 0x4d, 0xa9, 0x8b, 0x95, 0x4e, 0xed, + 0xea, 0xc4, 0x95, 0x27, 0x1d, 0x0f}; + +const uint8_t USDC_ADDRESS[ADDRESS_LENGTH] = {0xa0, 0xb8, 0x69, 0x91, 0xc6, 0x21, 0x8b, + 0x36, 0xc1, 0xd1, 0x9d, 0x4a, 0x2e, 0x9e, + 0xb0, 0xce, 0x36, 0x06, 0xeb, 0x48}; + +const uint8_t USDT_ADDRESS[ADDRESS_LENGTH] = {0xda, 0xc1, 0x7f, 0x95, 0x8d, 0x2e, 0xe5, + 0x23, 0xa2, 0x20, 0x62, 0x06, 0x99, 0x45, + 0x97, 0xc1, 0x3d, 0x83, 0x1e, 0xc7}; + +const uint8_t OETH_VAULT_ADDRESS[ADDRESS_LENGTH] = {0x39, 0x25, 0x40, 0x33, 0x94, 0x5a, 0xa2, + 0xe4, 0x80, 0x9c, 0xc2, 0x97, 0x7e, 0x70, + 0x87, 0xbe, 0xe4, 0x8b, 0xd7, 0xab}; + +const uint8_t WOETH_ADDRESS[ADDRESS_LENGTH] = {0xdc, 0xee, 0x70, 0x65, 0x42, 0x61, 0xaf, + 0x21, 0xc4, 0x4c, 0x09, 0x3c, 0x30, 0x0e, + 0xd3, 0xbb, 0x97, 0xb7, 0x81, 0x92}; + +const uint8_t CURVE_OETH_POOL_ADDRESS[ADDRESS_LENGTH] = {0x94, 0xb1, 0x74, 0x76, 0xa9, 0x3b, 0x32, + 0x62, 0xd8, 0x7b, 0x9a, 0x32, 0x69, 0x65, + 0xd1, 0xe9, 0x1f, 0x9c, 0x13, 0xe7}; + +const uint8_t CURVE_OUSD_POOL_ADDRESS[ADDRESS_LENGTH] = {0x87, 0x65, 0x0d, 0x7b, 0xbf, 0xc3, 0xa9, + 0xf1, 0x05, 0x87, 0xd7, 0x77, 0x82, 0x06, + 0x67, 0x17, 0x19, 0xd9, 0x91, 0x0d}; // Function to dispatch calls from the ethereum app. void dispatch_plugin_calls(int message, void *parameters) { - switch (message) { - case ETH_PLUGIN_INIT_CONTRACT: - handle_init_contract(parameters); - break; - case ETH_PLUGIN_PROVIDE_PARAMETER: - handle_provide_parameter(parameters); - break; - case ETH_PLUGIN_FINALIZE: - handle_finalize(parameters); - break; - case ETH_PLUGIN_PROVIDE_INFO: - handle_provide_token(parameters); - break; - case ETH_PLUGIN_QUERY_CONTRACT_ID: - handle_query_contract_id(parameters); - break; - case ETH_PLUGIN_QUERY_CONTRACT_UI: - handle_query_contract_ui(parameters); - break; - default: - PRINTF("Unhandled message %d\n", message); - break; - } + switch (message) { + case ETH_PLUGIN_INIT_CONTRACT: + handle_init_contract(parameters); + break; + case ETH_PLUGIN_PROVIDE_PARAMETER: + handle_provide_parameter(parameters); + break; + case ETH_PLUGIN_FINALIZE: + handle_finalize(parameters); + break; + case ETH_PLUGIN_PROVIDE_INFO: + handle_provide_token(parameters); + break; + case ETH_PLUGIN_QUERY_CONTRACT_ID: + handle_query_contract_id(parameters); + break; + case ETH_PLUGIN_QUERY_CONTRACT_UI: + handle_query_contract_ui(parameters); + break; + default: + PRINTF("Unhandled message %d\n", message); + break; + } } void handle_query_ui_exception(unsigned int *args) { - switch (args[0]) { - case ETH_PLUGIN_QUERY_CONTRACT_UI: - ((ethQueryContractUI_t *)args[1])->result = ETH_PLUGIN_RESULT_ERROR; - break; - default: - break; - } + switch (args[0]) { + case ETH_PLUGIN_QUERY_CONTRACT_UI: + ((ethQueryContractUI_t *) args[1])->result = ETH_PLUGIN_RESULT_ERROR; + break; + default: + break; + } } -const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Calls the ethereum app. void call_app_ethereum() { - unsigned int libcall_params[3]; - libcall_params[0] = (unsigned int)"Ethereum"; - libcall_params[1] = 0x100; - libcall_params[2] = RUN_APPLICATION; - os_lib_call((unsigned int *)&libcall_params); + unsigned int libcall_params[3]; + libcall_params[0] = (unsigned int) "Ethereum"; + libcall_params[1] = 0x100; + libcall_params[2] = RUN_APPLICATION; + os_lib_call((unsigned int *) &libcall_params); } // Weird low-level black magic. No need to edit this. __attribute__((section(".boot"))) int main(int arg0) { - // Exit critical section - __asm volatile("cpsie i"); - - // Ensure exception will work as planned - os_boot(); - - // Try catch block. Please read the docs for more information on how to use - // those! - BEGIN_TRY { - TRY { - // Low-level black magic. - check_api_level(CX_COMPAT_APILEVEL); - - // Check if we are called from the dashboard. - if (!arg0) { - // Called from dashboard, launch Ethereum app - call_app_ethereum(); - return 0; - } else { - // Not called from dashboard: called from the ethereum app! - const unsigned int *args = (const unsigned int *)arg0; - - // If `ETH_PLUGIN_CHECK_PRESENCE` is set, this means the caller is just - // trying to know whether this app exists or not. We can skip - // `dispatch_plugin_calls`. - if (args[0] != ETH_PLUGIN_CHECK_PRESENCE) { - dispatch_plugin_calls(args[0], (void *)args[1]); + // Exit critical section + __asm volatile("cpsie i"); + + // Ensure exception will work as planned + os_boot(); + + // Try catch block. Please read the docs for more information on how to use + // those! + BEGIN_TRY { + TRY { + // Low-level black magic. + check_api_level(CX_COMPAT_APILEVEL); + + // Check if we are called from the dashboard. + if (!arg0) { + // Called from dashboard, launch Ethereum app + call_app_ethereum(); + return 0; + } else { + // Not called from dashboard: called from the ethereum app! + const unsigned int *args = (const unsigned int *) arg0; + + // If `ETH_PLUGIN_CHECK_PRESENCE` is set, this means the caller is just + // trying to know whether this app exists or not. We can skip + // `dispatch_plugin_calls`. + if (args[0] != ETH_PLUGIN_CHECK_PRESENCE) { + dispatch_plugin_calls(args[0], (void *) args[1]); + } + } + } + CATCH_OTHER(e) { + switch (e) { + // These exceptions are only generated on handle_query_contract_ui() + case 0x6502: + case EXCEPTION_OVERFLOW: + handle_query_ui_exception((unsigned int *) arg0); + break; + default: + break; + } + PRINTF("Exception 0x%x caught\n", e); + } + FINALLY { + // Call `os_lib_end`, go back to the ethereum app. + os_lib_end(); } - } - } - CATCH_OTHER(e) { - switch (e) { - // These exceptions are only generated on handle_query_contract_ui() - case 0x6502: - case EXCEPTION_OVERFLOW: - handle_query_ui_exception((unsigned int *)arg0); - break; - default: - break; - } - PRINTF("Exception 0x%x caught\n", e); - } - FINALLY { - // Call `os_lib_end`, go back to the ethereum app. - os_lib_end(); } - } - END_TRY; + END_TRY; - // Will not get reached. - return 0; + // Will not get reached. + return 0; } diff --git a/src/origin_plugin.h b/src/origin_plugin.h index e41c78a9..286fd592 100644 --- a/src/origin_plugin.h +++ b/src/origin_plugin.h @@ -8,14 +8,14 @@ // Number of selectors defined in this plugin. Should match the enum // `selector_t`. EDIT THIS: Put in the number of selectors your plugin is going // to support. -#define NUM_SELECTORS 17 +#define NUM_SELECTORS 17 #define PARAMETER_LENGTH 32 // Name of the plugin. // EDIT THIS: Replace with your plugin name. #define PLUGIN_NAME "Origin DeFi" -#define TOKEN_SENT_FOUND 1 +#define TOKEN_SENT_FOUND 1 #define TOKEN_RECEIVED_FOUND 1 << 1 // Number of decimals used when the token wasn't found in the CAL. @@ -24,19 +24,19 @@ // Ticker used when the token wasn't found in the CAL. #define DEFAULT_TICKER "" -#define OETH_TICKER "OETH" +#define OETH_TICKER "OETH" #define OETH_DECIMALS WEI_TO_ETHER -#define OUSD_TICKER "OUSD" +#define OUSD_TICKER "OUSD" #define OUSD_DECIMALS WEI_TO_ETHER -#define DAI_TICKER "DAI" +#define DAI_TICKER "DAI" #define DAI_DECIMALS WEI_TO_ETHER -#define USDC_TICKER "USDC" +#define USDC_TICKER "USDC" #define USDC_DECIMALS 6 -#define USDT_TICKER "USDT" +#define USDT_TICKER "USDT" #define USDT_DECIMALS 6 #define WOETH_TICKER "WOETH" @@ -48,31 +48,31 @@ // Should follow the exact same order as the array declared in main.c // EDIT THIS: Change the naming (`selector_t`), and add your selector names. typedef enum { - ZAPPER_DEPOSIT_ETH, - ZAPPER_DEPOSIT_SFRXETH, - VAULT_MINT, - VAULT_REDEEM, - CURVE_POOL_EXCHANGE, - CURVE_POOL_EXCHANGE_UNDERLYING, - CURVE_ROUTER_EXCHANGE_MULTIPLE, - UNISWAP_ROUTER_EXACT_INPUT, - UNISWAP_ROUTER_EXACT_INPUT_SINGLE, - FLIPPER_BUY_OUSD_WITH_USDT, - FLIPPER_SELL_OUSD_FOR_USDT, - FLIPPER_BUY_OUSD_WITH_DAI, - FLIPPER_SELL_OUSD_FOR_DAI, - FLIPPER_BUY_OUSD_WITH_USDC, - FLIPPER_SELL_OUSD_FOR_USDC, - WRAP, - UNWRAP + ZAPPER_DEPOSIT_ETH, + ZAPPER_DEPOSIT_SFRXETH, + VAULT_MINT, + VAULT_REDEEM, + CURVE_POOL_EXCHANGE, + CURVE_POOL_EXCHANGE_UNDERLYING, + CURVE_ROUTER_EXCHANGE_MULTIPLE, + UNISWAP_ROUTER_EXACT_INPUT, + UNISWAP_ROUTER_EXACT_INPUT_SINGLE, + FLIPPER_BUY_OUSD_WITH_USDT, + FLIPPER_SELL_OUSD_FOR_USDT, + FLIPPER_BUY_OUSD_WITH_DAI, + FLIPPER_SELL_OUSD_FOR_DAI, + FLIPPER_BUY_OUSD_WITH_USDC, + FLIPPER_SELL_OUSD_FOR_USDC, + WRAP, + UNWRAP } selector_t; typedef enum { - SEND_SCREEN, - RECEIVE_SCREEN, - WARN_SCREEN, - BENEFICIARY_SCREEN, - ERROR, + SEND_SCREEN, + RECEIVE_SCREEN, + WARN_SCREEN, + BENEFICIARY_SCREEN, + ERROR, } screens_t; extern const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH]; @@ -88,28 +88,27 @@ extern const uint8_t CURVE_OETH_POOL_ADDRESS[ADDRESS_LENGTH]; extern const uint8_t CURVE_OUSD_POOL_ADDRESS[ADDRESS_LENGTH]; extern const uint8_t WOETH_ADDRESS[ADDRESS_LENGTH]; -#define ADDRESS_IS_NETWORK_TOKEN(_addr) \ - (!memcmp(_addr, NULL_ETH_ADDRESS, ADDRESS_LENGTH)) -#define ADDRESS_IS_OETH(_addr) (!memcmp(_addr, OETH_ADDRESS, ADDRESS_LENGTH)) -#define ADDRESS_IS_OUSD(_addr) (!memcmp(_addr, OUSD_ADDRESS, ADDRESS_LENGTH)) -#define ADDRESS_IS_DAI(_addr) (!memcmp(_addr, DAI_ADDRESS, ADDRESS_LENGTH)) -#define ADDRESS_IS_USDC(_addr) (!memcmp(_addr, USDC_ADDRESS, ADDRESS_LENGTH)) -#define ADDRESS_IS_USDT(_addr) (!memcmp(_addr, USDT_ADDRESS, ADDRESS_LENGTH)) +#define ADDRESS_IS_NETWORK_TOKEN(_addr) (!memcmp(_addr, NULL_ETH_ADDRESS, ADDRESS_LENGTH)) +#define ADDRESS_IS_OETH(_addr) (!memcmp(_addr, OETH_ADDRESS, ADDRESS_LENGTH)) +#define ADDRESS_IS_OUSD(_addr) (!memcmp(_addr, OUSD_ADDRESS, ADDRESS_LENGTH)) +#define ADDRESS_IS_DAI(_addr) (!memcmp(_addr, DAI_ADDRESS, ADDRESS_LENGTH)) +#define ADDRESS_IS_USDC(_addr) (!memcmp(_addr, USDC_ADDRESS, ADDRESS_LENGTH)) +#define ADDRESS_IS_USDT(_addr) (!memcmp(_addr, USDT_ADDRESS, ADDRESS_LENGTH)) // #define ADDRESS_IS_FRXETH(_addr) (!memcmp(_addr, FRXETH_ADDRESS, // ADDRESS_LENGTH)) // Enumeration used to parse the smart contract data. // EDIT THIS: Adapt the parameter names here. typedef enum { - TOKEN_SENT, - TOKEN_RECEIVED, - TOKEN_RECEIVED_REST, - AMOUNT_SENT, - MIN_AMOUNT_RECEIVED, - BENEFICIARY, - PATH_LENGTH, - UNEXPECTED_PARAMETER, - NONE, + TOKEN_SENT, + TOKEN_RECEIVED, + TOKEN_RECEIVED_REST, + AMOUNT_SENT, + MIN_AMOUNT_RECEIVED, + BENEFICIARY, + PATH_LENGTH, + UNEXPECTED_PARAMETER, + NONE, } parameter; // EDIT THIS: Rename `BOILERPLATE` to be the same as the one initialized in @@ -120,41 +119,40 @@ extern const uint32_t ORIGIN_SELECTORS[NUM_SELECTORS]; // EDIT THIS: This struct is used by your plugin to save the parameters you // parse. You will need to adapt this struct to your plugin. typedef struct origin_parameters_t { - // For display. - - uint8_t amount_sent[INT256_LENGTH]; - uint8_t min_amount_received[INT256_LENGTH]; - uint8_t contract_address_sent[ADDRESS_LENGTH]; - uint8_t contract_address_received[ADDRESS_LENGTH]; - uint8_t beneficiary[ADDRESS_LENGTH]; - char ticker_sent[MAX_TICKER_LEN]; - char ticker_received[MAX_TICKER_LEN]; - - uint8_t tokens_found; - uint8_t decimals_sent; - uint8_t decimals_received; - uint8_t skip; - - bool valid; - uint8_t amount_length; - - // For parsing data. - uint8_t next_param; // Set to be the next param we expect to parse. - uint8_t counter; - // uint16_t checkpoint; - uint16_t offset; - // bool go_to_offset; // If set, will force the parsing to iterate through - // parameters until - // `offset` is reached. - - // For both parsing and display. - selector_t selectorIndex; + // For display. + + uint8_t amount_sent[INT256_LENGTH]; + uint8_t min_amount_received[INT256_LENGTH]; + uint8_t contract_address_sent[ADDRESS_LENGTH]; + uint8_t contract_address_received[ADDRESS_LENGTH]; + uint8_t beneficiary[ADDRESS_LENGTH]; + char ticker_sent[MAX_TICKER_LEN]; + char ticker_received[MAX_TICKER_LEN]; + + uint8_t tokens_found; + uint8_t decimals_sent; + uint8_t decimals_received; + uint8_t skip; + + bool valid; + uint8_t amount_length; + + // For parsing data. + uint8_t next_param; // Set to be the next param we expect to parse. + uint8_t counter; + // uint16_t checkpoint; + uint16_t offset; + // bool go_to_offset; // If set, will force the parsing to iterate through + // parameters until + // `offset` is reached. + + // For both parsing and display. + selector_t selectorIndex; } origin_parameters_t; // Piece of code that will check that the above structure is not bigger than 5 // * 32. Do not remove this check. -_Static_assert(sizeof(origin_parameters_t) <= 5 * 32, - "Structure of parameters too big."); +_Static_assert(sizeof(origin_parameters_t) <= 5 * 32, "Structure of parameters too big."); void handle_provide_parameter(void *parameters); void handle_query_contract_ui(void *parameters); @@ -164,66 +162,65 @@ void handle_provide_token(void *parameters); void handle_query_contract_id(void *parameters); static inline check_token_sent(origin_parameters_t *context) { - if (ADDRESS_IS_OETH(context->contract_address_sent)) { - context->decimals_sent = OETH_DECIMALS; - context->tokens_found |= TOKEN_SENT_FOUND; - } else if (ADDRESS_IS_OUSD(context->contract_address_sent)) { - context->decimals_sent = OUSD_DECIMALS; - context->tokens_found |= TOKEN_SENT_FOUND; - } else if (ADDRESS_IS_DAI(context->contract_address_sent)) { - context->decimals_sent = DAI_DECIMALS; - context->tokens_found |= TOKEN_SENT_FOUND; - } else if (ADDRESS_IS_USDC(context->contract_address_sent)) { - context->decimals_sent = USDC_DECIMALS; - context->tokens_found |= TOKEN_SENT_FOUND; - } else if (ADDRESS_IS_USDT(context->contract_address_sent)) { - context->decimals_sent = USDT_DECIMALS; - context->tokens_found |= TOKEN_SENT_FOUND; - } else { - return false; - } - return true; + if (ADDRESS_IS_OETH(context->contract_address_sent)) { + context->decimals_sent = OETH_DECIMALS; + context->tokens_found |= TOKEN_SENT_FOUND; + } else if (ADDRESS_IS_OUSD(context->contract_address_sent)) { + context->decimals_sent = OUSD_DECIMALS; + context->tokens_found |= TOKEN_SENT_FOUND; + } else if (ADDRESS_IS_DAI(context->contract_address_sent)) { + context->decimals_sent = DAI_DECIMALS; + context->tokens_found |= TOKEN_SENT_FOUND; + } else if (ADDRESS_IS_USDC(context->contract_address_sent)) { + context->decimals_sent = USDC_DECIMALS; + context->tokens_found |= TOKEN_SENT_FOUND; + } else if (ADDRESS_IS_USDT(context->contract_address_sent)) { + context->decimals_sent = USDT_DECIMALS; + context->tokens_found |= TOKEN_SENT_FOUND; + } else { + return false; + } + return true; } static inline check_token_received(origin_parameters_t *context) { - if (ADDRESS_IS_OETH(context->contract_address_received)) { - context->decimals_received = OETH_DECIMALS; - context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else if (ADDRESS_IS_OUSD(context->contract_address_received)) { - context->decimals_received = OUSD_DECIMALS; - context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else if (ADDRESS_IS_DAI(context->contract_address_received)) { - context->decimals_received = DAI_DECIMALS; - context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else if (ADDRESS_IS_USDC(context->contract_address_received)) { - context->decimals_received = USDC_DECIMALS; - context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else if (ADDRESS_IS_USDT(context->contract_address_received)) { - context->decimals_received = USDT_DECIMALS; - context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else { - return false; - } - return true; + if (ADDRESS_IS_OETH(context->contract_address_received)) { + context->decimals_received = OETH_DECIMALS; + context->tokens_found |= TOKEN_RECEIVED_FOUND; + } else if (ADDRESS_IS_OUSD(context->contract_address_received)) { + context->decimals_received = OUSD_DECIMALS; + context->tokens_found |= TOKEN_RECEIVED_FOUND; + } else if (ADDRESS_IS_DAI(context->contract_address_received)) { + context->decimals_received = DAI_DECIMALS; + context->tokens_found |= TOKEN_RECEIVED_FOUND; + } else if (ADDRESS_IS_USDC(context->contract_address_received)) { + context->decimals_received = USDC_DECIMALS; + context->tokens_found |= TOKEN_RECEIVED_FOUND; + } else if (ADDRESS_IS_USDT(context->contract_address_received)) { + context->decimals_received = USDT_DECIMALS; + context->tokens_found |= TOKEN_RECEIVED_FOUND; + } else { + return false; + } + return true; } static inline void sent_network_token(origin_parameters_t *context) { - context->decimals_sent = WEI_TO_ETHER; - context->tokens_found |= TOKEN_SENT_FOUND; + context->decimals_sent = WEI_TO_ETHER; + context->tokens_found |= TOKEN_SENT_FOUND; } static inline void received_network_token(origin_parameters_t *context) { - context->decimals_received = WEI_TO_ETHER; - context->tokens_found |= TOKEN_RECEIVED_FOUND; + context->decimals_received = WEI_TO_ETHER; + context->tokens_found |= TOKEN_RECEIVED_FOUND; } static inline void printf_hex_array(const char *title __attribute__((unused)), size_t len __attribute__((unused)), - const uint8_t *data - __attribute__((unused))) { - PRINTF(title); - for (size_t i = 0; i < len; ++i) { - PRINTF("%02x", data[i]); - }; - PRINTF("\n"); + const uint8_t *data __attribute__((unused))) { + PRINTF(title); + for (size_t i = 0; i < len; ++i) { + PRINTF("%02x", data[i]); + }; + PRINTF("\n"); } \ No newline at end of file