-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm_planner support gas fees & add ICS20 withdrawal #3198
Changes from 5 commits
0204a50
2b2e37d
48e92b5
d5fc8b9
8e085b9
84ca956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ use wasm_bindgen::JsValue; | |
use penumbra_chain::params::{ChainParameters, FmdParameters}; | ||
use penumbra_dex::swap_claim::SwapClaimPlan; | ||
use penumbra_proto::core::asset::v1alpha1::{DenomMetadata, Value}; | ||
use penumbra_proto::core::component::fee::v1alpha1::Fee; | ||
use penumbra_proto::core::component::fee::v1alpha1::{Fee, GasPrices}; | ||
use penumbra_proto::core::component::ibc::v1alpha1::Ics20Withdrawal; | ||
use penumbra_proto::core::keys::v1alpha1::Address; | ||
use penumbra_proto::core::transaction::v1alpha1::MemoPlaintext; | ||
use penumbra_proto::crypto::tct::v1alpha1::StateCommitment; | ||
|
@@ -65,6 +66,15 @@ impl WasmPlanner { | |
Ok(()) | ||
} | ||
|
||
/// Set gas prices | ||
/// Arguments: | ||
/// gas_prices: `GasPrices` | ||
pub fn set_gas_prices(&mut self, gas_prices: JsValue) -> WasmResult<()> { | ||
let gas_prices_proto: GasPrices = serde_wasm_bindgen::from_value(gas_prices)?; | ||
self.planner.set_gas_prices(gas_prices_proto.try_into()?); | ||
Ok(()) | ||
} | ||
|
||
/// Add memo to plan | ||
/// Arguments: | ||
/// memo: `MemoPlaintext` | ||
|
@@ -164,6 +174,15 @@ impl WasmPlanner { | |
Ok(()) | ||
} | ||
|
||
/// Add ICS20 withdrawal to plan | ||
/// Arguments: | ||
/// withdrawal: `Ics20Withdrawal` | ||
pub fn ics20_withdrawal(&mut self, withdrawal: JsValue) -> WasmResult<()> { | ||
let withdrawal_proto: Ics20Withdrawal = serde_wasm_bindgen::from_value(withdrawal)?; | ||
self.planner.ics20_withdrawal(withdrawal_proto.try_into()?); | ||
Ok(()) | ||
} | ||
|
||
/// Builds transaction plan. | ||
/// Refund address provided in the case there is extra balances to be returned. | ||
/// Arguments: | ||
|
@@ -172,6 +191,12 @@ impl WasmPlanner { | |
pub async fn plan(&mut self, refund_address: JsValue) -> WasmResult<JsValue> { | ||
utils::set_panic_hook(); | ||
|
||
// Calculate the gas that needs to be paid for the transaction based on the configured gas prices. | ||
// Note that _paying the fee might incur an additional `Spend` action_, thus increasing the fee, | ||
// so we slightly overpay here and then capture the excess as change later during `plan_with_spendable_and_votable_notes`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is overpaying what is being done in plci as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's just copied from pcli |
||
// Add the fee to the planner's internal balance. | ||
self.planner.add_gas_fees(); | ||
|
||
let mut spendable_notes = Vec::new(); | ||
|
||
let (spendable_requests, _) = self.planner.notes_requests(); | ||
|
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.
Instead of having this be a separate call that needs to be done at the end, why not put it inside
set_gas_prices
and it gets done as someone adds the gas price?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.
add_gas_fees
depends on the actions that have been added to the plan. We must ensure that new actions cannot be added afteradd_gas_fees()
is executed, so it is better to do it once at the end. And yes, this solution is also inherited from pcli