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

chore: remove from aptos blockchain from families #8897

Draft
wants to merge 30 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4f3b88c
chore: remove from aptos blockchain from families
jccguimaraes Jan 14, 2025
8f6e936
chore: remove from aptos blockchain from families
jccguimaraes Jan 14, 2025
a065bcf
Merge branch 'develop' into feat/coin-aptos
jccguimaraes Jan 15, 2025
3b96235
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
3923584
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
ccc7059
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
0c416cb
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
df8ca58
Merge branch 'develop' into feat/coin-aptos
jccguimaraes Jan 15, 2025
6fa7b65
chore: remove from aptos blockchain from families
jccguimaraes Jan 15, 2025
08a5621
chore: remove aptos blockchain from families
jccguimaraes Jan 15, 2025
7b80570
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
b60b41f
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
3dab3c8
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
abfa132
Merge branch 'develop' into feat/coin-aptos
jccguimaraes Jan 16, 2025
f58983f
chore: remove aptos blockchain from families
jccguimaraes Jan 16, 2025
5a0e380
test: update tests
jccguimaraes Jan 16, 2025
b6e5c2d
test: update bot test
jccguimaraes Jan 16, 2025
21e7ac4
test: api unit tests
semeano Jan 17, 2025
ab4fc2f
test: broadcast unit tests
semeano Jan 17, 2025
d1cc7df
Merge branch 'develop' into feat/coin-aptos
semeano Jan 17, 2025
c8deb53
chore: save work
semeano Jan 17, 2025
1b4a8b9
build: update packages
semeano Jan 17, 2025
cf9e952
test: fix unit tests
semeano Jan 17, 2025
cac2ac8
test: fix unit tests
semeano Jan 17, 2025
a4aacc3
fix: update aptos bot test
jccguimaraes Jan 17, 2025
12ea13c
test: fix unit tests
semeano Jan 17, 2025
cfcbd63
test: unit test for deviceTransactionConfig
semeano Jan 17, 2025
6f14cee
test: unit test for signer
semeano Jan 17, 2025
28a8720
test: unit test for network
semeano Jan 17, 2025
72f22ca
fix: remove script from package.json
semeano Jan 17, 2025
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
8 changes: 8 additions & 0 deletions .changeset/calm-boats-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ledgerhq/coin-filecoin": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

support: move aptos to its own coin module
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"dependencies": {
"@braze/web-sdk": "4.10.2",
"@ledgerhq/coin-bitcoin": "workspace:^",
"@ledgerhq/coin-aptos": "workspace:^",
"@ledgerhq/coin-cosmos": "workspace:^",
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-filecoin": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@formatjs/intl-locale": "3.4.5",
"@formatjs/intl-pluralrules": "5.2.12",
"@formatjs/intl-relativetimeformat": "11.2.12",
"@ledgerhq/coin-aptos": "workspace:^",
"@ledgerhq/coin-cosmos": "workspace:^",
"@ledgerhq/coin-elrond": "workspace:^",
"@ledgerhq/coin-evm": "workspace:^",
Expand Down
22 changes: 22 additions & 0 deletions libs/coin-modules/coin-aptos/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"ignoreUnresolved": [
"follow-redirects",
"form-data",
"proxy-from-env"
],
"ignoreUnused": [
"@ledgerhq/devices",
"expect"
],
"ignoreUnimported": [
"src/bridge/deviceTransactionConfig.ts",
"src/bridge/transaction.ts",
"src/hw-signMessage.ts",
"src/test/bot-specs.ts",
"src/test/bridgeDatasetTest.ts",
"src/test/cli.ts",
"src/test/index.ts",
"src/test/speculos-deviceActions.ts"
]
}

8 changes: 8 additions & 0 deletions libs/coin-modules/coin-aptos/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
collectCoverageFrom: ["src/**/*.ts"],
coverageDirectory: "coverage",
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["lib/", "lib-es/", ".integration.test.ts"],
};
130 changes: 130 additions & 0 deletions libs/coin-modules/coin-aptos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"name": "@ledgerhq/coin-aptos",
"version": "1.3.2",
"description": "Ledger Aptos Coin integration",
"keywords": [
"Ledger",
"LedgerWallet",
"apt",
"Aptos",
"Hardware Wallet"
],
"repository": {
"type": "git",
"url": "https://github.com/LedgerHQ/ledger-live.git"
},
"bugs": {
"url": "https://github.com/LedgerHQ/ledger-live/issues"
},
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-aptos",
"publishConfig": {
"access": "public"
},
"typesVersions": {
"*": {
"lib/*": [
"lib/*"
],
"lib-es/*": [
"lib-es/*"
],
"specs": [
"lib/test/bot-specs"
],
"*": [
"lib/*",
"lib/api/*",
"lib/bridge/*",
"lib/common-logic/*",
"lib/signer/*",
"lib/test/*",
"lib/types/*"
]
}
},
"exports": {
"./lib/*": "./lib/*.js",
"./lib-es/*": "./lib-es/*.js",
"./api": {
"require": "./lib/api/index.js",
"default": "./lib-es/api/index.js"
},
"./deviceTransactionConfig": {
"require": "./lib/bridge/deviceTransactionConfig.js",
"default": "./lib-es/bridge/deviceTransactionConfig.js"
},
"./logic": {
"require": "./lib/common-logic/index.js",
"default": "./lib-es/common-logic/index.js"
},
"./network": {
"require": "./lib/network/index.js",
"default": "./lib-es/network/index.js"
},
"./signer": {
"require": "./lib/signer/index.js",
"default": "./lib-es/signer/index.js"
},
"./specs": {
"require": "./lib/test/bot-specs.js",
"default": "./lib-es/test/bot-specs.js"
},
"./transaction": {
"require": "./lib/bridge/transaction.js",
"default": "./lib-es/bridge/transaction.js"
},
"./types": {
"require": "./lib/types/index.js",
"default": "./lib-es/types/index.js"
},
"./*": {
"require": "./lib/*.js",
"default": "./lib-es/*.js"
},
".": {
"require": "./lib/index.js",
"default": "./lib-es/index.js"
},
"./package.json": "./package.json"
},
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/cryptoassets": "workspace:^",
"@ledgerhq/devices": "workspace:*",
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/live-env": "workspace:^",
"@ledgerhq/live-network": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"@ledgerhq/types-cryptoassets": "workspace:^",
"@ledgerhq/types-live": "workspace:^",
"@aptos-labs/ts-sdk": "^1.33.1",
"@apollo/client": "^3.8.7",
"bignumber.js": "^9.1.2",
"invariant": "^2.2.2",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@types/invariant": "^2.2.2",
"@types/jest": "^29.5.10",
"@types/lodash": "^4.14.191",
"@types/semver": "^7.5.8",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"axios": "1.7.7"
},
"scripts": {
"clean": "rimraf lib lib-es",
"build": "tsc && tsc -m ES6 --outDir lib-es",
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-aptos.json",
"prewatch": "pnpm build",
"watch": "tsc --watch",
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",
"test": "jest",
"unimported": "unimported"
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import BigNumber from "bignumber.js";
import bridge from "./js";
import { createBridges } from "./";
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";

const signer = jest.fn();
const bridge = createBridges(signer);

describe("Aptos bridge interface ", () => {
describe("currencyBridge", () => {
it("should have a preload method that returns a promise", async () => {
Expand Down
65 changes: 65 additions & 0 deletions libs/coin-modules/coin-aptos/src/bridge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
makeAccountBridgeReceive,
makeScanAccounts,
getSerializedAddressParameters,
makeSync,
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
import resolver from "../signer";
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
import { SignerContext } from "@ledgerhq/coin-framework/signer";
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
import { updateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
import type { Transaction, TransactionStatus, AptosSigner } from "../types";
import getTransactionStatus from "../getTransactionStatus";
import estimateMaxSpendable from "../estimateMaxSpendable";
import prepareTransaction from "../prepareTransaction";
import createTransaction from "../createTransaction";
import { getAccountShape } from "../synchronisation";
import { signOperation as buildSignOperation } from "../signOperation";
import broadcast from "../broadcast";

function buildCurrencyBridge(signerContext: SignerContext<AptosSigner>): CurrencyBridge {
const getAddress = resolver(signerContext);

const scanAccounts = makeScanAccounts({
getAccountShape,
getAddressFn: getAddressWrapper(getAddress),
});

return {
preload: () => Promise.resolve({}),
hydrate: () => {},
scanAccounts,
};
}

const sync = makeSync({ getAccountShape });

function buildAccountBridge(
signerContext: SignerContext<AptosSigner>,
): AccountBridge<Transaction, Account, TransactionStatus> {
const getAddress = resolver(signerContext);

const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
const signOperation = buildSignOperation(signerContext);

return {
estimateMaxSpendable,
createTransaction,
updateTransaction,
getTransactionStatus,
getSerializedAddressParameters,
prepareTransaction,
sync,
receive,
signOperation,
broadcast,
};
}

export function createBridges(signerContext: SignerContext<AptosSigner>) {
return {
currencyBridge: buildCurrencyBridge(signerContext),
accountBridge: buildAccountBridge(signerContext),
};
}
1 change: 1 addition & 0 deletions libs/coin-modules/coin-aptos/src/bridge/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// // TODO add content
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import broadcast from "./broadcast";
import { AptosAPI } from "./api";
import { patchOperationWithHash } from "./../../operation";
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
import { patchOperationWithHash } from "./../../operation";
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
import { AptosAPI } from "./api";

const broadcast = async ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createFixtureAccount } from "../../mock/fixtures/cryptoCurrencies";
import createTransaction from "./createTransaction";
import { createFixtureAccount, createFixtureTransaction } from "./types/bridge.fixture";
import buildTransaction from "./buildTransaction";
import { AptosAPI } from "./api";
import { normalizeTransactionOptions } from "./logic";
Expand Down Expand Up @@ -30,7 +29,7 @@ jest.mock("./api", () => {
describe("buildTransaction Test", () => {
it("should return tx", async () => {
const account = createFixtureAccount();
const transaction = createTransaction();
const transaction = createFixtureTransaction();
const aptosClient = new AptosAPI(account.currency.id);
const result = await buildTransaction(account, transaction, aptosClient);

Expand Down
27 changes: 27 additions & 0 deletions libs/coin-modules/coin-aptos/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import buildConConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";

export type AptosConfig = {
jccguimaraes marked this conversation as resolved.
Show resolved Hide resolved
node: {
url: string;
credentials?: string;
};
sidecar: {
url: string;
credentials?: string;
};
staking?: {
electionStatusThreshold: number;
};
metadataShortener: {
url: string;
};
metadataHash: {
url: string;
};
};

export type AptosCoinConfig = CurrencyConfig & AptosConfig;

const coinConfig = buildConConfig<AptosCoinConfig>();

export default coinConfig;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DeviceTransactionField } from "../../transaction";
import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
import BigNumber from "bignumber.js";

export const methodToString = (method: number): string => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createFixtureAccount } from "../../mock/fixtures/cryptoCurrencies";
import createTransaction from "./createTransaction";
import { createFixtureAccount, createFixtureTransaction } from "./types/bridge.fixture";
import estimateMaxSpendable from "./estimateMaxSpendable";
import BigNumber from "bignumber.js";

Expand Down Expand Up @@ -56,7 +55,7 @@ describe("estimateMaxSpendable Test", () => {
describe("transaction spendable balance is higher than the total gas", () => {
it("should return transaction spendable amount minus total gas", async () => {
const account = createFixtureAccount();
const transaction = createTransaction();
const transaction = createFixtureTransaction();

const spendableBalance = new BigNumber(1);

Expand All @@ -77,7 +76,7 @@ describe("estimateMaxSpendable Test", () => {
describe("transaction spendable balance is higher than the total gas", () => {
it("should return transaction spendable amount minus total gas", async () => {
const account = createFixtureAccount();
const transaction = createTransaction();
const transaction = createFixtureTransaction();

const spendableBalance = new BigNumber(100000);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Account, AccountLike } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import { getMainAccount } from "../../account";
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
import { AptosAPI } from "./api";
import { getEstimatedGas } from "./getFeesForTransaction";
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
Expand Down
Loading
Loading