added createStaticFeed to SwitchboardTestContext
This commit is contained in:
parent
ba5b6877a8
commit
d52c89f811
|
@ -26,7 +26,7 @@ jobs:
|
||||||
uses: ./.github/actions/setup-workspace
|
uses: ./.github/actions/setup-workspace
|
||||||
with:
|
with:
|
||||||
solanaVersion: "v1.14.10"
|
solanaVersion: "v1.14.10"
|
||||||
anchorVersion: "0.27.0"
|
anchorVersion: "0.26.0"
|
||||||
nodeVersion: ${{ matrix.nodeVersion }}
|
nodeVersion: ${{ matrix.nodeVersion }}
|
||||||
|
|
||||||
- name: Cache Build
|
- name: Cache Build
|
||||||
|
@ -69,7 +69,7 @@ jobs:
|
||||||
uses: ./.github/actions/setup-workspace
|
uses: ./.github/actions/setup-workspace
|
||||||
with:
|
with:
|
||||||
solanaVersion: "v1.14.10"
|
solanaVersion: "v1.14.10"
|
||||||
anchorVersion: "0.27.0"
|
anchorVersion: "0.26.0"
|
||||||
nodeVersion: ${{ matrix.nodeVersion }}
|
nodeVersion: ${{ matrix.nodeVersion }}
|
||||||
|
|
||||||
- name: Cache Build
|
- name: Cache Build
|
||||||
|
|
|
@ -16,7 +16,6 @@ __pycache__
|
||||||
|
|
||||||
# Rust
|
# Rust
|
||||||
programs/**/target
|
programs/**/target
|
||||||
Cargo.lock
|
|
||||||
.anchor
|
.anchor
|
||||||
target
|
target
|
||||||
.crates
|
.crates
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@switchboard-xyz/solana.js",
|
"name": "@switchboard-xyz/solana.js",
|
||||||
"version": "2.1.16",
|
"version": "2.1.18",
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A Typescript client to interact with Switchboard on Solana.",
|
"description": "A Typescript client to interact with Switchboard on Solana.",
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
|
import { AggregatorAccountData } from './generated';
|
||||||
import {
|
import {
|
||||||
|
AggregatorAccount,
|
||||||
|
CreateQueueFeedParams,
|
||||||
CreateQueueOracleParams,
|
CreateQueueOracleParams,
|
||||||
|
createStaticFeed,
|
||||||
|
JobAccount,
|
||||||
LoadedSwitchboardNetwork,
|
LoadedSwitchboardNetwork,
|
||||||
loadKeypair,
|
loadKeypair,
|
||||||
NetworkInitParams,
|
NetworkInitParams,
|
||||||
|
@ -7,10 +12,13 @@ import {
|
||||||
QueueAccount,
|
QueueAccount,
|
||||||
SwitchboardNetwork,
|
SwitchboardNetwork,
|
||||||
SwitchboardProgram,
|
SwitchboardProgram,
|
||||||
|
TransactionObject,
|
||||||
|
updateStaticFeed,
|
||||||
} from '.';
|
} from '.';
|
||||||
|
|
||||||
import { AnchorProvider } from '@coral-xyz/anchor';
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
||||||
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||||
|
import { OracleJob } from '@switchboard-xyz/common';
|
||||||
// import {
|
// import {
|
||||||
// IOracleConfig,
|
// IOracleConfig,
|
||||||
// NodeOracle,
|
// NodeOracle,
|
||||||
|
@ -325,6 +333,70 @@ export class SwitchboardTestContext {
|
||||||
public static loadKeypair(keypairPath: string): Keypair {
|
public static loadKeypair(keypairPath: string): Keypair {
|
||||||
return loadKeypair(keypairPath);
|
return loadKeypair(keypairPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a feed and wait for it to resolve to a static value
|
||||||
|
* @param params - the aggregator init params and the static value to resolve the feed to
|
||||||
|
* @param timeout - the number of milliseconds to wait before timing out
|
||||||
|
*
|
||||||
|
* Basic usage example:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* let switchboard: SwitchboardTestContext;
|
||||||
|
*
|
||||||
|
* const [staticFeedAccount] = await switchboard.createStaticFeed({
|
||||||
|
* value: 10,
|
||||||
|
* })
|
||||||
|
* const staticFeedValue: Big = await staticFeedAccount.fetchLatestValue();
|
||||||
|
* assert(staticFeedValue.toNumber() === 10, "StaticFeedValueMismatch");
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public async createStaticFeed(
|
||||||
|
params: Partial<CreateQueueFeedParams> & { value: number },
|
||||||
|
timeout = 30000
|
||||||
|
): Promise<[AggregatorAccount, AggregatorAccountData]> {
|
||||||
|
const [aggregatorAccount, aggregatorState] = await createStaticFeed(
|
||||||
|
this.network.queue.account,
|
||||||
|
params,
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
return [aggregatorAccount, aggregatorState];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing aggregator that resolves to a new static value, then await the new result
|
||||||
|
* @param aggregatorAccount - the aggregator account to modify
|
||||||
|
* @param value - the static value the feed will resolve to
|
||||||
|
* @param timeout - the number of milliseconds to wait before timing out
|
||||||
|
*
|
||||||
|
* Basic usage example:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* let switchboard: SwitchboardTestContext;
|
||||||
|
* let staticFeedAccount: AggregatorAccount;
|
||||||
|
*
|
||||||
|
* [staticFeedAccount] = await switchboard.createStaticFeed({
|
||||||
|
* value: 10,
|
||||||
|
* });
|
||||||
|
* const staticFeedValue: Big = await staticFeedAccount.fetchLatestValue();
|
||||||
|
* assert(staticFeedValue.toNumber() === 10, "StaticFeedValueMismatch");
|
||||||
|
*
|
||||||
|
* await switchboard.updateStaticFeed(
|
||||||
|
* staticFeedAccount,
|
||||||
|
* 25
|
||||||
|
* );
|
||||||
|
* staticFeedValue = await staticFeedAccount.fetchLatestValue();
|
||||||
|
* assert(staticFeedValue.toNumber() === 25, "StaticFeedValueMismatch");
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public async updateStaticFeed(
|
||||||
|
aggregatorAccount: AggregatorAccount,
|
||||||
|
value: number,
|
||||||
|
timeout = 30000
|
||||||
|
): Promise<AggregatorAccountData> {
|
||||||
|
const state = await updateStaticFeed(aggregatorAccount, value, timeout);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { SwitchboardTestContext as SwitchboardTestContextV2 };
|
export { SwitchboardTestContext as SwitchboardTestContextV2 };
|
||||||
|
|
|
@ -76,6 +76,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
||||||
*/
|
*/
|
||||||
public static getMetadata = (queue: types.OracleQueueAccountData) =>
|
public static getMetadata = (queue: types.OracleQueueAccountData) =>
|
||||||
toUtf8(queue.metadata);
|
toUtf8(queue.metadata);
|
||||||
|
|
||||||
/** Load an existing QueueAccount with its current on-chain state */
|
/** Load an existing QueueAccount with its current on-chain state */
|
||||||
public static async load(
|
public static async load(
|
||||||
program: SwitchboardProgram,
|
program: SwitchboardProgram,
|
||||||
|
@ -89,46 +90,6 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
||||||
return [account, state];
|
return [account, state];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a oracle queue account state initialized to the default values.
|
|
||||||
*/
|
|
||||||
public static default(): types.OracleQueueAccountData {
|
|
||||||
const buffer = Buffer.alloc(1269, 0);
|
|
||||||
types.OracleQueueAccountData.discriminator.copy(buffer, 0);
|
|
||||||
return types.OracleQueueAccountData.decode(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a mock account info for a given oracle queue config. Useful for test integrations.
|
|
||||||
*/
|
|
||||||
public static createMock(
|
|
||||||
programId: PublicKey,
|
|
||||||
data: Partial<types.OracleQueueAccountData>,
|
|
||||||
options?: {
|
|
||||||
lamports?: number;
|
|
||||||
rentEpoch?: number;
|
|
||||||
}
|
|
||||||
): AccountInfo<Buffer> {
|
|
||||||
const fields: types.OracleQueueAccountDataFields = {
|
|
||||||
...QueueAccount.default(),
|
|
||||||
...data,
|
|
||||||
// any cleanup actions here
|
|
||||||
};
|
|
||||||
const state = new types.OracleQueueAccountData(fields);
|
|
||||||
|
|
||||||
const buffer = Buffer.alloc(QueueAccount.size, 0);
|
|
||||||
types.OracleQueueAccountData.discriminator.copy(buffer, 0);
|
|
||||||
types.OracleQueueAccountData.layout.encode(state, buffer, 8);
|
|
||||||
|
|
||||||
return {
|
|
||||||
executable: false,
|
|
||||||
owner: programId,
|
|
||||||
lamports: options?.lamports ?? 1 * LAMPORTS_PER_SOL,
|
|
||||||
data: buffer,
|
|
||||||
rentEpoch: options?.rentEpoch ?? 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke a callback each time a QueueAccount's data has changed on-chain.
|
* Invoke a callback each time a QueueAccount's data has changed on-chain.
|
||||||
* @param callback - the callback invoked when the queues state changes
|
* @param callback - the callback invoked when the queues state changes
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
import { Keypair } from '@solana/web3.js';
|
import {
|
||||||
|
type AggregatorAccount,
|
||||||
|
type CreateQueueFeedParams,
|
||||||
|
JobAccount,
|
||||||
|
type QueueAccount,
|
||||||
|
} from './accounts';
|
||||||
|
import { type AggregatorAccountData } from './generated';
|
||||||
|
import { TransactionObject } from './TransactionObject';
|
||||||
|
|
||||||
|
import { Keypair, PublicKey } from '@solana/web3.js';
|
||||||
|
import { OracleJob } from '@switchboard-xyz/common';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
@ -25,3 +35,143 @@ export function loadKeypair(keypairPath: string): Keypair {
|
||||||
new Uint8Array(JSON.parse(fs.readFileSync(fullPath, 'utf-8')))
|
new Uint8Array(JSON.parse(fs.readFileSync(fullPath, 'utf-8')))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a feed and wait for it to resolve to a static value
|
||||||
|
* @param queueAccount - the oracle queue to create the feed on
|
||||||
|
* @param params - the aggregator init params and the static value to resolve the feed to
|
||||||
|
* @param timeout - the number of milliseconds to wait before timing out
|
||||||
|
*
|
||||||
|
* Basic usage example:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { createStaticFeed, QueueAccount, AggregatorAccount } from "@switchboard-xyz/solana.js";
|
||||||
|
*
|
||||||
|
* let queueAccount: QueueAccount;
|
||||||
|
* let staticFeedAccount: AggregatorAccount;
|
||||||
|
*
|
||||||
|
* [staticFeedAccount] = await createStaticFeed(queueAccount, {
|
||||||
|
* value: 10,
|
||||||
|
* });
|
||||||
|
* const staticFeedValue: Big = await staticFeedAccount.fetchLatestValue();
|
||||||
|
* assert(staticFeedValue.toNumber() === 10, "StaticFeedValueMismatch");
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export async function createStaticFeed(
|
||||||
|
queueAccount: QueueAccount,
|
||||||
|
params: Partial<CreateQueueFeedParams> & { value: number },
|
||||||
|
timeout = 30000
|
||||||
|
): Promise<[AggregatorAccount, AggregatorAccountData]> {
|
||||||
|
const [aggregatorAccount] = await queueAccount.createFeed({
|
||||||
|
...params,
|
||||||
|
batchSize: params.batchSize ?? 1,
|
||||||
|
minUpdateDelaySeconds: params.minUpdateDelaySeconds ?? 10,
|
||||||
|
minRequiredOracleResults: params.minRequiredOracleResults ?? 1,
|
||||||
|
minRequiredJobResults: params.minRequiredJobResults ?? 1,
|
||||||
|
jobs: [
|
||||||
|
{
|
||||||
|
weight: 1,
|
||||||
|
data: OracleJob.encodeDelimited(
|
||||||
|
OracleJob.fromObject({
|
||||||
|
tasks: [
|
||||||
|
{
|
||||||
|
valueTask: {
|
||||||
|
value: params.value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
).finish(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const [state] = await aggregatorAccount.openRoundAndAwaitResult(
|
||||||
|
undefined,
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
|
||||||
|
return [aggregatorAccount, state];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing aggregator that resolves to a new static value, then await the new result
|
||||||
|
* @param aggregatorAccount - the aggregator account to modify
|
||||||
|
* @param value - the static value the feed will resolve to
|
||||||
|
* @param timeout - the number of milliseconds to wait before timing out
|
||||||
|
*
|
||||||
|
* Basic usage example:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { updateStaticFeed, AggregatorAccount } from "@switchboard-xyz/solana.js";
|
||||||
|
*
|
||||||
|
* let staticFeedAccount: AggregatorAccount;
|
||||||
|
*
|
||||||
|
* const staticFeedState = await updateStaticFeed(staticFeedAccount, 100);
|
||||||
|
* staticFeedValue = AggregatorAccount.decodeLatestValue(staticFeedState);
|
||||||
|
* assert(staticFeedValue.toNumber() === 100, "StaticFeedValueMismatch");
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export async function updateStaticFeed(
|
||||||
|
aggregatorAccount: AggregatorAccount,
|
||||||
|
value: number,
|
||||||
|
timeout = 30000
|
||||||
|
): Promise<AggregatorAccountData> {
|
||||||
|
const aggregator = await aggregatorAccount.loadData();
|
||||||
|
|
||||||
|
const [jobAccount, jobInit] = JobAccount.createInstructions(
|
||||||
|
aggregatorAccount.program,
|
||||||
|
aggregatorAccount.program.walletPubkey,
|
||||||
|
{
|
||||||
|
data: OracleJob.encodeDelimited(
|
||||||
|
OracleJob.create({
|
||||||
|
tasks: [
|
||||||
|
OracleJob.Task.create({
|
||||||
|
valueTask: OracleJob.ValueTask.create({
|
||||||
|
value,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
).finish(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const oldJobKeys = aggregator.jobPubkeysData.filter(
|
||||||
|
pubkey => !pubkey.equals(PublicKey.default)
|
||||||
|
);
|
||||||
|
|
||||||
|
const oldJobs: Array<[JobAccount, number]> = oldJobKeys.map((pubkey, i) => [
|
||||||
|
new JobAccount(aggregatorAccount.program, pubkey),
|
||||||
|
i,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const removeJobTxns = oldJobs.map(job =>
|
||||||
|
aggregatorAccount.removeJobInstruction(
|
||||||
|
aggregatorAccount.program.walletPubkey,
|
||||||
|
{
|
||||||
|
job: job[0],
|
||||||
|
jobIdx: job[1],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const addJobTxn = aggregatorAccount.addJobInstruction(
|
||||||
|
aggregatorAccount.program.walletPubkey,
|
||||||
|
{ job: jobAccount }
|
||||||
|
);
|
||||||
|
|
||||||
|
const txns = TransactionObject.pack([
|
||||||
|
...jobInit,
|
||||||
|
...removeJobTxns,
|
||||||
|
addJobTxn,
|
||||||
|
]);
|
||||||
|
await aggregatorAccount.program.signAndSendAll(txns);
|
||||||
|
|
||||||
|
const [state] = await aggregatorAccount.openRoundAndAwaitResult(
|
||||||
|
undefined,
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
|
@ -18,5 +18,5 @@ cpi = ["no-entrypoint"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
||||||
# switchboard-v2 = { version = "^0.1.23" }
|
# switchboard-v2 = { version = "^0.1.23" }
|
||||||
anchor-lang = "^0.27.0"
|
anchor-lang = "^0.26.0"
|
||||||
solana-program = "~1.14.0"
|
solana-program = "~1.14.0"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,6 @@ cpi = ["no-entrypoint"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
||||||
# switchboard-v2 = { version = "0.1.23" }
|
# switchboard-v2 = { version = "0.1.23" }
|
||||||
anchor-lang = "^0.27.0"
|
anchor-lang = "^0.26.0"
|
||||||
solana-program = "~1.14.0"
|
solana-program = "~1.14.0"
|
||||||
bytemuck = "1.7.2"
|
bytemuck = "1.13.1"
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import * as anchor from "@coral-xyz/anchor";
|
import * as anchor from "@coral-xyz/anchor";
|
||||||
import { OracleJob, sleep } from "@switchboard-xyz/common";
|
import { Big, OracleJob, sleep } from "@switchboard-xyz/common";
|
||||||
import {
|
import {
|
||||||
AggregatorAccount,
|
AggregatorAccount,
|
||||||
SwitchboardTestContext,
|
SwitchboardTestContext,
|
||||||
|
types,
|
||||||
} from "@switchboard-xyz/solana.js";
|
} from "@switchboard-xyz/solana.js";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { AnchorFeedParser } from "../target/types/anchor_feed_parser";
|
import { AnchorFeedParser } from "../target/types/anchor_feed_parser";
|
||||||
|
@ -116,4 +117,26 @@ describe("anchor-feed-parser test", () => {
|
||||||
console.log(`Feed Result: ${feedResult}`);
|
console.log(`Feed Result: ${feedResult}`);
|
||||||
assert(feedResult === 100, "FeedResultMismatch");
|
assert(feedResult === 100, "FeedResultMismatch");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Creates a static feed then updates the value", async () => {
|
||||||
|
let staticFeedAccount: AggregatorAccount;
|
||||||
|
let staticFeedState: types.AggregatorAccountData;
|
||||||
|
let staticFeedValue: Big;
|
||||||
|
[staticFeedAccount, staticFeedState] = await switchboard.createStaticFeed({
|
||||||
|
value: 10,
|
||||||
|
minUpdateDelaySeconds: 5,
|
||||||
|
});
|
||||||
|
|
||||||
|
staticFeedValue = AggregatorAccount.decodeLatestValue(staticFeedState);
|
||||||
|
|
||||||
|
assert(staticFeedValue.toNumber() === 10, "StaticFeedValueMismatch");
|
||||||
|
|
||||||
|
await sleep(5000 * 2);
|
||||||
|
|
||||||
|
staticFeedState = await switchboard.updateStaticFeed(staticFeedAccount, 25);
|
||||||
|
|
||||||
|
staticFeedValue = AggregatorAccount.decodeLatestValue(staticFeedState);
|
||||||
|
|
||||||
|
assert(staticFeedValue.toNumber() === 25, "StaticFeedValueMismatch");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,5 +21,5 @@ overflow-checks = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
||||||
# switchboard-v2 = { version = "^0.1.23" }
|
# switchboard-v2 = { version = "^0.1.23" }
|
||||||
anchor-lang = "^0.27.0"
|
anchor-lang = "^0.26.0"
|
||||||
solana-program = "^1.13.6"
|
solana-program = "~1.14.0"
|
||||||
|
|
|
@ -18,7 +18,7 @@ cpi = ["no-entrypoint"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
||||||
# switchboard-v2 = { version = "^0.1.23" }
|
# switchboard-v2 = { version = "^0.1.23" }
|
||||||
anchor-lang = "^0.27.0"
|
anchor-lang = "^0.26.0"
|
||||||
anchor-spl = "^0.27.0"
|
anchor-spl = "^0.26.0"
|
||||||
solana-program = "~1.14.0"
|
solana-program = "~1.14.0"
|
||||||
bytemuck = "1.7.2"
|
bytemuck = "1.13.1"
|
||||||
|
|
|
@ -18,7 +18,7 @@ cpi = ["no-entrypoint"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
switchboard-v2 = { path = "../../rust/switchboard-v2" }
|
||||||
# switchboard-v2 = { version = "^0.1.23" }
|
# switchboard-v2 = { version = "^0.1.23" }
|
||||||
anchor-lang = "^0.27.0"
|
anchor-lang = "^0.26.0"
|
||||||
anchor-spl = "^0.27.0"
|
anchor-spl = "^0.26.0"
|
||||||
solana-program = "~1.14.0"
|
solana-program = "~1.14.0"
|
||||||
bytemuck = "1.7.2"
|
bytemuck = "1.13.1"
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
/target
|
/target
|
||||||
Cargo.lock
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,10 +21,15 @@ no-entrypoint = []
|
||||||
cpi = ["no-entrypoint"]
|
cpi = ["no-entrypoint"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anchor-lang = "~0.27.0"
|
|
||||||
anchor-spl = "~0.27.0"
|
|
||||||
rust_decimal = "=1.26.1"
|
rust_decimal = "=1.26.1"
|
||||||
solana-program = "^1.13.5"
|
bytemuck = "1.13.1"
|
||||||
bytemuck = "1.7.2"
|
|
||||||
superslice = "1"
|
superslice = "1"
|
||||||
spl-token = "3.5"
|
solana-program = ">= 1.13.5, < 1.15.0"
|
||||||
|
anchor-lang = "0.26.0"
|
||||||
|
anchor-spl = "0.26.0"
|
||||||
|
# https://github.com/coral-xyz/anchor/issues/2502
|
||||||
|
# anchor-lang = { git = "https://github.com/coral-xyz/anchor", version = "0.27.0" }
|
||||||
|
# anchor-spl = { git = "https://github.com/coral-xyz/anchor", version = "0.27.0" }
|
||||||
|
toml_datetime = "=0.6.1"
|
||||||
|
winnow = "=0.4.1"
|
||||||
|
toml_edit = "=0.19.8"
|
||||||
|
|
|
@ -5,7 +5,7 @@ use anchor_lang::Discriminator;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
pub struct Hash {
|
pub struct Hash {
|
||||||
|
@ -13,7 +13,7 @@ pub struct Hash {
|
||||||
pub data: [u8; 32],
|
pub data: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
#[derive(Default, Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
pub struct AggregatorRound {
|
pub struct AggregatorRound {
|
||||||
|
@ -54,14 +54,14 @@ pub enum AggregatorResolutionMode {
|
||||||
ModeRoundResolution = 0,
|
ModeRoundResolution = 0,
|
||||||
ModeSlidingResolution = 1,
|
ModeSlidingResolution = 1,
|
||||||
}
|
}
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct SlidingResultAccountData {
|
pub struct SlidingResultAccountData {
|
||||||
pub data: [SlidingWindowElement; 16],
|
pub data: [SlidingWindowElement; 16],
|
||||||
pub bump: u8,
|
pub bump: u8,
|
||||||
pub _ebuf: [u8; 512],
|
pub _ebuf: [u8; 512],
|
||||||
}
|
}
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct SlidingWindowElement {
|
pub struct SlidingWindowElement {
|
||||||
|
@ -72,7 +72,7 @@ pub struct SlidingWindowElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[zero_copy]
|
// #[zero_copy]
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct AggregatorAccountData {
|
pub struct AggregatorAccountData {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct CrankRow {
|
pub struct CrankRow {
|
||||||
|
@ -13,7 +13,7 @@ pub struct CrankRow {
|
||||||
unsafe impl Pod for CrankRow {}
|
unsafe impl Pod for CrankRow {}
|
||||||
unsafe impl Zeroable for CrankRow {}
|
unsafe impl Zeroable for CrankRow {}
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct CrankAccountData {
|
pub struct CrankAccountData {
|
||||||
/// Name of the crank to store on-chain.
|
/// Name of the crank to store on-chain.
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use std::convert::{From, TryInto};
|
use std::convert::{From, TryInto};
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
#[derive(Default, Debug, Eq, PartialEq)]
|
#[derive(Default, Debug, Eq, PartialEq)]
|
||||||
pub struct SwitchboardDecimal {
|
pub struct SwitchboardDecimal {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct AccountMetaZC {
|
pub struct AccountMetaZC {
|
||||||
pub pubkey: Pubkey,
|
pub pubkey: Pubkey,
|
||||||
|
@ -10,7 +10,7 @@ pub struct AccountMetaZC {
|
||||||
pub is_writable: bool,
|
pub is_writable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
#[derive(AnchorSerialize, AnchorDeserialize)]
|
#[derive(AnchorSerialize, AnchorDeserialize)]
|
||||||
pub struct AccountMetaBorsh {
|
pub struct AccountMetaBorsh {
|
||||||
|
@ -19,7 +19,7 @@ pub struct AccountMetaBorsh {
|
||||||
pub is_writable: bool,
|
pub is_writable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct CallbackZC {
|
pub struct CallbackZC {
|
||||||
/// The program ID of the callback program being invoked.
|
/// The program ID of the callback program being invoked.
|
||||||
|
@ -49,7 +49,7 @@ pub struct Callback {
|
||||||
pub ix_data: Vec<u8>,
|
pub ix_data: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct VrfRound {
|
pub struct VrfRound {
|
||||||
/// The alpha bytes used to calculate the VRF proof.
|
/// The alpha bytes used to calculate the VRF proof.
|
||||||
|
@ -101,7 +101,7 @@ impl std::fmt::Display for VrfStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct EcvrfProofZC {
|
pub struct EcvrfProofZC {
|
||||||
pub Gamma: EdwardsPointZC, // RistrettoPoint
|
pub Gamma: EdwardsPointZC, // RistrettoPoint
|
||||||
|
@ -117,7 +117,7 @@ impl Default for EcvrfProofZC {
|
||||||
/// The `Scalar` struct holds an integer \\(s < 2\^{255} \\) which
|
/// The `Scalar` struct holds an integer \\(s < 2\^{255} \\) which
|
||||||
/// represents an element of \\(\mathbb Z / \ell\\).
|
/// represents an element of \\(\mathbb Z / \ell\\).
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct Scalar {
|
pub struct Scalar {
|
||||||
/// `bytes` is a little-endian byte encoding of an integer representing a scalar modulo the
|
/// `bytes` is a little-endian byte encoding of an integer representing a scalar modulo the
|
||||||
|
@ -158,7 +158,7 @@ pub struct FieldElement51(pub(crate) [u64; 5]);
|
||||||
unsafe impl Pod for FieldElement51 {}
|
unsafe impl Pod for FieldElement51 {}
|
||||||
unsafe impl Zeroable for FieldElement51 {}
|
unsafe impl Zeroable for FieldElement51 {}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct FieldElementZC {
|
pub struct FieldElementZC {
|
||||||
pub(crate) bytes: [u64; 5],
|
pub(crate) bytes: [u64; 5],
|
||||||
|
@ -197,7 +197,7 @@ pub struct CompletedPoint {
|
||||||
pub Z: FieldElement51,
|
pub Z: FieldElement51,
|
||||||
pub T: FieldElement51,
|
pub T: FieldElement51,
|
||||||
}
|
}
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct CompletedPointZC {
|
pub struct CompletedPointZC {
|
||||||
pub X: FieldElementZC,
|
pub X: FieldElementZC,
|
||||||
|
@ -243,7 +243,7 @@ pub struct EdwardsPoint {
|
||||||
pub(crate) T: FieldElement51,
|
pub(crate) T: FieldElement51,
|
||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct EdwardsPointZC {
|
pub struct EdwardsPointZC {
|
||||||
pub(crate) X: FieldElementZC,
|
pub(crate) X: FieldElementZC,
|
||||||
|
@ -271,7 +271,7 @@ pub struct ProjectivePoint {
|
||||||
pub Y: FieldElement51,
|
pub Y: FieldElement51,
|
||||||
pub Z: FieldElement51,
|
pub Z: FieldElement51,
|
||||||
}
|
}
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct ProjectivePointZC {
|
pub struct ProjectivePointZC {
|
||||||
pub(crate) X: FieldElementZC,
|
pub(crate) X: FieldElementZC,
|
||||||
|
@ -304,7 +304,7 @@ impl Into<ProjectivePoint> for ProjectivePointZC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct EcvrfIntermediate {
|
pub struct EcvrfIntermediate {
|
||||||
pub r: FieldElementZC,
|
pub r: FieldElementZC,
|
||||||
|
@ -317,7 +317,7 @@ unsafe impl Pod for EcvrfIntermediate {}
|
||||||
unsafe impl Zeroable for EcvrfIntermediate {}
|
unsafe impl Zeroable for EcvrfIntermediate {}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct VrfBuilder {
|
pub struct VrfBuilder {
|
||||||
/// The OracleAccountData that is producing the randomness.
|
/// The OracleAccountData that is producing the randomness.
|
||||||
|
|
|
@ -6,7 +6,7 @@ use bytemuck::{Pod, Zeroable};
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
use superslice::*;
|
use superslice::*;
|
||||||
|
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct AggregatorHistoryRow {
|
pub struct AggregatorHistoryRow {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct LeaseAccountData {
|
pub struct LeaseAccountData {
|
||||||
/// Public key of the token account holding the lease contract funds until rewarded to oracles for successfully processing updates
|
/// Public key of the token account holding the lease contract funds until rewarded to oracles for successfully processing updates
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub enum OracleResponseType {
|
||||||
TypeDisagreement,
|
TypeDisagreement,
|
||||||
TypeNoResponse,
|
TypeNoResponse,
|
||||||
}
|
}
|
||||||
#[zero_copy(unsafe)]
|
#[zero_copy]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct OracleMetrics {
|
pub struct OracleMetrics {
|
||||||
|
@ -31,7 +31,7 @@ pub struct OracleMetrics {
|
||||||
pub total_late_response: u128,
|
pub total_late_response: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct OracleAccountData {
|
pub struct OracleAccountData {
|
||||||
/// Name of the oracle to store on-chain.
|
/// Name of the oracle to store on-chain.
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub enum SwitchboardPermission {
|
||||||
PermitVrfRequests = 1 << 2,
|
PermitVrfRequests = 1 << 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct PermissionAccountData {
|
pub struct PermissionAccountData {
|
||||||
/// The authority that is allowed to set permissions for this account.
|
/// The authority that is allowed to set permissions for this account.
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::decimal::SwitchboardDecimal;
|
||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
use bytemuck::try_cast_slice_mut;
|
use bytemuck::try_cast_slice_mut;
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct OracleQueueAccountData {
|
pub struct OracleQueueAccountData {
|
||||||
/// Name of the queue to store on-chain.
|
/// Name of the queue to store on-chain.
|
||||||
|
@ -76,7 +76,7 @@ impl OracleQueueAccountData {
|
||||||
|
|
||||||
pub fn get_mint(&self) -> Pubkey {
|
pub fn get_mint(&self) -> Pubkey {
|
||||||
if self.mint == Pubkey::default() {
|
if self.mint == Pubkey::default() {
|
||||||
return spl_token::native_mint::ID;
|
return anchor_spl::token::ID;
|
||||||
}
|
}
|
||||||
self.mint
|
self.mint
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct SbState {
|
pub struct SbState {
|
||||||
/// The account authority permitted to make account changes.
|
/// The account authority permitted to make account changes.
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::cell::Ref;
|
||||||
// VrfSetCallback
|
// VrfSetCallback
|
||||||
// VrfClose
|
// VrfClose
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct VrfAccountData {
|
pub struct VrfAccountData {
|
||||||
/// The current status of the VRF account.
|
/// The current status of the VRF account.
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::cell::Ref;
|
||||||
// VrfLiteRequestRandomnessParams
|
// VrfLiteRequestRandomnessParams
|
||||||
// VrfLiteCloseParams
|
// VrfLiteCloseParams
|
||||||
|
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
pub struct VrfLiteAccountData {
|
pub struct VrfLiteAccountData {
|
||||||
/// The bump used to derive the SbState account.
|
/// The bump used to derive the SbState account.
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub struct VrfPoolRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
#[account(zero_copy(unsafe))]
|
#[account(zero_copy)]
|
||||||
pub struct VrfPoolAccountData {
|
pub struct VrfPoolAccountData {
|
||||||
/// ACCOUNTS
|
/// ACCOUNTS
|
||||||
pub authority: Pubkey, // authority can never be changed or else vrf accounts are useless
|
pub authority: Pubkey, // authority can never be changed or else vrf accounts are useless
|
||||||
|
|
Loading…
Reference in New Issue