Skip to content

Commit

Permalink
chore: tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Aug 27, 2024
1 parent 4b883cc commit 65bd389
Show file tree
Hide file tree
Showing 46 changed files with 322 additions and 3,105 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/playground.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: playground
on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
jobs:
playground:
name: playground
Expand Down
Binary file modified bun.lockb
Binary file not shown.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sideEffects": false,
"name": "@biconomy/sdk",
"author": "Biconomy",
"version": "0.1.0",
"version": "0.0.1",
"description": "SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.",
"keywords": [
"erc-7579",
Expand Down Expand Up @@ -92,18 +92,20 @@
"buffer": "^6.0.3",
"concurrently": "^8.2.2",
"dotenv": "^16.4.5",
"ethers": "^6.12.0",
"ethers": "^6.13.2",
"execa": "^9.3.1",
"get-port": "^7.1.0",
"gh-pages": "^6.1.1",
"nexus": "github:bcnmy/nexus#f08ec9f2d6cd2cf0044b901cc4c4a1cb5c527273",
"prool": "^0.0.16",
"rimraf": "^5.0.5",
"simple-git-hooks": "^2.9.0",
"size-limit": "^11",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.8",
"tslib": "^2.6.3",
"typedoc": "^0.25.9",
"vitest": "^1.3.1",
"yargs": "^17.7.2"
"vitest": "^1.3.1"
},
"peerDependencies": {
"typescript": "^5",
Expand Down
63 changes: 35 additions & 28 deletions scripts/fetch:deployment.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
const fs = require("node:fs")
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
import fs from "node:fs"

const {
pathToDeployment = "../../nexus/deployments",
deploymentChainName = "localhost",
abisInSrc = ["K1ValidatorFactory", "Nexus", "MockExecutor", "K1Validator"]
} = yargs(hideBin(process.argv)).argv
const pathToDeployment = "../../nexus/deployments"
const deploymentChainName = "anvil-55000"
const abisInSrc = ["K1ValidatorFactory", "Nexus", "K1Validator"]

const relativePath = `${__dirname}/${pathToDeployment}/${deploymentChainName}`

type DeployedContract = {
address: string
bytecode: string
}

export const getDeployments = async () => {
const relativePath = `${__dirname}/${pathToDeployment}/${deploymentChainName}`
const files = fs.readdirSync(relativePath)
const deployedContracts: Record<string, DeployedContract> = {}

Expand All @@ -29,7 +25,7 @@ export const getDeployments = async () => {
`${relativePath}/${jsonFileNameWithExtension}`,
"utf8"
)
const { address, abi, bytecode } = JSON.parse(contents)
const { address, abi } = JSON.parse(contents)

const isForCore = abisInSrc.includes(name)
if (isForCore) {
Expand All @@ -45,14 +41,13 @@ export const getDeployments = async () => {
)} as const;\n`

const tsAbiPath = isForCore
? `${__dirname}/../src/contracts/abi/${name}Abi.ts`
: `${__dirname}/../tests/contracts/abi/${name}Abi.ts`
? `${__dirname}/../src/__contracts/abi/${name}Abi.ts`
: `${__dirname}/../tests/__contracts/abi/${name}Abi.ts`

fs.writeFileSync(tsAbiPath, tsAbiContent)

deployedContracts[name] = {
address,
bytecode
address
}
}
}
Expand All @@ -68,28 +63,40 @@ export const getDeployments = async () => {
.join("\n")}`

// Write the ABIs
const abiIndexPath = `${__dirname}/../src/contracts/abi/index.ts`
const abiIndexPath = `${__dirname}/../src/__contracts/abi/index.ts`
fs.writeFileSync(abiIndexPath, abiIndexContent)

const testAbiIndexPath = `${__dirname}/../tests/contracts/abi/index.ts`
const testAbiIndexPath = `${__dirname}/../tests/__contracts/abi/index.ts`
fs.writeFileSync(testAbiIndexPath, testAbiIndexContent)

// Write deployemts to tests folder
const writePath = `${__dirname}/../tests/contracts/deployment.json`
fs.writeFileSync(writePath, JSON.stringify(deployedContracts, null, 2))

// Write addresses to src folder
const writeAddressesPath = `${__dirname}/../src/contracts/addresses.ts`
const addressesContent = `import type { Hex } from "viem"\nexport const deployedContracts: Record<string, Hex> = ${JSON.stringify(
Object.keys(deployedContracts).reduce((acc, key) => {
acc[key] = deployedContracts[key].address
return acc
}, {}),
const writeAddressesPath = `${__dirname}/../src/__contracts/addresses.ts`
const writeAddressesPathTest = `${__dirname}/../tests/__contracts/addresses.ts`

const addressesContent = `import type { Hex } from "viem"\nexport const addresses: Record<string, Hex> = ${JSON.stringify(
Object.keys(deployedContracts)
.filter((key) => coreFiles.includes(key))
.reduce((acc, key) => {
acc[key] = deployedContracts[key].address
return acc
}, {}),
null,
2
)} as const;\nexport default addresses\n`

const testAddressesContent = `import type { Hex } from "viem"\nexport const addresses: Record<string, Hex> = ${JSON.stringify(
Object.keys(deployedContracts)
.filter((key) => testFiles.includes(key))
.reduce((acc, key) => {
acc[key] = deployedContracts[key].address
return acc
}, {}),
null,
2
)}\n`
)} as const;\nexport default addresses\n`

fs.writeFileSync(writeAddressesPath, addressesContent)
fs.writeFileSync(writeAddressesPathTest, testAddressesContent)
}

// We recommend this pattern to be able to use async/await everywhere
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/README.md → src/__contracts/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## The contents of this folder is auto-generated. Please do not edit as your changes are likely to become overwritten
## The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,22 @@ export const K1ValidatorFactoryAbi = [
inputs: [
{
internalType: "address",
name: "",
name: "eoaOwner",
type: "address"
},
{
internalType: "uint256",
name: "",
name: "index",
type: "uint256"
},
{
internalType: "address[]",
name: "",
name: "attesters",
type: "address[]"
},
{
internalType: "uint8",
name: "",
name: "threshold",
type: "uint8"
}
],
Expand Down
37 changes: 29 additions & 8 deletions src/contracts/abi/NexusAbi.ts → src/__contracts/abi/NexusAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const NexusAbi = [
},
{
inputs: [],
name: "CannotRemoveLastValidator",
name: "CanNotRemoveLastValidator",
type: "error"
},
{
Expand Down Expand Up @@ -46,6 +46,11 @@ export const NexusAbi = [
name: "FallbackAlreadyInstalledForSelector",
type: "error"
},
{
inputs: [],
name: "FallbackCallTypeInvalid",
type: "error"
},
{
inputs: [],
name: "FallbackHandlerUninstallFailed",
Expand Down Expand Up @@ -221,6 +226,11 @@ export const NexusAbi = [
name: "NexusInitializationFailed",
type: "error"
},
{
inputs: [],
name: "NoValidatorInstalled",
type: "error"
},
{
inputs: [],
name: "UnauthorizedCallContext",
Expand Down Expand Up @@ -275,6 +285,17 @@ export const NexusAbi = [
name: "UpgradeFailed",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "module",
type: "address"
}
],
name: "ValidatorNotInstalled",
type: "error"
},
{
anonymous: false,
inputs: [
Expand Down Expand Up @@ -397,9 +418,9 @@ export const NexusAbi = [
inputs: [
{
indexed: false,
internalType: "uint256",
name: "batchExecutionindex",
type: "uint256"
internalType: "bytes",
name: "callData",
type: "bytes"
},
{
indexed: false,
Expand All @@ -416,9 +437,9 @@ export const NexusAbi = [
inputs: [
{
indexed: false,
internalType: "uint256",
name: "batchExecutionindex",
type: "uint256"
internalType: "bytes",
name: "callData",
type: "bytes"
},
{
indexed: false,
Expand Down Expand Up @@ -937,7 +958,7 @@ export const NexusAbi = [
],
name: "setRegistry",
outputs: [],
stateMutability: "nonpayable",
stateMutability: "payable",
type: "function"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from "./EntryPointABI"
export * from "./NexusAbi"
export * from "./K1ValidatorAbi"
export * from "./K1ValidatorFactoryAbi"
export * from "./MockExecutorAbi"
7 changes: 7 additions & 0 deletions src/__contracts/addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Hex } from "viem"
export const addresses: Record<string, Hex> = {
Nexus: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
K1Validator: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
K1ValidatorFactory: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
} as const
export default addresses
36 changes: 36 additions & 0 deletions src/__contracts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Hex } from "viem"
import { EntrypointAbi, K1ValidatorAbi, K1ValidatorFactoryAbi } from "./abi"
import addresses from "./addresses"

export const ENTRYPOINT_SIMULATIONS: Hex =
"0x74Cb5e4eE81b86e70f9045036a1C5477de69eE87"
export const ENTRYPOINT_ADDRESS: Hex =
"0x0000000071727De22E5E9d8BAf0edAc6f37da032"

const entryPoint = {
address: ENTRYPOINT_ADDRESS,
abi: EntrypointAbi
} as const

const entryPointSimulations = {
address: ENTRYPOINT_SIMULATIONS
} as const

const k1ValidatorFactory = {
address: addresses.K1ValidatorFactory,
abi: K1ValidatorFactoryAbi
} as const

const k1Validator = {
address: addresses.K1Validator,
abi: K1ValidatorAbi
} as const

export const contracts = {
entryPoint,
entryPointSimulations,
k1ValidatorFactory,
k1Validator
} as const

export default contracts
8 changes: 4 additions & 4 deletions src/account/BaseSmartContractAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getContract,
trim
} from "viem"
import contracts from "../contracts"
import { EntrypointAbi } from "../contracts/abi/EntryPointABI.js"
import { EntrypointAbi } from "../__contracts/abi/EntryPointABI.js"
import contracts from "../__contracts/index.js"
import { Logger, type SmartAccountSigner } from "./index.js"
import type { MODE_MODULE_ENABLE, MODE_VALIDATION } from "./utils/Constants.js"
import type {
Expand Down Expand Up @@ -43,7 +43,7 @@ export abstract class BaseSmartContractAccount<
protected signer: TSigner

protected entryPoint: GetContractReturnType<
typeof contracts.EntryPoint.abi,
typeof contracts.entryPoint.abi,
PublicClient
>

Expand All @@ -53,7 +53,7 @@ export abstract class BaseSmartContractAccount<

constructor(params: BaseSmartContractAccountProps) {
this.entryPointAddress =
params.entryPointAddress ?? contracts.EntryPoint.address
params.entryPointAddress ?? contracts.entryPoint.address

this.publicClient = createPublicClient({
chain: params.chain,
Expand Down
Loading

0 comments on commit 65bd389

Please sign in to comment.