Backend method for programmatically calling the GMXv2 smart contracts using Paradigms alloy-rs crate.
NOTE: helpful link here - https://dashboard.tenderly.co/tx/arbitrum/0x05c5eac345eaf570c9557630919d33253708a04d0a9ab468c37a292f80a4b3a3/debugger?trace=0.1
You will need to set the private key of the executor wallet as an environment variable. You wlll also need to approve the GMX contracts to spend the collateral from your wallet (this will be abstracted away in future).
Assuming you have a trade you want to place, first describe the trade details in the following format:
let test: SimpleOrder = SimpleOrder {
is_long: true,
collateral_token: "ETH".to_string(),
collateral_amount: "1000000000000000000".to_string(),
index_token: "WBTC".to_string(),
leverage_factor: 10.0,
};
This corresponds to the SimpleOrder type. All type conversions and hashing are abstracted away on the backend.
The next step is to convert into an exectutable tx and, which is done by calling
let test_result: OrderObject = get_order_object_from_simple_order(&test).await?;
After which we can execute the tx by calling
let receipt = sol_call(test_result).await?;