Skip to content

Commit

Permalink
feat: xion integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Canestin committed Dec 16, 2024
1 parent eafb5d9 commit 13150e6
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/cli/src/live-common-setup-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ setSupportedCurrencies([
"zksync",
"zksync_sepolia",
"mantra",
"xion",
]);

for (const k in process.env) setEnvUnsafe(k as EnvName, process.env[k]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ setSupportedCurrencies([
"zksync",
"zksync_sepolia",
"mantra",
"xion",
]);
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const StepChooseCurrency = ({ currency, setCurrency }: StepProps) => {
const zksync = useFeature("currencyZkSync");
const zksyncSepolia = useFeature("currencyZkSyncSepolia");
const mantra = useFeature("currencyMantra");
const xion = useFeature("currencyXion");

const featureFlaggedCurrencies = useMemo(
(): Partial<Record<CryptoCurrencyId, Feature<unknown> | null>> => ({
Expand Down Expand Up @@ -138,6 +139,7 @@ const StepChooseCurrency = ({ currency, setCurrency }: StepProps) => {
zksync,
zksync_sepolia: zksyncSepolia,
mantra,
xion,
}),
[
axelar,
Expand Down Expand Up @@ -190,6 +192,7 @@ const StepChooseCurrency = ({ currency, setCurrency }: StepProps) => {
zksync,
zksyncSepolia,
mantra,
xion,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,5 +808,14 @@
"family": "cosmos",
"color": "#ffb386",
"decimals": 6
},
{
"type": "CryptoCurrency",
"id": "xion",
"ticker": "XION",
"name": "Xion",
"family": "cosmos",
"color": "#000000",
"decimals": 6
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -808,5 +808,14 @@
"family": "cosmos",
"color": "#ffb386",
"decimals": 6
},
{
"type": "CryptoCurrency",
"id": "xion",
"ticker": "XION",
"name": "Xion",
"family": "cosmos",
"color": "#000000",
"decimals": 6
}
]
]
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/src/live-common-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ setSupportedCurrencies([
"zksync",
"zksync_sepolia",
"mantra",
"xion",
]);

if (Config.BLE_LOG_LEVEL) BluetoothTransport.setLogLevel(Config.BLE_LOG_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function AddAccountsSelectCrypto({ navigation, route }: Props) {
const zksync = useFeature("currencyZkSync");
const zksyncSepolia = useFeature("currencyZkSyncSepolia");
const mantra = useFeature("currencyMantra");
const xion = useFeature("currencyXion");

const featureFlaggedCurrencies = useMemo(
(): Partial<Record<CryptoCurrencyId, Feature<unknown> | null>> => ({
Expand Down Expand Up @@ -160,6 +161,7 @@ export default function AddAccountsSelectCrypto({ navigation, route }: Props) {
zksync,
zksync_sepolia: zksyncSepolia,
mantra,
xion,
}),
[
axelar,
Expand Down Expand Up @@ -212,6 +214,7 @@ export default function AddAccountsSelectCrypto({ navigation, route }: Props) {
zksync,
zksyncSepolia,
mantra,
xion,
],
);

Expand Down
1 change: 1 addition & 0 deletions apps/web-tools/live-common-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ setSupportedCurrencies([
"linea",
"linea_sepolia",
"mantra",
"xion",
]);
20 changes: 20 additions & 0 deletions libs/coin-modules/coin-cosmos/src/chain/Xion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import CosmosBase from "./cosmosBase";

class Xion 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 = "xion";
this.validatorPrefix = `${this.prefix}valoper`;
}
}

export default Xion;
4 changes: 4 additions & 0 deletions libs/coin-modules/coin-cosmos/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Coreum from "./Coreum";
import Injective from "./Injective";
import Dydx from "./Dydx";
import Mantra from "./Mantra";
import Xion from "./Xion";

const cosmosChainParams: { [key: string]: CosmosBase } = {};
export default function cryptoFactory(currencyId: string): CosmosBase {
Expand Down Expand Up @@ -78,6 +79,9 @@ export default function cryptoFactory(currencyId: string): CosmosBase {
case "mantra":
cosmosChainParams[currencyId] = new Mantra();
break;
case "xion":
cosmosChainParams[currencyId] = new Xion();
break;
default:
throw new Error(`${currencyId} is not supported`);
}
Expand Down
1 change: 1 addition & 0 deletions libs/coin-modules/coin-cosmos/src/chain/chain.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("cryptoFactory test", () => {
"stargaze",
"stride",
"mantra",
"xion",
];
currencies.forEach(currency => {
expect(cryptoFactory(currency)).not.toBeNull();
Expand Down
11 changes: 11 additions & 0 deletions libs/coin-modules/coin-cosmos/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ export const cosmosConfig: CosmosConfig = {
},
},
},
config_currency_xion: {
type: "object",
default: {
lcd: "https://xion-api.polkachu.com",
minGasPrice: 0.04,
ledgerValidator: "xionvaloper1t8ysd9cg6s38ak9xfadkjtvfv9uczvrn8wzv77",
status: {
type: "active",
},
},
},
};

import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
Expand Down
10 changes: 10 additions & 0 deletions libs/coin-modules/coin-cosmos/src/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,15 @@ const mantra = {
}),
};

const xionMinimalTransactionAmount = new BigNumber(20000);
const xion = {
...generateGenericCosmosTest("xion", false, {
minViableAmount: xionMinimalTransactionAmount,
mutations: cosmosLikeMutations(xionMinimalTransactionAmount),
skipOperationHistory: true,
}),
};

export default {
axelar,
cosmos,
Expand All @@ -615,4 +624,5 @@ export default {
coreum,
injective,
mantra,
xion,
};
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ setSupportedCurrencies([
"zksync",
"zksync_sepolia",
"mantra",
"xion",
]);
LiveConfig.setConfig(liveConfig);

Expand Down
1 change: 1 addition & 0 deletions libs/ledger-live-common/src/account/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const getVotesCount = (
case "cosmos":
case "coreum":
case "mantra":
case "xion":
return (mainAccount as CosmosAccount)?.cosmosResources?.delegations.length || 0;
default:
return 0;
Expand Down
30 changes: 30 additions & 0 deletions libs/ledger-live-common/src/currencies/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const IDS = [
"persistence",
"onomy",
"mantra",
"xion",
];

export const CURRENCIES_LIST: CryptoCurrency[] = [
Expand Down Expand Up @@ -535,4 +536,33 @@ export const CURRENCIES_LIST: CryptoCurrency[] = [
},
],
},
{
type: "CryptoCurrency",
id: "xion",
coinType: 118,
name: "Xion",
managerAppName: "Cosmos",
ticker: "XION",
scheme: "xion",
color: "#000000",
family: "cosmos",
units: [
{
name: "Xion",
code: "XION",
magnitude: 6,
},
{
name: "Micro-XION",
code: "uxion",
magnitude: 0,
},
],
explorerViews: [
{
tx: "https://www.mintscan.io/xion/txs/$hash",
address: "https://www.mintscan.io/xion/validators/$address",
},
],
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DatasetTest } from "@ledgerhq/types-live";
import { testBridge } from "../../../__tests__/test-helpers/bridge";
import "../../../__tests__/test-helpers/setup";
import type { Transaction } from "../types";
import xion from "./xion";

const dataset: DatasetTest<Transaction> = {
implementations: ["js"],
currencies: {
xion,
},
};

testBridge(dataset);
66 changes: 66 additions & 0 deletions libs/ledger-live-common/src/families/cosmos/datasets/xion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { fromTransactionRaw } from "@ledgerhq/coin-cosmos/transaction";
import { CurrenciesData } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import type { Transaction } from "../types";

const dataset: CurrenciesData<Transaction> = {
FIXME_ignoreAccountFields: ["cosmosResources", "operationsCount", "operations"],
FIXME_ignorePreloadFields: ["validators"],
// scanAccounts: [
// {
// name: "xion seed 1",
// apdus: `
// => 55040000190478696f6e2c00008076000080000000800000000000000000
// <= 0x0301a5bc0d94728a62db72b7e162add7767a58f10a5013543637694b2c4a66cc5078696f6e316738343933346a70753376356465357971756b6b6b68786d637673773375326173306b726d359000
// `,
// },
// ],
accounts: [
{
FIXME_tests: ["balance is sum of ops", "pendingOperations are cleaned up"],
raw: {
id: "js:2:xion:xion1g84934jpu3v5de5yqukkkhxmcvsw3u2as0krm5:",
seedIdentifier: "0388459b2653519948b12492f1a0b464720110c147a8155d23d423a5cc3c21d89a",
xpub: "xion1g84934jpu3v5de5yqukkkhxmcvsw3u2as0krm5",
freshAddress: "xion1g84934jpu3v5de5yqukkkhxmcvsw3u2as0krm5",
freshAddressPath: "44'/118'/0'/0/0",
name: "Xion 1",
derivationMode: "",
index: 0,
operationsCount: 3,
operations: [],
balance: "715838",
spendableBalance: "715838",
blockHeight: 4476555,
pendingOperations: [],
currencyId: "xion",
lastSyncDate: "",
},
transactions: [
{
name: "Normal transaction",
transaction: fromTransactionRaw({
amount: "10000",
recipient: "xion108uy5q9jt59gwugq5yrdhkzcd9jryslmr32fql",
useAllAmount: false,
family: "cosmos",
mode: "send",
networkInfo: null,
fees: "8744",
gas: "87440",
validators: [],
memo: "",
sourceValidator: "",
}),
expectedStatus: () => ({
errors: {},
warnings: {},
amount: BigNumber("10000"),
}),
},
],
},
],
};

export default dataset;
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const CURRENCY_DEFAULT_FEATURES = {
currencyZkSync: DEFAULT_FEATURE,
currencyZkSyncSepolia: DEFAULT_FEATURE,
currencyMantra: DEFAULT_FEATURE,
currencyXion: DEFAULT_FEATURE,
};

/**
Expand Down
1 change: 1 addition & 0 deletions libs/ledgerjs/packages/cryptoassets/src/abandonseed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const abandonSeedAddresses: Partial<Record<CryptoCurrency["id"], string>> = {
zksync: EVM_DEAD_ADDRESS,
zksync_sepolia: EVM_DEAD_ADDRESS,
mantra: "mantra12jypwtxm7npfszx5x9780fhz0j3ken696fdp33",
xion: "xion19rl4cm2hmr8afy4kldpxz3fka4jguq0a5xyz123",
};

/**
Expand Down
29 changes: 29 additions & 0 deletions libs/ledgerjs/packages/cryptoassets/src/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4348,6 +4348,35 @@ export const cryptocurrenciesById: Record<CryptoCurrencyId, CryptoCurrency> = {
},
],
},
xion: {
type: "CryptoCurrency",
id: "xion",
coinType: CoinType.ATOM,
name: "Xion",
managerAppName: "Cosmos",
ticker: "XION",
scheme: "xion",
color: "#000000",
family: "cosmos",
units: [
{
name: "Xion",
code: "XION",
magnitude: 6,
},
{
name: "Micro-XION",
code: "uxion",
magnitude: 0,
},
],
explorerViews: [
{
tx: "https://www.mintscan.io/xion/txs/$hash",
address: "https://www.mintscan.io/xion/validators/$address",
},
],
},
};

const cryptocurrenciesByScheme: Record<string, CryptoCurrency> = {};
Expand Down
Loading

0 comments on commit 13150e6

Please sign in to comment.