-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'e1efe6b68f4528287410adb0a7d5782273959b7b' into integrat…
…e-api # Conflicts: # src/entities/exit/parser.ts # src/entities/join/parser.ts # test/weightedExit.integration.test.ts
- Loading branch information
Showing
18 changed files
with
433 additions
and
320 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@balancer/sdk": minor | ||
--- | ||
|
||
- Add join/exit pool support (non-nested pools) | ||
- Weighted pool type | ||
- Uses balancerHelpers to query amounts in/out rather than relying on specific pool math and associated data | ||
- Integration tests run against local hardhat fork |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './poolExit'; | ||
export * from './types'; |
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 +0,0 @@ | ||
import { BaseExit, ExitConfig } from './types'; | ||
import { WeightedExit } from './weighted/weightedExit'; | ||
|
||
/*********************** Basic Helper to get exit class from pool type *************/ | ||
|
||
export class ExitParser { | ||
private readonly poolExits: Record<string, BaseExit> = {}; | ||
|
||
constructor(config?: ExitConfig) { | ||
const { customPoolExits } = config || {}; | ||
this.poolExits = { | ||
WEIGHTED: new WeightedExit(), | ||
// custom pool Exits take precedence over base Exits | ||
...customPoolExits, | ||
}; | ||
} | ||
|
||
public getExit(poolType: string): BaseExit { | ||
return this.poolExits[poolType]; | ||
} | ||
} | ||
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,52 @@ | ||
import { | ||
BaseExit, | ||
ExitBuildOutput, | ||
ExitCallInput, | ||
ExitConfig, | ||
ExitInput, | ||
ExitQueryResult, | ||
} from './types'; | ||
import { WeightedExit } from './weighted/weightedExit'; | ||
import { PoolStateInput } from '../types'; | ||
import { validateInputs } from './weighted/validateInputs'; | ||
import { getSortedTokens } from '../utils/getSortedTokens'; | ||
|
||
export class PoolExit { | ||
private readonly poolExits: Record<string, BaseExit> = {}; | ||
|
||
constructor(config?: ExitConfig) { | ||
const { customPoolExits } = config || {}; | ||
this.poolExits = { | ||
WEIGHTED: new WeightedExit(), | ||
// custom pool Exits take precedence over base Exits | ||
...customPoolExits, | ||
}; | ||
} | ||
|
||
public getExit(poolType: string): BaseExit { | ||
if (!this.poolExits[poolType]) { | ||
throw new Error('Unsupported pool type'); | ||
} | ||
|
||
return this.poolExits[poolType]; | ||
} | ||
|
||
public async query( | ||
input: ExitInput, | ||
poolState: PoolStateInput, | ||
): Promise<ExitQueryResult> { | ||
validateInputs(input, poolState); | ||
|
||
const sortedTokens = getSortedTokens(poolState.tokens, input.chainId); | ||
const mappedPoolState = { | ||
...poolState, | ||
tokens: sortedTokens, | ||
}; | ||
|
||
return this.getExit(poolState.type).query(input, mappedPoolState); | ||
} | ||
|
||
public buildCall(input: ExitCallInput): ExitBuildOutput { | ||
return this.getExit(input.poolType).buildCall(input); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,73 +1,2 @@ | ||
import { TokenAmount } from '../tokenAmount'; | ||
import { Slippage } from '../slippage'; | ||
import { PoolState } from '../types'; | ||
import { Address, Hex } from '../../types'; | ||
|
||
export enum JoinKind { | ||
Init = 'Init', | ||
Unbalanced = 'Unbalanced', | ||
SingleAsset = 'SingleAsset', | ||
Proportional = 'Proportional', | ||
} | ||
|
||
// This will be extended for each pools specific input requirements | ||
export type BaseJoinInput = { | ||
chainId: number; | ||
rpcUrl: string; | ||
useNativeAssetAsWrappedAmountIn?: boolean; | ||
fromInternalBalance?: boolean; | ||
}; | ||
|
||
export type InitJoinInput = BaseJoinInput & { | ||
amountsIn: TokenAmount[]; | ||
kind: JoinKind.Init; | ||
}; | ||
|
||
export type UnbalancedJoinInput = BaseJoinInput & { | ||
amountsIn: TokenAmount[]; | ||
kind: JoinKind.Unbalanced; | ||
}; | ||
|
||
export type SingleAssetJoinInput = BaseJoinInput & { | ||
bptOut: TokenAmount; | ||
tokenIn: Address; | ||
kind: JoinKind.SingleAsset; | ||
}; | ||
|
||
export type ProportionalJoinInput = BaseJoinInput & { | ||
bptOut: TokenAmount; | ||
kind: JoinKind.Proportional; | ||
}; | ||
|
||
export type JoinInput = | ||
| InitJoinInput | ||
| UnbalancedJoinInput | ||
| SingleAssetJoinInput | ||
| ProportionalJoinInput; | ||
|
||
// Returned from a join query | ||
export type JoinQueryResult = { | ||
poolId: Hex; | ||
joinKind: JoinKind; | ||
bptOut: TokenAmount; | ||
amountsIn: TokenAmount[]; | ||
fromInternalBalance: boolean; | ||
tokenInIndex?: number; | ||
}; | ||
|
||
export type JoinCallInput = JoinQueryResult & { | ||
slippage: Slippage; | ||
sender: Address; | ||
recipient: Address; | ||
}; | ||
|
||
export interface BaseJoin { | ||
query(input: JoinInput, poolState: PoolState): Promise<JoinQueryResult>; | ||
buildCall(input: JoinCallInput): { | ||
call: Hex; | ||
to: Address; | ||
value: bigint | undefined; | ||
minBptOut: bigint; | ||
maxAmountsIn: bigint[]; | ||
}; | ||
} | ||
export * from './poolJoin'; | ||
export * from './types'; |
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,24 +0,0 @@ | ||
import { BaseJoin } from '.'; | ||
import { WeightedJoin } from './weighted/weightedJoin'; | ||
|
||
/*********************** Basic Helper to get join class from pool type *************/ | ||
export type JoinConfig = { | ||
customPoolJoins: Record<string, BaseJoin>; | ||
}; | ||
|
||
export class JoinParser { | ||
private readonly poolJoins: Record<string, BaseJoin> = {}; | ||
|
||
constructor(config?: JoinConfig) { | ||
const { customPoolJoins } = config || {}; | ||
this.poolJoins = { | ||
WEIGHTED: new WeightedJoin(), | ||
// custom pool Joins take precedence over base Joins | ||
...customPoolJoins, | ||
}; | ||
} | ||
|
||
public getJoin(poolType: string): BaseJoin { | ||
return this.poolJoins[poolType]; | ||
} | ||
} | ||
Oops, something went wrong.