Skip to content

Commit

Permalink
feat: rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm committed Dec 13, 2024
1 parent 5a40e4e commit b8a08fc
Show file tree
Hide file tree
Showing 25 changed files with 8,998 additions and 62 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HardhatUserConfig } from "hardhat/config";
import { config as dotenv } from "dotenv";

import "./tasks";
import { base, fraxtal, mode } from "viem/chains";

dotenv();

Expand All @@ -21,8 +22,9 @@ const config: HardhatUserConfig = {
namedAccounts: {
deployer: { default: 0 },
multisig: {
34443: "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2",
8453: "0x9eC25b8063De13d478Ba8121b964A339A1BB0ebB"
[mode.id]: "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2",
[base.id]: "0x9eC25b8063De13d478Ba8121b964A339A1BB0ebB",
[fraxtal.id]: "0xf8Ec79Ac74b16242d17cC7258250fA3317E3C1b2"
}
},
solidity: {
Expand Down
69 changes: 67 additions & 2 deletions packages/contracts/tasks/chain-specific/base/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import {
wusdm_MARKET,
wusdPlus_MARKET
} from ".";
import { Address, parseEther } from "viem";
import { Address, formatEther, parseEther } from "viem";
import { setupRewards } from "../../flywheel/setup";
import { BORROW_DURATION, SUPPLY_DURATION } from "..";
import { getCycleInfoForAllMarkets } from "../../flywheel/rewards";
import { getCycleInfoForAllMarkets, sendRewardsToMarkets } from "../../flywheel/rewards";

task("base:add-rewards:epoch1:supply", "add rewards to a market").setAction(
async (_, { viem, deployments, getNamedAccounts }) => {
Expand Down Expand Up @@ -626,3 +626,68 @@ task("flywheel:get_cycle_info:supply:base", "get cycle info from flywheel").setA
await getCycleInfoForAllMarkets(viem, COMPTROLLER, flywheelRewards.address as Address);
}
);

task("base:send-ion:epoch6", "send ion to a market").setAction(async (_, { viem, deployments, getNamedAccounts }) => {
const { deployer } = await getNamedAccounts();

const rewardsToSend: { market: Address; amount: string }[] = [
{
market: eUSD_MARKET,
amount: "25000"
},
{
market: bsdETH_MARKET,
amount: "25000"
},
{
market: hyUSD_MARKET,
amount: "25000"
},
{
market: WETH_MARKET,
amount: "50000"
},
{
market: weETH_MARKET,
amount: "25000"
},
{
market: AERO_MARKET,
amount: "7500"
},
{
market: cbETH_MARKET,
amount: "5000"
},
{
market: wusdm_MARKET,
amount: "5000"
},
{
market: USDz_MARKET,
amount: "10000"
},
{
market: wusdPlus_MARKET,
amount: "10000"
},
{
market: uSOL_MARKET,
amount: "5000"
},
{
market: uSUI_MARKET,
amount: "5000"
},
{
market: sUSDz_MARKET,
amount: "5000"
},
{
market: cbBTC_MARKET,
amount: "5000"
}
];

await sendRewardsToMarkets(viem, ION, rewardsToSend, deployer as Address);
});
5 changes: 5 additions & 0 deletions packages/contracts/tasks/chain-specific/fraxtal/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import "./pool";
import "./markets";
import "./rewards";

export const COMPTROLLER = "0xB5141403e811fFFE02f4d49Ea8d4a7B0b9590658";

export const ION = "0x5BD5c0cB9E4404C63526433BcBd6d133C1d73ffE";
export const FRAX_MARKET = "0x7Cc4253DD910bE388A1417c87755C593a4b3bcf1";
export const sfrxETH_MARKET = "0xE79A3131D93F135E3957D81B7f73730157e1D3E4";
48 changes: 48 additions & 0 deletions packages/contracts/tasks/chain-specific/fraxtal/rewards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Address } from "viem";

import { task } from "hardhat/config";
import { FRAX_MARKET, ION, sfrxETH_MARKET } from ".";
import { parseEther } from "viem";
import { BORROW_DURATION } from "..";
import { setupRewards } from "../../flywheel/setup";

task("fraxtal:add-rewards:epoch5:borrow", "add rewards to a market").setAction(
async (_, { viem, deployments, getNamedAccounts }) => {
const { deployer, multisig } = await getNamedAccounts();
const rewardToken = ION;
const rewardTokenName = "ION";
const market = sfrxETH_MARKET;
const _market = await viem.getContractAt("EIP20Interface", market);
const name = await _market.read.name();

const rewardAmount = (10_000).toString();

console.log("setting rewards for token: ", name, rewardAmount);
await new Promise((resolve) => setTimeout(resolve, 4000));

// Sending tokens
const _rewardToken = await viem.getContractAt("EIP20Interface", rewardToken);
let balance = await _rewardToken.read.balanceOf([market]);
console.log("balance: ", balance);
if (balance < parseEther(rewardAmount)) {
const tx = await _rewardToken.write.transfer([market, parseEther(rewardAmount) - balance]);
console.log(`Sent ${rewardAmount} ${rewardTokenName} to ${market} - ${tx}`);
} else {
console.log(`Market already has enough ${rewardTokenName} - ${market}`);
}

await setupRewards(
"borrow",
market,
rewardTokenName,
rewardToken,
BORROW_DURATION,
deployer as Address,
viem,
deployments,
multisig as Address,
"IonicFlywheelBorrow_Borrow_ION_epoch5",
"IonicFlywheelDynamicRewards_Borrow_ION_epoch5"
);
}
);
43 changes: 42 additions & 1 deletion packages/contracts/tasks/chain-specific/optimism/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, parseEther } from "viem";

import { ION, SNX_MARKET, USDC_MARKET, weETH_MARKET, WETH_MARKET, wUSDM_MARKET } from ".";
import { setupRewards } from "../../flywheel/setup";
import { SUPPLY_DURATION } from "..";
import { BORROW_DURATION, SUPPLY_DURATION } from "..";

task("optimism:add-rewards:supply:epoch4", "add rewards to a market").setAction(
async (_, { viem, deployments, getNamedAccounts }) => {
Expand Down Expand Up @@ -87,6 +87,47 @@ task("optimism:add-rewards:supply:epoch5", "add rewards to a market").setAction(
}
);

task("optimism:add-rewards:epoch5:borrow", "add rewards to a market").setAction(
async (_, { viem, deployments, getNamedAccounts }) => {
const { deployer, multisig } = await getNamedAccounts();
const rewardToken = ION;
const rewardTokenName = "ION";
const market = weETH_MARKET;
const _market = await viem.getContractAt("EIP20Interface", market);
const name = await _market.read.name();

const rewardAmount = (2_500).toString();

console.log("setting rewards for token: ", name, rewardAmount);
await new Promise((resolve) => setTimeout(resolve, 4000));

// Sending tokens
const _rewardToken = await viem.getContractAt("EIP20Interface", rewardToken);
let balance = await _rewardToken.read.balanceOf([market]);
console.log("balance: ", balance);
if (balance < parseEther(rewardAmount)) {
const tx = await _rewardToken.write.transfer([market, parseEther(rewardAmount) - balance]);
console.log(`Sent ${rewardAmount} ${rewardTokenName} to ${market} - ${tx}`);
} else {
console.log(`Market already has enough ${rewardTokenName} - ${market}`);
}

await setupRewards(
"borrow",
market,
rewardTokenName,
rewardToken,
BORROW_DURATION,
deployer as Address,
viem,
deployments,
multisig as Address,
"IonicFlywheelBorrow_Borrow_ION_epoch5",
"IonicFlywheelDynamicRewards_Borrow_ION_epoch5"
);
}
);

task("optimism:add-rewards:supply:epoch5", "add rewards to a market").setAction(
async (_, { viem, deployments, getNamedAccounts }) => {
const { deployer, multisig } = await getNamedAccounts();
Expand Down
34 changes: 33 additions & 1 deletion packages/contracts/tasks/flywheel/rewards.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Address } from "viem";
import { Address, formatEther, parseEther } from "viem";

export const getCycleInfoForAllMarkets = async (
viem: HardhatRuntimeEnvironment["viem"],
Expand All @@ -18,3 +18,35 @@ export const getCycleInfoForAllMarkets = async (
}
}
};

export const sendRewardsToMarkets = async (
viem: HardhatRuntimeEnvironment["viem"],
rewardToken: Address,
rewardsToSend: { market: Address; amount: string }[],
deployer: Address
) => {
const publicClient = await viem.getPublicClient();
const rewardContract = await viem.getContractAt("EIP20Interface", rewardToken);
const totalNeeded = rewardsToSend.reduce((acc, reward) => acc + parseInt(reward.amount), 0);
console.log("🚀 ~ task ~ totalNeeded:", totalNeeded);
const balance = await rewardContract.read.balanceOf([deployer as Address]);
if (balance < parseEther(totalNeeded.toString())) {
throw new Error(
`Not enough ${rewardToken} to send to all markets, needed ${totalNeeded}, balance is ${formatEther(balance)}`
);
}

for (const reward of rewardsToSend) {
const market = reward.market as Address;
const amount = reward.amount;
const balance = await rewardContract.read.balanceOf([market]);
console.log(`balance of ${rewardToken} on ${market}: ${formatEther(balance)}`);
if (balance < parseEther(amount)) {
const tx = await rewardContract.write.transfer([market, parseEther(amount) - balance]);
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`Sent ${amount} ${rewardToken} to ${market} - ${tx}`);
} else {
console.log(`Market already has enough ${rewardToken} - ${market}`);
}
}
};
15 changes: 15 additions & 0 deletions packages/sdk/deployments/fraxtal.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@
"GlobalPauser": {
"address": "0x50766FD9C93e65124f0160C8f301caC6f399B572"
},
"IonicFlywheelBorrowBooster_ION": {
"address": "0x63A1531a06F0Ac597a0DfA5A516a37073c3E1e0a"
},
"IonicFlywheelBorrow_Borrow_ION_epoch5": {
"address": "0xf3E5172A9d701F3E5d98A1A846Eec7CC205A10dF"
},
"IonicFlywheelBorrow_Borrow_ION_epoch5_Implementation": {
"address": "0x6576d9e96237921cf1C4529Ee6Cea2C3ef64Ff75"
},
"IonicFlywheelBorrow_Borrow_ION_epoch5_Proxy": {
"address": "0xf3E5172A9d701F3E5d98A1A846Eec7CC205A10dF"
},
"IonicFlywheelDynamicRewards_Borrow_ION_epoch5": {
"address": "0x2F7844aE39013A3E2770494f74067c184974f397"
},
"IonicFlywheelLensRouter": {
"address": "0x7AABEfD7d8d2576Dc932EbE97bE8Ba90299a4ee4"
},
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk/deployments/optimism.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
"GlobalPauser": {
"address": "0xAD310a60005EAB54137f7EFBf0Acc521f0A8eBbb"
},
"IonicFlywheelBorrowBooster_ION": {
"address": "0x51A022B23bFE99A4C50B94E9AffF3bBa7fa1bdE7"
},
"IonicFlywheelBorrow_Borrow_ION_epoch5": {
"address": "0x6660174886cb3B26B38E5D4c1324E0BfB361F7CA"
},
"IonicFlywheelBorrow_Borrow_ION_epoch5_Implementation": {
"address": "0x6e93f617AB6CEfFec7c276B4fD4c136B7A7aDD54"
},
"IonicFlywheelBorrow_Borrow_ION_epoch5_Proxy": {
"address": "0x6660174886cb3B26B38E5D4c1324E0BfB361F7CA"
},
"IonicFlywheelDynamicRewards_Borrow_ION_epoch5": {
"address": "0xfdC02d776547F0DEC6c91F7eb0219112630430e3"
},
"IonicFlywheelDynamicRewards_ION_epoch4": {
"address": "0xAE8D590B31c3De396B8B97a27A2039Bbd1fc2B35"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/_components/dialogs/loop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
parseEther,
parseUnits
} from 'viem';
import { useBalance, useChainId } from 'wagmi';
import { useBalance, useChainId, usePublicClient } from 'wagmi';

import {
Dialog,
Expand Down Expand Up @@ -67,6 +67,7 @@ export default function Loop({
}: LoopProps) {
const chainId = useChainId();
const [amount, setAmount] = useState<string>();
const publicClient = usePublicClient();
const amountAsBInt = useMemo<bigint>(
() => parseUnits(amount ?? '0', selectedCollateralAsset.underlyingDecimals),
[amount, selectedCollateralAsset]
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const REWARDS_TO_SYMBOL: Record<number, Record<Address, string>> = {
[lisk.id]: {
'0x3f608A49a3ab475dA7fBb167C1Be6b7a45cD7013': 'ION',
'0xac485391EB2d7D88253a7F1eF18C37f4242D1A24': 'LSK'
},
[fraxtal.id]: {
'0x5BD5c0cB9E4404C63526433BcBd6d133C1d73ffE': 'ION'
}
};

Expand Down Expand Up @@ -131,14 +134,18 @@ export const FLYWHEEL_TYPE_MAP: Record<
'0x4D01bb5710F1989b6C2Dde496a5400E7F3b88162',
'0x05c3e910F7639457f92220605966e7f86A2ef966'
],
borrow: []
borrow: ['0x6660174886cb3B26B38E5D4c1324E0BfB361F7CA']
},
[lisk.id]: {
supply: [
'0x523F183ECbBf9144403D937B444d8486aD752453',
'0x8A48245Db7D3572AD118D41b2F7dFf0aaBEF37A7'
],
borrow: []
},
[fraxtal.id]: {
supply: [],
borrow: ['0x63A1531a06F0Ac597a0DfA5A516a37073c3E1e0a']
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"lucide-react": "^0.454.0",
"mathjs": "^13.2.0",
"millify": "^6.1.0",
"next": "^15.0.3",
"next": "^15.1.0",
"next-nprogress-bar": "^2.3.12",
"nextjs-progressbar": "^0.0.16",
"react": "19.0.0-rc.1",
Expand Down
Loading

0 comments on commit b8a08fc

Please sign in to comment.