Skip to content

Commit

Permalink
Merge pull request #66 from nolus-protocol/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.0 - cosmos-sdk v0.47 and nolus-money-market v0.4 compatibility
  • Loading branch information
desislavva authored Dec 14, 2023
2 parents 35623db + 0bcc735 commit 73015e4
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 175 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"rules": {
"node/no-extraneous-import": "off",
"node/no-missing-import": "off",
"node/no-unsupported-features/es-syntax": "off"
"node/no-unsupported-features/es-syntax": "off",
"@typescript-eslint/no-explicit-any": "warn"
},
"parserOptions": {
"ecmaVersion": 2018,
Expand Down
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
"name": "@nolus/nolusjs",
"author": "Nolabs",
"license": "Apache-2.0",
"version": "1.0.9",
"version": "2.0.0",
"description": "JS library for NodeJS and Web browsers to interact with the Nolus Protocol",
"engines": {
"node": ">=14.0.0"
},
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down Expand Up @@ -33,15 +36,15 @@
},
"homepage": "https://github.com/N-Stealth/nolusjs#readme",
"dependencies": {
"@cosmjs/cosmwasm-stargate": "0.31.3",
"@cosmjs/crypto": "0.31.3",
"@cosmjs/encoding": "0.31.3",
"@cosmjs/ledger-amino": "0.31.3",
"@cosmjs/proto-signing": "0.31.3",
"@cosmjs/stargate": "0.31.3",
"@cosmjs/tendermint-rpc": "0.31.3",
"@keplr-wallet/crypto": "0.12.12",
"@keplr-wallet/unit": "0.12.12",
"@cosmjs/cosmwasm-stargate": "0.32.1",
"@cosmjs/crypto": "0.32.1",
"@cosmjs/encoding": "0.32.1",
"@cosmjs/ledger-amino": "0.32.1",
"@cosmjs/proto-signing": "0.32.1",
"@cosmjs/stargate": "0.32.1",
"@cosmjs/tendermint-rpc": "0.32.1",
"@keplr-wallet/crypto": "0.12.46",
"@keplr-wallet/unit": "0.12.46",
"@ledgerhq/hw-app-cosmos": "^6.28.5",
"@ledgerhq/hw-transport-webhid": "^6.27.19",
"@ledgerhq/hw-transport-webusb": "^6.27.19",
Expand All @@ -61,6 +64,6 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.0.3",
"typescript": "5.2.2"
"typescript": "5.3.2"
}
}
8 changes: 4 additions & 4 deletions src/client/NolusClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { CometClient, connectComet } from '@cosmjs/tendermint-rpc';
import { Coin } from '@cosmjs/proto-signing';
import { StargateClient } from '@cosmjs/stargate';

Expand All @@ -17,12 +17,12 @@ import { StargateClient } from '@cosmjs/stargate';
export class NolusClient {
private static instance: NolusClient | null = null;
protected cosmWasmClient: Promise<CosmWasmClient> | undefined;
protected tmClient: Promise<Tendermint34Client> | undefined;
protected tmClient: Promise<CometClient> | undefined;
protected stargateClient: Promise<StargateClient> | undefined;

private constructor(tendermintRpc: string) {
this.cosmWasmClient = CosmWasmClient.connect(tendermintRpc);
this.tmClient = Tendermint34Client.connect(tendermintRpc);
this.tmClient = connectComet(tendermintRpc);
this.stargateClient = StargateClient.connect(tendermintRpc);
}

Expand Down Expand Up @@ -53,7 +53,7 @@ export class NolusClient {
return client;
}

public async getTendermintClient(): Promise<Tendermint34Client> {
public async getTendermintClient(): Promise<CometClient> {
const client = await this.tmClient;
if (!client) {
throw new Error('Missing Tendermint client');
Expand Down
2 changes: 1 addition & 1 deletion src/constants/ChainConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ChainConstants {
public static readonly COIN_DENOM: string = 'NLS';
public static readonly COIN_MINIMAL_DENOM: string = 'unls';
public static readonly COIN_DECIMALS: number = 6;
public static readonly COIN_GECKO_ID: string = 'cosmos';
public static readonly COIN_GECKO_ID: string = 'nolus';
public static readonly COIN_TYPE: number = 118;
public static readonly IBC_TRANSFER_TIMEOUT: number = 60;

Expand Down
34 changes: 34 additions & 0 deletions src/contracts/clients/Admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { getProtocolsMsg, getProtocolMsg } from '../messages';
import { Protocol } from '../types';

/**
* The Admin contract is a contract that governs the storing and migration process of all smart contracts on the blockchain.
*
* Usage:
*
* ```ts
* import { NolusClient, NolusContracts } from '@nolus/nolusjs';
*
* const cosm = await NolusClient.getInstance().getCosmWasmClient();
* adminInstance = new NolusContracts.Admin(cosm, adminContractAddress);
* ```
*
*/
export class Admin {
private cosmWasmClient!: CosmWasmClient;
private _contractAddress: string;

constructor(cosmWasmClient: CosmWasmClient, contractAddress: string) {
this.cosmWasmClient = cosmWasmClient;
this._contractAddress = contractAddress;
}

public async getProtocols(): Promise<string[]> {
return await this.cosmWasmClient.queryContractSmart(this._contractAddress, getProtocolsMsg());
}

public async getProtocol(protocol: string): Promise<Protocol> {
return await this.cosmWasmClient.queryContractSmart(this._contractAddress, getProtocolMsg(protocol));
}
}
40 changes: 0 additions & 40 deletions src/contracts/clients/Treasury.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/contracts/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export * from './Lease';
export * from './Leaser';
export * from './Lpp';
export * from './Oracle';
export * from './Treasury';
export * from './Dispatcher';
export * from './Admin';
13 changes: 13 additions & 0 deletions src/contracts/messages/AdminMsg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const getProtocolsMsg = () => {
return {
protocols: {},
};
};

export const getProtocolMsg = (protocolName: string) => {
return {
protocol: {
protocol: protocolName,
},
};
};
9 changes: 0 additions & 9 deletions src/contracts/messages/TreasuryMsg.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/contracts/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export * from './LeaseMsg';
export * from './LeaserMsg';
export * from './LppMsg';
export * from './OracleMsg';
export * from './TreasuryMsg';
export * from './DispatcherMsg';
export * from './AdminMsg';
2 changes: 1 addition & 1 deletion src/contracts/types/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Asset {
amount: string;
ticker: string;
ticker?: string;
}
2 changes: 1 addition & 1 deletion src/contracts/types/LeasePositionSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { Asset } from './Asset';
export interface LeasePositionSpec {
liability: Liability;
min_asset: Asset;
min_sell_asset: Asset;
min_transaction: Asset;
}
1 change: 0 additions & 1 deletion src/contracts/types/LoanInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Asset } from './Asset';

export interface LoanInfo {
principal_due: Asset;
interest_due: Asset;
annual_interest_rate: number;
interest_paid: number;
}
7 changes: 2 additions & 5 deletions src/contracts/types/OracleConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { OraclePriceConfig } from './OraclePriceConfig';

export interface OracleConfig {
config: {
base_asset: string;
price_config: OraclePriceConfig;
};
owner: string;
base_asset: string;
price_config: OraclePriceConfig;
}
6 changes: 6 additions & 0 deletions src/contracts/types/Protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ProtocolContracts } from './ProtocolContracts';

export interface Protocol {
contracts: ProtocolContracts;
network: string;
}
6 changes: 6 additions & 0 deletions src/contracts/types/ProtocolContracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface ProtocolContracts {
leaser: string;
lpp: string;
oracle: string;
profit: string;
}
2 changes: 2 additions & 0 deletions src/contracts/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export * from './LiquidationOngoingState';
export * from './DEX';
export * from './LeasePositionSpec';
export * from './CloseOngoingState';
export * from './Protocol';
export * from './ProtocolContracts';
62 changes: 40 additions & 22 deletions src/types/Networks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Networks {
export interface NetworkData {
networks: {
list: {
[key: string]: {
Expand All @@ -9,41 +9,43 @@ export interface Networks {
};
channels: {
a: {
network: string;
network: Networks;
ch: string;
};
b: {
network: string;
network: Networks;
ch: string;
};
}[];
};
lease: {
Lpn:
| {
[key: string]: object;
}
| string[];
Lease: {
[key: string]: {
protocols: {
[key: string]: {
DexNetwork: string,
Lpn: {
"dex_currency": string;
};
Lease: {
[key: string]: {
"dex_currency": string;
swap_routes: Array<
{
pool_id: string;
pool_token: string;
}[]
>;
};
};
Native: {
"dex_currency": string;
swap_routes: Array<
{
pool_id: string;
pool_token: string;
}[]
>;
};
};
Native: {
id: string;
swap_routes: Array<
{
pool_id: string;
pool_token: string;
}[]
>;
};
};
}
}
definitions: string[];
}

Expand Down Expand Up @@ -82,3 +84,19 @@ export enum GROUPS {
Lease = 'lease',
Native = 'native',
}

export enum Protocols {
osmosis = 'OSMOSIS',
neutron = 'NEUTRON',
}

export enum Networks {
NOLUS = 'NOLUS',
OSMOSIS = 'OSMOSIS',
AXELAR = 'AXELAR',
COSMOS_HUB = 'COSMOS_HUB',
AKASH = 'AKASH',
JUNO = 'JUNO',
NEUTRON = 'NEUTRON',
DYDX = 'DYDX'
}
Loading

0 comments on commit 73015e4

Please sign in to comment.