Skip to content

Commit f39f9bb

Browse files
committed
Expose anchor coder and change idl for consistency
1 parent 7a387d3 commit f39f9bb

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

src/__tests__/Anchor.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AnchorProvider, Wallet } from '@coral-xyz/anchor'
22
import { Connection, Keypair, PublicKey } from '@solana/web3.js'
33
import { BN } from 'bn.js'
4-
import { getPythProgramKeyForCluster, pythOracleProgram, PythOracleCoder } from '../index'
4+
import { getPythProgramKeyForCluster, pythOracleProgram, pythOracleCoder } from '../index'
55

66
test('Anchor', (done) => {
77
jest.setTimeout(60000)
@@ -17,7 +17,7 @@ test('Anchor', (done) => {
1717
.instruction()
1818
.then((instruction) => {
1919
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 0, 0, 0, 0]))
20-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
20+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
2121
expect(decoded?.name).toBe('initMapping')
2222
expect(decoded?.data).toStrictEqual({})
2323
})
@@ -27,7 +27,7 @@ test('Anchor', (done) => {
2727
.instruction()
2828
.then((instruction) => {
2929
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 1, 0, 0, 0]))
30-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
30+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
3131
expect(decoded?.name).toBe('addMapping')
3232
expect(decoded?.data).toStrictEqual({})
3333
})
@@ -37,7 +37,7 @@ test('Anchor', (done) => {
3737
.instruction()
3838
.then((instruction) => {
3939
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 3, 0, 0, 0]))
40-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
40+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
4141
expect(decoded?.name).toBe('updProduct')
4242
expect(decoded?.data).toStrictEqual({})
4343
})
@@ -48,7 +48,7 @@ test('Anchor', (done) => {
4848
.instruction()
4949
.then((instruction) => {
5050
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]))
51-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
51+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
5252
expect(decoded?.name).toBe('addPrice')
5353
expect(decoded?.data).toStrictEqual({ expo: 1, pType: 1 })
5454
})
@@ -64,7 +64,7 @@ test('Anchor', (done) => {
6464
0, 0, 5,
6565
]),
6666
)
67-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
67+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
6868
expect(decoded?.name).toBe('addPublisher')
6969
expect(decoded?.data.pub.equals(new PublicKey(5))).toBeTruthy()
7070
})
@@ -80,7 +80,7 @@ test('Anchor', (done) => {
8080
0, 0, 0, 0,
8181
]),
8282
)
83-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
83+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
8484
expect(decoded?.name).toBe('updPrice')
8585
expect(decoded?.data.status === 1).toBeTruthy()
8686
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
@@ -99,7 +99,7 @@ test('Anchor', (done) => {
9999
0, 0, 0, 0,
100100
]),
101101
)
102-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
102+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
103103
expect(decoded?.name).toBe('updPriceNoFailOnError')
104104
expect(decoded?.data.status === 1).toBeTruthy()
105105
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
@@ -118,7 +118,7 @@ test('Anchor', (done) => {
118118
0, 0, 0, 0,
119119
]),
120120
)
121-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
121+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
122122
expect(decoded?.name).toBe('aggPrice')
123123
expect(decoded?.data.status === 1).toBeTruthy()
124124
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
@@ -132,7 +132,7 @@ test('Anchor', (done) => {
132132
.instruction()
133133
.then((instruction) => {
134134
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 12, 0, 0, 0, 5, 0, 0, 0]))
135-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
135+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
136136
expect(decoded?.name).toBe('setMinPub')
137137
expect(decoded?.data.minPub === 5).toBeTruthy()
138138
})
@@ -155,7 +155,7 @@ test('Anchor', (done) => {
155155
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
156156
]),
157157
)
158-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
158+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
159159
expect(decoded?.name).toBe('updPermissions')
160160
expect(decoded?.data.masterAuthority.equals(new PublicKey(6))).toBeTruthy()
161161
expect(decoded?.data.dataCurationAuthority.equals(new PublicKey(7))).toBeTruthy()

src/anchor/idl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"isSigner": true
5757
},
5858
{
59-
"name": "newProductAccount",
59+
"name": "productAccount",
6060
"isMut": true,
6161
"isSigner": true
6262
}

src/anchor/program.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export function pythOracleProgram(programId: PublicKey, provider: AnchorProvider
1212
return new Program<PythOracle>(IDL as PythOracle, programId, provider, new PythOracleCoder(IDL as Idl))
1313
}
1414

15-
export { PythOracleCoder } from './coder'
15+
export function pythOracleCoder(): PythOracleCoder {
16+
return new PythOracleCoder(IDL as PythOracle);
17+
}
18+
19+
export { default as pythIdl } from "./idl.json";
20+
1621

1722
export type PythOracle = {
1823
version: '2.20.0'
@@ -72,7 +77,7 @@ export type PythOracle = {
7277
isSigner: true
7378
},
7479
{
75-
name: 'newProductAccount'
80+
name: 'productAccount'
7681
isMut: true
7782
isSigner: true
7883
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,4 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData =>
370370
export { PythConnection } from './PythConnection'
371371
export { PythHttpClient } from './PythHttpClient'
372372
export { getPythProgramKeyForCluster } from './cluster'
373-
export { pythOracleProgram, PythOracleCoder } from './anchor'
373+
export { pythOracleProgram, pythOracleCoder, pythIdl } from './anchor'

0 commit comments

Comments
 (0)