nansen-cli 2.1.0 → 2.2.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/CHANGELOG.md +33 -0
- package/package.json +1 -1
- package/src/schema.json +1 -1
- package/src/trading.js +647 -120
- package/src/walletconnect-trading.js +50 -13
|
@@ -104,6 +104,36 @@ export async function getWalletConnectAddress(chainType, chainId) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Run a wallet send and mark anything that goes wrong as an ambiguous handoff.
|
|
109
|
+
*
|
|
110
|
+
* Once the wallet has been asked to send, no failure here proves the
|
|
111
|
+
* transaction stayed put. `wcExec` collapses a user rejection, a 120s approval
|
|
112
|
+
* timeout and a failure to launch the binary into the same bare
|
|
113
|
+
* `Error(err.message)`, and the timeout is precisely the case where the user DID
|
|
114
|
+
* approve and the wallet DID broadcast while the subprocess gave up waiting. A
|
|
115
|
+
* reply we cannot parse, or one carrying neither a hash nor signed bytes, says
|
|
116
|
+
* just as little about what the wallet did.
|
|
117
|
+
*
|
|
118
|
+
* Callers must therefore never read one of these as "nothing was sent" and go on
|
|
119
|
+
* to send something else. Marking it here, at the boundary, is what makes that
|
|
120
|
+
* hold for every call site — including ones added later — instead of depending
|
|
121
|
+
* on each `catch` to remember. `isFatalBroadcastError` in trading.js treats the
|
|
122
|
+
* flag as terminal; it is deliberately distinct from `broadcastRuledOut`, which
|
|
123
|
+
* is the opposite claim (the backend stated nothing was sent).
|
|
124
|
+
*
|
|
125
|
+
* @param {() => Promise<T>} fn - the send, from the wallet call through parsing
|
|
126
|
+
* @returns {Promise<T>}
|
|
127
|
+
* @template T
|
|
128
|
+
*/
|
|
129
|
+
async function markBroadcastAmbiguous(fn) {
|
|
130
|
+
try {
|
|
131
|
+
return await fn();
|
|
132
|
+
} catch (err) {
|
|
133
|
+
throw Object.assign(err, { broadcastAmbiguous: true });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
107
137
|
/**
|
|
108
138
|
* Send a transaction via WalletConnect.
|
|
109
139
|
*
|
|
@@ -128,14 +158,16 @@ export async function sendTransactionViaWalletConnect(txData, timeoutMs = 120000
|
|
|
128
158
|
chainId,
|
|
129
159
|
};
|
|
130
160
|
|
|
131
|
-
|
|
132
|
-
|
|
161
|
+
return markBroadcastAmbiguous(async () => {
|
|
162
|
+
const output = await wcExec('walletconnect', ['send-transaction', JSON.stringify(payload)], timeoutMs);
|
|
163
|
+
const result = parseWcJson(output);
|
|
133
164
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
165
|
+
if (result.transactionHash) return { txHash: result.transactionHash };
|
|
166
|
+
if (result.txHash) return { txHash: result.txHash };
|
|
167
|
+
if (result.signedTransaction) return { signedTransaction: result.signedTransaction };
|
|
137
168
|
|
|
138
|
-
|
|
169
|
+
throw new Error('Unexpected response from walletconnect send-transaction');
|
|
170
|
+
});
|
|
139
171
|
}
|
|
140
172
|
|
|
141
173
|
/**
|
|
@@ -186,15 +218,20 @@ export async function sendSolanaTransactionViaWalletConnect(txBase58, timeoutMs
|
|
|
186
218
|
chainId: SOLANA_MAINNET_CHAIN,
|
|
187
219
|
};
|
|
188
220
|
|
|
189
|
-
|
|
190
|
-
|
|
221
|
+
// Marked ambiguous for the same reason as the EVM send: this goes out over the
|
|
222
|
+
// CLI's `send-transaction` verb, so a wallet that signs-and-sends has already
|
|
223
|
+
// broadcast by the time a timeout or an unreadable reply reaches us.
|
|
224
|
+
return markBroadcastAmbiguous(async () => {
|
|
225
|
+
const output = await wcExec('walletconnect', ['send-transaction', JSON.stringify(payload)], timeoutMs);
|
|
226
|
+
const result = parseWcJson(output);
|
|
191
227
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
228
|
+
if (result.signedTransaction) return { signedTransaction: result.signedTransaction };
|
|
229
|
+
if (result.signature) return { signature: result.signature };
|
|
230
|
+
// Some wallets (e.g. Phantom) return 'transaction' instead of 'signedTransaction'
|
|
231
|
+
if (result.transaction) return { signedTransaction: result.transaction };
|
|
196
232
|
|
|
197
|
-
|
|
233
|
+
throw new Error('Unexpected response from walletconnect Solana sign');
|
|
234
|
+
});
|
|
198
235
|
}
|
|
199
236
|
|
|
200
237
|
/**
|