@syndicure/vault-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +90 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +184 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +36 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +44 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions/admin.d.ts +136 -0
- package/dist/instructions/admin.d.ts.map +1 -0
- package/dist/instructions/admin.js +227 -0
- package/dist/instructions/admin.js.map +1 -0
- package/dist/instructions/liquidity.d.ts +50 -0
- package/dist/instructions/liquidity.d.ts.map +1 -0
- package/dist/instructions/liquidity.js +118 -0
- package/dist/instructions/liquidity.js.map +1 -0
- package/dist/instructions/nft.d.ts +80 -0
- package/dist/instructions/nft.d.ts.map +1 -0
- package/dist/instructions/nft.js +159 -0
- package/dist/instructions/nft.js.map +1 -0
- package/dist/instructions/swap.d.ts +57 -0
- package/dist/instructions/swap.d.ts.map +1 -0
- package/dist/instructions/swap.js +117 -0
- package/dist/instructions/swap.js.map +1 -0
- package/dist/pda.d.ts +28 -0
- package/dist/pda.d.ts.map +1 -0
- package/dist/pda.js +59 -0
- package/dist/pda.js.map +1 -0
- package/dist/pool/fetcher.d.ts +23 -0
- package/dist/pool/fetcher.d.ts.map +1 -0
- package/dist/pool/fetcher.js +171 -0
- package/dist/pool/fetcher.js.map +1 -0
- package/dist/pool/index.d.ts +53 -0
- package/dist/pool/index.d.ts.map +1 -0
- package/dist/pool/index.js +90 -0
- package/dist/pool/index.js.map +1 -0
- package/dist/routing/pathfinder.d.ts +25 -0
- package/dist/routing/pathfinder.d.ts.map +1 -0
- package/dist/routing/pathfinder.js +116 -0
- package/dist/routing/pathfinder.js.map +1 -0
- package/dist/routing/quote.d.ts +53 -0
- package/dist/routing/quote.d.ts.map +1 -0
- package/dist/routing/quote.js +145 -0
- package/dist/routing/quote.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — NFT pool instruction builders.
|
|
4
|
+
*
|
|
5
|
+
* Builds transactions for:
|
|
6
|
+
* - swap_token_for_nft
|
|
7
|
+
* - swap_nft_for_token
|
|
8
|
+
* - add_liquidity_token_nft
|
|
9
|
+
* - remove_liquidity_token_nft
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.buildSwapTokenForNft = buildSwapTokenForNft;
|
|
13
|
+
exports.buildSwapNftForToken = buildSwapNftForToken;
|
|
14
|
+
exports.buildAddLiquidityNft = buildAddLiquidityNft;
|
|
15
|
+
exports.buildRemoveLiquidityNft = buildRemoveLiquidityNft;
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const pda_1 = require("../pda");
|
|
20
|
+
// ─── Helpers ─────────────────────────────────────────────────
|
|
21
|
+
function tokenProgramForA(pool) {
|
|
22
|
+
return pool.assetAIsToken2022
|
|
23
|
+
? new web3_js_1.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
|
|
24
|
+
: spl_token_1.TOKEN_PROGRAM_ID;
|
|
25
|
+
}
|
|
26
|
+
async function buildSwapTokenForNft(opts) {
|
|
27
|
+
const pid = opts.programId ?? constants_1.PROGRAM_ID;
|
|
28
|
+
const [configPda] = (0, pda_1.deriveConfigPda)(pid);
|
|
29
|
+
const [treasuryPda] = (0, pda_1.deriveTreasuryPda)(pid);
|
|
30
|
+
const [nftEscrow] = (0, pda_1.deriveNftEscrowPda)(opts.pool.address, opts.nftMint, pid);
|
|
31
|
+
return opts.program.methods
|
|
32
|
+
.swapTokenForNft(opts.maxCost)
|
|
33
|
+
.accounts({
|
|
34
|
+
user: opts.user,
|
|
35
|
+
config: configPda,
|
|
36
|
+
pool: opts.pool.address,
|
|
37
|
+
assetAMint: opts.pool.assetAMint,
|
|
38
|
+
vaultA: opts.pool.vaultA,
|
|
39
|
+
userTokenA: opts.userTokenA,
|
|
40
|
+
treasury: treasuryPda,
|
|
41
|
+
treasuryFeeAccount: opts.treasuryFeeAccount,
|
|
42
|
+
nftMint: opts.nftMint,
|
|
43
|
+
nftMetadata: opts.nftMetadata,
|
|
44
|
+
poolNftAccount: opts.poolNftAccount,
|
|
45
|
+
userNftAccount: opts.userNftAccount,
|
|
46
|
+
nftEscrow,
|
|
47
|
+
creatorFeeVault: (0, pda_1.deriveCreatorFeeVaultPda)(opts.pool.address, pid)[0],
|
|
48
|
+
tokenProgramA: tokenProgramForA(opts.pool),
|
|
49
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
50
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
51
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
52
|
+
})
|
|
53
|
+
.preInstructions([
|
|
54
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
55
|
+
units: opts.computeUnits ?? 400000,
|
|
56
|
+
}),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
async function buildSwapNftForToken(opts) {
|
|
60
|
+
const pid = opts.programId ?? constants_1.PROGRAM_ID;
|
|
61
|
+
const [configPda] = (0, pda_1.deriveConfigPda)(pid);
|
|
62
|
+
const [treasuryPda] = (0, pda_1.deriveTreasuryPda)(pid);
|
|
63
|
+
const [nftEscrow] = (0, pda_1.deriveNftEscrowPda)(opts.pool.address, opts.nftMint, pid);
|
|
64
|
+
return opts.program.methods
|
|
65
|
+
.swapNftForToken(opts.minPayout)
|
|
66
|
+
.accounts({
|
|
67
|
+
user: opts.user,
|
|
68
|
+
config: configPda,
|
|
69
|
+
pool: opts.pool.address,
|
|
70
|
+
assetAMint: opts.pool.assetAMint,
|
|
71
|
+
vaultA: opts.pool.vaultA,
|
|
72
|
+
userTokenA: opts.userTokenA,
|
|
73
|
+
treasury: treasuryPda,
|
|
74
|
+
treasuryFeeAccount: opts.treasuryFeeAccount,
|
|
75
|
+
nftMint: opts.nftMint,
|
|
76
|
+
nftMetadata: opts.nftMetadata,
|
|
77
|
+
userNftAccount: opts.userNftAccount,
|
|
78
|
+
poolNftAccount: opts.poolNftAccount,
|
|
79
|
+
nftEscrow,
|
|
80
|
+
creatorFeeVault: (0, pda_1.deriveCreatorFeeVaultPda)(opts.pool.address, pid)[0],
|
|
81
|
+
tokenProgramA: tokenProgramForA(opts.pool),
|
|
82
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
83
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
84
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
85
|
+
})
|
|
86
|
+
.preInstructions([
|
|
87
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
88
|
+
units: opts.computeUnits ?? 400000,
|
|
89
|
+
}),
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
async function buildAddLiquidityNft(opts) {
|
|
93
|
+
const pid = opts.programId ?? constants_1.PROGRAM_ID;
|
|
94
|
+
const [configPda] = (0, pda_1.deriveConfigPda)(pid);
|
|
95
|
+
const [lpMint] = (0, pda_1.deriveLpMintPda)(opts.pool.address, pid);
|
|
96
|
+
const [position] = (0, pda_1.derivePositionPda)(opts.pool.address, opts.user, pid);
|
|
97
|
+
const [nftEscrow] = (0, pda_1.deriveNftEscrowPda)(opts.pool.address, opts.nftMint, pid);
|
|
98
|
+
return opts.program.methods
|
|
99
|
+
.addLiquidityTokenNft(opts.tokenAmount)
|
|
100
|
+
.accounts({
|
|
101
|
+
user: opts.user,
|
|
102
|
+
config: configPda,
|
|
103
|
+
pool: opts.pool.address,
|
|
104
|
+
vaultA: opts.pool.vaultA,
|
|
105
|
+
assetAMint: opts.pool.assetAMint,
|
|
106
|
+
lpMint,
|
|
107
|
+
userTokenA: opts.userTokenA,
|
|
108
|
+
userLpAccount: opts.userLpAccount,
|
|
109
|
+
position,
|
|
110
|
+
nftMint: opts.nftMint,
|
|
111
|
+
nftMetadata: opts.nftMetadata,
|
|
112
|
+
userNftAccount: opts.userNftAccount,
|
|
113
|
+
poolNftAccount: opts.poolNftAccount,
|
|
114
|
+
nftEscrow,
|
|
115
|
+
tokenProgramA: tokenProgramForA(opts.pool),
|
|
116
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
117
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
118
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
119
|
+
})
|
|
120
|
+
.preInstructions([
|
|
121
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
122
|
+
units: opts.computeUnits ?? 400000,
|
|
123
|
+
}),
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
async function buildRemoveLiquidityNft(opts) {
|
|
127
|
+
const pid = opts.programId ?? constants_1.PROGRAM_ID;
|
|
128
|
+
const [configPda] = (0, pda_1.deriveConfigPda)(pid);
|
|
129
|
+
const [lpMint] = (0, pda_1.deriveLpMintPda)(opts.pool.address, pid);
|
|
130
|
+
const [position] = (0, pda_1.derivePositionPda)(opts.pool.address, opts.user, pid);
|
|
131
|
+
const [nftEscrow] = (0, pda_1.deriveNftEscrowPda)(opts.pool.address, opts.nftMint, pid);
|
|
132
|
+
return opts.program.methods
|
|
133
|
+
.removeLiquidityTokenNft(opts.lpTokensToBurn)
|
|
134
|
+
.accounts({
|
|
135
|
+
user: opts.user,
|
|
136
|
+
config: configPda,
|
|
137
|
+
pool: opts.pool.address,
|
|
138
|
+
vaultA: opts.pool.vaultA,
|
|
139
|
+
assetAMint: opts.pool.assetAMint,
|
|
140
|
+
lpMint,
|
|
141
|
+
userTokenA: opts.userTokenA,
|
|
142
|
+
userLpAccount: opts.userLpAccount,
|
|
143
|
+
position,
|
|
144
|
+
nftMint: opts.nftMint,
|
|
145
|
+
poolNftAccount: opts.poolNftAccount,
|
|
146
|
+
userNftAccount: opts.userNftAccount,
|
|
147
|
+
nftEscrow,
|
|
148
|
+
tokenProgramA: tokenProgramForA(opts.pool),
|
|
149
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
150
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
151
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
152
|
+
})
|
|
153
|
+
.preInstructions([
|
|
154
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
155
|
+
units: opts.computeUnits ?? 400000,
|
|
156
|
+
}),
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=nft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nft.js","sourceRoot":"","sources":["../../src/instructions/nft.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAuDH,oDAiCC;AAoBD,oDAiCC;AAmBD,oDAkCC;AAkBD,0DAiCC;AAlPD,6CAIyB;AACzB,iDAG2B;AAE3B,4CAA0C;AAC1C,gCAOgB;AAEhB,gEAAgE;AAEhE,SAAS,gBAAgB,CAAC,IAAU;IAClC,OAAO,IAAI,CAAC,iBAAiB;QAC3B,CAAC,CAAC,IAAI,mBAAS,CAAC,6CAA6C,CAAC;QAC9D,CAAC,CAAC,4BAAgB,CAAC;AACvB,CAAC;AA0BM,KAAK,UAAU,oBAAoB,CAAC,IAAyB;IAClE,MAAM,GAAG,GAAG,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AC,IAAI,CAAC,UAAU;QAChC,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,QAAQ;QACR,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,SAAS;QACT,aAAa,EAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1C,YAAY,EAAE,4BAAgB;QAC9B,sBAAsB,EAAE,uCAA2B;QACnD,aAAa,EAAE,uBAAa,CAAC,SAAS;KACvC,CAAC;SACD,eAAe,CAAC;QACf,8BAAoB,CAAC,mBAAmB,CAAC;YACvC,KAAK,EAAE,IAAI,CAAC,YAAY,IAAI,MAAO;SACpC,CAAC;KACH,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — Swap instruction builder.
|
|
3
|
+
*
|
|
4
|
+
* Builds swap_tokens transactions for 1–3 hop routes with the
|
|
5
|
+
* correct `remaining_accounts` layout.
|
|
6
|
+
*
|
|
7
|
+
* Layout per hop (intermediate = 9 accounts, final = 8 accounts):
|
|
8
|
+
* [0] pool writable
|
|
9
|
+
* [1] mintA read-only
|
|
10
|
+
* [2] mintB read-only
|
|
11
|
+
* [3] vaultA writable
|
|
12
|
+
* [4] vaultB writable
|
|
13
|
+
* [5] tokenProgramA read-only
|
|
14
|
+
* [6] tokenProgramB read-only
|
|
15
|
+
* [7] treasuryFee writable
|
|
16
|
+
* [8] userInterToken writable (intermediate hops only)
|
|
17
|
+
*/
|
|
18
|
+
import { Program } from "@coral-xyz/anchor";
|
|
19
|
+
import { PublicKey } from "@solana/web3.js";
|
|
20
|
+
import { SwapQuote } from "../types";
|
|
21
|
+
export interface BuildSwapOpts {
|
|
22
|
+
/** Anchor program instance. */
|
|
23
|
+
program: Program<any>;
|
|
24
|
+
/** The wallet executing the swap. */
|
|
25
|
+
user: PublicKey;
|
|
26
|
+
/** Quote obtained from the routing module. */
|
|
27
|
+
quote: SwapQuote;
|
|
28
|
+
/** User ATA for the input token. */
|
|
29
|
+
userInputToken: PublicKey;
|
|
30
|
+
/** User ATA for the output token. */
|
|
31
|
+
userOutputToken: PublicKey;
|
|
32
|
+
/**
|
|
33
|
+
* User ATAs for intermediate tokens (between hops).
|
|
34
|
+
* Required for 2+ hop routes: index 0 = ATA for token
|
|
35
|
+
* between hop 0 and hop 1, etc.
|
|
36
|
+
*/
|
|
37
|
+
userIntermediateTokens?: PublicKey[];
|
|
38
|
+
/** Override treasury PDA (defaults to derived). */
|
|
39
|
+
treasuryPda?: PublicKey;
|
|
40
|
+
/** Override config PDA (defaults to derived). */
|
|
41
|
+
configPda?: PublicKey;
|
|
42
|
+
/** Override program ID. */
|
|
43
|
+
programId?: PublicKey;
|
|
44
|
+
/** Compute unit limit (default 400_000). */
|
|
45
|
+
computeUnits?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build a complete swap_tokens transaction.
|
|
49
|
+
*
|
|
50
|
+
* Returns the method builder — call `.rpc()` or `.transaction()` on it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildSwapTransaction(opts: BuildSwapOpts): Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* Convenience: build + send a swap transaction, returning the signature.
|
|
55
|
+
*/
|
|
56
|
+
export declare function executeSwap(opts: BuildSwapOpts): Promise<string>;
|
|
57
|
+
//# sourceMappingURL=swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/instructions/swap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAM,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAO,SAAS,EAAQ,MAAM,UAAU,CAAC;AAMhD,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACtB,qCAAqC;IACrC,IAAI,EAAE,SAAS,CAAC;IAChB,8CAA8C;IAC9C,KAAK,EAAE,SAAS,CAAC;IACjB,oCAAoC;IACpC,cAAc,EAAE,SAAS,CAAC;IAC1B,qCAAqC;IACrC,eAAe,EAAE,SAAS,CAAC;IAC3B;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,SAAS,EAAE,CAAC;IACrC,mDAAmD;IACnD,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,iDAAiD;IACjD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA+ED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CA2C5E;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAGtE"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — Swap instruction builder.
|
|
4
|
+
*
|
|
5
|
+
* Builds swap_tokens transactions for 1–3 hop routes with the
|
|
6
|
+
* correct `remaining_accounts` layout.
|
|
7
|
+
*
|
|
8
|
+
* Layout per hop (intermediate = 9 accounts, final = 8 accounts):
|
|
9
|
+
* [0] pool writable
|
|
10
|
+
* [1] mintA read-only
|
|
11
|
+
* [2] mintB read-only
|
|
12
|
+
* [3] vaultA writable
|
|
13
|
+
* [4] vaultB writable
|
|
14
|
+
* [5] tokenProgramA read-only
|
|
15
|
+
* [6] tokenProgramB read-only
|
|
16
|
+
* [7] treasuryFee writable
|
|
17
|
+
* [8] userInterToken writable (intermediate hops only)
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.buildSwapTransaction = buildSwapTransaction;
|
|
21
|
+
exports.executeSwap = executeSwap;
|
|
22
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
23
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
24
|
+
const pda_1 = require("../pda");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
// ─── Helpers ─────────────────────────────────────────────────
|
|
27
|
+
function tokenProgramForMint(pool, isA) {
|
|
28
|
+
const is2022 = isA ? pool.assetAIsToken2022 : pool.assetBIsToken2022;
|
|
29
|
+
// Token-2022 program ID
|
|
30
|
+
return is2022
|
|
31
|
+
? new web3_js_1.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
|
|
32
|
+
: spl_token_1.TOKEN_PROGRAM_ID;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Derive the treasury ATA for the fee mint.
|
|
36
|
+
* Fee is always taken on the INPUT side of the hop.
|
|
37
|
+
*/
|
|
38
|
+
async function deriveTreasuryFeeAccount(hop, treasuryPda) {
|
|
39
|
+
const feeMint = hop.aToB ? hop.pool.assetAMint : hop.pool.assetBMint;
|
|
40
|
+
return (0, spl_token_1.getAssociatedTokenAddress)(feeMint, treasuryPda, true);
|
|
41
|
+
}
|
|
42
|
+
// ─── Builder ─────────────────────────────────────────────────
|
|
43
|
+
/**
|
|
44
|
+
* Build remaining_accounts for a multi-hop swap.
|
|
45
|
+
*
|
|
46
|
+
* @returns [remainingAccounts, hopDirections]
|
|
47
|
+
*/
|
|
48
|
+
async function buildRemainingAccounts(hops, treasuryPda, userIntermediateTokens) {
|
|
49
|
+
const remaining = [];
|
|
50
|
+
const directions = [];
|
|
51
|
+
for (let i = 0; i < hops.length; i++) {
|
|
52
|
+
const hop = hops[i];
|
|
53
|
+
const pool = hop.pool;
|
|
54
|
+
const isLast = i === hops.length - 1;
|
|
55
|
+
const treasuryFee = await deriveTreasuryFeeAccount(hop, treasuryPda);
|
|
56
|
+
const tokenProgramA = tokenProgramForMint(pool, true);
|
|
57
|
+
const tokenProgramB = tokenProgramForMint(pool, false);
|
|
58
|
+
remaining.push({ pubkey: pool.address, isSigner: false, isWritable: true }, { pubkey: pool.assetAMint, isSigner: false, isWritable: false }, { pubkey: pool.assetBMint, isSigner: false, isWritable: false }, { pubkey: pool.vaultA, isSigner: false, isWritable: true }, { pubkey: pool.vaultB, isSigner: false, isWritable: true }, { pubkey: tokenProgramA, isSigner: false, isWritable: false }, { pubkey: tokenProgramB, isSigner: false, isWritable: false }, { pubkey: treasuryFee, isSigner: false, isWritable: true });
|
|
59
|
+
// Intermediate hops include user's intermediate token account
|
|
60
|
+
if (!isLast) {
|
|
61
|
+
if (!userIntermediateTokens[i]) {
|
|
62
|
+
throw new Error(`Missing userIntermediateTokens[${i}] for hop ${i} → ${i + 1}`);
|
|
63
|
+
}
|
|
64
|
+
remaining.push({
|
|
65
|
+
pubkey: userIntermediateTokens[i],
|
|
66
|
+
isSigner: false,
|
|
67
|
+
isWritable: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
directions.push(hop.aToB);
|
|
71
|
+
}
|
|
72
|
+
return [remaining, directions];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a complete swap_tokens transaction.
|
|
76
|
+
*
|
|
77
|
+
* Returns the method builder — call `.rpc()` or `.transaction()` on it.
|
|
78
|
+
*/
|
|
79
|
+
async function buildSwapTransaction(opts) {
|
|
80
|
+
const programId = opts.programId ?? constants_1.PROGRAM_ID;
|
|
81
|
+
const [configPda] = opts.configPda
|
|
82
|
+
? [opts.configPda]
|
|
83
|
+
: (0, pda_1.deriveConfigPda)(programId);
|
|
84
|
+
const [treasuryPda] = opts.treasuryPda
|
|
85
|
+
? [opts.treasuryPda]
|
|
86
|
+
: (0, pda_1.deriveTreasuryPda)(programId);
|
|
87
|
+
const hops = opts.quote.route.hops;
|
|
88
|
+
const numHops = hops.length;
|
|
89
|
+
const [remaining, directions] = await buildRemainingAccounts(hops, treasuryPda, opts.userIntermediateTokens ?? []);
|
|
90
|
+
const builder = opts.program.methods
|
|
91
|
+
.swapTokens(opts.quote.amountIn, opts.quote.minimumOutput, numHops, directions)
|
|
92
|
+
.accounts({
|
|
93
|
+
user: opts.user,
|
|
94
|
+
config: configPda,
|
|
95
|
+
userInputToken: opts.userInputToken,
|
|
96
|
+
userOutputToken: opts.userOutputToken,
|
|
97
|
+
treasury: treasuryPda,
|
|
98
|
+
creatorFeeVault: (0, pda_1.deriveCreatorFeeVaultPda)(hops[0].pool.address, opts.programId ?? constants_1.PROGRAM_ID)[0],
|
|
99
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
100
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
101
|
+
})
|
|
102
|
+
.remainingAccounts(remaining)
|
|
103
|
+
.preInstructions([
|
|
104
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
105
|
+
units: opts.computeUnits ?? 400000,
|
|
106
|
+
}),
|
|
107
|
+
]);
|
|
108
|
+
return builder;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Convenience: build + send a swap transaction, returning the signature.
|
|
112
|
+
*/
|
|
113
|
+
async function executeSwap(opts) {
|
|
114
|
+
const builder = await buildSwapTransaction(opts);
|
|
115
|
+
return builder.rpc();
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/instructions/swap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AAiIH,oDA2CC;AAKD,kCAGC;AAjLD,6CAKyB;AACzB,iDAI2B;AAE3B,gCAAsF;AACtF,4CAA0C;AA+B1C,gEAAgE;AAEhE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,CAAC,CAAC,CAAC;QAChG,sBAAsB,EAAE,uCAA2B;QACnD,aAAa,EAAE,uBAAa,CAAC,SAAS;KACvC,CAAC;SACD,iBAAiB,CAAC,SAAS,CAAC;SAC5B,eAAe,CAAC;QACf,8BAAoB,CAAC,mBAAmB,CAAC;YACvC,KAAK,EAAE,IAAI,CAAC,YAAY,IAAI,MAAO;SACpC,CAAC;KACH,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,WAAW,CAAC,IAAmB;IACnD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/pda.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — PDA derivation helpers.
|
|
3
|
+
*/
|
|
4
|
+
import { PublicKey } from "@solana/web3.js";
|
|
5
|
+
/** Derive the singleton ProtocolConfig PDA. */
|
|
6
|
+
export declare function deriveConfigPda(programId?: PublicKey): [PublicKey, number];
|
|
7
|
+
/** Derive the treasury PDA. */
|
|
8
|
+
export declare function deriveTreasuryPda(programId?: PublicKey): [PublicKey, number];
|
|
9
|
+
/**
|
|
10
|
+
* Derive the Pool PDA.
|
|
11
|
+
* Mints are auto-sorted into canonical order (mintA < mintB).
|
|
12
|
+
* Returns `[poolPda, bump, sortedMintA, sortedMintB]`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function derivePoolPda(mintA: PublicKey, mintB: PublicKey, programId?: PublicKey): [PublicKey, number, PublicKey, PublicKey];
|
|
15
|
+
/** Derive the LP mint PDA for a given pool. */
|
|
16
|
+
export declare function deriveLpMintPda(poolPda: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
17
|
+
/** Derive the liquidity position PDA for a user + pool pair. */
|
|
18
|
+
export declare function derivePositionPda(poolPda: PublicKey, user: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
19
|
+
/** Derive the NFT escrow PDA. */
|
|
20
|
+
export declare function deriveNftEscrowPda(poolPda: PublicKey, nftMint: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
21
|
+
/**
|
|
22
|
+
* Sort two mints into canonical (ascending byte) order.
|
|
23
|
+
* This matches the on-chain constraint `asset_a_mint < asset_b_mint`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sortMints(a: PublicKey, b: PublicKey): [PublicKey, PublicKey];
|
|
26
|
+
/** Derive the CreatorFeeVault PDA for a given pool. */
|
|
27
|
+
export declare function deriveCreatorFeeVaultPda(poolPda: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
28
|
+
//# sourceMappingURL=pda.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pda.d.ts","sourceRoot":"","sources":["../src/pda.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,SAAS,YAAa,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAK3E;AAED,+BAA+B;AAC/B,wBAAgB,iBAAiB,CAAC,SAAS,YAAa,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAK7E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAChB,SAAS,YAAa,GACrB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAO3C;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,EAClB,SAAS,YAAa,GACrB,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,SAAS,EACf,SAAS,YAAa,GACrB,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED,iCAAiC;AACjC,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,SAAS,EAClB,SAAS,YAAa,GACrB,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAI5E;AAED,uDAAuD;AACvD,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,SAAS,EAClB,SAAS,YAAa,GACrB,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB"}
|
package/dist/pda.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — PDA derivation helpers.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deriveConfigPda = deriveConfigPda;
|
|
7
|
+
exports.deriveTreasuryPda = deriveTreasuryPda;
|
|
8
|
+
exports.derivePoolPda = derivePoolPda;
|
|
9
|
+
exports.deriveLpMintPda = deriveLpMintPda;
|
|
10
|
+
exports.derivePositionPda = derivePositionPda;
|
|
11
|
+
exports.deriveNftEscrowPda = deriveNftEscrowPda;
|
|
12
|
+
exports.sortMints = sortMints;
|
|
13
|
+
exports.deriveCreatorFeeVaultPda = deriveCreatorFeeVaultPda;
|
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
/** Derive the singleton ProtocolConfig PDA. */
|
|
17
|
+
function deriveConfigPda(programId = constants_1.PROGRAM_ID) {
|
|
18
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.PROTOCOL_CONFIG_SEED], programId);
|
|
19
|
+
}
|
|
20
|
+
/** Derive the treasury PDA. */
|
|
21
|
+
function deriveTreasuryPda(programId = constants_1.PROGRAM_ID) {
|
|
22
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.TREASURY_SEED], programId);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Derive the Pool PDA.
|
|
26
|
+
* Mints are auto-sorted into canonical order (mintA < mintB).
|
|
27
|
+
* Returns `[poolPda, bump, sortedMintA, sortedMintB]`.
|
|
28
|
+
*/
|
|
29
|
+
function derivePoolPda(mintA, mintB, programId = constants_1.PROGRAM_ID) {
|
|
30
|
+
const [sorted0, sorted1] = sortMints(mintA, mintB);
|
|
31
|
+
const [pda, bump] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.POOL_SEED, sorted0.toBuffer(), sorted1.toBuffer()], programId);
|
|
32
|
+
return [pda, bump, sorted0, sorted1];
|
|
33
|
+
}
|
|
34
|
+
/** Derive the LP mint PDA for a given pool. */
|
|
35
|
+
function deriveLpMintPda(poolPda, programId = constants_1.PROGRAM_ID) {
|
|
36
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.LP_MINT_SEED, poolPda.toBuffer()], programId);
|
|
37
|
+
}
|
|
38
|
+
/** Derive the liquidity position PDA for a user + pool pair. */
|
|
39
|
+
function derivePositionPda(poolPda, user, programId = constants_1.PROGRAM_ID) {
|
|
40
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.LP_POSITION_SEED, poolPda.toBuffer(), user.toBuffer()], programId);
|
|
41
|
+
}
|
|
42
|
+
/** Derive the NFT escrow PDA. */
|
|
43
|
+
function deriveNftEscrowPda(poolPda, nftMint, programId = constants_1.PROGRAM_ID) {
|
|
44
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.NFT_ESCROW_SEED, poolPda.toBuffer(), nftMint.toBuffer()], programId);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sort two mints into canonical (ascending byte) order.
|
|
48
|
+
* This matches the on-chain constraint `asset_a_mint < asset_b_mint`.
|
|
49
|
+
*/
|
|
50
|
+
function sortMints(a, b) {
|
|
51
|
+
const bufA = a.toBuffer();
|
|
52
|
+
const bufB = b.toBuffer();
|
|
53
|
+
return Buffer.compare(bufA, bufB) <= 0 ? [a, b] : [b, a];
|
|
54
|
+
}
|
|
55
|
+
/** Derive the CreatorFeeVault PDA for a given pool. */
|
|
56
|
+
function deriveCreatorFeeVaultPda(poolPda, programId = constants_1.PROGRAM_ID) {
|
|
57
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.CREATOR_FEE_SEED, poolPda.toBuffer()], programId);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=pda.js.map
|
package/dist/pda.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pda.js","sourceRoot":"","sources":["../src/pda.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAeH,0CAKC;AAGD,8CAKC;AAOD,sCAWC;AAGD,0CAQC;AAGD,8CASC;AAGD,gDASC;AAMD,8BAIC;AAGD,4DAQC;AApGD,6CAA4C;AAC5C,2CASqB;AAErB,+CAA+C;AAC/C,SAAgB,eAAe,CAAC,SAAS,GAAG,sBAAU;IACpD,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,gCAAoB,CAAC,EACtB,SAAS,CACV,CAAC;AACJ,CAAC;AAED,+BAA+B;AAC/B,SAAgB,iBAAiB,CAAC,SAAS,GAAG,sBAAU;IACtD,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,yBAAa,CAAC,EACf,SAAS,CACV,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,KAAgB,EAChB,KAAgB,EAChB,SAAS,GAAG,sBAAU;IAEtB,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,mBAAS,CAAC,sBAAsB,CAClD,CAAC,qBAAS,EAAE,OAAO,CAAC,QAAQ,E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,OAAkB,EAClB,SAAS,GAAG,sBAAU;IAEtB,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,4BAAgB,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EACtC,SAAS,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — Pool account deserialization.
|
|
3
|
+
*
|
|
4
|
+
* Uses raw `getProgramAccounts` with discriminator filter + borsh layout
|
|
5
|
+
* so the SDK does not depend on a full Anchor Program instance.
|
|
6
|
+
*/
|
|
7
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
8
|
+
import { Pool, ProtocolConfig } from "../types";
|
|
9
|
+
/** Parse a Pool from raw account data + its public key. */
|
|
10
|
+
export declare function deserializePool(address: PublicKey, data: Buffer): Pool;
|
|
11
|
+
/**
|
|
12
|
+
* Fetch all Pool accounts from the program.
|
|
13
|
+
* Uses a single `getProgramAccounts` call with a discriminator filter.
|
|
14
|
+
*/
|
|
15
|
+
export declare function fetchAllPools(connection: Connection, programId?: PublicKey): Promise<Pool[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Fetch a single Pool by its PDA address.
|
|
18
|
+
* Returns `null` if the account does not exist.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fetchPool(connection: Connection, poolAddress: PublicKey): Promise<Pool | null>;
|
|
21
|
+
/** Fetch and deserialize the ProtocolConfig. Returns `null` if not found. */
|
|
22
|
+
export declare function fetchConfig(connection: Connection, programId?: PublicKey): Promise<ProtocolConfig | null>;
|
|
23
|
+
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/pool/fetcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,IAAI,EAAY,cAAc,EAAE,MAAM,UAAU,CAAC;AA6E1D,2DAA2D;AAC3D,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,MAAM,GACX,IAAI,CA6BN;AAID;;;GAGG;AACH,wBAAsB,aAAa,CACjC,UAAU,EAAE,UAAU,EACtB,SAAS,YAAa,GACrB,OAAO,CAAC,IAAI,EAAE,CAAC,CAUjB;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,SAAS,GACrB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAItB;AAoBD,6EAA6E;AAC7E,wBAAsB,WAAW,CAC/B,UAAU,EAAE,UAAU,EACtB,SAAS,YAAa,GACrB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAmBhC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — Pool account deserialization.
|
|
4
|
+
*
|
|
5
|
+
* Uses raw `getProgramAccounts` with discriminator filter + borsh layout
|
|
6
|
+
* so the SDK does not depend on a full Anchor Program instance.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deserializePool = deserializePool;
|
|
13
|
+
exports.fetchAllPools = fetchAllPools;
|
|
14
|
+
exports.fetchPool = fetchPool;
|
|
15
|
+
exports.fetchConfig = fetchConfig;
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const pda_1 = require("../pda");
|
|
20
|
+
// ─── Anchor discriminator (first 8 bytes of sha256("account:Pool")) ──
|
|
21
|
+
const POOL_DISCRIMINATOR = Buffer.from([
|
|
22
|
+
241, 154, 109, 4, 17, 177, 109, 188,
|
|
23
|
+
]);
|
|
24
|
+
// ─── Borsh layout offsets for Pool ───────────────────────────
|
|
25
|
+
// Anchor prepends an 8-byte discriminator. All offsets below are
|
|
26
|
+
// relative to the start of the account data (i.e., include the discriminator).
|
|
27
|
+
const OFF_CREATOR = 8;
|
|
28
|
+
const OFF_ASSET_A_MINT = 40;
|
|
29
|
+
const OFF_ASSET_B_MINT = 72;
|
|
30
|
+
const OFF_POOL_TYPE = 104; // 1 byte enum
|
|
31
|
+
const OFF_VAULT_A = 105;
|
|
32
|
+
const OFF_VAULT_B = 137;
|
|
33
|
+
const OFF_NFT_ESCROW_COUNT = 169; // u32 LE
|
|
34
|
+
const OFF_LP_MINT = 173;
|
|
35
|
+
const OFF_TOTAL_LP_SUPPLY = 205; // u64 LE
|
|
36
|
+
const OFF_RESERVE_A = 213;
|
|
37
|
+
const OFF_RESERVE_B = 221;
|
|
38
|
+
const OFF_CUMULATIVE_FEE_A = 229;
|
|
39
|
+
const OFF_CUMULATIVE_FEE_B = 237;
|
|
40
|
+
const OFF_FEE_PER_SHARE_A = 245; // u128 LE (16 bytes)
|
|
41
|
+
const OFF_FEE_PER_SHARE_B = 261;
|
|
42
|
+
const OFF_LAST_PRICE = 277; // u64 LE
|
|
43
|
+
const OFF_IS_LOCKED = 285; // bool
|
|
44
|
+
const OFF_IS_ACTIVE = 286;
|
|
45
|
+
const OFF_ASSET_A_IS_TOKEN_2022 = 287;
|
|
46
|
+
const OFF_ASSET_B_IS_TOKEN_2022 = 288;
|
|
47
|
+
const OFF_POOL_FEE_BPS = 289; // u16 LE
|
|
48
|
+
const OFF_BASE_PRICE = 291; // u64 LE
|
|
49
|
+
const OFF_CURVE_DELTA = 299;
|
|
50
|
+
const OFF_CREATED_AT = 307; // i64 LE
|
|
51
|
+
const OFF_BUMP = 315;
|
|
52
|
+
// ─── Helpers ─────────────────────────────────────────────────
|
|
53
|
+
function readPubkey(buf, offset) {
|
|
54
|
+
return new web3_js_1.PublicKey(buf.subarray(offset, offset + 32));
|
|
55
|
+
}
|
|
56
|
+
function readU64(buf, offset) {
|
|
57
|
+
return new bn_js_1.default(buf.subarray(offset, offset + 8), "le");
|
|
58
|
+
}
|
|
59
|
+
function readU128(buf, offset) {
|
|
60
|
+
return new bn_js_1.default(buf.subarray(offset, offset + 16), "le");
|
|
61
|
+
}
|
|
62
|
+
function readI64(buf, offset) {
|
|
63
|
+
return new bn_js_1.default(buf.subarray(offset, offset + 8), "le");
|
|
64
|
+
}
|
|
65
|
+
function readU16(buf, offset) {
|
|
66
|
+
return buf.readUInt16LE(offset);
|
|
67
|
+
}
|
|
68
|
+
function readU32(buf, offset) {
|
|
69
|
+
return buf.readUInt32LE(offset);
|
|
70
|
+
}
|
|
71
|
+
function readBool(buf, offset) {
|
|
72
|
+
return buf[offset] !== 0;
|
|
73
|
+
}
|
|
74
|
+
function readPoolType(buf, offset) {
|
|
75
|
+
const v = buf[offset];
|
|
76
|
+
if (v > 3)
|
|
77
|
+
throw new Error(`Unknown PoolType variant: ${v}`);
|
|
78
|
+
return v;
|
|
79
|
+
}
|
|
80
|
+
// ─── Deserialize a single Pool ───────────────────────────────
|
|
81
|
+
/** Parse a Pool from raw account data + its public key. */
|
|
82
|
+
function deserializePool(address, data) {
|
|
83
|
+
return {
|
|
84
|
+
address,
|
|
85
|
+
creator: readPubkey(data, OFF_CREATOR),
|
|
86
|
+
assetAMint: readPubkey(data, OFF_ASSET_A_MINT),
|
|
87
|
+
assetBMint: readPubkey(data, OFF_ASSET_B_MINT),
|
|
88
|
+
poolType: readPoolType(data, OFF_POOL_TYPE),
|
|
89
|
+
vaultA: readPubkey(data, OFF_VAULT_A),
|
|
90
|
+
vaultB: readPubkey(data, OFF_VAULT_B),
|
|
91
|
+
nftEscrowCount: readU32(data, OFF_NFT_ESCROW_COUNT),
|
|
92
|
+
lpMint: readPubkey(data, OFF_LP_MINT),
|
|
93
|
+
totalLpSupply: readU64(data, OFF_TOTAL_LP_SUPPLY),
|
|
94
|
+
reserveA: readU64(data, OFF_RESERVE_A),
|
|
95
|
+
reserveB: readU64(data, OFF_RESERVE_B),
|
|
96
|
+
cumulativeFeeA: readU64(data, OFF_CUMULATIVE_FEE_A),
|
|
97
|
+
cumulativeFeeB: readU64(data, OFF_CUMULATIVE_FEE_B),
|
|
98
|
+
feePerShareA: readU128(data, OFF_FEE_PER_SHARE_A),
|
|
99
|
+
feePerShareB: readU128(data, OFF_FEE_PER_SHARE_B),
|
|
100
|
+
lastPrice: readU64(data, OFF_LAST_PRICE),
|
|
101
|
+
isLocked: readBool(data, OFF_IS_LOCKED),
|
|
102
|
+
isActive: readBool(data, OFF_IS_ACTIVE),
|
|
103
|
+
assetAIsToken2022: readBool(data, OFF_ASSET_A_IS_TOKEN_2022),
|
|
104
|
+
assetBIsToken2022: readBool(data, OFF_ASSET_B_IS_TOKEN_2022),
|
|
105
|
+
poolFeeBps: readU16(data, OFF_POOL_FEE_BPS),
|
|
106
|
+
basePrice: readU64(data, OFF_BASE_PRICE),
|
|
107
|
+
curveDelta: readU64(data, OFF_CURVE_DELTA),
|
|
108
|
+
createdAt: readI64(data, OFF_CREATED_AT),
|
|
109
|
+
bump: data[OFF_BUMP],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// ─── Fetch helpers ───────────────────────────────────────────
|
|
113
|
+
/**
|
|
114
|
+
* Fetch all Pool accounts from the program.
|
|
115
|
+
* Uses a single `getProgramAccounts` call with a discriminator filter.
|
|
116
|
+
*/
|
|
117
|
+
async function fetchAllPools(connection, programId = constants_1.PROGRAM_ID) {
|
|
118
|
+
const accounts = await connection.getProgramAccounts(programId, {
|
|
119
|
+
filters: [
|
|
120
|
+
{ memcmp: { offset: 0, bytes: POOL_DISCRIMINATOR.toString("base64") } },
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
return accounts.map(({ pubkey, account }) => deserializePool(pubkey, account.data));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetch a single Pool by its PDA address.
|
|
127
|
+
* Returns `null` if the account does not exist.
|
|
128
|
+
*/
|
|
129
|
+
async function fetchPool(connection, poolAddress) {
|
|
130
|
+
const info = await connection.getAccountInfo(poolAddress);
|
|
131
|
+
if (!info)
|
|
132
|
+
return null;
|
|
133
|
+
return deserializePool(poolAddress, info.data);
|
|
134
|
+
}
|
|
135
|
+
// ─── Config discriminator (sha256("account:ProtocolConfig")[..8]) ──
|
|
136
|
+
const CONFIG_DISCRIMINATOR = Buffer.from([
|
|
137
|
+
222, 70, 13, 54, 120, 240, 223, 72,
|
|
138
|
+
]);
|
|
139
|
+
const CFG_OFF_AUTHORITY = 8;
|
|
140
|
+
const CFG_OFF_TREASURY = 40;
|
|
141
|
+
const CFG_OFF_POOL_CREATION_FEE = 72; // u64
|
|
142
|
+
const CFG_OFF_SWAP_FEE_BPS = 80; // u16
|
|
143
|
+
const CFG_OFF_TREASURY_FEE_BPS = 82; // u16
|
|
144
|
+
const CFG_OFF_TOTAL_POOLS = 84; // u64
|
|
145
|
+
const CFG_OFF_IS_PAUSED = 92; // bool
|
|
146
|
+
const CFG_OFF_BUMP = 93; // u8
|
|
147
|
+
const CFG_OFF_TREASURY_BUMP = 94; // u8
|
|
148
|
+
const CFG_OFF_TOKEN_SWAP_SOL_FEE = 95; // u64
|
|
149
|
+
const CFG_OFF_NFT_SWAP_SOL_FEE = 103; // u64
|
|
150
|
+
/** Fetch and deserialize the ProtocolConfig. Returns `null` if not found. */
|
|
151
|
+
async function fetchConfig(connection, programId = constants_1.PROGRAM_ID) {
|
|
152
|
+
const [configPda] = (0, pda_1.deriveConfigPda)(programId);
|
|
153
|
+
const info = await connection.getAccountInfo(configPda);
|
|
154
|
+
if (!info)
|
|
155
|
+
return null;
|
|
156
|
+
const data = info.data;
|
|
157
|
+
return {
|
|
158
|
+
authority: readPubkey(data, CFG_OFF_AUTHORITY),
|
|
159
|
+
treasury: readPubkey(data, CFG_OFF_TREASURY),
|
|
160
|
+
poolCreationFee: readU64(data, CFG_OFF_POOL_CREATION_FEE),
|
|
161
|
+
swapFeeBps: readU16(data, CFG_OFF_SWAP_FEE_BPS),
|
|
162
|
+
treasuryFeeBps: readU16(data, CFG_OFF_TREASURY_FEE_BPS),
|
|
163
|
+
totalPools: readU64(data, CFG_OFF_TOTAL_POOLS),
|
|
164
|
+
isPaused: readBool(data, CFG_OFF_IS_PAUSED),
|
|
165
|
+
bump: data[CFG_OFF_BUMP],
|
|
166
|
+
treasuryBump: data[CFG_OFF_TREASURY_BUMP],
|
|
167
|
+
tokenSwapSolFee: readU64(data, CFG_OFF_TOKEN_SWAP_SOL_FEE),
|
|
168
|
+
nftSwapSolFee: readU64(data, CFG_OFF_NFT_SWAP_SOL_FEE),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=fetcher.js.map
|