Skip to content

Commit

Permalink
Merge pull request #523 from MoralisWeb3/feat/solUtils
Browse files Browse the repository at this point in the history
feat(sol): sol-utils package
  • Loading branch information
sogunshola authored Jul 25, 2022
2 parents 5952bf4 + 4a62e2c commit 532234d
Show file tree
Hide file tree
Showing 36 changed files with 661 additions and 1,193 deletions.
7 changes: 7 additions & 0 deletions .changeset/early-points-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/core': major
'@moralisweb3/sol-api': major
'@moralisweb3/sol-utils': major
---

Adding solUtils package to codebase.
2 changes: 1 addition & 1 deletion demos/test-node/src/SolApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SolNetworkName } from '@moralisweb3/core';
import { SolNetworkName } from '@moralisweb3/sol-utils';
import Moralis from 'moralis';
import { smokeTest } from './Tester';

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
// Map workspaces to their source code so that Jest can resolve them correctly.
moduleNameMapper: {
'^@moralisweb3/evm-api': '<rootDir>/../evmApi/src',
'^@moralisweb3/sol-utils': '<rootDir>/../solUtils/src',
'^@moralisweb3/evm-utils': '<rootDir>/../evmUtils/src',
'^@moralisweb3/api-utils': '<rootDir>/../apiUtils/src',
'^@moralisweb3/core': '<rootDir>/../core/src',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Config/MoralisConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SolNetworkish } from '../dataTypes';
import { SolNetworkish } from './interfaces';
import { CoreConfig, EvmAddressFormat, EvmChainIdFormat } from './CoreConfig';
import { EvmChainish } from './interfaces/EvmChainish';

Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/Config/interfaces/SolNetworkish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Note this is just an interface, used in the core config.
* The implementations are located in the @moralisweb3/sol-utils package.
*/

export const solNetworkNames = ['mainnet', 'devnet'] as const;

export type SolNetworkName = typeof solNetworkNames[number];

export interface SolNetworkable {
network: SolNetworkName;
}

export type SolNetworkish = SolNetworkable | string;
1 change: 1 addition & 0 deletions packages/core/src/Config/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './SolNetworkish';
export * from './EvmChainish';
3 changes: 0 additions & 3 deletions packages/core/src/dataTypes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export * from './SolNetwork';
export * from './SolAddress';
export * from './SolNative';
export * from './abstract';
4 changes: 3 additions & 1 deletion packages/moralis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MoralisApiUtils } from '@moralisweb3/api-utils';
import { MoralisAuth } from '@moralisweb3/auth';
import { MoralisEvmUtils } from '@moralisweb3/evm-utils';
import { MoralisEvmApi } from '@moralisweb3/evm-api';
import { MoralisSolUtils } from '@moralisweb3/sol-utils';
import { MoralisSolApi } from '@moralisweb3/sol-api';
import { MoralisCoreProvider } from '@moralisweb3/core';

Expand All @@ -15,10 +16,11 @@ const apiUtils = MoralisApiUtils.create(core);
// Feature modules
const auth = MoralisAuth.create(core);
const evmApi = MoralisEvmApi.create(core);
const solUtils = MoralisSolUtils.create(core);
const solApi = MoralisSolApi.create(core);

// Register all Moralis modules to MoralisCore
core.registerModules([evmUtils, auth, apiUtils, evmApi, solApi]);
core.registerModules([evmUtils, solUtils, auth, apiUtils, evmApi, solApi]);

const Moralis = {
Core: core,
Expand Down
1 change: 1 addition & 0 deletions packages/solApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@moralisweb3/api-utils": "^2.0.0-alpha.2",
"@moralisweb3/core": "^2.0.0-alpha.2",
"@moralisweb3/sol-utils": "^2.0.0-alpha.2",
"ethers": "^5.6.2"
}
}
3 changes: 2 additions & 1 deletion packages/solApi/src/config/SolApiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigKey, SolNetworkish } from '@moralisweb3/core/lib';
import { SolNetworkish } from '@moralisweb3/sol-utils';
import { ConfigKey } from '@moralisweb3/core';

export const SolApiConfig = {
defaultSolNetwork: {
Expand Down
3 changes: 2 additions & 1 deletion packages/solApi/src/resolvers/SolNetworkResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MoralisCoreProvider, SolNetwork, SolNetworkish, SolNetworkName } from '@moralisweb3/core';
import { MoralisCoreProvider } from '@moralisweb3/core';
import { SolNetwork, SolNetworkish, SolNetworkName } from '@moralisweb3/sol-utils';
import { SolApiConfig } from '../config/SolApiConfig';

export class SolNetworkResolver {
Expand Down
3 changes: 2 additions & 1 deletion packages/solApi/src/resolvers/account/getBalance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiResolver } from '@moralisweb3/api-utils';
import { Camelize, SolAddress, SolAddressish, SolNetworkish, SolNative } from '@moralisweb3/core';
import { Camelize } from '@moralisweb3/core';
import { SolAddress, SolAddressish, SolNetworkish, SolNative } from '@moralisweb3/sol-utils';
import { operations } from '../../generated/types';
import { BASE_URL } from '../../MoralisSolApi';
import { SolNetworkResolver } from '../SolNetworkResolver';
Expand Down
3 changes: 2 additions & 1 deletion packages/solApi/src/resolvers/account/getNFTs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiResolver } from '@moralisweb3/api-utils';
import { Camelize, SolAddress, SolAddressish, SolNetworkish } from '@moralisweb3/core';
import { Camelize } from '@moralisweb3/core';
import { SolAddress, SolAddressish, SolNetworkish } from '@moralisweb3/sol-utils';
import { operations } from '../../generated/types';
import { BASE_URL } from '../../MoralisSolApi';
import { SolNetworkResolver } from '../SolNetworkResolver';
Expand Down
3 changes: 2 additions & 1 deletion packages/solApi/src/resolvers/account/getPortfolio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiResolver } from '@moralisweb3/api-utils';
import { Camelize, SolAddress, SolAddressish, SolNative, SolNetworkish } from '@moralisweb3/core';
import { Camelize } from '@moralisweb3/core';
import { SolAddress, SolAddressish, SolNative, SolNetworkish } from '@moralisweb3/sol-utils';
import { operations } from '../../generated/types';
import { BASE_URL } from '../../MoralisSolApi';
import { SolNetworkResolver } from '../SolNetworkResolver';
Expand Down
3 changes: 2 additions & 1 deletion packages/solApi/src/resolvers/account/getSPL.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiResolver } from '@moralisweb3/api-utils';
import { Camelize, SolAddress, SolAddressish, SolNative, SolNetworkish } from '@moralisweb3/core';
import { Camelize } from '@moralisweb3/core';
import { SolAddress, SolAddressish, SolNative, SolNetworkish } from '@moralisweb3/sol-utils';
import { operations } from '../../generated/types';
import { BASE_URL } from '../../MoralisSolApi';
import { SolNetworkResolver } from '../SolNetworkResolver';
Expand Down
3 changes: 2 additions & 1 deletion packages/solApi/src/resolvers/nft/getNFTMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiResolver } from '@moralisweb3/api-utils';
import { Camelize, SolAddress, SolAddressish, SolNetworkish } from '@moralisweb3/core';
import { Camelize } from '@moralisweb3/core';
import { SolAddress, SolAddressish, SolNetworkish } from '@moralisweb3/sol-utils';
import { operations } from '../../generated/types';
import { BASE_URL } from '../../MoralisSolApi';
import { SolNetworkResolver } from '../SolNetworkResolver';
Expand Down
Empty file added packages/solUtils/.eslintrc
Empty file.
10 changes: 10 additions & 0 deletions packages/solUtils/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CHANGELOG.md

# Output folders
lib/**/*
dist
coverage/
lib.esm
node_modules

src/generated
3 changes: 3 additions & 0 deletions packages/solUtils/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../.prettierrc'),
};
1 change: 1 addition & 0 deletions packages/solUtils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @moralisweb3/sol-utils
3 changes: 3 additions & 0 deletions packages/solUtils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../jest.config'),
};
37 changes: 37 additions & 0 deletions packages/solUtils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@moralisweb3/sol-utils",
"author": "Moralis",
"version": "2.0.0-alpha.2",
"license": "MIT",
"private": false,
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"files": [
"lib/index.*",
"lib/**/*.d.ts",
"dist"
],
"scripts": {
"test": "yarn jest --runInBand --detectOpenHandles --forceExit --ci",
"test:coverage": "yarn run test --coverage",
"test:watch": "yarn run test --watch",
"format": "prettier . \"**/*.+(js|ts|json)\" --write",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"format:check": "prettier . \"**/*.+(js|ts|json)\" --check",
"clean": "rm -rf lib && rm -rf lib.esm && rm -rf tsconfig.tsbuildinfo",
"gen:types": "openapi-typescript https://solana-gateway.moralis.io/api-json/ --output src/generated/types.ts",
"build": "tsc",
"dev": "tsc --watch"
},
"devDependencies": {
"openapi-typescript": "^5.2.0",
"prettier": "^2.5.1",
"typescript": "^4.5.5"
},
"dependencies": {
"@ethersproject/bignumber": "^5.6.0",
"@ethersproject/units": "^5.6.0",
"@moralisweb3/core": "^2.0.0-alpha.2"
}
}
21 changes: 21 additions & 0 deletions packages/solUtils/src/MoralisSolUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import MoralisCore, { Module, MoralisCoreProvider } from '@moralisweb3/core';

export class MoralisSolUtils extends Module {
public static readonly moduleName = 'evmUtils';

public static create(core?: MoralisCore): MoralisSolUtils {
return new MoralisSolUtils(core ?? MoralisCoreProvider.getDefault());
}

private constructor(core: MoralisCore) {
super(MoralisSolUtils.moduleName, core);
}

public setup() {
// Nothing
}

public start() {
// Nothing
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoralisData, MoralisDataFormatted } from './abstract';
import { MoralisData, MoralisDataFormatted } from '@moralisweb3/core';

export type SolAddressish = SolAddress | string;

Expand Down
1 change: 1 addition & 0 deletions packages/solUtils/src/dataTypes/SolAddress/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SolAddress';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BigNumber, BigNumberish, parseFixed } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { CoreErrorCode, MoralisCoreError } from '../Error';
import { MoralisData, MoralisDataFormatted } from './abstract';
import { MoralisData, MoralisDataFormatted, CoreErrorCode, MoralisCoreError } from '@moralisweb3/core';

export type SolNativeUnit = 'solana' | 'lamports' | number;

Expand Down
1 change: 1 addition & 0 deletions packages/solUtils/src/dataTypes/SolNative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SolNative';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CoreErrorCode, MoralisCoreError } from '../Error';
import { MoralisData, MoralisDataFormatted } from './abstract';
import { MoralisData, MoralisDataFormatted, CoreErrorCode, MoralisCoreError } from '@moralisweb3/core';

const solNetworkNames = ['mainnet', 'devnet'] as const;

Expand Down
1 change: 1 addition & 0 deletions packages/solUtils/src/dataTypes/SolNetwork/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SolNetwork';
3 changes: 3 additions & 0 deletions packages/solUtils/src/dataTypes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './SolAddress';
export * from './SolNetwork';
export * from './SolNative';
2 changes: 2 additions & 0 deletions packages/solUtils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './dataTypes';
export * from './MoralisSolUtils';
9 changes: 9 additions & 0 deletions packages/solUtils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.package.json",
"compilerOptions": {
"outDir": "./lib",
"declarationDir": "./lib/",
"rootDir": "./src"
},
"include": ["src/**/*", "types/**/*"]
}
Loading

0 comments on commit 532234d

Please sign in to comment.