Skip to content

Commit

Permalink
Fix ES linter warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhigang1992 committed Nov 28, 2024
1 parent ef7caab commit 5d3dea0
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export type Currency = string & {
readonly brand: unique symbol;
};

// ignore duplicate
// eslint-disable-next-line @typescript-eslint/no-redeclare
/** The `Currency` namespace contains predefined constants for tokens in the AlexSDK.*/
// eslint-disable-next-line @typescript-eslint/no-redeclare
export namespace Currency {
/** Represents the `STX` token */
export const STX = createCurrency('token-wstx');
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/FeeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { unwrapResponse } from 'clarity-codegen';
import { readonlyCall } from '../utils/readonlyCallExecutor';
import type { Currency } from '../currency';
import type { PoolData } from '../types';
import { type AMMRouteSegment, resolveAmmRoute } from '../utils/ammRouteResolver';
import {
type AMMRouteSegment,
resolveAmmRoute,
} from '../utils/ammRouteResolver';
import { hasLength } from '../utils/arrayHelper';

export async function getLiquidityProviderFee(
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/RateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { unwrapResponse } from 'clarity-codegen';
import { readonlyCall } from '../utils/readonlyCallExecutor';
import type { Currency } from '../currency';
import type { PoolData } from '../types';
import { type AMMRouteSegment, resolveAmmRoute } from '../utils/ammRouteResolver';
import {
type AMMRouteSegment,
resolveAmmRoute,
} from '../utils/ammRouteResolver';
import { hasLength } from '../utils/arrayHelper';

export const getYAmountFromXAmount = async (
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/RouteHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Currency } from '../currency';
import type { PoolData } from '../types';
import { type AMMRouteSegment, resolveAmmRoute } from '../utils/ammRouteResolver';
import {
type AMMRouteSegment,
resolveAmmRoute,
} from '../utils/ammRouteResolver';

export async function getAllPossibleRoute(
from: Currency,
Expand Down
40 changes: 33 additions & 7 deletions src/helpers/SwapHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { AlexContracts } from '../generated/smartContract/contracts_Alex';
import { configs } from '../config';
import type { Currency } from '../currency';
import type { PoolData, TokenInfo } from '../types';
import { type AMMRouteSegment, resolveAmmRoute } from '../utils/ammRouteResolver';
import {
type AMMRouteSegment,
resolveAmmRoute,
} from '../utils/ammRouteResolver';
import { transferFactory } from '../utils/postConditions';
import { hasLength } from '../utils/arrayHelper';

Expand All @@ -38,7 +41,9 @@ const composeTx = <
: never,
postConditions: (FungiblePostCondition | StxPostCondition)[]
): TxToBroadCast => {
const functionDescriptor = AlexContracts[contractName][functionName] as OpenCallFunctionDescriptor;
const functionDescriptor = AlexContracts[contractName][
functionName
] as OpenCallFunctionDescriptor;
const clarityArgs = functionDescriptor.input.map((arg) =>
arg.type.encode(args[arg.name])
);
Expand All @@ -61,7 +66,8 @@ export function runSpot(
mappings: TokenInfo[],
customRoute?: AMMRouteSegment[]
): TxToBroadCast {
const ammRoute = customRoute ?? resolveAmmRoute(currencyX, currencyY, ammPools);
const ammRoute =
customRoute ?? resolveAmmRoute(currencyX, currencyY, ammPools);
const getContractId = (currency: Currency) => {
const mapping = mappings.find((x) => x.id === currency);
if (!mapping) {
Expand Down Expand Up @@ -90,7 +96,12 @@ export function runSpot(
},
[
transfer(stxAddress, currencyX, fromAmount),
transfer(AlexVault, currencyY, minDy, FungibleConditionCode.GreaterEqual),
transfer(
AlexVault,
currencyY,
minDy,
FungibleConditionCode.GreaterEqual
),
]
);
}
Expand Down Expand Up @@ -123,7 +134,12 @@ export function runSpot(
BigInt(0),
FungibleConditionCode.GreaterEqual
),
transfer(AlexVault, currencyY, minDy, FungibleConditionCode.GreaterEqual),
transfer(
AlexVault,
currencyY,
minDy,
FungibleConditionCode.GreaterEqual
),
]
);
}
Expand Down Expand Up @@ -170,7 +186,12 @@ export function runSpot(
BigInt(0),
FungibleConditionCode.GreaterEqual
),
transfer(AlexVault, currencyY, minDy, FungibleConditionCode.GreaterEqual),
transfer(
AlexVault,
currencyY,
minDy,
FungibleConditionCode.GreaterEqual
),
]
);
}
Expand Down Expand Up @@ -231,7 +252,12 @@ export function runSpot(
BigInt(0),
FungibleConditionCode.GreaterEqual
),
transfer(AlexVault, currencyY, minDy, FungibleConditionCode.GreaterEqual),
transfer(
AlexVault,
currencyY,
minDy,
FungibleConditionCode.GreaterEqual
),
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/arrayHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export function hasLength<T>(x: T[], length: 4): x is [T, T, T, T];
export function hasLength<T>(x: T[], length: 5): x is [T, T, T, T, T];
export function hasLength<T>(x: T[], length: number): boolean {
return x.length === length;
}
}
2 changes: 1 addition & 1 deletion src/utils/fetchData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function fetchBalanceForAccount(
client: {
...STACKS_MAINNET.client,
baseUrl: configs.READONLY_CALL_API_HOST,
}
},
},
});
const amount = unwrapResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/utils/postConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const transferFactory =
const nativeAmount = (amount * BigInt(scale)) / BigInt(1e8);

// validate sender address
addressToString(parsePrincipalString(senderAddress).address)
addressToString(parsePrincipalString(senderAddress).address);

if (currency === Currency.STX) {
return {
type: 'stx-postcondition',
Expand All @@ -50,8 +50,8 @@ export const transferFactory =
}

// For rebase tokens, use GreaterEqual with amount 0
const finalConditionCode = mapping.isRebaseToken
? FungibleConditionCode.GreaterEqual
const finalConditionCode = mapping.isRebaseToken
? FungibleConditionCode.GreaterEqual
: conditionCode;
const finalAmount = mapping.isRebaseToken ? BigInt(0) : nativeAmount;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/readonlyCallExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const defaultReadonlyCallExecutor: ReadonlyCallExecutor = async (options) => {
client: {
...STACKS_MAINNET.client,
baseUrl: configs.READONLY_CALL_API_HOST,
}
},
},
});
};
Expand Down
6 changes: 2 additions & 4 deletions test/alexSDK.mock-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
dummyTokenC,
DUMMY_DEPLOYER,
} from './mock-data/alexSDKMockResponses';
import { cvToValue, FungibleConditionCode } from '@stacks/transactions';
import { cvToValue } from '@stacks/transactions';

const sdk = new AlexSDK();

Expand Down Expand Up @@ -134,9 +134,7 @@ describe('AlexSDK - mock helpers', () => {
expect(cvToValue(result.functionArgs[3])).toStrictEqual(dummyFactorA);
expect(cvToValue(result.functionArgs[4])).toStrictEqual(dummyFactorB);
expect(cvToValue(result.functionArgs[5])).toStrictEqual(amount);
expect(result.postConditions[0].condition).toStrictEqual(
'gte'
);
expect(result.postConditions[0].condition).toStrictEqual('gte');
expect(result.postConditions[0].amount).toStrictEqual(BigInt(0));
});

Expand Down
6 changes: 5 additions & 1 deletion test/alexSDK.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ describe('AlexSDK', () => {

it('Attempt to Get Rate with an overflowing From amount (parseReadOnlyResponse)', async () => {
await expect(
sdk.getAmountTo(Currency.STX, BigInt('9999999992233720368547758007'), tokenDiko)
sdk.getAmountTo(
Currency.STX,
BigInt('9999999992233720368547758007'),
tokenDiko
)
).rejects.toThrow('ArithmeticOverflow');
}, 10000);

Expand Down

0 comments on commit 5d3dea0

Please sign in to comment.