Skip to content

Commit

Permalink
core: add external config, modify BaseConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Dec 24, 2024
1 parent 59625cb commit 7b79d68
Show file tree
Hide file tree
Showing 38 changed files with 159 additions and 72 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/actions/assembleExternalQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function assembleExternalQuote(
)

const res = await postWithSymmetricKey(config, {
url: config.getAuthServerUrl(ASSEMBLE_EXTERNAL_MATCH_ROUTE),
url: config.getBaseUrl(ASSEMBLE_EXTERNAL_MATCH_ROUTE),
body,
key: symmetricKey,
headers: {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/assignOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export async function assignOrder(
parameters: AssignOrderParameters,
) {
const { orderId, matchingPool } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

try {
await postRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_ASSIGN_ORDER_ROUTE(orderId, matchingPool)),
getBaseUrl(ADMIN_ASSIGN_ORDER_ROUTE(orderId, matchingPool)),
)
} catch (error) {
console.error(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/cancelOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function cancelOrder(
): Promise<CancelOrderReturnType> {
const { id } = parameters
const {
getRelayerBaseUrl,
getBaseUrl,
utils,
state: { seed },
} = config
Expand All @@ -35,7 +35,7 @@ export async function cancelOrder(
try {
const res = await postRelayerWithAuth(
config,
getRelayerBaseUrl(CANCEL_ORDER_ROUTE(walletId, id)),
getBaseUrl(CANCEL_ORDER_ROUTE(walletId, id)),
body,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/cancelOrderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export async function cancelOrderRequest(
parameters: CancelOrderRequestParameters,
): Promise<CancelOrderRequestReturnType> {
const { request, id } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

const walletId = getWalletId(config)

try {
const res = await postRelayerWithAuth(
config,
getRelayerBaseUrl(CANCEL_ORDER_ROUTE(walletId, id)),
getBaseUrl(CANCEL_ORDER_ROUTE(walletId, id)),
request,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/createMatchingPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export async function createMatchingPool(
parameters: CreateMatchingPoolParameters,
) {
const { matchingPool } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

try {
await postRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_MATCHING_POOL_CREATE_ROUTE(matchingPool)),
getBaseUrl(ADMIN_MATCHING_POOL_CREATE_ROUTE(matchingPool)),
)
} catch (error) {
console.error(`Failed to create matching pool ${matchingPool}`, {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/createOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function createOrder(
allowExternalMatches = false,
} = parameters
const {
getRelayerBaseUrl,
getBaseUrl,
utils,
state: { seed },
} = config
Expand All @@ -63,7 +63,7 @@ export async function createOrder(
try {
const res = await postRelayerWithAuth(
config,
getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId)),
getBaseUrl(WALLET_ORDERS_ROUTE(walletId)),
body,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/createOrderInMatchingPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function createOrderInMatchingPool(
matchingPool,
} = parameters
const {
getRelayerBaseUrl,
getBaseUrl,
utils,
state: { seed },
} = config
Expand All @@ -57,7 +57,7 @@ export async function createOrderInMatchingPool(
try {
const res = await postRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_CREATE_ORDER_IN_MATCHING_POOL_ROUTE(walletId)),
getBaseUrl(ADMIN_CREATE_ORDER_IN_MATCHING_POOL_ROUTE(walletId)),
body,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/createOrderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export async function createOrderRequest(
parameters: CreateOrderRequestParameters,
): Promise<CreateOrderRequestReturnType> {
const { request } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

const walletId = getWalletId(config)

try {
const res = await postRelayerWithAuth(
config,
getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId)),
getBaseUrl(WALLET_ORDERS_ROUTE(walletId)),
request,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/createWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type CreateWalletReturnType = ReturnType<typeof waitForWalletIndexing>

export async function createWallet(config: Config): CreateWalletReturnType {
const {
getRelayerBaseUrl,
getBaseUrl,
utils,
state: { seed },
} = config
Expand All @@ -20,7 +20,7 @@ export async function createWallet(config: Config): CreateWalletReturnType {
}

const res = await postRelayerRaw(
getRelayerBaseUrl(CREATE_WALLET_ROUTE),
getBaseUrl(CREATE_WALLET_ROUTE),
body,
headers,
)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function deposit(
const { fromAddr, mint, amount, permitNonce, permitDeadline, permit } =
parameters
const {
getRelayerBaseUrl,
getBaseUrl,
utils,
state: { seed },
} = config
Expand All @@ -56,7 +56,7 @@ export async function deposit(
try {
const res = await postRelayerWithAuth(
config,
getRelayerBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)),
getBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)),
body,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/depositRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export async function depositRequest(
parameters: DepositRequestParameters,
): Promise<DepositRequestReturnType> {
const { request } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

const walletId = getWalletId(config)

try {
const res = await postRelayerWithAuth(
config,
getRelayerBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)),
getBaseUrl(DEPOSIT_BALANCE_ROUTE(walletId)),
request,
)
console.log(`task update-wallet(${res.task_id}): ${walletId}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/destroyMatchingPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export async function destroyMatchingPool(
parameters: DestroyMatchingPoolParameters,
) {
const { matchingPool } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

try {
await postRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_MATCHING_POOL_DESTROY_ROUTE(matchingPool)),
getBaseUrl(ADMIN_MATCHING_POOL_DESTROY_ROUTE(matchingPool)),
)
} catch (error) {
console.error(`Failed to destroy matching pool ${matchingPool}`, {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getBackOfQueueWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export async function getBackOfQueueWallet(
parameters: GetBackOfQueueWalletParameters = {},
): Promise<GetBackOfQueueWalletReturnType> {
const { filterDefaults } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(BACK_OF_QUEUE_WALLET_ROUTE(walletId)),
getBaseUrl(BACK_OF_QUEUE_WALLET_ROUTE(walletId)),
)
if (!res.wallet) {
throw new BaseError('Back of queue wallet not found')
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { getWalletId } from './getWalletId.js'
export type GetBalancesReturnType = Promise<Balance[]>

export async function getBalances(config: Config): GetBalancesReturnType {
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(GET_BALANCES_ROUTE(walletId)),
getBaseUrl(GET_BALANCES_ROUTE(walletId)),
)
return res.balances
}
2 changes: 1 addition & 1 deletion packages/core/src/actions/getExternalMatchBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function getExternalMatchBundle(
)

const res = await postWithSymmetricKey(config, {
url: config.getAuthServerUrl(REQUEST_EXTERNAL_MATCH_ROUTE),
url: config.getBaseUrl(REQUEST_EXTERNAL_MATCH_ROUTE),
body,
key: symmetricKey,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/getExternalMatchQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function getExternalMatchQuote(
)

const res = await postWithSymmetricKey(config, {
url: config.getAuthServerUrl(REQUEST_EXTERNAL_MATCH_QUOTE_ROUTE),
url: config.getBaseUrl(REQUEST_EXTERNAL_MATCH_QUOTE_ROUTE),
body,
key: symmetricKey,
headers: {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getNetworkOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export type GetNetworkOrdersErrorType = BaseErrorType
export async function getNetworkOrders(
config: Config,
): Promise<GetNetworkOrdersReturnType> {
const { getRelayerBaseUrl } = config
const res = await getRelayerRaw(getRelayerBaseUrl(GET_NETWORK_ORDERS_ROUTE))
const { getBaseUrl } = config
const res = await getRelayerRaw(getBaseUrl(GET_NETWORK_ORDERS_ROUTE))
if (!res.orders) {
throw new BaseError('No orders found')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getOpenOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export async function getOpenOrders(
config: Config,
parameters: GetOpenOrdersParams = {},
): Promise<GetOpenOrdersReturnType> {
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

const url = new URL(getRelayerBaseUrl(ADMIN_OPEN_ORDERS_ROUTE))
const url = new URL(getBaseUrl(ADMIN_OPEN_ORDERS_ROUTE))

if (parameters.matchingPool) {
url.searchParams.set('matching_pool', parameters.matchingPool)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export async function getOrder(
parameters: GetOrderParameters,
): Promise<GetOrderReturnType> {
const { id } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(GET_ORDER_BY_ID_ROUTE(walletId, id)),
getBaseUrl(GET_ORDER_BY_ID_ROUTE(walletId, id)),
)
return res.order
}
4 changes: 2 additions & 2 deletions packages/core/src/actions/getOrderHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export async function getOrderHistory(
config: Config,
parameters: GetOrderHistoryParameters = {},
): Promise<GetOrderHistoryReturnType> {
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const { limit } = parameters
const walletId = getWalletId(config)

let url = getRelayerBaseUrl(ORDER_HISTORY_ROUTE(walletId))
let url = getBaseUrl(ORDER_HISTORY_ROUTE(walletId))

if (limit !== undefined) {
const searchParams = new URLSearchParams({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getOrderMatchingPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export async function getOrderMatchingPool(
parameters: GetOrderMatchingPoolParameters,
): Promise<GetOrderMatchingPoolReturnType> {
const { orderId } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

try {
const res = await getRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_GET_ORDER_MATCHING_POOL_ROUTE(orderId)),
getBaseUrl(ADMIN_GET_ORDER_MATCHING_POOL_ROUTE(orderId)),
)

return res.matching_pool
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getOrderMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export async function getOrderMetadata(
parameters: GetOrderMetadataParameters,
): Promise<GetOrderMetadataReturnType> {
const { id } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config

const url = new URL(getRelayerBaseUrl(ADMIN_ORDER_METADATA_ROUTE(id)))
const url = new URL(getBaseUrl(ADMIN_ORDER_METADATA_ROUTE(id)))

if (parameters.includeFillable) {
url.searchParams.set('include_fillable', String(true))
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { getWalletId } from './getWalletId.js'
export type GetOrdersReturnType = Order[]

export async function getOrders(config: Config): Promise<GetOrdersReturnType> {
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(WALLET_ORDERS_ROUTE(walletId)),
getBaseUrl(WALLET_ORDERS_ROUTE(walletId)),
)
return res.orders
}
4 changes: 2 additions & 2 deletions packages/core/src/actions/getTaskHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export type GetTaskHistoryErrorType = BaseErrorType
export async function getTaskHistory(
config: Config,
): Promise<GetTaskHistoryReturnType> {
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(TASK_HISTORY_ROUTE(walletId)),
getBaseUrl(TASK_HISTORY_ROUTE(walletId)),
)
if (!res.tasks) {
throw new BaseError('No tasks found')
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/getTaskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type { OldTask as Task } from '../types/wallet.js'
export type GetTaskQueueReturnType = Promise<Task[]>

export async function getTaskQueue(config: Config): GetTaskQueueReturnType {
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(GET_TASK_QUEUE_ROUTE(walletId)),
getBaseUrl(GET_TASK_QUEUE_ROUTE(walletId)),
)
return res.tasks
}
4 changes: 2 additions & 2 deletions packages/core/src/actions/getTaskStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export async function getTaskStatus(
parameters: GetTaskStatusParameters,
): GetTaskStatusReturnType {
const { id } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(GET_TASK_STATUS_ROUTE(id)),
getBaseUrl(GET_TASK_STATUS_ROUTE(id)),
)
return res.status
}
4 changes: 2 additions & 2 deletions packages/core/src/actions/getWalletFromRelayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export async function getWalletFromRelayer(
parameters: GetWalletFromRelayerParameters = {},
): Promise<GetWalletFromRelayerReturnType> {
const { filterDefaults } = parameters
const { getRelayerBaseUrl } = config
const { getBaseUrl } = config
const walletId = getWalletId(config)
const res = await getRelayerWithAuth(
config,
getRelayerBaseUrl(GET_WALLET_ROUTE(walletId)),
getBaseUrl(GET_WALLET_ROUTE(walletId)),
)
if (!res.wallet) {
throw new BaseError('Wallet not found')
Expand Down
Loading

0 comments on commit 7b79d68

Please sign in to comment.