Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
alessey committed Jan 22, 2025
1 parent 3f1108c commit 3d34cd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/api/buildSwapTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import type { BuildSwapTransaction } from './types';
*/
import { getAPIParamsForToken } from './utils/getAPIParamsForToken';
import { getSwapTransaction } from './utils/getSwapTransaction';
import type { Address } from 'viem';

vi.mock('@/core/network/request');

const testFromAddress = '0x6Cd01c0F55ce9E0Bf78f5E90f72b4345b16d515d';
const testFromAddress: Address = '0x6Cd01c0F55ce9E0Bf78f5E90f72b4345b16d515d';
const testAmount = '3305894409732200';
const testAmountReference = 'from' as const;

Expand All @@ -26,7 +27,7 @@ describe('buildSwapTransaction', () => {
it('should return a swap', async () => {
const mockParams = {
useAggregator: true,
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress ,
amountReference: testAmountReference,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand Down Expand Up @@ -122,7 +123,7 @@ describe('buildSwapTransaction', () => {
it('should return a swap with useAggregator=false', async () => {
const mockParams = {
useAggregator: false,
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: testAmountReference,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand Down Expand Up @@ -204,7 +205,7 @@ describe('buildSwapTransaction', () => {
it('should return an error for an unsupported amount reference', async () => {
const mockParams = {
useAggregator: true,
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: 'to' as const,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand All @@ -222,7 +223,7 @@ describe('buildSwapTransaction', () => {
const mockParams = {
useAggregator: true,
maxSlippage: '3',
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: testAmountReference,
from: DEGEN_TOKEN,
to: ETH_TOKEN,
Expand Down Expand Up @@ -311,7 +312,7 @@ describe('buildSwapTransaction', () => {
it('should return an error if sendRequest fails', async () => {
const mockParams = {
useAggregator: true,
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: testAmountReference,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand All @@ -337,7 +338,7 @@ describe('buildSwapTransaction', () => {
it('should return an error object from buildSwapTransaction', async () => {
const mockParams = {
useAggregator: true,
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: testAmountReference,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand Down Expand Up @@ -368,7 +369,7 @@ describe('buildSwapTransaction', () => {
it('should return an error object from buildSwapTransaction for invalid `amount` input', async () => {
const mockParams = {
useAggregator: true,
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: testAmountReference,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand All @@ -387,7 +388,7 @@ describe('buildSwapTransaction', () => {
const mockParams = {
useAggregator: true,
maxSlippage: '3',
fromAddress: testFromAddress as `0x${string}`,
fromAddress: testFromAddress,
amountReference: testAmountReference,
from: ETH_TOKEN,
to: DEGEN_TOKEN,
Expand Down
6 changes: 3 additions & 3 deletions src/buy/utils/getBuyQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export async function getBuyQuote({
let response: GetSwapQuoteResponse | undefined;
// only fetch quote if the from and to tokens are different
if (to?.symbol !== from?.symbol) {
// we are trying to swap from the token we are buying "to" the token we are selling
// instead of using amountRefence: 'to', we can use amountRefence: 'from'
// and then swap to and from to get the quote
// switching to and from here
// instead of getting a quote for how much of X do we need to sell to get the input token amount
// we can get a quote for how much of X we will recieve if we sell the input token amount
response = await getSwapQuote({
amount,
amountReference: 'from',
Expand Down

0 comments on commit 3d34cd3

Please sign in to comment.