Skip to content

Commit

Permalink
feat: Add max add/remove methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Jul 26, 2024
1 parent baa4dfc commit a68c386
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions typescript/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const MAX_UINT256 =
115792089237316195423570985008687907853269984665640564039457584007913129639935n;
22 changes: 22 additions & 0 deletions typescript/src/stable/stablePool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MAX_UINT256 } from '../constants';
import { MathSol } from '../utils/math';
import {
MaxSwapParams,
Expand Down Expand Up @@ -45,6 +46,27 @@ export class Stable implements PoolBase {
);
}

getMaxSingleTokenAddAmount(): bigint {
return MAX_UINT256;
}

getMaxSingleTokenExitAmount(
isExactIn: boolean,
totalSupply: bigint,
tokenOutBalance: bigint,
tokenOutScalingFactor: bigint,
tokenOutRate: bigint,
): bigint {
return this.getMaxSwapAmount({
swapKind: isExactIn ? SwapKind.GivenIn : SwapKind.GivenOut,
balancesLiveScaled18: [totalSupply, tokenOutBalance],
tokenRates: [1000000000000000000n, tokenOutRate],
scalingFactors: [1000000000000000000n, tokenOutScalingFactor],
indexIn: 0,
indexOut: 1,
});
}

onSwap(swapParams: SwapParams): bigint {
const {
swapKind,
Expand Down
8 changes: 8 additions & 0 deletions typescript/src/vault/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export enum SwapKind {

export interface PoolBase {
getMaxSwapAmount(maxSwapParams: MaxSwapParams): bigint;
getMaxSingleTokenExitAmount(
isExactIn: boolean,
totalSupply: bigint,
tokenOutBalance: bigint,
tokenOutScalingFactor: bigint,
tokenOutRate: bigint,
): bigint;
getMaxSingleTokenAddAmount(): bigint;
onSwap(swapParams: SwapParams): bigint;
computeInvariant(balancesLiveScaled18: bigint[]): bigint;
computeBalance(
Expand Down
22 changes: 22 additions & 0 deletions typescript/src/weighted/weightedPool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MAX_UINT256 } from '../constants';
import { MathSol } from '../utils/math';
import {
MaxSwapParams,
Expand Down Expand Up @@ -39,6 +40,27 @@ export class Weighted implements PoolBase {
);
}

getMaxSingleTokenAddAmount(): bigint {
return MAX_UINT256;
}

getMaxSingleTokenExitAmount(
isExactIn: boolean,
totalSupply: bigint,
tokenOutBalance: bigint,
tokenOutScalingFactor: bigint,
tokenOutRate: bigint,
): bigint {
return this.getMaxSwapAmount({
swapKind: isExactIn ? SwapKind.GivenIn : SwapKind.GivenOut,
balancesLiveScaled18: [totalSupply, tokenOutBalance],
tokenRates: [1000000000000000000n, tokenOutRate],
scalingFactors: [1000000000000000000n, tokenOutScalingFactor],
indexIn: 0,
indexOut: 1,
});
}

onSwap(swapParams: SwapParams): bigint {
const {
swapKind,
Expand Down

0 comments on commit a68c386

Please sign in to comment.