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",
|
"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",
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user