Skip to content

Commit be51d4a

Browse files
committed
Merge remote-tracking branch 'origin/main' into nicka/talos-pricing
2 parents 3c14851 + aecfedc commit be51d4a

17 files changed

Lines changed: 200 additions & 77 deletions

docs/ACTIONS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ The mainnet `setPrices*` actions use `--amount` as an explicit override for the
1717
DEX swap amount when fetching the reference price quote. This is separate from `--buy-amount` and
1818
`--sell-amount`, which set the buy-side liquidity-asset and sell-side base-asset
1919
liquidity remaining on the Ethena, USDC, and WETH ARMs. If omitted, each limit is
20-
set to the maximum `uint128` value. Liquidity amounts are integer native token
21-
units (for example, `100000000` is 100 tokens for an asset with 6 decimals).
20+
set to the maximum `uint128` value. Liquidity amounts are token-denominated:
21+
`1` is one liquidity or base token, with the appropriate token decimals applied
22+
by the action.
2223
When `--amount` is omitted, the DEX quote amount is the smaller of the
2324
withdrawable ARM/market reserves and the corresponding price liquidity limit.
2425
An explicit `--amount` is used unchanged.

src/js/tasks/actions/autoClaimLidoWithdraw.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ action({
1313
description: "Claim Lido withdrawals from Lido ARM",
1414
chains: [1],
1515
params: (t) =>
16-
t.addOptionalParam(
17-
"id",
18-
"Specific Lido withdrawal request identifier to claim. (default: all)",
19-
undefined,
20-
types.string,
21-
),
16+
t
17+
.addOptionalParam(
18+
"id",
19+
"Specific Lido withdrawal request identifier to claim. (deprecated: use ids)",
20+
undefined,
21+
types.string,
22+
)
23+
.addOptionalParam(
24+
"ids",
25+
"Comma-separated Lido withdrawal request identifiers to claim. (default: all)",
26+
undefined,
27+
types.string,
28+
),
2229
run: async ({ signer, log, args }) => {
2330
const arm = new ethers.Contract(mainnet.lidoARM, lidoARMAbi, signer);
2431
const withdrawalQueue = new ethers.Contract(
@@ -38,6 +45,7 @@ action({
3845
armName: "Lido",
3946
withdrawalQueue,
4047
id: args.id,
48+
ids: args.ids,
4149
},
4250
});
4351
},

src/js/tasks/actions/autoClaimWETHEtherFiWithdraw.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ action({
1212
description: "Claim EtherFi withdrawals from WETH ARM",
1313
chains: [1],
1414
params: (t) =>
15-
t.addOptionalParam(
16-
"id",
17-
"Specific EtherFi withdrawal request identifier to claim. (default: all)",
18-
undefined,
19-
types.string,
20-
),
15+
t
16+
.addOptionalParam(
17+
"id",
18+
"Specific EtherFi withdrawal request identifier to claim. (deprecated: use ids)",
19+
undefined,
20+
types.string,
21+
)
22+
.addOptionalParam(
23+
"ids",
24+
"Comma-separated EtherFi withdrawal request identifiers to claim. (default: all)",
25+
undefined,
26+
types.string,
27+
),
2128
run: async ({ signer, log, args }) => {
2229
const arm = new ethers.Contract(mainnet.wethARM, multiAssetARMAbi, signer);
2330

@@ -31,6 +38,7 @@ action({
3138
arm,
3239
armName: "WETH",
3340
id: args.id,
41+
ids: args.ids,
3442
},
3543
});
3644
},

src/js/tasks/actions/autoClaimWETHLidoWithdraw.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ action({
1212
description: "Claim Lido withdrawals from WETH ARM",
1313
chains: [1],
1414
params: (t) =>
15-
t.addOptionalParam(
16-
"id",
17-
"Specific Lido withdrawal request identifier to claim. (default: all)",
18-
undefined,
19-
types.string,
20-
),
15+
t
16+
.addOptionalParam(
17+
"id",
18+
"Specific Lido withdrawal request identifier to claim. (deprecated: use ids)",
19+
undefined,
20+
types.string,
21+
)
22+
.addOptionalParam(
23+
"ids",
24+
"Comma-separated Lido withdrawal request identifiers to claim. (default: all)",
25+
undefined,
26+
types.string,
27+
),
2128
run: async ({ signer, log, args }) => {
2229
const arm = new ethers.Contract(mainnet.wethARM, multiAssetARMAbi, signer);
2330

@@ -31,6 +38,7 @@ action({
3138
arm,
3239
armName: "WETH",
3340
id: args.id,
41+
ids: args.ids,
3442
},
3543
});
3644
},

src/js/tasks/actions/setPricesEthena.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ action({
3131
)
3232
.addOptionalParam(
3333
"buyAmount",
34-
"Liquidity asset amount remaining at the buy price for multi-base ARMs, as an integer in native token units.",
34+
"USDe remaining at the buy price, in token units (1 = 1 USDe).",
3535
undefined,
36-
types.string,
36+
types.float,
3737
)
3838
.addOptionalParam(
3939
"sellAmount",
40-
"Base asset amount remaining at the sell price for multi-base ARMs, as an integer in native token units.",
40+
"sUSDe remaining at the sell price, in token units (1 = 1 sUSDe).",
4141
undefined,
42-
types.string,
42+
types.float,
4343
)
4444
.addOptionalParam(
4545
"maxBuyPrice",

src/js/tasks/actions/setPricesUSDC.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ action({
3535
)
3636
.addOptionalParam(
3737
"buyAmount",
38-
"Liquidity asset amount remaining at the buy price for multi-base ARMs, as an integer in native token units.",
38+
"USDC remaining at the buy price, in token units (1 = 1 USDC).",
3939
undefined,
40-
types.string,
40+
types.float,
4141
)
4242
.addOptionalParam(
4343
"sellAmount",
44-
"Base asset amount remaining at the sell price for multi-base ARMs, as an integer in native token units.",
44+
"Base asset remaining at the sell price, in token units (1 = 1 token).",
4545
undefined,
46-
types.string,
46+
types.float,
4747
)
4848
.addOptionalParam(
4949
"maxBuyPrice",

src/js/tasks/actions/setPricesWETH.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ action({
5656
)
5757
.addOptionalParam(
5858
"buyAmount",
59-
"WETH remaining at the buy price, as an integer in native token units.",
59+
"WETH remaining at the buy price, in token units (1 = 1 WETH).",
6060
undefined,
61-
types.string,
61+
types.float,
6262
)
6363
.addOptionalParam(
6464
"sellAmount",
65-
"Base asset remaining at the sell price, as an integer in native token units.",
65+
"Base asset remaining at the sell price, in token units (1 = 1 token).",
6666
undefined,
67-
types.string,
67+
types.float,
6868
)
6969
.addOptionalParam(
7070
"maxBuyPrice",

src/js/tasks/armPrices.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ const setPrices = async (options) => {
9191
// Base asset decimals used to scale aggregator quote amounts. Legacy ARM
9292
// configs don't expose baseAssetDecimals as all their assets are 18 decimals.
9393
const baseDecimals = Number(config.baseAssetDecimals ?? 18);
94+
const liquidityDecimals = Number(
95+
await new Contract(
96+
liquidityAddress,
97+
["function decimals() view returns (uint8)"],
98+
signer,
99+
).decimals(),
100+
);
94101

95102
log(`Getting current ARM prices:`);
96103
log(`base asset : ${baseSymbol}`);
@@ -114,17 +121,6 @@ const setPrices = async (options) => {
114121
? 10n
115122
: 30n;
116123

117-
// The liquidity asset decimals are not in the base asset config so read
118-
// them on-chain. Can differ from the base asset decimals, eg an 18
119-
// decimals base asset over a 6 decimals USDC liquidity asset.
120-
const liquidityDecimals = Number(
121-
await new Contract(
122-
liquidityAddress,
123-
["function decimals() view returns (uint8)"],
124-
signer,
125-
).decimals(),
126-
);
127-
128124
// 2.1 Get reference prices
129125
let referencePrices;
130126
if (midPrice) {
@@ -152,8 +148,8 @@ const setPrices = async (options) => {
152148
amount: options.amount,
153149
liquidityAssets: reserves?.liquidityAssets ?? reserves?.[0],
154150
baseAssetReserve: reserves?.baseAssetReserve ?? reserves?.[1],
155-
buyLiquidity: parseSwapCap(buyAmount),
156-
sellLiquidity: parseSwapCap(sellAmount),
151+
buyLiquidity: parseSwapCap(buyAmount, liquidityDecimals),
152+
sellLiquidity: parseSwapCap(sellAmount, baseDecimals),
157153
liquidityDecimals,
158154
baseDecimals,
159155
});
@@ -392,8 +388,8 @@ const setPrices = async (options) => {
392388
const toleranceScaled = parseUnits(tolerance.toString(), 36 - 4);
393389
log(`tolerance : ${formatUnits(toleranceScaled, 32)} basis points`);
394390

395-
const targetBuyAmount = parseSwapCap(buyAmount);
396-
const targetSellAmount = parseSwapCap(sellAmount);
391+
const targetBuyAmount = parseSwapCap(buyAmount, liquidityDecimals);
392+
const targetSellAmount = parseSwapCap(sellAmount, baseDecimals);
397393
const swapCapsChanged = haveSwapCapsChanged(
398394
baseContext,
399395
targetBuyAmount,

src/js/tasks/etherfiQueue.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
} = require("../utils/arm");
1111
const addresses = require("../utils/addresses");
1212
const { createApolloClient } = require("../utils/apollo");
13+
const { parseRequestIds } = require("../utils/requestIds");
1314
const { logTxDetails } = require("../utils/txLogger");
1415

1516
const log = require("../utils/logger")("task:etherfiQueue");
@@ -42,12 +43,13 @@ const requestEtherFiWithdrawals = async (options) => {
4243
};
4344

4445
const claimEtherFiWithdrawals = async (options) => {
45-
const { signer, id } = options;
46+
const { signer } = options;
4647
const baseContext = await resolveArmBase(options);
4748

48-
const requestIds = id
49-
? // If an id is provided, just claim that one
50-
[id]
49+
const selectedRequestIds = parseRequestIds(options);
50+
const requestIds = selectedRequestIds
51+
? // If ids are provided, claim exactly those requests.
52+
selectedRequestIds
5153
: // Get the outstanding EtherFi withdrawal requests for the ARM
5254
await claimableEtherFiRequests(signer);
5355

src/js/tasks/lidoQueue.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
requestBaseAssetWithdrawal,
88
resolveArmBase,
99
} = require("../utils/arm");
10+
const { parseRequestIds } = require("../utils/requestIds");
1011
const { logTxDetails } = require("../utils/txLogger");
1112

1213
const log = require("../utils/logger")("task:lidoQueue");
@@ -83,18 +84,19 @@ const requestLidoWithdrawals = async (options) => {
8384
};
8485

8586
const claimLidoWithdrawals = async (options) => {
86-
const { signer, id, withdrawalQueue } = options;
87+
const { signer, withdrawalQueue } = options;
8788
const baseContext = await resolveArmBase(options);
8889
const { config } = baseContext;
90+
const selectedRequestIds = parseRequestIds(options);
8991

9092
if (baseContext.version === "legacy") {
9193
if (!withdrawalQueue) {
9294
throw new Error("Legacy Lido claims require the Lido withdrawal queue");
9395
}
9496

9597
const finalizedIds = [];
96-
if (id) {
97-
finalizedIds.push(id);
98+
if (selectedRequestIds) {
99+
finalizedIds.push(...selectedRequestIds);
98100
} else {
99101
const requestIds = await withdrawalQueue.getWithdrawalRequests(
100102
await baseContext.arm.getAddress(),
@@ -150,11 +152,21 @@ const claimLidoWithdrawals = async (options) => {
150152
const adapter = await adapterContract(config.adapter, signer);
151153

152154
let shares;
153-
if (id) {
154-
shares = await adapter["requestShares(uint256)"](id);
155+
if (selectedRequestIds) {
156+
shares = 0n;
157+
for (const requestId of selectedRequestIds) {
158+
const requestShares = await adapter["requestShares(uint256)"](requestId);
159+
if (requestShares === 0n) {
160+
log(
161+
`Withdrawal request ${requestId} does not belong to the ${baseContext.baseSymbol} adapter`,
162+
);
163+
continue;
164+
}
165+
shares += requestShares;
166+
}
155167
if (shares === 0n) {
156168
log(
157-
`Withdrawal request ${id} does not belong to the ${baseContext.baseSymbol} adapter`,
169+
`No selected withdrawal requests belong to the ${baseContext.baseSymbol} adapter`,
158170
);
159171
return;
160172
}

0 commit comments

Comments
 (0)