@amadeus-protocol/sdk 1.0.8 → 1.1.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 (199) hide show
  1. package/dist/api/chain.d.ts +144 -117
  2. package/dist/api/chain.d.ts.map +1 -1
  3. package/dist/api/chain.js +175 -146
  4. package/dist/api/chain.js.map +1 -1
  5. package/dist/api/contract.d.ts +78 -60
  6. package/dist/api/contract.d.ts.map +1 -1
  7. package/dist/api/contract.js +102 -75
  8. package/dist/api/contract.js.map +1 -1
  9. package/dist/api/epoch.d.ts +65 -66
  10. package/dist/api/epoch.d.ts.map +1 -1
  11. package/dist/api/epoch.js +90 -98
  12. package/dist/api/epoch.js.map +1 -1
  13. package/dist/api/peer.d.ts +77 -78
  14. package/dist/api/peer.d.ts.map +1 -1
  15. package/dist/api/peer.js +93 -94
  16. package/dist/api/peer.js.map +1 -1
  17. package/dist/api/proof.d.ts +44 -23
  18. package/dist/api/proof.d.ts.map +1 -1
  19. package/dist/api/proof.js +56 -29
  20. package/dist/api/proof.js.map +1 -1
  21. package/dist/api/transaction.d.ts +68 -69
  22. package/dist/api/transaction.d.ts.map +1 -1
  23. package/dist/api/transaction.js +84 -84
  24. package/dist/api/transaction.js.map +1 -1
  25. package/dist/api/wallet.d.ts +36 -37
  26. package/dist/api/wallet.d.ts.map +1 -1
  27. package/dist/api/wallet.js +47 -50
  28. package/dist/api/wallet.js.map +1 -1
  29. package/dist/client.d.ts +66 -68
  30. package/dist/client.d.ts.map +1 -1
  31. package/dist/client.js +231 -276
  32. package/dist/client.js.map +1 -1
  33. package/dist/constants.d.ts +13 -10
  34. package/dist/constants.d.ts.map +1 -1
  35. package/dist/constants.js +49 -45
  36. package/dist/constants.js.map +1 -1
  37. package/dist/contract-state.d.ts +6 -3
  38. package/dist/contract-state.d.ts.map +1 -1
  39. package/dist/contract-state.js +88 -106
  40. package/dist/contract-state.js.map +1 -1
  41. package/dist/contracts/abi-types.d.ts +32 -32
  42. package/dist/contracts/abi-types.d.ts.map +1 -1
  43. package/dist/contracts/coin.d.ts +13 -20
  44. package/dist/contracts/coin.d.ts.map +1 -1
  45. package/dist/contracts/coin.js +42 -38
  46. package/dist/contracts/coin.js.map +1 -1
  47. package/dist/contracts/contract-call.d.ts +14 -16
  48. package/dist/contracts/contract-call.d.ts.map +1 -1
  49. package/dist/contracts/contract-call.js +45 -54
  50. package/dist/contracts/contract-call.js.map +1 -1
  51. package/dist/contracts/contract.d.ts +24 -55
  52. package/dist/contracts/contract.d.ts.map +1 -1
  53. package/dist/contracts/contract.js +63 -101
  54. package/dist/contracts/contract.js.map +1 -1
  55. package/dist/contracts/lockup/abi.d.ts +54 -51
  56. package/dist/contracts/lockup/abi.d.ts.map +1 -1
  57. package/dist/contracts/lockup/abi.js +65 -74
  58. package/dist/contracts/lockup/abi.js.map +1 -1
  59. package/dist/contracts/lockup/helpers.d.ts +22 -18
  60. package/dist/contracts/lockup/helpers.d.ts.map +1 -1
  61. package/dist/contracts/lockup/helpers.js +44 -47
  62. package/dist/contracts/lockup/helpers.js.map +1 -1
  63. package/dist/contracts/lockup/parsers.d.ts +7 -3
  64. package/dist/contracts/lockup/parsers.d.ts.map +1 -1
  65. package/dist/contracts/lockup/parsers.js +51 -55
  66. package/dist/contracts/lockup/parsers.js.map +1 -1
  67. package/dist/contracts/lockup/storage-keys.d.ts +5 -2
  68. package/dist/contracts/lockup/storage-keys.d.ts.map +1 -1
  69. package/dist/contracts/lockup/storage-keys.js +54 -70
  70. package/dist/contracts/lockup/storage-keys.js.map +1 -1
  71. package/dist/contracts/lockup/types.d.ts +73 -70
  72. package/dist/contracts/lockup/types.d.ts.map +1 -1
  73. package/dist/contracts/lockup-prime/abi.d.ts +328 -325
  74. package/dist/contracts/lockup-prime/abi.d.ts.map +1 -1
  75. package/dist/contracts/lockup-prime/abi.js +397 -417
  76. package/dist/contracts/lockup-prime/abi.js.map +1 -1
  77. package/dist/contracts/lockup-prime/helpers.d.ts +35 -31
  78. package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -1
  79. package/dist/contracts/lockup-prime/helpers.js +131 -137
  80. package/dist/contracts/lockup-prime/helpers.js.map +1 -1
  81. package/dist/contracts/lockup-prime/parsers.d.ts +9 -5
  82. package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -1
  83. package/dist/contracts/lockup-prime/parsers.js +61 -61
  84. package/dist/contracts/lockup-prime/parsers.js.map +1 -1
  85. package/dist/contracts/lockup-prime/storage-keys.d.ts +7 -4
  86. package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -1
  87. package/dist/contracts/lockup-prime/storage-keys.js +64 -80
  88. package/dist/contracts/lockup-prime/storage-keys.js.map +1 -1
  89. package/dist/contracts/lockup-prime/types.d.ts +92 -89
  90. package/dist/contracts/lockup-prime/types.d.ts.map +1 -1
  91. package/dist/contracts/lockup-prime/types.js +12 -13
  92. package/dist/contracts/lockup-prime/types.js.map +1 -1
  93. package/dist/contracts/nft/abi.d.ts +104 -0
  94. package/dist/contracts/nft/abi.d.ts.map +1 -0
  95. package/dist/contracts/nft/abi.js +135 -0
  96. package/dist/contracts/nft/abi.js.map +1 -0
  97. package/dist/contracts/nft/helpers.d.ts +21 -0
  98. package/dist/contracts/nft/helpers.d.ts.map +1 -0
  99. package/dist/contracts/nft/helpers.js +61 -0
  100. package/dist/contracts/nft/helpers.js.map +1 -0
  101. package/dist/contracts/nft/types.d.ts +47 -0
  102. package/dist/contracts/nft/types.d.ts.map +1 -0
  103. package/dist/conversion.d.ts +5 -2
  104. package/dist/conversion.d.ts.map +1 -1
  105. package/dist/conversion.js +45 -50
  106. package/dist/conversion.js.map +1 -1
  107. package/dist/crypto.d.ts +14 -16
  108. package/dist/crypto.d.ts.map +1 -1
  109. package/dist/crypto.js +121 -140
  110. package/dist/crypto.js.map +1 -1
  111. package/dist/encoding.d.ts +11 -8
  112. package/dist/encoding.d.ts.map +1 -1
  113. package/dist/encoding.js +123 -144
  114. package/dist/encoding.js.map +1 -1
  115. package/dist/encryption.d.ts +15 -12
  116. package/dist/encryption.d.ts.map +1 -1
  117. package/dist/encryption.js +119 -117
  118. package/dist/encryption.js.map +1 -1
  119. package/dist/explorer.d.ts +10 -7
  120. package/dist/explorer.d.ts.map +1 -1
  121. package/dist/explorer.js +51 -48
  122. package/dist/explorer.js.map +1 -1
  123. package/dist/formatters.d.ts +8 -5
  124. package/dist/formatters.d.ts.map +1 -1
  125. package/dist/formatters.js +67 -68
  126. package/dist/formatters.js.map +1 -1
  127. package/dist/index.d.ts +42 -55
  128. package/dist/index.js +39 -55
  129. package/dist/mnemonic.d.ts +12 -9
  130. package/dist/mnemonic.d.ts.map +1 -1
  131. package/dist/mnemonic.js +105 -114
  132. package/dist/mnemonic.js.map +1 -1
  133. package/dist/networks.d.ts +14 -17
  134. package/dist/networks.d.ts.map +1 -1
  135. package/dist/networks.js +40 -36
  136. package/dist/networks.js.map +1 -1
  137. package/dist/schemas.js +75 -79
  138. package/dist/schemas.js.map +1 -1
  139. package/dist/sdk.d.ts +69 -65
  140. package/dist/sdk.d.ts.map +1 -1
  141. package/dist/sdk.js +126 -117
  142. package/dist/sdk.js.map +1 -1
  143. package/dist/serialization.d.ts +8 -18
  144. package/dist/serialization.d.ts.map +1 -1
  145. package/dist/serialization.js +207 -260
  146. package/dist/serialization.js.map +1 -1
  147. package/dist/signing.js +67 -67
  148. package/dist/signing.js.map +1 -1
  149. package/dist/transaction-builder.d.ts +175 -184
  150. package/dist/transaction-builder.d.ts.map +1 -1
  151. package/dist/transaction-builder.js +295 -344
  152. package/dist/transaction-builder.js.map +1 -1
  153. package/dist/transaction-errors.d.ts +10 -12
  154. package/dist/transaction-errors.d.ts.map +1 -1
  155. package/dist/transaction-errors.js +145 -166
  156. package/dist/transaction-errors.js.map +1 -1
  157. package/dist/types.d.ts +530 -450
  158. package/dist/types.d.ts.map +1 -1
  159. package/dist/types.js +169 -183
  160. package/dist/types.js.map +1 -1
  161. package/dist/validation.d.ts +24 -26
  162. package/dist/validation.d.ts.map +1 -1
  163. package/dist/validation.js +194 -192
  164. package/dist/validation.js.map +1 -1
  165. package/package.json +4 -3
  166. package/dist/api/index.d.ts +0 -8
  167. package/dist/api/index.d.ts.map +0 -1
  168. package/dist/api/index.js +0 -8
  169. package/dist/api/index.js.map +0 -1
  170. package/dist/contracts/abi-types.js +0 -8
  171. package/dist/contracts/abi-types.js.map +0 -1
  172. package/dist/contracts/index.d.ts +0 -7
  173. package/dist/contracts/index.d.ts.map +0 -1
  174. package/dist/contracts/index.js +0 -7
  175. package/dist/contracts/index.js.map +0 -1
  176. package/dist/contracts/lockup/calls.d.ts +0 -23
  177. package/dist/contracts/lockup/calls.d.ts.map +0 -1
  178. package/dist/contracts/lockup/calls.js +0 -25
  179. package/dist/contracts/lockup/calls.js.map +0 -1
  180. package/dist/contracts/lockup/index.d.ts +0 -6
  181. package/dist/contracts/lockup/index.d.ts.map +0 -1
  182. package/dist/contracts/lockup/index.js +0 -6
  183. package/dist/contracts/lockup/index.js.map +0 -1
  184. package/dist/contracts/lockup/types.js +0 -7
  185. package/dist/contracts/lockup/types.js.map +0 -1
  186. package/dist/contracts/lockup-prime/calls.d.ts +0 -53
  187. package/dist/contracts/lockup-prime/calls.d.ts.map +0 -1
  188. package/dist/contracts/lockup-prime/calls.js +0 -60
  189. package/dist/contracts/lockup-prime/calls.js.map +0 -1
  190. package/dist/contracts/lockup-prime/index.d.ts +0 -6
  191. package/dist/contracts/lockup-prime/index.d.ts.map +0 -1
  192. package/dist/contracts/lockup-prime/index.js +0 -6
  193. package/dist/contracts/lockup-prime/index.js.map +0 -1
  194. package/dist/index.d.ts.map +0 -1
  195. package/dist/index.js.map +0 -1
  196. package/dist/schemas.d.ts +0 -67
  197. package/dist/schemas.d.ts.map +0 -1
  198. package/dist/signing.d.ts +0 -39
  199. package/dist/signing.d.ts.map +0 -1
@@ -1,24 +1,20 @@
1
- /**
2
- * Core ContractCall Abstraction
3
- *
4
- * Provides a generic, ABI-driven way to build contract calls with both
5
- * compile-time type safety and runtime validation.
6
- */
7
- import type { SerializableValue } from '../types';
8
- import type { AbiDefinition, ExtractFunctionNames, FunctionParams } from './abi-types';
1
+ import { SerializableValue } from "../types.js";
2
+ import { AbiDefinition, ExtractFunctionNames, FunctionParams } from "./abi-types.js";
3
+
4
+ //#region src/contracts/contract-call.d.ts
9
5
  /**
10
6
  * A fully-resolved contract call ready for TransactionBuilder.
11
7
  *
12
8
  * The type parameters are optional and used only for documentation;
13
9
  * at runtime this is just `{ contract, method, args }`.
14
10
  */
15
- export interface ContractCall<_TAbi extends AbiDefinition = AbiDefinition, _TFn extends string = string> {
16
- /** Contract name (e.g. 'LockupPrime', 'Lockup', 'Coin') */
17
- readonly contract: string;
18
- /** Function/method name (e.g. 'lock', 'unlock', 'transfer') */
19
- readonly method: string;
20
- /** Serialized args array ready for VecPack encoding */
21
- readonly args: SerializableValue[];
11
+ interface ContractCall<_TAbi extends AbiDefinition = AbiDefinition, _TFn extends string = string> {
12
+ /** Contract name (e.g. 'LockupPrime', 'Lockup', 'Coin') */
13
+ readonly contract: string;
14
+ /** Function/method name (e.g. 'lock', 'unlock', 'transfer') */
15
+ readonly method: string;
16
+ /** Serialized args array ready for VecPack encoding */
17
+ readonly args: SerializableValue[];
22
18
  }
23
19
  /**
24
20
  * Build a type-safe ContractCall from an ABI definition.
@@ -45,5 +41,7 @@ export interface ContractCall<_TAbi extends AbiDefinition = AbiDefinition, _TFn
45
41
  * // call.args === ['1000000000', '30d']
46
42
  * ```
47
43
  */
48
- export declare function buildContractCall<TAbi extends AbiDefinition, TFn extends ExtractFunctionNames<TAbi>>(abi: TAbi, functionName: TFn, params: FunctionParams<TAbi, TFn & string>): ContractCall<TAbi, TFn & string>;
44
+ declare function buildContractCall<TAbi extends AbiDefinition, TFn extends ExtractFunctionNames<TAbi>>(abi: TAbi, functionName: TFn, params: FunctionParams<TAbi, TFn & string>): ContractCall<TAbi, TFn & string>;
45
+ //#endregion
46
+ export { ContractCall, buildContractCall };
49
47
  //# sourceMappingURL=contract-call.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract-call.d.ts","sourceRoot":"","sources":["../../src/contracts/contract-call.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAuB,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3G;;;;;GAKG;AACH,MAAM,WAAW,YAAY,CAC5B,KAAK,SAAS,aAAa,GAAG,aAAa,EAC3C,IAAI,SAAS,MAAM,GAAG,MAAM;IAE5B,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,iBAAiB,EAAE,CAAA;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,SAAS,aAAa,EAC1B,GAAG,SAAS,oBAAoB,CAAC,IAAI,CAAC,EAEtC,GAAG,EAAE,IAAI,EACT,YAAY,EAAE,GAAG,EACjB,MAAM,EAAE,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAAC,GACxC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAAC,CAkClC"}
1
+ {"version":3,"file":"contract-call.d.ts","names":[],"sources":["../../src/contracts/contract-call.ts"],"mappings":";;;;;;;;;;UAqBiB,YAAA,eACF,aAAA,GAAgB,aAAA;EAC9B;EAAA,SAGS,QAAA;EAEA;EAAA,SAAA,MAAA;EAEM;EAAA,SAAN,IAAA,EAAM,iBAAA;AAAA;AA4BhB;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,iBAAA,cACF,aAAA,cACD,oBAAA,CAAqB,IAAA,EAAA,CAEjC,GAAA,EAAK,IAAA,EACL,YAAA,EAAc,GAAA,EACd,MAAA,EAAQ,cAAA,CAAe,IAAA,EAAM,GAAA,aAC3B,YAAA,CAAa,IAAA,EAAM,GAAA"}
@@ -1,57 +1,48 @@
1
+ //#region src/contracts/contract-call.ts
1
2
  /**
2
- * Core ContractCall Abstraction
3
- *
4
- * Provides a generic, ABI-driven way to build contract calls with both
5
- * compile-time type safety and runtime validation.
6
- */
7
- /**
8
- * Build a type-safe ContractCall from an ABI definition.
9
- *
10
- * Compile-time:
11
- * - `functionName` is constrained to the ABI's function name union
12
- * - `params` is typed per the function's declared inputs
13
- *
14
- * Runtime:
15
- * - Validates function exists in ABI
16
- * - Validates all required params are present
17
- * - Validates enum constraints on inputs that declare them
18
- *
19
- * @example
20
- * ```ts
21
- * import { LOCKUP_PRIME_ABI } from './lockup-prime/abi'
22
- *
23
- * const call = buildContractCall(LOCKUP_PRIME_ABI, 'lock', {
24
- * amount: '1000000000',
25
- * tier: '30d'
26
- * })
27
- * // call.contract === 'LockupPrime'
28
- * // call.method === 'lock'
29
- * // call.args === ['1000000000', '30d']
30
- * ```
31
- */
32
- export function buildContractCall(abi, functionName, params) {
33
- const fn = abi.abi.find((f) => f.name === functionName);
34
- if (!fn) {
35
- throw new Error(`Function "${String(functionName)}" not found in ${abi.contractName} ABI`);
36
- }
37
- const args = [];
38
- for (const input of fn.inputs) {
39
- const value = params[input.name];
40
- if (value === undefined || value === null) {
41
- throw new Error(`Missing required parameter "${input.name}" for ${abi.contractName}.${String(functionName)}`);
42
- }
43
- if (input.enum && input.enum.length > 0) {
44
- if (!input.enum.includes(value)) {
45
- throw new Error(`Invalid value "${value}" for parameter "${input.name}". ` +
46
- `Expected one of: ${input.enum.join(', ')}`);
47
- }
48
- }
49
- args.push(value);
50
- }
51
- return {
52
- contract: abi.contractName,
53
- method: functionName,
54
- args
55
- };
3
+ * Build a type-safe ContractCall from an ABI definition.
4
+ *
5
+ * Compile-time:
6
+ * - `functionName` is constrained to the ABI's function name union
7
+ * - `params` is typed per the function's declared inputs
8
+ *
9
+ * Runtime:
10
+ * - Validates function exists in ABI
11
+ * - Validates all required params are present
12
+ * - Validates enum constraints on inputs that declare them
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { LOCKUP_PRIME_ABI } from './lockup-prime/abi'
17
+ *
18
+ * const call = buildContractCall(LOCKUP_PRIME_ABI, 'lock', {
19
+ * amount: '1000000000',
20
+ * tier: '30d'
21
+ * })
22
+ * // call.contract === 'LockupPrime'
23
+ * // call.method === 'lock'
24
+ * // call.args === ['1000000000', '30d']
25
+ * ```
26
+ */
27
+ function buildContractCall(abi, functionName, params) {
28
+ const fn = abi.abi.find((f) => f.name === functionName);
29
+ if (!fn) throw new Error(`Function "${String(functionName)}" not found in ${abi.contractName} ABI`);
30
+ const args = [];
31
+ for (const input of fn.inputs) {
32
+ const value = params[input.name];
33
+ if (value === void 0 || value === null) throw new Error(`Missing required parameter "${input.name}" for ${abi.contractName}.${String(functionName)}`);
34
+ if (input.enum && input.enum.length > 0) {
35
+ if (!input.enum.includes(value)) throw new Error(`Invalid value "${value}" for parameter "${input.name}". Expected one of: ${input.enum.join(", ")}`);
36
+ }
37
+ args.push(value);
38
+ }
39
+ return {
40
+ contract: abi.contractName,
41
+ method: functionName,
42
+ args
43
+ };
56
44
  }
45
+ //#endregion
46
+ export { buildContractCall };
47
+
57
48
  //# sourceMappingURL=contract-call.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract-call.js","sourceRoot":"","sources":["../../src/contracts/contract-call.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuBH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,iBAAiB,CAIhC,GAAS,EACT,YAAiB,EACjB,MAA0C;IAE1C,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,CAAA;IACvD,IAAI,CAAC,EAAE,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACd,aAAa,MAAM,CAAC,YAAY,CAAC,kBAAkB,GAAG,CAAC,YAAY,MAAM,CACzE,CAAA;IACF,CAAC;IAED,MAAM,IAAI,GAAwB,EAAE,CAAA;IACpC,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAI,MAAiC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC5D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CACd,+BAA+B,KAAK,CAAC,IAAI,SAAS,GAAG,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,CAC5F,CAAA;QACF,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACd,kBAAkB,KAAK,oBAAoB,KAAK,CAAC,IAAI,KAAK;oBAC1D,oBAAoB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC3C,CAAA;YACF,CAAC;QACF,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACjB,CAAC;IAED,OAAO;QACN,QAAQ,EAAE,GAAG,CAAC,YAAyC;QACvD,MAAM,EAAE,YAAsB;QAC9B,IAAI;KACJ,CAAA;AACF,CAAC"}
1
+ {"version":3,"file":"contract-call.js","names":[],"sources":["../../src/contracts/contract-call.ts"],"sourcesContent":["/**\n * Core ContractCall Abstraction\n *\n * Provides a generic, ABI-driven way to build contract calls with both\n * compile-time type safety and runtime validation.\n */\n\nimport type { SerializableValue } from '../types'\nimport type {\n\tAbiDefinition,\n\tExtractContractName,\n\tExtractFunctionNames,\n\tFunctionParams\n} from './abi-types'\n\n/**\n * A fully-resolved contract call ready for TransactionBuilder.\n *\n * The type parameters are optional and used only for documentation;\n * at runtime this is just `{ contract, method, args }`.\n */\nexport interface ContractCall<\n\t_TAbi extends AbiDefinition = AbiDefinition,\n\t_TFn extends string = string\n> {\n\t/** Contract name (e.g. 'LockupPrime', 'Lockup', 'Coin') */\n\treadonly contract: string\n\t/** Function/method name (e.g. 'lock', 'unlock', 'transfer') */\n\treadonly method: string\n\t/** Serialized args array ready for VecPack encoding */\n\treadonly args: SerializableValue[]\n}\n\n/**\n * Build a type-safe ContractCall from an ABI definition.\n *\n * Compile-time:\n * - `functionName` is constrained to the ABI's function name union\n * - `params` is typed per the function's declared inputs\n *\n * Runtime:\n * - Validates function exists in ABI\n * - Validates all required params are present\n * - Validates enum constraints on inputs that declare them\n *\n * @example\n * ```ts\n * import { LOCKUP_PRIME_ABI } from './lockup-prime/abi'\n *\n * const call = buildContractCall(LOCKUP_PRIME_ABI, 'lock', {\n * amount: '1000000000',\n * tier: '30d'\n * })\n * // call.contract === 'LockupPrime'\n * // call.method === 'lock'\n * // call.args === ['1000000000', '30d']\n * ```\n */\nexport function buildContractCall<\n\tTAbi extends AbiDefinition,\n\tTFn extends ExtractFunctionNames<TAbi>\n>(\n\tabi: TAbi,\n\tfunctionName: TFn,\n\tparams: FunctionParams<TAbi, TFn & string>\n): ContractCall<TAbi, TFn & string> {\n\tconst fn = abi.abi.find((f) => f.name === functionName)\n\tif (!fn) {\n\t\tthrow new Error(`Function \"${String(functionName)}\" not found in ${abi.contractName} ABI`)\n\t}\n\n\tconst args: SerializableValue[] = []\n\tfor (const input of fn.inputs) {\n\t\tconst value = (params as Record<string, string>)[input.name]\n\t\tif (value === undefined || value === null) {\n\t\t\tthrow new Error(\n\t\t\t\t`Missing required parameter \"${input.name}\" for ${abi.contractName}.${String(functionName)}`\n\t\t\t)\n\t\t}\n\n\t\tif (input.enum && input.enum.length > 0) {\n\t\t\tif (!input.enum.includes(value)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid value \"${value}\" for parameter \"${input.name}\". ` +\n\t\t\t\t\t\t`Expected one of: ${input.enum.join(', ')}`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\targs.push(value)\n\t}\n\n\treturn {\n\t\tcontract: abi.contractName as ExtractContractName<TAbi>,\n\t\tmethod: functionName as string,\n\t\targs\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,kBAIf,KACA,cACA,QACmC;CACnC,MAAM,KAAK,IAAI,IAAI,MAAM,MAAM,EAAE,SAAS,aAAa;CACvD,IAAI,CAAC,IACJ,MAAM,IAAI,MAAM,aAAa,OAAO,aAAa,CAAC,iBAAiB,IAAI,aAAa,MAAM;CAG3F,MAAM,OAA4B,EAAE;CACpC,KAAK,MAAM,SAAS,GAAG,QAAQ;EAC9B,MAAM,QAAS,OAAkC,MAAM;EACvD,IAAI,UAAU,KAAA,KAAa,UAAU,MACpC,MAAM,IAAI,MACT,+BAA+B,MAAM,KAAK,QAAQ,IAAI,aAAa,GAAG,OAAO,aAAa,GAC1F;EAGF,IAAI,MAAM,QAAQ,MAAM,KAAK,SAAS;OACjC,CAAC,MAAM,KAAK,SAAS,MAAM,EAC9B,MAAM,IAAI,MACT,kBAAkB,MAAM,mBAAmB,MAAM,KAAK,sBACjC,MAAM,KAAK,KAAK,KAAK,GAC1C;;EAIH,KAAK,KAAK,MAAM;;CAGjB,OAAO;EACN,UAAU,IAAI;EACd,QAAQ;EACR;EACA"}
@@ -1,51 +1,23 @@
1
- /**
2
- * ABI-Driven Contract Factory
3
- *
4
- * Generates fully-typed contract interfaces from `as const` ABI definitions,
5
- * similar to viem's getContract() or ethers typechain.
6
- *
7
- * Each function declared in the ABI becomes a typed method on the contract
8
- * object — with autocomplete for function names and typed params derived
9
- * from the ABI inputs.
10
- *
11
- * @example
12
- * ```ts
13
- * import { createContract, LOCKUP_PRIME_ABI, toAtomicAma } from '@amadeus-protocol/sdk'
14
- *
15
- * // Unsigned — returns ContractCall for TransactionBuilder.signCall()
16
- * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
17
- * const call = lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
18
- * const { txHash, txPacked } = TransactionBuilder.signCall(privateKey, call)
19
- *
20
- * // Signed — bind a private key, methods return BuildTransactionResult directly
21
- * const signed = createContract(LOCKUP_PRIME_ABI).connect(privateKey)
22
- * const result = signed.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
23
- * ```
24
- */
25
- import type { BuildTransactionResult } from '../types';
26
- import type { AbiDefinition, AbiInput } from './abi-types';
27
- import type { ContractCall } from './contract-call';
1
+ import { BuildTransactionResult } from "../types.js";
2
+ import { AbiDefinition, AbiInput } from "./abi-types.js";
3
+ import { ContractCall } from "./contract-call.js";
4
+
5
+ //#region src/contracts/contract.d.ts
28
6
  /**
29
7
  * Map an ABI inputs tuple to a params object: `{ inputName: string }`
30
8
  */
31
- type InputsToParams<Inputs extends readonly AbiInput[]> = {
32
- readonly [I in Inputs[number] as I['name']]: string;
33
- };
9
+ type InputsToParams<Inputs extends readonly AbiInput[]> = { readonly [I in Inputs[number] as I['name']]: string };
34
10
  /**
35
11
  * For each function in the ABI, generate a typed method signature.
36
12
  *
37
13
  * - Functions with inputs → `(params: { name: string, ... }) => ContractCall`
38
14
  * - Functions without inputs → `() => ContractCall`
39
15
  */
40
- type ContractMethods<TAbi extends AbiDefinition> = {
41
- readonly [F in TAbi['abi'][number] as F['name']]: F['inputs'] extends readonly [] ? () => ContractCall : (params: InputsToParams<F['inputs']>) => ContractCall;
42
- };
16
+ type ContractMethods<TAbi extends AbiDefinition> = { readonly [F in TAbi['abi'][number] as F['name']]: F['inputs'] extends readonly [] ? () => ContractCall : (params: InputsToParams<F['inputs']>) => ContractCall };
43
17
  /**
44
18
  * Same as ContractMethods but methods return signed `BuildTransactionResult`.
45
19
  */
46
- type SignedContractMethods<TAbi extends AbiDefinition> = {
47
- readonly [F in TAbi['abi'][number] as F['name']]: F['inputs'] extends readonly [] ? () => BuildTransactionResult : (params: InputsToParams<F['inputs']>) => BuildTransactionResult;
48
- };
20
+ type SignedContractMethods<TAbi extends AbiDefinition> = { readonly [F in TAbi['abi'][number] as F['name']]: F['inputs'] extends readonly [] ? () => BuildTransactionResult : (params: InputsToParams<F['inputs']>) => BuildTransactionResult };
49
21
  /**
50
22
  * A typed contract interface generated from an ABI definition.
51
23
  *
@@ -55,18 +27,16 @@ type SignedContractMethods<TAbi extends AbiDefinition> = {
55
27
  * Call `.connect(privateKey)` to get a `SignedContract` where methods
56
28
  * return `BuildTransactionResult` directly.
57
29
  */
58
- export type TypedContract<TAbi extends AbiDefinition> = ContractMethods<TAbi> & {
59
- /** The original ABI definition */
60
- readonly abi: TAbi;
61
- /** Contract name extracted from ABI */
62
- readonly contractName: TAbi['contractName'];
63
- /**
64
- * Bind a signer to produce a `SignedContract` where every method
65
- * derives keys, builds, and signs in one step.
66
- *
67
- * @param privateKey - Base58 encoded private key (seed)
68
- */
69
- connect(privateKey: string): SignedContract<TAbi>;
30
+ type TypedContract<TAbi extends AbiDefinition> = ContractMethods<TAbi> & {
31
+ /** The original ABI definition */readonly abi: TAbi; /** Contract name extracted from ABI */
32
+ readonly contractName: TAbi['contractName'];
33
+ /**
34
+ * Bind a signer to produce a `SignedContract` where every method
35
+ * derives keys, builds, and signs in one step.
36
+ *
37
+ * @param privateKey - Base58 encoded private key (seed)
38
+ */
39
+ connect(privateKey: string): SignedContract<TAbi>;
70
40
  };
71
41
  /**
72
42
  * A signer-bound contract interface.
@@ -74,11 +44,9 @@ export type TypedContract<TAbi extends AbiDefinition> = ContractMethods<TAbi> &
74
44
  * Every ABI function is a method that returns `BuildTransactionResult`
75
45
  * (txHash + txPacked ready for submission).
76
46
  */
77
- export type SignedContract<TAbi extends AbiDefinition> = SignedContractMethods<TAbi> & {
78
- /** The original ABI definition */
79
- readonly abi: TAbi;
80
- /** Contract name extracted from ABI */
81
- readonly contractName: TAbi['contractName'];
47
+ type SignedContract<TAbi extends AbiDefinition> = SignedContractMethods<TAbi> & {
48
+ /** The original ABI definition */readonly abi: TAbi; /** Contract name extracted from ABI */
49
+ readonly contractName: TAbi['contractName'];
82
50
  };
83
51
  /**
84
52
  * Create a typed contract interface from an ABI definition.
@@ -108,6 +76,7 @@ export type SignedContract<TAbi extends AbiDefinition> = SignedContractMethods<T
108
76
  * const result = signed.lock({ amount: '100000000000', tier: '30d' })
109
77
  * ```
110
78
  */
111
- export declare function createContract<TAbi extends AbiDefinition>(abi: TAbi): TypedContract<TAbi>;
112
- export {};
79
+ declare function createContract<TAbi extends AbiDefinition>(abi: TAbi): TypedContract<TAbi>;
80
+ //#endregion
81
+ export { SignedContract, TypedContract, createContract };
113
82
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/contracts/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAKnD;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,SAAS,QAAQ,EAAE,IAAI;IACzD,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM;CACnD,CAAA;AAED;;;;;GAKG;AACH,KAAK,eAAe,CAAC,IAAI,SAAS,aAAa,IAAI;IAClD,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,SAA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ts/contract.ts"],"mappings":";;;;;;;;KAoCK,cAAA,yBAAuC,QAAA,uBAC5B,MAAA,YAAkB,CAAA;;;;;;;KAS7B,eAAA,cAA6B,aAAA,qBAClB,IAAA,mBAAuB,CAAA,WAAY,CAAA,uCACzC,YAAA,IACL,MAAA,EAAQ,cAAA,CAAe,CAAA,gBAAiB,YAAA;;;;KAMxC,qBAAA,cAAmC,aAAA,qBACxB,IAAA,mBAAuB,CAAA,WAAY,CAAA,uCACzC,sBAAA,IACL,MAAA,EAAQ,cAAA,CAAe,CAAA,gBAAiB,sBAAA;;;;;;;;;;KAcjC,aAAA,cAA2B,aAAA,IAAiB,eAAA,CAAgB,IAAA;EAdL,2CAgBzD,GAAA,EAAK,IAAA,EAnByB;EAAA,SAqB9B,YAAA,EAAc,IAAA;EApBR;;;;;;EA2Bf,OAAA,CAAQ,UAAA,WAAqB,cAAA,CAAe,IAAA;AAAA;;;AAX7C;;;;KAoBY,cAAA,cAA4B,aAAA,IAAiB,qBAAA,CAAsB,IAAA;EApBvB,2CAsB9C,GAAA,EAAK,IAAA,EAlBS;EAAA,SAoBd,YAAA,EAAc,IAAA;AAAA;;;;;;;;;;;;;;;;;AAJxB;;;;;;;;;;;;iBAqCgB,cAAA,cAA4B,aAAA,CAAA,CAAe,GAAA,EAAK,IAAA,GAAO,aAAA,CAAc,IAAA"}
@@ -1,107 +1,69 @@
1
+ import { signContractCall } from "../signing.js";
2
+ import { buildContractCall } from "./contract-call.js";
3
+ //#region src/contracts/contract.ts
1
4
  /**
2
- * ABI-Driven Contract Factory
3
- *
4
- * Generates fully-typed contract interfaces from `as const` ABI definitions,
5
- * similar to viem's getContract() or ethers typechain.
6
- *
7
- * Each function declared in the ABI becomes a typed method on the contract
8
- * object with autocomplete for function names and typed params derived
9
- * from the ABI inputs.
10
- *
11
- * @example
12
- * ```ts
13
- * import { createContract, LOCKUP_PRIME_ABI, toAtomicAma } from '@amadeus-protocol/sdk'
14
- *
15
- * // Unsigned returns ContractCall for TransactionBuilder.signCall()
16
- * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
17
- * const call = lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
18
- * const { txHash, txPacked } = TransactionBuilder.signCall(privateKey, call)
19
- *
20
- * // Signed bind a private key, methods return BuildTransactionResult directly
21
- * const signed = createContract(LOCKUP_PRIME_ABI).connect(privateKey)
22
- * const result = signed.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
23
- * ```
24
- */
25
- import { signContractCall } from '../signing';
26
- import { buildContractCall } from './contract-call';
27
- // ── Factory functions ───────────────────────────────────────────────
28
- /**
29
- * Create a typed contract interface from an ABI definition.
30
- *
31
- * Returns an object where each ABI function is a method with fully typed
32
- * params (derived from ABI inputs) and autocomplete on function names.
33
- *
34
- * @param abi - An ABI definition object (must be declared `as const`)
35
- * @returns A typed `TypedContract<TAbi>` with methods for each ABI function
36
- *
37
- * @example
38
- * ```ts
39
- * import { createContract, LOCKUP_PRIME_ABI, LOCKUP_ABI, toAtomicAma } from '@amadeus-protocol/sdk'
40
- *
41
- * // Each ABI function becomes a typed method:
42
- * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
43
- * lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' }) // typed
44
- * lockupPrime.unlock({ vaultIndex: '3' }) // typed
45
- * lockupPrime.daily_checkin({ vaultIndex: '7' }) // typed
46
- *
47
- * // Sign the call:
48
- * const call = lockupPrime.lock({ amount: '100000000000', tier: '30d' })
49
- * const { txHash, txPacked } = TransactionBuilder.signCall(privateKey, call)
50
- *
51
- * // Or bind a signer:
52
- * const signed = lockupPrime.connect(privateKey)
53
- * const result = signed.lock({ amount: '100000000000', tier: '30d' })
54
- * ```
55
- */
56
- export function createContract(abi) {
57
- if (!abi || typeof abi !== 'object') {
58
- throw new Error('Invalid ABI: expected an object');
59
- }
60
- if (typeof abi.contractName !== 'string' || !abi.contractName) {
61
- throw new Error('Invalid ABI: missing or empty "contractName"');
62
- }
63
- if (!Array.isArray(abi.abi)) {
64
- throw new Error(`Invalid ABI for ${abi.contractName}: "abi" must be an array of functions`);
65
- }
66
- for (const fn of abi.abi) {
67
- if (fn.type !== 'function') {
68
- throw new Error(`Invalid ABI for ${abi.contractName}: entry "${fn.name ?? '?'}" has type "${fn.type}", expected "function"`);
69
- }
70
- if (typeof fn.name !== 'string' || !fn.name) {
71
- throw new Error(`Invalid ABI for ${abi.contractName}: function entry missing "name"`);
72
- }
73
- if (!Array.isArray(fn.inputs)) {
74
- throw new Error(`Invalid ABI for ${abi.contractName}: function "${fn.name}" missing "inputs" array`);
75
- }
76
- }
77
- const contract = {
78
- abi,
79
- contractName: abi.contractName,
80
- connect(privateKey) {
81
- return createSignedContract(abi, privateKey);
82
- }
83
- };
84
- for (const fn of abi.abi) {
85
- contract[fn.name] = (params) => {
86
- return buildContractCall(abi, fn.name, (params ?? {}));
87
- };
88
- }
89
- return contract;
5
+ * Create a typed contract interface from an ABI definition.
6
+ *
7
+ * Returns an object where each ABI function is a method with fully typed
8
+ * params (derived from ABI inputs) and autocomplete on function names.
9
+ *
10
+ * @param abi - An ABI definition object (must be declared `as const`)
11
+ * @returns A typed `TypedContract<TAbi>` with methods for each ABI function
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { createContract, LOCKUP_PRIME_ABI, LOCKUP_ABI, toAtomicAma } from '@amadeus-protocol/sdk'
16
+ *
17
+ * // Each ABI function becomes a typed method:
18
+ * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
19
+ * lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' }) // typed
20
+ * lockupPrime.unlock({ vaultIndex: '3' }) // typed
21
+ * lockupPrime.daily_checkin({ vaultIndex: '7' }) // typed
22
+ *
23
+ * // Sign the call:
24
+ * const call = lockupPrime.lock({ amount: '100000000000', tier: '30d' })
25
+ * const { txHash, txPacked } = TransactionBuilder.signCall(privateKey, call)
26
+ *
27
+ * // Or bind a signer:
28
+ * const signed = lockupPrime.connect(privateKey)
29
+ * const result = signed.lock({ amount: '100000000000', tier: '30d' })
30
+ * ```
31
+ */
32
+ function createContract(abi) {
33
+ if (!abi || typeof abi !== "object") throw new Error("Invalid ABI: expected an object");
34
+ if (typeof abi.contractName !== "string" || !abi.contractName) throw new Error("Invalid ABI: missing or empty \"contractName\"");
35
+ if (!Array.isArray(abi.abi)) throw new Error(`Invalid ABI for ${abi.contractName}: "abi" must be an array of functions`);
36
+ for (const fn of abi.abi) {
37
+ if (fn.type !== "function") throw new Error(`Invalid ABI for ${abi.contractName}: entry "${fn.name ?? "?"}" has type "${fn.type}", expected "function"`);
38
+ if (typeof fn.name !== "string" || !fn.name) throw new Error(`Invalid ABI for ${abi.contractName}: function entry missing "name"`);
39
+ if (!Array.isArray(fn.inputs)) throw new Error(`Invalid ABI for ${abi.contractName}: function "${fn.name}" missing "inputs" array`);
40
+ }
41
+ const contract = {
42
+ abi,
43
+ contractName: abi.contractName,
44
+ connect(privateKey) {
45
+ return createSignedContract(abi, privateKey);
46
+ }
47
+ };
48
+ for (const fn of abi.abi) contract[fn.name] = (params) => {
49
+ return buildContractCall(abi, fn.name, params ?? {});
50
+ };
51
+ return contract;
90
52
  }
91
53
  /**
92
- * Create a signer-bound contract where each method builds + signs in one step.
93
- */
54
+ * Create a signer-bound contract where each method builds + signs in one step.
55
+ */
94
56
  function createSignedContract(abi, privateKey) {
95
- const contract = {
96
- abi,
97
- contractName: abi.contractName
98
- };
99
- for (const fn of abi.abi) {
100
- contract[fn.name] = (params) => {
101
- const call = buildContractCall(abi, fn.name, (params ?? {}));
102
- return signContractCall(privateKey, call);
103
- };
104
- }
105
- return contract;
57
+ const contract = {
58
+ abi,
59
+ contractName: abi.contractName
60
+ };
61
+ for (const fn of abi.abi) contract[fn.name] = (params) => {
62
+ return signContractCall(privateKey, buildContractCall(abi, fn.name, params ?? {}));
63
+ };
64
+ return contract;
106
65
  }
66
+ //#endregion
67
+ export { createContract };
68
+
107
69
  //# sourceMappingURL=contract.js.map
@@ -1 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"],"sourcesContent":["/**\n * ABI-Driven Contract Factory\n *\n * Generates fully-typed contract interfaces from `as const` ABI definitions,\n * similar to viem's getContract() or ethers typechain.\n *\n * Each function declared in the ABI becomes a typed method on the contract\n * object — with autocomplete for function names and typed params derived\n * from the ABI inputs.\n *\n * @example\n * ```ts\n * import { createContract, LOCKUP_PRIME_ABI, toAtomicAma } from '@amadeus-protocol/sdk'\n *\n * // Unsigned — returns ContractCall for TransactionBuilder.signCall()\n * const lockupPrime = createContract(LOCKUP_PRIME_ABI)\n * const call = lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })\n * const { txHash, txPacked } = TransactionBuilder.signCall(privateKey, call)\n *\n * // Signed — bind a private key, methods return BuildTransactionResult directly\n * const signed = createContract(LOCKUP_PRIME_ABI).connect(privateKey)\n * const result = signed.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })\n * ```\n */\n\nimport type { BuildTransactionResult } from '../types'\nimport { signContractCall } from '../signing'\nimport type { AbiDefinition, AbiInput } from './abi-types'\nimport type { ContractCall } from './contract-call'\nimport { buildContractCall } from './contract-call'\n\n// ── Type-level ABI → Method mapping ─────────────────────────────────\n\n/**\n * Map an ABI inputs tuple to a params object: `{ inputName: string }`\n */\ntype InputsToParams<Inputs extends readonly AbiInput[]> = {\n\treadonly [I in Inputs[number] as I['name']]: string\n}\n\n/**\n * For each function in the ABI, generate a typed method signature.\n *\n * - Functions with inputs → `(params: { name: string, ... }) => ContractCall`\n * - Functions without inputs → `() => ContractCall`\n */\ntype ContractMethods<TAbi extends AbiDefinition> = {\n\treadonly [F in TAbi['abi'][number] as F['name']]: F['inputs'] extends readonly []\n\t\t? () => ContractCall\n\t\t: (params: InputsToParams<F['inputs']>) => ContractCall\n}\n\n/**\n * Same as ContractMethods but methods return signed `BuildTransactionResult`.\n */\ntype SignedContractMethods<TAbi extends AbiDefinition> = {\n\treadonly [F in TAbi['abi'][number] as F['name']]: F['inputs'] extends readonly []\n\t\t? () => BuildTransactionResult\n\t\t: (params: InputsToParams<F['inputs']>) => BuildTransactionResult\n}\n\n// ── Public types ────────────────────────────────────────────────────\n\n/**\n * A typed contract interface generated from an ABI definition.\n *\n * Each ABI function is exposed as a method that returns a `ContractCall`\n * (ready for `TransactionBuilder.signCall()`).\n *\n * Call `.connect(privateKey)` to get a `SignedContract` where methods\n * return `BuildTransactionResult` directly.\n */\nexport type TypedContract<TAbi extends AbiDefinition> = ContractMethods<TAbi> & {\n\t/** The original ABI definition */\n\treadonly abi: TAbi\n\t/** Contract name extracted from ABI */\n\treadonly contractName: TAbi['contractName']\n\t/**\n\t * Bind a signer to produce a `SignedContract` where every method\n\t * derives keys, builds, and signs in one step.\n\t *\n\t * @param privateKey - Base58 encoded private key (seed)\n\t */\n\tconnect(privateKey: string): SignedContract<TAbi>\n}\n\n/**\n * A signer-bound contract interface.\n *\n * Every ABI function is a method that returns `BuildTransactionResult`\n * (txHash + txPacked ready for submission).\n */\nexport type SignedContract<TAbi extends AbiDefinition> = SignedContractMethods<TAbi> & {\n\t/** The original ABI definition */\n\treadonly abi: TAbi\n\t/** Contract name extracted from ABI */\n\treadonly contractName: TAbi['contractName']\n}\n\n// ── Factory functions ───────────────────────────────────────────────\n\n/**\n * Create a typed contract interface from an ABI definition.\n *\n * Returns an object where each ABI function is a method with fully typed\n * params (derived from ABI inputs) and autocomplete on function names.\n *\n * @param abi - An ABI definition object (must be declared `as const`)\n * @returns A typed `TypedContract<TAbi>` with methods for each ABI function\n *\n * @example\n * ```ts\n * import { createContract, LOCKUP_PRIME_ABI, LOCKUP_ABI, toAtomicAma } from '@amadeus-protocol/sdk'\n *\n * // Each ABI function becomes a typed method:\n * const lockupPrime = createContract(LOCKUP_PRIME_ABI)\n * lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' }) // typed\n * lockupPrime.unlock({ vaultIndex: '3' }) // typed\n * lockupPrime.daily_checkin({ vaultIndex: '7' }) // typed\n *\n * // Sign the call:\n * const call = lockupPrime.lock({ amount: '100000000000', tier: '30d' })\n * const { txHash, txPacked } = TransactionBuilder.signCall(privateKey, call)\n *\n * // Or bind a signer:\n * const signed = lockupPrime.connect(privateKey)\n * const result = signed.lock({ amount: '100000000000', tier: '30d' })\n * ```\n */\nexport function createContract<TAbi extends AbiDefinition>(abi: TAbi): TypedContract<TAbi> {\n\tif (!abi || typeof abi !== 'object') {\n\t\tthrow new Error('Invalid ABI: expected an object')\n\t}\n\tif (typeof abi.contractName !== 'string' || !abi.contractName) {\n\t\tthrow new Error('Invalid ABI: missing or empty \"contractName\"')\n\t}\n\tif (!Array.isArray(abi.abi)) {\n\t\tthrow new Error(`Invalid ABI for ${abi.contractName}: \"abi\" must be an array of functions`)\n\t}\n\tfor (const fn of abi.abi) {\n\t\tif (fn.type !== 'function') {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid ABI for ${abi.contractName}: entry \"${fn.name ?? '?'}\" has type \"${fn.type}\", expected \"function\"`\n\t\t\t)\n\t\t}\n\t\tif (typeof fn.name !== 'string' || !fn.name) {\n\t\t\tthrow new Error(`Invalid ABI for ${abi.contractName}: function entry missing \"name\"`)\n\t\t}\n\t\tif (!Array.isArray(fn.inputs)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid ABI for ${abi.contractName}: function \"${fn.name}\" missing \"inputs\" array`\n\t\t\t)\n\t\t}\n\t}\n\n\tconst contract: Record<string, unknown> = {\n\t\tabi,\n\t\tcontractName: abi.contractName,\n\t\tconnect(privateKey: string) {\n\t\t\treturn createSignedContract(abi, privateKey)\n\t\t}\n\t}\n\n\tfor (const fn of abi.abi) {\n\t\tcontract[fn.name] = (params?: Record<string, string>) => {\n\t\t\treturn buildContractCall(abi, fn.name as never, (params ?? {}) as never)\n\t\t}\n\t}\n\n\treturn contract as TypedContract<TAbi>\n}\n\n/**\n * Create a signer-bound contract where each method builds + signs in one step.\n */\nfunction createSignedContract<TAbi extends AbiDefinition>(\n\tabi: TAbi,\n\tprivateKey: string\n): SignedContract<TAbi> {\n\tconst contract: Record<string, unknown> = {\n\t\tabi,\n\t\tcontractName: abi.contractName\n\t}\n\n\tfor (const fn of abi.abi) {\n\t\tcontract[fn.name] = (params?: Record<string, string>) => {\n\t\t\tconst call = buildContractCall(abi, fn.name as never, (params ?? {}) as never)\n\t\t\treturn signContractCall(privateKey, call)\n\t\t}\n\t}\n\n\treturn contract as SignedContract<TAbi>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiIA,SAAgB,eAA2C,KAAgC;CAC1F,IAAI,CAAC,OAAO,OAAO,QAAQ,UAC1B,MAAM,IAAI,MAAM,kCAAkC;CAEnD,IAAI,OAAO,IAAI,iBAAiB,YAAY,CAAC,IAAI,cAChD,MAAM,IAAI,MAAM,iDAA+C;CAEhE,IAAI,CAAC,MAAM,QAAQ,IAAI,IAAI,EAC1B,MAAM,IAAI,MAAM,mBAAmB,IAAI,aAAa,uCAAuC;CAE5F,KAAK,MAAM,MAAM,IAAI,KAAK;EACzB,IAAI,GAAG,SAAS,YACf,MAAM,IAAI,MACT,mBAAmB,IAAI,aAAa,WAAW,GAAG,QAAQ,IAAI,cAAc,GAAG,KAAK,wBACpF;EAEF,IAAI,OAAO,GAAG,SAAS,YAAY,CAAC,GAAG,MACtC,MAAM,IAAI,MAAM,mBAAmB,IAAI,aAAa,iCAAiC;EAEtF,IAAI,CAAC,MAAM,QAAQ,GAAG,OAAO,EAC5B,MAAM,IAAI,MACT,mBAAmB,IAAI,aAAa,cAAc,GAAG,KAAK,0BAC1D;;CAIH,MAAM,WAAoC;EACzC;EACA,cAAc,IAAI;EAClB,QAAQ,YAAoB;GAC3B,OAAO,qBAAqB,KAAK,WAAW;;EAE7C;CAED,KAAK,MAAM,MAAM,IAAI,KACpB,SAAS,GAAG,SAAS,WAAoC;EACxD,OAAO,kBAAkB,KAAK,GAAG,MAAgB,UAAU,EAAE,CAAW;;CAI1E,OAAO;;;;;AAMR,SAAS,qBACR,KACA,YACuB;CACvB,MAAM,WAAoC;EACzC;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