Skip to content

Commit 39885ee

Browse files
Merge branch 'main' of github.com:Thesauros/DefiLlama-Adapters
2 parents 1f2ae11 + fb73b63 commit 39885ee

File tree

9 files changed

+143
-144
lines changed

9 files changed

+143
-144
lines changed

projects/helper/chains.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
"flow",
162162
"fluence",
163163
"formnetwork",
164+
"fogo",
164165
"fraxtal",
165166
"fsc",
166167
"ftn",

projects/helper/env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DEFAULTS = {
2626
SUBSCAN_API_KEY: 'ca3ba5ed1ff44b689c5f81dfc6b1644b',
2727
RENEC_RPC: "https://api-mainnet-beta.renec.foundation:8899/",
2828
FLOW_RPC: 'https://rest-mainnet.onflow.org',
29+
FOGO_RPC: 'https://mainnet.fogo.io',
2930
CAMP_RPC: 'https://rpc.camp.raas.gelato.cloud',
3031
LULO_API_KEY: '',
3132
TRON_RPC: 'https://api.trongrid.io',

projects/helper/svmChainConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const endpointMap = {
1414
soon: () => getEnv('SOON_RPC'),
1515
soon_base: () => getEnv('SOON_BASE_RPC'),
1616
soon_bsc: () => getEnv('SOON_BSC_RPC'),
17+
fogo: () => getEnv('FOGO_RPC'),
1718
}
1819
const svmChains = Object.keys(endpointMap)
1920

projects/helper/tokenMapping.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ const fixBalancesTokens = {
7979
stable: {
8080
'0x779Ded0c9e1022225f8E0630b35a9b54bE713736': { coingeckoId: 'usdt0', decimals: 6 },
8181
'0x0000000000000000000000000000000000001003': { coingeckoId: 'usdt0', decimals: 18 },
82-
}
82+
},
83+
fogo: {
84+
'uSd2czE61Evaf76RNbq4KPpXnkiL3irdzgLFUMe3NoG': { coingeckoId: 'usd-coin', decimals: 6 },
85+
'HLc5hqihQGFU68488j7HkdyF6rywyJfV46BN6Dn8W5ug': { coingeckoId: 'solana', decimals: 8 },
86+
},
8387
}
8488

8589
ibcChains.forEach(chain => fixBalancesTokens[chain] = { ...ibcMappings, ...(fixBalancesTokens[chain] || {}) })

projects/kinetiq-markets/index.js

Lines changed: 32 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
const ADDRESSES = require('../helper/coreAssets.json')
2-
const { getLogs } = require('../helper/cache/getLogs')
1+
const router = '0x6AB31532382Ba5cD5E8b5D343Cf5995906bb8DD8'
32

4-
const WHYPE = ADDRESSES.hyperliquid.WHYPE
5-
const ROUTER = '0x6AB31532382Ba5cD5E8b5D343Cf5995906bb8DD8'
6-
const KHYPE_MANAGER = '0x393D0B87Ed38fc779FD9611144aE649BA6082109'
7-
8-
const FROM_BLOCK = 4800000
3+
const HYPE = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
4+
const kHypeManager = '0x393D0B87Ed38fc779FD9611144aE649BA6082109'
95

106
const abis = {
117
phase: "function phase(address exManager) view returns (uint8)",
@@ -15,115 +11,62 @@ const abis = {
1511
nextWithdrawalId: "function nextWithdrawalId(address) view returns (uint256)",
1612
withdrawalDelay: "function withdrawalDelay() view returns (uint256)",
1713
withdrawalRequests: "function withdrawalRequests(address user, uint256 id) view returns (uint256 hypeAmount, uint256 kHYPEAmount, uint256 kHYPEFee, uint256 bufferUsed, uint256 timestamp)",
18-
}
19-
20-
const eventAbi = "event ExManagerRegistered(address indexed exManager, address indexed exLST)"
14+
};
2115

22-
const DEFAULT_MANAGERS = [
23-
'0x4ef8bbacee867efd6faa684b30ecd12df74c4a48'
16+
const managers = [
17+
'0x4ef8bbacee867efd6faa684b30ecd12df74c4a48' // kmHYPE
2418
]
2519

26-
async function getExchangeManagers(api) {
27-
try {
28-
const logs = await getLogs({
29-
api,
30-
target: ROUTER,
31-
eventAbi,
32-
fromBlock: FROM_BLOCK,
33-
onlyArgs: true,
34-
})
35-
if (logs.length > 0) {
36-
return logs.map(log => log.exManager)
37-
}
38-
} catch (e) {
39-
// Fall back to known managers
40-
}
41-
return DEFAULT_MANAGERS
42-
}
43-
44-
async function tvl(api) {
45-
const managers = await getExchangeManagers(api)
46-
20+
const tvl = async (api) => {
4721
const [phases, exLSTs] = await Promise.all([
48-
api.multiCall({ target: ROUTER, calls: managers, abi: abis.phase }),
49-
api.multiCall({ target: ROUTER, calls: managers, abi: abis.exLST }),
22+
api.multiCall({ target: router, calls: managers, abi: abis.phase }),
23+
api.multiCall({ target: router, calls: managers, abi: abis.exLST }),
5024
])
5125

5226
for (const [index, exLST] of exLSTs.entries()) {
53-
if (!exLST || exLST === ADDRESSES.null) continue
54-
5527
const phase = phases[index]
5628
const manager = managers[index]
5729

5830
const supply = await api.call({ target: exLST, abi: 'erc20:totalSupply' })
59-
if (!supply || supply === '0') continue
60-
61-
const allowedAssets = await api.call({
62-
target: ROUTER,
63-
params: [phase],
64-
abi: abis.allowedTokensInOnDeposit,
65-
permitFailure: true
66-
})
31+
const allowedAssets = await api.call({ target: router, params: phase, abi: abis.allowedTokensInOnDeposit, permitFailure: true })
6732

6833
if (!allowedAssets?.length) continue
6934

7035
const assetOutputs = await api.multiCall({
7136
abi: abis.exLstToTokenOut,
7237
permitFailure: true,
73-
calls: allowedAssets.map((asset) => ({
74-
target: ROUTER,
75-
params: [manager, asset, supply]
76-
})),
38+
calls: allowedAssets.map((asset) => ({ target: router, params: [manager, asset, supply] })),
7739
})
7840

79-
for (let i = 0; i < allowedAssets.length; i++) {
80-
const asset = allowedAssets[i]
41+
allowedAssets.forEach((asset, i) => {
8142
const amount = assetOutputs[i]
43+
if (!amount) return
44+
api.add(asset, amount)
45+
})
8246

83-
if (!amount || amount === '0') continue
84-
85-
if (asset.toLowerCase() === WHYPE.toLowerCase() ||
86-
asset.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
87-
api.add(WHYPE, amount)
88-
break
89-
}
90-
}
91-
92-
try {
93-
const [nextWithdrawalId, withdrawalDelay] = await Promise.all([
94-
api.call({ target: KHYPE_MANAGER, params: [manager], abi: abis.nextWithdrawalId }),
95-
api.call({ target: KHYPE_MANAGER, abi: abis.withdrawalDelay })
96-
])
47+
const [nextWithdrawalId, withdrawalDelay] = await Promise.all([
48+
api.call({ target: kHypeManager, params: [manager], abi: abis.nextWithdrawalId }),
49+
api.call({ target: kHypeManager, abi: abis.withdrawalDelay })
50+
])
9751

98-
if (nextWithdrawalId && Number(nextWithdrawalId) > 0) {
99-
const withdrawalIds = [...Array(Math.min(Number(nextWithdrawalId), 100)).keys()]
52+
const withdrawalIds = [...Array(Number(nextWithdrawalId)).keys()]
10053

101-
const withdrawalRequests = await api.multiCall({
102-
target: KHYPE_MANAGER,
103-
abi: abis.withdrawalRequests,
104-
calls: withdrawalIds.map((id) => ({ params: [manager, id] })),
105-
permitFailure: true,
106-
})
54+
const withdrawalRequests = await api.multiCall({
55+
target: kHypeManager,
56+
abi: abis.withdrawalRequests,
57+
calls: withdrawalIds.map((id) => ({ params: [manager, id] })),
58+
permitFailure: true,
59+
})
10760

108-
const now = api.timestamp || Math.floor(Date.now() / 1000)
61+
if (!withdrawalRequests.length) continue
62+
const now = Math.floor(Date.now() / 1000)
10963

110-
withdrawalRequests.forEach((req) => {
111-
if (!req) return
112-
const { hypeAmount, timestamp } = req
113-
if (now >= Number(timestamp) + Number(withdrawalDelay)) {
114-
api.add(WHYPE, -BigInt(hypeAmount))
115-
}
116-
})
117-
}
118-
} catch (e) {
119-
// Continue without withdrawal adjustment
120-
}
64+
withdrawalRequests.forEach(({ hypeAmount, timestamp }) => {
65+
now < Number(timestamp) + Number(withdrawalDelay) ? api.add(HYPE, -hypeAmount) : api.add(HYPE, -0)
66+
})
12167
}
12268
}
12369

12470
module.exports = {
125-
doublecounted: true,
126-
timetravel: false,
127-
methodology: 'TVL is calculated from the total exLST supply converted to underlying HYPE value via router functions.',
12871
hyperliquid: { tvl }
129-
}
72+
}

projects/ribbon-earn/index.js

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,28 @@
11
const ADDRESSES = require('../helper/coreAssets.json')
22
const sdk = require("@defillama/sdk")
3-
const abi = require("../ribbon/abi.json")
43
const { sumTokensExport } = require('../helper/unwrapLPs');
5-
const { default: BigNumber } = require("bignumber.js");
64

75
// Ribbon Earn vaults
86
const rearnUSDC = "0x84c2b16FA6877a8fF4F3271db7ea837233DFd6f0";
97
const rearnstETH = "0xCE5513474E077F5336cf1B33c1347FDD8D48aE8c";
108

11-
// Ethereum Assets
12-
const usdc = ADDRESSES.ethereum.USDC;
13-
const steth = ADDRESSES.ethereum.STETH;
9+
const tokensAndOwners = [
10+
[ADDRESSES.ethereum.USDC, rearnUSDC],
11+
[ADDRESSES.ethereum.STETH, rearnstETH],
12+
]
1413

15-
async function addVaults({ balances, chain, vaults, block, transformAddress = a => a }) {
16-
const { output: balanceRes } = await sdk.api.abi.multiCall({
17-
abi: abi.totalBalance,
18-
calls: vaults.map(i => ({ target: i[1]})),
19-
chain, block,
20-
})
21-
22-
balanceRes.forEach((data, i) => sdk.util.sumSingleBalance(balances, transformAddress(vaults[i][0]), data.output))
23-
}
24-
25-
async function getAssetOnVault(asset, param, block) {
26-
const { output: balance } = await sdk.api.abi.call({
27-
target: asset, abi: 'erc20:balanceOf', params: param, block,
28-
})
29-
return balance
30-
}
31-
32-
async function borrowed(_, block) {
33-
const balances = {};
34-
const vaults = [
35-
// ribbon earn
36-
[usdc, rearnUSDC],
37-
[steth, rearnstETH],
38-
]
39-
await addVaults({ balances, block, vaults, })
40-
sdk.util.sumSingleBalance(balances, usdc, BigNumber(-1 * (await getAssetOnVault(usdc, rearnUSDC, block))).toFixed(0))
41-
sdk.util.sumSingleBalance(balances, steth, BigNumber(-1 * (await getAssetOnVault(steth, rearnstETH, block))).toFixed(0))
42-
return balances
14+
async function borrowed(api) {
15+
const cloneApi = new sdk.ChainApi({ block: api.block, chain: api.chain });
16+
await cloneApi.sumTokens({ tokensAndOwners })
17+
const bals = await api.multiCall({ abi: 'uint256:totalBalance', calls: tokensAndOwners.map(i => i[1]) })
18+
const tokens = tokensAndOwners.map(i => i[0])
19+
api.add(tokens, bals)
20+
api.getBalancesV2().subtract(cloneApi.getBalances())
4321
}
4422

4523
module.exports = {
4624
ethereum: {
47-
tvl: sumTokensExport({tokensAndOwners: [[usdc, rearnUSDC], [steth, rearnstETH]]}),
25+
tvl: sumTokensExport({ tokensAndOwners }),
4826
borrowed,
4927
},
5028
}

projects/ribbon/evm.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ const wavax = ADDRESSES.avax.WAVAX;
5050
const savax = ADDRESSES.avax.SAVAX;
5151
const usdce = ADDRESSES.avax.USDC_e;
5252

53-
async function addVaults({ vaults, api }) {
54-
const tokens = vaults.map(i => i[0])
55-
const calls = vaults.map(i => i[1])
56-
const balance = await api.multiCall({ abi: 'uint256:totalBalance', calls })
57-
api.add(tokens, balance)
58-
}
59-
6053
async function ethTvl(api) {
6154
const vaults = [
6255
// theta vault
@@ -80,8 +73,7 @@ async function ethTvl(api) {
8073
[badger, badgerCallVault],
8174

8275
]
83-
84-
await addVaults({ api, vaults, })
76+
await api.sumTokens({ tokensAndOwners: vaults })
8577
// pauser holds a variety of coins
8678
return sumTokens2({ api, owner: pauserEth, tokens: [nullAddress, usdc, wbtc, steth, aave,], })
8779
}
@@ -93,7 +85,7 @@ async function avaxTvl(api) {
9385
[usdce, usdcAvaxPutVault],
9486
]
9587

96-
await addVaults({ api, vaults, })
88+
await api.sumTokens({ tokensAndOwners: vaults })
9789
return sumTokens2({ owner: pauserAvax, tokens: [nullAddress, savax], api, })
9890
}
9991

projects/valiant-trade/index.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const { sumTokens2, getProvider, } = require("../helper/solana");
2+
const { Program } = require("@project-serum/anchor");
3+
const DEX_PROGRAM_ID = 'vnt1u7PzorND5JjweFWmDawKe2hLWoTwHU6QKz6XX98'
4+
5+
6+
async function tvl(api) {
7+
const provider = getProvider(api.chain);
8+
const program = new Program(idl, DEX_PROGRAM_ID, provider)
9+
10+
const tokenAccounts = (await program.account.vortex.all())
11+
.map(({ account }) => [account.tokenVaultA, account.tokenVaultB])
12+
.flat();
13+
14+
return sumTokens2({ tokenAccounts, api });
15+
}
16+
17+
module.exports = {
18+
timetravel: false,
19+
fogo: {
20+
tvl,
21+
}
22+
}
23+
24+
const idl = {
25+
"version": "0.3.4",
26+
"name": "vortex",
27+
"instructions": [],
28+
"accounts": [
29+
{
30+
"name": "Vortex",
31+
"type": {
32+
"kind": "struct",
33+
"fields": [
34+
{ "name": "vortexConfig", "type": "publicKey" },
35+
{ "name": "vortexBump", "type": { "array": ["u8", 1] } },
36+
{ "name": "tickSpacing", "type": "u16" },
37+
{ "name": "tickSpacingSeed", "type": { "array": ["u8", 2] } },
38+
{ "name": "feeRate", "type": "u16" },
39+
{ "name": "protocolFeeRate", "type": "u16" },
40+
{ "name": "liquidity", "type": "u128" },
41+
{ "name": "sqrtPrice", "type": "u128" },
42+
{ "name": "tickCurrentIndex", "type": "i32" },
43+
{ "name": "protocolFeeOwedA", "type": "u64" },
44+
{ "name": "protocolFeeOwedB", "type": "u64" },
45+
{ "name": "tokenMintA", "type": "publicKey" },
46+
{ "name": "tokenVaultA", "type": "publicKey" },
47+
{ "name": "feeGrowthGlobalA", "type": "u128" },
48+
{ "name": "tokenMintB", "type": "publicKey" },
49+
{ "name": "tokenVaultB", "type": "publicKey" },
50+
{ "name": "feeGrowthGlobalB", "type": "u128" },
51+
{ "name": "rewardLastUpdatedTimestamp", "type": "u64" },
52+
{ "name": "rewardInfos", "type": { "array": [{ "defined": "VortexRewardInfo" }, 3] } }
53+
]
54+
}
55+
}
56+
],
57+
"types": [
58+
{
59+
"name": "VortexRewardInfo",
60+
"docs": [
61+
"Stores the state relevant for tracking liquidity mining rewards at the `Vortex` level.",
62+
"These values are used in conjunction with `PositionRewardInfo`, `Tick.reward_growths_outside`,",
63+
"and `Vortex.reward_last_updated_timestamp` to determine how many rewards are earned by open",
64+
"positions."
65+
],
66+
"type": {
67+
"kind": "struct",
68+
"fields": [
69+
{ "name": "mint", "docs": ["Reward token mint."], "type": "publicKey" },
70+
{ "name": "vault", "docs": ["Reward vault token account."], "type": "publicKey" },
71+
{ "name": "authority", "docs": ["Authority account that has permission to initialize the reward and set emissions."], "type": "publicKey" },
72+
{ "name": "emissionsPerSecondX64", "docs": ["Q64.64 number that indicates how many tokens per second are earned."], "type": "u128" },
73+
{
74+
"name": "growthGlobalX64",
75+
"docs": ["Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward", "emissions were turned on."],
76+
"type": "u128"
77+
}
78+
]
79+
}
80+
}
81+
],
82+
"events": [],
83+
"errors": []
84+
}

0 commit comments

Comments
 (0)