-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add prisma finance adapter * add apybaseborrow rate
- Loading branch information
1 parent
132e23a
commit f2f4cfc
Showing
3 changed files
with
1,616 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ "internalType": "address", "name": "_prismaCore", "type": "address" }, | ||
{ | ||
"internalType": "contract IDebtToken", | ||
"name": "_debtToken", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "contract IStabilityPool", | ||
"name": "_stabilityPool", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "contract IBorrowerOperations", | ||
"name": "_borrowerOperations", | ||
"type": "address" | ||
}, | ||
{ "internalType": "address", "name": "_sortedTroves", "type": "address" }, | ||
{ "internalType": "address", "name": "_troveManager", "type": "address" }, | ||
{ | ||
"internalType": "contract ILiquidationManager", | ||
"name": "_liquidationManager", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "collateral", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "priceFeed", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "troveManager", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "sortedTroves", | ||
"type": "address" | ||
} | ||
], | ||
"name": "NewDeployment", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "PRISMA_CORE", | ||
"outputs": [ | ||
{ "internalType": "contract IPrismaCore", "name": "", "type": "address" } | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "borrowerOperations", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract IBorrowerOperations", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "debtToken", | ||
"outputs": [ | ||
{ "internalType": "contract IDebtToken", "name": "", "type": "address" } | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ "internalType": "address", "name": "collateral", "type": "address" }, | ||
{ "internalType": "address", "name": "priceFeed", "type": "address" }, | ||
{ | ||
"internalType": "address", | ||
"name": "customTroveManagerImpl", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "customSortedTrovesImpl", | ||
"type": "address" | ||
}, | ||
{ | ||
"components": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "minuteDecayFactor", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "redemptionFeeFloor", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "maxRedemptionFee", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "borrowingFeeFloor", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "maxBorrowingFee", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "interestRateInBps", | ||
"type": "uint256" | ||
}, | ||
{ "internalType": "uint256", "name": "maxDebt", "type": "uint256" }, | ||
{ "internalType": "uint256", "name": "MCR", "type": "uint256" } | ||
], | ||
"internalType": "struct Factory.DeploymentParams", | ||
"name": "params", | ||
"type": "tuple" | ||
} | ||
], | ||
"name": "deployNewInstance", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "guardian", | ||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "liquidationManager", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract ILiquidationManager", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_troveManagerImpl", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "_sortedTrovesImpl", | ||
"type": "address" | ||
} | ||
], | ||
"name": "setImplementations", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "sortedTrovesImpl", | ||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "stabilityPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract IStabilityPool", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "troveManagerCount", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "troveManagerImpl", | ||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"name": "troveManagers", | ||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
const axios = require('axios'); | ||
const sdk = require('@defillama/sdk4'); | ||
|
||
const factoryAbi = require('./factoryAbi.json'); | ||
const troveManagerAbi = require('./troveManagerAbi.json'); | ||
|
||
const mkUsd = '0x4591DBfF62656E7859Afe5e45f6f47D3669fBB28'; // debt token | ||
const prisma = '0xda47862a83dac0c112ba89c6abc2159b95afd71c'; // reward token | ||
const factory = '0x70b66E20766b775B2E9cE5B718bbD285Af59b7E1'; | ||
|
||
const apy = async () => { | ||
const troveManagerCount = ( | ||
await sdk.api.abi.call({ | ||
target: factory, | ||
abi: factoryAbi.find((i) => i.name === 'troveManagerCount'), | ||
}) | ||
).output; | ||
|
||
const troveManagers = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: Array.from({ length: troveManagerCount }, (_, index) => index).map( | ||
(i) => ({ target: factory, params: i }) | ||
), | ||
abi: factoryAbi.find((i) => i.name === 'troveManagers'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const collateralTokens = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: troveManagers.map((i) => ({ target: i })), | ||
abi: troveManagerAbi.find((i) => i.name === 'collateralToken'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const balanceOf = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: collateralTokens.map((t, i) => ({ | ||
target: t, | ||
params: troveManagers[i], | ||
})), | ||
abi: 'erc20:balanceOf', | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const MCR = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: troveManagers.map((i) => ({ target: i })), | ||
abi: troveManagerAbi.find((i) => i.name === 'MCR'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const systemDebt = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: troveManagers.map((i) => ({ target: i })), | ||
abi: troveManagerAbi.find((i) => i.name === 'getEntireSystemDebt'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const maxSystemDebt = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: troveManagers.map((i) => ({ target: i })), | ||
abi: troveManagerAbi.find((i) => i.name === 'maxSystemDebt'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const rewardRate = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: troveManagers.map((i) => ({ target: i })), | ||
abi: troveManagerAbi.find((i) => i.name === 'rewardRate'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const interestRate = ( | ||
await sdk.api.abi.multiCall({ | ||
calls: troveManagers.map((i) => ({ target: i })), | ||
abi: troveManagerAbi.find((i) => i.name === 'interestRate'), | ||
}) | ||
).output.map((i) => i.output); | ||
|
||
const keys = [...collateralTokens, prisma] | ||
.map((i) => `ethereum:${i}`) | ||
.join(','); | ||
const prices = ( | ||
await axios.get(`https://coins.llama.fi/prices/current/${keys}`) | ||
).data.coins; | ||
|
||
return troveManagers.map((t, i) => { | ||
const priceDetails = prices[`ethereum:${collateralTokens[i]}`]; | ||
const tvlUsd = | ||
(balanceOf[i] * priceDetails.price) / 10 ** priceDetails.decimals; | ||
|
||
const apyBaseBorrow = ((interestRate[i] * 86400 * 365) / 1e27) * 100; | ||
|
||
const apyRewardBorrow = | ||
(((rewardRate[i] / 1e18) * | ||
86400 * | ||
365 * | ||
prices[`ethereum:${prisma}`].price) / | ||
tvlUsd) * | ||
100; | ||
|
||
return { | ||
pool: t, | ||
chain: 'ethereum', | ||
project: 'prisma-finance', | ||
symbol: priceDetails.symbol, | ||
tvlUsd, | ||
apy: 0, | ||
mintedCoin: 'mkUsd', | ||
apyBaseBorrow, | ||
apyRewardBorrow, | ||
totalSupplyUsd: tvlUsd, | ||
totalBorrowUsd: systemDebt[i] / 1e18, | ||
debtCeilingUsd: maxSystemDebt[i] / 1e18, | ||
ltv: 1 / Number(MCR[i] / 1e18), | ||
url: `https://app.prismafinance.com/vaults/select/${t}`, | ||
rewardTokens: apyRewardBorrow > 0 ? [prisma] : [], | ||
underlyingTokens: [collateralTokens[i]], | ||
}; | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
apy, | ||
}; |
Oops, something went wrong.