Skip to content

Commit

Permalink
Merge pull request #215 from streamflow-finance/v7
Browse files Browse the repository at this point in the history
V7 Release
- staking
- CJS/ESM builds
  • Loading branch information
RolginRoman authored Oct 8, 2024
2 parents 0bfed01 + a3aa2b2 commit 528e941
Show file tree
Hide file tree
Showing 108 changed files with 11,934 additions and 5,913 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js 20
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/gh-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- master
- v6
- v7
- prerelease/v*

jobs:
tests:
Expand All @@ -14,7 +16,7 @@ jobs:
node-version: [18, 20]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/gh-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- v6
- v7
types: [closed]

permissions:
Expand All @@ -18,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js 20
Expand Down Expand Up @@ -53,6 +54,13 @@ jobs:
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish
if: steps.tag_check.outputs.exists_tag == 'false'
run: |
npm run publish
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Create Git Tag
if: steps.tag_check.outputs.exists_tag == 'false'
uses: pkgdeps/git-tag-action@v2
Expand All @@ -73,13 +81,6 @@ jobs:
${{ github.event.pull_request.body }}
draft: false
prerelease: false
- name: Publish
if: steps.tag_check.outputs.exists_tag == 'false'
run: |
npm run publish
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- uses: actions/github-script@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand Down
5 changes: 3 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
#!/bin/sh

. "$(dirname -- "$0")/_/husky.sh"

npm run lint
pnpm lint --parallel
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"useTabs": false
}
16 changes: 1 addition & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
{
"version": "1.0.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest: current file",
//"env": { "NODE_ENV": "test" },
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${fileBasenameNoExtension}", "--config", "jest.config.js"],
"console": "integratedTerminal",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
"configurations": []
}
27 changes: 14 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"prettier.requireConfig": true,
"eslint.enable": true,
"eslint.debug": false,
"eslint.workingDirectories": [
// Monorepo directories
{
"pattern": "./packages/*/"
}
],
"cSpell.words": [
"Streamflow"
]
}
"prettier.requireConfig": false,
"eslint.enable": true,
"eslint.debug": false,
"eslint.workingDirectories": [
// Monorepo directories
{
"pattern": "./packages/*/"
}
],
"cSpell.words": ["permissionless", "Solana", "Streamflow", "Unstake"],
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.importModuleSpecifierEnding": "js",
"javascript.preferences.importModuleSpecifierEnding": "js"
}
6 changes: 2 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"packages": [
"packages/*"
],
"version": "6.5.1",
"packages": ["packages/*"],
"version": "7.0.0-alpha.12",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,22 @@
"test": "lerna run test",
"lint": "lerna run lint",
"version-all": "lerna version --force-publish --no-git-tag-version --no-push",
"publish": "lerna publish from-package --yes",
"publish": "lerna publish from-package --yes --loglevel=verbose",
"local-publish": "lerna publish --no-git-tag-version --no-push --registry=\"http://localhost:4873/\" from-package --yes",
"local-unpublish": "lerna exec -- npm unpublish --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}@\\$(npm view \\$LERNA_PACKAGE_NAME version)\"",
"local-unpublish-all": "lerna exec -- npm unpublish -f --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}\"",
"prepare": "husky install"
"prepare": "husky install",
"convert-bn": "./scripts/convertBN.sh"
},
"devDependencies": {
"@types/eslint": "^8.56.3",
"@types/jest": "29.2.4",
"eslint": "^8.56.0",
"husky": "^8.0.0",
"jest": "^29.7.0",
"lerna": "7.4.2",
"lint-staged": "^13.1.0",
"ts-jest": "^29.1.1",
"typedoc": "0.25.11",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^2.0.5"
},
"version": "4.0.1"
}
5 changes: 3 additions & 2 deletions packages/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./types";
export * from "./utils";
export * from "./types.js";
export * from "./lib/assertions.js";
export * from "./lib/utils.js";
12 changes: 12 additions & 0 deletions packages/common/lib/assertions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const prefix = "Assertion failed";
export const invariant: (condition: any, message?: string | (() => string)) => asserts condition = (
condition,
message,
) => {
if (condition) {
return;
}
const provided: string | undefined = typeof message === "function" ? message() : message;
const value: string = provided ? `${prefix}: ${provided}` : prefix;
throw new Error(value);
};
4 changes: 3 additions & 1 deletion packages/common/utils.ts → packages/common/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BN from "bn.js";

import { ContractError } from "./types";
import { ContractError } from "../types.js";

/**
* Used for conversion of token amounts to their Big Number representation.
Expand Down Expand Up @@ -58,3 +58,5 @@ export async function handleContractError<T>(
export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export const divCeilN = (n: bigint, d: bigint): bigint => n / d + (n % d ? BigInt(1) : BigInt(0));
33 changes: 17 additions & 16 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{
"name": "@streamflow/common",
"version": "6.5.1",
"version": "7.0.0-alpha.12",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"type": "module",
"exports": {
".": "./dist/index.js",
"./solana": "./dist/solana/index.js"
},
"typesVersions": {
"*": {
"solana": [
"dist/solana/index.d.ts"
]
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/esm/index.d.ts"
},
"./solana": {
"import": "./dist/esm/solana/index.js",
"require": "./dist/cjs/solana/index.js",
"types": "./dist/esm/solana/index.d.ts"
}
},
"scripts": {
"build": "rm -rf dist; tsc -p tsconfig.json",
"build:cjs": "rm -rf dist/cjs; tsc -p tsconfig.cjs.json",
"build:esm": "rm -rf dist/esm; tsc -p tsconfig.esm.json",
"build": "rm -rf dist; pnpm run build:cjs && pnpm run build:esm",
"pack": "pnpm build && pnpm pack",
"lint": "eslint --fix .",
"lint-config": "eslint --print-config",
Expand All @@ -27,10 +31,7 @@
"devDependencies": {
"@streamflow/eslint-config": "workspace:*",
"@types/bn.js": "5.1.1",
"@types/jest": "29.2.4",
"date-fns": "2.28.0",
"jest": "29.3.1",
"ts-jest": "29.0.3",
"typescript": "^4.9.5"
},
"dependencies": {
Expand All @@ -43,6 +44,6 @@
"bn.js": "5.2.1",
"borsh": "^2.0.0",
"bs58": "5.0.0",
"p-queue": "^6.6.2"
"p-queue": "^8.0.1"
}
}
20 changes: 20 additions & 0 deletions packages/common/solana/account-filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MemcmpFilter, PublicKey } from "@solana/web3.js";

export const getFilters = <T extends Record<string, number | PublicKey>>(
criteria: T,
byteOffsets: Record<keyof T, number>,
): MemcmpFilter[] => {
return Object.entries(criteria).reduce((acc, [key, value]) => {
const criteriaKey = key as keyof typeof criteria;
const effectiveByteOffset = byteOffsets[criteriaKey];
if (criteria[criteriaKey] && effectiveByteOffset) {
acc.push({
memcmp: {
offset: effectiveByteOffset,
bytes: value.toString(),
},
});
}
return acc;
}, [] as MemcmpFilter[]);
};
8 changes: 5 additions & 3 deletions packages/common/solana/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./instructions";
export * from "./types";
export * from "./utils";
export * from "./account-filters.js";
export * from "./instructions.js";
export * from "./public-key.js";
export * from "./types.js";
export * from "./utils.js";
2 changes: 1 addition & 1 deletion packages/common/solana/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
getAssociatedTokenAddress,
NATIVE_MINT,
createAssociatedTokenAccountInstruction,
createSyncNativeInstruction,
getAssociatedTokenAddress,
} from "@solana/spl-token";
import { Connection, PublicKey, SystemProgram, TransactionInstruction } from "@solana/web3.js";
import BN from "bn.js";
Expand Down
5 changes: 5 additions & 0 deletions packages/common/solana/public-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PublicKey } from "@solana/web3.js";

export const pk = (address: string | PublicKey): PublicKey => {
return typeof address === "string" ? new PublicKey(address) : address;
};
8 changes: 4 additions & 4 deletions packages/common/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import {
ITransactionSolanaExt,
ThrottleParams,
TransactionFailedError,
} from "./types";
import { sleep } from "../utils";
} from "./types.js";
import { sleep } from "../lib/utils.js";

const SIMULATE_TRIES = 3;

Expand Down Expand Up @@ -256,7 +256,7 @@ export async function sendAndConfirmTransaction(

let signature: string;
if (isVersioned) {
signature = bs58.encode(tx.signatures[0]);
signature = bs58.encode(tx.signatures[0]!);
} else {
signature = bs58.encode(tx.signature!);
}
Expand Down Expand Up @@ -515,7 +515,7 @@ export async function checkOrCreateAtaBatch(
const response = await connection.getMultipleAccountsInfo(atas);
for (let i = 0; i < response.length; i++) {
if (!response[i]) {
ixs.push(createAssociatedTokenAccountInstruction(invoker.publicKey!, atas[i], owners[i], mint, programId));
ixs.push(createAssociatedTokenAccountInstruction(invoker.publicKey!, atas[i]!, owners[i]!, mint, programId));
}
}
return ixs;
Expand Down
6 changes: 6 additions & 0 deletions packages/common/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.cjs.json",
"compilerOptions": {
"outDir": "./dist/cjs"
}
}
6 changes: 6 additions & 0 deletions packages/common/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"outDir": "./dist/esm"
}
}
6 changes: 0 additions & 6 deletions packages/common/tsconfig.json

This file was deleted.

11 changes: 3 additions & 8 deletions packages/common/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"extends": [
"../../typedoc.base.json"
],
"entryPoints": [
"./index.ts",
"./solana/index.ts",
]
}
"extends": ["../../typedoc.base.json"],
"entryPoints": ["./index.ts", "./solana/index.ts"]
}
3 changes: 1 addition & 2 deletions packages/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TransactionInstruction } from "@solana/web3.js";
import { Types } from "aptos";

export interface ITransactionResult {
ixs: (TransactionInstruction | Types.TransactionPayload)[];
ixs: TransactionInstruction[];
txId: string;
}

Expand Down
Loading

0 comments on commit 528e941

Please sign in to comment.