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(relay-kit): Add Entrypoint v0.7 support #1103

Open
wants to merge 41 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
22ceffc
Add a specific userOperations module
yagopv Jan 10, 2025
5ab7193
eth_estimateUserOperationGas v0.7 support
yagopv Jan 13, 2025
ee61a99
Fix initCode
yagopv Jan 13, 2025
7a1a767
Change SafeOp structure
yagopv Jan 15, 2025
36c2da9
Working version for sponsored transactions
yagopv Jan 17, 2025
feda7e8
Update playgrounds
yagopv Jan 20, 2025
77c9973
Fix SigningMethod evaluated incorrectly
yagopv Jan 20, 2025
8eff392
Fix paymaster 0x0000...
yagopv Jan 20, 2025
dbe373d
Add more RPC calls
yagopv Jan 22, 2025
9fcea54
Update to work with new Pimlico paymasters
yagopv Jan 22, 2025
5eff169
Improvements
yagopv Jan 23, 2025
19b63c7
Update playgrounds
yagopv Jan 23, 2025
71048b4
Update comments in playgrounds
yagopv Jan 23, 2025
a27f78d
Improve SafeOperation
yagopv Jan 24, 2025
d94bbe8
Remove calculateSafeUserOperationHash
yagopv Jan 24, 2025
0cd4cfa
Improve dummySignatures retrieval
yagopv Jan 24, 2025
ce90770
Improve version management for SafeOperations
yagopv Jan 24, 2025
3c75c5d
Merge branch 'development' of https://github.com/safe-global/safe-cor…
yagopv Jan 24, 2025
958316c
Fix other kits
yagopv Jan 24, 2025
503a7cc
Refactor rpc schemas
yagopv Jan 27, 2025
c60dd14
Some improvements
yagopv Jan 27, 2025
38c85fb
Improve playgrounds
yagopv Jan 27, 2025
e1fa4b4
Fix SafeOperationV06
yagopv Jan 28, 2025
0a4ba15
Update playgrounds
yagopv Jan 28, 2025
3c524f3
uncomment
yagopv Jan 28, 2025
e245d03
Merge branch 'development' of https://github.com/safe-global/safe-cor…
yagopv Jan 28, 2025
e6559c1
Improve imports
yagopv Jan 28, 2025
a204a8a
Fix tests
yagopv Jan 29, 2025
800d2a0
Downgrade viem version breaking tests
yagopv Jan 30, 2025
d0e1147
Fix tests
yagopv Jan 30, 2025
dc086be
Merge branch 'development' of https://github.com/safe-global/safe-cor…
yagopv Jan 30, 2025
069e4f5
Fix nonce
yagopv Jan 30, 2025
6b5f563
Fix starter-kit
yagopv Jan 30, 2025
f57bab9
Fix api-kit tests
yagopv Jan 30, 2025
7529635
Fix some tests
yagopv Jan 31, 2025
705be62
Fix api kit tests
yagopv Jan 31, 2025
a8d7ba0
protocol-kit shouldn't be a dep of SafeOperation
yagopv Jan 31, 2025
d0d81e9
Merge branch 'development' of https://github.com/safe-global/safe-cor…
yagopv Jan 31, 2025
4a21b2c
Fix protocol-kit tests
yagopv Jan 31, 2025
0a3842f
Update test
yagopv Jan 31, 2025
bd31756
Not neccesary sharedSigner
yagopv Jan 31, 2025
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
11 changes: 7 additions & 4 deletions packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
SafeMultisigTransactionResponse,
SafeOperation,
SafeOperationConfirmationListResponse,
SafeOperationResponse
SafeOperationResponse,
UserOperationV06
} from '@safe-global/types-kit'
import { TRANSACTION_SERVICE_URLS } from './utils/config'
import { isEmptyData } from './utils'
Expand Down Expand Up @@ -122,7 +123,7 @@
* @throws "Not Found"
* @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
*/
async decodeData(data: string, to?: string): Promise<any> {

Check warning on line 126 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
if (data === '') {
throw new Error('Invalid data')
}
Expand Down Expand Up @@ -258,7 +259,7 @@
return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/safes/${address}/`,
method: HttpMethod.Get
}).then((response: any) => {

Check warning on line 262 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
// FIXME remove when the transaction service returns the singleton property instead of masterCopy
if (!response?.singleton) {
const { masterCopy, ...rest } = response
Expand Down Expand Up @@ -347,7 +348,7 @@
const { address: delegator } = this.#getEip3770Address(delegatorAddress)
const signature = await signDelegate(signer, delegate, this.#chainId)

const body: any = {

Check warning on line 351 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
safe: safeAddress ? this.#getEip3770Address(safeAddress).address : null,
delegate,
delegator,
Expand Down Expand Up @@ -415,7 +416,7 @@
return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/safes/${address}/creation/`,
method: HttpMethod.Get
}).then((response: any) => {

Check warning on line 419 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
// FIXME remove when the transaction service returns the singleton property instead of masterCopy
if (!response?.singleton) {
const { masterCopy, ...rest } = response
Expand Down Expand Up @@ -918,21 +919,23 @@
const getISOString = (date: number | undefined) =>
!date ? null : new Date(date * 1000).toISOString()

const userOperationV06 = userOperation as UserOperationV06

return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/safes/${safeAddress}/safe-operations/`,
method: HttpMethod.Post,
body: {
initCode: isEmptyData(userOperationV06.initCode) ? null : userOperationV06.initCode,
nonce: userOperation.nonce,
initCode: isEmptyData(userOperation.initCode) ? null : userOperation.initCode,
callData: userOperation.callData,
callGasLimit: userOperation.callGasLimit.toString(),
verificationGasLimit: userOperation.verificationGasLimit.toString(),
preVerificationGas: userOperation.preVerificationGas.toString(),
maxFeePerGas: userOperation.maxFeePerGas.toString(),
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas.toString(),
paymasterAndData: isEmptyData(userOperation.paymasterAndData)
paymasterAndData: isEmptyData(userOperationV06.paymasterAndData)
? null
: userOperation.paymasterAndData,
: userOperationV06.paymasterAndData,
entryPoint,
validAfter: getISOString(options?.validAfter),
validUntil: getISOString(options?.validUntil),
Expand Down
12 changes: 6 additions & 6 deletions packages/api-kit/src/utils/safeOperation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { SafeOperation } from '@safe-global/types-kit'

export const getAddSafeOperationProps = async (safeOperation: SafeOperation) => {
const userOperation = safeOperation.toUserOperation()
const userOperation = safeOperation.getUserOperation()
userOperation.signature = safeOperation.encodedSignatures() // Without validity dates

return {
entryPoint: safeOperation.data.entryPoint,
moduleAddress: safeOperation.moduleAddress,
safeAddress: safeOperation.data.safe,
entryPoint: safeOperation.options.entryPoint,
moduleAddress: safeOperation.options.moduleAddress,
safeAddress: userOperation.sender,
userOperation,
options: {
validAfter: safeOperation.data.validAfter,
validUntil: safeOperation.data.validUntil
validAfter: safeOperation.options.validAfter,
validUntil: safeOperation.options.validUntil
}
}
}
3 changes: 1 addition & 2 deletions packages/api-kit/tests/e2e/addMessageSignature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import Safe, {
EthSafeSignature,
buildSignatureBytes,
hashSafeMessage,
SigningMethod,
buildContractSignature
} from '@safe-global/protocol-kit'
import { SafeMessage } from '@safe-global/types-kit'
import { SafeMessage, SigningMethod } from '@safe-global/types-kit'
import SafeApiKit from '@safe-global/api-kit/index'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
Expand Down
9 changes: 5 additions & 4 deletions packages/api-kit/tests/e2e/addSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
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
// Needs to be imported from dist folder in order to mock the createBundlerClient function
import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils'
import { getKits } from '../utils/setupKits'

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('addSafeOperation', () => {
const requestStub = sinon.stub()
// Setup mocks for the bundler client
before(async () => {
sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({
sinon.stub(safe4337Utils, 'createBundlerClient').returns({
request: requestStub,
readContract: sinon
.stub()
Expand Down Expand Up @@ -77,7 +77,9 @@ describe('addSafeOperation', () => {
signer: protocolKit.getSafeProvider().signer,
options: { safeAddress: SAFE_ADDRESS },
bundlerUrl: BUNDLER_URL,
safeModulesVersion: '0.2.0',
paymasterOptions: {
paymasterUrl: 'https://paymaster.url',
paymasterTokenAddress: PAYMASTER_TOKEN_ADDRESS,
paymasterAddress: PAYMASTER_ADDRESS
}
Expand Down Expand Up @@ -178,12 +180,11 @@ describe('addSafeOperation', () => {
chai.expect(safeOperationsAfter.count).to.equal(initialNumSafeOperations + 1)
})

it('should add a new SafeOperation using a SafeOperation object from the relay-kit', async () => {
it.only('should add a new SafeOperation using a SafeOperation object from the relay-kit', async () => {
const safeOperation = await safe4337Pack.createTransaction({
transactions: [transferUSDC, transferUSDC]
})
const signedSafeOperation = await safe4337Pack.signSafeOperation(safeOperation)

// Get the number of SafeOperations before adding a new one
const safeOperationsBefore = await safeApiKit.getSafeOperationsByAddress({
safeAddress: SAFE_ADDRESS
Expand Down
22 changes: 15 additions & 7 deletions packages/api-kit/tests/e2e/confirmSafeOperation.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import sinon from 'sinon'
import { BundlerClient, Safe4337InitOptions, Safe4337Pack } from '@safe-global/relay-kit'
import {
BundlerClient,
Safe4337InitOptions,
Safe4337Pack,
SafeOperationBase
} from '@safe-global/relay-kit'
import { generateTransferCallData } from '@safe-global/relay-kit/packs/safe-4337/testing-utils/helpers'
import SafeApiKit from '@safe-global/api-kit/index'
import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation'
import { SafeOperation } from '@safe-global/types-kit'
// Needs to be imported from dist folder in order to mock the getEip4337BundlerProvider function
// Needs to be imported from dist folder in order to mock the createBundlerClient function
import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils'
import { getApiKit, getEip1193Provider } from '../utils/setupKits'
import {
Expand All @@ -16,8 +21,8 @@ import {

chai.use(chaiAsPromised)

const PRIVATE_KEY_1 = '0x83a415ca62e11f5fa5567e98450d0f82ae19ff36ef876c10a8d448c788a53676'
const PRIVATE_KEY_2 = '0xb88ad5789871315d0dab6fc5961d6714f24f35a6393f13a6f426dfecfc00ab44'
const PRIVATE_KEY_1 = '0x83a415ca62e11f5fa5567e98450d0f82ae19ff36ef876c10a8d448c788a53676' // 0x56e2C102c664De6DfD7315d12c0178b61D16F171
const PRIVATE_KEY_2 = '0xb88ad5789871315d0dab6fc5961d6714f24f35a6393f13a6f426dfecfc00ab44' // 0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B
const SAFE_ADDRESS = '0x60C4Ab82D06Fd7dFE9517e17736C2Dcc77443EF0' // 4337 enabled 1/2 Safe (v1.4.1) owned by PRIVATE_KEY_1 + PRIVATE_KEY_2
const TX_SERVICE_URL = 'https://safe-transaction-sepolia.staging.5afe.dev/api'
const BUNDLER_URL = `https://bundler.url`
Expand All @@ -41,12 +46,15 @@ describe('confirmSafeOperation', () => {
provider: options.provider || getEip1193Provider(),
signer: options.signer || PRIVATE_KEY_1,
options: { safeAddress: SAFE_ADDRESS },
bundlerUrl: BUNDLER_URL
bundlerUrl: BUNDLER_URL,
safeModulesVersion: '0.2.0'
})

const createSignature = async (safeOperation: SafeOperation, signer: string) => {
const safe4337Pack = await getSafe4337Pack({ signer })
const signedSafeOperation = await safe4337Pack.signSafeOperation(safeOperation)
const signedSafeOperation = await safe4337Pack.signSafeOperation(
safeOperation as SafeOperationBase
)
const signerAddress = await safe4337Pack.protocolKit.getSafeProvider().getSignerAddress()
return signedSafeOperation.getSignature(signerAddress!)
}
Expand All @@ -71,7 +79,7 @@ describe('confirmSafeOperation', () => {
const requestStub = sinon.stub()

before(async () => {
sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({
sinon.stub(safe4337Utils, 'createBundlerClient').returns({
request: requestStub
} as unknown as BundlerClient)

Expand Down
4 changes: 2 additions & 2 deletions packages/api-kit/tests/e2e/confirmTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Safe, {
EthSafeSignature,
buildSignatureBytes,
SigningMethod,
buildContractSignature
} from '@safe-global/protocol-kit'
import {
SafeMultisigConfirmationResponse,
SafeTransactionDataPartial
SafeTransactionDataPartial,
SigningMethod
} from '@safe-global/types-kit'
import SafeApiKit from '@safe-global/api-kit/index'
import chai from 'chai'
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
Transaction,
EIP712TypedData,
SafeTransactionData,
CompatibilityFallbackHandlerContractType
CompatibilityFallbackHandlerContractType,
SigningMethod,
SigningMethodType
} from '@safe-global/types-kit'
import {
encodeSetupCallData,
Expand All @@ -39,8 +41,6 @@ import {
RemoveOwnerTxParams,
SafeConfig,
SafeConfigProps,
SigningMethod,
SigningMethodType,
SwapOwnerTxParams,
SafeModulesPaginated,
RemovePasskeyOwnerTxParams,
Expand Down
1 change: 0 additions & 1 deletion packages/protocol-kit/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './contracts'
export * from './safeConfig'
export * from './safeProvider'
export * from './signing'
export * from './transactions'
export * from './passkeys'
9 changes: 0 additions & 9 deletions packages/protocol-kit/src/types/signing.ts

This file was deleted.

8 changes: 6 additions & 2 deletions packages/protocol-kit/src/utils/signatures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { recoverAddress } from 'viem'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { SafeSignature, SafeEIP712Args, SafeTransactionData } from '@safe-global/types-kit'
import {
SafeSignature,
SafeEIP712Args,
SafeTransactionData,
SigningMethod
} from '@safe-global/types-kit'
import semverSatisfies from 'semver/functions/satisfies'
import { sameString } from '../address'
import { EthSafeSignature } from './SafeSignature'
import { getEip712MessageTypes, getEip712TxTypes } from '../eip-712'
import { SigningMethod } from '@safe-global/protocol-kit/types'
import { hashTypedData } from '../eip-712'
import { encodeTypedData } from '../eip-712/encode'
import { asHash, asHex } from '../types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
getSafeWithOwners,
itif
} from '@safe-global/testing-kit'
import { SafeTransactionDataPartial } from '@safe-global/types-kit'
import { SigningMethod } from '@safe-global/protocol-kit/types'
import { SafeTransactionDataPartial, SigningMethod } from '@safe-global/types-kit'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol-kit/tests/e2e/eip1271.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
itif
} from '@safe-global/testing-kit'
import SafeMessage from '@safe-global/protocol-kit/utils/messages/SafeMessage'
import { OperationType, SafeTransactionDataPartial } from '@safe-global/types-kit'
import { SigningMethod } from '@safe-global/protocol-kit/types'
import { OperationType, SafeTransactionDataPartial, SigningMethod } from '@safe-global/types-kit'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-kit/tests/e2e/execution.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getERC20Mintable, safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit'
import Safe, { SigningMethod } from '@safe-global/protocol-kit/index'
import { TransactionOptions, MetaTransactionData } from '@safe-global/types-kit'
import Safe from '@safe-global/protocol-kit/index'
import { TransactionOptions, MetaTransactionData, SigningMethod } from '@safe-global/types-kit'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { waitSafeTxReceipt } from './utils/transactions'
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-kit/tests/e2e/offChainSignatures.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit'
import Safe, { SigningMethod } from '@safe-global/protocol-kit/index'
import { SafeMultisigTransactionResponse } from '@safe-global/types-kit'
import Safe from '@safe-global/protocol-kit/index'
import { SafeMultisigTransactionResponse, SigningMethod } from '@safe-global/types-kit'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/tests/e2e/utilsSignatures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
adjustVInSignature,
isTxHashSignedWithPrefix
} from '@safe-global/protocol-kit/utils/signatures'
import { SigningMethod } from '@safe-global/protocol-kit/index'
import { SigningMethod } from '@safe-global/types-kit'

const safeTxHash = '0x4de27e660bd23052b71c854b0188ef1c5b325b10075c70f27afe2343e5c287f5'
const signerAddress = '0xbc2BB26a6d821e69A38016f3858561a1D80d4182'
Expand Down
5 changes: 4 additions & 1 deletion packages/relay-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export * from './packs/gelato/GelatoRelayPack'
export * from './packs/gelato/types'

export * from './packs/safe-4337/Safe4337Pack'
export { default as EthSafeOperation } from './packs/safe-4337/SafeOperation'
export { default as SafeOperationBase } from './packs/safe-4337/SafeOperationBase'
export { default as SafeOperationV07 } from './packs/safe-4337/SafeOperationV07'
export { default as SafeOperationV06 } from './packs/safe-4337/SafeOperationV06'
export { default as SafeOperationFactory } from './packs/safe-4337/SafeOperationFactory'

export * from './packs/safe-4337/estimators'
export * from './packs/safe-4337/types'
Expand Down
Loading
Loading