-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract SwapApi type, add default implementation WIP🚧
- Loading branch information
Showing
5 changed files
with
62 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import defaultApi from './defaultApi'; | ||
import mintVault from './mintVault'; | ||
import redeemMix from './redeemMix'; | ||
|
||
export const swapActions = { | ||
'swap-curve': mintVault, | ||
'swap-zapper': redeemMix, | ||
'mint-vault': redeemMix, | ||
'redeem-mix': redeemMix, | ||
'wrap-oeth': redeemMix, | ||
'unwrap-woeth': redeemMix, | ||
import type { SwapAction, SwapApi } from '../types'; | ||
|
||
export const swapActions: Record<SwapAction, SwapApi> = { | ||
'swap-curve': { ...defaultApi, ...mintVault }, | ||
'swap-zapper': { ...defaultApi, ...redeemMix }, | ||
'mint-vault': { ...defaultApi }, | ||
'redeem-mix': { ...defaultApi }, | ||
'wrap-oeth': { ...defaultApi }, | ||
'unwrap-woeth': { ...defaultApi }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,13 @@ | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
import type { SwapApi, SwapState } from '../types'; | ||
|
||
import { getAvailableRoutes } from '../utils'; | ||
|
||
import type { SwapState } from '../types'; | ||
|
||
const estimateAmount = async ({ | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
}: Pick<SwapState, 'tokenIn' | 'tokenOut' | 'amountIn'>) => { | ||
const estimateAmount = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
if (amountIn === 0n) { | ||
return 0n; | ||
} | ||
|
||
return amountIn; | ||
}; | ||
|
||
const estimateRoutes = async ({ | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
}: Pick<SwapState, 'tokenIn' | 'tokenOut' | 'amountIn'>) => { | ||
if (amountIn === 0n) { | ||
return; | ||
} | ||
return getAvailableRoutes(tokenIn, tokenOut); | ||
}; | ||
|
||
const swap = async ({ | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
swapRoute, | ||
}: Pick<SwapState, 'tokenIn' | 'tokenOut' | 'amountIn' | 'swapRoute'>) => { | ||
if (amountIn === 0n || isNilOrEmpty(swapRoute)) { | ||
return; | ||
} | ||
return amountIn * 2n; | ||
}; | ||
|
||
export default { | ||
estimateAmount, | ||
estimateRoutes, | ||
swap, | ||
}; | ||
} as Partial<SwapApi>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters