export tx provider from sdk & remove safe util from infra (#3694)

### Description

* Exports new tx provider + Gnosis safe util from SDK
* Removes the Gnosis safe util from infra

### Drive-by changes

* Reminder to add a changeset
  * Output:
```
➜  hyperlane-monorepo-official git:(noah/move-safe) ✗ git commit -m "add changeset reminder to husky script"
  → No staged files match any configured task.
  📝 If you haven't yet, please add a changeset for your changes via 'yarn changeset'
  [noah/move-safe 3e668d0a7] add changeset reminder to husky script
   1 file changed, 2 insertions(+)
```

### Related issues

* Fixes https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/3684

### Backward compatibility

* Yes

### Testing

* n/a
pull/3696/head
Noah Bayindirli 🥂 6 months ago committed by GitHub
parent d37cbab724
commit a86a8296b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      .changeset/chilled-lamps-heal.md
  2. 2
      .husky/pre-commit
  3. 2
      typescript/infra/package.json
  4. 3
      typescript/infra/scripts/safe-delegate.ts
  5. 3
      typescript/infra/src/govern/HyperlaneAppGovernor.ts
  6. 9
      typescript/infra/src/govern/multisend.ts
  7. 62
      typescript/infra/src/utils/safe.ts
  8. 4
      typescript/sdk/package.json
  9. 17
      typescript/sdk/src/index.ts
  10. 21
      yarn.lock

@ -0,0 +1,6 @@
---
'@hyperlane-xyz/infra': patch
'@hyperlane-xyz/sdk': patch
---
Removes Gnosis safe util from infra in favor of SDK

@ -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"

@ -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",

@ -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';

@ -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,

@ -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<void>;
}

@ -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<Safe.default> {
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<boolean> {
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);
}

@ -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",

@ -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,

@ -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"

Loading…
Cancel
Save