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
32 changes: 16 additions & 16 deletions docs/ACTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ range, tolerance, and quote-amount flags apply to every selected base.

## EtherFi ARM — mainnet

| Action | Cron | Description |
| ---------------------------- | --------------- | -------------------------------------------- |
| `autoRequestEtherFiWithdraw` | `10,40 * * * *` | Request EtherFi withdrawals from EtherFi ARM |
| `autoClaimEtherFiWithdraw` | `40 * * * *` | Claim EtherFi withdrawals from EtherFi ARM |
| `collectEtherFiFees` | `45 23 * * *` | Collect fees from EtherFi ARM |
| `allocateEtherFi` | `52 * * * *` | Allocate liquidity for EtherFi ARM |
| `setPricesEtherFi` | `2,32 * * * *` | Set prices for EtherFi ARM |
| Action | Cron | Description |
| -------------------------- | -------------- | ------------------------------------------ |
| `autoClaimEtherFiWithdraw` | `40 * * * *` | Claim EtherFi withdrawals from EtherFi ARM |
| `collectEtherFiFees` | `45 23 * * *` | Collect fees from EtherFi ARM |
| `allocateEtherFi` | `52 * * * *` | Allocate liquidity for EtherFi ARM |
| `setPricesEtherFi` | `2,32 * * * *` | Set prices for EtherFi ARM |

## Ethena ARM — mainnet

Expand All @@ -73,15 +72,16 @@ range, tolerance, and quote-amount flags apply to every selected base.

## WETH ARM — mainnet

| Action | Cron | Description |
| -------------------------------- | ----------------------- | ---------------------------------------------- |
| `autoRequestWETHLidoWithdraw` | `29,58 12-23,0-8 * * *` | Request stETH/wstETH withdrawals from WETH ARM |
| `autoClaimWETHLidoWithdraw` | `32 0,12 * * *` | Claim stETH/wstETH withdrawals for WETH ARM |
| `autoRequestWETHEtherFiWithdraw` | `10,40 * * * *` | Request eETH/weETH withdrawals from WETH ARM |
| `autoClaimWETHEtherFiWithdraw` | `40 * * * *` | Claim eETH/weETH withdrawals for WETH ARM |
| `collectWETHFees` | `30 12 * * *` | Collect fees from WETH ARM |
| `allocateWETH` | `38,08 * * * *` | Allocate liquidity for WETH ARM |
| `setPricesWETH` | `*/30 * * * *` | Set prices for all four WETH ARM base assets |
| Action | Cron | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- | ---------------------------------------------- |
| `autoRequestWETHLidoWithdraw` | `29,58 12-23,0-8 * * *` | Request stETH/wstETH withdrawals from WETH ARM |
| `autoClaimWETHLidoWithdraw` | `32 0,12 * * *` | Claim stETH/wstETH withdrawals for WETH ARM |
| `autoRequestWETHEtherFiWithdraw` | `10,40 * * * *` | Request eETH/weETH withdrawals from WETH ARM |
| `autoClaimWETHEtherFiWithdraw` | `40 * * * *` | Claim eETH/weETH withdrawals for WETH ARM |
| `collectWETHFees` | `30 12 * * *` | Collect fees from WETH ARM |
| `allocateWETH` | `38,08 * * * *` | Allocate liquidity for WETH ARM |
| `setPricesWETH --bases STETH,WSTETH --fee 0.6 --inch false --kyber true --tolerance 0.1 --amount 30 --offset 0.3 --max-buy-price 0.99996 --min-sell-price 0.99998` | `*/10 * * * *` | Set WETH ARM prices for Lido base assets |
| `setPricesWETH --bases EETH,WEETH --fee 0.6 --inch false --kyber true --tolerance 0.1 --amount 30 --offset 0.3 --max-buy-price 0.99996 --min-sell-price 0.99998` | `2-59/10 * * * *` | Set WETH ARM prices for Ether.fi base assets |

## Origin ARM — Sonic

Expand Down
6 changes: 4 additions & 2 deletions migrations/seed_schedules.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ WHERE product = 'arm-oeth'
'mainnet_collect_usd_fees',
'mainnet_allocate_usd',
'mainnet_set_prices_usd',
'mainnet_set_prices_weth',
'mainnet_auto_request_etherfi_withdraw',
'mainnet_pause_usd',
'mainnet_pause_lido',
'mainnet_pause_etherfi',
Expand All @@ -24,7 +26,6 @@ INSERT INTO schedules (product, name, command, cron_expr, timezone, enabled, not
('arm-oeth', 'healthcheck', 'cd /app && pnpm hardhat healthcheck', '*/5 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_auto_request_lido_withdraw', 'cd /app && pnpm hardhat autoRequestLidoWithdraw --network mainnet', '29,58 12-23,0-8 * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_auto_claim_lido_withdraw', 'cd /app && pnpm hardhat autoClaimLidoWithdraw --network mainnet', '32 0,12 * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_auto_request_etherfi_withdraw','cd /app && pnpm hardhat autoRequestEtherFiWithdraw --network mainnet', '10,40 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_auto_claim_etherfi_withdraw', 'cd /app && pnpm hardhat autoClaimEtherFiWithdraw --network mainnet', '40 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_auto_request_ethena_withdraw', 'cd /app && pnpm hardhat autoRequestEthenaWithdraw --network mainnet', '12 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_auto_claim_ethena_withdraw', 'cd /app && pnpm hardhat autoClaimEthenaWithdraw --network mainnet', '40 * * * *', 'UTC', false, NULL),
Expand All @@ -48,7 +49,8 @@ INSERT INTO schedules (product, name, command, cron_expr, timezone, enabled, not
('arm-oeth', 'mainnet_auto_claim_weth_etherfi_withdraw', 'cd /app && pnpm hardhat autoClaimWETHEtherFiWithdraw --network mainnet', '40 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_collect_weth_fees', 'cd /app && pnpm hardhat collectWETHFees --network mainnet', '30 12 * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_allocate_weth', 'cd /app && pnpm hardhat allocateWETH --network mainnet', '38,08 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_set_prices_weth', 'cd /app && pnpm hardhat setPricesWETH --network mainnet', '*/30 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_set_prices_weth_lido', 'cd /app && pnpm hardhat setPricesWETH --bases STETH,WSTETH --network mainnet --fee 0.6 --inch false --kyber true --tolerance 0.1 --amount 30 --offset 0.3 --max-buy-price 0.99996 --min-sell-price 0.99998', '*/10 * * * *', 'UTC', false, NULL),
('arm-oeth', 'mainnet_set_prices_weth_etherfi', 'cd /app && pnpm hardhat setPricesWETH --bases EETH,WEETH --network mainnet --fee 0.6 --inch false --kyber true --tolerance 0.1 --amount 30 --offset 0.3 --max-buy-price 0.99996 --min-sell-price 0.99998', '2-59/10 * * * *', 'UTC', false, NULL),
-- Emergency pause action: manual-only (enabled=false). Edit `--arm` before
-- using "Run now". The supported Ethereum ARMs are lido, etherfi, ethena,
-- oeth, usdc, and weth. cron_expr is a placeholder and never fires while disabled.
Expand Down
28 changes: 25 additions & 3 deletions src/js/tasks/armPrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
rangeSellPrice,
rangeBuyPrice,
} = require("../utils/pricing");
const { haveSwapCapsChanged } = require("../utils/priceUpdate");

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

Expand Down Expand Up @@ -360,11 +361,32 @@ const setPrices = async (options) => {
const toleranceScaled = parseUnits(tolerance.toString(), 36 - 4);
log(`tolerance : ${formatUnits(toleranceScaled, 32)} basis points`);

const targetBuyAmount = parseSwapCap(buyAmount);
const targetSellAmount = parseSwapCap(sellAmount);
const swapCapsChanged = haveSwapCapsChanged(
baseContext,
targetBuyAmount,
targetSellAmount,
);
if (baseContext.version === "multiBase") {
log(`current buy amount : ${config.buyLiquidityRemaining}`);
log(`target buy amount : ${targetBuyAmount}`);
log(`current sell amount: ${config.sellLiquidityRemaining}`);
log(`target sell amount : ${targetSellAmount}`);
}

// decide if rates need to be updated
if (diffSellPrice > toleranceScaled || diffBuyPrice > toleranceScaled) {
if (
diffSellPrice > toleranceScaled ||
diffBuyPrice > toleranceScaled ||
swapCapsChanged
) {
console.log(`About to update ARM prices`);
console.log(`sell: ${formatUnits(targetSellPrice, 36)}`);
console.log(`buy : ${formatUnits(targetBuyPrice, 36)}`);
if (swapCapsChanged) {
console.log(`Buy or sell amount has changed`);
}

if (dryrun) {
console.log(`Dry run mode - not calling setPrices`);
Expand All @@ -376,8 +398,8 @@ const setPrices = async (options) => {
signer,
buyPrice: targetBuyPrice,
sellPrice: targetSellPrice,
buyAmount: parseSwapCap(buyAmount),
sellAmount: parseSwapCap(sellAmount),
buyAmount: targetBuyAmount,
sellAmount: targetSellAmount,
});

await logTxDetails(tx, "setPrices", options.confirm);
Expand Down
8 changes: 8 additions & 0 deletions src/js/utils/priceUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const haveSwapCapsChanged = (baseContext, buyAmount, sellAmount) =>
baseContext.version === "multiBase" &&
(buyAmount !== baseContext.config.buyLiquidityRemaining ||
sellAmount !== baseContext.config.sellLiquidityRemaining);

module.exports = {
haveSwapCapsChanged,
};
37 changes: 37 additions & 0 deletions test/js/armPrices.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const assert = require("assert");

const { haveSwapCapsChanged } = require("../../src/js/utils/priceUpdate");

const multiBaseContext = (buyLiquidityRemaining, sellLiquidityRemaining) => ({
version: "multiBase",
config: {
buyLiquidityRemaining,
sellLiquidityRemaining,
},
});

assert.strictEqual(
haveSwapCapsChanged(multiBaseContext(10n, 20n), 10n, 20n),
false,
"unchanged buy and sell amounts should not trigger an update",
);

assert.strictEqual(
haveSwapCapsChanged(multiBaseContext(9n, 20n), 10n, 20n),
true,
"a changed buy amount should trigger an update",
);

assert.strictEqual(
haveSwapCapsChanged(multiBaseContext(10n, 19n), 10n, 20n),
true,
"a changed sell amount should trigger an update",
);

assert.strictEqual(
haveSwapCapsChanged({ version: "legacy" }, 10n, 20n),
false,
"legacy ARMs do not support buy and sell amounts",
);

console.log("ARM price tests passed");
Loading