Skip to content

fix: use same feature for ofc tokens #6702

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mukeshsp
Copy link
Contributor

@mukeshsp mukeshsp commented Aug 13, 2025

We observed that separate features are being maintained for OFC tokens, but they should use the same features as their corresponding native coin or token. I confirmed with the Go team (with Manav) that currently, the OFC feature from the SDK isn’t being used—instead, they have a hardcoded mapping in the Prime service.

Problem:
Currently, the mapping of OFC tokens with Trust is based on hardcoded data in the Prime service. This means that whenever a new token needs to be onboarded, the hardcoded file has to be updated, which slows down the onboarding process.

Solution:
Instead of using hardcoded mappings, we should leverage the feature flags defined for OFC tokens. To enable this, we first need to correct the feature flags for OFC tokens.

Ticket: WIN-6707

@mukeshsp mukeshsp force-pushed the fix-ofc-features branch 2 times, most recently from fe40ced to 7532524 Compare August 14, 2025 08:39
@mukeshsp mukeshsp marked this pull request as ready for review August 14, 2025 08:43
@mukeshsp mukeshsp requested review from a team as code owners August 14, 2025 08:43
@mukeshsp mukeshsp marked this pull request as draft August 14, 2025 08:43
@mukeshsp mukeshsp marked this pull request as ready for review August 14, 2025 10:28
Copy link
Contributor

@sampras-saha sampras-saha left a comment

Choose a reason for hiding this comment

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

Test cases are failing. Please check

@mukeshsp mukeshsp requested a review from sampras-saha August 14, 2025 14:20
@mukeshsp
Copy link
Contributor Author

Test cases are failing. Please check

that is flaky test which is not related to my change

Copilot

This comment was marked as outdated.

sampras-saha
sampras-saha previously approved these changes Aug 18, 2025
Copy link
Contributor

@sampras-saha sampras-saha left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the OFC (off-chain) coin feature system to ensure that OFC tokens inherit features from their corresponding native coins, specifically focusing on custody-related features. The changes implement a mechanism to dynamically filter and apply features from base coins to their OFC counterparts.

  • Implements a feature inheritance system for OFC tokens to match native coin features
  • Adds test coverage to validate feature parity between OFC and native coins
  • Updates existing test logic to handle specific edge cases for CELO-based coins

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.

File Description
modules/statics/src/ofc.ts Adds getFilteredFeatures function and applies feature inheritance to all OFC token creation functions
modules/statics/test/unit/ofcCoinParity.ts Adds new test to verify OFC tokens have matching custody features with their base coins
modules/statics/test/unit/coins.ts Updates custody feature test to exclude specific CELO OFC variants and removes non-SD coin feature test
modules/statics/src/networkFeatureMapForTokens.ts Changes OFC network feature mapping from using default features to an empty array

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@@ -1,5 +1,7 @@
import { BaseCoin, BaseUnit, CoinFeature, CoinKind, KeyCurve, UnderlyingAsset } from './base';
import { BaseNetwork, Networks, OfcNetwork } from './networks';
import { allCoinsAndTokens } from './allCoinsAndToken';
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The import path './allCoinsAndToken' appears to be missing an 's' at the end. It should likely be './allCoinsAndTokens' to match standard naming conventions.

Suggested change
import { allCoinsAndTokens } from './allCoinsAndToken';
import { allCoinsAndTokens } from './allCoinsAndTokens';

Copilot uses AI. Check for mistakes.

const ofcFeatureSet = new Set(ofcFeatures);
const baseFeatureSet = new Set(baseFeatures);
const missingFeatures = Array.from(baseFeatureSet).filter(
(feature) => !ofcFeatureSet.has(feature) && feature.startsWith('custody')
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The filter condition feature.startsWith('custody') is hardcoded and may miss other custody-related features that don't follow this naming convention. Consider using a more robust way to identify custody features, such as checking against a predefined list of custody feature constants.

Suggested change
(feature) => !ofcFeatureSet.has(feature) && feature.startsWith('custody')
(feature) => !ofcFeatureSet.has(feature) && CUSTODY_FEATURES.has(feature)

Copilot uses AI. Check for mistakes.

if (!allCoinsAndTokensMap) {
allCoinsAndTokensMap = CoinMap.fromCoins(allCoinsAndTokens);
}
return allCoinsAndTokensMap;
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The lazy initialization pattern with a module-level variable could lead to issues in testing environments where the module might be reloaded. Consider implementing a more robust singleton pattern or making this function pure by accepting the coins map as a parameter.

Suggested change
return allCoinsAndTokensMap;
// Removed module-level cache to avoid issues with module reloads in testing environments.
const getAllCoinsAndTokensMap = (): CoinMap => {
return CoinMap.fromCoins(allCoinsAndTokens);

Copilot uses AI. Check for mistakes.

gianchandania
gianchandania previously approved these changes Aug 19, 2025
@mukeshsp mukeshsp force-pushed the fix-ofc-features branch 2 times, most recently from 6b23a5c to 63719d6 Compare August 19, 2025 13:27
@mukeshsp mukeshsp requested a review from gianchandania August 19, 2025 13:28
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this should rather be named someCoinsAndTokens 😉
What's the logic that determines which ones are defined here and which ones in coins.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all the native coins and token will be in [allCoinsAndTokens.ts] and ofc tokens are in ofc.ts file

Copy link
Contributor

@FloBitGo FloBitGo left a comment

Choose a reason for hiding this comment

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

Please fix the failing tests

@mukeshsp
Copy link
Contributor Author

Please fix the failing tests

this is a flaky test which is failing for many PRs and we are looking into it parallelly

@mukeshsp mukeshsp requested a review from FloBitGo August 19, 2025 14:33
Copy link
Contributor

@FloBitGo FloBitGo left a comment

Choose a reason for hiding this comment

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

Code is OK, test failure is unrelated and will get fixed in another PR

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.

4 participants