From 72c04ca469f183225696cec259e6045fe6fd4847 Mon Sep 17 00:00:00 2001
From: Aaron Cook <aaron@safe.global>
Date: Fri, 18 Oct 2024 17:07:09 +0200
Subject: [PATCH] fix: migrate to published SDK (#4393)

---
 jest.setup.js                                 |   8 +-
 package.json                                  |   2 +-
 .../__tests__/useSafeCreationData.test.ts     | 215 ++++++++----------
 .../multichain/hooks/useSafeCreationData.ts   |  13 +-
 src/pages/_app.tsx                            |   2 +-
 yarn.lock                                     |  21 +-
 6 files changed, 117 insertions(+), 144 deletions(-)

diff --git a/jest.setup.js b/jest.setup.js
index 08425f8b65..ec8ccaa216 100644
--- a/jest.setup.js
+++ b/jest.setup.js
@@ -5,7 +5,7 @@
 // Learn more: https://github.com/testing-library/jest-dom
 import '@testing-library/jest-dom/extend-expect'
 import { TextEncoder, TextDecoder } from 'util'
-import { Headers, Request, Response } from 'node-fetch'
+import { Request } from 'node-fetch'
 
 jest.mock('@web3-onboard/coinbase', () => jest.fn())
 jest.mock('@web3-onboard/injected-wallets', () => ({ ProviderLabel: { MetaMask: 'MetaMask' } }))
@@ -13,7 +13,7 @@ jest.mock('@web3-onboard/keystone/dist/index', () => jest.fn())
 jest.mock('@web3-onboard/ledger/dist/index', () => jest.fn())
 jest.mock('@web3-onboard/trezor', () => jest.fn())
 jest.mock('@web3-onboard/walletconnect', () => jest.fn())
-jest.mock('safe-client-gateway-sdk')
+jest.mock('@safe-global/safe-client-gateway-sdk')
 
 const mockOnboardState = {
   chains: [],
@@ -71,7 +71,5 @@ Object.defineProperty(Uint8Array, Symbol.hasInstance, {
   },
 })
 
-// These are required for safe-client-gateway-sdk
+// These are required for @safe-global/safe-client-gateway-sdk
 globalThis.Request = Request
-globalThis.Response = Response
-globalThis.Headers = Headers
diff --git a/package.json b/package.json
index d39c1b25f9..fd9201b034 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
     "@safe-global/protocol-kit": "^4.1.1",
     "@safe-global/safe-apps-sdk": "^9.1.0",
     "@safe-global/safe-deployments": "^1.37.10",
+    "@safe-global/safe-client-gateway-sdk": "1.58.0-next-25bba61",
     "@safe-global/safe-gateway-typescript-sdk": "3.22.3-beta.15",
     "@safe-global/safe-modules-deployments": "^2.2.1",
     "@sentry/react": "^7.91.0",
@@ -91,7 +92,6 @@
     "react-hook-form": "7.41.1",
     "react-papaparse": "^4.0.2",
     "react-redux": "^9.1.2",
-    "safe-client-gateway-sdk": "git+https://github.com/safe-global/safe-client-gateway-sdk.git#v1.53.0-next-7344903",
     "semver": "^7.6.3",
     "zodiac-roles-deployments": "^2.2.5"
   },
diff --git a/src/features/multichain/hooks/__tests__/useSafeCreationData.test.ts b/src/features/multichain/hooks/__tests__/useSafeCreationData.test.ts
index 1ea05115a2..3c6aba20e3 100644
--- a/src/features/multichain/hooks/__tests__/useSafeCreationData.test.ts
+++ b/src/features/multichain/hooks/__tests__/useSafeCreationData.test.ts
@@ -5,7 +5,7 @@ import { PendingSafeStatus, type UndeployedSafe } from '@/store/slices'
 import { PayMethod } from '@/features/counterfactual/PayNowPayLater'
 import { chainBuilder } from '@/tests/builders/chains'
 import * as sdk from '@/services/tx/tx-sender/sdk'
-import * as cgwSdk from 'safe-client-gateway-sdk'
+import * as cgwSdk from '@safe-global/safe-client-gateway-sdk'
 import * as web3 from '@/hooks/wallets/web3'
 import { encodeMultiSendData, type SafeProvider } from '@safe-global/protocol-kit'
 import { Safe__factory, Safe_proxy_factory__factory } from '@/types/contracts'
@@ -210,10 +210,7 @@ describe('useSafeCreationData', () => {
   })
 
   it('should throw an error if creation data cannot be found', async () => {
-    jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      response: new Response(),
-      data: undefined,
-    } as any)
+    jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue(undefined as any)
 
     const safeAddress = faker.finance.ethereumAddress()
     const chainInfos = [chainBuilder().with({ chainId: '1', l2: false }).build()]
@@ -228,15 +225,13 @@ describe('useSafeCreationData', () => {
 
   it('should throw an error if Safe creation data is incomplete', async () => {
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: null,
-        setupData: null,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: null,
+      setupData: null,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     const safeAddress = faker.finance.ethereumAddress()
@@ -252,15 +247,13 @@ describe('useSafeCreationData', () => {
 
   it('should throw an error if Safe setupData is empty', async () => {
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: faker.finance.ethereumAddress(),
-        setupData: '0x',
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: faker.finance.ethereumAddress(),
+      setupData: '0x',
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     const safeAddress = faker.finance.ethereumAddress()
@@ -287,15 +280,13 @@ describe('useSafeCreationData', () => {
     ])
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: getSafeSingletonDeployment({ version: '1.1.1' })?.defaultAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: getSafeSingletonDeployment({ version: '1.1.1' })?.defaultAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     const safeAddress = faker.finance.ethereumAddress()
@@ -326,15 +317,13 @@ describe('useSafeCreationData', () => {
     ])
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: faker.finance.ethereumAddress(),
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: faker.finance.ethereumAddress(),
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     const safeAddress = faker.finance.ethereumAddress()
@@ -365,15 +354,13 @@ describe('useSafeCreationData', () => {
     ])
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     const safeAddress = faker.finance.ethereumAddress()
@@ -400,15 +387,13 @@ describe('useSafeCreationData', () => {
     ])
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     const safeAddress = faker.finance.ethereumAddress()
@@ -435,15 +420,13 @@ describe('useSafeCreationData', () => {
     ])
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: faker.finance.ethereumAddress(),
-        transactionHash: faker.string.hexadecimal({ length: 64 }),
-        masterCopy: getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: faker.finance.ethereumAddress(),
+      transactionHash: faker.string.hexadecimal({ length: 64 }),
+      masterCopy: getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue(undefined)
@@ -476,15 +459,13 @@ describe('useSafeCreationData', () => {
     const mockMasterCopyAddress = getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: mockFactoryAddress,
-        transactionHash: mockTxHash,
-        masterCopy: mockMasterCopyAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: mockFactoryAddress,
+      transactionHash: mockTxHash,
+      masterCopy: mockMasterCopyAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue({
@@ -518,15 +499,13 @@ describe('useSafeCreationData', () => {
     const mockFactoryAddress = faker.finance.ethereumAddress()
     const mockMasterCopyAddress = getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress!
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: mockFactoryAddress,
-        transactionHash: mockTxHash,
-        masterCopy: mockMasterCopyAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: mockFactoryAddress,
+      transactionHash: mockTxHash,
+      masterCopy: mockMasterCopyAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue({
@@ -583,15 +562,13 @@ describe('useSafeCreationData', () => {
     const mockFactoryAddress = faker.finance.ethereumAddress()
     const mockMasterCopyAddress = getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress!
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: mockFactoryAddress,
-        transactionHash: mockTxHash,
-        masterCopy: mockMasterCopyAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: mockFactoryAddress,
+      transactionHash: mockTxHash,
+      masterCopy: mockMasterCopyAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue({
@@ -637,15 +614,13 @@ describe('useSafeCreationData', () => {
     const mockFactoryAddress = faker.finance.ethereumAddress()
     const mockMasterCopyAddress = getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress!
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: mockFactoryAddress,
-        transactionHash: mockTxHash,
-        masterCopy: mockMasterCopyAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: mockFactoryAddress,
+      transactionHash: mockTxHash,
+      masterCopy: mockMasterCopyAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue({
@@ -701,15 +676,13 @@ describe('useSafeCreationData', () => {
     const mockFactoryAddress = fakerChecksummedAddress()
     const mockMasterCopyAddress = getSafeSingletonDeployment({ version: '1.3.0' })?.defaultAddress!
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: fakerChecksummedAddress(),
-        factoryAddress: mockFactoryAddress,
-        transactionHash: mockTxHash,
-        masterCopy: mockMasterCopyAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: fakerChecksummedAddress(),
+      factoryAddress: mockFactoryAddress,
+      transactionHash: mockTxHash,
+      masterCopy: mockMasterCopyAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue({
@@ -777,15 +750,13 @@ describe('useSafeCreationData', () => {
     const mockMasterCopyAddress = getSafeSingletonDeployment({ version: '1.4.1' })?.defaultAddress!
 
     jest.spyOn(cgwSdk, 'getCreationTransaction').mockResolvedValue({
-      data: {
-        created: new Date(Date.now()).toISOString(),
-        creator: faker.finance.ethereumAddress(),
-        factoryAddress: mockFactoryAddress,
-        transactionHash: mockTxHash,
-        masterCopy: mockMasterCopyAddress,
-        setupData,
-      },
-      response: new Response(),
+      created: new Date(Date.now()).toISOString(),
+      creator: faker.finance.ethereumAddress(),
+      factoryAddress: mockFactoryAddress,
+      transactionHash: mockTxHash,
+      masterCopy: mockMasterCopyAddress,
+      setupData,
+      saltNonce: faker.string.hexadecimal({ length: 64 }),
     })
 
     jest.spyOn(web3, 'createWeb3ReadOnly').mockReturnValue({
diff --git a/src/features/multichain/hooks/useSafeCreationData.ts b/src/features/multichain/hooks/useSafeCreationData.ts
index b8e35abcb9..d4c60013f6 100644
--- a/src/features/multichain/hooks/useSafeCreationData.ts
+++ b/src/features/multichain/hooks/useSafeCreationData.ts
@@ -3,7 +3,7 @@ import { createWeb3ReadOnly } from '@/hooks/wallets/web3'
 import { type UndeployedSafe, selectRpc, type ReplayedSafeProps, selectUndeployedSafes } from '@/store/slices'
 import { Safe__factory, Safe_proxy_factory__factory } from '@/types/contracts'
 import { sameAddress } from '@/utils/addresses'
-import { getCreationTransaction } from 'safe-client-gateway-sdk'
+import { getCreationTransaction } from '@safe-global/safe-client-gateway-sdk'
 import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
 import { useAppSelector } from '@/store'
 import { determineMasterCopyVersion, isPredictedSafeProps } from '@/features/counterfactual/utils'
@@ -91,10 +91,12 @@ const getCreationDataForChain = async (
     return undeployedCreationData
   }
 
-  const { data: creation } = await getCreationTransaction({
-    path: {
-      chainId: chain.chainId,
-      safeAddress,
+  const creation = await getCreationTransaction({
+    params: {
+      path: {
+        chainId: chain.chainId,
+        safeAddress,
+      },
     },
   })
 
@@ -172,6 +174,7 @@ export const useSafeCreationData = (safeAddress: string, chains: ChainInfo[]): A
 
         try {
           const creationData = await getCreationDataForChain(chain, undeployedSafe, safeAddress, customRpc)
+          console.log({ creationData })
           return creationData
         } catch (err) {
           lastError = asError(err)
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index 2fa0067620..70ff8bcfd2 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -8,7 +8,7 @@ import CssBaseline from '@mui/material/CssBaseline'
 import type { Theme } from '@mui/material/styles'
 import { ThemeProvider } from '@mui/material/styles'
 import { setBaseUrl as setGatewayBaseUrl } from '@safe-global/safe-gateway-typescript-sdk'
-import { setBaseUrl as setNewGatewayBaseUrl } from 'safe-client-gateway-sdk'
+import { setBaseUrl as setNewGatewayBaseUrl } from '@safe-global/safe-client-gateway-sdk'
 import { CacheProvider, type EmotionCache } from '@emotion/react'
 import SafeThemeProvider from '@/components/theme/SafeThemeProvider'
 import '@/styles/globals.css'
diff --git a/yarn.lock b/yarn.lock
index c149a12884..1ede7813c9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4233,6 +4233,13 @@
     "@safe-global/safe-gateway-typescript-sdk" "^3.5.3"
     viem "^2.1.1"
 
+"@safe-global/safe-client-gateway-sdk@1.58.0-next-25bba61":
+  version "1.58.0-next-25bba61"
+  resolved "https://registry.yarnpkg.com/@safe-global/safe-client-gateway-sdk/-/safe-client-gateway-sdk-1.58.0-next-25bba61.tgz#1e5906d0a492ee72a77fbe1d782fee0376576968"
+  integrity sha512-sm19eckk6yjGOSgOOk4wE8pD7Ygdkr81ANyJUnOH1hr6RDxLgIkhvvatEI5aPB4vFD/iAKiJ2zMq19Pk1o41EA==
+  dependencies:
+    openapi-fetch "0.10.5"
+
 "@safe-global/safe-core-sdk-types@^5.0.1":
   version "5.0.2"
   resolved "https://registry.yarnpkg.com/@safe-global/safe-core-sdk-types/-/safe-core-sdk-types-5.0.2.tgz#9552f5793581333c81676986b3eb19697e1c6627"
@@ -14906,10 +14913,10 @@ open@^8.0.4:
     is-docker "^2.1.1"
     is-wsl "^2.2.0"
 
-openapi-fetch@^0.10.5:
-  version "0.10.6"
-  resolved "https://registry.yarnpkg.com/openapi-fetch/-/openapi-fetch-0.10.6.tgz#255017e3e609c5e7be16bc1ed7a973977c085cdc"
-  integrity sha512-6xXfvIEL/POtLGOaFPsp3O+pDe+J3DZYxbD9BrsQHXOTeNK8z/gsWHT6adUy1KcpQOhmkerMzlQrJM6DbN55dQ==
+openapi-fetch@0.10.5:
+  version "0.10.5"
+  resolved "https://registry.yarnpkg.com/openapi-fetch/-/openapi-fetch-0.10.5.tgz#ea714c7738cd7632df23521d20f32d906a3b5232"
+  integrity sha512-lOHWzQDYrMakHSqAOqJJGawitSGQzLM8w8zXTrpffe7u9aWqzFvhdJJNqfcW1EzaXtNNdPdMzXaFLdrjgn68ow==
   dependencies:
     openapi-typescript-helpers "^0.0.11"
 
@@ -16615,12 +16622,6 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1:
   resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
   integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
 
-"safe-client-gateway-sdk@git+https://github.com/safe-global/safe-client-gateway-sdk.git#v1.53.0-next-7344903":
-  version "1.53.0-next-7344903"
-  resolved "git+https://github.com/safe-global/safe-client-gateway-sdk.git#b0b91319b8753b41edd117bb6425729634250e15"
-  dependencies:
-    openapi-fetch "^0.10.5"
-
 safe-regex-test@^1.0.3:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/safe-regex-test/-/safe-regex-test-1.0.3.tgz#a5b4c0f06e0ab50ea2c395c14d8371232924c377"