owned this note
owned this note
Published
Linked with GitHub
# Transaction Legos
Transaction legos provide the transaction schemas & prepare arguments for external smart contract calls.
[**Check out all of our transaction legos here**](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-legos/src/tx.ts)
**How to make a simple transaction lego**
```jsx
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' },
],
};
```
| Properties | Description |
| -------- | -------- |
| ID | Arbitrary identifier. Should be unique. |
| contract | [Contract Lego](https://hackmd.io/@bootleggers/Skfd50_w3/https%3A%2F%2Fhackmd.io%2FTKPWVJC2SfuwthmzTtrJIw) |
| method | Function on the smart contract |
| args | Array of valid arg lookups needed for the function call ([see below](https://hackmd.io/@bootleggers/Skfd50_w3/https%3A%2F%2Fhackmd.io%2Fo54vqrecQQ-MR9nuhVUGOQ#Arg-Lookups)) |
| argCallback | Function that will assemble the args for the function call manually |
| staticArgs | Array of hardcoded arguments for the function call |
| overrides | Object with arg lookups for any tx override: `gasLimit`, `value`, `gasPrice`, `from` or `blockTag` |
| staticOverrides | Object with hardcoded values for any of the overrides listed above |
| disablePoll | Boolean to turn off automatic subgraph polling on the transaction hash - useful if not triggering a transaction the DAOhaus subgraph will be indexing |
| customPoll | Bbject 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 will find the values needed for any arg being passed to the function. There are a few varieties
| ValidArgType | | example |
| -------- | -------- | -------- |
| [StringSearch](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/search.ts#L62) | formatted as a string w/ '.' between object keys. The tx-builder will search the app state passed to it for this object path and return the final value | '.dao.shareAddress' |
| [StaticArg](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/args.ts#L88) | Hard coded argument value | { type: 'static', value: 'some value' } |
| [JSONDetailsSearch](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/search.ts#L88) | Will format 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](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/args.ts#L27) | 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](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/args.ts#L108) | returns a set of value nested in an array | { type: 'nestedArray', args: ['.formValues.memberAddress','formValues.amount'] } |
| [ProposalExpiry](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/args.ts#L194) | returns a date in epoch seconds | { type: 'proposalExpiry', search: '.formValues.proposalExpiry', fallback: 0 } |
| [TemplateArg](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/args.ts#L90) | Creates a string from values in the tx-builder app state | { type: 'template', value: "this is the ${.formValues.someFieldId}"} |
| [IPFSPinata](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/ipfs.ts#L7) | Pins content to ipfs and returns the ipfs hash. Requires passing pinata keys to tx-builder | { type: 'ipfsPinata', content: '.formValues.article' } |
| [MulticallArg and EncodeMulticall](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/args.ts#L125) | Takes a list of actions and encodes for a multicall function execution. Used in all DAO proposals | example in the [ISSUE_ERC20_SIDECAR](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-legos/src/tx.ts#L209) tx lego |
| [ArgEncode](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/multicall.ts#L181) | encodes a list of args and types | { type: 'argEncode', args: ['.formValues.quorum', .formValues.minRetention'], solidityTypes: ['uint256',' uint256']} |
| [EncodeCallArg](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/multicall.ts#L99) | encodes a function and it's args | example in the [MULTICALL_SIDECAR](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-legos/src/tx.t) tx lego |
| [EstimateGas](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/multicall.ts#L343) | Used for the gas estimate arg needed when submitting dao proposals | tx-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 transaction are 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 function](https://github.com/HausDAO/monorepo/blob/develop/libs/tx-builder/src/utils/multicall.ts#L431).
```ts!
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',
],
},
],
});
```