mirror of
https://github.com/alexgo-io/alex-sdk.git
synced 2026-01-12 14:25:02 +08:00
fix: order of parameters for sponsor tx
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"packageManager": "pnpm@9.4.0",
|
||||
"version": "3.0.0-beta.3",
|
||||
"version": "3.0.0-beta.4",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
||||
@@ -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';
|
||||
|
||||
/**
|
||||
* The AlexSDK class provides methods for interacting with a decentralized exchange (DEX) system,
|
||||
@@ -186,11 +186,14 @@ export class AlexSDK {
|
||||
to,
|
||||
route
|
||||
)
|
||||
const sponsorFeeAmount = await this.getAmountTo(
|
||||
const sponsorFeeAmount = from === Currency.STX ? stxAmount : await this.getAmountTo(
|
||||
Currency.STX,
|
||||
stxAmount,
|
||||
from
|
||||
)
|
||||
if (sponsorFeeAmount > fromAmount) {
|
||||
return BigInt(0)
|
||||
}
|
||||
return getYAmountFromXAmount(
|
||||
from,
|
||||
to,
|
||||
@@ -258,11 +261,14 @@ export class AlexSDK {
|
||||
currencyY,
|
||||
route
|
||||
)
|
||||
const sponsorFeeAmount = await this.getAmountTo(
|
||||
const sponsorFeeAmount = currencyX === Currency.STX ? stxAmount : await this.getAmountTo(
|
||||
Currency.STX,
|
||||
stxAmount,
|
||||
currencyX
|
||||
)
|
||||
if (sponsorFeeAmount > fromAmount) {
|
||||
throw new SponsoredTxError(SponsoredTxErrorCode.insufficient_funds, 'Insufficient funds to cover sponsor fee')
|
||||
}
|
||||
return runSponsoredSpotTx(
|
||||
stxAddress,
|
||||
currencyX,
|
||||
|
||||
@@ -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[]
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user