Skip to content

Commit

Permalink
fix: order of parameters for sponsor tx
Browse files Browse the repository at this point in the history
  • Loading branch information
zhigang1992 committed Dec 11, 2024
1 parent 921ab32 commit c4cbf1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packageManager": "[email protected]",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.4",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
12 changes: 9 additions & 3 deletions src/alexSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getAllPossibleRoute } from './helpers/RouteHelper';
import { getYAmountFromXAmount } from './helpers/RateHelper';
import { fromEntries } from './utils/utils';
import type { AMMRoute } from './utils/ammRouteResolver';
import { broadcastSponsoredTx, requiredStxAmountForSponsorTx, runSponsoredSpotTx } from './helpers/SponsorTxHelper';
import { broadcastSponsoredTx, requiredStxAmountForSponsorTx, runSponsoredSpotTx, SponsoredTxError, SponsoredTxErrorCode } from './helpers/SponsorTxHelper';

Check failure on line 14 in src/alexSDK.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·broadcastSponsoredTx,·requiredStxAmountForSponsorTx,·runSponsoredSpotTx,·SponsoredTxError,·SponsoredTxErrorCode·` with `⏎··broadcastSponsoredTx,⏎··requiredStxAmountForSponsorTx,⏎··runSponsoredSpotTx,⏎··SponsoredTxError,⏎··SponsoredTxErrorCode,⏎`

/**
* The AlexSDK class provides methods for interacting with a decentralized exchange (DEX) system,
Expand Down Expand Up @@ -186,11 +186,14 @@ export class AlexSDK {
to,
route
)
const sponsorFeeAmount = await this.getAmountTo(
const sponsorFeeAmount = from === Currency.STX ? stxAmount : await this.getAmountTo(

Check failure on line 189 in src/alexSDK.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·from·===·Currency.STX·?·stxAmount·:·await·this.getAmountTo(⏎······Currency.STX,⏎······stxAmount,⏎······from⏎····)` with `⏎······from·===·Currency.STX⏎········?·stxAmount⏎········:·await·this.getAmountTo(Currency.STX,·stxAmount,·from);`
Currency.STX,
stxAmount,
from
)
if (sponsorFeeAmount > fromAmount) {
return BigInt(0)

Check failure on line 195 in src/alexSDK.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`
}
return getYAmountFromXAmount(
from,
to,
Expand Down Expand Up @@ -258,11 +261,14 @@ export class AlexSDK {
currencyY,
route
)

Check failure on line 263 in src/alexSDK.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`
const sponsorFeeAmount = await this.getAmountTo(
const sponsorFeeAmount = currencyX === Currency.STX ? stxAmount : await this.getAmountTo(

Check failure on line 264 in src/alexSDK.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·currencyX·===·Currency.STX·?·stxAmount·:·await·this.getAmountTo(⏎······Currency.STX,⏎······stxAmount,⏎······currencyX⏎····)` with `⏎······currencyX·===·Currency.STX⏎········?·stxAmount⏎········:·await·this.getAmountTo(Currency.STX,·stxAmount,·currencyX);`
Currency.STX,
stxAmount,
currencyX
)
if (sponsorFeeAmount > fromAmount) {
throw new SponsoredTxError(SponsoredTxErrorCode.insufficient_funds, 'Insufficient funds to cover sponsor fee')

Check failure on line 270 in src/alexSDK.ts

View workflow job for this annotation

GitHub Actions / build

Replace `SponsoredTxErrorCode.insufficient_funds,·'Insufficient·funds·to·cover·sponsor·fee')` with `⏎········SponsoredTxErrorCode.insufficient_funds,⏎········'Insufficient·funds·to·cover·sponsor·fee'⏎······);`
}
return runSponsoredSpotTx(
stxAddress,
currencyX,
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/SponsorTxHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export function runSponsoredSpotTx(
currencyX: Currency,
currencyY: Currency,
totalAmount: bigint,
feeAmount: bigint,
minDy: bigint,
feeAmount: bigint,
ammPools: PoolData[],
mappings: TokenInfo[],
customRoute?: AMMRouteSegment[]
Expand Down Expand Up @@ -244,6 +244,8 @@ export enum SponsoredTxErrorCode {
"invalid_nonce" = "invalid_nonce",
// Worker failed to broadcast the tx
"broadcast_error" = "broadcast_error",
// Insufficient funds to cover sponsor fee
"insufficient_funds" = "insufficient_funds",
"unknown_error" = "unknown_error",
}

Expand Down

0 comments on commit c4cbf1f

Please sign in to comment.