Skip to content

Commit

Permalink
Merge pull request #11 from Abracadabra-money/test/reward-distributor
Browse files Browse the repository at this point in the history
test: Setup tests and add an example
  • Loading branch information
0xmDreamy authored Jul 26, 2024
2 parents ac05aa1 + 4fc9717 commit 2d012e4
Show file tree
Hide file tree
Showing 36 changed files with 1,016 additions and 629 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.lockb binary diff=lockb
3 changes: 3 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[diff "lockb"]
textconv = bun
binary = true
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ env:
ARBITRUM_PROVIDER_URL: https://1rpc.io/arb
OPTIMISM_PROVIDER_URL: https://endpoints.omniatech.io/v1/op/mainnet/public
MAINNET_PROVIDER_URL: https://eth.llamarpc.com
ARBITRUM_RPC_URL: ${{ secrets.ARBITRUM_RPC_URL }}
ZEROX_API_KEY: ${{ secrets.ZEROX_API_KEY }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: foundry-rs/foundry-toolchain@v1
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun install --frozen-lockfile
- run: bun run lint:ci
- run: bun run test
- run: bun run typecheck
- run: bun test
- run: bun run run-task
Binary file modified bun.lockb
Binary file not shown.
26 changes: 14 additions & 12 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import "@gelatonetwork/web3-functions-sdk/hardhat-plugin";
import "@nomiclabs/hardhat-ethers";
import "@foundry-rs/hardhat-anvil";

const PRIVATE_KEY = process.env.PRIVATE_KEY;
const PRIVATE_KEY =
process.env.PRIVATE_KEY ??
"0x0000000000000000000000000000000000000000000000000000000000000001";

const config = {
w3f: {
Expand All @@ -30,57 +32,57 @@ const config = {
launch: true,
chainId: 1,
forkUrl: "https://rpc.ankr.com/eth",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
ethereum: {
chainId: 1,
url: "https://rpc.ankr.com/eth",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
avalanche: {
url: "https://api.avax.network/ext/bc/C/rpc",
chainId: 43114,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
arbitrum: {
chainId: 42161,
url: "https://arb1.arbitrum.io/rpc",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
fantom: {
chainId: 250,
url: "https://rpc2.fantom.network",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
optimism: {
chainId: 10,
url: "https://mainnet.optimism.io",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
polygon: {
chainId: 137,
url: "https://rpc-mainnet.maticvigil.com",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
bsc: {
chainId: 56,
url: "https://bsc.publicnode.com",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
kava: {
chainId: 2222,
url: "https://kava-evm.publicnode.com",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
base: {
chainId: 8453,
url: "https://base.meowrpc.com",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
linea: {
chainId: 59144,
url: "https://rpc.linea.build",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
accounts: [PRIVATE_KEY],
},
},
// biome-ignore lint/complexity/noBannedTypes: Improve auto-completion
Expand Down
64 changes: 30 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"scripts": {
"build": "bun run clean && bun run install && npx tsc",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"lint": "biome check",
"lint:fix": "biome check --write",
"lint:ci": "biome ci",
"test": "concurrently \"bun:test:*(!test:[^:]+:)\"",
"run-task": "concurrently -m 1 \"bun:run-task:*(!run-task:[^:]+:)\"",
"create-task:gm": "hardhat run ./scripts/create-gm-task.ts --network ethereum",
"create-task:spell-staking": "killall -9 anvil; hardhat run ./scripts/create-spell-staking-task.ts --network anvil",
"create-task:magiclvl": "hardhat run ./scripts/create-magiclvl-task.ts --network anvil",
Expand All @@ -25,36 +26,31 @@
"create-task:velodrome-op-usdc": "hardhat run ./scripts/create-velodrome-op-usdc-task.ts --network anvil",
"create-task:magicape": "hardhat run ./scripts/create-magicape-task.ts --network anvil",
"create-task:xf33d": "hardhat run ./scripts/create-xf33d-task.ts --network anvil",
"test:spell-staking": "concurrently --kill-others-on-fail bun:test:spell-staking:*",
"test:spell-staking:mainnet": "hardhat w3f-run spell-staking --logs --network ethereum",
"test:spell-staking:avalanche": "hardhat w3f-run spell-staking --logs --network avalanche",
"test:spell-staking:arbitrum": "hardhat w3f-run spell-staking --logs --network arbitrum",
"test:spell-staking:fantom": "hardhat w3f-run spell-staking --logs --network fantom",
"test:gm": "concurrently --kill-others-on-fail -m 1 bun:test:gm:*",
"test:gm:gmarb": "cp web3-functions/gm/userArgs.gmarb.json web3-functions/gm/userArgs.json && hardhat w3f-run gm --logs --network arbitrum",
"test:gm:gmbtc": "cp web3-functions/gm/userArgs.gmbtc.json web3-functions/gm/userArgs.json && hardhat w3f-run gm --logs --network arbitrum",
"test:gm:gmeth": "cp web3-functions/gm/userArgs.gmeth.json web3-functions/gm/userArgs.json && hardhat w3f-run gm --logs --network arbitrum",
"test:gm:gmlink": "cp web3-functions/gm/userArgs.gmlink.json web3-functions/gm/userArgs.json && hardhat w3f-run gm --logs --network arbitrum",
"test:gm:gmsol": "cp web3-functions/gm/userArgs.gmsol.json web3-functions/gm/userArgs.json && hardhat w3f-run gm --logs --network arbitrum",
"test:magiclvl": "hardhat w3f-run magiclvl --logs --network bsc",
"test:process-locks": "concurrently --kill-others-on-fail -m 1 bun:test:process-locks:*",
"test:process-locks:arb-msr": "cp web3-functions/process-locks/userArgs.arb-msr.json web3-functions/process-locks/userArgs.json && hardhat w3f-run process-locks --logs --network arbitrum",
"test:process-locks:blast-founders": "cp web3-functions/process-locks/userArgs.blast-founders.json web3-functions/process-locks/userArgs.json && hardhat w3f-run process-locks --logs --network arbitrum",
"test:spell-swapper": "hardhat w3f-run spell-swapper --logs --network ethereum",
"test:negative-interests": "concurrently --kill-others-on-fail -m 1 bun:test:negative-interests:*",
"test:negative-interests:crv": "cp web3-functions/negative-interests/userArgs.crv.json web3-functions/negative-interests/userArgs.json; hardhat w3f-run negative-interests --logs --network ethereum; rm web3-functions/negative-interests/userArgs.json",
"test:negative-interests:default": "cp web3-functions/negative-interests/userArgs.default.json web3-functions/negative-interests/userArgs.json; hardhat w3f-run negative-interests --logs --network ethereum; rm web3-functions/negative-interests/userArgs.json",
"test:reward-distributor": "hardhat w3f-run reward-distributor --logs --network arbitrum",
"test:stargate-v1": "hardhat w3f-run stargate-v1 --logs --network ethereum",
"test:stargate-v2-kava": "cp web3-functions/stargate-v2/userArgs.kava.json web3-functions/stargate-v2/userArgs.json; hardhat w3f-run stargate-v2 --logs --network kava; rm web3-functions/stargate-v2/userArgs.json",
"test:magiccurvelp-kava": "cp web3-functions/magiccurvelp/userArgs.kava.json web3-functions/magiccurvelp/userArgs.json; hardhat w3f-run magiccurvelp --logs --network kava; rm web3-functions/magiccurvelp/userArgs.json",
"test:magicglp": "concurrently --kill-others-on-fail -m 1 bun:test:magicglp:*",
"test:magicglp:avalanche": "cp web3-functions/magicglp/userArgs.avalanche.json web3-functions/magicglp/userArgs.json; hardhat w3f-run magicglp --logs --network avalanche; rm web3-functions/magicglp/userArgs.json",
"test:magicglp:arbitrum": "cp web3-functions/magicglp/userArgs.arbitrum.json web3-functions/magicglp/userArgs.json; hardhat w3f-run magicglp --logs --network arbitrum; rm web3-functions/magicglp/userArgs.json",
"test:velodrome-op-usdc": "hardhat w3f-run velodrome-op-usdc --logs --network optimism",
"test:magicape": "hardhat w3f-run magicape --logs --network ethereum",
"test:xf33d": "hardhat w3f-run xf33d --logs --network arbitrum",
"prepare": "husky"
"run-task:spell-staking": "concurrently --kill-others-on-fail bun:run-task:spell-staking:*",
"run-task:spell-staking:mainnet": "hardhat w3f-run spell-staking --logs --network ethereum",
"run-task:spell-staking:avalanche": "hardhat w3f-run spell-staking --logs --network avalanche",
"run-task:spell-staking:arbitrum": "hardhat w3f-run spell-staking --logs --network arbitrum",
"run-task:spell-staking:fantom": "hardhat w3f-run spell-staking --logs --network fantom",
"run-task:gm": "hardhat w3f-run gm --logs --network arbitrum",
"run-task:magiclvl": "hardhat w3f-run magiclvl --logs --network bsc",
"run-task:process-locks": "concurrently --kill-others-on-fail -m 1 bun:run-task:process-locks:*",
"run-task:process-locks:arb-msr": "cp web3-functions/process-locks/userArgs.arb-msr.json web3-functions/process-locks/userArgs.json && hardhat w3f-run process-locks --logs --network arbitrum",
"run-task:process-locks:blast-founders": "cp web3-functions/process-locks/userArgs.blast-founders.json web3-functions/process-locks/userArgs.json && hardhat w3f-run process-locks --logs --network arbitrum",
"run-task:spell-swapper": "hardhat w3f-run spell-swapper --logs --network ethereum",
"run-task:negative-interests": "concurrently --kill-others-on-fail -m 1 bun:run-task:negative-interests:*",
"run-task:negative-interests:crv": "cp web3-functions/negative-interests/userArgs.crv.json web3-functions/negative-interests/userArgs.json; hardhat w3f-run negative-interests --logs --network ethereum; rm web3-functions/negative-interests/userArgs.json",
"run-task:negative-interests:default": "cp web3-functions/negative-interests/userArgs.default.json web3-functions/negative-interests/userArgs.json; hardhat w3f-run negative-interests --logs --network ethereum; rm web3-functions/negative-interests/userArgs.json",
"run-task:reward-distributor": "hardhat w3f-run reward-distributor --logs --network arbitrum",
"run-task:stargate-v1": "hardhat w3f-run stargate-v1 --logs --network ethereum",
"run-task:stargate-v2-kava": "cp web3-functions/stargate-v2/userArgs.kava.json web3-functions/stargate-v2/userArgs.json; hardhat w3f-run stargate-v2 --logs --network kava; rm web3-functions/stargate-v2/userArgs.json",
"run-task:magiccurvelp-kava": "cp web3-functions/magiccurvelp/userArgs.kava.json web3-functions/magiccurvelp/userArgs.json; hardhat w3f-run magiccurvelp --logs --network kava; rm web3-functions/magiccurvelp/userArgs.json",
"run-task:magicglp": "concurrently --kill-others-on-fail -m 1 bun:run-task:magicglp:*",
"run-task:magicglp:avalanche": "cp web3-functions/magicglp/userArgs.avalanche.json web3-functions/magicglp/userArgs.json; hardhat w3f-run magicglp --logs --network avalanche; rm web3-functions/magicglp/userArgs.json",
"run-task:magicglp:arbitrum": "cp web3-functions/magicglp/userArgs.arbitrum.json web3-functions/magicglp/userArgs.json; hardhat w3f-run magicglp --logs --network arbitrum; rm web3-functions/magicglp/userArgs.json",
"run-task:velodrome-op-usdc": "hardhat w3f-run velodrome-op-usdc --logs --network optimism",
"run-task:magicape": "hardhat w3f-run magicape --logs --network ethereum",
"run-task:xf33d": "hardhat w3f-run xf33d --logs --network arbitrum",
"prepare": "husky && git config --local include.path ../.gitconfig"
},
"license": "ISC",
"lint-staged": {
Expand All @@ -64,18 +60,19 @@
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@foundry-rs/easy-foundryup": "^0.1.3",
"@foundry-rs/hardhat-anvil": "^0.1.7",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@tsconfig/recommended": "^1.0.7",
"@types/bun": "latest",
"@viem/anvil": "^0.0.10",
"concurrently": "^8.2.2",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.7.2",
"hardhat": "^2.22.6",
"husky": "^9.1.1",
"lint-staged": "^15.2.7",
"ts-node": "10.9.2",
"type-fest": "^4.23.0",
"typescript": "5.5.3"
},
"dependencies": {
Expand All @@ -84,14 +81,13 @@
"@urql/core": "^5.0.4",
"ky": "^1.4.0",
"remeda": "^2.6.0",
"viem": "^2.17.9"
"viem": "^2.18.0"
},
"trustedDependencies": [
"@biomejs/biome",
"bufferutil",
"core-js",
"core-js-pure",
"cpu-features",
"deno-bin",
"es5-ext",
"esbuild",
Expand Down
12 changes: 4 additions & 8 deletions scripts/create-gm-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type Web3FunctionUserArgs,
} from "@gelatonetwork/automate-sdk";
import hre from "hardhat";
import { DEVOPS_SAFE } from "../utils/constants";

const { ethers, w3f } = hre;

Expand Down Expand Up @@ -102,15 +103,10 @@ const main = async () => {
] satisfies Partial<CreateBatchExecTaskOptions>[];

for (const config of configs) {
const task = await automate.prepareBatchExecTask(
config,
{},
"0x48c18844530c96AaCf24568fa7F912846aAc12B9",
);
const { tx } = await automate.prepareBatchExecTask(config, {}, DEVOPS_SAFE);
console.log(config.name);
console.log(`to: ${task.tx.to}`);
const data = task.tx.data;
console.log(data);
console.log(`to: ${tx.to}`);
console.log(tx.data);
console.log("------------------");
console.log();
}
Expand Down
33 changes: 20 additions & 13 deletions scripts/create-magicape-task.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { AutomateSDK } from "@gelatonetwork/automate-sdk";
import { AutomateSDK, TriggerType } from "@gelatonetwork/automate-sdk";
import hre from "hardhat";
import { DEVOPS_SAFE } from "../utils/constants";

const TEN_MINUTES_MILLIS = 10 * 60 * 1000;

const { ethers, w3f } = hre;

Expand All @@ -18,20 +21,24 @@ const main = async () => {

{
console.log("Creating Task");
const task = await automate.createBatchExecTask({
name: "MagicAPE",
web3FunctionHash: cid,
web3FunctionArgs: {
execAddress: "0x598330D0F504297f53799e37CfF80ed564eB3525",
intervalInSeconds: 604800,
const { tx } = await automate.prepareBatchExecTask(
{
name: "MagicAPE",
web3FunctionHash: cid,
trigger: {
type: TriggerType.TIME,
interval: TEN_MINUTES_MILLIS,
},
web3FunctionArgs: {
execAddress: "0x598330D0F504297f53799e37CfF80ed564eB3525",
intervalInSeconds: 604800,
},
},
});
console.log(`to: ${task.tx.to}`);
const data = task.tx.data.replace(
"9a688cc56f5f4fc75eaf8fdf18f43260ae43647c",
"4D0c7842cD6a04f8EDB39883Db7817160DA159C3",
{},
DEVOPS_SAFE,
);
console.log(data);
console.log(`to: ${tx.to}`);
console.log(tx.data);
console.log("------------------");
console.log();
}
Expand Down
44 changes: 26 additions & 18 deletions scripts/create-magiccurvelp-task.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { AutomateSDK } from "@gelatonetwork/automate-sdk";
import { AutomateSDK, TriggerType } from "@gelatonetwork/automate-sdk";
import hre from "hardhat";
import { DEVOPS_SAFE } from "../utils/constants";

const TEN_MINUTES_MILLIS = 10 * 60 * 1000;

const { ethers, w3f } = hre;

Expand All @@ -18,25 +21,30 @@ const main = async () => {

{
console.log("Creating Kava MagicCurveLP MIM/USDT Task");
const task = await automate.createBatchExecTask({
name: "",
web3FunctionHash: cid,
web3FunctionArgs: {
execAddress: "",
vaultAddress: "",
swapRewardToTokenAddress: "0x919c1c267bc06a7039e03fcc2ef738525769109c", // USDT
curveLensAddress: "0x5552b631e2ad801faa129aacf4b701071cc9d1f7",
minRequiredLpAmount: "100000000000000000000", // 100 lp min
intervalInSeconds: 86400,
swapRewardsSlippageBips: 100, // wKAVA -> USDT 1% slippage
const { tx } = await automate.prepareBatchExecTask(
{
name: "",
web3FunctionHash: cid,
trigger: {
type: TriggerType.TIME,
interval: TEN_MINUTES_MILLIS,
},
web3FunctionArgs: {
execAddress: "",
vaultAddress: "",
swapRewardToTokenAddress:
"0x919c1c267bc06a7039e03fcc2ef738525769109c", // USDT
curveLensAddress: "0x5552b631e2ad801faa129aacf4b701071cc9d1f7",
minRequiredLpAmount: "100000000000000000000", // 100 lp min
intervalInSeconds: 86400,
swapRewardsSlippageBips: 100, // wKAVA -> USDT 1% slippage
},
},
});
console.log(`to: ${task.tx.to}`);
const data = task.tx.data.replace(
"9a688cc56f5f4fc75eaf8fdf18f43260ae43647c",
"4D0c7842cD6a04f8EDB39883Db7817160DA159C3",
{},
DEVOPS_SAFE,
);
console.log(data);
console.log(`to: ${tx.to}`);
console.log(tx.data);
console.log("------------------");
console.log();
}
Expand Down
Loading

0 comments on commit 2d012e4

Please sign in to comment.