Skip to content

Commit

Permalink
Move shared types to safe-core-sdk-types
Browse files Browse the repository at this point in the history
  • Loading branch information
tmjssz committed Apr 29, 2024
1 parent f0846b4 commit 295b68b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Signer, TypedDataDomain, TypedDataField } from 'ethers'
import {
SafeMultisigTransactionResponse,
SafeOperation,
SafeTransactionData
} from '@safe-global/safe-core-sdk-types'
import SafeOperation from '@safe-global/relay-kit/src/packs/safe-4337/SafeOperation'

export type SafeServiceInfoResponse = {
readonly name: string
Expand Down
3 changes: 1 addition & 2 deletions packages/api-kit/tests/endpoint/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import SafeApiKit, {
} from '@safe-global/api-kit/index'
import * as httpRequests from '@safe-global/api-kit/utils/httpRequests'
import Safe from '@safe-global/protocol-kit'
import { EthAdapter } from '@safe-global/safe-core-sdk-types'
import { EthAdapter, SafeOperation } from '@safe-global/safe-core-sdk-types'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import config from '../utils/config'
import { getServiceClient } from '../utils/setupServiceClient'
import SafeOperation from '@safe-global/relay-kit/packs/safe-4337/SafeOperation'

chai.use(chaiAsPromised)
chai.use(sinonChai)
Expand Down
11 changes: 7 additions & 4 deletions packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import Safe, {
getMultiSendContract
} from '@safe-global/protocol-kit'
import { RelayKitBasePack } from '@safe-global/relay-kit/RelayKitBasePack'
import { MetaTransactionData, OperationType, SafeSignature } from '@safe-global/safe-core-sdk-types'
import {
MetaTransactionData,
OperationType,
SafeSignature,
UserOperation,
SafeUserOperation
} from '@safe-global/safe-core-sdk-types'
import {
getAddModulesLibDeployment,
getSafe4337ModuleDeployment
} from '@safe-global/safe-modules-deployments'

import SafeOperation from './SafeOperation'
import {
EstimateFeeProps,
Safe4337CreateTransactionProps,
Safe4337ExecutableProps,
Safe4337InitOptions,
Safe4337Options,
SafeUserOperation,
UserOperation,
UserOperationReceipt,
UserOperationWithPayload,
PaymasterOptions
Expand Down
12 changes: 8 additions & 4 deletions packages/relay-kit/src/packs/safe-4337/SafeOperation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { ethers } from 'ethers'
import { SafeSignature } from '@safe-global/safe-core-sdk-types'
import {
EstimateGasData,
SafeOperation as SafeOperationType,
SafeSignature,
SafeUserOperation,
UserOperation
} from '@safe-global/safe-core-sdk-types'
import { buildSignatureBytes } from '@safe-global/protocol-kit'

import { EstimateGasData, SafeUserOperation, UserOperation } from './types'

type SafeOperationOptions = { entryPoint: string; validAfter?: number; validUntil?: number }

class SafeOperation {
class SafeOperation implements SafeOperationType {
data: SafeUserOperation
signatures: Map<string, SafeSignature> = new Map()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { EstimateGasData } from '@safe-global/safe-core-sdk-types'
import {
EstimateFeeFunctionProps,
EstimateGasData,
EstimateSponsoredFeeFunctionProps,
EstimateSponsoredGasData,
IFeeEstimator
Expand Down
45 changes: 6 additions & 39 deletions packages/relay-kit/src/packs/safe-4337/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Safe, { EthersAdapter } from '@safe-global/protocol-kit'
import { MetaTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types'
import {
EstimateGasData,
MetaTransactionData,
SafeVersion,
UserOperation
} from '@safe-global/safe-core-sdk-types'
import { ethers } from 'ethers'
import SafeOperation from './SafeOperation'

Expand Down Expand Up @@ -61,44 +66,6 @@ export type Safe4337ExecutableProps = {
executable: SafeOperation
}

export type SafeUserOperation = {
safe: string
nonce: bigint
initCode: string
callData: string
callGasLimit: bigint
verificationGasLimit: bigint
preVerificationGas: bigint
maxFeePerGas: bigint
maxPriorityFeePerGas: bigint
paymasterAndData: string
validAfter: number
validUntil: number
entryPoint: string
}

export type UserOperation = {
sender: string
nonce: string
initCode: string
callData: string
callGasLimit: bigint
verificationGasLimit: bigint
preVerificationGas: bigint
maxFeePerGas: bigint
maxPriorityFeePerGas: bigint
paymasterAndData: string
signature: string
}

export type EstimateGasData = {
maxFeePerGas?: bigint
maxPriorityFeePerGas?: bigint
preVerificationGas?: bigint
verificationGasLimit?: bigint
callGasLimit?: bigint
}

export type EstimateSponsoredGasData = {
paymasterAndData: string
} & EstimateGasData
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-kit/src/packs/safe-4337/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers'
import { UserOperation } from './types'
import { UserOperation } from '@safe-global/safe-core-sdk-types'

/**
* Gets the EIP-4337 bundler provider.
Expand Down
48 changes: 48 additions & 0 deletions packages/safe-core-sdk-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,51 @@ export interface MetaTransactionOptions {
gasToken?: string
isSponsored?: boolean
}

export type UserOperation = {
sender: string
nonce: string
initCode: string
callData: string
callGasLimit: bigint
verificationGasLimit: bigint
preVerificationGas: bigint
maxFeePerGas: bigint
maxPriorityFeePerGas: bigint
paymasterAndData: string
signature: string
}

export type SafeUserOperation = {
safe: string
nonce: bigint
initCode: string
callData: string
callGasLimit: bigint
verificationGasLimit: bigint
preVerificationGas: bigint
maxFeePerGas: bigint
maxPriorityFeePerGas: bigint
paymasterAndData: string
validAfter: number
validUntil: number
entryPoint: string
}

export type EstimateGasData = {
maxFeePerGas?: bigint
maxPriorityFeePerGas?: bigint
preVerificationGas?: bigint
verificationGasLimit?: bigint
callGasLimit?: bigint
}

export interface SafeOperation {
readonly data: SafeUserOperation
readonly signatures: Map<string, SafeSignature>
getSignature(signer: string): SafeSignature | undefined
addSignature(signature: SafeSignature): void
encodedSignatures(): string
addEstimations(estimations: EstimateGasData): void
toUserOperation(): UserOperation
}

0 comments on commit 295b68b

Please sign in to comment.