Skip to content
Open
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
12 changes: 6 additions & 6 deletions Hardhat.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unset DEFENDER_API_KEY
unset DEFENDER_API_SECRET
export IMPERSONATE=0x39878253374355DBcc15C86458F084fb6f2d6DE7
export DEBUG=origin*
npx hardhat requestWithdraw --amount 300 --network local
yarn hardhat requestWithdraw --amount 300 --network local
```

3. Create a Relayer API key
Expand All @@ -30,15 +30,15 @@ unset IMPERSONATE
export DEFENDER_API_KEY=
export DEFENDER_API_SECRET=
export DEBUG=origin*
npx hardhat requestWithdraw --amount 300 --network mainnet
yarn hardhat requestWithdraw --amount 300 --network mainnet
```

5. Delete the Relayer API key

For more information, see the `requestWithdraw` help

```
npx hardhat requestWithdraw --help
yarn hardhat requestWithdraw --help
```

## Claim all claimable OETH withdraw requests
Expand All @@ -56,7 +56,7 @@ unset DEFENDER_API_KEY
unset DEFENDER_API_SECRET
export IMPERSONATE=0x39878253374355DBcc15C86458F084fb6f2d6DE7
export DEBUG=origin*
npx hardhat autoClaimWithdraw --network local
yarn hardhat autoClaimWithdraw --network local
```

3. Create a Relayer API key
Expand All @@ -70,13 +70,13 @@ unset IMPERSONATE
export DEFENDER_API_KEY=
export DEFENDER_API_SECRET=
export DEBUG=origin*
npx hardhat autoClaimWithdraw --network mainnet
yarn hardhat autoClaimWithdraw --network mainnet
```

5. Delete the Relayer API key

For more information, see the `autoClaimWithdraw` help

```
npx hardhat autoClaimWithdraw --help
yarn hardhat autoClaimWithdraw --help
```
80 changes: 37 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,61 +290,55 @@ The following will set the Defender Team API key and bundle the Actions code rea
```bash
cd ./src/js/actions

# Export the Defender Team API key. This is different to the Defender Relayer API key.
export API_KEY=
export API_SECRET=
# Set the DEFENDER_TEAM_KEY and DEFENDER_TEAM_SECRET env vars in the .env file

npx rollup -c
yarn rollup -c
```

The following will upload the different Action bundles to Defender.

```bash

# Set the DEBUG environment variable to oeth* for the Defender Action
npx hardhat setActionVars --id 93c010f9-05b5-460f-bd10-1205dd80a7c9
npx hardhat setActionVars --id 563d8d0c-17dc-46d3-8955-e4824864869f
npx hardhat setActionVars --id c010fb76-ea63-409d-9981-69322d27993a
npx hardhat setActionVars --id 127171fd-7b85-497e-8335-fd7907c08386
npx hardhat setActionVars --id 84b5f134-8351-4402-8f6a-fb4376034bc4
npx hardhat setActionVars --id ffcfc580-7b0a-42ed-a4f2-3f0a3add9779 --name ONEINCH_API_KEY # Don't forget to run `export ONEINCH_API_KEY=...` first!
npx hardhat setActionVars --id 32dbc67b-89f3-4856-8f3d-ad4dc5a09322
npx hardhat setActionVars --id 7a0cb2c9-11c2-41dd-bcd0-d7c2dbda6af6
npx hardhat setActionVars --id a9fc4c86-0506-4809-afbc-93b5e558cb68
npx hardhat setActionVars --id 12977d51-d107-45eb-ac20-45942009ab01
npx hardhat setActionVars --id 6ec46510-0b8e-48b4-a4c8-de759aad0ba4
npx hardhat setActionVars --id 6d148f26-54a6-4377-92f2-3148d572eea3 --name ONEINCH_API_KEY # Don't forget to run `export ONEINCH_API_KEY=...` first!
npx hardhat setActionVars --id acfbb7d6-5ea6-4ffc-a758-fa4b4f584dd1 # allocateLido
npx hardhat setActionVars --id 6e26641e-4132-4824-bb80-7c891fd31455 # collectEtherFiFees
npx hardhat setActionVars --id 002c2b0d-9522-4d5f-a340-9713ee43a1c3 # allocateEtherFi
npx hardhat setActionVars --id 062cfee1-c34e-43ae-beb0-de62bc668bbd # autoRequestEtherFiWithdraw
npx hardhat setActionVars --id 6c52f3a9-85d8-4c7f-8aee-90a95b13965c # autoClaimEtherFiWithdraw

# The Defender autotask client uses generic env var names so we'll set them first from the values in the .env file
export API_KEY=
export API_SECRET=
yarn hardhat setActionVars --id 93c010f9-05b5-460f-bd10-1205dd80a7c9
yarn hardhat setActionVars --id 563d8d0c-17dc-46d3-8955-e4824864869f
yarn hardhat setActionVars --id c010fb76-ea63-409d-9981-69322d27993a
yarn hardhat setActionVars --id 127171fd-7b85-497e-8335-fd7907c08386
yarn hardhat setActionVars --id 84b5f134-8351-4402-8f6a-fb4376034bc4
yarn hardhat setActionVars --id ffcfc580-7b0a-42ed-a4f2-3f0a3add9779 --name ONEINCH_API_KEY # Don't forget to run `export ONEINCH_API_KEY=...` first!
yarn hardhat setActionVars --id 32dbc67b-89f3-4856-8f3d-ad4dc5a09322
yarn hardhat setActionVars --id 7a0cb2c9-11c2-41dd-bcd0-d7c2dbda6af6
yarn hardhat setActionVars --id a9fc4c86-0506-4809-afbc-93b5e558cb68
yarn hardhat setActionVars --id 12977d51-d107-45eb-ac20-45942009ab01
yarn hardhat setActionVars --id 6ec46510-0b8e-48b4-a4c8-de759aad0ba4
yarn hardhat setActionVars --id 6d148f26-54a6-4377-92f2-3148d572eea3 --name ONEINCH_API_KEY # Don't forget to run `export ONEINCH_API_KEY=...` first!
yarn hardhat setActionVars --id acfbb7d6-5ea6-4ffc-a758-fa4b4f584dd1 # allocateLido
yarn hardhat setActionVars --id 6e26641e-4132-4824-bb80-7c891fd31455 # collectEtherFiFees
yarn hardhat setActionVars --id 002c2b0d-9522-4d5f-a340-9713ee43a1c3 # allocateEtherFi
yarn hardhat setActionVars --id 062cfee1-c34e-43ae-beb0-de62bc668bbd # autoRequestEtherFiWithdraw
yarn hardhat setActionVars --id 6c52f3a9-85d8-4c7f-8aee-90a95b13965c # autoClaimEtherFiWithdraw

# Mainnet
npx defender-autotask update-code 93c010f9-05b5-460f-bd10-1205dd80a7c9 ./dist/autoRequestWithdraw
npx defender-autotask update-code 563d8d0c-17dc-46d3-8955-e4824864869f ./dist/autoClaimWithdraw
npx defender-autotask update-code c010fb76-ea63-409d-9981-69322d27993a ./dist/autoRequestLidoWithdraw
npx defender-autotask update-code 127171fd-7b85-497e-8335-fd7907c08386 ./dist/autoClaimLidoWithdraw
npx defender-autotask update-code 84b5f134-8351-4402-8f6a-fb4376034bc4 ./dist/collectLidoFees
npx defender-autotask update-code ffcfc580-7b0a-42ed-a4f2-3f0a3add9779 ./dist/setPrices
npx defender-autotask update-code 32dbc67b-89f3-4856-8f3d-ad4dc5a09322 ./dist/collectFeesSonic
npx defender-autotask update-code 7a0cb2c9-11c2-41dd-bcd0-d7c2dbda6af6 ./dist/allocateSonic
npx defender-autotask update-code a9fc4c86-0506-4809-afbc-93b5e558cb68 ./dist/collectRewardsSonic
npx defender-autotask update-code 12977d51-d107-45eb-ac20-45942009ab01 ./dist/autoRequestWithdrawSonic
npx defender-autotask update-code 6ec46510-0b8e-48b4-a4c8-de759aad0ba4 ./dist/autoClaimWithdrawSonic
npx defender-autotask update-code 6d148f26-54a6-4377-92f2-3148d572eea3 ./dist/setOSSiloPriceAction
npx defender-autotask update-code acfbb7d6-5ea6-4ffc-a758-fa4b4f584dd1 ./dist/allocateLido
npx defender-autotask update-code 6e26641e-4132-4824-bb80-7c891fd31455 ./dist/collectEtherFiFees
npx defender-autotask update-code 002c2b0d-9522-4d5f-a340-9713ee43a1c3 ./dist/allocateEtherFi
npx defender-autotask update-code 062cfee1-c34e-43ae-beb0-de62bc668bbd ./dist/autoRequestEtherFiWithdraw
npx defender-autotask update-code 6c52f3a9-85d8-4c7f-8aee-90a95b13965c ./dist/autoClaimEtherFiWithdraw
yarn hardhat updateAction --id 93c010f9-05b5-460f-bd10-1205dd80a7c9 --file autoRequestWithdraw
yarn hardhat updateAction --id 563d8d0c-17dc-46d3-8955-e4824864869f --file autoClaimWithdraw
yarn hardhat updateAction --id c010fb76-ea63-409d-9981-69322d27993a --file autoRequestLidoWithdraw
yarn hardhat updateAction --id 127171fd-7b85-497e-8335-fd7907c08386 --file autoClaimLidoWithdraw
yarn hardhat updateAction --id 84b5f134-8351-4402-8f6a-fb4376034bc4 --file collectLidoFees
yarn hardhat updateAction --id ffcfc580-7b0a-42ed-a4f2-3f0a3add9779 --file setPrices
yarn hardhat updateAction --id 32dbc67b-89f3-4856-8f3d-ad4dc5a09322 --file collectFeesSonic
yarn hardhat updateAction --id 7a0cb2c9-11c2-41dd-bcd0-d7c2dbda6af6 --file allocateSonic
yarn hardhat updateAction --id a9fc4c86-0506-4809-afbc-93b5e558cb68 --file collectRewardsSonic
yarn hardhat updateAction --id 12977d51-d107-45eb-ac20-45942009ab01 --file autoRequestWithdrawSonic
yarn hardhat updateAction --id 6ec46510-0b8e-48b4-a4c8-de759aad0ba4 --file autoClaimWithdrawSonic
yarn hardhat updateAction --id 6d148f26-54a6-4377-92f2-3148d572eea3 --file setOSSiloPriceAction
yarn hardhat updateAction --id acfbb7d6-5ea6-4ffc-a758-fa4b4f584dd1 --file allocateLido
yarn hardhat updateAction --id 6e26641e-4132-4824-bb80-7c891fd31455 --file collectEtherFiFees
yarn hardhat updateAction --id 002c2b0d-9522-4d5f-a340-9713ee43a1c3 --file allocateEtherFi
yarn hardhat updateAction --id 062cfee1-c34e-43ae-beb0-de62bc668bbd --file autoRequestEtherFiWithdraw
yarn hardhat updateAction --id 6c52f3a9-85d8-4c7f-8aee-90a95b13965c --file autoClaimEtherFiWithdraw
```

`rollup` and `defender-autotask` can be installed globally to avoid the `npx` prefix.
`rollup` can be installed globally to avoid the `yarn` prefix.

The Defender Actions need to be under 5MB in size. The [rollup-plugin-visualizer](https://www.npmjs.com/package/rollup-plugin-visualizer) can be used to visualize the size of an Action's dependencies.
A `stats.html` file is generated in the`src/js/actions` folder that can be opened in a browser to see the size of the Action's dependencies.
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"@nomicfoundation/hardhat-ethers": "3.0.7",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@openzeppelin/defender-autotask-client": "^1.54.1",
"@openzeppelin/defender-sdk": "1.14.3",
"@openzeppelin/defender-sdk": "2.7.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
19 changes: 0 additions & 19 deletions src/js/tasks/autotask.js

This file was deleted.

51 changes: 45 additions & 6 deletions src/js/tasks/defender.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
require("dotenv").config();
const { AutotaskClient } = require("@openzeppelin/defender-autotask-client");
const path = require("path");
const fs = require("fs");
const JSZip = require("jszip");
const { Defender } = require("@openzeppelin/defender-sdk");

const log = require("../utils/logger")("task:defender");

const setActionVars = async ({ id, name }) => {
const getClient = () => {
log(`Used DEFENDER_TEAM_KEY ${process.env.DEFENDER_TEAM_KEY}`);
const creds = {
apiKey: process.env.DEFENDER_TEAM_KEY,
apiSecret: process.env.DEFENDER_TEAM_SECRET,
};
const client = new AutotaskClient(creds);
return new Defender(creds);
};

const setActionVars = async ({ id, name }) => {
const client = getClient();

const envVars = {};
if (name) {
envVars[name] = process.env[name];
}

// Update Variables
const variables = await client.updateEnvironmentVariables(id, {
...envVars,
DEBUG: "origin*",
const variables = await client.action.updateEnvironmentVariables(id, {
variables: {
...envVars,
DEBUG: "origin*",
},
});
console.log("Updated Defender Actions environment variables to:", variables);
};

const updateAction = async ({ id, file }) => {
const client = getClient();

// Read and zip the code
const distPath = path.join(process.cwd(), `src/js/actions/dist/${file}`);
const zip = new JSZip();
const files = fs.readdirSync(distPath, { recursive: true });
files.forEach((file) => {
const filePath = path.join(distPath, file);
const relativePath = path.relative(distPath, filePath);
const content = fs.readFileSync(filePath);
zip.file(relativePath, content);
});
const encodedZippedCode =
await client.action.getEncodedZippedCodeFromFolder(distPath); // SDK helper to base64-encode the zip

// Fetch the current autotask/action to preserve existing config
const currentAction = await client.action.get(id);

// Update with new code (preserve name, trigger, etc.)
const updateBody = {
...currentAction,
encodedZippedCode,
};

const updated = await client.action.update(updateBody);
console.log("Autotask updated successfully:", updated);
};

module.exports = {
setActionVars,
updateAction,
};
27 changes: 9 additions & 18 deletions src/js/tasks/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const {
parseAddress,
parseDeployedAddress,
} = require("../utils/addressParser");
const { setAutotaskVars } = require("./autotask");
const { setActionVars } = require("./defender");
const { setActionVars, updateAction } = require("./defender");
const {
submitLido,
snapLido,
Expand Down Expand Up @@ -279,22 +278,6 @@ task("withdrawStatus").setAction(async (_, __, runSuper) => {
return runSuper();
});

// Defender
subtask(
"setAutotaskVars",
"Set environment variables on Defender Autotasks. eg DEBUG=origin*",
)
.addOptionalParam(
"id",
"Identifier of the Defender Autotask",
"ffcfc580-7b0a-42ed-a4f2-3f0a3add9779",
types.string,
)
.setAction(setAutotaskVars);
task("setAutotaskVars").setAction(async (_, __, runSuper) => {
return runSuper();
});

// Token tasks.
subtask("allowance", "Get the token allowance an owner has given to a spender")
.addParam(
Expand Down Expand Up @@ -1209,6 +1192,14 @@ task("setActionVars").setAction(async (_, __, runSuper) => {
return runSuper();
});

subtask("updateAction", "Upload a Defender Actions")
.addParam("id", "Identifier of the Defender Actions", undefined, types.string)
.addParam("file", "Path to the file to upload", undefined, types.string)
.setAction(updateAction);
task("updateAction").setAction(async (_, __, runSuper) => {
return runSuper();
});

// FlyTrade
subtask("flyTradeQuote", "Get a Fly quote for a swap")
.addOptionalParam("from", "Token symbol to swap from.", "SILO", types.string)
Expand Down
Loading