Skip to content

Commit 06844eb

Browse files
authored
Merge pull request #341 from keepkey/add-top-evm-networks
add op, bnb, matic, xdai chain support
2 parents 28a8669 + 7793e92 commit 06844eb

File tree

4 files changed

+117
-77
lines changed

4 files changed

+117
-77
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.7.2)
22

33
project(
44
KeepKeyFirmware
5-
VERSION 7.7.0
5+
VERSION 7.8.0
66
LANGUAGES C CXX ASM)
77

88
set(BOOTLOADER_MAJOR_VERSION 2)

lib/firmware/ethereum.c

+16-25
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,12 @@ void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
337337
case 2:
338338
suffix = " EXP";
339339
break; // Expanse
340-
case 3:
341-
suffix = " tROP";
342-
break; // Ethereum Testnet Ropsten
343-
case 4:
344-
suffix = " tRIN";
345-
break; // Ethereum Testnet Rinkeby
346340
case 8:
347341
suffix = " UBQ";
348342
break; // UBIQ
343+
case 10:
344+
suffix = " OP";
345+
break; // Optimism
349346
case 20:
350347
suffix = " EOSC";
351348
break; // EOS Classic
@@ -354,31 +351,25 @@ void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
354351
break; // Ethereum Social
355352
case 30:
356353
suffix = " RBTC";
357-
break; // RSK
358-
case 31:
359-
suffix = " tRBTC";
360-
break; // RSK Testnet
361-
case 42:
362-
suffix = " tKOV";
363-
break; // Ethereum Testnet Kovan
354+
break; // Rootstock
355+
case 40:
356+
suffix = " TLOS";
357+
break; // Telos
358+
case 56:
359+
suffix = " BNB";
360+
break; // BNB Chain
364361
case 61:
365362
suffix = " ETC";
366363
break; // Ethereum Classic
367-
case 62:
368-
suffix = " tETC";
369-
break; // Ethereum Classic Testnet
370364
case 64:
371365
suffix = " ELLA";
372366
break; // Ellaism
373-
case 820:
374-
suffix = " CLO";
375-
break; // Callisto
376-
case 1987:
377-
suffix = " EGEM";
378-
break; // EtherGem
379-
default:
380-
suffix = " UNKN";
381-
break; // unknown chain
367+
case 100:
368+
suffix = " xDAI";
369+
break; // Gnosis Chain
370+
case 137:
371+
suffix = " MATIC";
372+
break; // Polygon Mainnet
382373
}
383374
}
384375
}

lib/firmware/fsm_msg_osmosis.h

+99-50
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) {
120120
}
121121

122122
void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
123-
// Confirm transaction basics
123+
/** Confirm transaction basics */
124124
CHECK_PARAM(osmosis_signingIsInited(), "Signing not in progress");
125125

126126
const CoinType *coin = fsm_getCoin(true, "Osmosis");
@@ -130,6 +130,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
130130

131131
const OsmosisSignTx *sign_tx = osmosis_getOsmosisSignTx();
132132

133+
/** Confirm required transaction parameters exist */
133134
if (msg->has_send) {
134135
if (!msg->send.has_to_address || !msg->send.has_amount) {
135136
osmosis_signAbort();
@@ -139,9 +140,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
139140
return;
140141
}
141142

142-
char amount_str[40];
143-
sprintf(amount_str, "%.6f OSMO",
144-
atof(msg->send.amount) / pow(10, OSMOSIS_PRECISION));
143+
float amount = atof(msg->send.amount);
144+
const char *denom = msg->send.denom;
145+
if (!strcmp(msg->send.denom, "uosmo")) {
146+
amount /= pow(10, OSMOSIS_PRECISION);
147+
denom = "OSMO";
148+
}
149+
150+
char amount_str[103];
151+
snprintf(amount_str, sizeof(amount_str) - 1, "%.6f %s", amount, denom);
152+
153+
/** Confirm transaction parameters on screen */
145154
if (!confirm_transaction_output(
146155
ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str,
147156
msg->send.to_address)) {
@@ -169,6 +178,14 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
169178
layoutHome();
170179
return;
171180
}
181+
182+
float amount = atof(msg->delegate.amount);
183+
const char *denom = msg->delegate.denom;
184+
if (!strcmp(msg->delegate.denom, "uosmo")) {
185+
amount /= pow(10, OSMOSIS_PRECISION);
186+
denom = "OSMO";
187+
}
188+
172189
/** Confirm transaction parameters on-screen */
173190
if (!confirm_osmosis_address("Confirm Delegator Address",
174191
msg->delegate.delegator_address)) {
@@ -187,8 +204,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
187204
}
188205

189206
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Amount",
190-
"%.6f OSMO",
191-
atof(msg->delegate.amount) / pow(10, OSMOSIS_PRECISION))) {
207+
"%.6f %s", amount, denom)) {
192208
osmosis_signAbort();
193209
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
194210
layoutHome();
@@ -214,8 +230,15 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
214230
layoutHome();
215231
return;
216232
}
217-
/** Confirm transaction parameters on-screen */
218233

234+
float amount = atof(msg->undelegate.amount);
235+
const char *denom = msg->undelegate.denom;
236+
if (!strcmp(msg->undelegate.denom, "uosmo")) {
237+
amount /= pow(10, OSMOSIS_PRECISION);
238+
denom = "OSMO";
239+
}
240+
241+
/** Confirm transaction parameters on-screen */
219242
if (!confirm_osmosis_address("Confirm Delegator Address",
220243
msg->undelegate.delegator_address)) {
221244
osmosis_signAbort();
@@ -233,8 +256,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
233256
}
234257

235258
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Amount",
236-
"%.6f OSMO",
237-
atof(msg->undelegate.amount) / pow(10, OSMOSIS_PRECISION))) {
259+
"%.6f %s", amount, denom)) {
238260
osmosis_signAbort();
239261
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
240262
layoutHome();
@@ -263,7 +285,6 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
263285
return;
264286
}
265287

266-
/** Confirm transaction parameters on-screen */
267288
char insoamt[33] = {0};
268289
uint8_t outsoamt[34] = {0};
269290
strlcpy(insoamt, msg->lp_add.share_out_amount,
@@ -277,24 +298,31 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
277298
return;
278299
}
279300

301+
float amount_in_max_b = atof(msg->lp_add.amount_in_max_b);
302+
const char *denom_in_max_b = msg->lp_add.denom_in_max_b;
303+
if (!strcmp(msg->lp_add.denom_in_max_b, "uosmo")) {
304+
amount_in_max_b /= pow(10, OSMOSIS_PRECISION);
305+
denom_in_max_b = "OSMO";
306+
}
307+
308+
float amount_in_max_a = atof(msg->lp_add.amount_in_max_a);
309+
const char *denom_in_max_a = msg->lp_add.denom_in_max_a;
310+
if (!strcmp(msg->lp_add.denom_in_max_a, "uosmo")) {
311+
amount_in_max_a /= pow(10, OSMOSIS_PRECISION);
312+
denom_in_max_a = "OSMO";
313+
}
314+
315+
/** Confirm transaction parameters on-screen */
280316
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity",
281-
"Deposit %.6f %s and...",
282-
atof(msg->lp_add.amount_in_max_b) / pow(10, OSMOSIS_PRECISION),
283-
(!strcmp(msg->lp_add.denom_in_max_b, "uosmo"))
284-
? "OSMO"
285-
: msg->lp_add.denom_in_max_b)) {
317+
"Deposit %.6f %s and...", amount_in_max_b, denom_in_max_b)) {
286318
osmosis_signAbort();
287319
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
288320
layoutHome();
289321
return;
290322
}
291323

292324
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity",
293-
"... %.6f %s?",
294-
atof(msg->lp_add.amount_in_max_a) / pow(10, OSMOSIS_PRECISION),
295-
(!strcmp(msg->lp_add.denom_in_max_a, "uosmo"))
296-
? "OSMO"
297-
: msg->lp_add.denom_in_max_a)) {
325+
"... %.6f %s?", amount_in_max_a, denom_in_max_a)) {
298326
osmosis_signAbort();
299327
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
300328
layoutHome();
@@ -344,7 +372,6 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
344372
return;
345373
}
346374

347-
/** Confirm transaction parameters on-screen */
348375
char insoamt[33] = {0};
349376
uint8_t outsoamt[34] = {0};
350377
strlcpy(insoamt, msg->lp_remove.share_in_amount,
@@ -358,26 +385,32 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
358385
return;
359386
}
360387

361-
if (!confirm(
362-
ButtonRequestType_ButtonRequest_Other, "Remove Liquidity",
363-
"Withdraw %.6f %s and...",
364-
atof(msg->lp_remove.amount_out_min_b) / pow(10, OSMOSIS_PRECISION),
365-
(!strcmp(msg->lp_remove.denom_out_min_b, "uosmo"))
366-
? "OSMO"
367-
: msg->lp_remove.denom_out_min_b)) {
388+
float amount_out_min_b = atof(msg->lp_remove.amount_out_min_b);
389+
const char *denom_out_min_b = msg->lp_remove.denom_out_min_b;
390+
if (!strcmp(msg->lp_remove.denom_out_min_b, "uosmo")) {
391+
amount_out_min_b /= pow(10, OSMOSIS_PRECISION);
392+
denom_out_min_b = "OSMO";
393+
}
394+
395+
float amount_out_min_a = atof(msg->lp_remove.amount_out_min_a);
396+
const char *denom_out_min_a = msg->lp_remove.denom_out_min_a;
397+
if (!strcmp(msg->lp_remove.denom_out_min_a, "uosmo")) {
398+
amount_out_min_a /= pow(10, OSMOSIS_PRECISION);
399+
denom_out_min_a = "OSMO";
400+
}
401+
402+
/** Confirm transaction parameters on-screen */
403+
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity",
404+
"Withdraw %.6f %s and...", amount_out_min_b,
405+
denom_out_min_b)) {
368406
osmosis_signAbort();
369407
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
370408
layoutHome();
371409
return;
372410
}
373411

374-
if (!confirm(
375-
ButtonRequestType_ButtonRequest_Other, "Remove Liquidity",
376-
"... %.6f %s ?",
377-
atof(msg->lp_remove.amount_out_min_a) / pow(10, OSMOSIS_PRECISION),
378-
(!strcmp(msg->lp_remove.denom_out_min_a, "uosmo"))
379-
? "OSMO"
380-
: msg->lp_remove.denom_out_min_a)) {
412+
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity",
413+
"... %.6f %s ?", amount_out_min_a, denom_out_min_a)) {
381414
osmosis_signAbort();
382415
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
383416
layoutHome();
@@ -424,11 +457,12 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
424457
layoutHome();
425458
return;
426459
}
427-
/** Confirm transaction parameters on-screen */
428460

461+
float amount = atof(msg->redelegate.amount) / pow(10, OSMOSIS_PRECISION);
462+
463+
/** Confirm transaction parameters on-screen */
429464
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate",
430-
"Redelegate %.6f OSMO?",
431-
atof(msg->send.amount) / pow(10, OSMOSIS_PRECISION))) {
465+
"Redelegate %.6f OSMO?", amount)) {
432466
osmosis_signAbort();
433467
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
434468
layoutHome();
@@ -480,6 +514,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
480514
return;
481515
}
482516

517+
/** Confirm transaction parameters on-screen */
483518
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards",
484519
"Claim all available rewards?")) {
485520
osmosis_signAbort();
@@ -525,15 +560,24 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
525560
return;
526561
}
527562

528-
/** Confirm transaction parameters on-screen */
563+
float token_in_amount = atof(msg->swap.token_in_amount);
564+
const char *token_in_denom = msg->swap.token_in_denom;
565+
if (!strcmp(msg->swap.token_in_denom, "uosmo")) {
566+
token_in_amount /= pow(10, OSMOSIS_PRECISION);
567+
token_in_denom = "OSMO";
568+
}
569+
570+
float token_out_min_amount = atof(msg->swap.token_out_min_amount);
571+
const char *token_out_denom = msg->swap.token_out_denom;
572+
if (!strcmp(msg->swap.token_out_denom, "uosmo")) {
573+
token_out_min_amount /= pow(10, OSMOSIS_PRECISION);
574+
token_out_denom = "OSMO";
575+
}
529576

530-
if (!confirm(
531-
ButtonRequestType_ButtonRequest_Other, "Swap",
532-
"Swap %.6f %s for at least %.6f %s?",
533-
atof(msg->swap.token_in_amount) / pow(10, OSMOSIS_PRECISION),
534-
msg->swap.token_in_denom,
535-
atof(msg->swap.token_out_min_amount) / pow(10, OSMOSIS_PRECISION),
536-
msg->swap.token_out_denom)) {
577+
/** Confirm transaction parameters on-screen */
578+
if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap",
579+
"Swap %.6f %s for at least %.6f %s?", token_in_amount,
580+
token_in_denom, token_out_min_amount, token_out_denom)) {
537581
osmosis_signAbort();
538582
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
539583
layoutHome();
@@ -573,12 +617,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) {
573617
layoutHome();
574618
return;
575619
}
576-
/** Confirm transaction parameters on-screen */
577620

621+
float amount = atof(msg->ibc_transfer.amount);
622+
const char *denom = msg->ibc_transfer.denom;
623+
if (!strcmp(msg->ibc_transfer.denom, "uosmo")) {
624+
amount /= pow(10, OSMOSIS_PRECISION);
625+
denom = "OSMO";
626+
}
627+
628+
/** Confirm transaction parameters on-screen */
578629
if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer",
579-
"Transfer %.6f %s?",
580-
atof(msg->ibc_transfer.amount) / pow(10, OSMOSIS_PRECISION),
581-
msg->ibc_transfer.denom)) {
630+
"Transfer %.6f %s?", amount, denom)) {
582631
osmosis_signAbort();
583632
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
584633
layoutHome();

0 commit comments

Comments
 (0)