Skip to content

Commit

Permalink
feat: fix smartSessions with paymaster (#8)
Browse files Browse the repository at this point in the history
* feat: resolved bic-660

* chore: fix minimum rhinestone version

* chore: mutual exclusion of unit + paid tests
  • Loading branch information
joepegler authored Jan 22, 2025
1 parent 510414a commit 81a8f88
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/funded-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
permissions: write-all
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-paid-tests
group: ${{ github.workflow }}-${{ github.ref }}-unit-tests
cancel-in-progress: true
steps:
- uses: actions/setup-node@v4
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @biconomy/abstractjs

## 0.0.33

### Patch Changes

- Fix paymaster + smartSessions

## 0.0.32

### Patch Changes
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/abstractjs",
"version": "0.0.32",
"version": "0.0.33",
"author": "Biconomy",
"repository": "github:bcnmy/abstractjs",
"main": "./dist/_cjs/index.js",
Expand Down Expand Up @@ -39,12 +39,12 @@
"viem": "2.21.6",
"vitest": "^1.3.1",
"yargs": "^17.7.2",
"@rhinestone/module-sdk": ">=0.1.0 <=0.2.3"
"@rhinestone/module-sdk": ">=0.2.3"
},
"peerDependencies": {
"typescript": "^5",
"viem": "^2.20.0",
"@rhinestone/module-sdk": ">=0.1.0 <=0.2.3"
"@rhinestone/module-sdk": ">=0.2.3"
},
"exports": {
".": {
Expand Down
3 changes: 1 addition & 2 deletions src/sdk/clients/createBicoPaymasterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
createSmartAccountClient
} from "./createSmartAccountClient"

describe.skip("bico.paymaster", async () => {
describe("bico.paymaster", async () => {
// describe.runIf(paymasterTruthy())("bico.paymaster", async () => {
let network: NetworkConfig

Expand Down Expand Up @@ -161,7 +161,6 @@ describe.skip("bico.paymaster", async () => {
})
const receipt = await nexusClient.waitForUserOperationReceipt({ hash })

console.log(receipt, "receipt")
expect(receipt.success).toBe("true")

// Get final balance
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/clients/createBicoPaymasterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type PaymasterContext = {
version: string
}
}
tokenInfo: {
tokenInfo?: {
feeTokenAddress: Address
}
expiryDuration?: number
Expand All @@ -61,7 +61,7 @@ type ToBiconomyTokenPaymasterContextParams = {
calculateGasLimits?: boolean
}

export const biconomySponsoredPaymasterContext = {
export const biconomySponsoredPaymasterContext: PaymasterContext = {
mode: "SPONSORED",
expiryDuration: 300,
calculateGasLimits: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
getValueLimitPolicy
} from "../../../constants"
import { SmartSessionAbi } from "../../../constants/abi/SmartSessionAbi"
import type { ModularSmartAccount } from "../../utils/Types"
import type { AnyData, ModularSmartAccount } from "../../utils/Types"
import {
abiToPoliciesInfo,
applyDefaults,
Expand Down Expand Up @@ -66,10 +66,12 @@ export type PreparePermissionParameters<
*/
export const getPermissionAction = async ({
chainId,
sessionRequestedInfo
sessionRequestedInfo,
withPaymaster = false
}: {
chainId: number
sessionRequestedInfo: FullCreateSessionDataParams[]
withPaymaster: boolean
}): Promise<PreparePermissionResponse | Error> => {
const sessions: Session[] = []
const permissionIds: Hex[] = []
Expand Down Expand Up @@ -160,16 +162,18 @@ export const getPermissionAction = async ({
}
}

const userOpPolicies = withPaymaster ? [getSudoPolicy()] : []

const session: Session = {
chainId: BigInt(chainId),
permitERC4337Paymaster: true,
permitERC4337Paymaster: withPaymaster,
sessionValidator: OWNABLE_VALIDATOR_ADDRESS,
sessionValidatorInitData: encodeValidationData({
threshold: 1,
owners: [sessionInfo.sessionKeyData]
}),
salt: sessionInfo.salt ?? generateSalt(),
userOpPolicies: [],
userOpPolicies,
actions: actionPolicies,
erc7739Policies: {
allowedERC7739Content: [],
Expand Down Expand Up @@ -272,6 +276,7 @@ export async function preparePermission<
throw new Error("Account not found")
}

const withPaymaster = !!(client as AnyData)?.paymaster
const chainId = publicClient_?.chain?.id

if (!chainId) {
Expand All @@ -282,7 +287,8 @@ export async function preparePermission<

const actionResponse = await getPermissionAction({
chainId,
sessionRequestedInfo: defaultedSessionRequestedInfo
sessionRequestedInfo: defaultedSessionRequestedInfo,
withPaymaster
})

if (actionResponse instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ describe.skip("modules.smartSessions.enable.mode.dx", async () => {
}
],
chainId: BigInt(chain.id)
// permitERC4337Paymaster: true
}

const nexusAccount = getAccount({
Expand Down
46 changes: 30 additions & 16 deletions src/test/playground.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {
} from "viem"
import { beforeAll, describe, expect, test } from "vitest"
import { playgroundTrue } from "../sdk/account/utils/Utils"
import { createBicoPaymasterClient } from "../sdk/clients/createBicoPaymasterClient"
import {
biconomySponsoredPaymasterContext,
type BicoPaymasterClient,
createBicoPaymasterClient,
type PaymasterContext
} from "../sdk/clients/createBicoPaymasterClient"
import {
type NexusClient,
createSmartAccountClient
Expand All @@ -31,19 +36,16 @@ import { toSmartSessionsValidator } from "../sdk/modules/smartSessionsValidator/
import { CounterAbi } from "./__contracts/abi/CounterAbi"
import { testAddresses } from "./callDatas"
import { toNetwork } from "./testSetup"
import {
type NetworkConfig,
type TestnetParams,
getTestParamsForTestnet
} from "./testUtils"
import type { NetworkConfig } from "./testUtils"
import { PaymasterClient } from "viem/account-abstraction"

describe.skipIf(!playgroundTrue())("playground", () => {
let network: NetworkConfig
// Nexus Config
let chain: Chain
let bundlerUrl: string
let walletClient: WalletClient
let paymasterUrl: string
let paymasterUrl: string | undefined
let nexusAccountAddress: Address

// Test utils
Expand All @@ -52,12 +54,19 @@ describe.skipIf(!playgroundTrue())("playground", () => {
let recipientAddress: Address
let nexusClient: NexusClient

let paymasterParams:
| undefined
| {
paymaster: BicoPaymasterClient
paymasterContext: PaymasterContext
}

beforeAll(async () => {
network = await toNetwork("TESTNET_FROM_ENV_VARS")

chain = network.chain
bundlerUrl = network.bundlerUrl
paymasterUrl = network.paymasterUrl || ""
paymasterUrl = network.paymasterUrl
eoaAccount = network.account as PrivateKeyAccount

recipientAddress = eoaAccount.address
Expand All @@ -72,6 +81,15 @@ describe.skipIf(!playgroundTrue())("playground", () => {
chain,
transport: http()
})

paymasterParams = paymasterUrl
? {
paymaster: createBicoPaymasterClient({
transport: http(paymasterUrl)
}),
paymasterContext: biconomySponsoredPaymasterContext
}
: undefined
})

test("should init the smart account", async () => {
Expand All @@ -80,11 +98,7 @@ describe.skipIf(!playgroundTrue())("playground", () => {
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
paymaster: network.paymasterUrl
? createBicoPaymasterClient({
transport: http(network.paymasterUrl)
})
: undefined
...(paymasterParams ? paymasterParams : {})
})
})

Expand Down Expand Up @@ -237,7 +251,8 @@ describe.skipIf(!playgroundTrue())("playground", () => {
accountAddress: nexusClient.account.address,
signer: eoaAccount,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
...(paymasterParams ? paymasterParams : {})
})

const usePermissionsModule = toSmartSessionsValidator({
Expand All @@ -256,8 +271,7 @@ describe.skipIf(!playgroundTrue())("playground", () => {
to: testAddresses.Counter,
data: encodeFunctionData({
abi: CounterAbi,
functionName: "incrementNumber",
args: []
functionName: "incrementNumber"
})
}
]
Expand Down
15 changes: 0 additions & 15 deletions src/test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,18 +502,3 @@ export const setByteCodeDynamic = async (
)
)
}

export type TestnetParams = ReturnType<typeof getTestParamsForTestnet>
export const getTestParamsForTestnet = (publicClient: PublicClient) => ({
validatorAddress: MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
userOperation: {
estimateFeesPerGas: async (_) => {
const feeData = await publicClient.estimateFeesPerGas()
return {
maxFeePerGas: safeMultiplier(feeData.maxFeePerGas, 1.5),
maxPriorityFeePerGas: safeMultiplier(feeData.maxPriorityFeePerGas, 1.5)
}
}
}
})

0 comments on commit 81a8f88

Please sign in to comment.