Custom Gateway

  • The Standard Gateway enables deposits and withdrawals without additional configurations or approvals, offering a simple and efficient onboarding process.

  • The Generic-Custom Gateway allows developers to add custom functionalities to an ERC-20 contract or pair it with a specific ERC-20 contract on dKargo Chain.

Both Gateways are smart contracts provided by dKargo’s Token Bridge. If a developer or project builder requires a Gateway with additional features or custom functionality, they can opt for the Custom Gateway instead of using a pre-deployed option.

STEP 1 - Use case

As previously explained in the Token Bridge overview, the L2 Gateway:

  • Locks tokens during deposits.

  • Releases locked tokens during withdrawals.

Meanwhile, the L3 Gateway:

  • Mints tokens upon deposits.

  • Burns tokens upon withdrawals.

If additional functionalities need to be implemented within this Gateway framework, the Custom Gateway is the appropriate choice.

Below are examples of features that can be added through a Custom Gateway:

  • Whitelist verification to ensure that only authorized users can deposit or withdraw tokens.

  • Fee mechanism to charge users for utilizing the bridge.

  • Balance tracking to record the amount of tokens bridged in and out.

By leveraging a Custom Gateway, it is possible to implement tailored functionalities that meet specific requirements.

STEP 2 - Setting up a Custom Gatewey

This guide explains how to implement and use a Custom Gateway with an added functionality that allows an administrator (owner) to enable or disable deposits and withdrawals.

A Gateway must be deployed on both L2 and L3.

  • Deposit requests are processed through the L2 Custom Gateway, so the deposit enable/disable functionality must be implemented in the L2 Custom Gateway.

  • Withdrawal requests are processed through the L3 Custom Gateway, so the withdrawal enable/disable functionality must be implemented in the L3 Custom Gateway.

L2 Custom Gateway example

L3 Custom Gateway example

Additionally, the interface and methods compatible with the Token Bridge can be referenced in the provided code below.

CrosschainMessenger.sol

ICustomGateway.sol

STEP 3 - Setting up the token

The ERC-20 token contract required for the Custom Gateway is very similar to the one used in the Generic-Custom Gateway. However, the token registration process within the Gateway is omitted. This is because users must manually deploy the Custom Gateway and register the ERC-20 token themselves.

L2 ERC20 Token example

In the provided example code, the registerTokenOnL2() method does not include a call to L1OrbitCustomGateway(gateway).registerTokenToL2() . Instead only L1OrbitGatewayRouter(router).setGateway() is called.

The ERC-20 token deployed on L3 is implemented exactly the same as in the Generic-Custom Gateway.

L3 ERC-20 Token example

The key point is that the bridgeMint() and bridgeBurn() methods must be implemented to allow the Gateway to mint or burn L3 ERC-20 tokens during deposits and withdrawals.

STEP 4 - Register the Token and Custom Gateway

Once the Custom Gateway and ERC-20 token contracts have been deployed on L2 and L3 (a total of four contracts), the next step is to register them with the Gateway and GatewayRouter.

Storing Contract Addresses

In the custom gateway, use the setTokenBridgeInformation() method to store the addresses of the paired gateways and the ERC-20 toekn contract addresses.

Pairing Configuration

To enable the Custom Gateway, it must be registered and paired with the GatewayRouter on each chain.

  • Since the GatewayRouter is deployed on both L2 and L3, the pairing process is conducted using retryable ticket.

  • During this process, L2 ERC-20 DKA is required to pay transaction fees.

  • The registration process starts by calling a method on the L2 ERC-20 token contract.

Before starting the pairing process, ensure that the L2 ERC-20 token contract is approved to use L2 ERC-20 DKA for transaction fees.

The dKargo Token Bridge is a dApp built using Arbitrum’s Retryable Ticket mechanism.

  • A Retryable Ticket allows an L2 transaction to be created and executed on L3.

  • This mechanism enables L3 operations to be initiated directly from L2.

  • The transaction fees for this process are paid in L2 ERC-20 DKA.

Gateway Registration

The registerTokenOnL2 method in the L2 ERC-20 contract is used to call router.setGateway, registering the L2 Custom Gateway as the designated Gateway for the L2 ERC-20 token within the L2 GatewayRouter.

This process also sends a message to dKargo Chain, where the same operation is executed to register the L3 Custom Gateway in the L3 GatewayRouter.

Since the two Custom Gateways are registered on separate chains, it takes some time for the pairing process to be fully completed.

  • The registration request status will initially be marked as "Pending".

  • After approximately 10 minutes, the request is finalized, and the pairing is completed on dKargo Chain (L3).

The status of the registration request can be checked on dScanner’s [L2 ➔ L3 Transactions] (link) page.

Deposit & Withdraw Token

With the Custom Gateway now set up, deposits and withdrawals between Arbitrum Chain and dKargo Chain can be performed.

From this point forward, the deposit and withdrawal processes function identically to those of the Standard Gateway. Refer to the Standard Gateway’s deposit and withdrawal process for execution details.

Last updated