get more stats

This commit is contained in:
Tyler Shipe 2021-08-13 12:28:52 -04:00
parent a5025e9307
commit 49442c4002
8 changed files with 98 additions and 93 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -10,9 +10,11 @@ module.exports = {
mangoGroup: {
type: Sequelize.STRING,
},
depositIndex: Sequelize.DECIMAL,
depositRate: {
type: Sequelize.DECIMAL,
},
borrowIndex: Sequelize.DECIMAL,
borrowRate: {
type: Sequelize.DECIMAL,
},

View File

@ -22,6 +22,24 @@ module.exports = {
baseOraclePrice: {
type: Sequelize.DECIMAL,
},
feesAccrued: {
type: Sequelize.DECIMAL,
},
mngoLeft: {
type: Sequelize.DECIMAL,
},
mngoPerPeriod: {
type: Sequelize.DECIMAL,
},
rate: {
type: Sequelize.DECIMAL,
},
maxDepthBps: {
type: Sequelize.DECIMAL,
},
periodStart: {
type: Sequelize.DATE,
},
time: {
type: Sequelize.DATE,
},

View File

@ -5,35 +5,17 @@ const PerpMarketStats = db.sequelize.define(
"perp_market_stats",
{
name: { type: DataTypes.STRING, allowNull: false },
longFunding: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("longFunding")
return value ? parseFloat(value) : null
},
},
shortFunding: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("shortFunding")
return value ? parseFloat(value) : null
},
},
openInterest: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("openInterest")
return value === null ? null : parseFloat(value)
},
},
baseOraclePrice: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("baseOraclePrice")
return value === null ? null : parseFloat(value)
},
},
mangoGroup: DataTypes.STRING,
longFunding: DataTypes.DECIMAL,
shortFunding: DataTypes.DECIMAL,
openInterest: DataTypes.DECIMAL,
baseOraclePrice: DataTypes.DECIMAL,
feesAccrued: DataTypes.DECIMAL,
mngoLeft: DataTypes.DECIMAL,
mngoPerPeriod: DataTypes.DECIMAL,
rate: DataTypes.DECIMAL,
maxDepthBps: DataTypes.DECIMAL,
periodStart: DataTypes.DECIMAL,
time: DataTypes.DATE,
},
{

View File

@ -5,41 +5,13 @@ const PerpMarketStats = db.sequelize.define(
"spot_market_stats",
{
name: { type: DataTypes.STRING, allowNull: false },
totalDeposits: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("totalDeposits")
return value ? parseFloat(value) : null
},
},
totalBorrows: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("totalBorrows")
return value ? parseFloat(value) : null
},
},
depositRate: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("depositRate")
return value === null ? null : parseFloat(value)
},
},
borrowRate: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("borrowRate")
return value === null ? null : parseFloat(value)
},
},
baseOraclePrice: {
type: DataTypes.DECIMAL,
get() {
const value = this.getDataValue("baseOraclePrice")
return value === null ? null : parseFloat(value)
},
},
totalDeposits: DataTypes.DECIMAL,
totalBorrows: DataTypes.DECIMAL,
depositRate: DataTypes.DECIMAL,
borrowRate: DataTypes.DECIMAL,
baseOraclePrice: DataTypes.DECIMAL,
depositIndex: DataTypes.DECIMAL,
borrowIndex: DataTypes.DECIMAL,
mangoGroup: DataTypes.STRING,
utilization: DataTypes.DECIMAL,
time: DataTypes.DATE,

View File

@ -21,11 +21,12 @@
"@typescript-eslint/parser": "^4.15.1",
"eslint": "^7.20.0",
"prettier": "^2.2.1",
"sequelize-cli": "^6.2.0",
"ts-node-dev": "^1.1.1",
"typescript": "^4.1.5"
},
"dependencies": {
"@blockworks-foundation/mango-client": "beta",
"@blockworks-foundation/mango-client": "^3.0.4",
"@solana/web3.js": "^1.18.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
@ -34,7 +35,6 @@
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"sequelize": "^6.5.0",
"sequelize-cli": "^6.2.0",
"ts-node": "^9.1.1"
}
}

View File

@ -64,8 +64,10 @@ async function fetchSpotStats() {
totalBorrows: totalBorrows.toNumber(),
depositRate: mangoGroup.getDepositRate(index).toNumber(),
borrowRate: mangoGroup.getBorrowRate(index).toNumber(),
depositIndex: mangoGroup.rootBankAccounts[index].depositIndex.toNumber(),
borrowIndex: mangoGroup.rootBankAccounts[index].borrowIndex.toNumber(),
utilization: totalDeposits.gt(I80F48.fromNumber(0)) ? totalBorrows.div(totalDeposits).toNumber() : 0,
baseOraclePrice: mangoCache.priceCache[index].price.toNumber(),
baseOraclePrice: mangoGroup.getPrice(index, mangoCache).toNumber(),
}
})
try {
@ -82,7 +84,6 @@ async function fetchPerpStats() {
const mangoGroup = await client.getMangoGroup(groupConfig.publicKey)
const mangoCache = await mangoGroup.loadCache(connection)
const perpMarkets = await loadPerpMarkets(connection, groupConfig)
console.log("6")
const perpMarketStats = perpMarkets.map((perpMarket, index) => {
return {
@ -93,6 +94,12 @@ async function fetchPerpStats() {
shortFunding: perpMarket.shortFunding.toNumber(),
openInterest: perpMarket.openInterest.toNumber(),
baseOraclePrice: mangoCache.priceCache[index].price.toNumber(),
feesAccrued: perpMarket.feesAccrued.toNumber(),
mngoLeft: perpMarket.liquidityMiningInfo.mngoLeft.toNumber(),
mngoPerPeriod: perpMarket.liquidityMiningInfo.mngoPerPeriod.toNumber(),
rate: perpMarket.liquidityMiningInfo.rate.toNumber(),
maxDepthBps: perpMarket.liquidityMiningInfo.maxDepthBps.toNumber(),
periodStart: perpMarket.liquidityMiningInfo.periodStart.toNumber(),
}
})

View File

@ -39,15 +39,15 @@
dependencies:
regenerator-runtime "^0.13.4"
"@blockworks-foundation/mango-client@beta":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-client/-/mango-client-3.0.2.tgz#18b56f64ab1d00c797b6fda238071f5aaa6b0780"
integrity sha512-9BZODZJ4YlbdXZ2mtGhMnitmEd4tKtH0PUNX2uWY4+tJoF4DCIwrK4D1qsxaW9Dx+so/CtCdJv7NgyNhIhZBLQ==
"@blockworks-foundation/mango-client@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-client/-/mango-client-3.0.4.tgz#4d388f4ac91210131b5d13429488aef33e6cc5ce"
integrity sha512-6xf7gVbrsHOLgShrVgtcirIzvTx0wK99u4wtvDGRnI1YtQBou3D0Mjw01Z1oyaEovWcsChtQPCmQPZqHdCPrsQ==
dependencies:
"@project-serum/serum" "^0.13.45"
"@project-serum/serum" "0.13.55"
"@project-serum/sol-wallet-adapter" "^0.2.0"
"@solana/spl-token" "^0.1.6"
"@solana/web3.js" "^1.18.0"
"@solana/web3.js" "1.21.0"
big.js "^6.1.1"
bigint-buffer "^1.1.5"
bn.js "^5.1.2"
@ -120,10 +120,10 @@
bn.js "^5.1.2"
buffer-layout "^1.2.0"
"@project-serum/serum@^0.13.45":
version "0.13.54"
resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.13.54.tgz#f7a05ade7a044b87f693928c3a0cd01e82fe0484"
integrity sha512-kYNAFcLbqhYocQ+cl3s+QZSroVOIrPiKo81fvdyrE/r2U2qshmULzMVDNpXqdrd3qdJUIZGroXMi1DHTaG2qjA==
"@project-serum/serum@0.13.55":
version "0.13.55"
resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.13.55.tgz#2ac44fe7b07651274eb57ac54ea9325789df5dd7"
integrity sha512-SPQ4NsuNbBJO3mLGnTYbjt47WCXoNIcW2C9xv0gNXyG62dxgONsAEEgErKv1gT34hWCMPsXFSpatnX6ppriq7w==
dependencies:
"@project-serum/anchor" "^0.11.1"
"@solana/spl-token" "^0.1.6"
@ -158,6 +158,26 @@
buffer-layout "^1.2.0"
dotenv "10.0.0"
"@solana/web3.js@1.21.0":
version "1.21.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.21.0.tgz#4f98edea38d4cb3ae4d2ea49a050b0ec09508023"
integrity sha512-x1NXlF92tEjxuTxS0u4n9JV17UKk0Dn2L+qSWGvKOb4iWhzApDj6wicJsrGdSbGdxnZ7eciQ/SNn3zB4ydUllA==
dependencies:
"@babel/runtime" "^7.12.5"
"@solana/buffer-layout" "^3.0.0"
bn.js "^5.0.0"
borsh "^0.4.0"
bs58 "^4.0.1"
buffer "6.0.1"
crypto-hash "^1.2.2"
jayson "^3.4.4"
js-sha3 "^0.8.0"
node-fetch "^2.6.1"
rpc-websockets "^7.4.2"
secp256k1 "^4.0.2"
superstruct "^0.14.2"
tweetnacl "^1.0.0"
"@solana/web3.js@^1.12.0", "@solana/web3.js@^1.17.0", "@solana/web3.js@^1.18.0", "@solana/web3.js@^1.21.0":
version "1.22.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.22.0.tgz#ded439eb903aff4269a16a7fdfacc6866c6f0c13"
@ -804,9 +824,9 @@ concat-map@0.0.1:
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
config-chain@^1.1.12:
version "1.1.12"
resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa"
integrity sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==
version "1.1.13"
resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.13.tgz#fad0795aa6a6cdaff9ed1b68e9dff94372c232f4"
integrity sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==
dependencies:
ini "^1.3.4"
proto-list "~1.2.1"
@ -1463,11 +1483,16 @@ globby@^11.0.1:
merge2 "^1.3.0"
slash "^3.0.0"
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
graceful-fs@^4.1.2:
version "4.2.6"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee"
integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==
graceful-fs@^4.1.6:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
@ -1698,14 +1723,13 @@ jayson@^3.4.4:
uuid "^3.4.0"
js-beautify@^1.8.8:
version "1.13.5"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.13.5.tgz#a08a97890cae55daf1d758d3f6577bd4a64d7014"
integrity sha512-MsXlH6Z/BiRYSkSRW3clNDqDjSpiSNOiG8xYVUBXt4k0LnGvDhlTGOlHX1VFtAdoLmtwjxMG5qiWKy/g+Ipv5w==
version "1.14.0"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.14.0.tgz#2ce790c555d53ce1e3d7363227acf5dc69024c2d"
integrity sha512-yuck9KirNSCAwyNJbqW+BxJqJ0NLJ4PwBUzQQACl5O3qHMBXVkXb/rD0ilh/Lat/tn88zSZ+CAHOlk0DsY7GuQ==
dependencies:
config-chain "^1.1.12"
editorconfig "^0.15.3"
glob "^7.1.3"
mkdirp "^1.0.4"
nopt "^5.0.0"
js-sha256@^0.9.0:
@ -1797,12 +1821,12 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"
lodash@^4.17.15, lodash@^4.17.5:
lodash@^4.17.15:
version "4.17.20"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
lodash@^4.17.20:
lodash@^4.17.20, lodash@^4.17.5:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@ -2955,9 +2979,9 @@ type@^1.0.1:
integrity sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==
type@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/type/-/type-2.2.0.tgz#3edd448793f517d8b9dd108b486a043f5befd91f"
integrity sha512-M/u37b4oSGlusaU8ZB96BfFPWQ8MbsZYXB+kXGMiDj6IKinkcNaQvmirBuWj8mAXqP6LYn1rQvbTYum3yPhaOA==
version "2.5.0"
resolved "https://registry.yarnpkg.com/type/-/type-2.5.0.tgz#0a2e78c2e77907b252abe5f298c1b01c63f0db3d"
integrity sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==
typescript@^4.1.5:
version "4.1.5"
@ -3106,9 +3130,9 @@ xtend@^4.0.0:
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==
y18n@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4"
integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==
version "4.0.3"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf"
integrity sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==
y18n@^5.0.5:
version "5.0.8"