Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

[KAVA] Stored CDP, HARD, incentive and auctions details in db #547

Open
wants to merge 25 commits into
base: kava
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

# [Unreleased]
## [UNRELEASED]
* [#536] Added missing `/` in staking parameters URL
* [#535] Stored CDP, HARD, incentive and auctions details in db

# kava-7-v1.1
* Update npm packages
Expand Down
20 changes: 1 addition & 19 deletions imports/api/accounts/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,5 @@ Meteor.methods({
console.log(e)
}
return cdp
},

'cdp.getCDPList': function (collateralType) {
this.unblock();
let url = LCD + '/cdp/cdps/collateralType/' + collateralType;
try {
let result = HTTP.get(url);
if (result.statusCode == 200) {
let list = JSON.parse(result.content).result;
return list

}
else{
console.log("No CDP for collateral type " + collateralType)
}
} catch (e) {
console.log(e)
}
},
}
})
3 changes: 3 additions & 0 deletions imports/api/cdp/cdp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';

export const CDPCollection = new Mongo.Collection('cdp');
160 changes: 160 additions & 0 deletions imports/api/cdp/server/methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';
import { CDPCollection } from '../cdp';


Meteor.methods({
'cdp.list': function () {
this.unblock();
let collateralTypes = [];
let CDPList = {};
let cdp = CDPCollection.find().fetch();
let parameters = cdp[0]?.parameters?.collateral_params;
for(let c in parameters){
collateralTypes[c] = parameters[c]?.type
}

for(let collateral in collateralTypes){
let url = LCD + '/cdp/cdps/collateralType/' + collateralTypes[collateral];
try {
let result = HTTP.get(url);
if (result.statusCode == 200) {
let list = JSON.parse(result.content).result;
CDPList[collateralTypes[collateral]] = list;

}
else {
console.log("No CDP for collateral type " + collateralTypes[collateral])
}
} catch (e) {
console.log(e)
}
}

if (CDPList){
try{
CDPCollection.upsert({}, { $set: { CDPList } });
}
catch(e){
console.log("Error updating CDP list " + e)
}
}

return CDPList;
},
'cdp.parameters': function () {
this.unblock();
let url = LCD + '/cdp/parameters';
let parameters = {};

try {
let response = HTTP.get(url);
if (response.statusCode == 200) {
parameters = JSON.parse(response.content).result;
CDPCollection.upsert({}, { $set: { parameters: parameters } });
return parameters
}
}
catch (e) {
console.log(e)
}
},

'cdp.price': function (market) {
this.unblock();
let url = LCD + '/pricefeed/price/' + market;

try {
let response = HTTP.get(url);
if (response.statusCode == 200) {
price = JSON.parse(response.content).result.price;
CDPCollection.upsert({}, { $set: { price: price } });
return price
}
}
catch (e) {
console.log(e)
}
},

'cdp.auctions': function () {
this.unblock();
let url = LCD + '/auction/auctions'

try {
let response = HTTP.get(url);
if (response.statusCode == 200) {
let auctions = JSON.parse(response.content).result;
CDPCollection.upsert({}, { $set: { auctions: auctions } });
return auctions
}
}
catch (e) {
console.log(url);
console.log(e)
}
},

'cdp.fetchList': function () {
this.unblock();
try{
let cdp = CDPCollection.find().fetch();
return cdp[0]
}
catch(e){
console.log(e)
}
},

'cdp.fetchParameters': function () {
this.unblock();
try {
let cdp = CDPCollection.find().fetch();
return cdp[0].parameters
}
catch (e) {
console.log(e)
}
},

//get Account CDP
'cdp.fetchAccount': function (address, collateralType) {
this.unblock();

try{
let CDPList = CDPCollection.find().fetch();
let findCDP = CDPList[0].CDPList[collateralType]
for(let d in findCDP){
if (findCDP[d].cdp.owner === address){
return findCDP[d]
}
}
}
catch(e){
console.log(e)
}
},

'cdp.fetchPrice': function () {
this.unblock();
try {
let cdp = CDPCollection.find().fetch();
return cdp[0].price
}
catch (e) {
console.log(e)
}
},

'cdp.fetchAuction': function () {
this.unblock();
try {
let cdp = CDPCollection.find().fetch();
return cdp[0].auctions
}
catch (e) {
console.log(e)
}
},

})
3 changes: 3 additions & 0 deletions imports/api/hard/hard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';

export const HARDCollection = new Mongo.Collection('hard');
92 changes: 89 additions & 3 deletions imports/api/hard/server/methods.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';

import { HARDCollection } from '../hard'

Meteor.methods({
'hard.parameters': function () {
Expand All @@ -10,6 +10,7 @@ Meteor.methods({
let result = HTTP.get(url);
if (result.statusCode == 200) {
let parameters = JSON.parse(result.content).result;
HARDCollection.upsert({}, { $set: { parameters: parameters } });
return parameters
}
} catch (e) {
Expand All @@ -24,6 +25,7 @@ Meteor.methods({
let result = HTTP.get(url);
if (result.statusCode == 200) {
let deposits = JSON.parse(result.content).result;
HARDCollection.upsert({}, { $set: { deposits: deposits } });
return deposits
}
} catch (e) {
Expand All @@ -36,11 +38,95 @@ Meteor.methods({
try {
let result = HTTP.get(url);
if (result.statusCode == 200) {
let deposits = JSON.parse(result.content).result;
return deposits
let borrows = JSON.parse(result.content).result;
HARDCollection.upsert({}, { $set: { borrows: borrows } });
return borrows
}
} catch (e) {
console.log(e)
}
},

'hard.incentive': function () {
this.unblock();
let url = LCD + '/incentive/rewards'

try {
let response = HTTP.get(url);
if (response.statusCode == 200) {
let incentive = JSON.parse(response.content).result;
HARDCollection.upsert({}, { $set: { incentive: incentive } });
return incentive
}
}
catch (e) {
console.log(url);
console.log(e)
}
},

'hard.fetchList': function () {
this.unblock();
try{
let HARDList = HARDCollection.find().fetch();
return HARDList[0]
}
catch(e){
console.log(e)
}

},
'hard.findDepositor': function (address) {
this.unblock();
try{
let HARDList = HARDCollection.find().fetch();
let depositsList = HARDList[0].deposits;
for (let d in depositsList) {
if (depositsList[d].depositor === address) {
return depositsList[d]
}
}
}
catch(e){
console.log(e)
}

},
'hard.findBorrower': function (address) {
this.unblock();
try{
let HARDList = HARDCollection.find().fetch();
let borrowsList = HARDList[0].borrows;
for (let d in borrowsList) {
if (borrowsList[d].borrower === address) {
return borrowsList[d]
}
}
}
catch(e){
console.log(e)
}
},
'hard.fetchParameters': function () {
this.unblock();
try {
let HARDList = HARDCollection.find().fetch();
let params = HARDList[0].parameters;
return params
}
catch (e) {
console.log(e)
}
},

'hard.fetchIncentive': function () {
this.unblock();
try {
let hard = HARDCollection.find().fetch();
return hard[0].incentive
}
catch (e) {
console.log(e)
}
}
})
Loading