@scalecrx/sdk 0.4.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/LICENSE +21 -0
- package/README.md +269 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +10 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +34 -0
- package/dist/idl/scale_amm.json +1471 -0
- package/dist/idl/scale_vmm.json +1425 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +29 -0
- package/dist/scale.d.ts +35 -0
- package/dist/scale.js +82 -0
- package/dist/scaleAmm.d.ts +68 -0
- package/dist/scaleAmm.js +465 -0
- package/dist/scaleVmm.d.ts +77 -0
- package/dist/scaleVmm.js +527 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +63 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Scale
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Scale SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for Scale AMM and Scale VMM.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @scalecrx/sdk @coral-xyz/anchor @solana/web3.js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Constants
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { AMM_ADDRESS, VMM_ADDRESS, CLUSTER_RPC_URLS } from "@scalecrx/sdk";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- `AMM_ADDRESS` => `SCALEwAvEK5gtkdHiFzXfPgtk2YwJxPDzaV3aDmR7tA`
|
|
18
|
+
- `VMM_ADDRESS` => `SCALEWoRSpVZpMRqHEcDfNvBh3nUSe34jDr9r689gLa`
|
|
19
|
+
|
|
20
|
+
## Constructors
|
|
21
|
+
|
|
22
|
+
### 1) RPC URL overload
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Scale } from "@scalecrx/sdk";
|
|
26
|
+
|
|
27
|
+
const sdk = new Scale("https://my-rpc.example.com", walletOptional);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2) Cluster overload (`"devnet" | "mainnet"`)
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Scale } from "@scalecrx/sdk";
|
|
34
|
+
|
|
35
|
+
const sdkDevnet = new Scale("devnet", walletOptional); // uses https://api.devnet.solana.com
|
|
36
|
+
const sdkMainnet = new Scale("mainnet", walletOptional); // uses https://api.mainnet-beta.solana.com
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If wallet is omitted, read-only and instruction-building flows still work, but direct execution methods throw.
|
|
40
|
+
|
|
41
|
+
## Execution vs Instruction Builders
|
|
42
|
+
|
|
43
|
+
Every write flow has two styles:
|
|
44
|
+
|
|
45
|
+
1. **Execute now** (requires wallet):
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
await sdk.amm.buy(poolAddress, { amount: 1_000, limit: 1 }, opts);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
2. **Return instructions only** (no send):
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const bundle = await sdk.amm.buyInstructions(poolAddress, { amount: 1_000, limit: 1 }, opts);
|
|
55
|
+
// bundle.instructions -> add to Transaction yourself
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Same pattern exists for AMM and VMM (`buy/sell/create*`, plus config instruction builders).
|
|
59
|
+
|
|
60
|
+
## Supported Curves (on-chain)
|
|
61
|
+
|
|
62
|
+
Pool/pair creation supports exactly two curve configs:
|
|
63
|
+
|
|
64
|
+
- `constantProduct`: standard x*y=k style curve.
|
|
65
|
+
- `exponential`: steeper curve profile than constant product for the same inputs.
|
|
66
|
+
|
|
67
|
+
Use one of:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
{ constantProduct: {} }
|
|
71
|
+
// or
|
|
72
|
+
{ exponential: {} }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Parameter Reference
|
|
76
|
+
|
|
77
|
+
### Common numeric types
|
|
78
|
+
|
|
79
|
+
- Most numeric args are `number | BN`.
|
|
80
|
+
- On-chain values are integer base units (raw token units), not UI decimals.
|
|
81
|
+
|
|
82
|
+
### Creation params (`CreatePoolParamsInput` / `CreatePairParamsInput`)
|
|
83
|
+
|
|
84
|
+
- `shift`: virtual token A liquidity shift used by curve math.
|
|
85
|
+
- `initialTokenBReserves`: initial token B reserves deposited for create.
|
|
86
|
+
- `curve`: `{ constantProduct: {} } | { exponential: {} }`.
|
|
87
|
+
- `feeBeneficiaries`: array of `{ wallet: PublicKey, shareBps: number }`.
|
|
88
|
+
|
|
89
|
+
### Create options (AMM: `CreatePoolOptions`, VMM: `CreatePairOptions`)
|
|
90
|
+
|
|
91
|
+
- `payer?`: transaction payer (defaults to SDK wallet public key).
|
|
92
|
+
- `owner?` (AMM only): pool owner PDA seed input (defaults to SDK wallet).
|
|
93
|
+
- `tokenWalletB?`: token B source account for create.
|
|
94
|
+
- `tokenWalletAuthority?`: authority for `tokenWalletB` transfers.
|
|
95
|
+
- `signers?`: extra signers appended to returned bundle/send.
|
|
96
|
+
|
|
97
|
+
### Swap params (`SwapParamsInput`)
|
|
98
|
+
|
|
99
|
+
- `amount`: input amount in raw units.
|
|
100
|
+
- `limit`: slippage guard / minimum-out style bound enforced by program.
|
|
101
|
+
|
|
102
|
+
### Swap options (`SwapOptions`)
|
|
103
|
+
|
|
104
|
+
- `userTokenAccountA?`, `userTokenAccountB?`: user token accounts override.
|
|
105
|
+
- `platformFeeTokenAccount?`: explicit platform fee token A account.
|
|
106
|
+
- `beneficiaryTokenAccounts?`: explicit creator fee accounts (order-sensitive).
|
|
107
|
+
- `wrapSol?`: wrap SOL into WSOL before swap when mint A is native.
|
|
108
|
+
- `unwrapSol?`: unwrap WSOL after swap when mint A is native.
|
|
109
|
+
- `autoCreateAta?`: auto-create missing ATAs (default true).
|
|
110
|
+
|
|
111
|
+
### VMM swap extension (`VmmSwapOptions`)
|
|
112
|
+
|
|
113
|
+
In addition to `SwapOptions`, VMM accepts AMM-routing overrides used for graduation-aware paths:
|
|
114
|
+
|
|
115
|
+
- `ammProgramId?`, `ammPool?`, `ammVaultA?`, `ammVaultB?`
|
|
116
|
+
- `ammConfig?`, `ammTokenProgramA?`, `ammTokenProgramB?`, `ammSystemProgram?`
|
|
117
|
+
|
|
118
|
+
### Graduation status check
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const pair = await sdk.vmm.getPairByMints(mintA, mintB);
|
|
122
|
+
const isGraduated = pair.data.graduated;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### SDK constructor options (`ScaleOptions`)
|
|
126
|
+
|
|
127
|
+
- `ammProgramId?`, `vmmProgramId?`: override default vanity program IDs.
|
|
128
|
+
- `ammIdl?`, `vmmIdl?`: IDL overrides.
|
|
129
|
+
- `programId?`, `idl?`: legacy AMM alias fallback.
|
|
130
|
+
- `providerOptions?`: Anchor provider confirmation/preflight options.
|
|
131
|
+
|
|
132
|
+
## AMM quick usage
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const config = await sdk.amm.getPlatformConfig();
|
|
136
|
+
const pool = await sdk.amm.getPoolByMints(owner, mintA, mintB);
|
|
137
|
+
const quote = await sdk.amm.estimateBuy(pool.address, { amount: 10_000, limit: 1 });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const createBundle = await sdk.amm.createPoolInstructions(
|
|
142
|
+
{
|
|
143
|
+
shift: 1_000_000,
|
|
144
|
+
initialTokenBReserves: 100_000,
|
|
145
|
+
curve: { constantProduct: {} },
|
|
146
|
+
feeBeneficiaries: [],
|
|
147
|
+
},
|
|
148
|
+
mintA,
|
|
149
|
+
mintB,
|
|
150
|
+
{
|
|
151
|
+
payer,
|
|
152
|
+
owner,
|
|
153
|
+
tokenWalletB,
|
|
154
|
+
tokenWalletAuthority,
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const swapBundle = await sdk.amm.buyInstructions(
|
|
159
|
+
poolAddress,
|
|
160
|
+
{ amount: 10_000, limit: 1 },
|
|
161
|
+
{
|
|
162
|
+
userTokenAccountA,
|
|
163
|
+
userTokenAccountB,
|
|
164
|
+
platformFeeTokenAccount,
|
|
165
|
+
beneficiaryTokenAccounts,
|
|
166
|
+
wrapSol: true,
|
|
167
|
+
unwrapSol: false,
|
|
168
|
+
autoCreateAta: true,
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## VMM quick usage
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
const config = await sdk.vmm.getPlatformConfig();
|
|
177
|
+
const pair = await sdk.vmm.getPairByMints(mintA, mintB);
|
|
178
|
+
const quote = await sdk.vmm.estimateSell(pair.address, { amount: 10_000, limit: 1 });
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const createBundle = await sdk.vmm.createPairInstructions(
|
|
183
|
+
{
|
|
184
|
+
shift: 1_000_000,
|
|
185
|
+
initialTokenBReserves: 100_000,
|
|
186
|
+
curve: { exponential: {} },
|
|
187
|
+
feeBeneficiaries: [],
|
|
188
|
+
},
|
|
189
|
+
mintA,
|
|
190
|
+
mintB,
|
|
191
|
+
{
|
|
192
|
+
payer,
|
|
193
|
+
tokenWalletB,
|
|
194
|
+
tokenWalletAuthority,
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const swapBundle = await sdk.vmm.sellInstructions(
|
|
199
|
+
pairAddress,
|
|
200
|
+
{ amount: 10_000, limit: 1 },
|
|
201
|
+
{
|
|
202
|
+
userTokenAccountA,
|
|
203
|
+
userTokenAccountB,
|
|
204
|
+
platformFeeTokenAccount,
|
|
205
|
+
beneficiaryTokenAccounts,
|
|
206
|
+
autoCreateAta: true,
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Public API map
|
|
212
|
+
|
|
213
|
+
### `Scale`
|
|
214
|
+
- `new Scale(connection, wallet, options)`
|
|
215
|
+
- `new Scale(rpcUrl, wallet?, options?)`
|
|
216
|
+
- `new Scale("devnet" | "mainnet", wallet?, options?)`
|
|
217
|
+
- `amm`, `vmm`, `loadAmm`, `loadVmm`
|
|
218
|
+
- `loadAmm(programId?, idlOverride?)`
|
|
219
|
+
- `loadVmm(programId?, idlOverride?)`
|
|
220
|
+
|
|
221
|
+
### `ScaleAmm`
|
|
222
|
+
- Read-only: `getConfigAddress`, `getPoolAddress`, `getVaultAddress`, `getPlatformConfig`, `getPlatformBaseToken`, `getPool*`, `getFee*`, `estimateBuy`, `estimateSell`
|
|
223
|
+
- Execute: `createPool`, `buy`, `sell`
|
|
224
|
+
- Instruction builders: `createPoolInstructions`, `createWithDevBuyInstructions`, `buyInstructions`, `sellInstructions`
|
|
225
|
+
- `createPool(params, mintA, mintB, options?)`
|
|
226
|
+
- `createPoolInstructions(params, mintA, mintB, options?)`
|
|
227
|
+
- `createWithDevBuyInstructions(params, mintA, mintB, buyParams, options?)`
|
|
228
|
+
- `buy(poolInput, params, options?)`
|
|
229
|
+
- `sell(poolInput, params, options?)`
|
|
230
|
+
- `buyInstructions(poolInput, params, options?)`
|
|
231
|
+
- `sellInstructions(poolInput, params, options?)`
|
|
232
|
+
|
|
233
|
+
### `ScaleVmm`
|
|
234
|
+
- Read-only: `getConfigAddress`, `getPairAddress`, `getVaultAddress`, `getAmmPoolAddress`, `getAmmVaultAddress`, `getPlatformConfig`, `getPlatformConfigView`, `getPlatformBaseToken`, `getGraduationThreshold`, `getPair*`, `getFee*`, `estimateBuy`, `estimateSell`
|
|
235
|
+
- Execute: `setGraduationThreshold`, `createPair`, `buy`, `sell`
|
|
236
|
+
- Instruction builders: `setGraduationThresholdInstruction`, `createPairInstructions`, `createWithDevBuyInstructions`, `buyInstructions`, `sellInstructions`
|
|
237
|
+
- `setGraduationThreshold(threshold)`
|
|
238
|
+
- `setGraduationThresholdInstruction(threshold)`
|
|
239
|
+
- `createPair(params, mintA, mintB, options?)`
|
|
240
|
+
- `createPairInstructions(params, mintA, mintB, options?)`
|
|
241
|
+
- `createWithDevBuyInstructions(params, mintA, mintB, buyParams, options?)`
|
|
242
|
+
- `buy(pairInput, params, options?)`
|
|
243
|
+
- `sell(pairInput, params, options?)`
|
|
244
|
+
- `buyInstructions(pairInput, params, options?)`
|
|
245
|
+
- `sellInstructions(pairInput, params, options?)`
|
|
246
|
+
|
|
247
|
+
## Agent Use
|
|
248
|
+
|
|
249
|
+
Use this prompt in your AI coding agent to integrate an existing project with Scale SDK:
|
|
250
|
+
|
|
251
|
+
```text
|
|
252
|
+
Integrate Scale SDK into this project end-to-end using the official docs:
|
|
253
|
+
https://github.com/scalecrx/sdk/blob/main/README.md
|
|
254
|
+
|
|
255
|
+
Requirements:
|
|
256
|
+
1. Install and configure @scalecrx/sdk and required Solana/Anchor dependencies.
|
|
257
|
+
2. Detect this project’s package manager, TypeScript setup, and runtime (Node/server/client), then implement integration in the correct layer.
|
|
258
|
+
3. Add a reusable Scale client module and environment-driven RPC/network configuration.
|
|
259
|
+
4. Implement at least one read flow (platform config + pair/pool fetch/quote) and one transaction instruction-building flow using this SDK.
|
|
260
|
+
5. If wallet execution is not available in this project context, use instruction builders only and wire outputs for external signing.
|
|
261
|
+
6. Keep all amounts in raw base units (not UI decimals) and add safe input validation.
|
|
262
|
+
7. Add/update minimal docs in this repo explaining how to run and use the integration.
|
|
263
|
+
8. Run build/typecheck/tests (if present) and fix any issues caused by the integration.
|
|
264
|
+
|
|
265
|
+
Output format:
|
|
266
|
+
- Summary of files changed and why
|
|
267
|
+
- Exact commands run
|
|
268
|
+
- Any assumptions or follow-up tasks
|
|
269
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export declare const AMM_ADDRESS: PublicKey;
|
|
3
|
+
export declare const VMM_ADDRESS: PublicKey;
|
|
4
|
+
export declare const CLUSTER_RPC_URLS: {
|
|
5
|
+
readonly devnet: "https://api.devnet.solana.com";
|
|
6
|
+
readonly mainnet: "https://api.mainnet-beta.solana.com";
|
|
7
|
+
};
|
|
8
|
+
export type ScaleCluster = keyof typeof CLUSTER_RPC_URLS;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLUSTER_RPC_URLS = exports.VMM_ADDRESS = exports.AMM_ADDRESS = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
exports.AMM_ADDRESS = new web3_js_1.PublicKey("SCALEwAvEK5gtkdHiFzXfPgtk2YwJxPDzaV3aDmR7tA");
|
|
6
|
+
exports.VMM_ADDRESS = new web3_js_1.PublicKey("SCALEWoRSpVZpMRqHEcDfNvBh3nUSe34jDr9r689gLa");
|
|
7
|
+
exports.CLUSTER_RPC_URLS = {
|
|
8
|
+
devnet: "https://api.devnet.solana.com",
|
|
9
|
+
mainnet: "https://api.mainnet-beta.solana.com",
|
|
10
|
+
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class ScaleSdkError extends Error {
|
|
2
|
+
readonly context: string;
|
|
3
|
+
readonly cause: unknown;
|
|
4
|
+
readonly logs?: string[];
|
|
5
|
+
readonly code?: string;
|
|
6
|
+
readonly number?: number;
|
|
7
|
+
constructor(message: string, context: string, cause: unknown, details?: {
|
|
8
|
+
logs?: string[];
|
|
9
|
+
code?: string;
|
|
10
|
+
number?: number;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export declare const toSdkError: (context: string, err: unknown, idlErrors: Map<number, string>) => ScaleSdkError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSdkError = exports.ScaleSdkError = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
class ScaleSdkError extends Error {
|
|
6
|
+
constructor(message, context, cause, details) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "ScaleSdkError";
|
|
9
|
+
this.context = context;
|
|
10
|
+
this.cause = cause;
|
|
11
|
+
this.logs = details?.logs;
|
|
12
|
+
this.code = details?.code;
|
|
13
|
+
this.number = details?.number;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ScaleSdkError = ScaleSdkError;
|
|
17
|
+
const toSdkError = (context, err, idlErrors) => {
|
|
18
|
+
if (err instanceof ScaleSdkError) {
|
|
19
|
+
return err;
|
|
20
|
+
}
|
|
21
|
+
const translated = (0, anchor_1.translateError)(err, idlErrors);
|
|
22
|
+
if (translated instanceof anchor_1.AnchorError) {
|
|
23
|
+
return new ScaleSdkError(`${context}: ${translated.message}`, context, err, {
|
|
24
|
+
logs: translated.logs,
|
|
25
|
+
code: translated.error.errorCode.code,
|
|
26
|
+
number: translated.error.errorCode.number,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (translated instanceof Error) {
|
|
30
|
+
return new ScaleSdkError(`${context}: ${translated.message}`, context, err);
|
|
31
|
+
}
|
|
32
|
+
return new ScaleSdkError(`${context}: Unknown error`, context, err);
|
|
33
|
+
};
|
|
34
|
+
exports.toSdkError = toSdkError;
|