all files / contracts/token/ERC20/ SpanningERC20Container.sol

94.74% Statements 72/76
80% Branches 16/20
97.44% Functions 38/39
93.67% Lines 74/79
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779                                                                                                    21× 21×                                                                                                                         21×                                                                                                                                                             12×                                                                                                                                                                                                                                                                                                                                                                                                                                 11×       10×                           12×         11×         11×         11×         11×                                                                                 17×       16×         15× 15× 15× 15×                                                                                                                                                                                                                                                                                                                                                                                                                     20× 20×                                           15× 15×              
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright (C) 2022 Spanning Labs Inc.
 
pragma solidity ^0.8.0;
 
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/Context.sol";
 
import "../../ISpanningDelegate.sol";
import "./ISpanningERC20.sol";
import "../../SpanningUtils.sol";
import "../../Spanning.sol";
 
/**
 * @dev Implementation of the {ISpanningERC20} interface.
 */
abstract contract SpanningERC20Container is
    Spanning,
    Context,
    ISpanningERC20,
    IERC20Metadata
{
    // This allows us to efficiently unpack data in our address specification.
    using SpanningAddress for bytes32;
 
    // Tracking ownership, keyed based on Address
    mapping(bytes32 => uint256) internal balances_;
 
    // Tracking allowances, keyed based on Address pairs
    mapping(bytes32 => mapping(bytes32 => uint256)) internal allowances_;
 
    // Standard metadata: supply cap
    uint256 internal totalSupply_;
    // Standard metadata: token name
    string internal name_;
    // Standard metadata: token symbol
    string internal symbol_;
 
    /**
     * @dev Creates the instance and assigns required values.
     *
     * @param nameIn - Desired name for the token
     * @param symbolIn - Desired symbol for the token
     * @param delegate - Legacy (local) address for the Spanning Delegate
     */
    constructor(
        string memory nameIn,
        string memory symbolIn,
        address delegate
    ) Spanning(delegate) {
        name_ = nameIn;
        symbol_ = symbolIn;
    }
 
    /**
     * @return string - Name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return name_;
    }
 
    /**
     * @return string - Symbol of the token.
     */
    function symbol() public view virtual override returns (string memory) {
        return symbol_;
    }
 
    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * @return uint8 - Number of decimals used to get a user representation.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }
 
    /**
     * @return string - Total supply of the token.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return totalSupply_;
    }
 
    /**
     * @dev Returns the amount of tokens owned by an account.
     *
     * @param accountLegacyAddress - Legacy (local) address to be queried
     *
     * @return uint256 - Token value for an account
     */
    function balanceOf(address accountLegacyAddress)
        public
        view
        virtual
        override
        returns (uint256)
    {
        bytes32 derivedAddress = getAddressFromLegacy(accountLegacyAddress);
        return balances_[derivedAddress];
    }
 
    /**
     * @dev Returns the amount of tokens owned by an account.
     *
     * @param account - Address to be queried
     *
     * @return uint256 - Token value for an account
     */
    function balanceOf(bytes32 account)
        public
        view
        virtual
        override
        returns (uint256)
    {
        return balances_[account];
    }
 
    /**
     * @dev Moves tokens from the caller's account to another account.
     *
     * @param receiverLegacyAddress - Legacy (local) address to receive the transfer
     * @param amount - Amount to transfer
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function transfer(address receiverLegacyAddress, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        bytes32 derivedSenderAddress = spanningMsgSender();
        bytes32 derivedReceiverAddress = getAddressFromLegacy(
            receiverLegacyAddress
        );
 
        _transfer(derivedSenderAddress, derivedReceiverAddress, amount);
        return true;
    }
 
    /**
     * @dev Moves tokens from the caller's account to another account.
     *
     * @param receiverAddress - Address to receive the transfer
     * @param amount - Amount to transfer
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function transfer(bytes32 receiverAddress, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        bytes32 derivedSenderAddress = spanningMsgSender();
 
        _transfer(derivedSenderAddress, receiverAddress, amount);
        return true;
    }
 
    /**
     * @dev Gets the number of authorized tokens in the allowance pair.
     *
     * Note: This value can change when {approve} or {transferFrom} are called
     * Note: The result is zero when an entry does not exist in the map
     *
     * @param senderLegacyAddress - Legacy (local) address of the allowance sender
     * @param receiverLegacyAddress - Legacy (local) address of the allowance receiver
     *
     * @return uint256 - Number of tokens in the allowance pair
     */
    function allowance(
        address senderLegacyAddress,
        address receiverLegacyAddress
    ) public view virtual override returns (uint256) {
        bytes32 derivedSenderAddress = getAddressFromLegacy(
            senderLegacyAddress
        );
        bytes32 derivedReceiverAddress = getAddressFromLegacy(
            receiverLegacyAddress
        );
 
        return allowance(derivedSenderAddress, derivedReceiverAddress);
    }
 
    /**
     * @dev Gets the number of authorized tokens in the allowance pair.
     *
     * Note: This value can change when {approve} or {transferFrom} are called
     * Note: The result is zero when an entry does not exist in the map
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     *
     * @return uint256 - Number of tokens in the allowance pair
     */
    function allowance(bytes32 senderAddress, bytes32 receiverAddress)
        public
        view
        virtual
        override
        returns (uint256)
    {
        return allowances_[senderAddress][receiverAddress];
    }
 
    /**
     * @dev Sets an allowance for a pair of addresses (sender and receiver).
     *
     * Note: There can be race conditions due to ordering. See more:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * @param receiverLegacyAddress - Legacy (local) address of the allowance receiver
     * @param amount - Amount of allowance to issue
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function approve(address receiverLegacyAddress, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        bytes32 derivedSenderAddress = spanningMsgSender();
        bytes32 derivedReceiverAddress = getAddressFromLegacy(
            receiverLegacyAddress
        );
 
        _approve(derivedSenderAddress, derivedReceiverAddress, amount);
        return true;
    }
 
    /**
     * @dev Sets an allowance for a pair of addresses (sender and receiver).
     *
     * Note: There can be race conditions due to ordering. See more:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount of allowance to issue
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function approve(bytes32 receiverAddress, uint256 amount)
        public
        virtual
        override
        returns (bool)
    {
        bytes32 derivedSenderAddress = spanningMsgSender();
 
        _approve(derivedSenderAddress, receiverAddress, amount);
        return true;
    }
 
    /**
     * @dev Transfers tokens from from sender to receiver.
     *
     * Note: This uses the allowance mechanism to transfer tokens.
     *
     * @param senderLegacyAddress - Legacy (local) address of the allowance sender
     * @param receiverLegacyAddress - Legacy (local) address of the allowance receiver
     * @param amount - Amount of allowance to issue
     * @return bool - Indicates whether the operation succeeded
     */
    function transferFrom(
        address senderLegacyAddress,
        address receiverLegacyAddress,
        uint256 amount
    ) public virtual override returns (bool) {
        bytes32 derivedSenderAddress = getAddressFromLegacy(
            senderLegacyAddress
        );
        bytes32 derivedReceiverAddress = getAddressFromLegacy(
            receiverLegacyAddress
        );
 
        return
            transferFrom(derivedSenderAddress, derivedReceiverAddress, amount);
    }
 
    /**
     * @dev Transfers tokens from from sender to receiver.
     *
     * Note: This uses the allowance mechanism to transfer tokens.
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount of allowance to issue
     * @return bool - Indicates whether the operation succeeded
     */
    function transferFrom(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(senderAddress, receiverAddress, amount);
 
        uint256 currentAllowance = allowance(
            senderAddress,
            spanningMsgSender()
        );
        require(
            currentAllowance >= amount,
            "ERC20: transfer amount exceeds allowance"
        );
        unchecked {
            _approve(
                senderAddress,
                spanningMsgSender(),
                currentAllowance - amount
            );
        }
 
        return true;
    }
 
    /**
     * @dev Pulls read-only information relevant to the domain ownership
     * from the appropriate middleware node or domain
     *
     * Note: This function should be called prior to reading any information
     * through this domain, to ensure data is up to date
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function updateRecords() public virtual override returns (bool) {
        // This is a passthrough for any base SpanningERC20. This domain maintains
        // the source of truth for the Spanning Token, so it is certainly up-to-date.
        return true;
    }
 
    /**
     * @dev Atomically increases the allowance
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {ISpanningERC20-approve}.
     *
     * @param receiverLegacyAddress - Legacy (local) address of the allowance receiver
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function increaseAllowance(
        address receiverLegacyAddress,
        uint256 addedValue
    ) public virtual returns (bool) {
        bytes32 derivedReceiverAddress = getAddressFromLegacy(
            receiverLegacyAddress
        );
        return increaseAllowance(derivedReceiverAddress, addedValue);
    }
 
    /**
     * @dev Atomically increases the allowance
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {ISpanningERC20-approve}.
     *
     * @param receiverAddress - Address of the allowance receiver
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function increaseAllowance(bytes32 receiverAddress, uint256 addedValue)
        public
        virtual
        returns (bool)
    {
        _approve(
            spanningMsgSender(),
            receiverAddress,
            allowance(spanningMsgSender(), receiverAddress) + addedValue
        );
        return true;
    }
 
    /**
     * @dev Atomically decreases the allowance
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {ISpanningERC20-approve}.
     *
     * @param receiverLegacyAddress - Legacy (local) address of the allowance receiver
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function decreaseAllowance(
        address receiverLegacyAddress,
        uint256 subtractedValue
    ) public virtual returns (bool) {
        bytes32 derivedReceiverAddress = getAddressFromLegacy(
            receiverLegacyAddress
        );
        return decreaseAllowance(derivedReceiverAddress, subtractedValue);
    }
 
    /**
     * @dev Atomically decreases the allowance
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {ISpanningERC20-approve}.
     *
     * @param receiverAddress - Address of the allowance receiver
     *
     * @return bool - Indicates whether the operation succeeded
     */
    function decreaseAllowance(bytes32 receiverAddress, uint256 subtractedValue)
        public
        virtual
        returns (bool)
    {
        uint256 currentAllowance = allowances_[spanningMsgSender()][
            receiverAddress
        ];
        require(
            currentAllowance >= subtractedValue,
            "ERC20: decreased allowance below zero"
        );
        unchecked {
            _approve(
                spanningMsgSender(),
                receiverAddress,
                currentAllowance - subtractedValue
            );
        }
 
        return true;
    }
 
    /**
     * @dev Moves tokens from the caller's account to another account.
     *
     * @param senderAddress - Address initiating the transfer
     * @param receiverAddress - Address receiving the transfer
     * @param amount - Amount to transfer
     */
    function _transfer(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {
        require(
            senderAddress.valid(),
            "ERC20 (transfer): invalid sender address"
        );
        require(
            receiverAddress.valid(),
            "ERC20 (transfer): invalid receiver address"
        );
 
        _beforeTokenTransfer(senderAddress, receiverAddress, amount);
        _duringTokenTransfer(senderAddress, receiverAddress, amount);
        _emitTransfer(senderAddress, receiverAddress, amount);
        _afterTokenTransfer(senderAddress, receiverAddress, amount);
    }
 
    /**
     * @dev Creates tokens and assigns ownership.
     *
     * @param receiverAddress - Address receiving the minted tokens
     * @param amount - Amount to mint
     */
    function _mint(bytes32 receiverAddress, uint256 amount) internal virtual {
        require(
            receiverAddress.valid(),
            "ERC20 (mint): invalid receiver address"
        );
 
        _beforeTokenMint(
            SpanningAddress.invalidAddress(),
            receiverAddress,
            amount
        );
        _duringTokenMint(
            SpanningAddress.invalidAddress(),
            receiverAddress,
            amount
        );
        _emitTransfer(
            SpanningAddress.invalidAddress(),
            receiverAddress,
            amount
        );
        _afterTokenMint(
            SpanningAddress.invalidAddress(),
            receiverAddress,
            amount
        );
    }
 
    /**
     * @dev Destroys tokens and lowering total supply.
     *
     * @param senderAddress - Address sending tokens to burn
     * @param amount - Amount to burn
     */
    function _burn(bytes32 senderAddress, uint256 amount) internal virtual {
        require(senderAddress.valid(), "ERC20 (burn): invalid sender address");
 
        _beforeTokenBurn(
            senderAddress,
            SpanningAddress.invalidAddress(),
            amount
        );
        _duringTokenBurn(
            senderAddress,
            SpanningAddress.invalidAddress(),
            amount
        );
        _emitTransfer(senderAddress, SpanningAddress.invalidAddress(), amount);
        _afterTokenBurn(
            senderAddress,
            SpanningAddress.invalidAddress(),
            amount
        );
    }
 
    /**
     * @dev Sets allowance pair between two addresses
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount to approve
     */
    function _approve(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {
        require(
            senderAddress.valid(),
            "ERC20 (approve): invalid sender address"
        );
        require(
            receiverAddress.valid(),
            "ERC20 (approve): invalid receiver address"
        );
 
        _beforeTokenApprove(senderAddress, receiverAddress, amount);
        _duringTokenApprove(senderAddress, receiverAddress, amount);
        _emitApproval(senderAddress, receiverAddress, amount);
        _afterTokenApprove(senderAddress, receiverAddress, amount);
    }
 
    /**
     * @dev Updates `senderAddress` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(senderAddress, receiverAddress);
        if (currentAllowance != type(uint256).max) {
            require(
                currentAllowance >= amount,
                "ERC20: insufficient allowance"
            );
            unchecked {
                _approve(
                    senderAddress,
                    receiverAddress,
                    currentAllowance - amount
                );
            }
        }
    }
 
    /**
     * @dev Hook that is called before any transfer of tokens.
     *
     * @param senderAddress - Address initiating the transfer
     * @param receiverAddress - Address receiving the transfer
     * @param amount - Amount to transfer
     */
    function _beforeTokenTransfer(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called during any transfer of tokens.
     *
     * @param senderAddress - Address initiating the transfer
     * @param receiverAddress - Address receiving the transfer
     * @param amount - Amount to transfer
     */
    function _duringTokenTransfer(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called after any transfer of tokens.
     *
     * @param senderAddress - Address initiating the transfer
     * @param receiverAddress - Address receiving the transfer
     * @param amount - Amount to transfer
     */
    function _afterTokenTransfer(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called before any burn of tokens.
     *
     * @param senderAddress - Address sending tokens to burn
     * @param receiverAddress - Unused
     * @param amount - Amount to burn
     */
    function _beforeTokenBurn(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called during any burn of tokens.
     *
     * @param senderAddress - Address sending tokens to burn
     * @param receiverAddress - Unused
     * @param amount - Amount to burn
     */
    function _duringTokenBurn(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called after any burn of tokens.
     *
     * @param senderAddress - Address sending tokens to burn
     * @param receiverAddress - Unused
     * @param amount - Amount to burn
     */
    function _afterTokenBurn(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called before any mint of tokens.
     *
     * @param senderAddress - Unused
     * @param receiverAddress - Address receiving the minted tokens
     * @param amount - Amount to mint
     */
    function _beforeTokenMint(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called during any mint of tokens.
     *
     * @param senderAddress - Unused
     * @param receiverAddress - Address receiving the minted tokens
     * @param amount - Amount to mint
     */
    function _duringTokenMint(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called after any mint of tokens.
     *
     * @param senderAddress - Unused
     * @param receiverAddress - Address receiving the minted tokens
     * @param amount - Amount to mint
     */
    function _afterTokenMint(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called before any allowance approval of tokens.
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount to approve
     */
    function _beforeTokenApprove(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called during any allowance approval of tokens.
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount to approve
     */
    function _duringTokenApprove(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Hook that is called after any allowance approval of tokens.
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount to approve
     */
    function _afterTokenApprove(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {}
 
    /**
     * @dev Emits both a Legacy Transfer event and Spanning Transfer event.
     *
     * Note: If an input Address is not domain-local, the Legacy Transfer event
     * field is set to 0. This avoids sending incorrect truncated data.
     *
     * @param senderAddress - Address initiating the transfer
     * @param receiverAddress - Address receiving the transfer
     * @param amount - Amount transferred
     */
    function _emitTransfer(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {
        emit Transfer(senderAddress, receiverAddress, amount);
        emit Transfer(
            getLegacyFromAddress(senderAddress),
            getLegacyFromAddress(receiverAddress),
            amount
        );
    }
 
    /**
     * @dev Emits both a Legacy Approval event and Spanning Approval event.
     *
     * Note: If an input Address is not domain-local, the Legacy Approval event
     * field is set to 0. This avoids sending incorrect truncated data.
     *
     * @param senderAddress - Address of the allowance sender
     * @param receiverAddress - Address of the allowance receiver
     * @param amount - Amount to transfer
     */
    function _emitApproval(
        bytes32 senderAddress,
        bytes32 receiverAddress,
        uint256 amount
    ) internal virtual {
        emit Approval(senderAddress, receiverAddress, amount);
        emit Approval(
            getLegacyFromAddress(senderAddress),
            getLegacyFromAddress(receiverAddress),
            amount
        );
    }
}