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
parent
d37cbab724
commit
a86a8296b2
@ -0,0 +1,6 @@ |
|||||||
|
--- |
||||||
|
'@hyperlane-xyz/infra': patch |
||||||
|
'@hyperlane-xyz/sdk': patch |
||||||
|
--- |
||||||
|
|
||||||
|
Removes Gnosis safe util from infra in favor of SDK |
@ -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); |
|
||||||
} |
|
Loading…
Reference in new issue