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

Kelp withdrawals (#32) #22

Merged
merged 2 commits into from
Aug 8, 2024
Merged
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ APPNAME = "Staderlabs"

# Application version
APPVERSION_M = 1
APPVERSION_N = 1
APPVERSION_P = 3
APPVERSION_N = 2
APPVERSION_P = 0

include ethereum-plugin-sdk/standard_plugin.mk
19 changes: 4 additions & 15 deletions PLUGIN_SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ Functions covered by above contract/s :
|StakeManager | requestWithdraw(uint256 \_amountInBnbX) | `0x745400c9`| `_amountInBnbX` |
|StakeManager | claimWithdraw(uint256 \_idx) | `0xb13acedd`| |

#### FTMx

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

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

| Network | Contract Name | Smart Contract |
Expand All @@ -60,17 +47,19 @@ Functions covered by above contract/s :
|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` |

#### KELP

| Network | Contract Name | Smart Contract |
| ------- | ------------- | -------------------------------------------- |
| Ethereum | LRTDepositPool | `0x036676389e48133B63a802f8635AD39E752D375D` |
| Ethereum | LRTWithdrawalManager | `0x62de59c08eb5dae4b7e6f7a8cad3006d6965ec16` |


Functions covered by above contract/s :
|Contract | Function | Selector | Displayed Parameters |
| --- | --- | --- | --- |
|LRTDepositPool | depositETH(uint256 minRSETHAmountExpected, string calldata referralId) | `0x72c51c0b`| native_token_amount (eth) |
|LRTDepositPool | depositAsset(address asset, uint256 depositAmount, uint256 minRSETHAmountExpected, string calldata referralId) | `0xc3ae1766`| `asset`, `depositAmount` |
|LRTWithdrawalManager | initiateWithdrawal(address asset, uint256 rsETHUnstaked) | `0xc8393ba9`| `asset`, `rsETHUnstaked` |
|LRTWithdrawalManager | completeWithdrawal(address asset) | `0x6dbaf9ee`| `asset` |
8 changes: 6 additions & 2 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ void handle_finalize(ethPluginFinalize_t *msg) {

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

case KELP_LST_DEPOSIT:
case KELP_CLAIM_WITHDRAW:
msg->numScreens = 1;
msg->tokenLookup1 = context->token_addr;
break;

case KELP_INITIATE_WITHDRAW:
msg->numScreens = 2;
msg->tokenLookup1 = context->token_addr;
break;

default:
msg->numScreens = 1;
break;
Expand Down
24 changes: 10 additions & 14 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
// 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;
break;

case ETHX_REQUEST_WITHDRAW_LEGACY:
case ETHX_REQUEST_WITHDRAW:
context->next_param = UNSTAKE_AMOUNT;
strlcpy(context->ticker, "ETHX", sizeof(context->ticker));
Expand All @@ -67,7 +65,6 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
break;

case BSC_STAKEMANAGER_DEPOSIT:
// case FTM_DEPOSIT: // the selector matches with `BSC_STAKEMANAGER_DEPOSIT`
context->next_param = UNEXPECTED_PARAMETER;
break;

Expand All @@ -79,12 +76,6 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
strlcpy(context->ticker, "MATICX", sizeof(context->ticker));
break;

case FTM_UNDELEGATE:
context->next_param = UNSTAKE_AMOUNT;
strlcpy(context->ticker, "FTMX", sizeof(context->ticker));
context->skip_next_param = true;
break;

case ETH_MATICX_CLAIM_WITHDRAWAL:
case POLYGON_CHILDPOOL_CLAIM_MATICX_SWAP:
context->next_param = UNEXPECTED_PARAMETER;
Expand All @@ -96,11 +87,6 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
strlcpy(context->ticker, "BNB", sizeof(context->ticker));
break;

case FTM_WITHDRAW:
context->next_param = UNEXPECTED_PARAMETER;
strlcpy(context->ticker, "FTM", sizeof(context->ticker));
break;

case KELP_LST_DEPOSIT:
context->next_param = TOKEN_ADDR;
break;
Expand All @@ -109,6 +95,16 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
context->next_param = UNEXPECTED_PARAMETER;
break;

case KELP_INITIATE_WITHDRAW:
context->next_param = TOKEN_ADDR;
strlcpy(context->ticker, "ETH", sizeof(context->ticker));
break;

case KELP_CLAIM_WITHDRAW:
context->next_param = TOKEN_ADDR;
strlcpy(context->ticker, "ETH", sizeof(context->ticker));
break;

// Keep this
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
Expand Down
39 changes: 27 additions & 12 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ static void handle_stake(ethPluginProvideParameter_t *msg, context_t *context) {
}

static void handle_unstake(ethPluginProvideParameter_t *msg, context_t *context) {
if (context->skip_next_param) { // this is currently only useful in ftm_undelegate
context->skip_next_param = false;
return;
}

switch (context->next_param) {
case UNSTAKE_AMOUNT:
handle_amount_received(msg, context);
Expand Down Expand Up @@ -110,6 +105,23 @@ static void handle_kelp_lst_deposit(ethPluginProvideParameter_t *msg, context_t
break;
}
}

static void handle_kelp_initiate_withdraw(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case TOKEN_ADDR:
copy_address(context->token_addr, msg->parameter, sizeof(context->token_addr));
context->next_param = UNSTAKE_AMOUNT;
break;
case UNSTAKE_AMOUNT:
handle_amount_received(msg, context);
context->next_param = UNEXPECTED_PARAMETER;
break;
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 All @@ -124,12 +136,10 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {

// 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 All @@ -138,11 +148,10 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
handle_stake(msg, context);
break;

case ETH_MATICX_REQUEST_WITHDRAW:
case POLYGON_CHILDPOOL_REQUEST_MATICX_SWAP:
// case BSC_STAKEMANAGER_REQUEST_WITHDRAW:
// the selector matches with `ETH_MATICX_REQUEST_WITHDRAW`
case FTM_UNDELEGATE:
case ETH_MATICX_REQUEST_WITHDRAW:
case POLYGON_CHILDPOOL_REQUEST_MATICX_SWAP:
handle_unstake(msg, context);
break;

Expand All @@ -152,14 +161,20 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
case POLYGON_CHILDPOOL_SWAP_MATIC_FOR_MATICX_VIA_INSTANT_POOL:
case POLYGON_CHILDPOOL_CLAIM_MATICX_SWAP:
case BSC_STAKEMANAGER_DEPOSIT:
// case FTM_DEPOSIT: // the selector matches with `BSC_STAKEMANAGER_DEPOSIT`
case BSC_STAKEMANAGER_CLAIM_WITHDRAW:
case FTM_WITHDRAW:
context->next_param = UNEXPECTED_PARAMETER;
break;
case KELP_LST_DEPOSIT:
handle_kelp_lst_deposit(msg, context);
break;
case KELP_INITIATE_WITHDRAW:
handle_kelp_initiate_withdraw(msg, context);
break;

case KELP_CLAIM_WITHDRAW:
copy_address(context->token_addr, msg->parameter, sizeof(context->token_addr));
context->next_param = UNEXPECTED_PARAMETER;
break;

default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
Expand Down
2 changes: 2 additions & 0 deletions src/handle_provide_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
void handle_provide_token(ethPluginProvideInfo_t *msg) {
context_t *context = (context_t *) msg->pluginContext;

// FOR KELP_INITIATE_WITHDRAW, assign the ticker if available,
// else it will be ETH, already set during init_contract
if (msg->item1) {
strlcpy(context->ticker, (char *) msg->item1->token.ticker, sizeof(context->ticker));
}
Expand Down
19 changes: 12 additions & 7 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,24 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
// 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 FTM_DEPOSIT: // the selector matches with `BSC_STAKEMANAGER_DEPOSIT`
case BSC_STAKEMANAGER_DEPOSIT:
msgVersion = "Stake";
break;

// case BSC_STAKEMANAGER_REQUEST_WITHDRAW:
// the selector matches with `ETH_MATICX_REQUEST_WITHDRAW`
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:
// the selector matches with `ETH_MATICX_REQUEST_WITHDRAW`
case FTM_UNDELEGATE:
msgVersion = "Unstake";
break;

case ETHX_CLAIM:
case ETH_MATICX_CLAIM_WITHDRAWAL:
case POLYGON_CHILDPOOL_CLAIM_MATICX_SWAP:
case BSC_STAKEMANAGER_CLAIM_WITHDRAW:
case FTM_WITHDRAW:
msgVersion = "Claim";
break;

Expand All @@ -48,6 +43,16 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
msgVersion = "Native Restake";
break;

case KELP_INITIATE_WITHDRAW:
strlcpy(msg->name, "Kelp", msg->nameLength);
msgVersion = "Unstake";
break;

case KELP_CLAIM_WITHDRAW:
strlcpy(msg->name, "Kelp", msg->nameLength);
msgVersion = "Claim";
break;

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

static bool handle_kelp_initiate_withdraw(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:
strlcpy(msg->title, "Unstake", msg->titleLength);
ret = amountToString(context->amount_received,
sizeof(context->amount_received),
WEI_TO_ETHER,
"RSETH",
msg->msg,
msg->msgLength);
break;

case 1:
strlcpy(msg->title, "Asset Expected", msg->titleLength);
strlcpy(msg->msg, context->ticker, msg->msgLength);
ret = true;
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 All @@ -125,39 +154,39 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
ret = set_stake_ui(msg, context);
break;

case ETH_MATICX_REQUEST_WITHDRAW:
case POLYGON_CHILDPOOL_REQUEST_MATICX_SWAP:
// case BSC_STAKEMANAGER_REQUEST_WITHDRAW:
// the selector matches with `ETH_MATICX_REQUEST_WITHDRAW`
case FTM_UNDELEGATE:
case ETH_MATICX_REQUEST_WITHDRAW:
case POLYGON_CHILDPOOL_REQUEST_MATICX_SWAP:
ret = set_unstake_ui(msg, context);
break;

case ETHX_CLAIM:
case ETH_MATICX_CLAIM_WITHDRAWAL:
case POLYGON_CHILDPOOL_CLAIM_MATICX_SWAP:
case BSC_STAKEMANAGER_CLAIM_WITHDRAW:
case FTM_WITHDRAW:
case KELP_CLAIM_WITHDRAW:
ret = set_claim_ui(msg, context);
break;

case KELP_ETH_DEPOSIT:
case POLYGON_CHILDPOOL_SWAP_MATIC_FOR_MATICX_VIA_INSTANT_POOL:
// case FTM_DEPOSIT: // the selector matches with `BSC_STAKEMANAGER_DEPOSIT`
case BSC_STAKEMANAGER_DEPOSIT:
ret = set_native_token_stake_ui(msg);
break;

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

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

case KELP_INITIATE_WITHDRAW:
ret = handle_kelp_initiate_withdraw(msg, context);
break;

default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
}
Expand Down
9 changes: 3 additions & 6 deletions src/staderlabs_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@
X(BSC_STAKEMANAGER_DEPOSIT, 0xd0e30db0) \
X(BSC_STAKEMANAGER_REQUEST_WITHDRAW, 0x745400c9) \
X(BSC_STAKEMANAGER_CLAIM_WITHDRAW, 0xb13acedd) \
X(FTM_DEPOSIT, 0xd0e30db0) \
X(FTM_UNDELEGATE, 0x4f864df4) \
X(FTM_WITHDRAW, 0x441a3e70) \
X(ETHX_DEPOSIT, 0xb7482509) \
X(ETHX_REQUEST_WITHDRAW, 0x1f7ec122) \
X(ETHX_CLAIM, 0x379607f5) \
X(ETHX_DEPOSIT_LEGACY, 0xf340fa01) \
X(ETHX_REQUEST_WITHDRAW_LEGACY, 0xccc143b8) \
X(KELP_LST_DEPOSIT, 0xc3ae1766) \
X(KELP_ETH_DEPOSIT, 0x72c51c0b)
X(KELP_ETH_DEPOSIT, 0x72c51c0b) \
X(KELP_INITIATE_WITHDRAW, 0xc8393ba9) \
X(KELP_CLAIM_WITHDRAW, 0x6dbaf9ee)

// Xmacro helpers to define the enum and map
// Do not modify !
Expand Down
Loading
Loading