@argonprotocol/mainchain 1.3.7 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,7 @@ This is a Node.js client for the Argon Protocol (https://argonprotocol.org). It
2
2
  core features:
3
3
 
4
4
  1. A typescript generated RPC client for the Argon Protocol.
5
- 2. A CLI for interacting with a subset of the Argon Protocol (Mining Bidding, Vaults, Liquidity
6
- Pools, Bitcoin)
7
- 3. A "Wage Protector" class that can be used to protect wages against inflation or deflation of the
5
+ 2. A "Wage Protector" class that can be used to protect wages against inflation or deflation of the
8
6
  Argon.
9
7
 
10
8
  ## Installation
@@ -56,193 +54,12 @@ interface IArgonCpiSnapshot {
56
54
  }
57
55
  ```
58
56
 
59
- ## Library Classes
57
+ ## Bitcoin Locks
60
58
 
61
- The library has a few classes that are used to interact with the Argon Protocol.
59
+ The client also has a `BitcoinLock` class that can be used to create, ratchet and release bitcoin
60
+ locks
62
61
 
63
- `clis` - this is a collection of cli commands and helpers. Included here are two helpers to read and
64
- store encrypted wallets from Polkadot.js or a wallet like [Talisman](https://talisman.xyz/).
62
+ ## Vaults
65
63
 
66
- `Accountset.ts` - manage subaccounts from a single keypair
67
-
68
- ```typescript
69
- import {
70
- Accountset,
71
- getClient,
72
- type KeyringPair,
73
- mnemonicGenerate,
74
- } from '@argonprotocol/mainchain';
75
- import { keyringFromFile } from '@argonprotocol/mainchain/clis';
76
- import { existsSync, promises as fs } from 'node:fs';
77
-
78
- const mnemonicFile = './sessionKeyMnemonic.key';
79
- // generate keys that are used to sign blocks.
80
- if (!existsSync(mnemonicFile)) {
81
- const sessionKeyMnemonic = mnemonicGenerate();
82
- await fs.writeFile(sessionKeyMnemonic, 'utf8');
83
- }
84
- const sessionKeyMnemonic = await fs.readFile(mnemonicFile, 'utf8');
85
- const seedAccount = await keyringFromFile({
86
- filePath: '<path to file>',
87
- passphrase: 'my password',
88
- });
89
- const mainchainUrl = 'wss://rpc.argon.network';
90
- const client = getClient(mainchainUrl);
91
- this.accountset = new Accountset({
92
- client,
93
- seedAccount,
94
- sessionKeyMnemonic,
95
- subaccountRange: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
96
- });
97
-
98
- // register your keys on your miner
99
- await this.accountset.registerKeys(localRpcUrl);
100
- ```
101
-
102
- `BidPool.ts` - monitor mining bid pools
103
-
104
- `BitcoinLocks.ts` - wait for bitcoin space, create bitcoin transactions and look up market pricing
105
-
106
- `CohortBidder.ts` - create a bidding bot
107
-
108
- ```typescript
109
- import { CohortBidder } from '@argonprotocol/mainchain';
110
-
111
- // on new bidding
112
- const subaccounts = await accountset.getAvailableMinerAccounts(5);
113
- const cohortBidder = new CohortBidder(accountset, cohortFrameId, subaccounts, {
114
- maxSeats: 5,
115
- // a budget not to exceed
116
- maxBudget: 100_000_000,
117
- // only spend max 1 argon per seat
118
- maxBid: 1_000_000,
119
- // start bidding at 0.5 argons
120
- minBid: 500_000,
121
- // increment by 0.01 argons each bid
122
- bidIncrement: 10_000,
123
- // wait 10 minutes between bids
124
- bidDelay: 10,
125
- });
126
- ```
127
-
128
- `MiningBids.ts` - subscribe to the next bidding cohorts
129
-
130
- ```typescript
131
- import { MiningBids } from '@argonprotocol/mainchain';
132
-
133
- const miningBids = new MiningBids(client);
134
- const { unsubscribe } = await miningBids.onCohortChange({
135
- async onBiddingStart(cohortFrameId) {
136
- // ...
137
- },
138
- async onBiddingEnd(cohortFrameId) {
139
- // ...
140
- },
141
- });
142
- ```
143
-
144
- `Vault.ts + VaultMonitor.ts` - watch vaults for available funds/opportunities and calculate fees
145
-
146
- ## Cli
147
-
148
- To use this CLI, the easiest way is to define an .env file with the following variables (you can
149
- also provide these to each command).
150
-
151
- ```env
152
- MAINCHAIN_URL=ws://localhost:9944
153
- ACCOUNT_SURI=# a suri for the account
154
- ACCOUNT_JSON_PATH=# a path to a polkadotjs extracted account json
155
- ACCOUNT_PASSPHRASE=# a passphrase for the pjs json account
156
- SUBACCOUNT_RANGE=# number of subaccounts to manage
157
- KEYS_MNEMONIC=# a mnemonic for the keys to generate
158
- ```
159
-
160
- ### Setup
161
-
162
- To perform actions like `bidding on mining seats`, this cli will need to run for a long period of
163
- time. The easiest way to do so is to install it alongside a full node. This gives you a server that:
164
-
165
- 1. Will stay alive.
166
- 2. Can have signing keys installed without exposing apis.
167
- 3. Is a trusted source to submit your bid apis through.
168
-
169
- You can setup an account as per the files above by running this command to start:
170
-
171
- ```bash
172
- npx @argonprotocol/mainchain accounts create --path=.env.bob --account-suri=//Bob --register-keys=http://localhost:9944
173
- ```
174
-
175
- Or with an exported Polkadotjs account (eg, from Talisman, Polkadot Extension, etc):
176
-
177
- ```bash
178
- npx @argonprotocol/mainchain accounts create --path=.env.bob --account-file-path=./bob.json --account-passphrase=1234 --register-keys=http://localhost:9944
179
- ```
180
-
181
- This will register your keys with the local node and serve as your `--env` file for the rest of the
182
- commands.
183
-
184
- ### Exporting PolkadotJs Keys
185
-
186
- You can export encrypted json accounts from Polkadot.js to use in this tool.
187
-
188
- 1. Go to the [Polkadot.js Apps](https://polkadot.js.org/apps/#/accounts).
189
- 2. Click on the dropdown for the account you want to export.
190
- 3. Click on the "Export Account" button.
191
- 4. Enter a password to encrypt the JSON file.
192
- 5. Move the file to somewhere accessible from where this tool is run (or to mounted docker volumes).
193
- 6. Ensure your `.env.<account>` file has a relative path to this JSON file and the password you used
194
- to encrypt it.
195
-
196
- ### Security Concerns (Bid Proxy Account)
197
-
198
- You might find the idea of putting an account on your server with the private key to be too risky.
199
- You can optionally create a proxy account for your bidder script using
200
- `npx @argonprotocol/mainchain mining create-bid-proxy`. You will need to run this from a machine
201
- with access to your full account keys (either via export or Polkadotjs directly). This will create a
202
- new `env`account file with the proxy details, which you'll use as your env file for the rest of the
203
- commands. The proxy will only be able to make `bid` calls and will not be able to transfer funds or
204
- do anything else with the account. This is a good way to limit the exposure of your main account
205
- keys.
206
-
207
- NOTE: you will still pay fees from your proxy account, so ensure you keep this account loaded up
208
- with fees. This is a major downside to this approach that we are still seeking to solve.
209
-
210
- ### Commands
211
-
212
- ```
213
- Usage: Argon CLI [options] [command]
214
-
215
- Options:
216
- -e, --env <path> The path to the account .env file to load
217
- -u, --mainchain-url <url> The mainchain URL to connect to (default: "wss://rpc.argon.network", env: MAINCHAIN_URL)
218
- --account-file-path <jsonPath> The path to your json seed file from polkadotjs (env: ACCOUNT_JSON_PATH)
219
- --account-suri <secretUri> A secret uri (suri) to use for the account (env: ACCOUNT_SURI)
220
- --account-passphrase <password> The password for your seed file (env: ACCOUNT_PASSPHRASE)
221
- --account-passphrase-file <path> A password for your seed file contained in a file
222
- -s, --subaccounts <range> Restrict this operation to a subset of the subaccounts (eg, 0-10) (env: SUBACCOUNT_RANGE)
223
- -h, --help display help for command
224
-
225
- Commands:
226
- accounts Manage subaccounts from a single keypair
227
- vaults Monitor vaults and manage securitization
228
- mining Watch mining seats or setup bidding
229
- liquidity-pools Monitor or bond to liquidity pools
230
- bitcoin Wait for bitcoin space
231
- help [command] display help for command
232
- ```
233
-
234
- ### Example Commands
235
-
236
- Create a dynamic bid for a mining seat, maxed at 10 argons per seat. Without a budget, this will use
237
- up to 100 argons ( eg, 10 seats).
238
-
239
- ```bash
240
- npx @argonprotocol/mainchain --env=accounts/.env.bob mining bid --min-bid=1 --max-bid=10 --bid-increment=0.1
241
- ```
242
-
243
- ### Subaccounts
244
-
245
- If you want to work with subaccounts during `consolidate` or setup of an account you can use the
246
- `-s, --subaccounts` flag to specify which subaccount to work with. `-s=0-9` is the default. You can
247
- also use `-s=0,1,2` to specify a list of subaccounts. You can also use `-s=0-2,4` to specify a range
248
- and a list of subaccounts.
64
+ The client also has a `Vault` class that can be used to create and manage vaults, as well as
65
+ calculate bitcoin fees.