Skip to content

Commit 85ebc05

Browse files
committed
cleanup
1 parent 5c5b84a commit 85ebc05

File tree

2 files changed

+28
-147
lines changed

2 files changed

+28
-147
lines changed

projects/kea-credit/index.js

Lines changed: 10 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
const sdk = require("@defillama/sdk");
2-
31
// KEA Credit Contract Addresses on Hedera
42
const INVOICE_FACTORY_PROXY = "0x79914D3C80246FBC9E40409C4688A4141A3abbCe";
5-
const INVOICE_NFT_PROXY = "0x28E99733E84dE18fF6f50024F6ad33483B3D7F80";
6-
7-
// Token Addresses (Hedera format: 0.0.tokenId)
8-
const TOKENS = {
9-
PIXD_V1: "0.0.9323052", // 0x00000000000000000000000000000000008e422c (0-decimal)
10-
KUSD_V2: "0.0.9590855", // 0x0000000000000000000000000000000000925847 (6-decimal)
11-
};
123

134
// Pool Status Constants - V1/V2
145
const POOL_STATUS_V1V2 = {
@@ -37,11 +28,6 @@ const FACTORY_ABI = [
3728
"function totalPools() external view returns (uint256)",
3829
];
3930

40-
const NFT_ABI = [
41-
"function getNextTokenId() external view returns (uint256)",
42-
"function totalSupply() external view returns (uint256)",
43-
];
44-
4531
const POOL_V1_ABI = [
4632
// V1 Pool ABI (simpler structure)
4733
"function getPoolInfo() external view returns (uint256 nftTokenId, uint256 targetAmount, uint256 currentAmount, uint256 interestRate, uint256 maturityDate, address borrower, uint8 status, uint256 platformFeePercentage, address treasuryWallet)",
@@ -52,25 +38,6 @@ const POOL_V3_ABI = [
5238
"function getPoolInfo() external view returns (uint256 nftTokenId, uint256 targetAmount, uint256 minAcceptableAmount, uint256 currentAmount, uint256 disbursedAmount, uint256 interestRate, uint256 originationDate, uint256 gracePeriodEndTime, uint256 maturityDate, address borrower, uint8 status, bool gracePeriodProcessed, address bridgeWalletAddress, uint256 supportedTokenCount)",
5339
];
5440

55-
/**
56-
* Determine if a token ID represents V1 or V3
57-
* Our first 12 NFTs are V1, rest are V3 (V2 was upgraded to V3 in place)
58-
*/
59-
function getVersionFromTokenId(tokenId) {
60-
return Number(tokenId) <= 12 ? "v1" : "v3";
61-
}
62-
63-
/**
64-
* Get token configuration based on version
65-
*/
66-
function getTokenConfig(version) {
67-
return {
68-
address: version === "v1" ? TOKENS.PIXD_V1 : TOKENS.KUSD_V2,
69-
decimals: version === "v1" ? 0 : 6,
70-
symbol: version === "v1" ? "PIXD" : "kUSD",
71-
};
72-
}
73-
7441
/**
7542
* Calculate TVL for a single pool based on its status
7643
*/
@@ -155,106 +122,25 @@ function calculatePoolTVL(poolInfo, version) {
155122
return tvlAmount;
156123
}
157124

158-
/**
159-
* Get pool info using the appropriate ABI based on pool index
160-
* First 12 pools (index 0-11) are V1, rest are V3 (V2 upgraded to V3)
161-
*/
162-
async function getPoolInfoWithVersion(poolAddress, poolIndex) {
163-
// Determine version based on pool index (first 12 are V1, rest are V3)
164-
const version = poolIndex < 12 ? "v1" : "v3";
165-
const abi = version === "v1" ? POOL_V1_ABI[0] : POOL_V3_ABI[0];
166-
167-
const result = await sdk.api.abi.call({
168-
target: poolAddress,
169-
abi: abi,
170-
chain: "hedera",
171-
});
172-
173-
if (result.output) {
174-
const tokenId = Number(result.output[0]);
175-
return {
176-
success: true,
177-
poolInfo: result.output,
178-
version,
179-
tokenId,
180-
};
181-
} else {
182-
return { success: false, error: "No output from pool call" };
183-
}
184-
}
185-
186125
/**
187126
* Main TVL calculation for Hedera
188127
*/
189-
async function hederaTvl() {
190-
const balances = {};
191-
let totalV1TVL = 0;
192-
let totalV3TVL = 0;
193-
let processedPools = 0;
194-
195-
// Get total NFTs to understand scale
196-
// Try getNextTokenId first (KEA Credit specific function)
197-
let totalNFTs = 0;
198-
199-
const nextTokenIdResult = await sdk.api.abi.call({
200-
target: INVOICE_NFT_PROXY,
201-
abi: NFT_ABI[0], // getNextTokenId
202-
chain: "hedera",
203-
});
204-
205-
if (nextTokenIdResult.output !== undefined) {
206-
totalNFTs = Number(nextTokenIdResult.output) - 1; // Next token ID - 1 = current total
207-
} else {
208-
throw new Error("getNextTokenId returned undefined");
209-
}
210-
128+
async function hederaTvl(api) {
211129
// Get all pool addresses
212-
const poolsResult = await sdk.api.abi.call({
213-
target: INVOICE_FACTORY_PROXY,
214-
abi: FACTORY_ABI[0],
215-
chain: "hedera",
216-
});
217-
218-
if (poolsResult.output === undefined) {
219-
throw new Error(
220-
`Factory getAllPools call failed: ${JSON.stringify(poolsResult)}`
221-
);
222-
}
223-
224-
const poolAddresses = poolsResult.output || [];
225-
226-
// Process each pool
227-
for (let i = 0; i < poolAddresses.length; i++) {
228-
const poolAddress = poolAddresses[i];
229-
230-
const poolResult = await getPoolInfoWithVersion(poolAddress, i);
231-
232-
if (!poolResult.success) {
233-
continue;
234-
}
235-
236-
const { poolInfo, version, tokenId } = poolResult;
237-
238-
// Calculate TVL for this pool
239-
const poolTVL = calculatePoolTVL(poolInfo, version);
240-
241-
if (version === "v1") {
242-
totalV1TVL += poolTVL;
243-
} else if (version === "v3") {
244-
totalV3TVL += poolTVL;
245-
}
246-
247-
processedPools++;
248-
}
249-
250-
const totalTVL = totalV1TVL + totalV3TVL;
130+
const poolAddresses = await api.call({ target: INVOICE_FACTORY_PROXY, abi: FACTORY_ABI[0], });
131+
const v1Pools = poolAddresses.slice(0, 12)
132+
const v3Pools = poolAddresses.slice(12)
133+
const poolV1Info = await api.multiCall({ abi: POOL_V1_ABI[0] , calls: v1Pools})
134+
const poolV3Info = await api.multiCall({ abi: POOL_V3_ABI[0] , calls: v3Pools})
251135

252-
balances["usd-coin"] = totalTVL;
136+
const v1Tvls = poolV1Info.map(info => calculatePoolTVL(info, "v1"))
137+
const v3Tvls = poolV3Info.map(info => calculatePoolTVL(info, "v3"))
253138

254-
return balances;
139+
api.addUSDValue(v1Tvls.concat(v3Tvls).reduce((a, b) => a + b, 0))
255140
}
256141

257142
module.exports = {
143+
misrepresentedTokens: true,
258144
methodology:
259145
"TVL represents the total value locked in KEA Credit's RWA (Real World Assets) invoice tokenization platform on Hedera. Businesses tokenize their invoices as NFTs and receive funding from lenders through investment pools. TVL calculation includes: (1) Active pools - current invested amounts, (2) Funded pools - fully funded target amounts, (3) Partially funded pools - current invested amounts, (4) Pools in grace period - current amounts during active grace period. Excludes repaid, cancelled, defaulted, or refunded pools. The platform operates with two versions: V1 pools (NFT IDs 1-12) using 0-decimal PIXD tokens, and V3 pools (NFT IDs 13+) using 6-decimal kUSD tokens. Both tokens maintain 1:1 USD parity representing underlying invoice values.",
260146
hedera: {

projects/kokoa-finance/index.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
const ABI = require("./Helper.json");
2-
const sdk = require("@defillama/sdk");
3-
const chain = 'klaytn'
1+
const ABI = {
2+
"address": "0x2b170005ADA0e616E78A7fa93ea4473c03A98aa0",
3+
"abi":{
4+
"getCollateralTVL": "uint256[]:getCollateralTVL",
5+
"getSkokoaTVL": "uint256:getSkokoaTVL",
6+
"getKlayswapLpFarmTVL": "function getKlayswapLpFarmTVL(address pool) view returns (uint256 tvl)",
7+
"getKokonutLpFarmTVL": "function getKokonutLpFarmTVL(address pool) view returns (uint256 tvl)"
8+
}
9+
}
410

511
const { toUSDTBalances } = require("../helper/balances");
612
const BigNumber = require("bignumber.js");
13+
const { getConfig } = require("../helper/cache");
714

815
const HELPER_ADDR = "0x2b170005ADA0e616E78A7fa93ea4473c03A98aa0";
916

@@ -38,14 +45,13 @@ const KOKONUT_POOLS = [
3845
}
3946
]
4047

41-
const fetchCollateral = async (ts, _block, chainBlocks) => {
42-
const block = chainBlocks[chain]
48+
const fetchCollateral = async (api) => {
49+
const _data = await getConfig('kokoa-finance', 'https://prod.kokoa-api.com/vaults/borrow')
4350
//calculate TVL sum of all collaterals locked in the protocol vaults
4451
const decimal = 18;
4552

4653
var sum = new BigNumber(0);
47-
const { output: assetTvlLists } = await sdk.api.abi.call({
48-
chain, block,
54+
const assetTvlLists = await api.call({
4955
target: HELPER_ADDR,
5056
abi: ABI.abi.getCollateralTVL
5157
})
@@ -56,20 +62,12 @@ const fetchCollateral = async (ts, _block, chainBlocks) => {
5662
return toUSDTBalances(sum.toFixed(2));
5763
}
5864

59-
const fetchPool2 = async (ts, _block, chainBlocks) => {
60-
const block = chainBlocks[chain]
61-
// const toa = [
62-
// ['0x4bFCc93fb85c969a590A2e7D7a4Ad72F0668AFF2', '0x53fe8c456c470a7214ed5caad88c486449f3b196'], // KLAY-KOKOA
63-
// ['0xd52aCC40924C906D3EeAB239D6F6C36B612011af', '0xc8D2b302266f90a713af573dFd4F305CC4C30C92'], // KLAY-KSD
64-
// ]
65-
66-
// return sumTokens2({ chain, block, tokensAndOwners: toa, resolveLP: true })
65+
const fetchPool2 = async (api) => {
6766
const decimal = 18;
6867

6968
let klayswapPool2Tvl = BigNumber(0);
7069
for (let pool of KLAYSWAP_POOLS) {
71-
const { output: value } = await sdk.api.abi.call({
72-
chain, block,
70+
const value = await api.call({
7371
target: HELPER_ADDR,
7472
params: [pool[`address`]],
7573
abi: ABI.abi.getKlayswapLpFarmTVL
@@ -78,8 +76,7 @@ const fetchPool2 = async (ts, _block, chainBlocks) => {
7876
}
7977
let kokonutPool2Tvl = BigNumber(0);
8078
for (let pool of KOKONUT_POOLS) {
81-
const { output: value } = await sdk.api.abi.call({
82-
chain, block,
79+
const value = await api.call({
8380
target: HELPER_ADDR,
8481
params: [pool[`address`]],
8582
abi: ABI.abi.getKokonutLpFarmTVL
@@ -90,12 +87,10 @@ const fetchPool2 = async (ts, _block, chainBlocks) => {
9087
return toUSDTBalances(totalPool2.toFixed(2));
9188
}
9289

93-
const fetchStakedToken = async (ts, _block, chainBlocks) => {
94-
const block = chainBlocks[chain]
90+
const fetchStakedToken = async (api) => {
9591
//staked token prices are calculated using real-time KOKOA price from KLAY-KOKOA LP
9692

97-
let { output: skokoaTvl } = await sdk.api.abi.call({
98-
chain, block,
93+
let skokoaTvl = await api.call({
9994
target: HELPER_ADDR,
10095
abi: ABI.abi.getSkokoaTVL
10196
})

0 commit comments

Comments
 (0)