This commit is contained in:
Conner Gallagher 2023-06-13 15:00:48 -06:00
parent 42e02e6e2f
commit d4c46e3db9
32 changed files with 493 additions and 363 deletions

8
.changeset/README.md Normal file
View File

@ -0,0 +1,8 @@
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

11
.changeset/config.json Normal file
View File

@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}

View File

@ -797,6 +797,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "hmac" name = "hmac"
version = "0.8.1" version = "0.8.1"
@ -1755,8 +1764,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
[[package]] [[package]]
name = "switchboard-v2" name = "switchboard-common"
version = "0.1.23" version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3432650dcf9ba9f8512ecd2d2424dba1accd21a2f57019964f193087fda7b4"
dependencies = [
"hex",
"serde",
"serde_json",
"sha2 0.10.6",
]
[[package]]
name = "switchboard-solana"
version = "0.0.1"
dependencies = [ dependencies = [
"anchor-lang", "anchor-lang",
"anchor-spl", "anchor-spl",
@ -1764,6 +1785,7 @@ dependencies = [
"rust_decimal", "rust_decimal",
"solana-program", "solana-program",
"superslice", "superslice",
"switchboard-common",
"toml_datetime", "toml_datetime",
"toml_edit", "toml_edit",
"winnow", "winnow",
@ -1777,7 +1799,7 @@ dependencies = [
"anchor-spl", "anchor-spl",
"bytemuck", "bytemuck",
"solana-program", "solana-program",
"switchboard-v2", "switchboard-solana",
] ]
[[package]] [[package]]

View File

@ -212,6 +212,91 @@ importers:
specifier: ^4.9.3 specifier: ^4.9.3
version: 4.9.4 version: 4.9.4
examples/03_basic_function:
dependencies:
'@coral-xyz/anchor':
specifier: ^0.27.0
version: 0.27.0
'@coral-xyz/borsh':
specifier: ^0.27.0
version: 0.27.0(@solana/web3.js@1.73.3)
'@project-serum/borsh':
specifier: ^0.2.5
version: 0.2.5(@solana/web3.js@1.73.3)
'@solana/spl-token':
specifier: ^0.3.6
version: 0.3.6(@solana/web3.js@1.73.3)
'@solana/web3.js':
specifier: ^1.73.3
version: 1.73.3
'@switchboard-xyz/common':
specifier: ^2.2.0
version: 2.2.0
'@switchboard-xyz/oracle':
specifier: ^2.1.13
version: 2.1.13
'@switchboard-xyz/solana.js':
specifier: workspace:*
version: link:../../javascript/solana.js
chalk:
specifier: ^4.1.2
version: 4.1.2
dotenv:
specifier: ^16.0.1
version: 16.0.3
yargs:
specifier: ^17.5.1
version: 17.6.2
devDependencies:
'@types/chai':
specifier: ^4.3.0
version: 4.3.4
'@types/mocha':
specifier: ^9.0.0
version: 9.1.1
'@types/node':
specifier: ^17.0.45
version: 17.0.45
'@typescript-eslint/eslint-plugin':
specifier: ^5.44.0
version: 5.44.0(@typescript-eslint/parser@5.44.0)(eslint@8.42.0)(typescript@4.9.4)
'@typescript-eslint/parser':
specifier: ^5.44.0
version: 5.44.0(eslint@8.42.0)(typescript@4.9.4)
chai:
specifier: ^4.3.6
version: 4.3.7
eslint:
specifier: ^8.28.0
version: 8.42.0
mocha:
specifier: ^9.0.3
version: 9.2.2
npm-run-all:
specifier: ^4.1.5
version: 4.1.5
prettier:
specifier: ^2.4.1
version: 2.7.1
prettier-plugin-organize-imports:
specifier: ^2.3.4
version: 2.3.4(prettier@2.7.1)(typescript@4.9.4)
shx:
specifier: ^0.3.4
version: 0.3.4
switchboard-solana:
specifier: workspace:*
version: link:../../rust/switchboard-solana
ts-mocha:
specifier: ^9.0.2
version: 9.0.2(mocha@9.2.2)
ts-node:
specifier: ^10.9.1
version: 10.9.1(@types/node@17.0.45)(typescript@4.9.4)
typescript:
specifier: ^4.9.3
version: 4.9.4
javascript/feed-walkthrough: javascript/feed-walkthrough:
dependencies: dependencies:
'@solana/web3.js': '@solana/web3.js':
@ -7139,7 +7224,7 @@ packages:
file:javascript/solana.js: file:javascript/solana.js:
resolution: {directory: javascript/solana.js, type: directory} resolution: {directory: javascript/solana.js, type: directory}
name: '@switchboard-xyz/solana.js' name: '@switchboard-xyz/solana.js'
version: 2.3.0-beta.5 version: 2.3.0-beta.6
engines: {node: '>=16.0.0', npm: '>=7.0.0'} engines: {node: '>=16.0.0', npm: '>=7.0.0'}
dependencies: dependencies:
'@coral-xyz/anchor': 0.27.0 '@coral-xyz/anchor': 0.27.0

View File

@ -91,25 +91,11 @@ dependencies = [
[[package]] [[package]]
name = "anchor-attribute-access-control" name = "anchor-attribute-access-control"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf7d535e1381be3de2c0716c0a1c1e32ad9df1042cddcf7bc18d743569e53319" checksum = "faa5be5b72abea167f87c868379ba3c2be356bfca9e6f474fd055fa0f7eeb4f2"
dependencies = [ dependencies = [
"anchor-syn 0.26.0", "anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"regex",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-access-control"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d5e1a413b311b039d29b61d0dbb401c9dbf04f792497ceca87593454bf6d7dd"
dependencies = [
"anchor-syn 0.27.0",
"anyhow", "anyhow",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
@ -119,28 +105,13 @@ dependencies = [
[[package]] [[package]]
name = "anchor-attribute-account" name = "anchor-attribute-account"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3bcd731f21048a032be27c7791701120e44f3f6371358fc4261a7f716283d29" checksum = "f468970344c7c9f9d03b4da854fd7c54f21305059f53789d0045c1dd803f0018"
dependencies = [ dependencies = [
"anchor-syn 0.26.0", "anchor-syn",
"anyhow", "anyhow",
"bs58 0.4.0", "bs58 0.5.0",
"proc-macro2 1.0.59",
"quote 1.0.28",
"rustversion",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-account"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cca9aeaf633c6e2365fed0525dcac68610be58eee5dc69d3b86fe0b1d4b320b9"
dependencies = [
"anchor-syn 0.27.0",
"anyhow",
"bs58 0.4.0",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
"rustversion", "rustversion",
@ -149,45 +120,22 @@ dependencies = [
[[package]] [[package]]
name = "anchor-attribute-constant" name = "anchor-attribute-constant"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1be64a48e395fe00b8217287f226078be2cf32dae42fdf8a885b997945c3d28" checksum = "59948e7f9ef8144c2aefb3f32a40c5fce2798baeec765ba038389e82301017ef"
dependencies = [ dependencies = [
"anchor-syn 0.26.0", "anchor-syn",
"proc-macro2 1.0.59",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-constant"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "788e44f9e8501dabeb6f9229da0f3268fb2ae3208912608ffaa056a72031296f"
dependencies = [
"anchor-syn 0.27.0",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]] [[package]]
name = "anchor-attribute-error" name = "anchor-attribute-error"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38ea6713d1938c0da03656ff8a693b17dc0396da66d1ba320557f07e86eca0d4" checksum = "fc753c9d1c7981cb8948cf7e162fb0f64558999c0413058e2d43df1df5448086"
dependencies = [ dependencies = [
"anchor-syn 0.26.0", "anchor-syn",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-error"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c4d8c7e4a2605ede6fcdced9690288b2f74e24768619a85229d57e597bc97"
dependencies = [
"anchor-syn 0.27.0",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
"syn 1.0.109", "syn 1.0.109",
@ -195,51 +143,11 @@ dependencies = [
[[package]] [[package]]
name = "anchor-attribute-event" name = "anchor-attribute-event"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d401f11efb3644285685f8339829a9786d43ed7490bb1699f33c478d04d5a582" checksum = "f38b4e172ba1b52078f53fdc9f11e3dc0668ad27997838a0aad2d148afac8c97"
dependencies = [ dependencies = [
"anchor-syn 0.26.0", "anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-event"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a3b07d5c5d87b5edc72428b447b8e9ee1143b83dd1afc6a6b1d352c6a6164d8"
dependencies = [
"anchor-syn 0.27.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-interface"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6700a6f5c888a9c33fe8afc0c64fd8575fa28d05446037306d0f96102ae4480"
dependencies = [
"anchor-syn 0.26.0",
"anyhow",
"heck",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-program"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ad769993b5266714e8939e47fbdede90e5c030333c7522d99a4d4748cf26712"
dependencies = [
"anchor-syn 0.26.0",
"anyhow", "anyhow",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
@ -248,54 +156,11 @@ dependencies = [
[[package]] [[package]]
name = "anchor-attribute-program" name = "anchor-attribute-program"
version = "0.27.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b22ad0445115dbea5869b1d062da49ae125abed9132fc20c33227f25e42dfa6b" checksum = "4eebd21543606ab61e2d83d9da37d24d3886a49f390f9c43a1964735e8c0f0d5"
dependencies = [ dependencies = [
"anchor-syn 0.27.0", "anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-state"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e677fae4a016a554acdd0e3b7f178d3acafaa7e7ffac6b8690cf4e171f1c116"
dependencies = [
"anchor-syn 0.26.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-client"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04c06e06497b5b4f392845e0d04dde8374fd244fa2832dd0e5c27bfd99cb0342"
dependencies = [
"anchor-lang 0.27.0",
"anyhow",
"regex",
"serde",
"solana-account-decoder",
"solana-client",
"solana-sdk",
"thiserror",
"url",
]
[[package]]
name = "anchor-derive-accounts"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "340beef6809d1c3fcc7ae219153d981e95a8a277ff31985bd7050e32645dc9a8"
dependencies = [
"anchor-syn 0.26.0",
"anyhow", "anyhow",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
@ -304,11 +169,11 @@ dependencies = [
[[package]] [[package]]
name = "anchor-derive-accounts" name = "anchor-derive-accounts"
version = "0.27.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48daeff6781ba2f02961b0ad211feb9a2de75af345d42c62b1a252fd4dfb0724" checksum = "ec4720d899b3686396cced9508f23dab420f1308344456ec78ef76f98fda42af"
dependencies = [ dependencies = [
"anchor-syn 0.27.0", "anchor-syn",
"anyhow", "anyhow",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
@ -317,9 +182,9 @@ dependencies = [
[[package]] [[package]]
name = "anchor-derive-space" name = "anchor-derive-space"
version = "0.27.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4fe2886f92c4f33ec1b2b8b2b43ca1b9070cf4929e63c7eaaa09a9f2c0d5123" checksum = "f495e85480bd96ddeb77b71d499247c7d4e8b501e75ecb234e9ef7ae7bd6552a"
dependencies = [ dependencies = [
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
@ -328,96 +193,55 @@ dependencies = [
[[package]] [[package]]
name = "anchor-lang" name = "anchor-lang"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "662ceafe667448ee4199a4be2ee83b6bb76da28566eee5cea05f96ab38255af8" checksum = "0d2d4b20100f1310a774aba3471ef268e5c4ba4d5c28c0bbe663c2658acbc414"
dependencies = [ dependencies = [
"anchor-attribute-access-control 0.26.0", "anchor-attribute-access-control",
"anchor-attribute-account 0.26.0", "anchor-attribute-account",
"anchor-attribute-constant 0.26.0", "anchor-attribute-constant",
"anchor-attribute-error 0.26.0", "anchor-attribute-error",
"anchor-attribute-event 0.26.0", "anchor-attribute-event",
"anchor-attribute-interface", "anchor-attribute-program",
"anchor-attribute-program 0.26.0", "anchor-derive-accounts",
"anchor-attribute-state",
"anchor-derive-accounts 0.26.0",
"arrayref",
"base64 0.13.1",
"bincode",
"borsh",
"bytemuck",
"solana-program",
"thiserror",
]
[[package]]
name = "anchor-lang"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbbe5d1c7c057c6d63b4f2f538a320e4a22111126c9966340c3d9490e2f15ed1"
dependencies = [
"anchor-attribute-access-control 0.27.0",
"anchor-attribute-account 0.27.0",
"anchor-attribute-constant 0.27.0",
"anchor-attribute-error 0.27.0",
"anchor-attribute-event 0.27.0",
"anchor-attribute-program 0.27.0",
"anchor-derive-accounts 0.27.0",
"anchor-derive-space", "anchor-derive-space",
"arrayref", "arrayref",
"base64 0.13.1", "base64 0.13.1",
"bincode", "bincode",
"borsh", "borsh",
"bytemuck", "bytemuck",
"getrandom 0.2.9",
"solana-program", "solana-program",
"thiserror", "thiserror",
] ]
[[package]] [[package]]
name = "anchor-spl" name = "anchor-spl"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f32390ce8356f54c0f0245ea156f8190717e37285b8bf4f406a613dc4b954cde" checksum = "78f860599da1c2354e7234c768783049eb42e2f54509ecfc942d2e0076a2da7b"
dependencies = [ dependencies = [
"anchor-lang 0.26.0", "anchor-lang",
"solana-program", "solana-program",
"spl-associated-token-account", "spl-associated-token-account",
"spl-token", "spl-token",
"spl-token-2022",
] ]
[[package]] [[package]]
name = "anchor-syn" name = "anchor-syn"
version = "0.26.0" version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0418bcb5daac3b8cb1b60d8fdb1d468ca36f5509f31fb51179326fae1028fdcc" checksum = "a125e4b0cc046cfec58f5aa25038e34cf440151d58f0db3afc55308251fe936d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bs58 0.3.1", "bs58 0.5.0",
"heck",
"proc-macro2 1.0.59",
"proc-macro2-diagnostics",
"quote 1.0.28",
"serde",
"serde_json",
"sha2 0.9.9",
"syn 1.0.109",
"thiserror",
]
[[package]]
name = "anchor-syn"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11cb31fe143aedb36fc41409ea072aa0b840cbea727e62eb2ff6e7b6cea036ff"
dependencies = [
"anyhow",
"bs58 0.3.1",
"heck", "heck",
"proc-macro2 1.0.59", "proc-macro2 1.0.59",
"quote 1.0.28", "quote 1.0.28",
"serde", "serde",
"serde_json", "serde_json",
"sha2 0.9.9", "sha2 0.10.6",
"syn 1.0.109", "syn 1.0.109",
"thiserror", "thiserror",
] ]
@ -719,18 +543,21 @@ dependencies = [
"alloc-stdlib", "alloc-stdlib",
] ]
[[package]]
name = "bs58"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb"
[[package]] [[package]]
name = "bs58" name = "bs58"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bs58"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896"
dependencies = [
"tinyvec",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.13.0" version = "3.13.0"
@ -2396,19 +2223,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "proc-macro2-diagnostics"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada"
dependencies = [
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
"version_check",
"yansi",
]
[[package]] [[package]]
name = "qstring" name = "qstring"
version = "0.7.2" version = "0.7.2"
@ -3785,9 +3599,9 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
[[package]] [[package]]
name = "switchboard-common" name = "switchboard-common"
version = "0.0.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3432650dcf9ba9f8512ecd2d2424dba1accd21a2f57019964f193087fda7b4" checksum = "4e684527505239852153ac6b4b27789815441a2b840564466cb6e47b25f543b3"
dependencies = [ dependencies = [
"getrandom 0.2.9", "getrandom 0.2.9",
"hex", "hex",
@ -3799,10 +3613,9 @@ dependencies = [
[[package]] [[package]]
name = "switchboard-solana" name = "switchboard-solana"
version = "0.0.1" version = "0.3.1"
dependencies = [ dependencies = [
"anchor-client", "anchor-lang",
"anchor-lang 0.26.0",
"anchor-spl", "anchor-spl",
"bincode", "bincode",
"bytemuck", "bytemuck",
@ -3810,12 +3623,11 @@ dependencies = [
"cron", "cron",
"rust_decimal", "rust_decimal",
"sgx-quote", "sgx-quote",
"solana-client",
"solana-program", "solana-program",
"solana-sdk",
"superslice", "superslice",
"switchboard-common", "switchboard-common",
"toml_datetime",
"toml_edit",
"winnow",
] ]
[[package]] [[package]]
@ -4637,12 +4449,6 @@ dependencies = [
"linked-hash-map", "linked-hash-map",
] ]
[[package]]
name = "yansi"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]] [[package]]
name = "yasna" name = "yasna"
version = "0.5.2" version = "0.5.2"

View File

@ -1,6 +1,6 @@
[package] [package]
name = "switchboard-solana" name = "switchboard-solana"
version = "0.0.1" version = "0.3.1"
edition = "2021" edition = "2021"
description = "A Rust library to interact with Switchboard accounts." description = "A Rust library to interact with Switchboard accounts."
readme = "README.md" readme = "README.md"
@ -21,7 +21,7 @@ no-entrypoint = []
cpi = ["no-entrypoint"] cpi = ["no-entrypoint"]
client = [ client = [
"switchboard-common/sgx", "switchboard-common/sgx",
"dep:anchor-client", "dep:solana-client",
"dep:bincode", "dep:bincode",
"dep:sgx-quote", "dep:sgx-quote",
"dep:cron", "dep:cron",
@ -29,19 +29,17 @@ client = [
] ]
[dependencies] [dependencies]
switchboard-common = { version = "0.0.1" } switchboard-common = { version = "0.1.1" }
rust_decimal = "1" rust_decimal = "^1"
bytemuck = "1.13.1" bytemuck = "^1"
superslice = "1" superslice = "1"
anchor-lang = "0.26.0" anchor-lang = "0.28.0"
anchor-spl = "0.26.0" anchor-spl = "0.28.0"
solana-program = ">= 1.13.5, < 1.15" solana-program = ">= 1.14, < 1.17"
# These may not be needed, anchor27 keeps complaining solana-sdk = ">= 1.14, < 1.17"
winnow = "=0.4.1" solana-client = { version = ">= 1.14, < 1.17", optional = true }
toml_edit = "=0.19.8" # anchor-client = { version = "0.28.0", optional = true }
toml_datetime = "=0.6.1" bincode = { version = "^1", optional = true }
anchor-client = { version = "0.27.0", optional = true }
bincode = { version = "1.3.3", optional = true }
sgx-quote = { version = "0.1.0", optional = true } sgx-quote = { version = "0.1.0", optional = true }
cron = { version = "0.12.0", optional = true } cron = { version = "0.12.0", optional = true }
chrono = { version = "0.4.25", optional = true } chrono = { version = "0.4.25", optional = true }

View File

@ -11,7 +11,7 @@ pub enum SwitchboardAttestationPermission {
PermitQueueUsage = 1 << 1, PermitQueueUsage = 1 << 1,
} }
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Debug)] #[derive(Debug)]
pub struct AttestationPermissionAccountData { pub struct AttestationPermissionAccountData {
@ -108,13 +108,11 @@ impl AttestationPermissionAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &anchor_client::Client< client: &solana_client::rpc_client::RpcClient,
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
} }

View File

@ -5,7 +5,7 @@ use std::cell::Ref;
use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID; use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Debug)] #[derive(Debug)]
pub struct AttestationQueueAccountData { pub struct AttestationQueueAccountData {
@ -115,10 +115,9 @@ impl AttestationQueueAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &anchor_client::Client< client: &solana_client::rpc_client::RpcClient,
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await

View File

@ -4,7 +4,7 @@ use bytemuck::{Pod, Zeroable};
use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID; use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Debug)] #[derive(Debug)]
pub struct AttestationState { pub struct AttestationState {

View File

@ -15,18 +15,16 @@ pub enum FunctionStatus {
InvalidPermissions = 1 << 4, InvalidPermissions = 1 << 4,
} }
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct FunctionAccountData { pub struct FunctionAccountData {
pub name: [u8; 64], pub name: [u8; 64],
pub metadata: [u8; 256], pub metadata: [u8; 256],
pub authority: Pubkey, pub authority: Pubkey,
///
pub container_registry: [u8; 64], pub container_registry: [u8; 64],
pub container: [u8; 64], pub container: [u8; 64],
pub version: [u8; 32], pub version: [u8; 32],
///
pub attestation_queue: Pubkey, pub attestation_queue: Pubkey,
pub queue_idx: u32, pub queue_idx: u32,
pub last_execution_timestamp: i64, pub last_execution_timestamp: i64,
@ -164,6 +162,7 @@ impl FunctionAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn get_schedule(&self) -> Option<cron::Schedule> { pub fn get_schedule(&self) -> Option<cron::Schedule> {
if self.schedule[0] == 0 { if self.schedule[0] == 0 {
return None; return None;
@ -177,6 +176,7 @@ impl FunctionAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn get_last_execution_datetime(&self) -> chrono::DateTime<chrono::Utc> { pub fn get_last_execution_datetime(&self) -> chrono::DateTime<chrono::Utc> {
chrono::DateTime::from_utc( chrono::DateTime::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(self.last_execution_timestamp, 0).unwrap(), chrono::NaiveDateTime::from_timestamp_opt(self.last_execution_timestamp, 0).unwrap(),
@ -185,6 +185,7 @@ impl FunctionAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn should_execute(&self, now: chrono::DateTime<chrono::Utc>) -> bool { pub fn should_execute(&self, now: chrono::DateTime<chrono::Utc>) -> bool {
let schedule = self.get_schedule(); let schedule = self.get_schedule();
if schedule.is_none() { if schedule.is_none() {
@ -203,6 +204,7 @@ impl FunctionAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn next_execution_timestamp(&self) -> Option<chrono::DateTime<chrono::Utc>> { pub fn next_execution_timestamp(&self) -> Option<chrono::DateTime<chrono::Utc>> {
let schedule = self.get_schedule(); let schedule = self.get_schedule();
if schedule.is_none() { if schedule.is_none() {
@ -213,10 +215,9 @@ impl FunctionAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &anchor_client::Client< client: &solana_client::rpc_client::RpcClient,
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await

View File

@ -3,7 +3,7 @@ use anchor_lang::{Discriminator, Owner, ZeroCopy};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::cell::Ref; use std::cell::Ref;
use crate::{SwitchboardError, QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID}; use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
@ -15,7 +15,7 @@ pub enum VerificationStatus {
VerificationOverride = 1 << 3, VerificationOverride = 1 << 3,
} }
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Debug)] #[derive(Debug)]
pub struct QuoteAccountData { pub struct QuoteAccountData {
@ -147,10 +147,9 @@ impl QuoteAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &anchor_client::Client< client: &solana_client::rpc_client::RpcClient,
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await

View File

@ -3,7 +3,6 @@ use anchor_lang::solana_program::entrypoint::ProgramResult;
use anchor_lang::solana_program::instruction::Instruction; use anchor_lang::solana_program::instruction::Instruction;
use anchor_lang::solana_program::program::{invoke, invoke_signed}; use anchor_lang::solana_program::program::{invoke, invoke_signed};
use anchor_lang::{Discriminator, InstructionData}; use anchor_lang::{Discriminator, InstructionData};
use anchor_spl::token::TokenAccount;
#[derive(Accounts)] #[derive(Accounts)]
#[instruction(params: FunctionTriggerParams)] // rpc parameters hint #[instruction(params: FunctionTriggerParams)] // rpc parameters hint

View File

@ -202,11 +202,10 @@ impl<'info> FunctionVerify<'info> {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn build( pub async fn build(
client: &anchor_client::Client< client: &solana_client::rpc_client::RpcClient,
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>, fn_signer: std::sync::Arc<solana_sdk::signer::keypair::Keypair>,
>,
fn_signer: std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
pubkeys: &FunctionVerifyPubkeys, pubkeys: &FunctionVerifyPubkeys,
mr_enclave: [u8; 32], mr_enclave: [u8; 32],
) -> std::result::Result<Instruction, switchboard_common::error::Error> { ) -> std::result::Result<Instruction, switchboard_common::error::Error> {
@ -285,6 +284,7 @@ impl<'info> FunctionVerify<'info> {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
fn build_ix( fn build_ix(
accounts: FunctionVerifyAccounts, accounts: FunctionVerifyAccounts,
observed_time: i64, observed_time: i64,
@ -307,6 +307,7 @@ impl<'info> FunctionVerify<'info> {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub struct FunctionVerifyAccounts { pub struct FunctionVerifyAccounts {
pub function: Pubkey, pub function: Pubkey,
pub fn_signer: Pubkey, pub fn_signer: Pubkey,
@ -324,6 +325,7 @@ pub struct FunctionVerifyAccounts {
pub system_program: Pubkey, pub system_program: Pubkey,
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
impl ToAccountMetas for FunctionVerifyAccounts { impl ToAccountMetas for FunctionVerifyAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> { fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
vec![ vec![

View File

@ -1,6 +1,5 @@
use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;
use anchor_client::solana_sdk::signer::keypair::Keypair;
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
use solana_sdk::signer::keypair::Keypair;
use std::result::Result; use std::result::Result;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
@ -13,14 +12,11 @@ pub fn to_pubkey(signer: Arc<Keypair>) -> std::result::Result<Pubkey, switchboar
} }
pub async fn load_account<T: bytemuck::Pod>( pub async fn load_account<T: bytemuck::Pod>(
client: &anchor_client::Client<Arc<Keypair>>, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> Result<T, switchboard_common::Error> { ) -> Result<T, switchboard_common::Error> {
let data = client let data = client
.program(SWITCHBOARD_ATTESTATION_PROGRAM_ID)
.async_rpc()
.get_account_data(&pubkey) .get_account_data(&pubkey)
.await
.map_err(|_| switchboard_common::Error::CustomMessage("AnchorParseError".to_string()))?; .map_err(|_| switchboard_common::Error::CustomMessage("AnchorParseError".to_string()))?;
Ok(*bytemuck::try_from_bytes::<T>(&data[8..]) Ok(*bytemuck::try_from_bytes::<T>(&data[8..])
.map_err(|_| switchboard_common::Error::CustomMessage("AnchorParseError".to_string()))?) .map_err(|_| switchboard_common::Error::CustomMessage("AnchorParseError".to_string()))?)

View File

@ -1,5 +1,4 @@
#![allow(clippy::result_large_err)] #![allow(clippy::result_large_err)]
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
use anchor_lang::solana_program::pubkey; use anchor_lang::solana_program::pubkey;
@ -9,14 +8,30 @@ pub use oracle_program::*;
pub mod attestation_program; pub mod attestation_program;
pub use attestation_program::*; pub use attestation_program::*;
// Includes re-exports used by macros.
//
// This module is not intended to be part of the public API. In general, any
// `doc(hidden)` code is not part of the public and stable API.
// #[macro_use]
// #[doc(hidden)]
// pub mod macros;
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub mod client; pub mod client;
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub use client::*; pub use client::*;
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub mod sgx; pub mod sgx;
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub use sgx::*; pub use sgx::*;
/// Seed used to derive the SbState PDA. /// Seed used to derive the SbState PDA.

View File

@ -0,0 +1,30 @@
macro_rules! cfg_solana {
($($item:item)*) => {
$(
#[cfg(target_os = "solana")]
$item
)*
}
}
macro_rules! cfg_not_solana {
($($item:item)*) => {
$( #[cfg(not(target_os = "solana"))] $item )*
}
}
macro_rules! cfg_client {
($($item:item)*) => {
$(
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
$item
)*
}
}
macro_rules! cfg_not_client {
($($item:item)*) => {
$( #[cfg(not(feature = "client"))] $item )*
}
}

View File

@ -3,7 +3,7 @@ use anchor_lang::Discriminator;
use rust_decimal::Decimal; use rust_decimal::Decimal;
use std::cell::Ref; use std::cell::Ref;
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Default, Debug, PartialEq, Eq)] #[derive(Default, Debug, PartialEq, Eq)]
pub struct Hash { pub struct Hash {
@ -11,7 +11,7 @@ pub struct Hash {
pub data: [u8; 32], pub data: [u8; 32],
} }
#[zero_copy] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Default, Debug, PartialEq, Eq)] #[derive(Default, Debug, PartialEq, Eq)]
pub struct AggregatorRound { pub struct AggregatorRound {
@ -53,8 +53,8 @@ pub enum AggregatorResolutionMode {
ModeSlidingResolution = 1, ModeSlidingResolution = 1,
} }
// #[zero_copy] // #[zero_copy(unsafe)]
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[repr(packed)] #[repr(packed)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct AggregatorAccountData { pub struct AggregatorAccountData {
@ -280,10 +280,9 @@ impl AggregatorAccountData {
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &anchor_client::Client< client: &solana_client::rpc_client::RpcClient,
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await

View File

@ -1,3 +1,4 @@
#![allow(unaligned_references)]
use crate::*; use crate::*;
use anchor_lang::{Discriminator, Owner}; use anchor_lang::{Discriminator, Owner};
@ -27,7 +28,7 @@ pub struct BufferRelayerAccountData {
pub result: Vec<u8>, pub result: Vec<u8>,
} }
#[zero_copy] #[zero_copy(unsafe)]
#[derive(Default, Debug, AnchorSerialize, AnchorDeserialize)] #[derive(Default, Debug, AnchorSerialize, AnchorDeserialize)]
pub struct BufferRelayerRound { pub struct BufferRelayerRound {
/// Number of successful responses. /// Number of successful responses.

View File

@ -1,7 +1,7 @@
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
#[zero_copy] #[zero_copy(unsafe)]
#[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)] #[account(zero_copy(unsafe))]
#[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.

View File

@ -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] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
#[derive(Default, Debug, Eq, PartialEq)] #[derive(Default, Debug, Eq, PartialEq)]
pub struct SwitchboardDecimal { pub struct SwitchboardDecimal {

View File

@ -2,7 +2,7 @@
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
#[zero_copy] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[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] #[zero_copy(unsafe)]
#[repr(packed)] #[repr(packed)]
pub struct VrfBuilder { pub struct VrfBuilder {
/// The OracleAccountData that is producing the randomness. /// The OracleAccountData that is producing the randomness.

View File

@ -6,7 +6,7 @@ use bytemuck::{Pod, Zeroable};
use std::cell::Ref; use std::cell::Ref;
use superslice::*; use superslice::*;
#[zero_copy] #[zero_copy(unsafe)]
#[derive(Default)] #[derive(Default)]
#[repr(packed)] #[repr(packed)]
pub struct AggregatorHistoryRow { pub struct AggregatorHistoryRow {

View File

@ -1,6 +1,6 @@
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[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

View File

@ -1,4 +1,6 @@
use anchor_lang::prelude::*; use crate::*;
use anchor_lang::Discriminator;
use std::cell::Ref;
#[derive(Copy, Clone, AnchorSerialize, AnchorDeserialize)] #[derive(Copy, Clone, AnchorSerialize, AnchorDeserialize)]
pub enum OracleResponseType { pub enum OracleResponseType {
@ -7,7 +9,8 @@ pub enum OracleResponseType {
TypeDisagreement, TypeDisagreement,
TypeNoResponse, TypeNoResponse,
} }
#[zero_copy]
#[zero_copy(unsafe)]
#[derive(Default)] #[derive(Default)]
#[repr(packed)] #[repr(packed)]
pub struct OracleMetrics { pub struct OracleMetrics {
@ -31,7 +34,7 @@ pub struct OracleMetrics {
pub total_late_response: u128, pub total_late_response: u128,
} }
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[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.
@ -57,4 +60,74 @@ pub struct OracleAccountData {
pub _ebuf: [u8; 255], pub _ebuf: [u8; 255],
} }
impl OracleAccountData {} impl OracleAccountData {
/// Returns the deserialized Switchboard Oracle account
///
/// # Arguments
///
/// * `account_info` - A Solana AccountInfo referencing an existing Switchboard Oracle
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleAccountData;
///
/// let oracle = OracleAccountData::new(oracle_account_info)?;
/// ```
pub fn new<'info>(
account_info: &'info AccountInfo<'info>,
) -> anchor_lang::Result<Ref<'info, Self>> {
let data = account_info.try_borrow_data()?;
if data.len() < OracleAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(Ref::map(data, |data| {
bytemuck::from_bytes(&data[8..std::mem::size_of::<OracleAccountData>() + 8])
}))
}
/// Returns the deserialized Switchboard Oracle account
///
/// # Arguments
///
/// * `data` - A Solana AccountInfo's data buffer
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleAccountData;
///
/// let oracle = OracleAccountData::new(oracle_account_info.try_borrow_data()?)?;
/// ```
pub fn new_from_bytes(data: &[u8]) -> anchor_lang::Result<&OracleAccountData> {
if data.len() < OracleAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(bytemuck::from_bytes(
&data[8..std::mem::size_of::<OracleAccountData>() + 8],
))
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await
}
}

View File

@ -10,7 +10,7 @@ pub enum SwitchboardPermission {
PermitVrfRequests = 1 << 2, PermitVrfRequests = 1 << 2,
} }
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[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.

View File

@ -1,8 +1,9 @@
use super::decimal::SwitchboardDecimal; use crate::*;
use anchor_lang::prelude::*; use anchor_lang::Discriminator;
use bytemuck::try_cast_slice_mut; use bytemuck::try_cast_slice_mut;
use std::cell::Ref;
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[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.
@ -57,6 +58,12 @@ pub struct OracleQueueAccountData {
pub data_buffer: Pubkey, pub data_buffer: Pubkey,
} }
impl Default for OracleQueueAccountData {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl OracleQueueAccountData { impl OracleQueueAccountData {
pub fn size() -> usize { pub fn size() -> usize {
std::mem::size_of::<OracleQueueAccountData>() + 8 std::mem::size_of::<OracleQueueAccountData>() + 8
@ -86,9 +93,74 @@ impl OracleQueueAccountData {
.checked_mul(batch_size.checked_add(1).unwrap().into()) .checked_mul(batch_size.checked_add(1).unwrap().into())
.unwrap() .unwrap()
} }
}
impl Default for OracleQueueAccountData { /// Returns the deserialized Switchboard OracleQueue account
fn default() -> Self { ///
unsafe { std::mem::zeroed() } /// # Arguments
///
/// * `account_info` - A Solana AccountInfo referencing an existing Switchboard OracleQueue
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleQueueAccountData;
///
/// let oracle_queue = OracleQueueAccountData::new(queue_account_info)?;
/// ```
pub fn new<'info>(
account_info: &'info AccountInfo<'info>,
) -> anchor_lang::Result<Ref<'info, Self>> {
let data = account_info.try_borrow_data()?;
if data.len() < OracleQueueAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleQueueAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(Ref::map(data, |data| {
bytemuck::from_bytes(&data[8..std::mem::size_of::<OracleQueueAccountData>() + 8])
}))
}
/// Returns the deserialized Switchboard OracleQueue account
///
/// # Arguments
///
/// * `data` - A Solana AccountInfo's data buffer
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleQueueAccountData;
///
/// let oracle_queue = OracleQueueAccountData::new(oracle_account_info.try_borrow_data()?)?;
/// ```
pub fn new_from_bytes(data: &[u8]) -> anchor_lang::Result<&OracleQueueAccountData> {
if data.len() < OracleQueueAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleQueueAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(bytemuck::from_bytes(
&data[8..std::mem::size_of::<OracleQueueAccountData>() + 8],
))
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await
} }
} }

View File

@ -1,6 +1,6 @@
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[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.

View File

@ -1,6 +1,6 @@
use crate::*; use crate::*;
#[zero_copy] #[zero_copy(unsafe)]
#[derive(Default)] #[derive(Default)]
#[repr(packed)] #[repr(packed)]
pub struct SlidingWindowElement { pub struct SlidingWindowElement {
@ -10,7 +10,7 @@ pub struct SlidingWindowElement {
pub timestamp: i64, pub timestamp: i64,
} }
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[repr(packed)] #[repr(packed)]
pub struct SlidingResultAccountData { pub struct SlidingResultAccountData {
pub data: [SlidingWindowElement; 16], pub data: [SlidingWindowElement; 16],

View File

@ -8,7 +8,7 @@ use std::cell::Ref;
// VrfSetCallback // VrfSetCallback
// VrfClose // VrfClose
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[repr(packed)] #[repr(packed)]
pub struct VrfAccountData { pub struct VrfAccountData {
/// The current status of the VRF account. /// The current status of the VRF account.
@ -122,4 +122,13 @@ impl VrfAccountData {
} }
Ok(self.current_round.result) Ok(self.current_round.result)
} }
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await
}
} }

View File

@ -3,7 +3,7 @@ use crate::*;
use anchor_lang::Discriminator; use anchor_lang::Discriminator;
use std::cell::Ref; use std::cell::Ref;
#[account(zero_copy)] #[account(zero_copy(unsafe))]
#[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.
@ -132,4 +132,13 @@ impl VrfLiteAccountData {
} }
Ok(self.result) Ok(self.result)
} }
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await
}
} }

View File

@ -14,7 +14,7 @@ pub struct VrfPoolRow {
} }
#[repr(packed)] #[repr(packed)]
#[account(zero_copy)] #[account(zero_copy(unsafe))]
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
@ -95,6 +95,15 @@ impl VrfPoolAccountData {
&data[8..std::mem::size_of::<VrfPoolAccountData>() + 8], &data[8..std::mem::size_of::<VrfPoolAccountData>() + 8],
)) ))
} }
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await
}
} }
// impl Discriminator for VrfPoolAccountData { // impl Discriminator for VrfPoolAccountData {

View File

@ -1,21 +1,14 @@
pub use anchor_client;
use anchor_client::solana_sdk::commitment_config::CommitmentConfig;
use anchor_client::solana_sdk::signer::keypair::{keypair_from_seed, Keypair};
use anchor_client::solana_sdk::transaction::Transaction;
use anchor_client::Cluster;
use anchor_lang::solana_program::instruction::Instruction; use anchor_lang::solana_program::instruction::Instruction;
use anchor_lang::solana_program::message::Message; use anchor_lang::solana_program::message::Message;
use anchor_lang::solana_program::pubkey::Pubkey; use anchor_lang::solana_program::pubkey::Pubkey;
use sgx_quote::Quote; use sgx_quote::Quote;
use solana_sdk::signer::keypair::{keypair_from_seed, Keypair};
use std::env; use std::env;
use std::result::Result; use std::result::Result;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use switchboard_common::{Error, FunctionResult, Gramine}; use switchboard_common::{Error, FunctionResult, Gramine};
// use crate::{FunctionVerify, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
use crate::attestation_program::FunctionVerify; use crate::attestation_program::FunctionVerify;
use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID}; use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
@ -26,15 +19,15 @@ pub fn generate_signer() -> Arc<Keypair> {
} }
pub async fn function_verify( pub async fn function_verify(
url: String,
fn_signer: Arc<Keypair>, fn_signer: Arc<Keypair>,
mut ixs: Vec<Instruction>, mut ixs: Vec<Instruction>,
) -> Result<FunctionResult, Error> { ) -> Result<FunctionResult, Error> {
let fn_signer_pubkey = crate::client::to_pubkey(fn_signer.clone())?; let fn_signer_pubkey = crate::client::to_pubkey(fn_signer.clone())?;
let client = anchor_client::Client::new_with_options( let client = solana_client::rpc_client::RpcClient::new_with_commitment(
Cluster::Devnet, url,
fn_signer.to_owned(), solana_sdk::commitment_config::CommitmentConfig::processed(),
CommitmentConfig::processed(),
); );
let quote_raw = Gramine::generate_quote(&fn_signer_pubkey.to_bytes()).unwrap(); let quote_raw = Gramine::generate_quote(&fn_signer_pubkey.to_bytes()).unwrap();
@ -54,13 +47,9 @@ pub async fn function_verify(
let message = Message::new(&ixs, Some(&pubkeys.payer)); let message = Message::new(&ixs, Some(&pubkeys.payer));
let blockhash = client let blockhash = client.get_latest_blockhash().unwrap();
.program(SWITCHBOARD_ATTESTATION_PROGRAM_ID)
.rpc()
.get_latest_blockhash()
.unwrap();
let mut tx = Transaction::new_unsigned(message); let mut tx = solana_sdk::transaction::Transaction::new_unsigned(message);
tx.partial_sign(&[fn_signer.as_ref()], blockhash); tx.partial_sign(&[fn_signer.as_ref()], blockhash);
Ok(FunctionResult { Ok(FunctionResult {