Lock & Unlock Connector Scheme
Create contract with name UTSConnectorLockUnlockShowcase
.
You need to import:
UTSBase
is our main contract that should be inherited by any Token or Connector.
In this implementation we also used Ownable
, Pausable
and IERC20Metadata
We are starting with defining contract and dependencies. As access control we are choosing Ownable
.
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 here.
_allowedChainIds
are simply whitelist of chain id's, where you are allowing to bridge tokens.
_chainConfigs
is array of settings responsible for bridge settings. We described this config here.
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.
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.
Also we need to use SafeERC20
library by OpenZeppelin.
So, our contract is ready, now it can be deployed on networks and we can start bridging tokens between each chain.
You can find full code here
Last updated