diff --git a/.changeset/chilled-lamps-heal.md b/.changeset/chilled-lamps-heal.md new file mode 100644 index 000000000..79c6f77c3 --- /dev/null +++ b/.changeset/chilled-lamps-heal.md @@ -0,0 +1,6 @@ +--- +'@hyperlane-xyz/infra': patch +'@hyperlane-xyz/sdk': patch +--- + +Removes Gnosis safe util from infra in favor of SDK diff --git a/.husky/pre-commit b/.husky/pre-commit index ea48d6b17..8eb8e9c84 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -3,6 +3,8 @@ yarn lint-staged +echo "📝 If you haven't yet, please add a changeset for your changes via 'yarn changeset'" + # if any *.rs files have changed if git diff --staged --exit-code --name-only | grep -q -E ".*\.rs$"; then echo "Running cargo fmt pre-commit hook" diff --git a/typescript/infra/package.json b/typescript/infra/package.json index cb062f9e7..f65cfdc58 100644 --- a/typescript/infra/package.json +++ b/typescript/infra/package.json @@ -17,8 +17,6 @@ "@hyperlane-xyz/sdk": "3.10.0", "@hyperlane-xyz/utils": "3.10.0", "@nomiclabs/hardhat-etherscan": "^3.0.3", - "@safe-global/api-kit": "^1.3.0", - "@safe-global/protocol-kit": "^1.2.0", "@solana/web3.js": "^1.78.0", "asn1.js": "5.4.1", "aws-kms-ethers-signer": "^0.1.3", diff --git a/typescript/infra/scripts/safe-delegate.ts b/typescript/infra/scripts/safe-delegate.ts index f067c2db8..74c08d210 100644 --- a/typescript/infra/scripts/safe-delegate.ts +++ b/typescript/infra/scripts/safe-delegate.ts @@ -4,8 +4,9 @@ import { LedgerSigner } from '@ethersproject/hardware-wallets'; import '@ethersproject/hardware-wallets/thirdparty'; import { AddSafeDelegateProps } from '@safe-global/api-kit'; +import { getSafeDelegates, getSafeService } from '@hyperlane-xyz/sdk'; + import { getChains } from '../config/registry.js'; -import { getSafeDelegates, getSafeService } from '../src/utils/safe.js'; import { getArgs as getRootArgs } from './agent-utils.js'; import { getEnvironmentConfig } from './core-utils.js'; diff --git a/typescript/infra/src/govern/HyperlaneAppGovernor.ts b/typescript/infra/src/govern/HyperlaneAppGovernor.ts index 98444af86..78256d090 100644 --- a/typescript/infra/src/govern/HyperlaneAppGovernor.ts +++ b/typescript/infra/src/govern/HyperlaneAppGovernor.ts @@ -11,6 +11,7 @@ import { InterchainAccount, OwnableConfig, OwnerViolation, + canProposeSafeTransactions, } from '@hyperlane-xyz/sdk'; import { Address, @@ -20,8 +21,6 @@ import { objMap, } from '@hyperlane-xyz/utils'; -import { canProposeSafeTransactions } from '../utils/safe.js'; - import { ManualMultiSend, MultiSend, diff --git a/typescript/infra/src/govern/multisend.ts b/typescript/infra/src/govern/multisend.ts index 56929e902..3d173cb2b 100644 --- a/typescript/infra/src/govern/multisend.ts +++ b/typescript/infra/src/govern/multisend.ts @@ -1,8 +1,11 @@ -import { ChainName, MultiProvider } from '@hyperlane-xyz/sdk'; +import { + ChainName, + MultiProvider, + getSafe, + getSafeService, +} from '@hyperlane-xyz/sdk'; import { CallData } from '@hyperlane-xyz/utils'; -import { getSafe, getSafeService } from '../utils/safe.js'; - export abstract class MultiSend { abstract sendTransactions(calls: CallData[]): Promise; } diff --git a/typescript/infra/src/utils/safe.ts b/typescript/infra/src/utils/safe.ts deleted file mode 100644 index ae6343dde..000000000 --- a/typescript/infra/src/utils/safe.ts +++ /dev/null @@ -1,62 +0,0 @@ -import SafeApiKit from '@safe-global/api-kit'; -import Safe, { EthersAdapter } from '@safe-global/protocol-kit'; -import { ethers } from 'ethers'; - -import { ChainName, MultiProvider } from '@hyperlane-xyz/sdk'; - -import { getChain } from '../../config/registry.js'; - -// NOTE about Safe: -// Accessing lib through .default due to https://github.com/safe-global/safe-core-sdk/issues/419 -// See also https://github.com/safe-global/safe-core-sdk/issues/514 - -export function getSafeService( - chain: ChainName, - multiProvider: MultiProvider, -): SafeApiKit.default { - const signer = multiProvider.getSigner(chain); - const ethAdapter = new EthersAdapter({ ethers, signerOrProvider: signer }); - const txServiceUrl = getChain(chain).gnosisSafeTransactionServiceUrl; - if (!txServiceUrl) - throw new Error(`must provide tx service url for ${chain}`); - return new SafeApiKit.default({ txServiceUrl, ethAdapter }); -} - -export function getSafe( - chain: ChainName, - multiProvider: MultiProvider, - safeAddress: string, -): Promise { - const signer = multiProvider.getSigner(chain); - const ethAdapter = new EthersAdapter({ ethers, signerOrProvider: signer }); - return Safe.default.create({ - ethAdapter, - safeAddress: safeAddress, - }); -} - -export async function getSafeDelegates( - service: SafeApiKit.default, - safeAddress: string, -) { - const delegateResponse = await service.getSafeDelegates({ safeAddress }); - return delegateResponse.results.map((r) => r.delegate); -} - -export async function canProposeSafeTransactions( - proposer: string, - chain: ChainName, - multiProvider: MultiProvider, - safeAddress: string, -): Promise { - let safeService; - try { - safeService = getSafeService(chain, multiProvider); - } catch (e) { - return false; - } - const safe = await getSafe(chain, multiProvider, safeAddress); - const delegates = await getSafeDelegates(safeService, safeAddress); - const owners = await safe.getOwners(); - return delegates.includes(proposer) || owners.includes(proposer); -} diff --git a/typescript/sdk/package.json b/typescript/sdk/package.json index 7d87b1d1f..1ae0e9029 100644 --- a/typescript/sdk/package.json +++ b/typescript/sdk/package.json @@ -66,8 +66,8 @@ ], "license": "Apache-2.0", "scripts": { - "build": "yarn build:fixSafeLib && tsc", - "build:fixSafeLib": "rm -rf ../../node_modules/@safe-global/protocol-kit/dist/typechain/", + "build": "yarn build:fixSafeGlobalLib && tsc", + "build:fixSafeGlobalLib": "rm -rf ../../node_modules/@safe-global/protocol-kit/dist/typechain/src/web3-v1/**/Multi_send.ts", "dev": "tsc --watch", "check": "tsc --noEmit", "clean": "rm -rf ./dist ./cache", diff --git a/typescript/sdk/src/index.ts b/typescript/sdk/src/index.ts index c185d1442..0fc7ad3ed 100644 --- a/typescript/sdk/src/index.ts +++ b/typescript/sdk/src/index.ts @@ -236,6 +236,17 @@ export { InterchainQueryDeployer, } from './middleware/query/InterchainQueryDeployer.js'; export { interchainQueryFactories } from './middleware/query/contracts.js'; +export { TxSubmitterBuilder } from './providers/transactions/submitter/builder/TxSubmitterBuilder.js'; +export { EV5GnosisSafeTxSubmitter } from './providers/transactions/submitter/ethersV5/EV5GnosisSafeTxSubmitter.js'; +export { EV5ImpersonatedAccountTxSubmitter } from './providers/transactions/submitter/ethersV5/EV5ImpersonatedAccountTxSubmitter.js'; +export { EV5JsonRpcTxSubmitter } from './providers/transactions/submitter/ethersV5/EV5JsonRpcTxSubmitter.js'; +export { EV5TxSubmitterInterface } from './providers/transactions/submitter/ethersV5/EV5TxSubmitterInterface.js'; +export { TxSubmitterInterface } from './providers/transactions/submitter/TxSubmitterInterface.js'; +export { TxSubmitterType } from './providers/transactions/submitter/TxSubmitterTypes.js'; +export { EV5InterchainAccountTxTransformer } from './providers/transactions/transformer/ethersV5/EV5InterchainAccountTxTransformer.js'; +export { EV5TxTransformerInterface } from './providers/transactions/transformer/ethersV5/EV5TxTransformerInterface.js'; +export { TxTransformerInterface } from './providers/transactions/transformer/TxTransformerInterface.js'; +export { TxTransformerType } from './providers/transactions/transformer/TxTransformerTypes.js'; export { MultiProtocolProvider, MultiProtocolProviderOptions, @@ -442,6 +453,12 @@ export { setFork, stopImpersonatingAccount, } from './utils/fork.js'; +export { + getSafeService, + getSafe, + getSafeDelegates, + canProposeSafeTransactions, +} from './utils/gnosisSafe.js'; export { multisigIsmVerificationCost } from './utils/ism.js'; export { SealevelAccountDataWrapper, diff --git a/yarn.lock b/yarn.lock index 7f158b426..f11e360c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5092,8 +5092,6 @@ __metadata: "@nomiclabs/hardhat-ethers": "npm:^2.2.3" "@nomiclabs/hardhat-etherscan": "npm:^3.0.3" "@nomiclabs/hardhat-waffle": "npm:^2.0.6" - "@safe-global/api-kit": "npm:^1.3.0" - "@safe-global/protocol-kit": "npm:^1.2.0" "@solana/web3.js": "npm:^1.78.0" "@types/chai": "npm:^4.2.21" "@types/json-stable-stringify": "npm:^1.0.36" @@ -7235,7 +7233,7 @@ __metadata: languageName: node linkType: hard -"@safe-global/api-kit@npm:1.3.0, @safe-global/api-kit@npm:^1.3.0": +"@safe-global/api-kit@npm:1.3.0": version: 1.3.0 resolution: "@safe-global/api-kit@npm:1.3.0" dependencies: @@ -7264,23 +7262,6 @@ __metadata: languageName: node linkType: hard -"@safe-global/protocol-kit@npm:^1.2.0": - version: 1.2.0 - resolution: "@safe-global/protocol-kit@npm:1.2.0" - dependencies: - "@ethersproject/address": "npm:^5.7.0" - "@ethersproject/bignumber": "npm:^5.7.0" - "@ethersproject/solidity": "npm:^5.7.0" - "@safe-global/safe-deployments": "npm:^1.26.0" - ethereumjs-util: "npm:^7.1.5" - semver: "npm:^7.5.4" - web3: "npm:^1.8.1" - web3-core: "npm:^1.8.1" - web3-utils: "npm:^1.8.1" - checksum: f6c6969ee5638fc1af1bf56f7848915bb9cb1e6a3f57f4e9b235f3f251c3a5f8cde6bad13bd8b9a321424cdecdad34e02ad13de3b4fe8fae32acc9000e52b4dc - languageName: node - linkType: hard - "@safe-global/safe-apps-provider@npm:^0.15.2": version: 0.15.2 resolution: "@safe-global/safe-apps-provider@npm:0.15.2"