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

Pendle Adaptor Support #264

Merged
merged 14 commits into from
Jul 3, 2024
Merged

Pendle Adaptor Support #264

merged 14 commits into from
Jul 3, 2024

Conversation

cbrit
Copy link
Member

@cbrit cbrit commented Jun 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced PendleAdaptorV1 for enhanced contract interactions.
    • Added transaction simulation using Tenderly in local Steward setup.
  • Bug Fixes

    • Updated SOMMELIER_IMAGE to version v7.0.1 in workflows.
  • Documentation

    • Added detailed instructions for running Steward locally with Tenderly integration.
  • Integration Tests

    • Enhanced logging and updated cork type imports to v2.
  • Refactor

    • Consolidated various cork-related functions to utilize corktypesv2.

@cbrit cbrit requested review from zmanian and 0xEinCodes June 28, 2024 20:01
Copy link

coderabbitai bot commented Jul 1, 2024

Walkthrough

A new contract adaptor named "PendleAdaptorV1" was added to the project for interfacing with Pendle's functionalities like minting, swapping, and adding liquidity. The addition affects multiple modules, test setups, and protobuf definitions, ensuring comprehensive integration and testing. Some updates switch from older to newer versions of certain imports, reflecting ongoing maintenance and enhancement. Notable documentation now includes guidance on running Steward locally with Tenderly for simulation and testing.

Changes

File/Path Group Change Summary
build.rs, hash_abi, hash_proto Added new contract adaptor "PendleAdaptorV1". Updated hash values to reflect content changes.
proto/steward/v4/… Introduced Pendle Adaptor related imports and message fields in various proto files.
src/cellars/adaptors.rs Added new module pendle.
src/cellars/adaptors/… Added match case for PendleV1Calls in multiple adaptor files to handle Pendle functionality.
src/lib.rs Added new module pendle_adaptor_v1 in abi module.
.github/workflows/integration_tests.yml Updated SOMMELIER_IMAGE version to v7.0.1. Added steps to show docker logs before cleanup.
integration_tests/… Updated integration test imports from corktypes to corktypesv2. Added and updated several loggings.
src/cellars/adaptors/pendle.rs New file introducing functionality for handling Pendle adaptor calls.
docs/06-StewardForStrategists.md Added instructions for running Steward locally, emphasizing simulation with Tenderly.

(Note: Paths have been shortened for readability.)

Sequence Diagrams

Adding a New Contract Adaptor (PendleAdaptorV1)

sequenceDiagram
    participant Developer
    participant BuildRS as build.rs
    participant ProtoFiles as Proto Files
    participant Adaptors as Adaptor Files
    participant Tests as Test Files
    participant Docs as Documentation

    Developer->>BuildRS: Add PendleAdaptorV1 to contract adaptors
    Developer->>ProtoFiles: Add pendle.proto import and PendleAdaptorV1 messages
    Developer->>Adaptors: Implement PendleAdaptorV1Calls handling
    Developer->>Tests: Update tests to use corktypesv2
    Developer->>Docs: Add documentation for local Steward testing with Tenderly
Loading

Logging and Simulation Integration

sequenceDiagram
    participant Developer
    participant GitHubYML as .github/workflows/integration_tests.yml
    participant Framework as Framework
    participant DockerContainers as Docker Containers
    participant Documentation as Docs
    
    Developer->>GitHubYML: Update SOMMELIER_IMAGE to v7.0.1
    GitHubYML->>DockerContainers: Add steps to log before cleaning up
    
    Developer->>Documentation: Add simulate mode and Tenderly setup instructions
Loading

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16588a6 and 4fd536f.

Files selected for processing (1)
  • docs/06-StewardForStrategists.md (1 hunks)
Additional context used
LanguageTool
docs/06-StewardForStrategists.md

[uncategorized] ~67-~67: Possible missing preposition found.
Context: ... a contract. This allows the strategist confirm they get the expected state changes fro...

(AI_HYDRA_LEO_MISSING_TO)


[uncategorized] ~69-~69: A comma might be missing here.
Context: ...data parameters. To use the simulation features you will need to have a Tenderly accoun...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


[style] ~69-~69: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...b=readme-ov-file#installation). You may need to build from source if you are planning t...

(REP_NEED_TO_VB)


[uncategorized] ~76-~76: Did you mean: “By default,”?
Context: ...n: bash steward simulate start By default this will run the simulate server on po...

(BY_DEFAULT_COMMA)

Markdownlint
docs/06-StewardForStrategists.md

66-66: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)

Additional comments not posted (12)
docs/06-StewardForStrategists.md (12)

61-61: Approved: Formatting change.

The added blank line improves readability.


62-62: Approved: New section header.

The "Testing and Development" section header is clear and relevant.


63-63: Approved: Formatting change.

The added blank line improves readability.


64-64: Approved: New paragraph.

The explanation of running Steward locally for testing and development is clear and relevant.


65-65: Approved: Formatting change.

The added blank line improves readability.


68-68: Approved: Formatting change.

The added blank line improves readability.


70-70: Approved: Continuation of paragraph.

The explanation of requirements for using simulation features is clear and relevant.


71-71: Approved: Formatting change.

The added blank line improves readability.


72-72: Approved: New paragraph.

The explanation of starting Steward in simulate mode is clear and relevant.


73-73: Approved: Formatting change.

The added blank line improves readability.


74-75: Approved: New code block.

The command to start Steward in simulate mode is clear and relevant.


76-76: Approved: Formatting change.

The added blank line improves readability.

Tools
LanguageTool

[uncategorized] ~76-~76: Did you mean: “By default,”?
Context: ...n: bash steward simulate start By default this will run the simulate server on po...

(BY_DEFAULT_COMMA)


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

Comment on lines +14 to +18
for c in params.calls {
let function = c
.function
.ok_or_else(|| sp_call_error("function cannot be empty".to_string()))?;

Copy link

Choose a reason for hiding this comment

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

Consider logging errors for better traceability.

Adding logging for the error case will help in debugging issues.

for c in params.calls {
    let function = c
        .function
        .ok_or_else(|| {
            let err_msg = "function cannot be empty".to_string();
            sp_call_error(err_msg.clone());
            log::error!("{}", err_msg);
            err_msg
        })?;

Comment on lines +19 to +122
spender: sp_call_parse_address(p.spender)?,
};
calls.push(
AbiPendleAdaptorV1Calls::RevokeApproval(call)
.encode()
.into(),
)
}
Function::MintSyFromToken(p) => {
let call = pendle_adaptor_v1::MintSyFromTokenCall {
market: sp_call_parse_address(p.market)?,
min_sy_out: string_to_u256(p.min_sy_out)?,
input: convert_token_input(p.input)?,
};
calls.push(
AbiPendleAdaptorV1Calls::MintSyFromToken(call)
.encode()
.into(),
)
}
Function::MintPyFromSy(p) => {
let call = pendle_adaptor_v1::MintPyFromSyCall {
market: sp_call_parse_address(p.market)?,
net_sy_in: string_to_u256(p.net_sy_in)?,
min_py_out: string_to_u256(p.min_py_out)?,
};
calls.push(AbiPendleAdaptorV1Calls::MintPyFromSy(call).encode().into())
}
Function::SwapExactPtForYt(p) => {
let call = pendle_adaptor_v1::SwapExactPtForYtCall {
market: sp_call_parse_address(p.market)?,
min_yt_out: string_to_u256(p.min_yt_out)?,
exact_pt_in: string_to_u256(p.exact_pt_in)?,
guess_total_yt_to_swap: convert_approx_params(p.guess_total_yt_to_swap)?,
};
calls.push(
AbiPendleAdaptorV1Calls::SwapExactPtForYt(call)
.encode()
.into(),
)
}
Function::SwapExactYtForPt(p) => {
let call = pendle_adaptor_v1::SwapExactYtForPtCall {
market: sp_call_parse_address(p.market)?,
min_pt_out: string_to_u256(p.min_pt_out)?,
exact_yt_in: string_to_u256(p.exact_yt_in)?,
guess_total_pt_from_swap: convert_approx_params(p.guess_total_pt_to_swap)?,
};
calls.push(
AbiPendleAdaptorV1Calls::SwapExactYtForPt(call)
.encode()
.into(),
)
}
Function::AddLiquidityDualSyAndPt(p) => {
let call = pendle_adaptor_v1::AddLiquidityDualSyAndPtCall {
market: sp_call_parse_address(p.market)?,
net_sy_desired: string_to_u256(p.net_sy_desired)?,
net_pt_desired: string_to_u256(p.net_pt_desired)?,
min_lp_out: string_to_u256(p.min_lp_out)?,
};
calls.push(
AbiPendleAdaptorV1Calls::AddLiquidityDualSyAndPt(call)
.encode()
.into(),
)
}
Function::RemoveLiquidityDualSyAndPt(p) => {
let call = pendle_adaptor_v1::RemoveLiquidityDualSyAndPtCall {
market: sp_call_parse_address(p.market)?,
net_lp_to_remove: string_to_u256(p.net_lp_to_remove)?,
min_sy_out: string_to_u256(p.min_sy_out)?,
min_pt_out: string_to_u256(p.min_pt_out)?,
};
calls.push(
AbiPendleAdaptorV1Calls::RemoveLiquidityDualSyAndPt(call)
.encode()
.into(),
)
}
Function::RedeemPyToSy(p) => {
let call = pendle_adaptor_v1::RedeemPyToSyCall {
market: sp_call_parse_address(p.market)?,
net_py_in: string_to_u256(p.net_py_in)?,
min_sy_out: string_to_u256(p.min_sy_out)?,
};
calls.push(AbiPendleAdaptorV1Calls::RedeemPyToSy(call).encode().into())
}
Function::RedeemSyToToken(p) => {
let call = pendle_adaptor_v1::RedeemSyToTokenCall {
market: sp_call_parse_address(p.market)?,
net_sy_in: string_to_u256(p.net_sy_in)?,
output: convert_token_output(p.output)?,
};
calls.push(
AbiPendleAdaptorV1Calls::RedeemSyToToken(call)
.encode()
.into(),
)
}
Copy link

Choose a reason for hiding this comment

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

Consider adding logging for each match arm.

Adding logging for each match arm will help in debugging and tracing the function calls.

match function {
    Function::RevokeApproval(p) => {
        log::info!("Encoding RevokeApproval call");
        let call = pendle_adaptor_v1::RevokeApprovalCall {
            asset: sp_call_parse_address(p.asset)?,
            spender: sp_call_parse_address(p.spender)?,
        };
        calls.push(
            AbiPendleAdaptorV1Calls::RevokeApproval(call)
                .encode()
                .into(),
        )
    }
    Function::MintSyFromToken(p) => {
        log::info!("Encoding MintSyFromToken call");
        let call = pendle_adaptor_v1::MintSyFromTokenCall {
            market: sp_call_parse_address(p.market)?,
            min_sy_out: string_to_u256(p.min_sy_out)?,
            input: convert_token_input(p.input)?,
        };
        calls.push(
            AbiPendleAdaptorV1Calls::MintSyFromToken(call)
                .encode()
                .into(),
        )
    }
    // Add similar logging for other match arms
}

Comment on lines 1 to 3
use abscissa_core::tracing::log::debug;
use ethers::{abi::AbiEncode, types::Bytes};

Copy link

Choose a reason for hiding this comment

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

Remove unused import.

The log::debug import is not used in this file.

- use abscissa_core::tracing::log::debug;
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
use abscissa_core::tracing::log::debug;
use ethers::{abi::AbiEncode, types::Bytes};
use ethers::{abi::AbiEncode, types::Bytes};

syntax = "proto3";
package steward.v4;

option go_package = "/steward_proto";
Copy link

Choose a reason for hiding this comment

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

Update go_package option.

The go_package option should be updated to match the package name and directory structure.

- option go_package = "/steward_proto";
+ option go_package = "steward/v4";
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
option go_package = "/steward_proto";
option go_package = "steward/v4";

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: 1

bz, err = tmjson.MarshalIndent(genDoc, "", " ")
s.Require().NoError(err)

// write the updated genesis file to each validator
for _, val := range s.chain.validators {
for i, val := range s.chain.validators {
s.T().Log("writing genesis to val %d", i)
Copy link

Choose a reason for hiding this comment

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

Fix the printf formatting directive.

The Log call has a possible Printf formatting directive %d. Change Log to Logf.

-        s.T().Log("writing genesis to val %d", i)
+        s.T().Logf("writing genesis to val %d", i)
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
s.T().Log("writing genesis to val %d", i)
s.T().Logf("writing genesis to val %d", i)
Tools
golangci-lint

504-504: printf: (*testing.common).Log call has possible Printf formatting directive %d

(govet)

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: 0

Outside diff range and nitpick comments (4)
docs/06-StewardForStrategists.md (4)

66-66: Approved: New content with trailing space issue.

The explanation of simulate mode features is clear and relevant. However, there is a trailing space at the end of the line.

- 1. Encode only, which simply takes a `ScheduleRequest` and returns the ABI encoded call data. 
+ 1. Encode only, which simply takes a `ScheduleRequest` and returns the ABI encoded call data.
Tools
Markdownlint

66-66: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


67-67: Approved: New content with missing preposition issue.

The explanation of the second feature of simulate mode is clear and relevant. However, there is a missing preposition "to".

- This allows the strategist confirm they get the expected state changes from their call data parameters.
+ This allows the strategist to confirm they get the expected state changes from their call data parameters.
Tools
LanguageTool

[uncategorized] ~67-~67: Possible missing preposition found.
Context: ... a contract. This allows the strategist confirm they get the expected state changes fro...

(AI_HYDRA_LEO_MISSING_TO)


69-69: Approved: New content with missing comma and repetitive phrasing issues.

The explanation of requirements for using simulation features is clear and relevant. However, there is a missing comma and repetitive phrasing.

- To use the simulation features you will need to have a Tenderly account, project, and API key.
+ To use the simulation features, you will need a Tenderly account, project, and API key.
Tools
LanguageTool

[uncategorized] ~69-~69: A comma might be missing here.
Context: ...data parameters. To use the simulation features you will need to have a Tenderly accoun...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


[style] ~69-~69: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...b=readme-ov-file#installation). You may need to build from source if you are planning t...

(REP_NEED_TO_VB)


77-77: Approved: New paragraph with missing comma issue.

The explanation of the default port for the simulate server is clear and relevant. However, there is a missing comma after "By default".

- By default this will run the simulate server on port 5734.
+ By default, this will run the simulate server on port 5734.

@cbrit cbrit merged commit a787143 into main Jul 3, 2024
13 checks passed
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.

2 participants