Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
  • Loading branch information
desislavva committed Apr 5, 2024
2 parents fa09360 + fb8a91b commit 008ac9b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nolus/nolusjs",
"author": "Nolabs",
"license": "Apache-2.0",
"version": "2.2.19",
"version": "2.3.0",
"description": "JS library for NodeJS and Web browsers to interact with the Nolus Protocol",
"engines": {
"node": ">=14.0.0"
Expand Down
13 changes: 9 additions & 4 deletions src/contracts/clients/Oracle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Price } from '../types';
import { feedPricesMsg, getConfigMsg, getFeedersMsg, getPriceForMsg, getPricesMsg, getCurrencyPairsMsg, getSwapPathMsg, isFeederMsg, getSwapTreeMsg } from '../messages';
import { NolusWallet } from '../../wallet';
import { StdFee } from '@cosmjs/stargate';
import { Coin } from '@cosmjs/proto-signing';
import { ExecuteResult } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient';
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { Price } from '../types';
import { feedPricesMsg, getConfigMsg, getFeedersMsg, getPriceForMsg, getPricesMsg, getCurrencyPairsMsg, getSwapPathMsg, isFeederMsg, getSwapTreeMsg, getCurrenciesMsg } from '../messages';
import { NolusWallet } from '../../wallet';
import { FeedPrices } from '../types/FeedPrices';
import { OracleConfig } from '../types/OracleConfig';
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { SwapPath } from '../types/SwapPath';
import { SwapTree } from '../types/SwapTree';
import { CurrencyInfo } from '../types/CurrencyInfo';

/**
* An on-chain oracle providing market data prices to the rest of the system.
Expand Down Expand Up @@ -45,6 +46,10 @@ export class Oracle {
return await this.cosmWasmClient.queryContractSmart(this._contractAddress, getCurrencyPairsMsg());
}

public async getCurrencies(): Promise<CurrencyInfo[]> {
return await this.cosmWasmClient.queryContractSmart(this._contractAddress, getCurrenciesMsg());
}

public async getSwapPath(fromCurrency: string, toCurrency: string): Promise<SwapPath[]> {
return await this.cosmWasmClient.queryContractSmart(this._contractAddress, getSwapPathMsg(fromCurrency, toCurrency));
}
Expand Down
6 changes: 6 additions & 0 deletions src/contracts/messages/OracleMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export const getCurrencyPairsMsg = () => {
};
};

export const getCurrenciesMsg = () => {
return {
currencies: {},
};
};

export const getFeedersMsg = () => {
return {
feeders: {},
Expand Down
7 changes: 7 additions & 0 deletions src/contracts/types/CurrencyInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface CurrencyInfo {
bankSymbol: string,
decimalDigits: number,
dexSymbol: string,
group: string,
ticker: string
}
1 change: 1 addition & 0 deletions src/contracts/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export * from './CloseOngoingState';
export * from './Protocol';
export * from './ProtocolContracts';
export * from './PlatformContracts';
export * from './CurrencyInfo';
68 changes: 17 additions & 51 deletions src/utils/AssetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CURRENCIES_DEVNET from './currencies_devnet.json';
import CURRENCIES_TESTNET from './currencies_testnet.json';
// @ts-ignore
import CURRENCIES_MAINNET from './currencies_mainnet.json';
import { CurrencyInfo } from '../contracts/types/CurrencyInfo';

/**
* AssetUtils provides helpers for working with Nolus assets.
Expand All @@ -29,33 +30,28 @@ export class AssetUtils {
*
* The current method returns a list of tickers by group.
*/
public static getCurrenciesByGroup(group: GROUPS, currenciesData: NetworkData, protocol: string): string | string[] {
switch (group) {
case GROUPS.Native: {
return AssetUtils.getNative(currenciesData, protocol).key;
}
case GROUPS.Lease: {
return AssetUtils.getLease(currenciesData, protocol);
}
case GROUPS.Lpn: {
return AssetUtils.getLpn(currenciesData, protocol);
public static findTickersByGroup(currenciesInfo: CurrencyInfo[], group: string): string[] {
const tickers: string[] = [];

currenciesInfo.forEach(currencyInfo => {
if (currencyInfo.group === group) {
tickers.push(currencyInfo.ticker);
}
}
}
});

public static getCurrenciesByGroupTestnet(group: GROUPS, protocol: string): string[] | string {
const currenciesData = CURRENCIES_TESTNET;
return this.getCurrenciesByGroup(group, currenciesData, protocol);
return tickers;
}

public static getCurrenciesByGroupMainnet(group: GROUPS, protocol: string): string[] | string {
const currenciesData = CURRENCIES_MAINNET;
return this.getCurrenciesByGroup(group, currenciesData, protocol);
public static findDexSymbolByTicker(currenciesInfo: CurrencyInfo[], ticker: string): string | null {
const dexSymbol = currenciesInfo.find(currencyInfo => currencyInfo.ticker === ticker);

return dexSymbol ? dexSymbol.dexSymbol : null;
}

public static getCurrenciesByGroupDevnet(group: GROUPS, protocol: string): string[] | string {
const currenciesData = CURRENCIES_DEVNET;
return this.getCurrenciesByGroup(group, currenciesData, protocol);
public static findBankSymbolByTicker(currenciesInfo: CurrencyInfo[], ticker: string): string | null {
const bankSymbol = currenciesInfo.find(currencyInfo => currencyInfo.ticker === ticker);

return bankSymbol ? bankSymbol.dexSymbol : null;
}

/**
Expand Down Expand Up @@ -87,21 +83,6 @@ export class AssetUtils {
);
}

public static makeIBCMinimalDenomDevnet(ticker: string, network: Networks = Networks.NOLUS, protocol: string): string {
const currenciesData = CURRENCIES_DEVNET;
return this.makeIBCMinimalDenom(ticker, currenciesData, network, protocol);
}

public static makeIBCMinimalDenomTestnet(ticker: string, network: Networks = Networks.NOLUS, protocol: string): string {
const currenciesData = CURRENCIES_TESTNET;
return this.makeIBCMinimalDenom(ticker, currenciesData, network, protocol);
}

public static makeIBCMinimalDenomMainnet(ticker: string, network: Networks = Networks.NOLUS, protocol: string): string {
const currenciesData = CURRENCIES_MAINNET;
return this.makeIBCMinimalDenom(ticker, currenciesData, network, protocol);
}

public static getChannel(
channels: {
a: {
Expand Down Expand Up @@ -209,21 +190,6 @@ export class AssetUtils {
return AssetUtils.getAsset(ntwrks, native as string, ChainConstants.CHAIN_KEY as string, protocol);
}

public static getLpn(ntwrks: NetworkData, protocol: string) {
const pr = AssetUtils.getProtocol(ntwrks, protocol);
const lpn = pr.Lpn;
return lpn.dex_currency;
}

public static getLease(ntwrks: NetworkData, protocol: string) {
const pr = AssetUtils.getProtocol(ntwrks, protocol);
const lease = Object.keys(pr.Lease);
return lease.map((c) => {
const asset = AssetUtils.getAsset(ntwrks, c as string, ChainConstants.CHAIN_KEY as string, protocol);
return asset.key;
});
}

private static getProtocol(ntwrks: NetworkData, protocol: string) {
for (const key in ntwrks.protocols) {
if (key == protocol) {
Expand Down

0 comments on commit 008ac9b

Please sign in to comment.