From d9e3d43ee2aa65ae8e41fc22c64cfca80724f753 Mon Sep 17 00:00:00 2001 From: Canestin Date: Fri, 25 Oct 2024 11:52:36 +0200 Subject: [PATCH] feat: mantra interation --- apps/cli/src/live-common-setup-base.ts | 1 + .../live-common-set-supported-currencies.ts | 1 + .../src/live-common-setup.ts | 1 + .../coin-cosmos/src/chain/Mantra.ts | 20 +++++++++++++ .../coin-cosmos/src/chain/chain.ts | 4 +++ .../coin-cosmos/src/chain/chain.unit.test.ts | 1 + libs/coin-modules/coin-cosmos/src/config.ts | 10 +++++++ libs/coin-modules/coin-cosmos/src/specs.ts | 10 +++++++ .../src/__tests__/test-helpers/environment.ts | 1 + .../ledger-live-common/src/account/helpers.ts | 1 + .../packages/cryptoassets/src/currencies.ts | 29 +++++++++++++++++++ .../packages/types-cryptoassets/src/index.ts | 3 +- libs/ui/packages/crypto-icons/src/svg/OM.svg | 3 ++ 13 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 libs/coin-modules/coin-cosmos/src/chain/Mantra.ts create mode 100644 libs/ui/packages/crypto-icons/src/svg/OM.svg diff --git a/apps/cli/src/live-common-setup-base.ts b/apps/cli/src/live-common-setup-base.ts index a2fd0e238b57..96f297a0b9d0 100644 --- a/apps/cli/src/live-common-setup-base.ts +++ b/apps/cli/src/live-common-setup-base.ts @@ -99,6 +99,7 @@ setSupportedCurrencies([ "scroll", "scroll_sepolia", "etherlink", + "mantra", ]); for (const k in process.env) setEnvUnsafe(k as EnvName, process.env[k]); diff --git a/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts b/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts index f3b4a841705a..2f280eabe429 100644 --- a/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts +++ b/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts @@ -93,4 +93,5 @@ setSupportedCurrencies([ "scroll_sepolia", "ton", "etherlink", + "mantra", ]); diff --git a/apps/ledger-live-mobile/src/live-common-setup.ts b/apps/ledger-live-mobile/src/live-common-setup.ts index 05815fd122a2..37bb22b8943d 100644 --- a/apps/ledger-live-mobile/src/live-common-setup.ts +++ b/apps/ledger-live-mobile/src/live-common-setup.ts @@ -126,6 +126,7 @@ setSupportedCurrencies([ "scroll_sepolia", "ton", "etherlink", + "mantra", ]); if (Config.BLE_LOG_LEVEL) BluetoothTransport.setLogLevel(Config.BLE_LOG_LEVEL); diff --git a/libs/coin-modules/coin-cosmos/src/chain/Mantra.ts b/libs/coin-modules/coin-cosmos/src/chain/Mantra.ts new file mode 100644 index 000000000000..332cacc64490 --- /dev/null +++ b/libs/coin-modules/coin-cosmos/src/chain/Mantra.ts @@ -0,0 +1,20 @@ +import CosmosBase from "./cosmosBase"; + +class Mantra extends CosmosBase { + stakingDocUrl: string; + unbondingPeriod: number; + prefix: string; + validatorPrefix: string; + // Provided by coin config + ledgerValidator!: string; + lcd!: string; + constructor() { + super(); + this.stakingDocUrl = ""; + this.unbondingPeriod = 21; + this.prefix = "mantra"; + this.validatorPrefix = `${this.prefix}valoper`; + } +} + +export default Mantra; diff --git a/libs/coin-modules/coin-cosmos/src/chain/chain.ts b/libs/coin-modules/coin-cosmos/src/chain/chain.ts index 254c7cbd4fcb..0eb41b83ad07 100644 --- a/libs/coin-modules/coin-cosmos/src/chain/chain.ts +++ b/libs/coin-modules/coin-cosmos/src/chain/chain.ts @@ -16,6 +16,7 @@ import BinanceBeaconChain from "./BinanceBeaconChain"; import Coreum from "./Coreum"; import Injective from "./Injective"; import Dydx from "./Dydx"; +import Mantra from "./Mantra"; const cosmosChainParams: { [key: string]: CosmosBase } = {}; export default function cryptoFactory(currencyId: string): CosmosBase { @@ -74,6 +75,9 @@ export default function cryptoFactory(currencyId: string): CosmosBase { case "injective": cosmosChainParams[currencyId] = new Injective(); break; + case "mantra": + cosmosChainParams[currencyId] = new Mantra(); + break; default: throw new Error(`${currencyId} is not supported`); } diff --git a/libs/coin-modules/coin-cosmos/src/chain/chain.unit.test.ts b/libs/coin-modules/coin-cosmos/src/chain/chain.unit.test.ts index 28850ed36ea7..0e129ac5e43e 100644 --- a/libs/coin-modules/coin-cosmos/src/chain/chain.unit.test.ts +++ b/libs/coin-modules/coin-cosmos/src/chain/chain.unit.test.ts @@ -20,6 +20,7 @@ describe("cryptoFactory test", () => { "sei_network", "stargaze", "stride", + "mantra", ]; currencies.forEach(currency => { expect(cryptoFactory(currency)).not.toBeNull(); diff --git a/libs/coin-modules/coin-cosmos/src/config.ts b/libs/coin-modules/coin-cosmos/src/config.ts index 2e01e2241ab0..01e6c0611c4a 100644 --- a/libs/coin-modules/coin-cosmos/src/config.ts +++ b/libs/coin-modules/coin-cosmos/src/config.ts @@ -158,6 +158,16 @@ export const cosmosConfig: CosmosConfig = { }, }, }, + config_currency_mantra: { + type: "object", + default: { + lcd: "https://api.mantrachain.io", + minGasPrice: 0.01, + status: { + type: "active", + }, + }, + }, }; import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config"; diff --git a/libs/coin-modules/coin-cosmos/src/specs.ts b/libs/coin-modules/coin-cosmos/src/specs.ts index 4fda6693b83c..3bc3414d37ee 100644 --- a/libs/coin-modules/coin-cosmos/src/specs.ts +++ b/libs/coin-modules/coin-cosmos/src/specs.ts @@ -590,6 +590,15 @@ const injective = { }), }; +const mantraMinimalTransactionAmount = new BigNumber(20000); +const mantra = { + ...generateGenericCosmosTest("mantra", false, { + minViableAmount: mantraMinimalTransactionAmount, + mutations: cosmosLikeMutations(mantraMinimalTransactionAmount), + skipOperationHistory: true, + }), +}; + export default { axelar, cosmos, @@ -605,4 +614,5 @@ export default { stargaze, coreum, injective, + mantra, }; diff --git a/libs/ledger-live-common/src/__tests__/test-helpers/environment.ts b/libs/ledger-live-common/src/__tests__/test-helpers/environment.ts index 9a798679bb12..774e08966e1f 100644 --- a/libs/ledger-live-common/src/__tests__/test-helpers/environment.ts +++ b/libs/ledger-live-common/src/__tests__/test-helpers/environment.ts @@ -101,6 +101,7 @@ setSupportedCurrencies([ "scroll_sepolia", "ton", "etherlink", + "mantra", ]); LiveConfig.setConfig(liveConfig); diff --git a/libs/ledger-live-common/src/account/helpers.ts b/libs/ledger-live-common/src/account/helpers.ts index fbb05526884f..a08c1db8f86f 100644 --- a/libs/ledger-live-common/src/account/helpers.ts +++ b/libs/ledger-live-common/src/account/helpers.ts @@ -78,6 +78,7 @@ export const getVotesCount = ( case "osmosis": case "cosmos": case "coreum": + case "mantra": return (mainAccount as CosmosAccount)?.cosmosResources?.delegations.length || 0; default: return 0; diff --git a/libs/ledgerjs/packages/cryptoassets/src/currencies.ts b/libs/ledgerjs/packages/cryptoassets/src/currencies.ts index f58e1fe0a612..da7d2a0d5074 100644 --- a/libs/ledgerjs/packages/cryptoassets/src/currencies.ts +++ b/libs/ledgerjs/packages/cryptoassets/src/currencies.ts @@ -4275,6 +4275,35 @@ export const cryptocurrenciesById: Record = { }, ], }, + mantra: { + type: "CryptoCurrency", + id: "mantra", + coinType: CoinType.ATOM, + name: "Mantra", + managerAppName: "Cosmos", + ticker: "OM", + scheme: "mantra", + color: "#ffb386", + family: "cosmos", + units: [ + { + name: "Mantra", + code: "OM", + magnitude: 6, + }, + { + name: "Micro-Mantra", + code: "uom", + magnitude: 0, + }, + ], + explorerViews: [ + { + tx: "https://www.mintscan.io/mantra/txs/$hash", + address: "https://www.mintscan.io/mantra/validators/$address", + }, + ], + }, }; const cryptocurrenciesByScheme: Record = {}; diff --git a/libs/ledgerjs/packages/types-cryptoassets/src/index.ts b/libs/ledgerjs/packages/types-cryptoassets/src/index.ts index f8555ac0510c..897e3be987c5 100644 --- a/libs/ledgerjs/packages/types-cryptoassets/src/index.ts +++ b/libs/ledgerjs/packages/types-cryptoassets/src/index.ts @@ -163,7 +163,8 @@ export type CryptoCurrencyId = | "blast_sepolia" | "scroll" | "scroll_sepolia" - | "etherlink"; + | "etherlink" + | "mantra"; export type LedgerExplorerId = | "btc" diff --git a/libs/ui/packages/crypto-icons/src/svg/OM.svg b/libs/ui/packages/crypto-icons/src/svg/OM.svg new file mode 100644 index 000000000000..d57313e3fabc --- /dev/null +++ b/libs/ui/packages/crypto-icons/src/svg/OM.svg @@ -0,0 +1,3 @@ + + +