sTRX Contract Developer Doc

sTRX Interface

Query Interface

Exchange rate

function exchangeRate() public view returns (uint256)

Method: Query the exchange rate between sTRX and TRX

Parameters: None

Returns: Exchange rate, 1 sTRX / 1 TRX exchange rate, scaled by 1e18

Total TRX assets

function totalUnderlying() public view returns (uint256)

Method: Query the total TRX assets managed by contract

Parameters: None

Returns: The total assets of TRX managed by contract, the minimum unit

User balance in TRX

function balanceInTrx(address _account) public view returns (uint256)

Method: Query the amount of TRX corresponding to the sTRX held by user

Parameters:

ParameterTypeDescription

_account

address

User address

Returns: The amount of TRX corresponding to the sTRX held by user, the minimum unit

Write Interface

Deposit TRX

function deposit() external payable returns (uint256)

Method: Deposit TRX assets and receive sTRX

Parameters:

ParameterTypeDescription

msg.value

The amount of TRX to deposit

Returns: The amount of sTRX received by user through exchange, the minimum unit

Withdraw sTRX

function withdraw(uint256 tokenAmount) external returns (uint256)

Method: specify the amount of sTRX to withdraw, the minimum unit

Parameters:

ParameterTypeDescription

tokenAmount

uint256

The amount of sTRX to withdraw

Returns: The amount of TRX to be unfrozen when user withdraws, the minimum unit

Withdraw sTRX (with the amount of TRX specified)

function withdrawExact(uint256 trxAmount) external returns (uint256)

Method: specify the amount of TRX user hopes to obtain through withdrawal, the minimum unit

Parameters:

ParameterTypeDescription

tokenAmount

uint256

The amount of sTRX to withdraw

Returns: The amount of sTRX withdrawn by user, the minimum unit

Claim TRX

function claim() external returns (uint256)

Method: Claim the ready-to-be-withdrawn TRX unfrozen in the earliest round

Parameters: None

Returns: The amount of TRX claimed by user in the earliest unfreezing round, the minimum unit

Claim all unfrozen TRX

function claimAll() external returns (uint256)

Method: Claim all ready-to-be-withdrawn, unfrozen TRX

Parameters: None

Returns: The amount of TRX claimed by the user for all expired unfreezing rounds, the minimum unit

Key Events

EventDescription

Deposit(address user, uint256 trxAmount, uint256 strx, uint256 userHoldStrx)

Emits when user successfully deposits TRX

  • trxAmount: the amount of TRX user deposits

  • strx : the amount of sTRX user gets

  • userHoldStrx: the total amount of sTRX held by user after the deposit

Withdraw(address user, uint256 strx, uint256 trxAmount, uint256 userHoldStrx)

Emits when user successfully withdraws sTRX

  • strx : the amount of sTRX user withdraws

  • trxAmount: the amount of TRX user gets

  • userHoldStrx: the total amount of sTRX held by user after the withdrawal

Claim(address user, uint256 trxAmount)

Emits when user successfully claims TRX

  • trxAmount: the amount of TRX user claims

Market Interface

Query Interface

Query Rental order information

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

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

Method: View the information of an order

Parameters:

ParameterTypeDescription

renter

address

Rent payer

receiver

address

Resource receiver

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns:

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)

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

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

Parameters:

ParameterTypeDescription

renter

address

Rent payer

receiver

address

Resource receiver

resourceType

uint256

Resource type, 0: bandwidth; 1: energy

Returns:

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

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

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

Parameters:

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)

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

Method: 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.

Parameters:

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)

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

Method: 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

Parameters:

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

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

Method: 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.

Parameters:

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