@ledgerhq/live-common 34.40.0 → 34.41.0-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/test-helpers/bridge.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/bridge.js +0 -4
- package/lib/__tests__/test-helpers/bridge.js.map +1 -1
- package/lib/bridge/impl.d.ts.map +1 -1
- package/lib/bridge/impl.js +45 -4
- package/lib/bridge/impl.js.map +1 -1
- package/lib/bridge/useBridgeTransaction.test.js +9 -0
- package/lib/bridge/useBridgeTransaction.test.js.map +1 -1
- package/lib/e2e/enum/Account.d.ts +1 -0
- package/lib/e2e/enum/Account.d.ts.map +1 -1
- package/lib/e2e/enum/Account.js +1 -0
- package/lib/e2e/enum/Account.js.map +1 -1
- package/lib/e2e/enum/Provider.d.ts +3 -0
- package/lib/e2e/enum/Provider.d.ts.map +1 -1
- package/lib/e2e/enum/Provider.js +3 -0
- package/lib/e2e/enum/Provider.js.map +1 -1
- package/lib/e2e/index.d.ts +1 -2
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/speculos.d.ts.map +1 -1
- package/lib/e2e/speculos.js +2 -0
- package/lib/e2e/speculos.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/exchange/error.d.ts +1 -0
- package/lib/exchange/error.d.ts.map +1 -1
- package/lib/exchange/error.js +11 -1
- package/lib/exchange/error.js.map +1 -1
- package/lib/exchange/swap/api/v5/actions.d.ts +3 -0
- package/lib/exchange/swap/api/v5/actions.d.ts.map +1 -0
- package/lib/exchange/swap/api/v5/actions.js +36 -0
- package/lib/exchange/swap/api/v5/actions.js.map +1 -0
- package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.js +13 -0
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/exchange/swap/getCompleteSwapHistory.js +1 -1
- package/lib/exchange/swap/getCompleteSwapHistory.js.map +1 -1
- package/lib/exchange/swap/postSwapState.d.ts.map +1 -1
- package/lib/exchange/swap/postSwapState.js +19 -9
- package/lib/exchange/swap/postSwapState.js.map +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.d.ts +3 -2
- package/lib/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.js +4 -2
- package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
- package/lib/exchange/swap/transactionStrategies.d.ts +25 -0
- package/lib/exchange/swap/transactionStrategies.d.ts.map +1 -0
- package/lib/exchange/swap/transactionStrategies.js +152 -0
- package/lib/exchange/swap/transactionStrategies.js.map +1 -0
- package/lib/exchange/swap/types.d.ts +59 -0
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/families/cardano/signerSerializer.js +4 -2
- package/lib/families/cardano/signerSerializer.js.map +1 -1
- package/lib/families/evm/bridge/mock.js +2 -2
- package/lib/families/evm/platformAdapter.js +2 -2
- package/lib/families/evm/platformAdapter.js.map +1 -1
- package/lib/families/evm/platformAdapter.test.js +4 -4
- package/lib/families/evm/platformAdapter.test.js.map +1 -1
- package/lib/families/evm/react.js +1 -1
- package/lib/families/evm/react.js.map +1 -1
- package/lib/families/evm/react.test.js +2 -2
- package/lib/families/evm/react.test.js.map +1 -1
- package/lib/families/evm/walletApiAdapter.js +1 -1
- package/lib/families/evm/walletApiAdapter.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +1 -1
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/hw/extractOnboardingState.d.ts.map +1 -1
- package/lib/hw/extractOnboardingState.js +8 -6
- package/lib/hw/extractOnboardingState.js.map +1 -1
- package/lib/hw/extractOnboardingState.test.js +7 -0
- package/lib/hw/extractOnboardingState.test.js.map +1 -1
- package/lib/mock/account.d.ts.map +1 -1
- package/lib/mock/account.js +1 -0
- package/lib/mock/account.js.map +1 -1
- package/lib/wallet-api/Exchange/server.d.ts +29 -10
- package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib/wallet-api/Exchange/server.js +204 -7
- package/lib/wallet-api/Exchange/server.js.map +1 -1
- package/lib/wallet-api/Exchange/server.test.js +3 -1
- package/lib/wallet-api/Exchange/server.test.js.map +1 -1
- package/lib/wallet-api/useDappLogic.js +2 -2
- package/lib-es/__tests__/test-helpers/bridge.d.ts.map +1 -1
- package/lib-es/__tests__/test-helpers/bridge.js +0 -4
- package/lib-es/__tests__/test-helpers/bridge.js.map +1 -1
- package/lib-es/bridge/impl.d.ts.map +1 -1
- package/lib-es/bridge/impl.js +43 -2
- package/lib-es/bridge/impl.js.map +1 -1
- package/lib-es/bridge/useBridgeTransaction.test.js +9 -0
- package/lib-es/bridge/useBridgeTransaction.test.js.map +1 -1
- package/lib-es/e2e/enum/Account.d.ts +1 -0
- package/lib-es/e2e/enum/Account.d.ts.map +1 -1
- package/lib-es/e2e/enum/Account.js +1 -0
- package/lib-es/e2e/enum/Account.js.map +1 -1
- package/lib-es/e2e/enum/Provider.d.ts +3 -0
- package/lib-es/e2e/enum/Provider.d.ts.map +1 -1
- package/lib-es/e2e/enum/Provider.js +3 -0
- package/lib-es/e2e/enum/Provider.js.map +1 -1
- package/lib-es/e2e/index.d.ts +1 -2
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/e2e/speculos.d.ts.map +1 -1
- package/lib-es/e2e/speculos.js +2 -0
- package/lib-es/e2e/speculos.js.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/exchange/error.d.ts +1 -0
- package/lib-es/exchange/error.d.ts.map +1 -1
- package/lib-es/exchange/error.js +9 -0
- package/lib-es/exchange/error.js.map +1 -1
- package/lib-es/exchange/swap/api/v5/actions.d.ts +3 -0
- package/lib-es/exchange/swap/api/v5/actions.d.ts.map +1 -0
- package/lib-es/exchange/swap/api/v5/actions.js +29 -0
- package/lib-es/exchange/swap/api/v5/actions.js.map +1 -0
- package/lib-es/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib-es/exchange/swap/completeExchange.js +13 -0
- package/lib-es/exchange/swap/completeExchange.js.map +1 -1
- package/lib-es/exchange/swap/getCompleteSwapHistory.js +1 -1
- package/lib-es/exchange/swap/getCompleteSwapHistory.js.map +1 -1
- package/lib-es/exchange/swap/postSwapState.d.ts.map +1 -1
- package/lib-es/exchange/swap/postSwapState.js +17 -7
- package/lib-es/exchange/swap/postSwapState.js.map +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +3 -2
- package/lib-es/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.js +4 -2
- package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
- package/lib-es/exchange/swap/transactionStrategies.d.ts +25 -0
- package/lib-es/exchange/swap/transactionStrategies.d.ts.map +1 -0
- package/lib-es/exchange/swap/transactionStrategies.js +140 -0
- package/lib-es/exchange/swap/transactionStrategies.js.map +1 -0
- package/lib-es/exchange/swap/types.d.ts +59 -0
- package/lib-es/exchange/swap/types.d.ts.map +1 -1
- package/lib-es/families/cardano/signerSerializer.js +4 -2
- package/lib-es/families/cardano/signerSerializer.js.map +1 -1
- package/lib-es/families/evm/bridge/mock.js +1 -1
- package/lib-es/families/evm/platformAdapter.js +1 -1
- package/lib-es/families/evm/platformAdapter.js.map +1 -1
- package/lib-es/families/evm/platformAdapter.test.js +1 -1
- package/lib-es/families/evm/platformAdapter.test.js.map +1 -1
- package/lib-es/families/evm/react.js +1 -1
- package/lib-es/families/evm/react.js.map +1 -1
- package/lib-es/families/evm/react.test.js +2 -2
- package/lib-es/families/evm/react.test.js.map +1 -1
- package/lib-es/families/evm/walletApiAdapter.js +1 -1
- package/lib-es/families/evm/walletApiAdapter.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +1 -1
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/hw/extractOnboardingState.d.ts.map +1 -1
- package/lib-es/hw/extractOnboardingState.js +8 -6
- package/lib-es/hw/extractOnboardingState.js.map +1 -1
- package/lib-es/hw/extractOnboardingState.test.js +7 -0
- package/lib-es/hw/extractOnboardingState.test.js.map +1 -1
- package/lib-es/mock/account.d.ts.map +1 -1
- package/lib-es/mock/account.js +1 -0
- package/lib-es/mock/account.js.map +1 -1
- package/lib-es/wallet-api/Exchange/server.d.ts +29 -10
- package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib-es/wallet-api/Exchange/server.js +206 -9
- package/lib-es/wallet-api/Exchange/server.js.map +1 -1
- package/lib-es/wallet-api/Exchange/server.test.js +3 -1
- package/lib-es/wallet-api/Exchange/server.test.js.map +1 -1
- package/lib-es/wallet-api/useDappLogic.js +1 -1
- package/package.json +40 -40
- package/src/__tests__/test-helpers/bridge.ts +0 -4
- package/src/bridge/impl.ts +70 -3
- package/src/bridge/useBridgeTransaction.test.ts +10 -0
- package/src/e2e/enum/Account.ts +6 -0
- package/src/e2e/enum/Provider.ts +3 -0
- package/src/e2e/speculos.ts +2 -0
- package/src/exchange/error.ts +10 -0
- package/src/exchange/swap/api/v5/actions.ts +36 -0
- package/src/exchange/swap/completeExchange.ts +14 -0
- package/src/exchange/swap/getCompleteSwapHistory.ts +1 -1
- package/src/exchange/swap/postSwapState.ts +24 -6
- package/src/exchange/swap/setBroadcastTransaction.ts +6 -2
- package/src/exchange/swap/transactionStrategies.ts +234 -0
- package/src/exchange/swap/types.ts +64 -0
- package/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap +1 -0
- package/src/families/cardano/signerSerializer.ts +4 -2
- package/src/families/evm/bridge/mock.ts +1 -1
- package/src/families/evm/platformAdapter.test.ts +1 -1
- package/src/families/evm/platformAdapter.ts +1 -1
- package/src/families/evm/react.test.ts +3 -3
- package/src/families/evm/react.ts +1 -1
- package/src/families/evm/walletApiAdapter.ts +1 -1
- package/src/featureFlags/defaultFeatures.ts +1 -1
- package/src/hw/extractOnboardingState.test.ts +9 -0
- package/src/hw/extractOnboardingState.ts +12 -8
- package/src/mock/account.ts +1 -0
- package/src/wallet-api/Exchange/server.test.ts +7 -5
- package/src/wallet-api/Exchange/server.ts +344 -32
- package/src/wallet-api/useDappLogic.ts +1 -1
package/src/e2e/enum/Provider.ts
CHANGED
@@ -16,6 +16,9 @@ export class Provider {
|
|
16
16
|
static readonly LIFI = new Provider("lifi", "LI.FI", false, true, false);
|
17
17
|
static readonly CIC = new Provider("cic", "CIC", false, true, true);
|
18
18
|
static readonly COINBASE = new Provider("coinbase", "Coinbase", false, true, true);
|
19
|
+
static readonly KILN = new Provider("kiln", "Kiln staking Pool", false, true, true);
|
20
|
+
static readonly STADER_LABS = new Provider("stader", "Stader Labs", false, true, true);
|
21
|
+
static readonly LIDO = new Provider("lido", "Lido", false, true, true);
|
19
22
|
|
20
23
|
static getNameByUiName(uiName: string): string {
|
21
24
|
const provider = Object.values(Provider).find(p => p.uiName === uiName);
|
package/src/e2e/speculos.ts
CHANGED
@@ -672,12 +672,14 @@ export async function signDelegationTransaction(delegatingAccount: Delegate) {
|
|
672
672
|
}
|
673
673
|
|
674
674
|
export async function verifyAmountsAndAcceptSwap(swap: Swap, amount: string) {
|
675
|
+
await waitFor(DeviceLabels.REVIEW_TRANSACTION);
|
675
676
|
const events = await pressUntilTextFound(DeviceLabels.ACCEPT);
|
676
677
|
await verifySwapData(swap, events, amount);
|
677
678
|
await pressBoth();
|
678
679
|
}
|
679
680
|
|
680
681
|
export async function verifyAmountsAndRejectSwap(swap: Swap, amount: string) {
|
682
|
+
await waitFor(DeviceLabels.REVIEW_TRANSACTION);
|
681
683
|
const events = await pressUntilTextFound(DeviceLabels.REJECT);
|
682
684
|
await verifySwapData(swap, events, amount);
|
683
685
|
await pressBoth();
|
package/src/exchange/error.ts
CHANGED
@@ -31,3 +31,13 @@ export function convertTransportError(
|
|
31
31
|
}
|
32
32
|
return err;
|
33
33
|
}
|
34
|
+
|
35
|
+
export function getSwapStepFromError(error: Error): string {
|
36
|
+
if ((error as CompleteExchangeError).step) {
|
37
|
+
return (error as CompleteExchangeError).step;
|
38
|
+
} else if (error.name === "DisabledTransactionBroadcastError") {
|
39
|
+
return "SIGN_COIN_TRANSACTION";
|
40
|
+
}
|
41
|
+
|
42
|
+
return "UNKNOWN_STEP";
|
43
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import axios from "axios";
|
2
|
+
import { getSwapAPIBaseURL } from "../..";
|
3
|
+
import { SwapPayloadRequestData, SwapPayloadResponse } from "../../types";
|
4
|
+
|
5
|
+
export async function retrieveSwapPayload(
|
6
|
+
data: SwapPayloadRequestData,
|
7
|
+
): Promise<SwapPayloadResponse> {
|
8
|
+
const SWAP_API_BASE = getSwapAPIBaseURL();
|
9
|
+
|
10
|
+
const swapAxiosClient = axios.create({
|
11
|
+
baseURL: SWAP_API_BASE,
|
12
|
+
});
|
13
|
+
|
14
|
+
const request = {
|
15
|
+
provider: data.provider,
|
16
|
+
deviceTransactionId: data.deviceTransactionId,
|
17
|
+
from: data.fromAccountCurrency,
|
18
|
+
to: data.toNewTokenId || data.toAccountCurrency,
|
19
|
+
address: data.toAccountAddress,
|
20
|
+
refundAddress: data.fromAccountAddress,
|
21
|
+
amountFrom: data.amount,
|
22
|
+
amountFromInSmallestDenomination: Number(data.amountInAtomicUnit),
|
23
|
+
rateId: data.quoteId,
|
24
|
+
};
|
25
|
+
|
26
|
+
const res = await swapAxiosClient.post(`${SWAP_API_BASE}/swap`, request);
|
27
|
+
|
28
|
+
return {
|
29
|
+
binaryPayload: res.data?.binaryPayload,
|
30
|
+
signature: res.data?.signature,
|
31
|
+
payinAddress: res.data?.payinAddress,
|
32
|
+
swapId: res.data?.swapId,
|
33
|
+
payinExtraId: res.data?.payinExtraId,
|
34
|
+
extraTransactionParameters: res.data?.extraTransactionParameters,
|
35
|
+
};
|
36
|
+
}
|
@@ -25,6 +25,8 @@ import { CompleteExchangeStep, convertTransportError } from "../error";
|
|
25
25
|
import type { CompleteExchangeInputSwap, CompleteExchangeRequestEvent } from "../platform/types";
|
26
26
|
import { convertToAppExchangePartnerKey, getSwapProvider } from "../providers";
|
27
27
|
import { CEXProviderConfig } from "../providers/swap";
|
28
|
+
import { isAddressSanctioned } from "@ledgerhq/coin-framework/sanction/index";
|
29
|
+
import { AddressesSanctionedError } from "@ledgerhq/coin-framework/sanction/errors";
|
28
30
|
|
29
31
|
const COMPLETE_EXCHANGE_LOG = "SWAP-CompleteExchange";
|
30
32
|
|
@@ -64,6 +66,18 @@ const completeExchange = (
|
|
64
66
|
const payoutCurrency = getAccountCurrency(toAccount);
|
65
67
|
const refundCurrency = getAccountCurrency(fromAccount);
|
66
68
|
const mainRefundCurrency = getAccountCurrency(refundAccount);
|
69
|
+
|
70
|
+
const sanctionedAddresses: string[] = [];
|
71
|
+
for (const acc of [refundAccount, payoutAccount]) {
|
72
|
+
const isSanctioned = await isAddressSanctioned(acc.currency, acc.freshAddress);
|
73
|
+
if (isSanctioned) sanctionedAddresses.push(acc.freshAddress);
|
74
|
+
}
|
75
|
+
|
76
|
+
if (sanctionedAddresses.length > 0) {
|
77
|
+
throw new AddressesSanctionedError("AddressesSanctionedError", {
|
78
|
+
addresses: sanctionedAddresses,
|
79
|
+
});
|
80
|
+
}
|
67
81
|
if (mainPayoutCurrency.type !== "CryptoCurrency")
|
68
82
|
throw new Error("This should be a cryptocurrency");
|
69
83
|
if (mainRefundCurrency.type !== "CryptoCurrency")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import network from "@ledgerhq/live-network
|
1
|
+
import network from "@ledgerhq/live-network";
|
2
2
|
import { mockPostSwapAccepted, mockPostSwapCancelled } from "./mock";
|
3
3
|
import type { PostSwapAccepted, PostSwapCancelled } from "./types";
|
4
4
|
import { isIntegrationTestEnv } from "./utils/isIntegrationTestEnv";
|
@@ -8,25 +8,31 @@ export const postSwapAccepted: PostSwapAccepted = async ({
|
|
8
8
|
provider,
|
9
9
|
swapId = "",
|
10
10
|
transactionId,
|
11
|
+
swapAppVersion,
|
11
12
|
...rest
|
12
13
|
}) => {
|
13
14
|
if (isIntegrationTestEnv())
|
14
15
|
return mockPostSwapAccepted({ provider, swapId, transactionId, ...rest });
|
15
16
|
|
16
17
|
/**
|
17
|
-
* Since swapId is
|
18
|
+
* Since swapId is required by the endpoint, don't call it if we don't have
|
18
19
|
* this info
|
19
20
|
*/
|
20
21
|
if (!swapId) {
|
21
22
|
return null;
|
22
23
|
}
|
23
24
|
try {
|
24
|
-
const
|
25
|
+
const ipHeader = getSwapUserIP();
|
26
|
+
const headers = {
|
27
|
+
...(ipHeader || {}),
|
28
|
+
...(swapAppVersion ? { "x-swap-app-version": swapAppVersion } : {}),
|
29
|
+
};
|
30
|
+
|
25
31
|
await network({
|
26
32
|
method: "POST",
|
27
33
|
url: `${getSwapAPIBaseURL()}/swap/accepted`,
|
28
34
|
data: { provider, swapId, transactionId, ...rest },
|
29
|
-
...(headers
|
35
|
+
...(Object.keys(headers).length > 0 ? { headers } : {}),
|
30
36
|
});
|
31
37
|
} catch (error) {
|
32
38
|
console.error(error);
|
@@ -35,11 +41,16 @@ export const postSwapAccepted: PostSwapAccepted = async ({
|
|
35
41
|
return null;
|
36
42
|
};
|
37
43
|
|
38
|
-
export const postSwapCancelled: PostSwapCancelled = async ({
|
44
|
+
export const postSwapCancelled: PostSwapCancelled = async ({
|
45
|
+
provider,
|
46
|
+
swapId = "",
|
47
|
+
swapAppVersion,
|
48
|
+
...rest
|
49
|
+
}) => {
|
39
50
|
if (isIntegrationTestEnv()) return mockPostSwapCancelled({ provider, swapId, ...rest });
|
40
51
|
|
41
52
|
/**
|
42
|
-
* Since swapId is
|
53
|
+
* Since swapId is required by the endpoint, don't call it if we don't have
|
43
54
|
* this info
|
44
55
|
*/
|
45
56
|
if (!swapId) {
|
@@ -47,10 +58,17 @@ export const postSwapCancelled: PostSwapCancelled = async ({ provider, swapId =
|
|
47
58
|
}
|
48
59
|
|
49
60
|
try {
|
61
|
+
const ipHeader = getSwapUserIP();
|
62
|
+
const headers = {
|
63
|
+
...(ipHeader || {}),
|
64
|
+
...(swapAppVersion ? { "x-swap-app-version": swapAppVersion } : {}),
|
65
|
+
};
|
66
|
+
|
50
67
|
await network({
|
51
68
|
method: "POST",
|
52
69
|
url: `${getSwapAPIBaseURL()}/swap/cancelled`,
|
53
70
|
data: { provider, swapId, ...rest },
|
71
|
+
...(Object.keys(headers).length > 0 ? { headers } : {}),
|
54
72
|
});
|
55
73
|
} catch (error) {
|
56
74
|
console.error(error);
|
@@ -11,13 +11,15 @@ export const setBroadcastTransaction = ({
|
|
11
11
|
targetCurrencyId,
|
12
12
|
hardwareWalletType,
|
13
13
|
swapType,
|
14
|
+
swapAppVersion,
|
14
15
|
}: {
|
15
|
-
result: { operation: Operation; swapId: string };
|
16
|
+
result: { operation: Operation | string; swapId: string };
|
16
17
|
provider: string;
|
17
18
|
sourceCurrencyId?: string;
|
18
19
|
targetCurrencyId?: string;
|
19
20
|
hardwareWalletType?: DeviceModelId;
|
20
21
|
swapType?: TradeMethod;
|
22
|
+
swapAppVersion?: string;
|
21
23
|
}) => {
|
22
24
|
const { operation, swapId } = result;
|
23
25
|
|
@@ -36,16 +38,18 @@ export const setBroadcastTransaction = ({
|
|
36
38
|
targetCurrencyId,
|
37
39
|
hardwareWalletType,
|
38
40
|
swapType: swapType,
|
41
|
+
swapAppVersion,
|
39
42
|
});
|
40
43
|
} else {
|
41
44
|
postSwapAccepted({
|
42
45
|
provider,
|
43
46
|
swapId,
|
44
|
-
transactionId: operation.hash,
|
47
|
+
transactionId: typeof operation === "string" ? operation : operation.hash,
|
45
48
|
sourceCurrencyId,
|
46
49
|
targetCurrencyId,
|
47
50
|
hardwareWalletType,
|
48
51
|
swapType,
|
52
|
+
swapAppVersion,
|
49
53
|
});
|
50
54
|
}
|
51
55
|
};
|
@@ -0,0 +1,234 @@
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
2
|
+
|
3
|
+
import {
|
4
|
+
CosmosTransaction,
|
5
|
+
ElrondTransaction,
|
6
|
+
RippleTransaction,
|
7
|
+
SolanaTransaction,
|
8
|
+
StellarTransaction,
|
9
|
+
TonTransaction,
|
10
|
+
Transaction,
|
11
|
+
TransactionCommon,
|
12
|
+
} from "@ledgerhq/wallet-api-client";
|
13
|
+
|
14
|
+
export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
|
15
|
+
|
16
|
+
export function defaultTransaction({
|
17
|
+
family,
|
18
|
+
amount,
|
19
|
+
recipient,
|
20
|
+
customFeeConfig,
|
21
|
+
}: TransactionWithCustomFee): Transaction {
|
22
|
+
return <Transaction>{
|
23
|
+
family,
|
24
|
+
amount,
|
25
|
+
recipient,
|
26
|
+
...customFeeConfig,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
export function modeSendTransaction({
|
31
|
+
family,
|
32
|
+
amount,
|
33
|
+
recipient,
|
34
|
+
customFeeConfig,
|
35
|
+
}: TransactionWithCustomFee): Transaction {
|
36
|
+
return {
|
37
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
38
|
+
mode: "send",
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
export function stellarTransaction({
|
43
|
+
family,
|
44
|
+
amount,
|
45
|
+
recipient,
|
46
|
+
customFeeConfig,
|
47
|
+
payinExtraId,
|
48
|
+
customErrorType,
|
49
|
+
}: TransactionWithCustomFee): StellarTransaction {
|
50
|
+
if (!payinExtraId)
|
51
|
+
throw {
|
52
|
+
error: new Error("Missing payinExtraId"),
|
53
|
+
step: "PayinExtraIdStepError",
|
54
|
+
customErrorType,
|
55
|
+
};
|
56
|
+
|
57
|
+
return {
|
58
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
59
|
+
family: "stellar",
|
60
|
+
memoValue: payinExtraId,
|
61
|
+
memoType: "MEMO_TEXT",
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
export function rippleTransaction({
|
66
|
+
amount,
|
67
|
+
recipient,
|
68
|
+
customFeeConfig,
|
69
|
+
payinExtraId,
|
70
|
+
customErrorType,
|
71
|
+
}: TransactionWithCustomFee): RippleTransaction {
|
72
|
+
if (!payinExtraId)
|
73
|
+
throw {
|
74
|
+
error: new Error("Missing payinExtraId"),
|
75
|
+
step: "PayinExtraIdStepError",
|
76
|
+
customErrorType,
|
77
|
+
};
|
78
|
+
|
79
|
+
const transaction: RippleTransaction = {
|
80
|
+
family: "ripple",
|
81
|
+
amount,
|
82
|
+
recipient,
|
83
|
+
...customFeeConfig,
|
84
|
+
tag: new BigNumber(payinExtraId).toNumber(),
|
85
|
+
};
|
86
|
+
return transaction;
|
87
|
+
}
|
88
|
+
|
89
|
+
// Function to remove gasLimit from customFeeConfig for Ethereum or Bitcoin
|
90
|
+
export function withoutGasLimitTransaction({
|
91
|
+
family,
|
92
|
+
amount,
|
93
|
+
recipient,
|
94
|
+
customFeeConfig,
|
95
|
+
extraTransactionParameters,
|
96
|
+
}: TransactionWithCustomFee): Transaction {
|
97
|
+
if (customFeeConfig?.gasLimit) {
|
98
|
+
delete customFeeConfig.gasLimit;
|
99
|
+
}
|
100
|
+
|
101
|
+
if (extraTransactionParameters) {
|
102
|
+
return <Transaction>{
|
103
|
+
family,
|
104
|
+
amount,
|
105
|
+
recipient,
|
106
|
+
...customFeeConfig,
|
107
|
+
data: Buffer.from(extraTransactionParameters, "hex"),
|
108
|
+
};
|
109
|
+
}
|
110
|
+
return defaultTransaction({ family, amount, recipient, customFeeConfig });
|
111
|
+
}
|
112
|
+
|
113
|
+
export function bitcoinTransaction({
|
114
|
+
amount,
|
115
|
+
recipient,
|
116
|
+
customFeeConfig,
|
117
|
+
extraTransactionParameters,
|
118
|
+
}: TransactionWithCustomFee): Transaction {
|
119
|
+
if (extraTransactionParameters) {
|
120
|
+
return {
|
121
|
+
family: "bitcoin",
|
122
|
+
amount,
|
123
|
+
recipient,
|
124
|
+
...customFeeConfig,
|
125
|
+
opReturnData: Buffer.from(extraTransactionParameters, "utf-8"),
|
126
|
+
};
|
127
|
+
}
|
128
|
+
return {
|
129
|
+
family: "bitcoin",
|
130
|
+
amount,
|
131
|
+
recipient,
|
132
|
+
...customFeeConfig,
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
136
|
+
export function solanaTransaction({
|
137
|
+
family,
|
138
|
+
amount,
|
139
|
+
recipient,
|
140
|
+
customFeeConfig,
|
141
|
+
}: TransactionWithCustomFee): SolanaTransaction {
|
142
|
+
return {
|
143
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
144
|
+
family: "solana",
|
145
|
+
model: { kind: "transfer", uiState: {} },
|
146
|
+
};
|
147
|
+
}
|
148
|
+
|
149
|
+
export function elrondTransaction({
|
150
|
+
amount,
|
151
|
+
recipient,
|
152
|
+
customFeeConfig,
|
153
|
+
}: TransactionWithCustomFee): ElrondTransaction {
|
154
|
+
const transaction: ElrondTransaction = {
|
155
|
+
family: "elrond",
|
156
|
+
amount,
|
157
|
+
recipient,
|
158
|
+
mode: "send",
|
159
|
+
...customFeeConfig,
|
160
|
+
gasLimit: 0, // FIXME: Placeholder, adjust as needed
|
161
|
+
};
|
162
|
+
return transaction;
|
163
|
+
}
|
164
|
+
|
165
|
+
function tonTransaction({
|
166
|
+
family,
|
167
|
+
amount,
|
168
|
+
recipient,
|
169
|
+
customFeeConfig,
|
170
|
+
}: TransactionWithCustomFee): TonTransaction {
|
171
|
+
return {
|
172
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
173
|
+
family: "ton",
|
174
|
+
comment: { isEncrypted: false, text: "" },
|
175
|
+
fees: new BigNumber(0), // Set default value as completeExchange call prepareTransaction, which set again fees.
|
176
|
+
};
|
177
|
+
}
|
178
|
+
|
179
|
+
export function cosmosTransaction({
|
180
|
+
family,
|
181
|
+
amount,
|
182
|
+
recipient,
|
183
|
+
customFeeConfig,
|
184
|
+
payinExtraId,
|
185
|
+
}: TransactionWithCustomFee): CosmosTransaction {
|
186
|
+
return <CosmosTransaction>{
|
187
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
188
|
+
family: "cosmos",
|
189
|
+
mode: "send",
|
190
|
+
memo: payinExtraId ?? undefined,
|
191
|
+
};
|
192
|
+
}
|
193
|
+
|
194
|
+
export type TransactionWithCustomFee = TransactionCommon & {
|
195
|
+
customFeeConfig: {
|
196
|
+
[key: string]: BigNumber;
|
197
|
+
};
|
198
|
+
payinExtraId?: string;
|
199
|
+
customErrorType?: "swap";
|
200
|
+
extraTransactionParameters?: string;
|
201
|
+
};
|
202
|
+
|
203
|
+
// Define a specific type for the strategy functions, assuming they might need parameters
|
204
|
+
export type TransactionStrategyFunction = (params: TransactionWithCustomFee) => Transaction;
|
205
|
+
|
206
|
+
export const transactionStrategy: {
|
207
|
+
[K in Transaction["family"]]: TransactionStrategyFunction;
|
208
|
+
} = {
|
209
|
+
algorand: defaultTransaction,
|
210
|
+
aptos: defaultTransaction,
|
211
|
+
bitcoin: bitcoinTransaction,
|
212
|
+
cardano: modeSendTransaction,
|
213
|
+
celo: defaultTransaction,
|
214
|
+
cosmos: cosmosTransaction,
|
215
|
+
crypto_org: defaultTransaction,
|
216
|
+
elrond: elrondTransaction,
|
217
|
+
ethereum: withoutGasLimitTransaction,
|
218
|
+
filecoin: defaultTransaction,
|
219
|
+
hedera: defaultTransaction,
|
220
|
+
near: modeSendTransaction,
|
221
|
+
neo: defaultTransaction,
|
222
|
+
polkadot: defaultTransaction,
|
223
|
+
ripple: rippleTransaction,
|
224
|
+
solana: solanaTransaction,
|
225
|
+
stacks: defaultTransaction,
|
226
|
+
stellar: stellarTransaction,
|
227
|
+
tezos: modeSendTransaction,
|
228
|
+
ton: tonTransaction,
|
229
|
+
tron: modeSendTransaction,
|
230
|
+
vechain: defaultTransaction,
|
231
|
+
casper: defaultTransaction,
|
232
|
+
sui: defaultTransaction,
|
233
|
+
internet_computer: defaultTransaction,
|
234
|
+
};
|
@@ -4,6 +4,7 @@ import { Account, AccountLike, AccountRaw, AccountRawLike, Operation } from "@le
|
|
4
4
|
import { BigNumber } from "bignumber.js";
|
5
5
|
import { Result as UseBridgeTransactionResult } from "../../bridge/useBridgeTransaction";
|
6
6
|
import { Transaction, TransactionRaw } from "../../generated/types";
|
7
|
+
|
7
8
|
export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
|
8
9
|
|
9
10
|
export type ExchangeSwap = {
|
@@ -198,6 +199,7 @@ type SwapStateRequest = {
|
|
198
199
|
targetCurrencyId: string;
|
199
200
|
hardwareWalletType: DeviceModelId;
|
200
201
|
swapType: TradeMethod;
|
202
|
+
swapAppVersion?: string;
|
201
203
|
}>;
|
202
204
|
|
203
205
|
export type SwapStateAcceptedRequest = SwapStateRequest & {
|
@@ -336,3 +338,65 @@ export type SwapTransactionType = UseBridgeTransactionResult & {
|
|
336
338
|
fromAmountError?: Error;
|
337
339
|
fromAmountWarning?: Error;
|
338
340
|
};
|
341
|
+
|
342
|
+
export type SwapPayloadRequestData = {
|
343
|
+
provider: string;
|
344
|
+
deviceTransactionId: string;
|
345
|
+
fromAccountAddress: string;
|
346
|
+
toAccountAddress: string;
|
347
|
+
fromAccountCurrency: string;
|
348
|
+
toAccountCurrency: string;
|
349
|
+
amount: string;
|
350
|
+
amountInAtomicUnit: number;
|
351
|
+
quoteId?: string;
|
352
|
+
toNewTokenId?: string;
|
353
|
+
};
|
354
|
+
export type SwapPayloadResponse = {
|
355
|
+
binaryPayload: string;
|
356
|
+
signature: string;
|
357
|
+
payinAddress: string;
|
358
|
+
swapId: string;
|
359
|
+
payinExtraId?: string;
|
360
|
+
extraTransactionParameters?: string;
|
361
|
+
};
|
362
|
+
|
363
|
+
export type ConfirmSwapRequest = {
|
364
|
+
provider: string;
|
365
|
+
swapId: string;
|
366
|
+
transactionId: string;
|
367
|
+
sourceCurrencyId?: string;
|
368
|
+
targetCurrencyId?: string;
|
369
|
+
hardwareWalletType?: string;
|
370
|
+
};
|
371
|
+
|
372
|
+
export type CancelSwapRequest = {
|
373
|
+
provider: string;
|
374
|
+
swapId: string;
|
375
|
+
statusCode?: string;
|
376
|
+
errorMessage?: string;
|
377
|
+
sourceCurrencyId?: string;
|
378
|
+
targetCurrencyId?: string;
|
379
|
+
hardwareWalletType?: string;
|
380
|
+
swapType?: string;
|
381
|
+
swapStep?: string;
|
382
|
+
};
|
383
|
+
|
384
|
+
export type SwapBackendResponse = {
|
385
|
+
provider: string;
|
386
|
+
swapId: string;
|
387
|
+
apiExtraFee: number;
|
388
|
+
apiFee: number;
|
389
|
+
refundAddress: string;
|
390
|
+
amountExpectedFrom: number;
|
391
|
+
amountExpectedTo: number;
|
392
|
+
status: string;
|
393
|
+
from: string;
|
394
|
+
to: string;
|
395
|
+
payinAddress: string;
|
396
|
+
payoutAddress: string;
|
397
|
+
createdAt: string; // ISO-8601
|
398
|
+
binaryPayload: string;
|
399
|
+
signature: string;
|
400
|
+
payinExtraId?: string;
|
401
|
+
extraTransactionParameters?: string;
|
402
|
+
};
|
@@ -7,6 +7,7 @@ exports[`cardano_testnet currency bridge scanAccounts cardano_testnet seed 1 1`]
|
|
7
7
|
"cardanoResources": {
|
8
8
|
"delegation": {
|
9
9
|
"dRepHex": undefined,
|
10
|
+
"deposit": "2000000",
|
10
11
|
"name": "Apex Cardano Pool",
|
11
12
|
"poolId": "7facad662e180ce45e5c504957cd1341940c72a708728f7ecfc6e349",
|
12
13
|
"rewards": "0",
|
@@ -121,9 +121,10 @@ function prepareCertificate(cert: SignerTxCertificate): Certificate {
|
|
121
121
|
switch (cert.type) {
|
122
122
|
case "REGISTRATION":
|
123
123
|
return {
|
124
|
-
type: CertificateType.
|
124
|
+
type: CertificateType.STAKE_REGISTRATION_CONWAY,
|
125
125
|
params: {
|
126
126
|
stakeCredential,
|
127
|
+
deposit: cert.params.deposit,
|
127
128
|
},
|
128
129
|
};
|
129
130
|
case "DELEGATION":
|
@@ -136,9 +137,10 @@ function prepareCertificate(cert: SignerTxCertificate): Certificate {
|
|
136
137
|
};
|
137
138
|
case "DEREGISTRATION":
|
138
139
|
return {
|
139
|
-
type: CertificateType.
|
140
|
+
type: CertificateType.STAKE_DEREGISTRATION_CONWAY,
|
140
141
|
params: {
|
141
142
|
stakeCredential,
|
143
|
+
deposit: cert.params.deposit,
|
142
144
|
},
|
143
145
|
};
|
144
146
|
case "VOTE_DELEGATION_ABSTAIN":
|
@@ -14,7 +14,7 @@ import {
|
|
14
14
|
getSerializedAddressParameters,
|
15
15
|
updateTransaction,
|
16
16
|
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
17
|
-
import { getGasLimit } from "@ledgerhq/coin-evm/
|
17
|
+
import { getGasLimit } from "@ledgerhq/coin-evm/utils";
|
18
18
|
import { getTypedTransaction } from "@ledgerhq/coin-evm/transaction";
|
19
19
|
const receive = makeAccountBridgeReceive();
|
20
20
|
const defaultGetFees = (_a, t: any) => (t.gasPrice || new BigNumber(0)).times(getGasLimit(t));
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { DEFAULT_NONCE } from "@ledgerhq/coin-evm/createTransaction";
|
2
1
|
import { Transaction } from "@ledgerhq/coin-evm/types/index";
|
3
2
|
import { FAMILIES, EthereumTransaction as PlatformTransaction } from "@ledgerhq/live-app-sdk";
|
4
3
|
import BigNumber from "bignumber.js";
|
5
4
|
import evm from "./platformAdapter";
|
5
|
+
import { DEFAULT_NONCE } from "@ledgerhq/coin-evm/utils";
|
6
6
|
|
7
7
|
describe("getPlatformTransactionSignFlowInfos", () => {
|
8
8
|
describe("should properly get infos for ETH platform tx", () => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// TODO: to remove once live-app-sdk is depreciated and removed from LL
|
2
2
|
|
3
|
-
import { DEFAULT_NONCE } from "@ledgerhq/coin-evm/
|
3
|
+
import { DEFAULT_NONCE } from "@ledgerhq/coin-evm/utils";
|
4
4
|
import { Transaction } from "@ledgerhq/coin-evm/types/index";
|
5
5
|
import { EthereumTransaction as PlatformTransaction } from "@ledgerhq/live-app-sdk";
|
6
6
|
|
@@ -4,15 +4,15 @@
|
|
4
4
|
import BigNumber from "bignumber.js";
|
5
5
|
import { renderHook, waitFor } from "@testing-library/react";
|
6
6
|
import { Transaction } from "@ledgerhq/coin-evm/types/index";
|
7
|
-
import { getGasTracker } from "@ledgerhq/coin-evm/
|
8
|
-
import type { GasTrackerApi } from "@ledgerhq/coin-evm/
|
7
|
+
import { getGasTracker } from "@ledgerhq/coin-evm/network/gasTracker/index";
|
8
|
+
import type { GasTrackerApi } from "@ledgerhq/coin-evm/network/gasTracker/types";
|
9
9
|
import { CryptoCurrency, CryptoCurrencyId } from "@ledgerhq/types-cryptoassets";
|
10
10
|
import { useGasOptions } from "./react";
|
11
11
|
|
12
12
|
jest.useFakeTimers();
|
13
13
|
jest.spyOn(global, "setInterval");
|
14
14
|
|
15
|
-
jest.mock("@ledgerhq/coin-evm/
|
15
|
+
jest.mock("@ledgerhq/coin-evm/network/gasTracker/index");
|
16
16
|
const mockedGetGasTracker = jest.mocked(getGasTracker);
|
17
17
|
|
18
18
|
const mockedGetGasOptions = jest.fn();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getGasTracker } from "@ledgerhq/coin-evm/
|
1
|
+
import { getGasTracker } from "@ledgerhq/coin-evm/network/gasTracker/index";
|
2
2
|
import type { GasOptions, Transaction } from "@ledgerhq/coin-evm/types/index";
|
3
3
|
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
4
4
|
import { useEffect, useMemo, useState } from "react";
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { createTransaction } from "@ledgerhq/coin-evm/createTransaction";
|
1
|
+
import { createTransaction } from "@ledgerhq/coin-evm/bridge/createTransaction";
|
2
2
|
import { Transaction } from "@ledgerhq/coin-evm/types/index";
|
3
3
|
import { EthereumTransaction as WalletAPIEthereumTransaction } from "@ledgerhq/wallet-api-core";
|
4
4
|
import {
|
@@ -153,6 +153,7 @@ export const DEFAULT_FEATURES: Features = {
|
|
153
153
|
protectServicesDesktop: {
|
154
154
|
enabled: false,
|
155
155
|
params: {
|
156
|
+
openWithDevTools: false,
|
156
157
|
availableOnDesktop: false,
|
157
158
|
isNew: false,
|
158
159
|
ledgerliveStorageState: false,
|
@@ -530,7 +531,6 @@ export const DEFAULT_FEATURES: Features = {
|
|
530
531
|
...DEFAULT_FEATURE,
|
531
532
|
params: { link: null },
|
532
533
|
},
|
533
|
-
llmNetworkBasedAddAccountFlow: DEFAULT_FEATURE,
|
534
534
|
llCounterValueGranularitiesRates: {
|
535
535
|
...DEFAULT_FEATURE,
|
536
536
|
params: {
|
@@ -35,6 +35,15 @@ describe("@hw/extractOnboardingState", () => {
|
|
35
35
|
expect(onboardingState?.currentOnboardingStep).toBe(OnboardingStep.Ready);
|
36
36
|
expect(onboardingState?.charonStatus).toBeNull();
|
37
37
|
});
|
38
|
+
|
39
|
+
it("should ignore charon update status", () => {
|
40
|
+
const charonState = Buffer.from([0x20]);
|
41
|
+
const onboardingState = extractOnboardingState(flagsBytes, charonState);
|
42
|
+
|
43
|
+
expect(onboardingState).not.toBeNull();
|
44
|
+
expect(onboardingState?.currentOnboardingStep).toBe(OnboardingStep.Ready);
|
45
|
+
expect(onboardingState?.charonStatus).toBeNull();
|
46
|
+
});
|
38
47
|
});
|
39
48
|
|
40
49
|
describe("and the user refuse to backup the charon", () => {
|