Skip to content

Commit

Permalink
support/20220819 CAL update (#995)
Browse files Browse the repository at this point in the history
* support(ledgerjs-cal): CAL update

* bump cryptoassets package

* update script and package

* LIVE-3525: Fixes WETH module to only remap the WETH token from Ethereum (#1027)

* Fixes WETH module to only remap the WETH token from Ethereum

* snapshot

* support(ledgerjs-cal): add tokens

* support(ledgerjs-cal): CAL update

* bump cryptoassets

Co-authored-by: @greweb <[email protected]>
  • Loading branch information
adrienlacombe and gre authored Aug 30, 2022
1 parent d2b4da4 commit e80336b
Show file tree
Hide file tree
Showing 18 changed files with 1,435 additions and 151 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-donkeys-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/cryptoassets": minor
---

CAL update 20220830
5 changes: 5 additions & 0 deletions .changeset/rude-cows-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/cryptoassets": minor
---

CAL update 20220819
86 changes: 71 additions & 15 deletions apps/ledger-live-desktop/cryptoassets.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { initialState, loadCountervalues, calculate } from "./logic";
import {
getFiatCurrencyByTicker,
getCryptoCurrencyById,
getTokenById,
findCurrencyByTicker,
} from "../currencies";
import { getBTCValues } from "../countervalues/mock";
import { Currency } from "@ledgerhq/types-cryptoassets";

const ethereum = getCryptoCurrencyById("ethereum");
const bitcoin = getCryptoCurrencyById("bitcoin");
const usd = getFiatCurrencyByTicker("USD");
const now = Date.now();
Expand Down Expand Up @@ -130,3 +132,51 @@ describe("extreme cases", () => {
expect(currenciesWithCVs.length).toBeGreaterThan(0);
});
});

describe("WETH rules", () => {
test("ethereum WETH have countervalues", async () => {
const weth = getTokenById("ethereum/erc20/weth");
const state = await loadCountervalues(initialState, {
// NB: inferTrackingPairForAccounts would infer eth->usd with the WETH module
// we set this explicitly just to confirm that asking weth->usd will make it work
trackingPairs: [
{
from: ethereum,
to: usd,
startDate: new Date(now - 10 * 24 * 60 * 60 * 1000),
},
],
autofillGaps: true,
disableAutoRecoverErrors: true,
});
const value = calculate(state, {
disableRounding: true,
from: weth,
to: usd,
value: 1000000,
});
expect(value).toBeGreaterThan(0);
});

test("ethereum goerli WETH doesn't countervalues", async () => {
const weth = getTokenById("ethereum_goerli/erc20/wrapped_ether");
const state = await loadCountervalues(initialState, {
trackingPairs: [
{
from: ethereum,
to: usd,
startDate: new Date(now - 1 * 24 * 60 * 60 * 1000),
},
],
autofillGaps: true,
disableAutoRecoverErrors: true,
});
const value = calculate(state, {
disableRounding: true,
from: weth,
to: usd,
value: 1000000,
});
expect(value).toBe(undefined);
});
});
21 changes: 9 additions & 12 deletions libs/ledger-live-common/src/countervalues/modules/weth.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import type { Module } from "./types";
import type { Module, Pair } from "./types";
import { getCryptoCurrencyById } from "../../currencies";

const ETH = getCryptoCurrencyById("ethereum");

const remap = (pair) => {
if (pair.from.ticker === "WETH")
return {
from: ETH,
to: pair.to,
};
if (pair.to.ticker === "WETH")
return {
from: pair.from,
to: ETH,
};
const wethId = "ethereum/erc20/weth";

const remap = (pair: Pair): Pair => {
if (pair.from.type === "TokenCurrency" && pair.from.id === wethId)
return { from: ETH, to: pair.to };
if (pair.to.type === "TokenCurrency" && pair.to.id === wethId)
return { from: pair.from, to: ETH };
return pair;
};

Expand Down
Loading

0 comments on commit e80336b

Please sign in to comment.