@pythnetwork/client
Advanced tools
Comparing version 2.9.0 to 2.10.0
# Changelog | ||
## 2.10.0 | ||
- Add `localnet` to `PythCluster` | ||
- Add `Permission` to `AccountType` | ||
- Fix error in idl and make it support `permissionsAccount` | ||
## 2.9.0 | ||
@@ -4,0 +10,0 @@ - Add Anchor client |
@@ -17,3 +17,17 @@ { | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -35,3 +49,3 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
@@ -41,3 +55,17 @@ { | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -59,8 +87,22 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "newProductAccount", | ||
"name": "productAccount", | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -82,3 +124,17 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -100,3 +156,3 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
@@ -106,3 +162,17 @@ { | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -133,3 +203,17 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -156,3 +240,17 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -265,3 +363,17 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -292,3 +404,17 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -353,19 +479,2 @@ ], | ||
{ | ||
"name": "resizeAccount", | ||
"discriminant": { "value": [2, 0, 0, 0, 14, 0, 0, 0] }, | ||
"accounts": [ | ||
{ | ||
"name": "fundingAccount", | ||
"isMut": true, | ||
"isSigner": true | ||
}, | ||
{ | ||
"name": "priceAccount", | ||
"isMut": true, | ||
"isSigner": true | ||
} | ||
], | ||
"args": [] | ||
}, | ||
{ | ||
"name": "delPrice", | ||
@@ -382,3 +491,3 @@ "discriminant": { "value": [2, 0, 0, 0, 15, 0, 0, 0] }, | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
@@ -388,3 +497,17 @@ { | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -406,3 +529,3 @@ ], | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
@@ -412,3 +535,17 @@ { | ||
"isMut": true, | ||
"isSigner": true | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "permissionsAccount", | ||
"isMut": false, | ||
"isSigner": false, | ||
"pda": { | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
} | ||
] | ||
} | ||
} | ||
@@ -428,7 +565,2 @@ ], | ||
{ | ||
"name": "programAccount", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "programDataAccount", | ||
@@ -443,7 +575,9 @@ "isMut": false, | ||
"pda": { | ||
"seeds": [{ | ||
"seeds": [ | ||
{ | ||
"kind": "const", | ||
"type": "string", | ||
"value": "permissions" | ||
}] | ||
} | ||
] | ||
} | ||
@@ -457,3 +591,4 @@ }, | ||
], | ||
"args": [{ | ||
"args": [ | ||
{ | ||
"name": "masterAuthority", | ||
@@ -469,5 +604,6 @@ "type": "publicKey" | ||
"type": "publicKey" | ||
}] | ||
} | ||
] | ||
} | ||
] | ||
} |
import { PublicKey } from '@solana/web3.js'; | ||
import { Program, AnchorProvider } from '@coral-xyz/anchor'; | ||
import { PythOracleCoder } from './coder'; | ||
/** The Pyth program is not fully compatible with Anchor idls. | ||
@@ -9,3 +10,4 @@ * However it can be interacted with from Anchor clients by using PythOracleCoder from this library. | ||
export declare function pythOracleProgram(programId: PublicKey, provider: AnchorProvider): Program<PythOracle>; | ||
export { PythOracleCoder } from './coder'; | ||
export declare function pythOracleCoder(): PythOracleCoder; | ||
export { default as pythIdl } from './idl.json'; | ||
export declare type PythOracle = { | ||
@@ -29,3 +31,17 @@ version: '2.20.0'; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -49,3 +65,3 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
@@ -55,3 +71,17 @@ { | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -75,8 +105,22 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'newProductAccount'; | ||
name: 'productAccount'; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -100,3 +144,17 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -120,3 +178,3 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
@@ -126,3 +184,17 @@ { | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -155,3 +227,17 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -180,3 +266,17 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -295,3 +395,17 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -324,3 +438,17 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -387,21 +515,2 @@ ]; | ||
{ | ||
name: 'resizeAccount'; | ||
discriminant: { | ||
value: [2, 0, 0, 0, 14, 0, 0, 0]; | ||
}; | ||
accounts: [ | ||
{ | ||
name: 'fundingAccount'; | ||
isMut: true; | ||
isSigner: true; | ||
}, | ||
{ | ||
name: 'priceAccount'; | ||
isMut: true; | ||
isSigner: true; | ||
} | ||
]; | ||
args: []; | ||
}, | ||
{ | ||
name: 'delPrice'; | ||
@@ -420,3 +529,3 @@ discriminant: { | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
@@ -426,3 +535,17 @@ { | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -446,3 +569,3 @@ ]; | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
@@ -452,3 +575,17 @@ { | ||
isMut: true; | ||
isSigner: true; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'permissionsAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
pda: { | ||
seeds: [ | ||
{ | ||
kind: 'const'; | ||
type: 'string'; | ||
value: 'permissions'; | ||
} | ||
]; | ||
}; | ||
} | ||
@@ -470,7 +607,2 @@ ]; | ||
{ | ||
name: 'programAccount'; | ||
isMut: false; | ||
isSigner: false; | ||
}, | ||
{ | ||
name: 'programDataAccount'; | ||
@@ -477,0 +609,0 @@ isMut: false; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PythOracleCoder = exports.pythOracleProgram = void 0; | ||
exports.pythIdl = exports.pythOracleCoder = exports.pythOracleProgram = void 0; | ||
var anchor_1 = require("@coral-xyz/anchor"); | ||
@@ -20,3 +20,7 @@ var coder_1 = require("./coder"); | ||
exports.pythOracleProgram = pythOracleProgram; | ||
var coder_2 = require("./coder"); | ||
Object.defineProperty(exports, "PythOracleCoder", { enumerable: true, get: function () { return coder_2.PythOracleCoder; } }); | ||
function pythOracleCoder() { | ||
return new coder_1.PythOracleCoder(idl_json_1.default); | ||
} | ||
exports.pythOracleCoder = pythOracleCoder; | ||
var idl_json_2 = require("./idl.json"); | ||
Object.defineProperty(exports, "pythIdl", { enumerable: true, get: function () { return __importDefault(idl_json_2).default; } }); |
import { Cluster, PublicKey } from '@solana/web3.js'; | ||
export declare type PythCluster = Cluster | 'pythtest' | 'pythnet'; | ||
export declare type PythCluster = Cluster | 'pythtest' | 'pythnet' | 'localnet'; | ||
/** Gets the public key of the Pyth program running on the given cluster. */ | ||
@@ -4,0 +4,0 @@ export declare function getPythProgramKeyForCluster(cluster: PythCluster): PublicKey; |
@@ -12,2 +12,3 @@ "use strict"; | ||
pythnet: 'FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH', | ||
localnet: 'gMYYig2utAxVoXnM9UhtTWrt8e7x2SVBZqsWZJeT5Gw', | ||
}; | ||
@@ -33,2 +34,5 @@ /** Gets the public key of the Pyth program running on the given cluster. */ | ||
} | ||
else if (cluster === 'localnet') { | ||
return 'http://localhost:8899'; | ||
} | ||
else { | ||
@@ -35,0 +39,0 @@ return web3_js_1.clusterApiUrl(cluster); |
@@ -32,3 +32,4 @@ /// <reference types="node" /> | ||
Price = 3, | ||
Test = 4 | ||
Test = 4, | ||
Permission = 5 | ||
} | ||
@@ -71,2 +72,6 @@ export interface Base { | ||
} | ||
/** | ||
* valueComponent = numerator / denominator | ||
* value = valueComponent * 10 ^ exponent (from PriceData) | ||
*/ | ||
export interface Ema { | ||
@@ -106,2 +111,7 @@ valueComponent: bigint; | ||
} | ||
export interface PermissionData extends Base { | ||
masterAuthority: PublicKey; | ||
dataCurationAuthority: PublicKey; | ||
securityAuthority: PublicKey; | ||
} | ||
/** Parse data as a generic Pyth account. Use this method if you don't know the account type. */ | ||
@@ -112,5 +122,6 @@ export declare function parseBaseData(data: Buffer): Base | undefined; | ||
export declare const parsePriceData: (data: Buffer, currentSlot?: number | undefined) => PriceData; | ||
export declare const parsePermissionData: (data: Buffer) => PermissionData; | ||
export { PythConnection } from './PythConnection'; | ||
export { PythHttpClient } from './PythHttpClient'; | ||
export { getPythProgramKeyForCluster } from './cluster'; | ||
export { pythOracleProgram, PythOracleCoder } from './anchor'; | ||
export { pythOracleProgram, pythOracleCoder, pythIdl } from './anchor'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PythOracleCoder = exports.pythOracleProgram = exports.getPythProgramKeyForCluster = exports.PythHttpClient = exports.PythConnection = exports.parsePriceData = exports.parseProductData = exports.parseMappingData = exports.parseBaseData = exports.AccountType = exports.DeriveType = exports.PriceType = exports.CorpAction = exports.PriceStatus = exports.MAX_SLOT_DIFFERENCE = exports.Version = exports.Version2 = exports.Magic = void 0; | ||
exports.pythIdl = exports.pythOracleCoder = exports.pythOracleProgram = exports.getPythProgramKeyForCluster = exports.PythHttpClient = exports.PythConnection = exports.parsePermissionData = exports.parsePriceData = exports.parseProductData = exports.parseMappingData = exports.parseBaseData = exports.AccountType = exports.DeriveType = exports.PriceType = exports.CorpAction = exports.PriceStatus = exports.MAX_SLOT_DIFFERENCE = exports.Version = exports.Version2 = exports.Magic = void 0; | ||
var web3_js_1 = require("@solana/web3.js"); | ||
@@ -41,2 +41,3 @@ var buffer_1 = require("buffer"); | ||
AccountType[AccountType["Test"] = 4] = "Test"; | ||
AccountType[AccountType["Permission"] = 5] = "Permission"; | ||
})(AccountType = exports.AccountType || (exports.AccountType = {})); | ||
@@ -280,2 +281,25 @@ var empty32Buffer = buffer_1.Buffer.alloc(32); | ||
exports.parsePriceData = parsePriceData; | ||
var parsePermissionData = function (data) { | ||
// pyth magic number | ||
var magic = data.readUInt32LE(0); | ||
// program version | ||
var version = data.readUInt32LE(4); | ||
// account type | ||
var type = data.readUInt32LE(8); | ||
// price account size | ||
var size = data.readUInt32LE(12); | ||
var masterAuthority = new web3_js_1.PublicKey(data.slice(16, 48)); | ||
var dataCurationAuthority = new web3_js_1.PublicKey(data.slice(48, 80)); | ||
var securityAuthority = new web3_js_1.PublicKey(data.slice(80, 112)); | ||
return { | ||
magic: magic, | ||
version: version, | ||
type: type, | ||
size: size, | ||
masterAuthority: masterAuthority, | ||
dataCurationAuthority: dataCurationAuthority, | ||
securityAuthority: securityAuthority, | ||
}; | ||
}; | ||
exports.parsePermissionData = parsePermissionData; | ||
var PythConnection_1 = require("./PythConnection"); | ||
@@ -289,2 +313,3 @@ Object.defineProperty(exports, "PythConnection", { enumerable: true, get: function () { return PythConnection_1.PythConnection; } }); | ||
Object.defineProperty(exports, "pythOracleProgram", { enumerable: true, get: function () { return anchor_1.pythOracleProgram; } }); | ||
Object.defineProperty(exports, "PythOracleCoder", { enumerable: true, get: function () { return anchor_1.PythOracleCoder; } }); | ||
Object.defineProperty(exports, "pythOracleCoder", { enumerable: true, get: function () { return anchor_1.pythOracleCoder; } }); | ||
Object.defineProperty(exports, "pythIdl", { enumerable: true, get: function () { return anchor_1.pythIdl; } }); |
@@ -116,2 +116,3 @@ "use strict"; | ||
case index_1.AccountType.Test: | ||
case index_1.AccountType.Permission: | ||
break; | ||
@@ -118,0 +119,0 @@ default: |
import { Commitment, Connection, PublicKey } from '@solana/web3.js'; | ||
import { Product, PriceData } from '.'; | ||
import { Product, PriceData, PermissionData } from '.'; | ||
export interface PythHttpClientResult { | ||
@@ -13,2 +13,3 @@ assetTypes: string[]; | ||
prices: PriceData[]; | ||
permissionData: PermissionData | undefined; | ||
} | ||
@@ -15,0 +16,0 @@ /** |
@@ -58,3 +58,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var assetTypes, productSymbols, products, productFromSymbol, productPrice, prices, accountList, priceDataQueue, productAccountKeyToProduct, currentSlot, result; | ||
var assetTypes, productSymbols, products, productFromSymbol, productPrice, prices, accountList, priceDataQueue, productAccountKeyToProduct, currentSlot, permissionData, result; | ||
return __generator(this, function (_a) { | ||
@@ -76,3 +76,5 @@ switch (_a.label) { | ||
productAccountKeyToProduct = new Map(); | ||
return [4 /*yield*/, this.connection.getSlot(this.commitment)]; | ||
return [4 /*yield*/, this.connection.getSlot(this.commitment) | ||
// Initialize permission field as undefined | ||
]; | ||
case 2: | ||
@@ -101,2 +103,5 @@ currentSlot = _a.sent(); | ||
break; | ||
case _1.AccountType.Permission: | ||
permissionData = _1.parsePermissionData(singleAccount.account.data); | ||
break; | ||
default: | ||
@@ -121,2 +126,3 @@ throw new Error("Unknown account type: " + base.type + ". Try upgrading pyth-client."); | ||
prices: prices, | ||
permissionData: permissionData, | ||
}; | ||
@@ -123,0 +129,0 @@ return [2 /*return*/, result]; |
{ | ||
"name": "@pythnetwork/client", | ||
"version": "2.9.0", | ||
"version": "2.10.0", | ||
"description": "Client for consuming Pyth price data", | ||
@@ -15,3 +15,3 @@ "homepage": "https://pyth.network", | ||
"build": "tsc", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"format": "prettier --write \"src/**/*.{ts,json}\"", | ||
"lint": "tslint -p tsconfig.json", | ||
@@ -18,0 +18,0 @@ "prepare": "npm run build", |
126933
2813