-
Notifications
You must be signed in to change notification settings - Fork 38
add cashu token melting to mutiny-node #1026
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really close, just a couple things
3446201
to
693c31f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you squash the commits?
Just some nits, otherwise lgtm
mutiny-core/src/lib.rs
Outdated
.clone() | ||
.bolt11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you do .bolt11.clone()
instead of .clone().bolt11
then it'll only clone the invoice instead of the whole struct.
mutiny-core/src/lib.rs
Outdated
let invoice_amount = token.proofs.total_amount() as f64 * (1.0 - 3.0 / 100.0); | ||
|
||
let mut mutiny_invoice = self | ||
.create_invoice(invoice_amount as u64, vec!["Cashu Token Melt".to_string()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make "Cashu Token Melt"
a const at the top of this file, we have one for SWAP
as well
mutiny-wasm/src/lib.rs
Outdated
Ok(JsValue::from_serde( | ||
&self.inner.melt_cashu_token(token).await?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to convert this into mutiny-wasm's version of MutinyInvoice
Have to do something like this.
let result = self.inner.melt_cashu_token(token).await?;
let invoices: Vec<MutinyInvoice> = result.into_iter().map(|i| i.into()).collect();
Ok(JsValue::from_serde(&invoices)?)
693c31f
to
5715450
Compare
mutiny-core/src/lib.rs
Outdated
log_debug!( | ||
self.logger, | ||
"will need to add extra outputs for overpaid fees" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, can we log the amount here as well.
should be something like
let amt = post_melt_bolt11_response.change.iter().map(|s|s.amount).sum();
you can add it to the log by just putting "{amt}"
5715450
to
547c246
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Cargo.lock
Outdated
] | ||
|
||
[[package]] | ||
name = "libsqlite3-sys" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eww, this adds another 4MB? Does mocha really need to pull in sqlite?
Cargo.lock
Outdated
] | ||
|
||
[[package]] | ||
name = "moksha-wallet" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pulls in a lot of dependencies. What is in moksha wallet that isn't in core that we need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moksha-core is providing the basic crypto implementation and primitives. Moksha-wallet adds a higher abstraction layer for working with a mint and provides methods for minting, melting, exporting etc. Since v1 cashu is using quotes for all the apis. The wallet hides this complexity and also adds multiple implementations for desktop/web httpclients and databases for storing the tokens. If you are not interested in storing tokens and just want to redeem them for a bolt11 invoice, using moksha-core might be the right choice.
mutiny-core/src/lib.rs
Outdated
&self, | ||
token_v3: TokenV3, | ||
) -> Result<Vec<MutinyInvoice>, MutinyError> { | ||
let mint_client = CrossPlatformHttpClient::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If moksha_wallet
is just for an HTTP client, can we get rid of it by just pulling in our current http library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. I think we can get rid of moksha-wallet and make the http calls to the mint without it.
mutiny-core/src/lib.rs
Outdated
None => return Err(MutinyError::EmptyMintURLError), | ||
}; | ||
|
||
let invoice_amount = token.proofs.total_amount() as f64 * (1.0 - 3.0 / 100.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of 1.0 - 3.0 / 100.0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the amount for the invoice needs to be a bit lower than the actual amount of the cashu token to account for potential fees. Not sure on best way to calculate it but landed on that number after discussing with @benthecarman
mutiny-core/src/lib.rs
Outdated
log_debug!( | ||
self.logger, | ||
"will need to add extra outputs for {amt} for overpaid fees" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused why this debug is here. Should this be a warning? And does it always occur?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benthecarman commented to add that log that could be for a follow-up. Follow up could be to add outputs param to the post_melt_bolt
call in order to get the overpaid fees if any. Or if we create an invoice for "right" amount, we could get rid of this.
9e988e3
to
31b88eb
Compare
018ce0d
to
73031be
Compare
looks like you have some rebase conflicts in the cargo.lock, I would just revert the changes in there and then compile again, let cargo fix it for you |
mutiny-core/src/lib.rs
Outdated
.mint_post( | ||
&mint_url.join("/v1/melt/quote/bolt11")?, | ||
json!(quote_request), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can make this a dedicated function on the cashu client. This way you can just pass the mint url and a PostMeltQuoteBolt11Request
. Will make things easier to use in the future and we could eventually mock it for tests too
mutiny-core/src/lib.rs
Outdated
let post_melt_bolt11_response: PostMeltBolt11Response = self | ||
.cashu_client | ||
.mint_post(&mint_url.join("v1/melt/bolt11")?, json!(melt_request)) | ||
.await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should do the same for this function
mutiny-core/src/lib.rs
Outdated
|
||
let total_proofs_amount = token.proofs.total_amount(); | ||
// create invoice for 1% less than proofs amount | ||
let mut invoice_amount = total_proofs_amount as f64 * (1.0 - 1.0 / 100.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be more readable as
let mut invoice_amount = total_proofs_amount as f64 * 0.99;
73031be
to
0ca90b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good! Nice work.
The only question/comment I have on is around the multiple token thing. Is that common? If so, I wonder if all of the errors in the for
loop should just result in a continue
and if a new PartialCashuError
could be introduced. If it's not very common, then I think it's fine to leave it as is.
thanks! I believe the
|
mutiny-core/Cargo.toml
Outdated
@@ -56,6 +56,7 @@ fedimint-mint-client = { git = "https://github.com/fedimint/fedimint", rev = "6a | |||
fedimint-ln-client = { git = "https://github.com/fedimint/fedimint", rev = "6a923ee10c3a578cd835044e3fdd94aa5123735a" } | |||
fedimint-bip39 = { git = "https://github.com/fedimint/fedimint", rev = "6a923ee10c3a578cd835044e3fdd94aa5123735a" } | |||
fedimint-ln-common = { git = "https://github.com/fedimint/fedimint", rev = "6a923ee10c3a578cd835044e3fdd94aa5123735a" } | |||
moksha-core = { git = "https://github.com/ngutech21/moksha", rev = "0b9a32d216ba0782a4aa2cdb19a87589e16d9089" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated waila to the commit 18d99977965662d46ccec29fecdb0ce493745917
, can you do the same here so their in sync, then we should be good to go
0ca90b0
to
908851d
Compare
following up on @oleonardolima outline on #1021.