mirror of
https://github.com/alexgo-io/alex-sdk.git
synced 2026-01-12 06:14:21 +08:00
feat: include lp fee in quoting
This commit is contained in:
@@ -4,14 +4,15 @@ import { configs } from '../src/config';
|
||||
|
||||
const API_HOST = configs.READONLY_CALL_API_HOST;
|
||||
const ALEX_CONTRACT_DEPLOYER = configs.CONTRACT_DEPLOYER;
|
||||
const QUOTE_CONTRACT_DEPLOYER = configs.QUOTE_CONTRACT_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() {
|
||||
await generateContracts(
|
||||
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,
|
||||
path.resolve(__dirname, '../src/generated/smartContract/'),
|
||||
'Alex',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export const configs = {
|
||||
CONTRACT_DEPLOYER: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM',
|
||||
QUOTE_CONTRACT_DEPLOYER: 'SP3MZM9WJ34Y4311XBJDBKQ41SXX5DY68424HSED2',
|
||||
SPONSOR_TX_DEPLOYER: 'SP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER',
|
||||
SDK_API_HOST: 'https://alex-sdk-api.alexlab.co',
|
||||
BACKEND_API_HOST: 'https://api.alexgo.io',
|
||||
|
||||
@@ -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);
|
||||
@@ -1,8 +1,10 @@
|
||||
import { defineContract } from '../smartContractHelpers/codegenImport';
|
||||
import { ammPoolV201 } from './contract_Alex_amm-pool-v2-01';
|
||||
import { sponsorDexV01 } from './contract_Alex_sponsor-dex-v01';
|
||||
import { alexAmmPoolV201GetHelper } from './contract_Alex_alex-amm-pool-v2-01-get-helper';
|
||||
|
||||
export const AlexContracts = defineContract({
|
||||
...ammPoolV201,
|
||||
...sponsorDexV01,
|
||||
...alexAmmPoolV201GetHelper,
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ export const getYAmountFromXAmount = async (
|
||||
}
|
||||
if (hasLength(ammRoute, 1)) {
|
||||
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-y': getContractId(segment.neighbour),
|
||||
dx: fromAmount,
|
||||
@@ -31,7 +31,7 @@ export const getYAmountFromXAmount = async (
|
||||
}
|
||||
if (hasLength(ammRoute, 2)) {
|
||||
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-y': getContractId(segment1.neighbour),
|
||||
'token-z': getContractId(segment2.neighbour),
|
||||
@@ -42,7 +42,7 @@ export const getYAmountFromXAmount = async (
|
||||
}
|
||||
if (hasLength(ammRoute, 3)) {
|
||||
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-y': getContractId(segment1.neighbour),
|
||||
'token-z': getContractId(segment2.neighbour),
|
||||
@@ -55,7 +55,7 @@ export const getYAmountFromXAmount = async (
|
||||
}
|
||||
if (hasLength(ammRoute, 4)) {
|
||||
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-y': getContractId(segment1.neighbour),
|
||||
'token-z': getContractId(segment2.neighbour),
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function readonlyCall<
|
||||
contractName,
|
||||
functionName: String(functionName),
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user