Skip to content

XDCFoundation/XDC-AlarmClock-Smart-Contract-Tool

Repository files navigation

XDC-Smart-Contract-Tool

Time Locked Smart Contracts


Create Time locked smart contracts where the time is sourced from a Chainlink oracle. A user needs to specify the following to set up the smart contract:

  • Amount of XDC to be locked in smart contract
  • A date and time at which the locked XDC will be released by the smart contract
  • XDC address where the XDC will be sent after it is released by the smart contract

Table of contents


Overview


Time Locked Smart Contract is a feature which allows users to send XDC payments to multiple receivers. These conditional payments, sets the XDC aside and transfers it to receivers when the time has elapsed. After the time has expired, only the intended receivers can get the locked up XDC.

Time Locked Contarct

Prerequisite


This application requires integration of XDC Network Network with Chainlink. It is recommended to follow XinFin-Chainlink guide and setup all the required applications which includes -

  • Chainlink node
  • Chainlink - External Initiator
  • Deploying LINK token contract
  • Deploying Oracle contract

Tools & Technologies


Following tools and technologies have been usse to develop Time Locked Smart Contract application -

Design

Configuring Chainlink Job


Create an Alarm Job in Chainlink node. Steps to create Alarm Job -

  • Login to Chainlink node
  • Navigate to Jobs and click on New Job
  • Copy the job specification form chainlink/alarm-job.json file
  • Paste the contents into the Json Spec field and create the job
  • Copy the newly created job ID which we will be using later

Deploying Time Locked Contracts


Compile and deploy the contracts required for Time Locked Smart Contract creation using remix editor.

  • contracts/TimeLockedContractFactory.sol - Factory contract used to create Time Locked Contracts and tracks all the contracts created by users.
  • contracts/TimeLockedContract.sol - Contract implementing ChainlinkClient which is responsible for initiating Alarm Job in Chainlink and implements the callback function which will be invoked on time expiry. Stores all the information related to the contract which includes -
    • Receivers and corresponding XDC to be locked up
    • Unlock date

Deploy the TimeLockedContractFactory using remix editor and take a note of the deployed contract address which we will be using later.

By the end of this step we should have following addresses -

Keyword Description
TLW_FACTORY_CONTRACT_ADDR Address of the deployed Time Locked Contract Factory
LINK_TOKEN_CONTRACT_ADDR Address of the deployed LINK token contract
ORACLE_CONTRACT_ADDR Address of the deployed Oracle contract
CHAIN_LINK_JOB_ID Address of the alarm job created in Chainlink node

Configuring the Application

--

Before building or running the application following fields values should be replaced in ui/src/assets/js/config.js.

NOTE: Network id 51 refers to XDC Apothem network and 50 refers to XDC Main network

  • TLW_FACTORY_CONTRACT_ADDR
  • LINK_TOKEN_CONTRACT_ADDR
  • ORACLE_CONTRACT_ADDR
  • CHAIN_LINK_JOB_ID

Building The Application


Using npm

  • For local development, run the below command from project root directory and access the application using http://localhost:3000

    npm install
    npm run serve -- --port 3000
  • For production environments, run the below command and once the build is successful final artifacts should be available in dist/ directory

    npm run build

Using Docker

docker build -t tlc .
docker run -p 8080:8080 tlc

Accessing the Application


Login


  • An account in XDCPay is required to access the application. Users will approve the transaction using XDCPay.
  • Make sure the address added in XDCPay has sufficient XDC based on the network being used.
  • Add the Link token address in XDCPay wallet and make sure there is sufficient LINK balance.

Login

Contracts


Displays the list of contracts created by the user with following information -

Field Description
Contract Address Address of the Time Locked Contract
XDC Total amount of XDC locked up
Created Date Contract creation date
Unlock Date XDC release date
Receivers Total number of receivers and corresponding XDC locked up
Status Status of the transaction

User will be provided with following actions based on the contract status -

Action Description
Transfer Link Token This option will be available only if LINK token is not transferred to the contract. Using this option LINK token can be transferred to the contract to initiate the Chainlink job
Withdraw Contract This option will be available only if LINK token is not transferred and when contract is not initiated. Using this option user can withdraw the total allocated XDC back to wallet

Contracts

New Contract


Creating Time Locked Contract is a 2 step process, which includes -

  • Creating a new Contract
  • Transferring the LINK token and initiating Alarm Job in Chainlink

New Contract

Creating a new Contract
  • User specifies the duration of XDC lockup
  • Amount of XDC to be allocated to each receiver

On contract creation, XDC will be transferred from user's wallet to the new contract.

Transferring the LINK token and initiating Alarm Job in Chainlink

In this step, LINK token (Link fee) will be transferred to the created contract. Link fee is required to initiate the job Chainlink job.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •