mirror of
https://github.com/alexgo-io/alex-sdk.git
synced 2026-04-29 10:15:45 +08:00
fix: prioritize amm pool over bridge
This commit is contained in:
@@ -52,32 +52,6 @@ export async function getLiquidityProviderFee(
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
|
||||
const reachableInAmm1_1 = AMMSwapPool.reachableInAMM(
|
||||
tokenX,
|
||||
tokenY,
|
||||
ammV1_1Pools
|
||||
);
|
||||
if (reachableInAmm1_1.type === 'fromAmm') {
|
||||
return await readonlyCall(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'fee-helper-from-amm',
|
||||
{
|
||||
'token-x': reachableInAmm1_1.tokenX,
|
||||
'token-y': reachableInAmm1_1.tokenY,
|
||||
'token-z': reachableInAmm1_1.tokenZ,
|
||||
'factor-x': reachableInAmm1_1.factorX,
|
||||
}
|
||||
).then(unwrapResponse);
|
||||
}
|
||||
if (reachableInAmm1_1.type === 'toAmm') {
|
||||
return await readonlyCall('swap-helper-bridged-v1-1', 'fee-helper-to-amm', {
|
||||
'token-x': reachableInAmm1_1.tokenX,
|
||||
'token-y': reachableInAmm1_1.tokenY,
|
||||
'token-z': reachableInAmm1_1.tokenZ,
|
||||
'factor-y': reachableInAmm1_1.factorY,
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
|
||||
const ammRoute = AMMSwapPool.getRoute(tokenX, tokenY, ammPools);
|
||||
if (ammRoute.length === 1) {
|
||||
return await readonlyCall('amm-swap-pool', 'fee-helper', {
|
||||
@@ -120,6 +94,32 @@ export async function getLiquidityProviderFee(
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
|
||||
const reachableInAmm1_1 = AMMSwapPool.reachableInAMM(
|
||||
tokenX,
|
||||
tokenY,
|
||||
ammV1_1Pools
|
||||
);
|
||||
if (reachableInAmm1_1.type === 'fromAmm') {
|
||||
return await readonlyCall(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'fee-helper-from-amm',
|
||||
{
|
||||
'token-x': reachableInAmm1_1.tokenX,
|
||||
'token-y': reachableInAmm1_1.tokenY,
|
||||
'token-z': reachableInAmm1_1.tokenZ,
|
||||
'factor-x': reachableInAmm1_1.factorX,
|
||||
}
|
||||
).then(unwrapResponse);
|
||||
}
|
||||
if (reachableInAmm1_1.type === 'toAmm') {
|
||||
return await readonlyCall('swap-helper-bridged-v1-1', 'fee-helper-to-amm', {
|
||||
'token-x': reachableInAmm1_1.tokenX,
|
||||
'token-y': reachableInAmm1_1.tokenY,
|
||||
'token-z': reachableInAmm1_1.tokenZ,
|
||||
'factor-y': reachableInAmm1_1.factorY,
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
|
||||
const reachableInAmm = AMMSwapPool.reachableInAMM(tokenX, tokenY, ammPools);
|
||||
if (reachableInAmm.type === 'fromAmm') {
|
||||
return await readonlyCall('swap-helper-bridged', 'fee-helper-from-amm', {
|
||||
|
||||
@@ -56,34 +56,6 @@ export const getYAmountFromXAmount = async (
|
||||
dx: fromAmount,
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
const reachableInAMMV1_1 = AMMSwapPool.reachableInAMM(
|
||||
tokenX,
|
||||
tokenY,
|
||||
ammV1_1Tokens
|
||||
);
|
||||
if (reachableInAMMV1_1.type === 'fromAmm') {
|
||||
return await readonlyCall(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'get-helper-from-amm',
|
||||
{
|
||||
dx: fromAmount,
|
||||
'token-x': reachableInAMMV1_1.tokenX,
|
||||
'token-y': reachableInAMMV1_1.tokenY,
|
||||
'token-z': reachableInAMMV1_1.tokenZ,
|
||||
'factor-x': reachableInAMMV1_1.factorX,
|
||||
}
|
||||
).then(unwrapResponse);
|
||||
}
|
||||
if (reachableInAMMV1_1.type === 'toAmm') {
|
||||
return await readonlyCall('swap-helper-bridged-v1-1', 'get-helper-to-amm', {
|
||||
dx: fromAmount,
|
||||
'token-x': reachableInAMMV1_1.tokenX,
|
||||
'token-y': reachableInAMMV1_1.tokenY,
|
||||
'token-z': reachableInAMMV1_1.tokenZ,
|
||||
'factor-y': reachableInAMMV1_1.factorY,
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
|
||||
const ammRoute = AMMSwapPool.getRoute(tokenX, tokenY, ammPools);
|
||||
if (ammRoute.length === 1) {
|
||||
return await readonlyCall('amm-swap-pool', 'get-helper', {
|
||||
@@ -129,6 +101,33 @@ export const getYAmountFromXAmount = async (
|
||||
dx: fromAmount,
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
const reachableInAMMV1_1 = AMMSwapPool.reachableInAMM(
|
||||
tokenX,
|
||||
tokenY,
|
||||
ammV1_1Tokens
|
||||
);
|
||||
if (reachableInAMMV1_1.type === 'fromAmm') {
|
||||
return await readonlyCall(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'get-helper-from-amm',
|
||||
{
|
||||
dx: fromAmount,
|
||||
'token-x': reachableInAMMV1_1.tokenX,
|
||||
'token-y': reachableInAMMV1_1.tokenY,
|
||||
'token-z': reachableInAMMV1_1.tokenZ,
|
||||
'factor-x': reachableInAMMV1_1.factorX,
|
||||
}
|
||||
).then(unwrapResponse);
|
||||
}
|
||||
if (reachableInAMMV1_1.type === 'toAmm') {
|
||||
return await readonlyCall('swap-helper-bridged-v1-1', 'get-helper-to-amm', {
|
||||
dx: fromAmount,
|
||||
'token-x': reachableInAMMV1_1.tokenX,
|
||||
'token-y': reachableInAMMV1_1.tokenY,
|
||||
'token-z': reachableInAMMV1_1.tokenZ,
|
||||
'factor-y': reachableInAMMV1_1.factorY,
|
||||
}).then(unwrapResponse);
|
||||
}
|
||||
const reachableInAMM = AMMSwapPool.reachableInAMM(tokenX, tokenY, ammPools);
|
||||
if (reachableInAMM.type === 'fromAmm') {
|
||||
return await readonlyCall('swap-helper-bridged', 'get-helper-from-amm', {
|
||||
|
||||
@@ -239,86 +239,6 @@ export function runSpot(
|
||||
);
|
||||
}
|
||||
|
||||
const reachableInAMMV1_1 = AMMSwapPool.reachableInAMM(
|
||||
currencyX,
|
||||
currencyY,
|
||||
ammPools
|
||||
);
|
||||
if (reachableInAMMV1_1.type === 'fromAmm') {
|
||||
return composeTx(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'swap-helper-from-amm',
|
||||
{
|
||||
'token-x-trait': reachableInAMMV1_1.tokenX,
|
||||
'token-y-trait': reachableInAMMV1_1.tokenY,
|
||||
'token-z-trait': reachableInAMMV1_1.tokenZ,
|
||||
dx: fromAmount,
|
||||
'min-dz': minDy,
|
||||
'factor-x': reachableInAMMV1_1.factorX,
|
||||
},
|
||||
[
|
||||
transfer(stxAddress, currencyX, fromAmount),
|
||||
...middleSteps.flatMap((middle, index) => [
|
||||
transfer(
|
||||
index === 0 ? AlexVaultV1_1 : AlexVault,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
transfer(
|
||||
stxAddress,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]),
|
||||
transfer(
|
||||
AlexVault,
|
||||
currencyY,
|
||||
minDy,
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
if (reachableInAMMV1_1.type === 'toAmm') {
|
||||
return composeTx(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'swap-helper-to-amm',
|
||||
{
|
||||
'token-x-trait': reachableInAMMV1_1.tokenX,
|
||||
'token-y-trait': reachableInAMMV1_1.tokenY,
|
||||
'token-z-trait': reachableInAMMV1_1.tokenZ,
|
||||
dx: fromAmount,
|
||||
'min-dz': minDy,
|
||||
'factor-y': reachableInAMMV1_1.factorY,
|
||||
},
|
||||
[
|
||||
transfer(stxAddress, currencyX, fromAmount),
|
||||
...middleSteps.flatMap((middle) => [
|
||||
transfer(
|
||||
AlexVault,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
transfer(
|
||||
stxAddress,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]),
|
||||
transfer(
|
||||
AlexVaultV1_1,
|
||||
currencyY,
|
||||
minDy,
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
const ammRoute = AMMSwapPool.getRoute(currencyX, currencyY, ammPools);
|
||||
if (ammRoute.length === 1) {
|
||||
return composeTx(
|
||||
@@ -493,6 +413,86 @@ export function runSpot(
|
||||
);
|
||||
}
|
||||
|
||||
const reachableInAMMV1_1 = AMMSwapPool.reachableInAMM(
|
||||
currencyX,
|
||||
currencyY,
|
||||
ammPools
|
||||
);
|
||||
if (reachableInAMMV1_1.type === 'fromAmm') {
|
||||
return composeTx(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'swap-helper-from-amm',
|
||||
{
|
||||
'token-x-trait': reachableInAMMV1_1.tokenX,
|
||||
'token-y-trait': reachableInAMMV1_1.tokenY,
|
||||
'token-z-trait': reachableInAMMV1_1.tokenZ,
|
||||
dx: fromAmount,
|
||||
'min-dz': minDy,
|
||||
'factor-x': reachableInAMMV1_1.factorX,
|
||||
},
|
||||
[
|
||||
transfer(stxAddress, currencyX, fromAmount),
|
||||
...middleSteps.flatMap((middle, index) => [
|
||||
transfer(
|
||||
index === 0 ? AlexVaultV1_1 : AlexVault,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
transfer(
|
||||
stxAddress,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]),
|
||||
transfer(
|
||||
AlexVault,
|
||||
currencyY,
|
||||
minDy,
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
if (reachableInAMMV1_1.type === 'toAmm') {
|
||||
return composeTx(
|
||||
'swap-helper-bridged-v1-1',
|
||||
'swap-helper-to-amm',
|
||||
{
|
||||
'token-x-trait': reachableInAMMV1_1.tokenX,
|
||||
'token-y-trait': reachableInAMMV1_1.tokenY,
|
||||
'token-z-trait': reachableInAMMV1_1.tokenZ,
|
||||
dx: fromAmount,
|
||||
'min-dz': minDy,
|
||||
'factor-y': reachableInAMMV1_1.factorY,
|
||||
},
|
||||
[
|
||||
transfer(stxAddress, currencyX, fromAmount),
|
||||
...middleSteps.flatMap((middle) => [
|
||||
transfer(
|
||||
AlexVault,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
transfer(
|
||||
stxAddress,
|
||||
middle,
|
||||
BigInt(0),
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]),
|
||||
transfer(
|
||||
AlexVaultV1_1,
|
||||
currencyY,
|
||||
minDy,
|
||||
FungibleConditionCode.GreaterEqual
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
const reachableInAMM = AMMSwapPool.reachableInAMM(
|
||||
currencyX,
|
||||
currencyY,
|
||||
|
||||
@@ -11,6 +11,9 @@ export function bridgeHelperResolver(
|
||||
if (bridgingToken.includes(from) || bridgingToken.includes(to)) {
|
||||
return { type: "none" as const }
|
||||
}
|
||||
if (bridgingToken.includes(from) || bridgingToken.includes(to)) {
|
||||
return { type: "none" as const }
|
||||
}
|
||||
const fromPool = ammPools.find((a) => {
|
||||
if (!AMMSwapPool.breakDown(a).includes(from)) return false;
|
||||
const [x, y] = AMMSwapPool.breakDown(a);
|
||||
|
||||
Reference in New Issue
Block a user