diff --git a/src/tasks/selfSell.ts b/src/tasks/selfSell.ts index 2029bf29..7548efaa 100644 --- a/src/tasks/selfSell.ts +++ b/src/tasks/selfSell.ts @@ -899,10 +899,7 @@ const setupSelfSellTask: () => void = () => "blocknativeGasPrice", "Use BlockNative gas price estimates for transactions.", ) - .addOptionalParam( - "toToken", - "All input tokens will be dumped to this token. If not specified, it defaults to the network's native token (e.g., ETH)", - ) + .addParam("toToken", "All input tokens will be dumped to this token.") .addFlag( "safe", "Whether the solver is a Safe and the script should propose the transaction to the Safe UI instead of sending a transaction directly", diff --git a/src/tasks/withdraw/safe.ts b/src/tasks/withdraw/safe.ts index 34895f3c..e8504c39 100644 --- a/src/tasks/withdraw/safe.ts +++ b/src/tasks/withdraw/safe.ts @@ -1,5 +1,6 @@ import SafeApiKit from "@safe-global/api-kit"; import Safe, { EthersAdapter } from "@safe-global/protocol-kit"; +import { SafeTransactionDataPartial } from "@safe-global/safe-core-sdk-types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; interface Transaction { @@ -18,22 +19,44 @@ function serviceUrlForNetwork(network: string): string { } } +interface SafesAddressNoncesOutput { + recommendedNonce: number; +} +// Once `@safe-global/api-kit` has been migrated from v1 to v2, this can be replaced with `getnextnonce`. +// +async function recommendedNonce(chainId: number, safeAddress: string) { + // + const url = `https://safe-client.safe.global/v1/chains/${chainId.toString()}/safes/${safeAddress}/nonces`; + const response = await fetch(url); + const output: SafesAddressNoncesOutput = await response.json(); + return output.recommendedNonce; +} + // Creates and proposes a transaction to the Safe Multisig, which can then be confirmed by other signers in the Web UI. Returns the link to the transaction in the Web UI. export async function proposeTransaction( { ethers }: HardhatRuntimeEnvironment, network: string, { authoringSafe, to, data }: Transaction, ): Promise { + const { chainId } = await ethers.provider.getNetwork(); const [proposer] = await ethers.getSigners(); const ethAdapter = new EthersAdapter({ ethers, signerOrProvider: proposer, }); + let nonce; + try { + nonce = await recommendedNonce(chainId, authoringSafe); + } catch { + console.log("Unable to determine recommended nonce, using current one"); + nonce = undefined; + } - const safeTransactionData = { + const safeTransactionData: SafeTransactionDataPartial = { to, data, value: "0", + nonce, }; const safeSdk = await Safe.create({ ethAdapter, safeAddress: authoringSafe });