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
4 changes: 1 addition & 3 deletions data/events_full_snap_testnet.json
Git LFS file not shown
4 changes: 1 addition & 3 deletions data/events_snap_testnet.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0c07489fcf6d2101ceb6eb338ae88926299eeb176842bf12a8d951bdcc43eb4c
size 2114
{"6Wpj1RUs1hBwKuAzfFPGeHtgiQp5Fx4PVkDwfgzkLYCu":{"active":[{"event":{"owner":"6Wpj1RUs1hBwKuAzfFPGeHtgiQp5Fx4PVkDwfgzkLYCu","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"03","liquidity":"174876e800","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"679763d2","secondsPerLiquidityInsideInitial":"7f15f9f605b6dfd5e3"},"points":"0719f11100"},{"event":{"owner":"6Wpj1RUs1hBwKuAzfFPGeHtgiQp5Fx4PVkDwfgzkLYCu","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"02","liquidity":"174876e800","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"67976352","secondsPerLiquidityInsideInitial":"7f043fd87a20ad019f"},"points":"07676d7e00"},{"event":{"owner":"6Wpj1RUs1hBwKuAzfFPGeHtgiQp5Fx4PVkDwfgzkLYCu","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"01","liquidity":"174876e800","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"679762e5","secondsPerLiquidityInsideInitial":"7ef523872230f5cbd3"},"points":"07a8fe2900"}],"closed":[]},"FA62Nzqaz2EEBFLdYK7QYCxqz8dgNCzPnHJmfb9zQNmR":{"active":[{"event":{"owner":"FA62Nzqaz2EEBFLdYK7QYCxqz8dgNCzPnHJmfb9zQNmR","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"00","liquidity":"5af36b8e8185","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"6793d965","secondsPerLiquidityInsideInitial":"014bd01608959f3a2c"},"points":"085a3e7456c100"}],"closed":[]},"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV":{"active":[],"closed":[{"events":[{"owner":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"03","liquidity":"174876e800","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"679763cc","secondsPerLiquidityInsideInitial":"7f152570637267b26a"},{"owner":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"03","liquidity":"174876e800","upperTick":221790,"currentTick":0,"lowerTick":-221790,"upperTickSecondsPerLiquidityOutside":"00","lowerTickSecondsPerLiquidityOutside":"00","poolSecondsPerLiquidityGlobal":"7f152570637267b26a","currentTimestamp":"679763d2"}],"points":"00"},{"events":[{"owner":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"02","liquidity":"174876e800","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"6797634c","secondsPerLiquidityInsideInitial":"7f036b1c8c07ac37e1"},{"owner":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"02","liquidity":"174876e800","upperTick":221790,"currentTick":0,"lowerTick":-221790,"upperTickSecondsPerLiquidityOutside":"00","lowerTickSecondsPerLiquidityOutside":"00","poolSecondsPerLiquidityGlobal":"7f036b1c8c07ac37e1","currentTimestamp":"67976352"}],"points":"00"},{"events":[{"owner":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"01","liquidity":"174876e800","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"679762c2","secondsPerLiquidityInsideInitial":"7ef04956d8f1f0f921"},{"owner":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"01","liquidity":"174876e800","upperTick":221790,"currentTick":0,"lowerTick":-221790,"upperTickSecondsPerLiquidityOutside":"00","lowerTickSecondsPerLiquidityOutside":"00","poolSecondsPerLiquidityGlobal":"7ef04956d8f1f0f921","currentTimestamp":"679762e5"}],"points":"00"}]},"3ZB2UBvE4QUTKNexk55TW4UwE85WNaVdmjqTenuGADV1":{"active":[],"closed":[{"events":[{"owner":"3ZB2UBvE4QUTKNexk55TW4UwE85WNaVdmjqTenuGADV1","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"00","liquidity":"5af36b8e8185","lowerTick":-221790,"upperTick":221790,"currentTimestamp":"6793d00e","secondsPerLiquidityInsideInitial":"00"},{"owner":"3ZB2UBvE4QUTKNexk55TW4UwE85WNaVdmjqTenuGADV1","pool":"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo","id":"00","liquidity":"5af36b8e8185","upperTick":221790,"currentTick":0,"lowerTick":-221790,"upperTickSecondsPerLiquidityOutside":"00","lowerTickSecondsPerLiquidityOutside":"00","poolSecondsPerLiquidityGlobal":"00","currentTimestamp":"6793d965"}],"points":"00"}]}}
1 change: 1 addition & 0 deletions data/final_data_lp_testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion data/final_data_testnet.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"address":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","points":"04a7ef7558","last24hPoints":"04a7ef7558","lpPoints":"00","swapPoints":"04a7ef7558","last24hLpPoints":"00","last24hSwapPoints":"04a7ef7558","positions":0,"swaps":2,"rank":1}]
{}
4 changes: 1 addition & 3 deletions data/last_snap_timestamp_testnet.json
Git LFS file not shown
Binary file added data/points_testnet.bin
Binary file not shown.
Binary file modified data/points_testnet.json
Binary file not shown.
4 changes: 1 addition & 3 deletions data/pools_last_tx_hashes_testnet.json
Git LFS file not shown
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@coral-xyz/anchor": "0.29.0",
"@invariant-labs/sdk-eclipse": "^0.0.68",
"@invariant-labs/sdk-eclipse": "^0.0.71",
"@onsol/tldparser": "^0.6.7",
"@pythnetwork/hermes-client": "^1.3.0",
"@solana/spl-token": "^0.4.9",
Expand Down
6 changes: 3 additions & 3 deletions scripts/convert-json-to-binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { BN } from "@coral-xyz/anchor";

async function main() {
try {
const originalFile = path.join(__dirname, "../data/points_mainnet.json");
const binaryFile = path.join(__dirname, "../data/points_mainnet.bin");
const originalFile = path.join(__dirname, "../data/points_testnet.json");
const binaryFile = path.join(__dirname, "../data/points_testnet.bin");
const restoredFile = path.join(
__dirname,
"../data/restored_points_mainnet.json"
"../data/restored_points_testnet.json"
);

console.log("Converting JSON to binary...");
Expand Down
4 changes: 2 additions & 2 deletions scripts/open-position-from-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const provider = AnchorProvider.local(
);
const connection = provider.connection;

const POOL = new PublicKey("4xLSZJwLdkQHGqgyx1E9KHvdMnj7QVKa9Pwcnp1x2mDc"); // USDC/TTS 0.05%
const POOL = new PublicKey("3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo"); // USDC/V2 0.03%
const FOUNDER = Keypair.fromSecretKey(
bs58.decode(process.env.FOUNDER_PRIVATE_KEY as string)
);

const main = async () => {
const market = await Market.build(
const market = Market.build(
Network.TEST,
provider.wallet as IWallet,
connection
Expand Down
43 changes: 43 additions & 0 deletions scripts/transfer-position.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { AnchorProvider } from "@coral-xyz/anchor";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
import { IWallet, Market, Network } from "@invariant-labs/sdk-eclipse";
import { TransferPositionOwnership } from "@invariant-labs/sdk-eclipse/lib/market";
import { Keypair } from "@solana/web3.js";

require("dotenv").config();

const provider = AnchorProvider.local(
"https://testnet.dev2.eclipsenetwork.xyz"
);
const connection = provider.connection;

const POSITION_OWNER = Keypair.fromSecretKey(
bs58.decode(process.env.OWNER_PRIVATE_KEY as string)
);
const TARGET = Keypair.fromSecretKey(
bs58.decode(process.env.TARGET_PRIVATE_KEY as string)
);

const main = async () => {
const market = Market.build(
Network.TEST,
provider.wallet as IWallet,
connection
);
const positions = await market.getAllUserPositionsWithIds(
POSITION_OWNER.publicKey
);
console.log(positions[positions.length - 1][1]);

const transferPositionOwnership: TransferPositionOwnership = {
owner: POSITION_OWNER.publicKey,
recipient: TARGET.publicKey,
index: positions.length - 1,
};
await market.transferPositionOwnership(
transferPositionOwnership,
POSITION_OWNER
);
};

main();
23 changes: 14 additions & 9 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ export const PROMOTED_POOLS_TESTNET: IPromotedPool[] = [
// address: new PublicKey("GTVKQs8o9D52y9SdwfAXCQSDrrCLosvsP19HgHKugpfw"),
// pointsPerSecond: new BN(100),
// }, // USDC/V2 0.01%
// {
// address: new PublicKey("G28wnbasJuXihJ76KgFxynsA8WCj4yJZujq9ZhTbBLQm"),
// pointsPerSecond: new BN(100),
// startCountTimestamp: new BN(0),
// }, // USDC/TTS 0.01%
// {
// address: new PublicKey("3YnSG9bS5tp7Bp8QZK6xZKKmfrNJJK8TE8UyZq99nhxH"),
// pointsPerSecond: new BN(100),
// startCountTimestamp: new BN(0),
// }, // USDC/V2 0.02%
{
address: new PublicKey("G28wnbasJuXihJ76KgFxynsA8WCj4yJZujq9ZhTbBLQm"),
pointsPerSecond: new BN(100),
startCountTimestamp: new BN(0),
}, // USDC/TTS 0.01%
{
address: new PublicKey("3YnSG9bS5tp7Bp8QZK6xZKKmfrNJJK8TE8UyZq99nhxH"),
address: new PublicKey("3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo"),
pointsPerSecond: new BN(100),
startCountTimestamp: new BN(0),
}, // USDC/V2 0.02%
startCountTimestamp: new BN(1737740472),
}, //USDC/V2 0.03%
];
export const PROMOTED_POOLS_MAINNET: IPromotedPool[] = [
{
Expand Down Expand Up @@ -52,7 +57,7 @@ export const RETRY_DELAY = 800;
export const FULL_SNAP_START_TX_HASH_MAINNET =
"zt4f4PYU2qKyvevjvED2Q9RSUJbiGSJns8NCQGAuLFgrTJ8irentnaEzc7uxxoi65vtmWxhwZh8HDg6NRsWjQxw";
export const FULL_SNAP_START_TX_HASH_TESTNET =
"AmjrAbNvGU8qK6xFTGpPCFPcYruZvH7gZ46YtxFyMp58x9UK3MXJ3CC3UojBvptxiAjip7fU4txZtQMoJ6Sc6kf";
"32voE8yoznSSBP3kExxeAbxjSeFYPUheS9LeDuZubyZubhu8goRTBvLASB4qzWbXsSoNG7NLQEqov1fP8eBL4Tjw";

// SWAPS
export const SWAP_MULTIPLIER = new BN(1);
Expand Down
4 changes: 3 additions & 1 deletion src/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export const prepareFinalData = async (network: Network) => {
__dirname,
"../data/final_data_lp_testnet.json"
);
data = {};
data = PointsBinaryConverter.readBinaryFile(
path.join(__dirname, "../data/points_testnet.bin")
);
staticData = {};
staticSwap = {};
contentProgramData = {};
Expand Down
50 changes: 26 additions & 24 deletions src/snap-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
} from "./utils";
import {
IActive,
IPointsHistory,
IPoolAndTicks,
IPositions,
IPromotedPool,
Expand All @@ -55,7 +54,6 @@ export const createSnapshotForNetwork = async (network: Network) => {
let FULL_SNAP_START_TX_HASH: string;
let lastSnapTimestampFileName: string;
let historicalPointsForClosedFileName: string;
let isBinary: boolean;
switch (network) {
case Network.MAIN:
provider = AnchorProvider.local("https://eclipse.helius-rpc.com");
Expand All @@ -64,7 +62,6 @@ export const createSnapshotForNetwork = async (network: Network) => {
"../data/events_snap_mainnet.json"
);
pointsFileName = path.join(__dirname, "../data/points_mainnet.bin");
isBinary = true;
poolsFileName = path.join(
__dirname,
"../data/pools_last_tx_hashes_mainnet.json"
Expand All @@ -88,8 +85,7 @@ export const createSnapshotForNetwork = async (network: Network) => {
__dirname,
"../data/events_snap_testnet.json"
);
pointsFileName = path.join(__dirname, "../data/points_testnet.json");
isBinary = false;
pointsFileName = path.join(__dirname, "../data/points_testnet.bin");
poolsFileName = path.join(
__dirname,
"../data/pools_last_tx_hashes_testnet.json"
Expand Down Expand Up @@ -163,9 +159,13 @@ export const createSnapshotForNetwork = async (network: Network) => {
finalLogs.map((log, index) => {
if (
log.startsWith("Program data:") &&
finalLogs[index + 1].startsWith(
(finalLogs[index + 1].startsWith(
`Program ${market.program.programId.toBase58()}`
)
) ||
(finalLogs[index + 2].startsWith(
`Program ${market.program.programId.toBase58()}`
) &&
finalLogs[index + 1].startsWith(`Program data:`)))
)
eventLogs.push(log.split("Program data: ")[1]);
});
Expand All @@ -188,14 +188,16 @@ export const createSnapshotForNetwork = async (network: Network) => {
eventsObject[owner].active.some(
(entry) =>
entry.event.pool.toString() === event.pool.toString() &&
new BN(entry.event.id, "hex").eq(event.id)
new BN(entry.event.id, "hex").eq(event.id) &&
entry.event.owner.toString() === owner
)
)
return acc;
const correspondingItemIndex = acc.newOpenClosed.findIndex(
(item) =>
item[1].id.eq(event.id) &&
item[1].pool.toString() === event.pool.toString()
item[1].pool.toString() === event.pool.toString() &&
item[1].owner.toString() === owner
);
if (correspondingItemIndex >= 0) {
const correspondingItem = acc.newOpenClosed[correspondingItemIndex];
Expand All @@ -215,7 +217,8 @@ export const createSnapshotForNetwork = async (network: Network) => {
const correspondingItemIndex = acc.newOpen.findIndex(
(item) =>
item.id.eq(event.id) &&
item.pool.toString() === event.pool.toString()
item.pool.toString() === event.pool.toString() &&
item.owner.toString() === ownerKey
);
if (correspondingItemIndex >= 0) {
const correspondingItem = acc.newOpen[correspondingItemIndex];
Expand All @@ -226,7 +229,8 @@ export const createSnapshotForNetwork = async (network: Network) => {
const correspondingItemIndexPreviousData = ownerData.active.findIndex(
(item) =>
new BN(item.event.id, "hex").eq(event.id) &&
item.event.pool.toString() === event.pool.toString()
item.event.pool.toString() === event.pool.toString() &&
item.event.owner.toString() === ownerKey
);

if (correspondingItemIndexPreviousData >= 0) {
Expand Down Expand Up @@ -271,7 +275,9 @@ export const createSnapshotForNetwork = async (network: Network) => {
(newClosedEntry) =>
newClosedEntry[0].event.id.eq(new BN(activeEntry.event.id, "hex")) &&
newClosedEntry[0].event.pool.toString() ===
activeEntry.event.pool.toString()
activeEntry.event.pool.toString() &&
newClosedEntry[0].event.owner.toString() ===
Comment thread
matepal00 marked this conversation as resolved.
activeEntry.event.owner.toString()
);
if (!hasBeenClosed) {
stillOpen.push({
Expand Down Expand Up @@ -357,24 +363,24 @@ export const createSnapshotForNetwork = async (network: Network) => {
eventsObject[ownerKey].closed.push(entry);
});

const previousPoints = isBinary
? PointsBinaryConverter.readBinaryFile(pointsFileName)
: JSON.parse(fs.readFileSync(pointsFileName, "utf-8"));
const previousPoints = PointsBinaryConverter.readBinaryFile(pointsFileName);

const points: Record<string, PointsEntry> = Object.keys(eventsObject).reduce(
(acc, curr) => {
const prev24HoursHistory = previousPoints[curr]?.points24HoursHistory;
if (prev24HoursHistory) {
prev24HoursHistory.forEach((item, idx) => {
if (new BN(item.timestamp).add(DAY).lt(currentTimestamp)) {
const timestamp = new BN(item.timestamp);
if (timestamp.add(DAY).lt(currentTimestamp)) {
prev24HoursHistory.splice(idx, 1);
}
});
}

const previousTotalPoints: BN =
// NOTE: After first snapshot with binary points file, ensure the points are not casted with hex
new BN(previousPoints[curr]?.totalPoints) ?? new BN(0);
// NOTE: After first snapshot with binary points file, ensure the points are not casted with hex
const previousTotal = new BN(previousPoints[curr]?.totalPoints);

const previousTotalPoints: BN = previousTotal ?? new BN(0);

const pointsForOpen: BN[] = eventsObject[curr].active.map(
(entry) => entry.points
Expand Down Expand Up @@ -449,11 +455,7 @@ export const createSnapshotForNetwork = async (network: Network) => {
);
fs.writeFileSync(poolsFileName, JSON.stringify(newPoolsFile));
fs.writeFileSync(eventsSnapFilename, JSON.stringify(eventsObject));
if (isBinary) {
PointsBinaryConverter.writeBinaryFile(pointsFileName, points);
} else {
fs.writeFileSync(pointsFileName, JSON.stringify(points));
}
PointsBinaryConverter.writeBinaryFile(pointsFileName, points);
};

// createSnapshotForNetwork(Network.TEST).then(
Expand Down