Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Viem migration #887

Closed
wants to merge 94 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
22354d2
relay-kit: Add viem dependency
tmjssz Jun 26, 2024
2666171
relay-kit: Migrate 4337 related components to viem
tmjssz Jun 26, 2024
b3d329e
playground: Use `generateTransferCallData` function from relay-kit in…
tmjssz Jun 26, 2024
e2be4ea
relay-kit: Fix hex string conversion for nonce
tmjssz Jun 26, 2024
6a5278c
relay-kit: Migrate 4337 bundler client to viem
tmjssz Jun 27, 2024
c040317
relay-kit: Remove `ethers` dependency
tmjssz Jun 27, 2024
7e0bd8e
fix(api-kit): Adjust e1e tests to 4337 bundler client changes
tmjssz Jul 2, 2024
e693167
fix(api-kit): e2e test
tmjssz Jul 2, 2024
92a62b7
Revert uses of `Hash`, `Hex` + `Address` types from viem in interfaces
tmjssz Jul 2, 2024
f554a93
api-kit: Migrate `signDelegate` to viem
tmjssz Jul 3, 2024
d008d4f
auth-kit: Migrate to viem
tmjssz Jul 3, 2024
56b294c
auth-kit: Rename file to `jest.setup.ts`
tmjssz Jul 3, 2024
da2b096
onramp-kit: Migrate to viem
tmjssz Jul 3, 2024
7704121
api-kit: Use WalletClient type with local account for `signDelegate` …
tmjssz Jul 4, 2024
bc494f5
api-kit: Improve Safe Delegates response types
tmjssz Jul 5, 2024
563ccce
api-kit: Fix `getSafeDelegates` e2e tests
tmjssz Jul 5, 2024
ee039ec
Merge branch 'development' into feat/viem-migration
tmjssz Jul 5, 2024
f1fc1f0
Merge branch 'development' into feat/viem-migration
tmjssz Jul 5, 2024
5129709
PR fixes
leonardotc Jul 9, 2024
2d56a2a
Add comment for TextEncoder polyfill
tmjssz Jul 10, 2024
8af26ef
Feat/viem migration tests (#894)
leonardotc Jul 11, 2024
de3ccc8
Fix onramp kit
leonardotc Jul 11, 2024
82d4512
Fix build
leonardotc Jul 11, 2024
4d91289
Api kit fixes
leonardotc Jul 12, 2024
4320cfa
Fix import
leonardotc Jul 12, 2024
65bda3a
Remove heap-size parameter
leonardotc Jul 12, 2024
e95fc3c
Remove ethers from onramp kit
leonardotc Jul 12, 2024
1fcc9eb
Add comment on global polyfill
leonardotc Jul 15, 2024
435ae4d
Change encode type conversion
leonardotc Jul 15, 2024
57f7219
Merge remote-tracking branch 'origin/development' into feat/viem-migr…
leonardotc Jul 15, 2024
6bc1f12
Fix build after merge
leonardotc Jul 15, 2024
ade9077
Merge remote-tracking branch 'origin/development' into feat/viem-migr…
leonardotc Jul 15, 2024
330f05c
api-kit: Move `viem` from devDependencies to dependencies
tmjssz Jul 15, 2024
eaca089
api-kit: Add `ethers` to devDependencies because it's still needed fo…
tmjssz Jul 15, 2024
ed70a38
api-kit: Fix import
tmjssz Jul 15, 2024
65127b4
api-kit: Fix tests for `addSafeOperation`
tmjssz Jul 15, 2024
4ff0dd8
api-kit: Fix e2e tests for `addSafeOperation`
tmjssz Jul 15, 2024
096ac25
api-kit: Add `@safe-global/relay-kit` to devDependencies because it's…
tmjssz Jul 15, 2024
a570ceb
api-kit: Fix `BrowserProvider` import
tmjssz Jul 15, 2024
f7cc1cd
Fix transaction encode test
leonardotc Jul 16, 2024
78979ed
Changed paymasterAndData
leonardotc Jul 16, 2024
9ae5384
Remove only on tests
leonardotc Jul 16, 2024
ec89e7a
api-kit: Fix `confirmSafeOperation` tests
tmjssz Jul 16, 2024
25e54f7
Fix (or maybe not) paymaster estimation on sponsored transaction
leonardotc Jul 16, 2024
8d29d3c
Merge remote-tracking branch 'origin/feat/viem-migration' into feat/v…
leonardotc Jul 16, 2024
a04a860
Fix gas estimation issue
leonardotc Jul 16, 2024
9e16f42
chore: remove deprecated ethereum utils lib (#884)
dasanra Jul 17, 2024
4f074f2
Remove ethers from safe-kit
leonardotc Jul 17, 2024
e926eba
Minor PR changes
leonardotc Jul 17, 2024
35c7cf6
Remove ethers dependency
leonardotc Jul 17, 2024
e966c67
Fix coverall file
leonardotc Jul 17, 2024
e553890
Re-add ethers but as dev deps
leonardotc Jul 17, 2024
93062e0
First clean up
leonardotc Jul 17, 2024
c5303af
Minor type changes and comments
leonardotc Jul 18, 2024
1adea41
Remove throws
leonardotc Jul 18, 2024
c2b2942
playground: Migrate scripts to viem
tmjssz Jul 18, 2024
32a6da4
Pre-pr changes
leonardotc Jul 18, 2024
47d4e1d
onramp-kit: Remove ethers from example app
tmjssz Jul 18, 2024
ee88653
Fix contracts
leonardotc Jul 19, 2024
6b0853c
Merge remote-tracking branch 'origin/development' into feat/viem-migr…
leonardotc Jul 19, 2024
3f0b7b5
Merge branch 'development' into feat/viem-migration
tmjssz Jul 19, 2024
1a52333
Add chain to the external signer
leonardotc Jul 22, 2024
e3ec4d8
Fix parsing of SafeTxGas estimation from viem error object
tmjssz Jul 22, 2024
a7c5bc1
relay-kit: Fix getNonce call in Safe4337Pack
tmjssz Jul 22, 2024
03907fd
Use different RPC endpoint
tmjssz Jul 22, 2024
17e149c
Merge branch 'development' into feat/viem-migration
tmjssz Jul 22, 2024
cc6589c
fix(api-kit): Fix confirmSafeOperation e2e test by making test transa…
tmjssz Jul 22, 2024
360d997
remove public schema from bundler
leonardotc Jul 23, 2024
3795719
refactor: Improve API Kit interoperability playground
tmjssz Jul 23, 2024
90157d0
refactor: Improve relay-kit playground scripts
tmjssz Jul 23, 2024
3000003
refactor: Fix wait for transaction being executed in api-kit playgrou…
tmjssz Jul 23, 2024
d20167c
refactor: Update playground scripts to use viem/accounts for private …
tmjssz Jul 23, 2024
dd6e775
refactor: Use `Account` type instead of LocalAccount in api-kit
tmjssz Jul 24, 2024
dca351a
Revert protocol kit playground
leonardotc Jul 24, 2024
124f931
refactor: Use `(await signer.getAddresses())[0]` instead of `signer.a…
tmjssz Jul 24, 2024
403e842
Fix wait for receipt in transaction result
leonardotc Jul 24, 2024
1d58ce8
Add comment for import from relay-kit dist folder
tmjssz Jul 24, 2024
3796ce4
Merge branch 'feat/viem-migration' of github.com:safe-global/safe-cor…
tmjssz Jul 24, 2024
4f9400e
refactor: Move `asBlockId` function to utils
tmjssz Jul 25, 2024
3648d94
refactor: Simplify SafeProvider constructor logic
tmjssz Jul 25, 2024
8e9391c
Add explanation for conversion
leonardotc Jul 25, 2024
0b940bb
Remove residual code
leonardotc Jul 26, 2024
128987f
Remove duplicate
leonardotc Jul 26, 2024
4475b88
Fix custom chain support
leonardotc Jul 26, 2024
8cd7e96
Depromisify getAddress
leonardotc Jul 26, 2024
658b9a8
Fix onramp
leonardotc Jul 26, 2024
00a292e
feat: Extend SafeProviders externalClient type (#928)
tmjssz Jul 30, 2024
9853b12
chore: align api-kit tests
dasanra Aug 1, 2024
48d4902
fix: delegator address not checksummed
dasanra Aug 1, 2024
19d7910
Add further comments
leonardotc Aug 2, 2024
86871bd
Change base address type
leonardotc Aug 8, 2024
eeeeb84
remove Viem dependency from @safe-global/safe-core-sdk-types
dasanra Aug 8, 2024
4dc89f1
revert unnecessary Viem changes in api-kit playground
dasanra Aug 8, 2024
9d92313
fix: types in tests
dasanra Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api-kit/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@nomicfoundation/hardhat-ethers'
import '@nomicfoundation/hardhat-viem'
import dotenv from 'dotenv'
import { HardhatUserConfig, HttpNetworkUserConfig } from 'hardhat/types'
import yargs from 'yargs'
Expand Down
22 changes: 12 additions & 10 deletions packages/api-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"API"
],
"scripts": {
"test:web3": "export TESTS_PATH=tests/endpoint && export ETH_LIB=web3 && nyc hardhat test",
"test:ethers": "export TESTS_PATH=tests/endpoint && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:viem": "export TESTS_PATH=tests/endpoint && export ETH_LIB=viem && nyc hardhat test",
"test": "yarn test:ethers",
"test:ci:web3": "export TESTS_PATH=tests/e2e && export ETH_LIB=web3 && nyc hardhat test",
"test:web3": "export TESTS_PATH=tests/endpoint && export ETH_LIB=web3 && nyc --reporter=lcov hardhat test",
"test:ethers": "export TESTS_PATH=tests/endpoint && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:viem": "export TESTS_PATH=tests/endpoint && export ETH_LIB=viem && nyc --reporter=lcov hardhat test",
"test": "yarn test:viem",
"test:ci:web3": "export TESTS_PATH=tests/e2e && export ETH_LIB=web3 && nyc --reporter=lcov hardhat test",
"test:ci:ethers": "export TESTS_PATH=tests/e2e && export ETH_LIB=ethers && nyc --reporter=lcov hardhat test",
"test:ci:viem": "export TESTS_PATH=tests/e2e && export ETH_LIB=viem && nyc --reporter=lcov hardhat test",
"test:ci": "yarn test:ci:ethers",
"test:ci": "yarn test:ci:viem",
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist .nyc_output cache",
Expand All @@ -39,7 +39,8 @@
],
"homepage": "https://github.com/safe-global/safe-core-sdk#readme",
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-viem": "^2.0.2",
"@safe-global/relay-kit": "^3.0.2",
"@types/chai": "^4.3.16",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.6",
Expand All @@ -48,20 +49,21 @@
"@types/yargs": "^17.0.32",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"ethers": "^6.13.1",
"hardhat": "^2.19.3",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"semver": "^7.6.1",
"sinon": "^14.0.2",
"sinon-chai": "^3.7.0",
"tsconfig-paths": "^4.2.0",
"viem": "^2.15.1",
"web3": "^4.7.0",
"yargs": "^17.7.2"
},
"dependencies": {
"@safe-global/protocol-kit": "^4.0.3",
"@safe-global/safe-core-sdk-types": "^5.0.3",
"ethers": "^6.13.1",
"node-fetch": "^2.7.0"
"node-fetch": "^2.7.0",
"viem": "^2.19.0"
}
}
6 changes: 6 additions & 0 deletions packages/api-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ import SafeApiKit, { SafeApiKitConfig } from './SafeApiKit'
export * from './types/safeTransactionServiceTypes'
export { SafeApiKitConfig }
export default SafeApiKit

declare module 'viem/node_modules/abitype' {
export interface Register {
AddressType: string
}
}
8 changes: 4 additions & 4 deletions packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Signer, TypedDataDomain, TypedDataField } from 'ethers'
import { Account, Chain, Transport, TypedDataDomain, TypedDataParameter, WalletClient } from 'viem'
import {
SafeMultisigTransactionResponse,
SafeTransactionData,
Expand Down Expand Up @@ -77,14 +77,14 @@ export type AddSafeDelegateProps = {
safeAddress?: string
delegateAddress: string
delegatorAddress: string
signer: Signer
signer: WalletClient<Transport, Chain, Account>
label: string
}

export type DeleteSafeDelegateProps = {
delegateAddress: string
delegatorAddress: string
signer: Signer
signer: WalletClient<Transport, Chain, Account>
}

export type SafeDelegateResponse = {
Expand Down Expand Up @@ -253,7 +253,7 @@ export type GetSafeMessageListProps = {

export type EIP712TypedData = {
domain: TypedDataDomain
types: TypedDataField
types: TypedDataParameter
message: Record<string, unknown>
}

Expand Down
17 changes: 13 additions & 4 deletions packages/api-kit/src/utils/signDelegate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Signer } from 'ethers'
import { Chain, Account, Transport, WalletClient } from 'viem'

export async function signDelegate(signer: Signer, delegateAddress: string, chainId: bigint) {
export async function signDelegate(
walletClient: WalletClient<Transport, Chain, Account>,
delegateAddress: string,
chainId: bigint
) {
const domain = {
name: 'Safe Transaction Service',
version: '1.0',
chainId: chainId
chainId: Number(chainId)
}
yagopv marked this conversation as resolved.
Show resolved Hide resolved

const types = {
Expand All @@ -16,5 +20,10 @@ export async function signDelegate(signer: Signer, delegateAddress: string, chai

const totp = Math.floor(Date.now() / 1000 / 3600)

return signer.signTypedData(domain, types, { delegateAddress, totp })
return walletClient.signTypedData({
domain,
types,
primaryType: 'Delegate',
message: { delegateAddress, totp }
})
}
36 changes: 20 additions & 16 deletions packages/api-kit/tests/e2e/addSafeDelegate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ethers, Signer } from 'ethers'
import { Address, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { sepolia } from 'viem/chains'
import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit/index'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
Expand All @@ -11,17 +13,22 @@ const PRIVATE_KEY_1 = '0x83a415ca62e11f5fa5567e98450d0f82ae19ff36ef876c10a8d448c
const PRIVATE_KEY_2 = '0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773'

let safeApiKit: SafeApiKit
let signer: Signer
let signer: AddSafeDelegateProps['signer']
let delegatorAddress: Address

describe('addSafeDelegate', () => {
before(async () => {
safeApiKit = getApiKit('https://safe-transaction-sepolia.staging.5afe.dev/api')
signer = new ethers.Wallet(PRIVATE_KEY_1)
signer = createWalletClient({
chain: sepolia,
transport: http(),
account: privateKeyToAccount(PRIVATE_KEY_1)
})
delegatorAddress = signer.account.address
})

it('should fail if Label is empty', async () => {
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
delegateAddress,
delegatorAddress,
Expand All @@ -35,7 +42,6 @@ describe('addSafeDelegate', () => {

it('should fail if Safe delegate address is empty', async () => {
const delegateAddress = ''
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
delegateAddress,
delegatorAddress,
Expand Down Expand Up @@ -64,7 +70,6 @@ describe('addSafeDelegate', () => {
it('should fail if Safe address is not checksummed', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78'.toLowerCase()
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
safeAddress,
delegateAddress,
Expand All @@ -80,7 +85,6 @@ describe('addSafeDelegate', () => {
it('should fail if Safe delegate address is not checksummed', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78'
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'.toLowerCase()
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
safeAddress,
delegateAddress,
Expand All @@ -96,23 +100,22 @@ describe('addSafeDelegate', () => {
it('should fail if Safe delegator address is not checksummed', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78'
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const delegatorAddress = (await signer.getAddress()).toLowerCase()
const delegatorAddressLowerCase = delegatorAddress.toLowerCase()
const delegateConfig: AddSafeDelegateProps = {
safeAddress,
delegateAddress,
delegatorAddress,
delegatorAddress: delegatorAddressLowerCase,
signer,
label: 'Label'
}
await chai
.expect(safeApiKit.addSafeDelegate(delegateConfig))
.to.be.rejectedWith(`Address ${delegatorAddress} is not checksumed`)
.to.be.rejectedWith(`Address ${delegatorAddressLowerCase} is not checksumed`)
})

it('should fail if Safe does not exist', async () => {
const safeAddress = '0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e'
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
safeAddress,
delegateAddress,
Expand All @@ -128,8 +131,12 @@ describe('addSafeDelegate', () => {
it('should fail if the signer is not an owner of the Safe', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78'
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const nonOwnerSigner = new ethers.Wallet(PRIVATE_KEY_2)
const delegatorAddress = await nonOwnerSigner.getAddress()
const nonOwnerSigner = createWalletClient({
chain: sepolia,
transport: http(),
account: privateKeyToAccount(PRIVATE_KEY_2)
})
const delegatorAddress = (await nonOwnerSigner.getAddresses())[0]
const delegateConfig: AddSafeDelegateProps = {
safeAddress,
delegateAddress,
Expand All @@ -147,7 +154,6 @@ describe('addSafeDelegate', () => {
it('should add a new delegate', async () => {
const safeAddress = '0xF8ef84392f7542576F6b9d1b140334144930Ac78'
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
safeAddress,
delegateAddress,
Expand All @@ -170,7 +176,6 @@ describe('addSafeDelegate', () => {

it('should add a new delegate without specifying a Safe', async () => {
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const delegatorAddress = await signer.getAddress()
const delegateConfig: AddSafeDelegateProps = {
delegateAddress,
delegatorAddress,
Expand Down Expand Up @@ -200,7 +205,6 @@ describe('addSafeDelegate', () => {
const eip3770SafeAddress = `${config.EIP_3770_PREFIX}:${safeAddress}`
const delegateAddress = '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B'
const eip3770DelegateAddress = `${config.EIP_3770_PREFIX}:${delegateAddress}`
const delegatorAddress = await signer.getAddress()
const eip3770DelegatorAddress = `${config.EIP_3770_PREFIX}:${delegatorAddress}`
const delegateConfig: AddSafeDelegateProps = {
safeAddress: eip3770SafeAddress,
Expand Down
68 changes: 42 additions & 26 deletions packages/api-kit/tests/e2e/addSafeOperation.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { ethers } from 'ethers'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import Safe from '@safe-global/protocol-kit'
import SafeApiKit from '@safe-global/api-kit/index'
import { Safe4337Pack } from '@safe-global/relay-kit'
import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation'
import { BundlerClient, Safe4337Pack } from '@safe-global/relay-kit'
import { generateTransferCallData } from '@safe-global/relay-kit/packs/safe-4337/testing-utils/helpers'
import { RPC_4337_CALLS } from '@safe-global/relay-kit/packs/safe-4337/constants'
import {
ENTRYPOINT_ABI,
ENTRYPOINT_ADDRESS_V06,
RPC_4337_CALLS
} from '@safe-global/relay-kit/packs/safe-4337/constants'
// Needs to be imported from dist folder in order to mock the getEip4337BundlerProvider function
import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils'
dasanra marked this conversation as resolved.
Show resolved Hide resolved
import { getKits } from '../utils/setupKits'
import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation'

chai.use(chaiAsPromised)
chai.use(sinonChai)
Expand All @@ -18,7 +23,7 @@ const SIGNER_PK = '0x83a415ca62e11f5fa5567e98450d0f82ae19ff36ef876c10a8d448c788a
const SAFE_ADDRESS = '0x60C4Ab82D06Fd7dFE9517e17736C2Dcc77443EF0' // 1/2 Safe (v1.4.1) with signer above being an owner + 4337 module enabled
const PAYMASTER_TOKEN_ADDRESS = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238'
const PAYMASTER_ADDRESS = '0x0000000000325602a77416A16136FDafd04b299f'
const BUNDLER_URL = `https://bundler.url`
const BUNDLER_URL = 'https://bundler.url'
const TX_SERVICE_URL = 'https://safe-transaction-sepolia.staging.5afe.dev/api'

let safeApiKit: SafeApiKit
Expand All @@ -33,35 +38,42 @@ describe('addSafeOperation', () => {
operation: 0
}

const requestStub = sinon.stub()
// Setup mocks for the bundler client
const providerStub = sinon.stub(ethers.JsonRpcProvider.prototype, 'send')

providerStub.withArgs(RPC_4337_CALLS.CHAIN_ID, []).returns(Promise.resolve('0xaa36a7'))
providerStub
.withArgs(RPC_4337_CALLS.SUPPORTED_ENTRY_POINTS, [])
.returns(Promise.resolve(['0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789']))
providerStub
.withArgs('pimlico_getUserOperationGasPrice', [])
.returns(
Promise.resolve({ fast: { maxFeePerGas: '0x3b9aca00', maxPriorityFeePerGas: '0x3b9aca00' } })
)
providerStub.withArgs(RPC_4337_CALLS.ESTIMATE_USER_OPERATION_GAS, sinon.match.any).returns(
Promise.resolve({
preVerificationGas: BigInt(Date.now()),
callGasLimit: BigInt(Date.now()),
verificationGasLimit: BigInt(Date.now())
})
)

providerStub.callThrough()

before(async () => {
sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({
request: requestStub,
readContract: sinon
.stub()
.withArgs({
address: ENTRYPOINT_ADDRESS_V06,
abi: ENTRYPOINT_ABI,
functionName: 'getNonce',
args: [SAFE_ADDRESS, BigInt(0)]
})
.resolves(123n)
} as unknown as BundlerClient)
;({ safeApiKit, protocolKit } = await getKits({
safeAddress: SAFE_ADDRESS,
signer: SIGNER_PK,
txServiceUrl: TX_SERVICE_URL
}))

requestStub.withArgs({ method: RPC_4337_CALLS.CHAIN_ID }).resolves('0xaa36a7')
requestStub
.withArgs({ method: RPC_4337_CALLS.SUPPORTED_ENTRY_POINTS })
.resolves([ENTRYPOINT_ADDRESS_V06])
requestStub
.withArgs({ method: 'pimlico_getUserOperationGasPrice' })
.resolves({ fast: { maxFeePerGas: '0x3b9aca00', maxPriorityFeePerGas: '0x3b9aca00' } })
requestStub
.withArgs({ method: RPC_4337_CALLS.ESTIMATE_USER_OPERATION_GAS, params: sinon.match.any })
.resolves({
preVerificationGas: BigInt(Date.now()),
callGasLimit: BigInt(Date.now()),
verificationGasLimit: BigInt(Date.now())
})

safe4337Pack = await Safe4337Pack.init({
provider: protocolKit.getSafeProvider().provider,
signer: protocolKit.getSafeProvider().signer,
Expand All @@ -74,6 +86,10 @@ describe('addSafeOperation', () => {
})
})

after(() => {
sinon.restore()
})

describe('should fail', () => {
it('if safeAddress is empty', async () => {
const safeOperation = await safe4337Pack.createTransaction({ transactions: [transferUSDC] })
Expand Down
Loading
Loading