@@ -135,6 +135,25 @@ export default class TradeAPI {
135135 ) ;
136136 }
137137
138+ /**
139+ * Call 0x API to generate a trade quote for two SetToken components.
140+ *
141+ * @param fromToken Address of token being sold
142+ * @param toToken Address of token being bought
143+ * @param fromTokenDecimals Token decimals of token being sold (ex: 18)
144+ * @param toTokenDecimals Token decimals of token being bought (ex: 18)
145+ * @param rawAmount String quantity of token to sell (ex: "0.5")
146+ * @param fromAddress SetToken address which holds the buy / sell components
147+ * @param setToken SetTokenAPI instance
148+ * @param gasPrice (Optional) gasPrice to calculate gas costs with (Default: fetched from GasNow)
149+ * @param slippagePercentage (Optional) maximum slippage, determines min receive quantity. (Default: 2%)
150+ * @param isFirmQuote (Optional) Whether quote request is indicative or firm
151+ * @param feePercentage (Optional) Default: 0
152+ * @param feeRecipient (Optional) Default: 0xD3D555Bb655AcBA9452bfC6D7cEa8cC7b3628C55
153+ * @param excludedSources (Optional) Exchanges to exclude (Default: ['Kyber', 'Eth2Dai', 'Uniswap', 'Mesh'])
154+ *
155+ * @return {Promise<TradeQuote> }
156+ */
138157 public async fetchTradeQuoteAsync (
139158 fromToken : Address ,
140159 toToken : Address ,
@@ -159,7 +178,6 @@ export default class TradeAPI {
159178
160179 const chainId = ( await this . provider . getNetwork ( ) ) . chainId ;
161180
162- // @ts -ignore
163181 return this . tradeQuoter . generate ( {
164182 fromToken,
165183 toToken,
@@ -180,30 +198,61 @@ export default class TradeAPI {
180198 } ) ;
181199 }
182200
183- public async fetchTokenList ( ) : Promise < CoinGeckoTokenData [ ] > {
201+ /**
202+ * Fetches a list of tokens and their metadata from CoinGecko. Each entry includes
203+ * the token's address, proper name, decimals, exchange symbol and a logo URI if available.
204+ * For Ethereum, this is a list of tokens tradeable on Uniswap, for Polygon it's a list of
205+ * tokens tradeable on Sushiswap's Polygon exchange. Method is useful for acquiring token decimals
206+ * necessary to generate a trade quote and images for representing available tokens in a UI.
207+ *
208+ * @return List of tradeable tokens for chain platform
209+ */
210+ public async fetchTokenListAsync ( ) : Promise < CoinGeckoTokenData [ ] > {
184211 await this . initializeForChain ( ) ;
185212 return this . coinGecko . fetchTokenList ( ) ;
186213 }
187214
188- public async fetchTokenMap ( ) : Promise < CoinGeckoTokenMap > {
215+ /**
216+ * Fetches the same info as `fetchTokenList` in the form of a map indexed by address. Method is
217+ * useful if you're cacheing the token list and want quick lookups for a variety of trades.
218+ *
219+ * @return Map of token addresses to token metadata
220+ */
221+ public async fetchTokenMapAsync ( ) : Promise < CoinGeckoTokenMap > {
189222 await this . initializeForChain ( ) ;
190223 return this . coinGecko . fetchTokenMap ( ) ;
191224 }
192225
193- public async fetchCoinPrices (
226+ /**
227+ * Fetches a list of prices vs currencies for the specified inputs from CoinGecko
228+ *
229+ * @param contractAddresses String array of contract addresses
230+ * @param vsCurrencies String array of currency codes (see CoinGecko api for a complete list)
231+ *
232+ * @return List of prices vs currencies
233+ */
234+ public async fetchCoinPricesAsync (
194235 contractAddresses : string [ ] ,
195236 vsCurrencies : string [ ]
196237 ) : Promise < CoinGeckoCoinPrices > {
197238 await this . initializeForChain ( ) ;
198239 return this . coinGecko . fetchCoinPrices ( { contractAddresses, vsCurrencies} ) ;
199240 }
200241
201- public async fetchGasPrice ( speed : GasOracleSpeed ) : Promise < number > {
242+ /**
243+ * Fetches the recommended gas price for a specified execution speed.
244+ *
245+ * @param speed (Optional) string value: "average" | "fast" | "fastest" (Default: fast)
246+ *
247+ * @return Number: gas price
248+ */
249+ public async fetchGasPriceAsync ( speed ?: GasOracleSpeed ) : Promise < number > {
202250 await this . initializeForChain ( ) ;
203251 const oracle = new GasOracleService ( this . chainId ) ;
204252 return oracle . fetchGasPrice ( speed ) ;
205253 }
206254
255+
207256 private async initializeForChain ( ) {
208257 if ( this . coinGecko === undefined ) {
209258 const network = await this . provider . getNetwork ( ) ;
0 commit comments