fix: order of parameters for sponsor tx

This commit is contained in:
Kyle Fang
2024-12-11 04:19:29 +00:00
parent 921ab3201b
commit c4cbf1f45c
3 changed files with 13 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{ {
"packageManager": "pnpm@9.4.0", "packageManager": "pnpm@9.4.0",
"version": "3.0.0-beta.3", "version": "3.0.0-beta.4",
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@@ -11,7 +11,7 @@ import { getAllPossibleRoute } from './helpers/RouteHelper';
import { getYAmountFromXAmount } from './helpers/RateHelper'; import { getYAmountFromXAmount } from './helpers/RateHelper';
import { fromEntries } from './utils/utils'; import { fromEntries } from './utils/utils';
import type { AMMRoute } from './utils/ammRouteResolver'; import type { AMMRoute } from './utils/ammRouteResolver';
import { broadcastSponsoredTx, requiredStxAmountForSponsorTx, runSponsoredSpotTx } from './helpers/SponsorTxHelper'; import { broadcastSponsoredTx, requiredStxAmountForSponsorTx, runSponsoredSpotTx, SponsoredTxError, SponsoredTxErrorCode } from './helpers/SponsorTxHelper';
/** /**
* The AlexSDK class provides methods for interacting with a decentralized exchange (DEX) system, * The AlexSDK class provides methods for interacting with a decentralized exchange (DEX) system,
@@ -186,11 +186,14 @@ export class AlexSDK {
to, to,
route route
) )
const sponsorFeeAmount = await this.getAmountTo( const sponsorFeeAmount = from === Currency.STX ? stxAmount : await this.getAmountTo(
Currency.STX, Currency.STX,
stxAmount, stxAmount,
from from
) )
if (sponsorFeeAmount > fromAmount) {
return BigInt(0)
}
return getYAmountFromXAmount( return getYAmountFromXAmount(
from, from,
to, to,
@@ -258,11 +261,14 @@ export class AlexSDK {
currencyY, currencyY,
route route
) )
const sponsorFeeAmount = await this.getAmountTo( const sponsorFeeAmount = currencyX === Currency.STX ? stxAmount : await this.getAmountTo(
Currency.STX, Currency.STX,
stxAmount, stxAmount,
currencyX currencyX
) )
if (sponsorFeeAmount > fromAmount) {
throw new SponsoredTxError(SponsoredTxErrorCode.insufficient_funds, 'Insufficient funds to cover sponsor fee')
}
return runSponsoredSpotTx( return runSponsoredSpotTx(
stxAddress, stxAddress,
currencyX, currencyX,

View File

@@ -21,8 +21,8 @@ export function runSponsoredSpotTx(
currencyX: Currency, currencyX: Currency,
currencyY: Currency, currencyY: Currency,
totalAmount: bigint, totalAmount: bigint,
feeAmount: bigint,
minDy: bigint, minDy: bigint,
feeAmount: bigint,
ammPools: PoolData[], ammPools: PoolData[],
mappings: TokenInfo[], mappings: TokenInfo[],
customRoute?: AMMRouteSegment[] customRoute?: AMMRouteSegment[]
@@ -244,6 +244,8 @@ export enum SponsoredTxErrorCode {
"invalid_nonce" = "invalid_nonce", "invalid_nonce" = "invalid_nonce",
// Worker failed to broadcast the tx // Worker failed to broadcast the tx
"broadcast_error" = "broadcast_error", "broadcast_error" = "broadcast_error",
// Insufficient funds to cover sponsor fee
"insufficient_funds" = "insufficient_funds",
"unknown_error" = "unknown_error", "unknown_error" = "unknown_error",
} }