forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__DexName__.ts.template
181 lines (162 loc) · 5.15 KB
/
__DexName__.ts.template
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { AsyncOrSync } from 'ts-essentials';
import {
Token,
Address,
ExchangePrices,
PoolPrices,
AdapterExchangeParam,
SimpleExchangeParam,
PoolLiquidity,
Logger,
} from '../../types';
import { SwapSide, Network } from '../../constants';
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
import { getDexKeysWithNetwork } from '../../utils';
import { IDex } from '../../dex/idex';
import { IDexHelper } from '../../dex-helper/idex-helper';
import { __DexName__Data } from './types';
import { SimpleExchange } from '../simple-exchange';
import { __DexName__Config, Adapters } from './config';
import { __DexName__EventPool } from './__DexNameParam__-pool';
export class __DexName__
extends SimpleExchange
implements IDex<__DexName__Data>
{
protected eventPools: __DexName__EventPool;
readonly hasConstantPriceLargeAmounts = false;
// TODO: set true here if protocols works only with wrapped asset
readonly needWrapNative = true;
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
getDexKeysWithNetwork(__DexName__Config);
logger: Logger;
constructor(
readonly network: Network,
readonly dexKey: string,
readonly dexHelper: IDexHelper,
protected adapters = Adapters[network] || {}, // TODO: add any additional optional params to support other fork DEXes
) {
super(dexHelper.config.data.augustusAddress, dexHelper.web3Provider);
this.logger = dexHelper.getLogger(dexKey);
this.eventPools = new __DexName__EventPool(
dexKey,
network,
dexHelper,
this.logger,
);
}
// Initialize pricing is called once in the start of
// pricing service. It is intended to setup the integration
// for pricing requests. It is optional for a DEX to
// implement this function
async initializePricing(blockNumber: number) {
// TODO: complete me!
}
// Returns the list of contract adapters (name and index)
// for a buy/sell. Return null if there are no adapters.
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
return this.adapters[side] ? this.adapters[side] : null;
}
// Returns list of pool identifiers that can be used
// for a given swap. poolIdentifiers must be unique
// across DEXes. It is recommended to use
// ${dexKey}_${poolAddress} as a poolIdentifier
async getPoolIdentifiers(
srcToken: Token,
destToken: Token,
side: SwapSide,
blockNumber: number,
): Promise<string[]> {
// TODO: complete me!
return [];
}
// Returns pool prices for amounts.
// If limitPools is defined only pools in limitPools
// should be used. If limitPools is undefined then
// any pools can be used.
async getPricesVolume(
srcToken: Token,
destToken: Token,
amounts: bigint[],
side: SwapSide,
blockNumber: number,
limitPools?: string[],
): Promise<null | ExchangePrices<__DexName__Data>> {
// TODO: complete me!
return null;
}
// Returns estimated gas cost of calldata for this DEX in multiSwap
getCalldataGasCost(
poolPrices: PoolPrices<__DexName__Data>,
): number | number[] {
// TODO: update if there is any payload in getAdapterParam
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
}
// Encode params required by the exchange adapter
// Used for multiSwap, buy & megaSwap
// Hint: abiCoder.encodeParameter() could be useful
getAdapterParam(
srcToken: string,
destToken: string,
srcAmount: string,
destAmount: string,
data: __DexName__Data,
side: SwapSide,
): AdapterExchangeParam {
// TODO: complete me!
const { exchange } = data;
// Encode here the payload for adapter
const payload = '';
return {
targetExchange: exchange,
payload,
networkFee: '0',
};
}
// Encode call data used by simpleSwap like routers
// Used for simpleSwap & simpleBuy
// Hint: this.buildSimpleParamWithoutWETHConversion
// could be useful
async getSimpleParam(
srcToken: string,
destToken: string,
srcAmount: string,
destAmount: string,
data: __DexName__Data,
side: SwapSide,
): Promise<SimpleExchangeParam> {
// TODO: complete me!
const { exchange } = data;
// Encode here the transaction arguments
const swapData = '';
return this.buildSimpleParamWithoutWETHConversion(
srcToken,
srcAmount,
destToken,
destAmount,
swapData,
exchange,
);
}
// This is called once before getTopPoolsForToken is
// called for multiple tokens. This can be helpful to
// update common state required for calculating
// getTopPoolsForToken. It is optional for a DEX
// to implement this
async updatePoolState(): Promise<void> {
// TODO: complete me!
}
// Returns list of top pools based on liquidity. Max
// limit number pools should be returned.
async getTopPoolsForToken(
tokenAddress: Address,
limit: number,
): Promise<PoolLiquidity[]> {
//TODO: complete me!
return [];
}
// This is optional function in case if your implementation has acquired any resources
// you need to release for graceful shutdown. For example, it may be any interval timer
releaseResources(): AsyncOrSync<void> {
// TODO: complete me!
}
}