-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathvalidateInputs.ts
More file actions
47 lines (44 loc) · 1.62 KB
/
Copy pathvalidateInputs.ts
File metadata and controls
47 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { inputValidationError, NATIVE_ASSETS } from '@/utils';
import { BaseToken } from '../../baseToken';
import { TokenAmount } from '../../tokenAmount';
import { NestedPoolState } from '../../types';
import { AddLiquidityNestedInput } from '../types';
import { AddLiquidityNestedCallInputV2 } from './types';
export const validateQueryInput = (
input: AddLiquidityNestedInput,
nestedPoolState: NestedPoolState,
): TokenAmount[] => {
const mainTokens = nestedPoolState.mainTokens.map(
(t) => new BaseToken(input.chainId, t.address, t.decimals),
);
const amountsIn = input.amountsIn.map((amountIn) => {
const tokenIn = mainTokens.find((t) =>
t.isSameAddress(amountIn.address),
);
if (tokenIn === undefined) {
throw inputValidationError(
'Add Liquidity Nested',
`Adding liquidity with amountIn address ${amountIn.address} requires it to exist within mainTokens`,
);
}
return TokenAmount.fromRawAmount(tokenIn, amountIn.rawAmount);
});
return amountsIn;
};
export const validateBuildCallInput = (
input: AddLiquidityNestedCallInputV2,
): void => {
const chainId = input.callsAttributes[0].chainId;
if (input.wethIsEth) {
if (
!input.amountsIn.some((a) =>
a.token.isSameAddress(NATIVE_ASSETS[chainId].wrapped),
)
) {
throw inputValidationError(
'Add Liquidity Nested',
'Adding liquidity with native asset requires wrapped native asset to exist within amountsIn',
);
}
}
};