Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add trading apy #44

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const TRADING_APY_TYPES = {
CAMELOT: 'CAMELOT',
BASESWAP: 'BASESWAP',
CURVE_BASE: 'CURVE_BASE',
MAGPIE: 'MAGPIE',
}

const POOL_TYPES = {
Expand Down
24 changes: 24 additions & 0 deletions data/mainnet/pools.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ module.exports = [
chain: CHAIN_IDS.ARBITRUM_ONE,
id: 'magpie_DAI_main',
type: POOL_TYPES.INCENTIVE,
tradingApyFunction: {
type: TRADING_APY_TYPES.MAGPIE,
params: [addresses.ARBITRUM_ONE.V2.magpie_DAI_main.Underlying],
},
contractAddress: addresses.ARBITRUM_ONE.V2.magpie_DAI_main.NewPool,
collateralAddress: addresses.ARBITRUM_ONE.V2.magpie_DAI_main.NewVault,
rewardAPY: [],
Expand All @@ -78,6 +82,10 @@ module.exports = [
chain: CHAIN_IDS.ARBITRUM_ONE,
id: 'magpie_ETH_frxeth',
type: POOL_TYPES.INCENTIVE,
tradingApyFunction: {
type: TRADING_APY_TYPES.MAGPIE,
params: [addresses.ARBITRUM_ONE.V2.magpie_ETH_frxeth.Underlying],
},
contractAddress: addresses.ARBITRUM_ONE.V2.magpie_ETH_frxeth.NewPool,
collateralAddress: addresses.ARBITRUM_ONE.V2.magpie_ETH_frxeth.NewVault,
rewardAPY: [],
Expand All @@ -104,6 +112,10 @@ module.exports = [
chain: CHAIN_IDS.ARBITRUM_ONE,
id: 'magpie_USDCe_main',
type: POOL_TYPES.INCENTIVE,
tradingApyFunction: {
type: TRADING_APY_TYPES.MAGPIE,
params: [addresses.ARBITRUM_ONE.V2.magpie_USDCe_main.Underlying],
},
contractAddress: addresses.ARBITRUM_ONE.V2.magpie_USDCe_main.NewPool,
collateralAddress: addresses.ARBITRUM_ONE.V2.magpie_USDCe_main.NewVault,
rewardAPY: [],
Expand All @@ -130,6 +142,10 @@ module.exports = [
chain: CHAIN_IDS.ARBITRUM_ONE,
id: 'magpie_USDC_main',
type: POOL_TYPES.INCENTIVE,
tradingApyFunction: {
type: TRADING_APY_TYPES.MAGPIE,
params: [addresses.ARBITRUM_ONE.V2.magpie_USDC_main.Underlying],
},
contractAddress: addresses.ARBITRUM_ONE.V2.magpie_USDC_main.NewPool,
collateralAddress: addresses.ARBITRUM_ONE.V2.magpie_USDC_main.NewVault,
rewardAPY: [],
Expand All @@ -156,6 +172,10 @@ module.exports = [
chain: CHAIN_IDS.ARBITRUM_ONE,
id: 'magpie_USDT_main',
type: POOL_TYPES.INCENTIVE,
tradingApyFunction: {
type: TRADING_APY_TYPES.MAGPIE,
params: [addresses.ARBITRUM_ONE.V2.magpie_USDT_main.Underlying],
},
contractAddress: addresses.ARBITRUM_ONE.V2.magpie_USDT_main.NewPool,
collateralAddress: addresses.ARBITRUM_ONE.V2.magpie_USDT_main.NewVault,
rewardAPY: [],
Expand All @@ -182,6 +202,10 @@ module.exports = [
chain: CHAIN_IDS.ARBITRUM_ONE,
id: 'magpie_WOM_mwom',
type: POOL_TYPES.INCENTIVE,
tradingApyFunction: {
type: TRADING_APY_TYPES.MAGPIE,
params: [addresses.ARBITRUM_ONE.V2.magpie_WOM_mwom.Underlying],
},
contractAddress: addresses.ARBITRUM_ONE.V2.magpie_WOM_mwom.NewPool,
collateralAddress: addresses.ARBITRUM_ONE.V2.magpie_WOM_mwom.NewVault,
rewardAPY: [],
Expand Down
7 changes: 7 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ const SWIRL_API_URL = 'https://api.swirl.cash/'
const MSTABLE_API_URL = 'https://api.mstable.org/pools'
const APE_API_URL = 'https://ape-swap-api.herokuapp.com'

const WOMBAT_ARB_SUBGRAPH_URL =
'https://api.thegraph.com/subgraphs/name/wombat-exchange/wombat-exchange-arbone'
const WOMBAT_ARB_ONE_BLOCK_URL =
'https://api.thegraph.com/subgraphs/name/wombat-exchange/arbitrum-one-block'

const BALANCER_SUBGRAPH_URLS = {
ETH: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2',
MATIC: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2',
Expand Down Expand Up @@ -299,4 +304,6 @@ module.exports = {
BASE_RPC_URL,
DEXSCREENER_API_URL,
CURVE_FINANCE_API_URL,
WOMBAT_ARB_SUBGRAPH_URL,
WOMBAT_ARB_ONE_BLOCK_URL,
}
59 changes: 59 additions & 0 deletions src/lib/third-party/wombat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { get } = require('lodash')
const { cachedAxios } = require('../db/models/cache')
const { WOMBAT_ARB_SUBGRAPH_URL, WOMBAT_ARB_ONE_BLOCK_URL } = require('../constants')

const executeWombatCall = (url, type, query) => {
return cachedAxios
.post(url, JSON.stringify({ query }))
.then(response => {
let data
if (type) {
data = get(response, `data.data.${type}`)
} else {
data = get(response, `data.data`)
}
if (data) {
return data
} else {
console.error(get(response, 'data.errors', response))
return null
}
})
.catch(error => {
console.error(`Wombat subgraph (${query}) failed:`, error)
return null
})
}

const getBlockNumArb = async timestamp => {
const blockQuery = `query {
blocks (first: 1, orderBy: timestamp, orderDirection:desc where:{timestamp_lte:${timestamp}}) {
number
}}`

const blockInfo = await executeWombatCall(WOMBAT_ARB_ONE_BLOCK_URL, 'blocks[0]', blockQuery)
return blockInfo.number
}

const getTradingVolumeDaily = async (underlyingAddr, blockNum) => {
const tradingVolQuery = `query {
assetsNow:assets (where: {id: "${underlyingAddr.toLowerCase()}"}) {
totalTradeVolumeUSD,
tvlUSD
}
assets24hAgo: assets(where: {id: "${underlyingAddr.toLowerCase()}"} block:{number:${blockNum}}){
totalTradeVolumeUSD
}
}`

const tradingVolInfo = await executeWombatCall(WOMBAT_ARB_SUBGRAPH_URL, null, tradingVolQuery)
const dailyTradingVol =
parseFloat(tradingVolInfo.assetsNow[0].totalTradeVolumeUSD) -
parseFloat(tradingVolInfo.assets24hAgo[0].totalTradeVolumeUSD)
return { dailyTradingVol, tvlUSD: parseFloat(tradingVolInfo.assetsNow[0].tvlUSD) }
}

module.exports = {
getTradingVolumeDaily,
getBlockNumArb,
}
14 changes: 14 additions & 0 deletions src/lib/web3/contracts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ const wombatStakingContract = require('../contracts/wombat-staking/contract.json
const wombatMasterMethods = require('../contracts/wom-master/methods')
const wombatMasterContract = require('../contracts/wom-master/contract.json')

const wombatAssetMethods = require('../contracts/wombat-asset/methods')
const wombatAssetContract = require('../contracts/wombat-asset/contract.json')

const wombatFeePoolMethods = require('../contracts/wombat-fee-pool/methods')
const wombatFeePoolContract = require('../contracts/wombat-fee-pool/contract.json')

const lodestarCTokenMethods = require('../contracts/lodestar-ctoken/methods')
const lodestarCTokenContract = require('../contracts/lodestar-ctoken/contract.json')

Expand Down Expand Up @@ -286,4 +292,12 @@ module.exports = {
contract: wombatMasterContract,
methods: wombatMasterMethods,
},
wombatAsset: {
contract: wombatAssetContract,
methods: wombatAssetMethods,
},
wombatFeePool: {
contract: wombatFeePoolContract,
methods: wombatFeePoolMethods,
},
}
Loading
Loading