@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.
@@ -0,0 +1,5 @@
1
+ export { Scale } from "./scale";
2
+ export { ScaleAmm, ScaleSdkError } from "./scaleAmm";
3
+ export { ScaleVmm } from "./scaleVmm";
4
+ export { AMM_ADDRESS, VMM_ADDRESS, CLUSTER_RPC_URLS } from "./constants";
5
+ export * from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CLUSTER_RPC_URLS = exports.VMM_ADDRESS = exports.AMM_ADDRESS = exports.ScaleVmm = exports.ScaleSdkError = exports.ScaleAmm = exports.Scale = void 0;
18
+ var scale_1 = require("./scale");
19
+ Object.defineProperty(exports, "Scale", { enumerable: true, get: function () { return scale_1.Scale; } });
20
+ var scaleAmm_1 = require("./scaleAmm");
21
+ Object.defineProperty(exports, "ScaleAmm", { enumerable: true, get: function () { return scaleAmm_1.ScaleAmm; } });
22
+ Object.defineProperty(exports, "ScaleSdkError", { enumerable: true, get: function () { return scaleAmm_1.ScaleSdkError; } });
23
+ var scaleVmm_1 = require("./scaleVmm");
24
+ Object.defineProperty(exports, "ScaleVmm", { enumerable: true, get: function () { return scaleVmm_1.ScaleVmm; } });
25
+ var constants_1 = require("./constants");
26
+ Object.defineProperty(exports, "AMM_ADDRESS", { enumerable: true, get: function () { return constants_1.AMM_ADDRESS; } });
27
+ Object.defineProperty(exports, "VMM_ADDRESS", { enumerable: true, get: function () { return constants_1.VMM_ADDRESS; } });
28
+ Object.defineProperty(exports, "CLUSTER_RPC_URLS", { enumerable: true, get: function () { return constants_1.CLUSTER_RPC_URLS; } });
29
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,35 @@
1
+ import { AnchorProvider, Idl, Program, Wallet } from "@coral-xyz/anchor";
2
+ import { Connection, PublicKey } from "@solana/web3.js";
3
+ import { ScaleAmm } from "./scaleAmm";
4
+ import { ScaleVmm } from "./scaleVmm";
5
+ import { ScaleCluster } from "./constants";
6
+ export type ScaleOptions = {
7
+ ammProgramId?: PublicKey;
8
+ vmmProgramId?: PublicKey;
9
+ ammIdl?: Idl;
10
+ vmmIdl?: Idl;
11
+ programId?: PublicKey;
12
+ idl?: Idl;
13
+ providerOptions?: ConstructorParameters<typeof AnchorProvider>[2];
14
+ };
15
+ export declare class Scale {
16
+ readonly connection: Connection;
17
+ readonly wallet: Wallet;
18
+ readonly hasWallet: boolean;
19
+ readonly provider: AnchorProvider;
20
+ readonly ammIdl: Idl;
21
+ readonly vmmIdl: Idl;
22
+ readonly ammProgramId: PublicKey;
23
+ readonly vmmProgramId: PublicKey;
24
+ readonly amm: ScaleAmm;
25
+ readonly vmm: ScaleVmm;
26
+ constructor(connection: Connection, wallet: Wallet, options?: ScaleOptions);
27
+ constructor(rpcUrl: string, wallet?: Wallet, options?: ScaleOptions);
28
+ constructor(cluster: ScaleCluster, wallet?: Wallet, options?: ScaleOptions);
29
+ loadAmm(programId?: PublicKey, idlOverride?: Idl): ScaleAmm;
30
+ loadVmm(programId?: PublicKey, idlOverride?: Idl): ScaleVmm;
31
+ load(programId?: PublicKey, idlOverride?: Idl): ScaleAmm;
32
+ }
33
+ export declare const createAmmProgram: (provider: AnchorProvider, programId: PublicKey, idlOverride?: Idl) => Program<Idl>;
34
+ export declare const createVmmProgram: (provider: AnchorProvider, programId: PublicKey, idlOverride?: Idl) => Program<Idl>;
35
+ export declare const createScaleProgram: (provider: AnchorProvider, programId: PublicKey, idlOverride?: Idl) => Program<Idl>;
package/dist/scale.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createScaleProgram = exports.createVmmProgram = exports.createAmmProgram = exports.Scale = void 0;
7
+ const anchor_1 = require("@coral-xyz/anchor");
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const scaleAmm_1 = require("./scaleAmm");
10
+ const scaleVmm_1 = require("./scaleVmm");
11
+ const scale_amm_json_1 = __importDefault(require("./idl/scale_amm.json"));
12
+ const scale_vmm_json_1 = __importDefault(require("./idl/scale_vmm.json"));
13
+ const constants_1 = require("./constants");
14
+ class ReadonlyWallet {
15
+ constructor(publicKey = web3_js_1.Keypair.generate().publicKey) {
16
+ this.publicKey = publicKey;
17
+ this.payer = web3_js_1.Keypair.generate();
18
+ }
19
+ async signTransaction(_tx) {
20
+ throw new Error("No wallet was provided. Use a constructor overload with wallet for direct execution.");
21
+ }
22
+ async signAllTransactions(_txs) {
23
+ throw new Error("No wallet was provided. Use a constructor overload with wallet for direct execution.");
24
+ }
25
+ }
26
+ class Scale {
27
+ constructor(connectionOrRpcOrCluster, wallet, options = {}) {
28
+ const connection = connectionOrRpcOrCluster instanceof web3_js_1.Connection
29
+ ? connectionOrRpcOrCluster
30
+ : new web3_js_1.Connection(connectionOrRpcOrCluster === "mainnet" ||
31
+ connectionOrRpcOrCluster === "devnet"
32
+ ? constants_1.CLUSTER_RPC_URLS[connectionOrRpcOrCluster]
33
+ : connectionOrRpcOrCluster, options.providerOptions?.commitment ?? "confirmed");
34
+ const resolvedWallet = wallet ?? new ReadonlyWallet();
35
+ this.connection = connection;
36
+ this.wallet = resolvedWallet;
37
+ this.hasWallet = Boolean(wallet);
38
+ this.provider = new anchor_1.AnchorProvider(connection, resolvedWallet, options.providerOptions);
39
+ this.ammIdl = options.ammIdl ?? options.idl ?? scale_amm_json_1.default;
40
+ this.vmmIdl = options.vmmIdl ?? scale_vmm_json_1.default;
41
+ this.ammProgramId =
42
+ options.ammProgramId ??
43
+ options.programId ??
44
+ constants_1.AMM_ADDRESS;
45
+ this.vmmProgramId =
46
+ options.vmmProgramId ??
47
+ constants_1.VMM_ADDRESS;
48
+ this.amm = new scaleAmm_1.ScaleAmm(this.provider, this.ammProgramId, this.ammIdl, this.hasWallet);
49
+ this.vmm = new scaleVmm_1.ScaleVmm(this.provider, this.vmmProgramId, this.vmmIdl, this.ammProgramId, this.hasWallet);
50
+ }
51
+ loadAmm(programId = this.ammProgramId, idlOverride) {
52
+ const resolvedIdl = idlOverride ?? this.ammIdl;
53
+ return new scaleAmm_1.ScaleAmm(this.provider, programId, resolvedIdl, this.hasWallet);
54
+ }
55
+ loadVmm(programId = this.vmmProgramId, idlOverride) {
56
+ const resolvedIdl = idlOverride ?? this.vmmIdl;
57
+ return new scaleVmm_1.ScaleVmm(this.provider, programId, resolvedIdl, this.ammProgramId, this.hasWallet);
58
+ }
59
+ load(programId = this.ammProgramId, idlOverride) {
60
+ return this.loadAmm(programId, idlOverride);
61
+ }
62
+ }
63
+ exports.Scale = Scale;
64
+ const createAmmProgram = (provider, programId, idlOverride) => {
65
+ const resolvedIdl = idlOverride ?? scale_amm_json_1.default;
66
+ const idlWithAddress = {
67
+ ...resolvedIdl,
68
+ address: programId.toBase58(),
69
+ };
70
+ return new anchor_1.Program(idlWithAddress, provider);
71
+ };
72
+ exports.createAmmProgram = createAmmProgram;
73
+ const createVmmProgram = (provider, programId, idlOverride) => {
74
+ const resolvedIdl = idlOverride ?? scale_vmm_json_1.default;
75
+ const idlWithAddress = {
76
+ ...resolvedIdl,
77
+ address: programId.toBase58(),
78
+ };
79
+ return new anchor_1.Program(idlWithAddress, provider);
80
+ };
81
+ exports.createVmmProgram = createVmmProgram;
82
+ exports.createScaleProgram = exports.createAmmProgram;
@@ -0,0 +1,68 @@
1
+ import { AnchorProvider, BN, Idl, Program } from "@coral-xyz/anchor";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ import { CreatePoolOptions, CreatePoolParamsInput, CreatePoolInstructionResult, CurveTypeInput, CreatePoolWithDevBuyInstructionResult, EstimateResult, PoolAddress, PoolRef, SwapInstructionResult, SwapOptions, SwapParamsInput } from "./types";
4
+ import { ScaleSdkError } from "./errors";
5
+ export type PoolAccount = {
6
+ enabled: boolean;
7
+ owner: PublicKey;
8
+ mintA: PublicKey;
9
+ mintB: PublicKey;
10
+ tokenAReserves: BN;
11
+ tokenBReserves: BN;
12
+ shift: BN;
13
+ curve: CurveTypeInput;
14
+ bump: number;
15
+ feeBeneficiaryCount: number;
16
+ feeBeneficiaries: Array<{
17
+ wallet: PublicKey;
18
+ shareBps: number;
19
+ }>;
20
+ };
21
+ export declare class ScaleAmm {
22
+ readonly provider: AnchorProvider;
23
+ readonly programId: PublicKey;
24
+ readonly program: Program;
25
+ readonly idl: Idl;
26
+ readonly idlErrors: Map<number, string>;
27
+ readonly hasWallet: boolean;
28
+ constructor(provider: AnchorProvider, programId: PublicKey, idlOverride?: Idl, hasWallet?: boolean);
29
+ getConfigAddress(): PublicKey;
30
+ getPoolAddress(owner: PublicKey, mintA: PublicKey, mintB: PublicKey): PublicKey;
31
+ getVaultAddress(pool: PublicKey, mint: PublicKey): PublicKey;
32
+ getPlatformConfig(): Promise<any>;
33
+ getPlatformBaseToken(): Promise<PublicKey | null>;
34
+ getFeeBeneficiaries(poolInput: PoolAddress | PoolRef): Promise<{
35
+ wallet: PublicKey;
36
+ shareBps: number;
37
+ }[]>;
38
+ getFeeShare(poolInput: PoolAddress | PoolRef, wallet: PublicKey): Promise<number>;
39
+ getTotalCreatorFeeBps(poolInput: PoolAddress | PoolRef): Promise<number>;
40
+ getPool(poolOrAddress: PoolAddress | PoolRef): Promise<PoolRef & {
41
+ data: PoolAccount;
42
+ }>;
43
+ getPoolByAddress(pool: PublicKey): Promise<PoolRef & {
44
+ data: PoolAccount;
45
+ }>;
46
+ getPoolByMints(owner: PublicKey, mintA: PublicKey, mintB: PublicKey): Promise<PoolRef & {
47
+ data: PoolAccount;
48
+ }>;
49
+ createPool(params: CreatePoolParamsInput, mintA: PublicKey, mintB: PublicKey, options?: CreatePoolOptions): Promise<{
50
+ pool: PublicKey;
51
+ vaultA: PublicKey;
52
+ vaultB: PublicKey;
53
+ signature: string;
54
+ }>;
55
+ createPoolInstructions(params: CreatePoolParamsInput, mintA: PublicKey, mintB: PublicKey, options?: CreatePoolOptions): Promise<CreatePoolInstructionResult>;
56
+ createWithDevBuyInstructions(params: CreatePoolParamsInput, mintA: PublicKey, mintB: PublicKey, buyParams: SwapParamsInput, options?: (CreatePoolOptions & SwapOptions)): Promise<CreatePoolWithDevBuyInstructionResult>;
57
+ buy(poolInput: PoolAddress | PoolRef, params: SwapParamsInput, options?: SwapOptions): Promise<string>;
58
+ sell(poolInput: PoolAddress | PoolRef, params: SwapParamsInput, options?: SwapOptions): Promise<string>;
59
+ buyInstructions(poolInput: PoolAddress | PoolRef, params: SwapParamsInput, options?: SwapOptions): Promise<SwapInstructionResult>;
60
+ sellInstructions(poolInput: PoolAddress | PoolRef, params: SwapParamsInput, options?: SwapOptions): Promise<SwapInstructionResult>;
61
+ estimateBuy(poolInput: PoolAddress | PoolRef, params: SwapParamsInput): Promise<EstimateResult>;
62
+ estimateSell(poolInput: PoolAddress | PoolRef, params: SwapParamsInput): Promise<EstimateResult>;
63
+ private estimate;
64
+ private resolvePool;
65
+ private swapInstructions;
66
+ private sendTransaction;
67
+ }
68
+ export { ScaleSdkError };