Skip to content

Commit

Permalink
feat: add wrap/unwrap estimates, zapper routes WIP 🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Sep 4, 2023
1 parent 2b8c35f commit 5deb60c
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/oeth/src/clients/wagmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const connectors = connectorsForWallets([
chains,
projectId: import.meta.env.VITE_WALLET_CONNECT_PROJECT_ID,
}),
coinbaseWallet({ appName: 'mStable', chains }),
coinbaseWallet({ appName: 'origin', chains }),
],
},
{
Expand Down
5 changes: 4 additions & 1 deletion libs/oeth/swap/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import defaultApi from './defaultApi';
import mintVault from './mintVault';
import redeemVault from './redeemVault';
import swapCurve from './swapCurve';
import swapZapperEth from './swapZapperEth';
import swapZapperSfrxeth from './swapZapperSfrxeth';
import unwrapWOETH from './unwrapWOETH';
import wrapOETH from './wrapOETH';

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

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

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

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

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

return amountIn;
};

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

return getAvailableRoutes(tokenIn, tokenOut);
};

const swap = async ({ tokenIn, tokenOut, amountIn, swapRoute }: SwapState) => {
if (amountIn === 0n || isNilOrEmpty(swapRoute)) {
return;
}
};

export default {
estimateAmount,
estimateRoutes,
swap,
} as SwapApi;
33 changes: 33 additions & 0 deletions libs/oeth/swap/src/actions/swapZapperSfrxeth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { isNilOrEmpty } from '@origin/shared/utils';

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

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

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

return amountIn;
};

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

return getAvailableRoutes(tokenIn, tokenOut);
};

const swap = async ({ tokenIn, tokenOut, amountIn, swapRoute }: SwapState) => {
if (amountIn === 0n || isNilOrEmpty(swapRoute)) {
return;
}
};

export default {
estimateAmount,
estimateRoutes,
swap,
} as SwapApi;
13 changes: 11 additions & 2 deletions libs/oeth/swap/src/actions/unwrapWOETH.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { contracts } from '@origin/shared/contracts';
import { isNilOrEmpty } from '@origin/shared/utils';
import { readContract } from '@wagmi/core';

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

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

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

return amountIn;
const data = await readContract({
address: contracts.mainnet.WOETH.address,
abi: contracts.mainnet.WOETH.abi,
functionName: 'convertToAssets',
args: [amountIn],
});

return data;
};

const estimateRoutes = async ({ tokenIn, tokenOut, amountIn }: SwapState) => {
Expand Down
13 changes: 11 additions & 2 deletions libs/oeth/swap/src/actions/wrapOETH.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { contracts } from '@origin/shared/contracts';
import { isNilOrEmpty } from '@origin/shared/utils';
import { readContract } from '@wagmi/core';

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

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

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

return amountIn;
const data = await readContract({
address: contracts.mainnet.WOETH.address,
abi: contracts.mainnet.WOETH.abi,
functionName: 'convertToShares',
args: [amountIn],
});

return data;
};

const estimateRoutes = async ({ tokenIn, tokenOut, amountIn }: SwapState) => {
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 @@ -23,7 +23,7 @@ export const swapRoutes = [
{
tokenIn: tokens.mainnet.ETH,
tokenOut: tokens.mainnet.OETH,
action: 'swap-zapper',
action: 'swap-zapper-eth',
},
{
tokenIn: tokens.mainnet.WETH,
Expand Down Expand Up @@ -68,7 +68,7 @@ export const swapRoutes = [
{
tokenIn: tokens.mainnet.sfrxETH,
tokenOut: tokens.mainnet.OETH,
action: 'swap-zapper',
action: 'swap-zapper-sfrxeth',
},
// Redeem
{
Expand Down
3 changes: 2 additions & 1 deletion libs/oeth/swap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export type TokenSource = 'tokenIn' | 'tokenOut';

export type SwapAction =
| 'swap-curve'
| 'swap-zapper'
| 'swap-zapper-eth'
| 'swap-zapper-sfrxeth'
| 'mint-vault'
| 'redeem-vault'
| 'wrap-oeth'
Expand Down
1 change: 1 addition & 0 deletions libs/shared/providers/src/prices/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const coingeckoTokenIds: Record<SupportedToken, string> = {
USDT: 'tether',
TUSD: 'true-usd',
OETH: 'origin-ether',
WOETH: 'origin-ether',
OUSD: 'origin-dollar',
stETH: 'staked-ether',
rETH: 'rocket-pool-eth',
Expand Down
1 change: 1 addition & 0 deletions libs/shared/providers/src/prices/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type SupportedToken =
| 'USDT'
| 'TUSD'
| 'OETH'
| 'WOETH'
| 'OUSD'
| 'stETH'
| 'rETH'
Expand Down

0 comments on commit 5deb60c

Please sign in to comment.