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

Add TON support for Swap (and Exchange in general) #7952

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion libs/exchange-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@ledgerhq/wallet-api-client": "^1.5.10",
"@ledgerhq/wallet-api-core": "^1.11.0"
"@ledgerhq/wallet-api-core": "^1.12.0"
},
"devDependencies": {
"@types/node": "^20.2.5"
Expand Down
2 changes: 1 addition & 1 deletion libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"@ledgerhq/logs": "workspace:^",
"@ledgerhq/speculos-transport": "workspace:^",
"@ledgerhq/wallet-api-client": "^1.5.10",
"@ledgerhq/wallet-api-core": "^1.11.0",
"@ledgerhq/wallet-api-core": "^1.12.0",
"@ledgerhq/wallet-api-exchange-module": "workspace:^",
"@ledgerhq/wallet-api-server": "^1.5.11",
"@stacks/network": "6.10.0",
Expand Down
11 changes: 7 additions & 4 deletions libs/ledger-live-common/src/exchange/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,29 @@ export const getProviderConfig = async (
}
};

let testProvider: ExchangeProviderNameAndSignature | undefined;
export let testProvider: ExchangeProviderNameAndSignature | undefined;

type TestProvider = {
name: string;
publicKey: {
curve: "secp256k1" | "secp256r1";
data: string;
};
service: {
appVersion: number;
name: "swap" | "sell" | "fund";
};
signature: string;
version: number;
};
export function setTestProviderInfo(provider: string) {
const { name, publicKey, signature, version } = JSON.parse(provider) as TestProvider;
const { name, publicKey, signature, service } = JSON.parse(provider) as TestProvider;
testProvider = {
name,
publicKey: {
curve: publicKey.curve,
data: Buffer.from(publicKey.data, "hex"),
},
signature: Buffer.from(signature, "hex"),
version,
version: service.appVersion,
};
}
15 changes: 14 additions & 1 deletion libs/ledger-live-common/src/exchange/providers/swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExchangeProviderNameAndSignature } from ".";
import { getEnv } from "@ledgerhq/live-env";
import { ExchangeProviderNameAndSignature, testProvider } from ".";
import { isIntegrationTestEnv } from "../swap/utils/isIntegrationTestEnv";
import { getProvidersData } from "./getProvidersData";
import network from "@ledgerhq/live-network";
Expand Down Expand Up @@ -220,6 +221,18 @@ let providerDataCache: Record<string, ProviderConfig & AdditionalProviderConfig>
export const getSwapProvider = async (
providerName: string,
): Promise<ProviderConfig & AdditionalProviderConfig> => {
if (getEnv("MOCK_EXCHANGE_TEST_CONFIG") && testProvider) {
return {
needsKYC: false,
needsBearerToken: false,
type: "CEX",
termsOfUseUrl: "https://example.com",
supportUrl: "https://example.com",
mainUrl: "https://example.com",
...testProvider,
};
}

const res = await fetchAndMergeProviderData();

if (!res[providerName.toLowerCase()]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const coins = [
0x82, 0x90, 0x4, 0xfe, 0x6f, 0x1d, 0x0, 0x3a, 0x58,
]).toString("hex"),
],
[
"ton",
"03544f4e03546f6e00",
"3045022100c47d2be0b63ebab67804250b8659143c344ae43c9daa55ba23e037d0bfa9fe47022046c67aa8a57030fbac3c0f2738b18cace4a231943a8aa83b9dbccf4f353a521b",
],
];

export default coins;
16 changes: 16 additions & 0 deletions libs/ledger-live-common/src/families/ton/exchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { bip32asBuffer } from "../../crypto";

const getSerializedAddressParameters = (
path: string,
): {
addressParameters: Buffer;
} => {
const addressParameters = bip32asBuffer(path);
return {
addressParameters,
};
};

export default {
getSerializedAddressParameters,
};
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/generated/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import polkadot from "../families/polkadot/exchange";
import solana from "../families/solana/exchange";
import stellar from "../families/stellar/exchange";
import tezos from "../families/tezos/exchange";
import ton from "../families/ton/exchange";
import tron from "../families/tron/exchange";
import xrp from "../families/xrp/exchange";

Expand All @@ -14,6 +15,7 @@ export default {
solana,
stellar,
tezos,
ton,
tron,
xrp,
};
1 change: 1 addition & 0 deletions libs/ledgerjs/packages/hw-app-exchange/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@ledgerhq/hw-transport-node-speculos-http": "workspace:^",
"@types/jest": "^29.5.10",
"@types/node": "^20.8.10",
"bip32-path": "^0.4.2",
"documentation": "14.0.2",
"jest": "^29.7.0",
"secp256k1": "5.0.0",
Expand Down
Loading
Loading