@renegade-fi/core
Advanced tools
Comparing version 0.0.0-canary-20241204161547 to 0.0.0-canary-20241204215715
import { PRICE_REPORTER_ROUTE } from '../constants.js'; | ||
import { Token } from '../types/token.js'; | ||
import { DEFAULT_QUOTE } from '../types/token.js'; | ||
import { getRelayerRaw } from '../utils/http.js'; | ||
export const DEFAULT_QUOTE = { | ||
binance: Token.findByTicker('USDT').address, | ||
coinbase: Token.findByTicker('USDC').address, | ||
kraken: '0x0000000000000000000000000000000000000000', | ||
okx: Token.findByTicker('USDT').address, | ||
}; | ||
export async function getPriceFromPriceReporter(config, parameters) { | ||
const { exchange = 'binance', base, quote = DEFAULT_QUOTE[exchange], } = parameters; | ||
const { exchange = 'binance', base, quote = DEFAULT_QUOTE[exchange].address, } = parameters; | ||
const { getPriceReporterHTTPBaseUrl } = config; | ||
@@ -13,0 +7,0 @@ const res = await getRelayerRaw(getPriceReporterHTTPBaseUrl(PRICE_REPORTER_ROUTE(exchange, base, quote))); |
@@ -65,3 +65,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { Token, tokenMapping, } from '../types/token.js'; | ||
export { Token, tokenMapping, DEFAULT_QUOTE, } from '../types/token.js'; | ||
export * from '../types/wallet.js'; | ||
@@ -68,0 +68,0 @@ export * from '../types/order.js'; |
@@ -6,5 +6,16 @@ import invariant from 'tiny-invariant'; | ||
invariant(tokenMappingUrl || tokenMappingStr, 'No token mapping initialization option provided'); | ||
export const tokenMapping = JSON.parse(tokenMappingUrl | ||
? await fetch(tokenMappingUrl).then((res) => res.text()) | ||
: tokenMappingStr); | ||
export const tokenMapping = tokenMappingUrl | ||
? await fetch(tokenMappingUrl) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
for (const t of data.tokens) { | ||
t.supported_exchanges = Object.fromEntries(Object.entries(t.supported_exchanges).map(([k, v]) => [ | ||
// Lowercase all of the exchange names to match the Exchange enum | ||
k.toLowerCase(), | ||
v, | ||
])); | ||
} | ||
return data; | ||
}) | ||
: JSON.parse(tokenMappingStr); | ||
//////////////////////////////////////////////////////////////////////////////// | ||
@@ -79,3 +90,3 @@ // Token Class | ||
get supportedExchanges() { | ||
return new Set(Object.keys(this._supported_exchanges).map((e) => Token.fromSupportedExchange(e))); | ||
return new Set(Object.keys(this._supported_exchanges)); | ||
} | ||
@@ -92,3 +103,3 @@ get rawSupportedExchanges() { | ||
getExchangeTicker(exchange) { | ||
return this._supported_exchanges[Token.toSupportedExchange(exchange)]; | ||
return this._supported_exchanges[exchange]; | ||
} | ||
@@ -126,11 +137,10 @@ isStablecoin() { | ||
} | ||
static toSupportedExchange(exchange) { | ||
return (exchange.charAt(0).toUpperCase() + | ||
exchange.slice(1)); | ||
} | ||
static fromSupportedExchange(exchange) { | ||
return exchange.toLowerCase(); | ||
} | ||
} | ||
const DEFAULT_TOKEN = Token.create('UNKNOWN', 'UNKNOWN', zeroAddress, 0); | ||
export const DEFAULT_QUOTE = { | ||
binance: Token.findByTicker('USDT'), | ||
coinbase: Token.findByTicker('USDC'), | ||
kraken: Token.create('USD Coin', 'USDC', '0x0000000000000000000000000000000000000000', 6, { kraken: 'USD' }), | ||
okx: Token.findByTicker('USDT'), | ||
}; | ||
//# sourceMappingURL=token.js.map |
import type { Address } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Exchange } from '../types/wallet.js'; | ||
export declare const DEFAULT_QUOTE: Record<Exchange, Address>; | ||
export type GetPriceParameters = { | ||
@@ -6,0 +5,0 @@ exchange?: Exchange; |
@@ -44,3 +44,3 @@ export { type CancelOrderRequestErrorType, type CancelOrderRequestParameters, type CancelOrderRequestReturnType, cancelOrderRequest, } from '../actions/cancelOrderRequest.js'; | ||
export { BaseError } from '../errors/base.js'; | ||
export { Token, tokenMapping, } from '../types/token.js'; | ||
export { Token, tokenMapping, DEFAULT_QUOTE, } from '../types/token.js'; | ||
export * from '../types/wallet.js'; | ||
@@ -47,0 +47,0 @@ export * from '../types/order.js'; |
import { type Address } from 'viem'; | ||
import type { Exchange } from './wallet.js'; | ||
type SupportedExchange = 'Binance' | 'Coinbase' | 'Kraken' | 'Okx'; | ||
type TokenMetadata = { | ||
@@ -9,3 +8,3 @@ name: string; | ||
decimals: number; | ||
supported_exchanges: Partial<Record<SupportedExchange, string>>; | ||
supported_exchanges: Partial<Record<Exchange, string>>; | ||
chain_addresses: Record<string, string>; | ||
@@ -33,3 +32,3 @@ logo_url: string; | ||
get supportedExchanges(): Set<Exchange>; | ||
get rawSupportedExchanges(): Partial<Record<SupportedExchange, string>>; | ||
get rawSupportedExchanges(): Partial<Record<Exchange, string>>; | ||
get chainAddresses(): Record<string, string>; | ||
@@ -41,7 +40,6 @@ get logoUrl(): string; | ||
static findByAddress(address: Address): Token; | ||
static create(name: string, ticker: string, address: Address, decimals: number, supported_exchanges?: Partial<Record<SupportedExchange, string>>, chain_addresses?: Record<string, string>, logo_url?: string): Token; | ||
private static toSupportedExchange; | ||
private static fromSupportedExchange; | ||
static create(name: string, ticker: string, address: Address, decimals: number, supported_exchanges?: Partial<Record<Exchange, string>>, chain_addresses?: Record<string, string>, logo_url?: string): Token; | ||
} | ||
export declare const DEFAULT_QUOTE: Record<Exchange, Token>; | ||
export {}; | ||
//# sourceMappingURL=token.d.ts.map |
{ | ||
"name": "@renegade-fi/core", | ||
"description": "VanillaJS library for Renegade", | ||
"version": "0.0.0-canary-20241204161547", | ||
"version": "0.0.0-canary-20241204215715", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
import type { Address } from 'viem' | ||
import { PRICE_REPORTER_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import { Token } from '../types/token.js' | ||
import { DEFAULT_QUOTE } from '../types/token.js' | ||
import type { Exchange } from '../types/wallet.js' | ||
import { getRelayerRaw } from '../utils/http.js' | ||
export const DEFAULT_QUOTE: Record<Exchange, Address> = { | ||
binance: Token.findByTicker('USDT').address, | ||
coinbase: Token.findByTicker('USDC').address, | ||
kraken: '0x0000000000000000000000000000000000000000' as Address, | ||
okx: Token.findByTicker('USDT').address, | ||
} | ||
export type GetPriceParameters = { | ||
@@ -30,3 +23,3 @@ exchange?: Exchange | ||
base, | ||
quote = DEFAULT_QUOTE[exchange], | ||
quote = DEFAULT_QUOTE[exchange].address, | ||
} = parameters | ||
@@ -33,0 +26,0 @@ const { getPriceReporterHTTPBaseUrl } = config |
@@ -282,2 +282,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
tokenMapping, | ||
DEFAULT_QUOTE, | ||
} from '../types/token.js' | ||
@@ -284,0 +285,0 @@ export * from '../types/wallet.js' |
@@ -9,4 +9,2 @@ import invariant from 'tiny-invariant' | ||
type SupportedExchange = 'Binance' | 'Coinbase' | 'Kraken' | 'Okx' | ||
type TokenMetadata = { | ||
@@ -17,3 +15,3 @@ name: string | ||
decimals: number | ||
supported_exchanges: Partial<Record<SupportedExchange, string>> | ||
supported_exchanges: Partial<Record<Exchange, string>> | ||
chain_addresses: Record<string, string> | ||
@@ -38,7 +36,18 @@ logo_url: string | ||
export const tokenMapping = JSON.parse( | ||
tokenMappingUrl | ||
? await fetch(tokenMappingUrl).then((res) => res.text()) | ||
: tokenMappingStr!, | ||
) as TokenMapping | ||
export const tokenMapping: TokenMapping = tokenMappingUrl | ||
? await fetch(tokenMappingUrl) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
for (const t of data.tokens) { | ||
t.supported_exchanges = Object.fromEntries( | ||
Object.entries(t.supported_exchanges).map(([k, v]) => [ | ||
// Lowercase all of the exchange names to match the Exchange enum | ||
k.toLowerCase(), | ||
v, | ||
]), | ||
) | ||
} | ||
return data | ||
}) | ||
: JSON.parse(tokenMappingStr!) | ||
@@ -56,3 +65,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
private _decimals: number | ||
private _supported_exchanges: Partial<Record<SupportedExchange, string>> | ||
private _supported_exchanges: Partial<Record<Exchange, string>> | ||
private _chain_addresses: Record<string, string> | ||
@@ -88,10 +97,6 @@ private _logo_url: string | ||
get supportedExchanges(): Set<Exchange> { | ||
return new Set( | ||
Object.keys(this._supported_exchanges).map((e) => | ||
Token.fromSupportedExchange(e as SupportedExchange), | ||
), | ||
) | ||
return new Set(Object.keys(this._supported_exchanges)) as Set<Exchange> | ||
} | ||
get rawSupportedExchanges(): Partial<Record<SupportedExchange, string>> { | ||
get rawSupportedExchanges(): Partial<Record<Exchange, string>> { | ||
return this._supported_exchanges | ||
@@ -109,3 +114,3 @@ } | ||
getExchangeTicker(exchange: Exchange): string | undefined { | ||
return this._supported_exchanges[Token.toSupportedExchange(exchange)] | ||
return this._supported_exchanges[exchange] | ||
} | ||
@@ -142,3 +147,3 @@ | ||
decimals: number, | ||
supported_exchanges: Partial<Record<SupportedExchange, string>> = {}, | ||
supported_exchanges: Partial<Record<Exchange, string>> = {}, | ||
chain_addresses: Record<string, string> = {}, | ||
@@ -160,13 +165,17 @@ logo_url = '', | ||
} | ||
} | ||
private static toSupportedExchange(exchange: Exchange): SupportedExchange { | ||
return (exchange.charAt(0).toUpperCase() + | ||
exchange.slice(1)) as SupportedExchange | ||
} | ||
const DEFAULT_TOKEN = Token.create('UNKNOWN', 'UNKNOWN', zeroAddress, 0) | ||
private static fromSupportedExchange(exchange: SupportedExchange): Exchange { | ||
return exchange.toLowerCase() as Exchange | ||
} | ||
export const DEFAULT_QUOTE: Record<Exchange, Token> = { | ||
binance: Token.findByTicker('USDT'), | ||
coinbase: Token.findByTicker('USDC'), | ||
kraken: Token.create( | ||
'USD Coin', | ||
'USDC', | ||
'0x0000000000000000000000000000000000000000', | ||
6, | ||
{ kraken: 'USD' }, | ||
), | ||
okx: Token.findByTicker('USDT'), | ||
} | ||
const DEFAULT_TOKEN = Token.create('UNKNOWN', 'UNKNOWN', zeroAddress, 0) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8655
755994