@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 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../src/pool/fetcher.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAmFH,0CAgCC;AAQD,sCAaC;AAMD,8BAOC;AAqBD,kCAsBC;AA9LD,6CAAwD;AACxD,kDAAuB;AACvB,4CAA0C;AAE1C,gCAAyC;AAEzC,wEAAwE;AAExE,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC;IACrC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CACpC,CAAC,CAAC;AAEH,gEAAgE;AAChE,iEAAiE;AACjE,+EAA+E;AAE/E,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,aAAa,GAAG,GAAG,CAAC,CAAE,cAAc;AAC1C,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,SAAS;AAC3C,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,mBAAmB,GAAG,GAAG,CAAC,CAAC,SAAS;AAC1C,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,mBAAmB,GAAG,GAAG,CAAC,CAA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,CAAC;IACxD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;IAEjC,OAAO;QACL,SAAS,EAAE,UAAU,CAAC,IAAI,EAAE,iBAAiB,CAAC;QAC9C,QAAQ,EAAE,UAAU,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAC5C,eAAe,EAAE,OAAO,CAAC,IAAI,EAAE,yBAAyB,CAAC;QACzD,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,oBAAoB,CAAC;QAC/C,cAAc,EAAE,OAAO,CAAC,IAAI,EAAE,wBAAwB,CAAC;QACvD,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,mBAAmB,CAAC;QAC9C,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;QAC3C,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC;QACxB,YAAY,EAAE,IAAI,CAAC,qBAAqB,CAAC;QACzC,eAAe,EAAE,OAAO,CAAC,IAAI,EAAE,0BAA0B,CAAC;QAC1D,aAAa,EAAE,OAAO,CAAC,IAAI,EAAE,wBAAwB,CAAC;KACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — Pool index for fast lookup and routing.
|
|
3
|
+
*
|
|
4
|
+
* Builds in-memory maps from mints → pools, enabling O(1) lookups
|
|
5
|
+
* and efficient graph traversal for route finding.
|
|
6
|
+
*/
|
|
7
|
+
import { PublicKey } from "@solana/web3.js";
|
|
8
|
+
import { Pool, PoolType } from "../types";
|
|
9
|
+
/** Indexed view of all pools for fast lookups. */
|
|
10
|
+
export interface PoolIndex {
|
|
11
|
+
/** All pools loaded from chain. */
|
|
12
|
+
all: Pool[];
|
|
13
|
+
/** Pool lookup by its PDA address string. */
|
|
14
|
+
byAddress: Map<string, Pool>;
|
|
15
|
+
/**
|
|
16
|
+
* Canonical pair key → Pool.
|
|
17
|
+
* Key format: `"mintA_base58:mintB_base58"` (already sorted on-chain).
|
|
18
|
+
*/
|
|
19
|
+
byMintPair: Map<string, Pool>;
|
|
20
|
+
/**
|
|
21
|
+
* Mint → all pools that contain that mint (as A or B).
|
|
22
|
+
* Key is the mint's base58 string.
|
|
23
|
+
*/
|
|
24
|
+
byMint: Map<string, Pool[]>;
|
|
25
|
+
/**
|
|
26
|
+
* For NFT pools: collection mint → pools.
|
|
27
|
+
* Key is the collection (asset_b_mint for NFT pools) base58 string.
|
|
28
|
+
*/
|
|
29
|
+
byCollection: Map<string, Pool[]>;
|
|
30
|
+
/** Pools grouped by type. */
|
|
31
|
+
byType: Map<PoolType, Pool[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Token routing adjacency map.
|
|
34
|
+
* Key: mint base58 → Set of directly reachable mint base58 strings.
|
|
35
|
+
* Only includes active TokenToken pools.
|
|
36
|
+
*/
|
|
37
|
+
tokenGraph: Map<string, Set<string>>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a PoolIndex from a list of pools.
|
|
41
|
+
* Only active pools are included in the routing graph.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildPoolIndex(pools: Pool[]): PoolIndex;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve the pool for a canonical mint pair from the index.
|
|
46
|
+
* Mints are auto-sorted so caller order doesn't matter.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getPoolByMints(index: PoolIndex, mintA: PublicKey, mintB: PublicKey): Pool | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Get all unique token mints that appear in active TokenToken pools.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getAllTokenMints(index: PoolIndex): PublicKey[];
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pool/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE1C,kDAAkD;AAClD,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,GAAG,EAAE,IAAI,EAAE,CAAC;IAEZ,6CAA6C;IAC7C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE7B;;;OAGG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE9B;;;OAGG;IACH,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5B;;;OAGG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAElC,6BAA6B;IAC7B,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAE9B;;;;OAIG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,CAyCvD;AAmBD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,GACf,IAAI,GAAG,SAAS,CAKlB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,CAS9D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — Pool index for fast lookup and routing.
|
|
4
|
+
*
|
|
5
|
+
* Builds in-memory maps from mints → pools, enabling O(1) lookups
|
|
6
|
+
* and efficient graph traversal for route finding.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.buildPoolIndex = buildPoolIndex;
|
|
10
|
+
exports.getPoolByMints = getPoolByMints;
|
|
11
|
+
exports.getAllTokenMints = getAllTokenMints;
|
|
12
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
/**
|
|
15
|
+
* Build a PoolIndex from a list of pools.
|
|
16
|
+
* Only active pools are included in the routing graph.
|
|
17
|
+
*/
|
|
18
|
+
function buildPoolIndex(pools) {
|
|
19
|
+
const byAddress = new Map();
|
|
20
|
+
const byMintPair = new Map();
|
|
21
|
+
const byMint = new Map();
|
|
22
|
+
const byCollection = new Map();
|
|
23
|
+
const byType = new Map();
|
|
24
|
+
const tokenGraph = new Map();
|
|
25
|
+
for (const pool of pools) {
|
|
26
|
+
const addr = pool.address.toBase58();
|
|
27
|
+
byAddress.set(addr, pool);
|
|
28
|
+
// Pair key
|
|
29
|
+
const mintA = pool.assetAMint.toBase58();
|
|
30
|
+
const mintB = pool.assetBMint.toBase58();
|
|
31
|
+
byMintPair.set(`${mintA}:${mintB}`, pool);
|
|
32
|
+
// By-mint index
|
|
33
|
+
pushToMap(byMint, mintA, pool);
|
|
34
|
+
pushToMap(byMint, mintB, pool);
|
|
35
|
+
// By-type index
|
|
36
|
+
pushToMap(byType, pool.poolType, pool);
|
|
37
|
+
// Collection index (NFT pools)
|
|
38
|
+
if (pool.poolType === types_1.PoolType.TokenNft ||
|
|
39
|
+
pool.poolType === types_1.PoolType.TokenPnft ||
|
|
40
|
+
pool.poolType === types_1.PoolType.TokenCoreNft) {
|
|
41
|
+
pushToMap(byCollection, mintB, pool);
|
|
42
|
+
}
|
|
43
|
+
// Token graph (only active TokenToken pools)
|
|
44
|
+
if (pool.poolType === types_1.PoolType.TokenToken && pool.isActive) {
|
|
45
|
+
getOrCreate(tokenGraph, mintA).add(mintB);
|
|
46
|
+
getOrCreate(tokenGraph, mintB).add(mintA);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { all: pools, byAddress, byMintPair, byMint, byCollection, byType, tokenGraph };
|
|
50
|
+
}
|
|
51
|
+
// ─── Helpers ─────────────────────────────────────────────────
|
|
52
|
+
function pushToMap(map, key, value) {
|
|
53
|
+
const arr = map.get(key);
|
|
54
|
+
if (arr)
|
|
55
|
+
arr.push(value);
|
|
56
|
+
else
|
|
57
|
+
map.set(key, [value]);
|
|
58
|
+
}
|
|
59
|
+
function getOrCreate(map, key) {
|
|
60
|
+
let set = map.get(key);
|
|
61
|
+
if (!set) {
|
|
62
|
+
set = new Set();
|
|
63
|
+
map.set(key, set);
|
|
64
|
+
}
|
|
65
|
+
return set;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve the pool for a canonical mint pair from the index.
|
|
69
|
+
* Mints are auto-sorted so caller order doesn't matter.
|
|
70
|
+
*/
|
|
71
|
+
function getPoolByMints(index, mintA, mintB) {
|
|
72
|
+
const a = mintA.toBase58();
|
|
73
|
+
const b = mintB.toBase58();
|
|
74
|
+
// On-chain: asset_a_mint < asset_b_mint (byte-sorted), but we try both orders
|
|
75
|
+
return index.byMintPair.get(`${a}:${b}`) ?? index.byMintPair.get(`${b}:${a}`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get all unique token mints that appear in active TokenToken pools.
|
|
79
|
+
*/
|
|
80
|
+
function getAllTokenMints(index) {
|
|
81
|
+
const mints = new Set();
|
|
82
|
+
for (const pool of index.all) {
|
|
83
|
+
if (pool.poolType === types_1.PoolType.TokenToken && pool.isActive) {
|
|
84
|
+
mints.add(pool.assetAMint.toBase58());
|
|
85
|
+
mints.add(pool.assetBMint.toBase58());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return Array.from(mints).map((s) => new web3_js_1.PublicKey(s));
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["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AAK,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC3B,8EAA8E;IAC9E,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAgB;IAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,QAAQ,KAAK,gBAAQ,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3D,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;YACtC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,mBAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — Route finding via BFS over the pool graph.
|
|
3
|
+
*
|
|
4
|
+
* Discovers all paths (up to MAX_HOPS) between two token mints,
|
|
5
|
+
* using only active TokenToken pools.
|
|
6
|
+
*/
|
|
7
|
+
import { PublicKey } from "@solana/web3.js";
|
|
8
|
+
import { Route } from "../types";
|
|
9
|
+
import { PoolIndex } from "../pool/index";
|
|
10
|
+
/**
|
|
11
|
+
* Find all token-swap routes from `inputMint` to `outputMint`.
|
|
12
|
+
*
|
|
13
|
+
* Uses BFS limited to `maxHops` (default 3). Each route is a
|
|
14
|
+
* sequence of 1–3 hops through distinct TokenToken pools.
|
|
15
|
+
*
|
|
16
|
+
* @returns Array of routes sorted by fewest hops (ascending).
|
|
17
|
+
* Empty if no path exists.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findRoutes(index: PoolIndex, inputMint: PublicKey, outputMint: PublicKey, maxHops?: number): Route[];
|
|
20
|
+
/**
|
|
21
|
+
* Get all token mints reachable from `inputMint` within `maxHops`.
|
|
22
|
+
* Useful for populating output-token selector UI.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getReachableMints(index: PoolIndex, inputMint: PublicKey, maxHops?: number): PublicKey[];
|
|
25
|
+
//# sourceMappingURL=pathfinder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathfinder.d.ts","sourceRoot":"","sources":["../../src/routing/pathfinder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAa,KAAK,EAAO,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,SAAS,EAAkB,MAAM,eAAe,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,OAAO,GAAE,MAAiB,GACzB,KAAK,EAAE,CA6ET;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,SAAS,EACpB,OAAO,GAAE,MAAiB,GACzB,SAAS,EAAE,CA4Bb"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — Route finding via BFS over the pool graph.
|
|
4
|
+
*
|
|
5
|
+
* Discovers all paths (up to MAX_HOPS) between two token mints,
|
|
6
|
+
* using only active TokenToken pools.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.findRoutes = findRoutes;
|
|
10
|
+
exports.getReachableMints = getReachableMints;
|
|
11
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
const index_1 = require("../pool/index");
|
|
15
|
+
/**
|
|
16
|
+
* Find all token-swap routes from `inputMint` to `outputMint`.
|
|
17
|
+
*
|
|
18
|
+
* Uses BFS limited to `maxHops` (default 3). Each route is a
|
|
19
|
+
* sequence of 1–3 hops through distinct TokenToken pools.
|
|
20
|
+
*
|
|
21
|
+
* @returns Array of routes sorted by fewest hops (ascending).
|
|
22
|
+
* Empty if no path exists.
|
|
23
|
+
*/
|
|
24
|
+
function findRoutes(index, inputMint, outputMint, maxHops = constants_1.MAX_HOPS) {
|
|
25
|
+
const inputStr = inputMint.toBase58();
|
|
26
|
+
const outputStr = outputMint.toBase58();
|
|
27
|
+
if (inputStr === outputStr)
|
|
28
|
+
return [];
|
|
29
|
+
const routes = [];
|
|
30
|
+
const queue = [
|
|
31
|
+
{ mint: inputStr, hops: [], visitedPools: new Set() },
|
|
32
|
+
];
|
|
33
|
+
while (queue.length > 0) {
|
|
34
|
+
const node = queue.shift();
|
|
35
|
+
if (node.hops.length >= maxHops)
|
|
36
|
+
continue;
|
|
37
|
+
// Get all mints reachable from current mint
|
|
38
|
+
const neighbours = index.tokenGraph.get(node.mint);
|
|
39
|
+
if (!neighbours)
|
|
40
|
+
continue;
|
|
41
|
+
for (const nextMintStr of neighbours) {
|
|
42
|
+
// Find the pool connecting node.mint ↔ nextMintStr
|
|
43
|
+
const currentMint = new web3_js_1.PublicKey(node.mint);
|
|
44
|
+
const nextMint = new web3_js_1.PublicKey(nextMintStr);
|
|
45
|
+
const pool = (0, index_1.getPoolByMints)(index, currentMint, nextMint);
|
|
46
|
+
if (!pool)
|
|
47
|
+
continue;
|
|
48
|
+
if (!pool.isActive)
|
|
49
|
+
continue;
|
|
50
|
+
if (pool.poolType !== types_1.PoolType.TokenToken)
|
|
51
|
+
continue;
|
|
52
|
+
const poolAddr = pool.address.toBase58();
|
|
53
|
+
if (node.visitedPools.has(poolAddr))
|
|
54
|
+
continue;
|
|
55
|
+
// Determine direction
|
|
56
|
+
const aToB = pool.assetAMint.toBase58() === node.mint;
|
|
57
|
+
const hop = {
|
|
58
|
+
pool,
|
|
59
|
+
aToB,
|
|
60
|
+
inputMint: currentMint,
|
|
61
|
+
outputMint: nextMint,
|
|
62
|
+
};
|
|
63
|
+
const newHops = [...node.hops, hop];
|
|
64
|
+
const newVisited = new Set(node.visitedPools);
|
|
65
|
+
newVisited.add(poolAddr);
|
|
66
|
+
if (nextMintStr === outputStr) {
|
|
67
|
+
// Found a complete route
|
|
68
|
+
routes.push({
|
|
69
|
+
hops: newHops,
|
|
70
|
+
inputMint,
|
|
71
|
+
outputMint,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else if (newHops.length < maxHops) {
|
|
75
|
+
// Continue searching
|
|
76
|
+
queue.push({
|
|
77
|
+
mint: nextMintStr,
|
|
78
|
+
hops: newHops,
|
|
79
|
+
visitedPools: newVisited,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Sort: fewest hops first, then by pool address (stable)
|
|
85
|
+
routes.sort((a, b) => a.hops.length - b.hops.length);
|
|
86
|
+
return routes;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get all token mints reachable from `inputMint` within `maxHops`.
|
|
90
|
+
* Useful for populating output-token selector UI.
|
|
91
|
+
*/
|
|
92
|
+
function getReachableMints(index, inputMint, maxHops = constants_1.MAX_HOPS) {
|
|
93
|
+
const inputStr = inputMint.toBase58();
|
|
94
|
+
const reachable = new Set();
|
|
95
|
+
const queue = [{ mint: inputStr, depth: 0 }];
|
|
96
|
+
const visited = new Set([inputStr]);
|
|
97
|
+
while (queue.length > 0) {
|
|
98
|
+
const { mint, depth } = queue.shift();
|
|
99
|
+
if (depth >= maxHops)
|
|
100
|
+
continue;
|
|
101
|
+
const neighbours = index.tokenGraph.get(mint);
|
|
102
|
+
if (!neighbours)
|
|
103
|
+
continue;
|
|
104
|
+
for (const next of neighbours) {
|
|
105
|
+
reachable.add(next);
|
|
106
|
+
if (!visited.has(next)) {
|
|
107
|
+
visited.add(next);
|
|
108
|
+
queue.push({ mint: next, depth: depth + 1 });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Don't include the input mint itself
|
|
113
|
+
reachable.delete(inputStr);
|
|
114
|
+
return Array.from(reachable).map((s) => new web3_js_1.PublicKey(s));
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=pathfinder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathfinder.js","sourceRoot":"","sources":["../../src/routing/pathfinder.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgBH,gCAkFC;AAMD,8CAgCC;AAtID,6CAA4C;AAC5C,4CAAwC;AACxC,oCAAiD;AACjD,yCAA0D;AAE1D;;;;;;;;GAQG;AACH,SAAgB,UAAU,CACxB,KAAgB,EAChB,SAAoB,EACpB,UAAqB,EACrB,UAAkB,oBAAQ;IAE1B,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IAExC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAEtC,MAAM,MAAM,GAAY,EAAE,CAAC;IAS3B,MAAM,KAAK,GAAc;QACvB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,GAAG,EAAE,EAAE;KACtD,CAAC;IAEF,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;Q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AAG,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU;YAAE,SAAS;QAE1B,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAClB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;IAED,sCAAsC;IACtC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,mBAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — Price quote engine.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the on-chain constant-product math exactly so that
|
|
5
|
+
* client-side quotes match program execution.
|
|
6
|
+
*
|
|
7
|
+
* Fee model (from `math/fees.rs`):
|
|
8
|
+
* total_fee = amount_in × fee_bps / 10_000
|
|
9
|
+
* treasury_cut = total_fee × treasury_fee_bps / 10_000
|
|
10
|
+
* lp_cut = total_fee − treasury_cut
|
|
11
|
+
* effective_input = amount_in − total_fee
|
|
12
|
+
*
|
|
13
|
+
* AMM output (from `math/constant_product.rs`):
|
|
14
|
+
* output = (output_reserve × effective_input) / (input_reserve + effective_input)
|
|
15
|
+
*/
|
|
16
|
+
import BN from "bn.js";
|
|
17
|
+
import { Route, Hop, Pool, FeeBreakdown, HopQuote, SwapQuote } from "../types";
|
|
18
|
+
/**
|
|
19
|
+
* Calculate fee breakdown.
|
|
20
|
+
* All division truncates (floor) — matching the on-chain rounding.
|
|
21
|
+
*/
|
|
22
|
+
export declare function calculateFee(amountIn: BN, feeBps: number, treasuryFeeBps: number): FeeBreakdown;
|
|
23
|
+
/**
|
|
24
|
+
* Constant-product output: dy = (y × dx) / (x + dx).
|
|
25
|
+
* Truncates (rounds down), matching on-chain behaviour.
|
|
26
|
+
* Returns zero if any input is zero.
|
|
27
|
+
*/
|
|
28
|
+
export declare function computeOutput(effectiveInput: BN, inputReserve: BN, outputReserve: BN): BN;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the effective fee bps for a pool.
|
|
31
|
+
* Pool-level override (if non-zero) takes precedence over the protocol default.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveFeeBps(pool: Pool, protocolFeeBps: number): number;
|
|
34
|
+
/** Quote a single hop. */
|
|
35
|
+
export declare function quoteHop(hop: Hop, amountIn: BN, protocolFeeBps: number, treasuryFeeBps: number): HopQuote;
|
|
36
|
+
/**
|
|
37
|
+
* Quote a complete swap route.
|
|
38
|
+
*
|
|
39
|
+
* @param route The route (1–3 hops) to quote.
|
|
40
|
+
* @param amountIn Raw input amount.
|
|
41
|
+
* @param protocolFeeBps Protocol default swap fee (from ProtocolConfig).
|
|
42
|
+
* @param treasuryFeeBps Treasury's share of the fee (from ProtocolConfig).
|
|
43
|
+
* @param slippageBps Slippage tolerance in bps (e.g. 50 = 0.5%).
|
|
44
|
+
*/
|
|
45
|
+
export declare function quoteRoute(route: Route, amountIn: BN, protocolFeeBps: number, treasuryFeeBps: number, slippageBps?: number): SwapQuote;
|
|
46
|
+
/**
|
|
47
|
+
* Find the best route and return its quote.
|
|
48
|
+
*
|
|
49
|
+
* Evaluates all provided routes and returns the one with the
|
|
50
|
+
* highest expected output.
|
|
51
|
+
*/
|
|
52
|
+
export declare function bestQuote(routes: Route[], amountIn: BN, protocolFeeBps: number, treasuryFeeBps: number, slippageBps?: number): SwapQuote | null;
|
|
53
|
+
//# sourceMappingURL=quote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../../src/routing/quote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,OAAO,EACL,KAAK,EACL,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,SAAS,EACV,MAAM,UAAU,CAAC;AAIlB;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,EAAE,EACZ,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,YAAY,CASd;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,cAAc,EAAE,EAAE,EAClB,YAAY,EAAE,EAAE,EAChB,aAAa,EAAE,EAAE,GAChB,EAAE,CAWJ;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAExE;AAID,0BAA0B;AAC1B,wBAAgB,QAAQ,CACtB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,EAAE,EACZ,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,GACrB,QAAQ,CA2BV;AAID;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,EAAE,EACZ,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,WAAW,GAAE,MAAW,GACvB,SAAS,CA+BX;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,KAAK,EAAE,EACf,QAAQ,EAAE,EAAE,EACZ,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,WAAW,CAAC,EAAE,MAAM,GACnB,SAAS,GAAG,IAAI,CAalB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @vault-program/sdk — Price quote engine.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the on-chain constant-product math exactly so that
|
|
6
|
+
* client-side quotes match program execution.
|
|
7
|
+
*
|
|
8
|
+
* Fee model (from `math/fees.rs`):
|
|
9
|
+
* total_fee = amount_in × fee_bps / 10_000
|
|
10
|
+
* treasury_cut = total_fee × treasury_fee_bps / 10_000
|
|
11
|
+
* lp_cut = total_fee − treasury_cut
|
|
12
|
+
* effective_input = amount_in − total_fee
|
|
13
|
+
*
|
|
14
|
+
* AMM output (from `math/constant_product.rs`):
|
|
15
|
+
* output = (output_reserve × effective_input) / (input_reserve + effective_input)
|
|
16
|
+
*/
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.calculateFee = calculateFee;
|
|
22
|
+
exports.computeOutput = computeOutput;
|
|
23
|
+
exports.resolveFeeBps = resolveFeeBps;
|
|
24
|
+
exports.quoteHop = quoteHop;
|
|
25
|
+
exports.quoteRoute = quoteRoute;
|
|
26
|
+
exports.bestQuote = bestQuote;
|
|
27
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
28
|
+
const constants_1 = require("../constants");
|
|
29
|
+
// ─── Core math (matches on-chain exactly) ────────────────────
|
|
30
|
+
/**
|
|
31
|
+
* Calculate fee breakdown.
|
|
32
|
+
* All division truncates (floor) — matching the on-chain rounding.
|
|
33
|
+
*/
|
|
34
|
+
function calculateFee(amountIn, feeBps, treasuryFeeBps) {
|
|
35
|
+
const denom = new bn_js_1.default(constants_1.BPS_DENOMINATOR);
|
|
36
|
+
const totalFee = amountIn.mul(new bn_js_1.default(feeBps)).div(denom);
|
|
37
|
+
const treasuryCut = totalFee.mul(new bn_js_1.default(treasuryFeeBps)).div(denom);
|
|
38
|
+
const lpCut = totalFee.sub(treasuryCut);
|
|
39
|
+
const effectiveInput = amountIn.sub(totalFee);
|
|
40
|
+
return { totalFee, treasuryCut, lpCut, effectiveInput };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Constant-product output: dy = (y × dx) / (x + dx).
|
|
44
|
+
* Truncates (rounds down), matching on-chain behaviour.
|
|
45
|
+
* Returns zero if any input is zero.
|
|
46
|
+
*/
|
|
47
|
+
function computeOutput(effectiveInput, inputReserve, outputReserve) {
|
|
48
|
+
if (effectiveInput.isZero() ||
|
|
49
|
+
inputReserve.isZero() ||
|
|
50
|
+
outputReserve.isZero()) {
|
|
51
|
+
return new bn_js_1.default(0);
|
|
52
|
+
}
|
|
53
|
+
const numerator = outputReserve.mul(effectiveInput);
|
|
54
|
+
const denominator = inputReserve.add(effectiveInput);
|
|
55
|
+
return numerator.div(denominator);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the effective fee bps for a pool.
|
|
59
|
+
* Pool-level override (if non-zero) takes precedence over the protocol default.
|
|
60
|
+
*/
|
|
61
|
+
function resolveFeeBps(pool, protocolFeeBps) {
|
|
62
|
+
return pool.poolFeeBps > 0 ? pool.poolFeeBps : protocolFeeBps;
|
|
63
|
+
}
|
|
64
|
+
// ─── Hop quote ───────────────────────────────────────────────
|
|
65
|
+
/** Quote a single hop. */
|
|
66
|
+
function quoteHop(hop, amountIn, protocolFeeBps, treasuryFeeBps) {
|
|
67
|
+
const pool = hop.pool;
|
|
68
|
+
const [inputReserve, outputReserve] = hop.aToB
|
|
69
|
+
? [pool.reserveA, pool.reserveB]
|
|
70
|
+
: [pool.reserveB, pool.reserveA];
|
|
71
|
+
const feeBps = resolveFeeBps(pool, protocolFeeBps);
|
|
72
|
+
const fee = calculateFee(amountIn, feeBps, treasuryFeeBps);
|
|
73
|
+
const outputAmount = computeOutput(fee.effectiveInput, inputReserve, outputReserve);
|
|
74
|
+
// Price impact: compare execution price vs spot price
|
|
75
|
+
// spot = outputReserve / inputReserve
|
|
76
|
+
// exec = outputAmount / amountIn
|
|
77
|
+
// impact = 1 − exec/spot = 1 − (outputAmount × inputReserve) / (amountIn × outputReserve)
|
|
78
|
+
let priceImpact = 0;
|
|
79
|
+
if (!amountIn.isZero() && !outputReserve.isZero()) {
|
|
80
|
+
const spotNumerator = outputAmount.mul(inputReserve);
|
|
81
|
+
const spotDenominator = amountIn.mul(outputReserve);
|
|
82
|
+
if (!spotDenominator.isZero()) {
|
|
83
|
+
// Use floating point for the impact fraction
|
|
84
|
+
const ratio = Number(spotNumerator.toString()) / Number(spotDenominator.toString());
|
|
85
|
+
priceImpact = Math.max(0, 1 - ratio);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { inputAmount: amountIn, outputAmount, fee, priceImpact };
|
|
89
|
+
}
|
|
90
|
+
// ─── Full route quote ────────────────────────────────────────
|
|
91
|
+
/**
|
|
92
|
+
* Quote a complete swap route.
|
|
93
|
+
*
|
|
94
|
+
* @param route The route (1–3 hops) to quote.
|
|
95
|
+
* @param amountIn Raw input amount.
|
|
96
|
+
* @param protocolFeeBps Protocol default swap fee (from ProtocolConfig).
|
|
97
|
+
* @param treasuryFeeBps Treasury's share of the fee (from ProtocolConfig).
|
|
98
|
+
* @param slippageBps Slippage tolerance in bps (e.g. 50 = 0.5%).
|
|
99
|
+
*/
|
|
100
|
+
function quoteRoute(route, amountIn, protocolFeeBps, treasuryFeeBps, slippageBps = 50) {
|
|
101
|
+
let currentAmount = amountIn;
|
|
102
|
+
const hopQuotes = [];
|
|
103
|
+
let totalFees = new bn_js_1.default(0);
|
|
104
|
+
for (const hop of route.hops) {
|
|
105
|
+
const hq = quoteHop(hop, currentAmount, protocolFeeBps, treasuryFeeBps);
|
|
106
|
+
hopQuotes.push(hq);
|
|
107
|
+
totalFees = totalFees.add(hq.fee.totalFee);
|
|
108
|
+
currentAmount = hq.outputAmount;
|
|
109
|
+
}
|
|
110
|
+
// Aggregate price impact: 1 − ∏(1 − hop_impact)
|
|
111
|
+
const totalPriceImpact = 1 - hopQuotes.reduce((acc, hq) => acc * (1 - hq.priceImpact), 1);
|
|
112
|
+
// Minimum output with slippage tolerance
|
|
113
|
+
const slippageDenom = new bn_js_1.default(constants_1.BPS_DENOMINATOR);
|
|
114
|
+
const minimumOutput = currentAmount
|
|
115
|
+
.mul(slippageDenom.sub(new bn_js_1.default(slippageBps)))
|
|
116
|
+
.div(slippageDenom);
|
|
117
|
+
return {
|
|
118
|
+
route,
|
|
119
|
+
amountIn,
|
|
120
|
+
expectedOutput: currentAmount,
|
|
121
|
+
minimumOutput,
|
|
122
|
+
hopQuotes,
|
|
123
|
+
totalPriceImpact,
|
|
124
|
+
totalFees,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Find the best route and return its quote.
|
|
129
|
+
*
|
|
130
|
+
* Evaluates all provided routes and returns the one with the
|
|
131
|
+
* highest expected output.
|
|
132
|
+
*/
|
|
133
|
+
function bestQuote(routes, amountIn, protocolFeeBps, treasuryFeeBps, slippageBps) {
|
|
134
|
+
if (routes.length === 0)
|
|
135
|
+
return null;
|
|
136
|
+
let best = null;
|
|
137
|
+
for (const route of routes) {
|
|
138
|
+
const quote = quoteRoute(route, amountIn, protocolFeeBps, treasuryFeeBps, slippageBps);
|
|
139
|
+
if (!best || quote.expectedOutput.gt(best.expectedOutput)) {
|
|
140
|
+
best = quote;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return best;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=quote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../../src/routing/quote.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAmBH,oCAaC;AAOD,sCAeC;AAMD,sCAEC;AAKD,4BAgCC;AAaD,gCAqCC;AAQD,8BAmBC;AA9KD,kDAAuB;AACvB,4CAA+C;AAU/C,gEAAgE;AAEhE;;;GAGG;AACH,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KG;AACH,SAAgB,SAAS,CACvB,MAAe,EACf,QAAY,EACZ,cAAsB,EACtB,cAAsB,EACtB,WAAoB;IAEpB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAErC,IAAI,IAAI,GAAqB,IAAI,CAAC;IAElC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;QACvF,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;YAC1D,IAAI,GAAG,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vault-program/sdk — Core types for pool, config, and routing.
|
|
3
|
+
*/
|
|
4
|
+
import { PublicKey } from "@solana/web3.js";
|
|
5
|
+
import BN from "bn.js";
|
|
6
|
+
export declare enum PoolType {
|
|
7
|
+
TokenToken = 0,
|
|
8
|
+
TokenNft = 1,
|
|
9
|
+
TokenPnft = 2,
|
|
10
|
+
TokenCoreNft = 3
|
|
11
|
+
}
|
|
12
|
+
export interface ProtocolConfig {
|
|
13
|
+
authority: PublicKey;
|
|
14
|
+
treasury: PublicKey;
|
|
15
|
+
poolCreationFee: BN;
|
|
16
|
+
swapFeeBps: number;
|
|
17
|
+
treasuryFeeBps: number;
|
|
18
|
+
totalPools: BN;
|
|
19
|
+
isPaused: boolean;
|
|
20
|
+
bump: number;
|
|
21
|
+
treasuryBump: number;
|
|
22
|
+
tokenSwapSolFee: BN;
|
|
23
|
+
nftSwapSolFee: BN;
|
|
24
|
+
}
|
|
25
|
+
export interface Pool {
|
|
26
|
+
/** Pool PDA address (added client-side, not on-chain). */
|
|
27
|
+
address: PublicKey;
|
|
28
|
+
creator: PublicKey;
|
|
29
|
+
assetAMint: PublicKey;
|
|
30
|
+
assetBMint: PublicKey;
|
|
31
|
+
poolType: PoolType;
|
|
32
|
+
vaultA: PublicKey;
|
|
33
|
+
vaultB: PublicKey;
|
|
34
|
+
nftEscrowCount: number;
|
|
35
|
+
lpMint: PublicKey;
|
|
36
|
+
totalLpSupply: BN;
|
|
37
|
+
reserveA: BN;
|
|
38
|
+
reserveB: BN;
|
|
39
|
+
cumulativeFeeA: BN;
|
|
40
|
+
cumulativeFeeB: BN;
|
|
41
|
+
feePerShareA: BN;
|
|
42
|
+
feePerShareB: BN;
|
|
43
|
+
lastPrice: BN;
|
|
44
|
+
isLocked: boolean;
|
|
45
|
+
isActive: boolean;
|
|
46
|
+
assetAIsToken2022: boolean;
|
|
47
|
+
assetBIsToken2022: boolean;
|
|
48
|
+
poolFeeBps: number;
|
|
49
|
+
basePrice: BN;
|
|
50
|
+
curveDelta: BN;
|
|
51
|
+
createdAt: BN;
|
|
52
|
+
bump: number;
|
|
53
|
+
}
|
|
54
|
+
export interface LiquidityPosition {
|
|
55
|
+
owner: PublicKey;
|
|
56
|
+
pool: PublicKey;
|
|
57
|
+
lpTokensHeld: BN;
|
|
58
|
+
depositedA: BN;
|
|
59
|
+
depositedB: BN;
|
|
60
|
+
feeDebtA: BN;
|
|
61
|
+
feeDebtB: BN;
|
|
62
|
+
lastUpdated: BN;
|
|
63
|
+
bump: number;
|
|
64
|
+
}
|
|
65
|
+
/** A single leg of a swap route through one pool. */
|
|
66
|
+
export interface Hop {
|
|
67
|
+
pool: Pool;
|
|
68
|
+
/** true = swap A→B in this pool; false = B→A. */
|
|
69
|
+
aToB: boolean;
|
|
70
|
+
inputMint: PublicKey;
|
|
71
|
+
outputMint: PublicKey;
|
|
72
|
+
}
|
|
73
|
+
/** A complete route from input mint to output mint (1–3 hops). */
|
|
74
|
+
export interface Route {
|
|
75
|
+
hops: Hop[];
|
|
76
|
+
inputMint: PublicKey;
|
|
77
|
+
outputMint: PublicKey;
|
|
78
|
+
}
|
|
79
|
+
/** Fee breakdown for a single hop. */
|
|
80
|
+
export interface FeeBreakdown {
|
|
81
|
+
totalFee: BN;
|
|
82
|
+
treasuryCut: BN;
|
|
83
|
+
lpCut: BN;
|
|
84
|
+
effectiveInput: BN;
|
|
85
|
+
}
|
|
86
|
+
/** Quote result for a single hop. */
|
|
87
|
+
export interface HopQuote {
|
|
88
|
+
inputAmount: BN;
|
|
89
|
+
outputAmount: BN;
|
|
90
|
+
fee: FeeBreakdown;
|
|
91
|
+
/** Price impact as a fraction (0.01 = 1%). */
|
|
92
|
+
priceImpact: number;
|
|
93
|
+
}
|
|
94
|
+
/** Full swap quote across all hops. */
|
|
95
|
+
export interface SwapQuote {
|
|
96
|
+
route: Route;
|
|
97
|
+
amountIn: BN;
|
|
98
|
+
expectedOutput: BN;
|
|
99
|
+
minimumOutput: BN;
|
|
100
|
+
hopQuotes: HopQuote[];
|
|
101
|
+
/** Aggregate price impact (1 − ∏(1 − hop_impact)). */
|
|
102
|
+
totalPriceImpact: number;
|
|
103
|
+
totalFees: BN;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,OAAO,CAAC;AAIvB,oBAAY,QAAQ;IAClB,UAAU,IAAI;IACd,QAAQ,IAAI;IACZ,SAAS,IAAI;IACb,YAAY,IAAI;CACjB;AAID,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;IACpB,eAAe,EAAE,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAA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