Socket
Socket
Sign inDemoInstall

@clockwork-xyz/sdk

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clockwork-xyz/sdk - npm Package Compare versions

Comparing version 0.2.4 to 0.3.0

3

lib/accounts/index.d.ts
import Thread from "./Thread";
import Worker from "./Worker";
export { Thread, Worker };
export { Thread };
/// <reference types="node" />
import { BN } from "@project-serum/anchor";
import { BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";

@@ -4,0 +4,0 @@ import { ExecContext, ClockData, SerializableInstruction, Trigger } from "../models";

import * as anchor from "@coral-xyz/anchor";
import { ConfirmOptions, Connection, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
import { ThreadProgram } from "./programs/thread/types";
import { NetworkProgram } from "./programs/network/types";
import { Thread, Worker } from "./accounts";
import { Thread } from "./accounts";
import { ThreadSettingsInput, TriggerInput } from "./models";

@@ -17,3 +16,3 @@ /**

threadProgram: anchor.Program<ThreadProgram>;
networkProgram: anchor.Program<NetworkProgram>;
anchorProvider: anchor.AnchorProvider;
constructor(wallet: ClockworkProviderWallet, connection: Connection, opts?: ConfirmOptions);

@@ -34,8 +33,2 @@ /**

/**
* Get Worker PDA. Returns the public key and bump.
*
* @param id worker id
*/
getWorkerPDA(id: string): [PublicKey, number];
/**
* Get Thread Account Data Deserialized.

@@ -47,8 +40,2 @@ *

/**
* Get Worker Account Data Deserialized.
*
* @param workerPubkey worker public key
*/
getWorkerAccount(workerPubkey: PublicKey): Promise<Worker>;
/**
* Create a new thread. Returns Transaction Signature.

@@ -62,3 +49,3 @@ *

*/
threadCreate(authority: PublicKey, id: string, instructions: TransactionInstruction[], trigger: TriggerInput, amount?: number): Promise<string>;
threadCreate(authority: PublicKey, id: string, instructions: TransactionInstruction[], trigger: TriggerInput, amount?: number): Promise<TransactionInstruction>;
/**

@@ -71,3 +58,3 @@ * Delete a thread. Returns Transaction Signature.

*/
threadDelete(authority: PublicKey, threadPubkey: PublicKey, closeTo?: PublicKey): Promise<string>;
threadDelete(authority: PublicKey, threadPubkey: PublicKey, closeTo?: PublicKey): Promise<TransactionInstruction>;
/**

@@ -79,3 +66,3 @@ * Pause a thread. Returns Transaction Signature.

*/
threadPause(authority: PublicKey, threadPubkey: PublicKey): Promise<string>;
threadPause(authority: PublicKey, threadPubkey: PublicKey): Promise<TransactionInstruction>;
/**

@@ -87,3 +74,3 @@ * Resume a thread. Returns Transaction Signature.

*/
threadResume(authority: PublicKey, threadPubkey: PublicKey): Promise<string>;
threadResume(authority: PublicKey, threadPubkey: PublicKey): Promise<TransactionInstruction>;
/**

@@ -95,3 +82,3 @@ * Reset a thread. Returns Transaction Signature.

*/
threadReset(authority: PublicKey, threadPubkey: PublicKey): Promise<string>;
threadReset(authority: PublicKey, threadPubkey: PublicKey): Promise<TransactionInstruction>;
/**

@@ -104,3 +91,3 @@ * Withdraw from thread. Returns Transaction Signature.

*/
threadWithdraw(authority: PublicKey, threadPubkey: PublicKey, amount: number, payTo?: PublicKey): Promise<string>;
threadWithdraw(authority: PublicKey, threadPubkey: PublicKey, amount: number, payTo?: PublicKey): Promise<TransactionInstruction>;
/**

@@ -113,3 +100,3 @@ * Update a thread. Returns Transaction Signature.

*/
threadUpdate(authority: PublicKey, threadPubkey: PublicKey, settings: ThreadSettingsInput): Promise<string>;
threadUpdate(authority: PublicKey, threadPubkey: PublicKey, settings: ThreadSettingsInput): Promise<TransactionInstruction>;
/**

@@ -122,3 +109,3 @@ * Add instruction to a thread. Returns Transaction Signature.

*/
threadInstructionAdd(authority: PublicKey, threadPubkey: PublicKey, instruction: TransactionInstruction): Promise<string>;
threadInstructionAdd(authority: PublicKey, threadPubkey: PublicKey, instruction: TransactionInstruction): Promise<TransactionInstruction>;
/**

@@ -131,3 +118,3 @@ * Remove an instruction from a thread. Returns Transaction Signature.

*/
threadInstructionRemove(authority: PublicKey, threadPubkey: PublicKey, index: number): Promise<string>;
threadInstructionRemove(authority: PublicKey, threadPubkey: PublicKey, index: number): Promise<TransactionInstruction>;
/**

@@ -137,4 +124,4 @@ * Get Crate Info.

*/
getCrateInfo(): Promise<string>;
getCrateInfo(): Promise<TransactionInstruction>;
}
export default ClockworkProvider;

@@ -41,9 +41,7 @@ "use strict";

const idl_json_1 = __importDefault(require("./programs/thread/idl.json"));
const idl_json_2 = __importDefault(require("./programs/network/idl.json"));
const utils_1 = require("./utils");
class ClockworkProvider {
constructor(wallet, connection, opts = anchor.AnchorProvider.defaultOptions()) {
const provider = new anchor.AnchorProvider(connection, wallet, opts);
this.threadProgram = new anchor.Program(idl_json_1.default, idl_json_1.default.metadata.address, provider);
this.networkProgram = new anchor.Program(idl_json_2.default, idl_json_2.default.metadata.address, provider);
this.anchorProvider = new anchor.AnchorProvider(connection, wallet, opts);
this.threadProgram = new anchor.Program(idl_json_1.default, idl_json_1.default.metadata.address, this.anchorProvider);
}

@@ -69,10 +67,2 @@ /**

/**
* Get Worker PDA. Returns the public key and bump.
*
* @param id worker id
*/
getWorkerPDA(id) {
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("worker"), new anchor.BN(id).toArrayLike(Buffer, "be", 8)], this.networkProgram.programId);
}
/**
* Get Thread Account Data Deserialized.

@@ -89,13 +79,2 @@ *

/**
* Get Worker Account Data Deserialized.
*
* @param workerPubkey worker public key
*/
getWorkerAccount(workerPubkey) {
return __awaiter(this, void 0, void 0, function* () {
const workerAccount = yield this.networkProgram.account.worker.fetch(workerPubkey);
return workerAccount;
});
}
/**
* Create a new thread. Returns Transaction Signature.

@@ -112,3 +91,3 @@ *

const threadPubkey = this.getThreadPDA(authority, id.toString())[0];
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadCreate(new anchor.BN(amount), Buffer.from(id),

@@ -121,4 +100,3 @@ // TODO: parsing can be removed accounts => keys

})
.rpc();
return tx;
.instruction();
});

@@ -135,3 +113,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadDelete()

@@ -143,4 +121,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -156,3 +133,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadPause()

@@ -163,4 +140,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -176,3 +152,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadResume()

@@ -183,4 +159,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -196,3 +171,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadReset()

@@ -203,4 +178,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -217,3 +191,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadWithdraw(new anchor.BN(amount))

@@ -225,4 +199,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -239,3 +212,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadUpdate((0, utils_1.parseThreadSettingsInput)(settings))

@@ -246,4 +219,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -260,3 +232,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadInstructionAdd((0, utils_1.parseTransactionInstruction)(instruction))

@@ -267,4 +239,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -281,3 +252,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const tx = yield this.threadProgram.methods
return yield this.threadProgram.methods
.threadInstructionRemove(new anchor.BN(index))

@@ -288,4 +259,3 @@ .accounts({

})
.rpc();
return tx;
.instruction();
});

@@ -300,4 +270,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
let tx = yield this.threadProgram.methods.getCrateInfo().accounts({}).rpc();
return tx;
return yield this.threadProgram.methods.getCrateInfo().accounts({}).instruction();
});

@@ -304,0 +273,0 @@ }

import ClockworkProvider from "./ClockworkProvider";
import { Worker, Thread } from "./accounts";
import { Thread } from "./accounts";
import { PAYER_PUBKEY } from "./constants";

@@ -7,5 +7,3 @@ import { ClockData, ExecContext, SerializableInstruction, SerializableAccount, Trigger, TriggerInput, Cron, Account, Now, Epoch, Slot, ThreadSettings, ThreadSettingsInput, CrateInfo, TriggerContext } from "./models";

import ThreadProgramIdl from "./programs/thread/idl.json";
import { NetworkProgram } from "./programs/network/types";
import NetworkProgramIdl from "./programs/network/idl.json";
import { parseThreadSettingsInput, parseTransactionInstruction, parseTransactionInstructions } from "./utils";
export { ClockworkProvider, Worker, Thread, PAYER_PUBKEY, ThreadProgram, ThreadProgramIdl, NetworkProgram, NetworkProgramIdl, parseThreadSettingsInput, parseTransactionInstruction, parseTransactionInstructions, ClockData, ExecContext, SerializableInstruction, SerializableAccount, Trigger, TriggerInput, Cron, Account, Now, Epoch, Slot, ThreadSettings, ThreadSettingsInput, CrateInfo, TriggerContext, };
export { ClockworkProvider, Thread, PAYER_PUBKEY, ThreadProgram, ThreadProgramIdl, parseThreadSettingsInput, parseTransactionInstruction, parseTransactionInstructions, ClockData, ExecContext, SerializableInstruction, SerializableAccount, Trigger, TriggerInput, Cron, Account, Now, Epoch, Slot, ThreadSettings, ThreadSettingsInput, CrateInfo, TriggerContext, };

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.parseTransactionInstructions = exports.parseTransactionInstruction = exports.parseThreadSettingsInput = exports.NetworkProgramIdl = exports.ThreadProgramIdl = exports.PAYER_PUBKEY = exports.ClockworkProvider = void 0;
exports.parseTransactionInstructions = exports.parseTransactionInstruction = exports.parseThreadSettingsInput = exports.ThreadProgramIdl = exports.PAYER_PUBKEY = exports.ClockworkProvider = void 0;
const ClockworkProvider_1 = __importDefault(require("./ClockworkProvider"));

@@ -14,4 +14,2 @@ exports.ClockworkProvider = ClockworkProvider_1.default;

exports.ThreadProgramIdl = idl_json_1.default;
const idl_json_2 = __importDefault(require("./programs/network/idl.json"));
exports.NetworkProgramIdl = idl_json_2.default;
const utils_1 = require("./utils");

@@ -18,0 +16,0 @@ Object.defineProperty(exports, "parseThreadSettingsInput", { enumerable: true, get: function () { return utils_1.parseThreadSettingsInput; } });

@@ -1,2 +0,2 @@

import { BN } from "@project-serum/anchor";
import { BN } from "@coral-xyz/anchor";
type ClockData = {

@@ -3,0 +3,0 @@ slot: BN;

@@ -1,2 +0,2 @@

import { BN } from "@project-serum/anchor";
import { BN } from "@coral-xyz/anchor";
import TriggerContext from "./TriggerContext";

@@ -3,0 +3,0 @@ type ExecContext = {

@@ -1,2 +0,2 @@

import { BN } from "@project-serum/anchor";
import { BN } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";

@@ -3,0 +3,0 @@ type Account = {

@@ -1,2 +0,2 @@

import { BN } from "@project-serum/anchor";
import { BN } from "@coral-xyz/anchor";
type AccountTriggerContext = {

@@ -3,0 +3,0 @@ dataHash: BN;

{
"name": "@clockwork-xyz/sdk",
"author": "Clockwork",
"version": "0.2.4",
"version": "0.3.0",
"description": "Clockwork Typescript SDK",

@@ -32,4 +32,3 @@ "license": "MIT",

"test": "mocha --timeout 600000 --reporter spec --require ts-node/register tests/**/*.test.ts",
"test:thread": "mocha --timeout 600000 --reporter spec --require ts-node/register tests/ThreadProgram.test.ts",
"test:network": "mocha --timeout 600000 --reporter spec --require ts-node/register tests/NetworkProgram.test.ts"
"test:thread": "mocha --timeout 600000 --reporter spec --require ts-node/register tests/ThreadProgram.test.ts"
},

@@ -48,5 +47,4 @@ "devDependencies": {

"@coral-xyz/anchor": "^0.26.0",
"@project-serum/anchor": "^0.26.0",
"@solana/web3.js": "^1.73.2"
}
}

@@ -31,3 +31,11 @@ <p align="center">

const connection = new Connection(clusterApiUrl("devnet"));
const provider = new ClockworkProvider(wallet, connection);
const clockworkProvider = new ClockworkProvider(wallet, connection);
#or
const anchorProvider = new anchor.AnchorProvider(
connection,
wallet,
anchor.AnchorProvider.defaultOptions()
);
const provider = new ClockworkProvider.fromAnchorProvider(provider);
```

@@ -38,3 +46,3 @@

```rust
let [pubkey, bump] = provider.getThreadPDA(
const [pubkey, bump] = provider.getThreadPDA(
wallet.publicKey,

@@ -48,3 +56,3 @@ "ThreadProgramTest"

```rust
let tx = await provider.threadCreate(
const ix = await provider.threadCreate(
wallet.publicKey, // authority

@@ -56,2 +64,4 @@ "ThreadProgramTest", // id

);
const tx = new Transaction().add(ix);
const signature = await provider.anchorProvider.sendAndConfirm(tx);
```

@@ -62,3 +72,3 @@

```rust
let threadAccount = await provider.getThreadAccount(threadPubkey);
const threadAccount = await provider.getThreadAccount(threadPubkey);
```

@@ -69,6 +79,6 @@

```rust
let tx = await provider.threadPause(wallet.publicKey, threadPubkey);
let tx = await provider.threadResume(wallet.publicKey, threadPubkey);
let tx = await provider.threadReset(wallet.publicKey, threadPubkey);
let tx = await provider.threadDelete(wallet.publicKey, threadPubkey);
const ix = await provider.threadPause(wallet.publicKey, threadPubkey);
const ix = await provider.threadResume(wallet.publicKey, threadPubkey);
const ix = await provider.threadReset(wallet.publicKey, threadPubkey);
const ix = await provider.threadDelete(wallet.publicKey, threadPubkey);
```

@@ -79,3 +89,3 @@

```rust
let tx = await provider.threadUpdate(wallet.publicKey, threadPubkey, {
const ix = await provider.threadUpdate(wallet.publicKey, threadPubkey, {
name: "TestUpdateThread",

@@ -85,2 +95,4 @@ rateLimit: new BN(32),

});
const tx = new Transaction().add(ix);
const signature = await provider.anchorProvider.sendAndConfirm(tx);
```

@@ -91,3 +103,3 @@

```rust
let tx = await provider.threadWithdraw(
const ix = await provider.threadWithdraw(
wallet.publicKey,

@@ -97,22 +109,4 @@ threadPubkey,

);
const tx = new Transaction().add(ix);
const signature = await provider.anchorProvider.sendAndConfirm(tx);
```
Get Crate Info
```rust
let tx = await provider.getCrateInfo();
```
Get Worker Address
```rust
let [pubkey, bump] = provider.getWorkerPDA("8");
```
Get Worker Account
```rust
let workerAccount = await provider.getWorkerAccount(workerPubkey);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc