Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: JS compress and decompress lamports #572

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 0 additions & 8 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ on:
push:
branches:
- main
paths:
- "js/stateless.js/**"
- "js/compressed-token/**"
- ".github/workflows/js.yml"
pull_request:
branches:
- main
paths:
- "js/stateless.js/**"
- "js/compressed-token/**"
- ".github/workflows/js.yml"
types:
- opened
- synchronize
Expand Down
24 changes: 22 additions & 2 deletions js/compressed-token/src/idl/psp_compressed_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export type PspCompressedToken = {
type: 'bool';
},
{
name: 'deCompressAmount';
name: 'deCompressLamports';
type: {
option: 'u64';
};
Expand Down Expand Up @@ -422,6 +422,16 @@ export type PspCompressedToken = {
option: 'u64';
};
},
{
name: 'deCompressLamports';
type: {
option: 'u64';
};
},
{
name: 'isCompress';
type: 'bool';
},
];
};
},
Expand Down Expand Up @@ -1035,7 +1045,7 @@ export const IDL: PspCompressedToken = {
type: 'bool',
},
{
name: 'deCompressAmount',
name: 'deCompressLamports',
type: {
option: 'u64',
},
Expand Down Expand Up @@ -1125,6 +1135,16 @@ export const IDL: PspCompressedToken = {
option: 'u64',
},
},
{
name: 'deCompressLamports',
type: {
option: 'u64',
},
},
{
name: 'isCompress',
type: 'bool',
},
],
},
},
Expand Down
4 changes: 3 additions & 1 deletion js/stateless.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"test-all": "vitest run",
"test:unit:all": "EXCLUDE_E2E=true vitest run",
"test-validator": "./../../cli/test_bin/run test-validator",
"pretest:e2e": "./../../cli/test_bin/run test-validator -b ",
"gnark-prover": "../../circuit-lib/circuit-lib.js/scripts/prover.sh",
"pretest:e2e": "./../../cli/test_bin/run test-validator -b && pnpm gnark-prover",
"test:e2e:transfer": "pnpm pretest:e2e && vitest run tests/e2e/transfer.test.ts",
"test:e2e:compress": "pnpm pretest:e2e && vitest run tests/e2e/compress.test.ts",
"test:e2e:all": "pnpm pretest:e2e && vitest run tests/e2e/*.test.ts",
"test:index": "vitest run tests/e2e/program.test.ts",
"test:e2e:serde": "vitest run tests/e2e/serde.test.ts",
Expand Down
198 changes: 196 additions & 2 deletions js/stateless.js/src/idls/psp_compressed_pda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
export type PspCompressedPda = {
version: '0.3.0';
name: 'psp_compressed_pda';
constants: [
{
name: 'COMPRESSED_SOL_PDA_SEED';
type: 'bytes';
value: '[99, 111, 109, 112, 114, 101, 115, 115, 101, 100, 95, 115, 111, 108, 95, 112, 100, 97]';
},
];
instructions: [
{
name: 'initCompressSolPda';
docs: [
'Initializes the compressed sol pda.',
'This pda is used to store compressed sol for the protocol.',
];
accounts: [
{
name: 'feePayer';
isMut: true;
isSigner: true;
},
{
name: 'compressedSolPda';
isMut: true;
isSigner: false;
},
{
name: 'systemProgram';
isMut: false;
isSigner: false;
},
];
args: [];
},
{
name: 'executeCompressedTransaction';
docs: [
Expand Down Expand Up @@ -47,6 +79,24 @@ export type PspCompressedPda = {
isSigner: false;
isOptional: true;
},
{
name: 'compressedSolPda';
isMut: true;
isSigner: false;
isOptional: true;
},
{
name: 'deCompressRecipient';
isMut: true;
isSigner: false;
isOptional: true;
},
{
name: 'systemProgram';
isMut: false;
isSigner: false;
isOptional: true;
},
];
args: [
{
Expand All @@ -60,6 +110,13 @@ export type PspCompressedPda = {
},
];
accounts: [
{
name: 'compressedSolPda';
type: {
kind: 'struct';
fields: [];
};
},
{
name: 'cpiSignatureAccount';
docs: [
Expand Down Expand Up @@ -226,7 +283,7 @@ export type PspCompressedPda = {
type: 'bool';
},
{
name: 'deCompressAmount';
name: 'deCompressLamports';
type: {
option: 'u64';
};
Expand Down Expand Up @@ -316,6 +373,16 @@ export type PspCompressedPda = {
option: 'u64';
};
},
{
name: 'deCompressLamports';
type: {
option: 'u64';
};
},
{
name: 'isCompress';
type: 'bool';
},
];
};
},
Expand Down Expand Up @@ -457,13 +524,75 @@ export type PspCompressedPda = {
name: 'DeriveAddressError';
msg: 'DeriveAddressError';
},
{
code: 6022;
name: 'CompressSolTransferFailed';
msg: 'CompressSolTransferFailed';
},
{
code: 6023;
name: 'CompressedSolPdaUndefinedForCompressSol';
msg: 'CompressedSolPdaUndefinedForCompressSol';
},
{
code: 6024;
name: 'DeCompressLamportsUndefinedForCompressSol';
msg: 'DeCompressLamportsUndefinedForCompressSol';
},
{
code: 6025;
name: 'CompressedSolPdaUndefinedForDecompressSol';
msg: 'CompressedSolPdaUndefinedForDecompressSol';
},
{
code: 6026;
name: 'DeCompressLamportsUndefinedForDecompressSol';
msg: 'DeCompressLamportsUndefinedForDecompressSol';
},
{
code: 6027;
name: 'DecompressRecipientUndefinedForDecompressSol';
msg: 'DecompressRecipientUndefinedForDecompressSol';
},
];
};

export const IDL: PspCompressedPda = {
version: '0.3.0',
name: 'psp_compressed_pda',
constants: [
{
name: 'COMPRESSED_SOL_PDA_SEED',
type: 'bytes',
value: '[99, 111, 109, 112, 114, 101, 115, 115, 101, 100, 95, 115, 111, 108, 95, 112, 100, 97]',
},
],
instructions: [
{
name: 'initCompressSolPda',
docs: [
'Initializes the compressed sol pda.',
'This pda is used to store compressed sol for the protocol.',
],
accounts: [
{
name: 'feePayer',
isMut: true,
isSigner: true,
},
{
name: 'compressedSolPda',
isMut: true,
isSigner: false,
},
{
name: 'systemProgram',
isMut: false,
isSigner: false,
},
],
args: [],
},
{
name: 'executeCompressedTransaction',
docs: [
Expand Down Expand Up @@ -509,6 +638,24 @@ export const IDL: PspCompressedPda = {
isSigner: false,
isOptional: true,
},
{
name: 'compressedSolPda',
isMut: true,
isSigner: false,
isOptional: true,
},
{
name: 'deCompressRecipient',
isMut: true,
isSigner: false,
isOptional: true,
},
{
name: 'systemProgram',
isMut: false,
isSigner: false,
isOptional: true,
},
],
args: [
{
Expand All @@ -522,6 +669,13 @@ export const IDL: PspCompressedPda = {
},
],
accounts: [
{
name: 'compressedSolPda',
type: {
kind: 'struct',
fields: [],
},
},
{
name: 'cpiSignatureAccount',
docs: [
Expand Down Expand Up @@ -688,7 +842,7 @@ export const IDL: PspCompressedPda = {
type: 'bool',
},
{
name: 'deCompressAmount',
name: 'deCompressLamports',
type: {
option: 'u64',
},
Expand Down Expand Up @@ -778,6 +932,16 @@ export const IDL: PspCompressedPda = {
option: 'u64',
},
},
{
name: 'deCompressLamports',
type: {
option: 'u64',
},
},
{
name: 'isCompress',
type: 'bool',
},
],
},
},
Expand Down Expand Up @@ -919,5 +1083,35 @@ export const IDL: PspCompressedPda = {
name: 'DeriveAddressError',
msg: 'DeriveAddressError',
},
{
code: 6022,
name: 'CompressSolTransferFailed',
msg: 'CompressSolTransferFailed',
},
{
code: 6023,
name: 'CompressedSolPdaUndefinedForCompressSol',
msg: 'CompressedSolPdaUndefinedForCompressSol',
},
{
code: 6024,
name: 'DeCompressLamportsUndefinedForCompressSol',
msg: 'DeCompressLamportsUndefinedForCompressSol',
},
{
code: 6025,
name: 'CompressedSolPdaUndefinedForDecompressSol',
msg: 'CompressedSolPdaUndefinedForDecompressSol',
},
{
code: 6026,
name: 'DeCompressLamportsUndefinedForDecompressSol',
msg: 'DeCompressLamportsUndefinedForDecompressSol',
},
{
code: 6027,
name: 'DecompressRecipientUndefinedForDecompressSol',
msg: 'DecompressRecipientUndefinedForDecompressSol',
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function packCompressedAccounts(
_remainingAccounts,
account.merkleTree,
);

const nullifierQueuePubkeyIndex = getIndexOrAdd(
_remainingAccounts,
account.nullifierQueue,
Expand Down
Loading
Loading