-
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.
- add common estimation methods - wrap/unwrap estimate implementation - find best route
- Loading branch information
Showing
11 changed files
with
258 additions
and
149 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 |
---|---|---|
@@ -1,33 +1,56 @@ | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
|
||
import { getAvailableRoutes } from '../utils'; | ||
import type { | ||
EstimateAmount, | ||
EstimateGas, | ||
EstimateRoute, | ||
Swap, | ||
} from '../types'; | ||
|
||
const estimateAmount: EstimateAmount = async ( | ||
_tokenIn, | ||
_tokenOut, | ||
amountIn, | ||
) => { | ||
if (amountIn === 0n) { | ||
return 0n; | ||
} | ||
|
||
import type { SwapApi, SwapState } from '../types'; | ||
return amountIn; | ||
}; | ||
|
||
const estimateAmount = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
const estimateGas: EstimateGas = async (_tokenIn, _tokenOut, amountIn) => { | ||
if (amountIn === 0n) { | ||
return 0n; | ||
} | ||
|
||
return amountIn; | ||
return 0n; | ||
}; | ||
|
||
const estimateRoutes = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
const estimateRoute: EstimateRoute = async ( | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
route, | ||
) => { | ||
if (amountIn === 0n) { | ||
return []; | ||
return { ...route, estimatedAmount: 0n, gas: 0n, rate: 0 }; | ||
} | ||
|
||
return getAvailableRoutes(tokenIn, tokenOut); | ||
const estimatedAmount = await estimateAmount(tokenIn, tokenOut, amountIn); | ||
|
||
return { ...route, estimatedAmount, gas: 0n, rate: 0 }; | ||
}; | ||
|
||
const swap = async ({ tokenIn, tokenOut, amountIn, swapRoute }: SwapState) => { | ||
if (amountIn === 0n || isNilOrEmpty(swapRoute)) { | ||
const swap: Swap = async (_tokenIn, _tokenOut, amountIn, route) => { | ||
if (amountIn === 0n || isNilOrEmpty(route)) { | ||
return; | ||
} | ||
}; | ||
|
||
export default { | ||
estimateAmount, | ||
estimateRoutes, | ||
estimateGas, | ||
estimateRoute, | ||
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,31 +1,13 @@ | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
import type { EstimateAmount } from '../types'; | ||
|
||
import type { SwapApi, SwapState } from '../types'; | ||
|
||
const estimateAmount = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
const estimateAmount: EstimateAmount = async (tokenIn, tokenOut, amountIn) => { | ||
if (amountIn === 0n) { | ||
return 0n; | ||
} | ||
|
||
return amountIn * 2n; | ||
}; | ||
|
||
const estimateRoutes = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
if (amountIn === 0n) { | ||
return []; | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
const swap = async ({ tokenIn, tokenOut, amountIn, swapRoute }: SwapState) => { | ||
if (amountIn === 0n || isNilOrEmpty(swapRoute)) { | ||
return; | ||
} | ||
}; | ||
|
||
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
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,33 +1,13 @@ | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
import type { EstimateAmount } from '../types'; | ||
|
||
import { getAvailableRoutes } from '../utils'; | ||
|
||
import type { SwapApi, SwapState } from '../types'; | ||
|
||
const estimateAmount = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
const estimateAmount: EstimateAmount = async (tokenIn, tokenOut, amountIn) => { | ||
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,33 +1,13 @@ | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
import type { EstimateAmount } from '../types'; | ||
|
||
import { getAvailableRoutes } from '../utils'; | ||
|
||
import type { SwapApi, SwapState } from '../types'; | ||
|
||
const estimateAmount = async ({ tokenIn, tokenOut, amountIn }: SwapState) => { | ||
const estimateAmount: EstimateAmount = async (tokenIn, tokenOut, amountIn) => { | ||
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
Oops, something went wrong.