Skip to content

Commit

Permalink
Merge pull request #8 from blooo-io/feat/LDG-253-implement-claimselfa…
Browse files Browse the repository at this point in the history
…pecoin-method-and-test

Feat/ldg 253 implement claimselfapecoin method and test
  • Loading branch information
GuilaneDen authored Sep 15, 2023
2 parents 2c6cbaf + 1c071dc commit 723aea9
Show file tree
Hide file tree
Showing 211 changed files with 6,327 additions and 34 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Smart contracts covered by this plugin are:
| Ethereum | CometRewards | 0x1b0e765f6224c21223aea2af16c1c46e38885a40|
| Polygon | TransparentUpgradeableProxy | 0xf25212e676d1f7f89cd72ffee66158f541246445|
| Polygon | CometRewards | 0x45939657d1ca34a8fa39a924b71d28fe8431e581|
| BSC | TokenHub | 0x0000000000000000000000000000000000001004|
| Celo | AccountsProxy | 0x7d21685c17607338b313a7174bab6620bad0aab7|
| Celo | LockedGoldProxy | 0x6cc083aed9e3ebe302a6336dbc7c921c9f03349e|
| Celo | ElectionProxy | 0x8d6677192144292870907e3fa8a5527fe55a7ff6|


## Methods
Expand Down Expand Up @@ -78,6 +82,12 @@ Methods covered by this plugin are:
| TransparentUpgradeableProxy | 0xf2b9fdb8 | supply |
| TransparentUpgradeableProxy | 0xf3fef3a3 | withdraw |
| CometRewards | 0xb7034f7e | claim |
| TokenHub | 0xaa7415f5 | transferOut |
| AccountsProxy | 0x9dca362f | createAccount |
| LockedGoldProxy | 0xf83d08ba | lock |
| LockedGoldProxy | 0x6198e339 | unlock |
| ElectionProxy | 0x580d747a | vote |
| ElectionProxy | 0x6e198475 | revokeActive |


## Build
Expand Down
22 changes: 17 additions & 5 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ static const uint8_t STAKEKIT_LEAVE_SELECTOR[SELECTOR_SIZE] = {0x67, 0xdf, 0xd4,
static const uint8_t STAKEKIT_COMET_SUPPLY_SELECTOR[SELECTOR_SIZE] = {0xf2, 0xb9, 0xfd, 0xb8};
static const uint8_t STAKEKIT_COMET_WITHDRAW_SELECTOR[SELECTOR_SIZE] = {0xf3, 0xfe, 0xf3, 0xa3};
static const uint8_t STAKEKIT_COMET_CLAIM_SELECTOR[SELECTOR_SIZE] = {0xb7, 0x03, 0x4f, 0x7e};
static const uint8_t STAKEKIT_TRANSFER_OUT_SELECTOR[SELECTOR_SIZE] = {0xaa, 0x74, 0x15, 0xf5};
static const uint8_t STAKEKIT_CREATE_ACCOUNT_SELECTOR[SELECTOR_SIZE] = {0x9d, 0xca, 0x36, 0x2f};
static const uint8_t STAKEKIT_LOCK_SELECTOR[SELECTOR_SIZE] = {0xf8, 0x3d, 0x08, 0xba};
static const uint8_t STAKEKIT_UNLOCK_SELECTOR[SELECTOR_SIZE] = {0x61, 0x98, 0xe3, 0x39};
static const uint8_t STAKEKIT_VOTE_SELECTOR[SELECTOR_SIZE] = {0x58, 0x0d, 0x74, 0x7a};
static const uint8_t STAKEKIT_REVOKE_ACTIVE_SELECTOR[SELECTOR_SIZE] = {0x6e, 0x19, 0x84, 0x75};

// Array of all the different StakeKit selectors.
const uint8_t *const STAKEKIT_SELECTORS[NUM_STAKEKIT_SELECTORS] = {
Expand Down Expand Up @@ -68,13 +74,19 @@ const uint8_t *const STAKEKIT_SELECTORS[NUM_STAKEKIT_SELECTORS] = {
STAKEKIT_COMET_SUPPLY_SELECTOR,
STAKEKIT_COMET_WITHDRAW_SELECTOR,
STAKEKIT_COMET_CLAIM_SELECTOR,
STAKEKIT_TRANSFER_OUT_SELECTOR,
STAKEKIT_CREATE_ACCOUNT_SELECTOR,
STAKEKIT_LOCK_SELECTOR,
STAKEKIT_UNLOCK_SELECTOR,
STAKEKIT_VOTE_SELECTOR,
STAKEKIT_REVOKE_ACTIVE_SELECTOR,
};

// Ask dummy address ETH
// Remove if not used
const uint8_t PLUGIN_ETH_ADDRESS[ADDRESS_LENGTH] = {0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
0xee, 0xee, 0xee, 0xee, 0xee, 0xee};
// Indicate the Ethereum chain ID
const uint8_t ETH_CHAIN_ID[CHAIN_ID_LENGTH] = {0x01};

// Indicate the BSC chain ID
const uint8_t BSC_CHAIN_ID[CHAIN_ID_LENGTH] = {0x38};

// Remove if not used
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
30 changes: 14 additions & 16 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ void handle_finalize(void *parameters) {

msg->uiType = ETH_UI_TYPE_GENERIC;

// Initialize the decimals and ticker to default value.
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, DEFAULT_TICKER, sizeof(context->ticker_sent));
context->decimals_received = DEFAULT_DECIMAL;
strlcpy(context->ticker_received, DEFAULT_TICKER, sizeof(context->ticker_received));

if (context->valid) {
switch (context->selectorIndex) {
case CLAIM_SELF_APECOIN:
msg->numScreens = 0;
break;
case COMET_CLAIM:
msg->numScreens = 2;
break;
case VOTE:
msg->numScreens = 4;
break;
case REVOKE_ACTIVE:
context->decimals_sent = 0;
msg->numScreens = 4;
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_3:
case TRANSFER_OUT:
msg->numScreens = 2;
msg->tokenLookup1 = context->contract_address_sent;
break;
Expand All @@ -37,69 +48,56 @@ void handle_finalize(void *parameters) {
case SELL_VOUCHER_NEW:
msg->numScreens = 1;
context->decimals_sent = 0;
strlcpy(context->ticker_sent, DEFAULT_TICKER, sizeof(context->ticker_sent));
break;
case ENTER:
msg->numScreens = 1;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, SUSHI_TICKER, sizeof(context->ticker_sent));
break;
case LEAVE:
msg->numScreens = 1;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, XSUSHI_TICKER, sizeof(context->ticker_sent));
break;
case STAKE:
msg->numScreens = 1;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent,
STAKEWISE_STAKED_ETH2_TICKER,
sizeof(context->ticker_sent));
break;
case DEPOSIT_SELF_APECOIN:
msg->numScreens = 1;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, APE_TICKER, sizeof(context->ticker_sent));
break;
case WITHDRAW_SELF_APECOIN:
case PARASPACE_WITHDRAW:
msg->numScreens = 1;
context->decimals_received = DEFAULT_DECIMAL;
strlcpy(context->ticker_received, APE_TICKER, sizeof(context->ticker_received));
break;
case SWAP_TO:
msg->numScreens = 1;
context->decimals_received = DEFAULT_DECIMAL;
strlcpy(context->ticker_received,
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;
strlcpy(context->ticker_received, WETH_TICKER, sizeof(context->ticker_received));
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, ROCKET_POOL_ETH_TICKER, sizeof(context->ticker_sent));
break;
case PARASPACE_DEPOSIT:
msg->numScreens = 2;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, APE_TICKER, sizeof(context->ticker_sent));
break;
case GRT_DELEGATE:
msg->numScreens = 2;
context->decimals_sent = DEFAULT_DECIMAL;
strlcpy(context->ticker_sent, GRT_TICKER, sizeof(context->ticker_sent));
break;
default:
Expand Down
6 changes: 6 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void handle_init_contract(void *parameters) {
case SELL_VOUCHER_NEW:
case ENTER:
case LEAVE:
case UNLOCK:
context->next_param = AMOUNT_SENT;
break;
case WITHDRAW_SELF_APECOIN:
Expand All @@ -51,6 +52,8 @@ void handle_init_contract(void *parameters) {
break;
case CLAIM_SELF_APECOIN:
case STAKE:
case CREATE_ACCOUNT:
case LOCK:
context->next_param = NONE;
break;
case SUBMIT_ETH_LIDO:
Expand All @@ -59,12 +62,15 @@ void handle_init_contract(void *parameters) {
case GRT_UNDELEGATE:
case GRT_WITHDRAW_DELEGATED:
case COMET_CLAIM:
case VOTE:
case REVOKE_ACTIVE:
context->next_param = RECIPIENT;
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_2:
case MORPHO_SUPPLY_3:
case COMET_SUPPLY:
case TRANSFER_OUT:
context->next_param = TOKEN_SENT;
break;
case MORPHO_WITHDRAW_1:
Expand Down
45 changes: 44 additions & 1 deletion src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg,

static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
case RECIPIENT: // Put the Comet protocol address in contract_address_sent
case RECIPIENT: // Put the Comet protocol address in contract_address_sent
copy_address(context->contract_address_sent, msg->parameter, ADDRESS_LENGTH);
context->next_param = RECIPIENT_2;
break;
Expand All @@ -153,6 +153,41 @@ static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_paramete
}
}

static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) {
switch (context->next_param) {
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 = RECIPIENT_2;
break;
case RECIPIENT_2: // Put the lesser group address in contract_address_sent
copy_address(context->contract_address_sent, msg->parameter, ADDRESS_LENGTH);
if (ADDRESS_IS_NULL(context->contract_address_sent)) {
copy_address(context->contract_address_sent, context->recipient, ADDRESS_LENGTH);
}
context->next_param = RECIPIENT_3;
break;
case RECIPIENT_3: // Put the greater group address in contract_address_received
copy_address(context->contract_address_received, msg->parameter, ADDRESS_LENGTH);
if (ADDRESS_IS_NULL(context->contract_address_received)) {
copy_address(context->contract_address_received,
context->recipient,
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 @@ -175,6 +210,7 @@ void handle_provide_parameter(void *parameters) {
case CLAIM_TOKENS:
case ENTER:
case LEAVE:
case UNLOCK:
copy_parameter(context->amount_sent, msg->parameter, INT256_LENGTH);
break;
case BUY_VOUCHER:
Expand All @@ -192,6 +228,8 @@ void handle_provide_parameter(void *parameters) {
break;
case CLAIM_SELF_APECOIN:
case STAKE:
case CREATE_ACCOUNT:
case LOCK:
break;
case SUBMIT_MATIC_LIDO:
case REQUEST_WITHDRAW:
Expand All @@ -202,6 +240,7 @@ void handle_provide_parameter(void *parameters) {
break;
case MORPHO_SUPPLY_1:
case MORPHO_SUPPLY_3:
case TRANSFER_OUT:
handle_morpho_supply_1_3(msg, context);
break;
case MORPHO_WITHDRAW_1:
Expand All @@ -227,6 +266,10 @@ void handle_provide_parameter(void *parameters) {
case COMET_CLAIM:
handle_comet_claim(msg, context);
break;
case VOTE:
case REVOKE_ACTIVE:
handle_vote_revoke(msg, context);
break;
default:
PRINTF("Selector Index %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
18 changes: 18 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ void handle_query_contract_id(void *parameters) {
case COMET_CLAIM:
strlcpy(msg->version, "Claim", msg->versionLength);
break;
case TRANSFER_OUT:
strlcpy(msg->version, "Transfer Out", msg->versionLength);
break;
case CREATE_ACCOUNT:
strlcpy(msg->version, "Create Account", msg->versionLength);
break;
case LOCK:
strlcpy(msg->version, "Lock", msg->versionLength);
break;
case UNLOCK:
strlcpy(msg->version, "Unlock", msg->versionLength);
break;
case VOTE:
strlcpy(msg->version, "Vote", msg->versionLength);
break;
case REVOKE_ACTIVE:
strlcpy(msg->version, "Revoke Active", msg->versionLength);
break;
default:
PRINTF("Selector Index :%d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
Loading

0 comments on commit 723aea9

Please sign in to comment.