Skip to content
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
13 changes: 13 additions & 0 deletions adapters/fluid/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const abi = {
factoryAbi: {
LogVestingStarted: "event LogVestingStarted(address indexed recipient, address indexed vesting, address owner, uint256 amount)",
},
vestingContractAbi: {
vestingBegin: "function vestingBegin() external view returns (uint32)",
vestingCliff: "function vestingCliff() external view returns (uint32)",
vestingEnd: "function vestingEnd() external view returns (uint32)",
vestingAmount: "function vestingAmount() external view returns (uint256)"
}
};

export default abi;
71 changes: 71 additions & 0 deletions adapters/fluid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { getLogs, lookupBlock } from "@defillama/sdk/build/util";
import { multiCall } from "@defillama/sdk/build/abi/abi2";
import abi from "./abi";
import { LinearAdapterResult } from "../../types/adapters";

const FACTORY_ADDRESS = "0x3b05a5295Aa749D78858E33ECe3b97bB3Ef4F029";
const FLUID_TOKEN = "0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb";

export default async function adapter(): Promise<LinearAdapterResult[]> {
const logs = await getLogs({
target: FACTORY_ADDRESS,
topic: "0x4ac20a376998e094ddc7f2886aacc04793f0967d837b03bcfea523a8f27f2485",
topics: [],
fromBlock: 12602043,
toBlock: 12782627,
keys: [],
chain: "ethereum",
});


const vestingContracts: { vesting: string; amount: number }[] = [];
logs.output.map((log: any) => {
if (log.topics[0] !== "0x4ac20a376998e094ddc7f2886aacc04793f0967d837b03bcfea523a8f27f2485") {
return;
}
vestingContracts.push({
vesting: `0x${log.topics[2].substring(26)}`,
amount: log.data / 1e18
});
});

const [beginTimes, cliffTimes, endTimes, amounts] = await Promise.all([
multiCall({
calls: vestingContracts.map(v => ({
target: v.vesting
})),
abi: abi.vestingContractAbi.vestingBegin,
chain: "ethereum"
}),
multiCall({
calls: vestingContracts.map(v => ({
target: v.vesting
})),
abi: abi.vestingContractAbi.vestingCliff,
chain: "ethereum"
}),
multiCall({
calls: vestingContracts.map(v => ({
target: v.vesting
})),
abi: abi.vestingContractAbi.vestingEnd,
chain: "ethereum"
}),
multiCall({
calls: vestingContracts.map(v => ({
target: v.vesting
})),
abi: abi.vestingContractAbi.vestingAmount,
chain: "ethereum"
})
]);

return vestingContracts.map((_, i) => ({
type: "linear" as const,
token: FLUID_TOKEN,
start: Number(beginTimes[i]),
end: Number(endTimes[i]),
cliff: Number(cliffTimes[i]),
amount: Number(amounts[i]) / 1e18
}));
}
87 changes: 87 additions & 0 deletions adapters/pancakeswap/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const abi = {
cakeRateToRegularFarm: {
inputs: [],
name: "cakeRateToRegularFarm",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
cakeRateToSpecialFarm: {
inputs: [],
name: "cakeRateToSpecialFarm",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
MASTERCHEF_CAKE_PER_BLOCK: {
inputs: [],
name: "MASTERCHEF_CAKE_PER_BLOCK",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
CAKE_RATE_TOTAL_PRECISION: {
inputs: [],
name: "CAKE_RATE_TOTAL_PRECISION",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
poolLength: {
inputs: [],
name: "poolLength",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
cakePerBlock: {
inputs: [{ name: "_isRegular", type: "bool" }],
name: "cakePerBlock",
outputs: [{ name: "amount", type: "uint256" }],
stateMutability: "view",
type: "function"
},
totalRegularAllocPoint: {
inputs: [],
name: "totalRegularAllocPoint",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
totalSpecialAllocPoint: {
inputs: [],
name: "totalSpecialAllocPoint",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
// Pool info
poolInfo: {
inputs: [{ name: "", type: "uint256" }],
name: "poolInfo",
outputs: [
{ name: "accCakePerShare", type: "uint256" },
{ name: "lastRewardBlock", type: "uint256" },
{ name: "allocPoint", type: "uint256" },
{ name: "totalBoostedShare", type: "uint256" },
{ name: "isRegular", type: "bool" }
],
stateMutability: "view",
type: "function"
},
lpToken: {
inputs: [{ name: "", type: "uint256" }],
name: "lpToken",
outputs: [{ name: "", type: "address" }],
stateMutability: "view",
type: "function"
}
};

const CONSTANTS = {
MASTERCHEF_CAKE_PER_BLOCK: "40000000000000000000", // 40 CAKE per block
CAKE_RATE_TOTAL_PRECISION: "1000000000000"
};

export default abi;
export { CONSTANTS };
6 changes: 6 additions & 0 deletions adapters/pancakeswap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import adapter from "./masterchef";

const MASTERCHEF_V2 = "0xa5f8C5Dbd5F286960b9d90548680aE5ebFf07652";

export const pancakeRegular = adapter(MASTERCHEF_V2, "bsc", true);
export const pancakeSpecial = adapter(MASTERCHEF_V2, "bsc", false);
111 changes: 111 additions & 0 deletions adapters/pancakeswap/masterchef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { call, multiCall } from "@defillama/sdk/build/abi/abi2";
import { AdapterResult } from "../../types/adapters";
import abi, { CONSTANTS } from "./abi";

const BLOCKS_PER_DAY = 28800; // approximate number of blocks per day (assuming 3s block time)
const ONE_YEAR = 365 * 24 * 60 * 60;
const DECIMALS = 18;
const CAKE_TOKEN = "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82";

export default function adapter(target: string, chain: string, isRegular: boolean) {
return async function calculateEmissions(): Promise<AdapterResult[]> {
try {
const poolLength = await call({
target,
abi: abi.poolLength,
chain,
});

const [cakeRateToRegularFarm, cakeRateToSpecialFarm, masterPerBlock, ratePrecision, totalAlloc] = await Promise.all([
call({
target,
abi: abi.cakeRateToRegularFarm,
chain,
}),
call({
target,
abi: abi.cakeRateToSpecialFarm,
chain,
}),
call({
target,
abi: abi.MASTERCHEF_CAKE_PER_BLOCK,
chain,
}).catch(() => CONSTANTS.MASTERCHEF_CAKE_PER_BLOCK),
call({
target,
abi: abi.CAKE_RATE_TOTAL_PRECISION,
chain,
}).catch(() => CONSTANTS.CAKE_RATE_TOTAL_PRECISION),
call({
target,
abi: isRegular ? abi.totalRegularAllocPoint : abi.totalSpecialAllocPoint,
chain,
}),
]);

const netEmissionRate = BigInt(masterPerBlock) *
BigInt(isRegular ? cakeRateToRegularFarm : cakeRateToSpecialFarm) /
BigInt(ratePrecision);

const poolIndexes = Array.from({ length: Number(poolLength) }, (_, i) => i);

const [poolInfos, lpTokens] = await Promise.all([
multiCall({
calls: poolIndexes.map(pid => ({
target,
params: [pid],
})),
abi: abi.poolInfo,
chain,
permitFailure: true,
}),
multiCall({
calls: poolIndexes.map(pid => ({
target,
params: [pid],
})),
abi: abi.lpToken,
chain,
permitFailure: true,
}),
]);

const results: AdapterResult[] = [];
const now = Math.floor(Date.now() / 1000);

for (let pid = 0; pid < poolLength; pid++) {
const poolInfo = poolInfos[pid];
const lpToken = lpTokens[pid];

if (!poolInfo || !lpToken) continue;
if (poolInfo.allocPoint === "0") continue;
if (poolInfo.isRegular !== isRegular) continue;

if (BigInt(totalAlloc) === BigInt(0)) continue;

const poolEmissionWei = BigInt(poolInfo.allocPoint) *
BigInt(BLOCKS_PER_DAY) *
netEmissionRate /
BigInt(totalAlloc);

const dailyEmission = Number(poolEmissionWei) / (10 ** DECIMALS);
const yearlyEmission = dailyEmission * 365;

results.push({
type: "linear",
start: now,
end: now + ONE_YEAR,
amount: yearlyEmission,
receiver: lpToken,
token: CAKE_TOKEN
});
}

return results;

} catch (error) {
throw new Error(`Failed to fetch PancakeSwap ${isRegular ? "regular" : "special"} emissions: ${error}`);
}
};
}
55 changes: 55 additions & 0 deletions adapters/rocketpool/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export default {
getAddress: {
"inputs": [{"type": "bytes32"}],
"name": "getAddress",
"outputs": [{"type": "address"}],
"stateMutability": "view",
"type": "function"
},
getRewardsClaimersPerc: {
"inputs": [],
"name": "getRewardsClaimersPerc",
"outputs": [
{ "name": "trustedNodePerc", "type": "uint256" },
{ "name": "protocolPerc", "type": "uint256" },
{ "name": "nodePerc", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
getInflationIntervalRate: {
"inputs": [],
"name": "getInflationIntervalRate",
"outputs": [{ "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
getInflationIntervalStartTime: {
"inputs": [],
"name": "getInflationIntervalStartTime",
"outputs": [{ "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
getInflationIntervalTime: {
"inputs": [],
"name": "getInflationIntervalTime",
"outputs": [{ "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
totalSupply: {
"inputs": [],
"name": "totalSupply",
"outputs": [{ "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
getInflationCalcTime: {
"inputs": [],
"name": "getInflationCalcTime",
"outputs": [{ "type": "uint256" }],
"stateMutability": "view",
"type": "function"
}
}
Loading
Loading