Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
9640b14
add parsing for swap events from instructions
jokrsec Jun 25, 2024
abba495
fix indentation
sssionggg Jun 25, 2024
b1cea5f
add support to handle multiple token transfers and add support for to…
jokrsec Jun 26, 2024
e03c86c
fix grouping token transfers
jokrsec Jun 28, 2024
4c89a0f
fix transfer stack height check
jokrsec Jun 29, 2024
4be8ac2
add token account positions and swap directions
jokrsec Jun 29, 2024
4b6224a
add negetive postions to support variable accounts length
jokrsec Jun 29, 2024
22dbb45
add test script
jokrsec Jun 29, 2024
ad76bb4
fix issue with extracting mint
jokrsec Jun 29, 2024
6bb70c8
add support for swaps with burn and mint instructions as in and out t…
jokrsec Jun 29, 2024
9875e02
fix bonkswap positoin
jokrsec Jun 29, 2024
02fbeee
add positons based on instruction rather than amm key
jokrsec Jun 30, 2024
3129ca2
improve code style
jokrsec Jun 30, 2024
cf127c8
add fee event parsing
jokrsec Jul 1, 2024
66eaf48
add unit test for extract
jokrsec Jul 1, 2024
42d4387
commit lock file
jokrsec Jul 1, 2024
1c86d4b
add beforeEach in setup
jokrsec Jul 1, 2024
e79769b
change function name
jokrsec Jul 1, 2024
49fe23d
add unit tests for constants
jokrsec Jul 1, 2024
9bbd06f
remove unit tests for constants
jokrsec Jul 2, 2024
98df474
minor update
sssionggg Jul 2, 2024
12089d5
update readme
sssionggg Jul 2, 2024
388fd06
Merge pull request #31 from jup-ag/new-events-parser
sssionggg Jul 2, 2024
b4bbbe8
fix fee edge case
jokrsec Jul 4, 2024
8f10117
fix gooseFxv2 key
jokrsec Jul 4, 2024
4616c2d
handle fee on token transfers
jokrsec Jul 4, 2024
c8f51c7
add orca v1
jokrsec Jul 5, 2024
9f3bd96
Merge pull request #33 from jup-ag/v61-fixes
sssionggg Jul 6, 2024
70cbb54
add guacswap support
sssionggg Jun 11, 2024
710b5f6
v6.0.23
sssionggg Jun 11, 2024
dbe8e1f
add parsing for swap events from instructions
jokrsec Jun 25, 2024
895bd1c
fix indentation
sssionggg Jun 25, 2024
604f9eb
add support to handle multiple token transfers and add support for to…
jokrsec Jun 26, 2024
5c31383
fix grouping token transfers
jokrsec Jun 28, 2024
8aaff12
fix transfer stack height check
jokrsec Jun 29, 2024
0917871
add token account positions and swap directions
jokrsec Jun 29, 2024
fdeb917
add negetive postions to support variable accounts length
jokrsec Jun 29, 2024
ca7a342
add test script
jokrsec Jun 29, 2024
897e27f
fix issue with extracting mint
jokrsec Jun 29, 2024
021b234
add support for swaps with burn and mint instructions as in and out t…
jokrsec Jun 29, 2024
be6f3ee
fix bonkswap positoin
jokrsec Jun 29, 2024
b5a97c6
add positons based on instruction rather than amm key
jokrsec Jun 30, 2024
84de514
improve code style
jokrsec Jun 30, 2024
bb3d7d7
add fee event parsing
jokrsec Jul 1, 2024
290fe76
add unit test for extract
jokrsec Jul 1, 2024
cba6e85
commit lock file
jokrsec Jul 1, 2024
1c7602c
add beforeEach in setup
jokrsec Jul 1, 2024
7426571
change function name
jokrsec Jul 1, 2024
71f7513
add unit tests for constants
jokrsec Jul 1, 2024
e3e6114
remove unit tests for constants
jokrsec Jul 2, 2024
766c9b5
minor update
sssionggg Jul 2, 2024
64cf2b3
update readme
sssionggg Jul 2, 2024
d0b3f67
new commit
jokrsec Jul 5, 2024
09af002
Merge branch 'main' into custom-swap-parsing
sssionggg Jul 9, 2024
cf24d7a
refactor event parser
jokrsec Jul 10, 2024
206b8ed
fix snapshot cmd
jokrsec Jul 10, 2024
a7e2406
Merge pull request #37 from jup-ag/refactor-event-parser
sssionggg Jul 10, 2024
dbeaf04
add comments to getMultiStepSwap
jokrsec Jul 10, 2024
39d30b8
v6.1.1
sssionggg Jul 10, 2024
437ad2c
don't need these packages
sssionggg Jul 10, 2024
0921696
v6.1.2
sssionggg Jul 10, 2024
1ac6743
update comments for getMultiStepSwap
jokrsec Jul 10, 2024
47fcef1
Merge pull request #35 from jup-ag/custom-swap-parsing
sssionggg Jul 11, 2024
0936381
add support for whirlpoolv2 and one-intro
sssionggg Jul 11, 2024
79e0c94
fix fee edge case
jokrsec Jul 11, 2024
b6752c3
add guacswap to xToY
jokrsec Jul 11, 2024
342f244
update gooseFxv2 key
jokrsec Jul 11, 2024
ead8956
add support for fee on transfer
jokrsec Jul 11, 2024
5ae7f7d
add support for multiple routes
jokrsec Jul 11, 2024
ef1c210
fix type
sssionggg Jul 11, 2024
fd664f4
Merge pull request #38 from jup-ag/feature/fix-type
jokrsec Jul 11, 2024
202bf07
Merge branch 'main' of github.com:jup-ag/instruction-parser into fix-…
jokrsec Jul 11, 2024
074b51f
add unit test and support for multiple routing instructions
jokrsec Jul 11, 2024
291d0d7
add unit test for fee on transfer
jokrsec Jul 11, 2024
e3ddb50
fix getInitialAndFinalSwapPositions to handle multiple routing instru…
jokrsec Jul 11, 2024
dd7ba57
update getExactOutAmount and getExactInAmount to use route info
jokrsec Jul 12, 2024
edf6309
Merge pull request #39 from jup-ag/fix-event-parser
sssionggg Jul 12, 2024
bcfbaf4
update tests to verify positions, exactInAmount and exactOutAmount
jokrsec Jul 12, 2024
c4b9ec2
Merge branch 'main' of github.com:jup-ag/instruction-parser into fix-…
jokrsec Jul 12, 2024
71d06dc
Merge pull request #40 from jup-ag/fix-event-parser
sssionggg Jul 12, 2024
c7c20a2
update token list api
jokrsec Jul 12, 2024
629d0c2
remove unused imports
jokrsec Jul 12, 2024
2fc8e67
add cache on token list
jokrsec Jul 12, 2024
9bbfae6
add positions for oneIntro
jokrsec Jul 12, 2024
12639c6
add support to inner routing instructions
jokrsec Jul 12, 2024
2088a40
add test
jokrsec Jul 12, 2024
773691d
add snapshot for test
jokrsec Jul 12, 2024
b481a2c
Merge pull request #41 from jup-ag/feature/update-token-list
sssionggg Jul 12, 2024
8c323a6
Merge pull request #42 from jup-ag/fix/inner-routing-instructions
sssionggg Jul 12, 2024
84d7d4c
v6.1.3
sssionggg Jul 17, 2024
bd4e06c
fix: update Jupiter IDL and do not fail on 'createTokenAccount' instr…
serejke Sep 4, 2024
fc16adf
fix: check if parsed instruction is not a memo instruction.
serejke Sep 4, 2024
5c2a7da
log: throw a reasonable error if the DEX is not supported yet.
serejke Sep 5, 2024
8e865bf
fix: support Jupiter Labs Perpetuals DEX.
serejke Sep 5, 2024
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: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ If you will need all of them in order to parse different contract, you can inclu
}
```

## Note

We are using Anchor events for extracting swap details. One downside about this approach is that we cannot longer extract swap details if the log is being truncated.

## Jupiter V4 Contract

For the old V4 contract, check out [v4 tag](https://github.com/jup-ag/instruction-parser/tree/v4).
Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jup-ag/instruction-parser",
"version": "6.0.23",
"version": "6.1.3",
"description": "Parser to parse instruction on the Jupiter v4 program.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -10,11 +10,15 @@
],
"scripts": {
"start": "ts-node src/cli.ts",
"build": "tsup"
"build": "tsup",
"test": "jest"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@jest/globals": "^29.7.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.5",
"tsup": "^6.4.0",
"typescript": "^4.4.4"
},
Expand Down
132 changes: 122 additions & 10 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Connection } from "@solana/web3.js";
import { Command } from "commander";
import { getTokenMap } from "./lib/utils";
import { extract } from ".";
import { JUPITER_V6_PROGRAM_ID } from "./constants";
import { writeFile, mkdir } from "fs/promises";
import * as path from "path";
import { EventParser } from "./lib/event-parser";
import { InstructionParser } from "./lib/instruction-parser";

const program = new Command();
// Make sure JSON.stringify works with BigInt
BigInt.prototype["toJSON"] = function () {
return this.toString();
};

const program = new Command();
program
.command("lookup-tx")
.requiredOption("-s, --signature <signature>")
Expand All @@ -23,16 +31,120 @@ program
console.log("Failed transaction", tx.meta.err);
}

const tokenMap = await getTokenMap();
const result = await extract(
signature,
connection,
tx,
tokenMap,
tx.blockTime
const result = await extract(signature, connection, tx, tx.blockTime);
console.log(result);
});

program
.command("test")
.option("-r --limit <limit>", "limit of transactions", "500")
.requiredOption("-r --rpc <rpc>")
.addHelpText("beforeAll", "Test instruction parser")
.action(async ({ limit, rpc }) => {
const connection = new Connection(rpc);
const signatures = await connection.getSignaturesForAddress(
JUPITER_V6_PROGRAM_ID,
{
limit: parseInt(limit),
}
);

console.log(result);
for (const signature of signatures) {
const tx = await connection.getParsedTransaction(signature.signature, {
maxSupportedTransactionVersion: 0,
});

if (tx.meta.err) {
continue;
}

try {
await extract(signature.signature, connection, tx, tx.blockTime);
console.log("Transaction succesfully extracted: ", signature.signature);
} catch (error) {
console.log(
"Error while extracting transaction: ",
signature.signature,
error
);
}
}
});

program
.command("snapshot")
.requiredOption("-s, --signature <signature>")
.requiredOption("-r, --rpc <rpc>")
.addHelpText("beforeAll", "Snapshot transaction for mock testing")
.action(async ({ signature, rpc }) => {
const directoryPath = path.join(__dirname, `./tests/snapshot/${signature}`);
await mkdir(directoryPath, { recursive: true });

const actualConnection = new Connection(rpc);
const connection = new Proxy(actualConnection, {
get: (target, prop, receiver) => {
switch (prop) {
case "_rpcRequest": {
return async (...args: any[]) => {
const [rpcMethod, restArgs] = args;
if (rpcMethod === "getTransaction") {
const result = await target[prop](...args);
await writeFile(
path.join(directoryPath + `/tx-${signature}.json`),
JSON.stringify(result),
{ flag: "w+" }
);

return result;
}

if (rpcMethod === "getAccountInfo") {
const account = restArgs[0];
const result = await target[prop](...args);
await writeFile(
path.join(directoryPath + `/account-${account}.json`),
JSON.stringify(result),
{ flag: "w+" }
);

return result;
}

return target[prop](...args);
};
}
}

return Reflect.get(target, prop, receiver);
},
});

const tx = await connection.getParsedTransaction(signature, {
maxSupportedTransactionVersion: 0,
});

const eventsParser = new EventParser(connection);
const instructionParser = new InstructionParser(JUPITER_V6_PROGRAM_ID);
const routeInfoList = eventsParser.getRouteInfoList(tx);
for (const [index, routeInfo] of routeInfoList.entries()) {
const parsedEvents = await eventsParser.getParsedEvents(tx, routeInfo);
const [initialPositions, finalPositions] =
instructionParser.getInitialAndFinalSwapPositions(routeInfo);
const exactOutAmount = instructionParser.getExactOutAmount(routeInfo);
const exactInAmount = instructionParser.getExactInAmount(routeInfo);
const swapResult = {
parsedEvents,
initialPositions,
finalPositions,
exactOutAmount,
exactInAmount,
};
await writeFile(
path.join(directoryPath + `/swap-result-${index}.json`),
JSON.stringify(swapResult),
{ flag: "w+" }
);
}
});

program.parse();
Loading