Skip to content

Commit

Permalink
feat: add swap curve action, test sdk WIP🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Sep 1, 2023
1 parent b00840f commit 005f374
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion libs/oeth/swap/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import defaultApi from './defaultApi';
import mintVault from './mintVault';
import redeemVault from './redeemVault';
import swapCurve from './swapCurve';

import type { SwapAction, SwapApi } from '../types';

export const swapActions: Record<SwapAction, SwapApi> = {
'swap-curve': { ...defaultApi },
'swap-curve': { ...defaultApi, ...swapCurve },
'swap-zapper': { ...defaultApi },
'mint-vault': { ...defaultApi, ...mintVault },
'redeem-vault': { ...defaultApi, ...redeemVault },
Expand Down
15 changes: 15 additions & 0 deletions libs/oeth/swap/src/actions/swapCurve.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import curve from '@curvefi/api';
import { isNilOrEmpty } from '@origin/shared/utils';

import { getAvailableRoutes } from '../utils';

import type { SwapApi, SwapState } from '../types';

const ETHOETHCurvePool = 'factory-v2-298';
const ETH = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';

const estimateAmount = async ({ tokenIn, tokenOut, amountIn }: SwapState) => {
if (amountIn === 0n) {
return 0n;
}

const bals = await curve.router.getBestRouteAndOutput(
tokenIn.address ?? ETH,
tokenOut.address ?? ETH,
amountIn.toString(),
);

console.groupCollapsed('Curve');
console.log(curve.getPool(ETHOETHCurvePool));
console.log(bals);
console.groupEnd();

return amountIn;
};

Expand Down
4 changes: 2 additions & 2 deletions libs/oeth/swap/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export const swapRoutes = [
{
tokenIn: tokens.mainnet.rETH,
tokenOut: tokens.mainnet.OETH,
action: 'mint-vault',
action: 'swap-curve',
},
{
tokenIn: tokens.mainnet.rETH,
tokenOut: tokens.mainnet.OETH,
action: 'swap-curve',
action: 'mint-vault',
},
{
tokenIn: tokens.mainnet.frxETH,
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/providers/src/curve/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const { Provider: CurveProvider, useTrackedState: useCurve } =
},
{ chainId: chain?.id ?? mainnet.id },
);
await curve.factory.fetchPools();
setState(curve);
};

Expand All @@ -47,6 +48,7 @@ export const { Provider: CurveProvider, useTrackedState: useCurve } =
chainId: chain.id,
},
);
await curve.factory.fetchPools();
setState(curve);
};

Expand Down

0 comments on commit 005f374

Please sign in to comment.