@haneullabs/haneulns 0.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 (70) hide show
  1. package/CHANGELOG.md +505 -0
  2. package/README.md +9 -0
  3. package/dist/cjs/constants.d.ts +11 -0
  4. package/dist/cjs/constants.js +120 -0
  5. package/dist/cjs/constants.js.map +7 -0
  6. package/dist/cjs/haneulns-client.d.ts +40 -0
  7. package/dist/cjs/haneulns-client.js +261 -0
  8. package/dist/cjs/haneulns-client.js.map +7 -0
  9. package/dist/cjs/haneulns-transaction.d.ts +105 -0
  10. package/dist/cjs/haneulns-transaction.js +465 -0
  11. package/dist/cjs/haneulns-transaction.js.map +7 -0
  12. package/dist/cjs/helpers.d.ts +18 -0
  13. package/dist/cjs/helpers.js +63 -0
  14. package/dist/cjs/helpers.js.map +7 -0
  15. package/dist/cjs/index.d.ts +5 -0
  16. package/dist/cjs/index.js +39 -0
  17. package/dist/cjs/index.js.map +7 -0
  18. package/dist/cjs/package.json +5 -0
  19. package/dist/cjs/pyth/PriceServiceConnection.d.ts +26 -0
  20. package/dist/cjs/pyth/PriceServiceConnection.js +68 -0
  21. package/dist/cjs/pyth/PriceServiceConnection.js.map +7 -0
  22. package/dist/cjs/pyth/pyth-helpers.d.ts +7 -0
  23. package/dist/cjs/pyth/pyth-helpers.js +36 -0
  24. package/dist/cjs/pyth/pyth-helpers.js.map +7 -0
  25. package/dist/cjs/pyth/pyth.d.ts +66 -0
  26. package/dist/cjs/pyth/pyth.js +270 -0
  27. package/dist/cjs/pyth/pyth.js.map +7 -0
  28. package/dist/cjs/types.d.ts +89 -0
  29. package/dist/cjs/types.js +17 -0
  30. package/dist/cjs/types.js.map +7 -0
  31. package/dist/esm/constants.d.ts +11 -0
  32. package/dist/esm/constants.js +100 -0
  33. package/dist/esm/constants.js.map +7 -0
  34. package/dist/esm/haneulns-client.d.ts +40 -0
  35. package/dist/esm/haneulns-client.js +249 -0
  36. package/dist/esm/haneulns-client.js.map +7 -0
  37. package/dist/esm/haneulns-transaction.d.ts +105 -0
  38. package/dist/esm/haneulns-transaction.js +445 -0
  39. package/dist/esm/haneulns-transaction.js.map +7 -0
  40. package/dist/esm/helpers.d.ts +18 -0
  41. package/dist/esm/helpers.js +43 -0
  42. package/dist/esm/helpers.js.map +7 -0
  43. package/dist/esm/index.d.ts +5 -0
  44. package/dist/esm/index.js +28 -0
  45. package/dist/esm/index.js.map +7 -0
  46. package/dist/esm/package.json +5 -0
  47. package/dist/esm/pyth/PriceServiceConnection.d.ts +26 -0
  48. package/dist/esm/pyth/PriceServiceConnection.js +38 -0
  49. package/dist/esm/pyth/PriceServiceConnection.js.map +7 -0
  50. package/dist/esm/pyth/pyth-helpers.d.ts +7 -0
  51. package/dist/esm/pyth/pyth-helpers.js +16 -0
  52. package/dist/esm/pyth/pyth-helpers.js.map +7 -0
  53. package/dist/esm/pyth/pyth.d.ts +66 -0
  54. package/dist/esm/pyth/pyth.js +250 -0
  55. package/dist/esm/pyth/pyth.js.map +7 -0
  56. package/dist/esm/types.d.ts +89 -0
  57. package/dist/esm/types.js +1 -0
  58. package/dist/esm/types.js.map +7 -0
  59. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  60. package/dist/tsconfig.tsbuildinfo +1 -0
  61. package/package.json +63 -0
  62. package/src/constants.ts +106 -0
  63. package/src/haneulns-client.ts +368 -0
  64. package/src/haneulns-transaction.ts +555 -0
  65. package/src/helpers.ts +52 -0
  66. package/src/index.ts +16 -0
  67. package/src/pyth/PriceServiceConnection.ts +48 -0
  68. package/src/pyth/pyth-helpers.ts +23 -0
  69. package/src/pyth/pyth.ts +312 -0
  70. package/src/types.ts +111 -0
@@ -0,0 +1,43 @@
1
+ import { normalizeHaneulNSName } from "@haneullabs/haneul/utils";
2
+ function isSubName(name) {
3
+ return normalizeHaneulNSName(name, "dot").split(".").length > 2;
4
+ }
5
+ function isNestedSubName(name) {
6
+ return normalizeHaneulNSName(name, "dot").split(".").length > 3;
7
+ }
8
+ function validateYears(years) {
9
+ if (!(years > 0 && years < 6)) throw new Error("Years must be between 1 and 5");
10
+ }
11
+ function zeroCoin(tx, type) {
12
+ return tx.moveCall({
13
+ target: "0x2::coin::zero",
14
+ typeArguments: [type]
15
+ });
16
+ }
17
+ function getConfigType(haneulnsPackageV1, innerType) {
18
+ return `${haneulnsPackageV1}::haneulns::ConfigKey<${innerType}>`;
19
+ }
20
+ function getDomainType(haneulnsPackageV1) {
21
+ return `${haneulnsPackageV1}::domain::Domain`;
22
+ }
23
+ function getPricelistConfigType(haneulnsPackageId) {
24
+ return `${haneulnsPackageId}::pricing_config::PricingConfig`;
25
+ }
26
+ function getRenewalPricelistConfigType(haneulnsPackageId) {
27
+ return `${haneulnsPackageId}::pricing_config::RenewalConfig`;
28
+ }
29
+ function getCoinDiscountConfigType(paymentPackageId) {
30
+ return `${paymentPackageId}::payments::PaymentsConfig`;
31
+ }
32
+ export {
33
+ getCoinDiscountConfigType,
34
+ getConfigType,
35
+ getDomainType,
36
+ getPricelistConfigType,
37
+ getRenewalPricelistConfigType,
38
+ isNestedSubName,
39
+ isSubName,
40
+ validateYears,
41
+ zeroCoin
42
+ };
43
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport { normalizeHaneulNSName } from '@haneullabs/haneul/utils';\n\nexport function isSubName(name: string): boolean {\n\treturn normalizeHaneulNSName(name, 'dot').split('.').length > 2;\n}\n\n/**\n * Checks if a name is a nested subname.\n * A nested subdomain is a subdomain that is a subdomain of another subdomain.\n * @param name The name to check (e.g test.example.sub.haneul)\n */\nexport function isNestedSubName(name: string): boolean {\n\treturn normalizeHaneulNSName(name, 'dot').split('.').length > 3;\n}\n\n/**\n * The years must be between 1 and 5.\n */\nexport function validateYears(years: number) {\n\tif (!(years > 0 && years < 6)) throw new Error('Years must be between 1 and 5');\n}\n\nexport function zeroCoin(tx: Transaction, type: string) {\n\treturn tx.moveCall({\n\t\ttarget: '0x2::coin::zero',\n\t\ttypeArguments: [type],\n\t});\n}\n\nexport function getConfigType(haneulnsPackageV1: string, innerType: string): string {\n\treturn `${haneulnsPackageV1}::haneulns::ConfigKey<${innerType}>`;\n}\n\nexport function getDomainType(haneulnsPackageV1: string): string {\n\treturn `${haneulnsPackageV1}::domain::Domain`;\n}\n\nexport function getPricelistConfigType(haneulnsPackageId: string): string {\n\treturn `${haneulnsPackageId}::pricing_config::PricingConfig`;\n}\n\nexport function getRenewalPricelistConfigType(haneulnsPackageId: string): string {\n\treturn `${haneulnsPackageId}::pricing_config::RenewalConfig`;\n}\n\nexport function getCoinDiscountConfigType(paymentPackageId: string): string {\n\treturn `${paymentPackageId}::payments::PaymentsConfig`;\n}\n"],
5
+ "mappings": "AAIA,SAAS,6BAA6B;AAE/B,SAAS,UAAU,MAAuB;AAChD,SAAO,sBAAsB,MAAM,KAAK,EAAE,MAAM,GAAG,EAAE,SAAS;AAC/D;AAOO,SAAS,gBAAgB,MAAuB;AACtD,SAAO,sBAAsB,MAAM,KAAK,EAAE,MAAM,GAAG,EAAE,SAAS;AAC/D;AAKO,SAAS,cAAc,OAAe;AAC5C,MAAI,EAAE,QAAQ,KAAK,QAAQ,GAAI,OAAM,IAAI,MAAM,+BAA+B;AAC/E;AAEO,SAAS,SAAS,IAAiB,MAAc;AACvD,SAAO,GAAG,SAAS;AAAA,IAClB,QAAQ;AAAA,IACR,eAAe,CAAC,IAAI;AAAA,EACrB,CAAC;AACF;AAEO,SAAS,cAAc,mBAA2B,WAA2B;AACnF,SAAO,GAAG,iBAAiB,yBAAyB,SAAS;AAC9D;AAEO,SAAS,cAAc,mBAAmC;AAChE,SAAO,GAAG,iBAAiB;AAC5B;AAEO,SAAS,uBAAuB,mBAAmC;AACzE,SAAO,GAAG,iBAAiB;AAC5B;AAEO,SAAS,8BAA8B,mBAAmC;AAChF,SAAO,GAAG,iBAAiB;AAC5B;AAEO,SAAS,0BAA0B,kBAAkC;AAC3E,SAAO,GAAG,gBAAgB;AAC3B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ export { HaneulnsClient } from './haneulns-client.js';
2
+ export { HaneulnsTransaction } from './haneulns-transaction.js';
3
+ export type { Network, HaneulnsClientConfig, Config } from './types.js';
4
+ export { ALLOWED_METADATA, mainPackage } from './constants.js';
5
+ export { isSubName, isNestedSubName, validateYears, getConfigType, getDomainType, getPricelistConfigType, getRenewalPricelistConfigType, getCoinDiscountConfigType, } from './helpers.js';
@@ -0,0 +1,28 @@
1
+ import { HaneulnsClient } from "./haneulns-client.js";
2
+ import { HaneulnsTransaction } from "./haneulns-transaction.js";
3
+ import { ALLOWED_METADATA, mainPackage } from "./constants.js";
4
+ import {
5
+ isSubName,
6
+ isNestedSubName,
7
+ validateYears,
8
+ getConfigType,
9
+ getDomainType,
10
+ getPricelistConfigType,
11
+ getRenewalPricelistConfigType,
12
+ getCoinDiscountConfigType
13
+ } from "./helpers.js";
14
+ export {
15
+ ALLOWED_METADATA,
16
+ HaneulnsClient,
17
+ HaneulnsTransaction,
18
+ getCoinDiscountConfigType,
19
+ getConfigType,
20
+ getDomainType,
21
+ getPricelistConfigType,
22
+ getRenewalPricelistConfigType,
23
+ isNestedSubName,
24
+ isSubName,
25
+ mainPackage,
26
+ validateYears
27
+ };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nexport { HaneulnsClient } from './haneulns-client.js';\nexport { HaneulnsTransaction } from './haneulns-transaction.js';\nexport type { Network, HaneulnsClientConfig, Config } from './types.js';\nexport { ALLOWED_METADATA, mainPackage } from './constants.js';\nexport {\n\tisSubName,\n\tisNestedSubName,\n\tvalidateYears,\n\tgetConfigType,\n\tgetDomainType,\n\tgetPricelistConfigType,\n\tgetRenewalPricelistConfigType,\n\tgetCoinDiscountConfigType,\n} from './helpers.js';\n"],
5
+ "mappings": "AAEA,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AAEpC,SAAS,kBAAkB,mBAAmB;AAC9C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "private": true,
3
+ "type": "module",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1,26 @@
1
+ export type HexString = string;
2
+ export type PriceFeedRequestConfig = {
3
+ verbose?: boolean;
4
+ binary?: boolean;
5
+ };
6
+ export type PriceServiceConnectionConfig = {
7
+ timeout?: number;
8
+ httpRetries?: number;
9
+ };
10
+ export declare class PriceServiceConnection {
11
+ private httpClient;
12
+ /**
13
+ * Constructs a new Connection.
14
+ *
15
+ * @param endpoint endpoint URL to the price service.
16
+ * @param config Optional configuration for custom setups.
17
+ */
18
+ constructor(endpoint: string, config?: PriceServiceConnectionConfig);
19
+ /**
20
+ * Fetch latest VAAs of given price IDs.
21
+ *
22
+ * @param priceIds Array of hex-encoded price IDs.
23
+ * @returns Array of base64 encoded VAAs.
24
+ */
25
+ getLatestVaas(priceIds: HexString[]): Promise<string[]>;
26
+ }
@@ -0,0 +1,38 @@
1
+ import axios from "axios";
2
+ import axiosRetry from "axios-retry";
3
+ class PriceServiceConnection {
4
+ /**
5
+ * Constructs a new Connection.
6
+ *
7
+ * @param endpoint endpoint URL to the price service.
8
+ * @param config Optional configuration for custom setups.
9
+ */
10
+ constructor(endpoint, config) {
11
+ this.httpClient = axios.create({
12
+ baseURL: endpoint,
13
+ timeout: config?.timeout || 5e3
14
+ });
15
+ axiosRetry(this.httpClient, {
16
+ retries: config?.httpRetries || 3,
17
+ retryDelay: axiosRetry.exponentialDelay
18
+ });
19
+ }
20
+ /**
21
+ * Fetch latest VAAs of given price IDs.
22
+ *
23
+ * @param priceIds Array of hex-encoded price IDs.
24
+ * @returns Array of base64 encoded VAAs.
25
+ */
26
+ async getLatestVaas(priceIds) {
27
+ const response = await this.httpClient.get("/api/latest_vaas", {
28
+ params: {
29
+ ids: priceIds
30
+ }
31
+ });
32
+ return response.data;
33
+ }
34
+ }
35
+ export {
36
+ PriceServiceConnection
37
+ };
38
+ //# sourceMappingURL=PriceServiceConnection.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/pyth/PriceServiceConnection.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport axios from 'axios';\nimport type { AxiosInstance } from 'axios';\nimport axiosRetry from 'axios-retry';\n\nexport type HexString = string;\nexport type PriceFeedRequestConfig = {\n\tverbose?: boolean;\n\tbinary?: boolean;\n};\nexport type PriceServiceConnectionConfig = {\n\ttimeout?: number;\n\thttpRetries?: number;\n};\nexport class PriceServiceConnection {\n\tprivate httpClient: AxiosInstance;\n\t/**\n\t * Constructs a new Connection.\n\t *\n\t * @param endpoint endpoint URL to the price service.\n\t * @param config Optional configuration for custom setups.\n\t */\n\tconstructor(endpoint: string, config?: PriceServiceConnectionConfig) {\n\t\tthis.httpClient = axios.create({\n\t\t\tbaseURL: endpoint,\n\t\t\ttimeout: config?.timeout || 5000,\n\t\t});\n\t\taxiosRetry(this.httpClient, {\n\t\t\tretries: config?.httpRetries || 3,\n\t\t\tretryDelay: axiosRetry.exponentialDelay,\n\t\t});\n\t}\n\t/**\n\t * Fetch latest VAAs of given price IDs.\n\t *\n\t * @param priceIds Array of hex-encoded price IDs.\n\t * @returns Array of base64 encoded VAAs.\n\t */\n\tasync getLatestVaas(priceIds: HexString[]): Promise<string[]> {\n\t\tconst response = await this.httpClient.get('/api/latest_vaas', {\n\t\t\tparams: {\n\t\t\t\tids: priceIds,\n\t\t\t},\n\t\t});\n\t\treturn response.data;\n\t}\n}\n"],
5
+ "mappings": "AAEA,OAAO,WAAW;AAElB,OAAO,gBAAgB;AAWhB,MAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnC,YAAY,UAAkB,QAAuC;AACpE,SAAK,aAAa,MAAM,OAAO;AAAA,MAC9B,SAAS;AAAA,MACT,SAAS,QAAQ,WAAW;AAAA,IAC7B,CAAC;AACD,eAAW,KAAK,YAAY;AAAA,MAC3B,SAAS,QAAQ,eAAe;AAAA,MAChC,YAAY,WAAW;AAAA,IACxB,CAAC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAc,UAA0C;AAC7D,UAAM,WAAW,MAAM,KAAK,WAAW,IAAI,oBAAoB;AAAA,MAC9D,QAAQ;AAAA,QACP,KAAK;AAAA,MACN;AAAA,IACD,CAAC;AACD,WAAO,SAAS;AAAA,EACjB;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Extracts the VAA bytes embedded in an accumulator message.
3
+ *
4
+ * @param accumulatorMessage The accumulator price update message as a Uint8Array.
5
+ * @returns VAA bytes as a Uint8Array.
6
+ */
7
+ export declare function extractVaaBytesFromAccumulatorMessage(accumulatorMessage: Uint8Array): Uint8Array;
@@ -0,0 +1,16 @@
1
+ function extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
2
+ const dataView = new DataView(
3
+ accumulatorMessage.buffer,
4
+ accumulatorMessage.byteOffset,
5
+ accumulatorMessage.byteLength
6
+ );
7
+ const trailingPayloadSize = dataView.getUint8(6);
8
+ const vaaSizeOffset = 7 + trailingPayloadSize + 1;
9
+ const vaaSize = dataView.getUint16(vaaSizeOffset, false);
10
+ const vaaOffset = vaaSizeOffset + 2;
11
+ return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
12
+ }
13
+ export {
14
+ extractVaaBytesFromAccumulatorMessage
15
+ };
16
+ //# sourceMappingURL=pyth-helpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/pyth/pyth-helpers.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Extracts the VAA bytes embedded in an accumulator message.\n *\n * @param accumulatorMessage The accumulator price update message as a Uint8Array.\n * @returns VAA bytes as a Uint8Array.\n */\nexport function extractVaaBytesFromAccumulatorMessage(accumulatorMessage: Uint8Array): Uint8Array {\n\tconst dataView = new DataView(\n\t\taccumulatorMessage.buffer,\n\t\taccumulatorMessage.byteOffset,\n\t\taccumulatorMessage.byteLength,\n\t);\n\n\tconst trailingPayloadSize = dataView.getUint8(6);\n\tconst vaaSizeOffset = 7 + trailingPayloadSize + 1; // Header (7 bytes), trailing payload size, proof type\n\tconst vaaSize = dataView.getUint16(vaaSizeOffset, false); // Read 2 bytes for VAA size (big-endian)\n\tconst vaaOffset = vaaSizeOffset + 2; // VAA size is 2 bytes\n\n\treturn accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);\n}\n"],
5
+ "mappings": "AASO,SAAS,sCAAsC,oBAA4C;AACjG,QAAM,WAAW,IAAI;AAAA,IACpB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,EACpB;AAEA,QAAM,sBAAsB,SAAS,SAAS,CAAC;AAC/C,QAAM,gBAAgB,IAAI,sBAAsB;AAChD,QAAM,UAAU,SAAS,UAAU,eAAe,KAAK;AACvD,QAAM,YAAY,gBAAgB;AAElC,SAAO,mBAAmB,SAAS,WAAW,YAAY,OAAO;AAClE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,66 @@
1
+ import type { HaneulClient } from '@haneullabs/haneul/client';
2
+ import type { Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';
3
+ import type { HexString } from './PriceServiceConnection.js';
4
+ import { PriceServiceConnection } from './PriceServiceConnection.js';
5
+ export type ObjectId = string;
6
+ export declare class HaneulPriceServiceConnection extends PriceServiceConnection {
7
+ /**
8
+ * Fetch price feed update data.
9
+ *
10
+ * @param priceIds Array of hex-encoded price IDs.
11
+ * @returns Array of buffers containing the price update data.
12
+ */
13
+ getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Uint8Array[]>;
14
+ }
15
+ export declare class HaneulPythClient {
16
+ #private;
17
+ provider: HaneulClient;
18
+ pythStateId: ObjectId;
19
+ wormholeStateId: ObjectId;
20
+ constructor(provider: HaneulClient, pythStateId: ObjectId, wormholeStateId: ObjectId);
21
+ /**
22
+ * Verifies the VAAs using the Wormhole contract.
23
+ *
24
+ * @param vaas Array of VAA buffers to verify.
25
+ * @param tx Transaction block to add commands to.
26
+ * @returns Array of verified VAAs.
27
+ */
28
+ verifyVaas(vaas: Uint8Array[], tx: Transaction): Promise<{
29
+ $kind: "NestedResult";
30
+ NestedResult: [number, number];
31
+ }[]>;
32
+ /**
33
+ * Adds the necessary commands for updating the Pyth price feeds to the transaction block.
34
+ *
35
+ * @param tx Transaction block to add commands to.
36
+ * @param updates Array of price feed updates received from the price service.
37
+ * @param feedIds Array of feed IDs to update (in hex format).
38
+ * @param feeCoin Optional custom SUI coin to use for Pyth oracle fees. If not provided, uses gas coin.
39
+ */
40
+ updatePriceFeeds(tx: Transaction, updates: Uint8Array[], feedIds: HexString[], feeCoin?: TransactionObjectArgument): Promise<ObjectId[]>;
41
+ /**
42
+ * Get the price feed object ID for a given feed ID, caching the promise.
43
+ * @param feedId
44
+ */
45
+ getPriceFeedObjectId(feedId: HexString): Promise<ObjectId | undefined>;
46
+ /**
47
+ * Fetches the price table object ID for the current state ID, caching the promise.
48
+ * @returns Price table object ID and field type
49
+ */
50
+ getPriceTableInfo(): Promise<{
51
+ id: ObjectId;
52
+ fieldType: ObjectId;
53
+ }>;
54
+ /**
55
+ * Fetches the package ID for the Wormhole contract, with caching.
56
+ */
57
+ getWormholePackageId(): Promise<ObjectId>;
58
+ /**
59
+ * Fetches the package ID for the Pyth contract, with caching.
60
+ */
61
+ getPythPackageId(): Promise<ObjectId>;
62
+ /**
63
+ * Returns the cached base update fee, fetching it if necessary.
64
+ */
65
+ getBaseUpdateFee(): Promise<number>;
66
+ }
@@ -0,0 +1,250 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+ var _pythPackageId, _wormholePackageId, _priceFeedObjectIdCache, _priceTableInfo, _baseUpdateFee, _HaneulPythClient_instances, fetchPriceFeedObjectId_fn, fetchPriceTableInfo_fn, fetchWormholePackageId_fn, fetchPythPackageId_fn, getPackageId_fn, fetchBaseUpdateFee_fn;
10
+ import { bcs } from "@haneullabs/haneul/bcs";
11
+ import { coinWithBalance } from "@haneullabs/haneul/transactions";
12
+ import { fromBase64, fromHex, parseStructTag } from "@haneullabs/haneul/utils";
13
+ import { PriceServiceConnection } from "./PriceServiceConnection.js";
14
+ import { extractVaaBytesFromAccumulatorMessage } from "./pyth-helpers.js";
15
+ const MAX_ARGUMENT_SIZE = 16 * 1024;
16
+ class HaneulPriceServiceConnection extends PriceServiceConnection {
17
+ /**
18
+ * Fetch price feed update data.
19
+ *
20
+ * @param priceIds Array of hex-encoded price IDs.
21
+ * @returns Array of buffers containing the price update data.
22
+ */
23
+ async getPriceFeedsUpdateData(priceIds) {
24
+ const latestVaas = await this.getLatestVaas(priceIds);
25
+ return latestVaas.map((vaa) => fromBase64(vaa));
26
+ }
27
+ }
28
+ class HaneulPythClient {
29
+ constructor(provider, pythStateId, wormholeStateId) {
30
+ __privateAdd(this, _HaneulPythClient_instances);
31
+ __privateAdd(this, _pythPackageId);
32
+ __privateAdd(this, _wormholePackageId);
33
+ __privateAdd(this, _priceFeedObjectIdCache, /* @__PURE__ */ new Map());
34
+ __privateAdd(this, _priceTableInfo);
35
+ __privateAdd(this, _baseUpdateFee);
36
+ this.provider = provider;
37
+ this.pythStateId = pythStateId;
38
+ this.wormholeStateId = wormholeStateId;
39
+ }
40
+ /**
41
+ * Verifies the VAAs using the Wormhole contract.
42
+ *
43
+ * @param vaas Array of VAA buffers to verify.
44
+ * @param tx Transaction block to add commands to.
45
+ * @returns Array of verified VAAs.
46
+ */
47
+ async verifyVaas(vaas, tx) {
48
+ const wormholePackageId = await this.getWormholePackageId();
49
+ const verifiedVaas = [];
50
+ for (const vaa of vaas) {
51
+ const [verifiedVaa] = tx.moveCall({
52
+ target: `${wormholePackageId}::vaa::parse_and_verify`,
53
+ arguments: [tx.object(this.wormholeStateId), tx.pure.vector("u8", vaa), tx.object.clock()]
54
+ });
55
+ verifiedVaas.push(verifiedVaa);
56
+ }
57
+ return verifiedVaas;
58
+ }
59
+ /**
60
+ * Adds the necessary commands for updating the Pyth price feeds to the transaction block.
61
+ *
62
+ * @param tx Transaction block to add commands to.
63
+ * @param updates Array of price feed updates received from the price service.
64
+ * @param feedIds Array of feed IDs to update (in hex format).
65
+ * @param feeCoin Optional custom SUI coin to use for Pyth oracle fees. If not provided, uses gas coin.
66
+ */
67
+ async updatePriceFeeds(tx, updates, feedIds, feeCoin) {
68
+ const packageId = await this.getPythPackageId();
69
+ let priceUpdatesHotPotato;
70
+ if (updates.length > 1) {
71
+ throw new Error(
72
+ "SDK does not support sending multiple accumulator messages in a single transaction"
73
+ );
74
+ }
75
+ const vaa = extractVaaBytesFromAccumulatorMessage(updates[0]);
76
+ const verifiedVaas = await this.verifyVaas([vaa], tx);
77
+ [priceUpdatesHotPotato] = tx.moveCall({
78
+ target: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,
79
+ arguments: [
80
+ tx.object(this.pythStateId),
81
+ tx.pure(
82
+ bcs.vector(bcs.U8).serialize(Array.from(updates[0]), {
83
+ maxSize: MAX_ARGUMENT_SIZE
84
+ }).toBytes()
85
+ ),
86
+ verifiedVaas[0],
87
+ tx.object.clock()
88
+ ]
89
+ });
90
+ const priceInfoObjects = [];
91
+ const baseUpdateFee = await this.getBaseUpdateFee();
92
+ for (const feedId of feedIds) {
93
+ const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
94
+ if (!priceInfoObjectId) {
95
+ throw new Error(`Price feed ${feedId} not found, please create it first`);
96
+ }
97
+ priceInfoObjects.push(priceInfoObjectId);
98
+ const feePayment = feeCoin ? tx.splitCoins(feeCoin, [tx.pure.u64(baseUpdateFee)])[0] : coinWithBalance({ balance: baseUpdateFee });
99
+ [priceUpdatesHotPotato] = tx.moveCall({
100
+ target: `${packageId}::pyth::update_single_price_feed`,
101
+ arguments: [
102
+ tx.object(this.pythStateId),
103
+ priceUpdatesHotPotato,
104
+ tx.object(priceInfoObjectId),
105
+ feePayment,
106
+ tx.object.clock()
107
+ ]
108
+ });
109
+ }
110
+ tx.moveCall({
111
+ target: `${packageId}::hot_potato_vector::destroy`,
112
+ arguments: [priceUpdatesHotPotato],
113
+ typeArguments: [`${packageId}::price_info::PriceInfo`]
114
+ });
115
+ return priceInfoObjects;
116
+ }
117
+ /**
118
+ * Get the price feed object ID for a given feed ID, caching the promise.
119
+ * @param feedId
120
+ */
121
+ getPriceFeedObjectId(feedId) {
122
+ if (!__privateGet(this, _priceFeedObjectIdCache).has(feedId)) {
123
+ __privateGet(this, _priceFeedObjectIdCache).set(
124
+ feedId,
125
+ __privateMethod(this, _HaneulPythClient_instances, fetchPriceFeedObjectId_fn).call(this, feedId).catch((err) => {
126
+ __privateGet(this, _priceFeedObjectIdCache).delete(feedId);
127
+ throw err;
128
+ })
129
+ );
130
+ }
131
+ return __privateGet(this, _priceFeedObjectIdCache).get(feedId);
132
+ }
133
+ /**
134
+ * Fetches the price table object ID for the current state ID, caching the promise.
135
+ * @returns Price table object ID and field type
136
+ */
137
+ getPriceTableInfo() {
138
+ if (!__privateGet(this, _priceTableInfo)) {
139
+ const promise = __privateMethod(this, _HaneulPythClient_instances, fetchPriceTableInfo_fn).call(this).catch((err) => {
140
+ __privateSet(this, _priceTableInfo, void 0);
141
+ throw err;
142
+ });
143
+ __privateSet(this, _priceTableInfo, promise);
144
+ }
145
+ return __privateGet(this, _priceTableInfo);
146
+ }
147
+ /**
148
+ * Fetches the package ID for the Wormhole contract, with caching.
149
+ */
150
+ getWormholePackageId() {
151
+ if (!__privateGet(this, _wormholePackageId)) {
152
+ __privateSet(this, _wormholePackageId, __privateMethod(this, _HaneulPythClient_instances, fetchWormholePackageId_fn).call(this));
153
+ }
154
+ return __privateGet(this, _wormholePackageId);
155
+ }
156
+ /**
157
+ * Fetches the package ID for the Pyth contract, with caching.
158
+ */
159
+ getPythPackageId() {
160
+ if (!__privateGet(this, _pythPackageId)) {
161
+ __privateSet(this, _pythPackageId, __privateMethod(this, _HaneulPythClient_instances, fetchPythPackageId_fn).call(this));
162
+ }
163
+ return __privateGet(this, _pythPackageId);
164
+ }
165
+ /**
166
+ * Returns the cached base update fee, fetching it if necessary.
167
+ */
168
+ getBaseUpdateFee() {
169
+ if (!__privateGet(this, _baseUpdateFee)) {
170
+ __privateSet(this, _baseUpdateFee, __privateMethod(this, _HaneulPythClient_instances, fetchBaseUpdateFee_fn).call(this));
171
+ }
172
+ return __privateGet(this, _baseUpdateFee);
173
+ }
174
+ }
175
+ _pythPackageId = new WeakMap();
176
+ _wormholePackageId = new WeakMap();
177
+ _priceFeedObjectIdCache = new WeakMap();
178
+ _priceTableInfo = new WeakMap();
179
+ _baseUpdateFee = new WeakMap();
180
+ _HaneulPythClient_instances = new WeakSet();
181
+ fetchPriceFeedObjectId_fn = async function(feedId) {
182
+ const { id: tableId, fieldType } = await this.getPriceTableInfo();
183
+ const result = await this.provider.getDynamicFieldObject({
184
+ parentId: tableId,
185
+ name: {
186
+ type: `${fieldType}::price_identifier::PriceIdentifier`,
187
+ value: {
188
+ bytes: Array.from(fromHex(feedId))
189
+ }
190
+ }
191
+ });
192
+ if (!result.data || !result.data.content) {
193
+ throw new Error(`Price feed object ID for feed ID ${feedId} not found.`);
194
+ }
195
+ if (result.data.content.dataType !== "moveObject") {
196
+ throw new Error("Price feed type mismatch");
197
+ }
198
+ return result.data.content.fields.value;
199
+ };
200
+ fetchPriceTableInfo_fn = async function() {
201
+ const result = await this.provider.getDynamicFieldObject({
202
+ parentId: this.pythStateId,
203
+ name: {
204
+ type: "vector<u8>",
205
+ value: "price_info"
206
+ }
207
+ });
208
+ if (!result.data || !result.data.type) {
209
+ throw new Error("Price Table not found, contract may not be initialized");
210
+ }
211
+ const priceIdentifier = parseStructTag(result.data.type).typeParams[0];
212
+ if (typeof priceIdentifier === "object" && priceIdentifier !== null && priceIdentifier.name === "PriceIdentifier" && "address" in priceIdentifier) {
213
+ return { id: result.data.objectId, fieldType: priceIdentifier.address };
214
+ } else {
215
+ throw new Error("fieldType not found");
216
+ }
217
+ };
218
+ fetchWormholePackageId_fn = async function() {
219
+ return await __privateMethod(this, _HaneulPythClient_instances, getPackageId_fn).call(this, this.wormholeStateId);
220
+ };
221
+ fetchPythPackageId_fn = async function() {
222
+ return await __privateMethod(this, _HaneulPythClient_instances, getPackageId_fn).call(this, this.pythStateId);
223
+ };
224
+ getPackageId_fn = async function(objectId) {
225
+ const result = await this.provider.getObject({
226
+ id: objectId,
227
+ options: { showContent: true }
228
+ });
229
+ if (result.data?.content?.dataType === "moveObject" && "upgrade_cap" in result.data.content.fields) {
230
+ const fields = result.data.content.fields;
231
+ return fields.upgrade_cap.fields.package;
232
+ }
233
+ throw new Error(`Cannot fetch package ID for object ${objectId}`);
234
+ };
235
+ fetchBaseUpdateFee_fn = async function() {
236
+ const result = await this.provider.getObject({
237
+ id: this.pythStateId,
238
+ options: { showContent: true }
239
+ });
240
+ if (!result.data || result.data.content?.dataType !== "moveObject") {
241
+ throw new Error("Unable to fetch Pyth state object");
242
+ }
243
+ const fields = result.data.content.fields;
244
+ return fields.base_update_fee;
245
+ };
246
+ export {
247
+ HaneulPriceServiceConnection,
248
+ HaneulPythClient
249
+ };
250
+ //# sourceMappingURL=pyth.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/pyth/pyth.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@haneullabs/haneul/bcs';\nimport type { HaneulClient } from '@haneullabs/haneul/client';\nimport type { Transaction, TransactionObjectArgument } from '@haneullabs/haneul/transactions';\nimport { coinWithBalance } from '@haneullabs/haneul/transactions';\nimport { fromBase64, fromHex, parseStructTag } from '@haneullabs/haneul/utils';\n\nimport type { HexString } from './PriceServiceConnection.js';\nimport { PriceServiceConnection } from './PriceServiceConnection.js';\nimport { extractVaaBytesFromAccumulatorMessage } from './pyth-helpers.js';\n\nconst MAX_ARGUMENT_SIZE = 16 * 1024;\nexport type ObjectId = string;\nexport class HaneulPriceServiceConnection extends PriceServiceConnection {\n\t/**\n\t * Fetch price feed update data.\n\t *\n\t * @param priceIds Array of hex-encoded price IDs.\n\t * @returns Array of buffers containing the price update data.\n\t */\n\tasync getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Uint8Array[]> {\n\t\tconst latestVaas = await this.getLatestVaas(priceIds);\n\t\treturn latestVaas.map((vaa) => fromBase64(vaa));\n\t}\n}\nexport class HaneulPythClient {\n\t#pythPackageId?: Promise<ObjectId>;\n\t#wormholePackageId?: Promise<ObjectId>;\n\t#priceFeedObjectIdCache: Map<HexString, Promise<ObjectId>> = new Map();\n\t#priceTableInfo?: Promise<{ id: ObjectId; fieldType: ObjectId }>;\n\t#baseUpdateFee?: Promise<number>;\n\tprovider: HaneulClient;\n\tpythStateId: ObjectId;\n\twormholeStateId: ObjectId;\n\n\tconstructor(provider: HaneulClient, pythStateId: ObjectId, wormholeStateId: ObjectId) {\n\t\tthis.provider = provider;\n\t\tthis.pythStateId = pythStateId;\n\t\tthis.wormholeStateId = wormholeStateId;\n\t}\n\t/**\n\t * Verifies the VAAs using the Wormhole contract.\n\t *\n\t * @param vaas Array of VAA buffers to verify.\n\t * @param tx Transaction block to add commands to.\n\t * @returns Array of verified VAAs.\n\t */\n\tasync verifyVaas(vaas: Uint8Array[], tx: Transaction) {\n\t\tconst wormholePackageId = await this.getWormholePackageId();\n\t\tconst verifiedVaas = [];\n\t\tfor (const vaa of vaas) {\n\t\t\tconst [verifiedVaa] = tx.moveCall({\n\t\t\t\ttarget: `${wormholePackageId}::vaa::parse_and_verify`,\n\t\t\t\targuments: [tx.object(this.wormholeStateId), tx.pure.vector('u8', vaa), tx.object.clock()],\n\t\t\t});\n\t\t\tverifiedVaas.push(verifiedVaa);\n\t\t}\n\t\treturn verifiedVaas;\n\t}\n\t/**\n\t * Adds the necessary commands for updating the Pyth price feeds to the transaction block.\n\t *\n\t * @param tx Transaction block to add commands to.\n\t * @param updates Array of price feed updates received from the price service.\n\t * @param feedIds Array of feed IDs to update (in hex format).\n\t * @param feeCoin Optional custom SUI coin to use for Pyth oracle fees. If not provided, uses gas coin.\n\t */\n\tasync updatePriceFeeds(\n\t\ttx: Transaction,\n\t\tupdates: Uint8Array[],\n\t\tfeedIds: HexString[],\n\t\tfeeCoin?: TransactionObjectArgument,\n\t): Promise<ObjectId[]> {\n\t\tconst packageId = await this.getPythPackageId();\n\t\tlet priceUpdatesHotPotato;\n\t\tif (updates.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t'SDK does not support sending multiple accumulator messages in a single transaction',\n\t\t\t);\n\t\t}\n\t\tconst vaa = extractVaaBytesFromAccumulatorMessage(updates[0]);\n\t\tconst verifiedVaas = await this.verifyVaas([vaa], tx);\n\t\t[priceUpdatesHotPotato] = tx.moveCall({\n\t\t\ttarget: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.pythStateId),\n\t\t\t\ttx.pure(\n\t\t\t\t\tbcs\n\t\t\t\t\t\t.vector(bcs.U8)\n\t\t\t\t\t\t.serialize(Array.from(updates[0]), {\n\t\t\t\t\t\t\tmaxSize: MAX_ARGUMENT_SIZE,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.toBytes(),\n\t\t\t\t),\n\t\t\t\tverifiedVaas[0],\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t\tconst priceInfoObjects: ObjectId[] = [];\n\t\tconst baseUpdateFee = await this.getBaseUpdateFee();\n\t\tfor (const feedId of feedIds) {\n\t\t\tconst priceInfoObjectId = await this.getPriceFeedObjectId(feedId);\n\t\t\tif (!priceInfoObjectId) {\n\t\t\t\tthrow new Error(`Price feed ${feedId} not found, please create it first`);\n\t\t\t}\n\t\t\tpriceInfoObjects.push(priceInfoObjectId);\n\n\t\t\tconst feePayment = feeCoin\n\t\t\t\t? tx.splitCoins(feeCoin, [tx.pure.u64(baseUpdateFee)])[0]\n\t\t\t\t: coinWithBalance({ balance: baseUpdateFee });\n\n\t\t\t[priceUpdatesHotPotato] = tx.moveCall({\n\t\t\t\ttarget: `${packageId}::pyth::update_single_price_feed`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.pythStateId),\n\t\t\t\t\tpriceUpdatesHotPotato,\n\t\t\t\t\ttx.object(priceInfoObjectId),\n\t\t\t\t\tfeePayment,\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t\ttx.moveCall({\n\t\t\ttarget: `${packageId}::hot_potato_vector::destroy`,\n\t\t\targuments: [priceUpdatesHotPotato],\n\t\t\ttypeArguments: [`${packageId}::price_info::PriceInfo`],\n\t\t});\n\t\treturn priceInfoObjects;\n\t}\n\t/**\n\t * Get the price feed object ID for a given feed ID, caching the promise.\n\t * @param feedId\n\t */\n\tgetPriceFeedObjectId(feedId: HexString): Promise<ObjectId | undefined> {\n\t\tif (!this.#priceFeedObjectIdCache.has(feedId)) {\n\t\t\tthis.#priceFeedObjectIdCache.set(\n\t\t\t\tfeedId,\n\t\t\t\tthis.#fetchPriceFeedObjectId(feedId).catch((err) => {\n\t\t\t\t\t// Remove failed promises from the cache to allow retries\n\t\t\t\t\tthis.#priceFeedObjectIdCache.delete(feedId);\n\t\t\t\t\tthrow err;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn this.#priceFeedObjectIdCache.get(feedId)!;\n\t}\n\n\t/**\n\t * Fetches the price feed object ID for a given feed ID (no caching).\n\t * Throws an error if the object is not found.\n\t */\n\tasync #fetchPriceFeedObjectId(feedId: HexString): Promise<ObjectId> {\n\t\tconst { id: tableId, fieldType } = await this.getPriceTableInfo();\n\t\tconst result = await this.provider.getDynamicFieldObject({\n\t\t\tparentId: tableId,\n\t\t\tname: {\n\t\t\t\ttype: `${fieldType}::price_identifier::PriceIdentifier`,\n\t\t\t\tvalue: {\n\t\t\t\t\tbytes: Array.from(fromHex(feedId)),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!result.data || !result.data.content) {\n\t\t\tthrow new Error(`Price feed object ID for feed ID ${feedId} not found.`);\n\t\t}\n\t\tif (result.data.content.dataType !== 'moveObject') {\n\t\t\tthrow new Error('Price feed type mismatch');\n\t\t}\n\n\t\t// @ts-ignore\n\t\treturn result.data.content.fields.value;\n\t}\n\n\t/**\n\t * Fetches the price table object ID for the current state ID, caching the promise.\n\t * @returns Price table object ID and field type\n\t */\n\tgetPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {\n\t\tif (!this.#priceTableInfo) {\n\t\t\tconst promise = this.#fetchPriceTableInfo().catch((err) => {\n\t\t\t\t// Clear the cached promise on error\n\t\t\t\tthis.#priceTableInfo = undefined;\n\t\t\t\tthrow err;\n\t\t\t});\n\n\t\t\tthis.#priceTableInfo = promise;\n\t\t}\n\n\t\treturn this.#priceTableInfo;\n\t}\n\n\t/**\n\t * Fetches the price table object ID and field type (no caching).\n\t * @returns Price table object ID and field type\n\t */\n\tasync #fetchPriceTableInfo(): Promise<{ id: ObjectId; fieldType: ObjectId }> {\n\t\tconst result = await this.provider.getDynamicFieldObject({\n\t\t\tparentId: this.pythStateId,\n\t\t\tname: {\n\t\t\t\ttype: 'vector<u8>',\n\t\t\t\tvalue: 'price_info',\n\t\t\t},\n\t\t});\n\n\t\tif (!result.data || !result.data.type) {\n\t\t\tthrow new Error('Price Table not found, contract may not be initialized');\n\t\t}\n\n\t\tconst priceIdentifier = parseStructTag(result.data.type).typeParams[0];\n\t\tif (\n\t\t\ttypeof priceIdentifier === 'object' &&\n\t\t\tpriceIdentifier !== null &&\n\t\t\tpriceIdentifier.name === 'PriceIdentifier' &&\n\t\t\t'address' in priceIdentifier\n\t\t) {\n\t\t\treturn { id: result.data.objectId, fieldType: priceIdentifier.address };\n\t\t} else {\n\t\t\tthrow new Error('fieldType not found');\n\t\t}\n\t}\n\t/**\n\t * Fetches the package ID for the Wormhole contract, with caching.\n\t */\n\tgetWormholePackageId(): Promise<ObjectId> {\n\t\tif (!this.#wormholePackageId) {\n\t\t\tthis.#wormholePackageId = this.#fetchWormholePackageId();\n\t\t}\n\t\treturn this.#wormholePackageId;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Wormhole contract (no caching).\n\t */\n\tasync #fetchWormholePackageId(): Promise<ObjectId> {\n\t\treturn await this.#getPackageId(this.wormholeStateId);\n\t}\n\n\t/**\n\t * Fetches the package ID for the Pyth contract, with caching.\n\t */\n\tgetPythPackageId(): Promise<ObjectId> {\n\t\tif (!this.#pythPackageId) {\n\t\t\tthis.#pythPackageId = this.#fetchPythPackageId();\n\t\t}\n\t\treturn this.#pythPackageId;\n\t}\n\n\t/**\n\t * Fetches the package ID for the Pyth contract (no caching).\n\t */\n\tasync #fetchPythPackageId(): Promise<ObjectId> {\n\t\treturn await this.#getPackageId(this.pythStateId);\n\t}\n\n\t/**\n\t * Fetches the package ID for a given object.\n\t *\n\t * @param objectId Object ID to fetch the package ID for.\n\t */\n\tasync #getPackageId(objectId: ObjectId): Promise<ObjectId> {\n\t\tconst result = await this.provider.getObject({\n\t\t\tid: objectId,\n\t\t\toptions: { showContent: true },\n\t\t});\n\n\t\tif (\n\t\t\tresult.data?.content?.dataType === 'moveObject' &&\n\t\t\t'upgrade_cap' in result.data.content.fields\n\t\t) {\n\t\t\tconst fields = result.data.content.fields as {\n\t\t\t\tupgrade_cap: {\n\t\t\t\t\tfields: {\n\t\t\t\t\t\tpackage: ObjectId;\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t};\n\t\t\treturn fields.upgrade_cap.fields.package;\n\t\t}\n\n\t\tthrow new Error(`Cannot fetch package ID for object ${objectId}`);\n\t}\n\t/**\n\t * Gets the base update fee from the Pyth state object.\n\t */\n\tasync #fetchBaseUpdateFee(): Promise<number> {\n\t\tconst result = await this.provider.getObject({\n\t\t\tid: this.pythStateId,\n\t\t\toptions: { showContent: true },\n\t\t});\n\n\t\tif (!result.data || result.data.content?.dataType !== 'moveObject') {\n\t\t\tthrow new Error('Unable to fetch Pyth state object');\n\t\t}\n\n\t\tconst fields = result.data.content.fields as { base_update_fee: number };\n\t\treturn fields.base_update_fee;\n\t}\n\n\t/**\n\t * Returns the cached base update fee, fetching it if necessary.\n\t */\n\tgetBaseUpdateFee(): Promise<number> {\n\t\tif (!this.#baseUpdateFee) {\n\t\t\tthis.#baseUpdateFee = this.#fetchBaseUpdateFee();\n\t\t}\n\t\treturn this.#baseUpdateFee;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;AAAA;AAGA,SAAS,WAAW;AAGpB,SAAS,uBAAuB;AAChC,SAAS,YAAY,SAAS,sBAAsB;AAGpD,SAAS,8BAA8B;AACvC,SAAS,6CAA6C;AAEtD,MAAM,oB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nC,WAAO,OAAO,YAAY,OAAO;AAAA,EAClC;AAEA,QAAM,IAAI,MAAM,sCAAsC,QAAQ,EAAE;AACjE;AAIM,wBAAmB,iBAAoB;AAC5C,QAAM,SAAS,MAAM,KAAK,SAAS,UAAU;AAAA,IAC5C,IAAI,KAAK;AAAA,IACT,SAAS,EAAE,aAAa,KAAK;AAAA,EAC9B,CAAC;AAED,MAAI,CAAC,OAAO,QAAQ,OAAO,KAAK,SAAS,aAAa,cAAc;AACnE,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACpD;AAEA,QAAM,SAAS,OAAO,KAAK,QAAQ;AACnC,SAAO,OAAO;AACf;",
6
+ "names": []
7
+ }
@@ -0,0 +1,89 @@
1
+ import type { HaneulClient } from '@haneullabs/haneul/client';
2
+ import type { TransactionObjectArgument, TransactionObjectInput } from '@haneullabs/haneul/transactions';
3
+ export interface CoinConfig {
4
+ type: string;
5
+ feed: string;
6
+ }
7
+ export interface DiscountInfo {
8
+ discountNft: TransactionObjectInput;
9
+ type: string;
10
+ isFreeClaim?: boolean;
11
+ }
12
+ export interface PackageInfo {
13
+ packageId: string;
14
+ packageIdV1: string;
15
+ packageIdPricing: string;
16
+ haneulns: string;
17
+ discountsPackage: {
18
+ packageId: string;
19
+ discountHouseId: string;
20
+ };
21
+ subNamesPackageId: string;
22
+ tempSubdomainsProxyPackageId: string;
23
+ coupons: {
24
+ packageId: string;
25
+ };
26
+ payments: {
27
+ packageId: string;
28
+ };
29
+ bbb: {
30
+ packageId: string;
31
+ vault: string;
32
+ };
33
+ registryTableId?: string;
34
+ pyth: {
35
+ pythStateId: string;
36
+ wormholeStateId: string;
37
+ };
38
+ utils?: {
39
+ packageId: string;
40
+ };
41
+ coins: Record<string, CoinConfig>;
42
+ }
43
+ export interface NameRecord {
44
+ name: string;
45
+ nftId: string;
46
+ targetAddress: string;
47
+ expirationTimestampMs: number;
48
+ data: Record<string, string>;
49
+ avatar?: string;
50
+ contentHash?: string;
51
+ walrusSiteId?: string;
52
+ }
53
+ export type Network = 'mainnet' | 'testnet' | 'custom';
54
+ export type VersionedPackageId = {
55
+ latest: string;
56
+ v1: string;
57
+ [key: string]: string;
58
+ };
59
+ export type Config = Record<'mainnet' | 'testnet', PackageInfo>;
60
+ export type BaseParams = {
61
+ years: number;
62
+ coinConfig: CoinConfig;
63
+ coin?: TransactionObjectInput;
64
+ couponCode?: string;
65
+ discountInfo?: DiscountInfo;
66
+ maxAmount?: bigint;
67
+ priceInfoObjectId?: string | null;
68
+ };
69
+ export type RegistrationParams = BaseParams & {
70
+ domain: string;
71
+ };
72
+ export type RenewalParams = BaseParams & {
73
+ nft: TransactionObjectInput;
74
+ };
75
+ export type ReceiptParams = {
76
+ paymentIntent: TransactionObjectArgument;
77
+ priceAfterDiscount: TransactionObjectArgument;
78
+ coinConfig: CoinConfig;
79
+ coin?: TransactionObjectInput;
80
+ maxAmount?: bigint;
81
+ priceInfoObjectId?: string | null;
82
+ };
83
+ export type HaneulnsClientConfig = {
84
+ client: HaneulClient;
85
+ network?: Network;
86
+ config?: Config;
87
+ };
88
+ export type SuinsPriceList = Map<[number, number], number>;
89
+ export type CoinTypeDiscount = Map<string, number>;