diff --git a/ethereum-plugin-sdk b/ethereum-plugin-sdk index d672ec1..5ade2d7 160000 --- a/ethereum-plugin-sdk +++ b/ethereum-plugin-sdk @@ -1 +1 @@ -Subproject commit d672ec1d2aadd3a272760168f58022ca674876e3 +Subproject commit 5ade2d77cb6f0f366210d014bc731212a22fc29c diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index 639492b..33d7c5b 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -1,23 +1,15 @@ #include "quickswap_plugin.h" -// Copies the whole parameter (32 bytes long) from `src` to `dst`. -// Useful for numbers, data... -static void copy_parameter(uint8_t *dst, size_t dst_len, uint8_t *src) { - // Take the minimum between dst_len and parameter_length to make sure we don't overwrite memory. - size_t len = MIN(dst_len, PARAMETER_LENGTH); - memcpy(dst, src, len); -} - // Copy amount sent parameter to amount_sent static void handle_amount_sent(const ethPluginProvideParameter_t *msg, quickswap_parameters_t *context) { - copy_parameter(context->amount_sent, sizeof(context->amount_sent), msg->parameter); + copy_parameter(context->amount_sent, msg->parameter, sizeof(context->amount_sent)); } // Copy amount sent parameter to amount_received static void handle_amount_received(const ethPluginProvideParameter_t *msg, quickswap_parameters_t *context) { - copy_parameter(context->amount_received, sizeof(context->amount_received), msg->parameter); + copy_parameter(context->amount_received, msg->parameter, sizeof(context->amount_received)); } static void handle_beneficiary(const ethPluginProvideParameter_t *msg, @@ -67,8 +59,8 @@ static void handle_value_sent(const ethPluginProvideParameter_t *msg, ethPluginSharedRO_t *pluginSharedRO = (ethPluginSharedRO_t *) msg->pluginSharedRO; copy_parameter(context->amount_sent, - pluginSharedRO->txContent->value.length, - pluginSharedRO->txContent->value.value); + pluginSharedRO->txContent->value.value, + pluginSharedRO->txContent->value.length); } static void handle_swap_exact_tokens(ethPluginProvideParameter_t *msg, @@ -169,51 +161,6 @@ static void handle_swap_tokens_for_exact_tokens(ethPluginProvideParameter_t *msg } } -static void handle_swap_exact_eth_for_tokens(ethPluginProvideParameter_t *msg, - quickswap_parameters_t *context) { - switch (context->next_param) { - case AMOUNT_RECEIVED: // amountOut - handle_amount_received(msg, context); - - handle_value_sent(msg, context); - - context->next_param = PATHS_OFFSET; - break; - - case PATHS_OFFSET: - context->next_param = BENEFICIARY; - break; - - case BENEFICIARY: - handle_beneficiary(msg, context); - context->next_param = PATH; - context->skip++; // we skip deadline - break; - - case PATH: // len(path) - context->next_param = TOKEN_SENT; - break; - - case TOKEN_SENT: // path[0] - handle_token_sent(msg, context); - context->next_param = TOKEN_RECEIVED; - break; - - case TOKEN_RECEIVED: // path[len(path) - 1] - handle_token_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_add_remove_liquidity(ethPluginProvideParameter_t *msg, quickswap_parameters_t *context) { switch (context->next_param) { diff --git a/src/handle_provide_token.c b/src/handle_provide_token.c index b7ea0c2..b12c71a 100644 --- a/src/handle_provide_token.c +++ b/src/handle_provide_token.c @@ -1,16 +1,18 @@ #include "quickswap_plugin.h" void handle_provide_token(void *parameters) { - ethPluginProvideToken_t *msg = (ethPluginProvideToken_t *) parameters; + ethPluginProvideInfo_t *msg = (ethPluginProvideInfo_t *) parameters; quickswap_parameters_t *context = (quickswap_parameters_t *) msg->pluginContext; - PRINTF("QUICKSWAP plugin provide token: 0x%p, 0x%p\n", msg->token1, msg->token2); + PRINTF("QUICKSWAP plugin provide token: 0x%p, 0x%p\n", msg->item1->token, msg->item2->token); if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_sent)) { context->decimals_sent = WEI_TO_ETHER; context->tokens_found |= TOKEN_SENT_FOUND; - } else if (msg->token1 != NULL) { - context->decimals_sent = msg->token1->decimals; - strlcpy(context->ticker_sent, (char *) msg->token1->ticker, sizeof(context->ticker_sent)); + } 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. @@ -22,10 +24,10 @@ void handle_provide_token(void *parameters) { if (ADDRESS_IS_NETWORK_TOKEN(context->contract_address_received)) { context->decimals_received = WEI_TO_ETHER; context->tokens_found |= TOKEN_RECEIVED_FOUND; - } else if (msg->token2 != NULL) { - context->decimals_received = msg->token2->decimals; + } else if (msg->item2 != NULL) { + context->decimals_received = msg->item2->token.decimals; strlcpy(context->ticker_received, - (char *) msg->token2->ticker, + (char *) msg->item2->token.ticker, sizeof(context->ticker_received)); context->tokens_found |= TOKEN_RECEIVED_FOUND; } else { diff --git a/src/main.c b/src/main.c index b2dbcd7..d23c53e 100644 --- a/src/main.c +++ b/src/main.c @@ -183,7 +183,7 @@ void quickswap_plugin_call(int message, void *parameters) { case ETH_PLUGIN_FINALIZE: handle_finalize(parameters); break; - case ETH_PLUGIN_PROVIDE_TOKEN: + case ETH_PLUGIN_PROVIDE_INFO: handle_provide_token(parameters); break; case ETH_PLUGIN_QUERY_CONTRACT_ID: diff --git a/tests/elfs/ethereum_nanos.elf b/tests/elfs/ethereum_nanos.elf index 94d4811..da9e475 100755 Binary files a/tests/elfs/ethereum_nanos.elf and b/tests/elfs/ethereum_nanos.elf differ diff --git a/tests/elfs/ethereum_nanox.elf b/tests/elfs/ethereum_nanox.elf index cc2ef44..a1e31a9 100755 Binary files a/tests/elfs/ethereum_nanox.elf and b/tests/elfs/ethereum_nanox.elf differ diff --git a/tests/elfs/quickswap_nanos.elf b/tests/elfs/quickswap_nanos.elf index 4f74140..1b09799 100755 Binary files a/tests/elfs/quickswap_nanos.elf and b/tests/elfs/quickswap_nanos.elf differ diff --git a/tests/elfs/quickswap_nanox.elf b/tests/elfs/quickswap_nanox.elf index f786f17..91b4b4c 100755 Binary files a/tests/elfs/quickswap_nanox.elf and b/tests/elfs/quickswap_nanox.elf differ