@agoric/fast-usdc 0.1.1-dev-02967de.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Fast USDC
2
+
3
+ Development package for the Fast USDC product.
4
+ Here in agoric-sdk as a convenience for integration testing and iterating on the SDK affordances required for the product.
5
+
6
+ # Factoring
7
+
8
+ This package is meant to contain all the code for the Fast USDC product. However there are some constraints:
9
+
10
+ - a3p integration tests are in the `a3p-integration` top-level package, separate from this workspace
11
+ - the proposal builders are in `@agoric/builders` to work with the a3p-integration `build:submissions` script
12
+ - the RunUtils tests are in `@agoric/boot` to test running them atop a fresh bootstrapped environment
13
+
14
+ Over time we can update our tooling to decouple this more from the `packages` directory.
15
+
16
+ 1. Make a3p-integration `build:submissions` script work with arbitrary builder paths, allowing this to be above `@agoric/builders` in the package graph
17
+ 2. Export bootstrap testing utilities from `@agoric/boot`, allowing this to be above `@agoric/boot` in the package graph
18
+ 3. Update CI to support packages that aren't under `packages/`, eg. a top-level `dapps` directory
19
+ 4. Move this package out of agoric-sdk
20
+
21
+ # Transaction feed
22
+
23
+ ## Oracles interface
24
+
25
+ Oracles run off-chain and interact with the contract via an Agoric smart wallet bridge.
26
+ ```mermaid
27
+ sequenceDiagram
28
+ title Becoming an oracle operator
29
+ participant OW as Operator N<br/>Smart Wallet
30
+ participant FUC as Fast USDC<br/>Contract Exo
31
+ participant CE as Core Eval
32
+
33
+ CE->>FUC: makeOperatorInvitation()
34
+ FUC-->>CE: operatorInvitation
35
+ CE->>+OW: deposit(operatorInvitation)
36
+
37
+ Note left of FUC: Off-chain wallet accepts the operator invitation
38
+
39
+ OW->>+FUC: offer(operatorInvitation)
40
+ FUC-->>OW: operator invitationMakers: {SubmitEvidence}
41
+
42
+ Note left of FUC: Off-chain watcher detects evidence
43
+ OW->>+FUC: offer(SubmitEvidence, evidence)
44
+ ```
45
+
46
+ ```mermaid
47
+ sequenceDiagram
48
+ title Receiving evidence
49
+ participant W as Operator N<br/>Smart Wallet
50
+ participant A as Operator N<br/>Admin Oexo
51
+ participant TF as Transaction<br/>Feed
52
+
53
+ W->>A: offer(SubmitEvidence, evidence)
54
+
55
+ Note left of A: Once 3 operators push the same…
56
+
57
+ A->>TF: notify(evidence)
58
+ ```
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@agoric/fast-usdc",
3
+ "version": "0.1.1-dev-02967de.0+02967de",
4
+ "description": "CLI and library for Fast USDC product",
5
+ "type": "module",
6
+ "files": [
7
+ "contract",
8
+ "src"
9
+ ],
10
+ "bin": {
11
+ "fast-usdc": "./src/cli/bin.js"
12
+ },
13
+ "scripts": {
14
+ "build": "exit 0",
15
+ "test": "ava",
16
+ "test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
17
+ "test:xs": "exit 0",
18
+ "lint-fix": "yarn lint:eslint --fix",
19
+ "lint": "run-s --continue-on-error lint:*",
20
+ "lint:types": "tsc",
21
+ "lint:eslint": "eslint ."
22
+ },
23
+ "devDependencies": {
24
+ "@agoric/swingset-liveslots": "0.10.3-dev-02967de.0+02967de",
25
+ "@agoric/vats": "0.15.2-dev-02967de.0+02967de",
26
+ "@agoric/zone": "0.2.3-dev-02967de.0+02967de",
27
+ "@fast-check/ava": "^2.0.1",
28
+ "ava": "^5.3.0",
29
+ "c8": "^9.1.0",
30
+ "execa": "9.1.0",
31
+ "ts-blank-space": "^0.4.1"
32
+ },
33
+ "dependencies": {
34
+ "@agoric/client-utils": "0.1.1-dev-02967de.0+02967de",
35
+ "@agoric/ertp": "0.16.3-dev-02967de.0+02967de",
36
+ "@agoric/internal": "0.3.3-dev-02967de.0+02967de",
37
+ "@agoric/notifier": "0.6.3-dev-02967de.0+02967de",
38
+ "@agoric/orchestration": "0.1.1-dev-02967de.0+02967de",
39
+ "@agoric/store": "0.9.3-dev-02967de.0+02967de",
40
+ "@agoric/vat-data": "0.5.3-dev-02967de.0+02967de",
41
+ "@agoric/vow": "0.1.1-dev-02967de.0+02967de",
42
+ "@agoric/zoe": "0.26.3-dev-02967de.0+02967de",
43
+ "@cosmjs/proto-signing": "^0.32.4",
44
+ "@cosmjs/stargate": "^0.32.4",
45
+ "@endo/base64": "^1.0.9",
46
+ "@endo/common": "^1.2.8",
47
+ "@endo/errors": "^1.2.8",
48
+ "@endo/eventual-send": "^1.2.8",
49
+ "@endo/far": "^1.1.9",
50
+ "@endo/init": "^1.1.7",
51
+ "@endo/marshal": "^1.6.2",
52
+ "@endo/pass-style": "^1.4.7",
53
+ "@endo/patterns": "^1.4.7",
54
+ "@endo/promise-kit": "^1.1.8",
55
+ "@nick134-bit/noblejs": "0.0.2",
56
+ "bech32": "^2.0.0",
57
+ "commander": "^12.1.0",
58
+ "ethers": "^6.13.4"
59
+ },
60
+ "ava": {
61
+ "extensions": {
62
+ "js": true,
63
+ "ts": "module"
64
+ },
65
+ "files": [
66
+ "test/**/*.test.*"
67
+ ],
68
+ "nodeArguments": [
69
+ "--import=ts-blank-space/register",
70
+ "--no-warnings"
71
+ ],
72
+ "require": [
73
+ "@endo/init/debug.js"
74
+ ],
75
+ "timeout": "20m"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public"
79
+ },
80
+ "gitHead": "02967de672887513c78a98565e95b2932f165863"
81
+ }
package/src/cli/bin.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import '@endo/init/legacy.js';
3
+ import { initProgram } from './cli.js';
4
+
5
+ const program = initProgram();
6
+ program.parse();
package/src/cli/cli.js ADDED
@@ -0,0 +1,211 @@
1
+ import { assertParsableNumber } from '@agoric/zoe/src/contractSupport/ratio.js';
2
+ import {
3
+ Command,
4
+ InvalidArgumentError,
5
+ InvalidOptionArgumentError,
6
+ } from 'commander';
7
+ import { existsSync, mkdirSync, readFileSync } from 'fs';
8
+ import { fileURLToPath } from 'url';
9
+ import { dirname, resolve } from 'path';
10
+ import { homedir } from 'os';
11
+ import {
12
+ readFile as readAsync,
13
+ writeFile as writeAsync,
14
+ } from 'node:fs/promises';
15
+ import configLib from './config.js';
16
+ import transferLib from './transfer.js';
17
+ import { makeFile } from '../util/file.js';
18
+
19
+ const packageJson = JSON.parse(
20
+ readFileSync(
21
+ resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json'),
22
+ 'utf8',
23
+ ),
24
+ );
25
+
26
+ const defaultHome = homedir();
27
+
28
+ export const initProgram = (
29
+ configHelpers = configLib,
30
+ transferHelpers = transferLib,
31
+ readFile = readAsync,
32
+ writeFile = writeAsync,
33
+ mkdir = mkdirSync,
34
+ exists = existsSync,
35
+ ) => {
36
+ const program = new Command();
37
+
38
+ program
39
+ .name('fast-usdc')
40
+ .description('CLI to interact with Fast USDC liquidity pool')
41
+ .version(packageJson.version)
42
+ .option(
43
+ '--home <path>',
44
+ `Home directory to use for config`,
45
+ `${defaultHome}/.fast-usdc/`,
46
+ );
47
+
48
+ const config = program.command('config').description('Manage config');
49
+
50
+ const configFilename = 'config.json';
51
+ const getConfigPath = () => {
52
+ const { home: configDir } = program.opts();
53
+ return configDir + configFilename;
54
+ };
55
+
56
+ const makeConfigFile = () =>
57
+ makeFile(getConfigPath(), readFile, writeFile, mkdir, exists);
58
+
59
+ config
60
+ .command('show')
61
+ .description('Show current config')
62
+ .action(async () => {
63
+ await configHelpers.show(makeConfigFile());
64
+ });
65
+
66
+ config
67
+ .command('init')
68
+ .description('Set initial config values')
69
+ .requiredOption(
70
+ '--noble-seed <seed>',
71
+ 'Seed phrase for Noble account. CAUTION: Stored unencrypted in file system',
72
+ )
73
+ .requiredOption(
74
+ '--eth-seed <seed>',
75
+ 'Seed phrase for Ethereum account. CAUTION: Stored unencrypted in file system',
76
+ )
77
+ .requiredOption(
78
+ '--agoric-seed <seed>',
79
+ 'Seed phrase for Agoric LP account. CAUTION: Stored unencrypted in file system',
80
+ )
81
+ .option(
82
+ '--agoric-rpc [url]',
83
+ 'Agoric RPC endpoint',
84
+ 'http://127.0.0.1:26656',
85
+ )
86
+ .option(
87
+ '--agoric-api [url]',
88
+ 'Agoric RPC endpoint',
89
+ 'http://127.0.0.1:1317',
90
+ )
91
+ .option('--noble-rpc [url]', 'Noble RPC endpoint', 'http://127.0.0.1:26657')
92
+ .option('--noble-api [url]', 'Noble API endpoint', 'http://127.0.0.1:1318')
93
+ .option('--eth-rpc [url]', 'Ethereum RPC Endpoint', 'http://127.0.0.1:8545')
94
+ .option(
95
+ '--noble-to-agoric-channel [channel]',
96
+ 'Channel ID on Noble for Agoric',
97
+ 'channel-21',
98
+ )
99
+ .option(
100
+ '--token-messenger-address [address]',
101
+ 'Address of TokenMessenger contract',
102
+ // Default to ETH mainnet contract address. For ETH sepolia, use 0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5
103
+ '0xbd3fa81b58ba92a82136038b25adec7066af3155',
104
+ )
105
+ .option(
106
+ '--token-contract-address [address]',
107
+ 'Address of USDC token contract',
108
+ // Detault to ETH mainnet token address. For ETH sepolia, use 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238
109
+ '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
110
+ )
111
+ .action(async options => {
112
+ await configHelpers.init(makeConfigFile(), options);
113
+ });
114
+
115
+ config
116
+ .command('update')
117
+ .description('Update config values')
118
+ .option(
119
+ '--noble-seed [string]',
120
+ 'Seed phrase for Noble account. CAUTION: Stored unencrypted in file system',
121
+ )
122
+ .option(
123
+ '--eth-seed [string]',
124
+ 'Seed phrase for Ethereum account. CAUTION: Stored unencrypted in file system',
125
+ )
126
+ .option(
127
+ '--agoric-seed <seed>',
128
+ 'Seed phrase for Agoric LP account. CAUTION: Stored unencrypted in file system',
129
+ )
130
+ .option('--agoric-rpc [url]', 'Agoric RPC endpoint')
131
+ .option('--agoric-api [url]', 'Agoric API endpoint')
132
+ .option('--noble-rpc [url]', 'Noble RPC endpoint')
133
+ .option('--noble-api [url]', 'Noble API endpoint')
134
+ .option('--eth-rpc [url]', 'Ethereum RPC Endpoint')
135
+ .option(
136
+ '--noble-to-agoric-channel [channel]',
137
+ 'Channel ID on Noble for Agoric',
138
+ )
139
+ .option(
140
+ '--token-messenger-address [address]',
141
+ 'Address of TokenMessenger contract',
142
+ )
143
+ .option(
144
+ '--token-contract-address [address]',
145
+ 'Address of USDC token contract',
146
+ )
147
+ .action(async options => {
148
+ await configHelpers.update(makeConfigFile(), options);
149
+ });
150
+
151
+ /** @param {string} value */
152
+ const parseDecimal = value => {
153
+ try {
154
+ assertParsableNumber(value);
155
+ } catch {
156
+ throw new InvalidArgumentError('Not a decimal number.');
157
+ }
158
+ return value;
159
+ };
160
+
161
+ /**
162
+ * @param {string} str
163
+ * @returns {'auto' | number}
164
+ */
165
+ const parseFee = str => {
166
+ if (str === 'auto') return 'auto';
167
+ const num = parseFloat(str);
168
+ if (Number.isNaN(num)) {
169
+ throw new InvalidOptionArgumentError('Fee must be a number.');
170
+ }
171
+ return num;
172
+ };
173
+
174
+ program
175
+ .command('deposit')
176
+ .description('Offer assets to the liquidity pool')
177
+ .argument('<give>', 'USDC to give', parseDecimal)
178
+ .option('--id [offer-id]', 'Offer ID')
179
+ .option('--fee [fee]', 'Cosmos fee', parseFee)
180
+ .action(() => {
181
+ console.error('TODO actually send deposit');
182
+ // TODO: Implement deposit logic
183
+ });
184
+
185
+ program
186
+ .command('withdraw')
187
+ .description('Withdraw assets from the liquidity pool')
188
+ .argument('<want>', 'USDC to withdraw', parseDecimal)
189
+ .option('--id [offer-id]', 'Offer ID')
190
+ .option('--fee [fee]', 'Cosmos fee', parseFee)
191
+ .action(() => {
192
+ console.error('TODO actually send withdrawal');
193
+ // TODO: Implement withdraw logic
194
+ });
195
+
196
+ program
197
+ .command('transfer')
198
+ .description('Transfer USDC from Ethereum/L2 to Cosmos via Fast USDC')
199
+ .argument('amount', 'Amount to transfer denominated in uusdc')
200
+ .argument('dest', 'Destination address in Cosmos')
201
+ .action(
202
+ async (
203
+ /** @type {string} */ amount,
204
+ /** @type {string} */ destination,
205
+ ) => {
206
+ await transferHelpers.transfer(makeConfigFile(), amount, destination);
207
+ },
208
+ );
209
+
210
+ return program;
211
+ };
@@ -0,0 +1,101 @@
1
+ import * as readline from 'node:readline/promises';
2
+ import { stdin as input, stdout as output } from 'node:process';
3
+
4
+ /**
5
+ @typedef {{
6
+ nobleSeed: string,
7
+ ethSeed: string,
8
+ nobleToAgoricChannel: string,
9
+ agoricRpc: string,
10
+ nobleApi: string,
11
+ nobleRpc: string,
12
+ ethRpc: string,
13
+ tokenMessengerAddress: string,
14
+ tokenAddress: string
15
+ }} ConfigOpts
16
+ */
17
+
18
+ /** @import { file } from '../util/file' */
19
+
20
+ const init = async (
21
+ /** @type {file} */ configFile,
22
+ /** @type {ConfigOpts} */ options,
23
+ out = console,
24
+ rl = readline.createInterface({ input, output }),
25
+ ) => {
26
+ const showOverrideWarning = async () => {
27
+ const answer = await rl.question(
28
+ `Config at ${configFile.path} already exists. Override it? (To partially update, use "update", or set "--home" to use a different config path.) y/N: `,
29
+ );
30
+ rl.close();
31
+ const confirmed = ['y', 'yes'].includes(answer.toLowerCase());
32
+ if (!confirmed) {
33
+ throw new Error('User cancelled');
34
+ }
35
+ };
36
+
37
+ const writeConfig = async () => {
38
+ await null;
39
+ try {
40
+ await configFile.write(JSON.stringify(options, null, 2));
41
+ out.log(`Config initialized at ${configFile.path}`);
42
+ } catch (error) {
43
+ out.error(`An unexpected error has occurred: ${error}`);
44
+ throw error;
45
+ }
46
+ };
47
+
48
+ await null;
49
+ if (configFile.exists()) {
50
+ await showOverrideWarning();
51
+ }
52
+ await writeConfig();
53
+ };
54
+
55
+ const update = async (
56
+ /** @type {file} */ configFile,
57
+ /** @type {Partial<ConfigOpts>} */ options,
58
+ out = console,
59
+ ) => {
60
+ const updateConfig = async (/** @type {ConfigOpts} */ data) => {
61
+ await null;
62
+ const stringified = JSON.stringify(data, null, 2);
63
+ try {
64
+ await configFile.write(stringified);
65
+ out.log(`Config updated at ${configFile.path}`);
66
+ out.log(stringified);
67
+ } catch (error) {
68
+ out.error(`An unexpected error has occurred: ${error}`);
69
+ throw error;
70
+ }
71
+ };
72
+
73
+ let file;
74
+ await null;
75
+ try {
76
+ file = await configFile.read();
77
+ } catch {
78
+ out.error(
79
+ `No config found at ${configFile.path}. Use "init" to create one, or "--home" to specify config location.`,
80
+ );
81
+ throw new Error();
82
+ }
83
+ await updateConfig({ ...JSON.parse(file), ...options });
84
+ };
85
+
86
+ const show = async (/** @type {file} */ configFile, out = console) => {
87
+ let contents;
88
+ await null;
89
+ try {
90
+ contents = await configFile.read();
91
+ } catch {
92
+ out.error(
93
+ `No config found at ${configFile.path}. Use "init" to create one, or "--home" to specify config location.`,
94
+ );
95
+ throw new Error();
96
+ }
97
+ out.log(`Config found at ${configFile.path}:`);
98
+ out.log(contents);
99
+ };
100
+
101
+ export default { init, update, show };