Skip to content

Commit

Permalink
Add CW20 (hINJ) to Neptune Finance adapter (#10034)
Browse files Browse the repository at this point in the history
* Fixed methodology description for Neptune Finance

* add CW20 lookup Neptune Finance adapter

* token factory address

---------

Co-authored-by: Francisco Inacio <[email protected]>
  • Loading branch information
1biest and FrankBoltzmann authored Apr 30, 2024
1 parent a904ea3 commit 6b81238
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions projects/neptune-finance/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
const { queryContract, getToken, sumTokens } = require('../helper/chain/cosmos')
const { queryContract, getToken, sumTokens, getBalance } = require('../helper/chain/cosmos')

const MARKET_ADDR = 'inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u';

const CW20_ADDRS = [
['inj18luqttqyckgpddndh8hvaq25d5nfwjc78m56lc', 'factory:inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk:inj18luqttqyckgpddndh8hvaq25d5nfwjc78m56lc']
];

async function sumCW20Tokens({
balances = {},
tokens,
owner,
chain
} = {}) {
// Loop through each token in the tokens array
await Promise.all(
tokens.map(async (token) => {
// Fetch the balance for the token and owner
const balance = await getBalance({ token: token[0], owner, chain });
// Add the balance to the balances object
if (!isNaN(balance) && typeof balance === 'number' && isFinite(balance)) {
balances[`injective:${token[1].toString()}`] = balance.toString(); // Convert balance to string and append to 2nd token in array
}
})
);
return balances;
}

async function tvl(api) {
return sumTokens({ chain: api.chain, owner: MARKET_ADDR})
let balances = {};

// Sum the balances of all tokens excluding CW20
await sumTokens({
balances,
chain: api.chain,
owner: MARKET_ADDR
});

// Sum the balances of CW20 tokens
await sumCW20Tokens({
balances,
chain: api.chain,
tokens: CW20_ADDRS,
owner: MARKET_ADDR
});

/* console.log("balances", balances) */
return balances
}

async function borrowed(api) {
// query market-state
const { markets, } = await queryContract({ chain: api.chain, contract: MARKET_ADDR, data: { get_state: {} } })
const { markets, } = await queryContract({
chain: api.chain,
contract: MARKET_ADDR,
data: {
get_state: {}
}
})

// get all borrowed
markets.map(market => {
Expand All @@ -22,4 +70,4 @@ module.exports = {
injective: {
tvl, borrowed
}
};
};

0 comments on commit 6b81238

Please sign in to comment.