Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: bcb5f68066b800e0bf8a68ed706a47a798292f3c
  • Loading branch information
Copybara authored and actions-user committed Aug 21, 2023
1 parent c8b6ec9 commit 493befd
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 230 deletions.
2 changes: 1 addition & 1 deletion examples/feeds/01_feed_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@project-serum/borsh": "^0.2.5",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.78.3",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/oracle": "latest",
"@switchboard-xyz/solana.js": "^2.5.0",
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/feeds/02_spl_native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@solana/web3.js": "^1.77.3",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/oracle": "latest",
"@switchboard-xyz/solana.js": "^2.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ async fn main() {
// Finally, emit the signed quote and partially signed transaction to the functionRunner oracle
// The functionRunner oracle will use the last outputted word to stdout as the serialized result. This is what gets executed on-chain.
runner.emit(ixs).await.unwrap();
}
}
2 changes: 1 addition & 1 deletion examples/functions/02_liquidity_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@coral-xyz/anchor": "^0.28.0",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.78.3",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/solana.js": "^2.5.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/functions/03_candles_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@coral-xyz/anchor": "^0.28.0",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.78.3",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/solana.js": "^2.5.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ impl Initialize<'_> {
oracle.bump = *ctx.bumps.get("oracle").unwrap();
Ok(())
}
}
}
2 changes: 1 addition & 1 deletion examples/functions/03_candles_oracle/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub mod set_function;
pub use set_function::*;

pub mod trigger_function;
pub use trigger_function::*;
pub use trigger_function::*;
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ impl RefreshPrices<'_> {

Ok(())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct SetFunction<'info> {
}

#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct SetFunctionParams { }
pub struct SetFunctionParams {}

impl SetFunction<'_> {
pub fn validate(
Expand All @@ -34,4 +34,4 @@ impl SetFunction<'_> {
program.function = ctx.accounts.function.key();
Ok(())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct TriggerFunction<'info> {
}

#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct TriggerFunctionParams { }
pub struct TriggerFunctionParams {}

impl TriggerFunction<'_> {
pub fn validate(
Expand All @@ -32,12 +32,16 @@ impl TriggerFunction<'_> {
Ok(())
}

pub fn actuate(ctx: &Context<Self>, _params: &TriggerFunctionParams) -> anchor_lang::Result<()> {
pub fn actuate(
ctx: &Context<Self>,
_params: &TriggerFunctionParams,
) -> anchor_lang::Result<()> {
FunctionTrigger {
function: ctx.accounts.function.clone(),
authority: ctx.accounts.authority.clone(),
attestation_queue: ctx.accounts.attestation_queue.clone(),
}.invoke(ctx.accounts.attestation_program.clone())?;
}
.invoke(ctx.accounts.attestation_program.clone())?;
Ok(())
}
}
}
2 changes: 1 addition & 1 deletion examples/functions/04_randomness_callback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@coral-xyz/anchor": "^0.27.0",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.78.3",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/solana.js": "^2.5.0",
"dotenv": "^16.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/functions/05_raffle_program/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/solana.js": "^2.5.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub struct Initialize<'info> {
space = 8 + std::mem::size_of::<RaffleAccount>(),
payer = payer,
seeds = [
b"MY_RAFFLE",
authority.key().as_ref(),
b"MY_RAFFLE",
authority.key().as_ref(),
params.recent_slot.to_le_bytes().as_ref()
],
bump
Expand Down Expand Up @@ -47,7 +47,6 @@ impl Initialize<'_> {
let mut raffle = ctx.accounts.raffle.load_init()?;
raffle.bump = *ctx.bumps.get("raffle").unwrap();


// accounts
raffle.authority = ctx.accounts.authority.key();
raffle.function = ctx.accounts.function.key();
Expand Down
2 changes: 1 addition & 1 deletion examples/vrf/01_vrf_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@project-serum/borsh": "^0.2.5",
"@solana/spl-token": "^0.3.6",
"@solana/web3.js": "^1.77.3",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/common": "^2.3.2",
"@switchboard-xyz/oracle": "latest",
"@switchboard-xyz/solana.js": "^2.5.0",
"chalk": "^4.1.2",
Expand Down
163 changes: 36 additions & 127 deletions javascript/solana.js/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as utils from "@switchboard-xyz/common/esm-utils";
import { execSync } from "child_process";
import { build } from "esbuild";
import fs from "fs";
import fsPromises from "fs/promises";
import path from "path";
import shell from "shelljs";
import { fileURLToPath } from "url";
Expand All @@ -14,144 +15,52 @@ const __dirname = path.dirname(__filename);

const buildFiles = ["tsconfig.tsbuildinfo"];

const isCI =
process.env.CI && process.env.CI.length > 0 ? Boolean(process.env.CI) : false;

const tscPath = path.relative(
process.cwd(),
path.join(__dirname, "..", "..", "node_modules", "typescript", "bin", "tsc")
);

const outDir = path.join(__dirname, "lib");

const commonOptions = {
bundle: true,
minify: true,
treeShaking: true,
platform: "node",
sourcemap: true,
sourcesContent: false,
target: "node16",
plugins: [],
legalComments: "none",
};

const entrypoints = {
index: "index",
SwitchboardProgram: "SwitchboardProgram",
TransactionObject: "TransactionObject",
AggregatorAccount: "accounts/AggregatorAccount",
generated: "generated/index",
"generated/accounts": "generated/accounts",
"generated/instructions": "generated/instructions",
"generated/types": "generated/types",
"generated/oracle": "generated/oracle-program/index",
"generated/oracle/accounts": "generated/oracle-program/accounts/index",
"generated/oracle/instructions":
"generated/oracle-program/instructions/index",
"generated/oracle/types": "generated/oracle-program/types/index",
"generated/attestation": "generated/attestation-program/index",
"generated/attestation/accounts":
"generated/attestation-program/accounts/index",
"generated/attestation/instructions":
"generated/attestation-program/instructions/index",
"generated/attestation/types": "generated/attestation-program/types/index",
};

const updateJsonFile = (relativePath, updateFunction) => {
const contents = fs.readFileSync(relativePath).toString();
const res = updateFunction(JSON.parse(contents));
fs.writeFileSync(relativePath, JSON.stringify(res, null, 2) + "\n");
};

const generateFiles = () => {
const files = [...Object.entries(entrypoints), ["index", "index"]].flatMap(
([key, value]) => {
const nrOfDots = key.split("/").length - 1;
const relativePath = "../".repeat(nrOfDots) || "./";
const compiledPath = `${relativePath}lib/${value}.js`;
return [
[
`${key}.cjs`,
`module.exports = require('${relativePath}lib/${value}.cjs');`,
],
[`${key}.js`, `export * from '${compiledPath}'`],
[`${key}.d.ts`, `export * from '${compiledPath}'`],
];
}
);

return Object.fromEntries(files);
};

const updateConfig = () => {
// Update tsconfig.json `typedocOptions.entryPoints` field
updateJsonFile("./tsconfig.json", (json) => ({
...json,
typedocOptions: {
...json.typedocOptions,
entryPoints: [...Object.keys(entrypoints)].map(
(key) => `src/${entrypoints[key]}.ts`
),
},
}));

const generatedFiles = generateFiles();
const filenames = Object.keys(generatedFiles);

// Update package.json `exports` and `files` fields
updateJsonFile("./package.json", (json) => ({
...json,
exports: Object.assign(
Object.fromEntries(
["index", ...Object.keys(entrypoints)].map((key) => {
const entryPoint = {
types: `./${key}.d.ts`,
import: `./${key}.js`,
require: `./${key}.cjs`,
};

return [key === "index" ? "." : `./${key}`, entryPoint];
})
),
{ "./package.json": "./package.json" }
),
files: ["lib/", "package.json", ...filenames],
}));

// Write generated files
Object.entries(generatedFiles).forEach(([filename, content]) => {
fs.mkdirSync(path.dirname(filename), { recursive: true });
fs.writeFileSync(filename, content);
});

// Update .gitignore
fs.writeFileSync("./.gitignore", filenames.join("\n") + "\n");
};

async function main() {
fs.rmSync(outDir, {
force: true,
recursive: true,
});
for (const file of buildFiles) {
if (fs.existsSync(file)) {
fs.rmSync(file);
}
}
await Promise.all([
fsPromises.rm(outDir, { recursive: true, force: true }),
fsPromises.rm(path.join(__dirname, "lib-cjs"), {
recursive: true,
force: true,
}),
buildFiles.map((f) => fsPromises.rm(f, { force: true })),
]);

fs.mkdirSync(outDir, { recursive: true });

execSync(`${tscPath} --outDir lib`, { encoding: "utf-8" });
execSync(`pnpm exec tsc --outDir lib`, { encoding: "utf-8" });

execSync(`${tscPath} --outDir lib-cjs -p tsconfig.cjs.json`, {
execSync(`pnpm exec tsc --outDir lib-cjs -p tsconfig.cjs.json`, {
encoding: "utf-8",
});
utils.moveCjsFiles("lib-cjs", "lib");
fs.rmSync("lib-cjs", { recursive: true });

await utils
.moveCjsFilesAsync("lib-cjs", "lib")
.then(() => fsPromises.rm("lib-cjs", { recursive: true, force: true }));

console.log(`Generating entrypoints ...`);
updateConfig();
utils.generateEntrypoints(__dirname, "lib", {
index: "index",
SwitchboardProgram: "SwitchboardProgram",
TransactionObject: "TransactionObject",
AggregatorAccount: "accounts/AggregatorAccount",
generated: "generated/index",
"generated/accounts": "generated/accounts",
"generated/instructions": "generated/instructions",
"generated/types": "generated/types",
"generated/oracle": "generated/oracle-program/index",
"generated/oracle/accounts": "generated/oracle-program/accounts/index",
"generated/oracle/instructions":
"generated/oracle-program/instructions/index",
"generated/oracle/types": "generated/oracle-program/types/index",
"generated/attestation": "generated/attestation-program/index",
"generated/attestation/accounts":
"generated/attestation-program/accounts/index",
"generated/attestation/instructions":
"generated/attestation-program/instructions/index",
"generated/attestation/types": "generated/attestation-program/types/index",
});
}

main().catch((error) => {
Expand Down
Loading

0 comments on commit 493befd

Please sign in to comment.