Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Elrond ESDT tokens & EGLD staking integration #1585

Open
wants to merge 174 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
76ee01a
Integrate Elrond in Ledger families
Jun 21, 2021
75dad61
Serialize specific resources for Elrond family
Jun 21, 2021
05aff5d
Reconciliate specific resources for Elrond family
Jun 21, 2021
695e6c5
Elrond mainnet api for interactions
Jun 21, 2021
58a2939
Set elrond as supported currency
Jun 21, 2021
5b719c3
Merge pull request #1 from pislaProgramming/integrate
AlexandruPislariu Jun 21, 2021
341793d
Revert "Integrate"
AlexandruPislariu Jun 22, 2021
5af312f
Merge pull request #2 from ElrondNetwork/revert-1-integrate
AlexandruPislariu Jun 22, 2021
62975f0
Revert "Revert "Integrate""
AlexandruPislariu Jun 22, 2021
63404a5
Incremental synchronisation depending on timestamp
Jun 22, 2021
3d15bb6
Sync with last operation only if is confirmed
Jun 22, 2021
ecfb86b
Unused import
Jun 23, 2021
929969f
Unnecessary variable
Jun 23, 2021
71c665e
Lint
Jun 23, 2021
e874779
Unnecessary object destructuring
Jun 23, 2021
444d12e
Account details and blockchain blockHeight
Jun 23, 2021
bf3e1ab
Network configs for fees
Jun 23, 2021
2b3ed44
Submit transaction
Jun 23, 2021
5100004
Remove call for nonce
Jun 23, 2021
3b1c8a5
Merge pull request #4 from ElrondNetwork/elrond-integration
AlexandruPislariu Jun 24, 2021
6f7caa5
self transaction warning
Jul 14, 2021
f46af8a
Update changes from base repo
Jul 19, 2021
3df8eac
Revert "Update changes from base repo"
Jul 19, 2021
21d0b83
fix ledger infinite sync on first account
Jul 19, 2021
ecb5f9d
remove elrond specific errors, use ledger errors instead
Jul 29, 2021
4e99077
typo in nonce display
Jul 29, 2021
d1cf9c1
use METACHAIN_SHARD constant
Jul 29, 2021
50e448c
unnecessary ELROND_API_ENDPOINT constant
Jul 29, 2021
1d4c476
broadcast instead of submit transaction
Jul 29, 2021
a1b3b2b
use cache mechanism for transaction network config
Jul 29, 2021
c458dc7
address validation using bech32 decode
Jul 29, 2021
413d21c
remove unnecessary getNetworkConfigs from logic
Jul 29, 2021
2c5cc91
use erdjs for address validation
Jul 29, 2021
1792802
install @elrondnetwork/erdjs
Jul 29, 2021
57294b4
add tests for elrond transactions
Jul 29, 2021
87b793d
Merge branch 'master' into accept-cryptoorg
AlexandruPislariu Jul 29, 2021
15b9cb0
add elrond to test setup
Jul 29, 2021
01f1e2c
small fixes to test-dataset
Jul 29, 2021
c28f156
test setup for elrond
Jul 29, 2021
fa57513
remove mock implementations
Jul 29, 2021
a56c2cc
elrond seeds for tests
Jul 29, 2021
a3102e0
compute spendable balance
Jul 30, 2021
b6a61a7
fees as BigNumber
Jul 30, 2021
7caf5e6
test address with 0 balance
Jul 30, 2021
f3d2338
toBe => toStrictEqual jest matcher
Aug 2, 2021
9fc0245
add bsc supported currency
Aug 2, 2021
cad581e
sync with LedgerHQ:master
Aug 2, 2021
cdd5010
Merge branch 'master' into accept-cryptoorg
AlexandruPislariu Aug 4, 2021
e3e6429
Merge branch 'LedgerHQ:master' into master
AlexandruPislariu Aug 5, 2021
0334ce1
Merge branch 'master' of https://github.com/ElrondNetwork/ledger-live…
Aug 5, 2021
dc57216
Merge branch 'master' of https://github.com/LedgerHQ/ledger-live-common
Aug 11, 2021
ca4cca3
migrate elrond integration to ts
Aug 11, 2021
b764395
Merge branch 'accept-cryptoorg' of https://github.com/ElrondNetwork/l…
Aug 11, 2021
53eef7a
Merge branch 'elrond-develop' into accept-cryptoorg
Aug 11, 2021
0a703d2
lint
Aug 11, 2021
7c31bae
formatOperationSpecifics empty
Aug 11, 2021
3e0aa6a
elrond network info types
Aug 12, 2021
87f2474
remove react flags(overwritten issue)
Aug 12, 2021
5f2b732
Merge branch 'master' into accept-cryptoorg
AlexandruPislariu Aug 12, 2021
11a6e6c
remove erdjs dependency
Aug 12, 2021
4a512d1
lint issues
Aug 12, 2021
70d0a7c
recipient address required
Aug 12, 2021
042743b
empty recipient address
Aug 13, 2021
4d0adfe
Merge branch 'master' into accept-cryptoorg
AlexandruPislariu Aug 13, 2021
38349db
fix lint issues
Aug 13, 2021
0a93544
Merge branch 'accept-cryptoorg' of https://github.com/ElrondNetwork/l…
Aug 13, 2021
c035c67
transaction status empty string recipient
Aug 13, 2021
5a7f8a7
precedence in recipient error
Aug 13, 2021
5a6cb56
configure elrond bot
Aug 23, 2021
8f8a8af
Merge branch 'master' of https://github.com/LedgerHQ/ledger-live-common
Aug 23, 2021
c632d7d
Merge branch 'master' into elrond-bot
Aug 23, 2021
bf64087
add speculos device actions
Aug 23, 2021
4374d6a
amount lt min safe
Aug 23, 2021
ef32951
operation date in ms
Aug 23, 2021
32283aa
op extra field
Aug 24, 2021
a7fda50
lint issues fix
Aug 24, 2021
ca9aa3d
build esdt token accounts for elrond
Aug 26, 2021
0d41674
add ESDT token accounts in sync
Aug 26, 2021
7d9752f
test build ESDT sub accounts
Aug 26, 2021
97f20f4
prevent infinite sync on ESDT accounts
Aug 30, 2021
4b1ee4d
elrond ESDT operations via api
Sep 6, 2021
3bafc52
compute token identifier string
Sep 6, 2021
055778e
remove unused existingTokenAccount
Sep 6, 2021
d3df754
build and ESDT transfer
Sep 6, 2021
9f361b8
Merge branch 'master' into esdt-integration
Sep 16, 2021
ae8e721
elrond device transaction config
Sep 17, 2021
37632b0
Merge branch 'master' of github.com:ElrondNetwork/ledger-live-common
Sep 17, 2021
6164a61
Height on round (#11)
AlexandruPislariu Sep 27, 2021
e658c7e
Merge branch 'LedgerHQ:master' into master
AlexandruPislariu Sep 27, 2021
f1a18ae
Merge branch 'LedgerHQ:master' into master
AlexandruPislariu Sep 30, 2021
3a8c47c
Merge branch 'master' into esdt-integration
Oct 1, 2021
ee11af3
provideESDTInfo instruction for ledger device
Oct 1, 2021
56bc456
account esdt tokens for address
Oct 1, 2021
dc8d01e
build sub account operations
Oct 1, 2021
968ea33
ESDT transactions specifics
Oct 4, 2021
e8e5bdb
constant gas for esdt transfer
Oct 5, 2021
5a293f0
add types to communicate properly with elrond protocol
Oct 5, 2021
2d932b1
return hash when transaction is submitted
Oct 5, 2021
d0859d9
encode and ESDT transfer logic
Oct 5, 2021
c242c61
return only hash when broadcasting transaction
Oct 5, 2021
434c92d
compute transaction fees by using data field of transaction
Oct 5, 2021
df9a8af
compute transaction fees
Oct 5, 2021
e1c21c5
verify ESDT token credentials
Oct 5, 2021
858e32a
use elrond account as fallback
Oct 5, 2021
18dcf84
check if account has ESDT tokens
Oct 5, 2021
029380f
check if fees are greater than account balance
Nov 3, 2021
d0a1874
compute operation value for send max transactions
Nov 3, 2021
c44eead
Merge branch 'LedgerHQ:master' into master
AlexandruPislariu Nov 3, 2021
fa150c8
lint
Nov 3, 2021
ed8b78f
Merge branch 'master' of github.com:ElrondNetwork/ledger-live-common
Nov 3, 2021
54ba905
Merge branch 'master' into esdt-integration
Nov 15, 2021
e8b4acc
refactor api calls
Nov 15, 2021
88ec4d5
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Nov 15, 2021
fdaf4e7
Merge branch 'master' into esdt-integration
Nov 17, 2021
4736c0d
operation value for esdt transfers
Nov 17, 2021
f7804cd
define max pagination size constant
Nov 18, 2021
706b454
define and use tokens count for address call
Nov 18, 2021
f5be588
esdt use all amount transactions
Nov 18, 2021
6f8cde5
transaction value for esdt transfers
Nov 18, 2021
06b0c30
set transaction amount for esdt transfers
Nov 18, 2021
1e978f6
define chain id constant
Nov 18, 2021
f5d98a7
compute fees for transactions status
Nov 18, 2021
178b344
parsing token identifier
Nov 18, 2021
9f7c645
get token transactions within api call and show only egld transaction…
Nov 18, 2021
f57aaf5
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Dec 14, 2021
8927d58
use mainnet chainID
Dec 14, 2021
7be6f9e
Merge branch 'esdt-integration' of github.com:ElrondNetwork/ledger-li…
Dec 14, 2021
01ac3ac
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Dec 20, 2021
cb1c538
run lint
Dec 27, 2021
f8aee73
use dictionary for fast lookup into subaccounts
Dec 27, 2021
6f58931
implement reconciliation for elrond sub accounts sync
Dec 27, 2021
2acaff5
implement reconciliation for elrond sub accounts sync
Dec 27, 2021
e6428f1
Merge branch 'esdt-integration' of github.com:ElrondNetwork/ledger-li…
Dec 27, 2021
2627b43
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Jan 4, 2022
9bfc941
estimate max spendable for token accounts
Jan 5, 2022
118c27d
transaction status for ESDTs
Jan 5, 2022
128d149
adapt transaction value for esdt transactions
Jan 5, 2022
3aa0015
compute fees for ESDT transfers
Jan 6, 2022
989a4eb
encode ESDT transfer accordingly
Jan 6, 2022
454dd26
transaction amount should be 0 for ESDT transfers
Jan 6, 2022
4bcf8eb
compute transaction value helper
Jan 6, 2022
1736d3f
fix issues related to lint
Jan 7, 2022
631a87a
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Jan 7, 2022
3c8c631
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Jan 10, 2022
f1077be
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Jan 25, 2022
02af147
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Jan 25, 2022
21ebc8c
Merge branch 'esdt-integration' of https://github.com/ElrondNetwork/l…
Jan 25, 2022
c7d7cdd
Merge branch 'LedgerHQ:master' into esdt-integration
AlexandruPislariu Feb 14, 2022
e6e39fc
use timestamp scroll for transactions
Feb 18, 2022
4b8719f
Merge branch 'LedgerHQ:develop' into esdt-integration
AlexandruPislariu Feb 18, 2022
43a6d83
Merge branch 'esdt-integration' of https://github.com/ElrondNetwork/l…
Feb 18, 2022
abf3301
Merge branch 'LedgerHQ:develop' into esdt-integration
AlexandruPislariu Mar 2, 2022
7dd7bb5
Merge branch 'LedgerHQ:develop' into esdt-integration
AlexandruPislariu Mar 4, 2022
59552b2
Egld staking (#13)
AlexandruPislariu Mar 4, 2022
b4c04d4
retrieve ESDT amount from transaction action
Mar 4, 2022
cad63ba
MEX & RIDE logos
Mar 15, 2022
9da9d35
remove unnecessary filter
Mar 28, 2022
99777af
decode transaction action for esdt transfers
Mar 28, 2022
c0e9695
LL-1589 more robust bitcoin retry (#1835)
hzheng-ledger Mar 29, 2022
e527a27
show account delegations & decode delegation transactions
Mar 31, 2022
83c563a
Merge branch 'LedgerHQ:develop' into esdt-integration
AlexandruPislariu Apr 1, 2022
3e2905c
integrate erdjs
Apr 7, 2022
c042831
transaction gasLimit
Apr 7, 2022
25c1053
use erdjs proxy to compute fees
Apr 7, 2022
acaffd7
Merge branch 'esdt-integration' of https://github.com/ElrondNetwork/l…
Apr 7, 2022
020a44c
keep 0.005 egld for future transaction fees
Apr 18, 2022
475cb09
compute fees when estimate max spendable balance
Apr 18, 2022
9488c3c
reDelegateRewards as delegate operation type
Apr 18, 2022
8efd6bb
Merge branch 'develop' into esdt-integration
AlexandruPislariu Apr 18, 2022
e5f122b
Maximum decimals limit
May 2, 2022
c9c04cc
spendable balance for lower accounts
May 2, 2022
3d8523c
encode esdt amount using useAllAmount tx field
May 2, 2022
a55312a
Merge branch 'esdt-integration' of https://github.com/ElrondNetwork/l…
May 2, 2022
5252276
Merge branch 'LedgerHQ:develop' into esdt-integration
AlexandruPislariu May 18, 2022
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@cosmjs/proto-signing": "^0.26.5",
"@cosmjs/stargate": "^0.26.5",
"@crypto-com/chain-jslib": "0.0.19",
"@elrondnetwork/erdjs": "^9.2.4",
"@ethereumjs/common": "^2.6.2",
"@ethereumjs/tx": "^3.5.0",
"@ledgerhq/compressjs": "1.3.2",
Expand Down Expand Up @@ -177,4 +178,4 @@
"typescript": "^4.5.5",
"typescript-eslint-parser": "^22.0.0"
}
}
}
6 changes: 6 additions & 0 deletions src/data/icons/svg/MEX.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/data/icons/svg/RIDE.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const envDefinitions = {
def: "https://elrond.coin.ledger.com",
desc: "Elrond API url",
},
ELROND_DELEGATION_API_ENDPOINT: {
parser: stringParser,
def: "https://delegation-api.elrond.com",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will probably need a ledger proxy for this one

desc: "Elrond DELEGATION API url",
},
API_STELLAR_HORIZON: {
parser: stringParser,
def: "https://stellar.coin.ledger.com",
Expand Down
192 changes: 164 additions & 28 deletions src/families/elrond/api/apiCalls.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import BigNumber from "bignumber.js";
import network from "../../../network";
import { Operation } from "../../../types";
import { BinaryUtils } from "../utils/binary.utils";
import {
HASH_TRANSACTION,
METACHAIN_SHARD,
TRANSACTIONS_SIZE,
MAX_PAGINATION_SIZE,
GAS,
} from "../constants";
import {
ElrondDelegation,
ElrondProtocolTransaction,
ElrondTransferOptions,
ESDTToken,
NetworkInfo,
Transaction,
} from "../types";
import { decodeTransaction } from "./sdk";
export default class ElrondApi {
private API_URL: string;
private DELEGATION_API_URL: string;

constructor(API_URL: string) {
constructor(API_URL: string, DELEGATION_API_URL: string) {
this.API_URL = API_URL;
this.DELEGATION_API_URL = DELEGATION_API_URL;
}

async getAccountDetails(addr: string) {
Expand All @@ -18,6 +33,7 @@ export default class ElrondApi {
method: "GET",
url: `${this.API_URL}/accounts/${addr}`,
});

return {
balance,
nonce,
Expand All @@ -42,7 +58,7 @@ export default class ElrondApi {
return data;
}

async getNetworkConfig() {
async getNetworkConfig(): Promise<NetworkInfo> {
const {
data: {
data: {
Expand All @@ -52,77 +68,197 @@ export default class ElrondApi {
erd_min_gas_limit: gasLimit,
erd_min_gas_price: gasPrice,
erd_gas_per_data_byte: gasPerByte,
erd_gas_price_modifier: gasPriceModifier,
},
},
},
} = await network({
method: "GET",
url: `${this.API_URL}/network/config`,
});

return {
chainId,
chainID: chainId,
denomination,
gasLimit,
gasPrice,
gasPerByte,
gasPriceModifier,
};
}

async submit({ operation, signature }) {
const { chainId, gasLimit, gasPrice } = await this.getNetworkConfig();
async submit(operation: Operation, signature: string): Promise<string> {
const networkConfig: NetworkInfo = await this.getNetworkConfig();
const { chainID, gasPrice } = networkConfig;
let gasLimit = networkConfig.gasLimit;

const {
senders: [sender],
recipients: [receiver],
value,
transactionSequenceNumber: nonce,
extra: { data },
} = operation;
let { value } = operation;

if (data) {
const dataDecoded = BinaryUtils.base64Decode(data);

const funcName: string = dataDecoded.split("@")[0];
switch (funcName) {
case "ESDTTransfer":
value = new BigNumber(0);
gasLimit = GAS.ESDT_TRANSFER;
break;
case "delegate":
gasLimit = GAS.DELEGATE;
break;
case "claimRewards":
value = new BigNumber(0);
gasLimit = GAS.CLAIM;
break;
case "withdraw":
value = new BigNumber(0);
gasLimit = GAS.DELEGATE;
break;
case "reDelegateRewards":
value = new BigNumber(0);
gasLimit = GAS.DELEGATE;
break;
case "unDelegate":
value = new BigNumber(0);
gasLimit = GAS.DELEGATE;
break;
default:
throw new Error(`Invalid function name ${funcName}`);
}
}

const transaction: ElrondProtocolTransaction = {
nonce: nonce ?? 0,
value: value.toString(),
receiver,
sender,
gasPrice,
gasLimit,
chainID,
signature,
data,
...HASH_TRANSACTION,
};

const {
data: {
data: { txHash: hash },
},
} = await network({
method: "POST",
url: `${this.API_URL}/transaction/send`,
data: {
nonce,
value,
receiver,
sender,
gasPrice,
gasLimit,
chainID: chainId,
signature,
...HASH_TRANSACTION,
},
data: transaction,
});
return {
hash,
};

return hash;
}

async getHistory(addr: string, startAt: number) {
async getHistory(addr: string, startAt: number): Promise<Transaction[]> {
const { data: transactionsCount } = await network({
method: "GET",
url: `${this.API_URL}/transactions/count?condition=should&sender=${addr}&receiver=${addr}&after=${startAt}`,
url: `${this.API_URL}/accounts/${addr}/transactions/count?after=${startAt}`,
});

let allTransactions: any[] = [];
let allTransactions: Transaction[] = [];
let from = 0;
let before = Math.floor(Date.now() / 1000);
while (from <= transactionsCount) {
const { data: transactions } = await network({
let { data: transactions } = await network({
method: "GET",
url: `${this.API_URL}/transactions?condition=should&sender=${addr}&receiver=${addr}&after=${startAt}&from=${from}&size=${TRANSACTIONS_SIZE}`,
url: `${this.API_URL}/accounts/${addr}/transactions?after=${startAt}&before=${before}&size=${MAX_PAGINATION_SIZE}`,
});

transactions = transactions.map((transaction) =>
decodeTransaction(transaction)
);

allTransactions = [...allTransactions, ...transactions];

from = from + TRANSACTIONS_SIZE;
from = from + MAX_PAGINATION_SIZE;
before = transactions.slice(-1).timestamp;
}

return allTransactions;
}

async getBlockchainBlockHeight() {
async getAccountDelegations(addr: string): Promise<ElrondDelegation[]> {
const { data: delegations } = await network({
method: "GET",
url: `${this.DELEGATION_API_URL}/accounts/${addr}/delegations`,
});

return delegations;
}

async getESDTTransactionsForAddress(
addr: string,
token: string
): Promise<Transaction[]> {
const { data: tokenTransactionsCount } = await network({
method: "GET",
url: `${this.API_URL}/accounts/${addr}/transactions/count?token=${token}`,
});

let allTokenTransactions: Transaction[] = [];
let from = 0;
let before = Math.floor(Date.now() / 1000);
while (from <= tokenTransactionsCount) {
const { data: tokenTransactions } = await network({
method: "GET",
url: `${this.API_URL}/accounts/${addr}/transactions?token=${token}&before=${before}&size=${MAX_PAGINATION_SIZE}`,
});

allTokenTransactions = [...allTokenTransactions, ...tokenTransactions];

from = from + MAX_PAGINATION_SIZE;
before = tokenTransactions.slice(-1).timestamp;
}

for (const esdtTransaction of allTokenTransactions) {
esdtTransaction.transfer = ElrondTransferOptions.esdt;
}

return allTokenTransactions;
}

async getESDTTokensForAddress(addr: string): Promise<ESDTToken[]> {
const { data: tokensCount } = await network({
method: "GET",
url: `${this.API_URL}/accounts/${addr}/tokens/count`,
});

let allTokens: ESDTToken[] = [];
let from = 0;
while (from <= tokensCount) {
const { data: tokens } = await network({
method: "GET",
url: `${this.API_URL}/accounts/${addr}/tokens?from=${from}&size=${MAX_PAGINATION_SIZE}`,
});

allTokens = [...allTokens, ...tokens];

from = from + MAX_PAGINATION_SIZE;
}

return allTokens;
}

async getESDTTokensCountForAddress(addr: string): Promise<number> {
const { data: tokensCount } = await network({
method: "GET",
url: `${this.API_URL}/accounts/${addr}/tokens/count`,
});

return tokensCount;
}

async getBlockchainBlockHeight(): Promise<number> {
const {
data: [{ round: blockHeight }],
} = await network({
Expand Down
4 changes: 4 additions & 0 deletions src/families/elrond/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export {
getOperations,
getFees,
broadcastTransaction,
getAccountESDTTokens,
getAccountDelegations,
getAccountESDTOperations,
hasESDTTokens,
} from "./sdk";
Loading