@renegade-fi/core
Advanced tools
Comparing version 0.0.8 to 0.0.9
//////////////////////////////////////////////////////////////////////////////// | ||
// createConfig | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { createConfig, } from "./createConfig.js"; | ||
export { createConfig, } from './createConfig.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Actions | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { cancelOrder, } from "./actions/cancelOrder.js"; | ||
export { connect } from "./actions/connect.js"; | ||
export { createOrder, } from "./actions/createOrder.js"; | ||
export { createWallet, } from "./actions/createWallet.js"; | ||
export { deposit } from "./actions/deposit.js"; | ||
export { disconnect, } from "./actions/disconnect.js"; | ||
export { getAuthorizationHeaders, } from "./actions/getAuthHeaders.js"; | ||
export { getBalances, } from "./actions/getBalances.js"; | ||
export { getOrder } from "./actions/getOrder.js"; | ||
export { getOrderHistory, } from "./actions/getOrderHistory.js"; | ||
export { getNetworkOrders, } from "./actions/getNetworkOrders.js"; | ||
export { getOrders, } from "./actions/getOrders.js"; | ||
export { getPkRoot, getPkRootScalars, } from "./actions/getPkRoot.js"; | ||
export { getSkRoot, } from "./actions/getSkRoot.js"; | ||
export { getTaskHistory, } from "./actions/getTaskHistory.js"; | ||
export { getTaskStatus, } from "./actions/getTaskStatus.js"; | ||
export { getTaskQueue, } from "./actions/getTaskQueue.js"; | ||
export { getWalletFromRelayer, } from "./actions/getWalletFromRelayer.js"; | ||
export { getWalletId, } from "./actions/getWalletId.js"; | ||
export { lookupWallet, } from "./actions/lookupWallet.js"; | ||
export { payFees } from "./actions/payFees.js"; | ||
export { signMessage, } from "./actions/signMessage.js"; | ||
export { waitForTaskCompletion, } from "./actions/waitForTaskCompletion.js"; | ||
export { watchStatus, } from "./actions/watchStatus.js"; | ||
export { withdraw } from "./actions/withdraw.js"; | ||
export { cancelOrder, } from './actions/cancelOrder.js'; | ||
export { connect, } from './actions/connect.js'; | ||
export { createOrder, } from './actions/createOrder.js'; | ||
export { createWallet, } from './actions/createWallet.js'; | ||
export { deposit, } from './actions/deposit.js'; | ||
export { disconnect, } from './actions/disconnect.js'; | ||
export { getAuthorizationHeaders, } from './actions/getAuthHeaders.js'; | ||
export { getBalances, } from './actions/getBalances.js'; | ||
export { getOrder, } from './actions/getOrder.js'; | ||
export { getOrderHistory, } from './actions/getOrderHistory.js'; | ||
export { getNetworkOrders, } from './actions/getNetworkOrders.js'; | ||
export { getOrders, } from './actions/getOrders.js'; | ||
export { getPkRoot, getPkRootScalars, } from './actions/getPkRoot.js'; | ||
export { getSkRoot, } from './actions/getSkRoot.js'; | ||
export { getTaskHistory, } from './actions/getTaskHistory.js'; | ||
export { getTaskStatus, } from './actions/getTaskStatus.js'; | ||
export { getTaskQueue, } from './actions/getTaskQueue.js'; | ||
export { getWalletFromRelayer, } from './actions/getWalletFromRelayer.js'; | ||
export { getWalletId, } from './actions/getWalletId.js'; | ||
export { lookupWallet, } from './actions/lookupWallet.js'; | ||
export { payFees } from './actions/payFees.js'; | ||
export { signMessage, } from './actions/signMessage.js'; | ||
export { waitForTaskCompletion, } from './actions/waitForTaskCompletion.js'; | ||
export { watchStatus, } from './actions/watchStatus.js'; | ||
export { withdraw, } from './actions/withdraw.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Hydrate | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { hydrate } from "./hydrate.js"; | ||
export { hydrate } from './hydrate.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Errors | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { BaseError } from "./errors/base.js"; | ||
export { BaseError } from './errors/base.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Constants | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export * from "./constants.js"; | ||
export * from './constants.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Types | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { Token } from "./types/token.js"; | ||
export * from "./types/wallet.js"; | ||
export { UpdateType, TaskType } from "./types/task.js"; | ||
export { Token } from './types/token.js'; | ||
export * from './types/wallet.js'; | ||
export { UpdateType, TaskType } from './types/task.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Utils | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { formatAmount, parseAmount } from "./utils/format.js"; | ||
export { deepEqual } from "./utils/deepEqual.js"; | ||
export { WebSocketManager } from "./utils/websocket.js"; | ||
export { formatAmount, parseAmount } from './utils/format.js'; | ||
export { deepEqual } from './utils/deepEqual.js'; | ||
export { WebSocketManager } from './utils/websocket.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Viem | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { chain } from "./utils/chain.js"; | ||
export { chain } from './utils/chain.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,7 +0,6 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js"; | ||
import { getWalletId } from "./getWalletId.js"; | ||
import JSONBigInt from "json-bigint"; | ||
import { postRelayerWithAuth } from "../utils/http.js"; | ||
import { CANCEL_ORDER_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import JSONBigInt from 'json-bigint'; | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js'; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { postRelayerWithAuth } from '../utils/http.js'; | ||
import { CANCEL_ORDER_ROUTE } from '../constants.js'; | ||
export async function cancelOrder(config, parameters) { | ||
@@ -8,0 +7,0 @@ const { id } = parameters; |
@@ -1,6 +0,5 @@ | ||
import { createWallet } from "./createWallet.js"; | ||
import { getWalletFromRelayer } from "./getWalletFromRelayer.js"; | ||
import { getWalletId } from "./getWalletId.js"; | ||
import { lookupWallet, lookupWalletOnChain } from "./lookupWallet.js"; | ||
import {} from "../createConfig.js"; | ||
import { createWallet } from './createWallet.js'; | ||
import { getWalletFromRelayer } from './getWalletFromRelayer.js'; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { lookupWallet, lookupWalletOnChain } from './lookupWallet.js'; | ||
export async function connect(config, parameters = {}) { | ||
@@ -13,3 +12,3 @@ const { seed } = parameters; | ||
catch (error) { | ||
console.error("Error getting wallet id", { | ||
console.error('Error getting wallet id', { | ||
errorStack: error.stack, | ||
@@ -22,9 +21,9 @@ errorMessage: error.message, | ||
} | ||
console.log("Attempting to connect wallet", { walletId }); | ||
console.log('Attempting to connect wallet', { walletId }); | ||
try { | ||
const wallet = await getWalletFromRelayer(config, { seed }); | ||
if (wallet) { | ||
config.setState({ ...config.state, status: "in relayer", id: wallet.id }); | ||
console.log("Wallet found in relayer", { | ||
status: "in relayer", | ||
config.setState({ ...config.state, status: 'in relayer', id: wallet.id }); | ||
console.log('Wallet found in relayer', { | ||
status: 'in relayer', | ||
walletId: wallet.id, | ||
@@ -36,3 +35,3 @@ }); | ||
catch (error) { | ||
console.error("Error getting wallet from relayer", { error, walletId }); | ||
console.error('Error getting wallet from relayer', { error, walletId }); | ||
} | ||
@@ -46,3 +45,3 @@ // If wallet on chain, start lookup wallet task | ||
console.log(`task lookup-wallet(${res.taskId}): ${res.walletId}`, { | ||
status: "looking up", | ||
status: 'looking up', | ||
walletId: res.walletId, | ||
@@ -55,6 +54,10 @@ }); | ||
error, | ||
status: "looking up", | ||
status: 'looking up', | ||
walletId, | ||
}); | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }); | ||
config.setState({ | ||
status: 'disconnected', | ||
id: undefined, | ||
seed: undefined, | ||
}); | ||
throw error; | ||
@@ -68,3 +71,3 @@ } | ||
console.log(`task create-wallet(${res.taskId}): ${res.walletId}`, { | ||
status: "creating wallet", | ||
status: 'creating wallet', | ||
walletId: res.walletId, | ||
@@ -77,6 +80,6 @@ }); | ||
error, | ||
status: "creating wallet", | ||
status: 'creating wallet', | ||
walletId, | ||
}); | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }); | ||
config.setState({ status: 'disconnected', id: undefined, seed: undefined }); | ||
throw error; | ||
@@ -83,0 +86,0 @@ } |
@@ -1,11 +0,10 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js"; | ||
import { getWalletId } from "./getWalletId.js"; | ||
import JSONBigInt from "json-bigint"; | ||
import { toHex } from "viem"; | ||
import { postRelayerWithAuth } from "../utils/http.js"; | ||
import { WALLET_ORDERS_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { Token } from "../types/token.js"; | ||
import JSONBigInt from 'json-bigint'; | ||
import { toHex } from 'viem'; | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js'; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { postRelayerWithAuth } from '../utils/http.js'; | ||
import { WALLET_ORDERS_ROUTE } from '../constants.js'; | ||
import { Token } from '../types/token.js'; | ||
export async function createOrder(config, parameters) { | ||
const { id = "", base, quote, side, amount } = parameters; | ||
const { id = '', base, quote, side, amount } = parameters; | ||
const { getRelayerBaseUrl, utils } = config; | ||
@@ -12,0 +11,0 @@ const walletId = getWalletId(config); |
@@ -1,8 +0,6 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { waitForTaskCompletion } from "./waitForTaskCompletion.js"; | ||
import { postRelayerRaw } from "../utils/http.js"; | ||
import { CREATE_WALLET_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
export async function createWallet(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { waitForTaskCompletion } from './waitForTaskCompletion.js'; | ||
import { postRelayerRaw } from '../utils/http.js'; | ||
import { CREATE_WALLET_ROUTE } from '../constants.js'; | ||
export async function createWallet(config) { | ||
const { getRelayerBaseUrl, utils } = config; | ||
@@ -12,9 +10,13 @@ const skRoot = getSkRoot(config); | ||
const headers = { | ||
"Content-Type": "application/json", | ||
'Content-Type': 'application/json', | ||
}; | ||
const res = await postRelayerRaw(getRelayerBaseUrl(CREATE_WALLET_ROUTE), body, headers); | ||
if (res.task_id) { | ||
config.setState({ ...config.state, status: "creating wallet" }); | ||
config.setState({ ...config.state, status: 'creating wallet' }); | ||
waitForTaskCompletion(config, { id: res.task_id }).then(() => { | ||
config.setState({ ...config.state, status: "in relayer" }); | ||
config.setState({ | ||
...config.state, | ||
id: res.wallet_id, | ||
status: 'in relayer', | ||
}); | ||
}); | ||
@@ -21,0 +23,0 @@ } |
@@ -1,10 +0,9 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js"; | ||
import { getWalletId } from "./getWalletId.js"; | ||
import JSONBigInt from "json-bigint"; | ||
import invariant from "tiny-invariant"; | ||
import { toHex } from "viem"; | ||
import { postRelayerWithAuth } from "../utils/http.js"; | ||
import { DEPOSIT_BALANCE_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { Token } from "../types/token.js"; | ||
import JSONBigInt from 'json-bigint'; | ||
import invariant from 'tiny-invariant'; | ||
import { toHex } from 'viem'; | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js'; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { postRelayerWithAuth } from '../utils/http.js'; | ||
import { DEPOSIT_BALANCE_ROUTE } from '../constants.js'; | ||
import { Token } from '../types/token.js'; | ||
export async function deposit(config, parameters) { | ||
@@ -14,3 +13,3 @@ const { fromAddr, mint, amount, permitNonce, permitDeadline, permit } = parameters; | ||
const token = Token.findByAddress(mint); | ||
invariant(token, "Token not found"); | ||
invariant(token, 'Token not found'); | ||
const walletId = getWalletId(config); | ||
@@ -17,0 +16,0 @@ const wallet = await getBackOfQueueWallet(config); |
@@ -1,7 +0,4 @@ | ||
import {} from "../createConfig.js"; | ||
export async function disconnect(config, parameters = {}) { | ||
const {} = config; | ||
const {} = parameters; | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }); | ||
export async function disconnect(config) { | ||
config.setState({ status: 'disconnected', id: undefined, seed: undefined }); | ||
} | ||
//# sourceMappingURL=disconnect.js.map |
@@ -1,2 +0,2 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
export const getAuthorizationHeaders = (config, parameters) => { | ||
@@ -3,0 +3,0 @@ const { message } = parameters; |
@@ -1,5 +0,4 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { BACK_OF_QUEUE_WALLET_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { BACK_OF_QUEUE_WALLET_ROUTE } from '../constants.js'; | ||
export async function getBackOfQueueWallet(config, parameters = {}) { | ||
@@ -6,0 +5,0 @@ const { seed } = parameters; |
@@ -1,7 +0,5 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { GET_BALANCES_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
export async function getBalances(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { GET_BALANCES_ROUTE } from '../constants.js'; | ||
export async function getBalances(config) { | ||
const { getRelayerBaseUrl, utils } = config; | ||
@@ -8,0 +6,0 @@ const skRoot = getSkRoot(config); |
@@ -1,6 +0,4 @@ | ||
import { getRelayerRaw } from "../utils/http.js"; | ||
import { GET_NETWORK_ORDERS_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
export async function getNetworkOrders(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getRelayerRaw } from '../utils/http.js'; | ||
import { GET_NETWORK_ORDERS_ROUTE } from '../constants.js'; | ||
export async function getNetworkOrders(config) { | ||
const { getRelayerBaseUrl } = config; | ||
@@ -7,0 +5,0 @@ const res = await getRelayerRaw(getRelayerBaseUrl(GET_NETWORK_ORDERS_ROUTE)); |
@@ -1,5 +0,4 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { GET_ORDER_BY_ID_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { GET_ORDER_BY_ID_ROUTE } from '../constants.js'; | ||
export async function getOrder(config, parameters) { | ||
@@ -6,0 +5,0 @@ const { id } = parameters; |
@@ -1,7 +0,5 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { ORDER_HISTORY_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
export async function getOrderHistory(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { ORDER_HISTORY_ROUTE } from '../constants.js'; | ||
export async function getOrderHistory(config) { | ||
const { getRelayerBaseUrl, utils } = config; | ||
@@ -8,0 +6,0 @@ const skRoot = getSkRoot(config); |
@@ -1,7 +0,5 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { WALLET_ORDERS_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
export async function getOrders(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { WALLET_ORDERS_ROUTE } from '../constants.js'; | ||
export async function getOrders(config) { | ||
const { getRelayerBaseUrl, utils } = config; | ||
@@ -8,0 +6,0 @@ const skRoot = getSkRoot(config); |
@@ -1,3 +0,2 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import {} from "viem"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
export function getPkRoot(config) { | ||
@@ -4,0 +3,0 @@ const { utils } = config; |
@@ -1,4 +0,2 @@ | ||
import invariant from "tiny-invariant"; | ||
import {} from "viem"; | ||
import {} from "../createConfig.js"; | ||
import invariant from 'tiny-invariant'; | ||
export function getSkRoot(config, parameters = {}) { | ||
@@ -12,5 +10,5 @@ const { seed } = parameters; | ||
const storedSeed = config.state.seed; | ||
invariant(storedSeed, "Seed must be defined when none exists in memory"); | ||
invariant(storedSeed, 'Seed must be defined when none exists in memory'); | ||
return utils.derive_signing_key_from_seed(storedSeed); | ||
} | ||
//# sourceMappingURL=getSkRoot.js.map |
@@ -1,8 +0,5 @@ | ||
import { getWalletId } from "./getWalletId.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { TASK_HISTORY_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import {} from "../types/task.js"; | ||
export async function getTaskHistory(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { TASK_HISTORY_ROUTE } from '../constants.js'; | ||
export async function getTaskHistory(config) { | ||
const { getRelayerBaseUrl } = config; | ||
@@ -9,0 +6,0 @@ const walletId = getWalletId(config); |
@@ -1,7 +0,5 @@ | ||
import { getWalletId } from "./getWalletId.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { GET_TASK_QUEUE_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
export async function getTaskQueue(config, parameters = {}) { | ||
const {} = parameters; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { GET_TASK_QUEUE_ROUTE } from '../constants.js'; | ||
export async function getTaskQueue(config) { | ||
const { getRelayerBaseUrl } = config; | ||
@@ -8,0 +6,0 @@ const walletId = getWalletId(config); |
@@ -1,4 +0,3 @@ | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { GET_TASK_STATUS_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { GET_TASK_STATUS_ROUTE } from '../constants.js'; | ||
export async function getTaskStatus(config, parameters) { | ||
@@ -5,0 +4,0 @@ const { id } = parameters; |
@@ -1,5 +0,4 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { GET_WALLET_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { GET_WALLET_ROUTE } from '../constants.js'; | ||
export async function getWalletFromRelayer(config, parameters = {}) { | ||
@@ -12,3 +11,7 @@ const { seed } = parameters; | ||
if (res.wallet) { | ||
config.setState({ ...config.state, status: "in relayer" }); | ||
config.setState({ | ||
...config.state, | ||
status: 'in relayer', | ||
id: res.wallet.id, | ||
}); | ||
return res.wallet; | ||
@@ -15,0 +18,0 @@ } |
@@ -1,3 +0,2 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import {} from "../createConfig.js"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
export function getWalletId(config, parameters = {}) { | ||
@@ -4,0 +3,0 @@ const { utils } = config; |
@@ -1,8 +0,7 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getWalletFromRelayer } from "./getWalletFromRelayer.js"; | ||
import { waitForTaskCompletion } from "./waitForTaskCompletion.js"; | ||
import { createPublicClient, http, parseAbiItem } from "viem"; | ||
import { postRelayerRaw } from "../utils/http.js"; | ||
import { FIND_WALLET_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { http, createPublicClient, parseAbiItem } from 'viem'; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
import { getWalletFromRelayer } from './getWalletFromRelayer.js'; | ||
import { waitForTaskCompletion } from './waitForTaskCompletion.js'; | ||
import { postRelayerRaw } from '../utils/http.js'; | ||
import { FIND_WALLET_ROUTE } from '../constants.js'; | ||
export async function lookupWallet(config, parameters = {}) { | ||
@@ -15,9 +14,13 @@ const { seed } = parameters; | ||
if (res.task_id) { | ||
config.setState({ ...config.state, status: "looking up" }); | ||
config.setState({ ...config.state, status: 'looking up' }); | ||
waitForTaskCompletion(config, { id: res.task_id }).then(async () => { | ||
await getWalletFromRelayer(config, { seed }).then(wallet => { | ||
await getWalletFromRelayer(config, { seed }).then((wallet) => { | ||
if (wallet) { | ||
config.setState({ ...config.state, status: "in relayer", id: res.wallet_id }); | ||
config.setState({ | ||
...config.state, | ||
status: 'in relayer', | ||
id: res.wallet_id, | ||
}); | ||
console.log(`task lookup-wallet(${res.task_id}) completed: ${res.wallet_id}`, { | ||
status: "in relayer", | ||
status: 'in relayer', | ||
walletId: res.wallet_id, | ||
@@ -42,3 +45,3 @@ }); | ||
address: config.darkPoolAddress, | ||
event: parseAbiItem("event WalletUpdated(uint256 indexed wallet_blinder_share)"), | ||
event: parseAbiItem('event WalletUpdated(uint256 indexed wallet_blinder_share)'), | ||
args: { | ||
@@ -45,0 +48,0 @@ wallet_blinder_share: blinderShare, |
@@ -1,7 +0,6 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js"; | ||
import { getWalletId } from "./getWalletId.js"; | ||
import { waitForTaskCompletion } from "./waitForTaskCompletion.js"; | ||
import { postRelayerWithAuth } from "../utils/http.js"; | ||
import { PAY_FEES_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js'; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { waitForTaskCompletion } from './waitForTaskCompletion.js'; | ||
import { postRelayerWithAuth } from '../utils/http.js'; | ||
import { PAY_FEES_ROUTE } from '../constants.js'; | ||
export async function payFees(config, parameters = {}) { | ||
@@ -8,0 +7,0 @@ const { getRelayerBaseUrl } = config; |
@@ -1,4 +0,3 @@ | ||
import { getRelayerWithAuth } from "../utils/http.js"; | ||
import { GET_WALLET_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { getRelayerWithAuth } from '../utils/http.js'; | ||
import { GET_WALLET_ROUTE } from '../constants.js'; | ||
export async function reconnect(config, parameters) { | ||
@@ -9,3 +8,3 @@ const { getRelayerBaseUrl } = config; | ||
// Persisted state is malformed | ||
config.setState({ status: "disconnected" }); | ||
config.setState({ status: 'disconnected' }); | ||
return; | ||
@@ -15,14 +14,18 @@ } | ||
await getRelayerWithAuth(config, getRelayerBaseUrl(GET_WALLET_ROUTE(id))) | ||
.then(res => { | ||
.then((res) => { | ||
if (res.wallet) { | ||
config.setState({ ...config.state, status: "in relayer" }); | ||
config.setState({ ...config.state, status: 'in relayer' }); | ||
} | ||
return res.wallet; | ||
}) | ||
.catch(err => { | ||
console.error("Error reconnecting: ", err); | ||
.catch((err) => { | ||
console.error('Error reconnecting: ', err); | ||
// Should lookup wallet in connect | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }); | ||
config.setState({ | ||
status: 'disconnected', | ||
id: undefined, | ||
seed: undefined, | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=reconnect.js.map |
@@ -1,2 +0,2 @@ | ||
import { getSkRoot } from "./getSkRoot.js"; | ||
import { getSkRoot } from './getSkRoot.js'; | ||
export const signMessage = (config, parameters) => { | ||
@@ -3,0 +3,0 @@ const { message } = parameters; |
@@ -1,7 +0,6 @@ | ||
import { getTaskStatus } from "./getTaskStatus.js"; | ||
import axios from "axios"; | ||
import {} from "../createConfig.js"; | ||
import axios from 'axios'; | ||
import { getTaskStatus } from './getTaskStatus.js'; | ||
export async function waitForTaskCompletion(config, parameters, onStateChange) { | ||
const { pollingInterval } = config; | ||
let lastState = ""; | ||
let lastState = ''; | ||
while (true) { | ||
@@ -26,5 +25,5 @@ try { | ||
// Sleep for a bit before polling again | ||
await new Promise(resolve => setTimeout(resolve, pollingInterval)); | ||
await new Promise((resolve) => setTimeout(resolve, pollingInterval)); | ||
} | ||
} | ||
//# sourceMappingURL=waitForTaskCompletion.js.map |
@@ -1,6 +0,5 @@ | ||
import {} from "../createConfig.js"; | ||
export function watchStatus(config, parameters) { | ||
const { onChange } = parameters; | ||
return config.subscribe(state => state.status, onChange); | ||
return config.subscribe((state) => state.status, onChange); | ||
} | ||
//# sourceMappingURL=watchStatus.js.map |
@@ -1,9 +0,8 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js"; | ||
import { getWalletId } from "./getWalletId.js"; | ||
import JSONBigInt from "json-bigint"; | ||
import { toHex } from "viem"; | ||
import { postRelayerWithAuth } from "../utils/http.js"; | ||
import { WITHDRAW_BALANCE_ROUTE } from "../constants.js"; | ||
import {} from "../createConfig.js"; | ||
import { Token } from "../types/token.js"; | ||
import JSONBigInt from 'json-bigint'; | ||
import { toHex } from 'viem'; | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js'; | ||
import { getWalletId } from './getWalletId.js'; | ||
import { postRelayerWithAuth } from '../utils/http.js'; | ||
import { WITHDRAW_BALANCE_ROUTE } from '../constants.js'; | ||
import { Token } from '../types/token.js'; | ||
export async function withdraw(config, parameters) { | ||
@@ -10,0 +9,0 @@ const { mint, amount, destinationAddr } = parameters; |
/// Header name for the HTTP auth signature | ||
export const RENEGADE_AUTH_HEADER_NAME = "renegade-auth"; | ||
export const RENEGADE_AUTH_HEADER_NAME = 'renegade-auth'; | ||
/// Header name for the expiration timestamp of a signature | ||
export const RENEGADE_SIG_EXPIRATION_HEADER_NAME = "renegade-auth-expiration"; | ||
export const RENEGADE_SIG_EXPIRATION_HEADER_NAME = 'renegade-auth-expiration'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
@@ -9,5 +9,5 @@ // Wallet | ||
// Create a new wallet | ||
export const CREATE_WALLET_ROUTE = "/wallet"; | ||
export const CREATE_WALLET_ROUTE = '/wallet'; | ||
// Find a wallet in contract storage | ||
export const FIND_WALLET_ROUTE = "/wallet/lookup"; | ||
export const FIND_WALLET_ROUTE = '/wallet/lookup'; | ||
// Returns the wallet information for the given id | ||
@@ -42,3 +42,3 @@ export const GET_WALLET_ROUTE = (wallet_id) => `/wallet/${wallet_id}`; | ||
// Returns the full network topology known to the local node | ||
export const GET_NETWORK_TOPOLOGY_ROUTE = "/network"; | ||
export const GET_NETWORK_TOPOLOGY_ROUTE = '/network'; | ||
// Returns the cluster information for the specified cluster | ||
@@ -52,3 +52,3 @@ export const GET_CLUSTER_INFO_ROUTE = (cluster_id) => `/network/clusters/${cluster_id}`; | ||
// Returns all known network orders | ||
export const GET_NETWORK_ORDERS_ROUTE = "/order_book/orders"; | ||
export const GET_NETWORK_ORDERS_ROUTE = '/order_book/orders'; | ||
// Returns the network order information of the specified order | ||
@@ -60,3 +60,3 @@ export const GET_NETWORK_ORDER_BY_ID_ROUTE = (order_id) => `/order_book/orders/${order_id}`; | ||
// Price report route | ||
export const PRICE_REPORT_ROUTE = "/price_report"; | ||
export const PRICE_REPORT_ROUTE = '/price_report'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
@@ -75,3 +75,3 @@ // Task | ||
// Initiates a handshake with the server | ||
export const HANDSHAKE_ROUTE = "/v0/handshake"; | ||
export const HANDSHAKE_ROUTE = '/v0/handshake'; | ||
// Retrieves wallet information by wallet ID | ||
@@ -82,5 +82,5 @@ export const WALLET_ROUTE = (wallet_id) => `/v0/wallet/${wallet_id}`; | ||
// Streams order book events | ||
export const ORDER_BOOK_ROUTE = "/v0/order_book"; | ||
export const ORDER_BOOK_ROUTE = '/v0/order_book'; | ||
/// The network topic, streams events about network peers | ||
export const NETWORK_INFO_ROUTE = "/v0/network"; | ||
export const NETWORK_INFO_ROUTE = '/v0/network'; | ||
/// The task status topic, streams information about task statuses | ||
@@ -102,113 +102,113 @@ export const TASK_STATUS_ROUTE = (task_id) => `/v0/tasks/${task_id}`; | ||
{ | ||
name: "WBTC", | ||
ticker: "WBTC", | ||
address: "0x11b57fe348584f042e436c6bf7c3c3def171de49", | ||
name: 'WBTC', | ||
ticker: 'WBTC', | ||
address: '0x11b57fe348584f042e436c6bf7c3c3def171de49', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "WETH", | ||
ticker: "WETH", | ||
address: "0xa6e41ffd769491a42a6e5ce453259b93983a22ef", | ||
name: 'WETH', | ||
ticker: 'WETH', | ||
address: '0xa6e41ffd769491a42a6e5ce453259b93983a22ef', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "BNB", | ||
ticker: "BNB", | ||
address: "0xe1080224b632a93951a7cfa33eeea9fd81558b5e", | ||
name: 'BNB', | ||
ticker: 'BNB', | ||
address: '0xe1080224b632a93951a7cfa33eeea9fd81558b5e', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MATIC", | ||
ticker: "MATIC", | ||
address: "0x7e32b54800705876d3b5cfbc7d9c226a211f7c1a", | ||
name: 'MATIC', | ||
ticker: 'MATIC', | ||
address: '0x7e32b54800705876d3b5cfbc7d9c226a211f7c1a', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LDO", | ||
ticker: "LDO", | ||
address: "0x525c2aba45f66987217323e8a05ea400c65d06dc", | ||
name: 'LDO', | ||
ticker: 'LDO', | ||
address: '0x525c2aba45f66987217323e8a05ea400c65d06dc', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDC", | ||
ticker: "USDC", | ||
address: "0x85d9a8a4bd77b9b5559c1b7fcb8ec9635922ed49", | ||
name: 'USDC', | ||
ticker: 'USDC', | ||
address: '0x85d9a8a4bd77b9b5559c1b7fcb8ec9635922ed49', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDT", | ||
ticker: "USDT", | ||
address: "0x4a2ba922052ba54e29c5417bc979daaf7d5fe4f4", | ||
name: 'USDT', | ||
ticker: 'USDT', | ||
address: '0x4a2ba922052ba54e29c5417bc979daaf7d5fe4f4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LINK", | ||
ticker: "LINK", | ||
address: "0x4af567288e68cad4aa93a272fe6139ca53859c70", | ||
name: 'LINK', | ||
ticker: 'LINK', | ||
address: '0x4af567288e68cad4aa93a272fe6139ca53859c70', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "UNI", | ||
ticker: "UNI", | ||
address: "0x3df948c956e14175f43670407d5796b95bb219d8", | ||
name: 'UNI', | ||
ticker: 'UNI', | ||
address: '0x3df948c956e14175f43670407d5796b95bb219d8', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "SUSHI", | ||
ticker: "SUSHI", | ||
address: "0x75e0e92a79880bd81a69f72983d03c75e2b33dc8", | ||
name: 'SUSHI', | ||
ticker: 'SUSHI', | ||
address: '0x75e0e92a79880bd81a69f72983d03c75e2b33dc8', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "1INCH", | ||
ticker: "1INCH", | ||
address: "0xf5ffd11a55afd39377411ab9856474d2a7cb697e", | ||
name: '1INCH', | ||
ticker: '1INCH', | ||
address: '0xf5ffd11a55afd39377411ab9856474d2a7cb697e', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "AAVE", | ||
ticker: "AAVE", | ||
address: "0x408da76e87511429485c32e4ad647dd14823fdc4", | ||
name: 'AAVE', | ||
ticker: 'AAVE', | ||
address: '0x408da76e87511429485c32e4ad647dd14823fdc4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "COMP", | ||
ticker: "COMP", | ||
address: "0xdb2d15a3eb70c347e0d2c2c7861cafb946baab48", | ||
name: 'COMP', | ||
ticker: 'COMP', | ||
address: '0xdb2d15a3eb70c347e0d2c2c7861cafb946baab48', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MKR", | ||
ticker: "MKR", | ||
address: "0xa39ffa43eba037d67a0f4fe91956038aba0ca386", | ||
name: 'MKR', | ||
ticker: 'MKR', | ||
address: '0xa39ffa43eba037d67a0f4fe91956038aba0ca386', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "REN", | ||
ticker: "REN", | ||
address: "0xdb3f4ecb0298238a19ec5afd087c6d9df8041919", | ||
name: 'REN', | ||
ticker: 'REN', | ||
address: '0xdb3f4ecb0298238a19ec5afd087c6d9df8041919', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MANA", | ||
ticker: "MANA", | ||
address: "0x1b9cbdc65a7bebb0be7f18d93a1896ea1fd46d7a", | ||
name: 'MANA', | ||
ticker: 'MANA', | ||
address: '0x1b9cbdc65a7bebb0be7f18d93a1896ea1fd46d7a', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "ENS", | ||
ticker: "ENS", | ||
address: "0x47cec0749bd110bc11f9577a70061202b1b6c034", | ||
name: 'ENS', | ||
ticker: 'ENS', | ||
address: '0x47cec0749bd110bc11f9577a70061202b1b6c034', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "DYDX", | ||
ticker: "DYDX", | ||
address: "0x841118047f42754332d0ad4db8a2893761dd7f5d", | ||
name: 'DYDX', | ||
ticker: 'DYDX', | ||
address: '0x841118047f42754332d0ad4db8a2893761dd7f5d', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "CRV", | ||
ticker: "CRV", | ||
address: "0xc2c0c3398915a2d2e9c33c186abfef3192ee25e8", | ||
name: 'CRV', | ||
ticker: 'CRV', | ||
address: '0xc2c0c3398915a2d2e9c33c186abfef3192ee25e8', | ||
decimals: 18, | ||
@@ -221,113 +221,113 @@ }, | ||
{ | ||
name: "WBTC", | ||
ticker: "WBTC", | ||
address: "0xd542490eba60e4b4d28d23c5b392b1607438f3cc", | ||
name: 'WBTC', | ||
ticker: 'WBTC', | ||
address: '0xd542490eba60e4b4d28d23c5b392b1607438f3cc', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "WETH", | ||
ticker: "WETH", | ||
address: "0x663e903ff15a0e911258cea2116b2071e80fed68", | ||
name: 'WETH', | ||
ticker: 'WETH', | ||
address: '0x663e903ff15a0e911258cea2116b2071e80fed68', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "BNB", | ||
ticker: "BNB", | ||
address: "0xed7ec2d4d4d9a6a702769679fb5a36f55ebf197b", | ||
name: 'BNB', | ||
ticker: 'BNB', | ||
address: '0xed7ec2d4d4d9a6a702769679fb5a36f55ebf197b', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MATIC", | ||
ticker: "MATIC", | ||
address: "0x9268bb5c5f6403ff02a89dcff7ddbb07ff046f99", | ||
name: 'MATIC', | ||
ticker: 'MATIC', | ||
address: '0x9268bb5c5f6403ff02a89dcff7ddbb07ff046f99', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LDO", | ||
ticker: "LDO", | ||
address: "0x22963655fe6ebbfa46400e9f01012e54bae543c4", | ||
name: 'LDO', | ||
ticker: 'LDO', | ||
address: '0x22963655fe6ebbfa46400e9f01012e54bae543c4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDC", | ||
ticker: "USDC", | ||
address: "0xab03a15c0b1bfe992765280247b31a73489aa57b", | ||
name: 'USDC', | ||
ticker: 'USDC', | ||
address: '0xab03a15c0b1bfe992765280247b31a73489aa57b', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDT", | ||
ticker: "USDT", | ||
address: "0xacca32fccaf3220c1a3a31f7a5f879c231320642", | ||
name: 'USDT', | ||
ticker: 'USDT', | ||
address: '0xacca32fccaf3220c1a3a31f7a5f879c231320642', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LINK", | ||
ticker: "LINK", | ||
address: "0x77edb6f64f86a6794d5da3a34aa9fbbe8e61e852", | ||
name: 'LINK', | ||
ticker: 'LINK', | ||
address: '0x77edb6f64f86a6794d5da3a34aa9fbbe8e61e852', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "UNI", | ||
ticker: "UNI", | ||
address: "0xe78b46ae59984d11a215b6f84c7de4cb111ef63c", | ||
name: 'UNI', | ||
ticker: 'UNI', | ||
address: '0xe78b46ae59984d11a215b6f84c7de4cb111ef63c', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "SUSHI", | ||
ticker: "SUSHI", | ||
address: "0x93fe5ec17f31112dcd25770fbd07270159b67451", | ||
name: 'SUSHI', | ||
ticker: 'SUSHI', | ||
address: '0x93fe5ec17f31112dcd25770fbd07270159b67451', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "1INCH", | ||
ticker: "1INCH", | ||
address: "0xc6464a3072270a3da814bb0ec2907df935ff839d", | ||
name: '1INCH', | ||
ticker: '1INCH', | ||
address: '0xc6464a3072270a3da814bb0ec2907df935ff839d', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "AAVE", | ||
ticker: "AAVE", | ||
address: "0x104f5cc5d1593f1ba2a0eecf5882be85e231aca9", | ||
name: 'AAVE', | ||
ticker: 'AAVE', | ||
address: '0x104f5cc5d1593f1ba2a0eecf5882be85e231aca9', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "COMP", | ||
ticker: "COMP", | ||
address: "0xac3b14cb55c2242bb8ca1dc8269701948cb0c348", | ||
name: 'COMP', | ||
ticker: 'COMP', | ||
address: '0xac3b14cb55c2242bb8ca1dc8269701948cb0c348', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MKR", | ||
ticker: "MKR", | ||
address: "0x15f7fe757a582634e1ed105ea68f07f6cf240b37", | ||
name: 'MKR', | ||
ticker: 'MKR', | ||
address: '0x15f7fe757a582634e1ed105ea68f07f6cf240b37', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "REN", | ||
ticker: "REN", | ||
address: "0xe7e96cef8812d2d24add2de592b5c786f915f64b", | ||
name: 'REN', | ||
ticker: 'REN', | ||
address: '0xe7e96cef8812d2d24add2de592b5c786f915f64b', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MANA", | ||
ticker: "MANA", | ||
address: "0xb66ff14a830d5527f06e384b309288b843d555c4", | ||
name: 'MANA', | ||
ticker: 'MANA', | ||
address: '0xb66ff14a830d5527f06e384b309288b843d555c4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "ENS", | ||
ticker: "ENS", | ||
address: "0xf5c43ef3d79caf5680584d9087f95d81e75e2ddf", | ||
name: 'ENS', | ||
ticker: 'ENS', | ||
address: '0xf5c43ef3d79caf5680584d9087f95d81e75e2ddf', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "DYDX", | ||
ticker: "DYDX", | ||
address: "0xe85035f1145ac49333d105632a0d254e479a75be", | ||
name: 'DYDX', | ||
ticker: 'DYDX', | ||
address: '0xe85035f1145ac49333d105632a0d254e479a75be', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "CRV", | ||
ticker: "CRV", | ||
address: "0x47b8399a8a3ad9665e4257904f99eafe043c4f50", | ||
name: 'CRV', | ||
ticker: 'CRV', | ||
address: '0x47b8399a8a3ad9665e4257904f99eafe043c4f50', | ||
decimals: 18, | ||
@@ -337,4 +337,6 @@ }, | ||
}; | ||
const isDevelopment = process.env.NEXT_PUBLIC_RPC_URL?.includes("dev"); | ||
export const tokenMapping = isDevelopment ? devnetTokenMapping : testnetTokenMapping; | ||
const isDevelopment = process.env.NEXT_PUBLIC_RPC_URL?.includes('dev'); | ||
export const tokenMapping = isDevelopment | ||
? devnetTokenMapping | ||
: testnetTokenMapping; | ||
//# sourceMappingURL=constants.js.map |
@@ -1,13 +0,13 @@ | ||
import { createStorage, noopStorage } from "./createStorage.js"; | ||
import invariant from "tiny-invariant"; | ||
import { createPublicClient, defineChain, http, } from "viem"; | ||
import { persist, subscribeWithSelector } from "zustand/middleware"; | ||
import { createStore } from "zustand/vanilla"; | ||
import invariant from 'tiny-invariant'; | ||
import { http, createPublicClient, defineChain, } from 'viem'; | ||
import { persist, subscribeWithSelector } from 'zustand/middleware'; | ||
import { createStore } from 'zustand/vanilla'; | ||
import { createStorage, noopStorage } from './createStorage.js'; | ||
export function createConfig(parameters) { | ||
const { relayerUrl, priceReporterUrl, httpPort = 3000, pollingInterval = 5000, ssr, storage = createStorage({ | ||
storage: typeof window !== "undefined" && window.localStorage | ||
storage: typeof window !== 'undefined' && window.localStorage | ||
? window.localStorage | ||
: noopStorage, | ||
}), websocketPort = 4000, } = parameters; | ||
invariant(parameters.utils, "Utils must be provided by the package if not supplied by the user."); | ||
invariant(parameters.utils, 'Utils must be provided by the package if not supplied by the user.'); | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
@@ -19,3 +19,3 @@ // Create store | ||
seed: undefined, | ||
status: "disconnected", | ||
status: 'disconnected', | ||
id: undefined, | ||
@@ -28,3 +28,3 @@ }; | ||
? persist(getInitialState, { | ||
name: "store", | ||
name: 'store', | ||
partialize(state) { | ||
@@ -45,11 +45,13 @@ // Only persist "critical" store properties to preserve storage size. | ||
`https://${parameters.rpcUrl}` ?? | ||
`https://${relayerUrl.includes("dev") ? "dev." : ""}sequencer.renegade.fi`; | ||
`https://${relayerUrl.includes('dev') ? 'dev.' : ''}sequencer.renegade.fi`; | ||
return defineChain({ | ||
id: 473474, | ||
name: "Renegade Testnet", | ||
network: "Renegade Testnet", | ||
name: 'Renegade Testnet', | ||
network: 'Renegade Testnet', | ||
testnet: true, | ||
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" }, | ||
nativeCurrency: { decimals: 18, name: 'Ether', symbol: 'ETH' }, | ||
rpcUrls: { default: { http: [rpcUrl] }, public: { http: [rpcUrl] } }, | ||
blockExplorers: { default: { name: "Explorer", url: "https://explorer.renegade.fi" } }, | ||
blockExplorers: { | ||
default: { name: 'Explorer', url: 'https://explorer.renegade.fi' }, | ||
}, | ||
}); | ||
@@ -63,11 +65,11 @@ }; | ||
getRenegadeChain, | ||
getRelayerBaseUrl: function (route = "") { | ||
const baseUrl = parameters.relayerUrl.includes("localhost") | ||
getRelayerBaseUrl: (route = '') => { | ||
const baseUrl = parameters.relayerUrl.includes('localhost') | ||
? `http://127.0.0.1:${httpPort}/v0` | ||
: `https://${parameters.relayerUrl}:${httpPort}/v0`; | ||
const formattedRoute = route.startsWith("/") ? route : `/${route}`; | ||
const formattedRoute = route.startsWith('/') ? route : `/${route}`; | ||
return `${baseUrl}${formattedRoute}`; | ||
}, | ||
getPriceReporterBaseUrl: function () { | ||
const baseUrl = parameters.priceReporterUrl.includes("localhost") | ||
getPriceReporterBaseUrl: () => { | ||
const baseUrl = parameters.priceReporterUrl.includes('localhost') | ||
? `ws://127.0.0.1:${websocketPort}/` | ||
@@ -77,4 +79,4 @@ : `wss://${parameters.priceReporterUrl}:${websocketPort}/`; | ||
}, | ||
getWebsocketBaseUrl: function () { | ||
const baseUrl = parameters.relayerUrl.includes("localhost") | ||
getWebsocketBaseUrl: () => { | ||
const baseUrl = parameters.relayerUrl.includes('localhost') | ||
? `ws://127.0.0.1:${websocketPort}` | ||
@@ -94,3 +96,5 @@ : `wss://${parameters.relayerUrl}:${websocketPort}`; | ||
subscribe(selector, listener, options) { | ||
return store.subscribe(selector, listener, options ? { ...options, fireImmediately: options.emitImmediately } : undefined); | ||
return store.subscribe(selector, listener, options | ||
? { ...options, fireImmediately: options.emitImmediately } | ||
: undefined); | ||
}, | ||
@@ -97,0 +101,0 @@ _internal: { |
@@ -1,10 +0,10 @@ | ||
import {} from "./createConfig.js"; | ||
import {} from "./types/utils.js"; | ||
import { deserialize as deserialize_ } from "./utils/deserialize.js"; | ||
import { serialize as serialize_ } from "./utils/serialize.js"; | ||
import {} from './createConfig.js'; | ||
import {} from './types/utils.js'; | ||
import { deserialize as deserialize_ } from './utils/deserialize.js'; | ||
import { serialize as serialize_ } from './utils/serialize.js'; | ||
export function createStorage(parameters) { | ||
const { deserialize = deserialize_, key: prefix = "renegade", serialize = serialize_, storage = noopStorage, } = parameters; | ||
const { deserialize = deserialize_, key: prefix = 'renegade', serialize = serialize_, storage = noopStorage, } = parameters; | ||
function unwrap(value) { | ||
if (value instanceof Promise) | ||
return value.then(x => x).catch(() => null); | ||
return value.then((x) => x).catch(() => null); | ||
return value; | ||
@@ -11,0 +11,0 @@ } |
@@ -7,6 +7,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
var _BaseError_instances, _BaseError_walk; | ||
import { getVersion } from "../utils/getVersion.js"; | ||
import { getVersion } from '../utils/getVersion.js'; | ||
export class BaseError extends Error { | ||
get docsBaseUrl() { | ||
return "todo: put a docs link here"; | ||
return 'todo: put a docs link here'; | ||
} | ||
@@ -47,3 +47,3 @@ get version() { | ||
writable: true, | ||
value: "RenegadeCoreError" | ||
value: 'RenegadeCoreError' | ||
}); | ||
@@ -59,8 +59,8 @@ const details = options.cause instanceof BaseError | ||
this.message = [ | ||
shortMessage || "An error occurred.", | ||
"", | ||
...(options.metaMessages ? [...options.metaMessages, ""] : []), | ||
shortMessage || 'An error occurred.', | ||
'', | ||
...(options.metaMessages ? [...options.metaMessages, ''] : []), | ||
...(docsPath | ||
? [ | ||
`Docs: ${this.docsBaseUrl}${docsPath}.html${options.docsSlug ? `#${options.docsSlug}` : ""}`, | ||
`Docs: ${this.docsBaseUrl}${docsPath}.html${options.docsSlug ? `#${options.docsSlug}` : ''}`, | ||
] | ||
@@ -70,3 +70,3 @@ : []), | ||
`Version: ${this.version}`, | ||
].join("\n"); | ||
].join('\n'); | ||
if (options.cause) | ||
@@ -73,0 +73,0 @@ this.cause = options.cause; |
@@ -1,2 +0,2 @@ | ||
import { reconnect } from "./actions/reconnect.js"; | ||
import { reconnect } from './actions/reconnect.js'; | ||
export function hydrate(config, parameters) { | ||
@@ -8,3 +8,3 @@ const { initialState, reconnectOnMount } = parameters; | ||
...initialState, | ||
status: reconnectOnMount ? "looking up" : "disconnected", | ||
status: reconnectOnMount ? 'looking up' : 'disconnected', | ||
seed: reconnectOnMount ? config.state.seed : undefined, | ||
@@ -15,7 +15,7 @@ }); | ||
if (config._internal.ssr) { | ||
console.log("💧 SSR enabled, rehydrating state"); | ||
console.log('💧 SSR enabled, rehydrating state'); | ||
await config._internal.store.persist.rehydrate(); | ||
} | ||
if (reconnectOnMount) { | ||
console.log("🚝 Reconnecting on mount"); | ||
console.log('🚝 Reconnecting on mount'); | ||
reconnect(config, { id: config.state.id }); | ||
@@ -22,0 +22,0 @@ } |
//////////////////////////////////////////////////////////////////////////////// | ||
// createConfig | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { createConfig, } from "./createConfig.js"; | ||
export { createConfig, } from './createConfig.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Actions | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { cancelOrder, } from "./actions/cancelOrder.js"; | ||
export { connect } from "./actions/connect.js"; | ||
export { createOrder, } from "./actions/createOrder.js"; | ||
export { createWallet, } from "./actions/createWallet.js"; | ||
export { deposit } from "./actions/deposit.js"; | ||
export { disconnect, } from "./actions/disconnect.js"; | ||
export { getAuthorizationHeaders, } from "./actions/getAuthHeaders.js"; | ||
export { getBalances, } from "./actions/getBalances.js"; | ||
export { getOrder } from "./actions/getOrder.js"; | ||
export { getOrderHistory, } from "./actions/getOrderHistory.js"; | ||
export { getNetworkOrders, } from "./actions/getNetworkOrders.js"; | ||
export { getOrders, } from "./actions/getOrders.js"; | ||
export { getPkRoot, getPkRootScalars, } from "./actions/getPkRoot.js"; | ||
export { getSkRoot, } from "./actions/getSkRoot.js"; | ||
export { getTaskHistory, } from "./actions/getTaskHistory.js"; | ||
export { getTaskStatus, } from "./actions/getTaskStatus.js"; | ||
export { getTaskQueue, } from "./actions/getTaskQueue.js"; | ||
export { getWalletFromRelayer, } from "./actions/getWalletFromRelayer.js"; | ||
export { getWalletId, } from "./actions/getWalletId.js"; | ||
export { lookupWallet, } from "./actions/lookupWallet.js"; | ||
export { payFees } from "./actions/payFees.js"; | ||
export { signMessage, } from "./actions/signMessage.js"; | ||
export { waitForTaskCompletion, } from "./actions/waitForTaskCompletion.js"; | ||
export { watchStatus, } from "./actions/watchStatus.js"; | ||
export { withdraw } from "./actions/withdraw.js"; | ||
export { cancelOrder, } from './actions/cancelOrder.js'; | ||
export { connect, } from './actions/connect.js'; | ||
export { createOrder, } from './actions/createOrder.js'; | ||
export { createWallet, } from './actions/createWallet.js'; | ||
export { deposit, } from './actions/deposit.js'; | ||
export { disconnect, } from './actions/disconnect.js'; | ||
export { getAuthorizationHeaders, } from './actions/getAuthHeaders.js'; | ||
export { getBalances, } from './actions/getBalances.js'; | ||
export { getOrder, } from './actions/getOrder.js'; | ||
export { getOrderHistory, } from './actions/getOrderHistory.js'; | ||
export { getNetworkOrders, } from './actions/getNetworkOrders.js'; | ||
export { getOrders, } from './actions/getOrders.js'; | ||
export { getPkRoot, getPkRootScalars, } from './actions/getPkRoot.js'; | ||
export { getSkRoot, } from './actions/getSkRoot.js'; | ||
export { getTaskHistory, } from './actions/getTaskHistory.js'; | ||
export { getTaskStatus, } from './actions/getTaskStatus.js'; | ||
export { getTaskQueue, } from './actions/getTaskQueue.js'; | ||
export { getWalletFromRelayer, } from './actions/getWalletFromRelayer.js'; | ||
export { getWalletId, } from './actions/getWalletId.js'; | ||
export { lookupWallet, } from './actions/lookupWallet.js'; | ||
export { payFees } from './actions/payFees.js'; | ||
export { signMessage, } from './actions/signMessage.js'; | ||
export { waitForTaskCompletion, } from './actions/waitForTaskCompletion.js'; | ||
export { watchStatus, } from './actions/watchStatus.js'; | ||
export { withdraw, } from './actions/withdraw.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Hydrate | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { hydrate } from "./hydrate.js"; | ||
export { hydrate } from './hydrate.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Errors | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { BaseError } from "./errors/base.js"; | ||
export { BaseError } from './errors/base.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Constants | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export * from "./constants.js"; | ||
export * from './constants.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Types | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { Token } from "./types/token.js"; | ||
export * from "./types/wallet.js"; | ||
export { UpdateType, TaskType } from "./types/task.js"; | ||
export { Token } from './types/token.js'; | ||
export * from './types/wallet.js'; | ||
export { UpdateType, TaskType } from './types/task.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Utils | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { formatAmount, parseAmount } from "./utils/format.js"; | ||
export { deepEqual } from "./utils/deepEqual.js"; | ||
export { WebSocketManager } from "./utils/websocket.js"; | ||
export { formatAmount, parseAmount } from './utils/format.js'; | ||
export { deepEqual } from './utils/deepEqual.js'; | ||
export { WebSocketManager } from './utils/websocket.js'; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Viem | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { chain } from "./utils/chain.js"; | ||
export { chain } from './utils/chain.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Config } from '../createConfig.js'; | ||
export type CancelOrderParameters = { | ||
@@ -3,0 +3,0 @@ id: string; |
@@ -1,3 +0,3 @@ | ||
import type { Hex } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type ConnectParameters = { | ||
@@ -4,0 +4,0 @@ seed?: Hex; |
@@ -1,3 +0,3 @@ | ||
import { type Address } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import { type Address } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type CreateOrderParameters = { | ||
@@ -7,3 +7,3 @@ id?: string; | ||
quote: Address; | ||
side: "buy" | "sell"; | ||
side: 'buy' | 'sell'; | ||
amount: bigint; | ||
@@ -10,0 +10,0 @@ }; |
@@ -1,3 +0,2 @@ | ||
import { type Config } from "../createConfig.js"; | ||
export type CreateWalletParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
export type CreateWalletReturnType = Promise<{ | ||
@@ -7,3 +6,3 @@ taskId: string; | ||
}>; | ||
export declare function createWallet(config: Config, parameters?: CreateWalletParameters): CreateWalletReturnType; | ||
export declare function createWallet(config: Config): CreateWalletReturnType; | ||
//# sourceMappingURL=createWallet.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { type Address } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import { type Address } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type DepositParameters = { | ||
@@ -4,0 +4,0 @@ fromAddr: Address; |
@@ -1,5 +0,4 @@ | ||
import { type Config } from "../createConfig.js"; | ||
export type DisconnectParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
export type DisconnectReturnType = Promise<void>; | ||
export declare function disconnect(config: Config, parameters?: DisconnectParameters): DisconnectReturnType; | ||
export declare function disconnect(config: Config): DisconnectReturnType; | ||
//# sourceMappingURL=disconnect.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { Config } from "../createConfig.js"; | ||
import type { Config } from '../createConfig.js'; | ||
export type GetAuthorizationHeadersParameters = { | ||
@@ -3,0 +3,0 @@ message: string; |
@@ -1,9 +0,9 @@ | ||
import type { Hex } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import type { Wallet } from "../types/wallet.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Wallet } from '../types/wallet.js'; | ||
export type GetBackOfQueueWalletParameters = { | ||
seed?: Hex; | ||
}; | ||
export type GetBackOfQueueWalletReturnType = Promise<Wallet | void>; | ||
export type GetBackOfQueueWalletReturnType = Promise<Wallet | undefined>; | ||
export declare function getBackOfQueueWallet(config: Config, parameters?: GetBackOfQueueWalletParameters): GetBackOfQueueWalletReturnType; | ||
//# sourceMappingURL=getBackOfQueueWallet.d.ts.map |
@@ -1,6 +0,5 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Balance } from "../types/wallet.js"; | ||
export type GetBalancesParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Balance } from '../types/wallet.js'; | ||
export type GetBalancesReturnType = Promise<Balance[]>; | ||
export declare function getBalances(config: Config, parameters?: GetBalancesParameters): GetBalancesReturnType; | ||
export declare function getBalances(config: Config): GetBalancesReturnType; | ||
//# sourceMappingURL=getBalances.d.ts.map |
@@ -1,6 +0,5 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { NetworkOrder } from "../types/wallet.js"; | ||
export type GetNetworkOrdersParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
import type { NetworkOrder } from '../types/wallet.js'; | ||
export type GetNetworkOrdersReturnType = Promise<NetworkOrder[]>; | ||
export declare function getNetworkOrders(config: Config, parameters?: GetNetworkOrdersParameters): GetNetworkOrdersReturnType; | ||
export declare function getNetworkOrders(config: Config): GetNetworkOrdersReturnType; | ||
//# sourceMappingURL=getNetworkOrders.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Order } from "../types/wallet.js"; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Order } from '../types/wallet.js'; | ||
export type GetOrderParameters = { | ||
@@ -4,0 +4,0 @@ id: string; |
@@ -1,6 +0,5 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { OrderMetadata } from "../types/wallet.js"; | ||
export type GetOrderHistoryParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
import type { OrderMetadata } from '../types/wallet.js'; | ||
export type GetOrderHistoryReturnType = Promise<OrderMetadata[]>; | ||
export declare function getOrderHistory(config: Config, parameters?: GetOrderHistoryParameters): GetOrderHistoryReturnType; | ||
export declare function getOrderHistory(config: Config): GetOrderHistoryReturnType; | ||
//# sourceMappingURL=getOrderHistory.d.ts.map |
@@ -1,6 +0,5 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Order } from "../types/wallet.js"; | ||
export type GetOrdersParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Order } from '../types/wallet.js'; | ||
export type GetOrdersReturnType = Promise<Order[]>; | ||
export declare function getOrders(config: Config, parameters?: GetOrdersParameters): GetOrdersReturnType; | ||
export declare function getOrders(config: Config): GetOrdersReturnType; | ||
//# sourceMappingURL=getOrders.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { type Hex } from "viem"; | ||
import type { Config } from "../createConfig.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type GetPkRootReturnType = Hex; | ||
@@ -4,0 +4,0 @@ export type GetPkRootScalarsReturnType = bigint[]; |
@@ -1,3 +0,3 @@ | ||
import { type Hex } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type GetSkRootParameters = { | ||
@@ -4,0 +4,0 @@ seed?: Hex; |
@@ -1,6 +0,5 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import { type Task as TaskHistoryItem } from "../types/task.js"; | ||
export type GetTaskHistoryParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Task as TaskHistoryItem } from '../types/task.js'; | ||
export type GetTaskHistoryReturnType = Promise<TaskHistoryItem[]>; | ||
export declare function getTaskHistory(config: Config, parameters?: GetTaskHistoryParameters): GetTaskHistoryReturnType; | ||
export declare function getTaskHistory(config: Config): GetTaskHistoryReturnType; | ||
//# sourceMappingURL=getTaskHistory.d.ts.map |
@@ -1,6 +0,5 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { OldTask as Task } from "../types/wallet.js"; | ||
export type GetTaskQueueParameters = {}; | ||
import type { Config } from '../createConfig.js'; | ||
import type { OldTask as Task } from '../types/wallet.js'; | ||
export type GetTaskQueueReturnType = Promise<Task[]>; | ||
export declare function getTaskQueue(config: Config, parameters?: GetTaskQueueParameters): GetTaskQueueReturnType; | ||
export declare function getTaskQueue(config: Config): GetTaskQueueReturnType; | ||
//# sourceMappingURL=getTaskQueue.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { OldTask as Task } from "../types/wallet.js"; | ||
import type { Config } from '../createConfig.js'; | ||
import type { OldTask as Task } from '../types/wallet.js'; | ||
export type GetTaskStatusParameters = { | ||
@@ -4,0 +4,0 @@ id: string; |
@@ -1,9 +0,9 @@ | ||
import type { Hex } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import type { Wallet } from "../types/wallet.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
import type { Wallet } from '../types/wallet.js'; | ||
export type GetWalletFromRelayerParameters = { | ||
seed?: Hex; | ||
}; | ||
export type GetWalletFromRelayerReturnType = Promise<Wallet | void>; | ||
export type GetWalletFromRelayerReturnType = Promise<Wallet | undefined>; | ||
export declare function getWalletFromRelayer(config: Config, parameters?: GetWalletFromRelayerParameters): GetWalletFromRelayerReturnType; | ||
//# sourceMappingURL=getWalletFromRelayer.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import type { Hex } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type GetWalletIdParameters = { | ||
@@ -4,0 +4,0 @@ seed?: Hex; |
@@ -1,3 +0,3 @@ | ||
import { type Hex } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import { type Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type LookupWalletParameters = { | ||
@@ -4,0 +4,0 @@ seed?: Hex; |
@@ -1,2 +0,2 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Config } from '../createConfig.js'; | ||
export type PayFeesParameters = { | ||
@@ -3,0 +3,0 @@ waitForCompletion?: boolean; |
@@ -1,2 +0,2 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Config } from '../createConfig.js'; | ||
export type ReconnectParameters = { | ||
@@ -3,0 +3,0 @@ id?: string; |
@@ -1,3 +0,3 @@ | ||
import type { Hex } from "viem"; | ||
import type { Config } from "../createConfig.js"; | ||
import type { Hex } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type SignMessageParameters = { | ||
@@ -4,0 +4,0 @@ message: string; |
@@ -1,3 +0,3 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { OldTask as Task } from "../types/wallet.js"; | ||
import type { Config } from '../createConfig.js'; | ||
import type { OldTask as Task } from '../types/wallet.js'; | ||
export type WaitForTaskCompletionParameters = { | ||
@@ -4,0 +4,0 @@ id: string; |
@@ -1,4 +0,4 @@ | ||
import { type Config } from "../createConfig.js"; | ||
import type { Config } from '../createConfig.js'; | ||
export type WatchStatusParameters = { | ||
onChange(status: Config["state"]["status"], prevStatus: Config["state"]["status"]): void; | ||
onChange(status: Config['state']['status'], prevStatus: Config['state']['status']): void; | ||
}; | ||
@@ -5,0 +5,0 @@ export type WatchStatusReturnType = () => void; |
@@ -1,3 +0,3 @@ | ||
import { type Address } from "viem"; | ||
import { type Config } from "../createConfig.js"; | ||
import { type Address } from 'viem'; | ||
import type { Config } from '../createConfig.js'; | ||
export type WithdrawParameters = { | ||
@@ -4,0 +4,0 @@ mint: Address; |
@@ -1,2 +0,2 @@ | ||
import type { Address } from "viem"; | ||
import type { Address } from 'viem'; | ||
export declare const RENEGADE_AUTH_HEADER_NAME = "renegade-auth"; | ||
@@ -3,0 +3,0 @@ export declare const RENEGADE_SIG_EXPIRATION_HEADER_NAME = "renegade-auth-expiration"; |
@@ -1,6 +0,6 @@ | ||
import { type Storage } from "./createStorage.js"; | ||
import type { Evaluate, ExactPartial } from "./types/utils.js"; | ||
import type * as rustUtils from "./utils.d.ts"; | ||
import { type Address, type Chain, type Hex, type PublicClient } from "viem"; | ||
import { type Mutate, type StoreApi } from "zustand/vanilla"; | ||
import { type Address, type Chain, type Hex, type PublicClient } from 'viem'; | ||
import { type Mutate, type StoreApi } from 'zustand/vanilla'; | ||
import { type Storage } from './createStorage.js'; | ||
import type { Evaluate, ExactPartial } from './types/utils.js'; | ||
import type * as rustUtils from './utils.d.ts'; | ||
export type CreateConfigParameters = { | ||
@@ -42,3 +42,3 @@ darkPoolAddress: Address; | ||
_internal: { | ||
readonly store: Mutate<StoreApi<any>, [["zustand/persist", any]]>; | ||
readonly store: Mutate<StoreApi<any>, [['zustand/persist', any]]>; | ||
readonly ssr: boolean; | ||
@@ -49,6 +49,6 @@ }; | ||
seed?: Hex | undefined; | ||
status?: "in relayer" | "disconnected" | "looking up" | "creating wallet" | "connecting"; | ||
status?: 'in relayer' | 'disconnected' | 'looking up' | 'creating wallet' | 'connecting'; | ||
id?: string | undefined; | ||
} | ||
export type PartializedState = Evaluate<ExactPartial<Pick<State, "id" | "seed" | "status">>>; | ||
export type PartializedState = Evaluate<ExactPartial<Pick<State, 'id' | 'seed' | 'status'>>>; | ||
//# sourceMappingURL=createConfig.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { type PartializedState } from "./createConfig.js"; | ||
import { type Evaluate } from "./types/utils.js"; | ||
import { type PartializedState } from './createConfig.js'; | ||
import { type Evaluate } from './types/utils.js'; | ||
export type StorageItemMap = { | ||
@@ -4,0 +4,0 @@ recentConnectorId: string; |
@@ -1,3 +0,3 @@ | ||
import type { Evaluate, OneOf } from "../types/utils.js"; | ||
export type ErrorType<name extends string = "Error"> = Error & { | ||
import type { Evaluate, OneOf } from '../types/utils.js'; | ||
export type ErrorType<name extends string = 'Error'> = Error & { | ||
name: name; | ||
@@ -15,3 +15,3 @@ }; | ||
export type BaseErrorType = BaseError & { | ||
name: "RenegadeCoreError"; | ||
name: 'RenegadeCoreError'; | ||
}; | ||
@@ -18,0 +18,0 @@ export declare class BaseError extends Error { |
@@ -1,2 +0,2 @@ | ||
import type { Config, State } from "./createConfig.js"; | ||
import type { Config, State } from './createConfig.js'; | ||
type HydrateParameters = { | ||
@@ -3,0 +3,0 @@ initialState?: State | undefined; |
@@ -1,38 +0,38 @@ | ||
export { type Config, type CreateConfigParameters, type State, createConfig, } from "./createConfig.js"; | ||
export { type CancelOrderParameters, type CancelOrderReturnType, cancelOrder, } from "./actions/cancelOrder.js"; | ||
export { type ConnectParameters, type ConnectReturnType, connect } from "./actions/connect.js"; | ||
export { type CreateOrderParameters, type CreateOrderReturnType, createOrder, } from "./actions/createOrder.js"; | ||
export { type CreateWalletParameters, type CreateWalletReturnType, createWallet, } from "./actions/createWallet.js"; | ||
export { type DepositParameters, type DepositReturnType, deposit } from "./actions/deposit.js"; | ||
export { type DisconnectParameters, type DisconnectReturnType, disconnect, } from "./actions/disconnect.js"; | ||
export { type GetAuthorizationHeadersParameters, type GetAuthorizationHeadersReturnType, getAuthorizationHeaders, } from "./actions/getAuthHeaders.js"; | ||
export { type GetBalancesParameters, type GetBalancesReturnType, getBalances, } from "./actions/getBalances.js"; | ||
export { type GetOrderParameters, type GetOrderReturnType, getOrder } from "./actions/getOrder.js"; | ||
export { type GetOrderHistoryParameters, type GetOrderHistoryReturnType, getOrderHistory, } from "./actions/getOrderHistory.js"; | ||
export { type GetNetworkOrdersParameters, type GetNetworkOrdersReturnType, getNetworkOrders, } from "./actions/getNetworkOrders.js"; | ||
export { type GetOrdersParameters, type GetOrdersReturnType, getOrders, } from "./actions/getOrders.js"; | ||
export { type GetPkRootReturnType, getPkRoot, type GetPkRootScalarsReturnType, getPkRootScalars, } from "./actions/getPkRoot.js"; | ||
export { type GetSkRootParameters, type GetSkRootReturnType, getSkRoot, } from "./actions/getSkRoot.js"; | ||
export { type GetTaskHistoryParameters, type GetTaskHistoryReturnType, getTaskHistory, } from "./actions/getTaskHistory.js"; | ||
export { type GetTaskStatusParameters, type GetTaskStatusReturnType, getTaskStatus, } from "./actions/getTaskStatus.js"; | ||
export { type GetTaskQueueParameters, type GetTaskQueueReturnType, getTaskQueue, } from "./actions/getTaskQueue.js"; | ||
export { type GetWalletFromRelayerParameters, type GetWalletFromRelayerReturnType, getWalletFromRelayer, } from "./actions/getWalletFromRelayer.js"; | ||
export { type GetWalletIdParameters, type GetWalletIdReturnType, getWalletId, } from "./actions/getWalletId.js"; | ||
export { type LookupWalletParameters, type LookupWalletReturnType, lookupWallet, } from "./actions/lookupWallet.js"; | ||
export { type PayFeesReturnType, payFees } from "./actions/payFees.js"; | ||
export { type SignMessageParameters, type SignMessageReturnType, signMessage, } from "./actions/signMessage.js"; | ||
export { type WaitForTaskCompletionParameters, type WaitForTaskCompletionReturnType, waitForTaskCompletion, } from "./actions/waitForTaskCompletion.js"; | ||
export { type WatchStatusParameters, type WatchStatusReturnType, watchStatus, } from "./actions/watchStatus.js"; | ||
export { type WithdrawParameters, type WithdrawReturnType, withdraw } from "./actions/withdraw.js"; | ||
export { hydrate } from "./hydrate.js"; | ||
export { BaseError } from "./errors/base.js"; | ||
export * from "./constants.js"; | ||
export { Token } from "./types/token.js"; | ||
export * from "./types/wallet.js"; | ||
export type { Task, TaskInfo, TaskState } from "./types/task.js"; | ||
export { UpdateType, TaskType } from "./types/task.js"; | ||
export { formatAmount, parseAmount } from "./utils/format.js"; | ||
export { deepEqual } from "./utils/deepEqual.js"; | ||
export { WebSocketManager } from "./utils/websocket.js"; | ||
export { chain } from "./utils/chain.js"; | ||
export { type Config, type CreateConfigParameters, type State, createConfig, } from './createConfig.js'; | ||
export { type CancelOrderParameters, type CancelOrderReturnType, cancelOrder, } from './actions/cancelOrder.js'; | ||
export { type ConnectParameters, type ConnectReturnType, connect, } from './actions/connect.js'; | ||
export { type CreateOrderParameters, type CreateOrderReturnType, createOrder, } from './actions/createOrder.js'; | ||
export { type CreateWalletReturnType, createWallet, } from './actions/createWallet.js'; | ||
export { type DepositParameters, type DepositReturnType, deposit, } from './actions/deposit.js'; | ||
export { type DisconnectReturnType, disconnect, } from './actions/disconnect.js'; | ||
export { type GetAuthorizationHeadersParameters, type GetAuthorizationHeadersReturnType, getAuthorizationHeaders, } from './actions/getAuthHeaders.js'; | ||
export { type GetBalancesReturnType, getBalances, } from './actions/getBalances.js'; | ||
export { type GetOrderParameters, type GetOrderReturnType, getOrder, } from './actions/getOrder.js'; | ||
export { type GetOrderHistoryReturnType, getOrderHistory, } from './actions/getOrderHistory.js'; | ||
export { type GetNetworkOrdersReturnType, getNetworkOrders, } from './actions/getNetworkOrders.js'; | ||
export { type GetOrdersReturnType, getOrders, } from './actions/getOrders.js'; | ||
export { type GetPkRootReturnType, getPkRoot, type GetPkRootScalarsReturnType, getPkRootScalars, } from './actions/getPkRoot.js'; | ||
export { type GetSkRootParameters, type GetSkRootReturnType, getSkRoot, } from './actions/getSkRoot.js'; | ||
export { type GetTaskHistoryReturnType, getTaskHistory, } from './actions/getTaskHistory.js'; | ||
export { type GetTaskStatusParameters, type GetTaskStatusReturnType, getTaskStatus, } from './actions/getTaskStatus.js'; | ||
export { type GetTaskQueueReturnType, getTaskQueue, } from './actions/getTaskQueue.js'; | ||
export { type GetWalletFromRelayerParameters, type GetWalletFromRelayerReturnType, getWalletFromRelayer, } from './actions/getWalletFromRelayer.js'; | ||
export { type GetWalletIdParameters, type GetWalletIdReturnType, getWalletId, } from './actions/getWalletId.js'; | ||
export { type LookupWalletParameters, type LookupWalletReturnType, lookupWallet, } from './actions/lookupWallet.js'; | ||
export { type PayFeesReturnType, payFees } from './actions/payFees.js'; | ||
export { type SignMessageParameters, type SignMessageReturnType, signMessage, } from './actions/signMessage.js'; | ||
export { type WaitForTaskCompletionParameters, type WaitForTaskCompletionReturnType, waitForTaskCompletion, } from './actions/waitForTaskCompletion.js'; | ||
export { type WatchStatusParameters, type WatchStatusReturnType, watchStatus, } from './actions/watchStatus.js'; | ||
export { type WithdrawParameters, type WithdrawReturnType, withdraw, } from './actions/withdraw.js'; | ||
export { hydrate } from './hydrate.js'; | ||
export { BaseError } from './errors/base.js'; | ||
export * from './constants.js'; | ||
export { Token } from './types/token.js'; | ||
export * from './types/wallet.js'; | ||
export type { Task, TaskInfo, TaskState } from './types/task.js'; | ||
export { UpdateType, TaskType } from './types/task.js'; | ||
export { formatAmount, parseAmount } from './utils/format.js'; | ||
export { deepEqual } from './utils/deepEqual.js'; | ||
export { WebSocketManager } from './utils/websocket.js'; | ||
export { chain } from './utils/chain.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { isHex } from "viem"; | ||
import { tokenMapping } from "../constants.js"; | ||
import { isHex } from 'viem'; | ||
import { tokenMapping } from '../constants.js'; | ||
export class Token { | ||
@@ -47,3 +47,3 @@ constructor(name, ticker, address, decimals) { | ||
static findByTicker(ticker) { | ||
const tokenData = tokenMapping.tokens.find(token => token.ticker === ticker); | ||
const tokenData = tokenMapping.tokens.find((token) => token.ticker === ticker); | ||
if (tokenData) { | ||
@@ -55,3 +55,3 @@ return new Token(tokenData.name, tokenData.ticker, tokenData.address, tokenData.decimals); | ||
static findByAddress(address) { | ||
const tokenData = tokenMapping.tokens.find(token => token.address === address); | ||
const tokenData = tokenMapping.tokens.find((token) => token.address === address); | ||
if (tokenData) { | ||
@@ -64,3 +64,3 @@ return new Token(tokenData.name, tokenData.ticker, tokenData.address, tokenData.decimals); | ||
if (!isHex(address)) { | ||
throw new Error("Invalid address"); | ||
throw new Error('Invalid address'); | ||
} | ||
@@ -67,0 +67,0 @@ return new Token(name, ticker, address, decimals); |
@@ -1,2 +0,2 @@ | ||
import type { Address } from "viem"; | ||
import type { Address } from 'viem'; | ||
export type Task = { | ||
@@ -8,3 +8,3 @@ id: string; | ||
}; | ||
export type TaskState = "Queued" | "Running" | "Proving" | "Proving Payment" | "Submitting Tx" | "Submitting Payment" | "Finding Opening" | "Updating Validity Proofs" | "Completed" | "Failed"; | ||
export type TaskState = 'Queued' | 'Running' | 'Proving' | 'Proving Payment' | 'Submitting Tx' | 'Submitting Payment' | 'Finding Opening' | 'Updating Validity Proofs' | 'Completed' | 'Failed'; | ||
export declare enum UpdateType { | ||
@@ -38,3 +38,3 @@ Deposit = "Deposit", | ||
quote: Address; | ||
side: "Buy" | "Sell"; | ||
side: 'Buy' | 'Sell'; | ||
} | { | ||
@@ -46,3 +46,3 @@ update_type: UpdateType.CancelOrder; | ||
quote: Address; | ||
side: "Buy" | "Sell"; | ||
side: 'Buy' | 'Sell'; | ||
} | { | ||
@@ -49,0 +49,0 @@ task_type: TaskType.SettleMatch; |
@@ -1,2 +0,2 @@ | ||
import { type Address } from "viem"; | ||
import { type Address } from 'viem'; | ||
export declare class Token { | ||
@@ -3,0 +3,0 @@ private _name; |
@@ -1,3 +0,3 @@ | ||
import type { Address, Hex } from "viem"; | ||
export type Exchange = "binance" | "coinbase" | "kraken" | "okx"; | ||
import type { Address, Hex } from 'viem'; | ||
export type Exchange = 'binance' | 'coinbase' | 'kraken' | 'okx'; | ||
export type NetworkOrder = { | ||
@@ -29,4 +29,4 @@ id: string; | ||
base_mint: Address; | ||
side: "Buy" | "Sell"; | ||
type: "Midpoint"; | ||
side: 'Buy' | 'Sell'; | ||
type: 'Midpoint'; | ||
worst_case_price: string; | ||
@@ -33,0 +33,0 @@ amount: bigint; |
@@ -1,4 +0,4 @@ | ||
import type { Token } from "../types/token.js"; | ||
import type { Token } from '../types/token.js'; | ||
export declare function formatAmount(amount: bigint, token: Token): string; | ||
export declare function parseAmount(amount: string, token: Token): bigint; | ||
//# sourceMappingURL=format.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { Config } from "../createConfig.js"; | ||
import type { Config } from '../createConfig.js'; | ||
export declare function postRelayerRaw(url: string, body: any, headers?: {}): Promise<any>; | ||
@@ -3,0 +3,0 @@ export declare function getRelayerRaw(url: string, headers?: {}): Promise<any>; |
@@ -1,18 +0,18 @@ | ||
import { defineChain } from "viem"; | ||
import { defineChain } from 'viem'; | ||
export const devnetChain = defineChain({ | ||
id: 473474, | ||
name: "Renegade Devnet", | ||
network: "Renegade Devnet", | ||
name: 'Renegade Devnet', | ||
network: 'Renegade Devnet', | ||
testnet: true, | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Ether", | ||
symbol: "ETH", | ||
name: 'Ether', | ||
symbol: 'ETH', | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: [`https://dev.sequencer.renegade.fi`], | ||
http: ['https://dev.sequencer.renegade.fi'], | ||
}, | ||
public: { | ||
http: [`https://dev.sequencer.renegade.fi`], | ||
http: ['https://dev.sequencer.renegade.fi'], | ||
}, | ||
@@ -22,4 +22,4 @@ }, | ||
default: { | ||
name: "Explorer", | ||
url: "https://explorer.renegade.fi/", | ||
name: 'Explorer', | ||
url: 'https://explorer.renegade.fi/', | ||
}, | ||
@@ -30,16 +30,16 @@ }, | ||
id: 473474, | ||
name: "Renegade Testnet", | ||
network: "Renegade Testnet", | ||
name: 'Renegade Testnet', | ||
network: 'Renegade Testnet', | ||
testnet: true, | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Ether", | ||
symbol: "ETH", | ||
name: 'Ether', | ||
symbol: 'ETH', | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: [`https://sequencer.renegade.fi`], | ||
http: ['https://sequencer.renegade.fi'], | ||
}, | ||
public: { | ||
http: [`https://sequencer.renegade.fi`], | ||
http: ['https://sequencer.renegade.fi'], | ||
}, | ||
@@ -49,8 +49,10 @@ }, | ||
default: { | ||
name: "Explorer", | ||
url: "https://explorer.renegade.fi/", | ||
name: 'Explorer', | ||
url: 'https://explorer.renegade.fi/', | ||
}, | ||
}, | ||
}); | ||
export const chain = process.env.NEXT_PUBLIC_RPC_URL?.includes("dev") ? devnetChain : testnetChain; | ||
export const chain = process.env.NEXT_PUBLIC_RPC_URL?.includes('dev') | ||
? devnetChain | ||
: testnetChain; | ||
//# sourceMappingURL=chain.js.map |
@@ -5,3 +5,3 @@ /** Forked from https://github.com/epoberezkin/fast-deep-equal */ | ||
return true; | ||
if (a && b && typeof a === "object" && typeof b === "object") { | ||
if (a && b && typeof a === 'object' && typeof b === 'object') { | ||
if (a.constructor !== b.constructor) | ||
@@ -8,0 +8,0 @@ return false; |
export function deserialize(value, reviver) { | ||
return JSON.parse(value, (key, value_) => { | ||
let value = value_; | ||
if (value?.__type === "bigint") | ||
if (value?.__type === 'bigint') | ||
value = BigInt(value.value); | ||
if (value?.__type === "Map") | ||
if (value?.__type === 'Map') | ||
value = new Map(value.value); | ||
@@ -8,0 +8,0 @@ return reviver?.(key, value) ?? value; |
@@ -1,2 +0,2 @@ | ||
import { formatUnits, parseUnits } from "viem"; | ||
import { formatUnits, parseUnits } from 'viem'; | ||
export function formatAmount(amount, token) { | ||
@@ -7,4 +7,4 @@ const decimals = token.decimals; | ||
let formatted = formatUnits(amount, decimals); | ||
if (formatted.includes(".")) { | ||
const [integerPart, decimalPart = ""] = formatted.split("."); | ||
if (formatted.includes('.')) { | ||
const [integerPart, decimalPart = ''] = formatted.split('.'); | ||
formatted = `${integerPart}.${decimalPart.substring(0, 2)}`; | ||
@@ -11,0 +11,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { version } from "../version.js"; | ||
import { version } from '../version.js'; | ||
export const getVersion = () => `@renegade-fi/core@${version}`; | ||
//# sourceMappingURL=getVersion.js.map |
@@ -1,5 +0,5 @@ | ||
import axios from "axios"; | ||
import JSONBigint from "json-bigint"; | ||
import { getSkRoot } from "../index.js"; | ||
import { RENEGADE_AUTH_HEADER_NAME, RENEGADE_SIG_EXPIRATION_HEADER_NAME } from "../constants.js"; | ||
import axios from 'axios'; | ||
import JSONBigint from 'json-bigint'; | ||
import { getSkRoot } from '../index.js'; | ||
import { RENEGADE_AUTH_HEADER_NAME, RENEGADE_SIG_EXPIRATION_HEADER_NAME, } from '../constants.js'; | ||
export async function postRelayerRaw(url, body, headers = {}) { | ||
@@ -17,11 +17,11 @@ try { | ||
// that falls out of the range of 2xx | ||
console.error("Response error:", error.response.data); | ||
console.error('Response error:', error.response.data); | ||
} | ||
else if (error.request) { | ||
// The request was made but no response was received | ||
console.error("Request error: No response received"); | ||
console.error('Request error: No response received'); | ||
} | ||
else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.error("Error:", error.message); | ||
console.error('Error:', error.message); | ||
} | ||
@@ -31,3 +31,3 @@ } | ||
// Non-Axios error | ||
console.error("Error:", error); | ||
console.error('Error:', error); | ||
} | ||
@@ -41,7 +41,7 @@ throw error; // Rethrow the error for further handling or logging | ||
headers, | ||
transformResponse: data => { | ||
transformResponse: (data) => { | ||
try { | ||
return JSONBigint({ useNativeBigInt: true }).parse(data); | ||
} | ||
catch (error) { | ||
catch (_error) { | ||
return data; | ||
@@ -60,11 +60,11 @@ } | ||
// that falls out of the range of 2xx | ||
console.error("Response error:", error.response.data); | ||
console.error('Response error:', error.response.data); | ||
} | ||
else if (error.request) { | ||
// The request was made but no response was received | ||
console.error("Request error: No response received"); | ||
console.error('Request error: No response received'); | ||
} | ||
else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.error("Error:", error.message); | ||
console.error('Error:', error.message); | ||
} | ||
@@ -74,3 +74,3 @@ } | ||
// Non-Axios error | ||
console.error("Error:", error); | ||
console.error('Error:', error); | ||
} | ||
@@ -82,7 +82,7 @@ throw error; // Rethrow the error for further handling or logging | ||
const skRoot = await getSkRoot(config); | ||
const [auth, expiration] = config.utils.build_auth_headers(skRoot, body ?? "", BigInt(Date.now())); | ||
const [auth, expiration] = config.utils.build_auth_headers(skRoot, body ?? '', BigInt(Date.now())); | ||
const headers = { | ||
[RENEGADE_AUTH_HEADER_NAME]: auth, | ||
[RENEGADE_SIG_EXPIRATION_HEADER_NAME]: expiration, | ||
"Content-Type": "application/json", | ||
'Content-Type': 'application/json', | ||
}; | ||
@@ -93,7 +93,7 @@ return await postRelayerRaw(url, body, headers); | ||
const skRoot = await getSkRoot(config); | ||
const [auth, expiration] = config.utils.build_auth_headers(skRoot, "", BigInt(Date.now())); | ||
const [auth, expiration] = config.utils.build_auth_headers(skRoot, '', BigInt(Date.now())); | ||
const headers = { | ||
[RENEGADE_AUTH_HEADER_NAME]: auth, | ||
[RENEGADE_SIG_EXPIRATION_HEADER_NAME]: expiration, | ||
"Content-Type": "application/json", | ||
'Content-Type': 'application/json', | ||
}; | ||
@@ -100,0 +100,0 @@ return await getRelayerRaw(url, headers); |
@@ -9,3 +9,3 @@ /** | ||
function getReferenceKey(keys, cutoff) { | ||
return keys.slice(0, cutoff).join(".") || "."; | ||
return keys.slice(0, cutoff).join('.') || '.'; | ||
} | ||
@@ -36,8 +36,8 @@ /** | ||
function createReplacer(replacer, circularReplacer) { | ||
const hasReplacer = typeof replacer === "function"; | ||
const hasCircularReplacer = typeof circularReplacer === "function"; | ||
const hasReplacer = typeof replacer === 'function'; | ||
const hasCircularReplacer = typeof circularReplacer === 'function'; | ||
const cache = []; | ||
const keys = []; | ||
return function replace(key, value) { | ||
if (typeof value === "object") { | ||
if (typeof value === 'object') { | ||
if (cache.length) { | ||
@@ -82,6 +82,6 @@ const thisCutoff = getCutoff(cache, this); | ||
let value = value_; | ||
if (typeof value === "bigint") | ||
value = { __type: "bigint", value: value_.toString() }; | ||
if (typeof value === 'bigint') | ||
value = { __type: 'bigint', value: value_.toString() }; | ||
if (value instanceof Map) | ||
value = { __type: "Map", value: Array.from(value_.entries()) }; | ||
value = { __type: 'Map', value: Array.from(value_.entries()) }; | ||
return replacer?.(key, value) ?? value; | ||
@@ -88,0 +88,0 @@ }, circularReplacer), indent ?? undefined); |
@@ -52,4 +52,4 @@ export class WebSocketManager { | ||
this.isConnected = false; | ||
if (typeof window !== "undefined") { | ||
window.addEventListener("focus", this.handleWindowFocus.bind(this)); | ||
if (typeof window !== 'undefined') { | ||
window.addEventListener('focus', this.handleWindowFocus.bind(this)); | ||
} | ||
@@ -59,8 +59,8 @@ } | ||
if (this.isConnected || this.ws) { | ||
console.warn("WebSocket connection attempt aborted: already connected."); | ||
console.warn('WebSocket connection attempt aborted: already connected.'); | ||
return; | ||
} | ||
this.ws = new WebSocket(this.url); | ||
this.ws.addEventListener("open", () => { | ||
console.log("[Price Reporter] WebSocket connected."); | ||
this.ws.addEventListener('open', () => { | ||
console.log('[Price Reporter] WebSocket connected.'); | ||
this.isConnected = true; | ||
@@ -70,3 +70,3 @@ this.retryCount = 0; | ||
}); | ||
this.ws.addEventListener("message", event => { | ||
this.ws.addEventListener('message', (event) => { | ||
try { | ||
@@ -82,10 +82,10 @@ const data = JSON.parse(event.data); | ||
catch (error) { | ||
console.error("Error parsing WebSocket message:", error); | ||
console.error('Error parsing WebSocket message:', error); | ||
} | ||
}); | ||
this.ws.addEventListener("error", error => { | ||
console.error("WebSocket error:", error); | ||
this.ws.addEventListener('error', (error) => { | ||
console.error('WebSocket error:', error); | ||
}); | ||
this.ws.addEventListener("close", () => { | ||
console.log("[Price Reporter] WebSocket closed. Attempting to reconnect..."); | ||
this.ws.addEventListener('close', () => { | ||
console.log('[Price Reporter] WebSocket closed. Attempting to reconnect...'); | ||
this.isConnected = false; | ||
@@ -98,6 +98,6 @@ this.ws = null; | ||
if (this.retryCount >= this.maxRetries) { | ||
console.error("[Price Reporter] Maximum reconnect attempts reached."); | ||
console.error('[Price Reporter] Maximum reconnect attempts reached.'); | ||
return; | ||
} | ||
const backoffDelay = this.retryDelay * Math.pow(2, this.retryCount); | ||
const backoffDelay = this.retryDelay * 2 ** this.retryCount; | ||
const jitter = Math.random() * backoffDelay * 0.3; // Jitter up to 30% of the backoff delay | ||
@@ -113,3 +113,3 @@ const delayWithJitter = backoffDelay + jitter; | ||
if (!this.isConnected) { | ||
console.log("[Price Reporter] Window refocused. Attempting to reconnect..."); | ||
console.log('[Price Reporter] Window refocused. Attempting to reconnect...'); | ||
this.retryCount = 0; | ||
@@ -123,3 +123,3 @@ this.reconnect(); | ||
if (this.isConnected && this.ws) { | ||
this.ws.send(JSON.stringify({ method: "subscribe", topic })); | ||
this.ws.send(JSON.stringify({ method: 'subscribe', topic })); | ||
} | ||
@@ -131,3 +131,3 @@ } | ||
if (this.isConnected && this.ws) { | ||
this.ws.send(JSON.stringify({ method: "subscribe", topic })); | ||
this.ws.send(JSON.stringify({ method: 'subscribe', topic })); | ||
} | ||
@@ -134,0 +134,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
export const version = "0.0.1"; | ||
export const version = '0.0.1'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@renegade-fi/core", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "VanillaJS library for Renegade", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -1,12 +0,12 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js" | ||
import { getWalletId } from "./getWalletId.js" | ||
import JSONBigInt from "json-bigint" | ||
import JSONBigInt from 'json-bigint' | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js' | ||
import { getWalletId } from './getWalletId.js' | ||
import { postRelayerWithAuth } from "../utils/http.js" | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
import { CANCEL_ORDER_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { CANCEL_ORDER_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
export type CancelOrderParameters = { | ||
id: string | ||
id: string | ||
} | ||
@@ -17,34 +17,34 @@ | ||
export async function cancelOrder( | ||
config: Config, | ||
parameters: CancelOrderParameters, | ||
config: Config, | ||
parameters: CancelOrderParameters, | ||
): CancelOrderReturnType { | ||
const { id } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const { id } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const body = utils.cancel_order(JSONBigInt.stringify(wallet), id) | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const body = utils.cancel_order(JSONBigInt.stringify(wallet), id) | ||
const logContext = { | ||
walletId, | ||
orderId: id, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
const logContext = { | ||
walletId, | ||
orderId: id, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(CANCEL_ORDER_ROUTE(walletId, id)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} canceling order ${id} failed`, { | ||
error, | ||
...logContext, | ||
}) | ||
throw error | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(CANCEL_ORDER_ROUTE(walletId, id)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} canceling order ${id} failed`, { | ||
error, | ||
...logContext, | ||
}) | ||
throw error | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
import { createWallet } from "./createWallet.js" | ||
import { getWalletFromRelayer } from "./getWalletFromRelayer.js" | ||
import { getWalletId } from "./getWalletId.js" | ||
import { lookupWallet, lookupWalletOnChain } from "./lookupWallet.js" | ||
import type { Hex } from "viem" | ||
import type { Hex } from 'viem' | ||
import { createWallet } from './createWallet.js' | ||
import { getWalletFromRelayer } from './getWalletFromRelayer.js' | ||
import { getWalletId } from './getWalletId.js' | ||
import { lookupWallet, lookupWalletOnChain } from './lookupWallet.js' | ||
import { type Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
@@ -14,75 +14,79 @@ export type ConnectParameters = { seed?: Hex } | ||
export async function connect( | ||
config: Config, | ||
parameters: ConnectParameters = {}, | ||
config: Config, | ||
parameters: ConnectParameters = {}, | ||
): ConnectReturnType { | ||
const { seed } = parameters | ||
let walletId = config.state.id | ||
try { | ||
walletId = getWalletId(config, { seed }) | ||
} catch (error: any) { | ||
console.error("Error getting wallet id", { | ||
errorStack: error.stack, | ||
errorMessage: error.message, | ||
walletId, | ||
seed, | ||
}) | ||
throw error | ||
} | ||
const { seed } = parameters | ||
let walletId = config.state.id | ||
try { | ||
walletId = getWalletId(config, { seed }) | ||
} catch (error: any) { | ||
console.error('Error getting wallet id', { | ||
errorStack: error.stack, | ||
errorMessage: error.message, | ||
walletId, | ||
seed, | ||
}) | ||
throw error | ||
} | ||
console.log("Attempting to connect wallet", { walletId }) | ||
console.log('Attempting to connect wallet', { walletId }) | ||
try { | ||
const wallet = await getWalletFromRelayer(config, { seed }) | ||
if (wallet) { | ||
config.setState({ ...config.state, status: "in relayer", id: wallet.id }) | ||
console.log("Wallet found in relayer", { | ||
status: "in relayer", | ||
walletId: wallet.id, | ||
}) | ||
return | ||
} | ||
} catch (error) { | ||
console.error("Error getting wallet from relayer", { error, walletId }) | ||
try { | ||
const wallet = await getWalletFromRelayer(config, { seed }) | ||
if (wallet) { | ||
config.setState({ ...config.state, status: 'in relayer', id: wallet.id }) | ||
console.log('Wallet found in relayer', { | ||
status: 'in relayer', | ||
walletId: wallet.id, | ||
}) | ||
return | ||
} | ||
} catch (error) { | ||
console.error('Error getting wallet from relayer', { error, walletId }) | ||
} | ||
// If wallet on chain, start lookup wallet task | ||
const isOnChain = await lookupWalletOnChain(config) | ||
if (isOnChain) { | ||
try { | ||
const res = await lookupWallet(config, { seed }) | ||
walletId = res.walletId | ||
console.log(`task lookup-wallet(${res.taskId}): ${res.walletId}`, { | ||
status: "looking up", | ||
walletId: res.walletId, | ||
}) | ||
return { taskId: res.taskId } | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} looking up failed`, { | ||
error, | ||
status: "looking up", | ||
walletId, | ||
}) | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }) | ||
throw error | ||
} | ||
} | ||
// If wallet not in relayer or on chain, call createWallet | ||
// If wallet on chain, start lookup wallet task | ||
const isOnChain = await lookupWalletOnChain(config) | ||
if (isOnChain) { | ||
try { | ||
const res = await createWallet(config) | ||
walletId = res.walletId | ||
console.log(`task create-wallet(${res.taskId}): ${res.walletId}`, { | ||
status: "creating wallet", | ||
walletId: res.walletId, | ||
}) | ||
return { taskId: res.taskId } | ||
const res = await lookupWallet(config, { seed }) | ||
walletId = res.walletId | ||
console.log(`task lookup-wallet(${res.taskId}): ${res.walletId}`, { | ||
status: 'looking up', | ||
walletId: res.walletId, | ||
}) | ||
return { taskId: res.taskId } | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} creating wallet failed`, { | ||
error, | ||
status: "creating wallet", | ||
walletId, | ||
}) | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }) | ||
throw error | ||
console.error(`wallet id: ${walletId} looking up failed`, { | ||
error, | ||
status: 'looking up', | ||
walletId, | ||
}) | ||
config.setState({ | ||
status: 'disconnected', | ||
id: undefined, | ||
seed: undefined, | ||
}) | ||
throw error | ||
} | ||
} | ||
// If wallet not in relayer or on chain, call createWallet | ||
try { | ||
const res = await createWallet(config) | ||
walletId = res.walletId | ||
console.log(`task create-wallet(${res.taskId}): ${res.walletId}`, { | ||
status: 'creating wallet', | ||
walletId: res.walletId, | ||
}) | ||
return { taskId: res.taskId } | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} creating wallet failed`, { | ||
error, | ||
status: 'creating wallet', | ||
walletId, | ||
}) | ||
config.setState({ status: 'disconnected', id: undefined, seed: undefined }) | ||
throw error | ||
} | ||
} |
@@ -1,18 +0,18 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js" | ||
import { getWalletId } from "./getWalletId.js" | ||
import JSONBigInt from "json-bigint" | ||
import { type Address, toHex } from "viem" | ||
import JSONBigInt from 'json-bigint' | ||
import { type Address, toHex } from 'viem' | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js' | ||
import { getWalletId } from './getWalletId.js' | ||
import { postRelayerWithAuth } from "../utils/http.js" | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
import { WALLET_ORDERS_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { Token } from "../types/token.js" | ||
import { WALLET_ORDERS_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import { Token } from '../types/token.js' | ||
export type CreateOrderParameters = { | ||
id?: string | ||
base: Address | ||
quote: Address | ||
side: "buy" | "sell" | ||
amount: bigint | ||
id?: string | ||
base: Address | ||
quote: Address | ||
side: 'buy' | 'sell' | ||
amount: bigint | ||
} | ||
@@ -23,40 +23,49 @@ | ||
export async function createOrder( | ||
config: Config, | ||
parameters: CreateOrderParameters, | ||
config: Config, | ||
parameters: CreateOrderParameters, | ||
): CreateOrderReturnType { | ||
const { id = "", base, quote, side, amount } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const { id = '', base, quote, side, amount } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const body = utils.new_order(JSONBigInt.stringify(wallet), id, base, quote, side, toHex(amount)) | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const body = utils.new_order( | ||
JSONBigInt.stringify(wallet), | ||
id, | ||
base, | ||
quote, | ||
side, | ||
toHex(amount), | ||
) | ||
const logContext = { | ||
walletId, | ||
base, | ||
quote, | ||
side, | ||
amount, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
const logContext = { | ||
walletId, | ||
base, | ||
quote, | ||
side, | ||
amount, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error( | ||
`wallet id: ${walletId} creating order to ${side} ${amount} ${Token.findByAddress(base).ticker} failed`, | ||
{ | ||
error, | ||
...logContext, | ||
}, | ||
) | ||
throw error | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error( | ||
`wallet id: ${walletId} creating order to ${side} ${amount} ${ | ||
Token.findByAddress(base).ticker | ||
} failed`, | ||
{ | ||
error, | ||
...logContext, | ||
}, | ||
) | ||
throw error | ||
} | ||
} |
@@ -1,33 +0,38 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { waitForTaskCompletion } from "./waitForTaskCompletion.js" | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { waitForTaskCompletion } from './waitForTaskCompletion.js' | ||
import { postRelayerRaw } from "../utils/http.js" | ||
import { postRelayerRaw } from '../utils/http.js' | ||
import { CREATE_WALLET_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { CREATE_WALLET_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
export type CreateWalletParameters = {} | ||
export type CreateWalletReturnType = Promise<{ | ||
taskId: string | ||
walletId: string | ||
}> | ||
export type CreateWalletReturnType = Promise<{ taskId: string; walletId: string }> | ||
export async function createWallet(config: Config): CreateWalletReturnType { | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const body = utils.create_wallet(skRoot) | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
} | ||
export async function createWallet( | ||
config: Config, | ||
parameters: CreateWalletParameters = {}, | ||
): CreateWalletReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const body = utils.create_wallet(skRoot) | ||
const headers = { | ||
"Content-Type": "application/json", | ||
} | ||
const res = await postRelayerRaw(getRelayerBaseUrl(CREATE_WALLET_ROUTE), body, headers) | ||
if (res.task_id) { | ||
config.setState({ ...config.state, status: "creating wallet" }) | ||
waitForTaskCompletion(config, { id: res.task_id }).then(() => { | ||
config.setState({ ...config.state, status: "in relayer" }) | ||
}) | ||
} | ||
return { walletId: res.wallet_id, taskId: res.task_id } | ||
const res = await postRelayerRaw( | ||
getRelayerBaseUrl(CREATE_WALLET_ROUTE), | ||
body, | ||
headers, | ||
) | ||
if (res.task_id) { | ||
config.setState({ ...config.state, status: 'creating wallet' }) | ||
waitForTaskCompletion(config, { id: res.task_id }).then(() => { | ||
config.setState({ | ||
...config.state, | ||
id: res.wallet_id, | ||
status: 'in relayer', | ||
}) | ||
}) | ||
} | ||
return { walletId: res.wallet_id, taskId: res.task_id } | ||
} |
@@ -1,20 +0,20 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js" | ||
import { getWalletId } from "./getWalletId.js" | ||
import JSONBigInt from "json-bigint" | ||
import invariant from "tiny-invariant" | ||
import { type Address, toHex } from "viem" | ||
import JSONBigInt from 'json-bigint' | ||
import invariant from 'tiny-invariant' | ||
import { type Address, toHex } from 'viem' | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js' | ||
import { getWalletId } from './getWalletId.js' | ||
import { postRelayerWithAuth } from "../utils/http.js" | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
import { DEPOSIT_BALANCE_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { Token } from "../types/token.js" | ||
import { DEPOSIT_BALANCE_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import { Token } from '../types/token.js' | ||
export type DepositParameters = { | ||
fromAddr: Address | ||
mint: Address | ||
amount: bigint | ||
permitNonce: bigint | ||
permitDeadline: bigint | ||
permit: `0x${string}` | ||
fromAddr: Address | ||
mint: Address | ||
amount: bigint | ||
permitNonce: bigint | ||
permitDeadline: bigint | ||
permit: `0x${string}` | ||
} | ||
@@ -24,50 +24,56 @@ | ||
export async function deposit(config: Config, parameters: DepositParameters): DepositReturnType { | ||
const { fromAddr, mint, amount, permitNonce, permitDeadline, permit } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
export async function deposit( | ||
config: Config, | ||
parameters: DepositParameters, | ||
): DepositReturnType { | ||
const { fromAddr, mint, amount, permitNonce, permitDeadline, permit } = | ||
parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const token = Token.findByAddress(mint) | ||
invariant(token, "Token not found") | ||
const token = Token.findByAddress(mint) | ||
invariant(token, 'Token not found') | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const body = utils.deposit( | ||
JSONBigInt.stringify(wallet), | ||
fromAddr, | ||
mint, | ||
toHex(amount), | ||
toHex(permitNonce), | ||
toHex(permitDeadline), | ||
permit, | ||
) | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const body = utils.deposit( | ||
JSONBigInt.stringify(wallet), | ||
fromAddr, | ||
mint, | ||
toHex(amount), | ||
toHex(permitNonce), | ||
toHex(permitDeadline), | ||
permit, | ||
) | ||
const logContext = { | ||
walletId, | ||
mint, | ||
amount, | ||
permitNonce, | ||
permitDeadline, | ||
permit, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
const logContext = { | ||
walletId, | ||
mint, | ||
amount, | ||
permitNonce, | ||
permitDeadline, | ||
permit, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error( | ||
`wallet id: ${walletId} depositing ${amount} ${Token.findByAddress(mint).ticker} failed`, | ||
{ | ||
error, | ||
...logContext, | ||
}, | ||
) | ||
throw error | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error( | ||
`wallet id: ${walletId} depositing ${amount} ${ | ||
Token.findByAddress(mint).ticker | ||
} failed`, | ||
{ | ||
error, | ||
...logContext, | ||
}, | ||
) | ||
throw error | ||
} | ||
} |
@@ -1,14 +0,7 @@ | ||
import { type Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
export type DisconnectParameters = {} | ||
export type DisconnectReturnType = Promise<void> | ||
export async function disconnect( | ||
config: Config, | ||
parameters: DisconnectParameters = {}, | ||
): DisconnectReturnType { | ||
const {} = config | ||
const {} = parameters | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }) | ||
export async function disconnect(config: Config): DisconnectReturnType { | ||
config.setState({ status: 'disconnected', id: undefined, seed: undefined }) | ||
} |
@@ -1,21 +0,21 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { getSkRoot } from './getSkRoot.js' | ||
import type { Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
export type GetAuthorizationHeadersParameters = { | ||
message: string | ||
message: string | ||
} | ||
export type GetAuthorizationHeadersReturnType = [string, string] | ||
export const getAuthorizationHeaders = ( | ||
config: Config, | ||
parameters: GetAuthorizationHeadersParameters, | ||
config: Config, | ||
parameters: GetAuthorizationHeadersParameters, | ||
): GetAuthorizationHeadersReturnType => { | ||
const { message } = parameters | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
return utils.build_auth_headers( | ||
skRoot, | ||
message, | ||
BigInt(Date.now()), | ||
) as GetAuthorizationHeadersReturnType | ||
const { message } = parameters | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
return utils.build_auth_headers( | ||
skRoot, | ||
message, | ||
BigInt(Date.now()), | ||
) as GetAuthorizationHeadersReturnType | ||
} |
@@ -1,27 +0,27 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import type { Hex } from "viem" | ||
import type { Hex } from 'viem' | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { BACK_OF_QUEUE_WALLET_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { Wallet } from "../types/wallet.js" | ||
import { BACK_OF_QUEUE_WALLET_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { Wallet } from '../types/wallet.js' | ||
export type GetBackOfQueueWalletParameters = { seed?: Hex } | ||
export type GetBackOfQueueWalletReturnType = Promise<Wallet | void> | ||
export type GetBackOfQueueWalletReturnType = Promise<Wallet | undefined> | ||
export async function getBackOfQueueWallet( | ||
config: Config, | ||
parameters: GetBackOfQueueWalletParameters = {}, | ||
config: Config, | ||
parameters: GetBackOfQueueWalletParameters = {}, | ||
): GetBackOfQueueWalletReturnType { | ||
const { seed } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config, { seed }) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(BACK_OF_QUEUE_WALLET_ROUTE(walletId)), | ||
) | ||
return res.wallet | ||
const { seed } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config, { seed }) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(BACK_OF_QUEUE_WALLET_ROUTE(walletId)), | ||
) | ||
return res.wallet | ||
} |
@@ -1,23 +0,20 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { GET_BALANCES_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { Balance } from "../types/wallet.js" | ||
import { GET_BALANCES_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { Balance } from '../types/wallet.js' | ||
export type GetBalancesParameters = {} | ||
export type GetBalancesReturnType = Promise<Balance[]> | ||
export async function getBalances( | ||
config: Config, | ||
parameters: GetBalancesParameters = {}, | ||
): GetBalancesReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(GET_BALANCES_ROUTE(walletId))) | ||
return res.balances | ||
export async function getBalances(config: Config): GetBalancesReturnType { | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(GET_BALANCES_ROUTE(walletId)), | ||
) | ||
return res.balances | ||
} |
@@ -1,19 +0,15 @@ | ||
import { getRelayerRaw } from "../utils/http.js" | ||
import { getRelayerRaw } from '../utils/http.js' | ||
import { GET_NETWORK_ORDERS_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { NetworkOrder } from "../types/wallet.js" | ||
import { GET_NETWORK_ORDERS_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { NetworkOrder } from '../types/wallet.js' | ||
export type GetNetworkOrdersParameters = {} | ||
export type GetNetworkOrdersReturnType = Promise<NetworkOrder[]> | ||
export async function getNetworkOrders( | ||
config: Config, | ||
parameters: GetNetworkOrdersParameters = {}, | ||
config: Config, | ||
): GetNetworkOrdersReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl } = config | ||
const res = await getRelayerRaw(getRelayerBaseUrl(GET_NETWORK_ORDERS_ROUTE)) | ||
return res.orders | ||
const { getRelayerBaseUrl } = config | ||
const res = await getRelayerRaw(getRelayerBaseUrl(GET_NETWORK_ORDERS_ROUTE)) | ||
return res.orders | ||
} |
@@ -1,8 +0,8 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { GET_ORDER_BY_ID_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { Order } from "../types/wallet.js" | ||
import { GET_ORDER_BY_ID_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { Order } from '../types/wallet.js' | ||
@@ -13,12 +13,15 @@ export type GetOrderParameters = { id: string } | ||
export async function getOrder(config: Config, parameters: GetOrderParameters): GetOrderReturnType { | ||
const { id } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(GET_ORDER_BY_ID_ROUTE(walletId, id)), | ||
) | ||
return res.order | ||
export async function getOrder( | ||
config: Config, | ||
parameters: GetOrderParameters, | ||
): GetOrderReturnType { | ||
const { id } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(GET_ORDER_BY_ID_ROUTE(walletId, id)), | ||
) | ||
return res.order | ||
} |
@@ -1,23 +0,22 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { ORDER_HISTORY_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { OrderMetadata } from "../types/wallet.js" | ||
import { ORDER_HISTORY_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { OrderMetadata } from '../types/wallet.js' | ||
export type GetOrderHistoryParameters = {} | ||
export type GetOrderHistoryReturnType = Promise<OrderMetadata[]> | ||
export async function getOrderHistory( | ||
config: Config, | ||
parameters: GetOrderHistoryParameters = {}, | ||
config: Config, | ||
): GetOrderHistoryReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(ORDER_HISTORY_ROUTE(walletId))) | ||
return res.orders | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(ORDER_HISTORY_ROUTE(walletId)), | ||
) | ||
return res.orders | ||
} |
@@ -1,23 +0,20 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { WALLET_ORDERS_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { Order } from "../types/wallet.js" | ||
import { WALLET_ORDERS_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { Order } from '../types/wallet.js' | ||
export type GetOrdersParameters = {} | ||
export type GetOrdersReturnType = Promise<Order[]> | ||
export async function getOrders( | ||
config: Config, | ||
parameters: GetOrdersParameters = {}, | ||
): GetOrdersReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId))) | ||
return res.orders | ||
export async function getOrders(config: Config): GetOrdersReturnType { | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId)), | ||
) | ||
return res.orders | ||
} |
@@ -1,5 +0,5 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { type Hex } from "viem" | ||
import type { Hex } from 'viem' | ||
import { getSkRoot } from './getSkRoot.js' | ||
import type { Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
@@ -9,12 +9,12 @@ export type GetPkRootReturnType = Hex | ||
export function getPkRoot(config: Config): GetPkRootReturnType { | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
return `0x${utils.get_pk_root(skRoot)}` | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
return `0x${utils.get_pk_root(skRoot)}` | ||
} | ||
export function getPkRootScalars(config: Config): GetPkRootScalarsReturnType { | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
const scalars = utils.pk_root_scalars(skRoot) | ||
return scalars.map((s: string) => BigInt(s)).slice(0, 4) | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
const scalars = utils.pk_root_scalars(skRoot) | ||
return scalars.map((s: string) => BigInt(s)).slice(0, 4) | ||
} |
@@ -1,8 +0,8 @@ | ||
import invariant from "tiny-invariant" | ||
import { type Hex } from "viem" | ||
import invariant from 'tiny-invariant' | ||
import type { Hex } from 'viem' | ||
import { type Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
export type GetSkRootParameters = { | ||
seed?: Hex | ||
seed?: Hex | ||
} | ||
@@ -13,14 +13,14 @@ | ||
export function getSkRoot( | ||
config: Config, | ||
parameters: GetSkRootParameters = {}, | ||
config: Config, | ||
parameters: GetSkRootParameters = {}, | ||
): GetSkRootReturnType { | ||
const { seed } = parameters | ||
const { utils } = config | ||
if (seed) { | ||
config.setState({ ...config.state, seed }) | ||
return utils.derive_signing_key_from_seed(seed) | ||
} | ||
const storedSeed = config.state.seed | ||
invariant(storedSeed, "Seed must be defined when none exists in memory") | ||
return utils.derive_signing_key_from_seed(storedSeed) | ||
const { seed } = parameters | ||
const { utils } = config | ||
if (seed) { | ||
config.setState({ ...config.state, seed }) | ||
return utils.derive_signing_key_from_seed(seed) | ||
} | ||
const storedSeed = config.state.seed | ||
invariant(storedSeed, 'Seed must be defined when none exists in memory') | ||
return utils.derive_signing_key_from_seed(storedSeed) | ||
} |
@@ -1,22 +0,19 @@ | ||
import { getWalletId } from "./getWalletId.js" | ||
import { getWalletId } from './getWalletId.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { TASK_HISTORY_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { type Task as TaskHistoryItem } from "../types/task.js" | ||
import { TASK_HISTORY_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { Task as TaskHistoryItem } from '../types/task.js' | ||
export type GetTaskHistoryParameters = {} | ||
export type GetTaskHistoryReturnType = Promise<TaskHistoryItem[]> | ||
export async function getTaskHistory( | ||
config: Config, | ||
parameters: GetTaskHistoryParameters = {}, | ||
): GetTaskHistoryReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl } = config | ||
const walletId = getWalletId(config) | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(TASK_HISTORY_ROUTE(walletId))) | ||
return res.tasks | ||
export async function getTaskHistory(config: Config): GetTaskHistoryReturnType { | ||
const { getRelayerBaseUrl } = config | ||
const walletId = getWalletId(config) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(TASK_HISTORY_ROUTE(walletId)), | ||
) | ||
return res.tasks | ||
} |
@@ -1,22 +0,19 @@ | ||
import { getWalletId } from "./getWalletId.js" | ||
import { getWalletId } from './getWalletId.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { GET_TASK_QUEUE_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { OldTask as Task } from "../types/wallet.js" | ||
import { GET_TASK_QUEUE_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { OldTask as Task } from '../types/wallet.js' | ||
export type GetTaskQueueParameters = {} | ||
export type GetTaskQueueReturnType = Promise<Task[]> | ||
export async function getTaskQueue( | ||
config: Config, | ||
parameters: GetTaskQueueParameters = {}, | ||
): GetTaskQueueReturnType { | ||
const {} = parameters | ||
const { getRelayerBaseUrl } = config | ||
const walletId = getWalletId(config) | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(GET_TASK_QUEUE_ROUTE(walletId))) | ||
return res.tasks | ||
export async function getTaskQueue(config: Config): GetTaskQueueReturnType { | ||
const { getRelayerBaseUrl } = config | ||
const walletId = getWalletId(config) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(GET_TASK_QUEUE_ROUTE(walletId)), | ||
) | ||
return res.tasks | ||
} |
@@ -1,6 +0,6 @@ | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { GET_TASK_STATUS_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { OldTask as Task } from "../types/wallet.js" | ||
import { GET_TASK_STATUS_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { OldTask as Task } from '../types/wallet.js' | ||
@@ -12,9 +12,12 @@ export type GetTaskStatusParameters = { id: string } | ||
export async function getTaskStatus( | ||
config: Config, | ||
parameters: GetTaskStatusParameters, | ||
config: Config, | ||
parameters: GetTaskStatusParameters, | ||
): GetTaskStatusReturnType { | ||
const { id } = parameters | ||
const { getRelayerBaseUrl } = config | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(GET_TASK_STATUS_ROUTE(id))) | ||
return res.status | ||
const { id } = parameters | ||
const { getRelayerBaseUrl } = config | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(GET_TASK_STATUS_ROUTE(id)), | ||
) | ||
return res.status | ||
} |
@@ -1,28 +0,35 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import type { Hex } from "viem" | ||
import type { Hex } from 'viem' | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { GET_WALLET_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import type { Wallet } from "../types/wallet.js" | ||
import { GET_WALLET_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { Wallet } from '../types/wallet.js' | ||
export type GetWalletFromRelayerParameters = { seed?: Hex } | ||
export type GetWalletFromRelayerReturnType = Promise<Wallet | void> | ||
export type GetWalletFromRelayerReturnType = Promise<Wallet | undefined> | ||
export async function getWalletFromRelayer( | ||
config: Config, | ||
parameters: GetWalletFromRelayerParameters = {}, | ||
config: Config, | ||
parameters: GetWalletFromRelayerParameters = {}, | ||
): GetWalletFromRelayerReturnType { | ||
const { seed } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config, { seed }) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth(config, getRelayerBaseUrl(GET_WALLET_ROUTE(walletId))) | ||
if (res.wallet) { | ||
config.setState({ ...config.state, status: "in relayer" }) | ||
return res.wallet | ||
} | ||
return | ||
const { seed } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config, { seed }) | ||
const walletId = utils.wallet_id(skRoot) | ||
const res = await getRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(GET_WALLET_ROUTE(walletId)), | ||
) | ||
if (res.wallet) { | ||
config.setState({ | ||
...config.state, | ||
status: 'in relayer', | ||
id: res.wallet.id, | ||
}) | ||
return res.wallet | ||
} | ||
return | ||
} |
@@ -1,5 +0,5 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import type { Hex } from "viem" | ||
import type { Hex } from 'viem' | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { type Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
@@ -11,10 +11,10 @@ export type GetWalletIdParameters = { seed?: Hex } | ||
export function getWalletId( | ||
config: Config, | ||
parameters: GetWalletIdParameters = {}, | ||
config: Config, | ||
parameters: GetWalletIdParameters = {}, | ||
): GetWalletIdReturnType { | ||
const { utils } = config | ||
const { seed } = parameters | ||
const skRoot = getSkRoot(config, { seed }) | ||
const walletId = utils.wallet_id(skRoot) | ||
return walletId | ||
const { utils } = config | ||
const { seed } = parameters | ||
const skRoot = getSkRoot(config, { seed }) | ||
const walletId = utils.wallet_id(skRoot) | ||
return walletId | ||
} |
@@ -1,65 +0,77 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import { getWalletFromRelayer } from "./getWalletFromRelayer.js" | ||
import { waitForTaskCompletion } from "./waitForTaskCompletion.js" | ||
import { type Hex, createPublicClient, http, parseAbiItem } from "viem" | ||
import { http, type Hex, createPublicClient, parseAbiItem } from 'viem' | ||
import { getSkRoot } from './getSkRoot.js' | ||
import { getWalletFromRelayer } from './getWalletFromRelayer.js' | ||
import { waitForTaskCompletion } from './waitForTaskCompletion.js' | ||
import { postRelayerRaw } from "../utils/http.js" | ||
import { postRelayerRaw } from '../utils/http.js' | ||
import { FIND_WALLET_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { FIND_WALLET_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
export type LookupWalletParameters = { seed?: Hex } | ||
export type LookupWalletReturnType = Promise<{ taskId: string; walletId: string }> | ||
export type LookupWalletReturnType = Promise<{ | ||
taskId: string | ||
walletId: string | ||
}> | ||
export async function lookupWallet( | ||
config: Config, | ||
parameters: LookupWalletParameters = {}, | ||
config: Config, | ||
parameters: LookupWalletParameters = {}, | ||
): LookupWalletReturnType { | ||
const { seed } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config, { seed }) | ||
const body = utils.find_wallet(skRoot) | ||
const res = await postRelayerRaw(getRelayerBaseUrl(FIND_WALLET_ROUTE), body) | ||
if (res.task_id) { | ||
config.setState({ ...config.state, status: "looking up" }) | ||
waitForTaskCompletion(config, { id: res.task_id }).then(async () => { | ||
await getWalletFromRelayer(config, { seed }).then(wallet => { | ||
if (wallet) { | ||
config.setState({ ...config.state, status: "in relayer", id: res.wallet_id }) | ||
console.log(`task lookup-wallet(${res.task_id}) completed: ${res.wallet_id}`, { | ||
status: "in relayer", | ||
walletId: res.wallet_id, | ||
}) | ||
} | ||
}) | ||
}) | ||
} | ||
return { taskId: res.task_id, walletId: res.wallet_id } | ||
const { seed } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const skRoot = getSkRoot(config, { seed }) | ||
const body = utils.find_wallet(skRoot) | ||
const res = await postRelayerRaw(getRelayerBaseUrl(FIND_WALLET_ROUTE), body) | ||
if (res.task_id) { | ||
config.setState({ ...config.state, status: 'looking up' }) | ||
waitForTaskCompletion(config, { id: res.task_id }).then(async () => { | ||
await getWalletFromRelayer(config, { seed }).then((wallet) => { | ||
if (wallet) { | ||
config.setState({ | ||
...config.state, | ||
status: 'in relayer', | ||
id: res.wallet_id, | ||
}) | ||
console.log( | ||
`task lookup-wallet(${res.task_id}) completed: ${res.wallet_id}`, | ||
{ | ||
status: 'in relayer', | ||
walletId: res.wallet_id, | ||
}, | ||
) | ||
} | ||
}) | ||
}) | ||
} | ||
return { taskId: res.task_id, walletId: res.wallet_id } | ||
} | ||
export async function lookupWalletOnChain(config: Config) { | ||
try { | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
const blinderShare = utils.derive_blinder_share(skRoot) | ||
try { | ||
const { utils } = config | ||
const skRoot = getSkRoot(config) | ||
const blinderShare = utils.derive_blinder_share(skRoot) | ||
const publicClient = createPublicClient({ | ||
chain: config.getRenegadeChain(), | ||
transport: http(), | ||
}) | ||
const publicClient = createPublicClient({ | ||
chain: config.getRenegadeChain(), | ||
transport: http(), | ||
}) | ||
const logs = await publicClient.getLogs({ | ||
address: config.darkPoolAddress, | ||
event: parseAbiItem("event WalletUpdated(uint256 indexed wallet_blinder_share)"), | ||
args: { | ||
wallet_blinder_share: blinderShare, | ||
}, | ||
fromBlock: 0n, | ||
}) | ||
return logs.length > 0 | ||
} catch (error) { | ||
console.error(`Error looking up wallet on chain: ${error}`) | ||
throw error | ||
} | ||
const logs = await publicClient.getLogs({ | ||
address: config.darkPoolAddress, | ||
event: parseAbiItem( | ||
'event WalletUpdated(uint256 indexed wallet_blinder_share)', | ||
), | ||
args: { | ||
wallet_blinder_share: blinderShare, | ||
}, | ||
fromBlock: 0n, | ||
}) | ||
return logs.length > 0 | ||
} catch (error) { | ||
console.error(`Error looking up wallet on chain: ${error}`) | ||
throw error | ||
} | ||
} |
@@ -1,12 +0,12 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js" | ||
import { getWalletId } from "./getWalletId.js" | ||
import { waitForTaskCompletion } from "./waitForTaskCompletion.js" | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js' | ||
import { getWalletId } from './getWalletId.js' | ||
import { waitForTaskCompletion } from './waitForTaskCompletion.js' | ||
import { postRelayerWithAuth } from "../utils/http.js" | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
import { PAY_FEES_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { PAY_FEES_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
export type PayFeesParameters = { | ||
waitForCompletion?: boolean | ||
waitForCompletion?: boolean | ||
} | ||
@@ -16,35 +16,38 @@ export type PayFeesReturnType = Promise<void> | ||
export async function payFees( | ||
config: Config, | ||
parameters: PayFeesParameters = {}, | ||
config: Config, | ||
parameters: PayFeesParameters = {}, | ||
): PayFeesReturnType { | ||
const { getRelayerBaseUrl } = config | ||
const { waitForCompletion = true } = parameters | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const { getRelayerBaseUrl } = config | ||
const { waitForCompletion = true } = parameters | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const logContext = { | ||
walletId, | ||
wallet, | ||
} | ||
const logContext = { | ||
walletId, | ||
wallet, | ||
} | ||
try { | ||
const res = await postRelayerWithAuth(config, getRelayerBaseUrl(PAY_FEES_ROUTE(walletId))) | ||
if (res?.task_ids) { | ||
const tasks = res.task_ids.map((id: string) => { | ||
console.log(`task pay-fees(${id}): ${walletId}`, logContext) | ||
if (waitForCompletion) { | ||
return waitForTaskCompletion(config, { id }) | ||
} | ||
return Promise.resolve() // Return a resolved promise for cases where no waiting is needed | ||
}) | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(PAY_FEES_ROUTE(walletId)), | ||
) | ||
if (res?.task_ids) { | ||
const tasks = res.task_ids.map((id: string) => { | ||
console.log(`task pay-fees(${id}): ${walletId}`, logContext) | ||
if (waitForCompletion) { | ||
return waitForTaskCompletion(config, { id }) | ||
} | ||
return Promise.resolve() // Return a resolved promise for cases where no waiting is needed | ||
}) | ||
await Promise.all(tasks) | ||
} | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} pay fees failed`, { | ||
error, | ||
...logContext, | ||
}) | ||
throw error | ||
await Promise.all(tasks) | ||
} | ||
} catch (error) { | ||
console.error(`wallet id: ${walletId} pay fees failed`, { | ||
error, | ||
...logContext, | ||
}) | ||
throw error | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
import { getRelayerWithAuth } from "../utils/http.js" | ||
import { getRelayerWithAuth } from '../utils/http.js' | ||
import { GET_WALLET_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { GET_WALLET_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
@@ -11,25 +11,29 @@ export type ReconnectParameters = { id?: string } | ||
export async function reconnect( | ||
config: Config, | ||
parameters: ReconnectParameters, | ||
config: Config, | ||
parameters: ReconnectParameters, | ||
): ReconnectReturnType { | ||
const { getRelayerBaseUrl } = config | ||
const { id } = parameters | ||
if (!id) { | ||
// Persisted state is malformed | ||
config.setState({ status: "disconnected" }) | ||
return | ||
} | ||
// If wallet in relayer, set status to in relayer | ||
await getRelayerWithAuth(config, getRelayerBaseUrl(GET_WALLET_ROUTE(id))) | ||
.then(res => { | ||
if (res.wallet) { | ||
config.setState({ ...config.state, status: "in relayer" }) | ||
} | ||
return res.wallet | ||
}) | ||
.catch(err => { | ||
console.error("Error reconnecting: ", err) | ||
// Should lookup wallet in connect | ||
config.setState({ status: "disconnected", id: undefined, seed: undefined }) | ||
}) | ||
const { getRelayerBaseUrl } = config | ||
const { id } = parameters | ||
if (!id) { | ||
// Persisted state is malformed | ||
config.setState({ status: 'disconnected' }) | ||
return | ||
} | ||
// If wallet in relayer, set status to in relayer | ||
await getRelayerWithAuth(config, getRelayerBaseUrl(GET_WALLET_ROUTE(id))) | ||
.then((res) => { | ||
if (res.wallet) { | ||
config.setState({ ...config.state, status: 'in relayer' }) | ||
} | ||
return res.wallet | ||
}) | ||
.catch((err) => { | ||
console.error('Error reconnecting: ', err) | ||
// Should lookup wallet in connect | ||
config.setState({ | ||
status: 'disconnected', | ||
id: undefined, | ||
seed: undefined, | ||
}) | ||
}) | ||
} |
@@ -1,17 +0,17 @@ | ||
import { getSkRoot } from "./getSkRoot.js" | ||
import type { Hex } from "viem" | ||
import type { Hex } from 'viem' | ||
import { getSkRoot } from './getSkRoot.js' | ||
import type { Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
export type SignMessageParameters = { | ||
message: string | ||
message: string | ||
} | ||
export type SignMessageReturnType = Hex | ||
export const signMessage = ( | ||
config: Config, | ||
parameters: SignMessageParameters, | ||
config: Config, | ||
parameters: SignMessageParameters, | ||
): SignMessageReturnType => { | ||
const { message } = parameters | ||
const { utils } = config | ||
return `0x${utils.sign_message(getSkRoot(config), message)}` | ||
const { message } = parameters | ||
const { utils } = config | ||
return `0x${utils.sign_message(getSkRoot(config), message)}` | ||
} |
@@ -1,6 +0,6 @@ | ||
import { getTaskStatus } from "./getTaskStatus.js" | ||
import axios from "axios" | ||
import axios from 'axios' | ||
import { getTaskStatus } from './getTaskStatus.js' | ||
import { type Config } from "../createConfig.js" | ||
import type { OldTask as Task } from "../types/wallet.js" | ||
import type { Config } from '../createConfig.js' | ||
import type { OldTask as Task } from '../types/wallet.js' | ||
@@ -12,30 +12,30 @@ export type WaitForTaskCompletionParameters = { id: string } | ||
export async function waitForTaskCompletion( | ||
config: Config, | ||
parameters: WaitForTaskCompletionParameters, | ||
onStateChange?: (task: Task) => void, | ||
config: Config, | ||
parameters: WaitForTaskCompletionParameters, | ||
onStateChange?: (task: Task) => void, | ||
): WaitForTaskCompletionReturnType { | ||
const { pollingInterval } = config | ||
let lastState = "" | ||
const { pollingInterval } = config | ||
let lastState = '' | ||
while (true) { | ||
try { | ||
const response = await getTaskStatus(config, { id: parameters.id }) | ||
const taskState = response.state | ||
onStateChange?.(response) | ||
if (taskState !== lastState) { | ||
// console.log(`Task ${response.description} is ${taskState}...`) | ||
lastState = taskState | ||
} | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
if (error.response?.status === 404) { | ||
// Assume a 404 means the task is completed | ||
break | ||
} | ||
} | ||
while (true) { | ||
try { | ||
const response = await getTaskStatus(config, { id: parameters.id }) | ||
const taskState = response.state | ||
onStateChange?.(response) | ||
if (taskState !== lastState) { | ||
// console.log(`Task ${response.description} is ${taskState}...`) | ||
lastState = taskState | ||
} | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
if (error.response?.status === 404) { | ||
// Assume a 404 means the task is completed | ||
break | ||
} | ||
} | ||
} | ||
// Sleep for a bit before polling again | ||
await new Promise(resolve => setTimeout(resolve, pollingInterval)) | ||
} | ||
// Sleep for a bit before polling again | ||
await new Promise((resolve) => setTimeout(resolve, pollingInterval)) | ||
} | ||
} |
@@ -1,5 +0,8 @@ | ||
import { type Config } from "../createConfig.js" | ||
import type { Config } from '../createConfig.js' | ||
export type WatchStatusParameters = { | ||
onChange(status: Config["state"]["status"], prevStatus: Config["state"]["status"]): void | ||
onChange( | ||
status: Config['state']['status'], | ||
prevStatus: Config['state']['status'], | ||
): void | ||
} | ||
@@ -10,8 +13,8 @@ | ||
export function watchStatus( | ||
config: Config, | ||
parameters: WatchStatusParameters, | ||
config: Config, | ||
parameters: WatchStatusParameters, | ||
): WatchStatusReturnType { | ||
const { onChange } = parameters | ||
const { onChange } = parameters | ||
return config.subscribe(state => state.status, onChange) | ||
return config.subscribe((state) => state.status, onChange) | ||
} |
@@ -1,16 +0,16 @@ | ||
import { getBackOfQueueWallet } from "./getBackOfQueueWallet.js" | ||
import { getWalletId } from "./getWalletId.js" | ||
import JSONBigInt from "json-bigint" | ||
import { type Address, toHex } from "viem" | ||
import JSONBigInt from 'json-bigint' | ||
import { type Address, toHex } from 'viem' | ||
import { getBackOfQueueWallet } from './getBackOfQueueWallet.js' | ||
import { getWalletId } from './getWalletId.js' | ||
import { postRelayerWithAuth } from "../utils/http.js" | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
import { WITHDRAW_BALANCE_ROUTE } from "../constants.js" | ||
import { type Config } from "../createConfig.js" | ||
import { Token } from "../types/token.js" | ||
import { WITHDRAW_BALANCE_ROUTE } from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import { Token } from '../types/token.js' | ||
export type WithdrawParameters = { | ||
mint: Address | ||
amount: bigint | ||
destinationAddr: Address | ||
mint: Address | ||
amount: bigint | ||
destinationAddr: Address | ||
} | ||
@@ -20,50 +20,60 @@ | ||
export async function withdraw(config: Config, parameters: WithdrawParameters): WithdrawReturnType { | ||
const { mint, amount, destinationAddr } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
export async function withdraw( | ||
config: Config, | ||
parameters: WithdrawParameters, | ||
): WithdrawReturnType { | ||
const { mint, amount, destinationAddr } = parameters | ||
const { getRelayerBaseUrl, utils } = config | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
const walletId = getWalletId(config) | ||
const wallet = await getBackOfQueueWallet(config) | ||
// Pay Fees | ||
// try { | ||
// if (shouldPayFees) { | ||
// await payFees(config) | ||
// } | ||
// } catch (error) { | ||
// console.error(`Failed to pay fees before withdrawing, cancelling withdraw.`) | ||
// throw error | ||
// } | ||
// Pay Fees | ||
// try { | ||
// if (shouldPayFees) { | ||
// await payFees(config) | ||
// } | ||
// } catch (error) { | ||
// console.error(`Failed to pay fees before withdrawing, cancelling withdraw.`) | ||
// throw error | ||
// } | ||
// Withdraw | ||
const body = utils.withdraw(JSONBigInt.stringify(wallet), mint, toHex(amount), destinationAddr) | ||
// Withdraw | ||
const body = utils.withdraw( | ||
JSONBigInt.stringify(wallet), | ||
mint, | ||
toHex(amount), | ||
destinationAddr, | ||
) | ||
const logContext = { | ||
walletId, | ||
mint, | ||
ticker: Token.findByAddress(mint).ticker, | ||
amount, | ||
destinationAddr, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
const logContext = { | ||
walletId, | ||
mint, | ||
ticker: Token.findByAddress(mint).ticker, | ||
amount, | ||
destinationAddr, | ||
body: JSON.parse(body), | ||
wallet, | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(WITHDRAW_BALANCE_ROUTE(walletId, mint)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error( | ||
`wallet id: ${walletId} withdrawing ${amount} ${Token.findByAddress(mint).ticker} failed`, | ||
{ | ||
error, | ||
...logContext, | ||
}, | ||
) | ||
throw error | ||
} | ||
try { | ||
const res = await postRelayerWithAuth( | ||
config, | ||
getRelayerBaseUrl(WITHDRAW_BALANCE_ROUTE(walletId, mint)), | ||
body, | ||
) | ||
console.log(`task update-wallet(${res.task_id}): ${walletId}`, logContext) | ||
return { taskId: res.task_id } | ||
} catch (error) { | ||
console.error( | ||
`wallet id: ${walletId} withdrawing ${amount} ${ | ||
Token.findByAddress(mint).ticker | ||
} failed`, | ||
{ | ||
error, | ||
...logContext, | ||
}, | ||
) | ||
throw error | ||
} | ||
} |
@@ -1,7 +0,7 @@ | ||
import type { Address } from "viem" | ||
import type { Address } from 'viem' | ||
/// Header name for the HTTP auth signature | ||
export const RENEGADE_AUTH_HEADER_NAME = "renegade-auth" | ||
export const RENEGADE_AUTH_HEADER_NAME = 'renegade-auth' | ||
/// Header name for the expiration timestamp of a signature | ||
export const RENEGADE_SIG_EXPIRATION_HEADER_NAME = "renegade-auth-expiration" | ||
export const RENEGADE_SIG_EXPIRATION_HEADER_NAME = 'renegade-auth-expiration' | ||
@@ -13,5 +13,5 @@ //////////////////////////////////////////////////////////////////////////////// | ||
// Create a new wallet | ||
export const CREATE_WALLET_ROUTE = "/wallet" | ||
export const CREATE_WALLET_ROUTE = '/wallet' | ||
// Find a wallet in contract storage | ||
export const FIND_WALLET_ROUTE = "/wallet/lookup" | ||
export const FIND_WALLET_ROUTE = '/wallet/lookup' | ||
// Returns the wallet information for the given id | ||
@@ -22,28 +22,33 @@ export const GET_WALLET_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}` | ||
export const BACK_OF_QUEUE_WALLET_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/back-of-queue` | ||
`/wallet/${wallet_id}/back-of-queue` | ||
// Route to the orders of a given wallet | ||
export const WALLET_ORDERS_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/orders` | ||
export const WALLET_ORDERS_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/orders` | ||
// Returns a single order by the given identifier | ||
export const GET_ORDER_BY_ID_ROUTE = (wallet_id: string, order_id: string) => | ||
`/wallet/${wallet_id}/orders/${order_id}` | ||
`/wallet/${wallet_id}/orders/${order_id}` | ||
// Updates a given order | ||
export const UPDATE_ORDER_ROUTE = (wallet_id: string, order_id: string) => | ||
`/wallet/${wallet_id}/orders/${order_id}/update` | ||
`/wallet/${wallet_id}/orders/${order_id}/update` | ||
// Cancels a given order | ||
export const CANCEL_ORDER_ROUTE = (wallet_id: string, order_id: string) => | ||
`/wallet/${wallet_id}/orders/${order_id}/cancel` | ||
`/wallet/${wallet_id}/orders/${order_id}/cancel` | ||
// Returns the balances within a given wallet | ||
export const GET_BALANCES_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/balances` | ||
export const GET_BALANCES_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/balances` | ||
// Returns the balance associated with the given mint | ||
export const GET_BALANCE_BY_MINT_ROUTE = (wallet_id: string, mint: string) => | ||
`/wallet/${wallet_id}/balances/${mint}` | ||
`/wallet/${wallet_id}/balances/${mint}` | ||
// Deposits an ERC-20 token into the darkpool | ||
export const DEPOSIT_BALANCE_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/balances/deposit` | ||
export const DEPOSIT_BALANCE_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/balances/deposit` | ||
// Withdraws an ERC-20 token from the darkpool | ||
export const WITHDRAW_BALANCE_ROUTE = (wallet_id: string, mint: string) => | ||
`/wallet/${wallet_id}/balances/${mint}/withdraw` | ||
`/wallet/${wallet_id}/balances/${mint}/withdraw` | ||
// Pays all wallet fees | ||
export const PAY_FEES_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/pay-fees` | ||
export const PAY_FEES_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/pay-fees` | ||
// Returns the order history of a wallet | ||
export const ORDER_HISTORY_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/order-history` | ||
export const ORDER_HISTORY_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/order-history` | ||
@@ -55,7 +60,9 @@ //////////////////////////////////////////////////////////////////////////////// | ||
// Returns the full network topology known to the local node | ||
export const GET_NETWORK_TOPOLOGY_ROUTE = "/network" | ||
export const GET_NETWORK_TOPOLOGY_ROUTE = '/network' | ||
// Returns the cluster information for the specified cluster | ||
export const GET_CLUSTER_INFO_ROUTE = (cluster_id: string) => `/network/clusters/${cluster_id}` | ||
export const GET_CLUSTER_INFO_ROUTE = (cluster_id: string) => | ||
`/network/clusters/${cluster_id}` | ||
// Returns the peer info for a given peer | ||
export const GET_PEER_INFO_ROUTE = (peer_id: string) => `/network/peers/${peer_id}` | ||
export const GET_PEER_INFO_ROUTE = (peer_id: string) => | ||
`/network/peers/${peer_id}` | ||
@@ -67,5 +74,6 @@ //////////////////////////////////////////////////////////////////////////////// | ||
// Returns all known network orders | ||
export const GET_NETWORK_ORDERS_ROUTE = "/order_book/orders" | ||
export const GET_NETWORK_ORDERS_ROUTE = '/order_book/orders' | ||
// Returns the network order information of the specified order | ||
export const GET_NETWORK_ORDER_BY_ID_ROUTE = (order_id: string) => `/order_book/orders/${order_id}` | ||
export const GET_NETWORK_ORDER_BY_ID_ROUTE = (order_id: string) => | ||
`/order_book/orders/${order_id}` | ||
@@ -77,3 +85,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
// Price report route | ||
export const PRICE_REPORT_ROUTE = "/price_report" | ||
export const PRICE_REPORT_ROUTE = '/price_report' | ||
@@ -87,5 +95,7 @@ //////////////////////////////////////////////////////////////////////////////// | ||
// Get the task queue of a given wallet | ||
export const GET_TASK_QUEUE_ROUTE = (wallet_id: string) => `/task_queue/${wallet_id}` | ||
export const GET_TASK_QUEUE_ROUTE = (wallet_id: string) => | ||
`/task_queue/${wallet_id}` | ||
/// The route to fetch task history for a wallet | ||
export const TASK_HISTORY_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/task-history` | ||
export const TASK_HISTORY_ROUTE = (wallet_id: string) => | ||
`/wallet/${wallet_id}/task-history` | ||
@@ -97,18 +107,23 @@ //////////////////////////////////////////////////////////////////////////////// | ||
// Initiates a handshake with the server | ||
export const HANDSHAKE_ROUTE = "/v0/handshake" | ||
export const HANDSHAKE_ROUTE = '/v0/handshake' | ||
// Retrieves wallet information by wallet ID | ||
export const WALLET_ROUTE = (wallet_id: string) => `/v0/wallet/${wallet_id}` | ||
// Fetches price reports based on source, base, and quote currencies | ||
export const WS_PRICE_REPORT_ROUTE = (source: string, base: string, quote: string) => | ||
`/v0/price_report/${source}/${base}/${quote}` | ||
export const WS_PRICE_REPORT_ROUTE = ( | ||
source: string, | ||
base: string, | ||
quote: string, | ||
) => `/v0/price_report/${source}/${base}/${quote}` | ||
// Streams order book events | ||
export const ORDER_BOOK_ROUTE = "/v0/order_book" | ||
export const ORDER_BOOK_ROUTE = '/v0/order_book' | ||
/// The network topic, streams events about network peers | ||
export const NETWORK_INFO_ROUTE = "/v0/network" | ||
export const NETWORK_INFO_ROUTE = '/v0/network' | ||
/// The task status topic, streams information about task statuses | ||
export const TASK_STATUS_ROUTE = (task_id: string) => `/v0/tasks/${task_id}` | ||
/// The task history topic, streams information about historical tasks | ||
export const WS_TASK_HISTORY_ROUTE = (wallet_id: string) => `/v0/wallet/${wallet_id}/task-history` | ||
export const WS_TASK_HISTORY_ROUTE = (wallet_id: string) => | ||
`/v0/wallet/${wallet_id}/task-history` | ||
/// The wallet order status topic, streams events about wallet's orders | ||
export const WS_WALLET_ORDERS_ROUTE = (wallet_id: string) => `/v0/wallet/${wallet_id}/order-status` | ||
export const WS_WALLET_ORDERS_ROUTE = (wallet_id: string) => | ||
`/v0/wallet/${wallet_id}/order-status` | ||
@@ -119,4 +134,7 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export const PRICE_REPORTER_TOPIC = (exchange: string, base: Address, quote: Address) => | ||
`${exchange}-${base.toLowerCase()}-${quote.toLowerCase()}` | ||
export const PRICE_REPORTER_TOPIC = ( | ||
exchange: string, | ||
base: Address, | ||
quote: Address, | ||
) => `${exchange}-${base.toLowerCase()}-${quote.toLowerCase()}` | ||
@@ -128,241 +146,243 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export const devnetTokenMapping = { | ||
tokens: [ | ||
{ | ||
name: "WBTC", | ||
ticker: "WBTC", | ||
address: "0x11b57fe348584f042e436c6bf7c3c3def171de49", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "WETH", | ||
ticker: "WETH", | ||
address: "0xa6e41ffd769491a42a6e5ce453259b93983a22ef", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "BNB", | ||
ticker: "BNB", | ||
address: "0xe1080224b632a93951a7cfa33eeea9fd81558b5e", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MATIC", | ||
ticker: "MATIC", | ||
address: "0x7e32b54800705876d3b5cfbc7d9c226a211f7c1a", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LDO", | ||
ticker: "LDO", | ||
address: "0x525c2aba45f66987217323e8a05ea400c65d06dc", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDC", | ||
ticker: "USDC", | ||
address: "0x85d9a8a4bd77b9b5559c1b7fcb8ec9635922ed49", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDT", | ||
ticker: "USDT", | ||
address: "0x4a2ba922052ba54e29c5417bc979daaf7d5fe4f4", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LINK", | ||
ticker: "LINK", | ||
address: "0x4af567288e68cad4aa93a272fe6139ca53859c70", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "UNI", | ||
ticker: "UNI", | ||
address: "0x3df948c956e14175f43670407d5796b95bb219d8", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "SUSHI", | ||
ticker: "SUSHI", | ||
address: "0x75e0e92a79880bd81a69f72983d03c75e2b33dc8", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "1INCH", | ||
ticker: "1INCH", | ||
address: "0xf5ffd11a55afd39377411ab9856474d2a7cb697e", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "AAVE", | ||
ticker: "AAVE", | ||
address: "0x408da76e87511429485c32e4ad647dd14823fdc4", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "COMP", | ||
ticker: "COMP", | ||
address: "0xdb2d15a3eb70c347e0d2c2c7861cafb946baab48", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MKR", | ||
ticker: "MKR", | ||
address: "0xa39ffa43eba037d67a0f4fe91956038aba0ca386", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "REN", | ||
ticker: "REN", | ||
address: "0xdb3f4ecb0298238a19ec5afd087c6d9df8041919", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MANA", | ||
ticker: "MANA", | ||
address: "0x1b9cbdc65a7bebb0be7f18d93a1896ea1fd46d7a", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "ENS", | ||
ticker: "ENS", | ||
address: "0x47cec0749bd110bc11f9577a70061202b1b6c034", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "DYDX", | ||
ticker: "DYDX", | ||
address: "0x841118047f42754332d0ad4db8a2893761dd7f5d", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "CRV", | ||
ticker: "CRV", | ||
address: "0xc2c0c3398915a2d2e9c33c186abfef3192ee25e8", | ||
decimals: 18, | ||
}, | ||
], | ||
tokens: [ | ||
{ | ||
name: 'WBTC', | ||
ticker: 'WBTC', | ||
address: '0x11b57fe348584f042e436c6bf7c3c3def171de49', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'WETH', | ||
ticker: 'WETH', | ||
address: '0xa6e41ffd769491a42a6e5ce453259b93983a22ef', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'BNB', | ||
ticker: 'BNB', | ||
address: '0xe1080224b632a93951a7cfa33eeea9fd81558b5e', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'MATIC', | ||
ticker: 'MATIC', | ||
address: '0x7e32b54800705876d3b5cfbc7d9c226a211f7c1a', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'LDO', | ||
ticker: 'LDO', | ||
address: '0x525c2aba45f66987217323e8a05ea400c65d06dc', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'USDC', | ||
ticker: 'USDC', | ||
address: '0x85d9a8a4bd77b9b5559c1b7fcb8ec9635922ed49', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'USDT', | ||
ticker: 'USDT', | ||
address: '0x4a2ba922052ba54e29c5417bc979daaf7d5fe4f4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'LINK', | ||
ticker: 'LINK', | ||
address: '0x4af567288e68cad4aa93a272fe6139ca53859c70', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'UNI', | ||
ticker: 'UNI', | ||
address: '0x3df948c956e14175f43670407d5796b95bb219d8', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'SUSHI', | ||
ticker: 'SUSHI', | ||
address: '0x75e0e92a79880bd81a69f72983d03c75e2b33dc8', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: '1INCH', | ||
ticker: '1INCH', | ||
address: '0xf5ffd11a55afd39377411ab9856474d2a7cb697e', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'AAVE', | ||
ticker: 'AAVE', | ||
address: '0x408da76e87511429485c32e4ad647dd14823fdc4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'COMP', | ||
ticker: 'COMP', | ||
address: '0xdb2d15a3eb70c347e0d2c2c7861cafb946baab48', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'MKR', | ||
ticker: 'MKR', | ||
address: '0xa39ffa43eba037d67a0f4fe91956038aba0ca386', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'REN', | ||
ticker: 'REN', | ||
address: '0xdb3f4ecb0298238a19ec5afd087c6d9df8041919', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'MANA', | ||
ticker: 'MANA', | ||
address: '0x1b9cbdc65a7bebb0be7f18d93a1896ea1fd46d7a', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'ENS', | ||
ticker: 'ENS', | ||
address: '0x47cec0749bd110bc11f9577a70061202b1b6c034', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'DYDX', | ||
ticker: 'DYDX', | ||
address: '0x841118047f42754332d0ad4db8a2893761dd7f5d', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'CRV', | ||
ticker: 'CRV', | ||
address: '0xc2c0c3398915a2d2e9c33c186abfef3192ee25e8', | ||
decimals: 18, | ||
}, | ||
], | ||
} | ||
export const testnetTokenMapping = { | ||
tokens: [ | ||
{ | ||
name: "WBTC", | ||
ticker: "WBTC", | ||
address: "0xd542490eba60e4b4d28d23c5b392b1607438f3cc", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "WETH", | ||
ticker: "WETH", | ||
address: "0x663e903ff15a0e911258cea2116b2071e80fed68", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "BNB", | ||
ticker: "BNB", | ||
address: "0xed7ec2d4d4d9a6a702769679fb5a36f55ebf197b", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MATIC", | ||
ticker: "MATIC", | ||
address: "0x9268bb5c5f6403ff02a89dcff7ddbb07ff046f99", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LDO", | ||
ticker: "LDO", | ||
address: "0x22963655fe6ebbfa46400e9f01012e54bae543c4", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDC", | ||
ticker: "USDC", | ||
address: "0xab03a15c0b1bfe992765280247b31a73489aa57b", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "USDT", | ||
ticker: "USDT", | ||
address: "0xacca32fccaf3220c1a3a31f7a5f879c231320642", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "LINK", | ||
ticker: "LINK", | ||
address: "0x77edb6f64f86a6794d5da3a34aa9fbbe8e61e852", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "UNI", | ||
ticker: "UNI", | ||
address: "0xe78b46ae59984d11a215b6f84c7de4cb111ef63c", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "SUSHI", | ||
ticker: "SUSHI", | ||
address: "0x93fe5ec17f31112dcd25770fbd07270159b67451", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "1INCH", | ||
ticker: "1INCH", | ||
address: "0xc6464a3072270a3da814bb0ec2907df935ff839d", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "AAVE", | ||
ticker: "AAVE", | ||
address: "0x104f5cc5d1593f1ba2a0eecf5882be85e231aca9", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "COMP", | ||
ticker: "COMP", | ||
address: "0xac3b14cb55c2242bb8ca1dc8269701948cb0c348", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MKR", | ||
ticker: "MKR", | ||
address: "0x15f7fe757a582634e1ed105ea68f07f6cf240b37", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "REN", | ||
ticker: "REN", | ||
address: "0xe7e96cef8812d2d24add2de592b5c786f915f64b", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "MANA", | ||
ticker: "MANA", | ||
address: "0xb66ff14a830d5527f06e384b309288b843d555c4", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "ENS", | ||
ticker: "ENS", | ||
address: "0xf5c43ef3d79caf5680584d9087f95d81e75e2ddf", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "DYDX", | ||
ticker: "DYDX", | ||
address: "0xe85035f1145ac49333d105632a0d254e479a75be", | ||
decimals: 18, | ||
}, | ||
{ | ||
name: "CRV", | ||
ticker: "CRV", | ||
address: "0x47b8399a8a3ad9665e4257904f99eafe043c4f50", | ||
decimals: 18, | ||
}, | ||
], | ||
tokens: [ | ||
{ | ||
name: 'WBTC', | ||
ticker: 'WBTC', | ||
address: '0xd542490eba60e4b4d28d23c5b392b1607438f3cc', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'WETH', | ||
ticker: 'WETH', | ||
address: '0x663e903ff15a0e911258cea2116b2071e80fed68', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'BNB', | ||
ticker: 'BNB', | ||
address: '0xed7ec2d4d4d9a6a702769679fb5a36f55ebf197b', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'MATIC', | ||
ticker: 'MATIC', | ||
address: '0x9268bb5c5f6403ff02a89dcff7ddbb07ff046f99', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'LDO', | ||
ticker: 'LDO', | ||
address: '0x22963655fe6ebbfa46400e9f01012e54bae543c4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'USDC', | ||
ticker: 'USDC', | ||
address: '0xab03a15c0b1bfe992765280247b31a73489aa57b', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'USDT', | ||
ticker: 'USDT', | ||
address: '0xacca32fccaf3220c1a3a31f7a5f879c231320642', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'LINK', | ||
ticker: 'LINK', | ||
address: '0x77edb6f64f86a6794d5da3a34aa9fbbe8e61e852', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'UNI', | ||
ticker: 'UNI', | ||
address: '0xe78b46ae59984d11a215b6f84c7de4cb111ef63c', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'SUSHI', | ||
ticker: 'SUSHI', | ||
address: '0x93fe5ec17f31112dcd25770fbd07270159b67451', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: '1INCH', | ||
ticker: '1INCH', | ||
address: '0xc6464a3072270a3da814bb0ec2907df935ff839d', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'AAVE', | ||
ticker: 'AAVE', | ||
address: '0x104f5cc5d1593f1ba2a0eecf5882be85e231aca9', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'COMP', | ||
ticker: 'COMP', | ||
address: '0xac3b14cb55c2242bb8ca1dc8269701948cb0c348', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'MKR', | ||
ticker: 'MKR', | ||
address: '0x15f7fe757a582634e1ed105ea68f07f6cf240b37', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'REN', | ||
ticker: 'REN', | ||
address: '0xe7e96cef8812d2d24add2de592b5c786f915f64b', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'MANA', | ||
ticker: 'MANA', | ||
address: '0xb66ff14a830d5527f06e384b309288b843d555c4', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'ENS', | ||
ticker: 'ENS', | ||
address: '0xf5c43ef3d79caf5680584d9087f95d81e75e2ddf', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'DYDX', | ||
ticker: 'DYDX', | ||
address: '0xe85035f1145ac49333d105632a0d254e479a75be', | ||
decimals: 18, | ||
}, | ||
{ | ||
name: 'CRV', | ||
ticker: 'CRV', | ||
address: '0x47b8399a8a3ad9665e4257904f99eafe043c4f50', | ||
decimals: 18, | ||
}, | ||
], | ||
} | ||
const isDevelopment = process.env.NEXT_PUBLIC_RPC_URL?.includes("dev") | ||
const isDevelopment = process.env.NEXT_PUBLIC_RPC_URL?.includes('dev') | ||
export const tokenMapping = isDevelopment ? devnetTokenMapping : testnetTokenMapping | ||
export const tokenMapping = isDevelopment | ||
? devnetTokenMapping | ||
: testnetTokenMapping |
@@ -1,189 +0,200 @@ | ||
import { type Storage, createStorage, noopStorage } from "./createStorage.js" | ||
import type { Evaluate, ExactPartial } from "./types/utils.js" | ||
import type * as rustUtils from "./utils.d.ts" | ||
import invariant from "tiny-invariant" | ||
import invariant from 'tiny-invariant' | ||
import { | ||
type Address, | ||
type Chain, | ||
type Hex, | ||
type PublicClient, | ||
createPublicClient, | ||
defineChain, | ||
http, | ||
} from "viem" | ||
import { persist, subscribeWithSelector } from "zustand/middleware" | ||
import { type Mutate, type StoreApi, createStore } from "zustand/vanilla" | ||
http, | ||
type Address, | ||
type Chain, | ||
type Hex, | ||
type PublicClient, | ||
createPublicClient, | ||
defineChain, | ||
} from 'viem' | ||
import { persist, subscribeWithSelector } from 'zustand/middleware' | ||
import { type Mutate, type StoreApi, createStore } from 'zustand/vanilla' | ||
import { type Storage, createStorage, noopStorage } from './createStorage.js' | ||
import type { Evaluate, ExactPartial } from './types/utils.js' | ||
import type * as rustUtils from './utils.d.ts' | ||
export type CreateConfigParameters = { | ||
darkPoolAddress: Address | ||
priceReporterUrl: string | ||
relayerUrl: string | ||
httpPort?: number | ||
pollingInterval?: number | ||
rpcUrl: string | ||
ssr?: boolean | undefined | ||
storage?: Storage | null | undefined | ||
utils?: typeof rustUtils | ||
websocketPort?: number | ||
darkPoolAddress: Address | ||
priceReporterUrl: string | ||
relayerUrl: string | ||
httpPort?: number | ||
pollingInterval?: number | ||
rpcUrl: string | ||
ssr?: boolean | undefined | ||
storage?: Storage | null | undefined | ||
utils?: typeof rustUtils | ||
websocketPort?: number | ||
} | ||
export function createConfig(parameters: CreateConfigParameters): Config { | ||
const { | ||
relayerUrl, | ||
priceReporterUrl, | ||
httpPort = 3000, | ||
pollingInterval = 5000, | ||
ssr, | ||
storage = createStorage({ | ||
storage: | ||
typeof window !== "undefined" && window.localStorage | ||
? window.localStorage | ||
: noopStorage, | ||
}), | ||
websocketPort = 4000, | ||
} = parameters | ||
const { | ||
relayerUrl, | ||
priceReporterUrl, | ||
httpPort = 3000, | ||
pollingInterval = 5000, | ||
ssr, | ||
storage = createStorage({ | ||
storage: | ||
typeof window !== 'undefined' && window.localStorage | ||
? window.localStorage | ||
: noopStorage, | ||
}), | ||
websocketPort = 4000, | ||
} = parameters | ||
invariant( | ||
parameters.utils, | ||
"Utils must be provided by the package if not supplied by the user.", | ||
) | ||
invariant( | ||
parameters.utils, | ||
'Utils must be provided by the package if not supplied by the user.', | ||
) | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Create store | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Create store | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
function getInitialState(): State { | ||
return { | ||
seed: undefined, | ||
status: "disconnected", | ||
id: undefined, | ||
} | ||
function getInitialState(): State { | ||
return { | ||
seed: undefined, | ||
status: 'disconnected', | ||
id: undefined, | ||
} | ||
} | ||
const store = createStore( | ||
subscribeWithSelector( | ||
// only use persist middleware if storage exists | ||
storage | ||
? persist(getInitialState, { | ||
name: "store", | ||
partialize(state) { | ||
// Only persist "critical" store properties to preserve storage size. | ||
return { | ||
id: state.id, | ||
seed: state.seed, | ||
status: state.status, | ||
} satisfies PartializedState | ||
}, | ||
skipHydration: ssr, | ||
storage: storage as Storage<Record<string, unknown>>, | ||
}) | ||
: getInitialState, | ||
), | ||
) | ||
const store = createStore( | ||
subscribeWithSelector( | ||
// only use persist middleware if storage exists | ||
storage | ||
? persist(getInitialState, { | ||
name: 'store', | ||
partialize(state) { | ||
// Only persist "critical" store properties to preserve storage size. | ||
return { | ||
id: state.id, | ||
seed: state.seed, | ||
status: state.status, | ||
} satisfies PartializedState | ||
}, | ||
skipHydration: ssr, | ||
storage: storage as Storage<Record<string, unknown>>, | ||
}) | ||
: getInitialState, | ||
), | ||
) | ||
const getRenegadeChain = (_rpcUrl?: string) => { | ||
const rpcUrl = | ||
_rpcUrl ?? | ||
`https://${parameters.rpcUrl}` ?? | ||
`https://${relayerUrl.includes("dev") ? "dev." : ""}sequencer.renegade.fi` | ||
return defineChain({ | ||
id: 473474, | ||
name: "Renegade Testnet", | ||
network: "Renegade Testnet", | ||
testnet: true, | ||
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" }, | ||
rpcUrls: { default: { http: [rpcUrl] }, public: { http: [rpcUrl] } }, | ||
blockExplorers: { default: { name: "Explorer", url: "https://explorer.renegade.fi" } }, | ||
}) | ||
} | ||
const getRenegadeChain = (_rpcUrl?: string) => { | ||
const rpcUrl = | ||
_rpcUrl ?? | ||
`https://${parameters.rpcUrl}` ?? | ||
`https://${relayerUrl.includes('dev') ? 'dev.' : ''}sequencer.renegade.fi` | ||
return defineChain({ | ||
id: 473474, | ||
name: 'Renegade Testnet', | ||
network: 'Renegade Testnet', | ||
testnet: true, | ||
nativeCurrency: { decimals: 18, name: 'Ether', symbol: 'ETH' }, | ||
rpcUrls: { default: { http: [rpcUrl] }, public: { http: [rpcUrl] } }, | ||
blockExplorers: { | ||
default: { name: 'Explorer', url: 'https://explorer.renegade.fi' }, | ||
}, | ||
}) | ||
} | ||
return { | ||
utils: parameters.utils, | ||
relayerUrl, | ||
priceReporterUrl, | ||
darkPoolAddress: parameters.darkPoolAddress, | ||
getRenegadeChain, | ||
getRelayerBaseUrl: function (route: string = "") { | ||
const baseUrl = parameters.relayerUrl.includes("localhost") | ||
? `http://127.0.0.1:${httpPort}/v0` | ||
: `https://${parameters.relayerUrl}:${httpPort}/v0` | ||
const formattedRoute = route.startsWith("/") ? route : `/${route}` | ||
return `${baseUrl}${formattedRoute}` | ||
}, | ||
getPriceReporterBaseUrl: function () { | ||
const baseUrl = parameters.priceReporterUrl.includes("localhost") | ||
? `ws://127.0.0.1:${websocketPort}/` | ||
: `wss://${parameters.priceReporterUrl}:${websocketPort}/` | ||
return baseUrl | ||
}, | ||
getWebsocketBaseUrl: function () { | ||
const baseUrl = parameters.relayerUrl.includes("localhost") | ||
? `ws://127.0.0.1:${websocketPort}` | ||
: `wss://${parameters.relayerUrl}:${websocketPort}` | ||
return baseUrl | ||
}, | ||
getViemClient: () => | ||
createPublicClient({ | ||
chain: getRenegadeChain(), | ||
transport: http(), | ||
}), | ||
pollingInterval, | ||
get state() { | ||
return store.getState() | ||
}, | ||
setState: (newState: State) => store.setState(newState), | ||
subscribe(selector, listener, options) { | ||
return store.subscribe( | ||
selector as unknown as (state: State) => any, | ||
listener, | ||
options ? { ...options, fireImmediately: options.emitImmediately } : undefined, | ||
) | ||
}, | ||
_internal: { | ||
store, | ||
ssr: Boolean(ssr), | ||
}, | ||
} | ||
return { | ||
utils: parameters.utils, | ||
relayerUrl, | ||
priceReporterUrl, | ||
darkPoolAddress: parameters.darkPoolAddress, | ||
getRenegadeChain, | ||
getRelayerBaseUrl: (route = '') => { | ||
const baseUrl = parameters.relayerUrl.includes('localhost') | ||
? `http://127.0.0.1:${httpPort}/v0` | ||
: `https://${parameters.relayerUrl}:${httpPort}/v0` | ||
const formattedRoute = route.startsWith('/') ? route : `/${route}` | ||
return `${baseUrl}${formattedRoute}` | ||
}, | ||
getPriceReporterBaseUrl: () => { | ||
const baseUrl = parameters.priceReporterUrl.includes('localhost') | ||
? `ws://127.0.0.1:${websocketPort}/` | ||
: `wss://${parameters.priceReporterUrl}:${websocketPort}/` | ||
return baseUrl | ||
}, | ||
getWebsocketBaseUrl: () => { | ||
const baseUrl = parameters.relayerUrl.includes('localhost') | ||
? `ws://127.0.0.1:${websocketPort}` | ||
: `wss://${parameters.relayerUrl}:${websocketPort}` | ||
return baseUrl | ||
}, | ||
getViemClient: () => | ||
createPublicClient({ | ||
chain: getRenegadeChain(), | ||
transport: http(), | ||
}), | ||
pollingInterval, | ||
get state() { | ||
return store.getState() | ||
}, | ||
setState: (newState: State) => store.setState(newState), | ||
subscribe(selector, listener, options) { | ||
return store.subscribe( | ||
selector as unknown as (state: State) => any, | ||
listener, | ||
options | ||
? { ...options, fireImmediately: options.emitImmediately } | ||
: undefined, | ||
) | ||
}, | ||
_internal: { | ||
store, | ||
ssr: Boolean(ssr), | ||
}, | ||
} | ||
} | ||
export type Config = { | ||
darkPoolAddress: Address | ||
getPriceReporterBaseUrl: () => string | ||
getRelayerBaseUrl: (route?: string) => string | ||
getRenegadeChain: (rpcUrl?: string) => Chain | ||
getWebsocketBaseUrl: () => string | ||
pollingInterval: number | ||
priceReporterUrl: string | ||
relayerUrl: string | ||
rpcUrl?: string | ||
setState: (newState: State) => void | ||
state: State | ||
subscribe<state>( | ||
selector: (state: State) => state, | ||
listener: (state: state, previousState: state) => void, | ||
options?: | ||
| { | ||
emitImmediately?: boolean | undefined | ||
equalityFn?: ((a: state, b: state) => boolean) | undefined | ||
} | ||
| undefined, | ||
): () => void | ||
getViemClient: () => PublicClient | ||
utils: typeof rustUtils | ||
/** | ||
* Not part of versioned API, proceed with caution. | ||
* @internal | ||
*/ | ||
_internal: { | ||
readonly store: Mutate<StoreApi<any>, [["zustand/persist", any]]> | ||
readonly ssr: boolean | ||
} | ||
darkPoolAddress: Address | ||
getPriceReporterBaseUrl: () => string | ||
getRelayerBaseUrl: (route?: string) => string | ||
getRenegadeChain: (rpcUrl?: string) => Chain | ||
getWebsocketBaseUrl: () => string | ||
pollingInterval: number | ||
priceReporterUrl: string | ||
relayerUrl: string | ||
rpcUrl?: string | ||
setState: (newState: State) => void | ||
state: State | ||
subscribe<state>( | ||
selector: (state: State) => state, | ||
listener: (state: state, previousState: state) => void, | ||
options?: | ||
| { | ||
emitImmediately?: boolean | undefined | ||
equalityFn?: ((a: state, b: state) => boolean) | undefined | ||
} | ||
| undefined, | ||
): () => void | ||
getViemClient: () => PublicClient | ||
utils: typeof rustUtils | ||
/** | ||
* Not part of versioned API, proceed with caution. | ||
* @internal | ||
*/ | ||
_internal: { | ||
readonly store: Mutate<StoreApi<any>, [['zustand/persist', any]]> | ||
readonly ssr: boolean | ||
} | ||
} | ||
export interface State { | ||
seed?: Hex | undefined | ||
status?: "in relayer" | "disconnected" | "looking up" | "creating wallet" | "connecting" | ||
id?: string | undefined | ||
seed?: Hex | undefined | ||
status?: | ||
| 'in relayer' | ||
| 'disconnected' | ||
| 'looking up' | ||
| 'creating wallet' | ||
| 'connecting' | ||
id?: string | undefined | ||
} | ||
export type PartializedState = Evaluate<ExactPartial<Pick<State, "id" | "seed" | "status">>> | ||
export type PartializedState = Evaluate< | ||
ExactPartial<Pick<State, 'id' | 'seed' | 'status'>> | ||
> |
@@ -1,89 +0,91 @@ | ||
import { type PartializedState } from "./createConfig.js" | ||
import { type Evaluate } from "./types/utils.js" | ||
import { type PartializedState } from './createConfig.js' | ||
import { type Evaluate } from './types/utils.js' | ||
import { deserialize as deserialize_ } from "./utils/deserialize.js" | ||
import { serialize as serialize_ } from "./utils/serialize.js" | ||
import { deserialize as deserialize_ } from './utils/deserialize.js' | ||
import { serialize as serialize_ } from './utils/serialize.js' | ||
// key-values for loose autocomplete and typing | ||
export type StorageItemMap = { | ||
recentConnectorId: string | ||
state: PartializedState | ||
recentConnectorId: string | ||
state: PartializedState | ||
} | ||
export type Storage< | ||
itemMap extends Record<string, unknown> = {}, | ||
/// | ||
storageItemMap extends StorageItemMap = StorageItemMap & itemMap, | ||
itemMap extends Record<string, unknown> = {}, | ||
/// | ||
storageItemMap extends StorageItemMap = StorageItemMap & itemMap, | ||
> = { | ||
key: string | ||
getItem< | ||
key extends keyof storageItemMap, | ||
value extends storageItemMap[key], | ||
defaultValue extends value | null | undefined, | ||
>( | ||
key: key, | ||
defaultValue?: defaultValue | undefined, | ||
): | ||
| (defaultValue extends null ? value | null : value) | ||
| Promise<defaultValue extends null ? value | null : value> | ||
setItem<key extends keyof storageItemMap, value extends storageItemMap[key] | null>( | ||
key: key, | ||
value: value, | ||
): void | Promise<void> | ||
removeItem(key: keyof storageItemMap): void | Promise<void> | ||
key: string | ||
getItem< | ||
key extends keyof storageItemMap, | ||
value extends storageItemMap[key], | ||
defaultValue extends value | null | undefined, | ||
>( | ||
key: key, | ||
defaultValue?: defaultValue | undefined, | ||
): | ||
| (defaultValue extends null ? value | null : value) | ||
| Promise<defaultValue extends null ? value | null : value> | ||
setItem< | ||
key extends keyof storageItemMap, | ||
value extends storageItemMap[key] | null, | ||
>(key: key, value: value): void | Promise<void> | ||
removeItem(key: keyof storageItemMap): void | Promise<void> | ||
} | ||
export type BaseStorage = { | ||
getItem(key: string): string | null | undefined | Promise<string | null | undefined> | ||
setItem(key: string, value: string): void | Promise<void> | ||
removeItem(key: string): void | Promise<void> | ||
getItem( | ||
key: string, | ||
): string | null | undefined | Promise<string | null | undefined> | ||
setItem(key: string, value: string): void | Promise<void> | ||
removeItem(key: string): void | Promise<void> | ||
} | ||
export type CreateStorageParameters = { | ||
deserialize?: (<T>(value: string) => T) | undefined | ||
key?: string | undefined | ||
serialize?: (<T>(value: T) => string) | undefined | ||
storage?: Evaluate<BaseStorage> | undefined | ||
deserialize?: (<T>(value: string) => T) | undefined | ||
key?: string | undefined | ||
serialize?: (<T>(value: T) => string) | undefined | ||
storage?: Evaluate<BaseStorage> | undefined | ||
} | ||
export function createStorage< | ||
itemMap extends Record<string, unknown> = {}, | ||
storageItemMap extends StorageItemMap = StorageItemMap & itemMap, | ||
itemMap extends Record<string, unknown> = {}, | ||
storageItemMap extends StorageItemMap = StorageItemMap & itemMap, | ||
>(parameters: CreateStorageParameters): Evaluate<Storage<storageItemMap>> { | ||
const { | ||
deserialize = deserialize_, | ||
key: prefix = "renegade", | ||
serialize = serialize_, | ||
storage = noopStorage, | ||
} = parameters | ||
const { | ||
deserialize = deserialize_, | ||
key: prefix = 'renegade', | ||
serialize = serialize_, | ||
storage = noopStorage, | ||
} = parameters | ||
function unwrap<type>(value: type): type | Promise<type> { | ||
if (value instanceof Promise) return value.then(x => x).catch(() => null) | ||
return value | ||
} | ||
function unwrap<type>(value: type): type | Promise<type> { | ||
if (value instanceof Promise) return value.then((x) => x).catch(() => null) | ||
return value | ||
} | ||
return { | ||
...storage, | ||
key: prefix, | ||
async getItem(key, defaultValue) { | ||
const value = storage.getItem(`${prefix}.${key as string}`) | ||
const unwrapped = await unwrap(value) | ||
if (unwrapped) return deserialize(unwrapped) ?? null | ||
return (defaultValue ?? null) as any | ||
}, | ||
async setItem(key, value) { | ||
const storageKey = `${prefix}.${key as string}` | ||
if (value === null) await unwrap(storage.removeItem(storageKey)) | ||
else await unwrap(storage.setItem(storageKey, serialize(value))) | ||
}, | ||
async removeItem(key) { | ||
await unwrap(storage.removeItem(`${prefix}.${key as string}`)) | ||
}, | ||
} | ||
return { | ||
...storage, | ||
key: prefix, | ||
async getItem(key, defaultValue) { | ||
const value = storage.getItem(`${prefix}.${key as string}`) | ||
const unwrapped = await unwrap(value) | ||
if (unwrapped) return deserialize(unwrapped) ?? null | ||
return (defaultValue ?? null) as any | ||
}, | ||
async setItem(key, value) { | ||
const storageKey = `${prefix}.${key as string}` | ||
if (value === null) await unwrap(storage.removeItem(storageKey)) | ||
else await unwrap(storage.setItem(storageKey, serialize(value))) | ||
}, | ||
async removeItem(key) { | ||
await unwrap(storage.removeItem(`${prefix}.${key as string}`)) | ||
}, | ||
} | ||
} | ||
export const noopStorage = { | ||
getItem: () => null, | ||
setItem: () => {}, | ||
removeItem: () => {}, | ||
getItem: () => null, | ||
setItem: () => {}, | ||
removeItem: () => {}, | ||
} satisfies BaseStorage |
@@ -1,75 +0,75 @@ | ||
import { getVersion } from "../utils/getVersion.js" | ||
import { getVersion } from '../utils/getVersion.js' | ||
import type { Evaluate, OneOf } from "../types/utils.js" | ||
import type { Evaluate, OneOf } from '../types/utils.js' | ||
export type ErrorType<name extends string = "Error"> = Error & { name: name } | ||
export type ErrorType<name extends string = 'Error'> = Error & { name: name } | ||
type BaseErrorOptions = Evaluate< | ||
OneOf<{ details?: string | undefined } | { cause: BaseError | Error }> & { | ||
docsPath?: string | undefined | ||
docsSlug?: string | undefined | ||
metaMessages?: string[] | undefined | ||
} | ||
OneOf<{ details?: string | undefined } | { cause: BaseError | Error }> & { | ||
docsPath?: string | undefined | ||
docsSlug?: string | undefined | ||
metaMessages?: string[] | undefined | ||
} | ||
> | ||
export type BaseErrorType = BaseError & { name: "RenegadeCoreError" } | ||
export type BaseErrorType = BaseError & { name: 'RenegadeCoreError' } | ||
export class BaseError extends Error { | ||
details: string | ||
docsPath?: string | undefined | ||
metaMessages?: string[] | undefined | ||
shortMessage: string | ||
details: string | ||
docsPath?: string | undefined | ||
metaMessages?: string[] | undefined | ||
shortMessage: string | ||
override name = "RenegadeCoreError" | ||
get docsBaseUrl() { | ||
return "todo: put a docs link here" | ||
} | ||
get version() { | ||
return getVersion() | ||
} | ||
override name = 'RenegadeCoreError' | ||
get docsBaseUrl() { | ||
return 'todo: put a docs link here' | ||
} | ||
get version() { | ||
return getVersion() | ||
} | ||
constructor(shortMessage: string, options: BaseErrorOptions = {}) { | ||
super() | ||
constructor(shortMessage: string, options: BaseErrorOptions = {}) { | ||
super() | ||
const details = | ||
options.cause instanceof BaseError | ||
? options.cause.details | ||
: options.cause?.message | ||
? options.cause.message | ||
: options.details! | ||
const docsPath = | ||
options.cause instanceof BaseError | ||
? options.cause.docsPath || options.docsPath | ||
: options.docsPath | ||
const details = | ||
options.cause instanceof BaseError | ||
? options.cause.details | ||
: options.cause?.message | ||
? options.cause.message | ||
: options.details! | ||
const docsPath = | ||
options.cause instanceof BaseError | ||
? options.cause.docsPath || options.docsPath | ||
: options.docsPath | ||
this.message = [ | ||
shortMessage || "An error occurred.", | ||
"", | ||
...(options.metaMessages ? [...options.metaMessages, ""] : []), | ||
...(docsPath | ||
? [ | ||
`Docs: ${this.docsBaseUrl}${docsPath}.html${ | ||
options.docsSlug ? `#${options.docsSlug}` : "" | ||
}`, | ||
] | ||
: []), | ||
...(details ? [`Details: ${details}`] : []), | ||
`Version: ${this.version}`, | ||
].join("\n") | ||
this.message = [ | ||
shortMessage || 'An error occurred.', | ||
'', | ||
...(options.metaMessages ? [...options.metaMessages, ''] : []), | ||
...(docsPath | ||
? [ | ||
`Docs: ${this.docsBaseUrl}${docsPath}.html${ | ||
options.docsSlug ? `#${options.docsSlug}` : '' | ||
}`, | ||
] | ||
: []), | ||
...(details ? [`Details: ${details}`] : []), | ||
`Version: ${this.version}`, | ||
].join('\n') | ||
if (options.cause) this.cause = options.cause | ||
this.details = details | ||
this.docsPath = docsPath | ||
this.metaMessages = options.metaMessages | ||
this.shortMessage = shortMessage | ||
} | ||
if (options.cause) this.cause = options.cause | ||
this.details = details | ||
this.docsPath = docsPath | ||
this.metaMessages = options.metaMessages | ||
this.shortMessage = shortMessage | ||
} | ||
walk(fn?: (err: unknown) => boolean) { | ||
return this.#walk(this, fn) | ||
} | ||
walk(fn?: (err: unknown) => boolean) { | ||
return this.#walk(this, fn) | ||
} | ||
#walk(err: unknown, fn?: (err: unknown) => boolean): unknown { | ||
if (fn?.(err)) return err | ||
if ((err as Error).cause) return this.#walk((err as Error).cause, fn) | ||
return err | ||
} | ||
#walk(err: unknown, fn?: (err: unknown) => boolean): unknown { | ||
if (fn?.(err)) return err | ||
if ((err as Error).cause) return this.#walk((err as Error).cause, fn) | ||
return err | ||
} | ||
} |
@@ -1,33 +0,33 @@ | ||
import { reconnect } from "./actions/reconnect.js" | ||
import type { Config, State } from "./createConfig.js" | ||
import { reconnect } from './actions/reconnect.js' | ||
import type { Config, State } from './createConfig.js' | ||
type HydrateParameters = { | ||
initialState?: State | undefined | ||
reconnectOnMount?: boolean | undefined | ||
initialState?: State | undefined | ||
reconnectOnMount?: boolean | undefined | ||
} | ||
export function hydrate(config: Config, parameters: HydrateParameters) { | ||
const { initialState, reconnectOnMount } = parameters | ||
const { initialState, reconnectOnMount } = parameters | ||
// TODO: Handle initial state | ||
if (initialState && !config._internal.store.persist.hasHydrated()) | ||
config.setState({ | ||
...initialState, | ||
status: reconnectOnMount ? "looking up" : "disconnected", | ||
seed: reconnectOnMount ? config.state.seed : undefined, | ||
}) | ||
// TODO: Handle initial state | ||
if (initialState && !config._internal.store.persist.hasHydrated()) | ||
config.setState({ | ||
...initialState, | ||
status: reconnectOnMount ? 'looking up' : 'disconnected', | ||
seed: reconnectOnMount ? config.state.seed : undefined, | ||
}) | ||
return { | ||
async onMount() { | ||
if (config._internal.ssr) { | ||
console.log("💧 SSR enabled, rehydrating state") | ||
await config._internal.store.persist.rehydrate() | ||
} | ||
return { | ||
async onMount() { | ||
if (config._internal.ssr) { | ||
console.log('💧 SSR enabled, rehydrating state') | ||
await config._internal.store.persist.rehydrate() | ||
} | ||
if (reconnectOnMount) { | ||
console.log("🚝 Reconnecting on mount") | ||
reconnect(config, { id: config.state.id }) | ||
} | ||
}, | ||
} | ||
if (reconnectOnMount) { | ||
console.log('🚝 Reconnecting on mount') | ||
reconnect(config, { id: config.state.id }) | ||
} | ||
}, | ||
} | ||
} |
212
src/index.ts
@@ -6,7 +6,7 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { | ||
type Config, | ||
type CreateConfigParameters, | ||
type State, | ||
createConfig, | ||
} from "./createConfig.js" | ||
type Config, | ||
type CreateConfigParameters, | ||
type State, | ||
createConfig, | ||
} from './createConfig.js' | ||
@@ -18,131 +18,139 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { | ||
type CancelOrderParameters, | ||
type CancelOrderReturnType, | ||
cancelOrder, | ||
} from "./actions/cancelOrder.js" | ||
type CancelOrderParameters, | ||
type CancelOrderReturnType, | ||
cancelOrder, | ||
} from './actions/cancelOrder.js' | ||
export { type ConnectParameters, type ConnectReturnType, connect } from "./actions/connect.js" | ||
export { | ||
type ConnectParameters, | ||
type ConnectReturnType, | ||
connect, | ||
} from './actions/connect.js' | ||
export { | ||
type CreateOrderParameters, | ||
type CreateOrderReturnType, | ||
createOrder, | ||
} from "./actions/createOrder.js" | ||
type CreateOrderParameters, | ||
type CreateOrderReturnType, | ||
createOrder, | ||
} from './actions/createOrder.js' | ||
export { | ||
type CreateWalletParameters, | ||
type CreateWalletReturnType, | ||
createWallet, | ||
} from "./actions/createWallet.js" | ||
type CreateWalletReturnType, | ||
createWallet, | ||
} from './actions/createWallet.js' | ||
export { type DepositParameters, type DepositReturnType, deposit } from "./actions/deposit.js" | ||
export { | ||
type DepositParameters, | ||
type DepositReturnType, | ||
deposit, | ||
} from './actions/deposit.js' | ||
export { | ||
type DisconnectParameters, | ||
type DisconnectReturnType, | ||
disconnect, | ||
} from "./actions/disconnect.js" | ||
type DisconnectReturnType, | ||
disconnect, | ||
} from './actions/disconnect.js' | ||
export { | ||
type GetAuthorizationHeadersParameters, | ||
type GetAuthorizationHeadersReturnType, | ||
getAuthorizationHeaders, | ||
} from "./actions/getAuthHeaders.js" | ||
type GetAuthorizationHeadersParameters, | ||
type GetAuthorizationHeadersReturnType, | ||
getAuthorizationHeaders, | ||
} from './actions/getAuthHeaders.js' | ||
export { | ||
type GetBalancesParameters, | ||
type GetBalancesReturnType, | ||
getBalances, | ||
} from "./actions/getBalances.js" | ||
type GetBalancesReturnType, | ||
getBalances, | ||
} from './actions/getBalances.js' | ||
export { type GetOrderParameters, type GetOrderReturnType, getOrder } from "./actions/getOrder.js" | ||
export { | ||
type GetOrderParameters, | ||
type GetOrderReturnType, | ||
getOrder, | ||
} from './actions/getOrder.js' | ||
export { | ||
type GetOrderHistoryParameters, | ||
type GetOrderHistoryReturnType, | ||
getOrderHistory, | ||
} from "./actions/getOrderHistory.js" | ||
type GetOrderHistoryReturnType, | ||
getOrderHistory, | ||
} from './actions/getOrderHistory.js' | ||
export { | ||
type GetNetworkOrdersParameters, | ||
type GetNetworkOrdersReturnType, | ||
getNetworkOrders, | ||
} from "./actions/getNetworkOrders.js" | ||
type GetNetworkOrdersReturnType, | ||
getNetworkOrders, | ||
} from './actions/getNetworkOrders.js' | ||
export { | ||
type GetOrdersParameters, | ||
type GetOrdersReturnType, | ||
getOrders, | ||
} from "./actions/getOrders.js" | ||
type GetOrdersReturnType, | ||
getOrders, | ||
} from './actions/getOrders.js' | ||
export { | ||
type GetPkRootReturnType, | ||
getPkRoot, | ||
type GetPkRootScalarsReturnType, | ||
getPkRootScalars, | ||
} from "./actions/getPkRoot.js" | ||
type GetPkRootReturnType, | ||
getPkRoot, | ||
type GetPkRootScalarsReturnType, | ||
getPkRootScalars, | ||
} from './actions/getPkRoot.js' | ||
export { | ||
type GetSkRootParameters, | ||
type GetSkRootReturnType, | ||
getSkRoot, | ||
} from "./actions/getSkRoot.js" | ||
type GetSkRootParameters, | ||
type GetSkRootReturnType, | ||
getSkRoot, | ||
} from './actions/getSkRoot.js' | ||
export { | ||
type GetTaskHistoryParameters, | ||
type GetTaskHistoryReturnType, | ||
getTaskHistory, | ||
} from "./actions/getTaskHistory.js" | ||
type GetTaskHistoryReturnType, | ||
getTaskHistory, | ||
} from './actions/getTaskHistory.js' | ||
export { | ||
type GetTaskStatusParameters, | ||
type GetTaskStatusReturnType, | ||
getTaskStatus, | ||
} from "./actions/getTaskStatus.js" | ||
type GetTaskStatusParameters, | ||
type GetTaskStatusReturnType, | ||
getTaskStatus, | ||
} from './actions/getTaskStatus.js' | ||
export { | ||
type GetTaskQueueParameters, | ||
type GetTaskQueueReturnType, | ||
getTaskQueue, | ||
} from "./actions/getTaskQueue.js" | ||
type GetTaskQueueReturnType, | ||
getTaskQueue, | ||
} from './actions/getTaskQueue.js' | ||
export { | ||
type GetWalletFromRelayerParameters, | ||
type GetWalletFromRelayerReturnType, | ||
getWalletFromRelayer, | ||
} from "./actions/getWalletFromRelayer.js" | ||
type GetWalletFromRelayerParameters, | ||
type GetWalletFromRelayerReturnType, | ||
getWalletFromRelayer, | ||
} from './actions/getWalletFromRelayer.js' | ||
export { | ||
type GetWalletIdParameters, | ||
type GetWalletIdReturnType, | ||
getWalletId, | ||
} from "./actions/getWalletId.js" | ||
type GetWalletIdParameters, | ||
type GetWalletIdReturnType, | ||
getWalletId, | ||
} from './actions/getWalletId.js' | ||
export { | ||
type LookupWalletParameters, | ||
type LookupWalletReturnType, | ||
lookupWallet, | ||
} from "./actions/lookupWallet.js" | ||
type LookupWalletParameters, | ||
type LookupWalletReturnType, | ||
lookupWallet, | ||
} from './actions/lookupWallet.js' | ||
export { type PayFeesReturnType, payFees } from "./actions/payFees.js" | ||
export { type PayFeesReturnType, payFees } from './actions/payFees.js' | ||
export { | ||
type SignMessageParameters, | ||
type SignMessageReturnType, | ||
signMessage, | ||
} from "./actions/signMessage.js" | ||
type SignMessageParameters, | ||
type SignMessageReturnType, | ||
signMessage, | ||
} from './actions/signMessage.js' | ||
export { | ||
type WaitForTaskCompletionParameters, | ||
type WaitForTaskCompletionReturnType, | ||
waitForTaskCompletion, | ||
} from "./actions/waitForTaskCompletion.js" | ||
type WaitForTaskCompletionParameters, | ||
type WaitForTaskCompletionReturnType, | ||
waitForTaskCompletion, | ||
} from './actions/waitForTaskCompletion.js' | ||
export { | ||
type WatchStatusParameters, | ||
type WatchStatusReturnType, | ||
watchStatus, | ||
} from "./actions/watchStatus.js" | ||
type WatchStatusParameters, | ||
type WatchStatusReturnType, | ||
watchStatus, | ||
} from './actions/watchStatus.js' | ||
export { type WithdrawParameters, type WithdrawReturnType, withdraw } from "./actions/withdraw.js" | ||
export { | ||
type WithdrawParameters, | ||
type WithdrawReturnType, | ||
withdraw, | ||
} from './actions/withdraw.js' | ||
@@ -153,3 +161,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { hydrate } from "./hydrate.js" | ||
export { hydrate } from './hydrate.js' | ||
@@ -160,3 +168,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { BaseError } from "./errors/base.js" | ||
export { BaseError } from './errors/base.js' | ||
@@ -166,3 +174,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export * from "./constants.js" | ||
export * from './constants.js' | ||
@@ -173,8 +181,8 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { Token } from "./types/token.js" | ||
export { Token } from './types/token.js' | ||
export * from "./types/wallet.js" | ||
export * from './types/wallet.js' | ||
export type { Task, TaskInfo, TaskState } from "./types/task.js" | ||
export { UpdateType, TaskType } from "./types/task.js" | ||
export type { Task, TaskInfo, TaskState } from './types/task.js' | ||
export { UpdateType, TaskType } from './types/task.js' | ||
@@ -185,7 +193,7 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { formatAmount, parseAmount } from "./utils/format.js" | ||
export { formatAmount, parseAmount } from './utils/format.js' | ||
export { deepEqual } from "./utils/deepEqual.js" | ||
export { deepEqual } from './utils/deepEqual.js' | ||
export { WebSocketManager } from "./utils/websocket.js" | ||
export { WebSocketManager } from './utils/websocket.js' | ||
@@ -195,2 +203,2 @@ //////////////////////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
export { chain } from "./utils/chain.js" | ||
export { chain } from './utils/chain.js' |
@@ -1,77 +0,77 @@ | ||
import type { Address } from "viem" | ||
import type { Address } from 'viem' | ||
export type Task = { | ||
id: string | ||
state: TaskState | ||
created_at: number | ||
task_info: TaskInfo | ||
id: string | ||
state: TaskState | ||
created_at: number | ||
task_info: TaskInfo | ||
} | ||
export type TaskState = | ||
| "Queued" | ||
| "Running" | ||
| "Proving" | ||
| "Proving Payment" | ||
| "Submitting Tx" | ||
| "Submitting Payment" | ||
| "Finding Opening" | ||
| "Updating Validity Proofs" | ||
| "Completed" | ||
| "Failed" | ||
| 'Queued' | ||
| 'Running' | ||
| 'Proving' | ||
| 'Proving Payment' | ||
| 'Submitting Tx' | ||
| 'Submitting Payment' | ||
| 'Finding Opening' | ||
| 'Updating Validity Proofs' | ||
| 'Completed' | ||
| 'Failed' | ||
export enum UpdateType { | ||
Deposit = "Deposit", | ||
Withdraw = "Withdraw", | ||
PlaceOrder = "PlaceOrder", | ||
CancelOrder = "CancelOrder", | ||
Deposit = 'Deposit', | ||
Withdraw = 'Withdraw', | ||
PlaceOrder = 'PlaceOrder', | ||
CancelOrder = 'CancelOrder', | ||
} | ||
export enum TaskType { | ||
NewWallet = "NewWallet", | ||
UpdateWallet = "UpdateWallet", | ||
SettleMatch = "SettleMatch", | ||
PayOfflineFee = "PayOfflineFee", | ||
NewWallet = 'NewWallet', | ||
UpdateWallet = 'UpdateWallet', | ||
SettleMatch = 'SettleMatch', | ||
PayOfflineFee = 'PayOfflineFee', | ||
} | ||
export type TaskInfo = | ||
| { | ||
update_type: UpdateType.Deposit | ||
task_type: TaskType.UpdateWallet | ||
mint: Address | ||
amount: bigint | ||
} | ||
| { | ||
update_type: UpdateType.Withdraw | ||
task_type: TaskType.UpdateWallet | ||
mint: Address | ||
amount: bigint | ||
} | ||
| { | ||
update_type: UpdateType.PlaceOrder | ||
task_type: TaskType.UpdateWallet | ||
amount: bigint | ||
base: Address | ||
quote: Address | ||
side: "Buy" | "Sell" | ||
} | ||
| { | ||
update_type: UpdateType.CancelOrder | ||
task_type: TaskType.UpdateWallet | ||
amount: bigint | ||
base: Address | ||
quote: Address | ||
side: "Buy" | "Sell" | ||
} | ||
| { | ||
task_type: TaskType.SettleMatch | ||
base: Address | ||
is_sell: boolean | ||
quote: Address | ||
volume: bigint | ||
} | ||
| { | ||
task_type: TaskType.PayOfflineFee | ||
} | ||
| { | ||
task_type: TaskType.NewWallet | ||
} | ||
| { | ||
update_type: UpdateType.Deposit | ||
task_type: TaskType.UpdateWallet | ||
mint: Address | ||
amount: bigint | ||
} | ||
| { | ||
update_type: UpdateType.Withdraw | ||
task_type: TaskType.UpdateWallet | ||
mint: Address | ||
amount: bigint | ||
} | ||
| { | ||
update_type: UpdateType.PlaceOrder | ||
task_type: TaskType.UpdateWallet | ||
amount: bigint | ||
base: Address | ||
quote: Address | ||
side: 'Buy' | 'Sell' | ||
} | ||
| { | ||
update_type: UpdateType.CancelOrder | ||
task_type: TaskType.UpdateWallet | ||
amount: bigint | ||
base: Address | ||
quote: Address | ||
side: 'Buy' | 'Sell' | ||
} | ||
| { | ||
task_type: TaskType.SettleMatch | ||
base: Address | ||
is_sell: boolean | ||
quote: Address | ||
volume: bigint | ||
} | ||
| { | ||
task_type: TaskType.PayOfflineFee | ||
} | ||
| { | ||
task_type: TaskType.NewWallet | ||
} |
@@ -1,66 +0,80 @@ | ||
import { type Address, isHex } from "viem" | ||
import { type Address, isHex } from 'viem' | ||
import { tokenMapping } from "../constants.js" | ||
import { tokenMapping } from '../constants.js' | ||
export class Token { | ||
private _name: string | ||
private _ticker: string | ||
private _address: Address | ||
private _decimals: number | ||
private _name: string | ||
private _ticker: string | ||
private _address: Address | ||
private _decimals: number | ||
constructor(name: string, ticker: string, address: Address, decimals: number) { | ||
this._name = name | ||
this._ticker = ticker | ||
this._address = address | ||
this._decimals = decimals | ||
} | ||
constructor( | ||
name: string, | ||
ticker: string, | ||
address: Address, | ||
decimals: number, | ||
) { | ||
this._name = name | ||
this._ticker = ticker | ||
this._address = address | ||
this._decimals = decimals | ||
} | ||
get name(): string { | ||
return this._name | ||
} | ||
get name(): string { | ||
return this._name | ||
} | ||
get ticker(): string { | ||
return this._ticker | ||
} | ||
get ticker(): string { | ||
return this._ticker | ||
} | ||
get address(): Address { | ||
return this._address | ||
} | ||
get address(): Address { | ||
return this._address | ||
} | ||
get decimals(): number { | ||
return this._decimals | ||
} | ||
get decimals(): number { | ||
return this._decimals | ||
} | ||
static findByTicker(ticker: string): Token { | ||
const tokenData = tokenMapping.tokens.find(token => token.ticker === ticker) | ||
if (tokenData) { | ||
return new Token( | ||
tokenData.name, | ||
tokenData.ticker, | ||
tokenData.address as Address, | ||
tokenData.decimals, | ||
) | ||
} | ||
throw new Error(`Token not found for ${ticker}`) | ||
static findByTicker(ticker: string): Token { | ||
const tokenData = tokenMapping.tokens.find( | ||
(token) => token.ticker === ticker, | ||
) | ||
if (tokenData) { | ||
return new Token( | ||
tokenData.name, | ||
tokenData.ticker, | ||
tokenData.address as Address, | ||
tokenData.decimals, | ||
) | ||
} | ||
throw new Error(`Token not found for ${ticker}`) | ||
} | ||
static findByAddress(address: Address): Token { | ||
const tokenData = tokenMapping.tokens.find(token => token.address === address) | ||
if (tokenData) { | ||
return new Token( | ||
tokenData.name, | ||
tokenData.ticker, | ||
tokenData.address as Address, | ||
tokenData.decimals, | ||
) | ||
} | ||
throw new Error(`Token not found for ${address}`) | ||
static findByAddress(address: Address): Token { | ||
const tokenData = tokenMapping.tokens.find( | ||
(token) => token.address === address, | ||
) | ||
if (tokenData) { | ||
return new Token( | ||
tokenData.name, | ||
tokenData.ticker, | ||
tokenData.address as Address, | ||
tokenData.decimals, | ||
) | ||
} | ||
throw new Error(`Token not found for ${address}`) | ||
} | ||
static create(name: string, ticker: string, address: Address, decimals: number): Token { | ||
if (!isHex(address)) { | ||
throw new Error("Invalid address") | ||
} | ||
return new Token(name, ticker, address, decimals) | ||
static create( | ||
name: string, | ||
ticker: string, | ||
address: Address, | ||
decimals: number, | ||
): Token { | ||
if (!isHex(address)) { | ||
throw new Error('Invalid address') | ||
} | ||
return new Token(name, ticker, address, decimals) | ||
} | ||
} |
@@ -11,16 +11,16 @@ /** Combines members of an intersection into a readable type. */ | ||
export type ExactPartial<type> = { | ||
[key in keyof type]?: type[key] | undefined | ||
[key in keyof type]?: type[key] | undefined | ||
} | ||
/** Checks if {@link type} can be narrowed further than {@link type2} */ | ||
export type IsNarrowable<type, type2> = | ||
IsUnknown<type> extends true | ||
? false | ||
: undefined extends type | ||
? false | ||
: IsNever< | ||
(type extends type2 ? true : false) & (type2 extends type ? false : true) | ||
> extends true | ||
? false | ||
: true | ||
export type IsNarrowable<type, type2> = IsUnknown<type> extends true | ||
? false | ||
: undefined extends type | ||
? false | ||
: IsNever< | ||
(type extends type2 ? true : false) & | ||
(type2 extends type ? false : true) | ||
> extends true | ||
? false | ||
: true | ||
@@ -41,3 +41,4 @@ /** | ||
export type Merge<obj1, obj2> = Evaluate< | ||
LooseOmit<obj1, keyof obj2 extends infer key extends string ? key : never> & obj2 | ||
LooseOmit<obj1, keyof obj2 extends infer key extends string ? key : never> & | ||
obj2 | ||
> | ||
@@ -47,16 +48,19 @@ | ||
export type Mutable<type extends object> = { | ||
-readonly [key in keyof type]: type[key] | ||
-readonly [key in keyof type]: type[key] | ||
} | ||
/** Strict version of built-in Omit type */ | ||
export type Omit<type, keys extends keyof type> = Pick<type, Exclude<keyof type, keys>> | ||
export type Omit<type, keys extends keyof type> = Pick< | ||
type, | ||
Exclude<keyof type, keys> | ||
> | ||
/** Makes objects destructurable. */ | ||
export type OneOf< | ||
union extends object, | ||
/// | ||
keys extends KeyofUnion<union> = KeyofUnion<union>, | ||
union extends object, | ||
/// | ||
keys extends KeyofUnion<union> = KeyofUnion<union>, | ||
> = union extends infer Item | ||
? Evaluate<Item & { [K in Exclude<keys, keyof Item>]?: undefined }> | ||
: never | ||
? Evaluate<Item & { [K in Exclude<keys, keyof Item>]?: undefined }> | ||
: never | ||
type KeyofUnion<type> = type extends type ? keyof type : never | ||
@@ -66,4 +70,6 @@ | ||
// s/o trpc (https://github.com/trpc/trpc/blob/main/packages/server/src/types.ts#L6) | ||
export type PartialBy<type, key extends keyof type> = ExactPartial<Pick<type, key>> & | ||
Omit<type, key> | ||
export type PartialBy<type, key extends keyof type> = ExactPartial< | ||
Pick<type, key> | ||
> & | ||
Omit<type, key> | ||
@@ -74,3 +80,6 @@ /////////////////////////////////////////////////////////////////////////// | ||
/** Loose version of {@link Omit} */ | ||
export type LooseOmit<type, keys extends string> = Pick<type, Exclude<keyof type, keys>> | ||
export type LooseOmit<type, keys extends string> = Pick< | ||
type, | ||
Exclude<keyof type, keys> | ||
> | ||
@@ -77,0 +86,0 @@ /////////////////////////////////////////////////////////////////////////// |
@@ -1,74 +0,74 @@ | ||
import type { Address, Hex } from "viem" | ||
import type { Address, Hex } from 'viem' | ||
export type Exchange = "binance" | "coinbase" | "kraken" | "okx" | ||
export type Exchange = 'binance' | 'coinbase' | 'kraken' | 'okx' | ||
export type NetworkOrder = { | ||
id: string | ||
public_share_nullifier: number[] | ||
local: boolean | ||
cluster: string | ||
state: string | ||
validity_proofs: (ValidityProof | number[])[] | ||
timestamp: number | ||
id: string | ||
public_share_nullifier: number[] | ||
local: boolean | ||
cluster: string | ||
state: string | ||
validity_proofs: (ValidityProof | number[])[] | ||
timestamp: number | ||
} | ||
type ValidityProof = { | ||
statement: { | ||
original_shares_nullifier?: number[] | ||
reblinded_private_share_commitment?: number[] | ||
merkle_root?: number[] | ||
indices?: { | ||
balance_send: number | ||
balance_receive: number | ||
order: number | ||
} | ||
statement: { | ||
original_shares_nullifier?: number[] | ||
reblinded_private_share_commitment?: number[] | ||
merkle_root?: number[] | ||
indices?: { | ||
balance_send: number | ||
balance_receive: number | ||
order: number | ||
} | ||
proof: string | ||
} | ||
proof: string | ||
} | ||
export type Order = { | ||
id: string | ||
quote_mint: Address | ||
base_mint: Address | ||
side: "Buy" | "Sell" | ||
type: "Midpoint" | ||
worst_case_price: string | ||
amount: bigint | ||
id: string | ||
quote_mint: Address | ||
base_mint: Address | ||
side: 'Buy' | 'Sell' | ||
type: 'Midpoint' | ||
worst_case_price: string | ||
amount: bigint | ||
} | ||
export type Balance = { | ||
mint: Address | ||
amount: bigint | ||
relayer_fee_balance: bigint | ||
protocol_fee_balance: bigint | ||
mint: Address | ||
amount: bigint | ||
relayer_fee_balance: bigint | ||
protocol_fee_balance: bigint | ||
} | ||
export type KeyChain = { | ||
public_keys: { | ||
pk_root: Hex | ||
pk_match: Hex | ||
} | ||
private_keys: { | ||
sk_root: Hex | ||
sk_match: Hex | ||
} | ||
public_keys: { | ||
pk_root: Hex | ||
pk_match: Hex | ||
} | ||
private_keys: { | ||
sk_root: Hex | ||
sk_match: Hex | ||
} | ||
} | ||
export type Wallet = { | ||
id: string | ||
orders: Order[] | ||
balances: Balance[] | ||
key_chain: KeyChain | ||
managing_cluster: Hex | ||
match_fee: bigint | ||
blinded_public_shares: bigint[][] | ||
private_shares: bigint[][] | ||
blinder: bigint[] | ||
id: string | ||
orders: Order[] | ||
balances: Balance[] | ||
key_chain: KeyChain | ||
managing_cluster: Hex | ||
match_fee: bigint | ||
blinded_public_shares: bigint[][] | ||
private_shares: bigint[][] | ||
blinder: bigint[] | ||
} | ||
export type OldTask = { | ||
id: string | ||
description: string | ||
state: string | ||
committed: boolean | ||
id: string | ||
description: string | ||
state: string | ||
committed: boolean | ||
} | ||
@@ -78,15 +78,15 @@ | ||
export enum OrderState { | ||
Created = "Created", | ||
Matching = "Matching", | ||
SettlingMatch = "SettlingMatch", | ||
Filled = "Filled", | ||
Cancelled = "Cancelled", | ||
Created = 'Created', | ||
Matching = 'Matching', | ||
SettlingMatch = 'SettlingMatch', | ||
Filled = 'Filled', | ||
Cancelled = 'Cancelled', | ||
} | ||
export type OrderMetadata = { | ||
id: string | ||
state: OrderState | ||
filled: bigint | ||
created: number | ||
data: Order | ||
id: string | ||
state: OrderState | ||
filled: bigint | ||
created: number | ||
data: Order | ||
} |
@@ -34,9 +34,9 @@ /* tslint:disable */ | ||
export function deposit( | ||
wallet_str: string, | ||
from_addr: string, | ||
mint: string, | ||
amount: string, | ||
permit_nonce: string, | ||
permit_deadline: string, | ||
permit_signature: string, | ||
wallet_str: string, | ||
from_addr: string, | ||
mint: string, | ||
amount: string, | ||
permit_nonce: string, | ||
permit_deadline: string, | ||
permit_signature: string, | ||
): any | ||
@@ -51,6 +51,6 @@ /** | ||
export function withdraw( | ||
wallet_str: string, | ||
mint: string, | ||
amount: string, | ||
destination_addr: string, | ||
wallet_str: string, | ||
mint: string, | ||
amount: string, | ||
destination_addr: string, | ||
): any | ||
@@ -67,8 +67,8 @@ /** | ||
export function new_order( | ||
wallet_str: string, | ||
id: string, | ||
base_mint: string, | ||
quote_mint: string, | ||
side: string, | ||
amount: string, | ||
wallet_str: string, | ||
id: string, | ||
base_mint: string, | ||
quote_mint: string, | ||
side: string, | ||
amount: string, | ||
): any | ||
@@ -88,3 +88,7 @@ /** | ||
*/ | ||
export function build_auth_headers(sk_root: string, req: string, current_timestamp: bigint): any[] | ||
export function build_auth_headers( | ||
sk_root: string, | ||
req: string, | ||
current_timestamp: bigint, | ||
): any[] | ||
/** | ||
@@ -91,0 +95,0 @@ * @param {string} seed |
@@ -1,55 +0,57 @@ | ||
import { defineChain } from "viem" | ||
import { defineChain } from 'viem' | ||
export const devnetChain = defineChain({ | ||
id: 473474, | ||
name: "Renegade Devnet", | ||
network: "Renegade Devnet", | ||
testnet: true, | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Ether", | ||
symbol: "ETH", | ||
id: 473474, | ||
name: 'Renegade Devnet', | ||
network: 'Renegade Devnet', | ||
testnet: true, | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: 'Ether', | ||
symbol: 'ETH', | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: ['https://dev.sequencer.renegade.fi'], | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: [`https://dev.sequencer.renegade.fi`], | ||
}, | ||
public: { | ||
http: [`https://dev.sequencer.renegade.fi`], | ||
}, | ||
public: { | ||
http: ['https://dev.sequencer.renegade.fi'], | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: "Explorer", | ||
url: "https://explorer.renegade.fi/", | ||
}, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: 'Explorer', | ||
url: 'https://explorer.renegade.fi/', | ||
}, | ||
}, | ||
}) | ||
export const testnetChain = defineChain({ | ||
id: 473474, | ||
name: "Renegade Testnet", | ||
network: "Renegade Testnet", | ||
testnet: true, | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Ether", | ||
symbol: "ETH", | ||
id: 473474, | ||
name: 'Renegade Testnet', | ||
network: 'Renegade Testnet', | ||
testnet: true, | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: 'Ether', | ||
symbol: 'ETH', | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: ['https://sequencer.renegade.fi'], | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: [`https://sequencer.renegade.fi`], | ||
}, | ||
public: { | ||
http: [`https://sequencer.renegade.fi`], | ||
}, | ||
public: { | ||
http: ['https://sequencer.renegade.fi'], | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: "Explorer", | ||
url: "https://explorer.renegade.fi/", | ||
}, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: 'Explorer', | ||
url: 'https://explorer.renegade.fi/', | ||
}, | ||
}, | ||
}) | ||
export const chain = process.env.NEXT_PUBLIC_RPC_URL?.includes("dev") ? devnetChain : testnetChain | ||
export const chain = process.env.NEXT_PUBLIC_RPC_URL?.includes('dev') | ||
? devnetChain | ||
: testnetChain |
/** Forked from https://github.com/epoberezkin/fast-deep-equal */ | ||
export function deepEqual(a: any, b: any) { | ||
if (a === b) return true | ||
if (a === b) return true | ||
if (a && b && typeof a === "object" && typeof b === "object") { | ||
if (a.constructor !== b.constructor) return false | ||
if (a && b && typeof a === 'object' && typeof b === 'object') { | ||
if (a.constructor !== b.constructor) return false | ||
let length: number | ||
let i: number | ||
let length: number | ||
let i: number | ||
if (Array.isArray(a) && Array.isArray(b)) { | ||
length = a.length | ||
if (length !== b.length) return false | ||
for (i = length; i-- !== 0; ) if (!deepEqual(a[i], b[i])) return false | ||
return true | ||
} | ||
if (Array.isArray(a) && Array.isArray(b)) { | ||
length = a.length | ||
if (length !== b.length) return false | ||
for (i = length; i-- !== 0; ) if (!deepEqual(a[i], b[i])) return false | ||
return true | ||
} | ||
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf() | ||
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString() | ||
if (a.valueOf !== Object.prototype.valueOf) | ||
return a.valueOf() === b.valueOf() | ||
if (a.toString !== Object.prototype.toString) | ||
return a.toString() === b.toString() | ||
const keys = Object.keys(a) | ||
length = keys.length | ||
if (length !== Object.keys(b).length) return false | ||
const keys = Object.keys(a) | ||
length = keys.length | ||
if (length !== Object.keys(b).length) return false | ||
for (i = length; i-- !== 0; ) | ||
if (!Object.prototype.hasOwnProperty.call(b, keys[i]!)) return false | ||
for (i = length; i-- !== 0; ) | ||
if (!Object.prototype.hasOwnProperty.call(b, keys[i]!)) return false | ||
for (i = length; i-- !== 0; ) { | ||
const key = keys[i] | ||
for (i = length; i-- !== 0; ) { | ||
const key = keys[i] | ||
if (key && !deepEqual(a[key], b[key])) return false | ||
} | ||
return true | ||
if (key && !deepEqual(a[key], b[key])) return false | ||
} | ||
// true if both NaN, false otherwise | ||
// biome-ignore lint/suspicious/noSelfCompare: <explanation> | ||
return a !== a && b !== b | ||
return true | ||
} | ||
// true if both NaN, false otherwise | ||
// biome-ignore lint/suspicious/noSelfCompare: <explanation> | ||
return a !== a && b !== b | ||
} |
type Reviver = (key: string, value: any) => any | ||
export function deserialize<type>(value: string, reviver?: Reviver): type { | ||
return JSON.parse(value, (key, value_) => { | ||
let value = value_ | ||
if (value?.__type === "bigint") value = BigInt(value.value) | ||
if (value?.__type === "Map") value = new Map(value.value) | ||
return reviver?.(key, value) ?? value | ||
}) | ||
return JSON.parse(value, (key, value_) => { | ||
let value = value_ | ||
if (value?.__type === 'bigint') value = BigInt(value.value) | ||
if (value?.__type === 'Map') value = new Map(value.value) | ||
return reviver?.(key, value) ?? value | ||
}) | ||
} |
@@ -1,21 +0,21 @@ | ||
import { formatUnits, parseUnits } from "viem" | ||
import { formatUnits, parseUnits } from 'viem' | ||
import type { Token } from "../types/token.js" | ||
import type { Token } from '../types/token.js' | ||
export function formatAmount(amount: bigint, token: Token) { | ||
const decimals = token.decimals | ||
if (!decimals) throw new Error(`Decimals not found for 0x${token.address}`) | ||
let formatted = formatUnits(amount, decimals) | ||
if (formatted.includes(".")) { | ||
const [integerPart, decimalPart = ""] = formatted.split(".") | ||
formatted = `${integerPart}.${decimalPart.substring(0, 2)}` | ||
} | ||
return formatted | ||
const decimals = token.decimals | ||
if (!decimals) throw new Error(`Decimals not found for 0x${token.address}`) | ||
let formatted = formatUnits(amount, decimals) | ||
if (formatted.includes('.')) { | ||
const [integerPart, decimalPart = ''] = formatted.split('.') | ||
formatted = `${integerPart}.${decimalPart.substring(0, 2)}` | ||
} | ||
return formatted | ||
} | ||
export function parseAmount(amount: string, token: Token) { | ||
const decimals = token.decimals | ||
if (!decimals) throw new Error(`Decimals not found for 0x${token.address}`) | ||
// TODO: Should try to fetch decimals from on chain | ||
return parseUnits(amount, decimals) | ||
const decimals = token.decimals | ||
if (!decimals) throw new Error(`Decimals not found for 0x${token.address}`) | ||
// TODO: Should try to fetch decimals from on chain | ||
return parseUnits(amount, decimals) | ||
} |
@@ -1,3 +0,3 @@ | ||
import { version } from "../version.js" | ||
import { version } from '../version.js' | ||
export const getVersion = () => `@renegade-fi/core@${version}` |
@@ -1,96 +0,107 @@ | ||
import axios from "axios" | ||
import JSONBigint from "json-bigint" | ||
import axios from 'axios' | ||
import JSONBigint from 'json-bigint' | ||
import { getSkRoot } from "../index.js" | ||
import { getSkRoot } from '../index.js' | ||
import { RENEGADE_AUTH_HEADER_NAME, RENEGADE_SIG_EXPIRATION_HEADER_NAME } from "../constants.js" | ||
import type { Config } from "../createConfig.js" | ||
import { | ||
RENEGADE_AUTH_HEADER_NAME, | ||
RENEGADE_SIG_EXPIRATION_HEADER_NAME, | ||
} from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
export async function postRelayerRaw(url: string, body: any, headers = {}) { | ||
try { | ||
const response = await axios.post(url, body, { headers }) | ||
// console.log(`POST ${url} with body: `, body, "response: ", response.data) | ||
// Process the response data as needed | ||
return response.data // Assuming the function should return the response data | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
if (error.response) { | ||
// The request was made and the server responded with a status code | ||
// that falls out of the range of 2xx | ||
console.error("Response error:", error.response.data) | ||
} else if (error.request) { | ||
// The request was made but no response was received | ||
console.error("Request error: No response received") | ||
} else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.error("Error:", error.message) | ||
} | ||
} else { | ||
// Non-Axios error | ||
console.error("Error:", error) | ||
} | ||
throw error // Rethrow the error for further handling or logging | ||
try { | ||
const response = await axios.post(url, body, { headers }) | ||
// console.log(`POST ${url} with body: `, body, "response: ", response.data) | ||
// Process the response data as needed | ||
return response.data // Assuming the function should return the response data | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
if (error.response) { | ||
// The request was made and the server responded with a status code | ||
// that falls out of the range of 2xx | ||
console.error('Response error:', error.response.data) | ||
} else if (error.request) { | ||
// The request was made but no response was received | ||
console.error('Request error: No response received') | ||
} else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.error('Error:', error.message) | ||
} | ||
} else { | ||
// Non-Axios error | ||
console.error('Error:', error) | ||
} | ||
throw error // Rethrow the error for further handling or logging | ||
} | ||
} | ||
export async function getRelayerRaw(url: string, headers = {}) { | ||
try { | ||
const response = await axios.get(url, { | ||
headers, | ||
transformResponse: data => { | ||
try { | ||
return JSONBigint({ useNativeBigInt: true }).parse(data) | ||
} catch (error) { | ||
return data | ||
} | ||
}, | ||
}) | ||
// console.log(`GET ${url} response: `, response.data) | ||
// Process the response data as needed | ||
return response.data // Assuming the function should return the response data | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
if (error.response) { | ||
// The request was made and the server responded with a status code | ||
// that falls out of the range of 2xx | ||
console.error("Response error:", error.response.data) | ||
} else if (error.request) { | ||
// The request was made but no response was received | ||
console.error("Request error: No response received") | ||
} else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.error("Error:", error.message) | ||
} | ||
} else { | ||
// Non-Axios error | ||
console.error("Error:", error) | ||
try { | ||
const response = await axios.get(url, { | ||
headers, | ||
transformResponse: (data) => { | ||
try { | ||
return JSONBigint({ useNativeBigInt: true }).parse(data) | ||
} catch (_error) { | ||
return data | ||
} | ||
throw error // Rethrow the error for further handling or logging | ||
}, | ||
}) | ||
// console.log(`GET ${url} response: `, response.data) | ||
// Process the response data as needed | ||
return response.data // Assuming the function should return the response data | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
if (error.response) { | ||
// The request was made and the server responded with a status code | ||
// that falls out of the range of 2xx | ||
console.error('Response error:', error.response.data) | ||
} else if (error.request) { | ||
// The request was made but no response was received | ||
console.error('Request error: No response received') | ||
} else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.error('Error:', error.message) | ||
} | ||
} else { | ||
// Non-Axios error | ||
console.error('Error:', error) | ||
} | ||
throw error // Rethrow the error for further handling or logging | ||
} | ||
} | ||
export async function postRelayerWithAuth(config: Config, url: string, body?: string) { | ||
const skRoot = await getSkRoot(config) | ||
const [auth, expiration] = config.utils.build_auth_headers( | ||
skRoot, | ||
body ?? "", | ||
BigInt(Date.now()), | ||
) | ||
const headers = { | ||
[RENEGADE_AUTH_HEADER_NAME]: auth, | ||
[RENEGADE_SIG_EXPIRATION_HEADER_NAME]: expiration, | ||
"Content-Type": "application/json", | ||
} | ||
return await postRelayerRaw(url, body, headers) | ||
export async function postRelayerWithAuth( | ||
config: Config, | ||
url: string, | ||
body?: string, | ||
) { | ||
const skRoot = await getSkRoot(config) | ||
const [auth, expiration] = config.utils.build_auth_headers( | ||
skRoot, | ||
body ?? '', | ||
BigInt(Date.now()), | ||
) | ||
const headers = { | ||
[RENEGADE_AUTH_HEADER_NAME]: auth, | ||
[RENEGADE_SIG_EXPIRATION_HEADER_NAME]: expiration, | ||
'Content-Type': 'application/json', | ||
} | ||
return await postRelayerRaw(url, body, headers) | ||
} | ||
export async function getRelayerWithAuth(config: Config, url: string) { | ||
const skRoot = await getSkRoot(config) | ||
const [auth, expiration] = config.utils.build_auth_headers(skRoot, "", BigInt(Date.now())) | ||
const headers = { | ||
[RENEGADE_AUTH_HEADER_NAME]: auth, | ||
[RENEGADE_SIG_EXPIRATION_HEADER_NAME]: expiration, | ||
"Content-Type": "application/json", | ||
} | ||
return await getRelayerRaw(url, headers) | ||
const skRoot = await getSkRoot(config) | ||
const [auth, expiration] = config.utils.build_auth_headers( | ||
skRoot, | ||
'', | ||
BigInt(Date.now()), | ||
) | ||
const headers = { | ||
[RENEGADE_AUTH_HEADER_NAME]: auth, | ||
[RENEGADE_SIG_EXPIRATION_HEADER_NAME]: expiration, | ||
'Content-Type': 'application/json', | ||
} | ||
return await getRelayerRaw(url, headers) | ||
} |
@@ -9,3 +9,3 @@ /** | ||
function getReferenceKey(keys: string[], cutoff: number) { | ||
return keys.slice(0, cutoff).join(".") || "." | ||
return keys.slice(0, cutoff).join('.') || '.' | ||
} | ||
@@ -21,11 +21,11 @@ | ||
function getCutoff(array: any[], value: any) { | ||
const { length } = array | ||
const { length } = array | ||
for (let index = 0; index < length; ++index) { | ||
if (array[index] === value) { | ||
return index + 1 | ||
} | ||
for (let index = 0; index < length; ++index) { | ||
if (array[index] === value) { | ||
return index + 1 | ||
} | ||
} | ||
return 0 | ||
return 0 | ||
} | ||
@@ -44,45 +44,45 @@ | ||
function createReplacer( | ||
replacer?: StandardReplacer | null | undefined, | ||
circularReplacer?: CircularReplacer | null | undefined, | ||
replacer?: StandardReplacer | null | undefined, | ||
circularReplacer?: CircularReplacer | null | undefined, | ||
): StandardReplacer { | ||
const hasReplacer = typeof replacer === "function" | ||
const hasCircularReplacer = typeof circularReplacer === "function" | ||
const hasReplacer = typeof replacer === 'function' | ||
const hasCircularReplacer = typeof circularReplacer === 'function' | ||
const cache: any[] = [] | ||
const keys: string[] = [] | ||
const cache: any[] = [] | ||
const keys: string[] = [] | ||
return function replace(this: any, key: string, value: any) { | ||
if (typeof value === "object") { | ||
if (cache.length) { | ||
const thisCutoff = getCutoff(cache, this) | ||
return function replace(this: any, key: string, value: any) { | ||
if (typeof value === 'object') { | ||
if (cache.length) { | ||
const thisCutoff = getCutoff(cache, this) | ||
if (thisCutoff === 0) { | ||
cache[cache.length] = this | ||
} else { | ||
cache.splice(thisCutoff) | ||
keys.splice(thisCutoff) | ||
} | ||
if (thisCutoff === 0) { | ||
cache[cache.length] = this | ||
} else { | ||
cache.splice(thisCutoff) | ||
keys.splice(thisCutoff) | ||
} | ||
keys[keys.length] = key | ||
keys[keys.length] = key | ||
const valueCutoff = getCutoff(cache, value) | ||
const valueCutoff = getCutoff(cache, value) | ||
if (valueCutoff !== 0) { | ||
return hasCircularReplacer | ||
? circularReplacer.call( | ||
this, | ||
key, | ||
value, | ||
getReferenceKey(keys, valueCutoff), | ||
) | ||
: `[ref=${getReferenceKey(keys, valueCutoff)}]` | ||
} | ||
} else { | ||
cache[0] = value | ||
keys[0] = key | ||
} | ||
if (valueCutoff !== 0) { | ||
return hasCircularReplacer | ||
? circularReplacer.call( | ||
this, | ||
key, | ||
value, | ||
getReferenceKey(keys, valueCutoff), | ||
) | ||
: `[ref=${getReferenceKey(keys, valueCutoff)}]` | ||
} | ||
} else { | ||
cache[0] = value | ||
keys[0] = key | ||
} | ||
} | ||
return hasReplacer ? replacer.call(this, key, value) : value | ||
} | ||
return hasReplacer ? replacer.call(this, key, value) : value | ||
} | ||
} | ||
@@ -102,17 +102,19 @@ | ||
export function serialize( | ||
value: any, | ||
replacer?: StandardReplacer | null | undefined, | ||
indent?: number | null | undefined, | ||
circularReplacer?: CircularReplacer | null | undefined, | ||
value: any, | ||
replacer?: StandardReplacer | null | undefined, | ||
indent?: number | null | undefined, | ||
circularReplacer?: CircularReplacer | null | undefined, | ||
) { | ||
return JSON.stringify( | ||
value, | ||
createReplacer((key, value_) => { | ||
let value = value_ | ||
if (typeof value === "bigint") value = { __type: "bigint", value: value_.toString() } | ||
if (value instanceof Map) value = { __type: "Map", value: Array.from(value_.entries()) } | ||
return replacer?.(key, value) ?? value | ||
}, circularReplacer), | ||
indent ?? undefined, | ||
) | ||
return JSON.stringify( | ||
value, | ||
createReplacer((key, value_) => { | ||
let value = value_ | ||
if (typeof value === 'bigint') | ||
value = { __type: 'bigint', value: value_.toString() } | ||
if (value instanceof Map) | ||
value = { __type: 'Map', value: Array.from(value_.entries()) } | ||
return replacer?.(key, value) ?? value | ||
}, circularReplacer), | ||
indent ?? undefined, | ||
) | ||
} |
type Callback = (message: unknown) => void | ||
export class WebSocketManager { | ||
private url: string | ||
private ws: WebSocket | null | ||
private subscriptions: Map<string, Callback> | ||
private maxRetries: number | ||
private retryCount: number | ||
private retryDelay: number | ||
private isConnected: boolean | ||
private url: string | ||
private ws: WebSocket | null | ||
private subscriptions: Map<string, Callback> | ||
private maxRetries: number | ||
private retryCount: number | ||
private retryDelay: number | ||
private isConnected: boolean | ||
constructor(url: string) { | ||
this.url = url | ||
this.ws = null | ||
this.subscriptions = new Map<string, Callback>() | ||
this.maxRetries = 5 | ||
this.retryCount = 0 | ||
this.retryDelay = 2000 // Initial retry delay in milliseconds | ||
this.isConnected = false | ||
constructor(url: string) { | ||
this.url = url | ||
this.ws = null | ||
this.subscriptions = new Map<string, Callback>() | ||
this.maxRetries = 5 | ||
this.retryCount = 0 | ||
this.retryDelay = 2000 // Initial retry delay in milliseconds | ||
this.isConnected = false | ||
if (typeof window !== "undefined") { | ||
window.addEventListener("focus", this.handleWindowFocus.bind(this)) | ||
} | ||
if (typeof window !== 'undefined') { | ||
window.addEventListener('focus', this.handleWindowFocus.bind(this)) | ||
} | ||
} | ||
connect(): void { | ||
if (this.isConnected || this.ws) { | ||
console.warn("WebSocket connection attempt aborted: already connected.") | ||
return | ||
} | ||
connect(): void { | ||
if (this.isConnected || this.ws) { | ||
console.warn('WebSocket connection attempt aborted: already connected.') | ||
return | ||
} | ||
this.ws = new WebSocket(this.url) | ||
this.ws = new WebSocket(this.url) | ||
this.ws.addEventListener("open", () => { | ||
console.log("[Price Reporter] WebSocket connected.") | ||
this.isConnected = true | ||
this.retryCount = 0 | ||
this.resubscribeAll() | ||
}) | ||
this.ws.addEventListener('open', () => { | ||
console.log('[Price Reporter] WebSocket connected.') | ||
this.isConnected = true | ||
this.retryCount = 0 | ||
this.resubscribeAll() | ||
}) | ||
this.ws.addEventListener("message", event => { | ||
try { | ||
const data = JSON.parse(event.data) | ||
if (this.subscriptions.has(data.topic)) { | ||
const callback = this.subscriptions.get(data.topic) | ||
if (callback) { | ||
callback(data.price) | ||
} | ||
} | ||
} catch (error) { | ||
console.error("Error parsing WebSocket message:", error) | ||
} | ||
}) | ||
this.ws.addEventListener('message', (event) => { | ||
try { | ||
const data = JSON.parse(event.data) | ||
if (this.subscriptions.has(data.topic)) { | ||
const callback = this.subscriptions.get(data.topic) | ||
if (callback) { | ||
callback(data.price) | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Error parsing WebSocket message:', error) | ||
} | ||
}) | ||
this.ws.addEventListener("error", error => { | ||
console.error("WebSocket error:", error) | ||
}) | ||
this.ws.addEventListener('error', (error) => { | ||
console.error('WebSocket error:', error) | ||
}) | ||
this.ws.addEventListener("close", () => { | ||
console.log("[Price Reporter] WebSocket closed. Attempting to reconnect...") | ||
this.isConnected = false | ||
this.ws = null | ||
this.reconnect() | ||
}) | ||
this.ws.addEventListener('close', () => { | ||
console.log( | ||
'[Price Reporter] WebSocket closed. Attempting to reconnect...', | ||
) | ||
this.isConnected = false | ||
this.ws = null | ||
this.reconnect() | ||
}) | ||
} | ||
private reconnect(): void { | ||
if (this.retryCount >= this.maxRetries) { | ||
console.error('[Price Reporter] Maximum reconnect attempts reached.') | ||
return | ||
} | ||
const backoffDelay = this.retryDelay * 2 ** this.retryCount | ||
const jitter = Math.random() * backoffDelay * 0.3 // Jitter up to 30% of the backoff delay | ||
const delayWithJitter = backoffDelay + jitter | ||
private reconnect(): void { | ||
if (this.retryCount >= this.maxRetries) { | ||
console.error("[Price Reporter] Maximum reconnect attempts reached.") | ||
return | ||
} | ||
const backoffDelay = this.retryDelay * Math.pow(2, this.retryCount) | ||
const jitter = Math.random() * backoffDelay * 0.3 // Jitter up to 30% of the backoff delay | ||
const delayWithJitter = backoffDelay + jitter | ||
setTimeout(() => { | ||
console.log( | ||
`[Price Reporter] Reconnecting attempt ${this.retryCount + 1}`, | ||
) | ||
this.retryCount++ | ||
this.connect() | ||
}, delayWithJitter) | ||
} | ||
setTimeout(() => { | ||
console.log(`[Price Reporter] Reconnecting attempt ${this.retryCount + 1}`) | ||
this.retryCount++ | ||
this.connect() | ||
}, delayWithJitter) | ||
private handleWindowFocus(): void { | ||
if (!this.isConnected) { | ||
console.log( | ||
'[Price Reporter] Window refocused. Attempting to reconnect...', | ||
) | ||
this.retryCount = 0 | ||
this.reconnect() | ||
} | ||
} | ||
private handleWindowFocus(): void { | ||
if (!this.isConnected) { | ||
console.log("[Price Reporter] Window refocused. Attempting to reconnect...") | ||
this.retryCount = 0 | ||
this.reconnect() | ||
} | ||
subscribe(topic: string, callback: Callback): void { | ||
if (!this.subscriptions.has(topic)) { | ||
this.subscriptions.set(topic, callback) | ||
if (this.isConnected && this.ws) { | ||
this.ws.send(JSON.stringify({ method: 'subscribe', topic })) | ||
} | ||
} | ||
} | ||
subscribe(topic: string, callback: Callback): void { | ||
if (!this.subscriptions.has(topic)) { | ||
this.subscriptions.set(topic, callback) | ||
if (this.isConnected && this.ws) { | ||
this.ws.send(JSON.stringify({ method: "subscribe", topic })) | ||
} | ||
} | ||
} | ||
private resubscribeAll(): void { | ||
this.subscriptions.forEach((_, topic) => { | ||
if (this.isConnected && this.ws) { | ||
this.ws.send(JSON.stringify({ method: 'subscribe', topic })) | ||
} | ||
}) | ||
} | ||
private resubscribeAll(): void { | ||
this.subscriptions.forEach((_, topic) => { | ||
if (this.isConnected && this.ws) { | ||
this.ws.send(JSON.stringify({ method: "subscribe", topic })) | ||
} | ||
}) | ||
close(): void { | ||
if (this.ws) { | ||
this.ws.close() | ||
this.isConnected = false | ||
this.ws = null | ||
} | ||
close(): void { | ||
if (this.ws) { | ||
this.ws.close() | ||
this.isConnected = false | ||
this.ws = null | ||
} | ||
} | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = "0.0.1" | ||
export const version = '0.0.1' |
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
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
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
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
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
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
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
5121
272060