@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.
- package/CHANGELOG.md +505 -0
- package/README.md +9 -0
- package/dist/cjs/constants.d.ts +11 -0
- package/dist/cjs/constants.js +120 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/haneulns-client.d.ts +40 -0
- package/dist/cjs/haneulns-client.js +261 -0
- package/dist/cjs/haneulns-client.js.map +7 -0
- package/dist/cjs/haneulns-transaction.d.ts +105 -0
- package/dist/cjs/haneulns-transaction.js +465 -0
- package/dist/cjs/haneulns-transaction.js.map +7 -0
- package/dist/cjs/helpers.d.ts +18 -0
- package/dist/cjs/helpers.js +63 -0
- package/dist/cjs/helpers.js.map +7 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/pyth/PriceServiceConnection.d.ts +26 -0
- package/dist/cjs/pyth/PriceServiceConnection.js +68 -0
- package/dist/cjs/pyth/PriceServiceConnection.js.map +7 -0
- package/dist/cjs/pyth/pyth-helpers.d.ts +7 -0
- package/dist/cjs/pyth/pyth-helpers.js +36 -0
- package/dist/cjs/pyth/pyth-helpers.js.map +7 -0
- package/dist/cjs/pyth/pyth.d.ts +66 -0
- package/dist/cjs/pyth/pyth.js +270 -0
- package/dist/cjs/pyth/pyth.js.map +7 -0
- package/dist/cjs/types.d.ts +89 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/constants.d.ts +11 -0
- package/dist/esm/constants.js +100 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/haneulns-client.d.ts +40 -0
- package/dist/esm/haneulns-client.js +249 -0
- package/dist/esm/haneulns-client.js.map +7 -0
- package/dist/esm/haneulns-transaction.d.ts +105 -0
- package/dist/esm/haneulns-transaction.js +445 -0
- package/dist/esm/haneulns-transaction.js.map +7 -0
- package/dist/esm/helpers.d.ts +18 -0
- package/dist/esm/helpers.js +43 -0
- package/dist/esm/helpers.js.map +7 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/pyth/PriceServiceConnection.d.ts +26 -0
- package/dist/esm/pyth/PriceServiceConnection.js +38 -0
- package/dist/esm/pyth/PriceServiceConnection.js.map +7 -0
- package/dist/esm/pyth/pyth-helpers.d.ts +7 -0
- package/dist/esm/pyth/pyth-helpers.js +16 -0
- package/dist/esm/pyth/pyth-helpers.js.map +7 -0
- package/dist/esm/pyth/pyth.d.ts +66 -0
- package/dist/esm/pyth/pyth.js +250 -0
- package/dist/esm/pyth/pyth.js.map +7 -0
- package/dist/esm/types.d.ts +89 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +63 -0
- package/src/constants.ts +106 -0
- package/src/haneulns-client.ts +368 -0
- package/src/haneulns-transaction.ts +555 -0
- package/src/helpers.ts +52 -0
- package/src/index.ts +16 -0
- package/src/pyth/PriceServiceConnection.ts +48 -0
- package/src/pyth/pyth-helpers.ts +23 -0
- package/src/pyth/pyth.ts +312 -0
- package/src/types.ts +111 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
ALLOWED_METADATA: () => import_constants.ALLOWED_METADATA,
|
|
22
|
+
HaneulnsClient: () => import_haneulns_client.HaneulnsClient,
|
|
23
|
+
HaneulnsTransaction: () => import_haneulns_transaction.HaneulnsTransaction,
|
|
24
|
+
getCoinDiscountConfigType: () => import_helpers.getCoinDiscountConfigType,
|
|
25
|
+
getConfigType: () => import_helpers.getConfigType,
|
|
26
|
+
getDomainType: () => import_helpers.getDomainType,
|
|
27
|
+
getPricelistConfigType: () => import_helpers.getPricelistConfigType,
|
|
28
|
+
getRenewalPricelistConfigType: () => import_helpers.getRenewalPricelistConfigType,
|
|
29
|
+
isNestedSubName: () => import_helpers.isNestedSubName,
|
|
30
|
+
isSubName: () => import_helpers.isSubName,
|
|
31
|
+
mainPackage: () => import_constants.mainPackage,
|
|
32
|
+
validateYears: () => import_helpers.validateYears
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_haneulns_client = require("./haneulns-client.js");
|
|
36
|
+
var import_haneulns_transaction = require("./haneulns-transaction.js");
|
|
37
|
+
var import_constants = require("./constants.js");
|
|
38
|
+
var import_helpers = require("./helpers.js");
|
|
39
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,6BAA+B;AAC/B,kCAAoC;AAEpC,uBAA8C;AAC9C,qBASO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -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,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var PriceServiceConnection_exports = {};
|
|
30
|
+
__export(PriceServiceConnection_exports, {
|
|
31
|
+
PriceServiceConnection: () => PriceServiceConnection
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(PriceServiceConnection_exports);
|
|
34
|
+
var import_axios = __toESM(require("axios"));
|
|
35
|
+
var import_axios_retry = __toESM(require("axios-retry"));
|
|
36
|
+
class PriceServiceConnection {
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a new Connection.
|
|
39
|
+
*
|
|
40
|
+
* @param endpoint endpoint URL to the price service.
|
|
41
|
+
* @param config Optional configuration for custom setups.
|
|
42
|
+
*/
|
|
43
|
+
constructor(endpoint, config) {
|
|
44
|
+
this.httpClient = import_axios.default.create({
|
|
45
|
+
baseURL: endpoint,
|
|
46
|
+
timeout: config?.timeout || 5e3
|
|
47
|
+
});
|
|
48
|
+
(0, import_axios_retry.default)(this.httpClient, {
|
|
49
|
+
retries: config?.httpRetries || 3,
|
|
50
|
+
retryDelay: import_axios_retry.default.exponentialDelay
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Fetch latest VAAs of given price IDs.
|
|
55
|
+
*
|
|
56
|
+
* @param priceIds Array of hex-encoded price IDs.
|
|
57
|
+
* @returns Array of base64 encoded VAAs.
|
|
58
|
+
*/
|
|
59
|
+
async getLatestVaas(priceIds) {
|
|
60
|
+
const response = await this.httpClient.get("/api/latest_vaas", {
|
|
61
|
+
params: {
|
|
62
|
+
ids: priceIds
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return response.data;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAElB,yBAAuB;AAWhB,MAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnC,YAAY,UAAkB,QAAuC;AACpE,SAAK,aAAa,aAAAA,QAAM,OAAO;AAAA,MAC9B,SAAS;AAAA,MACT,SAAS,QAAQ,WAAW;AAAA,IAC7B,CAAC;AACD,2BAAAC,SAAW,KAAK,YAAY;AAAA,MAC3B,SAAS,QAAQ,eAAe;AAAA,MAChC,YAAY,mBAAAA,QAAW;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": ["axios", "axiosRetry"]
|
|
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,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var pyth_helpers_exports = {};
|
|
20
|
+
__export(pyth_helpers_exports, {
|
|
21
|
+
extractVaaBytesFromAccumulatorMessage: () => extractVaaBytesFromAccumulatorMessage
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(pyth_helpers_exports);
|
|
24
|
+
function extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
|
|
25
|
+
const dataView = new DataView(
|
|
26
|
+
accumulatorMessage.buffer,
|
|
27
|
+
accumulatorMessage.byteOffset,
|
|
28
|
+
accumulatorMessage.byteLength
|
|
29
|
+
);
|
|
30
|
+
const trailingPayloadSize = dataView.getUint8(6);
|
|
31
|
+
const vaaSizeOffset = 7 + trailingPayloadSize + 1;
|
|
32
|
+
const vaaSize = dataView.getUint16(vaaSizeOffset, false);
|
|
33
|
+
const vaaOffset = vaaSizeOffset + 2;
|
|
34
|
+
return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
|
|
35
|
+
}
|
|
36
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
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);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
var pyth_exports = {};
|
|
28
|
+
__export(pyth_exports, {
|
|
29
|
+
HaneulPriceServiceConnection: () => HaneulPriceServiceConnection,
|
|
30
|
+
HaneulPythClient: () => HaneulPythClient
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(pyth_exports);
|
|
33
|
+
var import_bcs = require("@haneullabs/haneul/bcs");
|
|
34
|
+
var import_transactions = require("@haneullabs/haneul/transactions");
|
|
35
|
+
var import_utils = require("@haneullabs/haneul/utils");
|
|
36
|
+
var import_PriceServiceConnection = require("./PriceServiceConnection.js");
|
|
37
|
+
var import_pyth_helpers = require("./pyth-helpers.js");
|
|
38
|
+
var _pythPackageId, _wormholePackageId, _priceFeedObjectIdCache, _priceTableInfo, _baseUpdateFee, _HaneulPythClient_instances, fetchPriceFeedObjectId_fn, fetchPriceTableInfo_fn, fetchWormholePackageId_fn, fetchPythPackageId_fn, getPackageId_fn, fetchBaseUpdateFee_fn;
|
|
39
|
+
const MAX_ARGUMENT_SIZE = 16 * 1024;
|
|
40
|
+
class HaneulPriceServiceConnection extends import_PriceServiceConnection.PriceServiceConnection {
|
|
41
|
+
/**
|
|
42
|
+
* Fetch price feed update data.
|
|
43
|
+
*
|
|
44
|
+
* @param priceIds Array of hex-encoded price IDs.
|
|
45
|
+
* @returns Array of buffers containing the price update data.
|
|
46
|
+
*/
|
|
47
|
+
async getPriceFeedsUpdateData(priceIds) {
|
|
48
|
+
const latestVaas = await this.getLatestVaas(priceIds);
|
|
49
|
+
return latestVaas.map((vaa) => (0, import_utils.fromBase64)(vaa));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class HaneulPythClient {
|
|
53
|
+
constructor(provider, pythStateId, wormholeStateId) {
|
|
54
|
+
__privateAdd(this, _HaneulPythClient_instances);
|
|
55
|
+
__privateAdd(this, _pythPackageId);
|
|
56
|
+
__privateAdd(this, _wormholePackageId);
|
|
57
|
+
__privateAdd(this, _priceFeedObjectIdCache, /* @__PURE__ */ new Map());
|
|
58
|
+
__privateAdd(this, _priceTableInfo);
|
|
59
|
+
__privateAdd(this, _baseUpdateFee);
|
|
60
|
+
this.provider = provider;
|
|
61
|
+
this.pythStateId = pythStateId;
|
|
62
|
+
this.wormholeStateId = wormholeStateId;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Verifies the VAAs using the Wormhole contract.
|
|
66
|
+
*
|
|
67
|
+
* @param vaas Array of VAA buffers to verify.
|
|
68
|
+
* @param tx Transaction block to add commands to.
|
|
69
|
+
* @returns Array of verified VAAs.
|
|
70
|
+
*/
|
|
71
|
+
async verifyVaas(vaas, tx) {
|
|
72
|
+
const wormholePackageId = await this.getWormholePackageId();
|
|
73
|
+
const verifiedVaas = [];
|
|
74
|
+
for (const vaa of vaas) {
|
|
75
|
+
const [verifiedVaa] = tx.moveCall({
|
|
76
|
+
target: `${wormholePackageId}::vaa::parse_and_verify`,
|
|
77
|
+
arguments: [tx.object(this.wormholeStateId), tx.pure.vector("u8", vaa), tx.object.clock()]
|
|
78
|
+
});
|
|
79
|
+
verifiedVaas.push(verifiedVaa);
|
|
80
|
+
}
|
|
81
|
+
return verifiedVaas;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds the necessary commands for updating the Pyth price feeds to the transaction block.
|
|
85
|
+
*
|
|
86
|
+
* @param tx Transaction block to add commands to.
|
|
87
|
+
* @param updates Array of price feed updates received from the price service.
|
|
88
|
+
* @param feedIds Array of feed IDs to update (in hex format).
|
|
89
|
+
* @param feeCoin Optional custom SUI coin to use for Pyth oracle fees. If not provided, uses gas coin.
|
|
90
|
+
*/
|
|
91
|
+
async updatePriceFeeds(tx, updates, feedIds, feeCoin) {
|
|
92
|
+
const packageId = await this.getPythPackageId();
|
|
93
|
+
let priceUpdatesHotPotato;
|
|
94
|
+
if (updates.length > 1) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"SDK does not support sending multiple accumulator messages in a single transaction"
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const vaa = (0, import_pyth_helpers.extractVaaBytesFromAccumulatorMessage)(updates[0]);
|
|
100
|
+
const verifiedVaas = await this.verifyVaas([vaa], tx);
|
|
101
|
+
[priceUpdatesHotPotato] = tx.moveCall({
|
|
102
|
+
target: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,
|
|
103
|
+
arguments: [
|
|
104
|
+
tx.object(this.pythStateId),
|
|
105
|
+
tx.pure(
|
|
106
|
+
import_bcs.bcs.vector(import_bcs.bcs.U8).serialize(Array.from(updates[0]), {
|
|
107
|
+
maxSize: MAX_ARGUMENT_SIZE
|
|
108
|
+
}).toBytes()
|
|
109
|
+
),
|
|
110
|
+
verifiedVaas[0],
|
|
111
|
+
tx.object.clock()
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
const priceInfoObjects = [];
|
|
115
|
+
const baseUpdateFee = await this.getBaseUpdateFee();
|
|
116
|
+
for (const feedId of feedIds) {
|
|
117
|
+
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
|
|
118
|
+
if (!priceInfoObjectId) {
|
|
119
|
+
throw new Error(`Price feed ${feedId} not found, please create it first`);
|
|
120
|
+
}
|
|
121
|
+
priceInfoObjects.push(priceInfoObjectId);
|
|
122
|
+
const feePayment = feeCoin ? tx.splitCoins(feeCoin, [tx.pure.u64(baseUpdateFee)])[0] : (0, import_transactions.coinWithBalance)({ balance: baseUpdateFee });
|
|
123
|
+
[priceUpdatesHotPotato] = tx.moveCall({
|
|
124
|
+
target: `${packageId}::pyth::update_single_price_feed`,
|
|
125
|
+
arguments: [
|
|
126
|
+
tx.object(this.pythStateId),
|
|
127
|
+
priceUpdatesHotPotato,
|
|
128
|
+
tx.object(priceInfoObjectId),
|
|
129
|
+
feePayment,
|
|
130
|
+
tx.object.clock()
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
tx.moveCall({
|
|
135
|
+
target: `${packageId}::hot_potato_vector::destroy`,
|
|
136
|
+
arguments: [priceUpdatesHotPotato],
|
|
137
|
+
typeArguments: [`${packageId}::price_info::PriceInfo`]
|
|
138
|
+
});
|
|
139
|
+
return priceInfoObjects;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get the price feed object ID for a given feed ID, caching the promise.
|
|
143
|
+
* @param feedId
|
|
144
|
+
*/
|
|
145
|
+
getPriceFeedObjectId(feedId) {
|
|
146
|
+
if (!__privateGet(this, _priceFeedObjectIdCache).has(feedId)) {
|
|
147
|
+
__privateGet(this, _priceFeedObjectIdCache).set(
|
|
148
|
+
feedId,
|
|
149
|
+
__privateMethod(this, _HaneulPythClient_instances, fetchPriceFeedObjectId_fn).call(this, feedId).catch((err) => {
|
|
150
|
+
__privateGet(this, _priceFeedObjectIdCache).delete(feedId);
|
|
151
|
+
throw err;
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return __privateGet(this, _priceFeedObjectIdCache).get(feedId);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Fetches the price table object ID for the current state ID, caching the promise.
|
|
159
|
+
* @returns Price table object ID and field type
|
|
160
|
+
*/
|
|
161
|
+
getPriceTableInfo() {
|
|
162
|
+
if (!__privateGet(this, _priceTableInfo)) {
|
|
163
|
+
const promise = __privateMethod(this, _HaneulPythClient_instances, fetchPriceTableInfo_fn).call(this).catch((err) => {
|
|
164
|
+
__privateSet(this, _priceTableInfo, void 0);
|
|
165
|
+
throw err;
|
|
166
|
+
});
|
|
167
|
+
__privateSet(this, _priceTableInfo, promise);
|
|
168
|
+
}
|
|
169
|
+
return __privateGet(this, _priceTableInfo);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Fetches the package ID for the Wormhole contract, with caching.
|
|
173
|
+
*/
|
|
174
|
+
getWormholePackageId() {
|
|
175
|
+
if (!__privateGet(this, _wormholePackageId)) {
|
|
176
|
+
__privateSet(this, _wormholePackageId, __privateMethod(this, _HaneulPythClient_instances, fetchWormholePackageId_fn).call(this));
|
|
177
|
+
}
|
|
178
|
+
return __privateGet(this, _wormholePackageId);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Fetches the package ID for the Pyth contract, with caching.
|
|
182
|
+
*/
|
|
183
|
+
getPythPackageId() {
|
|
184
|
+
if (!__privateGet(this, _pythPackageId)) {
|
|
185
|
+
__privateSet(this, _pythPackageId, __privateMethod(this, _HaneulPythClient_instances, fetchPythPackageId_fn).call(this));
|
|
186
|
+
}
|
|
187
|
+
return __privateGet(this, _pythPackageId);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns the cached base update fee, fetching it if necessary.
|
|
191
|
+
*/
|
|
192
|
+
getBaseUpdateFee() {
|
|
193
|
+
if (!__privateGet(this, _baseUpdateFee)) {
|
|
194
|
+
__privateSet(this, _baseUpdateFee, __privateMethod(this, _HaneulPythClient_instances, fetchBaseUpdateFee_fn).call(this));
|
|
195
|
+
}
|
|
196
|
+
return __privateGet(this, _baseUpdateFee);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
_pythPackageId = new WeakMap();
|
|
200
|
+
_wormholePackageId = new WeakMap();
|
|
201
|
+
_priceFeedObjectIdCache = new WeakMap();
|
|
202
|
+
_priceTableInfo = new WeakMap();
|
|
203
|
+
_baseUpdateFee = new WeakMap();
|
|
204
|
+
_HaneulPythClient_instances = new WeakSet();
|
|
205
|
+
fetchPriceFeedObjectId_fn = async function(feedId) {
|
|
206
|
+
const { id: tableId, fieldType } = await this.getPriceTableInfo();
|
|
207
|
+
const result = await this.provider.getDynamicFieldObject({
|
|
208
|
+
parentId: tableId,
|
|
209
|
+
name: {
|
|
210
|
+
type: `${fieldType}::price_identifier::PriceIdentifier`,
|
|
211
|
+
value: {
|
|
212
|
+
bytes: Array.from((0, import_utils.fromHex)(feedId))
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
if (!result.data || !result.data.content) {
|
|
217
|
+
throw new Error(`Price feed object ID for feed ID ${feedId} not found.`);
|
|
218
|
+
}
|
|
219
|
+
if (result.data.content.dataType !== "moveObject") {
|
|
220
|
+
throw new Error("Price feed type mismatch");
|
|
221
|
+
}
|
|
222
|
+
return result.data.content.fields.value;
|
|
223
|
+
};
|
|
224
|
+
fetchPriceTableInfo_fn = async function() {
|
|
225
|
+
const result = await this.provider.getDynamicFieldObject({
|
|
226
|
+
parentId: this.pythStateId,
|
|
227
|
+
name: {
|
|
228
|
+
type: "vector<u8>",
|
|
229
|
+
value: "price_info"
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (!result.data || !result.data.type) {
|
|
233
|
+
throw new Error("Price Table not found, contract may not be initialized");
|
|
234
|
+
}
|
|
235
|
+
const priceIdentifier = (0, import_utils.parseStructTag)(result.data.type).typeParams[0];
|
|
236
|
+
if (typeof priceIdentifier === "object" && priceIdentifier !== null && priceIdentifier.name === "PriceIdentifier" && "address" in priceIdentifier) {
|
|
237
|
+
return { id: result.data.objectId, fieldType: priceIdentifier.address };
|
|
238
|
+
} else {
|
|
239
|
+
throw new Error("fieldType not found");
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
fetchWormholePackageId_fn = async function() {
|
|
243
|
+
return await __privateMethod(this, _HaneulPythClient_instances, getPackageId_fn).call(this, this.wormholeStateId);
|
|
244
|
+
};
|
|
245
|
+
fetchPythPackageId_fn = async function() {
|
|
246
|
+
return await __privateMethod(this, _HaneulPythClient_instances, getPackageId_fn).call(this, this.pythStateId);
|
|
247
|
+
};
|
|
248
|
+
getPackageId_fn = async function(objectId) {
|
|
249
|
+
const result = await this.provider.getObject({
|
|
250
|
+
id: objectId,
|
|
251
|
+
options: { showContent: true }
|
|
252
|
+
});
|
|
253
|
+
if (result.data?.content?.dataType === "moveObject" && "upgrade_cap" in result.data.content.fields) {
|
|
254
|
+
const fields = result.data.content.fields;
|
|
255
|
+
return fields.upgrade_cap.fields.package;
|
|
256
|
+
}
|
|
257
|
+
throw new Error(`Cannot fetch package ID for object ${objectId}`);
|
|
258
|
+
};
|
|
259
|
+
fetchBaseUpdateFee_fn = async function() {
|
|
260
|
+
const result = await this.provider.getObject({
|
|
261
|
+
id: this.pythStateId,
|
|
262
|
+
options: { showContent: true }
|
|
263
|
+
});
|
|
264
|
+
if (!result.data || result.data.content?.dataType !== "moveObject") {
|
|
265
|
+
throw new Error("Unable to fetch Pyth state object");
|
|
266
|
+
}
|
|
267
|
+
const fields = result.data.content.fields;
|
|
268
|
+
return fields.base_update_fee;
|
|
269
|
+
};
|
|
270
|
+
//# 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AAGpB,0BAAgC;AAChC,mBAAoD;AAGpD,oCAAuC;AACvC,0BAAsD;AAXtD;AAaA,MAAM,oBAAoB,KAAK;AAExB,MAAM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