Skip to content

Commit

Permalink
Merge pull request #3 from solana-fm/fix/system-program-string-decode
Browse files Browse the repository at this point in the history
fix: string decoding for system program ix
  • Loading branch information
doodoo-aihc authored Oct 25, 2023
2 parents bee7bb9 + caab7e5 commit 43fecd1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-ghosts-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solanafm/explorer-kit": patch
---

fix: fix system program instructions string args not decoding properly due to bincode serialization"
2 changes: 1 addition & 1 deletion packages/explorerkit-idls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clean": "rimraf .turbo && rimraf node_modules && rimraf dist",
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
"lint:fix": "TIMING=1 eslint \"src/**/*.ts*\" --fix",
"publish-package": "npm publish --access=public"
"publish-package": "pnpm build && npm publish --access=public"
},
"keywords": [],
"author": "SolanaFM",
Expand Down
2 changes: 1 addition & 1 deletion packages/explorerkit-translator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clean": "rimraf .turbo && rimraf node_modules && rimraf dist",
"lint": "TIMING=1 eslint \"src/**/*.ts*\"",
"lint:fix": "TIMING=1 eslint \"src/**/*.ts*\" --fix",
"publish-package": "npm publish --access=public"
"publish-package": "pnpm build && npm publish --access=public"
},
"keywords": [],
"author": "SolanaFM",
Expand Down
18 changes: 18 additions & 0 deletions packages/explorerkit-translator/src/helpers/KinobiTreeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
unit,
} from "@metaplex-foundation/umi/serializers";
import {
assertStringTypeNode,
assertStructFieldTypeNode,
bytesTypeNode,
createFromIdls,
Expand Down Expand Up @@ -116,6 +117,23 @@ export class KinobiTreeGenerator {
},
])
);
} else if (idl.metadata.address === "11111111111111111111111111111111") {
kinobiTree.update(
new TransformNodesVisitor([
{
selector: { kind: "structFieldTypeNode", name: "seed" },
transformer: (node) => {
assertStructFieldTypeNode(node);
return structFieldTypeNode({
...node,
child: stringTypeNode({
size: prefixedSize(numberTypeNode("u64")),
}),
});
},
},
])
);
}

this.rootNode = kinobiTree.getRoot();
Expand Down
21 changes: 21 additions & 0 deletions packages/explorerkit-translator/tests/v2/instruction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ describe("createShankParser", () => {
}
}
});

it("should construct an shank instruction parser for a given valid IDL and parses a createAccountWithSeed instruction", async () => {
const programId = "11111111111111111111111111111111";
const idlItem = await getProgramIdl(programId);
const instructionData =
"2Xryq2Rm8AVqNzd2gDapkK7mqHKfz5Pu6XYXP4wRtDaYaPaSgoViaxxNzRpvkj2p91YVCJq1He1pGHENJ3RfofrAxuxeYfo96X2kRyxGLGDLjcwZxZGRHJ7NDE6RExSMrK8M85D";

if (idlItem) {
const parser = new SolanaFMParser(idlItem, programId);
const instructionParser = parser.createParser(ParserType.INSTRUCTION);

if (instructionParser && checkIfInstructionParser(instructionParser)) {
const decodedData = instructionParser.parseInstructions(instructionData);
expect(decodedData).not.toBeNull();
expect(decodedData?.type).toBe("instruction");
expect(decodedData?.name).toBe("createAccountWithSeed");
expect(decodedData?.data["seed"]).toBe("stake:2");
expect(decodedData?.data["lamports"]).toBe("12000000000");
}
}
});
});

describe("createCustomKinobiParser", () => {
Expand Down

0 comments on commit 43fecd1

Please sign in to comment.