-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from blooo-io/feat/paraswap-v5-migration
feat: migration including v5 methods
- Loading branch information
Showing
327 changed files
with
4,495 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ __pycache__/ | |
|
||
# JS | ||
tests/node_modules | ||
tests/lib | ||
tests/lib | ||
tests/snapshots-tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "paraswap_plugin.h" | ||
|
||
void handle_finalize(void *parameters) { | ||
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters; | ||
paraswap_parameters_t *context = (paraswap_parameters_t *) msg->pluginContext; | ||
if (context->valid) { | ||
msg->numScreens = 2; | ||
if ((context->selectorIndex == SIMPLE_SWAP || context->selectorIndex == SIMPLE_BUY || | ||
context->selectorIndex == SIMPLE_SWAP_V4) && | ||
(strncmp(context->beneficiary, | ||
(const unsigned char *) NULL_ETH_ADDRESS, | ||
ADDRESS_LENGTH) != 0)) { | ||
// An addiitonal screen is required to display the `beneficiary` field. | ||
msg->numScreens += 1; | ||
} | ||
if (!ADDRESS_IS_ETH(context->contract_address_sent)) { | ||
// Address is not ETH so we will need to look up the token in the CAL. | ||
msg->tokenLookup1 = context->contract_address_sent; | ||
PRINTF("Setting address sent to: %.*H\n", | ||
ADDRESS_LENGTH, | ||
context->contract_address_sent); | ||
|
||
// The user is not swapping ETH, so make sure there's no ETH being sent in this tx. | ||
if (!allzeroes(msg->pluginSharedRO->txContent->value.value, | ||
msg->pluginSharedRO->txContent->value.length)) { | ||
PRINTF("ETH attached to tx when token being swapped is %.*H\n", | ||
sizeof(context->contract_address_sent), | ||
context->contract_address_sent); | ||
msg->result = ETH_PLUGIN_RESULT_ERROR; | ||
} | ||
} else { | ||
msg->tokenLookup1 = NULL; | ||
} | ||
if (!ADDRESS_IS_ETH(context->contract_address_received)) { | ||
// Address is not ETH so we will need to look up the token in the CAL. | ||
PRINTF("Setting address receiving to: %.*H\n", | ||
ADDRESS_LENGTH, | ||
context->contract_address_received); | ||
msg->tokenLookup2 = context->contract_address_received; | ||
} else { | ||
msg->tokenLookup2 = NULL; | ||
} | ||
|
||
msg->uiType = ETH_UI_TYPE_GENERIC; | ||
msg->result = ETH_PLUGIN_RESULT_OK; | ||
} else { | ||
PRINTF("Context not valid\n"); | ||
msg->result = ETH_PLUGIN_RESULT_FALLBACK; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "paraswap_plugin.h" | ||
|
||
// Called once to init. | ||
void handle_init_contract(void *parameters) { | ||
ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters; | ||
|
||
if (msg->interfaceVersion != ETH_PLUGIN_INTERFACE_VERSION_LATEST) { | ||
PRINTF("Wrong interface version: expected %d got %d\n", | ||
ETH_PLUGIN_INTERFACE_VERSION_LATEST, | ||
msg->interfaceVersion); | ||
msg->result = ETH_PLUGIN_RESULT_UNAVAILABLE; | ||
return; | ||
} | ||
|
||
if (msg->pluginContextLength < sizeof(paraswap_parameters_t)) { | ||
PRINTF("Paraswap context size too big: expected %d got %d\n", | ||
sizeof(paraswap_parameters_t), | ||
msg->pluginContextLength); | ||
msg->result = ETH_PLUGIN_RESULT_ERROR; | ||
return; | ||
} | ||
|
||
paraswap_parameters_t *context = (paraswap_parameters_t *) msg->pluginContext; | ||
memset(context, 0, sizeof(*context)); | ||
context->valid = 1; | ||
|
||
for (uint8_t i = 0; i < NUM_PARASWAP_SELECTORS; i++) { | ||
if (memcmp((uint8_t *) PIC(PARASWAP_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { | ||
context->selectorIndex = i; | ||
break; | ||
} | ||
} | ||
|
||
// Set `next_param` to be the first field we expect to parse. | ||
switch (context->selectorIndex) { | ||
case BUY_ON_UNI_FORK: | ||
case SWAP_ON_UNI_FORK: | ||
case BUY_ON_UNI: | ||
case SWAP_ON_UNI: | ||
case SWAP_ON_UNI_V4: | ||
case SWAP_ON_UNI_FORK_V4: | ||
case BUY_ON_UNI_V4: | ||
case BUY_ON_UNI_FORK_V4: | ||
if (context->selectorIndex == SWAP_ON_UNI_FORK || | ||
context->selectorIndex == BUY_ON_UNI_FORK || | ||
context->selectorIndex == SWAP_ON_UNI_FORK_V4 || | ||
context->selectorIndex == BUY_ON_UNI_FORK_V4) { | ||
context->skip = | ||
2; // Skip the first two parameters (factory and initCode) for uni forks. | ||
} | ||
context->next_param = AMOUNT_SENT; | ||
break; | ||
case SWAP_ON_ZERO_V4: | ||
case SWAP_ON_ZERO_V2: | ||
context->next_param = TOKEN_SENT; | ||
break; | ||
case MEGA_SWAP: | ||
case BUY: | ||
case MULTI_SWAP: | ||
case SIMPLE_BUY: | ||
case SIMPLE_SWAP: | ||
case SIMPLE_SWAP_V4: | ||
case MULTI_SWAP_V4: | ||
case MEGA_SWAP_V4: | ||
context->next_param = TOKEN_SENT; | ||
if (context->selectorIndex != SIMPLE_SWAP_V4) | ||
context->skip = 1; // Skipping 0x20 (offset of structure) | ||
break; | ||
default: | ||
PRINTF("Missing selectorIndex\n"); | ||
msg->result = ETH_PLUGIN_RESULT_ERROR; | ||
return; | ||
} | ||
msg->result = ETH_PLUGIN_RESULT_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.