diff --git a/data/events_full_snap_testnet.json b/data/events_full_snap_testnet.json index a56d721aaf..0967ef424b 100644 --- a/data/events_full_snap_testnet.json +++ b/data/events_full_snap_testnet.json @@ -1,3 +1 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356 -size 3 +{} diff --git a/data/events_snap_testnet.json b/data/events_snap_testnet.json index 42d06d7195..615d3a8c81 100644 --- a/data/events_snap_testnet.json +++ b/data/events_snap_testnet.json @@ -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"}]}} \ No newline at end of file diff --git a/data/final_data_lp_testnet.json b/data/final_data_lp_testnet.json index e69de29bb2..0967ef424b 100644 --- a/data/final_data_lp_testnet.json +++ b/data/final_data_lp_testnet.json @@ -0,0 +1 @@ +{} diff --git a/data/final_data_testnet.json b/data/final_data_testnet.json index 8ec5995f58..0967ef424b 100644 --- a/data/final_data_testnet.json +++ b/data/final_data_testnet.json @@ -1 +1 @@ -[{"address":"Fp93x7oYTZftGN8jUPv9qE1dVPEASH33P33ew19JedDV","points":"04a7ef7558","last24hPoints":"04a7ef7558","lpPoints":"00","swapPoints":"04a7ef7558","last24hLpPoints":"00","last24hSwapPoints":"04a7ef7558","positions":0,"swaps":2,"rank":1}] \ No newline at end of file +{} diff --git a/data/last_snap_timestamp_testnet.json b/data/last_snap_timestamp_testnet.json index 294db51e6d..cc5e5433b9 100644 --- a/data/last_snap_timestamp_testnet.json +++ b/data/last_snap_timestamp_testnet.json @@ -1,3 +1 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:af38f435c910a7626d2abb50c1cd814d87e17b5ac0644f371f9bc1dea2a5697b -size 32 +{"lastSnapTimestamp":"67976fcd"} \ No newline at end of file diff --git a/data/points_testnet.bin b/data/points_testnet.bin new file mode 100644 index 0000000000..593f4708db Binary files /dev/null and b/data/points_testnet.bin differ diff --git a/data/points_testnet.json b/data/points_testnet.json index 3de2f404c1..ed6ce4183e 100644 Binary files a/data/points_testnet.json and b/data/points_testnet.json differ diff --git a/data/pools_last_tx_hashes_testnet.json b/data/pools_last_tx_hashes_testnet.json index 4829c5e90d..d51c0710d1 100644 --- a/data/pools_last_tx_hashes_testnet.json +++ b/data/pools_last_tx_hashes_testnet.json @@ -1,3 +1 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:659883c0cc1eea5aeb621ba2e5d8b217c6401fc4693a44a5f8510681bda8989d -size 285 +{"3aK4ibSQamqLnB2yvCYLh1DjVDqYKBLyhT8vVs5u8cdo":"3JSdymq11Awj98om9TvrQSwpSyvL4qiHCpCeyY38e9u4jf79LSa856DYyqVa6k74CNGv9Rk4rWuKd5Ao6B9AdXop"} \ No newline at end of file diff --git a/package.json b/package.json index 94fbab61f6..70a1900b56 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/convert-json-to-binary.ts b/scripts/convert-json-to-binary.ts index 8b7bab2cb4..05a1ee24e3 100644 --- a/scripts/convert-json-to-binary.ts +++ b/scripts/convert-json-to-binary.ts @@ -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..."); diff --git a/scripts/open-position-from-env.ts b/scripts/open-position-from-env.ts index 106400a639..ef6ccf8047 100644 --- a/scripts/open-position-from-env.ts +++ b/scripts/open-position-from-env.ts @@ -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 diff --git a/scripts/transfer-position.ts b/scripts/transfer-position.ts new file mode 100644 index 0000000000..711a5f6830 --- /dev/null +++ b/scripts/transfer-position.ts @@ -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(); diff --git a/src/consts.ts b/src/consts.ts index 9a138d920a..8d71a5b341 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -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[] = [ { @@ -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); diff --git a/src/prepare-data.ts b/src/prepare-data.ts index 8a0634ae5b..331d7be1eb 100644 --- a/src/prepare-data.ts +++ b/src/prepare-data.ts @@ -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 = {}; diff --git a/src/snap-points.ts b/src/snap-points.ts index b410060ac3..142ec31a40 100644 --- a/src/snap-points.ts +++ b/src/snap-points.ts @@ -30,7 +30,6 @@ import { } from "./utils"; import { IActive, - IPointsHistory, IPoolAndTicks, IPositions, IPromotedPool, @@ -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"); @@ -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" @@ -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" @@ -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]); }); @@ -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]; @@ -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]; @@ -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) { @@ -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() === + activeEntry.event.owner.toString() ); if (!hasBeenClosed) { stillOpen.push({ @@ -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 = 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 @@ -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(