@equilab/utils
v1.2.34
Published
utils for equilab project
Downloads
125
Readme
EQ Utils
Convenience Types
type Undef<T> = T | undefined;
type Unwrap<T> = T extends Undef<infer D> ? D : T;
type UnwrapArray<T> = T extends Array<infer D> ? D : T;
type UnwrapPromise<T> = T extends Promise<infer D> ? D : T;
Async helpers
- Mutex
export { Mutex } from "@equilab/utils";
const mutex = new Mutex();
const release = await mutex.acquire(); // if mutex is acquired by another task then pause execution
release(); // release mutex to let it be acquired
API
Get borrower LTV
Request example
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
{"namespace": "portfolio", "method": "ltv", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
When debt exists and ltv computable then response should look like
HTTP/1.1 200 OK
{
"success": true,
"payload": "2.740757"
}
Ltv is 2.74 or 274%.
When borrower account does not exist (user never borrowed or deposited funds to borrow)
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Borrower account not found"
}
When account has no debt
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "No debt on account"
}
Get latest margincall info
Request example
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
{"namespace": "portfolio", "method": "margincall", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
When there info about latest margin call you will recieve response with block, block timestamp and tokens transferred during margin call
HTTP/1.1 200 OK
{
"success": true,
"payload": {
"timestamp": 1611652206000,
"block": 69115,
"tokens": [
{
"currency": "Btc",
"amount": 0.009759895
},
{
"currency": "Eos",
"amount": 1
}
]
}
}
When borrower account does not exist (user never borrowed or deposited funds to borrow)
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Borrower account not found"
}
Get EQ balance
Request example
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
{"namespace": "portfolio", "method": "eqbalance", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
Balance is returned as string
HTTP/1.1 200 OK
{
"success": true,
"payload": "1"
}
When borrower account does not exist (user never borrowed or deposited funds to borrow)
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Borrower account not found"
}
Get fees paid
Request example
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
{"namespace": "fees", "method": "interestpaid", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
If you have active borrower and/or bailsman role
{
"success": true,
"payload": "26.674442518"
}
This means you paid 26.67 EQ
When you don't have borrower and bailsman role:
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Borrower or bailsman account not found"
}
Get current borrowing rate
Request example
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
Cache-Control: no-cache
{"namespace": "fees", "method": "borrowingrate", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
HTTP/1.1 200 OK
{
"success": true,
"payload": "0.3992476577010985651225"
}
When you don't have borrower and bailsman role:
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Borrower or bailsman account not found"
}
Get interest earned (by bailsman)
Request example
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
Cache-Control: no-cache
{"namespace": "fees", "method": "interestearned", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
HTTP/1.1 200 OK
{
"success": true,
"payload": {
"EQ": "53.750042915",
"Btc": "0.000118141"
}
}
When bailsman account doesn't exist
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Bailsman account not found"
}
Current savings rate (for bailsman)
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
Cache-Control: no-cache
{"namespace": "fees", "method": "savingsrate", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
HTTP/1.1 200 OK
{
"success": true,
"payload": "0.07932925850387014265"
}
When bailsman account doesn't exist
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Bailsman account not found"
}
Received assets (for bailsman)
POST https://app.equilibrium.io/testnet/service HTTP/1.1
Content-Type: application/x-javascript
Cache-Control: no-cache
{"namespace": "portfolio", "method": "recievedassets", "payload": {"address": "5GN3sWbQxyZJ7Q47rnFVyWXxwe14LtRJiqrMmKeqmf6FDM9Y"}}
Responses
HTTP/1.1 200 OK
{
"success": true,
"payload": [
{
"timestamp": 1612528116000,
"blockNumber": 57783,
"currency": "Usd",
"amount": "4.270045693"
}
]
}
When bailsman account doesn't exist
HTTP/1.1 500 Internal Server Error
{
"success": false,
"error": "Bailsman account not found"
}