Skip to content

#prepare-Create-Auction-Params-flow #621

@Dargon789

Description

@Dargon789

Reviewer's Guide

Adds and refactors internal helpers and tests around marketplace auctions/offers, ClaimButton, zkSync EIP-712 transactions, RPC utils, transaction encoding, currency resolution, and wallet chain RPC selection; exposes some internal helpers, tightens validation, and bumps dependencies (shiki, AWS KMS) per Snyk recommendations.

Sequence diagram for prepareCreateAuctionParams flow

sequenceDiagram
  actor User
  participant App as AppCode
  participant CreateAuction as CreateAuctionModule
  participant Helper as prepareCreateAuctionParams
  participant AssetContract as AssetContract
  participant RPC as RpcClient
  participant ERC20 as CurrencyContract

  User->>App: call createAuction(options)
  App->>CreateAuction: createAuction(options)
  CreateAuction->>Helper: prepareCreateAuctionParams(options)

  Helper->>AssetContract: isERC721(assetContract)
  Helper->>AssetContract: isERC1155(assetContract)
  Helper->>RPC: eth_getBlockByNumber(latest)
  RPC-->>Helper: latestBlock(timestamp)

  Helper-->>Helper: validate assetIsERC721 || assetIsERC1155
  Helper-->>Helper: compute startTimestamp and endTimestamp
  Helper-->>Helper: adjust startTimestamp if <= latestBlock.timestamp
  Helper-->>Helper: throw if startTimestamp >= endTimestamp

  alt assetIsERC721
    Helper-->>Helper: quantity = 1n
  else assetIsERC1155
    Helper-->>Helper: quantity = options.quantity ?? 1n
  end

  Helper-->>Helper: currencyAddress = options.currencyContractAddress ?? NATIVE_TOKEN_ADDRESS

  alt buyoutBidAmount in display units
    alt isNativeTokenAddress(currencyAddress)
      Helper-->>Helper: buyoutBidAmount = toUnits(buyoutBidAmount, 18)
    else ERC20 token
      Helper->>ERC20: decimals()
      ERC20-->>Helper: currencyDecimals
      Helper-->>Helper: buyoutBidAmount = toUnits(buyoutBidAmount, currencyDecimals)
    end
  else buyoutBidAmountWei provided
    Helper-->>Helper: buyoutBidAmount = BigInt(buyoutBidAmountWei)
  end

  alt minimumBidAmount in display units
    alt isNativeTokenAddress(currencyAddress)
      Helper-->>Helper: minimumBidAmount = toUnits(minimumBidAmount, 18)
    else ERC20 token
      Helper->>ERC20: decimals()
      ERC20-->>Helper: currencyDecimals
      Helper-->>Helper: minimumBidAmount = toUnits(minimumBidAmount, currencyDecimals)
    end
  else minimumBidAmountWei provided
    Helper-->>Helper: minimumBidAmount = BigInt(minimumBidAmountWei)
  end

  Helper-->>CreateAuction: {params, overrides:{extraGas:50000n}}
  CreateAuction-->>App: PreparedTransaction
  App-->>User: transaction ready to send
Loading

Sequence diagram for prepareBidInAuctionParams flow

sequenceDiagram
  actor Bidder
  participant App as AppCode
  participant BidInAuction as BidInAuctionModule
  participant Helper as prepareBidInAuctionParams
  participant AuctionRead as GetAuction
  participant WinningBidRead as GetWinningBid
  participant NewWinning as IsNewWinningBid
  participant ERC20Util as convertErc20Amount

  Bidder->>App: call bidInAuction(options)
  App->>BidInAuction: bidInAuction(options)
  BidInAuction->>Helper: prepareBidInAuctionParams(options)

  Helper->>AuctionRead: getAuction(auctionId)
  AuctionRead-->>Helper: auction

  alt bidAmountWei provided
    Helper-->>Helper: resolvedBidAmountWei = bidAmountWei
  else bidAmount in display units
    Helper->>ERC20Util: convertErc20Amount(amount, chain, auction.currencyContractAddress, client)
    ERC20Util-->>Helper: resolvedBidAmountWei
  end

  Helper-->>Helper: validate resolvedBidAmountWei != 0n
  Helper-->>Helper: validate resolvedBidAmountWei <= auction.buyoutCurrencyValue.value

  Helper->>WinningBidRead: getWinningBid(auctionId)
  WinningBidRead-->>Helper: existingWinningBid or undefined

  alt existingWinningBid exists
    Helper->>NewWinning: isNewWinningBid(auctionId, resolvedBidAmountWei)
    NewWinning-->>Helper: isNewWinner
    alt isNewWinner is false
      Helper-->>Helper: throw "Bid amount is too low to outbid the existing winning bid"
    end
  else no existing winning bid
    alt resolvedBidAmountWei < auction.minimumBidCurrencyValue.value
      Helper-->>Helper: throw "Bid amount is below the minimum bid amount"
    end
  end

  Helper-->>BidInAuction: {auctionId, bidAmount, overrides:{value?, extraGas:50000n}}
  BidInAuction-->>App: PreparedTransaction
  App-->>Bidder: transaction ready to send
Loading

Sequence diagram for zkSync EIP-712 getZkGasFees and formatTransaction

sequenceDiagram
  participant App as AppCode
  participant Tx as PreparedTransaction
  participant ZkGas as getZkGasFees
  participant Format as formatTransaction
  participant RPC as RpcClient

  App->>ZkGas: getZkGasFees({transaction, from})
  ZkGas->>Format: formatTransaction({transaction, from})
  Format->>Tx: read to, data, value, eip712
  Format-->>ZkGas: formattedTx{from,to,data,value,gasPerPubdata?,eip712Meta,type}

  ZkGas->>RPC: estimateGasL1(formattedTx)
  RPC-->>ZkGas: gas
  ZkGas->>RPC: getMaxFeePerGas()
  RPC-->>ZkGas: maxFeePerGas
  ZkGas->>RPC: getMaxPriorityFeePerGas()
  RPC-->>ZkGas: maxPriorityFeePerGas

  ZkGas-->>App: {gas,maxFeePerGas,maxPriorityFeePerGas,gasPerPubdata}
Loading

Class diagram for marketplace English auction helpers

classDiagram
  class ThirdwebContract {
    +address: string
    +chain: Chain
    +client: Client
  }

  class CreateAuctionModule {
    +createAuction(options)
  }

  class BidInAuctionModule {
    +bidInAuction(options)
  }

  class PrepareCreateAuctionParamsHelper {
    +prepareCreateAuctionParams(options) Promise~PreparedAuctionParams~
    -validateAssetIsERC721Or1155(assetContract)
    -computeTimestamps(startTimestamp, endTimestamp, latestBlock)
    -resolveQuantity(isERC721, quantity)
    -resolveBidAmount(displayAmount, amountWei, currencyAddress) bigint
  }

  class PrepareBidInAuctionParamsHelper {
    +prepareBidInAuctionParams(options) Promise~PreparedBidParams~
    -resolveBidAmount(bidAmount, bidAmountWei, auction) bigint
    -validateBidRange(amountWei, auction)
    -ensureOutbidsExistingWinner(amountWei, auction)
  }

  class MapEnglishAuctionUtil {
    +mapEnglishAuction(contract, rawAuction, latestBlock) Promise~MappedAuction~
  }

  class GeneratedGetAllAuctions {
    +getAllAuctions(contract, startId, endId) Promise~RawAuction[]~
  }

  class GetAllInBatchesUtil {
    +getAllInBatches(fetchFn, range, ) Promise~any[]~
  }

  class GetAuctionRead {
    +getAuction(contract, auctionId) Promise~MappedAuction~
  }

  class GetWinningBidRead {
    +getWinningBid(contract, auctionId) Promise~WinningBid?~
  }

  class IsNewWinningBidRead {
    +isNewWinningBid(contract, auctionId, bidAmount) Promise~boolean~
  }

  CreateAuctionModule --> PrepareCreateAuctionParamsHelper : uses
  BidInAuctionModule --> PrepareBidInAuctionParamsHelper : uses

  PrepareCreateAuctionParamsHelper --> ThirdwebContract : reads
  PrepareBidInAuctionParamsHelper --> GetAuctionRead : queries
  PrepareBidInAuctionParamsHelper --> GetWinningBidRead : queries
  PrepareBidInAuctionParamsHelper --> IsNewWinningBidRead : queries

  MapEnglishAuctionUtil --> ThirdwebContract : reads
  MapEnglishAuctionUtil --> GeneratedGetAllAuctions : consumes output
  GeneratedGetAllAuctions --> ThirdwebContract : queries
  GetAllInBatchesUtil --> GeneratedGetAllAuctions : calls
Loading

File-Level Changes

Change Details Files
Refactor English auctions write helpers into reusable parameter-preparation functions and expand end-to-end auction tests, including ERC20 currency flows and support-check helpers.
  • Extract prepareCreateAuctionParams from createAuction asyncParams and keep all validation/normalization logic there, returning params and overrides
  • Extract prepareBidInAuctionParams from bidInAuction asyncParams to compute bid amount in wei, validate against min/buyout/current bid, and return call params with proper overrides
  • Extend english-auctions tests to run only with TW_SECRET_KEY, add ERC20 marketplace currency setup, cover new helpers, validation paths, and mapEnglishAuction behavior
packages/thirdweb/src/extensions/marketplace/english-auctions/english-auctions.test.ts
packages/thirdweb/src/extensions/marketplace/english-auctions/write/createAuction.ts
packages/thirdweb/src/extensions/marketplace/english-auctions/write/bidInAuction.ts
Improve marketplace offers and direct listings utilities and tests, including mapping and feature-detection helpers plus minor cleanup.
  • Add a mapOffer test that exercises mapping from raw offer + block to enriched offer model with currency and asset metadata
  • Expose isCreateListingSupported and add a test that derives selectors from the marketplace ABI to assert support
  • Fix minor comments in direct-listings write paths (validate quantity spelling)
packages/thirdweb/src/extensions/marketplace/offers/offers.test.ts
packages/thirdweb/src/extensions/marketplace/direct-listings/direct-listings.test.ts
packages/thirdweb/src/extensions/marketplace/direct-listings/write/createListing.ts
packages/thirdweb/src/extensions/marketplace/direct-listings/write/updateListing.ts
Strengthen ClaimButton tests by reusing shared deployed contracts, reducing duplication and explicitly validating ERC20/ERC1155 claim flows and error paths.
  • Introduce shared DropERC20 and DropERC1155 deployments in ClaimButton test setup
  • Update ERC1155 tests to use shared contract instance and assert correct target address
  • Update ERC20 claim tests to use shared contract, assert correct target, and verify error when missing quantity parameters
packages/thirdweb/src/react/web/ui/prebuilt/thirdweb/ClaimButton/ClaimButton.test.tsx
Enhance zkSync EIP-712 transaction utilities by exposing formatTransaction and adding tests for transaction formatting and zkSync gas fee estimation.
  • Export formatTransaction as @internal so it can be tested and reused
  • Add tests verifying formatTransaction output including eip712Meta.paymaster and gasPerPubdata defaults
  • Add tests for getZkGasFees to ensure bigint types for gas-related fields
packages/thirdweb/src/transaction/actions/zksync/send-eip712-transaction.ts
packages/thirdweb/src/transaction/actions/zksync/send-eip712-transaction.test.ts
Increase coverage and robustness for low-level RPC and transaction helpers (encoding, extra calldata, RPC actions, currency resolution, promise concurrency, wallet chain RPCs).
  • Extend getExtraCallDataFromTx tests to cover function-returned calldata, invalid/non-hex values, and noop 0x results
  • Add tests for eth_getBlockByHash and eth_getTransactionByHash helpers against forked Ethereum data, including error paths
  • Add resolveCurrencyValue tests for native and ERC20 tokens to validate name/symbol/decimals and displayValue conversion
  • Add pLimit tests that ensure invalid concurrency values (non-integer, negative) throw the expected error
  • Export getValidChainRPCs and add tests validating HTTP/WS URL filtering and error when no RPC URLs are available
packages/thirdweb/src/transaction/actions/encode.test.ts
packages/thirdweb/src/rpc/actions/eth_getBlockByHash.test.ts
packages/thirdweb/src/rpc/actions/eth_getTransactionByHash.test.ts
packages/thirdweb/src/utils/extensions/resolve-currency-value.test.ts
packages/thirdweb/src/utils/promise/p-limit.test.ts
packages/thirdweb/src/wallets/utils/chains.ts
packages/thirdweb/src/wallets/utils/chains.test.ts
Update third-party dependencies to address Snyk advisories and keep SDK apps up to date.
  • Bump shiki from 1.27.0 to 2.3.2 in dashboard, playground-web, and portal applications
  • Bump @aws-sdk/client-kms from 3.592.0 to 3.734.0 in react-native-adapter
  • Regenerate pnpm-lock.yaml to align with dependency changes
apps/dashboard/package.json
apps/playground-web/package.json
apps/portal/package.json
packages/react-native-adapter/package.json
pnpm-lock.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #619 (comment)

Sub-issues

Metadata

Metadata

Assignees

Projects

Status

In Review

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions