-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from balancer/refactor-join-interface
Refactor Join/Exit Interface to Add/Remove Liquidity
- Loading branch information
Showing
49 changed files
with
2,130 additions
and
1,941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
AddLiquidityBase, | ||
AddLiquidityBuildOutput, | ||
AddLiquidityConfig, | ||
AddLiquidityInput, | ||
AddLiquidityQueryOutput, | ||
AddLiquidityCall, | ||
} from './types'; | ||
import { AddLiquidityWeighted } from './weighted/addLiquidityWeighted'; | ||
import { PoolStateInput } from '../types'; | ||
import { validateInputs } from './utils/validateInputs'; | ||
import { getSortedTokens } from '../utils/getSortedTokens'; | ||
import { AddLiquidityComposableStable } from './composable-stable/addLiquidityComposableStable'; | ||
|
||
export class AddLiquidity { | ||
private readonly addLiquidityTypes: Record<string, AddLiquidityBase> = {}; | ||
|
||
constructor(config?: AddLiquidityConfig) { | ||
const { customAddLiquidityTypes } = config || {}; | ||
this.addLiquidityTypes = { | ||
//GYRO2, GYRO3, GYROE pool types only support Add Liquidity Proportional (3 - ALL_TOKENS_IN_FOR_BPT_OUT) | ||
GYRO2: new AddLiquidityWeighted(), | ||
GYRO3: new AddLiquidityWeighted(), | ||
GYROE: new AddLiquidityWeighted(), | ||
WEIGHTED: new AddLiquidityWeighted(), | ||
// PHANTOM_STABLE === ComposableStables in API | ||
PHANTOM_STABLE: new AddLiquidityComposableStable(), | ||
// custom add liquidity types take precedence over base types | ||
...customAddLiquidityTypes, | ||
}; | ||
} | ||
|
||
public getAddLiquidity(poolType: string): AddLiquidityBase { | ||
if (!this.addLiquidityTypes[poolType]) { | ||
throw new Error('Unsupported pool type'); | ||
} | ||
|
||
return this.addLiquidityTypes[poolType]; | ||
} | ||
|
||
public async query( | ||
input: AddLiquidityInput, | ||
poolState: PoolStateInput, | ||
): Promise<AddLiquidityQueryOutput> { | ||
validateInputs(input, poolState); | ||
|
||
const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); | ||
const mappedPoolState = { | ||
...poolState, | ||
tokens: sortedTokens, | ||
}; | ||
|
||
return this.getAddLiquidity(poolState.type).query( | ||
input, | ||
mappedPoolState, | ||
); | ||
} | ||
|
||
public buildCall(input: AddLiquidityCall): AddLiquidityBuildOutput { | ||
return this.getAddLiquidity(input.poolType).buildCall(input); | ||
} | ||
} |
Oops, something went wrong.