Skip to content

Commit

Permalink
Add swap variants which provide token program accounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Jan 6, 2025
1 parent 5a99aba commit e1af124
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,49 @@ static GlamJupiterProgramClient createClient(final GlamProgramAccountClient nati

JupiterAccounts jupiterAccounts();

List<Instruction> swapChecked(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL);
default List<Instruction> swapChecked(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL) {
return swapChecked(
null, inputMintKey, inputTokenProgram,
null, outputMintKey, outputTokenProgram,
amount,
swapInstruction,
wrapSOL
);
}

default List<Instruction> swapChecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL) {
final var tokenProgram = solanaAccounts().readTokenProgram();
return swapChecked(
inputProgramStateKey, inputMintKey, tokenProgram,
outputProgramStateKey, outputMintKey, tokenProgram,
amount, swapInstruction, wrapSOL
);
}

default List<Instruction> swapChecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final long amount,
final Instruction swapInstruction) {
return swapChecked(
inputProgramStateKey, inputMintKey,
outputProgramStateKey, outputMintKey,
amount, swapInstruction, true
);
}

default List<Instruction> swapChecked(final PublicKey inputMintKey,
final PublicKey outputMintKey,
Expand Down Expand Up @@ -58,21 +94,43 @@ List<Instruction> swapChecked(final PublicKey inputProgramStateKey,
final Instruction swapInstruction,
final boolean wrapSOL);

Instruction swapUncheckedAndNoWrap(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction);
default Instruction swapUncheckedAndNoWrap(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction) {
return swapUncheckedAndNoWrap(
null, inputMintKey, inputTokenProgram,
null, outputMintKey, outputTokenProgram,
amount,
swapInstruction
);
}

default Instruction swapUncheckedAndNoWrap(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final long amount,
final Instruction swapInstruction) {
final var tokenProgram = solanaAccounts().readTokenProgram();
return swapUncheckedAndNoWrap(
inputProgramStateKey, inputMintKey, tokenProgram,
outputProgramStateKey, outputMintKey, tokenProgram,
amount,
swapInstruction
);
}

default Instruction swapUncheckedAndNoWrap(final PublicKey inputMintKey,
final PublicKey outputMintKey,
final long amount,
final Instruction swapInstruction) {
final var tokenProgram = solanaAccounts().readTokenProgram();
return swapUncheckedAndNoWrap(
inputMintKey, tokenProgram,
outputMintKey, tokenProgram,
null, inputMintKey, tokenProgram,
null, outputMintKey, tokenProgram,
amount,
swapInstruction
);
Expand All @@ -87,13 +145,50 @@ Instruction swapUncheckedAndNoWrap(final PublicKey inputProgramStateKey,
final long amount,
final Instruction swapInstruction);

List<Instruction> swapUnchecked(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL);
default List<Instruction> swapUnchecked(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
long amount,
final Instruction swapInstruction,
final boolean wrapSOL) {
return swapUnchecked(
null, inputMintKey, inputTokenProgram,
null, outputMintKey, outputTokenProgram,
amount,
swapInstruction,
wrapSOL
);
}

default List<Instruction> swapUnchecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL) {
final var tokenProgram = solanaAccounts().readTokenProgram();
return swapUnchecked(
inputProgramStateKey, inputMintKey, tokenProgram,
outputProgramStateKey, outputMintKey, tokenProgram,
amount, swapInstruction, wrapSOL
);
}

default List<Instruction> swapUnchecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final long amount,
final Instruction swapInstruction) {
final var tokenProgram = solanaAccounts().readTokenProgram();
return swapUnchecked(
inputProgramStateKey, inputMintKey, tokenProgram,
outputProgramStateKey, outputMintKey, tokenProgram,
amount, swapInstruction, true
);
}

default List<Instruction> swapUnchecked(final PublicKey inputMintKey,
final PublicKey outputMintKey,
Expand All @@ -111,4 +206,14 @@ default List<Instruction> swapUnchecked(final PublicKey inputMintKey,
final var tokenProgram = solanaAccounts().readTokenProgram();
return swapUnchecked(inputMintKey, tokenProgram, outputMintKey, tokenProgram, amount, swapInstruction, true);
}

List<Instruction> swapUnchecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ private Instruction jupiterSwap(final PublicKey inputTreasuryATA,
).extraAccounts(swapInstruction.accounts());
}


@Override
public List<Instruction> swapChecked(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL) {
return swapChecked(
null,
inputMintKey,
inputTokenProgram,
null,
outputMintKey,
outputTokenProgram,
amount,
swapInstruction,
wrapSOL
);
}

@Override
public List<Instruction> swapChecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
Expand Down Expand Up @@ -159,25 +137,6 @@ public List<Instruction> swapChecked(final PublicKey inputProgramStateKey,
}
}

@Override
public Instruction swapUncheckedAndNoWrap(final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction) {
return swapUncheckedAndNoWrap(
null,
inputMintKey,
inputTokenProgram,
null,
outputMintKey,
outputTokenProgram,
amount,
swapInstruction
);
}

@Override
public Instruction swapUncheckedAndNoWrap(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
Expand Down Expand Up @@ -212,16 +171,18 @@ public Instruction swapUncheckedAndNoWrap(final PublicKey inputProgramStateKey,
}

@Override
public List<Instruction> swapUnchecked(final PublicKey inputMintKey,
public List<Instruction> swapUnchecked(final PublicKey inputProgramStateKey,
final PublicKey inputMintKey,
final AccountMeta inputTokenProgram,
final PublicKey outputProgramStateKey,
final PublicKey outputMintKey,
final AccountMeta outputTokenProgram,
final long amount,
final Instruction swapInstruction,
final boolean wrapSOL) {
final var glamJupiterSwap = swapUncheckedAndNoWrap(
inputMintKey, inputTokenProgram,
outputMintKey, outputTokenProgram,
inputProgramStateKey, inputMintKey, inputTokenProgram,
outputProgramStateKey, outputMintKey, outputTokenProgram,
amount,
swapInstruction
);
Expand Down

0 comments on commit e1af124

Please sign in to comment.