Skip to content

Swap RPC implementation #40

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

Merged
merged 13 commits into from
Jan 22, 2024
Prev Previous commit
Next Next commit
Minor renames
  • Loading branch information
jeffyanta committed Jan 18, 2024
commit 559960e8638dd495decc8e9d1eeb371da4889030
12 changes: 6 additions & 6 deletions pkg/code/server/grpc/transaction/v2/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
}
txn.SetBlockhash(blockhash)

computeUnitLimit, _ := compute_budget.ParseSetComputeUnitLimitIxnData(jupiterSwapIxns.ComputeBudgetInstructions[0].Data)
computeUnitPrice, _ := compute_budget.ParseSetComputeUnitPriceIxnData(jupiterSwapIxns.ComputeBudgetInstructions[1].Data)
computeUnitLimit, _ := compute_budget.DecompileSetComputeUnitLimitIxnData(jupiterSwapIxns.ComputeBudgetInstructions[0].Data)
computeUnitPrice, _ := compute_budget.DecompileSetComputeUnitPriceIxnData(jupiterSwapIxns.ComputeBudgetInstructions[1].Data)

var protoSwapIxnAccounts []*commonpb.InstructionAccount
for _, ixnAccount := range jupiterSwapIxns.SwapInstruction.Accounts {
Expand Down Expand Up @@ -329,11 +329,11 @@ func (s *transactionServer) validateJupiterIxns(ixns *jupiter.SwapInstructions)
return errors.New("invalid ComputeBudget instruction accounts")
}

if _, err := compute_budget.ParseSetComputeUnitLimitIxnData(ixns.ComputeBudgetInstructions[0].Data); err != nil {
if _, err := compute_budget.DecompileSetComputeUnitLimitIxnData(ixns.ComputeBudgetInstructions[0].Data); err != nil {
return errors.Wrap(err, "invalid ComputeBudget::SetComputeUnitLimit instruction data")
}

if _, err := compute_budget.ParseSetComputeUnitPriceIxnData(ixns.ComputeBudgetInstructions[1].Data); err != nil {
if _, err := compute_budget.DecompileSetComputeUnitPriceIxnData(ixns.ComputeBudgetInstructions[1].Data); err != nil {
return errors.Wrap(err, "invalid ComputeBudget::SetComputeUnitPrice instruction data")
}

Expand All @@ -358,12 +358,12 @@ func (s *transactionServer) mustLoadSwapSubsidizer(ctx context.Context) {
return err
}

ownerAccount, err := common.NewAccountFromPrivateKeyString(vaultRecord.PrivateKey)
authorityAccount, err := common.NewAccountFromPrivateKeyString(vaultRecord.PrivateKey)
if err != nil {
return err
}

s.swapSubsidizer = ownerAccount
s.swapSubsidizer = authorityAccount
return nil
}()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/computebudget/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func SetComputeUnitPrice(computeUnitPrice uint64) solana.Instruction {
)
}

func ParseSetComputeUnitLimitIxnData(data []byte) (uint32, error) {
func DecompileSetComputeUnitLimitIxnData(data []byte) (uint32, error) {
if len(data) != 5 {
return 0, errors.New("invalid length")
}
Expand All @@ -52,7 +52,7 @@ func ParseSetComputeUnitLimitIxnData(data []byte) (uint32, error) {
return binary.LittleEndian.Uint32(data[1:]), nil
}

func ParseSetComputeUnitPriceIxnData(data []byte) (uint64, error) {
func DecompileSetComputeUnitPriceIxnData(data []byte) (uint64, error) {
if len(data) != 9 {
return 0, errors.New("invalid length")
}
Expand Down