Fix OKX integration approve transaction #104
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Added implementation for getting OKX smart contract address which is used during swap of a particular token handled by the OKX dex. This address needs to be used to set allowances (returned in
dex::Swap::allowance
).Implementation
OKX smart contract address is taken from
/approve-transaction
endpoint (documentation) for particular sell token. From my observations I saw at least two different smart contract addresses returned by this endpoint (for different tokens, for one token always same address was returned).Added generic function
send()
which handles preparation, http roundtrip and errors handling for different OKX API calls.Map of: token address <=> OKX smart contract address for that token is stored in non-persistent LRU cache (size of 1000 items). Rust interior mutability pattern was used to simplify the implementation over the whole application (only changes to the okx module was needed).
Tests
Updated tests with additional endpoint requests mocks, added assert to api call test which verifies that allowance address.