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

Release/v1.52.0 #242

Merged
merged 2 commits into from
Sep 18, 2024
Merged

Release/v1.52.0 #242

merged 2 commits into from
Sep 18, 2024

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Sep 18, 2024

  • Added OFAC restricted addresses validations

Summary by CodeRabbit

  • New Features

    • Introduced an OfacChecker for compliance checks against the OFAC blacklist.
    • Enhanced client initialization to fail if the account address is blacklisted.
    • Added methods to check the compliance of granter addresses during authorization processes.
    • Implemented a mechanism to download and manage the OFAC list dynamically.
  • Bug Fixes

    • Improved error handling when creating clients with blacklisted addresses.
  • Tests

    • Added a new test suite to validate OFAC compliance functionality.

Copy link

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduce an OfacChecker to the chainClient structure, enabling compliance checks against the OFAC (Office of Foreign Assets Control) list. The OfacChecker is instantiated upon client creation, checking for blacklisted addresses and modifying several authorization methods to enforce compliance. Additionally, a new test suite is added to validate the OFAC functionality, and a new file manages the OFAC list. A JSON file containing blacklisted addresses is also introduced, along with a program to download the OFAC list.

Changes

File Path Change Summary
client/chain/chain.go Introduced OfacChecker in chainClient, modified client initialization and authorization methods to include OFAC compliance checks.
client/chain/chain_test.go Added OfacTestSuite for testing OFAC compliance, including setup and teardown methods, and a test for validating the OFAC list functionality.
client/chain/ofac.go Implemented OfacChecker struct with methods for downloading, loading, and checking blacklisted addresses against the OFAC list.
client/metadata/ofac.json Introduced a JSON file containing a list of blacklisted Ethereum addresses for OFAC compliance.
examples/chain/ofac/1_DownloadOfacList/example.go Implemented a program to download the OFAC list using the Injective Labs SDK.

Possibly related PRs

  • (feat) Add OFAC list check #236: The changes in this PR directly implement an OfacChecker in the chainClient structure, which is a core part of the main PR's functionality, enhancing compliance checks against the OFAC list.

Suggested reviewers

  • aarmoa

Poem

In the land of code where rabbits hop,
An OfacChecker helps us stop,
With lists of names that we must heed,
Compliance is now our noble creed.
So let us code with joy and cheer,
For a safer world is drawing near! 🐇✨


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (2)
examples/chain/ofac/1_DownloadOfacList/example.go (1)

9-11: Consider handling the error gracefully.

Panicking on error is not the best practice for a production-grade application. Instead of panicking, consider handling the error gracefully. For example:

err := chainclient.DownloadOfacList()
if err != nil {
    log.Printf("Failed to download OFAC list: %v", err)
    return
}
client/metadata/ofac.json (1)

4-5: Clean up the duplicate Ethereum addresses.

There are a few duplicate Ethereum addresses in the list:

  • 0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff appears on lines 4 and 5.
  • 0x2f389ce8bd8ff92de3402ffce4691d17fc4f6535 appears on lines 7 and 8.
  • 0x4f47bc496083c727c5fbe3ce9cdf2b0f6496270c appears on lines 14, 15, and 16.
  • 0xb6f5ec1a0a9cd1526536d3f0426c429529471f40 appears on lines 33, 34, and 35.

While the presence of duplicates does not affect the functionality, it's recommended to clean them up for better maintainability.

Apply this diff to remove the duplicate addresses:

-  "0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff",
   "0x1da5821544e25c636c1417ba96ade4cf6d2f9b5a",
-  "0x2f389ce8bd8ff92de3402ffce4691d17fc4f6535",
   "0x2f50508a8a3d323b91336fa3ea6ae50e55f32185",
   "0x308ed4b7b49797e1a98d3818bff6fe5385410370",
   "0x3cbded43efdaf0fc77b9c55f6fc9988fcc9b757d",
   "0x3efa30704d2b8bbac821307230376556cf8cc39e",
   "0x48549a34ae37b12f6a30566245176994e17c6b4a",
-  "0x4f47bc496083c727c5fbe3ce9cdf2b0f6496270c",
-  "0x4f47bc496083c727c5fbe3ce9cdf2b0f6496270c",
   "0x530a64c0ce595026a4a556b703644228179e2d57",
   "0x5512d943ed1f7c8a43f3435c85f7ab68b30121b0",
   "0x5a7a51bfb49f190e5a6060a5bc6052ac14a3b59f",
   "0x5f48c2a71b2cc96e3f0ccae4e39318ff0dc375b2",
   "0x6be0ae71e6c41f2f9d0d1a3b8d0f75e6f6a0b46e",
   "0x6f1ca141a28907f78ebaa64fb83a9088b02a8352",
   "0x746aebc06d2ae31b71ac51429a19d54e797878e9",
   "0x77777feddddffc19ff86db637967013e6c6a116c",
   "0x797d7ae72ebddcdea2a346c1834e04d1f8df102b",
   "0x8576acc5c05d6ce88f4e49bf65bdf0c62f91353c",
   "0x901bb9583b24d97e995513c6778dc6888ab6870e",
   "0x961c5be54a2ffc17cf4cb021d863c42dacd47fc1",
   "0x97b1043abd9e6fc31681635166d430a458d14f9c",
   "0x9c2bc757b66f24d60f016b6237f8cdd414a879fa",
   "0x9f4cda013e354b8fc285bf4b9a60460cee7f7ea9",
   "0xa7e5d5a720f06526557c513402f2e6b5fa20b008",
-  "0xb6f5ec1a0a9cd1526536d3f0426c429529471f40",
-  "0xb6f5ec1a0a9cd1526536d3f0426c429529471f40",
   "0xc455f7fd3e0e12afd51fba5c106909934d8a0e4a",
   "0xca0840578f57fe71599d29375e16783424023357",
   "0xd0975b32cea532eadddfc9c60481976e39db3472",
   "0xd882cfc20f52f2599d84b8e8d58c7fb62cfe344b",
-  "0xd882cfc20f52f2599d84b8e8d58c7fb62cfe344b",
   "0xe1d865c3d669dcc8c57c8d023140cb204e672ee4",
   "0xe7aa314c77f4233c18c6cc84384a9247c0cf367b",
   "0xed6e0a7e4ac94d976eebfb82ccf777a3c6bad921",
   "0xf3701f445b6bdafedbca97d1e477357839e4120d",
   "0xfac583c0cf07ea434052c49115a4682172ab6b4f",
   "0xfec8a60023265364d066a1212fde3930f6ae8da7",
   "0xffbac21a641dcfe4552920138d90f3638b3c9fba"

Also applies to: 7-8, 14-16, 33-35

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7a68cc and bec4474.

Files selected for processing (5)
  • client/chain/chain.go (5 hunks)
  • client/chain/chain_test.go (2 hunks)
  • client/chain/ofac.go (1 hunks)
  • client/metadata/ofac.json (1 hunks)
  • examples/chain/ofac/1_DownloadOfacList/example.go (1 hunks)
Additional comments not posted (9)
examples/chain/ofac/1_DownloadOfacList/example.go (1)

1-12: LGTM!

The code provides a clear and concise example of how to use the new DownloadOfacList function from the chainclient package to download the OFAC list.

client/chain/ofac.go (4)

27-40: LGTM!

The function correctly initializes the OfacChecker by ensuring the OFAC list is available locally and loaded into memory. It handles errors appropriately.


50-76: LGTM!

The function correctly downloads the OFAC list from the specified URL and saves it locally. It handles errors appropriately.


78-93: LGTM!

The method correctly loads the OFAC list from the local file into memory for efficient lookups. It handles errors appropriately.


95-97: LGTM!

The method provides a simple and efficient way to check if an address is blacklisted by leveraging the map data structure for fast lookups.

client/metadata/ofac.json (1)

1-48: LGTM! The file structure and content are valid.

The client/metadata/ofac.json file contains a valid JSON array of Ethereum addresses. This file serves as a reference for the application to check against when determining whether a transaction or interaction involves an entity sanctioned by the Office of Foreign Assets Control (OFAC).

Ensure that this list is kept up to date with the latest OFAC regulations to maintain compliance.

client/chain/chain_test.go (1)

58-122: LGTM!

The OfacTestSuite is a well-structured test suite that thoroughly tests the OFAC list functionality. The setup and teardown methods effectively manage the test environment, and the TestOfacList method correctly verifies the expected behavior when the OFAC list is present.

The use of the testify/suite package enhances the organization and error handling of the tests.

client/chain/chain.go (2)

324-325: LGTM!

The addition of the ofacChecker field to the chainClient struct is a valid change. It enables the client to perform OFAC compliance checks.


445-458: LGTM!

The code segment correctly initializes the OfacChecker and performs the OFAC compliance check during client initialization. If the account's address is blacklisted, the client initialization fails with an appropriate error message.

Comment on lines +42 to +48
func getOfacListPath() string {
currentDirectory, _ := os.Getwd()
for !strings.HasSuffix(currentDirectory, "sdk-go") {
currentDirectory = filepath.Dir(currentDirectory)
}
return filepath.Join(filepath.Join(filepath.Join(currentDirectory, "client"), "metadata"), ofacListFilename)
}
Copy link

Choose a reason for hiding this comment

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

Consider improving the OFAC list path determination.

The current implementation assumes a specific directory structure and may break if the structure changes. It also doesn't handle the case where the "sdk-go" directory is not found.

Consider the following improvements:

  • Use a configuration file or environment variable to specify the OFAC list path instead of relying on a specific directory structure. This would make the code more flexible and easier to maintain.
  • Handle the case where the "sdk-go" directory is not found by returning an error or using a default path. This would make the code more robust and prevent potential issues.

Comment on lines +1295 to +1297
if c.ofacChecker.IsBlacklisted(granter) {
panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
}
Copy link

Choose a reason for hiding this comment

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

Consider returning an error instead of panicking.

The OFAC compliance check on the granter address is correctly performed. However, as mentioned in the previous comments, using panic is generally discouraged. It would be better to return an error instead of panicking to allow proper error handling.

Apply this diff to return an error instead of panicking:

-	if c.ofacChecker.IsBlacklisted(granter) {
-		panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
-	}
+	if c.ofacChecker.IsBlacklisted(granter) {
+		return nil, errors.New("granter address is in the OFAC list")
+	}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if c.ofacChecker.IsBlacklisted(granter) {
panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
}
if c.ofacChecker.IsBlacklisted(granter) {
return nil, errors.New("granter address is in the OFAC list")
}

Comment on lines +1197 to +1199
if c.ofacChecker.IsBlacklisted(granter) {
panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
}
Copy link

Choose a reason for hiding this comment

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

Consider returning an error instead of panicking.

The OFAC compliance check on the granter address is correctly performed. However, as mentioned in the previous comment, using panic is generally discouraged. It would be better to return an error instead of panicking to allow proper error handling.

Apply this diff to return an error instead of panicking:

-	if c.ofacChecker.IsBlacklisted(granter) {
-		panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
-	}
+	if c.ofacChecker.IsBlacklisted(granter) {
+		return nil, errors.New("granter address is in the OFAC list")
+	}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if c.ofacChecker.IsBlacklisted(granter) {
panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
}
if c.ofacChecker.IsBlacklisted(granter) {
return nil, errors.New("granter address is in the OFAC list")
}

Comment on lines +1163 to +1165
if c.ofacChecker.IsBlacklisted(granter) {
panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
}
Copy link

Choose a reason for hiding this comment

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

Consider returning an error instead of panicking.

The OFAC compliance check on the granter address is correctly performed. However, using panic is generally discouraged as it abruptly terminates the program. It would be better to return an error instead of panicking to allow proper error handling.

Apply this diff to return an error instead of panicking:

-	if c.ofacChecker.IsBlacklisted(granter) {
-		panic("Address is in the OFAC list") // panics should generally be avoided, but otherwise function signature should be changed
-	}
+	if c.ofacChecker.IsBlacklisted(granter) {
+		return nil, errors.New("granter address is in the OFAC list")
+	}

Committable suggestion was skipped due to low confidence.

@aarmoa aarmoa merged commit 08caf8f into master Sep 18, 2024
4 checks passed
@aarmoa aarmoa deleted the release/v_1_52_0 branch September 18, 2024 12:13
This was referenced Nov 13, 2024
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