LogoLogo
  • Entangle
    • Overview
    • Security Audits
  • Universal Interoperability Protocol
    • Overview
    • Architecture
      • Scalability and Network Stability
        • L2 Utility Blockchains
        • Transmitter Groups
      • Security and Consensus Mechanism
      • Finality
      • Execution Latency
      • Compatibility and Interoperability
    • Developer Guides
      • Getting Started
      • Solidity
        • Simple Abstract Messenger Example
        • Deploying Your Custom EVM Protocol
        • Bridging Tokens with UIP
        • Become an EVM Transmitter
      • Solana
        • Simple Abstract Messenger Example
        • Deploying Your Custom Solana Protocol
        • Become a Solana Transmitter
      • Calculate Cross-Chain Transaction Cost
      • Customizable Message Transmission Options
      • How to Debug Sent Messages
      • SDK Setup
      • Revenue Sharing for Transmitters
      • How to Become a Super Transmitter
    • Endpoints
  • Universal Data Feeds
    • Overview
    • Architecture
      • Data Delivery Methods
        • Pull Model
        • Push Model
      • Oracle Contract & User Interaction
    • Developer Guides
      • Custom Data Feeds
      • Fetch Data via Pull Model (PAYG)
        • EVM Smart Contracts
        • Solana Smart Contracts
      • Fetch Data via Pull Model (Subscriptions)
        • EVM Smart Contracts
        • Solana Smart Contracts
      • Fetch Data via Push Model
        • EVM Smart Contracts
        • Solana Smart Contracts
    • User Guides
      • Accessing Feeds
      • Subscribe to a Data Feed
      • Check Subscription
      • Manage Subscription
      • Renew Subscription
    • Data Endpoints
  • Universal Token Standard
    • Overview
    • Architecture
      • Fee Components
    • Developer Guides
      • Manual Deploy
        • Token Deployment Types
        • Create a Custom Token
        • Factory Blueprint Deployment
        • Examples
          • Initial Setup
          • UTS Connector
            • Mint & Burn Connector Scheme
            • Lock & Unlock Connector Scheme
            • Connector Over Native Currency
          • UTS Token
            • Simple Token
            • Token with Messages
      • Bridge SDK
      • Token Verification
      • Fees Calculation & Gas Estimation Logic
      • Estimations
    • User Guides
      • Launch Universal Token
      • Create a Liquidity Pool
      • Expand Existing Token
      • Transfer Liquidity to Connector
      • Bridging
    • Contract Addresses
  • Entangle Interoperable Blockchain
    • Overview
    • Architecture
    • Developer Guides
      • Set up a Validator Node
      • Delegating to Validators
      • Undelegating from Validators
      • Supported Accounts
  • More
    • Media Kit
    • FAQ
    • Report an Issue
    • Become a Partner
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Universal Token Standard
  2. Developer Guides
  3. Manual Deploy
  4. Examples
  5. UTS Connector

Lock & Unlock Connector Scheme

Create contract with name UTSConnectorLockUnlockShowcase .

You need to import:

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@entangle-labs/uts-contracts/contracts/ERC20/UTSBase";

UTSBase is our main contract that should be inherited by any Token or Connector.

In this implementation we also used Ownable, Pausable and IERC20Metadata

contract UTSConnectorLockUnlockShowcase is UTSBase, Ownable {}

We are starting with defining contract and dependencies. As access control we are choosing Ownable.

constructor(
    address underlyingToken_,
    address _router,  
    uint256[] memory _allowedChainIds,
    ChainConfig[] memory _chainConfigs
) Ownable(msg.sender) {
    __UTSBase_init(underlyingToken_, IERC20Metadata(underlyingToken_).decimals());

    _setRouter(_router);
    _setChainConfig(_allowedChainIds, _chainConfigs);
}

_allowedChainIds are simply whitelist of chain id's, where you are allowing to bridge tokens.

In constructor we need to call __UTSBase_init function to initialize UTS Base contract. Also we need to set router and chain config.

We can skip setting router and chain configs in constructor, but before starting bridging we need to do it with relevant public functions.

After this step we need to override 3 functions: _mintTo, _burnFrom and _authorizeCall.

Since this connector is working via lock/unlock scheme, you need to fulfill it, to start bridging to this connector. This can be done or via just transferring underlying token to connector, or you can initially bridge your tokens from this connector to any chain where you have uts token or connector with non zero balance and initial money will be locked in connector.

function _authorizeCall() internal override onlyOwner() {}
function _burnFrom(
    address spender,
    address /* from */, 
    bytes memory /* to */, 
    uint256 amount, 
    uint256 /* dstChainId */, 
    bytes memory /* customPayload */
) internal override returns(uint256 bridgedAmount) {
    IERC20(_underlyingToken).safeTransferFrom(spender, address(this), amount);

    return amount;
}
function _mintTo(    
    address to,
    uint256 amount,
    bytes memory /* customPayload */,
    Origin memory /* origin */
) internal override returns(uint256 receivedAmount) {
    IERC20(_underlyingToken).safeTransfer(to, amount);

    return amount;
}

So, here is very simple logic, in the outbounding bridge transaction, we need to transfer tokens from spender to connector address, in the inbounding redeem transaction, we need to transfer tokens from connector to receiver to address.

Also we will implement one more function: getter for underlying token decimals.

function underlyingDecimals() external view returns(uint8) {
    return _decimals;
}

Also we need to use SafeERC20 library by OpenZeppelin.

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

using SafeERC20 for IERC20;

So, our contract is ready, now it can be deployed on networks and we can start bridging tokens between each chain.

PreviousMint & Burn Connector SchemeNextConnector Over Native Currency

Last updated 4 months ago

Was this helpful?

Then we need do define constructor. Since it is connector, we need underlyingToken_(the token that will be bridged through UTS protocol). We need also setup _router address, that can be found .

_chainConfigs is array of settings responsible for bridge settings. We described this config .

You can find full code

here
here
here