SDK
Transaction Legos

Transaction Legos

Transaction legos provide the transaction schemas and prepare arguments for external smart contract calls.

Github (opens in a new tab)

Usage

Examples

How to make a simple transaction lego

import { TXLego, CONTRACT_KEYCHAINS } from '@daohaus/utils';
import { CONTRACT } from '@daohaus/moloch-v3-legos';
 
const tokenApproval: TXLego = {
  id: 'APPROVE_TOKEN',
  contract: CONTRACT.ERC_20,
  method: 'approve',
  args: [
    { type: 'singleton', keychain: CONTRACT_KEYCHAINS.TRIBUTE_MINION },
    { type: 'static', value: 'some big number' },
  ],
};
PropertiesDescription
IDArbitrary identifier. Should be unique.
contractContract Lego (opens in a new tab)
methodFunction on the smart contract
args Array of valid arg lookups needed for the function call (see below (opens in a new tab))
argCallbackFunction that will assemble the args for the function call manually
staticArgsArray of hardcoded arguments for the function call
overridesObject with arg lookups for any tx override: gasLimit, value, gasPrice, from or blockTag
staticOverridesObject with hardcoded values for any of the overrides listed above
disablePollBoolean to turn off automatic subgraph polling on the transaction hash - useful if not triggering a transaction the DAOhaus subgraph will be indexing
customPollBbject with two functions. fetch: a function for what to fetch or do continually until the test function returns true. test: a function that will do somehting with the results of the fetch function and stop the fetch interval if it returns true

Note: You must provide one of 'args', argCallback or staticArgs.

Arg Lookups

Arg lookups are a series of options for how the tx-builder finds the values needed for any arg being passed to the function.

There are a few varieties:

ValidArgTypeDescriptionExample
StringSearch (opens in a new tab)Formatted as a string with '.' between object keys. The tx-builder searches the app state passed to it for this object path and returns the final value.dao.shareAddress
StaticArg (opens in a new tab)Hard coded argument value{ type: 'static', value: 'some value' }
JSONDetailsSearch (opens in a new tab)Formats the arg into a .json string. The sub key-value pairs can be formatted as any other valid arg type{ type: 'JSONDetails', jsonSchema: { daoId: '.daoId', token: '.dao.sharesAddress '}}
SingletonSearch (opens in a new tab)For values that are hardcoded, but dynamic per chain. Parses an object with keys that are the chainId{ type: 'singleton', keychain: { 0x1: 'some value, '0x5': 'some other value'}}
NestedArray (opens in a new tab)Returns set of values nested in an array{ type: 'nestedArray', args: ['.formValues.memberAddress','formValues.amount'] }
ProposalExpiry (opens in a new tab)Returns date in epoch seconds{ type: 'proposalExpiry', search: '.formValues.proposalExpiry', fallback: 0 }
TemplateArg (opens in a new tab)Creates a string from values in the tx-builder app state{ type: 'template', value: "this is the ${.formValues.someFieldId}"}
IPFSPinata (opens in a new tab)Pins content to IPFS and returns the IPFS hash. Requires passing pinata keys to tx-builder{ type: 'ipfsPinata', content: '.formValues.article' }
MulticallArg and EncodeMulticall (opens in a new tab)Takes a list of actions and encodes for a multicall function execution. Used in all DAO proposalsExample in the ISSUE_ERC20_SIDECAR (opens in a new tab) tx lego
ArgEncode (opens in a new tab)Encodes list of args and types{ type: 'argEncode', args: ['.formValues.quorum', .formValues.minRetention'], solidityTypes: ['uint256',' uint256']}
EncodeCallArg (opens in a new tab)Encodes a function and it's argsExample in the MULTICALL_SIDECAR (opens in a new tab) tx lego
EstimateGas (opens in a new tab)Used for the gas estimate arg needed when submitting DAO proposalstx-builder will add this automatically

How to make a transaction lego for creating a DAO proposal

This is done just like the transaction lego above, but with some extras. These transactions setup another transaction or series of transactions that the DAO will execute if the proposal passes. However, the proposal itself is also a transaction. The whole lego is wrapped in the buildMultiCallTX (opens in a new tab) function.

const ISSUE_SHARES = buildMultiCallTX({
  id: 'ISSUE',
  JSONDetails: {
    type: 'JSONDetails',
    jsonSchema: {
      title: '.formValues.title',
      description: '.formValues.description',
      contentURI: `.formValues.link`,
      contentURIType: { type: 'static', value: 'url' },
      proposalType: {
        type: 'static',
        value: ProposalTypeIds.IssueSharesLoot,
      },
    },
  },
  actions: [
    {
      contract: CONTRACT.CURRENT_DAO,
      method: 'mintShares',
      args: [
        '.formValues.addressesAndAmounts.recipients',
        '.formValues.addressesAndAmounts.values',
      ],
    },
  ],
});