[BTC] Tx crafting#60
Conversation
* Align all cosmos packages versions * Update config: celestia nodeURL & dydx minGasPrice * Improve logs for all Cosmos node error messages * Better handle pubKey and other cosmos account data * Update dYdX node + minor fixes * Change nonce type from number to bigint + actually include it during cosmos completeTransaction
This reverts commit 132abf0.
This reverts commit 294e452.
This reverts commit e9632f8.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| }, | ||
| "pnpm": { | ||
| "patchedDependencies": { | ||
| "coinselect@3.1.13": "patches/coinselect@3.1.13.patch" |
There was a problem hiding this comment.
Do you have some context about the need for this patch? A link or anything.
Not mandatory just in case, could be useful for future reference.
There was a problem hiding this comment.
I put those links as context in the description of the PR:
with basic UTXO selection using bitcoinjs coinselect.
⚠️ Known issues:
Because the lib is only published in NPM without its types (bitcoinjs/coinselect#77 (comment)), I've patched the lib using their own definitions.
But your comment makes me think that I should put that context closer to the codebase itself. A recommendation?
There was a problem hiding this comment.
I chose to add the following documentation right next to the patch.
| /** | ||
| * add fields for compatibility with coinselect @see {@link UTXO} | ||
| */ |
There was a problem hiding this comment.
(nitpicking)
Single-line comment when possible, for more compact code
There was a problem hiding this comment.
I just wanted to have the @see {@link UTXO} picked up as JsDoc. And VS code only parses them when between /** .... */ 🙈
There was a problem hiding this comment.
Realised it could be done in one line 🤦
| * This should never happen because the transaction is already validated by zod | ||
| * @see {@link transactionDataSchema.refine} at the {@link transactionDataSchema} definition | ||
| * TODO: maybe we could make sure that completeTransaction directly receives a multi-recipient transaction ? | ||
| */ | ||
| if (!isMultiRecipientTransaction(transaction.data)) { | ||
| throw new Error(`Something went wrong, the transaction is not a multi-recipient transaction.`); | ||
| } |
There was a problem hiding this comment.
Should be solved after merging MultiRecipientTransaction into the regular TransferTransaction, if I followed correctly 🙂
| transaction: TransactionWrapper | ||
| ): Promise<void> { | ||
| throw new Error("Not implemented"); | ||
| async function completeTransaction(this: BtcService, transaction: TransactionWrapper): Promise<void> { |
There was a problem hiding this comment.
Just noticing useMaxAmount is not handled yet. Is it planned? (not a blocker, Fabrice said many times that this bonus feature would drop if it was any trouble)
| mode: TransactionMode.TRANSFER_TO_MANY; | ||
| sender: Xpub; | ||
| recipients: Recipient[]; | ||
| inputs?: UtxoWithMetadata[]; |
There was a problem hiding this comment.
That's new though! Would need to figure out if it makes sense in a regular TransferTransaction 🤔
However I don't remember if we discussed it, and sorry if we didn't, but this raises the question: should the client be given the possibility to pick UTXOs?
I am tempted to say 'no', at least for now. The Adamik API should only handle a single amount, both input and output, and manage UTXOs completely internally and behind the scenes from the user.
Even if we do in the future expose the inputs/outputs to the user, this will have to be an additional, bonus feature, on top of the standard single amount. This is important so Bitcoin can still be handled the same as the other chains on client side.
That's just the idea, but do you see any issue proceeding that way?
There was a problem hiding this comment.
Excellent points!
- I had discussed the introduction of
inputsas one of the reasons for a different tx model. Although, those are just for the user's information, they're not use as a input field (paradoxically 🤣) by the API.
So we could:
- remove it altogether (and only use an internal model to transit the input data between BTC family Service implementations) => my favourite (but longer to do)
- keep it as optional for debug purposes on the client side. => my actual recommendation (it's not perfect, but allows for a quick integration of BTC within the API and we could always remove this field later)
- Yes we discussed it and decided that the client should not be able to (for now).
=> I'll go for the introduction of an internal model to forward the input data between functions of the BTC service.
There was a problem hiding this comment.
😮 I just realised we're already talking about the inner model, the schema doesn't expose the inputs.
So it's only an internal model problem:
-> knowing we already agreed on having a regular TransferTransaction having family dependents optional fields (like gas)
=> I wouldn't see an issue in having an inputs for BTC usage only in here too.
|
|
||
| // Enrich inputs from the explorer | ||
| await Promise.all( | ||
| transaction.data.inputs.map(async (input, inputIndex) => { |
There was a problem hiding this comment.
Maybe I'm missing something, but aren't you always adding all inputs to the psbt?
There was a problem hiding this comment.
Right I am. At minimum we always have 2 recipients:
- the actual recipient of the transaction intent
- the change recipient
| }) | ||
| ); | ||
|
|
||
| for (const recipient of transaction.data.recipients) { |
There was a problem hiding this comment.
About recipients, don't you need to add the change output manually? And effectively add a recipient to the input transaction?
If I get it correctly, here you handle every recipient that's in the input transaction, i.e for an actual transfer request to multiple addresses (which by the way doesn't need to be supported, nice-to-have feature if we can have it at no cost)
There was a problem hiding this comment.
The change output was indeed added manually during the completeTransaction step: https://github.com/AdamikHQ/adamik/pull/60/files#diff-919690c591b9a53acc95310ea442b358e27fb74d4241dc1e1b20423e3d01323cR55
In all the inputs are already setup when we enter encodeTransactionToSign.
I have to handle multiple inputs because it's actually the default case for a BTC tx.
* Complete Cosmos staking implementation * Update OpenAPI JSON docs * Add prevalidation that transaction mode is supported for the chain * Update OpenAPI JSON docs * Better handle validation of token balance --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Additionally: - improved coinselect types and documentation - moved validation from zod to BTC service prevalidate as handling of simple transactions is widely different in BTC - fixed a potential race condition in transaction encoding
|
Should be ready to merge now as soon as 🟢 for you @hakim-adamik 👍 |
# Conflicts: # pnpm-lock.yaml # public/openapi.json # src/app/api/transaction/broadcast/schema.ts # src/app/families/common.ts # src/app/model/types_WIP.ts
# Conflicts: # package.json # pnpm-lock.yaml # public/openapi.json # src/app/api/transaction/broadcast/schema.ts # src/app/families/common.ts # src/app/model/types_WIP.ts
# Conflicts: # src/app/config/chains.ts # src/app/families/bitcoin/backend/explorer.ts # src/app/families/bitcoin/backend/types.ts # src/app/families/bitcoin/service/getAddressesState.ts # src/app/model/types_WIP.ts
|
OpenAPI Comparison results: 1 changes: 1 error, 0 warning, 0 info |
|
Damn! Github misinterpreted a faulty merge on Reopened here just for the merge back to btc_balances: |
This pull request adds support for:
Incoming:
useMaxAmountfield in the API transaction intent.