@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.
Files changed (228) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/dist/clients/AdminClient.d.ts +194 -0
  4. package/dist/clients/AdminClient.d.ts.map +1 -0
  5. package/dist/clients/AdminClient.js +482 -0
  6. package/dist/clients/AdminClient.js.map +1 -0
  7. package/dist/clients/CofferBackendClient.d.ts +877 -0
  8. package/dist/clients/CofferBackendClient.d.ts.map +1 -0
  9. package/dist/clients/CofferBackendClient.js +536 -0
  10. package/dist/clients/CofferBackendClient.js.map +1 -0
  11. package/dist/clients/CubeBackendClient.d.ts +877 -0
  12. package/dist/clients/CubeBackendClient.d.ts.map +1 -0
  13. package/dist/clients/CubeBackendClient.js +536 -0
  14. package/dist/clients/CubeBackendClient.js.map +1 -0
  15. package/dist/clients/CubicPoolClient.d.ts +120 -0
  16. package/dist/clients/CubicPoolClient.d.ts.map +1 -0
  17. package/dist/clients/CubicPoolClient.js +687 -0
  18. package/dist/clients/CubicPoolClient.js.map +1 -0
  19. package/dist/clients/PoolFactoryClient.d.ts +53 -0
  20. package/dist/clients/PoolFactoryClient.d.ts.map +1 -0
  21. package/dist/clients/PoolFactoryClient.js +91 -0
  22. package/dist/clients/PoolFactoryClient.js.map +1 -0
  23. package/dist/clients/RpcClient.d.ts +49 -0
  24. package/dist/clients/RpcClient.d.ts.map +1 -0
  25. package/dist/clients/RpcClient.js +135 -0
  26. package/dist/clients/RpcClient.js.map +1 -0
  27. package/dist/clients/SingleTokenDepositClient.d.ts +67 -0
  28. package/dist/clients/SingleTokenDepositClient.d.ts.map +1 -0
  29. package/dist/clients/SingleTokenDepositClient.js +105 -0
  30. package/dist/clients/SingleTokenDepositClient.js.map +1 -0
  31. package/dist/clients/contract-instructions.d.ts +24 -0
  32. package/dist/clients/contract-instructions.d.ts.map +1 -0
  33. package/dist/clients/contract-instructions.js +130 -0
  34. package/dist/clients/contract-instructions.js.map +1 -0
  35. package/dist/clients/index.d.ts +10 -0
  36. package/dist/clients/index.d.ts.map +1 -0
  37. package/dist/clients/index.js +26 -0
  38. package/dist/clients/index.js.map +1 -0
  39. package/dist/clients/quote-math.d.ts +15 -0
  40. package/dist/clients/quote-math.d.ts.map +1 -0
  41. package/dist/clients/quote-math.js +98 -0
  42. package/dist/clients/quote-math.js.map +1 -0
  43. package/dist/clients/tx-builders.d.ts +231 -0
  44. package/dist/clients/tx-builders.d.ts.map +1 -0
  45. package/dist/clients/tx-builders.js +861 -0
  46. package/dist/clients/tx-builders.js.map +1 -0
  47. package/dist/clients/versioned.d.ts +34 -0
  48. package/dist/clients/versioned.d.ts.map +1 -0
  49. package/dist/clients/versioned.js +55 -0
  50. package/dist/clients/versioned.js.map +1 -0
  51. package/dist/config/index.d.ts +65 -0
  52. package/dist/config/index.d.ts.map +1 -0
  53. package/dist/config/index.js +75 -0
  54. package/dist/config/index.js.map +1 -0
  55. package/dist/config/networks.d.ts +12 -0
  56. package/dist/config/networks.d.ts.map +1 -0
  57. package/dist/config/networks.js +51 -0
  58. package/dist/config/networks.js.map +1 -0
  59. package/dist/config/tokens.d.ts +19 -0
  60. package/dist/config/tokens.d.ts.map +1 -0
  61. package/dist/config/tokens.js +43 -0
  62. package/dist/config/tokens.js.map +1 -0
  63. package/dist/idl/cubic_pool.json +4203 -0
  64. package/dist/idl/index.d.ts +1769 -0
  65. package/dist/idl/index.d.ts.map +1 -0
  66. package/dist/idl/index.js +18 -0
  67. package/dist/idl/index.js.map +1 -0
  68. package/dist/idl/protocol_admin.json +2615 -0
  69. package/dist/idl/single_token_liquidity.json +1121 -0
  70. package/dist/index.d.ts +75 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +206 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/math/cubicMath.d.ts +40 -0
  75. package/dist/math/cubicMath.d.ts.map +1 -0
  76. package/dist/math/cubicMath.js +82 -0
  77. package/dist/math/cubicMath.js.map +1 -0
  78. package/dist/math/fixedPoint.d.ts +19 -0
  79. package/dist/math/fixedPoint.d.ts.map +1 -0
  80. package/dist/math/fixedPoint.js +86 -0
  81. package/dist/math/fixedPoint.js.map +1 -0
  82. package/dist/math/index.d.ts +9 -0
  83. package/dist/math/index.d.ts.map +1 -0
  84. package/dist/math/index.js +30 -0
  85. package/dist/math/index.js.map +1 -0
  86. package/dist/math/logExp.d.ts +6 -0
  87. package/dist/math/logExp.d.ts.map +1 -0
  88. package/dist/math/logExp.js +68 -0
  89. package/dist/math/logExp.js.map +1 -0
  90. package/dist/math/lpLoss.d.ts +44 -0
  91. package/dist/math/lpLoss.d.ts.map +1 -0
  92. package/dist/math/lpLoss.js +103 -0
  93. package/dist/math/lpLoss.js.map +1 -0
  94. package/dist/math/maxSelloff.d.ts +164 -0
  95. package/dist/math/maxSelloff.d.ts.map +1 -0
  96. package/dist/math/maxSelloff.js +397 -0
  97. package/dist/math/maxSelloff.js.map +1 -0
  98. package/dist/math/singleToken.d.ts +54 -0
  99. package/dist/math/singleToken.d.ts.map +1 -0
  100. package/dist/math/singleToken.js +188 -0
  101. package/dist/math/singleToken.js.map +1 -0
  102. package/dist/math/slippage.d.ts +13 -0
  103. package/dist/math/slippage.d.ts.map +1 -0
  104. package/dist/math/slippage.js +44 -0
  105. package/dist/math/slippage.js.map +1 -0
  106. package/dist/math/surgeFee.d.ts +24 -0
  107. package/dist/math/surgeFee.d.ts.map +1 -0
  108. package/dist/math/surgeFee.js +85 -0
  109. package/dist/math/surgeFee.js.map +1 -0
  110. package/dist/math/weightedMath.d.ts +20 -0
  111. package/dist/math/weightedMath.d.ts.map +1 -0
  112. package/dist/math/weightedMath.js +66 -0
  113. package/dist/math/weightedMath.js.map +1 -0
  114. package/dist/parsers/borsh.d.ts +28 -0
  115. package/dist/parsers/borsh.d.ts.map +1 -0
  116. package/dist/parsers/borsh.js +104 -0
  117. package/dist/parsers/borsh.js.map +1 -0
  118. package/dist/parsers/contracts.d.ts +26 -0
  119. package/dist/parsers/contracts.d.ts.map +1 -0
  120. package/dist/parsers/contracts.js +62 -0
  121. package/dist/parsers/contracts.js.map +1 -0
  122. package/dist/parsers/events.d.ts +3 -0
  123. package/dist/parsers/events.d.ts.map +1 -0
  124. package/dist/parsers/events.js +281 -0
  125. package/dist/parsers/events.js.map +1 -0
  126. package/dist/parsers/index.d.ts +6 -0
  127. package/dist/parsers/index.d.ts.map +1 -0
  128. package/dist/parsers/index.js +22 -0
  129. package/dist/parsers/index.js.map +1 -0
  130. package/dist/parsers/mintAccount.d.ts +24 -0
  131. package/dist/parsers/mintAccount.d.ts.map +1 -0
  132. package/dist/parsers/mintAccount.js +27 -0
  133. package/dist/parsers/mintAccount.js.map +1 -0
  134. package/dist/parsers/poolAccount.d.ts +141 -0
  135. package/dist/parsers/poolAccount.d.ts.map +1 -0
  136. package/dist/parsers/poolAccount.js +224 -0
  137. package/dist/parsers/poolAccount.js.map +1 -0
  138. package/dist/types/contracts.d.ts +1340 -0
  139. package/dist/types/contracts.d.ts.map +1 -0
  140. package/dist/types/contracts.js +3 -0
  141. package/dist/types/contracts.js.map +1 -0
  142. package/dist/types/events.d.ts +172 -0
  143. package/dist/types/events.d.ts.map +1 -0
  144. package/dist/types/events.js +3 -0
  145. package/dist/types/events.js.map +1 -0
  146. package/dist/types/index.d.ts +6 -0
  147. package/dist/types/index.d.ts.map +1 -0
  148. package/dist/types/index.js +22 -0
  149. package/dist/types/index.js.map +1 -0
  150. package/dist/types/pool.d.ts +149 -0
  151. package/dist/types/pool.d.ts.map +1 -0
  152. package/dist/types/pool.js +3 -0
  153. package/dist/types/pool.js.map +1 -0
  154. package/dist/types/result.d.ts +24 -0
  155. package/dist/types/result.d.ts.map +1 -0
  156. package/dist/types/result.js +11 -0
  157. package/dist/types/result.js.map +1 -0
  158. package/dist/types/tx.d.ts +261 -0
  159. package/dist/types/tx.d.ts.map +1 -0
  160. package/dist/types/tx.js +3 -0
  161. package/dist/types/tx.js.map +1 -0
  162. package/dist/utils/errors.d.ts +44 -0
  163. package/dist/utils/errors.d.ts.map +1 -0
  164. package/dist/utils/errors.js +192 -0
  165. package/dist/utils/errors.js.map +1 -0
  166. package/dist/utils/extensions.d.ts +98 -0
  167. package/dist/utils/extensions.d.ts.map +1 -0
  168. package/dist/utils/extensions.js +187 -0
  169. package/dist/utils/extensions.js.map +1 -0
  170. package/dist/utils/index.d.ts +5 -0
  171. package/dist/utils/index.d.ts.map +1 -0
  172. package/dist/utils/index.js +21 -0
  173. package/dist/utils/index.js.map +1 -0
  174. package/dist/utils/pda.d.ts +8 -0
  175. package/dist/utils/pda.d.ts.map +1 -0
  176. package/dist/utils/pda.js +27 -0
  177. package/dist/utils/pda.js.map +1 -0
  178. package/dist/utils/retry.d.ts +22 -0
  179. package/dist/utils/retry.d.ts.map +1 -0
  180. package/dist/utils/retry.js +62 -0
  181. package/dist/utils/retry.js.map +1 -0
  182. package/package.json +54 -0
  183. package/src/clients/AdminClient.ts +608 -0
  184. package/src/clients/CofferBackendClient.ts +1413 -0
  185. package/src/clients/CubicPoolClient.ts +719 -0
  186. package/src/clients/PoolFactoryClient.ts +110 -0
  187. package/src/clients/RpcClient.ts +195 -0
  188. package/src/clients/SingleTokenDepositClient.ts +143 -0
  189. package/src/clients/contract-instructions.ts +115 -0
  190. package/src/clients/index.ts +9 -0
  191. package/src/clients/quote-math.ts +81 -0
  192. package/src/clients/tx-builders.ts +1096 -0
  193. package/src/clients/versioned.ts +80 -0
  194. package/src/config/index.ts +111 -0
  195. package/src/config/networks.ts +71 -0
  196. package/src/config/tokens.ts +52 -0
  197. package/src/idl/cubic_pool.json +4203 -0
  198. package/src/idl/index.ts +13 -0
  199. package/src/idl/protocol_admin.json +2615 -0
  200. package/src/idl/single_token_liquidity.json +1121 -0
  201. package/src/index.ts +262 -0
  202. package/src/math/cubicMath.ts +92 -0
  203. package/src/math/fixedPoint.ts +71 -0
  204. package/src/math/index.ts +13 -0
  205. package/src/math/logExp.ts +61 -0
  206. package/src/math/lpLoss.ts +160 -0
  207. package/src/math/maxSelloff.ts +564 -0
  208. package/src/math/singleToken.ts +251 -0
  209. package/src/math/slippage.ts +38 -0
  210. package/src/math/surgeFee.ts +101 -0
  211. package/src/math/weightedMath.ts +64 -0
  212. package/src/parsers/borsh.ts +106 -0
  213. package/src/parsers/contracts.ts +64 -0
  214. package/src/parsers/events.ts +275 -0
  215. package/src/parsers/index.ts +5 -0
  216. package/src/parsers/mintAccount.ts +44 -0
  217. package/src/parsers/poolAccount.ts +372 -0
  218. package/src/types/contracts.ts +238 -0
  219. package/src/types/events.ts +198 -0
  220. package/src/types/index.ts +5 -0
  221. package/src/types/pool.ts +147 -0
  222. package/src/types/result.ts +51 -0
  223. package/src/types/tx.ts +278 -0
  224. package/src/utils/errors.ts +210 -0
  225. package/src/utils/extensions.ts +196 -0
  226. package/src/utils/index.ts +4 -0
  227. package/src/utils/pda.ts +58 -0
  228. package/src/utils/retry.ts +85 -0
@@ -0,0 +1,24 @@
1
+ import { AccountMeta, TransactionInstruction } from "@solana/web3.js";
2
+ import { CofferConfig } from "../config";
3
+ import { ContractInstructionMap, ContractProgram } from "../types/contracts";
4
+ type InstructionName<P extends ContractProgram> = keyof ContractInstructionMap[P] & string;
5
+ export type ContractInstructionArgs<P extends ContractProgram, I extends InstructionName<P>> = ContractInstructionMap[P][I] extends {
6
+ args: infer A;
7
+ } ? A : never;
8
+ export type ContractInstructionAccounts<P extends ContractProgram, I extends InstructionName<P>> = ContractInstructionMap[P][I] extends {
9
+ accounts: infer A;
10
+ } ? A : never;
11
+ /**
12
+ * Build any instruction exposed by the three deployed contracts. Argument and
13
+ * account names use the exact snake_case names from the shipped IDLs; all fixed
14
+ * accounts are explicit. Integer widths, argument fields, account order and
15
+ * signer/writable flags are checked or derived from those IDLs.
16
+ *
17
+ * This only builds an instruction. Required signatures, authority constraints,
18
+ * remaining-account layouts and transaction size still apply. A Treasury PDA
19
+ * can sign only during CPI: use the corresponding protocolAdmin wrapper for
20
+ * governance, rather than sending a cubicPool instruction with a PDA signer.
21
+ */
22
+ export declare function buildContractInstruction<P extends ContractProgram, I extends InstructionName<P>>(config: CofferConfig, program: P, instruction: I, args: ContractInstructionArgs<P, I>, accounts: ContractInstructionAccounts<P, I>, remainingAccounts?: AccountMeta[]): TransactionInstruction;
23
+ export {};
24
+ //# sourceMappingURL=contract-instructions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-instructions.d.ts","sourceRoot":"","sources":["../../src/clients/contract-instructions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAa,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE7E,KAAK,eAAe,CAAC,CAAC,SAAS,eAAe,IAAI,MAAM,sBAAsB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAC3F,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,IACzF,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AACrE,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,IAC7F,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAIzE;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAC9F,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,EACd,IAAI,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,QAAQ,EAAE,2BAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3C,iBAAiB,GAAE,WAAW,EAAO,GACpC,sBAAsB,CA4BxB"}
@@ -0,0 +1,130 @@
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.buildContractInstruction = buildContractInstruction;
7
+ const anchor_1 = require("@coral-xyz/anchor");
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const bn_js_1 = __importDefault(require("bn.js"));
10
+ const idl_1 = require("../idl");
11
+ const coders = new Map();
12
+ /**
13
+ * Build any instruction exposed by the three deployed contracts. Argument and
14
+ * account names use the exact snake_case names from the shipped IDLs; all fixed
15
+ * accounts are explicit. Integer widths, argument fields, account order and
16
+ * signer/writable flags are checked or derived from those IDLs.
17
+ *
18
+ * This only builds an instruction. Required signatures, authority constraints,
19
+ * remaining-account layouts and transaction size still apply. A Treasury PDA
20
+ * can sign only during CPI: use the corresponding protocolAdmin wrapper for
21
+ * governance, rather than sending a cubicPool instruction with a PDA signer.
22
+ */
23
+ function buildContractInstruction(config, program, instruction, args, accounts, remainingAccounts = []) {
24
+ const idl = idl_1.IDLS[program];
25
+ const schema = idl.instructions.find((ix) => ix.name === instruction);
26
+ if (!schema)
27
+ throw new Error(`Unknown ${program} instruction: ${instruction}`);
28
+ validateFields(args, schema.args, idl, `${program}.${instruction}`);
29
+ const supplied = accounts;
30
+ assertObjectFields(supplied, schema.accounts.map((a) => a.name), "accounts");
31
+ const keys = schema.accounts.map((a) => ({
32
+ pubkey: publicKey(supplied[a.name], `accounts.${a.name}`),
33
+ isSigner: a.signer === true,
34
+ isWritable: a.writable === true,
35
+ }));
36
+ for (const meta of remainingAccounts) {
37
+ if (typeof meta.isSigner !== "boolean" || typeof meta.isWritable !== "boolean") {
38
+ throw new Error("remainingAccounts must contain explicit signer and writable flags");
39
+ }
40
+ keys.push({ ...meta, pubkey: publicKey(meta.pubkey, "remainingAccounts.pubkey") });
41
+ }
42
+ let coder = coders.get(program);
43
+ if (!coder) {
44
+ coder = new anchor_1.BorshInstructionCoder(idl);
45
+ coders.set(program, coder);
46
+ }
47
+ return new web3_js_1.TransactionInstruction({
48
+ programId: config.programs[program],
49
+ keys,
50
+ data: coder.encode(instruction, args),
51
+ });
52
+ }
53
+ function publicKey(value, path) {
54
+ if (!value || typeof value.toBuffer !== "function")
55
+ throw new Error(`${path} must be a PublicKey`);
56
+ const bytes = value.toBuffer();
57
+ if (bytes.length !== 32)
58
+ throw new Error(`${path} must be a 32-byte PublicKey`);
59
+ return new web3_js_1.PublicKey(bytes);
60
+ }
61
+ function assertObjectFields(value, expected, path) {
62
+ if (!value || typeof value !== "object" || Array.isArray(value))
63
+ throw new Error(`${path} must be an object`);
64
+ const names = Object.keys(value);
65
+ for (const key of expected)
66
+ if (!Object.prototype.hasOwnProperty.call(value, key))
67
+ throw new Error(`${path}.${key} is required`);
68
+ for (const key of names)
69
+ if (!expected.includes(key))
70
+ throw new Error(`${path}.${key} is not in the contract ABI`);
71
+ }
72
+ function validateFields(value, fields, idl, path) {
73
+ assertObjectFields(value, fields.map((f) => f.name), path);
74
+ for (const field of fields)
75
+ validateType(value[field.name], field.type, idl, `${path}.${field.name}`);
76
+ }
77
+ function validateType(value, type, idl, path) {
78
+ if (typeof type === "string") {
79
+ if (type === "pubkey") {
80
+ publicKey(value, path);
81
+ return;
82
+ }
83
+ if (type === "bool") {
84
+ if (typeof value !== "boolean")
85
+ throw new Error(`${path} must be boolean`);
86
+ return;
87
+ }
88
+ if (type === "bytes") {
89
+ if (!Buffer.isBuffer(value))
90
+ throw new Error(`${path} must be a Buffer`);
91
+ return;
92
+ }
93
+ const integer = /^([ui])(\d+)$/.exec(type);
94
+ if (integer) {
95
+ const width = Number(integer[2]);
96
+ const signed = integer[1] === "i";
97
+ if (width > 32 ? !bn_js_1.default.isBN(value) : !Number.isSafeInteger(value))
98
+ throw new Error(`${path} must be ${width > 32 ? "BN" : "an integer"} (${type})`);
99
+ const n = bn_js_1.default.isBN(value) ? value : new bn_js_1.default(value);
100
+ const min = signed ? new bn_js_1.default(1).shln(width - 1).neg() : new bn_js_1.default(0);
101
+ const max = new bn_js_1.default(1).shln(signed ? width - 1 : width).subn(1);
102
+ if (n.lt(min) || n.gt(max))
103
+ throw new Error(`${path} is outside ${type}`);
104
+ return;
105
+ }
106
+ throw new Error(`Unsupported ABI primitive ${type}`);
107
+ }
108
+ if (type.option) {
109
+ if (value !== null)
110
+ validateType(value, type.option, idl, path);
111
+ return;
112
+ }
113
+ if (type.vec || type.array) {
114
+ if (!Array.isArray(value))
115
+ throw new Error(`${path} must be an array`);
116
+ if (type.array && value.length !== type.array[1])
117
+ throw new Error(`${path} must have ${type.array[1]} entries`);
118
+ value.forEach((v, i) => validateType(v, type.vec ?? type.array[0], idl, `${path}[${i}]`));
119
+ return;
120
+ }
121
+ if (type.defined) {
122
+ const definition = idl.types.find((t) => t.name === type.defined.name);
123
+ if (!definition || definition.type.kind !== "struct")
124
+ throw new Error(`Unsupported ABI type ${type.defined.name}`);
125
+ validateFields(value, definition.type.fields, idl, path);
126
+ return;
127
+ }
128
+ throw new Error(`Unsupported ABI type at ${path}`);
129
+ }
130
+ //# sourceMappingURL=contract-instructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-instructions.js","sourceRoot":"","sources":["../../src/clients/contract-instructions.ts"],"names":[],"mappings":";;;;;AA0BA,4DAmCC;AA7DD,8CAA+D;AAC/D,6CAAiF;AACjF,kDAAuB;AAEvB,gCAA8B;AAS9B,MAAM,MAAM,GAAG,IAAI,GAAG,EAA0C,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,SAAgB,wBAAwB,CACtC,MAAoB,EACpB,OAAU,EACV,WAAc,EACd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,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACnH,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACzD,OAAO;IACT,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,10 @@
1
+ export * from "./RpcClient";
2
+ export * from "./CofferBackendClient";
3
+ export * from "./CubicPoolClient";
4
+ export * from "./tx-builders";
5
+ export * from "./versioned";
6
+ export * from "./SingleTokenDepositClient";
7
+ export * from "./PoolFactoryClient";
8
+ export * from "./AdminClient";
9
+ export * from "./contract-instructions";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,26 @@
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("./RpcClient"), exports);
18
+ __exportStar(require("./CofferBackendClient"), exports);
19
+ __exportStar(require("./CubicPoolClient"), exports);
20
+ __exportStar(require("./tx-builders"), exports);
21
+ __exportStar(require("./versioned"), exports);
22
+ __exportStar(require("./SingleTokenDepositClient"), exports);
23
+ __exportStar(require("./PoolFactoryClient"), exports);
24
+ __exportStar(require("./AdminClient"), exports);
25
+ __exportStar(require("./contract-instructions"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,wDAAsC;AACtC,oDAAkC;AAClC,gDAA8B;AAC9B,8CAA4B;AAC5B,6DAA2C;AAC3C,sDAAoC;AACpC,gDAA8B;AAC9B,0DAAwC"}
@@ -0,0 +1,15 @@
1
+ import { PoolInfo } from "../types/pool";
2
+ export declare function u64(value: bigint, label: string): bigint;
3
+ /** Compute one deployed-contract swap against a snapshot, optionally advance a private zap copy. */
4
+ export declare function simulatePoolSwap(pool: PoolInfo, tokenInIndex: number, tokenOutIndex: number, amountIn: bigint, now: bigint, mutate?: boolean): {
5
+ amountOut: bigint;
6
+ grossAmountOut: bigint;
7
+ feeAmount: bigint;
8
+ protocolFeeAmount: bigint;
9
+ surgeFeeAmount: bigint;
10
+ spotOut: bigint;
11
+ window: import("../math/maxSelloff").SelloffResult | null;
12
+ };
13
+ /** Clock from sync; callers may supply the transaction's expected Unix timestamp explicitly. */
14
+ export declare function quoteTimestamp(pool: PoolInfo, nowSeconds?: number): bigint;
15
+ //# sourceMappingURL=quote-math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote-math.d.ts","sourceRoot":"","sources":["../../src/clients/quote-math.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAOxD,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGxD;AAGD,oGAAoG;AACpG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAQ;;;;;;;;EAsD1I;AAED,gGAAgG;AAChG,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1E"}
@@ -0,0 +1,98 @@
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.u64 = u64;
7
+ exports.simulatePoolSwap = simulatePoolSwap;
8
+ exports.quoteTimestamp = quoteTimestamp;
9
+ const bn_js_1 = __importDefault(require("bn.js"));
10
+ const cubicMath_1 = require("../math/cubicMath");
11
+ const slippage_1 = require("../math/slippage");
12
+ const maxSelloff_1 = require("../math/maxSelloff");
13
+ const surgeFee_1 = require("../math/surgeFee");
14
+ const U64_MAX = (1n << 64n) - 1n;
15
+ function u64(value, label) {
16
+ if (value < 0n || value > U64_MAX)
17
+ throw new Error(`${label} must fit u64`);
18
+ return value;
19
+ }
20
+ const bi = (value) => BigInt(value?.toString() ?? "0");
21
+ /** Compute one deployed-contract swap against a snapshot, optionally advance a private zap copy. */
22
+ function simulatePoolSwap(pool, tokenInIndex, tokenOutIndex, amountIn, now, mutate = false) {
23
+ if (!Number.isInteger(tokenInIndex) || !Number.isInteger(tokenOutIndex) || tokenInIndex === tokenOutIndex ||
24
+ tokenInIndex < 0 || tokenOutIndex < 0 || tokenInIndex >= pool.tokenCount || tokenOutIndex >= pool.tokenCount) {
25
+ throw new Error("InvalidTokenIndex");
26
+ }
27
+ if (!pool.poolEnabled)
28
+ throw new Error("PoolDisabled");
29
+ if (!pool.swapsEnabled)
30
+ throw new Error("SwapsDisabled");
31
+ u64(amountIn, "amountIn");
32
+ if (amountIn === 0n)
33
+ throw new Error("ZeroAmount");
34
+ const input = pool.tokens[tokenInIndex], output = pool.tokens[tokenOutIndex];
35
+ if (!input.isActive)
36
+ throw new Error("TokenInactive");
37
+ const virtualBalanceIn = bi(input.virtualBalance), virtualBalanceOut = bi(output.virtualBalance);
38
+ const actualBalanceOut = bi(output.actualBalance);
39
+ if (input.maxSelloffPct > 0 && [input.maxSelloffPeriodLength, input.previousSelloff, input.currentSelloff,
40
+ input.windowStartTimestamp, input.selloffVbSnapshot].some(v => v === undefined)) {
41
+ throw new Error("Selloff state missing: sync the pool before quoting");
42
+ }
43
+ const window = (0, maxSelloff_1.checkAndAdvanceSelloff)({
44
+ state: { previousSelloff: bi(input.previousSelloff), currentSelloff: bi(input.currentSelloff),
45
+ windowStartTimestamp: bi(input.windowStartTimestamp), selloffVbSnapshot: bi(input.selloffVbSnapshot) },
46
+ maxSelloffPct: input.maxSelloffPct, period: input.maxSelloffPeriodLength ?? 0,
47
+ amountIn, virtualBalance: virtualBalanceIn, now,
48
+ });
49
+ const feeAmount = (0, slippage_1.calculateSwapFee)(amountIn, pool.swapFeeRate);
50
+ const protocolFeeAmount = (0, slippage_1.calculateProtocolFee)(feeAmount, pool.protocolFeeRate);
51
+ const amountInAfterFee = amountIn - feeAmount;
52
+ const weightInBps = BigInt(input.weightBps), weightOutBps = BigInt(output.weightBps);
53
+ const grossAmountOut = (0, cubicMath_1.calcOutGivenIn)({ virtualBalanceIn, virtualBalanceOut, weightInBps, weightOutBps, amountIn: amountInAfterFee, actualBalanceOut });
54
+ const surgeFeeAmount = (0, surgeFee_1.calcSurgeFeeAmount)({ window,
55
+ thresholdPct: input.variableFeeThresholdPct ?? 0, slopeLowPct: input.variableFeeSlopeLowPct ?? 0,
56
+ slopeMidPct: input.variableFeeSlopeMidPct ?? 0, slopeHighPct: input.variableFeeSlopeHighPct ?? 0,
57
+ kinkPct: input.variableFeeKinkPct ?? 0, amountInAfterFee, amountOut: grossAmountOut,
58
+ virtualBalanceIn, virtualBalanceOut, weightInBps, weightOutBps, actualBalanceOut });
59
+ const amountOut = grossAmountOut - surgeFeeAmount;
60
+ const netInput = amountIn - protocolFeeAmount;
61
+ const actualInAfter = u64(bi(input.actualBalance) + netInput, "input actual balance");
62
+ const virtualInAfter = u64(virtualBalanceIn + netInput, "input virtual balance");
63
+ const actualOutAfter = u64(actualBalanceOut - grossAmountOut, "output actual balance");
64
+ const virtualOutAfter = u64(virtualBalanceOut - grossAmountOut, "output virtual balance");
65
+ const inputFees = u64(bi(input.protocolFeesOwed) + protocolFeeAmount, "input fees");
66
+ const outputFees = u64(bi(output.protocolFeesOwed) + surgeFeeAmount, "output fees");
67
+ if (mutate) {
68
+ input.actualBalance = new bn_js_1.default(actualInAfter.toString());
69
+ input.virtualBalance = new bn_js_1.default(virtualInAfter.toString());
70
+ output.actualBalance = new bn_js_1.default(actualOutAfter.toString());
71
+ output.virtualBalance = new bn_js_1.default(virtualOutAfter.toString());
72
+ input.protocolFeesOwed = new bn_js_1.default(inputFees.toString());
73
+ output.protocolFeesOwed = new bn_js_1.default(outputFees.toString());
74
+ if (window) {
75
+ input.previousSelloff = new bn_js_1.default(window.previousSelloff.toString());
76
+ input.currentSelloff = new bn_js_1.default(window.currentSelloff.toString());
77
+ input.windowStartTimestamp = new bn_js_1.default(window.windowStartTimestamp.toString());
78
+ input.selloffVbSnapshot = new bn_js_1.default(window.vbSnapshot.toString());
79
+ }
80
+ }
81
+ const spotOut = (0, cubicMath_1.calcSpotOut)({ virtualBalanceIn, virtualBalanceOut, weightInBps, weightOutBps, amountIn: amountInAfterFee });
82
+ // `window` is exposed for display math (post-trade fill %, span-average
83
+ // surge pct) — null when the input token has no sell-off cap configured.
84
+ return { amountOut, grossAmountOut, feeAmount, protocolFeeAmount, surgeFeeAmount, spotOut, window };
85
+ }
86
+ /** Clock from sync; callers may supply the transaction's expected Unix timestamp explicitly. */
87
+ function quoteTimestamp(pool, nowSeconds) {
88
+ const now = nowSeconds ?? pool.chainTimestamp;
89
+ if (now === undefined) {
90
+ if (pool.tokens.some(t => t.maxSelloffPct > 0))
91
+ throw new Error("Chain timestamp missing: sync or supply nowSeconds");
92
+ return 0n;
93
+ }
94
+ if (!Number.isSafeInteger(now) || now < 0)
95
+ throw new Error("Invalid quote timestamp");
96
+ return BigInt(now);
97
+ }
98
+ //# sourceMappingURL=quote-math.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote-math.js","sourceRoot":"","sources":["../../src/clients/quote-math.ts"],"names":[],"mappings":";;;;;AAQA,kBAGC;AAID,4CAsDC;AAGD,wCAQC;AAhFD,kDAAuB;AAEvB,iDAAgE;AAChE,+CAA0E;AAC1E,mDAA4D;AAC5D,+CAAsD;AAEtD,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AACjC,SAAgB,GAAG,CAAC,KAAa,EAAE,KAAa;IAC9C,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,eAAe,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC;AACf,CAAC;AACD,MAAM,EAAE,GAAG,CAAC,KAAqB,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,CAAC;AAE/E,oGAAoG;AACpG,SAAgB,gBAAgB,CAAC,IAAc,EAAE,YAAoB,EAAE,aAAqB,EAAE,QAAgB,EAAE,GAAW,EAAE,MAAM,GAAG,KAAK;IACzI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,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I,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACtH,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACtF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
@@ -0,0 +1,231 @@
1
+ import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ import { CofferConfig } from "../config";
4
+ import { PoolInfo } from "../types/pool";
5
+ import { AddLiquidityParams, BuiltTx, DeployPoolParams, RangeManagerUpdateParams, RemoveLiquidityParams, SetRangeManagerConfigParams, SetRangeManagerParams, SingleTokenDepositParams, SwapParams, SelloffParams } from "../types/tx";
6
+ export declare function buildSwapIx(cfg: CofferConfig, pool: PoolInfo, params: SwapParams & {
7
+ minAmountOut: BN;
8
+ }): TransactionInstruction;
9
+ export declare function buildSwapTx(cfg: CofferConfig, pool: PoolInfo, params: SwapParams & {
10
+ minAmountOut: BN;
11
+ }): BuiltTx;
12
+ /**
13
+ * `add_liquidity` — proportional join.
14
+ *
15
+ * ⚠ **`params.tokenAmounts` is a CEILING, not an exact amount** (v5.1,
16
+ * audit M-4 / I-1). The program takes the largest strictly-proportional
17
+ * basket that fits inside the vector you pass and leaves the remainder in
18
+ * the wallet; it does NOT pull the full amounts. Any UI copy of the form
19
+ * "you will deposit exactly X" is wrong — quote the proportional basket
20
+ * instead (see `CubicPoolClient.quoteAddLiquidity`).
21
+ *
22
+ * The wire format is unchanged, so this is a behaviour note, not an
23
+ * encoding change: the same bytes now mean "at most this much".
24
+ */
25
+ export declare function buildAddLiquidityIx(cfg: CofferConfig, pool: PoolInfo, params: AddLiquidityParams): TransactionInstruction;
26
+ export declare function buildAddLiquidityTx(cfg: CofferConfig, pool: PoolInfo, params: AddLiquidityParams): BuiltTx;
27
+ export declare function buildRemoveLiquidityIx(cfg: CofferConfig, pool: PoolInfo, params: RemoveLiquidityParams): TransactionInstruction;
28
+ export declare function buildRemoveLiquidityTx(cfg: CofferConfig, pool: PoolInfo, params: RemoveLiquidityParams): BuiltTx;
29
+ /**
30
+ * Largest pool the zap will accept, mirroring `STLD_MAX_TOKENS` in
31
+ * `single-token-liquidity/src/constants.rs` (which is defined as
32
+ * cubic-pool's `MAX_TOKENS`).
33
+ *
34
+ * Raised from 5 to 10 in v5.1 (audit SF-3): the old ceiling existed because
35
+ * the per-leg allocations exhausted the 32 KiB bump heap. Above this the
36
+ * program rejects with `PoolTooLargeForZap` (stld 6032).
37
+ */
38
+ export declare const STLD_MAX_TOKENS = 10;
39
+ /**
40
+ * Compute units to request for the zap.
41
+ *
42
+ * Measured on the v5.1 build at the worst case N=10: 1,073,206 CU for
43
+ * classic SPL and 913,986 CU for Token-2022. 1.4M is the per-transaction
44
+ * maximum and leaves headroom for the surge-fee path.
45
+ */
46
+ export declare const STLD_DEPOSIT_CU_LIMIT = 1400000;
47
+ export declare function buildSingleTokenDepositIx(cfg: CofferConfig, pool: PoolInfo, params: SingleTokenDepositParams): TransactionInstruction;
48
+ /**
49
+ * The idempotent ATA creates a zap depends on: the user's and the helper's
50
+ * ATA for every pool token, plus both BPT ATAs. `2N + 2` instructions.
51
+ *
52
+ * The helper validates every user ATA up front because it may refund dust
53
+ * in any pool token, so these cannot be trimmed to just the input token.
54
+ */
55
+ export declare function buildSingleTokenDepositAtaIxs(cfg: CofferConfig, pool: PoolInfo, user: PublicKey): TransactionInstruction[];
56
+ /**
57
+ * Full single-token deposit in ONE transaction: idempotent ATA setup
58
+ * followed by the deposit itself.
59
+ *
60
+ * ⚠ **This only fits for small pools.** Two independent runtime ceilings
61
+ * bite as `N` grows, and neither is a byte-size problem an ALT can fix:
62
+ *
63
+ * - `MAX_INSTRUCTION_TRACE_LENGTH = 64` counts CPI frames across the whole
64
+ * transaction. One idempotent ATA create costs 5, and the v5.1 zap alone
65
+ * uses 52/64 at N=10. The `2N + 2` setup instructions cost `10N + 10`
66
+ * frames, so the combined transaction blows the limit well before N=10.
67
+ * - Raw size at N=10 is 1796 bytes (437 with the pool's ALT), over the
68
+ * 1232-byte legacy ceiling.
69
+ *
70
+ * For anything but a small pool use {@link buildSingleTokenDepositTxs},
71
+ * which splits setup and deposit into two transactions, and compile the
72
+ * deposit leg through the pool's ALT via `compileBuiltTx`.
73
+ */
74
+ export declare function buildSingleTokenDepositTx(cfg: CofferConfig, pool: PoolInfo, params: SingleTokenDepositParams): BuiltTx;
75
+ /**
76
+ * Single-token deposit split into the two transactions large pools need.
77
+ *
78
+ * Send `setup` first and let it confirm, then send `deposit`. They are
79
+ * separated because the ATA creates and the zap compete for the same
80
+ * 64-frame instruction-trace budget (see {@link buildSingleTokenDepositTx}).
81
+ *
82
+ * `setup` is `null` when there is nothing to create — the caller can check
83
+ * ATA existence itself and skip the leg. Otherwise it is always safe to
84
+ * send: every instruction in it is idempotent.
85
+ *
86
+ * The `deposit` leg should be compiled as a v0 transaction against the
87
+ * pool's Address Lookup Table (`compileBuiltTx(conn, user, deposit, pool)`).
88
+ * At N=10 it is 1796 bytes raw and 437 with the ALT — the ALT is mandatory,
89
+ * not an optimisation. Note that an ALT cannot be referenced in the same
90
+ * slot it was extended, so a freshly-created table needs a slot to settle.
91
+ */
92
+ export declare function buildSingleTokenDepositTxs(cfg: CofferConfig, pool: PoolInfo, params: SingleTokenDepositParams): {
93
+ setup: BuiltTx | null;
94
+ deposit: BuiltTx;
95
+ };
96
+ /**
97
+ * Raw `cubic_pool::initialize_config`.
98
+ *
99
+ * ⚠ **This instruction is no longer directly callable from a wallet.** In
100
+ * v5.1 (audit H-2) the `protocol_admin: Pubkey` ARGUMENT was removed and
101
+ * the Treasury PDA account became a `Signer`. The config's admin is now
102
+ * whoever signs, which by construction can only be protocol-admin's
103
+ * Treasury PDA via `invoke_signed` — no keypair exists for it.
104
+ *
105
+ * Sending this instruction from a wallet fails signature verification. The
106
+ * only working path is `AdminClient.poolInitializeConfigIx()`, which calls
107
+ * `protocol_admin::pool_initialize_config` and CPIs in here. This builder
108
+ * is kept so the wire format stays documented and testable, and so the
109
+ * treasury meta carries `isSigner: true` — Anchor derives CPI account
110
+ * metas from the field type, and emitting it as a non-signer would strand
111
+ * the outer `invoke_signed` signature.
112
+ */
113
+ export declare function buildInitializeConfigIx(cfg: CofferConfig, params: {
114
+ config: PublicKey;
115
+ payer: PublicKey;
116
+ defaultProtocolFeeRate: number;
117
+ }): TransactionInstruction;
118
+ /**
119
+ * `protocol_admin::pool_initialize_config` — the ONLY way to create a
120
+ * `CubicPoolConfig` that a wallet can actually sign.
121
+ *
122
+ * `cubic_pool::initialize_config` takes the Treasury PDA as a `Signer`
123
+ * (audit H-01: an unauthenticated config let anyone open a pool that charged
124
+ * a swap fee and paid the protocol nothing). A PDA cannot sign a transaction
125
+ * — only the program that owns its seeds can, via `invoke_signed`. So the
126
+ * direct instruction is unreachable from a wallet by design, and every caller
127
+ * has to come through this wrapper, where the Treasury `admin` is the human
128
+ * signer and protocol-admin performs the CPI.
129
+ *
130
+ * Signers: `admin` (must equal `Treasury.admin`) and `config` (a freshly
131
+ * generated keypair — the account is `init`, not a PDA).
132
+ */
133
+ export declare function buildPoolInitializeConfigIx(cfg: CofferConfig, params: {
134
+ config: PublicKey;
135
+ admin: PublicKey;
136
+ defaultProtocolFeeRate: number;
137
+ }): TransactionInstruction;
138
+ export declare function buildInitializeCubicPoolIx(cfg: CofferConfig, params: DeployPoolParams): TransactionInstruction;
139
+ export declare function buildDeployPoolTx(cfg: CofferConfig, params: DeployPoolParams): BuiltTx;
140
+ export interface InitializePoolAltParams {
141
+ /** Pool PDA. */
142
+ pool: PublicKey;
143
+ /** `CubicPoolConfig` account this pool is pinned to. Read by the
144
+ * program to gate the alternative-authority path (`config.protocol_admin`). */
145
+ config: PublicKey;
146
+ /** Authority. Must equal either `pool.pool_admin` (per-pool owner
147
+ * path) or `config.protocol_admin` (Treasury PDA via the
148
+ * protocol-admin CPI wrapper). The ALT address is derived from
149
+ * `[authority, recent_slot]`. */
150
+ authority: PublicKey;
151
+ /** Rent payer. Decoupled from `authority` so the wrapper path can
152
+ * pay from a regular wallet while Treasury PDA acts as authority.
153
+ * In the pool-admin path pass the same key for both. */
154
+ payer: PublicKey;
155
+ /**
156
+ * Recent slot. Used by the upstream ALT program to derive the table
157
+ * address as `[authority, recent_slot]`. Must be a slot the runtime
158
+ * still has in slot-hashes — caller should pass
159
+ * `await connection.getSlot('finalized')`.
160
+ */
161
+ recentSlot: BN;
162
+ }
163
+ /**
164
+ * Re-derives the Address Lookup Table address from `(authority, recent_slot)`
165
+ * the same way the upstream ALT program does.
166
+ *
167
+ * `@solana/web3.js` v1 doesn't expose `deriveLookupTableAddress` as a static,
168
+ * so we inline the seed derivation.
169
+ */
170
+ export declare function deriveAltAddress(authority: PublicKey, recentSlot: BN): PublicKey;
171
+ /**
172
+ * Build the on-chain `initialize_pool_alt` instruction. Performs three
173
+ * upstream CPIs inside the program: create + extend + freeze. After
174
+ * this ix lands, the ALT is immutable and the pool's `lookup_table`
175
+ * field points at it.
176
+ *
177
+ * Caller must NOT use the ALT in the same slot (warmup) — wait at
178
+ * least one slot before sending any v0 tx that references it.
179
+ */
180
+ export declare function buildInitializePoolAltIx(cfg: CofferConfig, params: InitializePoolAltParams): TransactionInstruction;
181
+ export declare function buildInitializePoolAltTx(cfg: CofferConfig, params: InitializePoolAltParams): BuiltTx & {
182
+ lookupTable: PublicKey;
183
+ };
184
+ /**
185
+ * `set_range_manager` — appoint or disable a pool's range manager.
186
+ *
187
+ * ⚠ v5.1 (audit L-1) PREPENDED a `config` account before `pool`. The
188
+ * account list is `[config, pool, authority]`. A client still sending
189
+ * `[pool, authority]` has the program read the pool account as the config
190
+ * and fail on the discriminator, or worse pass a lookalike.
191
+ *
192
+ * Pool admin can appoint or change the manager. The contract also accepts a
193
+ * config protocol-admin signer for disable-only updates that retain the current
194
+ * manager key; the deployed protocol-admin program has no CPI wrapper for it. Combine
195
+ * `newManager = PublicKey.default` with `enabled = false` for the fully
196
+ * disabled state.
197
+ */
198
+ export declare function buildSetRangeManagerIx(cfg: CofferConfig, pool: PublicKey, params: SetRangeManagerParams): TransactionInstruction;
199
+ /**
200
+ * `set_range_manager_config` — the range manager's movement envelope.
201
+ *
202
+ * v5.1 appended `max_leverage_bps` and `min_leverage_bps` to the argument
203
+ * list. Both are required; pass `0` to leave a bound disabled.
204
+ */
205
+ export declare function buildSetRangeManagerConfigIx(cfg: CofferConfig, pool: PublicKey, params: SetRangeManagerConfigParams): TransactionInstruction;
206
+ /**
207
+ * `range_manager_update` — sparse compare-and-swap over virtual balances
208
+ * and/or weights.
209
+ *
210
+ * Every {@link TokenChange} carries an `expectedCurrent` guard (v5.1, audit
211
+ * M-6). The program reverts the whole instruction with
212
+ * `RangeManagerStaleValue` (6061) if any entry no longer matches the stored
213
+ * value, so a bot MUST derive `expectedCurrent` and `newValue` from the
214
+ * same pool read and retry from a fresh read on failure — never re-send the
215
+ * same payload.
216
+ *
217
+ * The instruction also honours the pool kill switch now: it reverts while
218
+ * `pool_enabled` is false.
219
+ */
220
+ export declare function buildRangeManagerUpdateIx(cfg: CofferConfig, pool: PublicKey, params: RangeManagerUpdateParams): TransactionInstruction;
221
+ /** Set the pool-local swap fee (hundredths of a basis point). */
222
+ export declare function buildSetSwapFeeRateIx(cfg: CofferConfig, pool: PublicKey, authority: PublicKey, swapFeeRate: number): TransactionInstruction;
223
+ /** Replace every token's sell-off policy, including both kink parameters. */
224
+ export declare function buildSetMaxSelloffIx(cfg: CofferConfig, pool: PublicKey, authority: PublicKey, params: SelloffParams[]): TransactionInstruction;
225
+ export declare function buildInitiatePoolAdminTransferIx(cfg: CofferConfig, pool: PublicKey, authority: PublicKey, newAdmin: PublicKey): TransactionInstruction;
226
+ export declare function buildAcceptPoolAdminTransferIx(cfg: CofferConfig, pool: PublicKey, newAdmin: PublicKey): TransactionInstruction;
227
+ export declare function buildCancelPoolAdminTransferIx(cfg: CofferConfig, pool: PublicKey, authority: PublicKey): TransactionInstruction;
228
+ /** Permanently renounce the pool-local admin role. */
229
+ export declare function buildDisablePoolAdminIx(cfg: CofferConfig, pool: PublicKey, authority: PublicKey): TransactionInstruction;
230
+ export declare function buildGetPoolInfoIx(cfg: CofferConfig, pool: PublicKey): TransactionInstruction;
231
+ //# sourceMappingURL=tx-builders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx-builders.d.ts","sourceRoot":"","sources":["../../src/clients/tx-builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EAET,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,YAAY,EAAuB,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,OAAO,EACP,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACxB,UAAU,EACV,aAAa,EAEd,MAAM,aAAa,CAAC;AAuIrB,wBAAgB,WAAW,CACzB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,UAAU,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,GACxC,sBAAsB,CAkCxB;AAED,wBAAgB,WAAW,CACzB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,UAAU,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,GACxC,OAAO,CAQT;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,kBAAkB,GACzB,sBAAsB,CAmExB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,Q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