Skip to content

Commit

Permalink
Refactor Python withdraw example for clarity (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtin0x authored Jul 5, 2024
1 parent 5b297f5 commit 76dcbfc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions v4-client-py-v2/examples/transfer_example_withdraw_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ async def test():

wallet = await Wallet.from_mnemonic(node, DYDX_TEST_MNEMONIC, TEST_ADDRESS)

message = partial(withdraw, subaccount(TEST_ADDRESS, 0), TEST_ADDRESS, 0)
withdraw_tx = partial(withdraw, subaccount(TEST_ADDRESS, 0), TEST_ADDRESS, 0)
amount = 100_000_000

simulated = node.builder.build(wallet, message(amount))

simulation = await node.simulate(simulated)
simulated_txs = node.builder.build(wallet, withdraw_tx(amount))
simulation = await node.simulate(simulated_txs)
print("**Simulate**")
print(simulation)

fee = node.calculate_fee(simulation.gas_info.gas_used)
print("**Total Fee**")
print(fee)

response = await node.broadcast(
node.build(wallet, message(amount - fee.amount[0].amount), fee)
)
final_withdraw_tx = withdraw_tx(amount - fee.amount[0].amount)
final_txs = node.build(wallet, final_withdraw_tx, fee)
response = await node.broadcast(final_txs)
print("**Withdraw and Send**")
print(response)

Expand Down

0 comments on commit 76dcbfc

Please sign in to comment.