feat: Update with new interface

Give more context in the swap-encoder.md
This commit is contained in:
Diana Carvalho
2024-08-30 10:42:13 +01:00
parent 41f20f14b0
commit 7ba63bf404
4 changed files with 54 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
from typing import Any
from core.encoding.interface import SwapStructEncoder
from core.encoding.interface import SwapStructEncoder, EncodingContext
from core.type_aliases import Address
from eth_abi.packed import encode_abi_packed
from hexbytes import HexBytes
@@ -8,18 +8,8 @@ from hexbytes import HexBytes
class BalancerSwapStructEncoder(SwapStructEncoder):
def encode_swap_struct(
self, swap: dict[str, Any], receiver: Address, exact_out: bool, **kwargs
self, swap: dict[str, Any], receiver: Address, encoding_context: EncodingContext
) -> bytes:
"""
Parameters:
----------
swap
The swap to encode
receiver
The receiver of the buy token
exact_out
Whether the amount encoded is the exact amount out
"""
return encode_abi_packed(
["address", "address", "bytes32", "address", "bool", "bool"],
[
@@ -27,7 +17,7 @@ class BalancerSwapStructEncoder(SwapStructEncoder):
swap["buy_token"].address,
HexBytes(swap["pool_id"]),
receiver,
exact_out,
encoding_context.exact_out,
swap["token_approval_needed"],
],
)

View File

@@ -1,5 +1,6 @@
from core.models.evm.ethereum_token import EthereumToken
from propeller_swap_encoders.balancer import BalancerSwapStructEncoder
from core.encoding.interface import EncodingContext
def test_encode_balancer():
@@ -29,7 +30,9 @@ def test_encode_balancer():
"pool_fee": None,
}
balancer_encoder = BalancerSwapStructEncoder()
encoded = balancer_encoder.encode_swap_struct(swap, receiver=bob, exact_out=False)
encoded = balancer_encoder.encode_swap_struct(
swap, receiver=bob, encoding_context=EncodingContext(exact_out=False)
)
assert (
encoded.hex()
==