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
-
Copy the template:
cd projects cp -r template-twb your-staking-protocol-name
-
Update package.json:
{ "name": "@absinthe/your-staking-protocol-name", "description": "Absinthe adapter for YourStakingProtocol" }
-
Add your contract ABIs:
# Replace hemi.json with your actual staking contract ABIs # Ensure you have Deposit and Withdraw events (or equivalent)
-
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 } ] }
-
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
-
Wrap in Single Quotes
- The final string should be wrapped in single quotes ('...') when setting it in your .env file.
-
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.
-
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 ];
-
Generate types and run:
pnpm typegen # Generate ABI types pnpm codegen # Generate TypeORM models pnpm migration # Run database migrations pnpm dev # Start development
-
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