feat: add Safe Transaction Builder to Warp Apply (#4621)
### Description Adds feature to create a Safe Transaction Builder "receipt" that can be uploaded to the Safe UI. This relies on a a gnosisSafeTxBuilder strategy: ``` basesepolia: submitter: chain: 'basesepolia' type: gnosisSafeTxBuilder version: '1.0' meta: {} safeAddress: '0x7232Ad76d905ae9D8D00379359DDa744a7A21C46' ``` To generate this, to be uploaded to the UI: ``` { "version": "1.0", "chainId": "10200", "meta": {}, "transactions": [ { "to": "0xB86F6AF56C411688b3dAB479f646E990287094a0", "value": "0", "data": "0xe9198bf9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000014a3400000000000000000000000000000000000000000000000000000000002fd16700000000000000000000000000000000000000000000000000000000002fd1cb000000000000000000000000000000000000000000000000000000000000000300000000000000000000000021d4928020f503658603a036dd3ad5570e8495ab000000000000000000000000de612cfd22a35aae677398decd7a13057d6d5a300000000000000000000000008c08821f5f94b519c853486eb131667aa528a460", "operation": 0, "baseGas": "0", "gasPrice": "0", "gasToken": "0x0000000000000000000000000000000000000000", "refundReceiver": "0x0000000000000000000000000000000000000000", "nonce": 9, "safeTxGas": "0" } ] } ``` <img width="1713" alt="Screenshot 2024-10-03 at 1 08 31 PM" src="https://github.com/user-attachments/assets/60009b47-4018-455b-8324-495f286de973"> ### Drive-by changes - Refactor warp apply to use `submitWarpApplyTransactions()` to submit and write the receipt file, de-duplicating code. ### Related issues - Fixes #4620 ### Backward compatibility Yes ### Testing Manual - [ ] Enrollment on 1 chain basesepolia - [ ] adding 2 anvil chains - [ ] Enrollment to 2 chains: basesepolia chiado - [ ] Adding 2 anvil chainspull/4640/head
parent
bb75eba74a
commit
4415ac224a
@ -0,0 +1,7 @@ |
||||
--- |
||||
'@hyperlane-xyz/utils': minor |
||||
'@hyperlane-xyz/cli': minor |
||||
'@hyperlane-xyz/sdk': minor |
||||
--- |
||||
|
||||
Add Gnosis safe transaction builder to warp apply |
@ -0,0 +1,6 @@ |
||||
basesepolia: |
||||
submitter: |
||||
chain: 'basesepolia' |
||||
type: gnosisSafeTxBuilder |
||||
version: '1.0' |
||||
safeAddress: '0x7232Ad76d905ae9D8D00379359DDa744a7A21C46' |
@ -1 +1 @@ |
||||
export const DEFAULT_CONTRACT_READ_CONCURRENCY = 20; |
||||
export const DEFAULT_CONTRACT_READ_CONCURRENCY = 1; |
||||
|
@ -0,0 +1,72 @@ |
||||
import { SafeTransactionData } from '@safe-global/safe-core-sdk-types'; |
||||
|
||||
import { assert } from '@hyperlane-xyz/utils'; |
||||
|
||||
// prettier-ignore
|
||||
// @ts-ignore
|
||||
import { getSafe, getSafeService } from '../../../../utils/gnosisSafe.js'; |
||||
import { MultiProvider } from '../../../MultiProvider.js'; |
||||
import { GnosisTransactionBuilderPayload } from '../../../ProviderType.js'; |
||||
import { PopulatedTransaction, PopulatedTransactions } from '../../types.js'; |
||||
import { TxSubmitterType } from '../TxSubmitterTypes.js'; |
||||
|
||||
import { EV5GnosisSafeTxSubmitter } from './EV5GnosisSafeTxSubmitter.js'; |
||||
import { EV5GnosisSafeTxBuilderProps } from './types.js'; |
||||
|
||||
/** |
||||
* This class is used to create a Safe Transaction Builder compatible object. |
||||
* It is not a true Submitter because it does not submits any transactions. |
||||
*/ |
||||
export class EV5GnosisSafeTxBuilder extends EV5GnosisSafeTxSubmitter { |
||||
public readonly txSubmitterType: TxSubmitterType = |
||||
TxSubmitterType.GNOSIS_TX_BUILDER; |
||||
constructor( |
||||
public readonly multiProvider: MultiProvider, |
||||
public readonly props: EV5GnosisSafeTxBuilderProps, |
||||
safe: any, |
||||
safeService: any, |
||||
) { |
||||
super(multiProvider, props, safe, safeService); |
||||
} |
||||
|
||||
static async create( |
||||
multiProvider: MultiProvider, |
||||
props: EV5GnosisSafeTxBuilderProps, |
||||
): Promise<EV5GnosisSafeTxBuilder> { |
||||
const { chain, safeAddress } = props; |
||||
const { gnosisSafeTransactionServiceUrl } = |
||||
multiProvider.getChainMetadata(chain); |
||||
assert( |
||||
gnosisSafeTransactionServiceUrl, |
||||
`Must set gnosisSafeTransactionServiceUrl in the Registry metadata for ${chain}`, |
||||
); |
||||
const safe = await getSafe(chain, multiProvider, safeAddress); |
||||
const safeService = await getSafeService(chain, multiProvider); |
||||
|
||||
return new EV5GnosisSafeTxBuilder(multiProvider, props, safe, safeService); |
||||
} |
||||
|
||||
/** |
||||
* Creates a Gnosis Safe transaction builder object using the PopulatedTransactions |
||||
* |
||||
* @param txs - An array of populated transactions |
||||
*/ |
||||
public async submit( |
||||
...txs: PopulatedTransactions |
||||
): Promise<GnosisTransactionBuilderPayload> { |
||||
const transactions: SafeTransactionData[] = await Promise.all( |
||||
txs.map( |
||||
async (tx: PopulatedTransaction) => |
||||
( |
||||
await this.createSafeTransaction(tx) |
||||
).data, |
||||
), |
||||
); |
||||
return { |
||||
version: this.props.version, |
||||
chainId: this.multiProvider.getChainId(this.props.chain).toString(), |
||||
meta: {}, |
||||
transactions, |
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue