@coffer_so/sdk 1.0.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 +283 -0
- package/dist/clients/AdminClient.d.ts +194 -0
- package/dist/clients/AdminClient.d.ts.map +1 -0
- package/dist/clients/AdminClient.js +482 -0
- package/dist/clients/AdminClient.js.map +1 -0
- package/dist/clients/CofferBackendClient.d.ts +877 -0
- package/dist/clients/CofferBackendClient.d.ts.map +1 -0
- package/dist/clients/CofferBackendClient.js +536 -0
- package/dist/clients/CofferBackendClient.js.map +1 -0
- package/dist/clients/CubeBackendClient.d.ts +877 -0
- package/dist/clients/CubeBackendClient.d.ts.map +1 -0
- package/dist/clients/CubeBackendClient.js +536 -0
- package/dist/clients/CubeBackendClient.js.map +1 -0
- package/dist/clients/CubicPoolClient.d.ts +120 -0
- package/dist/clients/CubicPoolClient.d.ts.map +1 -0
- package/dist/clients/CubicPoolClient.js +687 -0
- package/dist/clients/CubicPoolClient.js.map +1 -0
- package/dist/clients/PoolFactoryClient.d.ts +53 -0
- package/dist/clients/PoolFactoryClient.d.ts.map +1 -0
- package/dist/clients/PoolFactoryClient.js +91 -0
- package/dist/clients/PoolFactoryClient.js.map +1 -0
- package/dist/clients/RpcClient.d.ts +49 -0
- package/dist/clients/RpcClient.d.ts.map +1 -0
- package/dist/clients/RpcClient.js +135 -0
- package/dist/clients/RpcClient.js.map +1 -0
- package/dist/clients/SingleTokenDepositClient.d.ts +67 -0
- package/dist/clients/SingleTokenDepositClient.d.ts.map +1 -0
- package/dist/clients/SingleTokenDepositClient.js +105 -0
- package/dist/clients/SingleTokenDepositClient.js.map +1 -0
- package/dist/clients/contract-instructions.d.ts +24 -0
- package/dist/clients/contract-instructions.d.ts.map +1 -0
- package/dist/clients/contract-instructions.js +130 -0
- package/dist/clients/contract-instructions.js.map +1 -0
- package/dist/clients/index.d.ts +10 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/clients/index.js +26 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/quote-math.d.ts +15 -0
- package/dist/clients/quote-math.d.ts.map +1 -0
- package/dist/clients/quote-math.js +98 -0
- package/dist/clients/quote-math.js.map +1 -0
- package/dist/clients/tx-builders.d.ts +231 -0
- package/dist/clients/tx-builders.d.ts.map +1 -0
- package/dist/clients/tx-builders.js +861 -0
- package/dist/clients/tx-builders.js.map +1 -0
- package/dist/clients/versioned.d.ts +34 -0
- package/dist/clients/versioned.d.ts.map +1 -0
- package/dist/clients/versioned.js +55 -0
- package/dist/clients/versioned.js.map +1 -0
- package/dist/config/index.d.ts +65 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +75 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/networks.d.ts +12 -0
- package/dist/config/networks.d.ts.map +1 -0
- package/dist/config/networks.js +51 -0
- package/dist/config/networks.js.map +1 -0
- package/dist/config/tokens.d.ts +19 -0
- package/dist/config/tokens.d.ts.map +1 -0
- package/dist/config/tokens.js +43 -0
- package/dist/config/tokens.js.map +1 -0
- package/dist/idl/cubic_pool.json +4203 -0
- package/dist/idl/index.d.ts +1769 -0
- package/dist/idl/index.d.ts.map +1 -0
- package/dist/idl/index.js +18 -0
- package/dist/idl/index.js.map +1 -0
- package/dist/idl/protocol_admin.json +2615 -0
- package/dist/idl/single_token_liquidity.json +1121 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +206 -0
- package/dist/index.js.map +1 -0
- package/dist/math/cubicMath.d.ts +40 -0
- package/dist/math/cubicMath.d.ts.map +1 -0
- package/dist/math/cubicMath.js +82 -0
- package/dist/math/cubicMath.js.map +1 -0
- package/dist/math/fixedPoint.d.ts +19 -0
- package/dist/math/fixedPoint.d.ts.map +1 -0
- package/dist/math/fixedPoint.js +86 -0
- package/dist/math/fixedPoint.js.map +1 -0
- package/dist/math/index.d.ts +9 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +30 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/logExp.d.ts +6 -0
- package/dist/math/logExp.d.ts.map +1 -0
- package/dist/math/logExp.js +68 -0
- package/dist/math/logExp.js.map +1 -0
- package/dist/math/lpLoss.d.ts +44 -0
- package/dist/math/lpLoss.d.ts.map +1 -0
- package/dist/math/lpLoss.js +103 -0
- package/dist/math/lpLoss.js.map +1 -0
- package/dist/math/maxSelloff.d.ts +164 -0
- package/dist/math/maxSelloff.d.ts.map +1 -0
- package/dist/math/maxSelloff.js +397 -0
- package/dist/math/maxSelloff.js.map +1 -0
- package/dist/math/singleToken.d.ts +54 -0
- package/dist/math/singleToken.d.ts.map +1 -0
- package/dist/math/singleToken.js +188 -0
- package/dist/math/singleToken.js.map +1 -0
- package/dist/math/slippage.d.ts +13 -0
- package/dist/math/slippage.d.ts.map +1 -0
- package/dist/math/slippage.js +44 -0
- package/dist/math/slippage.js.map +1 -0
- package/dist/math/surgeFee.d.ts +24 -0
- package/dist/math/surgeFee.d.ts.map +1 -0
- package/dist/math/surgeFee.js +85 -0
- package/dist/math/surgeFee.js.map +1 -0
- package/dist/math/weightedMath.d.ts +20 -0
- package/dist/math/weightedMath.d.ts.map +1 -0
- package/dist/math/weightedMath.js +66 -0
- package/dist/math/weightedMath.js.map +1 -0
- package/dist/parsers/borsh.d.ts +28 -0
- package/dist/parsers/borsh.d.ts.map +1 -0
- package/dist/parsers/borsh.js +104 -0
- package/dist/parsers/borsh.js.map +1 -0
- package/dist/parsers/contracts.d.ts +26 -0
- package/dist/parsers/contracts.d.ts.map +1 -0
- package/dist/parsers/contracts.js +62 -0
- package/dist/parsers/contracts.js.map +1 -0
- package/dist/parsers/events.d.ts +3 -0
- package/dist/parsers/events.d.ts.map +1 -0
- package/dist/parsers/events.js +281 -0
- package/dist/parsers/events.js.map +1 -0
- package/dist/parsers/index.d.ts +6 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +22 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/mintAccount.d.ts +24 -0
- package/dist/parsers/mintAccount.d.ts.map +1 -0
- package/dist/parsers/mintAccount.js +27 -0
- package/dist/parsers/mintAccount.js.map +1 -0
- package/dist/parsers/poolAccount.d.ts +141 -0
- package/dist/parsers/poolAccount.d.ts.map +1 -0
- package/dist/parsers/poolAccount.js +224 -0
- package/dist/parsers/poolAccount.js.map +1 -0
- package/dist/types/contracts.d.ts +1340 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/contracts.js +3 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/events.d.ts +172 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +3 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/pool.d.ts +149 -0
- package/dist/types/pool.d.ts.map +1 -0
- package/dist/types/pool.js +3 -0
- package/dist/types/pool.js.map +1 -0
- package/dist/types/result.d.ts +24 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +11 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/tx.d.ts +261 -0
- package/dist/types/tx.d.ts.map +1 -0
- package/dist/types/tx.js +3 -0
- package/dist/types/tx.js.map +1 -0
- package/dist/utils/errors.d.ts +44 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +192 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/extensions.d.ts +98 -0
- package/dist/utils/extensions.d.ts.map +1 -0
- package/dist/utils/extensions.js +187 -0
- package/dist/utils/extensions.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pda.d.ts +8 -0
- package/dist/utils/pda.d.ts.map +1 -0
- package/dist/utils/pda.js +27 -0
- package/dist/utils/pda.js.map +1 -0
- package/dist/utils/retry.d.ts +22 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +62 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +54 -0
- package/src/clients/AdminClient.ts +608 -0
- package/src/clients/CofferBackendClient.ts +1413 -0
- package/src/clients/CubicPoolClient.ts +719 -0
- package/src/clients/PoolFactoryClient.ts +110 -0
- package/src/clients/RpcClient.ts +195 -0
- package/src/clients/SingleTokenDepositClient.ts +143 -0
- package/src/clients/contract-instructions.ts +115 -0
- package/src/clients/index.ts +9 -0
- package/src/clients/quote-math.ts +81 -0
- package/src/clients/tx-builders.ts +1096 -0
- package/src/clients/versioned.ts +80 -0
- package/src/config/index.ts +111 -0
- package/src/config/networks.ts +71 -0
- package/src/config/tokens.ts +52 -0
- package/src/idl/cubic_pool.json +4203 -0
- package/src/idl/index.ts +13 -0
- package/src/idl/protocol_admin.json +2615 -0
- package/src/idl/single_token_liquidity.json +1121 -0
- package/src/index.ts +262 -0
- package/src/math/cubicMath.ts +92 -0
- package/src/math/fixedPoint.ts +71 -0
- package/src/math/index.ts +13 -0
- package/src/math/logExp.ts +61 -0
- package/src/math/lpLoss.ts +160 -0
- package/src/math/maxSelloff.ts +564 -0
- package/src/math/singleToken.ts +251 -0
- package/src/math/slippage.ts +38 -0
- package/src/math/surgeFee.ts +101 -0
- package/src/math/weightedMath.ts +64 -0
- package/src/parsers/borsh.ts +106 -0
- package/src/parsers/contracts.ts +64 -0
- package/src/parsers/events.ts +275 -0
- package/src/parsers/index.ts +5 -0
- package/src/parsers/mintAccount.ts +44 -0
- package/src/parsers/poolAccount.ts +372 -0
- package/src/types/contracts.ts +238 -0
- package/src/types/events.ts +198 -0
- package/src/types/index.ts +5 -0
- package/src/types/pool.ts +147 -0
- package/src/types/result.ts +51 -0
- package/src/types/tx.ts +278 -0
- package/src/utils/errors.ts +210 -0
- package/src/utils/extensions.ts +196 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/pda.ts +58 -0
- package/src/utils/retry.ts +85 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_BANNED_EXTENSIONS = exports.HARD_UNSUPPORTED_MINT_EXTENSIONS = exports.MAX_KNOWN_MINT_EXTENSION = exports.MintExtension = void 0;
|
|
4
|
+
exports.mintExtensionName = mintExtensionName;
|
|
5
|
+
exports.parseMintExtensions = parseMintExtensions;
|
|
6
|
+
exports.unsupportedMintExtensions = unsupportedMintExtensions;
|
|
7
|
+
exports.bannedMintExtensions = bannedMintExtensions;
|
|
8
|
+
exports.describeUnsupportedToken = describeUnsupportedToken;
|
|
9
|
+
exports.assertTokensSupported = assertTokensSupported;
|
|
10
|
+
/**
|
|
11
|
+
* Token-2022 mint-extension policy.
|
|
12
|
+
*
|
|
13
|
+
* The cubic-pool program moves tokens with the plain SPL `Transfer`
|
|
14
|
+
* instruction (no `transfer_checked`, no fee accounting). Token-2022 refuses
|
|
15
|
+
* a plain `Transfer` for mints that carry a transfer fee, transfer hook or
|
|
16
|
+
* pausable extension,
|
|
17
|
+
* and a `NonTransferable` mint cannot move at all — so any pool operation
|
|
18
|
+
* that touches such a token reverts inside the token program
|
|
19
|
+
* (`MintRequiredForTransfer`, error 0x1f), after the user has already paid
|
|
20
|
+
* for the transaction.
|
|
21
|
+
*
|
|
22
|
+
* The SDK therefore inspects every pool token's mint on `sync()` and refuses
|
|
23
|
+
* to quote or build a transaction that would move a token with an
|
|
24
|
+
* unsupported extension. The refusal is a normal `SdkResult` error with code
|
|
25
|
+
* `unsupported_token_extension` (or a thrown `Error` from the low-level
|
|
26
|
+
* `build*Ix` helpers).
|
|
27
|
+
*/
|
|
28
|
+
/** Token-2022 `ExtensionType` discriminants (u16, little-endian on the wire). */
|
|
29
|
+
var MintExtension;
|
|
30
|
+
(function (MintExtension) {
|
|
31
|
+
MintExtension[MintExtension["Uninitialized"] = 0] = "Uninitialized";
|
|
32
|
+
MintExtension[MintExtension["TransferFeeConfig"] = 1] = "TransferFeeConfig";
|
|
33
|
+
MintExtension[MintExtension["TransferFeeAmount"] = 2] = "TransferFeeAmount";
|
|
34
|
+
MintExtension[MintExtension["MintCloseAuthority"] = 3] = "MintCloseAuthority";
|
|
35
|
+
MintExtension[MintExtension["ConfidentialTransferMint"] = 4] = "ConfidentialTransferMint";
|
|
36
|
+
MintExtension[MintExtension["ConfidentialTransferAccount"] = 5] = "ConfidentialTransferAccount";
|
|
37
|
+
MintExtension[MintExtension["DefaultAccountState"] = 6] = "DefaultAccountState";
|
|
38
|
+
MintExtension[MintExtension["ImmutableOwner"] = 7] = "ImmutableOwner";
|
|
39
|
+
MintExtension[MintExtension["MemoTransfer"] = 8] = "MemoTransfer";
|
|
40
|
+
MintExtension[MintExtension["NonTransferable"] = 9] = "NonTransferable";
|
|
41
|
+
MintExtension[MintExtension["InterestBearingConfig"] = 10] = "InterestBearingConfig";
|
|
42
|
+
MintExtension[MintExtension["CpiGuard"] = 11] = "CpiGuard";
|
|
43
|
+
MintExtension[MintExtension["PermanentDelegate"] = 12] = "PermanentDelegate";
|
|
44
|
+
MintExtension[MintExtension["NonTransferableAccount"] = 13] = "NonTransferableAccount";
|
|
45
|
+
MintExtension[MintExtension["TransferHook"] = 14] = "TransferHook";
|
|
46
|
+
MintExtension[MintExtension["TransferHookAccount"] = 15] = "TransferHookAccount";
|
|
47
|
+
MintExtension[MintExtension["ConfidentialTransferFeeConfig"] = 16] = "ConfidentialTransferFeeConfig";
|
|
48
|
+
MintExtension[MintExtension["ConfidentialTransferFeeAmount"] = 17] = "ConfidentialTransferFeeAmount";
|
|
49
|
+
MintExtension[MintExtension["MetadataPointer"] = 18] = "MetadataPointer";
|
|
50
|
+
MintExtension[MintExtension["TokenMetadata"] = 19] = "TokenMetadata";
|
|
51
|
+
MintExtension[MintExtension["GroupPointer"] = 20] = "GroupPointer";
|
|
52
|
+
MintExtension[MintExtension["TokenGroup"] = 21] = "TokenGroup";
|
|
53
|
+
MintExtension[MintExtension["GroupMemberPointer"] = 22] = "GroupMemberPointer";
|
|
54
|
+
MintExtension[MintExtension["TokenGroupMember"] = 23] = "TokenGroupMember";
|
|
55
|
+
MintExtension[MintExtension["ConfidentialMintBurn"] = 24] = "ConfidentialMintBurn";
|
|
56
|
+
MintExtension[MintExtension["ScaledUiAmountConfig"] = 25] = "ScaledUiAmountConfig";
|
|
57
|
+
MintExtension[MintExtension["PausableConfig"] = 26] = "PausableConfig";
|
|
58
|
+
MintExtension[MintExtension["PausableAccount"] = 27] = "PausableAccount";
|
|
59
|
+
MintExtension[MintExtension["PermissionedBurn"] = 28] = "PermissionedBurn";
|
|
60
|
+
})(MintExtension || (exports.MintExtension = MintExtension = {}));
|
|
61
|
+
/** Highest extension discriminant accepted by the deployed cubic-pool program. */
|
|
62
|
+
exports.MAX_KNOWN_MINT_EXTENSION = MintExtension.PausableAccount;
|
|
63
|
+
/**
|
|
64
|
+
* Extensions the AMM can never move, whatever the pool's `banned_extensions`
|
|
65
|
+
* policy says. This is a transfer-capability check, not the mint-creation
|
|
66
|
+
* policy: even an inert TransferHook needs a mint account for plain Transfer.
|
|
67
|
+
*/
|
|
68
|
+
exports.HARD_UNSUPPORTED_MINT_EXTENSIONS = [
|
|
69
|
+
MintExtension.TransferFeeConfig, // Token-2022 rejects plain Transfer (needs transfer_checked_with_fee)
|
|
70
|
+
MintExtension.TransferHook, // Token-2022 rejects plain Transfer (needs transfer_checked + hook accounts)
|
|
71
|
+
MintExtension.NonTransferable, // cannot move at all
|
|
72
|
+
MintExtension.ConfidentialTransferFeeConfig, // implies a transfer fee
|
|
73
|
+
MintExtension.PausableConfig, // Token-2022 needs the mint to check the pause state
|
|
74
|
+
];
|
|
75
|
+
/**
|
|
76
|
+
* `DEFAULT_BANNED_EXTENSIONS` from `cubic-pool/constants.rs`: the bitmap a
|
|
77
|
+
* fresh `CubicPoolConfig` starts with. Exposed so consumers can render the
|
|
78
|
+
* policy; the per-pool effective bitmap is `PoolInfo.bannedExtensions`.
|
|
79
|
+
*/
|
|
80
|
+
exports.DEFAULT_BANNED_EXTENSIONS = (1n << BigInt(MintExtension.TransferFeeConfig)) |
|
|
81
|
+
(1n << BigInt(MintExtension.MintCloseAuthority)) |
|
|
82
|
+
(1n << BigInt(MintExtension.InterestBearingConfig)) |
|
|
83
|
+
(1n << BigInt(MintExtension.PermanentDelegate)) |
|
|
84
|
+
(1n << BigInt(MintExtension.TransferHook)) |
|
|
85
|
+
(1n << BigInt(MintExtension.ScaledUiAmountConfig)) |
|
|
86
|
+
(1n << BigInt(MintExtension.PausableConfig));
|
|
87
|
+
/** Human-readable name for an extension discriminant. */
|
|
88
|
+
function mintExtensionName(type) {
|
|
89
|
+
return MintExtension[type] ?? `Unknown(${type})`;
|
|
90
|
+
}
|
|
91
|
+
const MINT_BASE_LEN = 82;
|
|
92
|
+
const ACCOUNT_TYPE_OFFSET = 165; // base(82) + padding to token-account size(165)
|
|
93
|
+
const ACCOUNT_TYPE_MINT = 1;
|
|
94
|
+
/**
|
|
95
|
+
* Parse the TLV extension list of a Token-2022 mint. Returns `[]` for a
|
|
96
|
+
* classic SPL Token mint (82 bytes) or a Token-2022 mint with no
|
|
97
|
+
* extensions. Rejects uninitialized mints, invalid mint layouts and malformed
|
|
98
|
+
* TLV data. Pool policy and transfer capability are classified separately.
|
|
99
|
+
*/
|
|
100
|
+
function parseMintExtensions(data) {
|
|
101
|
+
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
102
|
+
if (buf.length !== MINT_BASE_LEN && buf.length <= ACCOUNT_TYPE_OFFSET) {
|
|
103
|
+
throw new Error(`parseMintExtensions: invalid mint length ${buf.length}`);
|
|
104
|
+
}
|
|
105
|
+
if (buf[45] !== 1) {
|
|
106
|
+
throw new Error("parseMintExtensions: mint is not initialized");
|
|
107
|
+
}
|
|
108
|
+
if (buf.length === MINT_BASE_LEN)
|
|
109
|
+
return [];
|
|
110
|
+
if (buf[ACCOUNT_TYPE_OFFSET] !== ACCOUNT_TYPE_MINT) {
|
|
111
|
+
throw new Error(`parseMintExtensions: account type byte is ${buf[ACCOUNT_TYPE_OFFSET]}, expected ${ACCOUNT_TYPE_MINT} (Mint)`);
|
|
112
|
+
}
|
|
113
|
+
const out = [];
|
|
114
|
+
let off = ACCOUNT_TYPE_OFFSET + 1;
|
|
115
|
+
while (off + 4 <= buf.length) {
|
|
116
|
+
const type = buf.readUInt16LE(off);
|
|
117
|
+
const len = buf.readUInt16LE(off + 2);
|
|
118
|
+
if (type === MintExtension.Uninitialized) {
|
|
119
|
+
if (buf.subarray(off).some((byte) => byte !== 0)) {
|
|
120
|
+
throw new Error("parseMintExtensions: nonzero data in uninitialized TLV tail");
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
off += 4;
|
|
125
|
+
if (off + len > buf.length) {
|
|
126
|
+
throw new Error(`parseMintExtensions: extension ${type} claims ${len} bytes past end of account`);
|
|
127
|
+
}
|
|
128
|
+
if (out.includes(type)) {
|
|
129
|
+
throw new Error(`parseMintExtensions: duplicate extension ${type}`);
|
|
130
|
+
}
|
|
131
|
+
out.push(type);
|
|
132
|
+
off += len;
|
|
133
|
+
}
|
|
134
|
+
if (buf.subarray(off).some((byte) => byte !== 0)) {
|
|
135
|
+
throw new Error("parseMintExtensions: incomplete TLV header");
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Which of `extensions` the AMM cannot transfer: everything in
|
|
141
|
+
* {@link HARD_UNSUPPORTED_MINT_EXTENSIONS}, anything the program does not
|
|
142
|
+
* know (> {@link MAX_KNOWN_MINT_EXTENSION}; the program rejects unknown
|
|
143
|
+
* types at creation and the SDK cannot assume their transfer semantics).
|
|
144
|
+
*
|
|
145
|
+
* `banned_extensions` is a snapshot of creation policy, not a runtime transfer
|
|
146
|
+
* restriction. The optional second argument is retained for compatibility
|
|
147
|
+
* but does not change this result. Use `bannedMintExtensions` for diagnostics.
|
|
148
|
+
*/
|
|
149
|
+
function unsupportedMintExtensions(extensions, _bannedExtensions) {
|
|
150
|
+
return extensions.filter((type) => exports.HARD_UNSUPPORTED_MINT_EXTENSIONS.includes(type) || type > exports.MAX_KNOWN_MINT_EXTENSION);
|
|
151
|
+
}
|
|
152
|
+
/** Extensions covered by a creation-policy bitmap; does not imply transfer failure. */
|
|
153
|
+
function bannedMintExtensions(extensions, bannedExtensions) {
|
|
154
|
+
const banned = bannedExtensions === undefined
|
|
155
|
+
? 0n
|
|
156
|
+
: typeof bannedExtensions === "bigint"
|
|
157
|
+
? bannedExtensions
|
|
158
|
+
: BigInt(bannedExtensions.toString());
|
|
159
|
+
if (banned < 0n || banned > 0xffffffffffffffffn) {
|
|
160
|
+
throw new Error("bannedMintExtensions: bitmap must fit u64");
|
|
161
|
+
}
|
|
162
|
+
return extensions.filter((type) => type >= 0 && type < 64 && ((banned >> BigInt(type)) & 1n) === 1n);
|
|
163
|
+
}
|
|
164
|
+
/** One-line description of why a token is refused, for error messages. */
|
|
165
|
+
function describeUnsupportedToken(t) {
|
|
166
|
+
const sym = t.metadata?.symbol ?? t.mint.toBase58();
|
|
167
|
+
return `token[${t.index}] ${sym} has unsupported Token-2022 extension(s): ${(t.unsupportedExtensions ?? [])
|
|
168
|
+
.map(mintExtensionName)
|
|
169
|
+
.join(", ")}`;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Throw if any of the given token indices (or every token when `indices` is
|
|
173
|
+
* `"all"`) carries an unsupported extension. Used by the low-level
|
|
174
|
+
* instruction builders so that direct `build*Ix` callers get the same
|
|
175
|
+
* protection as `CubicPoolClient` users.
|
|
176
|
+
*/
|
|
177
|
+
function assertTokensSupported(pool, indices, op) {
|
|
178
|
+
const idx = indices === "all" ? pool.tokens.map((t) => t.index) : indices;
|
|
179
|
+
const bad = idx
|
|
180
|
+
.map((i) => pool.tokens[i])
|
|
181
|
+
.filter((t) => !!t && (t.unsupportedExtensions?.length ?? 0) > 0);
|
|
182
|
+
if (bad.length === 0)
|
|
183
|
+
return;
|
|
184
|
+
throw new Error(`${op}: unsupported Token-2022 extension for this program's transfer instructions. ` +
|
|
185
|
+
bad.map(describeUnsupportedToken).join("; "));
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../src/utils/extensions.ts"],"names":[],"mappings":";;;AAsFA,8CAEC;AAYD,kDAuCC;AAYD,8DAIC;AAGD,oDAWC;AAGD,4DAKC;AAQD,sDAUC;AAhMD;;;;;;;;;;;;;;;;;GAiBG;AAEH,iFAAiF;AACjF,IAAY,aA8BX;AA9BD,WAAY,aAAa;IACvB,mEAAiB,CAAA;IACjB,2EAAqB,CAAA;IACrB,2EAAqB,CAAA;IACrB,6EAAsB,CAAA;IACtB,yFAA4B,CAAA;IAC5B,+FAA+B,CAAA;IAC/B,+EAAuB,CAAA;IACvB,qEAAkB,CAAA;IAClB,iEAAgB,CAAA;IAChB,uEAAmB,CAAA;IACnB,oFAA0B,CAAA;IAC1B,0DAAa,CAAA;IACb,4EAAsB,CAAA;IACtB,sFAA2B,CAAA;IAC3B,kEAAiB,CAAA;IACjB,gFAAwB,CAAA;IACxB,oGAAkC,CAAA;IAClC,oGAAkC,CAAA;IAClC,wEAAoB,CAAA;IACpB,oEAAkB,CAAA;IAClB,kEAAiB,CAAA;IACjB,8DAAe,CAAA;IACf,8EAAuB,CAAA;IACvB,0EAAqB,CAAA;IACrB,kFAAyB,CAAA;IACzB,kFAAyB,CAAA;IACzB,sEAAmB,CAAA;IACnB,wEAAoB,CAAA;IACpB,0EAAqB,CAAA;AACvB,CAAC,EA9BW,aAAa,6BAAb,aAAa,QA8BxB;AAED,kFAAkF;AACrE,QAAA,wBAAwB,GAAG,aAAa,CAAC,eAAe,CAAC;AAEtE;;;;GAIG;AACU,QAAA,gCAA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":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
__exportStar(require("./errors"), exports);
|
|
18
|
+
__exportStar(require("./retry"), exports);
|
|
19
|
+
__exportStar(require("./pda"), exports);
|
|
20
|
+
__exportStar(require("./extensions"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,wCAAsB;AACtB,+CAA6B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
export declare function derivePoolPda(programId: PublicKey, config: PublicKey, poolId: BN): [PublicKey, number];
|
|
4
|
+
export declare function deriveBptMint(cubicPoolProgramId: PublicKey, pool: PublicKey): [PublicKey, number];
|
|
5
|
+
export declare function deriveHelperPda(stldProgramId: PublicKey, pool: PublicKey): [PublicKey, number];
|
|
6
|
+
export declare function deriveTreasuryPda(protocolFeesProgramId: PublicKey): [PublicKey, number];
|
|
7
|
+
export declare function deriveAta(owner: PublicKey, mint: PublicKey, tokenProgram: PublicKey): PublicKey;
|
|
8
|
+
//# sourceMappingURL=pda.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pda.d.ts","sourceRoot":"","sources":["../../src/utils/pda.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,OAAO,CAAC;AASvB,wBAAgB,aAAa,CAC3B,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,EAAE,GACT,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,SAAS,EAC7B,IAAI,EAAE,SAAS,GACd,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED,wBAAgB,eAAe,CAC7B,aAAa,EAAE,SAAS,EACxB,IAAI,EAAE,SAAS,GACd,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED,wBAAgB,iBAAiB,CAC/B,qBAAqB,EAAE,SAAS,GAC/B,CAAC,SAAS,EAAE,MAAM,CAAC,CAErB;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,SAAS,EACf,YAAY,EAAE,SAAS,GACtB,SAAS,CAMX"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.derivePoolPda = derivePoolPda;
|
|
4
|
+
exports.deriveBptMint = deriveBptMint;
|
|
5
|
+
exports.deriveHelperPda = deriveHelperPda;
|
|
6
|
+
exports.deriveTreasuryPda = deriveTreasuryPda;
|
|
7
|
+
exports.deriveAta = deriveAta;
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
10
|
+
const config_1 = require("../config");
|
|
11
|
+
function derivePoolPda(programId, config, poolId) {
|
|
12
|
+
return web3_js_1.PublicKey.findProgramAddressSync([config_1.CUBIC_POOL_SEED, config.toBuffer(), poolId.toArrayLike(Buffer, "le", 8)], programId);
|
|
13
|
+
}
|
|
14
|
+
function deriveBptMint(cubicPoolProgramId, pool) {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([config_1.BPT_MINT_SEED, pool.toBuffer()], cubicPoolProgramId);
|
|
16
|
+
}
|
|
17
|
+
function deriveHelperPda(stldProgramId, pool) {
|
|
18
|
+
return web3_js_1.PublicKey.findProgramAddressSync([config_1.STLD_HELPER_SEED, pool.toBuffer()], stldProgramId);
|
|
19
|
+
}
|
|
20
|
+
function deriveTreasuryPda(protocolFeesProgramId) {
|
|
21
|
+
return web3_js_1.PublicKey.findProgramAddressSync([config_1.TREASURY_SEED], protocolFeesProgramId);
|
|
22
|
+
}
|
|
23
|
+
function deriveAta(owner, mint, tokenProgram) {
|
|
24
|
+
const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
25
|
+
return ata;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=pda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pda.js","sourceRoot":"","sources":["../../src/utils/pda.ts"],"names":[],"mappings":";;AAUA,sCASC;AAED,sCAQC;AAED,0CAQC;AAED,8CAIC;AAED,8BAUC;AAzDD,6CAA4C;AAE5C,iDAAgE;AAChE,sCAKmB;AAEnB,SAAgB,aAAa,CAC3B,SAAoB,EACpB,MAAiB,EACjB,MAAU;IAEV,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,wBAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EACzE,SAAS,CACV,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa,CAC3B,kBAA6B,EAC7B,IAAe;IAEf,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,sBAAa,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAChC,kBAAkB,CACnB,CAAC;AACJ,CAAC;AAED,SAAgB,eAAe,CAC7B,aAAwB,EACxB,IAAe;IAEf,OAAO,mBAAS,CAAC,sBAAsB,CACrC,CAAC,yBAAgB,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EACnC,aAAa,CACd,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB,CAC/B,qBAAgC;IAEhC,OAAO,mBAAS,CAAC,sBAAsB,CAAC,CAAC,sBAAa,CAAC,EAAE,qBAAqB,CAAC,CAAC;AAClF,CAAC;AAED,SAAgB,SAAS,CACvB,KAAgB,EAChB,IAAe,EACf,YAAuB;IAEvB,MAAM,CAAC,GAAG,CAAC,GAAG,mBAAS,CAAC,sBAAsB,CAC5C,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,YAAY,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAC5D,uCAA2B,CAC5B,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SdkResult } from "../types/result";
|
|
2
|
+
export interface RetryOptions {
|
|
3
|
+
/** Number of attempts total (1 = no retry). */
|
|
4
|
+
attempts?: number;
|
|
5
|
+
/** Per-attempt timeout (ms). */
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
/** Backoff schedule (ms) between attempts. */
|
|
8
|
+
backoffMs?: number[];
|
|
9
|
+
/** Additional predicate: return `false` to stop retrying early. */
|
|
10
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Retry-wrapped helper. Returns a SdkResult<T>. Never throws. Use for any
|
|
14
|
+
* I/O: RPC calls, backend fetches, CPI simulations.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const res = await safeCall(() => connection.getAccountInfo(pk), { attempts: 3 });
|
|
18
|
+
* if (!res.ok) showToast(res.error.humanMessage);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function safeCall<T>(operation: () => Promise<T>, opts?: RetryOptions): Promise<SdkResult<T>>;
|
|
22
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,iBAAiB,CAAC;AAGrD,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,mEAAmE;IACnE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAC3C;AAID;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,IAAI,GAAE,YAAiB,GACtB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAyBvB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeCall = safeCall;
|
|
4
|
+
const result_1 = require("../types/result");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const DEFAULT_BACKOFF_MS = [200, 500, 1500];
|
|
7
|
+
/**
|
|
8
|
+
* Retry-wrapped helper. Returns a SdkResult<T>. Never throws. Use for any
|
|
9
|
+
* I/O: RPC calls, backend fetches, CPI simulations.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const res = await safeCall(() => connection.getAccountInfo(pk), { attempts: 3 });
|
|
13
|
+
* if (!res.ok) showToast(res.error.humanMessage);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
async function safeCall(operation, opts = {}) {
|
|
17
|
+
const attempts = opts.attempts ?? 3;
|
|
18
|
+
const backoff = opts.backoffMs ?? DEFAULT_BACKOFF_MS;
|
|
19
|
+
const timeoutMs = opts.timeoutMs ?? 15000;
|
|
20
|
+
const shouldRetry = opts.shouldRetry ?? defaultShouldRetry;
|
|
21
|
+
let lastError;
|
|
22
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
23
|
+
try {
|
|
24
|
+
const raced = await withTimeout(operation(), timeoutMs);
|
|
25
|
+
return (0, result_1.ok)(raced);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
lastError = e;
|
|
29
|
+
if (!shouldRetry(e))
|
|
30
|
+
break;
|
|
31
|
+
if (attempt < attempts - 1) {
|
|
32
|
+
const delayIdx = Math.min(attempt, backoff.length - 1);
|
|
33
|
+
await sleep(backoff[delayIdx]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return (0, result_1.err)((0, errors_1.toSdkError)(lastError).code, (0, errors_1.toSdkError)(lastError).humanMessage, lastError);
|
|
38
|
+
}
|
|
39
|
+
function defaultShouldRetry(e) {
|
|
40
|
+
const err = (0, errors_1.toSdkError)(e);
|
|
41
|
+
// Retry on transient network / rate-limit errors, stop on structural ones.
|
|
42
|
+
return (err.code === "rpc_timeout" ||
|
|
43
|
+
err.code === "rpc_unavailable" ||
|
|
44
|
+
err.code === "rpc_rate_limited" ||
|
|
45
|
+
err.code === "backend_unavailable");
|
|
46
|
+
}
|
|
47
|
+
function sleep(ms) {
|
|
48
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
49
|
+
}
|
|
50
|
+
function withTimeout(p, ms) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const h = setTimeout(() => reject(new Error(`timed out after ${ms}ms`)), ms);
|
|
53
|
+
p.then((v) => {
|
|
54
|
+
clearTimeout(h);
|
|
55
|
+
resolve(v);
|
|
56
|
+
}, (e) => {
|
|
57
|
+
clearTimeout(h);
|
|
58
|
+
reject(e);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":";;AAyBA,4BA4BC;AArDD,4CAAqD;AACrD,qCAAsC;AAatC,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAE5C;;;;;;;;GAQG;AACI,KAAK,UAAU,QAAQ,CAC5B,SAA2B,EAC3B,OAAqB,EAAE;IAEvB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,kBAAkB,CAAC;IACrD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,KAAM,CAAC;IAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,kBAAkB,CAAC;IAE3D,IAAI,SAAkB,CAAC;IACvB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC;YAC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,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,EAAE,EAAE;YACJ,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO,CAAC,CAAC,CAAC,CAAC;QACb,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,MAAM,CAAC,CAAC,CAAC,CAAC;QACZ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coffer_so/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Coffer DEX SDK — client library for interacting with the Cubic Pool AMM on Solana",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"env:mainnet": "cp .env.mainnet .env && echo 'Active env: MAINNET'",
|
|
16
|
+
"env:testnet": "cp .env.testnet .env && echo 'Active env: TESTNET'",
|
|
17
|
+
"env:show": "grep -E '^NETWORK=' .env || echo 'no .env'",
|
|
18
|
+
"build": "tsc --declaration",
|
|
19
|
+
"build:mainnet": "npm run env:mainnet && npm run build",
|
|
20
|
+
"build:testnet": "npm run env:testnet && npm run build",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"lint": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": ""
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"solana",
|
|
30
|
+
"dex",
|
|
31
|
+
"amm",
|
|
32
|
+
"coffer",
|
|
33
|
+
"sdk"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@solana/web3.js": "^1.95.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@coral-xyz/anchor": "^0.32.1",
|
|
41
|
+
"@solana/spl-token": "^0.4.8",
|
|
42
|
+
"@solana/web3.js": "^1.95.0",
|
|
43
|
+
"bn.js": "^5.2.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/bn.js": "^5.1.5",
|
|
47
|
+
"@types/jest": "^29.5.12",
|
|
48
|
+
"@types/node": "^20.10.4",
|
|
49
|
+
"jest": "^29.7.0",
|
|
50
|
+
"ts-jest": "^29.2.4",
|
|
51
|
+
"ts-node": "^10.9.1",
|
|
52
|
+
"typescript": "^5.3.3"
|
|
53
|
+
}
|
|
54
|
+
}
|