Skip to content

Option 1: Use the Adapter Template (Recommended) πŸš€

For quick setup, choose the appropriate pre-built template based on your protocol type:

Template-TWB (Time-Weighted Balance) πŸ“Š

When to use: For protocols that require tracking user balances over time for yield calculations, staking rewards, or liquidity mining programs.

Best for:

  • Staking protocols (deposits/withdrawals with yield tracking)
  • Liquidity mining programs
  • Time-based reward distribution systems
  • Any protocol where "balance Γ— time" matters for rewards
  1. Copy the template:

    cd projects
    cp -r template-twb your-staking-protocol-name
  2. Update package.json:

    {
      "name": "@absinthe/your-staking-protocol-name",
      "description": "Absinthe adapter for YourStakingProtocol"
    }
  3. Add your contract ABIs:

    # Replace hemi.json with your actual staking contract ABIs
    # Ensure you have Deposit and Withdraw events (or equivalent)
  4. Update configuration: Add to abs_config.json:

    {
      "stakingProtocols": [
        {
          "type": "your-staking-protocol-name",
          "name": "your-protocol-instance",
          "contractAddress": "0x...",
          "chainId": 1,
          "fromBlock": 12345678,
          "toBlock": 0
        }
      ]
    }
  5. Minify the JSON

    • Remove all whitespace and newlines to make it a single-line string.
    • You can use tools like jsonformatter.org or run:
      • cat abs_config.example.json | jq -c
  6. Wrap in Single Quotes

    • The final string should be wrapped in single quotes ('...') when setting it in your .env file.
  7. Set in Your Environment

  • Open your .env file and add or update the ABS_CONFIG line:
    • ABS_CONFIG='{"balanceFlushIntervalHours":6,"dexProtocols":[...]}'
  • Tip: If you don’t set ABS_CONFIG, the code will fall back to abs_config.example.json (see below). You can refer to Getting Started Guide for more details.
  1. Configure supported tokens: Update src/utils/conts.ts with your supported tokens:

    const TOKEN_METADATA = [
      {
        address: '0x...', // Token contract address
        decimals: 18, // Token decimals
        coingeckoId: 'token-name', // CoinGecko ID for price data
      },
      // ... more tokens
    ];
  2. Generate types and run:

    pnpm typegen   # Generate ABI types
    pnpm codegen   # Generate TypeORM models
    pnpm migration # Run database migrations
    pnpm dev       # Start development
  3. Customize the logic:

  • Update src/BatchProcessor.ts with your protocol's event handling
  • Modify src/processor.ts with correct events and contract addresses
  • Adjust time window duration in configuration (balanceFlushIntervalHours)
  • Implement your specific staking/reward logic