-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Idea
Extend the API of w3.NewFunc, w3.MustNewFunc, w3.NewEvent, w3.MustNewEvent with struct mappings. A struct mapping maps a Solidity struct (tuple) to a Go struct.
Benefits:
- compact ABI definition
- mapping verification at function/event-creation time
Challenges:
- Go types like
big.Inthave an ambiguous mapping to Solidity types.- Possible solution: introduce a struct arg tag
abitypethat maps to the Solidity type
- Possible solution: introduce a struct arg tag
- func MustNewFunc(signature, returns string) *Func
+ func MustNewFunc(signature, returns string, types ...any) *FuncExample (Uniswap V4 Swap Function)
Potential Future API
funcSwap := w3.MustNewFunc("swap(PoolKey key, SwapParams params, bytes hookData)", "int256 delta",
PoolKey{}, SwapParams{},
)
// ABI binding for the PoolKey struct.
type PoolKey struct {
Currency0 common.Address
Currency1 common.Address
Fee *big.Int `abitype:"uint24"`
TickSpacing *big.Int `abitype:"int24"`
Hooks common.Address
}
// ABI binding for the SwapParams struct.
type SwapParams struct {
ZeroForOne bool
AmountSpecified *big.Int `abitype:"int256"`
SqrtPriceLimitX96 *big.Int `abitype:"uint160"`
}Current API
funcSwap := w3.MustNewFunc(`swap(
(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key,
(bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96) params,
bytes hookData
)`, "int256 delta")
// ABI binding for the PoolKey struct.
type PoolKey struct {
Currency0 common.Address
Currency1 common.Address
Fee *big.Int
TickSpacing *big.Int
Hooks common.Address
}
// ABI binding for the SwapParams struct.
type SwapParams struct {
ZeroForOne bool
AmountSpecified *big.Int
SqrtPriceLimitX96 *big.Int
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request