Skip to content
LogoLogo

earn.createStack

Deploys deterministic EarnShare, EarnVault, and EarnFees contracts around an unbound engine. This API is experimental.

Usage

import { ,  } from 'viem/utils'
import {  } from './viem.config'
 
const  = await ..({
  : .(.('acme-usd-v1')),
  : '0x0000000000000000000000000000000000000001',
  : '0x0000000000000000000000000000000000000002',
})
{ earnFees: '0x...', earnShare: '0x...', earnVault: '0x...', receipt: { ... } }

Omitting fees deploys a fee-free stack. The emergency guardian and async janitor default to the zero address, migration defaults to userOnly, managed assets are unlimited, and transfers use the built-in always-allow policy.

Asynchronous Usage

earn.createStackSync waits for inclusion and returns the decoded deployment event. Use earn.createStack to return the transaction hash immediately.

import { ,  } from 'viem/utils'
import {  } from 'viem/tempo'
import {  } from './viem.config'
 
const  = '0x0000000000000000000000000000000000000002'
const  = await ..({
  : .(.('acme-usd-v1')),
  : '0x0000000000000000000000000000000000000001',
  ,
})
const  = await ..({  }).
const {  } = ...(., {
  ,
})

Return Value

type ReturnValue = {
  /** Async janitor address. */
  asyncJanitor: Address
  /** Venue asset address. */
  asset: Address
  /** Control configuration hash. */
  controlConfigHash: Hex
  /** Deployment identifier. */
  deploymentId: Hex
  /** Deployed EarnFees address. */
  earnFees: Address
  /** Deterministic EarnFees salt. */
  earnFeesSalt: Hex
  /** Deployed EarnShare address. */
  earnShare: Address
  /** Deterministic EarnShare salt. */
  earnShareSalt: Hex
  /** Deployed EarnVault address. */
  earnVault: Address
  /** Emergency guardian address. */
  emergencyGuardian: Address
  /** ERC-4626 engine address. */
  engine: Address
  /** Fee configuration hash. */
  feeConfigHash: Hex
  /** Maximum managed assets. */
  maxManagedAssets: bigint
  /** Engine migration mode. */
  migrationMode: number
  /** Final stack owner and operator. */
  owner: Address
  /** Transaction receipt. */
  receipt: TransactionReceipt
  /** Effective transfer policy ID. */
  transferPolicyId: bigint
}

The asynchronous action returns the transaction hash instead.

Parameters

deploymentId

  • Type: Hex

A required, nonzero 32-byte identifier shared with the engine deployment.

engine

  • Type: Address

Unbound engine address.

factory

  • Type: Address

Reviewed EarnFactory address from the same release as the engine factory.

owner (optional)

  • Type: Account | Address
  • Default: account.address

Final stack owner and operator.

controls (optional)

  • Type: EarnVaultControls

Initial emergencyGuardian, asyncJanitor, maxManagedAssets, and migrationMode controls.

fees (optional)

  • Type: EarnFeeConfiguration

Up to four fixed fees and an optional excess-return fee, all expressed in basis points. Omit this parameter for a fee-free stack. When a distributor is enabled, fixedFees[0] is its protected fee and the remaining entries are operator-controlled.

distributor (optional)

  • Type: EarnDistributorConfiguration

Protected distributor and update delay. An enabled distributor requires at least one fixed fee and controls the first entry in fees.fixedFees through its delayed update path.

transferPolicyId (optional)

  • Type: bigint
  • Default: 0n

Existing simple whitelist policy. Zero selects the built-in always-allow policy.

account (optional)

  • Type: Account | Address

Account that will be used to send the transaction.

feePayer (optional)

  • Type: Account | boolean

Fee payer for the transaction (TIP-1 gas sponsorship).

Pass true to defer the fee token to an external fee payer (e.g. a relay), or a local Account to co-sign the transaction as the fee payer.

feeToken (optional)

  • Type: Address | bigint

Fee token for the transaction.

Can be an unpaused USD-denominated TIP-20 token address or ID.

gas (optional)

  • Type: bigint

Gas limit for the transaction.

keyAuthorization (optional)

  • Type: KeyAuthorization

Signed key authorization to include with the transaction, authorizing an access key to act for the sending account.

maxFeePerGas (optional)

  • Type: bigint

Max fee per gas for the transaction.

maxPriorityFeePerGas (optional)

  • Type: bigint

Max priority fee per gas for the transaction.

nonce (optional)

  • Type: number

Nonce for the transaction.

nonceKey (optional)

  • Type: 'expiring' | 'random' | bigint

Nonce key for the transaction (TIP-1009 2D nonces).

Use 'expiring' to select an expiring nonce, which enables concurrent transaction submission without nonce ordering. Use 'random' to select a random key.

throwOnReceiptRevert (optional)

  • Type: boolean
  • Default: true

Whether a Sync action throws when the receipt reports a revert.

validAfter (optional)

  • Type: number

Unix timestamp after which the transaction can be included.

validBefore (optional)

  • Type: number

Unix timestamp before which the transaction must be included.