Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Git LFS file not shown
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
4 changes: 1 addition & 3 deletions data/points_testnet.json
Git LFS 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
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 @@ -47,7 +52,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(5);
Expand Down
69 changes: 42 additions & 27 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 Down Expand Up @@ -163,9 +162,12 @@ 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 - 1].startsWith(
Comment thread
matepal00 marked this conversation as resolved.
Outdated
`Program log: INVARIANT: TRANSFER POSITION`
))
)
eventLogs.push(log.split("Program data: ")[1]);
});
Expand Down Expand Up @@ -263,6 +265,7 @@ export const createSnapshotForNetwork = async (network: Network) => {
{ newOpen: [], newClosed: [], newOpenClosed: [] }
);

console.log(newOpen, newOpenClosed);
Comment thread
matepal00 marked this conversation as resolved.
Outdated
const stillOpen: IActive[] = [];

Object.values(eventsObject).forEach((positions) =>
Expand Down Expand Up @@ -366,15 +369,27 @@ export const createSnapshotForNetwork = async (network: Network) => {
const prev24HoursHistory = previousPoints[curr]?.points24HoursHistory;
if (prev24HoursHistory) {
prev24HoursHistory.forEach((item, idx) => {
if (new BN(item.timestamp).add(DAY).lt(currentTimestamp)) {
let timestamp: BN;
if (network === Network.TEST) {
Comment thread
matepal00 marked this conversation as resolved.
Outdated
timestamp = new BN(item.timestamp, "hex");
Comment thread
matepal00 marked this conversation as resolved.
Outdated
} else {
timestamp = new BN(item.timestamp);
}
if (timestamp.add(DAY).lt(currentTimestamp)) {
prev24HoursHistory.splice(idx, 1);
}
});
}

const previousTotalPoints: BN =
let previousTotal: BN;
if (network === Network.TEST) {
previousTotal = new BN(previousPoints[curr]?.totalPoints, "hex");
} else {
// NOTE: After first snapshot with binary points file, ensure the points are not casted with hex
new BN(previousPoints[curr]?.totalPoints) ?? new BN(0);
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 @@ -443,33 +458,33 @@ export const createSnapshotForNetwork = async (network: Network) => {
lastSnapTimestamp: currentTimestamp,
};

fs.writeFileSync(
lastSnapTimestampFileName,
JSON.stringify(currentSnapTimestampData)
);
fs.writeFileSync(poolsFileName, JSON.stringify(newPoolsFile));
// fs.writeFileSync(
// lastSnapTimestampFileName,
// JSON.stringify(currentSnapTimestampData)
// );
// 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));
}
// if (isBinary) {
// PointsBinaryConverter.writeBinaryFile(pointsFileName, points);
// } else {
// fs.writeFileSync(pointsFileName, JSON.stringify(points));
// }
};

// createSnapshotForNetwork(Network.TEST).then(
// () => {
// console.log("Eclipse: Testnet snapshot done!");
// },
// (err) => {
// console.log(err);
// }
// );

createSnapshotForNetwork(Network.MAIN).then(
createSnapshotForNetwork(Network.TEST).then(
() => {
console.log("Eclipse: Mainnet snapshot done!");
console.log("Eclipse: Testnet snapshot done!");
},
(err) => {
console.log(err);
}
);

// createSnapshotForNetwork(Network.MAIN).then(
// () => {
// console.log("Eclipse: Mainnet snapshot done!");
// },
// (err) => {
// console.log(err);
// }
// );