@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/dist/utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferSolInstruction = exports.maybeCreateAtaInstruction = exports.getAta = exports.getTokenProgramForMint = exports.toBN = exports.getConfigAddress = exports.getPairAddress = exports.getVaultAddress = exports.getPoolAddress = exports.getProgramDataAddress = exports.BPF_LOADER_UPGRADEABLE_PROGRAM_ID = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
exports.BPF_LOADER_UPGRADEABLE_PROGRAM_ID = new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111");
|
|
8
|
+
const getProgramDataAddress = (programId) => web3_js_1.PublicKey.findProgramAddressSync([programId.toBuffer()], exports.BPF_LOADER_UPGRADEABLE_PROGRAM_ID)[0];
|
|
9
|
+
exports.getProgramDataAddress = getProgramDataAddress;
|
|
10
|
+
const getPoolAddress = (programId, owner, mintA, mintB) => web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("pool"), owner.toBuffer(), mintA.toBuffer(), mintB.toBuffer()], programId)[0];
|
|
11
|
+
exports.getPoolAddress = getPoolAddress;
|
|
12
|
+
const getVaultAddress = (programId, pool, mint) => web3_js_1.PublicKey.findProgramAddressSync([pool.toBuffer(), mint.toBuffer()], programId)[0];
|
|
13
|
+
exports.getVaultAddress = getVaultAddress;
|
|
14
|
+
const getPairAddress = (programId, mintA, mintB) => web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("state"), mintA.toBuffer(), mintB.toBuffer()], programId)[0];
|
|
15
|
+
exports.getPairAddress = getPairAddress;
|
|
16
|
+
const getConfigAddress = (programId) => web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("config")], programId)[0];
|
|
17
|
+
exports.getConfigAddress = getConfigAddress;
|
|
18
|
+
const toBN = (value) => (anchor_1.BN.isBN(value) ? value : new anchor_1.BN(value));
|
|
19
|
+
exports.toBN = toBN;
|
|
20
|
+
const getTokenProgramForMint = async (connection, mint) => {
|
|
21
|
+
const mintInfo = await connection.getAccountInfo(mint);
|
|
22
|
+
if (!mintInfo) {
|
|
23
|
+
throw new Error(`Mint account not found: ${mint.toBase58()}`);
|
|
24
|
+
}
|
|
25
|
+
if (mintInfo.owner.equals(spl_token_1.TOKEN_PROGRAM_ID)) {
|
|
26
|
+
return spl_token_1.TOKEN_PROGRAM_ID;
|
|
27
|
+
}
|
|
28
|
+
if (mintInfo.owner.equals(spl_token_1.TOKEN_2022_PROGRAM_ID)) {
|
|
29
|
+
return spl_token_1.TOKEN_2022_PROGRAM_ID;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Unknown token program for mint: ${mint.toBase58()}`);
|
|
32
|
+
};
|
|
33
|
+
exports.getTokenProgramForMint = getTokenProgramForMint;
|
|
34
|
+
const getAta = (mint, owner, tokenProgramId, allowOffCurve = false) => (0, spl_token_1.getAssociatedTokenAddressSync)(mint, owner, allowOffCurve, tokenProgramId);
|
|
35
|
+
exports.getAta = getAta;
|
|
36
|
+
const maybeCreateAtaInstruction = async (connection, payer, owner, mint, tokenProgramId, allowOffCurve = false) => {
|
|
37
|
+
let ata;
|
|
38
|
+
try {
|
|
39
|
+
ata = (0, exports.getAta)(mint, owner, tokenProgramId, allowOffCurve);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (!allowOffCurve && err instanceof spl_token_1.TokenOwnerOffCurveError) {
|
|
43
|
+
ata = (0, exports.getAta)(mint, owner, tokenProgramId, true);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const info = await connection.getAccountInfo(ata);
|
|
50
|
+
if (info) {
|
|
51
|
+
return { ata };
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
ata,
|
|
55
|
+
instruction: (0, spl_token_1.createAssociatedTokenAccountInstruction)(payer, ata, owner, mint, tokenProgramId),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.maybeCreateAtaInstruction = maybeCreateAtaInstruction;
|
|
59
|
+
const transferSolInstruction = (from, to, lamports) => {
|
|
60
|
+
const amount = anchor_1.BN.isBN(lamports) ? lamports.toNumber() : lamports;
|
|
61
|
+
return web3_js_1.SystemProgram.transfer({ fromPubkey: from, toPubkey: to, lamports: amount });
|
|
62
|
+
};
|
|
63
|
+
exports.transferSolInstruction = transferSolInstruction;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scalecrx/sdk",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "TypeScript SDK for Scale AMM and VMM on Solana",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/scalecrx/sdk.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/scalecrx/sdk/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/scalecrx/sdk#readme",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"type": "commonjs",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/idl && cp src/idl/*.json dist/idl/",
|
|
27
|
+
"clean": "rm -rf dist",
|
|
28
|
+
"prepare": "npm run clean && npm run build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@coral-xyz/anchor": "^0.30.0",
|
|
32
|
+
"@solana/spl-token": "^0.4.8",
|
|
33
|
+
"@solana/web3.js": "^1.95.3"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@coral-xyz/anchor": "^0.30.0",
|
|
37
|
+
"@solana/web3.js": "^1.95.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"typescript": "^5.4.5"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"solana",
|
|
44
|
+
"anchor",
|
|
45
|
+
"amm",
|
|
46
|
+
"vmm",
|
|
47
|
+
"scale"
|
|
48
|
+
]
|
|
49
|
+
}
|