feat: include lp fee in quoting

This commit is contained in:
Kyle Fang
2025-04-24 09:53:55 +00:00
parent 8dd0a81924
commit b3c6561287
6 changed files with 74 additions and 7 deletions

View File

@@ -4,14 +4,15 @@ import { configs } from '../src/config';
const API_HOST = configs.READONLY_CALL_API_HOST; const API_HOST = configs.READONLY_CALL_API_HOST;
const ALEX_CONTRACT_DEPLOYER = configs.CONTRACT_DEPLOYER; const ALEX_CONTRACT_DEPLOYER = configs.CONTRACT_DEPLOYER;
const QUOTE_CONTRACT_DEPLOYER = configs.QUOTE_CONTRACT_DEPLOYER;
const SPONSOR_CONTRACT_DEPLOYER = configs.SPONSOR_TX_DEPLOYER; const SPONSOR_CONTRACT_DEPLOYER = configs.SPONSOR_TX_DEPLOYER;
const contracts = ['amm-pool-v2-01', 'sponsor-dex-v01']; const contracts = ['amm-pool-v2-01', 'sponsor-dex-v01', 'alex-amm-pool-v2-01-get-helper'];
(async function main() { (async function main() {
await generateContracts( await generateContracts(
API_HOST, API_HOST,
(contract) => contract === 'sponsor-dex-v01' ? SPONSOR_CONTRACT_DEPLOYER : ALEX_CONTRACT_DEPLOYER, (contract) => contract === 'sponsor-dex-v01' ? SPONSOR_CONTRACT_DEPLOYER : contract === 'alex-amm-pool-v2-01-get-helper' ? QUOTE_CONTRACT_DEPLOYER : ALEX_CONTRACT_DEPLOYER,
contracts, contracts,
path.resolve(__dirname, '../src/generated/smartContract/'), path.resolve(__dirname, '../src/generated/smartContract/'),
'Alex', 'Alex',

View File

@@ -1,5 +1,6 @@
export const configs = { export const configs = {
CONTRACT_DEPLOYER: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM', CONTRACT_DEPLOYER: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM',
QUOTE_CONTRACT_DEPLOYER: 'SP3MZM9WJ34Y4311XBJDBKQ41SXX5DY68424HSED2',
SPONSOR_TX_DEPLOYER: 'SP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER', SPONSOR_TX_DEPLOYER: 'SP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER',
SDK_API_HOST: 'https://alex-sdk-api.alexlab.co', SDK_API_HOST: 'https://alex-sdk-api.alexlab.co',
BACKEND_API_HOST: 'https://api.alexgo.io', BACKEND_API_HOST: 'https://api.alexgo.io',

View File

@@ -0,0 +1,63 @@
import {
defineContract,
principalT,
uintT,
responseSimpleT,
} from '../smartContractHelpers/codegenImport';
export const alexAmmPoolV201GetHelper = defineContract({
'alex-amm-pool-v2-01-get-helper': {
'get-helper-with-fee': {
input: [
{ name: 'token-x', type: principalT },
{ name: 'token-y', type: principalT },
{ name: 'factor', type: uintT },
{ name: 'dx', type: uintT },
],
output: responseSimpleT(uintT),
mode: 'readonly',
},
'get-helper-with-fee-a': {
input: [
{ name: 'token-x', type: principalT },
{ name: 'token-y', type: principalT },
{ name: 'token-z', type: principalT },
{ name: 'factor-x', type: uintT },
{ name: 'factor-y', type: uintT },
{ name: 'dx', type: uintT },
],
output: responseSimpleT(uintT),
mode: 'readonly',
},
'get-helper-with-fee-b': {
input: [
{ name: 'token-x', type: principalT },
{ name: 'token-y', type: principalT },
{ name: 'token-z', type: principalT },
{ name: 'token-w', type: principalT },
{ name: 'factor-x', type: uintT },
{ name: 'factor-y', type: uintT },
{ name: 'factor-z', type: uintT },
{ name: 'dx', type: uintT },
],
output: responseSimpleT(uintT),
mode: 'readonly',
},
'get-helper-with-fee-c': {
input: [
{ name: 'token-x', type: principalT },
{ name: 'token-y', type: principalT },
{ name: 'token-z', type: principalT },
{ name: 'token-w', type: principalT },
{ name: 'token-v', type: principalT },
{ name: 'factor-x', type: uintT },
{ name: 'factor-y', type: uintT },
{ name: 'factor-z', type: uintT },
{ name: 'factor-w', type: uintT },
{ name: 'dx', type: uintT },
],
output: responseSimpleT(uintT),
mode: 'readonly',
},
},
} as const);

View File

@@ -1,8 +1,10 @@
import { defineContract } from '../smartContractHelpers/codegenImport'; import { defineContract } from '../smartContractHelpers/codegenImport';
import { ammPoolV201 } from './contract_Alex_amm-pool-v2-01'; import { ammPoolV201 } from './contract_Alex_amm-pool-v2-01';
import { sponsorDexV01 } from './contract_Alex_sponsor-dex-v01'; import { sponsorDexV01 } from './contract_Alex_sponsor-dex-v01';
import { alexAmmPoolV201GetHelper } from './contract_Alex_alex-amm-pool-v2-01-get-helper';
export const AlexContracts = defineContract({ export const AlexContracts = defineContract({
...ammPoolV201, ...ammPoolV201,
...sponsorDexV01, ...sponsorDexV01,
...alexAmmPoolV201GetHelper,
}); });

View File

@@ -22,7 +22,7 @@ export const getYAmountFromXAmount = async (
} }
if (hasLength(ammRoute, 1)) { if (hasLength(ammRoute, 1)) {
const [segment] = ammRoute; const [segment] = ammRoute;
return await readonlyCall('amm-pool-v2-01', 'get-helper', { return await readonlyCall('alex-amm-pool-v2-01-get-helper', 'get-helper-with-fee', {
'token-x': getContractId(tokenX), 'token-x': getContractId(tokenX),
'token-y': getContractId(segment.neighbour), 'token-y': getContractId(segment.neighbour),
dx: fromAmount, dx: fromAmount,
@@ -31,7 +31,7 @@ export const getYAmountFromXAmount = async (
} }
if (hasLength(ammRoute, 2)) { if (hasLength(ammRoute, 2)) {
const [segment1, segment2] = ammRoute; const [segment1, segment2] = ammRoute;
return await readonlyCall('amm-pool-v2-01', 'get-helper-a', { return await readonlyCall('alex-amm-pool-v2-01-get-helper', 'get-helper-with-fee-a', {
'token-x': getContractId(tokenX), 'token-x': getContractId(tokenX),
'token-y': getContractId(segment1.neighbour), 'token-y': getContractId(segment1.neighbour),
'token-z': getContractId(segment2.neighbour), 'token-z': getContractId(segment2.neighbour),
@@ -42,7 +42,7 @@ export const getYAmountFromXAmount = async (
} }
if (hasLength(ammRoute, 3)) { if (hasLength(ammRoute, 3)) {
const [segment1, segment2, segment3] = ammRoute; const [segment1, segment2, segment3] = ammRoute;
return await readonlyCall('amm-pool-v2-01', 'get-helper-b', { return await readonlyCall('alex-amm-pool-v2-01-get-helper', 'get-helper-with-fee-b', {
'token-x': getContractId(tokenX), 'token-x': getContractId(tokenX),
'token-y': getContractId(segment1.neighbour), 'token-y': getContractId(segment1.neighbour),
'token-z': getContractId(segment2.neighbour), 'token-z': getContractId(segment2.neighbour),
@@ -55,7 +55,7 @@ export const getYAmountFromXAmount = async (
} }
if (hasLength(ammRoute, 4)) { if (hasLength(ammRoute, 4)) {
const [segment1, segment2, segment3, segment4] = ammRoute; const [segment1, segment2, segment3, segment4] = ammRoute;
return await readonlyCall('amm-pool-v2-01', 'get-helper-c', { return await readonlyCall('alex-amm-pool-v2-01-get-helper', 'get-helper-with-fee-c', {
'token-x': getContractId(tokenX), 'token-x': getContractId(tokenX),
'token-y': getContractId(segment1.neighbour), 'token-y': getContractId(segment1.neighbour),
'token-z': getContractId(segment2.neighbour), 'token-z': getContractId(segment2.neighbour),

View File

@@ -60,7 +60,7 @@ export async function readonlyCall<
contractName, contractName,
functionName: String(functionName), functionName: String(functionName),
functionArgs: clarityArgs, functionArgs: clarityArgs,
contractAddress: configs.CONTRACT_DEPLOYER, contractAddress: contractName === 'alex-amm-pool-v2-01-get-helper' ? configs.QUOTE_CONTRACT_DEPLOYER : configs.CONTRACT_DEPLOYER,
}); });
return functionDescriptor.output.decode(result); return functionDescriptor.output.decode(result);
} }