Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NIM - CRC swap #502

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

feat: add NIM - CRC swap #502

wants to merge 13 commits into from

Conversation

onmax
Copy link
Member

@onmax onmax commented Jun 18, 2024

No description provided.

@onmax onmax force-pushed the onmax/sinpe branch 3 times, most recently from 56e493b to adcac24 Compare June 18, 2024 19:37
src/request/sign-swap/SignSwapApi.js Outdated Show resolved Hide resolved
src/request/sign-swap/index.html Outdated Show resolved Hide resolved
src/request/swap-iframe/SwapIFrameApi.js Outdated Show resolved Hide resolved
src/request/swap-iframe/SwapIFrameApi.js Outdated Show resolved Hide resolved
src/request/sign-swap/SignSwap.js Outdated Show resolved Hide resolved
src/request/sign-swap/SignSwap.js Outdated Show resolved Hide resolved
src/request/sign-swap/SignSwap.js Outdated Show resolved Hide resolved
src/request/sign-swap/SignSwap.js Outdated Show resolved Hide resolved
client/src/PublicRequest.ts Outdated Show resolved Hide resolved
src/request/sign-swap/SignSwapApi.js Outdated Show resolved Hide resolved
@onmax onmax marked this pull request as ready for review August 13, 2024 14:45
@onmax onmax requested a review from sisou August 13, 2024 14:45
Copy link
Member

@danimoh danimoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things which I think should be improved:

  • There's the assumption in many places in the code that only one side of the swap is a fiat currency. This should be enforced by the request parser.
  • I don't think that fractional CRC amounts should be displayed.
  • Quite a lot of code repetition / copy-paste between EUR and CRC handling, which can in most cases be reasonably well be generalized and merged.
  • Some code style suggestions.

I think at a minimum, the stricter parsing and handling of fractional CRC amounts should be addressed, so I'm requesting changes.

src/assets/icons/sinpe-movil.svg Outdated Show resolved Hide resolved
? redeemTx.fee
: 0;

const theirFee = fundTx.type === 'EUR' ? fundFees.processing : redeemFees.processing;
const theirFee = fundTx.type === 'EUR' || fundTx.type === 'CRC'
? fundFees.processing : redeemFees.processing;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? fundFees.processing : redeemFees.processing;
? fundFees.processing
: redeemFees.processing;

src/components/SwapFeesTooltip.js Outdated Show resolved Hide resolved
@@ -0,0 +1,3 @@
const CrcConstants = { // eslint-disable-line no-unused-vars
CENTS_PER_COIN: 100,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Historically, CRC did in fact have cents but those are not in circulation anymore. Are the amounts in request types in CRC cents or CRC? Until seeing this line, I assumed CRC, but in any case, a comment should be added in PublicRequest to clarify this.

Are fractional CRC amounts also displayed in the UI? In that case, I don't think we should do so, except for exchange rates.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we added the wallet exchange logic, all Oasis fiat was in EUR. Now the wallet uses multiple / 100 conversions from cents to coins. See here for an example.

To keep things simple in the Wallet PR, I used 2 decimal places for the CRC, which Jeff confirmed is valid, though less common. This gives us more precision and is still a correct format while keeping the PR as simple as possible without breaking changes for EUR swaps.

Let me know your thoughts on this trade-off.

Comment on lines +1 to +19
/* global CrcConstants */

class CrcUtils { // eslint-disable-line no-unused-vars
/**
* @param {number} coins CRC amount in decimal
* @returns {number} Number of CRC cents
*/
static coinsToCents(coins) {
return Math.round(coins * CrcConstants.CENTS_PER_COIN);
}

/**
* @param {number} cents Number of CRC cents
* @returns {number} CRC count in decimal
*/
static centsToCoins(cents) {
return cents / CrcConstants.CENTS_PER_COIN;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, these should be combined with EuroUtils into FiatUtils, in a similar fashion as the CryptoUtils, which are also not individual utils for each crypto asset, or if they are, they provide more utilities specific to that crypto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have all the assets under CryptoUtils (both fiat and crypto). Maybe the CryptoUtils name is not the best, but renaming the class should be another PR?

src/request/sign-swap/SignSwapApi.js Show resolved Hide resolved
src/request/sign-swap/SignSwapApi.js Outdated Show resolved Hide resolved
src/request/swap-iframe/SwapIFrameApi.js Outdated Show resolved Hide resolved
src/request/swap-iframe/SwapIFrameApi.js Outdated Show resolved Hide resolved
src/request/swap-iframe/SwapIFrameApi.js Outdated Show resolved Hide resolved
@danimoh
Copy link
Member

danimoh commented Sep 30, 2024

Another question: the commit history refers to NIM-CRC swaps, but in the code I didn't see anything that specifically disallows any other CRC swaps, e.g. BTC-CRC. Are those possible, or should they be disallowed by the RequestParser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants