mirror of
https://github.com/uniwhale-io/DefiLlama-yield-server.git
synced 2026-04-30 12:52:06 +08:00
update schema, tests and insert controllers for borrow fields (#331)
* update schema, tests and insert controllers for borrow fields * tvl -> usd * update adapter handler * round total supply/total borrow
This commit is contained in:
@@ -26,6 +26,12 @@ interface Pool {
|
|||||||
underlyingTokens?: Array<string>;
|
underlyingTokens?: Array<string>;
|
||||||
poolMeta?: string;
|
poolMeta?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
// optional lending protocol specific fields:
|
||||||
|
apyBaseBorrow?: number;
|
||||||
|
apyRewardBorrow?: number;
|
||||||
|
totalSupplyUsd?: number;
|
||||||
|
totalBorrowUsd?: number;
|
||||||
|
ltv?: number;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
11
migrations/1663509086058_yield-borrow-fields.js
Normal file
11
migrations/1663509086058_yield-borrow-fields.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
exports.up = (pgm) => {
|
||||||
|
pgm.addColumns('yield', {
|
||||||
|
apyBaseBorrow: 'numeric',
|
||||||
|
apyRewardBorrow: 'numeric',
|
||||||
|
totalSupplyUsd: 'numeric',
|
||||||
|
totalBorrowUsd: 'numeric',
|
||||||
|
});
|
||||||
|
pgm.addColumns('config', {
|
||||||
|
ltv: 'numeric',
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -22,6 +22,11 @@ describe(`Running ${process.env.npm_config_adapter} Test`, () => {
|
|||||||
'rewardTokens',
|
'rewardTokens',
|
||||||
'poolMeta',
|
'poolMeta',
|
||||||
'url',
|
'url',
|
||||||
|
'apyBaseBorrow',
|
||||||
|
'apyRewardBorrow',
|
||||||
|
'totalSupplyUsd',
|
||||||
|
'totalBorrowUsd',
|
||||||
|
'ltv',
|
||||||
];
|
];
|
||||||
const fields = [...Object.keys(baseFields), ...optionalFields, 'tvlUsd'];
|
const fields = [...Object.keys(baseFields), ...optionalFields, 'tvlUsd'];
|
||||||
apy.forEach((pool) => {
|
apy.forEach((pool) => {
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ const buildInsertConfigQuery = (payload) => {
|
|||||||
{ name: 'underlyingTokens', def: null },
|
{ name: 'underlyingTokens', def: null },
|
||||||
{ name: 'rewardTokens', def: null },
|
{ name: 'rewardTokens', def: null },
|
||||||
'url',
|
'url',
|
||||||
|
{ name: 'ltv', def: null },
|
||||||
];
|
];
|
||||||
const cs = new pgp.helpers.ColumnSet(columns, { table: tableName });
|
const cs = new pgp.helpers.ColumnSet(columns, { table: tableName });
|
||||||
const query =
|
const query =
|
||||||
|
|||||||
@@ -250,6 +250,10 @@ const buildInsertYieldQuery = (payload) => {
|
|||||||
'apy',
|
'apy',
|
||||||
'apyBase',
|
'apyBase',
|
||||||
'apyReward',
|
'apyReward',
|
||||||
|
{ name: 'apyBaseBorrow', def: null },
|
||||||
|
{ name: 'apyRewardBorrow', def: null },
|
||||||
|
{ name: 'totalSupplyUsd', def: null },
|
||||||
|
{ name: 'totalBorrowUsd', def: null },
|
||||||
];
|
];
|
||||||
const cs = new pgp.helpers.ColumnSet(columns, { table: tableName });
|
const cs = new pgp.helpers.ColumnSet(columns, { table: tableName });
|
||||||
return pgp.helpers.insert(payload, cs);
|
return pgp.helpers.insert(payload, cs);
|
||||||
|
|||||||
@@ -60,12 +60,14 @@ const main = async (body) => {
|
|||||||
// number to string. so in order for the below filters to work proplerly we need to guarantee that the
|
// number to string. so in order for the below filters to work proplerly we need to guarantee that the
|
||||||
// datatypes are correct (on db insert, mongoose checks field types against the schema and the bulk insert
|
// datatypes are correct (on db insert, mongoose checks field types against the schema and the bulk insert
|
||||||
// will fail if a pools field types doesnt match)
|
// will fail if a pools field types doesnt match)
|
||||||
|
const strToNum = (val) => (typeof val === 'string' ? Number(val) : val);
|
||||||
data = data.map((p) => ({
|
data = data.map((p) => ({
|
||||||
...p,
|
...p,
|
||||||
apy: typeof p.apy === 'string' ? Number(p.apy) : p.apy,
|
apy: strToNum(p.apy),
|
||||||
apyBase: typeof p.apyBase === 'string' ? Number(p.apyBase) : p.apyBase,
|
apyBase: strToNum(p.apyBase),
|
||||||
apyReward:
|
apyReward: strToNum(p.apyReward),
|
||||||
typeof p.apyReward === 'string' ? Number(p.apyReward) : p.apyReward,
|
apyBaseBorrow: strToNum(p.apyBaseBorrow),
|
||||||
|
apyRewardBorrow: strToNum(p.apyRewardBorrow),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// filter tvl to be btw lb-ub
|
// filter tvl to be btw lb-ub
|
||||||
@@ -81,6 +83,10 @@ const main = async (body) => {
|
|||||||
apy: Number.isFinite(p.apy) ? p.apy : null,
|
apy: Number.isFinite(p.apy) ? p.apy : null,
|
||||||
apyBase: Number.isFinite(p.apyBase) ? p.apyBase : null,
|
apyBase: Number.isFinite(p.apyBase) ? p.apyBase : null,
|
||||||
apyReward: Number.isFinite(p.apyReward) ? p.apyReward : null,
|
apyReward: Number.isFinite(p.apyReward) ? p.apyReward : null,
|
||||||
|
apyBaseBorrow: Number.isFinite(p.apyBaseBorrow) ? p.apyBaseBorrow : null,
|
||||||
|
apyRewardBorrow: Number.isFinite(p.apyRewardBorrow)
|
||||||
|
? p.apyRewardBorrow
|
||||||
|
: null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// remove pools where all 3 apy related fields are null
|
// remove pools where all 3 apy related fields are null
|
||||||
@@ -93,8 +99,9 @@ const main = async (body) => {
|
|||||||
...p,
|
...p,
|
||||||
apy: p.apy < 0 ? 0 : p.apy,
|
apy: p.apy < 0 ? 0 : p.apy,
|
||||||
apyBase: p.apyBase < 0 ? 0 : p.apyBase,
|
apyBase: p.apyBase < 0 ? 0 : p.apyBase,
|
||||||
// this shouldn't be lower than 0 lol, but leaving it here anyways in case of bug in adapter
|
|
||||||
apyReward: p.apyReward < 0 ? 0 : p.apyReward,
|
apyReward: p.apyReward < 0 ? 0 : p.apyReward,
|
||||||
|
apyBaseBorrow: p.apyBaseBorrow < 0 ? 0 : p.apyBaseBorrow,
|
||||||
|
apyRewardBorrow: p.apyRewardBorrow < 0 ? 0 : p.apyRewardBorrow,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// derive final total apy field
|
// derive final total apy field
|
||||||
@@ -150,6 +157,22 @@ const main = async (body) => {
|
|||||||
p.apyReward !== null ? +p.apyReward.toFixed(precision) : p.apyReward,
|
p.apyReward !== null ? +p.apyReward.toFixed(precision) : p.apyReward,
|
||||||
url: p.url ?? project.url,
|
url: p.url ?? project.url,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
apyBaseBorrow:
|
||||||
|
p.apyBaseBorrow !== null
|
||||||
|
? +p.apyBaseBorrow.toFixed(precision)
|
||||||
|
: p.apyBaseBorrow,
|
||||||
|
apyRewardBorrow:
|
||||||
|
p.apyRewardBorrow !== null
|
||||||
|
? +p.apyRewardBorrow.toFixed(precision)
|
||||||
|
: p.apyRewardBorrow,
|
||||||
|
totalSupplyUsd:
|
||||||
|
p.totalSupplyUsd === undefined || p.totalSupplyUsd === null
|
||||||
|
? null
|
||||||
|
: Math.round(p.totalSupplyUsd),
|
||||||
|
totalBorrowUsd:
|
||||||
|
p.totalBorrowUsd === undefined || p.totalBorrowUsd === null
|
||||||
|
? null
|
||||||
|
: Math.round(p.totalBorrowUsd),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user