Skip to content

Commit

Permalink
Merge pull request #6189 from overcat/support/bump-stellar-sdk
Browse files Browse the repository at this point in the history
chore(deps): Bump stellar-sdk from 10.4.1 to 11.2.2.
  • Loading branch information
hedi-edelbloute committed Feb 23, 2024
2 parents 826a498 + fa4886c commit 6a0c185
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-steaks-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

Bump stellar-sdk from 10.4.1 to 11.2.2.
2 changes: 1 addition & 1 deletion libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"@solana/web3.js": "1.77.3",
"@stacks/network": "6.10.0",
"@stacks/transactions": "6.11.0",
"@stellar/stellar-sdk": "^11.2.2",
"@stricahq/bip32ed25519": "^1.0.3",
"@stricahq/typhonjs": "^1.2.6",
"@taquito/ledger-signer": "^13.0.1",
Expand Down Expand Up @@ -240,7 +241,6 @@
"semver": "^7.3.5",
"sha.js": "^2.4.11",
"simple-cbor": "^0.4.1",
"stellar-sdk": "^10.4.1",
"superstruct": "0.14.2",
"thor-devkit": "^2.0.6",
"triple-beam": "^1.3.0",
Expand Down
40 changes: 27 additions & 13 deletions libs/ledger-live-common/src/families/stellar/api/horizon.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { LedgerAPI4xx, LedgerAPI5xx, NetworkDown } from "@ledgerhq/errors";
import { requestInterceptor, responseInterceptor } from "@ledgerhq/live-network/network";
import type { Account, Operation } from "@ledgerhq/types-live";

import { BigNumber } from "bignumber.js";
import {
// @ts-expect-error stellar-sdk ts definition missing?
AccountRecord,
NetworkError,
NotFoundError,
Server,
HorizonAxiosClient,
Horizon,
BASE_FEE,
Asset,
Operation as StellarSdkOperation,
Account as StellarSdkAccount,
Transaction as StellarSdkTransaction,
TransactionBuilder,
Networks,
ServerApi,
} from "stellar-sdk";
} from "@stellar/stellar-sdk";
import { log } from "@ledgerhq/logs";

import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
import { getEnv } from "@ledgerhq/live-env";
Expand All @@ -34,24 +33,39 @@ const FALLBACK_BASE_FEE = 100;
const TRESHOLD_LOW = 0.5;
const TRESHOLD_MEDIUM = 0.75;
const currency = getCryptoCurrencyById("stellar");
const server = new Server(getEnv("API_STELLAR_HORIZON"));
const server = new Horizon.Server(getEnv("API_STELLAR_HORIZON"));

// Constants
export const BASE_RESERVE = 0.5;
export const BASE_RESERVE_MIN_COUNT = 2;
export const MIN_BALANCE = 1;

HorizonAxiosClient.interceptors.request.use(requestInterceptor);
// Due to the inconsistency between the axios version (1.6.5) used by `stellar-sdk`
// and the version (0.26.1) used by `@ledgerhq/live-network/network`, it is not possible to use the interceptors
// provided by `@ledgerhq/live-network/network`.
Horizon.AxiosClient.interceptors.request.use(config => {
if (!getEnv("ENABLE_NETWORK_LOGS")) {
return config;
}

const { url, method, data } = config;
log("network", `${method} ${url}`, { data });
return config;
});

Horizon.AxiosClient.interceptors.response.use(response => {
if (getEnv("ENABLE_NETWORK_LOGS")) {
const { url, method } = response.config;
log("network-success", `${response.status} ${method} ${url}`, { data: response.data });
}

HorizonAxiosClient.interceptors.response.use(response => {
responseInterceptor(response);
// FIXME: workaround for the Stellar SDK not using the correct URL: the "next" URL
// included in server responses points to the node itself instead of our reverse proxy...
// (https://github.com/stellar/js-stellar-sdk/issues/637)
const url = response?.data?._links?.next?.href;
const next_href = response?.data?._links?.next?.href;

if (url) {
const next = new URL(url);
if (next_href) {
const next = new URL(next_href);
next.host = new URL(getEnv("API_STELLAR_HORIZON")).host;
response.data._links.next.href = next.toString();
}
Expand Down Expand Up @@ -121,7 +135,7 @@ export const fetchAccount = async (
spendableBalance: BigNumber;
assets: BalanceAsset[];
}> => {
let account: ServerApi.AccountRecord = {} as ServerApi.AccountRecord;
let account: Horizon.ServerApi.AccountRecord = {} as Horizon.ServerApi.AccountRecord;
let assets: BalanceAsset[] = [];
let balance = "0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ const dataset: DatasetTest<Transaction> = {
recipient: "GAIXIJBMYPTSF2CDVQ35WOTULCLZIE4W2SDEK3RQGAA3A22BPWY7R53Z",
}),
expectedStatus: {
// You can get the spenaable balance here
// You can get the spendable balance here
// https://stellar.expert/explorer/public/account/GAS5NQ2VU6LA3QPDSCVBH66IHP2RE52VFCLFQKSGRF7VKMZA2KTLGI3M
amount: new BigNumber(12485498),
amount: new BigNumber(12486627),
errors: {},
warnings: {},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import invariant from "invariant";
import { Memo, Operation as StellarSdkOperation, xdr } from "stellar-sdk";
import { Memo, Operation as StellarSdkOperation, xdr } from "@stellar/stellar-sdk";
import { AmountRequired, FeeNotLoaded, NetworkDown } from "@ledgerhq/errors";
import type { Account } from "@ledgerhq/types-live";
import type { Transaction } from "./types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const signOperation: SignOperationFnSignature<Transaction> = ({ account, deviceI
}

const unsigned = await buildTransaction(account, transaction);
const unsignedPayload = unsigned.signatureBase();
const unsignedPayload: Buffer = Buffer.from(unsigned.signatureBase());
// Sign by device
const hwApp = new Stellar(transport);
const { signature } = await hwApp.signTransaction(
Expand Down
12 changes: 6 additions & 6 deletions libs/ledger-live-common/src/families/stellar/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CacheRes } from "@ledgerhq/live-network/cache";
import { makeLRUCache } from "@ledgerhq/live-network/cache";
import type { Account, OperationType, TokenAccount } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import { ServerApi, StrKey, MuxedAccount } from "stellar-sdk";
import { Horizon, StrKey, MuxedAccount } from "@stellar/stellar-sdk";
import { findSubAccountById } from "../../account";
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../currencies";
import { encodeOperationId } from "../../operation";
Expand All @@ -25,13 +25,13 @@ export const STELLAR_BURN_ADDRESS = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

const currency = getCryptoCurrencyById("stellar");

const getMinimumBalance = (account: ServerApi.AccountRecord): BigNumber => {
const getMinimumBalance = (account: Horizon.ServerApi.AccountRecord): BigNumber => {
return parseCurrencyUnit(currency.units[0], getReservedBalance(account).toString());
};

export const getAccountSpendableBalance = async (
balance: BigNumber,
account: ServerApi.AccountRecord,
account: Horizon.ServerApi.AccountRecord,
): Promise<BigNumber> => {
const minimumBalance = getMinimumBalance(account);
const { recommendedFee } = await fetchBaseFee();
Expand Down Expand Up @@ -69,14 +69,14 @@ export const getBalanceId = (balance: BalanceAsset): string | null => {
}
};

export const getReservedBalance = (account: ServerApi.AccountRecord): BigNumber => {
export const getReservedBalance = (account: Horizon.ServerApi.AccountRecord): BigNumber => {
const numOfSponsoringEntries = Number(account.num_sponsoring);
const numOfSponsoredEntries = Number(account.num_sponsored);

const nativeAsset = account.balances?.find(b => b.asset_type === "native") as BalanceAsset;

const amountInOffers = new BigNumber(nativeAsset?.selling_liabilities || 0);
const numOfEntries = new BigNumber(account.subentry_count);
const numOfEntries = new BigNumber(account.subentry_count || 0);

return new BigNumber(BASE_RESERVE_MIN_COUNT)
.plus(numOfEntries)
Expand Down Expand Up @@ -201,7 +201,7 @@ export const formatOperation = async (

const getValue = (
operation: RawOperation,
transaction: ServerApi.TransactionRecord,
transaction: Horizon.ServerApi.TransactionRecord,
type: OperationType,
): BigNumber => {
let value = new BigNumber(0);
Expand Down
4 changes: 2 additions & 2 deletions libs/ledger-live-common/src/families/stellar/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ServerApi } from "stellar-sdk";
import { Horizon } from "@stellar/stellar-sdk";
import type { BigNumber } from "bignumber.js";
import type {
Operation,
Expand Down Expand Up @@ -73,7 +73,7 @@ export type BalanceAsset = {
liquidity_pool_id?: string;
};

export type RawOperation = ServerApi.OperationRecord & {
export type RawOperation = Horizon.ServerApi.OperationRecord & {
asset_code?: string;
asset_issuer?: string;
from?: string;
Expand Down
2 changes: 1 addition & 1 deletion libs/ledgerjs/packages/hw-app-str/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Str from "@ledgerhq/hw-app-str";
import StellarSdk from "stellar-sdk";
import * as StellarSdk from "@stellar/stellar-sdk";

const getStrAppVersion = async () => {
const transport = await Transport.create();
Expand Down
Loading

0 comments on commit 6a0c185

Please sign in to comment.