Skip to content

Commit

Permalink
[coins] refactor kamino adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Jan 17, 2025
1 parent ee595d7 commit 285844b
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 1,223 deletions.
1,250 changes: 64 additions & 1,186 deletions coins/package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion coins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@aws-sdk/client-s3": "^3.354.0",
"@defillama/sdk": "^5.0.96",
"@ethersproject/bignumber": "^5.5.0",
"@kamino-finance/klend-sdk": "^5.10.9",
"@project-serum/anchor": "^0.26.0",
"@sentry/serverless": "^6.19.7",
"@sentry/tracing": "^6.19.7",
Expand Down
1 change: 0 additions & 1 deletion coins/src/adapters/rwa/kuma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const config: { [chain: string]: { [symbol: string]: string } } = {
const abi = "function latestRoundData() view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)";

export async function kuma(timestamp: number): Promise<Write[]> {
console.log("starting kuma");
const ethApi = await getApi("ethereum", timestamp);
const polyApi = await getApi("polygon", timestamp);
const prices: { [symbol: string]: number } = {
Expand Down
31 changes: 5 additions & 26 deletions coins/src/adapters/solana/kamino.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Write } from "../utils/dbInterfaces";
import { addToDBWritesList } from "../utils/database";
import { getConnection } from "./utils";
import { PublicKey } from "@solana/web3.js";
import { KaminoMarket } from "@kamino-finance/klend-sdk";

import rpcProxy from "../utils/rpcProxy";

const markets: string[] = [
"DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek",
Expand All @@ -12,32 +11,12 @@ const markets: string[] = [
export async function kamino(timestamp: number) {
if (timestamp != 0) throw new Error(`Kamino adapter only works for current`);

const connection = getConnection();
const reserves: any[] = [];
await Promise.all(
markets.map((m) =>
KaminoMarket.load(connection, new PublicKey(m), 60000).then((r) => {
if (r) reserves.push(...r.reserves);
}),
),
);
const reserves: any[] = (await Promise.all(markets.map(rpcProxy.kamino.reserves))).flat();

const writes: Write[] = [];
for (let [_, v] of reserves) {
const { price, decimals } = v.tokenOraclePrice;
const token = v.state.collateral.mintPubkey.toString();
for (let { price, token, decimals, symbol } of reserves) {

addToDBWritesList(
writes,
"solana",
token,
Number(price),
decimals.e,
`Kamino Reserve Collateral (${v.symbol}) Token`,
timestamp,
"kamino",
0.8,
);
addToDBWritesList(writes, "solana", token, price, decimals, `Kamino Reserve Collateral (${symbol}) Token`, timestamp, "kamino", 0.8,);
}

return writes;
Expand Down
4 changes: 0 additions & 4 deletions coins/src/adapters/solana/saber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,12 @@ async function priceMSOL2(timestamp: number) {
const res = await getMultipleAccountBuffers({ mint, vaultA, vaultB, lvaultA, lvaultB, lvtA, lvtB, });

const lpSupply = getSupply(res.mint, decimals)
// console.log(lpSupply)
// console.log(getBalance(res.vaultA)/1e12, getBalance(res.lvaultA)/1e12, getSupply(res.lvtA)/1e12, getBalance(res.lvaultA) / getSupply(res.lvtA))
// console.log(getBalance(res.vaultB)/1e12, getBalance(res.lvaultB)/1e12, getSupply(res.lvtB)/1e12, getBalance(res.lvaultB) / getSupply(res.lvtB))
const tokenABal = getBalance(res.vaultA) * getBalance(res.lvaultA) / getSupply(res.lvtA)
const tokenBBal = getBalance(res.vaultB) * getBalance(res.lvaultB) / getSupply(res.lvtB)
const coinBalances = new sdk.ChainApi({ chain: 'solana', })
coinBalances.add(tokenAMint, tokenABal)
coinBalances.add(tokenBMint, tokenBBal)
const price = (await coinBalances.getUSDValue()) / lpSupply
// console.log(tokenABal/1e12, tokenBBal/1e12, (await coinBalances.getUSDValue())/1e6, lpSupply/1e3)
addToDBWritesList(writes, chain, mint, price, decimals, symbol, timestamp, 'saber', 0.95)
}

Expand Down
8 changes: 4 additions & 4 deletions coins/src/adapters/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export async function getTokenAccountBalances(
) {
return;
}
console.log(
data.data.map((i: any) => i.result.value)[i],
tokenAccounts[i].toString(),
);
// console.log(
// data.data.map((i: any) => i.result.value)[i],
// tokenAccounts[i].toString(),
// );
if (allowError) return;
}
const {
Expand Down
15 changes: 15 additions & 0 deletions coins/src/adapters/utils/rpcProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from 'axios'

const client = axios.create({
baseURL: process.env.RPC_PROXY_URL,
timeout: 30000,
})

export default {
kamino: {
reserves: async (market) => {
const { data } = await client.get('/kamino/lend/'+market)
return data
},
},
}
1 change: 1 addition & 0 deletions coins/src/adapters/yield/misc4626/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"sUSDS": "0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD",
"pWBTC": "0x2f1aBb81ed86Be95bcf8178bA62C8e72D6834775",
"maxETH": "0x9847c14FCa377305c8e2D10A760349c667c367d4",
"aCVX": "0xb0903Ab70a7467eE5756074b31ac88aEBb8fB777",
"fUSDC": "0x9Fb7b4477576Fe5B32be4C1843aFB1e55F251B33"
},
"arbitrum": {
Expand Down
1 change: 0 additions & 1 deletion coins/src/utils/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export async function getCache(project: string, chain: string, { useTvlCache = f
if (useTvlCache)
Key = Key.replace('coins-cache', 'tvl-adapter-cache/cache')

console.log(Key, 'kye')
try {
const json = await sdk.cache.readCache(Key)
if (!json || Object.keys(json).length === 0) throw new Error('Invalid data')
Expand Down

0 comments on commit 285844b

Please sign in to comment.