Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ type phoenixPair @entity {
stakeAddress: String
totalFeeBps: Int
}

type cometPair @entity {
id: ID! # Contract address
ledger: Int!
date: Date!
tokenA: String! @index
tokenB: String! @index
reserveA: BigInt!
reserveB: BigInt!
}
```

## 📡 Accessing the GraphQL API
Expand Down Expand Up @@ -182,8 +192,9 @@ query GetPairsAqua {
}
}
}
query {
query GetPhoenixPairs {
phoenixPairs (orderBy: DATE_DESC){
nodes {
id
tokenA
tokenB
Expand All @@ -192,6 +203,21 @@ query {
reserveLp
stakeAddress
totalFeeBps
}
}
}

query GetCometPairs {
cometPairs {
nodes {
id
ledger
date
tokenA
tokenB
reserveA
reserveB
}
}
}
```
Expand Down
49 changes: 47 additions & 2 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import {
} from "@subql/types-stellar";
import { Networks } from "@stellar/stellar-sdk";
import { config } from "dotenv";
import { getPhoenixFactory, getSoroswapFactory, getAquaFactory, NETWORK } from "./src/constants";
import {
getCometFactory,
getPhoenixFactory,
getSoroswapFactory,
getAquaFactory,
NETWORK,
} from "./src/constants";
config();

// Soroswap Handlers
Expand Down Expand Up @@ -97,6 +103,45 @@ const aquaHandlers: SubqlRuntimeHandler[] = [
},
];

const cometFactory = getCometFactory(process.env.NETWORK as NETWORK);
const cometHandlers: SubqlRuntimeHandler[] = [
{
handler: "handleCometEvent",
kind: StellarHandlerKind.Event,
filter: {
topics: ["POOL", "deposit"],
},
},
{
handler: "handleCometEvent",
kind: StellarHandlerKind.Event,
filter: {
topics: ["POOL", "swap"],
},
},
{
handler: "handleCometEvent",
kind: StellarHandlerKind.Event,
filter: {
topics: ["POOL", "withdraw"],
},
},
{
handler: "handleCometEvent",
kind: StellarHandlerKind.Event,
filter: {
topics: ["POOL", "join_pool"],
},
},
{
handler: "handleCometEvent",
kind: StellarHandlerKind.Event,
filter: {
topics: ["POOL", "exit_pool"],
},
},
];

/* This is your project configuration */
const project: StellarProject = {
specVersion: "1.0.0",
Expand Down Expand Up @@ -144,7 +189,7 @@ const project: StellarProject = {
startBlock: soroswapFactory.startBlock,
mapping: {
file: "./dist/index.js",
handlers: [...soroswapHandlers, ...phoenixHandlers, ...aquaHandlers],
handlers: [...soroswapHandlers, ...phoenixHandlers, ...aquaHandlers, ...cometHandlers],
},
},
],
Expand Down
10 changes: 10 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ type AquaPair @entity {
poolType: String!
fee: BigInt!
}

type cometPair @entity {
id: ID! # Contract address
ledger: Int!
date: Date!
tokenA: String! @index
tokenB: String! @index
reserveA: BigInt!
reserveB: BigInt!
}
75 changes: 75 additions & 0 deletions scripts/comet/pairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { NETWORK, getCometPools } from "../../src/constants";
import { toolkit } from "../toolkit";
import { scValToNative, xdr } from "@stellar/stellar-sdk";
import * as fs from "fs";
import * as path from "path";
import pLimit from "p-limit";

const COMET_POOLS = getCometPools(process.env.NETWORK as NETWORK);

export async function getCometPreStart(): Promise<any> {
console.log("--------------------------------------------");
console.log("Updating Comet Data");
console.log("--------------------------------------------");

let pools: {
address: string;
token_a: string;
token_b: string;
reserve_a: any;
reserve_b: any;
}[] = [];

const key = xdr.ScVal.scvVec([xdr.ScVal.scvSymbol("AllRecordData")]);
const limit = pLimit(20); // Adjust concurrency level as needed
const tasks = COMET_POOLS.map((pool) =>
limit(async () => {
const rawLedgerEntries = await toolkit.rpc.getContractData(pool, key);
const ledgerEntries = scValToNative(rawLedgerEntries.val.value()["_attributes"].val);

const keys = Object.keys(ledgerEntries);
if (keys.length < 2) {
throw new Error("Not enough ledger entries to parse.");
}

const entry_1 = ledgerEntries[keys[0]];
const entry_2 = ledgerEntries[keys[1]];

pools.push({
address: pool,
token_a: keys[0],
token_b: keys[1],
reserve_a: entry_1.balance,
reserve_b: entry_2.balance,
});
})
);

await Promise.all(tasks);

// Generate file content
const fileContent = `
// This file is generated automatically by scripts/comet/pairs.ts
// Do not modify manually

export interface CometPairReserves {
address: string;
token_a: string;
token_b: string;
reserve_a: string;
reserve_b: string;
}

export const cometPairsGeneratedDate = "${new Date().toISOString()}";

export const cometPairReservesList: CometPairReserves[] = ${JSON.stringify(
pools,
(key, value) => (typeof value === "bigint" ? value.toString() : value),
2
)};
`;
// Write file
const filePath = path.join(__dirname, "../../src/comet/pairReservesData.ts");
fs.writeFileSync(filePath, fileContent);
console.log(`✅ pairReservesData.ts file generated successfully`);
}
9 changes: 9 additions & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { generatePairTokenReservesList } from "./soroswap/pairsTokensMaker";
import { getLatestRouterLedger } from "./soroswap/latestLedger";
import { getPhoenixPreStart } from "./phoenix/pairs";
import { getAquaPreStart } from "./aqua/aquaPoolsTokensMaker";
import { getCometPreStart } from "./comet/pairs";

config();

export const { SOROBAN_ENDPOINT, SECRET_KEY_HELPER, NETWORK } = process.env;
Expand Down Expand Up @@ -41,6 +43,13 @@ async function main() {
console.error("❌ Error generating Aqua pairs:", error);
}

// COMET
try {
await getCometPreStart();
} catch (error) {
console.error("❌ Error generating Aqua pairs:", error);
}

process.exit(1);
}

Expand Down
Loading