Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ldg 267 implement the 2 withdraw methods and tests #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Smart contracts covered by this plugin are:
| Ethereum | AppProxyUpgradeable | 0xae7ab96520de3a18e5e111b5eaab095312d7fe84|
| Ethereum | RocketSwapRouter | 0x16d5a408e807db8ef7c578279beeee6b228f1c1c|
| Ethereum | AdminUpgradeabilityProxy | 0xc874b064f465bdd6411d45734b56fac750cda29a|
| Ethereum | TransparentUpgradeableProxy | 0x9ee91f9f426fa633d227f7a9b000e28b9dfd8599|
| Ethereum | ValidatorShareProxy | 0x857679d69fe50e7b722f94acd2629d80c355163d|
| Ethereum | TransparentUpgradeableProxy | 0x777777c9898d384f785ee44acfe945efdff5f3e0|


## Methods
Expand All @@ -48,6 +51,16 @@ Methods covered by this plugin are:
| RocketSwapRouter | 0x55362f4d | swapTo |
| RocketSwapRouter | 0xa824ae8b | swapFrom |
| AdminUpgradeabilityProxy | 0x3a4b66f1 | stake |
| TransparentUpgradeableProxy | 0xf532e86a | submit |
| TransparentUpgradeableProxy | 0xccc143b8 | requestWithdraw |
| TransparentUpgradeableProxy | 0x46e04a2f | claimTokens |
| ValidatorShareProxy | 0x6ab15071 | buyVoucher |
| ValidatorShareProxy | 0xc83ec04d | sellVoucher_new |
| TransparentUpgradeableProxy | 0x0c0a769b | supply |
| TransparentUpgradeableProxy | 0xf2b9fdb8 | supply |
| TransparentUpgradeableProxy | 0xf62256c7 | supply |
| TransparentUpgradeableProxy | 0xf3fef3a3 | withdraw |
| TransparentUpgradeableProxy | 0x69328dec | withdraw |


## Build
Expand Down
20 changes: 20 additions & 0 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ static const uint8_t STAKEKIT_SUBMIT_ETH_LIDO_SELECTOR[SELECTOR_SIZE] = {0xa1, 0
static const uint8_t STAKEKIT_SWAP_TO_SELECTOR[SELECTOR_SIZE] = {0x55, 0x36, 0x2f, 0x4d};
static const uint8_t STAKEKIT_SWAP_FROM_SELECTOR[SELECTOR_SIZE] = {0xa8, 0x24, 0xae, 0x8b};
static const uint8_t STAKEKIT_STAKE_SELECTOR[SELECTOR_SIZE] = {0x3a, 0x4b, 0x66, 0xf1};
static const uint8_t STAKEKIT_SUBMIT_MATIC_LIDO_SELECTOR[SELECTOR_SIZE] = {0xf5, 0x32, 0xe8, 0x6a};
static const uint8_t STAKEKIT_REQUEST_WITHDRAW_SELECTOR[SELECTOR_SIZE] = {0xcc, 0xc1, 0x43, 0xb8};
static const uint8_t STAKEKIT_CLAIM_TOKENS_SELECTOR[SELECTOR_SIZE] = {0x46, 0xe0, 0x4a, 0x2f};
static const uint8_t STAKEKIT_BUY_VOUCHER_SELECTOR[SELECTOR_SIZE] = {0x6a, 0xb1, 0x50, 0x71};
static const uint8_t STAKEKIT_SELL_VOUCHER_NEW_SELECTOR[SELECTOR_SIZE] = {0xc8, 0x3e, 0xc0, 0x4d};
static const uint8_t STAKEKIT_MORPHO_SUPPLY_1_SELECTOR[SELECTOR_SIZE] = {0x0c, 0x0a, 0x76, 0x9b};
static const uint8_t STAKEKIT_MORPHO_SUPPLY_2_SELECTOR[SELECTOR_SIZE] = {0xf2, 0xb9, 0xfd, 0xb8};
static const uint8_t STAKEKIT_MORPHO_SUPPLY_3_SELECTOR[SELECTOR_SIZE] = {0xf6, 0x22, 0x56, 0xc7};
static const uint8_t STAKEKIT_MORPHO_WITHDRAW_1_SELECTOR[SELECTOR_SIZE] = {0xf3, 0xfe, 0xf3, 0xa3};
static const uint8_t STAKEKIT_MORPHO_WITHDRAW_2_SELECTOR[SELECTOR_SIZE] = {0x69, 0x32, 0x8d, 0xec};

// Array of all the different StakeKit selectors.
const uint8_t *const STAKEKIT_SELECTORS[NUM_STAKEKIT_SELECTORS] = {
Expand All @@ -25,6 +35,16 @@ const uint8_t *const STAKEKIT_SELECTORS[NUM_STAKEKIT_SELECTORS] = {
STAKEKIT_SWAP_TO_SELECTOR,
STAKEKIT_SWAP_FROM_SELECTOR,
STAKEKIT_STAKE_SELECTOR,
STAKEKIT_SUBMIT_MATIC_LIDO_SELECTOR,
STAKEKIT_REQUEST_WITHDRAW_SELECTOR,
STAKEKIT_CLAIM_TOKENS_SELECTOR,
STAKEKIT_BUY_VOUCHER_SELECTOR,
STAKEKIT_SELL_VOUCHER_NEW_SELECTOR,
STAKEKIT_MORPHO_SUPPLY_1_SELECTOR,
STAKEKIT_MORPHO_SUPPLY_2_SELECTOR,
STAKEKIT_MORPHO_SUPPLY_3_SELECTOR,
STAKEKIT_MORPHO_WITHDRAW_1_SELECTOR,
STAKEKIT_MORPHO_WITHDRAW_2_SELECTOR,
};

// Ask dummy address ETH
Expand Down
34 changes: 34 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ void handle_finalize(void *parameters) {
case CLAIM_SELF_APECOIN:
msg->numScreens = 0;
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_3:
msg->numScreens = 2;
msg->tokenLookup1 = context->contract_address_sent;
break;
case MORPHO_SUPPLY_2:
msg->numScreens = 1;
msg->tokenLookup1 = context->contract_address_sent;
break;
case MORPHO_WITHDRAW_1:
msg->numScreens = 1;
msg->tokenLookup2 = context->contract_address_received;
break;
case MORPHO_WITHDRAW_2:
msg->numScreens = 2;
msg->tokenLookup2 = context->contract_address_received;
break;
case CLAIM_TOKENS:
case SELL_VOUCHER_NEW:
msg->numScreens = 1;
context->decimals_sent = 0;
strlcpy(context->ticker_sent, DEFAULT_TICKER, sizeof(context->ticker_sent));
break;
case STAKE:
msg->numScreens = 1;
context->decimals_sent = DEFAULT_DECIMAL;
Expand All @@ -35,6 +58,17 @@ void handle_finalize(void *parameters) {
ROCKET_POOL_ETH_TICKER,
sizeof(context->ticker_received));
break;
case SUBMIT_MATIC_LIDO:
case REQUEST_WITHDRAW:
msg->numScreens = 2;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, MATIC_TICKER, sizeof(context->ticker_sent));
break;
case BUY_VOUCHER:
msg->numScreens = 1;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, MATIC_TICKER, sizeof(context->ticker_sent));
break;
case SWAP_FROM:
msg->numScreens = 2;
context->decimals_received = DEFAULT_DECIMAL;
Expand Down
14 changes: 14 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void handle_init_contract(void *parameters) {
// Set `next_param` to be the first field we expect to parse.
switch (context->selectorIndex) {
case DEPOSIT_SELF_APECOIN:
case SUBMIT_MATIC_LIDO:
case REQUEST_WITHDRAW:
case CLAIM_TOKENS:
case BUY_VOUCHER:
case SELL_VOUCHER_NEW:
context->next_param = AMOUNT_SENT;
break;
case WITHDRAW_SELF_APECOIN:
Expand All @@ -48,6 +53,15 @@ void handle_init_contract(void *parameters) {
case SUBMIT_ETH_LIDO:
context->next_param = RECIPIENT;
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_2:
case MORPHO_SUPPLY_3:
context->next_param = TOKEN_SENT;
break;
case MORPHO_WITHDRAW_1:
case MORPHO_WITHDRAW_2:
context->next_param = TOKEN_RECEIVED;
break;
case SWAP_TO:
case SWAP_FROM:
context->skip = 3;
Expand Down
126 changes: 124 additions & 2 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,107 @@ static void handle_swap_from(ethPluginProvideParameter_t *msg, plugin_parameters
}
}

static void handle_amount_recipient(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
case AMOUNT_SENT:
copy_parameter(context->amount_sent, msg->parameter, INT256_LENGTH);
context->next_param = RECIPIENT;
break;
case RECIPIENT:
copy_address(context->recipient, msg->parameter, ADDRESS_LENGTH);
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

static void handle_morpho_supply_1_3(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
case TOKEN_SENT:
copy_address(context->contract_address_sent, msg->parameter, INT256_LENGTH);
context->next_param = RECIPIENT;
break;
case RECIPIENT:
copy_address(context->recipient, msg->parameter, ADDRESS_LENGTH);
context->next_param = AMOUNT_SENT;
break;
case AMOUNT_SENT:
copy_parameter(context->amount_sent, msg->parameter, INT256_LENGTH);
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

static void handle_morpho_supply_2(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case TOKEN_SENT:
copy_address(context->contract_address_sent, msg->parameter, INT256_LENGTH);
context->next_param = AMOUNT_SENT;
break;
case AMOUNT_SENT:
copy_parameter(context->amount_sent, msg->parameter, INT256_LENGTH);
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

static void handle_morpho_withdraw_1(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
case TOKEN_RECEIVED:
copy_address(context->contract_address_received, msg->parameter, INT256_LENGTH);
context->next_param = AMOUNT_RECEIVED;
break;
case AMOUNT_RECEIVED:
copy_parameter(context->amount_received, msg->parameter, INT256_LENGTH);
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg,
plugin_parameters_t *context) {
switch (context->next_param) {
case TOKEN_RECEIVED:
copy_address(context->contract_address_received, msg->parameter, INT256_LENGTH);
context->next_param = AMOUNT_RECEIVED;
break;
case AMOUNT_RECEIVED:
copy_parameter(context->amount_received, msg->parameter, INT256_LENGTH);
context->next_param = RECIPIENT;
break;
case RECIPIENT:
copy_address(context->recipient, msg->parameter, ADDRESS_LENGTH);
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;
plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext;
Expand All @@ -35,9 +136,16 @@ void handle_provide_parameter(void *parameters) {
} else {
switch (context->selectorIndex) {
case DEPOSIT_SELF_APECOIN:
case CLAIM_TOKENS:
copy_parameter(context->amount_sent, msg->parameter, INT256_LENGTH);
break;
case BUY_VOUCHER:
case SELL_VOUCHER_NEW:
copy_parameter(context->amount_sent, msg->parameter, INT256_LENGTH);
context->skip = 1;
break;
case WITHDRAW_SELF_APECOIN:
case SWAP_TO:
copy_parameter(context->amount_received, msg->parameter, INT256_LENGTH);
break;
case SUBMIT_ETH_LIDO:
Expand All @@ -46,12 +154,26 @@ void handle_provide_parameter(void *parameters) {
case CLAIM_SELF_APECOIN:
case STAKE:
break;
case SWAP_TO:
copy_parameter(context->amount_received, msg->parameter, INT256_LENGTH);
case SUBMIT_MATIC_LIDO:
case REQUEST_WITHDRAW:
handle_amount_recipient(msg, context);
break;
case SWAP_FROM:
handle_swap_from(msg, context);
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_3:
handle_morpho_supply_1_3(msg, context);
break;
case MORPHO_WITHDRAW_1:
handle_morpho_withdraw_1(msg, context);
break;
case MORPHO_WITHDRAW_2:
handle_morpho_withdraw_2(msg, context);
break;
case MORPHO_SUPPLY_2:
handle_morpho_supply_2(msg, context);
break;
default:
PRINTF("Selector Index %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
62 changes: 29 additions & 33 deletions src/handle_provide_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,36 @@ void handle_provide_token(void *parameters) {
plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext;
PRINTF("Plugin provide tokens : 0x%p, 0x%p\n", msg->item1, msg->item2);

switch (context->selectorIndex) {
default:
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 (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 (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 {
// 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_sent));
// // We will need an additional screen to display a warning message.
msg->additionalScreens++;
}
break;
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 {
// 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_sent));
// // We will need an additional screen to display a warning message.
msg->additionalScreens++;
}

msg->result = ETH_PLUGIN_RESULT_OK;
Expand Down
22 changes: 22 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void handle_query_contract_id(void *parameters) {
strlcpy(msg->version, "Withdraw Self APE coin", msg->versionLength);
break;
case SUBMIT_ETH_LIDO:
case SUBMIT_MATIC_LIDO:
strlcpy(msg->version, "Submit", msg->versionLength);
break;
case SWAP_TO:
Expand All @@ -28,6 +29,27 @@ void handle_query_contract_id(void *parameters) {
case STAKE:
strlcpy(msg->version, "Stake", msg->versionLength);
break;
case REQUEST_WITHDRAW:
strlcpy(msg->version, "Request Withdraw", msg->versionLength);
break;
case CLAIM_TOKENS:
strlcpy(msg->version, "Claim Tokens", msg->versionLength);
break;
case BUY_VOUCHER:
strlcpy(msg->version, "Buy Voucher", msg->versionLength);
break;
case SELL_VOUCHER_NEW:
strlcpy(msg->version, "Sell Voucher New", msg->versionLength);
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_2:
case MORPHO_SUPPLY_3:
strlcpy(msg->version, "Supply", msg->versionLength);
break;
case MORPHO_WITHDRAW_1:
case MORPHO_WITHDRAW_2:
strlcpy(msg->version, "Withdraw", msg->versionLength);
break;
default:
PRINTF("Selector Index :%d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
Loading
Loading