@pythnetwork/client
Advanced tools
Comparing version 2.10.0 to 2.11.0
# Changelog | ||
## 2.11.0 | ||
- Add `@coral-xyz/anchor` to deps | ||
- ``ProductData.priceAccountKey` was `PublicKey` becomes `PublicKey | null` if the product account doesn't yet have a price account | ||
## 2.10.0 | ||
@@ -4,0 +9,0 @@ |
@@ -90,5 +90,23 @@ "use strict"; | ||
} | ||
var len = layout.encode(ix, buffer); | ||
var data = buffer.subarray(0, len); | ||
return buffer_1.Buffer.concat([discriminator, data]); | ||
/// updProduct has its own format | ||
if (methodName === 'updProduct') { | ||
var offset = 0; | ||
for (var _i = 0, _a = Object.keys(ix.productMetadata); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
offset += buffer.subarray(offset).writeInt8(key.length); | ||
offset += buffer.subarray(offset).write(key); | ||
offset += buffer.subarray(offset).writeInt8(ix.productMetadata[key].length); | ||
offset += buffer.subarray(offset).write(ix.productMetadata[key]); | ||
} | ||
if (offset > 464) { | ||
throw new Error('The metadata is too long'); | ||
} | ||
var data = buffer.subarray(0, offset); | ||
return buffer_1.Buffer.concat([discriminator, data]); | ||
} | ||
else { | ||
var len = layout.encode(ix, buffer); | ||
var data = buffer.subarray(0, len); | ||
return buffer_1.Buffer.concat([discriminator, data]); | ||
} | ||
}; | ||
@@ -117,6 +135,30 @@ PythOracleInstructionCoder.parseIxLayout = function (idl) { | ||
} | ||
return { | ||
data: decoder.layout.decode(data), | ||
name: decoder.name, | ||
}; | ||
/// updProduct has its own format | ||
if (decoder.name === 'updProduct') { | ||
var product = {}; | ||
var idx = 0; | ||
while (idx < data.length) { | ||
var keyLength = data[idx]; | ||
idx++; | ||
if (keyLength) { | ||
var key = data.slice(idx, idx + keyLength).toString(); | ||
idx += keyLength; | ||
var valueLength = data[idx]; | ||
idx++; | ||
var value = data.slice(idx, idx + valueLength).toString(); | ||
idx += valueLength; | ||
product[key] = value; | ||
} | ||
} | ||
return { | ||
data: product, | ||
name: decoder.name, | ||
}; | ||
} | ||
else { | ||
return { | ||
data: decoder.layout.decode(data), | ||
name: decoder.name, | ||
}; | ||
} | ||
}; | ||
@@ -123,0 +165,0 @@ return PythOracleInstructionCoder; |
@@ -137,3 +137,10 @@ { | ||
], | ||
"args": [] | ||
"args": [ | ||
{ | ||
"name": "productMetadata", | ||
"type": { | ||
"defined": "ProductMetadata" | ||
} | ||
} | ||
] | ||
}, | ||
@@ -589,3 +596,12 @@ { | ||
} | ||
], | ||
"types": [ | ||
{ | ||
"name": "ProductMetadata", | ||
"type": { | ||
"kind": "struct", | ||
"fields": [] | ||
} | ||
} | ||
] | ||
} |
@@ -156,3 +156,10 @@ import { PublicKey } from '@solana/web3.js'; | ||
]; | ||
args: []; | ||
args: [ | ||
{ | ||
name: 'productMetadata'; | ||
type: { | ||
defined: 'ProductMetadata'; | ||
}; | ||
} | ||
]; | ||
}, | ||
@@ -631,2 +638,11 @@ { | ||
]; | ||
types: [ | ||
{ | ||
name: 'ProductMetadata'; | ||
type: { | ||
kind: 'struct'; | ||
fields: []; | ||
}; | ||
} | ||
]; | ||
}; |
@@ -46,11 +46,6 @@ /// <reference types="node" /> | ||
export interface Product { | ||
symbol: string; | ||
asset_type: string; | ||
quote_currency: string; | ||
tenor: string; | ||
price_account: string; | ||
[index: string]: string; | ||
} | ||
export interface ProductData extends Base { | ||
priceAccountKey: PublicKey; | ||
priceAccountKey: PublicKey | null; | ||
product: Product; | ||
@@ -68,3 +63,3 @@ } | ||
export interface PriceComponent { | ||
publisher: PublicKey | null; | ||
publisher: PublicKey; | ||
aggregate: Price; | ||
@@ -71,0 +66,0 @@ latest: Price; |
@@ -111,5 +111,6 @@ "use strict"; | ||
var priceAccountBytes = data.slice(16, 48); | ||
var priceAccountKey = new web3_js_1.PublicKey(priceAccountBytes); | ||
var priceAccountKey = PKorNull(priceAccountBytes); | ||
var product = {}; | ||
product.price_account = priceAccountKey.toBase58(); | ||
if (priceAccountKey) | ||
product.price_account = priceAccountKey.toBase58(); | ||
var idx = 48; | ||
@@ -232,16 +233,10 @@ while (idx < size) { | ||
var offset = 240; | ||
var shouldContinue = true; | ||
while (offset < data.length && shouldContinue) { | ||
var publisher = PKorNull(data.slice(offset, offset + 32)); | ||
while (priceComponents.length < numComponentPrices) { | ||
var publisher = new web3_js_1.PublicKey(data.slice(offset, offset + 32)); | ||
offset += 32; | ||
if (publisher) { | ||
var componentAggregate = parsePriceInfo(data.slice(offset, offset + 32), exponent); | ||
offset += 32; | ||
var latest = parsePriceInfo(data.slice(offset, offset + 32), exponent); | ||
offset += 32; | ||
priceComponents.push({ publisher: publisher, aggregate: componentAggregate, latest: latest }); | ||
} | ||
else { | ||
shouldContinue = false; | ||
} | ||
var componentAggregate = parsePriceInfo(data.slice(offset, offset + 32), exponent); | ||
offset += 32; | ||
var latest = parsePriceInfo(data.slice(offset, offset + 32), exponent); | ||
offset += 32; | ||
priceComponents.push({ publisher: publisher, aggregate: componentAggregate, latest: latest }); | ||
} | ||
@@ -248,0 +243,0 @@ return { |
@@ -77,3 +77,3 @@ "use strict"; | ||
}; | ||
if (productData.priceAccountKey.toString() !== ONES) { | ||
if (productData.priceAccountKey) { | ||
this.priceAccountKeyToProductAccountKey[productData.priceAccountKey.toString()] = key.toString(); | ||
@@ -80,0 +80,0 @@ } |
{ | ||
"name": "@pythnetwork/client", | ||
"version": "2.10.0", | ||
"version": "2.11.0", | ||
"description": "Client for consuming Pyth price data", | ||
@@ -32,3 +32,2 @@ "homepage": "https://pyth.network", | ||
"devDependencies": { | ||
"@coral-xyz/anchor": "^0.26.0", | ||
"@solana/web3.js": "^1.30.2", | ||
@@ -47,8 +46,8 @@ "@types/bn.js": "^5.1.1", | ||
"dependencies": { | ||
"buffer": "^6.0.1" | ||
"buffer": "^6.0.1", | ||
"@coral-xyz/anchor": "^0.26.0" | ||
}, | ||
"peerDependencies": { | ||
"@coral-xyz/anchor": "^0.26.0", | ||
"@solana/web3.js": "^1.30.2" | ||
} | ||
} |
129224
11
2877
+ Added@coral-xyz/anchor@^0.26.0