-
Notifications
You must be signed in to change notification settings - Fork 33
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(rfq-api): add v2 contracts to rfq api endpoint [SLT-429] #3386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,14 +95,15 @@ func NewAPI( | |
|
||
docs.SwaggerInfo.Title = "RFQ Quoter API" | ||
|
||
bridges := make(map[uint32]*fastbridge.FastBridge) | ||
// TODO: allow role checking for v2 vs v1 contracts; for now default to v1 | ||
fastBridgeContracts := make(map[uint32]*fastbridge.FastBridge) | ||
roles := make(map[uint32]*ttlcache.Cache[string, bool]) | ||
for chainID, bridge := range cfg.Bridges { | ||
for chainID, contract := range cfg.FastBridgeContractsV1 { | ||
chainClient, err := omniRPCClient.GetChainClient(ctx, int(chainID)) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create omnirpc client: %w", err) | ||
} | ||
bridges[chainID], err = fastbridge.NewFastBridge(common.HexToAddress(bridge), chainClient) | ||
fastBridgeContracts[chainID], err = fastbridge.NewFastBridge(common.HexToAddress(contract), chainClient) | ||
Comment on lines
+99
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize both v1 and v2 fast bridge contracts The code only initializes v1 contracts despite the config supporting both v1 and v2 contracts. This could lead to v2 contracts being inaccessible. Apply this diff to initialize both contract versions: fastBridgeContracts := make(map[uint32]*fastbridge.FastBridge)
roles := make(map[uint32]*ttlcache.Cache[string, bool])
-for chainID, contract := range cfg.FastBridgeContractsV1 {
+// Initialize v1 contracts
+for chainID, contract := range cfg.FastBridgeContractsV1 {
+ if err := initializeContract(ctx, chainID, contract, fastBridgeContracts, roles, omniRPCClient); err != nil {
+ return nil, fmt.Errorf("could not initialize v1 contract: %w", err)
+ }
+}
+
+// Initialize v2 contracts
+for chainID, contract := range cfg.FastBridgeContractsV2 {
+ if err := initializeContract(ctx, chainID, contract, fastBridgeContracts, roles, omniRPCClient); err != nil {
+ return nil, fmt.Errorf("could not initialize v2 contract: %w", err)
+ }
+}
+
+// Helper function to initialize contracts
+func initializeContract(ctx context.Context, chainID uint32, contract string, contracts map[uint32]*fastbridge.FastBridge, roles map[uint32]*ttlcache.Cache[string, bool], omniRPCClient omniClient.RPCClient) error {
chainClient, err := omniRPCClient.GetChainClient(ctx, int(chainID))
if err != nil {
- return nil, fmt.Errorf("could not create omnirpc client: %w", err)
+ return fmt.Errorf("could not create omnirpc client: %w", err)
}
- fastBridgeContracts[chainID], err = fastbridge.NewFastBridge(common.HexToAddress(contract), chainClient)
+ contracts[chainID], err = fastbridge.NewFastBridge(common.HexToAddress(contract), chainClient)
if err != nil {
- return nil, fmt.Errorf("could not create bridge contract: %w", err)
+ return fmt.Errorf("could not create bridge contract: %w", err)
}
+ return nil
+}
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not create bridge contract: %w", err) | ||
} | ||
|
@@ -136,7 +137,7 @@ func NewAPI( | |
omnirpcClient: omniRPCClient, | ||
handler: handler, | ||
meter: handler.Meter(meterName), | ||
fastBridgeContracts: bridges, | ||
fastBridgeContracts: fastBridgeContracts, | ||
roleCache: roles, | ||
relayAckCache: relayAckCache, | ||
ackMux: sync.Mutex{}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,5 +536,6 @@ func (c *ServerSuite) TestContracts() { | |
contracts, err := client.GetRFQContracts(c.GetTestContext()) | ||
c.Require().NoError(err) | ||
|
||
c.Require().Len(contracts.Contracts, 2) | ||
c.Require().Len(contracts.ContractsV1, 2) | ||
c.Require().Len(contracts.ContractsV2, 2) | ||
Comment on lines
+539
to
+540
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance test coverage for contract validation The test only verifies the length of contract lists. Consider enhancing it to validate:
Apply this diff to improve the test: - c.Require().Len(contracts.ContractsV1, 2)
- c.Require().Len(contracts.ContractsV2, 2)
+ // Verify v1 contracts
+ c.Require().Len(contracts.ContractsV1, 2, "Expected 2 v1 contracts")
+ for _, contract := range contracts.ContractsV1 {
+ c.Require().NotEmpty(contract.Address, "Contract address should not be empty")
+ c.Require().NotZero(contract.ChainID, "Chain ID should not be zero")
+ // Add more specific assertions based on v1 contract properties
+ }
+
+ // Verify v2 contracts
+ c.Require().Len(contracts.ContractsV2, 2, "Expected 2 v2 contracts")
+ for _, contract := range contracts.ContractsV2 {
+ c.Require().NotEmpty(contract.Address, "Contract address should not be empty")
+ c.Require().NotZero(contract.ChainID, "Chain ID should not be zero")
+ // Add more specific assertions based on v2 contract properties
+ }
+
+ // Verify uniqueness across v1 and v2
+ allContracts := append(contracts.ContractsV1, contracts.ContractsV2...)
+ seen := make(map[string]bool)
+ for _, contract := range allContracts {
+ key := fmt.Sprintf("%d-%s", contract.ChainID, contract.Address)
+ c.Require().False(seen[key], "Duplicate contract found: %s", key)
+ seen[key] = true
+ }
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Existing configuration files impacted by new fields
services/rfq/api/docs/swagger.yaml
needs to be updated to include the new fast_bridge configurations.🔗 Analysis chain
Verify the impact on existing configurations
The addition of new fields might require updates to existing configuration files and deployment processes.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 27176