Skip to content
Verified contractExact

FyndPolicy

Address0xea8e17d7709143ebcb08158fe3a70c755c23c778
Balance

0 ETH

 

Transactions

1

 

Compiler

vyper 0.4.3

 

Same code

Only this contract

 

Details

Compiler
vyper 0.4.3+commit.bff19ea2
Language
vyper
License
Not stated
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,484,877
Creation transaction
0xafd05f6ef2…eba239d2fc

contracts/policies/FyndPolicy.vy

# pragma version 0.4.3
# pragma optimize gas
"""
@title FyndPolicy
@notice Twocrypto policy for Fynd-routed swaps. Every operation pays the pool's
        own fee, except a swap that Fynd's router arms with a grant signed by
        Fynd's controller key: it pays the granted fee, at least min_fee.
@dev Vyper port of Fynd's FyndCurvePolicy sketch (28 Oct 2026) without its Pyth
     floor and revenue share fields. The policy checks who signed a grant, not
     what the trade is worth: LPs rely on Fynd to price each grant.

     CALLERS
         router            submit_grant, in the swap's transaction, before it
         pool              get_fee, get_price_scale, update_pool_state
         anyone            views
         owner (Curve)     set_controller, set_router, set_min_fee, set_killed, ownership
         emergency admin   set_killed

     GRANTS
     An EIP-712 Grant signed by the `controller` key (ECDSA, no contract wallets)
     gives one swap in its direction and input range the granted fee; a coin1
     input can read 1 wei below the amount sent. A swap in the other direction
     or outside the range pays the pool's own fee. The router submits it with the address that
     called the router, which must be the grant's taker, at most
     MAX_GRANT_WINDOW before its deadline. Each nonce works once. Arming records
     the pool's balances, which the swap's must differ from in the granted
     direction and range to get the granted fee. The pool's callback after the next operation clears
     the grant, as do a kill and the end of the transaction: every operation that
     changes the pool's balances or price_scale calls back. Liquidity operations
     pay the pool's own fee and clear it.

     UNITS
     Fees in FEE_PRECISION (1e10 = 100%).
"""
from snekmate.auth import ownable
from snekmate.utils import ecdsa
from snekmate.utils import eip712_domain_separator as eip712

initializes: ownable
initializes: eip712
exports: (
    ownable.owner,
    ownable.transfer_ownership,
    ownable.renounce_ownership,
    eip712.eip712Domain,
)


interface Pool:
    def balances(i: uint256) -> uint256: view
    def precisions() -> uint256[N_COINS]: view
    def price_scale() -> uint256: view  # Nonreentrant: reverts inside a pool operation.


N_COINS: constant(uint256) = 2
PRECISION: constant(uint256) = 10**18
FEE_PRECISION: constant(uint256) = 10**10  # Twocrypto fee units: 10**10 = 100%.
MIN_FEE: constant(uint256) = 10**5  # Twocrypto MIN_FEE (0.1 bp); a fee of 0 means the pool's own.
MIN_FEE_CAP: constant(uint256) = FEE_PRECISION // 10  # 10%
# Equal to the EIP-712 domain version. Bump both when the grant rules change.
VERSION: public(constant(uint256)) = 1
MAX_GRANT_WINDOW: constant(uint256) = 120  # seconds from submission to the grant's deadline


GRANT_TYPEHASH: public(constant(bytes32)) = keccak256(
    "Grant(address taker,uint8 coin_in,uint256 min_amount_in,uint256 max_amount_in,uint256 fee,uint64 nonce,uint32 deadline)"
)


struct Grant:
    taker: address  # the router's caller
    coin_in: uint8  # pool index of the input coin
    min_amount_in: uint256  # input range, in the input coin's units
    max_amount_in: uint256
    fee: uint256  # FEE_PRECISION
    nonce: uint64
    deadline: uint32  # unix seconds


struct ArmedGrant:
    coin_in: uint256
    min_amount_in: uint256
    max_amount_in: uint256
    fee: uint256
    xp: uint256[N_COINS]  # the pool's balances when armed, coin1 scaled by price_scale
    price_scale: uint256


POOL: public(immutable(address))
EMERGENCY_ADMIN: public(immutable(address))
PRECISIONS: immutable(uint256[N_COINS])

controller: public(address)  # Fynd's signing key
router: public(address)  # Fynd's router, the only caller of submit_grant
min_fee: public(uint256)  # lowest fee of a granted swap
is_killed: public(bool)
used_nonces: HashMap[uint256, uint256]  # nonce // 256 => bitmap of used nonces

armed: transient(bool)
armed_grant: transient(ArmedGrant)


event FyndPolicyCreated:
    pool: indexed(address)
    version: uint256


event GrantArmed:
    taker: indexed(address)
    nonce: uint64
    coin_in: uint8
    fee: uint256


event SetController:
    controller: address


event SetRouter:
    router: address


event SetMinFee:
    min_fee: uint256


event SetKilled:
    is_killed: bool


@deploy
def __init__(
    pool: address,
    controller: address,
    router: address,
    emergency_admin: address,
    min_fee: uint256,
):
    """
    @param pool Twocrypto pool
    @param controller Fynd's signing key
    @param router Fynd's router
    @param emergency_admin May kill and revive the policy, as may the owner
    @param min_fee Lowest fee of a granted swap; the deployer becomes the owner
    """
    assert pool.is_contract, "pool"
    assert emergency_admin != empty(address), "emergency admin=0"

    POOL = pool
    EMERGENCY_ADMIN = emergency_admin
    PRECISIONS = staticcall Pool(pool).precisions()

    log FyndPolicyCreated(pool=pool, version=VERSION)

    ownable.__init__()
    eip712.__init__("FyndPolicy", "1")
    self._set_controller(controller)
    self._set_router(router)
    self._set_min_fee(min_fee)


# ----------------------------------- Grants ------------------------------------


@external
def submit_grant(grant: Grant, signature: Bytes[65], taker: address):
    """
    @notice Arm `grant` for this transaction's next pool operation. Router only.
    @param signature The controller's EIP-712 signature of `grant`
    @param taker The address that called the router
    """
    assert msg.sender == self.router, "router"
    assert not self.is_killed, "killed"
    assert not self.armed, "armed"
    assert taker == grant.taker, "taker"
    deadline: uint256 = convert(grant.deadline, uint256)
    assert block.timestamp <= deadline, "expired"
    assert deadline <= block.timestamp + MAX_GRANT_WINDOW, "deadline"
    assert convert(grant.coin_in, uint256) < N_COINS, "coin"
    self._use_nonce(grant.nonce)

    digest: bytes32 = eip712._hash_typed_data_v4(keccak256(abi_encode(GRANT_TYPEHASH, grant)))
    # Reverts on a malformed signature; the controller is never empty.
    assert ecdsa._recover_sig(digest, signature) == self.controller, "signature"

    # price_scale() is nonreentrant: arming reverts inside a pool operation.
    price_scale: uint256 = staticcall Pool(POOL).price_scale()
    self.armed = True
    self.armed_grant = ArmedGrant(
        coin_in=convert(grant.coin_in, uint256),
        min_amount_in=grant.min_amount_in,
        max_amount_in=grant.max_amount_in,
        fee=grant.fee,
        # As Twocrypto._xp computes it.
        xp=[
            staticcall Pool(POOL).balances(0) * PRECISIONS[0],
            staticcall Pool(POOL).balances(1) * PRECISIONS[1] * price_scale // PRECISION,
        ],
        price_scale=price_scale,
    )
    log GrantArmed(taker=taker, nonce=grant.nonce, coin_in=grant.coin_in, fee=grant.fee)


@internal
def _use_nonce(nonce: uint64):
    word: uint256 = convert(nonce, uint256) >> 8
    bit: uint256 = 1 << (convert(nonce, uint256) & 255)
    bitmap: uint256 = self.used_nonces[word]
    assert bitmap & bit == 0, "nonce"
    self.used_nonces[word] = bitmap | bit


@external
@view
def is_nonce_used(nonce: uint64) -> bool:
    return self.used_nonces[convert(nonce, uint256) >> 8] & (1 << (convert(nonce, uint256) & 255)) != 0


# ------------------------------------- Fee -------------------------------------


@external
@view
def get_fee(xp: uint256[N_COINS]) -> uint256:
    """
    @notice Fee of the pool operation in progress: for the swap an armed grant
            admits, the granted fee, at least min_fee; 0 for everything else,
            so the pool charges its own fee.
    @param xp Pool balances after the operation and before its fee, coin1 scaled
           by price_scale
    @return FEE_PRECISION fee
    """
    if not self.armed:
        return 0

    grant: ArmedGrant = self.armed_grant
    old_xp: uint256[N_COINS] = grant.xp
    # A grant admits only a swap: one balance rises and the other falls.
    if xp[0] >= old_xp[0] and xp[1] >= old_xp[1]:
        return 0
    if xp[0] <= old_xp[0] and xp[1] <= old_xp[1]:
        return 0

    coin_in: uint256 = 0 if xp[0] > old_xp[0] else 1
    if coin_in != grant.coin_in:
        return 0
    amount_in: uint256 = xp[coin_in] - old_xp[coin_in]
    if coin_in == 1:
        amount_in = amount_in * PRECISION // grant.price_scale
    amount_in //= PRECISIONS[coin_in]
    if amount_in < grant.min_amount_in or amount_in > grant.max_amount_in:
        return 0

    return max(grant.fee, self.min_fee)


# --------------------------------- Pool hooks ----------------------------------


@external
@pure
def get_price_scale() -> uint256:
    """@notice 0: the pool keeps its own price_scale target."""
    return 0


@external
def update_pool_state(
    _xp: uint256[N_COINS],
    _price_scale: uint256,
    _price_oracle: uint256,
    _last_prices: uint256,
    _virtual_price: uint256,
    _xcp_profit: uint256,
    _D: uint256,
    _oracle_timestamp: uint256,
):
    """
    @notice Pool callback after every operation: clear the armed grant.
    @dev A balanced removal calls back best-effort with 300k gas, which this
         never runs out of.
    """
    assert msg.sender == POOL, "pool"
    self.armed = False


# --------------------------------- Governance ----------------------------------


@external
def set_controller(controller: address):
    """@notice Replace Fynd's signing key. Owner only."""
    ownable._check_owner()
    self._set_controller(controller)


@external
def set_router(router: address):
    """@notice Replace Fynd's router. Owner only."""
    ownable._check_owner()
    self._set_router(router)


@external
def set_min_fee(min_fee: uint256):
    """@notice Set the lowest granted fee. Owner only."""
    ownable._check_owner()
    self._set_min_fee(min_fee)


@external
def set_killed(is_killed: bool):
    """
    @notice Kill (True) or revive the policy. Owner or emergency admin.
    @dev While killed, no grant can be armed, so every operation pays the pool's
         own fee.
         Killing also clears a grant armed earlier in the same transaction.
    """
    assert msg.sender == EMERGENCY_ADMIN or msg.sender == ownable.owner, "access"
    if is_killed:
        self.armed = False
    self.is_killed = is_killed
    log SetKilled(is_killed=is_killed)


@internal
def _set_controller(controller: address):
    assert controller != empty(address), "controller=0"
    self.controller = controller
    log SetController(controller=controller)


@internal
def _set_router(router: address):
    assert router != empty(address), "router=0"
    self.router = router
    log SetRouter(router=router)


@internal
def _set_min_fee(min_fee: uint256):
    assert MIN_FEE <= min_fee and min_fee <= MIN_FEE_CAP, "min fee"
    self.min_fee = min_fee
    log SetMinFee(min_fee=min_fee)

.venv/lib/python3.12/site-packages/snekmate/auth/ownable.vy

# pragma version ~=0.4.3
# pragma nonreentrancy off
"""
@title Owner-Based Access Control Functions
@custom:contract-name ownable
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions can be used to implement a basic access
        control mechanism, where there is an account (an owner)
        that can be granted exclusive access to specific functions.
        By default, the owner account will be the one that deploys
        the contract. This can later be changed with `transfer_ownership`.
        An exemplary integration can be found in the ERC-20 implementation here:
        https://github.com/pcaversaccio/snekmate/blob/main/src/snekmate/tokens/erc20.vy.
        The implementation is inspired by OpenZeppelin's implementation here:
        https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol.
"""


# @dev Returns the address of the current owner.
# @notice If you declare a variable as `public`,
# Vyper automatically generates an `external`
# getter function for the variable.
owner: public(address)


# @dev Emitted when the ownership is transferred
# from `previous_owner` to `new_owner`.
event OwnershipTransferred:
    previous_owner: indexed(address)
    new_owner: indexed(address)


@deploy
@payable
def __init__():
    """
    @dev To omit the opcodes for checking the `msg.value`
         in the creation-time EVM bytecode, the constructor
         is declared as `payable`.
    @notice The `owner` role will be assigned to
            the `msg.sender`.
    """
    self._transfer_ownership(msg.sender)


@external
def transfer_ownership(new_owner: address):
    """
    @dev Transfers the ownership of the contract
         to a new account `new_owner`.
    @notice Note that this function can only be
            called by the current `owner`. Also,
            the `new_owner` cannot be the zero address.
    @param new_owner The 20-byte address of the new owner.
    """
    self._check_owner()
    assert new_owner != empty(address), "ownable: new owner is the zero address"
    self._transfer_ownership(new_owner)


@external
def renounce_ownership():
    """
    @dev Leaves the contract without an owner.
    @notice Renouncing ownership will leave the
            contract without an owner, thereby
            removing any functionality that is
            only available to the owner.
    """
    self._check_owner()
    self._transfer_ownership(empty(address))


@internal
def _check_owner():
    """
    @dev Throws if the sender is not the owner.
    """
    assert msg.sender == self.owner, "ownable: caller is not the owner"


@internal
def _transfer_ownership(new_owner: address):
    """
    @dev Transfers the ownership of the contract
         to a new account `new_owner`.
    @notice This is an `internal` function without
            access restriction.
    @param new_owner The 20-byte address of the new owner.
    """
    old_owner: address = self.owner
    self.owner = new_owner
    log OwnershipTransferred(previous_owner=old_owner, new_owner=new_owner)

.venv/lib/python3.12/site-packages/snekmate/utils/ecdsa.vy

# pragma version ~=0.4.3
# pragma nonreentrancy off
"""
@title Elliptic Curve Digital Signature Algorithm (ECDSA) Secp256k1-Based Functions
@custom:contract-name ecdsa
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions can be used to verify that a message was signed by
        the holder of the private key of a given address. All cryptographic
        calculations are based on the Ethereum-native secp256k1 elliptic curve
        (see https://en.bitcoin.it/wiki/Secp256k1). For verification functions
        based on the NIST P-256 elliptic curve (also known as secp256r1), see
        the {p256} contract. The implementation is inspired by OpenZeppelin's
        implementation here:
        https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol.
@custom:security Signatures must not be used as unique identifiers since the
                 `ecrecover` EVM precompile allows for malleable (non-unique)
                 signatures (see EIP-2: https://eips.ethereum.org/EIPS/eip-2)
                 or signatures can be malleablised using EIP-2098:
                 https://eips.ethereum.org/EIPS/eip-2098.
"""


# @dev The malleability threshold used as part of the ECDSA
# verification function.
_MALLEABILITY_THRESHOLD: constant(uint256) = (
    57_896_044_618_658_097_711_785_492_504_343_953_926_418_782_139_537_452_191_302_581_570_759_080_747_168
)


@deploy
@payable
def __init__():
    """
    @dev To omit the opcodes for checking the `msg.value`
         in the creation-time EVM bytecode, the constructor
         is declared as `payable`.
    """
    pass


@internal
@pure
def _recover_sig(hash: bytes32, signature: Bytes[65]) -> address:
    """
    @dev Recovers the signer address from a message digest `hash`
         and the signature `signature`.
    @notice WARNING: This function is vulnerable to a kind of
            signature malleability due to accepting EIP-2098
            compact signatures in addition to the traditional
            65-byte signature format. The potentially affected
            contracts are those that implement signature reuse
            or replay protection by marking the signature itself
            as used rather than the signed message or a nonce
            included in it. A user may take a signature that has
            already been submitted, submit it again in a different
            form, and bypass this protection. Also, see OpenZeppelin's
            security advisory for more information:
            https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-4h98-2769-gh6h.
    @param hash The 32-byte message digest that was signed.
    @param signature The secp256k1 64/65-byte signature of `hash`.
    @return address The recovered 20-byte signer address.
    """
    sig_length: uint256 = len(signature)
    # 65-byte case: `(r,s,v)` standard signature.
    if sig_length == 65:
        r: uint256 = extract32(signature, empty(uint256), output_type=uint256)
        s: uint256 = extract32(signature, 32, output_type=uint256)
        v: uint256 = convert(slice(signature, 64, 1), uint256)
        return self._try_recover_vrs(hash, v, r, s)
    # 64-byte case: `(r,vs)` signature; see: https://eips.ethereum.org/EIPS/eip-2098.
    elif sig_length == 64:
        r: uint256 = extract32(signature, empty(uint256), output_type=uint256)
        vs: uint256 = extract32(signature, 32, output_type=uint256)
        return self._try_recover_r_vs(hash, r, vs)

    return empty(address)


@internal
@pure
def _recover_vrs(hash: bytes32, v: uint256, r: uint256, s: uint256) -> address:
    """
    @dev Recovers the signer address from a message digest `hash`
         and the secp256k1 signature parameters `v`, `r`, and `s`.
    @param hash The 32-byte message digest that was signed.
    @param v The secp256k1 1-byte signature parameter `v`.
    @param r The secp256k1 32-byte signature parameter `r`.
    @param s The secp256k1 32-byte signature parameter `s`.
    @return address The recovered 20-byte signer address.
    """
    return self._try_recover_vrs(hash, v, r, s)


@internal
@pure
def _try_recover_r_vs(hash: bytes32, r: uint256, vs: uint256) -> address:
    """
    @dev Recovers the signer address from a message digest `hash`
         and the secp256k1 short signature fields `r` and `vs`.
    @notice See https://eips.ethereum.org/EIPS/eip-2098 for the
            compact signature representation.
    @param hash The 32-byte message digest that was signed.
    @param r The secp256k1 32-byte signature parameter `r`.
    @param vs The secp256k1 32-byte short signature field of `v` and `s`.
    @return address The recovered 20-byte signer address.
    """
    s: uint256 = vs & convert(max_value(int256), uint256)
    # We do not check for an overflow here, as the shift operation
    # `vs >> 255` results in `0` or `1`.
    v: uint256 = unsafe_add(vs >> 255, 27)
    return self._try_recover_vrs(hash, v, r, s)


@internal
@pure
def _try_recover_vrs(hash: bytes32, v: uint256, r: uint256, s: uint256) -> address:
    """
    @dev Recovers the signer address from a message digest `hash`
         and the secp256k1 signature parameters `v`, `r`, and `s`.
    @notice All client implementations of the precompile `ecrecover`
            check if the value of `v` is `27` or `28`. The references
            for the different client implementations can be found here:
            https://github.com/ethereum/yellowpaper/pull/860. Thus,
            the signature check on the value of `v` is neglected.
    @param hash The 32-byte message digest that was signed.
    @param v The secp256k1 1-byte signature parameter `v`.
    @param r The secp256k1 32-byte signature parameter `r`.
    @param s The secp256k1 32-byte signature parameter `s`.
    @return address The recovered 20-byte signer address.
    """
    assert s <= _MALLEABILITY_THRESHOLD, "ecdsa: invalid signature `s` value"

    signer: address = ecrecover(hash, v, r, s)
    assert signer != empty(address), "ecdsa: invalid signature"

    return signer

.venv/lib/python3.12/site-packages/snekmate/utils/eip712_domain_separator.vy

# pragma version ~=0.4.3
# pragma nonreentrancy off
"""
@title EIP-712 Domain Separator
@custom:contract-name eip712_domain_separator
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions are part of EIP-712: https://eips.ethereum.org/EIPS/eip-712.
        These functions implement the version of encoding known
        as "v4" as implemented by the JSON-RPC method:
        https://docs.metamask.io/guide/signing-data.html#sign-typed-data-v4.
        In addition, this contract also implements EIP-5267:
        https://eips.ethereum.org/EIPS/eip-5267.
        The implementation is inspired by OpenZeppelin's implementation here:
        https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol.
"""


# @dev We import and implement the `IERC5267` interface,
# which is written using standard Vyper syntax.
from .interfaces import IERC5267
implements: IERC5267


# @dev We import the `message_hash_utils` module.
# @notice Please note that the `message_hash_utils`
# module is stateless and therefore does not require
# the `uses` keyword for usage.
from . import message_hash_utils


# @dev The 32-byte type hash for the EIP-712 domain separator.
_TYPE_HASH: constant(bytes32) = keccak256(
    "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
)


# @dev Caches the domain separator as an `immutable`
# value, but also stores the corresponding chain ID
# to invalidate the cached domain separator if the
# chain ID changes.
_CACHED_DOMAIN_SEPARATOR: immutable(bytes32)
_CACHED_CHAIN_ID: immutable(uint256)


# @dev Caches `self` to `immutable` storage to avoid
# potential issues if a vanilla contract is used in
# a `delegatecall` context.
_CACHED_SELF: immutable(address)


# @dev `immutable` variables to store the (hashed)
# name and (hashed) version during contract creation.
_NAME: immutable(String[50])
_HASHED_NAME: immutable(bytes32)
_VERSION: immutable(String[20])
_HASHED_VERSION: immutable(bytes32)


@deploy
@payable
def __init__(name_: String[50], version_: String[20]):
    """
    @dev Initialises the domain separator and the parameter caches.
         To omit the opcodes for checking the `msg.value` in the
         creation-time EVM bytecode, the constructor is declared as
         `payable`.
    @notice The definition of the domain separator can be found here:
            https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator.
            Since the Vyper design requires strings of fixed size,
            we arbitrarily set the maximum length for `name` to 50
            characters and `version` to 20 characters.
    @param name_ The maximum 50-character user-readable string name
           of the signing domain, i.e. the name of the dApp or protocol.
    @param version_ The maximum 20-character current main version of
           the signing domain. Signatures from different versions are
           not compatible.
    """
    _NAME = name_
    _VERSION = version_
    _HASHED_NAME = keccak256(name_)
    _HASHED_VERSION = keccak256(version_)
    _CACHED_DOMAIN_SEPARATOR = self._build_domain_separator()
    _CACHED_CHAIN_ID = chain.id
    _CACHED_SELF = self


@external
@view
def eip712Domain() -> (bytes1, String[50], String[20], uint256, address, bytes32, DynArray[uint256, 32]):
    """
    @dev Returns the fields and values that describe the domain
         separator used by this contract for EIP-712 signatures.
    @notice The bits in the 1-byte bit map are read from the least
            significant to the most significant, and fields are indexed
            in the order that is specified by EIP-712, identical to the
            order in which they are listed in the function type.
    @return bytes1 The 1-byte bit map where bit `i` is set to `1`
            if and only if domain field `i` is present (`0 ≤ i ≤ 4`).
    @return String The maximum 50-character user-readable string name
            of the signing domain, i.e. the name of the dApp or protocol.
    @return String The maximum 20-character current main version of
            the signing domain. Signatures from different versions are
            not compatible.
    @return uint256 The 32-byte EIP-155 chain ID.
    @return address The 20-byte address of the verifying contract.
    @return bytes32 The 32-byte disambiguation salt for the protocol.
    @return DynArray The 32-byte array of EIP-712 extensions.
    """
    # Note that `0x0f` equals `01111`.
    return (0x0f, _NAME, _VERSION, chain.id, self, empty(bytes32), empty(DynArray[uint256, 32]))


@internal
@view
def _domain_separator_v4() -> bytes32:
    """
    @dev Returns the domain separator for the current chain.
    @return bytes32 The 32-byte domain separator.
    """
    if self == _CACHED_SELF and chain.id == _CACHED_CHAIN_ID:
        return _CACHED_DOMAIN_SEPARATOR

    return self._build_domain_separator()


@internal
@view
def _build_domain_separator() -> bytes32:
    """
    @dev Builds the domain separator for the current chain.
    @return bytes32 The 32-byte domain separator.
    """
    return keccak256(abi_encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, chain.id, self))


@internal
@view
def _hash_typed_data_v4(struct_hash: bytes32) -> bytes32:
    """
    @dev Returns the hash of the fully encoded EIP-712
         message for this domain.
    @notice The definition of the hashed struct can be found here:
            https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct.
    @param struct_hash The 32-byte hashed struct.
    @return bytes32 The 32-byte fully encoded EIP712
            message hash for this domain.
    """
    return message_hash_utils._to_typed_data_hash(self._domain_separator_v4(), struct_hash)

.venv/lib/python3.12/site-packages/snekmate/utils/interfaces/IERC5267.vyi

# pragma version ~=0.4.3
"""
@title EIP-5267 Interface Definition
@custom:contract-name IERC5267
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice The ERC-5267 standard complements the EIP-712 standard
        by standardising how contracts should publish the fields
        and values that describe their domain. This enables
        applications to retrieve this description and generate
        appropriate domain separators in a general way, and thus
        integrate EIP-712 signatures securely and scalably. For
        more details, please refer to:
        https://eips.ethereum.org/EIPS/eip-5267.

        Note that Vyper interfaces that implement functions
        with return values that require an upper bound (e.g.
        `Bytes`, `DynArray`, or `String`), the upper bound
        defined in the interface represents the lower bound
        of the implementation:
        https://github.com/vyperlang/vyper/pull/3205.

        On how to use interfaces in Vyper, please visit:
        https://vyper.readthedocs.io/en/latest/interfaces.html#interfaces.
"""


# @dev May be emitted to signal that the domain could
# have changed.
event EIP712DomainChanged:
    pass


@external
@view
def eip712Domain() -> (bytes1, String[50], String[20], uint256, address, bytes32, DynArray[uint256, 32]):
    """
    @dev Returns the fields and values that describe the domain
         separator used by this contract for EIP-712 signatures.
    @notice The bits in the 1-byte bit map are read from the least
            significant to the most significant, and fields are indexed
            in the order that is specified by EIP-712, identical to the
            order in which they are listed in the function type.
    @return bytes1 The 1-byte bit map where bit `i` is set to `1`
            if and only if domain field `i` is present (`0 ≤ i ≤ 4`).
    @return String The maximum 50-character user-readable string name
            of the signing domain, i.e. the name of the dApp or protocol.
    @return String The maximum 20-character current main version of
            the signing domain. Signatures from different versions are
            not compatible.
    @return uint256 The 32-byte EIP-155 chain ID.
    @return address The 20-byte address of the verifying contract.
    @return bytes32 The 32-byte disambiguation salt for the protocol.
    @return DynArray The 32-byte array of EIP-712 extensions.
    """
    ...

.venv/lib/python3.12/site-packages/snekmate/utils/message_hash_utils.vy

# pragma version ~=0.4.3
# pragma nonreentrancy off
"""
@title Signature Message Hash Utility Functions
@custom:contract-name message_hash_utils
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions can be used to generate message hashes that conform
        to the EIP-191 (https://eips.ethereum.org/EIPS/eip-191) as well as
        EIP-712 (https://eips.ethereum.org/EIPS/eip-712) specifications. The
        implementation is inspired by OpenZeppelin's implementation here:
        https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MessageHashUtils.sol.
"""


@deploy
@payable
def __init__():
    """
    @dev To omit the opcodes for checking the `msg.value`
         in the creation-time EVM bytecode, the constructor
         is declared as `payable`.
    """
    pass


@internal
@pure
def _to_eth_signed_message_hash(hash: bytes32) -> bytes32:
    """
    @dev Returns an Ethereum signed message from a 32-byte
         message digest `hash`.
    @notice This function returns a 32-byte hash that
            corresponds to the one signed with the JSON-RPC method:
            https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign.
            This method is part of EIP-191:
            https://eips.ethereum.org/EIPS/eip-191.
    @param hash The 32-byte message digest.
    @return bytes32 The 32-byte Ethereum signed message.
    """
    return keccak256(concat(b"\x19Ethereum Signed Message:\n32", hash))


@internal
@view
def _to_data_with_intended_validator_hash_self(data: Bytes[1_024]) -> bytes32:
    """
    @dev Returns an Ethereum signed data with this contract
         as the intended validator and a maximum 1,024-byte
         payload `data`.
    @notice This function structures the data according to
            the version `0x00` of EIP-191:
            https://eips.ethereum.org/EIPS/eip-191#version-0x00.
    @param data The maximum 1,024-byte data to be signed.
    @return bytes32 The 32-byte Ethereum signed data.
    """
    return self._to_data_with_intended_validator_hash(self, data)


@internal
@pure
def _to_data_with_intended_validator_hash(validator: address, data: Bytes[1_024]) -> bytes32:
    """
    @dev Returns an Ethereum signed data with `validator` as
         the intended validator and a maximum 1,024-byte payload
         `data`.
    @notice This function structures the data according to
            the version `0x00` of EIP-191:
            https://eips.ethereum.org/EIPS/eip-191#version-0x00.
    @param validator The 20-byte intended validator address.
    @param data The maximum 1,024-byte data to be signed.
    @return bytes32 The 32-byte Ethereum signed data.
    """
    return keccak256(concat(x"1900", convert(validator, bytes20), data))


@internal
@pure
def _to_typed_data_hash(domain_separator: bytes32, struct_hash: bytes32) -> bytes32:
    """
    @dev Returns an Ethereum signed typed data from a 32-byte
         `domain_separator` and a 32-byte `struct_hash`.
    @notice This function returns a 32-byte hash that
            corresponds to the one signed with the JSON-RPC method:
            https://eips.ethereum.org/EIPS/eip-712#specification-of-the-eth_signtypeddata-json-rpc.
            This method is part of EIP-712:
            https://eips.ethereum.org/EIPS/eip-712.
    @param domain_separator The 32-byte domain separator that is
           used as part of the EIP-712 encoding scheme.
    @param struct_hash The 32-byte struct hash that is used as
           part of the EIP-712 encoding scheme. See the definition:
           https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct.
    @return bytes32 The 32-byte Ethereum signed typed data.
    """
    return keccak256(concat(x"1901", domain_separator, struct_hash))
Compiler settingsShow
{
  "search_paths": [
    ".venv/lib/python3.12/site-packages",
    "."
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.