Skip to content

Commit

Permalink
feat: batch pair config
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPresident committed Nov 28, 2023
1 parent 752e747 commit 6792ca9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/contracts/services/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '~/types/contracts/swap/response';
import {
BatchPairsInfo,
BatchPairsConfig,
BatchStakingInfo,
FactoryConfig,
FactoryPairs,
Expand Down Expand Up @@ -233,6 +234,12 @@ const parseBatchQueryPairInfoResponse = (
pairInfo: parsePairInfo(item.response),
}));

const parseBatchQueryPairConfigResponse = (
response: BatchQueryParsedResponse,
): BatchPairsConfig => response.map((item) => ({
pairContractAddress: item.id as string,
pairConfig: parsePairConfig(item.response),
}));
/**
* parses the single staking info response
*/
Expand Down Expand Up @@ -547,6 +554,61 @@ async function batchQueryPairsInfo({
}));
}

function batchQueryPairsConfig$({
queryRouterContractAddress,
queryRouterCodeHash,
lcdEndpoint,
chainId,
pairsContracts,
}:{
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
lcdEndpoint?: string,
chainId?: string,
pairsContracts: Contract[]
}) {
const queries:BatchQuery[] = pairsContracts.map((contract) => ({
id: contract.address,
contract: {
address: contract.address,
codeHash: contract.codeHash,
},
queryMsg: msgQueryPairConfig(),
}));
return batchQuery$({
contractAddress: queryRouterContractAddress,
codeHash: queryRouterCodeHash,
lcdEndpoint,
chainId,
queries,
}).pipe(
map(parseBatchQueryPairConfigResponse),
first(),
);
}

async function batchQueryPairsConfig({
queryRouterContractAddress,
queryRouterCodeHash,
lcdEndpoint,
chainId,
pairsContracts,
}:{
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
lcdEndpoint?: string,
chainId?: string,
pairsContracts: Contract[]
}) {
return lastValueFrom(batchQueryPairsConfig$({
queryRouterContractAddress,
queryRouterCodeHash,
lcdEndpoint,
chainId,
pairsContracts,
}));
}

/**
* query the staking info for multiple staking contracts at one time
*/
Expand Down Expand Up @@ -622,6 +684,8 @@ export {
queryPairConfig,
batchQueryPairsInfo$,
batchQueryPairsInfo,
batchQueryPairsConfig$,
batchQueryPairsConfig,
batchQueryStakingInfo$,
batchQueryStakingInfo,
parseSwapResponse,
Expand Down
8 changes: 8 additions & 0 deletions src/types/contracts/swap/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ type BatchPairInfo = {

type BatchPairsInfo = BatchPairInfo[]

type BatchPairConfig = {
pairContractAddress: string,
pairConfig: PairConfig,
}

type BatchPairsConfig = BatchPairConfig[]

type RewardTokenInfo = {
token: Contract,
rewardPerSecond: string,
Expand Down Expand Up @@ -138,6 +145,7 @@ type ParsedSwapResponse = {
export type {
FactoryPairs,
PairConfig,
BatchPairsConfig,
FactoryConfig,
PairInfo,
BatchPairsInfo,
Expand Down

0 comments on commit 6792ca9

Please sign in to comment.