diff --git a/.clang-format b/.clang-format index b4abfa0..c76e9fc 100644 --- a/.clang-format +++ b/.clang-format @@ -12,7 +12,6 @@ SortIncludes: false SpaceAfterCStyleCast: true AllowShortCaseLabelsOnASingleLine: false AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: Never AllowShortFunctionsOnASingleLine: None BinPackArguments: false diff --git a/src/contract.c b/src/contract.c index d55a2be..213e8c2 100644 --- a/src/contract.c +++ b/src/contract.c @@ -33,11 +33,10 @@ static const uint32_t KILN_V2_CLAIM_SELECTOR = 0xadcf1163; static const uint32_t KILN_LR_DEPOSIT_INTO_STRATEGY_SELECTOR = 0xe7a050aa; // --- cast sig "queueWithdrawal(uint256[],address[],uint256[],address,bool)" static const uint32_t KILN_LR_QUEUE_WITHDRAWAL_SELECTOR = 0xf123991e; -// --- cast sig "completeQueuedWithdrawal((address[],uint256[],address,(address,uint96),uint32,address),address[],uint256,bool)" +// --- cast sig +// "completeQueuedWithdrawal((address[],uint256[],address,(address,uint96),uint32,address),address[],uint256,bool)" static const uint32_t KILN_LR_COMPLETE_QUEUED_WITHDRAWAL_SELECTOR = 0xf3be65d3; - - const uint32_t KILN_SELECTORS[NUM_SELECTORS] = { // V1 KILN_V1_DEPOSIT_SELECTOR, @@ -59,46 +58,42 @@ const uint32_t KILN_SELECTORS[NUM_SELECTORS] = { KILN_LR_COMPLETE_QUEUED_WITHDRAWAL_SELECTOR, }; - - const char lr_strategy_addresses[LR_STRATEGIES_COUNT][ADDRESS_STR_LEN] = { - "0x54945180dB7943c0ed0FEE7EdaB2Bd24620256bc", // cbETH - "0x93c4b944D05dfe6df7645A86cd2206016c51564D", // stETH - "0x1BeE69b7dFFfA4E2d53C2a2Df135C388AD25dCD2", // rETH - "0x9d7eD45EE2E8FC5482fa2428f15C971e6369011d", // ETHx - "0x13760F50a9d7377e4F20CB8CF9e4c26586c658ff", // ankrETH - "0xa4C637e0F704745D182e4D38cAb7E7485321d059", // OETH - "0x57ba429517c3473B6d34CA9aCd56c0e735b94c02", // osETH - "0x0Fe4F44beE93503346A3Ac9EE5A26b130a5796d6", // swETH - "0x7CA911E83dabf90C90dD3De5411a10F1A6112184", // wBETH - "0x8CA7A5d6f3acd3A7A8bC468a8CD0FB14B6BD28b6", // sfrxETH - "0x298aFB19A105D59E74658C4C334Ff360BadE6dd2" // mETH + "0x54945180dB7943c0ed0FEE7EdaB2Bd24620256bc", // cbETH + "0x93c4b944D05dfe6df7645A86cd2206016c51564D", // stETH + "0x1BeE69b7dFFfA4E2d53C2a2Df135C388AD25dCD2", // rETH + "0x9d7eD45EE2E8FC5482fa2428f15C971e6369011d", // ETHx + "0x13760F50a9d7377e4F20CB8CF9e4c26586c658ff", // ankrETH + "0xa4C637e0F704745D182e4D38cAb7E7485321d059", // OETH + "0x57ba429517c3473B6d34CA9aCd56c0e735b94c02", // osETH + "0x0Fe4F44beE93503346A3Ac9EE5A26b130a5796d6", // swETH + "0x7CA911E83dabf90C90dD3De5411a10F1A6112184", // wBETH + "0x8CA7A5d6f3acd3A7A8bC468a8CD0FB14B6BD28b6", // sfrxETH + "0x298aFB19A105D59E74658C4C334Ff360BadE6dd2" // mETH }; const char lr_erc20_addresses[LR_STRATEGIES_COUNT][ADDRESS_STR_LEN] = { - "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704", // cbETH - "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84", // stETH - "0xae78736Cd615f374D3085123A210448E74Fc6393", // rETH - "0xA35b1B31Ce002FBF2058D22F30f95D405200A15b", // ETHx - "0xE95A203B1a91a908F9B9CE46459d101078c2c3cb", // ankrETH - "0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3", // OETH - "0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38", // osETH - "0xf951E335afb289353dc249e82926178EaC7DEd78", // swETH - "0xa2E3356610840701BDf5611a53974510Ae27E2e1", // wBETH - "0xac3E018457B222d93114458476f3E3416Abbe38F", // sfrxETH - "0xd5F7838F5C461fefF7FE49ea5ebaF7728bB0ADfa", // mETH + "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704", // cbETH + "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84", // stETH + "0xae78736Cd615f374D3085123A210448E74Fc6393", // rETH + "0xA35b1B31Ce002FBF2058D22F30f95D405200A15b", // ETHx + "0xE95A203B1a91a908F9B9CE46459d101078c2c3cb", // ankrETH + "0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3", // OETH + "0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38", // osETH + "0xf951E335afb289353dc249e82926178EaC7DEd78", // swETH + "0xa2E3356610840701BDf5611a53974510Ae27E2e1", // wBETH + "0xac3E018457B222d93114458476f3E3416Abbe38F", // sfrxETH + "0xd5F7838F5C461fefF7FE49ea5ebaF7728bB0ADfa", // mETH }; -const char lr_tickers[LR_STRATEGIES_COUNT][MAX_TICKER_LEN] = { - "cbETH", - "stETH", - "rETH", - "ETHx", - "ankrETH", - "OETH", - "osETH", - "swETH", - "wBETH", - "sfrxETH", - "mETH" -}; \ No newline at end of file +const char lr_tickers[LR_STRATEGIES_COUNT][MAX_TICKER_LEN] = {"cbETH", + "stETH", + "rETH", + "ETHx", + "ankrETH", + "OETH", + "osETH", + "swETH", + "wBETH", + "sfrxETH", + "mETH"}; \ No newline at end of file diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index 239a209..e6a716b 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -1,16 +1,16 @@ #include "kiln_plugin.h" -/* - * Compare two addresses - * - * @param a: first address - * @param b: second address - * - * @return true if the addresses are the same -*/ +/* + * Compare two addresses + * + * @param a: first address + * @param b: second address + * + * @return true if the addresses are the same + */ bool compare_addresses(const char *a, const char *b) { for (size_t i = 0; i < ADDRESS_STR_LEN; i += 1) { - if (tolower((unsigned char)a[i]) != tolower((unsigned char)b[i])) { + if (tolower((unsigned char) a[i]) != tolower((unsigned char) b[i])) { return false; } } @@ -18,21 +18,21 @@ bool compare_addresses(const char *a, const char *b) { } /* - * If address is a known erc20, update lr display context with its name - * otherwise set it to unkwown (-1) - * - * @param address: address to compare - * @param index: index of the erc20 in the context - * @param context: context to update - * - * @note impacts the following context storage: - * `context->lr_strategy_to_display`: set index of the erc20 in the context -*/ + * If address is a known erc20, update lr display context with its name + * otherwise set it to unkwown (-1) + * + * @param address: address to compare + * @param index: index of the erc20 in the context + * @param context: context to update + * + * @note impacts the following context storage: + * `context->lr_strategy_to_display`: set index of the erc20 in the context + */ void find_lr_known_erc20(const char *address, size_t index, context_t *context) { for (size_t i = 0; i < LR_STRATEGIES_COUNT; i++) { if (compare_addresses(address, &lr_erc20_addresses[i])) { context->lr_erc20_to_display[index] = i; - return; + return; } } // if unknown erc20, indicate it @@ -40,21 +40,21 @@ void find_lr_known_erc20(const char *address, size_t index, context_t *context) } /* - * If address is a known strategy, update lr display context with its name - * otherwise set it to unkwown (-1) - * - * @param address: address to compare - * @param index: index of the strategy in the context - * @param context: context to update - * - * @note impacts the following context storage: - * `context->lr_strategy_to_display`: set index of the strategy in the context -*/ + * If address is a known strategy, update lr display context with its name + * otherwise set it to unkwown (-1) + * + * @param address: address to compare + * @param index: index of the strategy in the context + * @param context: context to update + * + * @note impacts the following context storage: + * `context->lr_strategy_to_display`: set index of the strategy in the context + */ void find_lr_known_strategy(const char *address, size_t index, context_t *context) { for (size_t i = 0; i < LR_STRATEGIES_COUNT; i++) { if (compare_addresses(address, &lr_strategy_addresses[i])) { context->lr_strategy_to_display[index] = i; - return; + return; } } // if unknown strategy, indicate it @@ -62,64 +62,50 @@ void find_lr_known_strategy(const char *address, size_t index, context_t *contex } /* - * Handle the parameters for the depositIntoStrategy(strategy,erc20,amount) - * selector - * - * @param msg: message containing the parameter - * @param context: context to update - * - * @note impacts the following context storage: - * `context->next_param`: set to the next parameter to handle - * `context->lr_strategy_to_display`: set index of the strategy in the context - * `context->lr_erc20_to_display`: set index of the erc20 in the context - * `context->lr_erc20_amount_to_display`: set amount of the erc20 in the context - * -*/ + * Handle the parameters for the depositIntoStrategy(strategy,erc20,amount) + * selector + * + * @param msg: message containing the parameter + * @param context: context to update + * + * @note impacts the following context storage: + * `context->next_param`: set to the next parameter to handle + * `context->lr_strategy_to_display`: set index of the strategy in the context + * `context->lr_erc20_to_display`: set index of the erc20 in the context + * `context->lr_erc20_amount_to_display`: set amount of the erc20 in the context + * + */ void handle_lr_deposit_into_strategy(ethPluginProvideParameter_t *msg, context_t *context) { uint8_t buffer[ADDRESS_LENGTH]; char address_buffer[ADDRESS_STR_LEN]; - + switch (context->next_param) { case LR_DEPOSIT_INTO_STRATEGY_STRATEGY: - copy_address( - buffer, - msg->parameter, - sizeof(buffer) - ); - getEthDisplayableAddress( - buffer, - address_buffer, - sizeof(address_buffer), - msg->pluginSharedRW->sha3, - 0 - ); + copy_address(buffer, msg->parameter, sizeof(buffer)); + getEthDisplayableAddress(buffer, + address_buffer, + sizeof(address_buffer), + msg->pluginSharedRW->sha3, + 0); find_lr_known_strategy(&address_buffer, 0, context); context->next_param = LR_DEPOSIT_INTO_STRATEGY_TOKEN; break; case LR_DEPOSIT_INTO_STRATEGY_TOKEN: - copy_address( - buffer, - msg->parameter, - sizeof(buffer) - ); - getEthDisplayableAddress( - buffer, - address_buffer, - sizeof(address_buffer), - msg->pluginSharedRW->sha3, - 0 - ); + copy_address(buffer, msg->parameter, sizeof(buffer)); + getEthDisplayableAddress(buffer, + address_buffer, + sizeof(address_buffer), + msg->pluginSharedRW->sha3, + 0); find_lr_known_erc20(&address_buffer, 0, context); context->next_param = LR_DEPOSIT_INTO_STRATEGY_AMOUNT; break; case LR_DEPOSIT_INTO_STRATEGY_AMOUNT: - copy_parameter( - context->lr_erc20_amount_to_display[0], - msg->parameter, - sizeof(context->lr_erc20_amount_to_display[0]) - ); + copy_parameter(context->lr_erc20_amount_to_display[0], + msg->parameter, + sizeof(context->lr_erc20_amount_to_display[0])); context->next_param = LR_DEPOSIT_INTO_STRATEGY_UNEXPECTED_PARAMETER; break; default: @@ -148,7 +134,7 @@ void handle_lr_queue_withdrawal(ethPluginProvideParameter_t *msg, context_t *con break; default: PRINTF("Param not supported: %d\n", context->next_param); - //msg->result = ETH_PLUGIN_RESULT_ERROR; + // msg->result = ETH_PLUGIN_RESULT_ERROR; break; } } @@ -169,7 +155,7 @@ void handle_lr_complete_queued_withdrawal(ethPluginProvideParameter_t *msg, cont break; default: PRINTF("Param not supported: %d\n", context->next_param); - //msg->result = ETH_PLUGIN_RESULT_ERROR; + // msg->result = ETH_PLUGIN_RESULT_ERROR; break; } } @@ -220,7 +206,7 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) { msg->result = ETH_PLUGIN_RESULT_OK; break; case KILN_LR_COMPLETE_QUEUED_WITHDRAWAL: - handle_lr_complete_queued_withdrawal(msg, context); + handle_lr_complete_queued_withdrawal(msg, context); msg->result = ETH_PLUGIN_RESULT_OK; break; diff --git a/src/handle_query_contract_id.c b/src/handle_query_contract_id.c index 7708cc0..b9c0180 100644 --- a/src/handle_query_contract_id.c +++ b/src/handle_query_contract_id.c @@ -47,7 +47,7 @@ void handle_query_contract_id(ethQueryContractID_t *msg) { case KILN_LR_DEPOSIT_INTO_STRATEGY: strlcpy(msg->version, "Deposit In Strategy", msg->versionLength); break; - + case KILN_LR_QUEUE_WITHDRAWAL: strlcpy(msg->version, "Queue Withdrawal", msg->versionLength); break; diff --git a/src/handle_query_contract_ui.c b/src/handle_query_contract_ui.c index 4e3e8e4..1a28680 100644 --- a/src/handle_query_contract_ui.c +++ b/src/handle_query_contract_ui.c @@ -189,12 +189,13 @@ static bool deposit_into_stragey_ui_lr(ethQueryContractUI_t *msg, context_t *con case 1: strlcpy(msg->title, "Amount", msg->titleLength); amountToString(context->lr_erc20_amount_to_display[0], - sizeof(context->lr_erc20_amount_to_display[0]), - 2, - context->lr_erc20_to_display[0] == -1 ? - "UNKNOWN" : lr_tickers[context->lr_erc20_to_display[0]], - msg->msg, - msg->msgLength); + sizeof(context->lr_erc20_amount_to_display[0]), + 2, + context->lr_erc20_to_display[0] == -1 + ? "UNKNOWN" + : lr_tickers[context->lr_erc20_to_display[0]], + msg->msg, + msg->msgLength); ret = true; break; default: diff --git a/src/kiln_plugin.h b/src/kiln_plugin.h index f14e360..86788cc 100644 --- a/src/kiln_plugin.h +++ b/src/kiln_plugin.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include "eth_internals.h" #include "eth_plugin_interface.h" @@ -30,7 +29,9 @@ // LR selectors // --- 12. depositIntoStrategy(address,address,uint256) // --- 13. queueWithdrawal(uint256[],address[],uint256[],address,bool) -// --- 14. completeQueuedWithdrawal((address,address,address,uint256,uint32,address[],uint256[]),address[],uint256,bool) +// --- 14. +// completeQueuedWithdrawal((address,address,address,uint256,uint32,address[],uint256[]),address[],uint256,bool) +// #define NUM_SELECTORS 15 // Selectors available (see mapping above). @@ -87,7 +88,7 @@ typedef enum { LR_COMPLETE_QUEUED_WITHDRAWAL_MIDDLEWARETIMEINDEX, LR_COMPLETE_QUEUED_WITHDRAWAL_RECEIVEASTOKENS, LR_COMPLETE_QUEUED_WITHDRAWAL_UNEXPECTED_PARAMETER -} lr_complete_queued_withdrawal_parameters; +} lr_complete_queued_withdrawal_parameters; #define LR_STRATEGIES_COUNT 11 @@ -107,7 +108,6 @@ typedef struct context_t { uint8_t lr_erc20_amount_to_display[MAX_DISPLAY_COUNT][INT256_LENGTH]; size_t lr_display_buffer_size; - selector_t selectorIndex; } context_t;