Skip to content

Commit

Permalink
feat(sol): sol-utils package
Browse files Browse the repository at this point in the history
added solana utils module to have shared logic related to solana
  • Loading branch information
sogunshola committed Jul 24, 2022
1 parent 2edb1c1 commit ed75131
Show file tree
Hide file tree
Showing 33 changed files with 128 additions and 16 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 packages/core/src/Config/MoralisConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SolNetworkish } from '../dataTypes';
import { CoreConfig } from './CoreConfig';
import { SolNetworkish } from './interfaces';

// @moralisweb3/core
type CoreConfigType = typeof CoreConfig;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Config';
export * from './CoreConfig';
export * from './MoralisConfig';
export * from './interfaces';
10 changes: 10 additions & 0 deletions packages/core/src/Config/interfaces/SolNetworkish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Note this is just an interface, used in the core config.
* The implementations are located in the @moralisweb3/sol-utils package.
*/

export interface SolNetworkable {
network: string;
}

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
@@ -0,0 +1 @@
export * from './SolNetworkish';
3 changes: 0 additions & 3 deletions packages/core/src/dataTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ export * from './EvmAddress';
export * from './EvmNative';
export * from './EvmTransaction';
export * from './EvmTransactionLog';
export * from './SolNetwork';
export * from './SolAddress';
export * from './SolNative';
export * from './tokens';
export * from './abstract';
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": "^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';
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';
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';
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';
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';
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'),
};
2 changes: 2 additions & 0 deletions packages/solUtils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @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'),
};
34 changes: 34 additions & 0 deletions packages/solUtils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"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": {
"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/**/*"]
}

0 comments on commit ed75131

Please sign in to comment.