-
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
20 changed files
with
270 additions
and
70 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,50 @@ | ||
import invariant from 'tiny-invariant' | ||
import { | ||
RENEGADE_API_KEY_HEADER, | ||
REQUEST_EXTERNAL_MATCH_ROUTE, | ||
} from '../constants.js' | ||
import type { Config } from '../createConfig.js' | ||
import type { BaseErrorType } from '../errors/base.js' | ||
import { postRelayerWithAuth } from '../utils/http.js' | ||
import { toHex } from 'viem' | ||
|
||
export type GetAtomicMatchParameters = { | ||
base: `0x${string}` | ||
quote: `0x${string}` | ||
side: 'buy' | 'sell' | ||
amount: bigint | ||
minFillSize?: bigint | ||
} | ||
|
||
export type GetAtomicMatchReturnType = any | ||
|
||
export type GetAtomicMatchErrorType = BaseErrorType | ||
|
||
export async function getAtomicMatch( | ||
config: Config, | ||
parameters: GetAtomicMatchParameters, | ||
): Promise<GetAtomicMatchReturnType> { | ||
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, | ||
}, | ||
}) | ||
return res | ||
} |
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.