diff --git a/go/builder/adaptors/aave_v2_a_token.go b/go/builder/adaptors/aave_v2_a_token.go index 9c7b7060..fa25f1cb 100644 --- a/go/builder/adaptors/aave_v2_a_token.go +++ b/go/builder/adaptors/aave_v2_a_token.go @@ -7,6 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) +// AaveV2ATokenAdaptorV2CallBuilder is a builder for AaveV2ATokenAdaptorV2 calls. +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Aave/AaveATokenAdaptor.sol type AaveV2ATokenAdaptorV2CallBuilder struct { adaptor common.Address calls []*steward_proto.AaveATokenAdaptorV2 diff --git a/go/builder/adaptors/aave_v2_enable_asset_as_collateral.go b/go/builder/adaptors/aave_v2_enable_asset_as_collateral.go index 6ab470d3..79911649 100644 --- a/go/builder/adaptors/aave_v2_enable_asset_as_collateral.go +++ b/go/builder/adaptors/aave_v2_enable_asset_as_collateral.go @@ -5,6 +5,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) +// AaveV2EnableAssetAsCollateralAdaptorV1CallBuilder builds calls for the AaveV2EnableAssetAsCollateralAdaptorV1 adaptor +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Aave/AaveV2EnableAssetAsCollateralAdaptor.sol type AaveV2EnableAssetAsCollateralAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.AaveV2EnableAssetAsCollateralAdaptorV1 diff --git a/go/builder/adaptors/aave_v3_a_token.go b/go/builder/adaptors/aave_v3_a_token.go index f7d50da2..80248381 100644 --- a/go/builder/adaptors/aave_v3_a_token.go +++ b/go/builder/adaptors/aave_v3_a_token.go @@ -7,6 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) +// Builder for AaveV3ATokenAdaptorV1 adaptor +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Aave/V3/AaveV3ATokenAdaptor.sol type AaveV3ATokenAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.AaveV3ATokenAdaptorV1 diff --git a/go/builder/adaptors/aave_v3_debt_token.go b/go/builder/adaptors/aave_v3_debt_token.go index 7b2d660e..817d7232 100644 --- a/go/builder/adaptors/aave_v3_debt_token.go +++ b/go/builder/adaptors/aave_v3_debt_token.go @@ -7,6 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) +// AaveV3DebtTokenAdaptorV1CallBuilder is a builder for AaveV3DebtTokenAdaptorV1 calls +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Aave/V3/AaveV3DebtTokenAdaptor.sol type AaveV3DebtTokenAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.AaveV3DebtTokenAdaptorV1 diff --git a/go/builder/adaptors/aave_v3_debt_token_flash_loan.go b/go/builder/adaptors/aave_v3_debt_token_flash_loan.go index 7fe58020..436d00d0 100644 --- a/go/builder/adaptors/aave_v3_debt_token_flash_loan.go +++ b/go/builder/adaptors/aave_v3_debt_token_flash_loan.go @@ -7,7 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) -// Builder +// Builder for using flash loans with the AaveV3DebtTokenAdaptorV1 adaptor +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Aave/V3/AaveV3DebtTokenAdaptor.sol type AaveV3DebtTokenFlashLoanAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.AaveV3DebtTokenAdaptorV1FlashLoan diff --git a/go/builder/adaptors/balancer_pool.go b/go/builder/adaptors/balancer_pool.go index 6e4aec12..81d2aaad 100644 --- a/go/builder/adaptors/balancer_pool.go +++ b/go/builder/adaptors/balancer_pool.go @@ -13,6 +13,8 @@ const ( BalancerSwapKindGivenOut ) +// BalancerPoolAdaptorV1CallBuilder is a builder for BalancerPoolAdaptorV1 calls +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Balancer/BalancerPoolAdaptor.sol type BalancerPoolAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.BalancerPoolAdaptorV1 diff --git a/go/builder/adaptors/balancer_pool_flash_loan.go b/go/builder/adaptors/balancer_pool_flash_loan.go index a4cfd118..90263843 100644 --- a/go/builder/adaptors/balancer_pool_flash_loan.go +++ b/go/builder/adaptors/balancer_pool_flash_loan.go @@ -7,7 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) -// Builder +// BalancerPoolAdaptorV1CallBuilder is a builder for using flash loans with the BalancerPoolAdaptorV1 adaptor. +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Balancer/BalancerPoolAdaptor.sol type BalancerPoolFlashLoanAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.BalancerPoolAdaptorV1FlashLoan diff --git a/go/builder/adaptors/pendle.go b/go/builder/adaptors/pendle.go index a12c6f58..9f3570c9 100644 --- a/go/builder/adaptors/pendle.go +++ b/go/builder/adaptors/pendle.go @@ -7,7 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) -// Builder +// PendleAdaptorCallBuilder is a builder for PendleAdaptorV1 calls +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Pendle/PendleAdaptor.sol type PendleAdaptorCallBuilder struct { adaptor common.Address calls []*steward_proto.PendleAdaptorV1 diff --git a/go/builder/adaptors/swap_with_uniswap.go b/go/builder/adaptors/swap_with_uniswap.go index cbac7d55..b1709c22 100644 --- a/go/builder/adaptors/swap_with_uniswap.go +++ b/go/builder/adaptors/swap_with_uniswap.go @@ -7,7 +7,8 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) -// Builder for SwapWithUniswapAdaptorV1 +// SwapWithUniswapAdaptorV1CallBuilder is a builder for SwapWithUniswapAdaptorV1 calls +// Contract: https://github.com/PeggyJV/cellar-contracts/blob/main/src/modules/adaptors/Uniswap/SwapWithUniswapAdaptor.sol type SwapWithUniswapAdaptorV1CallBuilder struct { adaptor common.Address calls []*steward_proto.SwapWithUniswapAdaptorV1 @@ -21,7 +22,6 @@ func NewSwapWithUniswapAdaptorV1CallBuilder(adaptor common.Address) *SwapWithUni } } -// Build builds the AdaptorCall func (b *SwapWithUniswapAdaptorV1CallBuilder) Build() *steward_proto.AdaptorCall { return &steward_proto.AdaptorCall{ Adaptor: b.adaptor.Hex(), diff --git a/go/builder/cellar_call.go b/go/builder/cellar_call.go index b43714ba..c1456efc 100644 --- a/go/builder/cellar_call.go +++ b/go/builder/cellar_call.go @@ -8,16 +8,19 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) +// CellarCallBuilder is the builder for cellar call data. It can be used to string together multiple function calls to one Cellar. Function calls will execute in the order they are added to the builder. type CellarCallBuilder struct { functionCalls []*steward_proto.CellarV2_5_FunctionCall } +// NewCallDataBuilder creates a new CallDataBuilder func NewCallDataBuilder() *CellarCallBuilder { return &CellarCallBuilder{ functionCalls: make([]*steward_proto.CellarV2_5_FunctionCall, 0), } } +// Build returns the CallData struct with the function calls added to the builder func (cdb *CellarCallBuilder) Build() (*steward_proto.CellarV2_5, error) { if len(cdb.functionCalls) == 0 { return nil, fmt.Errorf("no function calls added to CallDataBuilder") diff --git a/go/builder/request.go b/go/builder/request.go index f6b7ff01..349581f3 100644 --- a/go/builder/request.go +++ b/go/builder/request.go @@ -7,6 +7,7 @@ import ( "github.com/peggyjv/steward/steward_proto_go/steward_proto" ) +// ScheduleRequestBuilder is the top-level builder for sending requests to Steward. It is used to build a ScheduleRequest. type ScheduleRequestBuilder struct { cellarID string chainID int @@ -15,10 +16,14 @@ type ScheduleRequestBuilder struct { deadline int } +// NewScheduleRequestBuilder creates a new ScheduleRequestBuilder. func NewScheduleRequestBuilder() *ScheduleRequestBuilder { - return &ScheduleRequestBuilder{} + return &ScheduleRequestBuilder{ + callData: &steward_proto.CellarV2_5{}, + } } +// Build tries to build the ScheduleRequest from the builder. It will return an error if basic validation fails. func (b *ScheduleRequestBuilder) Build() (*steward_proto.ScheduleRequest, error) { if err := b.Validate(); err != nil { return nil, err @@ -35,6 +40,7 @@ func (b *ScheduleRequestBuilder) Build() (*steward_proto.ScheduleRequest, error) }, nil } +// Validate checks if the builder has all the required fields set with legal values. func (b *ScheduleRequestBuilder) Validate() error { if b.chainID == 0 { return fmt.Errorf("chain ID cannot be zero") @@ -46,29 +52,58 @@ func (b *ScheduleRequestBuilder) Validate() error { return fmt.Errorf("deadline must be zero or positive") } + return validateCallData(b.callData) +} + +// Sanity check for call data builder +func validateCallData(callData *steward_proto.CellarV2_5) error { + if callData == nil { + return fmt.Errorf("call data cannot be nil") + } + + switch callData.GetCallType().(type) { + case *steward_proto.CellarV2_5_FunctionCall_: + if callData.GetFunctionCall() == nil { + return fmt.Errorf("function call cannot be nil") + } + case *steward_proto.CellarV2_5_Multicall_: + if callData.GetMulticall() == nil { + return fmt.Errorf("multi call cannot be nil") + } + + if len(callData.GetMulticall().FunctionCalls) == 0 { + return fmt.Errorf("multi call cannot be empty") + } + } + return nil } +// WithCellarID sets the cellar ID for the request. func (b *ScheduleRequestBuilder) WithCellarID(cellarID common.Address) *ScheduleRequestBuilder { b.cellarID = cellarID.Hex() return b } +// WithChainID sets the chain ID for the request. func (b *ScheduleRequestBuilder) WithChainID(chainID int) *ScheduleRequestBuilder { b.chainID = chainID return b } +// WithBlockHeight sets the Sommelier block height for the request at which the chain will tally votes for the cellar call. func (b *ScheduleRequestBuilder) WithBlockHeight(blockHeight int) *ScheduleRequestBuilder { b.blockHeight = blockHeight return b } +// WithCallData sets the call data for the request. func (b *ScheduleRequestBuilder) WithCallData(callData *steward_proto.CellarV2_5) *ScheduleRequestBuilder { b.callData = callData return b } +// WithDeadline sets the deadline for the request. Only applies to non-Ethereum chains. func (b *ScheduleRequestBuilder) WithDeadline(deadline int) *ScheduleRequestBuilder { b.deadline = deadline return b