Skip to content

Commit

Permalink
add readme #1
Browse files Browse the repository at this point in the history
  • Loading branch information
simke9445 committed Jan 30, 2023
1 parent cd31597 commit d801d99
Showing 1 changed file with 242 additions and 1 deletion.
243 changes: 242 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,244 @@
# warp-sdk

TODO: add readme
WarpSdk is a software development kit (SDK) for using warp protocol, the automation protocol of the Terra blockchain. The SDK provides a simple way to interact with the warp protocol's contracts, allowing developers to perform operations such as creating and managing jobs, templates, and accounts.

## Installation

```bash
npm install -S @terra-money/warp-sdk
```


## Usage

```typescript
import { WarpSdk } from "warp-sdk";

const wallet = { ... }; // Wallet object
const contractAddress = "terra1..."; // Warp Protocol contract address

const warpSdk = new WarpSdk(wallet, contractAddress);

const jobId = "abc123...";
const isActive = await warpSdk.isJobActive(jobId)
console.log(`Job is ${isActive ? "active" : "inactive"}.`)
```
## Methods

**isJobActive(jobId: string): Promise<boolean>:** Check if a job is active by its ID.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const jobId = 'jobId';
const isActive = await WarpSdk.isJobActive(jobId);
console.log(isActive);
```

**jobs(opts: QueryJobsMsg = {}): Promise<Job[]>:** List jobs with optional filters.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const allJobs = await warpSdk.jobs();
console.log(allJobs);
```

**job(id: string): Promise<Job>:** Get a job by its ID.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const jobId = 'jobId';
const jobDetails = await WarpSdk.job(jobId);
console.log(jobDetails);
```

**templates(opts: QueryTemplatesMsg = {}): Promise<Template[]>:** List templates with optional filters.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const allTemplates = await warpSdk.templates();
console.log(allTemplates);
```

**template(id: string): Promise<Template>:** Get a template by its ID.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const templateId = 'templateId';
const templateDetails = await warpSdk.template(templateId);
console.log(templateDetails);
```

**simulateQuery(query: QueryRequestFor_String): Promise<object>:** Simulate a query.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const query = { ... };
const queryResult = await warpSdk.simulateQuery(query);
console.log(queryResult);
```

**account(owner: string): Promise<Account>:** Get an account by its owner.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const accountId = 'accountId';
const accountDetails = await WarpSdk.account(accountId);
console.log(accountDetails);
```

**accounts(opts: QueryAccountsMsg): Promise<Account[]>:** List accounts with optional filters.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const allAccounts = await warpSdk.accounts();
console.log(allAccounts);
```

**config(): Promise<Config>:** Get the config of the Warp Protocol.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const configInfo = await warpSdk.config();
console.log(configInfo);
```

**createJob(sender: string, msg: CreateJobMsg): Promise<TxInfo>:** Create a job.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);

const msg = {
....,
msgs: [...],
reward: '1000000',
condition: {
and: [{
expr: {
string: {
left: {
value: 'val1',
},
op: 'eq',
right: {
value: 'val1',
},
},
},
}],
},
};

const sender = 'sender address';
const job = await warpSdk.createJob(sender, msg);
console.log(job);
```

**createJobSequence(sender: string, sequence: CreateJobMsg[]): Promise<TxInfo>:** Create a sequence of jobs.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);

const msg1 = {
...
msgs: [...],
reward: '1000000',
condition: {
and: [{
expr: {
string: {
left: {
value: 'val1',
},
op: 'eq',
right: {
value: 'val1',
},
},
},
}],
}],
};

const msg2 = {
...,
msgs: [...],
reward: '1000000',
condition: {
and: [{
expr: {
string: {
left: {
value: 'val',
},
op: 'eq',
right: {
value: 'val2',
},
},
},
}],
},
};

const sender = 'sender address';
const jobSequence = await warpSdk.createJobSequence(sender, [msg1, msg2]);
console.log(jobSequence);
```

**deleteJob(sender: string, jobId: string): Promise<TxInfo>:** Delete a job.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const sender = 'sender address';

const jobId = 'abc123';
const response = await warpSdk.deleteJob(sender, jobId);
console.log(response);
```

**updateJob(sender: string, msg: UpdateJobMsg): Promise<TxInfo>:** Update a job.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const sender = 'sender address';

const jobId = 'abc123';
const updateData = { name: 'Updated Job Name' };
const response = await warpSdk.updateJob(jobId, updateData);
console.log(response);
```

**executeJob(sender: string, jobId: string): Promise<TxInfo>:** Execute a job.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const sender = 'sender address';

const jobId = 'abc123';
const response = await warpSdk.executeJob(jobId);
console.log(response);
```

**submitTemplate(sender: string, msg: SubmitTemplateMsg): Promise<TxInfo>:** Submit a template.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);

const template = { name: 'Template 1', formatted_str: 'this is a template', vars: []};
const response = await sdk.submitTemplate(template);
console.log(response);
```

**deleteTemplate(sender: string, templateId: string): Promise<TxInfo>:** Delete a template.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);
const sender = 'sender address';

const templateId = 'template_id';
const response = await sdk.deleteTemplate(sender, templateId);
console.log(response);
```

**editTemplate(sender: string, msg: EditTemplateMsg): Promise<TxInfo>:** Edit a template.
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);

const templateId = 'template_id';
const updates = { name: 'Updated Template' };
const response = await warpSdk.editTemplate(templateId, updates);
console.log(response);
```

**createAccount(sender: string): Promise<TxInfo>**
```typescript
const warpSdk = new WarpSdk(wallet, contractAddress);

const sender = 'sender address';
const account = await warpSdk.createAccount(sender);
console.log(account);
```

0 comments on commit d801d99

Please sign in to comment.