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(abracadabra): Add support for Kava cauldrons #1081

Merged
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
112 changes: 112 additions & 0 deletions src/adaptors/abracadabra/abis/FeeCollectable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"inputs": [],
"name": "ErrInvalidFeeBips",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "ErrInvalidFeeOperator",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousFeeCollector",
"type": "address"
},
{
"indexed": false,
"internalType": "uint16",
"name": "previousFeeAmount",
"type": "uint16"
},
{
"indexed": true,
"internalType": "address",
"name": "feeCollector",
"type": "address"
},
{
"indexed": false,
"internalType": "uint16",
"name": "feeAmount",
"type": "uint16"
}
],
"name": "LogFeeParametersChanged",
"type": "event"
},
{
"inputs": [],
"name": "feeBips",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "feeCollector",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "isFeeOperator",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_feeCollector",
"type": "address"
},
{
"internalType": "uint16",
"name": "_feeBips",
"type": "uint16"
}
],
"name": "setFeeParameters",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
62 changes: 57 additions & 5 deletions src/adaptors/abracadabra/cauldrons.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CAULDRON_V2_ABI = require('./abis/CauldronV2.json');
const BENTOBOX_V1_ABI = require('./abis/BentoBoxV1.json');
const INTEREST_STRATEGY = require('./abis/InterestStrategy.json');
const BASE_STARGATE_LP_STRATEGY = require('./abis/BaseStargateLPStrategy.json');
const FEE_COLLECTABLE_STRATEGY = require('./abis/FeeCollectable.json');

const MIM_COINGECKO_ID = 'magic-internet-money';

Expand Down Expand Up @@ -166,6 +167,17 @@ const POOLS = {
{ version: 3, address: '0x68f498c230015254aff0e1eb6f85da558dff2362' },
],
},
kava: {
marketLensAddress: '0x2d50927A6E87E517946591A137b765fAba018E70',
cauldrons: [
{ version: 4, address: '0x3CFf6F628Ebc88e167640966E67314Cf6466E6A8' }, // MIM/USDT Curve LP
{
version: 4,
address: '0x895731a0C3836a5534561268F15EBA377218651D',
collateralPoolId: '246ee0b2-434e-44dd-90a7-a728deaf1597',
}, // Stargate USDT
]
},
};

const NEGATIVE_INTEREST_STRATEGIES = {
Expand All @@ -182,6 +194,12 @@ const BASE_STARGATE_LP_STRATEGIES = {
],
};

const FEE_COLLECTABLE_STRATEGIES = {
kava: [
'0x30D525cbB79D2baaE7637eA748631a6360Ce7c16'
]
}

const getMarketLensDetailsForCauldrons = (
chain,
marketLensAddress,
Expand Down Expand Up @@ -453,6 +471,37 @@ const getBaseStargateLpStrategyFees = (baseStargateLpStrategies) =>
)
).then(Object.fromEntries);

const getFeeCollectableStrategyFees = (feeCollectableStrategies) =>
Promise.all(
Object.entries(feeCollectableStrategies).map(
async ([chain, chainFeeCollectableStrategies]) => [
chain,
await sdk.api.abi
.multiCall({
abi: FEE_COLLECTABLE_STRATEGY.find(
({ name }) => name === 'feeBips'
),
calls: chainFeeCollectableStrategies.map(
(feeCollectableStrategy) => ({
target: feeCollectableStrategy,
})
),
chain,
requery: true,
})
.then((call) =>
Object.fromEntries(
call.output.map((x, i) => [
chainFeeCollectableStrategies[i].toLowerCase(),
x.output / 10000,
])
)
),
]
)
).then(Object.fromEntries);


const getDetailsFromCollaterals = (collaterals, abi) =>
Promise.all(
Object.entries(collaterals).map(async ([chain, chainCollaterals]) => {
Expand Down Expand Up @@ -539,7 +588,7 @@ const getApy = async () => {
bentoboxes,
strategies,
negativeInterestStrategyApys,
baseStargateLpStrategyFees,
strategyFees,
symbols,
decimals,
pricesObj,
Expand All @@ -552,7 +601,10 @@ const getApy = async () => {
([collaterals, bentoboxes]) => getStrategies(collaterals, bentoboxes)
),
getNegativeInterestStrategyApy(NEGATIVE_INTEREST_STRATEGIES),
getBaseStargateLpStrategyFees(BASE_STARGATE_LP_STRATEGIES),
Promise.all([
getBaseStargateLpStrategyFees(BASE_STARGATE_LP_STRATEGIES),
getFeeCollectableStrategyFees(FEE_COLLECTABLE_STRATEGIES),
]).then((strategyFeesArr) => _.merge({}, ...strategyFeesArr)),
collateralsPromise.then((collaterals) =>
getDetailsFromCollaterals(collaterals, 'erc20:symbol')
),
Expand Down Expand Up @@ -601,20 +653,20 @@ const getApy = async () => {
negativeInterestStrategyApys,
[chain, strategy]
);
const baseStargateLpStrategyFee = _.get(baseStargateLpStrategyFees, [
const strategyFee = _.get(strategyFees, [
chain,
strategy,
]);
if (negativeInterestStrategyApy !== undefined) {
collateral.apyBase =
(targetPercentage / 100) * -negativeInterestStrategyApy;
} else if (
baseStargateLpStrategyFee !== undefined &&
strategyFee !== undefined &&
collateralApy !== undefined
) {
collateral.apyBase =
((collateralApy.apy * targetPercentage) / 100) *
baseStargateLpStrategyFee;
(1 - strategyFee);
}
} else {
// No strategy to consider, so just use the apy from the pool if one exists.
Expand Down
Loading