import { expect } from 'chai'; import { ethers } from 'ethers'; import { pino } from 'pino'; import { type ChainMap, Token, TokenStandard } from '@hyperlane-xyz/sdk'; import { type MinAmountStrategyConfig, RebalancerMinAmountType, RebalancerStrategyOptions, type StrategyConfig, type WeightedStrategyConfig, } from '../config/types.js'; import { MinAmountStrategy } from './MinAmountStrategy.js'; import { StrategyFactory } from './StrategyFactory.js'; import { WeightedStrategy } from './WeightedStrategy.js'; const testLogger = pino({ level: 'silent' }); describe('StrategyFactory', () => { const chain1 = 'chain1'; const chain2 = 'chain2'; const totalCollateral = BigInt(20e18); const tokensByChainName: ChainMap = {}; const tokenArgs = { name: 'token', decimals: 18, symbol: 'TOKEN', standard: TokenStandard.ERC20, addressOrDenom: '', }; tokensByChainName[chain1] = new Token({ ...tokenArgs, chainName: chain1 }); tokensByChainName[chain2] = new Token({ ...tokenArgs, chainName: chain2 }); describe('createStrategy', () => { it('creates a WeightedStrategy when given weighted configuration', () => { const config: WeightedStrategyConfig = { [chain1]: { weighted: { weight: 100n, tolerance: 0n, }, bridge: ethers.constants.AddressZero, bridgeLockTime: 1, }, [chain2]: { weighted: { weight: 100n, tolerance: 0n, }, bridge: ethers.constants.AddressZero, bridgeLockTime: 1, }, }; const strategyConfig: StrategyConfig = { rebalanceStrategy: RebalancerStrategyOptions.Weighted, chains: config, }; const strategy = StrategyFactory.createStrategy( [strategyConfig], tokensByChainName, totalCollateral, testLogger, ); expect(strategy).to.be.instanceOf(WeightedStrategy); }); it('creates a MinAmountStrategy when given minAmount configuration', () => { const config: MinAmountStrategyConfig = { [chain1]: { minAmount: { min: 8, target: 10, type: RebalancerMinAmountType.Absolute, }, bridge: ethers.constants.AddressZero, bridgeLockTime: 1, }, [chain2]: { minAmount: { min: 8, target: 10, type: RebalancerMinAmountType.Absolute, }, bridge: ethers.constants.AddressZero, bridgeLockTime: 1, }, }; const strategyConfig: StrategyConfig = { rebalanceStrategy: RebalancerStrategyOptions.MinAmount, chains: config, }; const strategy = StrategyFactory.createStrategy( [strategyConfig], tokensByChainName, totalCollateral, testLogger, ); expect(strategy).to.be.instanceOf(MinAmountStrategy); }); }); });