Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
loicttn committed Feb 2, 2024
1 parent fc73149 commit e4cfaf9
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 129 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
Expand Down
75 changes: 35 additions & 40 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
};
const char lr_tickers[LR_STRATEGIES_COUNT][MAX_TICKER_LEN] = {"cbETH",
"stETH",
"rETH",
"ETHx",
"ankrETH",
"OETH",
"osETH",
"swETH",
"wBETH",
"sfrxETH",
"mETH"};
140 changes: 63 additions & 77 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,125 +1,111 @@
#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;
}
}
return true;
}

/*
* 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
context->lr_erc20_to_display[index] = -1;
}

/*
* 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
context->lr_strategy_to_display[index] = -1;
}

/*
* 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:
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/kiln_plugin.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <string.h>
#include <ctype.h>

#include "eth_internals.h"
#include "eth_plugin_interface.h"
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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

Expand All @@ -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;

Expand Down

0 comments on commit e4cfaf9

Please sign in to comment.