Skip to content
Verified contractPartialGPL-3.0

TransferValidationLib

Address0xc49275bea16629c86bf4636bf4bfb609102078d0
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
GPL-3.0
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,434,336
Creation transaction
0xfa86101418…90d6e988f7
Libraries
dependencies/trex-develop/contracts/token/TokenGuardsLib.sol:TokenGuardsLib0xc8e4…27bf58dependencies/trex-develop/contracts/token/TokenLedgerLib.sol:TokenLedgerLib0x543f…dbbf0bdependencies/trex-develop/contracts/token/TokenRecoveryLib.sol:TokenRecoveryLib0x5231…fbf9b4dependencies/trex-develop/contracts/interop/TREXMessagingLib.sol:TREXMessagingLib0x4142…75c5c9dependencies/trex-develop/contracts/token/TokenDelegationLib.sol:TokenDelegationLib0x52d2…4f45bedependencies/trex-develop/contracts/compliance/modular/ModuleSetLib.sol:ModuleSetLib0xf674…14900bdependencies/trex-develop/contracts/compliance/modular/TransferValidationLib.sol:TransferValidationLib0xc492…2078d0

36 files

The source code is large: one file is shown at a time. Choose a file in the list.

dependencies/trex-develop/contracts/compliance/modular/TransferValidationLib.sol

// SPDX-License-Identifier: GPL-3.0
//
//                                             :+#####%%%%%%%%%%%%%%+
//                                         .-*@@@%+.:+%@@@@@%%#***%@@%=
//                                     :=*%@@@#=.      :#@@%       *@@@%=
//                       .-+*%@%*-.:+%@@@@@@+.     -*+:  .=#.       :%@@@%-
//                   :=*@@@@%%@@@@@@@@@%@@@-   .=#@@@%@%=             =@@@@#.
//             -=+#%@@%#*=:.  :%@@@@%.   -*@@#*@@@@@@@#=:-              *@@@@+
//            =@@%=:.     :=:   *@@@@@%#-   =%*%@@@@#+-.        =+       :%@@@%-
//           -@@%.     .+@@@     =+=-.         @@#-           +@@@%-       =@@@@%:
//          :@@@.    .+@@#%:                   :    .=*=-::.-%@@@+*@@=       +@@@@#.
//          %@@:    +@%%*                         =%@@@@@@@@@@@#.  .*@%-       +@@@@*.
//         #@@=                                .+@@@@%:=*@@@@@-      :%@%:      .*@@@@+
//        *@@*                                +@@@#-@@%-:%@@*          +@@#.      :%@@@@-
//       -@@%           .:-=++*##%%%@@@@@@@@@@@@*. :@+.@@@%:            .#@@+       =@@@@#:
//      .@@@*-+*#%%%@@@@@@@@@@@@@@@@%%#**@@%@@@.   *@=*@@#                :#@%=      .#@@@@#-
//      -%@@@@@@@@@@@@@@@*+==-:-@@@=    *@# .#@*-=*@@@@%=                 -%@@@*       =@@@@@%-
//         -+%@@@#.   %@%%=   -@@:+@: -@@*    *@@*-::                   -%@@%=.         .*@@@@@#
//            *@@@*  +@* *@@##@@-  #@*@@+    -@@=          .         :+@@@#:           .-+@@@%+-
//             +@@@%*@@:..=@@@@*   .@@@*   .#@#.       .=+-       .=%@@@*.         :+#@@@@*=:
//              =@@@@%@@@@@@@@@@@@@@@@@@@@@@%-      :+#*.       :*@@@%=.       .=#@@@@%+:
//               .%@@=                 .....    .=#@@+.       .#@@@*:       -*%@@@@%+.
//                 +@@#+===---:::...         .=%@@*-         +@@@+.      -*@@@@@%+.
//                  -@@@@@@@@@@@@@@@@@@@@@@%@@@@=          -@@@+      -#@@@@@#=.
//                    ..:::---===+++***###%%%@@@#-       .#@@+     -*@@@@@#=.
//                                           @@@@@@+.   +@@*.   .+@@@@@%=.
//                                          -@@@@@=   =@@%:   -#@@@@%+.
//                                          +@@@@@. =@@@=  .+@@@@@*:
//                                          #@@@@#:%@@#. :*@@@@#-
//                                          @@@@@%@@@= :#@@@@+.
//                                         :@@@@@@@#.:#@@@%-
//                                         +@@@@@@-.*@@@*:
//                                         #@@@@#.=@@@+.
//                                         @@@@+-%@%=
//                                        :@@@#%@%=
//                                        +@@@@%-
//                                        :#%%=
//

// T-REX Smart Contracts
// The ERC-3643 token suite of the T-REX ecosystem.
//
// Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
//
// This file is part of the T-REX smart contract suite.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.8.30;

import { EventsLib } from "../../libraries/EventsLib.sol";
import { MessageTypesLib } from "../../libraries/MessageTypesLib.sol";
import { WalletKeyLib } from "../../libraries/WalletKeyLib.sol";
import { IToken } from "../../token/IToken.sol";
import { ComplianceLedgerLib } from "./ComplianceLedgerLib.sol";
import { ITransferValidation } from "./ITransferValidation.sol";

/**
 * @title TransferValidationLib
 * @dev The layout of the compliance's validation record, and the last step of an issuance, deployed once
 * and linked: once every question about a requested validation is answered, this takes the next id, keeps
 * the validation, reserves its amount, announces it and encodes what the satellites will execute against.
 *
 * That step is storage writes and ABI encoding the compliance would otherwise carry, and it is what kept
 * it over EIP-170. The compliance reaches it by DELEGATECALL, so the storage is its own namespaces at the
 * slots they always had, the token sees the compliance as its caller, and the event is the compliance's.
 * Deciding whether a validation may be issued, and sending its legs, stay in the compliance.
 */
library TransferValidationLib {

    /// @custom:storage-location erc7201:erc3643.storage.TransferValidation
    struct ValidationStorage {
        /// Added to the issuance timestamp to compute `expiry`. Zero blocks issuance.
        uint64 defaultValidityWindow;
        /// Per-chain worst-case reconciliation latency. Zero blocks issuance toward that chain.
        mapping(bytes32 chainKey => uint64 window) reconciliationWindows;
        /// Per-chain issuance pause, set by the manager or a breaching late reconciliation, lifted by the manager
        /// only.
        mapping(bytes32 chainKey => bool paused) issuancePaused;
        /// The last id issued. Ids start at 1.
        uint256 lastValidationId;
        /// Every issued validation, kept forever.
        mapping(uint256 validationId => ITransferValidation.Validation validation) validations;
    }

    // keccak256(abi.encode(uint256(keccak256("erc3643.storage.TransferValidation")) - 1)) & ~bytes32(uint256(0xff));
    bytes32 private constant VALIDATION_STORAGE_LOCATION =
        0x518dcda4927033bd42da8dd6047b92b4a950cebbc5bdd8461a5e9bb9c0545400;

    /// @dev What issuance works out before the first write, in memory so the flow stays one function.
    struct Draft {
        bytes32 fromChainKey;
        bytes32 toChainKey;
        bool twoLegs;
        address fromIdentity;
        address toIdentity;
        bytes32 fromKey;
        uint256 amountMin;
        uint256 amountMax;
        uint64 expiry;
        uint64 reconciliationWindow;
    }

    /// @dev Turns a settled draft into an issued validation: take the next id, build the object the satellite
    ///  will execute against, keep its terms, reserve the amount, then announce it.
    /// @param token the token the compliance is bound to
    /// @return validationId the id issued
    /// @return body the encoded validation, for the compliance to send, one leg per satellite chain involved
    function issue(bytes calldata from, bytes calldata to, bytes calldata spender, Draft memory draft, address token)
        external
        returns (uint256 validationId, bytes memory body)
    {
        validationId = ++layout().lastValidationId;

        MessageTypesLib.ComplianceValidation memory issued = MessageTypesLib.ComplianceValidation({
            validationId: validationId,
            from: from,
            to: to,
            spender: spender,
            amountMin: draft.amountMin,
            amountMax: draft.amountMax,
            expiry: draft.expiry,
            reconciliationWindow: draft.reconciliationWindow,
            token: token
        });
        _record(validationId, issued, from, to, draft, token);

        emit EventsLib.TransferValidationIssued(
            validationId, from, to, spender, draft.amountMin, draft.amountMax, draft.expiry, draft.reconciliationWindow
        );

        body = abi.encode(issued);
    }

    function layout() internal pure returns (ValidationStorage storage $) {
        assembly ("memory-safe") {
            $.slot := VALIDATION_STORAGE_LOCATION
        }
    }

    /// @dev Keeps the validation forever and reserves its amount. Everything written here is the issuance half
    ///  of {ITransferValidation-Validation}; the lifecycle half stays at its zero value until a settlement or a
    ///  discard moves it.
    function _record(
        uint256 validationId,
        MessageTypesLib.ComplianceValidation memory issued,
        bytes calldata from,
        bytes calldata to,
        Draft memory draft,
        address token
    ) private {
        ITransferValidation.Validation storage stored = layout().validations[validationId];
        stored.hash = MessageTypesLib.hashValidation(issued);
        stored.amountMin = draft.amountMin;
        stored.amountMax = draft.amountMax;
        stored.expiry = draft.expiry;
        stored.releaseAt = draft.expiry + draft.reconciliationWindow;
        stored.fromChainKey = draft.fromChainKey;
        stored.toChainKey = draft.toChainKey;
        stored.fromKey = draft.fromKey;
        stored.fromWallet = from;
        stored.toKey = WalletKeyLib.canonicalKey(to);
        stored.twoLegs = draft.twoLegs;
        stored.fromIdentity = draft.fromIdentity;
        stored.toIdentity = draft.toIdentity;
        stored.spender = issued.spender;
        // `reservePending` returns whether it reserved against the identities; it does not on a relocation.
        stored.relocation = !ComplianceLedgerLib.reservePending(draft.fromIdentity, draft.toIdentity, draft.amountMax);
        IToken(token).reserveForValidation(from, draft.amountMax);
    }

}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": false,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {
    "dependencies/trex-develop/contracts/token/TokenGuardsLib.sol": {
      "TokenGuardsLib": "0xC8E48bf2154d6f2aABC98B0a4743D0d3f327bf58"
    },
    "dependencies/trex-develop/contracts/token/TokenLedgerLib.sol": {
      "TokenLedgerLib": "0x543F036f6812c5a799C818465CE8760bFEdBBf0B"
    },
    "dependencies/trex-develop/contracts/token/TokenRecoveryLib.sol": {
      "TokenRecoveryLib": "0x5231A9f48994FBED949f051a53477349DCFBF9B4"
    },
    "dependencies/trex-develop/contracts/interop/TREXMessagingLib.sol": {
      "TREXMessagingLib": "0x4142e2230413f167Ab98D8A3DB5dFCe2A475c5c9"
    },
    "dependencies/trex-develop/contracts/token/TokenDelegationLib.sol": {
      "TokenDelegationLib": "0x52d24426b844737Fc5fdF704Bf68346CbB4F45BE"
    },
    "dependencies/trex-develop/contracts/compliance/modular/ModuleSetLib.sol": {
      "ModuleSetLib": "0xF674215e1FC78303C49960F9c0129A34f514900B"
    },
    "dependencies/trex-develop/contracts/compliance/modular/TransferValidationLib.sol": {
      "TransferValidationLib": "0xc49275Bea16629C86bF4636bf4bfB609102078d0"
    }
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@chainlink/=../dependencies/smartcontractkit-chainlink-evm-1.5.0/",
    "@dino/=../",
    "@createx/=../dependencies/createx-v1.0.0/",
    "@erc3643org/erc-3643/=../dependencies/erc3643org-4.2.0-beta1/",
    "@fee-collector/=../dependencies/FeeCollector-dev/",
    "@forge-std/=dependencies/forge-std-v1.14.0/",
    "@onchain-id/solidity/=dependencies/onchain-id-develop/",
    "@openzeppelin/contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.7.0/",
    "@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.7.0/",
    "@trex/=dependencies/trex-develop/",
    "@openzeppelin-contracts-5.7.0/=dependencies/@openzeppelin-contracts-5.7.0/",
    "@openzeppelin-contracts-upgradeable-5.7.0/=dependencies/@openzeppelin-contracts-upgradeable-5.7.0/",
    "@openzeppelin/accounts/=dependencies/onchain-id-develop/dependencies/@openzeppelin-accounts-0.0.0-4ceb836d/packages/contracts/src/",
    "forge-std-v1.14.0/=dependencies/forge-std-v1.14.0/src/",
    "forge-std/=dependencies/onchain-id-develop/dependencies/forge-std-v1.14.0/src/",
    "onchain-id-develop/=dependencies/onchain-id-develop/",
    "trex-develop/=dependencies/trex-develop/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.