mirror of
https://github.com/alexgo-io/alex-sdk.git
synced 2026-01-12 14:25:02 +08:00
feat: use separate file to avoid cycle reference
This commit is contained in:
48
src/alexSDK.ts
Normal file
48
src/alexSDK.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Currency } from './currency';
|
||||
import { getLiquidityProviderFee } from './helpers/FeeHelper';
|
||||
import { AMMSwapPool } from './utils/ammPool';
|
||||
import { getRoute } from './helpers/RouteHelper';
|
||||
import { getYAmountFromXAmount } from './helpers/RateHelper';
|
||||
import { runSpot, TxToBroadCast } from './helpers/SwapHelper';
|
||||
import { findCurrencyByNativeAddress } from './utils/currencyUtils';
|
||||
|
||||
export class AlexSDK {
|
||||
getFee(from: Currency, to: Currency): Promise<bigint> {
|
||||
return getLiquidityProviderFee(from, to, AMMSwapPool.ammTokens);
|
||||
}
|
||||
|
||||
getRouter(from: Currency, to: Currency): Promise<Currency[]> {
|
||||
return getRoute(from, to, AMMSwapPool.ammTokens);
|
||||
}
|
||||
|
||||
getAmountTo(
|
||||
from: Currency,
|
||||
fromAmount: bigint,
|
||||
to: Currency,
|
||||
): Promise<bigint> {
|
||||
return getYAmountFromXAmount(from, to, fromAmount, AMMSwapPool.ammTokens);
|
||||
}
|
||||
|
||||
runSwap(
|
||||
stxAddress: string,
|
||||
currencyX: Currency,
|
||||
currencyY: Currency,
|
||||
fromAmount: bigint,
|
||||
minDy: bigint,
|
||||
router: Currency[],
|
||||
): TxToBroadCast {
|
||||
return runSpot(
|
||||
stxAddress,
|
||||
currencyX,
|
||||
currencyY,
|
||||
fromAmount,
|
||||
minDy,
|
||||
router,
|
||||
AMMSwapPool.ammTokens,
|
||||
);
|
||||
}
|
||||
|
||||
getCurrencyFrom(address: string): Currency | undefined {
|
||||
return findCurrencyByNativeAddress(address);
|
||||
}
|
||||
}
|
||||
13
src/currency.ts
Normal file
13
src/currency.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export enum Currency {
|
||||
ALEX = 'age000-governance-token',
|
||||
USDA = 'token-wusda',
|
||||
STX = 'token-wstx',
|
||||
BANANA = 'token-wban',
|
||||
XBTC = 'token-wbtc',
|
||||
DIKO = 'token-wdiko',
|
||||
SLIME = 'token-wslm',
|
||||
XUSD = 'token-wxusd',
|
||||
MIA = 'token-wmia',
|
||||
NYCC = 'token-wnycc',
|
||||
CORGI = 'token-wcorgi',
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { AlexSDK, Currency } from '../index';
|
||||
import { AMMSwapPool } from '../utils/ammPool';
|
||||
import { unwrapResponse } from 'clarity-codegen';
|
||||
import { readonlyCall } from '../utils/readonlyCallExecutor';
|
||||
import { Currency } from '../currency';
|
||||
import { AlexSDK } from '../alexSDK';
|
||||
|
||||
export async function getLiquidityProviderFee(
|
||||
tokenX: Currency,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { AlexSDK, Currency } from '../index';
|
||||
import { AMMSwapPool } from '../utils/ammPool';
|
||||
import { unwrapResponse } from 'clarity-codegen';
|
||||
import { readonlyCall } from '../utils/readonlyCallExecutor';
|
||||
import { Currency } from '../currency';
|
||||
import { AlexSDK } from '../alexSDK';
|
||||
|
||||
export const getYAmountFromXAmount = async (
|
||||
tokenX: Currency,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { AlexSDK, Currency } from '../index';
|
||||
import { AMMSwapPool } from '../utils/ammPool';
|
||||
import { unwrapResponse } from 'clarity-codegen';
|
||||
import { readonlyCall } from '../utils/readonlyCallExecutor';
|
||||
import { Currency } from '../currency';
|
||||
import { AlexSDK } from '../alexSDK';
|
||||
|
||||
export async function getRoute(
|
||||
from: Currency,
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from 'clarity-codegen';
|
||||
import { AlexContracts } from '../generated/smartContract/contracts_Alex';
|
||||
import { CONTRACT_DEPLOYER } from '../config';
|
||||
import { Currency } from '../index';
|
||||
import { Currency } from '../currency';
|
||||
|
||||
export type TxToBroadCast = {
|
||||
contractAddress: string;
|
||||
|
||||
59
src/index.ts
59
src/index.ts
@@ -1,57 +1,2 @@
|
||||
import { getLiquidityProviderFee } from './helpers/FeeHelper';
|
||||
import { AMMSwapPool } from './utils/ammPool';
|
||||
import { getRoute } from './helpers/RouteHelper';
|
||||
import { getYAmountFromXAmount } from './helpers/RateHelper';
|
||||
import { runSpot, TxToBroadCast } from './helpers/SwapHelper';
|
||||
import { findCurrencyByNativeAddress } from './utils/currencyUtils';
|
||||
|
||||
export enum Currency {
|
||||
ALEX = 'age000-governance-token',
|
||||
USDA = 'token-wusda',
|
||||
STX = 'token-wstx',
|
||||
BANANA = 'token-wban',
|
||||
XBTC = 'token-wbtc',
|
||||
DIKO = 'token-wdiko',
|
||||
SLIME = 'token-wslm',
|
||||
XUSD = 'token-wxusd',
|
||||
MIA = 'token-wmia',
|
||||
NYCC = 'token-wnycc',
|
||||
CORGI = 'token-wcorgi',
|
||||
}
|
||||
|
||||
export class AlexSDK {
|
||||
getFee(from: Currency, to: Currency): Promise<bigint> {
|
||||
return getLiquidityProviderFee(from, to, AMMSwapPool.ammTokens);
|
||||
}
|
||||
getRouter(from: Currency, to: Currency): Promise<Currency[]> {
|
||||
return getRoute(from, to, AMMSwapPool.ammTokens);
|
||||
}
|
||||
getAmountTo(
|
||||
from: Currency,
|
||||
fromAmount: bigint,
|
||||
to: Currency
|
||||
): Promise<bigint> {
|
||||
return getYAmountFromXAmount(from, to, fromAmount, AMMSwapPool.ammTokens);
|
||||
}
|
||||
runSwap(
|
||||
stxAddress: string,
|
||||
currencyX: Currency,
|
||||
currencyY: Currency,
|
||||
fromAmount: bigint,
|
||||
minDy: bigint,
|
||||
router: Currency[]
|
||||
): TxToBroadCast {
|
||||
return runSpot(
|
||||
stxAddress,
|
||||
currencyX,
|
||||
currencyY,
|
||||
fromAmount,
|
||||
minDy,
|
||||
router,
|
||||
AMMSwapPool.ammTokens
|
||||
);
|
||||
}
|
||||
getCurrencyFrom(address: string): Currency | undefined {
|
||||
return findCurrencyByNativeAddress(address);
|
||||
}
|
||||
}
|
||||
export * from './currency';
|
||||
export * from './alexSDK';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { AMMSwapRoute, resolveAmmRoute } from './ammRouteResolver';
|
||||
import { bridgeHelperResolver } from './bridgeHelperResolver';
|
||||
import { assertNever } from './utils';
|
||||
import { Currency } from '../index';
|
||||
import { Currency } from '../currency';
|
||||
|
||||
export namespace AMMSwapPool {
|
||||
export enum Pool {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
import { AMMSwapPool } from './ammPool';
|
||||
import { Currency } from '../index';
|
||||
import { Currency } from '../currency';
|
||||
|
||||
export function bridgeHelperResolver(
|
||||
from: Currency,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Currency } from '../index';
|
||||
import { Currency } from '../currency';
|
||||
|
||||
const tokenNativeAddressDefinition = {
|
||||
'age000-governance-token':
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from '@stacks/transactions';
|
||||
import { CONTRACT_DEPLOYER } from '../config';
|
||||
import { getCurrencyNativeAddress, getCurrencyNativeScale } from './currencyUtils';
|
||||
import { Currency } from '../index';
|
||||
import { Currency } from '../currency';
|
||||
|
||||
export const AlexVault = `${CONTRACT_DEPLOYER}.alex-vault`;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { AlexSDK, Currency } from '../src';
|
||||
import { CONTRACT_DEPLOYER } from '../src/config';
|
||||
import { Currency } from '../src/currency';
|
||||
import { AlexSDK } from '../src/alexSDK';
|
||||
|
||||
describe.skip('AlexSDK', () => {
|
||||
it('Get fee', async () => {
|
||||
|
||||
Reference in New Issue
Block a user