-
Notifications
You must be signed in to change notification settings - Fork 289
[Sui 21/x] - pyth-sui-js SDK #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
- normalize sui js sdk batch price attestation and accumulator update functions to take in base64 string (as opposed to hex)
…updatePriceFeedWithBatchPriceAttestation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the most complex sdk that we have had so far! I left some inline comments.
Also on sui/scripts/pyth:
- Can we remove Yarn in favor of our package?
- It's good to make it a local package which relies local dependencies instead of their released version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not exists when we have lerna. We should instead add this package to the global package.json file
import { SuiPriceServiceConnection } from "../index"; | ||
|
||
const argv = yargs(hideBin(process.argv)) | ||
.option("price-feed", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally it's better to accept multiple price feeds
@@ -0,0 +1,2 @@ | |||
export { SuiPriceServiceConnection } from "./SuiPriceServiceConnection"; | |||
export { SuiPythClient } from "./client"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to export other useful types as well like this
* @param priceIds Array of hex-encoded price ids. | ||
* @returns Array of price update data. | ||
*/ | ||
async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<number[][]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number[]
is a weird type. I prefer passing arrays of buffers instead and do the conversion on the edges as Buffer is more known as the data blob type.
const trailingPayloadSize = accumulatorMessage.slice(6, 7)[0]; | ||
const vaaSizeOffset = | ||
7 + // header bytes (header(4) + major(1) + minor(1) + trailing payload size(1)) | ||
trailingPayloadSize + // trailing payload (variable number of bytes) | ||
1; // proof_type (1 byte) | ||
const vaaSizeBytes = accumulatorMessage.slice( | ||
vaaSizeOffset, | ||
vaaSizeOffset + 2 | ||
); | ||
const vaaSize = vaaSizeBytes[1] + 16 * vaaSizeBytes[0]; | ||
const vaaOffset = vaaSizeOffset + 2; | ||
return accumulatorMessage.slice(vaaOffset, vaaOffset + vaaSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use Buffer you can use buffer.readUint...
if (updates.length > 1) { | ||
throw new Error( | ||
"SDK does not support sending multiple accumulator messages in a single transaction" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for the sake of simplicity of the sdk and the fact that it's rare.
throw new Error( | ||
`Price feed ${feedId} not found, please create it first` | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we don't want to create this ourself each time. Isn't it better to add the object creation part to the tx if possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try but last time I checked it was not that easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PriceInfoObjects are shared objects and should be specified by user as inputs to the transaction. Therefore, it's not possible to create and use them in the same transaction.
); | ||
} | ||
priceInfoObjects.push(priceInfoObjectId); | ||
const coin = tx.splitCoins(tx.gas, [tx.pure(1)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it assuming the update cost is always 1 per price feed? I think we should query it from on-chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm still a bit unclear on the createPrice part and the single sized update data but i don't have much context to judge.
Please add this package to the global package.json file before merging.
https://github.com/pyth-network/pyth-crosschain/blob/main/package.json
Summary
SuiPriceServiceConnection
classSuiRelay
example for fetching update data and updating a price feedhelpers
for updating price feed using accumulator message / batch price attestation, getting latest package ids given Wormhole or Pyth state, parsing VAA from accumulator msg, etc.README
TODOs
pyth-sui-js
npm package so that it is available to users vianpm install --save @pythnetwork/pyth-sui-js