Skip to content

Commit

Permalink
backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Manoj Patra committed Oct 19, 2023
1 parent ce56599 commit f090f96
Show file tree
Hide file tree
Showing 60 changed files with 121 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ void handle_finalize(void *parameters) {

switch (context->selectorIndex) {
case ETHX_DEPOSIT:
case ETHX_DEPOSIT_LEGACY:
case ETHX_REQUEST_WITHDRAW:
case ETHX_REQUEST_WITHDRAW_LEGACY:
msg->numScreens = 2;
break;

Expand Down
2 changes: 2 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ void handle_init_contract(void *parameters) {
// EDIT THIS: Adapt the `cases`, and set the `next_param` to be the first parameter you expect
// to parse.
switch (context->selectorIndex) {
case ETHX_DEPOSIT_LEGACY:
case ETHX_DEPOSIT:
context->next_param = ACCOUNT_ADDR;
context->ticker = "ETH";
break;

case ETHX_REQUEST_WITHDRAW_LEGACY:
case ETHX_REQUEST_WITHDRAW:
context->next_param = UNSTAKE_AMOUNT;
context->ticker = "ETHX";
Expand Down
2 changes: 2 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ void handle_provide_parameter(void *parameters) {

// EDIT THIS: adapt the cases and the names of the functions.
switch (context->selectorIndex) {
case ETHX_DEPOSIT_LEGACY:
case ETHX_DEPOSIT:
handle_ethx_deposit(msg, context);
break;

case ETHX_REQUEST_WITHDRAW_LEGACY:
case ETHX_REQUEST_WITHDRAW:
handle_ethx_request_withdraw(msg, context);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void handle_query_contract_id(void *parameters) {
// EDIT THIS: Adapt the cases by modifying the strings you pass to `strlcpy`.
switch (context->selectorIndex) {
case ETHX_DEPOSIT:
case ETHX_DEPOSIT_LEGACY:
case ETH_MATICX_SUBMIT:
case POLYGON_CHILDPOOL_SWAP_MATIC_FOR_MATICX_VIA_INSTANT_POOL:
case BSC_STAKEMANAGER_DEPOSIT:
Expand All @@ -22,6 +23,7 @@ void handle_query_contract_id(void *parameters) {
break;

case ETHX_REQUEST_WITHDRAW:
case ETHX_REQUEST_WITHDRAW_LEGACY:
case ETH_MATICX_REQUEST_WITHDRAW:
case POLYGON_CHILDPOOL_REQUEST_MATICX_SWAP:
case BSC_STAKEMANAGER_REQUEST_WITHDRAW:
Expand Down
2 changes: 2 additions & 0 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ void handle_query_contract_ui(void *parameters) {
break;

case ETHX_DEPOSIT:
case ETHX_DEPOSIT_LEGACY:
handle_ethx_deposit(msg, context);
break;

case ETHX_REQUEST_WITHDRAW:
case ETHX_REQUEST_WITHDRAW_LEGACY:
handle_ethx_request_withdraw(msg, context);
break;

Expand Down
14 changes: 14 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ static const uint32_t ETHX_REQUEST_WITHDRAW_SELECTOR = 0x1f7ec122;
// Selector: 0x379607f5
static const uint32_t ETHX_CLAIM_SELECTOR = 0x379607f5;

// Network: Ethereum
// Contract: StaderStakePoolsManager
// Method: function deposit(address _receiver)
// Selector: 0xf340fa01
static const uint32_t ETHX_DEPOSIT_LEGACY_SELECTOR = 0xf340fa01;

// Network: Ethereum
// Contract: UserWithdrawalManager
// Method: function requestWithdraw(uint256 _ethXAmount, address _owner)
// Selector: 0xccc143b8
static const uint32_t ETHX_REQUEST_WITHDRAW_LEGACY_SELECTOR = 0xccc143b8;

// Array of all the different staderlabs selectors. Make sure this follows the same order as the
// enum defined in `staderlabs_plugin.h`
const uint32_t STADERLABS_SELECTORS[NUM_SELECTORS] = {
Expand All @@ -136,6 +148,8 @@ const uint32_t STADERLABS_SELECTORS[NUM_SELECTORS] = {
ETHX_DEPOSIT_SELECTOR,
ETHX_REQUEST_WITHDRAW_SELECTOR,
ETHX_CLAIM_SELECTOR,
ETHX_DEPOSIT_LEGACY_SELECTOR,
ETHX_REQUEST_WITHDRAW_LEGACY_SELECTOR,
};

// Function to dispatch calls from the ethereum app.
Expand Down
4 changes: 3 additions & 1 deletion src/staderlabs_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string.h>

// Number of selectors defined in this plugin. Should match the enum `selector_t`.
#define NUM_SELECTORS 15
#define NUM_SELECTORS 17

// Name of the plugin.
#define PLUGIN_NAME "Staderlabs"
Expand All @@ -28,6 +28,8 @@ typedef enum {
ETHX_DEPOSIT,
ETHX_REQUEST_WITHDRAW,
ETHX_CLAIM,
ETHX_DEPOSIT_LEGACY,
ETHX_REQUEST_WITHDRAW_LEGACY,
} selector_t;

// Enumeration used to parse the smart contract data.
Expand Down
10 changes: 10 additions & 0 deletions tests/networks/ethereum/staderlabs/b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"address": "0xcf5ea1b38380f6af39068375516daf40ed70d299",
"contractName": "StaderStakePoolsManager",
"selectors": {
"0xf340fa01": {
"erc20OfInterest": [],
"method": "deposit",
"plugin": "Staderlabs"
},
"0xb7482509": {
"erc20OfInterest": [],
"method": "deposit",
Expand All @@ -37,6 +42,11 @@
"address": "0x9f0491b32dbce587c50c4c43ab303b06478193a7",
"contractName": "UserWithdrawalManager",
"selectors": {
"0xccc143b8": {
"erc20OfInterest": [],
"method": "requestWithdraw",
"plugin": "Staderlabs"
},
"0x1f7ec122": {
"erc20OfInterest": [],
"method": "requestWithdraw",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions tests/src/eth/ethx/deposit_legacy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import "core-js/stable";
import "regenerator-runtime";
import {
waitForAppScreen,
zemu,
nano_models,
serializeTx,
txFromEtherscan,
} from "../../test.fixture";

const contractAddr = "0xcf5ea1b38380f6af39068375516daf40ed70d299";
const pluginName = "staderlabs";
const testNetwork = "ethereum";
const chainID = 1;
// Test from replayed transaction: https://etherscan.io/tx/0x4e771017864ff34176c8c9fa62fe1950852933345f921dc5316c63554c9bc453
const inputData =
"0x02f8980113850550de54dd850550de54dd8301c88a94cf5ea1b38380f6af39068375516daf40ed70d29987038d7ea4c68000a4f340fa01000000000000000000000000ad345b348bd84a4b42a5fde63feb7a29ef2af4e9c080a0a3adf22f4ce9fead664befb0ca33730f3bb8edb1a1d65a7f5275ac9a8622d29ea01a99e171740d723ee61049d7f0465f4e219fca86aaddf06bab02d3400f554242";

nano_models.forEach(function (model) {
test(
"[Nano " + model.letter + "] Legacy Deposit ETH",
zemu(model, async (sim, eth) => {
const serializedTx = txFromEtherscan(inputData);

const tx = eth.signTransaction("44'/60'/0'/0", serializedTx);

const right_clicks = model.letter === "S" ? 9 : 5;

// Wait for the application to actually load and parse the transaction
await waitForAppScreen(sim);
// Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction.
await sim.navigateAndCompareSnapshots(
".",
testNetwork + "_ethx_" + model.name + "_legacy_stake_eth",
[right_clicks, 0]
);

await tx;
}),
50000
);
});
42 changes: 42 additions & 0 deletions tests/src/eth/ethx/withdraw_legacy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import "core-js/stable";
import "regenerator-runtime";
import {
waitForAppScreen,
zemu,
nano_models,
serializeTx,
txFromEtherscan,
} from "../../test.fixture";

const contractAddr = "0xcf5ea1b38380f6af39068375516daf40ed70d299";
const pluginName = "staderlabs";
const testNetwork = "ethereum";
const chainID = 1;
// Test from replayed transaction: https://etherscan.io/tx/0xa7b2f78c84bc5528629d37b56856d47601c42f4d7f1505fa6767bcd090fb5044
const inputData =
"0x02f8b30182059585053f837bd185053f837bd18304d7be949f0491b32dbce587c50c4c43ab303b06478193a780b844ccc143b80000000000000000000000000000000000000000000000056a30e2758fb0a40000000000000000000000000087bc2f2ba8c83f412fed5c3151de0ffbdc959984c080a01bf62d962c7e2d888df40f0a61dd9eb6c60ed01e1291ce15b9acbad154e0cf619fc470d4477df1e52cb4030e2f976dc13856d09010d164dd97a5532d59b9d413";

nano_models.forEach(function (model) {
test(
"[Nano " + model.letter + "] Legacy Request Withdraw ETH",
zemu(model, async (sim, eth) => {
const serializedTx = txFromEtherscan(inputData);

const tx = eth.signTransaction("44'/60'/0'/0", serializedTx);

const right_clicks = model.letter === "S" ? 9 : 5;

// Wait for the application to actually load and parse the transaction
await waitForAppScreen(sim);
// Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction.
await sim.navigateAndCompareSnapshots(
".",
testNetwork + "_ethx_" + model.name + "_legacy_request_withdraw_eth",
[right_clicks, 0]
);

await tx;
}),
50000
);
});

0 comments on commit f090f96

Please sign in to comment.