@agoric/fast-usdc 0.1.1-dev-9e5f628.0 → 0.1.1-dev-6fbd20a.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/fast-usdc",
3
- "version": "0.1.1-dev-9e5f628.0+9e5f628",
3
+ "version": "0.1.1-dev-6fbd20a.0+6fbd20a",
4
4
  "description": "CLI and library for Fast USDC product",
5
5
  "type": "module",
6
6
  "files": [
@@ -22,9 +22,9 @@
22
22
  "lint:eslint": "eslint ."
23
23
  },
24
24
  "devDependencies": {
25
- "@agoric/swingset-liveslots": "0.10.3-dev-9e5f628.0+9e5f628",
26
- "@agoric/vats": "0.15.2-dev-9e5f628.0+9e5f628",
27
- "@agoric/zone": "0.2.3-dev-9e5f628.0+9e5f628",
25
+ "@agoric/swingset-liveslots": "0.10.3-dev-6fbd20a.0+6fbd20a",
26
+ "@agoric/vats": "0.15.2-dev-6fbd20a.0+6fbd20a",
27
+ "@agoric/zone": "0.2.3-dev-6fbd20a.0+6fbd20a",
28
28
  "@fast-check/ava": "^2.0.1",
29
29
  "ava": "^5.3.0",
30
30
  "c8": "^10.1.2",
@@ -32,16 +32,16 @@
32
32
  "ts-blank-space": "^0.4.4"
33
33
  },
34
34
  "dependencies": {
35
- "@agoric/client-utils": "0.1.1-dev-9e5f628.0+9e5f628",
36
- "@agoric/cosmic-proto": "0.4.1-dev-9e5f628.0+9e5f628",
37
- "@agoric/ertp": "0.16.3-dev-9e5f628.0+9e5f628",
38
- "@agoric/internal": "0.3.3-dev-9e5f628.0+9e5f628",
39
- "@agoric/notifier": "0.6.3-dev-9e5f628.0+9e5f628",
40
- "@agoric/orchestration": "0.1.1-dev-9e5f628.0+9e5f628",
41
- "@agoric/store": "0.9.3-dev-9e5f628.0+9e5f628",
42
- "@agoric/vat-data": "0.5.3-dev-9e5f628.0+9e5f628",
43
- "@agoric/vow": "0.1.1-dev-9e5f628.0+9e5f628",
44
- "@agoric/zoe": "0.26.3-dev-9e5f628.0+9e5f628",
35
+ "@agoric/client-utils": "0.1.1-dev-6fbd20a.0+6fbd20a",
36
+ "@agoric/cosmic-proto": "0.4.1-dev-6fbd20a.0+6fbd20a",
37
+ "@agoric/ertp": "0.16.3-dev-6fbd20a.0+6fbd20a",
38
+ "@agoric/internal": "0.3.3-dev-6fbd20a.0+6fbd20a",
39
+ "@agoric/notifier": "0.6.3-dev-6fbd20a.0+6fbd20a",
40
+ "@agoric/orchestration": "0.1.1-dev-6fbd20a.0+6fbd20a",
41
+ "@agoric/store": "0.9.3-dev-6fbd20a.0+6fbd20a",
42
+ "@agoric/vat-data": "0.5.3-dev-6fbd20a.0+6fbd20a",
43
+ "@agoric/vow": "0.1.1-dev-6fbd20a.0+6fbd20a",
44
+ "@agoric/zoe": "0.26.3-dev-6fbd20a.0+6fbd20a",
45
45
  "@cosmjs/proto-signing": "^0.32.4",
46
46
  "@cosmjs/stargate": "^0.32.4",
47
47
  "@endo/base64": "^1.0.9",
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "9e5f628a3d953539bcea5e3ba2365367158ec069"
84
+ "gitHead": "6fbd20a0d6b8342a0f607960da5b5b6550c29fa8"
85
85
  }
package/src/cli/cli.js CHANGED
@@ -91,7 +91,12 @@ export const initProgram = (
91
91
  /** @type {string} */ amount,
92
92
  /** @type {string} */ destination,
93
93
  ) => {
94
+ const start = now();
94
95
  await transferHelpers.transfer(makeConfigFile(), amount, destination);
96
+ const duration = now() - start;
97
+ stdout.write(
98
+ `Transfer finished in ${(duration / 1000).toFixed(1)} seconds`,
99
+ );
95
100
  },
96
101
  );
97
102
 
package/src/cli/config.js CHANGED
@@ -1,6 +1,14 @@
1
1
  import * as readline from 'node:readline/promises';
2
2
  import { stdin as input, stdout as output } from 'node:process';
3
3
 
4
+ /**
5
+ @typedef {{
6
+ bech32Prefix: string,
7
+ api: string,
8
+ USDCDenom: string
9
+ }} DestinationChain
10
+ */
11
+
4
12
  /**
5
13
  @typedef {{
6
14
  nobleSeed: string,
@@ -11,6 +19,7 @@ import { stdin as input, stdout as output } from 'node:process';
11
19
  ethRpc: string,
12
20
  tokenMessengerAddress: string,
13
21
  tokenAddress: string
22
+ destinationChains?: DestinationChain[]
14
23
  }} ConfigOpts
15
24
  */
16
25
 
@@ -14,6 +14,7 @@ import {
14
14
  queryForwardingAccount,
15
15
  registerFwdAccount,
16
16
  } from '../util/noble.js';
17
+ import { queryUSDCBalance } from '../util/bank.js';
17
18
 
18
19
  /** @import { File } from '../util/file' */
19
20
  /** @import { VStorage } from '@agoric/client-utils' */
@@ -30,6 +31,7 @@ const transfer = async (
30
31
  /** @type {{signer: SigningStargateClient, address: string} | undefined} */ nobleSigner,
31
32
  /** @type {ethProvider | undefined} */ ethProvider,
32
33
  env = process.env,
34
+ setTimeout = globalThis.setTimeout,
33
35
  ) => {
34
36
  const execute = async (
35
37
  /** @type {import('./config').ConfigOpts} */ config,
@@ -71,6 +73,18 @@ const transfer = async (
71
73
  }
72
74
  }
73
75
 
76
+ const destChain = config.destinationChains?.find(chain =>
77
+ EUD.startsWith(chain.bech32Prefix),
78
+ );
79
+ if (!destChain) {
80
+ out.error(
81
+ `No destination chain found in config with matching bech32 prefix for ${EUD}, cannot query destination address`,
82
+ );
83
+ throw new Error();
84
+ }
85
+ const { api, USDCDenom } = destChain;
86
+ const startingBalance = await queryUSDCBalance(EUD, api, USDCDenom, fetch);
87
+
74
88
  ethProvider ||= makeProvider(config.ethRpc);
75
89
  await depositForBurn(
76
90
  ethProvider,
@@ -81,6 +95,34 @@ const transfer = async (
81
95
  amount,
82
96
  out,
83
97
  );
98
+
99
+ const refreshDelayMS = 1200;
100
+ const completeP = /** @type {Promise<void>} */ (
101
+ new Promise((res, rej) => {
102
+ const refreshUSDCBalance = async () => {
103
+ out.log('polling usdc balance');
104
+ const currentBalance = await queryUSDCBalance(
105
+ EUD,
106
+ api,
107
+ USDCDenom,
108
+ fetch,
109
+ );
110
+ if (currentBalance !== startingBalance) {
111
+ res();
112
+ } else {
113
+ setTimeout(() => refreshUSDCBalance().catch(rej), refreshDelayMS);
114
+ }
115
+ };
116
+ refreshUSDCBalance().catch(rej);
117
+ })
118
+ ).catch(e => {
119
+ out.error(
120
+ 'Error checking destination address balance, could not detect completion of transfer.',
121
+ );
122
+ out.error(e.message);
123
+ });
124
+
125
+ await completeP;
84
126
  };
85
127
 
86
128
  let config;
@@ -0,0 +1,12 @@
1
+ export const queryUSDCBalance = async (
2
+ /** @type {string} */ address,
3
+ /** @type {string} */ api,
4
+ /** @type {string} */ denom,
5
+ /** @type {typeof globalThis.fetch} */ fetch,
6
+ ) => {
7
+ const query = `${api}/cosmos/bank/v1beta1/balances/${address}`;
8
+ const json = await fetch(query).then(res => res.json());
9
+ const amount = json.balances?.find(b => b.denom === denom)?.amount ?? '0';
10
+
11
+ return BigInt(amount);
12
+ };
package/src/util/cctp.js CHANGED
@@ -67,5 +67,5 @@ export const depositForBurn = async (
67
67
 
68
68
  out.log('Transaction confirmed in block', receipt.blockNumber);
69
69
  out.log('Transaction hash:', receipt.hash);
70
- out.log('USDC transfer initiated successfully, our work here is done.');
70
+ out.log('USDC transfer initiated successfully');
71
71
  };