/
odos-on-chain-parser.ts
47 lines (43 loc) · 1.7 KB
/
odos-on-chain-parser.ts
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 { blockchainId } from 'src/core/blockchain/utils/blockchains-info/constants/blockchain-id';
import { Web3Pure } from 'src/core/blockchain/web3-pure/web3-pure';
import { Injector } from 'src/core/injector/injector';
import { FAKE_WALLET_ADDRESS } from 'src/features/common/constants/fake-wallet-address';
import { ODOS_REFERRAL_CODE } from '../constants/odos-api-consts';
import {
OdosBestRouteRequestBody,
OdosInputTokenRequest,
OdosOutputTokenRequest
} from '../models/odos-api-best-route-types';
import { GetBestRouteBodyType } from '../models/odos-on-chain-parser-types';
export class OdosOnChainParser {
public static getBestRouteBody({
from,
toToken,
options,
swappersBlacklist = [],
swappersWhitelist = []
}: GetBestRouteBodyType): OdosBestRouteRequestBody {
const chainId = blockchainId[from.blockchain];
const userAddr =
options.fromAddress ??
Injector.web3PrivateService.getWeb3PrivateByBlockchain(from.blockchain).address ??
FAKE_WALLET_ADDRESS;
const inputTokens = [
{ tokenAddress: from.address, amount: Web3Pure.toWei(from.tokenAmount, from.decimals) }
] as OdosInputTokenRequest[];
const outputTokens = [
{ proportion: 1, tokenAddress: toToken.address }
] as OdosOutputTokenRequest[];
return {
inputTokens,
outputTokens,
chainId,
userAddr,
slippageLimitPercent: options.slippageTolerance * 100,
sourceBlacklist: swappersBlacklist,
sourceWhitelist: swappersWhitelist,
likeAsset: true,
referralCode: ODOS_REFERRAL_CODE
};
}
}