|
1 | 1 | # warp-sdk |
2 | 2 |
|
3 | | -TODO: add readme |
| 3 | +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. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install -S @terra-money/warp-sdk |
| 9 | +``` |
| 10 | + |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +```typescript |
| 15 | +import { WarpSdk } from "warp-sdk"; |
| 16 | + |
| 17 | +const wallet = { ... }; // Wallet object |
| 18 | +const contractAddress = "terra1..."; // Warp Protocol contract address |
| 19 | + |
| 20 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 21 | + |
| 22 | +const jobId = "abc123..."; |
| 23 | +const isActive = await warpSdk.isJobActive(jobId) |
| 24 | +console.log(`Job is ${isActive ? "active" : "inactive"}.`) |
| 25 | +``` |
| 26 | +## Methods |
| 27 | + |
| 28 | +**isJobActive(jobId: string): Promise<boolean>:** Check if a job is active by its ID. |
| 29 | +```typescript |
| 30 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 31 | +const jobId = 'jobId'; |
| 32 | +const isActive = await WarpSdk.isJobActive(jobId); |
| 33 | +console.log(isActive); |
| 34 | +``` |
| 35 | + |
| 36 | +**jobs(opts: QueryJobsMsg = {}): Promise<Job[]>:** List jobs with optional filters. |
| 37 | +```typescript |
| 38 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 39 | +const allJobs = await warpSdk.jobs(); |
| 40 | +console.log(allJobs); |
| 41 | +``` |
| 42 | + |
| 43 | +**job(id: string): Promise<Job>:** Get a job by its ID. |
| 44 | +```typescript |
| 45 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 46 | +const jobId = 'jobId'; |
| 47 | +const jobDetails = await WarpSdk.job(jobId); |
| 48 | +console.log(jobDetails); |
| 49 | +``` |
| 50 | + |
| 51 | +**templates(opts: QueryTemplatesMsg = {}): Promise<Template[]>:** List templates with optional filters. |
| 52 | +```typescript |
| 53 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 54 | +const allTemplates = await warpSdk.templates(); |
| 55 | +console.log(allTemplates); |
| 56 | +``` |
| 57 | + |
| 58 | +**template(id: string): Promise<Template>:** Get a template by its ID. |
| 59 | +```typescript |
| 60 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 61 | +const templateId = 'templateId'; |
| 62 | +const templateDetails = await warpSdk.template(templateId); |
| 63 | +console.log(templateDetails); |
| 64 | +``` |
| 65 | + |
| 66 | +**simulateQuery(query: QueryRequestFor_String): Promise<object>:** Simulate a query. |
| 67 | +```typescript |
| 68 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 69 | +const query = { ... }; |
| 70 | +const queryResult = await warpSdk.simulateQuery(query); |
| 71 | +console.log(queryResult); |
| 72 | +``` |
| 73 | + |
| 74 | +**account(owner: string): Promise<Account>:** Get an account by its owner. |
| 75 | +```typescript |
| 76 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 77 | +const accountId = 'accountId'; |
| 78 | +const accountDetails = await WarpSdk.account(accountId); |
| 79 | +console.log(accountDetails); |
| 80 | +``` |
| 81 | + |
| 82 | +**accounts(opts: QueryAccountsMsg): Promise<Account[]>:** List accounts with optional filters. |
| 83 | +```typescript |
| 84 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 85 | +const allAccounts = await warpSdk.accounts(); |
| 86 | +console.log(allAccounts); |
| 87 | +``` |
| 88 | + |
| 89 | +**config(): Promise<Config>:** Get the config of the Warp Protocol. |
| 90 | +```typescript |
| 91 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 92 | +const configInfo = await warpSdk.config(); |
| 93 | +console.log(configInfo); |
| 94 | +``` |
| 95 | + |
| 96 | +**createJob(sender: string, msg: CreateJobMsg): Promise<TxInfo>:** Create a job. |
| 97 | +```typescript |
| 98 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 99 | + |
| 100 | +const msg = { |
| 101 | + ...., |
| 102 | + msgs: [...], |
| 103 | + reward: '1000000', |
| 104 | + condition: { |
| 105 | + and: [{ |
| 106 | + expr: { |
| 107 | + string: { |
| 108 | + left: { |
| 109 | + value: 'val1', |
| 110 | + }, |
| 111 | + op: 'eq', |
| 112 | + right: { |
| 113 | + value: 'val1', |
| 114 | + }, |
| 115 | + }, |
| 116 | + }, |
| 117 | + }], |
| 118 | + }, |
| 119 | +}; |
| 120 | + |
| 121 | +const sender = 'sender address'; |
| 122 | +const job = await warpSdk.createJob(sender, msg); |
| 123 | +console.log(job); |
| 124 | +``` |
| 125 | + |
| 126 | +**createJobSequence(sender: string, sequence: CreateJobMsg[]): Promise<TxInfo>:** Create a sequence of jobs. |
| 127 | +```typescript |
| 128 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 129 | + |
| 130 | +const msg1 = { |
| 131 | + ... |
| 132 | + msgs: [...], |
| 133 | + reward: '1000000', |
| 134 | + condition: { |
| 135 | + and: [{ |
| 136 | + expr: { |
| 137 | + string: { |
| 138 | + left: { |
| 139 | + value: 'val1', |
| 140 | + }, |
| 141 | + op: 'eq', |
| 142 | + right: { |
| 143 | + value: 'val1', |
| 144 | + }, |
| 145 | + }, |
| 146 | + }, |
| 147 | + }], |
| 148 | + }], |
| 149 | +}; |
| 150 | + |
| 151 | +const msg2 = { |
| 152 | + ..., |
| 153 | + msgs: [...], |
| 154 | + reward: '1000000', |
| 155 | + condition: { |
| 156 | + and: [{ |
| 157 | + expr: { |
| 158 | + string: { |
| 159 | + left: { |
| 160 | + value: 'val', |
| 161 | + }, |
| 162 | + op: 'eq', |
| 163 | + right: { |
| 164 | + value: 'val2', |
| 165 | + }, |
| 166 | + }, |
| 167 | + }, |
| 168 | + }], |
| 169 | + }, |
| 170 | +}; |
| 171 | + |
| 172 | +const sender = 'sender address'; |
| 173 | +const jobSequence = await warpSdk.createJobSequence(sender, [msg1, msg2]); |
| 174 | +console.log(jobSequence); |
| 175 | +``` |
| 176 | + |
| 177 | +**deleteJob(sender: string, jobId: string): Promise<TxInfo>:** Delete a job. |
| 178 | +```typescript |
| 179 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 180 | +const sender = 'sender address'; |
| 181 | + |
| 182 | +const jobId = 'abc123'; |
| 183 | +const response = await warpSdk.deleteJob(sender, jobId); |
| 184 | +console.log(response); |
| 185 | +``` |
| 186 | + |
| 187 | +**updateJob(sender: string, msg: UpdateJobMsg): Promise<TxInfo>:** Update a job. |
| 188 | +```typescript |
| 189 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 190 | +const sender = 'sender address'; |
| 191 | + |
| 192 | +const jobId = 'abc123'; |
| 193 | +const updateData = { name: 'Updated Job Name' }; |
| 194 | +const response = await warpSdk.updateJob(jobId, updateData); |
| 195 | +console.log(response); |
| 196 | +``` |
| 197 | + |
| 198 | +**executeJob(sender: string, jobId: string): Promise<TxInfo>:** Execute a job. |
| 199 | +```typescript |
| 200 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 201 | +const sender = 'sender address'; |
| 202 | + |
| 203 | +const jobId = 'abc123'; |
| 204 | +const response = await warpSdk.executeJob(jobId); |
| 205 | +console.log(response); |
| 206 | +``` |
| 207 | + |
| 208 | +**submitTemplate(sender: string, msg: SubmitTemplateMsg): Promise<TxInfo>:** Submit a template. |
| 209 | +```typescript |
| 210 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 211 | + |
| 212 | +const template = { name: 'Template 1', formatted_str: 'this is a template', vars: []}; |
| 213 | +const response = await sdk.submitTemplate(template); |
| 214 | +console.log(response); |
| 215 | +``` |
| 216 | + |
| 217 | +**deleteTemplate(sender: string, templateId: string): Promise<TxInfo>:** Delete a template. |
| 218 | +```typescript |
| 219 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 220 | +const sender = 'sender address'; |
| 221 | + |
| 222 | +const templateId = 'template_id'; |
| 223 | +const response = await sdk.deleteTemplate(sender, templateId); |
| 224 | +console.log(response); |
| 225 | +``` |
| 226 | + |
| 227 | +**editTemplate(sender: string, msg: EditTemplateMsg): Promise<TxInfo>:** Edit a template. |
| 228 | +```typescript |
| 229 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 230 | + |
| 231 | +const templateId = 'template_id'; |
| 232 | +const updates = { name: 'Updated Template' }; |
| 233 | +const response = await warpSdk.editTemplate(templateId, updates); |
| 234 | +console.log(response); |
| 235 | +``` |
| 236 | + |
| 237 | +**createAccount(sender: string): Promise<TxInfo>** |
| 238 | +```typescript |
| 239 | +const warpSdk = new WarpSdk(wallet, contractAddress); |
| 240 | + |
| 241 | +const sender = 'sender address'; |
| 242 | +const account = await warpSdk.createAccount(sender); |
| 243 | +console.log(account); |
| 244 | +``` |
0 commit comments