Energy Rental

Introduction

All transactions on JustLend DAO require Energy, which can only be acquired through staking or burning TRX. This process involves high costs and lengthy procedures. In response, JustLend DAO introduces the Energy Rental service, allowing users to rent Energy at a significantly reduced price compared to staking or burning TRX. The contract EnergyRental used to set up the Energy Rental service.

Solidity API

Query Interface

Query Rental order information

View the information of an order.

function rentals(
        address renter, 
        address receiver, 
        uint256 resourceType
    ) 
        public 
        view 
        returns (RentalInfo)

struct RentalInfo {
    uint256 amount;
    uint256 securityDeposit;
    uint256 rentIndex;
}

Parameter description:

ParameterTypeDescription

renter

address

Rent payer

receiver

address

Resource receiver

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns Values:

FieldTypeDescription

amount

uint256

Order resources corresponding to the number of TRX

securityDeposit

uint256

Order deposit, not updated to current

rentIndex

uint256

Order's global index at the time of its last update


Query current rental order information (updated to current)

View the information of an order, with the returned data updated to current.

function getRentInfo(
        address renter,
        address receiver,
        uint256 resourceType
    )
        external
        view
        returns (uint256, uint256)

Parameter description:

ParameterTypeDescription

renter

address

Rent payer

receiver

address

Resource receiver

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns Values:

FieldTypeDescription

[0] securityDeposit

uint256

Order deposit, updated to current

[1] rentIndex

uint256

Real-time global index of the order at the time of query

Write Interface

Rent resources

Rent resources, allow amount = 0 (extension only) or msg.value = 0 (no new deposit), both are 0 is not allowed.

function rentResource(
        address receiver,
        uint256 amount,
        uint256 resourceType
    )
        external
        payable

Parameter description:

ParameterTypeDescription

msg.sender

The payer for this rental

receiver

address

The resource receiver of this rental Not allowed to be a contract or an unactivated account

amount

uint256

The rent resource corresponding to the amount of TRX, the minimum unit, if the amount is not 0 (renewal only), it must be greater than 1 TRX

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

msg.value

New deposit of this time

Returns: None, revert on failure.


Return resources (called by payer)

Return resources. Return resources in the order (msg.sender, receiver, resourceType). When the remaining deposit is insufficient, all resources will be forcibly emptied, and the remaining deposit will be returned to the order payer.

function returnResource(
        address receiver,
        uint256 amount,
        uint256 resourceType
    )
        external
        returns (uint256)

Parameter description:

ParameterTypeDescription

msg.sender

Order payer

receiver

address

Resource receiver

amount

uint256

The amount of TRX correspounding to the resources returned, the minimum unit

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns: The amount of the deposit returned in this operation. 0 for a partial return.


Return resources (called by receiver)

Return resources. Return resources in the order (renter, msg.sender, resourceType). When the remaining deposit is insufficient, all resources will be forcibly emptied, and the remaining deposit will be returned to the order payer.

function returnResourceByReceiver(
        address renter,
        uint256 amount,
        uint256 resourceType
    )
        external
        returns (uint256)

Parameter description:

ParameterTypeDescription

msg.sender

Resource receiver

renter

address

Order payer

amount

uint256

The amount of TRX correspounding to the resources returned, the minimum unit

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns: The amount of the deposit returned in this operation. 0 for partial return.


Liquidate

When the order deposit is insufficient, the liquidator can liquidate the order, and the liquidator will get the liquidation reward. If there is any remaining deposit, it will be returned to the order payer.

function liquidate(
        address renter,
        address receiver,
        uint256 resourceType
    )
        external
        returns (uint256)

Parameter description:

ParameterTypeDescription

msg.sender

Liquidator

renter

address

Order payer

Receiver

address

Resource receiver

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns: Liquidation reward in this operation.

Key Events

EventDescription

RentResource( address indexed renter, address indexed receiver, uint256 addedAmount, uint256 resourceType, uint256 addedSecurityDeposit, uint256 amount)

Emits when renting occurs

  • addedAmount: the TRX amount (minimum unit) of the newly-rent resource

  • addedSecurityDeposit: the added deposit amount

  • amount: the total amount of rental resources in the order after renting

ReturnResource( address indexed renter, address indexed receiver, uint256 subedAmount, uint256 resourceType, uint256 usageRental, uint256 subedSecurityDeposit, uint256 amount)

Emits when resources are returned

  • subedAmount: the amount of TRX (minimum unit) for returned resources

  • usageRental: the cost of recovery for the used resources in the returned resources

  • subedSecurityDeposit: the refunded deposit amount (0 for partial returns)

  • amount: the remaining amount of rental resources after returning resources

Liquidate( address indexed liquidator, address indexed renter, address indexed receiver, uint256 amount, uint256 resourceType, uint256 usageRental, uint256 liquidateFee, uint256 sendBack)

Emits when liquidation occurs

  • amount: the amount of TRX (minimum unit) of the order resource

  • usageRental: the fee for the recovery time of the order resource usage

  • liquidateFee: the liquidation reward received by the liquidator

  • sendBack: the remaining deposit received by the payer

Last updated