Skip to content

Commit

Permalink
Revert "feat(LIVE-14948): remove CDN for release issues and thorswap … (
Browse files Browse the repository at this point in the history
#8480)

Revert "feat(LIVE-14948): remove CDN for release issues and thorswap as DEX (#8436)"

This reverts commit 2ebf404.
  • Loading branch information
lpaquet-ledger authored Nov 26, 2024
1 parent 9b5b5c7 commit 5b67938
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
5 changes: 0 additions & 5 deletions .changeset/mighty-days-tan.md

This file was deleted.

9 changes: 6 additions & 3 deletions libs/ledger-live-common/src/cal/partners.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getEnv } from "@ledgerhq/live-env";
import network from "@ledgerhq/live-network";
import { AdditionalProviderConfig, SWAP_DATA_CDN } from "../exchange/providers/swap";

const CAL_BASE_URL = getEnv("CAL_SERVICE_URL");

Expand All @@ -15,8 +14,12 @@ export type PartnerType = {
version?: number;
};

export function getProvidersCDNData(): Record<string, AdditionalProviderConfig> {
return SWAP_DATA_CDN;
export async function getProvidersCDNData(): Promise<Record<string, PartnerType>> {
const { data: providers } = await network<Record<string, PartnerType>>({
url: "https://cdn.live.ledger.com/swap-providers/data.json",
});

return providers;
}

export type ExchangeProvider = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const startExchange = (input: StartExchangeInput): Observable<ExchangeRequestEve
switch (exchangeType) {
case ExchangeTypes.Swap: {
const providerConfig = await getSwapProvider(provider);
if (providerConfig.useInExchangeApp === false) {
if (providerConfig.type !== "CEX") {
throw new Error(`Unsupported provider type ${providerConfig.type}`);
}
version = providerConfig.version;
Expand Down
39 changes: 15 additions & 24 deletions libs/ledger-live-common/src/exchange/providers/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,35 @@ export type SwapProviderConfig = {
needsBearerToken?: boolean;
};

export type CEXProviderConfig = ExchangeProviderNameAndSignature &
SwapProviderConfig & { type: "CEX" };
export type DEXProviderConfig = SwapProviderConfig & { type: "DEX" };
type CEXProviderConfig = ExchangeProviderNameAndSignature & SwapProviderConfig & { type: "CEX" };
type DEXProviderConfig = SwapProviderConfig & { type: "DEX" };
export type AdditionalProviderConfig = SwapProviderConfig & { type: "DEX" | "CEX" } & {
version?: number;
termsOfUseUrl: string;
supportUrl: string;
mainUrl: string;
useInExchangeApp: boolean;
displayName: string;
};

export type ProviderConfig = CEXProviderConfig | DEXProviderConfig;

export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
exodus: {
type: "CEX",
useInExchangeApp: true,
displayName: "Exodus",
termsOfUseUrl: "https://www.exodus.com/terms/",
supportUrl: "mailto:[email protected]",
mainUrl: "https://www.exodus.com/",
needsKYC: false,
version: 2,
},
changelly: {
needsKYC: false,
needsBearerToken: false,
type: "CEX",
useInExchangeApp: true,
displayName: "Changelly",
termsOfUseUrl: "https://changelly.com/terms-of-use",
supportUrl: "https://support.changelly.com/en/support/home",
mainUrl: "https://changelly.com/",
},
exodus: {
type: "CEX",
displayName: "Exodus",
needsBearerToken: false,
termsOfUseUrl: "https://www.exodus.com/legal/exodus-tos-20240219-v29.pdf",
supportUrl: "https://www.exodus.com/contact-support/",
mainUrl: "https://www.exodus.com/",
needsKYC: false,
version: 2,
},
Expand All @@ -48,7 +45,6 @@ export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
needsBearerToken: false,
displayName: "CIC",
type: "CEX",
useInExchangeApp: true,
termsOfUseUrl: "https://criptointercambio.com/terms-of-use",
supportUrl: "https://criptointercambio.com/en/about",
mainUrl: "https://criptointercambio.com/",
Expand All @@ -58,15 +54,14 @@ export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
needsBearerToken: false,
displayName: "MoonPay",
type: "CEX",
useInExchangeApp: true,
version: 2,
termsOfUseUrl: "https://www.moonpay.com/legal/terms_of_use_row",
supportUrl: "https://support.moonpay.com/",
mainUrl: "https://www.moonpay.com/",
},
oneinch: {
type: "DEX",
needsKYC: false,
useInExchangeApp: false,
displayName: "1inch",
needsBearerToken: false,
termsOfUseUrl: "https://1inch.io/assets/1inch_network_terms_of_use.pdf",
Expand All @@ -76,27 +71,24 @@ export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
paraswap: {
type: "DEX",
needsKYC: false,
useInExchangeApp: false,
displayName: "Paraswap",
needsBearerToken: false,
termsOfUseUrl: "https://files.paraswap.io/tos_v4.pdf",
supportUrl: "https://help.paraswap.io/en/",
mainUrl: "https://www.paraswap.io/",
},
thorswap: {
type: "DEX",
type: "CEX",
needsBearerToken: false,
useInExchangeApp: true,
displayName: "THORChain",
termsOfUseUrl: "https://docs.thorswap.finance/thorswap/resources/terms-of-service",
supportUrl: "https://ledgerhelp.swapkit.dev/",
supportUrl: "mailto:[email protected]",
mainUrl: "https://www.thorswap.finance/",
needsKYC: false,
},
uniswap: {
type: "DEX",
needsBearerToken: false,
useInExchangeApp: false,
displayName: "Uniswap",
termsOfUseUrl:
"https://support.uniswap.org/hc/en-us/articles/30935100859661-Uniswap-Labs-Terms-of-Service",
Expand Down Expand Up @@ -245,7 +237,6 @@ export const getSwapProvider = async (
if (ledgerSignatureEnv === "test" && testProviderInfo) {
return {
needsKYC: false,
useInExchangeApp: false,
needsBearerToken: false,
type: "CEX",
termsOfUseUrl: "https://example.com",
Expand Down
9 changes: 3 additions & 6 deletions libs/ledger-live-common/src/exchange/swap/completeExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { convertToAppExchangePartnerKey } from "../providers";
import { CompleteExchangeStep, convertTransportError } from "../error";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import BigNumber from "bignumber.js";
import { CEXProviderConfig } from "../providers/swap";

const withDevicePromise = (deviceId, fn) =>
firstValueFrom(withDevice(deviceId)(transport => from(fn(transport))));
Expand All @@ -50,7 +49,7 @@ const completeExchange = (
const confirmExchange = async () => {
await withDevicePromise(deviceId, async transport => {
const providerConfig = await getSwapProvider(provider);
if (providerConfig.useInExchangeApp === false) {
if (providerConfig.type !== "CEX") {
throw new Error(`Unsupported provider type ${providerConfig.type}`);
}

Expand Down Expand Up @@ -103,13 +102,11 @@ const completeExchange = (
if (errorsKeys.length > 0) throw errors[errorsKeys[0]]; // throw the first error

currentStep = "SET_PARTNER_KEY";
await exchange.setPartnerKey(
convertToAppExchangePartnerKey(providerConfig as CEXProviderConfig),
);
await exchange.setPartnerKey(convertToAppExchangePartnerKey(providerConfig));
if (unsubscribed) return;

currentStep = "CHECK_PARTNER";
await exchange.checkPartner((providerConfig as CEXProviderConfig).signature);
await exchange.checkPartner(providerConfig.signature);
if (unsubscribed) return;

currentStep = "PROCESS_TRANSACTION";
Expand Down
9 changes: 3 additions & 6 deletions libs/ledger-live-common/src/exchange/swap/initSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { decodePayloadProtobuf } from "@ledgerhq/hw-app-exchange";
import { getSwapProvider } from "../providers";
import { convertToAppExchangePartnerKey } from "../providers";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import { CEXProviderConfig } from "../providers/swap";

const withDevicePromise = (deviceId, fn) =>
firstValueFrom(withDevice(deviceId)(transport => from(fn(transport))));
Expand Down Expand Up @@ -168,17 +167,15 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
throw errors[errorsKeys[0]]; // throw the first error
}

if (swapProviderConfig.useInExchangeApp === false) {
if (swapProviderConfig.type !== "CEX") {
throw new Error(`Unsupported provider type ${swapProviderConfig.type}`);
}

// Prepare swap app to receive the tx to forward.
await swap.setPartnerKey(
convertToAppExchangePartnerKey(swapProviderConfig as CEXProviderConfig),
);
await swap.setPartnerKey(convertToAppExchangePartnerKey(swapProviderConfig));
if (unsubscribed) return;

await swap.checkPartner((swapProviderConfig as CEXProviderConfig).signature!);
await swap.checkPartner(swapProviderConfig.signature!);
if (unsubscribed) return;

await swap.processTransaction(Buffer.from(swapResult.binaryPayload, "hex"), estimatedFees);
Expand Down

1 comment on commit 5b67938

@github-actions
Copy link

Choose a reason for hiding this comment

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

[Bot] Testing with 'Nitrogen' ❌ 1 txs ($6.19) ⏲ 70.8s

❌ 1 specs have problems: Tezos

What is the bot and how does it work? Everything is documented here!

❌ 1 mutation errors
necessary accounts resynced in 0.22ms
▬ TezosWallet 3.0.5 on nanoS 2.1.0
→ FROM undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
max spendable ~5.28774
★ using mutation 'send unrevealed'
→ TO undefined: 0 XTZ (0ops) (tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA on 44'/1729'/2'/0') tezbox#2 js:2:tezos:029d7bcf10737806147b22ba4578747ce4ac53e26b443c9eb1ac0e4d5bfbb8f67e:tezbox
✔️ transaction 
SEND 2.643872 XTZ
TO tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA
with fees=0.0005
with gasLimit=600
with storageLimit=277
(estimatedFees 0.000563)
STATUS (665ms)
  amount: 2.643872 XTZ
  estimated fees: 0.000563 XTZ
  total spent: 2.644435 XTZ
errors: 
warnings: 
⚠️ Error: device action timeout. Recent events was:
{"text":"Review operation","x":13,"y":17,"w":107,"h":11}
{"text":"Operation (0)","x":26,"y":-1,"w":94,"h":11}
{"text":"Reveal","x":47,"y":10,"w":81,"h":11}
(totally spent 61s – ends at 2024-11-26T12:10:24.792Z)
⚠️ 2 spec hints
  • Spec Tezos:
    • mutations should define a test(): send unrevealed, send revealed, send max (non delegating), delegate unrevealed, delegate revealed, undelegate unrevealed, undelegate revealed
    • There are not enough accounts (3) to cover all mutations (7).
      Please increase the account target to at least 8 accounts
Details of the 1 mutations

Spec Tezos (3)

Spec Tezos found 3 Tezos accounts (preload: 230ms). Will use TezosWallet 3.0.5 on nanoS 2.1.0
undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
undefined: 0 XTZ (4ops) (tz1he4fPXP3c9fFrztYT3k7KyYuLb28arFNn on 44'/1729'/1'/0') tezbox#1 js:2:tezos:02fe3d777af5380ef0a431c4985772c9669743050cee5feff717c3c3272d7a2810:tezbox
undefined: 0 XTZ (0ops) (tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA on 44'/1729'/2'/0') tezbox#2 js:2:tezos:029d7bcf10737806147b22ba4578747ce4ac53e26b443c9eb1ac0e4d5bfbb8f67e:tezbox
necessary accounts resynced in 0.22ms
▬ TezosWallet 3.0.5 on nanoS 2.1.0
→ FROM undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
max spendable ~5.28774
★ using mutation 'send unrevealed'
→ TO undefined: 0 XTZ (0ops) (tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA on 44'/1729'/2'/0') tezbox#2 js:2:tezos:029d7bcf10737806147b22ba4578747ce4ac53e26b443c9eb1ac0e4d5bfbb8f67e:tezbox
✔️ transaction 
SEND 2.643872 XTZ
TO tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA
with fees=0.0005
with gasLimit=600
with storageLimit=277
(estimatedFees 0.000563)
STATUS (665ms)
  amount: 2.643872 XTZ
  estimated fees: 0.000563 XTZ
  total spent: 2.644435 XTZ
errors: 
warnings: 
⚠️ Error: device action timeout. Recent events was:
{"text":"Review operation","x":13,"y":17,"w":107,"h":11}
{"text":"Operation (0)","x":26,"y":-1,"w":94,"h":11}
{"text":"Reveal","x":47,"y":10,"w":81,"h":11}
(totally spent 61s – ends at 2024-11-26T12:10:24.795Z)

Details of the 6 uncovered mutations

Spec Tezos (6)

  • send revealed: balance is too low (2)
  • send max (non delegating): balance is too low (2)
  • delegate unrevealed: balance is too low (2)
  • delegate revealed: balance is too low (2)
  • undelegate unrevealed: balance is too low (2)
  • undelegate revealed: balance is too low (2)
Portfolio ($6.19) – Details of the 1 currencies
Spec (accounts) State Remaining Runs (est) funds?
Tezos (3) 156 ops , 5.28869 XTZ ($6.19) 👍 182 tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF
undefined: 5.28869 XTZ (152ops) (tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF on 44'/1729'/0'/0') tezbox#0 js:2:tezos:0240051fc51799e60dcc8870415b87fc4fd948e71b23fdc0d9b8ac7438cf7d4708:tezbox
undefined: 0 XTZ (4ops) (tz1he4fPXP3c9fFrztYT3k7KyYuLb28arFNn on 44'/1729'/1'/0') tezbox#1 js:2:tezos:02fe3d777af5380ef0a431c4985772c9669743050cee5feff717c3c3272d7a2810:tezbox
undefined: 0 XTZ (0ops) (tz1SApkt3kmMaqNE1qtgADc6m3B49HZkFVDA on 44'/1729'/2'/0') tezbox#2 js:2:tezos:029d7bcf10737806147b22ba4578747ce4ac53e26b443c9eb1ac0e4d5bfbb8f67e:tezbox
Performance ⏲ 70.8s

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL 230ms 4.1s 0.59ms 665ms N/A N/A N/A N/A
Tezos (2) 230ms 4.1s 0.59ms 665ms N/A N/A N/A N/A

What is the bot and how does it work? Everything is documented here!

Please sign in to comment.