-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparing Project as NPM Package (#23)
- add tsconfig with a bunch of standard stuff. - make index an export * file - move the former main script to examples and - update the package json accordingly. Issues Encountered: Many Issues were encountered. Mostly involving CommonJS, ESModules and our dependency near-ca (which has since been updated to support both). We also had painful problems with ts-node and now use tsx instead (it is wonderful 🥇 )
- Loading branch information
Showing
13 changed files
with
715 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
.env | ||
dist/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import dotenv from "dotenv"; | ||
import { ethers } from "ethers"; | ||
import { loadArgs } from "./cli"; | ||
import { TransactionManager } from "../src"; | ||
|
||
dotenv.config(); | ||
|
||
async function main(): Promise<void> { | ||
const options = await loadArgs(); | ||
const txManager = await TransactionManager.create({ | ||
ethRpc: process.env.ETH_RPC!, | ||
erc4337BundlerUrl: process.env.ERC4337_BUNDLER_URL!, | ||
safeSaltNonce: options.safeSaltNonce, | ||
}); | ||
const transactions = [ | ||
// TODO: Replace dummy transaction with real user transaction. | ||
{ | ||
to: "0xbeef4dad00000000000000000000000000000000", | ||
value: "0", // 0 value transfer with non-trivial data. | ||
data: "0xbeef", | ||
}, | ||
]; | ||
// Add Recovery if safe not deployed & recoveryAddress was provided. | ||
if (txManager.safeNotDeployed && options.recoveryAddress) { | ||
const recoveryTx = txManager.addOwnerTx(options.recoveryAddress); | ||
// This would happen (sequentially) after the userTx, but all executed in a single | ||
transactions.push(recoveryTx); | ||
} | ||
|
||
const { unsignedUserOp, safeOpHash } = await txManager.buildTransaction({ | ||
transactions, | ||
options, | ||
}); | ||
console.log("Unsigned UserOp", unsignedUserOp); | ||
console.log("Safe Op Hash", safeOpHash); | ||
|
||
// TODO: Evaluate gas cost (in ETH) | ||
const gasCost = ethers.parseEther("0.01"); | ||
// Whenever not using paymaster, or on value transfer, the Safe must be funded. | ||
const sufficientFunded = await txManager.safeSufficientlyFunded( | ||
transactions, | ||
options.usePaymaster ? 0n : gasCost | ||
); | ||
if (!sufficientFunded) { | ||
console.warn( | ||
`Safe ${txManager.safeAddress} insufficiently funded to perform this transaction. Exiting...` | ||
); | ||
process.exit(0); // soft exit with warning! | ||
} | ||
|
||
console.log("Signing with Near..."); | ||
const signature = await txManager.signTransaction(safeOpHash); | ||
|
||
console.log("Executing UserOp..."); | ||
const userOpReceipt = await txManager.executeTransaction({ | ||
...unsignedUserOp, | ||
signature, | ||
}); | ||
console.log("userOp Receipt", userOpReceipt); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exitCode = 1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,3 @@ | ||
import dotenv from "dotenv"; | ||
import { TransactionManager } from "./tx-manager"; | ||
import { loadArgs } from "./cli"; | ||
import { ethers } from "ethers"; | ||
|
||
dotenv.config(); | ||
|
||
async function main(): Promise<void> { | ||
const options = await loadArgs(); | ||
const txManager = await TransactionManager.create({ | ||
ethRpc: process.env.ETH_RPC!, | ||
erc4337BundlerUrl: process.env.ERC4337_BUNDLER_URL!, | ||
safeSaltNonce: options.safeSaltNonce, | ||
}); | ||
const transactions = [ | ||
// TODO: Replace dummy transaction with real user transaction. | ||
{ | ||
to: "0xbeef4dad00000000000000000000000000000000", | ||
value: "0", // 0 value transfer with non-trivial data. | ||
data: "0xbeef", | ||
}, | ||
]; | ||
// Add Recovery if safe not deployed & recoveryAddress was provided. | ||
if (txManager.safeNotDeployed && options.recoveryAddress) { | ||
const recoveryTx = txManager.addOwnerTx(options.recoveryAddress); | ||
// This would happen (sequentially) after the userTx, but all executed in a single | ||
transactions.push(recoveryTx); | ||
} | ||
|
||
const { unsignedUserOp, safeOpHash } = await txManager.buildTransaction({ | ||
transactions, | ||
options, | ||
}); | ||
console.log("Unsigned UserOp", unsignedUserOp); | ||
console.log("Safe Op Hash", safeOpHash); | ||
|
||
// TODO: Evaluate gas cost (in ETH) | ||
const gasCost = ethers.parseEther("0.01"); | ||
// Whenever not using paymaster, or on value transfer, the Safe must be funded. | ||
const sufficientFunded = await txManager.safeSufficientlyFunded( | ||
transactions, | ||
options.usePaymaster ? 0n : gasCost | ||
); | ||
if (!sufficientFunded) { | ||
console.warn( | ||
`Safe ${txManager.safeAddress} insufficiently funded to perform this transaction. Exiting...` | ||
); | ||
process.exit(0); // soft exit with warning! | ||
} | ||
|
||
console.log("Signing with Near..."); | ||
const signature = await txManager.signTransaction(safeOpHash); | ||
|
||
console.log("Executing UserOp..."); | ||
const userOpReceipt = await txManager.executeTransaction({ | ||
...unsignedUserOp, | ||
signature, | ||
}); | ||
console.log("userOp Receipt", userOpReceipt); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exitCode = 1; | ||
}); | ||
export * from "./tx-manager.js"; | ||
export * from "./types.js"; | ||
export * from "./util.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"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, | ||
|
||
/* Completeness */ | ||
"skipLibCheck": true /* Skip type checking all .d.ts files. */ | ||
}, | ||
"exclude": ["node_modules", "dist", "examples", "tests", "eslint.config.cjs"] | ||
} |
Oops, something went wrong.