Skip to content

Commit 730e7fc

Browse files
authored
Force shared accounts for Jupiter swaps (#145)
1 parent d448360 commit 730e7fc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/code/server/grpc/transaction/v2/swap.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
176176
50, // todo: configurable slippage or something based on liquidity?
177177
true, // Direct routes for now since we're using legacy instructions
178178
16, // Max accounts limited due to the use of legacy instructions
179+
true, // Use shared accounts so we don't have to manage ATAs
179180
true, // Force legacy instructions
180181
)
181182
if err != nil {

pkg/jupiter/client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func NewClient(baseUrl string) *Client {
4444
type Quote struct {
4545
jsonString string
4646
estimatedSwapAmount uint64
47+
useSharedAccounts bool
4748
useLegacyInstructions bool
4849
}
4950

@@ -60,13 +61,14 @@ func (c *Client) GetQuote(
6061
slippageBps uint32,
6162
forceDirectRoute bool,
6263
maxAccounts uint8,
64+
useSharedAccounts bool,
6365
useLegacyInstruction bool,
6466
) (*Quote, error) {
6567
tracer := metrics.TraceMethodCall(ctx, metricsStructName, "GetQuote")
6668
defer tracer.End()
6769

6870
url := fmt.Sprintf(
69-
"%s%s?inputMint=%s&outputMint=%s&amount=%d&slippageBps=%d&onlyDirectRoutes=%v&maxAccounts=%d&asLegacyTransaction=%v",
71+
"%s%s?inputMint=%s&outputMint=%s&amount=%d&slippageBps=%d&onlyDirectRoutes=%v&maxAccounts=%d&useSharedAccounts=%v&asLegacyTransaction=%v",
7072
c.baseUrl,
7173
quoteEndpointName,
7274
inputMint,
@@ -75,6 +77,7 @@ func (c *Client) GetQuote(
7577
slippageBps,
7678
forceDirectRoute,
7779
maxAccounts,
80+
useSharedAccounts,
7881
useLegacyInstruction,
7982
)
8083

@@ -107,6 +110,7 @@ func (c *Client) GetQuote(
107110
return &Quote{
108111
jsonString: string(respBody),
109112
estimatedSwapAmount: estimatedSwapAmount,
113+
useSharedAccounts: useSharedAccounts,
110114
useLegacyInstructions: useLegacyInstruction,
111115
}, nil
112116
}
@@ -136,10 +140,11 @@ func (c *Client) GetSwapInstructions(
136140

137141
// todo: struct this
138142
reqBody := fmt.Sprintf(
139-
`{"quoteResponse": %s, "userPublicKey": "%s", "destinationTokenAccount": "%s", "prioritizationFeeLamports": "auto", "asLegacyTransaction": %v}`,
143+
`{"quoteResponse": %s, "userPublicKey": "%s", "destinationTokenAccount": "%s", "prioritizationFeeLamports": "auto", "useSharedAccounts": %v, "asLegacyTransaction": %v}`,
140144
quote.jsonString,
141145
owner,
142146
destinationTokenAccount,
147+
quote.useSharedAccounts,
143148
quote.useLegacyInstructions,
144149
)
145150

0 commit comments

Comments
 (0)