Skip to content

Commit

Permalink
feat: make prime route chain safe
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Jul 30, 2024
1 parent 2738394 commit 55eb854
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions libs/shared/routes/src/prime/restakePrime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const isRouteAvailable: IsRouteAvailable = async ({ config }) => {
address: contracts.mainnet.lrtDepositPool.address,
abi: contracts.mainnet.lrtDepositPool.abi,
functionName: 'paused',
chainId: contracts.mainnet.lrtDepositPool.chainId,
});

return !paused;
Expand All @@ -62,12 +63,14 @@ const estimateAmount: EstimateAmount = async (
address: contracts.mainnet.lrtOracle.address,
abi: contracts.mainnet.lrtOracle.abi,
functionName: 'primeETHPrice',
chainId: contracts.mainnet.lrtOracle.chainId,
},
{
address: contracts.mainnet.lrtOracle.address,
abi: contracts.mainnet.lrtOracle.abi,
functionName: 'getAssetPrice',
args: [tokenIn.address ?? ZERO_ADDRESS],
chainId: contracts.mainnet.lrtOracle.chainId,
},
],
}),
Expand All @@ -85,7 +88,9 @@ const estimateGas: EstimateGas = async (
{ tokenIn, tokenOut, amountIn, amountOut, slippage },
) => {
let gasEstimate = 0n;
const publicClient = getPublicClient(config);
const publicClient = getPublicClient(config, {
chainId: contracts.mainnet.lrtDepositPool.chainId,
});

if (amountIn === 0n || !publicClient || !tokenIn?.address) {
return gasEstimate;
Expand Down Expand Up @@ -144,6 +149,7 @@ const allowance: Allowance = async ({ config, queryClient }, { tokenIn }) => {
abi: tokenIn.abi,
functionName: 'allowance',
args: [address, contracts.mainnet.lrtDepositPool.address],
chainId: tokenIn.chainId,
}),
staleTime: 15e3,
});
Expand All @@ -157,7 +163,7 @@ const estimateApprovalGas: EstimateApprovalGas = async (
) => {
let approvalEstimate = 0n;
const { address } = getAccount(config);
const publicClient = getPublicClient(config);
const publicClient = getPublicClient(config, { chainId: tokenIn.chainId });

if (amountIn === 0n || !address || !publicClient || !tokenIn?.address) {
return approvalEstimate;
Expand Down Expand Up @@ -188,6 +194,7 @@ const approve: Approve = async ({ config }, { tokenIn, amountIn }) => {
abi: tokenIn.abi,
functionName: 'approve',
args: [contracts.mainnet.lrtDepositPool.address, amountIn],
chainId: tokenIn.chainId,
});
const hash = await writeContract(config, request);

Expand Down Expand Up @@ -229,6 +236,7 @@ const swap: Swap = async (
minAmountOut[0],
referrerId ?? '',
],
chainId: contracts.mainnet.lrtDepositPool.chainId,
});
const hash = await writeContract(config, request);

Expand Down
10 changes: 8 additions & 2 deletions libs/shared/routes/src/prime/swapUniwsapPrime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const isRouteAvailable: IsRouteAvailable = async ({ config }, { amountIn }) => {
abi: tokens.mainnet.primeETH.abi,
functionName: 'balanceOf',
args: [contracts.mainnet.uniswapV3WETHPrimeETHPool.address],
chainId: tokens.mainnet.primeETH.chainId,
});

return poolBalance > amountIn;
Expand All @@ -40,7 +41,9 @@ const estimateAmount: EstimateAmount = async (
{ amountIn, tokenOut },
) => {
let estimate = 0n;
const publicClient = getPublicClient(config);
const publicClient = getPublicClient(config, {
chainId: contracts.mainnet.uniswapV3Quoter.chainId,
});
if (amountIn === 0n || !tokenOut?.address || !publicClient) {
return estimate;
}
Expand All @@ -62,7 +65,9 @@ const estimateGas: EstimateGas = async (
{ tokenOut, amountIn, amountOut, slippage },
) => {
let gasEstimate = 0n;
const publicClient = getPublicClient(config);
const publicClient = getPublicClient(config, {
chainId: contracts.mainnet.uniswapV3Quoter.chainId,
});

if (amountIn === 0n || !publicClient || !tokenOut?.address) {
return gasEstimate;
Expand Down Expand Up @@ -158,6 +163,7 @@ const swap: Swap = async (
sqrtPriceLimitX96: 0n,
},
],
chainId: contracts.mainnet.uniswapV3Quoter.chainId,
});
const hash = await writeContract(config, request);

Expand Down
1 change: 1 addition & 0 deletions libs/shared/routes/src/prime/swapZapperPrime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const swap: Swap = async (
args: [minAmountOut[0], referrerId ?? ''],
value: amountIn,
account: address,
chainId: contracts.mainnet.PrimeETHZapper.chainId,
});
const hash = await writeContract(config, request);

Expand Down

0 comments on commit 55eb854

Please sign in to comment.