Skip to content

Commit

Permalink
Support/filecoin evm (#7414)
Browse files Browse the repository at this point in the history
* feat(fil): add erc20 tokens data for filecoin

* chore(fil): add token icons and remove staked tokens

* refac(fil): update logic and minor updates to dependencies

* chore(fil): update logic post refac

* tests(fil): update bot tests

* refac(fil): fixup operation and increase bot tests timeout

* chore(fil): bump iso-filecoin

* feat(fil): use importer for erc20 tokens

* refac(fil): update ifil svg icon

* refac(fil): add recipient address when using 0xff

* refac(fil): deviceTransactionConfig updates

* fix: rework estimate fees for token transfer

* refac(fil): lowercase recipient always

* refac(fil): drop network call for address convert

* refactor: rework functions to make them cleaner

* refac(fil): fix error when estimating fee with wrong params

* refac(fil): fix wrong recipient on confirmation screen

* refac(fil): fix problem with estimating gas

* fix: remove leading 0x for eth addresses

* feat: handle hasFailed flag from erc20 txs sync

* fix(fil): irrelevant error on feeEstimationFail

* refac(fil): update type of fees transfers

* fix(fil): estimateMaxSpendable failing for native transfer

* fix(fil): sort operations on sync

* fix: update snapshots

* fix(icp): estimatedSpendable and transactionStatus

* fix: unit test

* fix: update sortByMarketcap unit test snapshot

---------

Co-authored-by: Prateek Rathod <[email protected]>
Co-authored-by: emmanuelm41 <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2024
1 parent a3fbf6d commit 5758950
Show file tree
Hide file tree
Showing 41 changed files with 1,588 additions and 240 deletions.
9 changes: 9 additions & 0 deletions .changeset/famous-worms-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ledgerhq/cryptoassets": minor
"ledger-live-desktop": minor
"live-mobile": minor
"@ledgerhq/live-common": minor
"@ledgerhq/live-env": minor
---

Add ERC20 token support for filecoin
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const fieldComponents = {
"filecoin.gasPremium": FilecoinField,
"filecoin.gasLimit": FilecoinField,
"filecoin.method": FilecoinField,
"filecoin.recipient": FilecoinField,
};
export default {
fieldComponents,
Expand Down
7 changes: 7 additions & 0 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5569,6 +5569,13 @@
"title": "Impossible to calculate amount and fees",
"description": "Impossible to calculate amount and fees"
},
"InvalidRecipientForTokenTransfer": {
"title": "Invalid recipient for token transfer, supported account types for token transfer: [f0, f4, 0x]"
},
"FilecoinFeeEstimationFailed": {
"title": "Sorry, fee estimation failed",
"description": "Fee estimation failed on the network. Check inputs, transaction most likely to fail"
},
"NotEnoughBalance": {
"title": "Sorry, insufficient funds",
"description": "Please make sure the account has enough funds."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const fieldComponents = {
"filecoin.gasPremium": FilecoinField,
"filecoin.gasLimit": FilecoinField,
"filecoin.method": FilecoinField,
"filecoin.recipient": FilecoinField,
};
export default {
fieldComponents,
Expand Down
7 changes: 7 additions & 0 deletions apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,13 @@
"InvalidMemoICP": {
"title": "Memo is required to be a number"
},
"InvalidRecipientForTokenTransfer": {
"title": "Invalid recipient for token transfer, supported account types for token transfer: [f0, f4, 0x]"
},
"FilecoinFeeEstimationFailed": {
"title": "Sorry, fee estimation failed",
"description": "Fee estimation failed on the network. Check inputs, transaction most likely to fail"
},
"FirmwareNotRecognized": {
"title": "Invalid Provider",
"description": "You have to change \"My Ledger provider\" setting. To change it, open Ledger Live \"Settings\", select \"Experimental features\", and then select a different provider."
Expand Down
3 changes: 2 additions & 1 deletion libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@
"cosmjs-types": "0.2.1",
"date-fns": "^2.23.0",
"eip55": "^2.1.1",
"ethers": "5.7.2",
"expect": "^27.4.6",
"fuse.js": "^6.6.2",
"invariant": "^2.2.2",
"iso-filecoin": "^4.0.3",
"iso-filecoin": "^4.1.0",
"isomorphic-ws": "^4.0.1",
"jotai": "^2.7.0",
"json-rpc-2.0": "^0.2.19",
Expand Down
3 changes: 3 additions & 0 deletions libs/ledger-live-common/src/__tests__/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ test("erc20 are all consistent with those on ledgerjs side", () => {
}

if (token.tokenType === "erc20") {
if (token.parentCurrency.family === "filecoin") {
continue;
}
const tokenData = byContractAddressAndChainId(
token.contractAddress,
token.parentCurrency.ethereumLikeInfo?.chainId || 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ exports[`sortCurrenciesByIds snapshot 1`] = `
"ethereum/erc20/lambda",
"ethereum/erc20/dent",
"ethereum/erc20/odem_token",
"filecoin/erc20/securitized_filecoin_token",
"ethereum/erc20/elitium",
"ethereum/erc20/anchor",
"ethereum/erc20/arcblock_token",
Expand Down Expand Up @@ -11027,6 +11028,13 @@ exports[`sortCurrenciesByIds snapshot 1`] = `
"polygon/erc20/zrx",
"polygon/erc20/zurf",
"polygon/erc20/zurf_f91e",
"filecoin/erc20/axelar_wrapped_usdc",
"filecoin/erc20/collectif_staked_fil",
"filecoin/erc20/infinity_pool_staked_fil",
"filecoin/erc20/node_fil",
"filecoin/erc20/pfil_token",
"filecoin/erc20/wrapped_fil",
"filecoin/erc20/wrapped_pfil_token",
"tron/trc10/1002670",
"tron/trc10/1001943",
"tron/trc10/1001351",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`filecoin currency bridge scanAccounts filecoin seed 1 1`] = `
[
{
"balance": "1000000000000000",
"currencyId": "filecoin",
"derivationMode": "glifLegacy",
"freshAddress": "t15lauyzdivqj7m3yob3rxmzdsy7uyhfflwyheuri",
"freshAddressPath": "44'/1'/0'/0/0",
"id": "js:2:filecoin:t15lauyzdivqj7m3yob3rxmzdsy7uyhfflwyheuri:glifLegacy",
"index": 0,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "1000000000000000",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": true,
},
{
"balance": "100000000000000000",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a",
"freshAddressPath": "44'/461'/0'/0/0",
"id": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:glif",
"index": 0,
"operationsCount": 1,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "100000000000000000",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": true,
},
{
"balance": "10000000000000000",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia",
"freshAddressPath": "44'/461'/0'/0/1",
"id": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif",
"index": 1,
"operationsCount": 1,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "10000000000000000",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": true,
},
{
"balance": "12340000000000000",
"id": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif+filecoin%2Ferc20%2Fwrapped~!underscore!~fil",
"operationsCount": 1,
"parentId": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif",
"pendingOperations": [],
"spendableBalance": "12340000000000000",
"swapHistory": [],
"tokenId": "filecoin/erc20/wrapped_fil",
"type": "TokenAccountRaw",
},
{
"balance": "0",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f15nh4cywefp6pavzjifbe2ormma74malwdyy5rfq",
"freshAddressPath": "44'/461'/0'/0/2",
"id": "js:2:filecoin:f15nh4cywefp6pavzjifbe2ormma74malwdyy5rfq:glif",
"index": 2,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "0",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": false,
},
{
"balance": "0",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1lg3347otxjblwqx6pnqnqoz4cqwasq57yo2bxcy",
"freshAddressPath": "44'/461'/0'/0/3",
"id": "js:2:filecoin:f1lg3347otxjblwqx6pnqnqoz4cqwasq57yo2bxcy:glif",
"index": 3,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "0",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": false,
},
{
"balance": "0",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1j2uoeuoiusmh2godly4fivd6gomi6asmzkd47li",
"freshAddressPath": "44'/461'/0'/0/4",
"id": "js:2:filecoin:f1j2uoeuoiusmh2godly4fivd6gomi6asmzkd47li:glif",
"index": 4,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "0",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": false,
},
{
"balance": "0",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1l7h6nvobmqc7adq7plta5kn7xaltx6k6l7paqsq",
"freshAddressPath": "44'/461'/0'/0/5",
"id": "js:2:filecoin:f1l7h6nvobmqc7adq7plta5kn7xaltx6k6l7paqsq:glif",
"index": 5,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "0",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": false,
},
{
"balance": "0",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1i2drwsilv35pp75dvd52enl3ohqakua2mshf5fy",
"freshAddressPath": "44'/461'/0'/0/6",
"id": "js:2:filecoin:f1i2drwsilv35pp75dvd52enl3ohqakua2mshf5fy:glif",
"index": 6,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "0",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": false,
},
{
"balance": "0",
"currencyId": "filecoin",
"derivationMode": "glif",
"freshAddress": "f1347zfz7jiz3oeufp2lrbcwwt265ejk32n2wqrla",
"freshAddressPath": "44'/461'/0'/0/7",
"id": "js:2:filecoin:f1347zfz7jiz3oeufp2lrbcwwt265ejk32n2wqrla:glif",
"index": 7,
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
"spendableBalance": "0",
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
"used": false,
},
]
`;

exports[`filecoin currency bridge scanAccounts filecoin seed 1 2`] = `
[
[],
[
{
"accountId": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:glif",
"blockHash": null,
"blockHeight": 1802367,
"extra": {},
"fee": "0",
"hasFailed": false,
"hash": "bafy2bzaceaztepnzdzbul7nmkef6blk5x2luvbvangrjal25k6xi5qob36k32",
"id": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:glif-bafy2bzaceaztepnzdzbul7nmkef6blk5x2luvbvangrjal25k6xi5qob36k32-IN",
"recipients": [
"f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a",
],
"senders": [
"f1ov6d42tujoyexkbdh34oik2vhe5unqo2a5ocqoq",
],
"type": "IN",
"value": "100000000000000000",
},
],
[
{
"accountId": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif",
"blockHash": null,
"blockHeight": 3853241,
"extra": {},
"fee": "0",
"hasFailed": false,
"hash": "bafy2bzacecwvvvxtlbm5s6wpk546r66hjqw4amjioihe2rt5ufoebu3zv6xiw",
"id": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif-bafy2bzacecwvvvxtlbm5s6wpk546r66hjqw4amjioihe2rt5ufoebu3zv6xiw-IN",
"recipients": [
"f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia",
],
"senders": [
"f1ovlkmtnqji7wrvdpcys3i22c62obbamgokmg35q",
],
"type": "IN",
"value": "10000000000000000",
},
],
[
{
"accountId": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif+filecoin%2Ferc20%2Fwrapped~!underscore!~fil",
"blockHash": "",
"blockHeight": 3853248,
"extra": {},
"fee": "0",
"hasFailed": false,
"hash": "bafy2bzaceaw6jxm3bp6rdvtse7k4evsg2zhis3ootn2pe5k3txtxor4efhl7k",
"id": "js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:glif+filecoin%2Ferc20%2Fwrapped~!underscore!~fil-bafy2bzaceaw6jxm3bp6rdvtse7k4evsg2zhis3ootn2pe5k3txtxor4efhl7k-IN",
"recipients": [
"f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia",
],
"senders": [
"f1pnc33cba2c2a3olqadho7wiohyosbkl3upescei",
],
"type": "IN",
"value": "12340000000000000",
},
],
[],
[],
[],
[],
[],
[],
]
`;
Loading

0 comments on commit 5758950

Please sign in to comment.