-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifies types while keeps storing last query response state inside…
… hander (#200) * Improve add liquidity interface typing * Fix twamm example in build call data query * Rename to previewQueryData
- Loading branch information
Showing
15 changed files
with
133 additions
and
127 deletions.
There are no files selected for viewing
22 changes: 5 additions & 17 deletions
22
lib/modules/pool/actions/add-liquidity/add-liquidity.types.ts
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 |
---|---|---|
@@ -1,23 +1,11 @@ | ||
import { AddLiquidityQueryOutput, PriceImpact, TokenAmount } from '@balancer/sdk' | ||
import { TokenAmount } from '@balancer/sdk' | ||
import { Address } from 'wagmi' | ||
import { HumanAmountIn } from '../liquidity-types' | ||
|
||
// TODO: this type should be exposed by the SDK | ||
export type PriceImpactAmount = Awaited<ReturnType<typeof PriceImpact.addLiquidityUnbalanced>> | ||
|
||
export type AddLiquidityInputs = { | ||
humanAmountsIn: HumanAmountIn[] | ||
account?: Address | ||
slippagePercent?: string | ||
} | ||
|
||
// sdkQueryOutput is optional because it will be only used in cases where we use the SDK to query/build the transaction | ||
// We will probably need a more abstract interface to be used by edge cases | ||
export type AddLiquidityOutputs = { | ||
export type QueryAddLiquidityOutput = { | ||
bptOut: TokenAmount | ||
sdkQueryOutput?: AddLiquidityQueryOutput | ||
} | ||
|
||
export type BuildLiquidityInputs = { | ||
inputs: AddLiquidityInputs | ||
export type BuildAddLiquidityInputs = { | ||
account: Address | ||
slippagePercent: string | ||
} |
33 changes: 21 additions & 12 deletions
33
lib/modules/pool/actions/add-liquidity/handlers/AddLiquidity.handler.ts
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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' | ||
import { | ||
AddLiquidityInputs, | ||
AddLiquidityOutputs, | ||
BuildLiquidityInputs, | ||
} from '../add-liquidity.types' | ||
import { HumanAmountIn } from '../../liquidity-types' | ||
import { BuildAddLiquidityInputs, QueryAddLiquidityOutput } from '../add-liquidity.types' | ||
|
||
/** | ||
* AddLiquidityHandler is an interface that defines the methods that must be implemented by a handler. | ||
* They take standard inputs from the UI and return frontend standardised outputs. | ||
* The outputs should not be return types from the SDK. This is to | ||
* allow handlers to be developed in the future that may not use the SDK. | ||
* | ||
* SDK handlers: | ||
* - Default handlers will interact with the SDK to query and build the call data for the transaction | ||
* - They store the response of the last query execution inside the handler instance so it can be used later by buildAddLiquidityCallData | ||
* - Each time queryAddLiquidity is called they update that internal state | ||
* | ||
* Edge-case handlers: | ||
* - Edge case handlers (e.g. Twamm handler) will not interact with the SDK | ||
* - They do not store the response of a SDK query but could store other state related to the edge-case implementation | ||
*/ | ||
export interface AddLiquidityHandler { | ||
// Query the SDK for the expected output of adding liquidity | ||
queryAddLiquidity(inputs: AddLiquidityInputs): Promise<AddLiquidityOutputs> | ||
// Query the expected output of adding liquidity and store it inside the handler instance | ||
// Also returns bptOut to be used by the UI | ||
queryAddLiquidity(humanAmountsIn: HumanAmountIn[]): Promise<QueryAddLiquidityOutput> | ||
// Calculate the price impact of adding liquidity | ||
calculatePriceImpact(inputs: AddLiquidityInputs): Promise<number> | ||
// Build tx payload for adding liquidity | ||
buildAddLiquidityCallData(inputs: BuildLiquidityInputs): Promise<TransactionConfig> | ||
calculatePriceImpact(humanAmountsIn: HumanAmountIn[]): Promise<number> | ||
/* | ||
Build tx callData payload for adding liquidity | ||
It is responsibility of the UI to avoid calling buildAddLiquidityCallData before the last queryAddLiquidity was finished | ||
("Next" button will be disabled if the react-query calling queryAddLiquidity is in loading state) | ||
*/ | ||
buildAddLiquidityCallData(inputs: BuildAddLiquidityInputs): Promise<TransactionConfig> | ||
} |
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
2 changes: 1 addition & 1 deletion
2
lib/modules/pool/actions/add-liquidity/handlers/selectAddLiquidityHandler.ts
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
Oops, something went wrong.