-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm, core: add action to request atomic matches
- Loading branch information
Showing
21 changed files
with
270 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import invariant from 'tiny-invariant' | ||
import { toHex } from 'viem' | ||
import { | ||
RENEGADE_API_KEY_HEADER, | ||
REQUEST_EXTERNAL_MATCH_ROUTE, | ||
} from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import { BaseError, type BaseErrorType } from '../errors/base.js' | ||
import type { ExternalMatchResponse } from '../types/externalOrder.js' | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
|
||
export type GetAtomicMatchBundleParameters = { | ||
base: `0x${string}` | ||
quote: `0x${string}` | ||
side: 'buy' | 'sell' | ||
amount: bigint | ||
minFillSize?: bigint | ||
} | ||
|
||
export type GetAtomicMatchBundleReturnType = ExternalMatchResponse | ||
|
||
export type GetAtomicMatchBundleErrorType = BaseErrorType | ||
|
||
export async function getAtomicMatchBundle( | ||
config: Config, | ||
parameters: GetAtomicMatchBundleParameters, | ||
): Promise<GetAtomicMatchBundleReturnType> { | ||
const { base, quote, side, amount, minFillSize = BigInt(0) } = parameters | ||
const { apiSecret, apiKey } = config | ||
invariant(apiSecret, 'API secret not specified in config') | ||
invariant(apiKey, 'API key not specified in config') | ||
const symmetricKey = config.utils.b64_to_hex_hmac_key(apiSecret) | ||
|
||
const body = config.utils.new_external_order( | ||
base, | ||
quote, | ||
side, | ||
toHex(amount), | ||
toHex(minFillSize), | ||
) | ||
|
||
const res = await postRelayerWithAuth(config, { | ||
url: config.getAuthServerUrl(REQUEST_EXTERNAL_MATCH_ROUTE), | ||
body, | ||
key: symmetricKey, | ||
headers: { | ||
[RENEGADE_API_KEY_HEADER]: apiKey, | ||
}, | ||
}) | ||
if (!res.match_bundle) { | ||
throw new BaseError('No match bundle found') | ||
} | ||
return res.match_bundle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.