Endpoints List RESTful API
The Defactor Postman Collection comprises a suite of pre-configured API requests designed for seamless integration into the Postman application, facilitating access to the services offered by the Defactor API.
This API offers dual modes of interaction with the smart contract: firstly, via the RESTful API; and secondly, through the GraphQL API.
It facilitates interaction with various Pools smart contracts by providing an intuitive interface that maps the actions to straightforward concepts, such as create, lend, borrow, repaid, etc. Also, it enables seamless communication with smart contracts configured across multiple blockchain networks. It is necessary to specify the network and contract name in each request payload.
Outlined below is a detailed overview of the API's functionalities, leveraging a designated instance of the erc20collateralpool
contract as the primary data source.
The erc20collateralpool
contract is based on a token that follows the erc20
token standard that has a set precision. For example it can be usdc
, euroc
with a exactly a precision of 6 or any other token that meets the above mentioned requirements.
Then, 10500000 is equivalent to 10.5 USDC.
Security Details
To secure the API access control, all requests are made through Hasura which provides secure GraphQL, and RESTful endpoints restricted by a role-based authorization system.
Those endpoints that return public blockchain data do not require authentication for use. Query type requests are opened under the guest
role, while mutation type needs a token with admin
role.
For those that can modify data the API expects a valid authorization header containing a bearer token. These tokens are implemented as JSON Web Tokens (JWTs) issued by the server.
The security of the JWT is because it is signed by a secret key and has a configurable expiration time, which by default is 60 minutes.
Upon receiving a request, Hasura decodes and validates the JWT, which contains user account data, and their corresponding role. If the role lacks the necessary permissions or the token is invalid, expired or missing, the request is promptly rejected.
Authentication
Login
Return a JSON Web Token (JWT) access token and refresh token. By default, the access token has a maturity of 60 minutes, but it may vary depending on the server configuration.
HTTP Request Method: POST
Roles: Admin
Request URL: {{BASE_RESTFUL_URL}}/v1/login
Request Body
{
"session": {
"address": "0xa8983Fe59b2F08F9F1B3E833c5D47B256F7FE0d5"
}
}
Response
Upon successful completion of a request, the server will issue a status code of 200 along with a JSON object encapsulating the generated access token and refresh token. This object encompasses the following attributes:
{
"v1Login": {
"res": {
"accessToken": "<jwt>",
"refreshToken": "0a1a6d5f-1bf9-4540-8c22-d9442a75476f"
},
"success": true
}
}
Restore Session
Return a new access and refresh token.
HTTP Request Method: POST
Roles: Admin
Request URL: {{BASE_RESTFUL_URL}}/v1/restore-session
Request Body
{
"session": {
"refreshToken": "e6781b1a-ff37-4074-8b9e-39953b5a4f9d"
}
}
Response
Upon successful completion of a request, the server will issue a status code of 200 along with a JSON object encapsulating the generated access token and refresh token. This object encompasses the following attributes:
{
"v1RestoreSession": {
"res": {
"accessToken": "<jwt>",
"refreshToken": "0a1a6d5f-1bf9-4540-8c22-d9442a75476f"
},
"success": true
}
}
Pools
The collateralDetails
schema has the following properties:
Property | Description |
---|---|
collateralToken | The address where the collateral token is deployed. |
collateralTokenChainlink | The address where the contract that indicates the price of the collateral token is deployed. |
collateralTokenFactor | Used to adjust the collateral amount from the price of the collateral. |
collateralTokenPercentage | Used to calculate the amount of collateral token a borrower will need to provide to borrow from the pool. |
Create Pool
Create a new pool with the indicated collateral token using the collateralDetails
schema. Once the endTime
period concludes, neither lending nor borrowing are allowed.
HTTP Request Method: POST
Roles: Admin
Request URL: {{BASE_RESTFUL_URL}}/v1/create-pool
Request Body
{
"pool": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool",
"data": {
"endTime": "2024-08-09T23:58:00.000",
"interest": 10,
"collateralDetails": {
"collateralToken": "0x6BaB3bEA9aD00893101837d46638B470076f8AAF",
"collateralTokenChainlink": "0x295894a94F859cE1Ac960364D6b0D2Fa430027b4",
"collateralTokenFactor": 10,
"collateralTokenPercentage": 115
}
}
}
}
Response
Upon successful completion of a request, the server will issue a status code of 200 along with a JSON object encapsulating pertinent blockchain transaction details. This object encompasses the following attributes:
{
"v1CreatePool": {
"res": {
"_type": "TransactionResponse",
"accessList": [],
"blobVersionedHashes": null,
"blockHash": null,
"blockNumber": null,
"chainId": "80001",
"from": "0xa8983Fe59b2F08F9F1B3E833c5D47B256F7FE0d5",
"gasLimit": "150012",
"gasPrice": null,
"hash": "0x68dc6f65b96a427c4c289371637b063bbe20d9841d6c8183f06e657ab10efb1e",
.
.
.
},
"success": true
}
}
Get Pool
Retrieves the data associated with the specified poolId
.
HTTP Request Method: GET
Roles: Guest
Request URL: {{BASE_RESTFUL_URL}}/v1/get-pool
Request Body
{
"pool": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool",
"poolId": "6"
}
}
Response
Upon successful request completion, the server will return a status code of 200 along with a JSON object containing pool information. This object encompasses the following attributes:
{
"v1GetPool": {
"res": {
"borrowed": "0",
"collateralDetails": {
"collateralToken": "0x81da82b49CD9Ee7b7d67B4655784581f30590eA1",
"collateralTokenChainlink": "0x997a6BCe1372baca6Bbb8db382Cb12F2dDca2b45",
"collateralTokenFactor": "115",
"collateralTokenPercentage": "60"
},
"collateralTokenAmount": "0",
"collateralTokenAmountAtLiquidation": "0",
"endTime": "1706924460",
"interest": "10",
"lastUpdated": "0",
"lended": "0",
"liquidated": false,
"liquidatedCollateral": "0",
"repaid": "0",
"rewardPerToken": "0",
"rewardRate": "0",
"rewards": "0"
},
"success": true
}
}
Get Pools
Retrieves the data associated with the pools
specified in the pagination parameters. If the offset exceeds the total number of pools, the API will return an empty list.
HTTP Request Method: GET
Roles: Guest
Request URL: {{BASE_RESTFUL_URL}}/v1/get-pools
Request Body
{
"pool": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool",
"offset": "6",
"limit": "10"
}
}
Response
Upon successful request completion, the server will respond with a status code of 200, accompanied by a JSON object containing information regarding the pools. This object comprises the following attributes:
{
"v1GetPools": {
"res": {
"data":
[{
"borrowed": "2630",
"collateralDetails": {
"collateralToken": "0x81da82b49CD9Ee7b7d67B4655784581f30590eA1",
"collateralTokenChainlink": "0x997a6BCe1372baca6Bbb8db382Cb12F2dDca2b45",
"collateralTokenFactor": "115",
"collateralTokenPercentage": "50"
},
"collateralTokenAmount": "80353506350309",
"collateralTokenAmountAtLiquidation": "0",
"endTime": "1711925999",
"interest": "10",
"lastUpdated": "1707770796",
"lended": "6225000150",
"liquidated": false,
"liquidatedCollateral": "0",
"repaid": "470",
"rewardPerToken": "419803556",
"rewardRate": "1100",
"rewards": "0"
},
.
.
.
],
"more": false
},
"success": true
}
}
Get Total Pools
Returns the count of pools created within the current instance of erc20collateraltoken
.
HTTP Request Method: GET
Roles: Guest
Request URL: {{BASE_RESTFUL_URL}}/v1/get-total-pools
Request Body
{
"data": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool"
}
}
Response
Upon successful request completion, the server will respond with a status code of 200 and a JSON object containing information about the total pools. This object includes the following attributes:
{
"v1GetTotalPools": {
"res": "672",
"success": true
}
}
Liquidate Pool
Liquidate a pool if it is not completed.
The erc20collateralpool
contract needs the approval to spend the amount of base token on behalf of the lender, to give the approve the erc20 approve
endpoint could be used. Also, to get the amount needed to liquidate the pool use the get liquidation info
endpoint.
HTTP Request Method: POST
Roles: Admin
Request URL: {{BASE_RESTFUL_URL}}/v1/liquidate-pool
Request Body
{
"pool": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool",
"data": {
"poolId": "3"
}
}
}
Response
Upon successful completion of a request, the server will issue a status code of 200 along with a JSON object encapsulating pertinent blockchain transaction details. This object encompasses the following attributes:
{
"v1LiquidatePool": {
"res": {
"_type": "TransactionResponse",
"accessList": [],
"blobVersionedHashes": null,
"blockHash": null,
"blockNumber": null,
"chainId": "80001",
"from": "0xa8983Fe59b2F08F9F1B3E833c5D47B256F7FE0d5",
"gasLimit": "150012",
"gasPrice": null,
"hash": "0x68dc6f65b96a427c4c289371637b063bbe20d9841d6c8183f06e657ab10efb1e",
.
.
.
},
"success": true
}
}
Get Liquidation Info
if the pool is not completed retrieves the liquidation information of a loan.
HTTP Request Method: GET
Roles: Guest
Request URL: {{BASE_RESTFUL_URL}}/v1/get-liquidation-info
Request Body
{
"pool": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool",
"poolId": "0"
}
}
Response
Upon successful request completion, the server will respond with a status code of 200 and a JSON object containing the amount required to be paid in order to liquidate the pool. This object includes the following attributes:
{
"v1GetLiquidationInfo": {
"res": {
"liquidatableAmountWithLiquidationFee": "2874604918977589116",
"liquidatableAmountWithProtocolFee": "2743941059024062338",
"remainingInterest": "2613277199070533400"
},
"success": true
}
}
Get Liquidation Protocol Fee
Retrieves the fee for liquidation.
HTTP Request Method: GET
Roles: Guest
Request URL: {{BASE_RESTFUL_URL}}/v1/get-liquidation-protocol-fee
Request Body
{
"data": {
"network": "{{NETWORK_NAME}}",
"contractName": "erc20-collateral-pool"
}
}
Response
Upon successful request completion, the server will respond with a status code of 200 and a JSON object containing the liquidation fee. This object includes the following attributes:
{
"v1GetLiquidationProtocolFee": {
"res": "5",
"success": true
}
}