Skip to content

Commit

Permalink
feat: replace curve sdk with ad hoc calls WIP🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Sep 10, 2023
1 parent 8c63ee4 commit 9b30af8
Show file tree
Hide file tree
Showing 33 changed files with 3,598 additions and 479 deletions.
8 changes: 1 addition & 7 deletions apps/oeth/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ root.render(
[CssVarsProvider, { theme: theme, defaultMode: 'dark' }],
[WagmiConfig, { config: wagmiConfig }],
[RainbowKitProvider, { chains: chains, theme: darkTheme() }],
[
CurveProvider,
{
alchemyApiKey: import.meta.env.VITE_ALCHEMY_ID,
customRpcUrl: import.meta.env.VITE_CUSTOM_RPC,
},
],
[CurveProvider],
],
<RouterProvider router={createHashRouter(routes)} />,
),
Expand Down
33 changes: 9 additions & 24 deletions libs/oeth/swap/src/actions/defaultApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,38 @@ import type {
Swap,
} from '../types';

const estimateAmount: EstimateAmount = async (
_tokenIn,
_tokenOut,
amountIn,
) => {
const estimateAmount: EstimateAmount = async ({ amountIn }) => {
console.log('Amount estimation not implemented');

return amountIn;
};

const estimateGas: EstimateGas = async (
_tokenIn,
_tokenOut,
_amountIn,
_slippage,
) => {
const estimateGas: EstimateGas = async () => {
console.log('Gas estimation not implemented');

return 0n;
};

const estimateRoute: EstimateRoute = async (
tokenIn,
tokenOut,
const estimateRoute: EstimateRoute = async ({
amountIn,
route,
tokenIn,
tokenOut,
slippage,
) => {
}) => {
if (amountIn === 0n) {
return { ...route, estimatedAmount: 0n, gas: 0n, rate: 0 };
}

const [estimatedAmount, gas] = await Promise.all([
estimateAmount(tokenIn, tokenOut, amountIn),
estimateGas(tokenIn, tokenOut, amountIn, slippage),
estimateAmount({ tokenIn, tokenOut, amountIn }),
estimateGas({ tokenIn, tokenOut, amountIn, slippage }),
]);

return { ...route, estimatedAmount, gas, rate: 0 };
};

const swap: Swap = async (
_tokenIn,
_tokenOut,
_amountIn,
_route,
_slippage,
) => {
const swap: Swap = async () => {
console.log('Route swap operation not implemented');
};

Expand Down
27 changes: 15 additions & 12 deletions libs/oeth/swap/src/actions/mintVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { formatUnits, parseUnits } from 'viem';
import type { EstimateGas, EstimateRoute, Swap } from '../types';
import type { EstimateAmount } from '../types';

const estimateAmount: EstimateAmount = async (tokenIn, tokenOut, amountIn) => {
const estimateAmount: EstimateAmount = async ({
tokenIn,
tokenOut,
amountIn,
}) => {
if (amountIn === 0n) {
return 0n;
}
Expand All @@ -37,13 +41,13 @@ const estimateAmount: EstimateAmount = async (tokenIn, tokenOut, amountIn) => {
);
};

const estimateGas: EstimateGas = async (
const estimateGas: EstimateGas = async ({
tokenIn,
tokenOut,
amountIn,
slippage,
amountOut,
) => {
}) => {
let gasEstimate = 0n;

if (amountIn === 0n) {
Expand Down Expand Up @@ -110,25 +114,25 @@ const estimateGas: EstimateGas = async (
return gasEstimate;
};

const estimateRoute: EstimateRoute = async (
const estimateRoute: EstimateRoute = async ({
tokenIn,
tokenOut,
amountIn,
route,
slippage,
) => {
}) => {
if (amountIn === 0n) {
return { ...route, estimatedAmount: 0n, gas: 0n, rate: 0 };
}

const estimatedAmount = await estimateAmount(tokenIn, tokenOut, amountIn);
const gas = await estimateGas(
const estimatedAmount = await estimateAmount({ tokenIn, tokenOut, amountIn });
const gas = await estimateGas({
tokenIn,
tokenOut,
amountIn,
slippage,
estimatedAmount,
);
amountOut: estimatedAmount,
});

return {
...route,
Expand All @@ -140,14 +144,13 @@ const estimateRoute: EstimateRoute = async (
};
};

const swap: Swap = async (
const swap: Swap = async ({
tokenIn,
tokenOut,
amountIn,
_route,
slippage,
amountOut,
) => {
}) => {
const { address } = getAccount();

if (amountIn === 0n || isNilOrEmpty(address)) {
Expand Down
32 changes: 10 additions & 22 deletions libs/oeth/swap/src/actions/redeemVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ import type {
Swap,
} from '../types';

const estimateAmount: EstimateAmount = async (
_tokenIn,
_tokenOut,
amountIn,
) => {
const estimateAmount: EstimateAmount = async ({ amountIn }) => {
if (amountIn === 0n) {
return 0n;
}
Expand Down Expand Up @@ -71,13 +67,12 @@ const estimateAmount: EstimateAmount = async (
}, 0n);
};

const estimateGas: EstimateGas = async (
_tokenIn,
const estimateGas: EstimateGas = async ({
tokenOut,
amountIn,
slippage,
amountOut,
) => {
}) => {
let gasEstimate = 0n;

if (amountIn === 0n) {
Expand Down Expand Up @@ -108,25 +103,25 @@ const estimateGas: EstimateGas = async (
return gasEstimate;
};

const estimateRoute: EstimateRoute = async (
const estimateRoute: EstimateRoute = async ({
tokenIn,
tokenOut,
amountIn,
route,
slippage,
) => {
}) => {
if (amountIn === 0n) {
return { ...route, estimatedAmount: 0n, gas: 0n, rate: 0 };
}

const estimatedAmount = await estimateAmount(tokenIn, tokenOut, amountIn);
const gas = await estimateGas(
const estimatedAmount = await estimateAmount({ tokenIn, tokenOut, amountIn });
const gas = await estimateGas({
tokenIn,
tokenOut,
amountIn,
slippage,
estimatedAmount,
);
amountOut: estimatedAmount,
});

return {
...route,
Expand All @@ -138,14 +133,7 @@ const estimateRoute: EstimateRoute = async (
};
};

const swap: Swap = async (
_tokenIn,
tokenOut,
amountIn,
_route,
slippage,
amountOut,
) => {
const swap: Swap = async ({ tokenOut, amountIn, slippage, amountOut }) => {
const { address } = getAccount();

if (amountIn === 0n || isNilOrEmpty(address)) {
Expand Down
141 changes: 0 additions & 141 deletions libs/oeth/swap/src/actions/swapCurve.ts

This file was deleted.

Loading

0 comments on commit 9b30af8

Please sign in to comment.