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

Ethx boost rewards #29

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
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
20 changes: 12 additions & 8 deletions PLUGIN_SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

This documentation describes the smart contracts and functions supported by the staderlabs plugin.

#### MATICx
## MATICx

| Network | Contract Name | Smart Contract |
| -------- | ------------- | -------------------------------------------- |
| Ethereum | MaticX | `0xf03a7eb46d01d9ecaa104558c732cf82f6b6b645` |
| Polygon | ChildPool | `0xfd225c9e6601c9d38d8f98d8731bf59efcf8c0e3` |

Functions covered by above contract/s :
#### Functions covered by above contract/s :
|Contract | Function | Selector | Displayed Parameters |
| --- | --- | --- | --- |
|MaticX | submit(uint256 \_amount) | `0xea99c2a6`| `_amount` |
Expand All @@ -21,44 +21,48 @@ Functions covered by above contract/s :
|ChildPool | requestMaticXSwap(uint256 \_amount) | `0x48eaf6d6`| `_amount` |
|ChildPool | claimMaticXSwap(uint256 \_idx) | `0x77baf209`| |

#### BNBx
## BNBx

| Network | Contract Name | Smart Contract |
| ------- | ------------- | -------------------------------------------- |
| BSC | StakeManager | `0x7276241a669489E4BBB76f63d2A43Bfe63080F2F` |

Functions covered by above contract/s :
#### Functions covered by above contract/s :
|Contract | Function | Selector | Displayed Parameters |
| --- | --- | --- | --- |
|StakeManager | deposit() | `0xd0e30db0`| native_token_amount (bnb) |
|StakeManager | requestWithdraw(uint256 \_amountInBnbX) | `0x745400c9`| `_amountInBnbX` |
|StakeManager | claimWithdraw(uint256 \_idx) | `0xb13acedd`| |

#### FTMx
## FTMx

| Network | Contract Name | Smart Contract |
| ------- | ------------- | -------------------------------------------- |
| Fantom | FTMStaking | `0xb458bfc855ab504a8a327720fcef98886065529b` |

Functions covered by above contract/s :
#### Functions covered by above contract/s :
|Contract | Function | Selector | Displayed Parameters |
| --- | --- | --- | --- |
|FTMStaking | deposit() | `0xd0e30db0`| native_token_amount (ftm) |
|FTMStaking | undelegate(uint256 wrID, uint256 amountFTMx, uint256 minAmountFTM) | `0x4f864df4`| `amountFTMx` |
|FTMStaking | withdraw(uint256 wrID, uint256 bitmaskToSkip) | `0x441a3e70`| |

#### ETHx
## ETHx

| Network | Contract Name | Smart Contract |
| -------- | ----------------------- | -------------------------------------------- |
| Ethereum | StaderStakePoolsManager | `0xcf5ea1b38380f6af39068375516daf40ed70d299` |
| Ethereum | UserWithdrawalManager | `0x9f0491b32dbce587c50c4c43ab303b06478193a7` |
| Ethereum | MerkleDistributor | `0xefE048ADed507b21CcA84d295135652Ef49CD04e` |

Functions covered by above contract/s :
NOTE: MerkleDistributor address is a sample contract, there could be multiple instances of it.

#### Functions covered by above contract/s :
|Contract | Function | Selector | Displayed Parameters |
| --- | --- | --- | --- |
|StaderStakePoolsManager | deposit(address \_receiver, string calldata \_referralId) | `0xb7482509`| `_receiver`, native_token_amount (eth) |
|UserWithdrawalManager | requestWithdraw(uint256 \_ethXAmount, address \_owner, string calldata \_referralId) | `0x1f7ec122`| `_ethXAmount`, `_owner` |
|UserWithdrawalManager | claim(uint256 \_requestId) | `0x379607f5`| |
|StaderStakePoolsManager | deposit(address \_receiver) | `0xf340fa01`| `_receiver`, native_token_amount (eth) |
|UserWithdrawalManager | requestWithdraw(uint256 \_ethXAmount, address \_owner) | `0xccc143b8`| `_ethXAmount`, `_owner` |
|MerkleDistributor | claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) | `0x2e7ba6ef`| `account`, `amount` |
4 changes: 4 additions & 0 deletions ledger_app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+", "stax"]
8 changes: 8 additions & 0 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ static const uint32_t ETHX_DEPOSIT_LEGACY_SELECTOR = 0xf340fa01;
// Selector: 0xccc143b8
static const uint32_t ETHX_REQUEST_WITHDRAW_LEGACY_SELECTOR = 0xccc143b8;

// Network: Ethereum
// Contract: MerkleDistributor
// Method: function claim(uint256 index, address account, uint256 amount, bytes32[] calldata
// merkleProof)
// Selector: 0x2e7ba6ef
static const uint32_t ETHX_BOOST_REWARDS_CLAIM_SELECTOR = 0x2e7ba6ef;

// 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 @@ -144,4 +151,5 @@ const uint32_t STADERLABS_SELECTORS[NUM_SELECTORS] = {
ETHX_CLAIM_SELECTOR,
ETHX_DEPOSIT_LEGACY_SELECTOR,
ETHX_REQUEST_WITHDRAW_LEGACY_SELECTOR,
ETHX_BOOST_REWARDS_CLAIM_SELECTOR,
};
1 change: 1 addition & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void handle_finalize(ethPluginFinalize_t *msg) {
case ETHX_DEPOSIT_LEGACY:
case ETHX_REQUEST_WITHDRAW:
case ETHX_REQUEST_WITHDRAW_LEGACY:
case ETHX_BOOST_REWARDS_CLAIM:
msg->numScreens = 2;
break;

Expand Down
5 changes: 5 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
context->ticker = "FTM";
break;

case ETHX_BOOST_REWARDS_CLAIM:
context->next_param = UNUSED_PARAM;
context->ticker = "SD";
break;

// Keep this
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
Expand Down
30 changes: 30 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ static void handle_ethx_request_withdraw(ethPluginProvideParameter_t *msg, conte
}
}

static void handle_boost_rewards_claim(ethPluginProvideParameter_t *msg, context_t *context) {
if (context->skip_next_param) {
return;
}
switch (context->next_param) {
case UNUSED_PARAM:
context->next_param = ACCOUNT_ADDR;
break;
case ACCOUNT_ADDR:
copy_address(context->account_addr, msg->parameter, sizeof(context->account_addr));
context->next_param = TOKEN_AMOUNT;
break;

case TOKEN_AMOUNT:
handle_amount_received(msg, context);
context->next_param = UNEXPECTED_PARAMETER;
context->skip_next_param = true;
break;

// Keep this
default:
handle_unsupported_param(msg);
break;
}
}

void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
context_t *context = (context_t *) msg->pluginContext;
// We use `%.*H`: it's a utility function to print bytes. You first give
Expand Down Expand Up @@ -133,6 +159,10 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
context->next_param = UNEXPECTED_PARAMETER;
break;

case ETHX_BOOST_REWARDS_CLAIM:
handle_boost_rewards_claim(msg, context);
break;

default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
4 changes: 4 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
msgVersion = "Claim";
break;

case ETHX_BOOST_REWARDS_CLAIM:
msgVersion = "Claim SD Rewards";
break;

default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
25 changes: 25 additions & 0 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ static bool handle_ethx_request_withdraw(ethQueryContractUI_t *msg, context_t *c
return ret;
}

static bool handle_boost_rewards_claim(ethQueryContractUI_t *msg, context_t *context) {
bool ret = false;

memset(msg->title, 0, msg->titleLength);
memset(msg->msg, 0, msg->msgLength);
switch (msg->screenIndex) {
case 0:
ret = set_stake_ui(msg, context); // sets title to "Stake" and msg to token amount
strlcpy(msg->title, "Claim", msg->titleLength); // update the title to "Claim"
break;
case 1:
strlcpy(msg->title, "Receiver", msg->titleLength);
ret = set_account_addr_ui(msg, context);
break;

default:
PRINTF("Received an invalid screenIndex\n");
}
return ret;
}

void handle_query_contract_ui(ethQueryContractUI_t *msg) {
context_t *context = (context_t *) msg->pluginContext;
bool ret = false;
Expand Down Expand Up @@ -160,6 +181,10 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
ret = handle_ethx_request_withdraw(msg, context);
break;

case ETHX_BOOST_REWARDS_CLAIM:
ret = handle_boost_rewards_claim(msg, context);
break;

default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
}
Expand Down
17 changes: 10 additions & 7 deletions 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 17
#define NUM_SELECTORS 18

// Name of the plugin.
#define PLUGIN_NAME "Staderlabs"
Expand All @@ -30,13 +30,16 @@ typedef enum {
ETHX_CLAIM,
ETHX_DEPOSIT_LEGACY,
ETHX_REQUEST_WITHDRAW_LEGACY,
ETHX_BOOST_REWARDS_CLAIM,
} selector_t;

// Enumeration used to parse the smart contract data.
typedef enum {
STAKE_AMOUNT = 0,
UNSTAKE_AMOUNT,
TOKEN_AMOUNT,
ACCOUNT_ADDR,
UNUSED_PARAM,
UNEXPECTED_PARAMETER,
} parameter;

Expand All @@ -45,16 +48,16 @@ extern const uint32_t STADERLABS_SELECTORS[NUM_SELECTORS];
// Shared global memory with Ethereum app. Must be at most 5 * 32 bytes.
typedef struct context_t {
// For display.
uint8_t amount_received[INT256_LENGTH];
const char *ticker;
uint8_t account_addr[ADDRESS_LENGTH];
uint8_t amount_received[INT256_LENGTH]; // 32 bytes
const char *ticker; // 8 bytes
uint8_t account_addr[ADDRESS_LENGTH]; // 20 bytes

// For parsing data.
uint8_t next_param; // Set to be the next param we expect to parse.
bool skip_next_param; // flag to skip next param while parsing.
uint8_t next_param; // Set to be the next param we expect to parse. // 1 byte
bool skip_next_param; // flag to skip next param while parsing. // 1 byte

// For both parsing and display.
selector_t selectorIndex;
selector_t selectorIndex; // 8 bytes
} context_t;

// Piece of code that will check that the above structure is not bigger than 5 * 32. Do not remove
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "token_",
"type": "address"
},
{
"internalType": "bytes32",
"name": "merkleRoot_",
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "account",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Claimed",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
},
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "bytes32[]",
"name": "merkleProof",
"type": "bytes32[]"
}
],
"name": "claim",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "isClaimed",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "merkleRoot",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "token",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]
Loading
Loading