Skip to content

Commit

Permalink
Add Publish Workflow (#30)
Browse files Browse the repository at this point in the history
Preparing workflow to publish to npm
  • Loading branch information
bh2smith authored Aug 15, 2024
1 parent 3ec05ee commit bfa8030
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 38 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: NPM Publish

on:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Build & Set Package Version to Tag
run: |
yarn --frozen-lockfile
yarn build
VERSION=${GITHUB_REF#refs/tags/}
npm version $VERSION --no-git-tag-version
- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
{
"name": "near-safe",
"version": "0.0.0",
"module": "index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"keywords": [
"near",
"ethereum",
"safe",
"account-abstraction",
"erc4337",
"chain-signatures"
],
"main": "dist/cjs/index.js",
"module": "dist/cjs/index.js",
"types": "dist/esm/index.d.ts",
"files": [
"dist/**/*"
],
"private": true,
"scripts": {
"build": "rm -rf ./dist && tsc",
"build": "rm -fr dist/* && yarn build:esm && yarn build:cjs",
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"start": "yarn example",
"example": "tsx examples/send-tx.ts",
"lint": "eslint . --ignore-pattern dist/",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./tx-manager.js";
export * from "./types.js";
export * from "./util.js";
export * from "./tx-manager";
export * from "./types";
export * from "./util";
4 changes: 2 additions & 2 deletions src/lib/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
UnsignedUserOperation,
UserOperation,
UserOperationReceipt,
} from "../types.js";
import { PLACEHOLDER_SIG } from "../util.js";
} from "../types";
import { PLACEHOLDER_SIG } from "../util";

export class Erc4337Bundler {
provider: ethers.JsonRpcProvider;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
getSafe4337ModuleDeployment,
getSafeModuleSetupDeployment,
} from "@safe-global/safe-modules-deployments";
import { PLACEHOLDER_SIG, packGas, packPaymasterData } from "../util.js";
import { PLACEHOLDER_SIG, packGas, packPaymasterData } from "../util";
import {
GasPrice,
PaymasterData,
UnsignedUserOperation,
UserOperation,
} from "../types.js";
} from "../types";
import { MetaTransaction } from "ethers-multisend";

/**
Expand Down
15 changes: 9 additions & 6 deletions src/tx-manager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ethers } from "ethers";
import { NearEthAdapter, MpcContract } from "near-ca";
import { Erc4337Bundler } from "./lib/bundler.js";
import { packSignature } from "./util.js";
import { getNearSignature } from "./lib/near.js";
import { UserOperation, UserOperationReceipt, UserOptions } from "./types.js";
import { Erc4337Bundler } from "./lib/bundler";
import { packSignature } from "./util";
import { getNearSignature } from "./lib/near";
import { UserOperation, UserOperationReceipt, UserOptions } from "./types";
import { MetaTransaction, encodeMulti } from "ethers-multisend";
import { ContractSuite } from "./lib/safe.js";
import { ContractSuite } from "./lib/safe";
import { Account } from "near-api-js";

export class TransactionManager {
Expand Down Expand Up @@ -98,8 +98,11 @@ export class TransactionManager {
const gasFees = (await this.bundler.getGasPrice()).fast;
// const gasFees = await this.provider.getFeeData();
// Build Singular MetaTransaction for Multisend from transaction list.
if (transactions.length === 0) {
throw new Error("Empty transaction set!");
}
const tx =
transactions.length > 1 ? encodeMulti(transactions) : transactions[0];
transactions.length > 1 ? encodeMulti(transactions) : transactions[0]!;
const rawUserOp = await this.safePack.buildUserOp(
tx,
this.safeAddress,
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from "ethers";
import { PaymasterData } from "./types.js";
import { PaymasterData } from "./types";
import { MetaTransaction } from "ethers-multisend";

export const PLACEHOLDER_SIG = ethers.solidityPacked(
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
}
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"outDir": "dist/esm",
}
}
41 changes: 22 additions & 19 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ES6",
"moduleResolution": "Node",
"esModuleInterop": true,

/* Emit */
"declaration": true,
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,

/* Type Checking */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"esModuleInterop": true,

/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
// Best practices
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
"strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
"strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
"strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
"useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
"exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
"noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// TODO: Add this back!
// "noUncheckedIndexedAccess": true,
"noPropertyAccessFromIndexSignature": false,
"skipLibCheck": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "examples", "tests", "eslint.config.cjs"]
}
}

0 comments on commit bfa8030

Please sign in to comment.