Skip to content

Commit

Permalink
Merge pull request #150 from OriginProtocol/feat/arb_swap
Browse files Browse the repository at this point in the history
Feat/arb_swap
  • Loading branch information
toniocodo authored Aug 2, 2024
2 parents e9794e5 + 7786f89 commit 821fcf1
Show file tree
Hide file tree
Showing 22 changed files with 1,403 additions and 19 deletions.
6 changes: 6 additions & 0 deletions apps/defi/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,12 @@
"value": "Error while estimating"
}
],
"iQgt9N": [
{
"type": 0,
"value": "Swap via Balancer"
}
],
"iaS0YY": [
{
"type": 0,
Expand Down
3 changes: 3 additions & 0 deletions apps/defi/src/lang/extracts/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@
"iLgjES": {
"defaultMessage": "Error while estimating"
},
"iQgt9N": {
"defaultMessage": "Swap via Balancer"
},
"iaS0YY": {
"defaultMessage": "I have read and agree to the above terms"
},
Expand Down
6 changes: 6 additions & 0 deletions libs/defi/oeth/src/swap/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
mintVaultOeth,
swapBalancerOeth,
SwapCurveOeth,
swapCurveOethEth,
swapCurveOethSfrxeth,
Expand All @@ -15,6 +16,11 @@ import type { SwapApi } from '@origin/shared/providers';
import type { OethSwapAction } from './types';

export const oethSwapActions: Record<OethSwapAction, SwapApi> = {
'swap-balancer-oeth': {
...swapBalancerOeth,
routeLabel: defineMessage({ defaultMessage: 'Swap via Balancer' }),
buttonLabel: defineMessage({ defaultMessage: 'Swap' }),
},
'swap-curve-oeth': {
...SwapCurveOeth,
routeLabel: defineMessage({ defaultMessage: 'Swap via Curve' }),
Expand Down
20 changes: 20 additions & 0 deletions libs/defi/oeth/src/swap/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import type { OethSwapAction } from './types';

export const oethSwapRoutes: SwapRoute<OethSwapAction>[] = [
// Mint
{
tokenIn: tokens.arbitrum.ETH,
tokenOut: tokens.arbitrum.wOETH,
action: 'swap-balancer-oeth',
},
{
tokenIn: tokens.arbitrum.WETH,
tokenOut: tokens.arbitrum.wOETH,
action: 'swap-balancer-oeth',
},
{
tokenIn: tokens.mainnet.ETH,
tokenOut: tokens.mainnet.OETH,
Expand All @@ -29,6 +39,16 @@ export const oethSwapRoutes: SwapRoute<OethSwapAction>[] = [
action: 'swap-curve-oeth',
},
// Redeem
{
tokenIn: tokens.arbitrum.wOETH,
tokenOut: tokens.arbitrum.ETH,
action: 'swap-balancer-oeth',
},
{
tokenIn: tokens.arbitrum.wOETH,
tokenOut: tokens.arbitrum.WETH,
action: 'swap-balancer-oeth',
},
{
tokenIn: tokens.mainnet.OETH,
tokenOut: tokens.mainnet.WETH,
Expand Down
1 change: 1 addition & 0 deletions libs/defi/oeth/src/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OethRoute } from '@origin/shared/routes';
export type OethSwapAction = Extract<
OethRoute,
| 'mint-vault-oeth'
| 'swap-balancer-oeth'
| 'swap-curve-oeth'
| 'swap-curve-oeth-eth'
| 'swap-curve-oeth-sfrxeth'
Expand Down
11 changes: 10 additions & 1 deletion libs/defi/oeth/src/swap/views/SwapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
} from '@origin/defi/shared';
import { tokens } from '@origin/shared/contracts';
import { useIntl } from 'react-intl';
import { mainnet } from 'viem/chains';
import { useAccount } from 'wagmi';

import { oethSwapActions } from '../actions';
import { AnalyticsCard } from '../components/AnalyticsCard';
Expand All @@ -19,6 +21,13 @@ import { oethSwapRoutes } from '../constants';

export const SwapView = () => {
const intl = useIntl();
const { chain } = useAccount();

const token =
(chain ?? mainnet).id === mainnet.id
? tokens.mainnet.OETH
: tokens.arbitrum.wOETH;

return (
<Page>
<PageTitle
Expand All @@ -45,7 +54,7 @@ export const SwapView = () => {
</Grid2>
<Grid2 xs={12} md={3}>
<Stack spacing={4}>
<GlobalStatsCard token={tokens.mainnet.OETH} />
<GlobalStatsCard token={token} />
<AnalyticsCard />
</Stack>
</Grid2>
Expand Down
16 changes: 14 additions & 2 deletions libs/defi/shared/src/components/Cards/GlobalStatsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Card, CardContent, CardHeader, Divider, Stack } from '@mui/material';
import { ValueLabel } from '@origin/shared/components';
import { supportedChainNames } from '@origin/shared/constants';
import {
getTokenPriceKey,
useTokenPrice,
Expand Down Expand Up @@ -35,9 +36,11 @@ export const GlobalStatsCard = ({ token, ...rest }: GlobalStatsCardProps) => {
labelProps={{ variant: 'body3', fontWeight: 'medium' }}
labelInfoTooltip={intl.formatMessage(
{
defaultMessage: 'Total value locked {symbol}',
defaultMessage: 'Total value locked on {chainName}',
},
{
chainName: supportedChainNames[token.chainId].short,
},
{ symbol: token.symbol },
)}
value={`$${format(tvl ?? from(0), 2)}`}
valueProps={{ fontWeight: 'medium' }}
Expand All @@ -47,6 +50,15 @@ export const GlobalStatsCard = ({ token, ...rest }: GlobalStatsCardProps) => {
direction="row"
justifyContent="space-between"
label={intl.formatMessage({ defaultMessage: 'Price' })}
labelInfoTooltip={intl.formatMessage(
{
defaultMessage: 'USD price of {symbol} on {chainName}',
},
{
symbol: token.symbol,
chainName: supportedChainNames[token.chainId].short,
},
)}
labelProps={{ variant: 'body3', fontWeight: 'medium' }}
value={`$${format(price ?? from(0), 2)}`}
valueProps={{ fontWeight: 'medium' }}
Expand Down
6 changes: 6 additions & 0 deletions libs/shared/constants/src/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { arbitrum, mainnet, optimism } from 'viem/chains';

export const supportedChains = {
[mainnet.id.toString()]: mainnet,
[arbitrum.id.toString()]: arbitrum,
[optimism.id.toString()]: optimism,
} as const;

export const supportedChainNames = {
[mainnet.id.toString()]: {
short: 'Ethereum',
Expand Down
161 changes: 161 additions & 0 deletions libs/shared/contracts/src/abis/BalancerQueries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
export const BalancerQueriesABI = [
{
inputs: [
{ internalType: 'contract IVault', name: '_vault', type: 'address' },
],
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [
{ internalType: 'enum IVault.SwapKind', name: 'kind', type: 'uint8' },
{
components: [
{ internalType: 'bytes32', name: 'poolId', type: 'bytes32' },
{ internalType: 'uint256', name: 'assetInIndex', type: 'uint256' },
{ internalType: 'uint256', name: 'assetOutIndex', type: 'uint256' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'bytes', name: 'userData', type: 'bytes' },
],
internalType: 'struct IVault.BatchSwapStep[]',
name: 'swaps',
type: 'tuple[]',
},
{ internalType: 'contract IAsset[]', name: 'assets', type: 'address[]' },
{
components: [
{ internalType: 'address', name: 'sender', type: 'address' },
{ internalType: 'bool', name: 'fromInternalBalance', type: 'bool' },
{
internalType: 'address payable',
name: 'recipient',
type: 'address',
},
{ internalType: 'bool', name: 'toInternalBalance', type: 'bool' },
],
internalType: 'struct IVault.FundManagement',
name: 'funds',
type: 'tuple',
},
],
name: 'queryBatchSwap',
outputs: [
{ internalType: 'int256[]', name: 'assetDeltas', type: 'int256[]' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'bytes32', name: 'poolId', type: 'bytes32' },
{ internalType: 'address', name: 'sender', type: 'address' },
{ internalType: 'address', name: 'recipient', type: 'address' },
{
components: [
{
internalType: 'contract IAsset[]',
name: 'assets',
type: 'address[]',
},
{
internalType: 'uint256[]',
name: 'minAmountsOut',
type: 'uint256[]',
},
{ internalType: 'bytes', name: 'userData', type: 'bytes' },
{ internalType: 'bool', name: 'toInternalBalance', type: 'bool' },
],
internalType: 'struct IVault.ExitPoolRequest',
name: 'request',
type: 'tuple',
},
],
name: 'queryExit',
outputs: [
{ internalType: 'uint256', name: 'bptIn', type: 'uint256' },
{ internalType: 'uint256[]', name: 'amountsOut', type: 'uint256[]' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'bytes32', name: 'poolId', type: 'bytes32' },
{ internalType: 'address', name: 'sender', type: 'address' },
{ internalType: 'address', name: 'recipient', type: 'address' },
{
components: [
{
internalType: 'contract IAsset[]',
name: 'assets',
type: 'address[]',
},
{
internalType: 'uint256[]',
name: 'maxAmountsIn',
type: 'uint256[]',
},
{ internalType: 'bytes', name: 'userData', type: 'bytes' },
{ internalType: 'bool', name: 'fromInternalBalance', type: 'bool' },
],
internalType: 'struct IVault.JoinPoolRequest',
name: 'request',
type: 'tuple',
},
],
name: 'queryJoin',
outputs: [
{ internalType: 'uint256', name: 'bptOut', type: 'uint256' },
{ internalType: 'uint256[]', name: 'amountsIn', type: 'uint256[]' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
components: [
{ internalType: 'bytes32', name: 'poolId', type: 'bytes32' },
{ internalType: 'enum IVault.SwapKind', name: 'kind', type: 'uint8' },
{ internalType: 'contract IAsset', name: 'assetIn', type: 'address' },
{
internalType: 'contract IAsset',
name: 'assetOut',
type: 'address',
},
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'bytes', name: 'userData', type: 'bytes' },
],
internalType: 'struct IVault.SingleSwap',
name: 'singleSwap',
type: 'tuple',
},
{
components: [
{ internalType: 'address', name: 'sender', type: 'address' },
{ internalType: 'bool', name: 'fromInternalBalance', type: 'bool' },
{
internalType: 'address payable',
name: 'recipient',
type: 'address',
},
{ internalType: 'bool', name: 'toInternalBalance', type: 'bool' },
],
internalType: 'struct IVault.FundManagement',
name: 'funds',
type: 'tuple',
},
],
name: 'querySwap',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'vault',
outputs: [{ internalType: 'contract IVault', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
] as const;
Loading

0 comments on commit 821fcf1

Please sign in to comment.