• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-core-sdk / 12008523214

25 Nov 2024 10:55AM CUT coverage: 75.515%. Remained the same
12008523214

push

github

web-flow
feat(protocol-kit): Add react native compatibility (#1033)

241 of 390 branches covered (61.79%)

Branch coverage included in aggregate %.

786 of 970 relevant lines covered (81.03%)

3.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.0
/packages/sdk-starter-kit/src/extensions/safe-operations/safeOperations.ts
1
import { PredictedSafeProps } from '@safe-global/protocol-kit'
2
import { GetSafeOperationListResponse, ListOptions } from '@safe-global/api-kit'
3
import { PaymasterOptions, Safe4337Pack } from '@safe-global/relay-kit'
2✔
4

5
import { SafeClient } from '@safe-global/sdk-starter-kit/SafeClient'
6
import { SafeOperationClient } from '@safe-global/sdk-starter-kit/extensions/safe-operations/SafeOperationClient'
2✔
7
import {
8
  ConfirmSafeOperationProps,
9
  SafeClientResult,
10
  SendSafeOperationProps
11
} from '@safe-global/sdk-starter-kit/types'
12

13
export type BundlerOptions = {
14
  bundlerUrl: string
15
}
16

17
/**
18
 * Extend the SafeClient with the ability to use a bundler and a paymaster
19
 *
20
 * @example
21
 * const safeClient = await createSafeClient({ ... })
22
 *
23
 * const safeOperationClient = await safeClient.extend(
24
 *   safeOperations({ ... }, { ... })
25
 * )
26
 *
27
 * const { safeOperations } = await safeOperationClient.sendSafeOperation({ transactions })
28
 * await safeOperationClient.confirmSafeOperation({ safeOperationHash: safeOperations?.safeOperationHash})
29
 */
30
export function safeOperations(
2✔
31
  { bundlerUrl }: BundlerOptions,
32
  paymasterOptions?: PaymasterOptions
33
) {
34
  return async (client: SafeClient) => {
1✔
35
    const { provider, signer } = client.protocolKit.getSafeProvider()
1✔
36
    const isSafeDeployed = await client.protocolKit.isSafeDeployed()
1✔
37

38
    let options
39
    if (isSafeDeployed) {
1!
40
      const safeAddress = await client.protocolKit.getAddress()
×
41

42
      options = {
×
43
        safeAddress
44
      }
45
    } else {
46
      const { safeDeploymentConfig, safeAccountConfig } =
47
        client.protocolKit.getPredictedSafe() as PredictedSafeProps
1✔
48

49
      options = {
1✔
50
        owners: safeAccountConfig.owners,
51
        threshold: safeAccountConfig.threshold,
52
        ...safeDeploymentConfig
53
      }
54
    }
55

56
    const safe4337Pack = await Safe4337Pack.init({
1✔
57
      provider,
58
      signer,
59
      bundlerUrl,
60
      options,
61
      paymasterOptions
62
    })
63

64
    client.protocolKit = safe4337Pack.protocolKit
1✔
65

66
    const safeOperationClient = new SafeOperationClient(safe4337Pack, client.apiKit)
1✔
67

68
    return {
1✔
69
      /**
70
       * Send SafeOperations from a group of transactions.
71
       * This method will convert your transactions in a batch and:
72
       * - If the threshold > 1 it will save for later the SafeOperation using the Transaction service
73
       *   You must confirmSafeOperation() with other owners
74
       * - If the threshold = 1 the SafeOperation can be submitted to the bundler so it will execute it immediately
75
       *
76
       * @param {Safe4337CreateTransactionProps} props The Safe4337CreateTransactionProps object
77
       * @returns {Promise<SafeClientResult>} A promise that resolves with the status of the SafeOperation
78
       */
79
      async sendSafeOperation(props: SendSafeOperationProps): Promise<SafeClientResult> {
80
        return safeOperationClient.sendSafeOperation(props)
×
81
      },
82
      /**
83
       * Confirms the stored safeOperation
84
       *
85
       * @param {ConfirmSafeOperationProps} props The ConfirmSafeOperationProps object
86
       * @returns {Promise<SafeClientResult>} A promise that resolves to the result of the safeOperation.
87
       */
88
      async confirmSafeOperation(props: ConfirmSafeOperationProps): Promise<SafeClientResult> {
89
        return safeOperationClient.confirmSafeOperation(props)
×
90
      },
91
      /**
92
       * Retrieves the pending Safe operations for the current Safe account
93
       *
94
       * @async
95
       * @param {ListOptions} options The pagination options
96
       * @returns {Promise<GetSafeOperationListResponse>} A promise that resolves to an array of pending Safe operations.
97
       * @throws {Error} If there is an issue retrieving the safe address or pending Safe operations.
98
       */
99
      async getPendingSafeOperations(options?: ListOptions): Promise<GetSafeOperationListResponse> {
100
        return safeOperationClient.getPendingSafeOperations(options)
×
101
      }
102
    }
103
  }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc