gmx-io / gmx-contracts Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I'm working on an integration with GMX contracts and I keep getting an error when I try to execute increase position requests.
The transaction either reverts with error PositionRouter: request has expired"
or PositionRouter: min delay not yet passed
The error appears be be coming from this block of code in the Position router contract
function _validateExecution(uint256 _positionBlockNumber, uint256 _positionBlockTime, address _account) internal view returns (bool) {
if (_positionBlockTime.add(maxTimeDelay) <= block.timestamp) {
revert("PositionRouter: request has expired");
}
..........
require(_positionBlockTime.add(minTimeDelayPublic) <= block.timestamp, "PositionRouter: min delay not yet passed");
return true;
}
I inspected the contract and minTimeDelayPublic
is set as 31536000
while maxTimeDelay
is 1800
When I evm_increaseTime
with >=1800
seconds, the tx reverts with the error request has expired
and when I evm_increaseTime
with <1800
secs, the txn fails with the error PositionRouter: min delay not yet passed
Is there something wrong with the logic here?
i tried to use python web3 to open long position on gmx, but keep getting errors about format:
the gmx.usdc etc are the usdc address on arbitrum and i downloaded the ABIs.
gmx_position_router_contract.functions.createIncreasePosition(
_path = [gmx.usdc, gmx.weth],
_indexToken = gmx.weth,
_amountIn = 910**6,
_minOut = 0,
_sizeDelta = 181030,
_isLong = True,
_acceptablePrice = 1670*1030,
_executionFee = 1*10**14,
_referralCode = bytes(0),
_callbackTarget = '0x0').buildTransaction(....)
web3.exceptions.ValidationError:
Could not identify the intended function with name createIncreasePosition
, positional argument(s) of type ()
and keyword argument(s) of type {'_path': <class 'list'>, '_indexToken': <class 'str'>, '_amountIn': <class 'int'>, '_minOut': <class 'int'>, '_sizeDelta': <class 'int'>, '_isLong': <class 'bool'>, '_acceptablePrice': <class 'int'>, '_executionFee': <class 'int'>, '_referralCode': <class 'bytes'>, '_callbackTarget': <class 'str'>}
.
Found 1 function(s) with the name createIncreasePosition
: ['createIncreasePosition(address[],address,uint256,uint256,uint256,bool,uint256,uint256,bytes32,address)']
Function invocation failed due to no matching argument types.
is there any python example to do this:
https://gmxio.gitbook.io/gmx/contracts#opening-increasing-a-position
C:\01_web3\gmx-io\gmx-contracts>npx hardhat compile
An unexpected error occurred:
Error: Cannot find module './env.json'
Require stack:
I saw lots of deploy scripts, lost track of all.
Which should I run when trying to deploy?
gm,
The fee calc when selling GLP (the vault.sellUSDG()
function) may have a bug.
When selling GLP, the fee for the token to sell into is calculated here:
https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/Vault.sol#L508
This underlying fee calc depends on vault.usdgAmounts(usg)
for the initialAmount:
https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/VaultUtils.sol#L146
However this usdgAmount
has already been updated (decreased) prior to this being called
https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/Vault.sol#L497
So it looks like the initialAmount
var isn't the initial amount, it's already had the usdgDelta applied to it.
Also as far as I can tell, the UI quote is inconsistent with this contract calc - since the usdgAmount being used is the amount prior to the transaction.
https://github.com/gmx-io/gmx-interface/blob/master/src/Helpers.js#L655
Apart from potentially taking more fees than necessary, I guess if the UI quote is different from the actual calc, it may have slippage issues for users.
Dear GMX team, I have a design questions. When trading, I noticed that to increase or decrease positions, two transactions are executed: a request and an execution transactions. Why it was done in this way ? other perpetuals platforms have only one transaction to do it. Also, in Avalanche, after requesting my inc/dec, the one that executes the second transaction is the https://snowtrace.io/address/0x864db9152169d68299b599331c6bfc77e3f91070 wallet. Does it mean that you have an operator listening the requests and execute for them ? If yes, may I question how this affects the decentralization level ?
thanks in advance,
hh
https://arbiscan.io/tx/0xe3106ea8b12903d535e105839c51b9b85f8e74fe994a3bedf633b2d70929fdee#eventlog
in arb,the marginFeeBasisPoints is 500,but in CollectMarginFees log, feeUsd is 147801980198019801978142963902,
my deltaSize is 147801980198019801978142963901550,the fee need to be
147801980198019801978142963901550 * 5%=7390099009900990098907148195078L,
but anctual the fee is
147801980198019801978142963901550 * 0.1% = 147801980198019801978142963902,
why??
function getPositionFee(uint256 _sizeDelta) public view returns (uint256) {
if (_sizeDelta == 0) { return 0; }
uint256 afterFeeUsd = _sizeDelta.mul(BASIS_POINTS_DIVISOR.sub(marginFeeBasisPoints)).div(BASIS_POINTS_DIVISOR);
return _sizeDelta.sub(afterFeeUsd);
}
According to the minimum price change documentation, the 1.5% price difference requirement over the first 12 hours after opening/updating a position is to deter bots from exploiting potential Chainlink price feed delays. This makes sense and I don't disagree of the current implementation in order to protect GLP holders.
What I think should be considered is if the position is in profit at all at the time of closing/decreasing a position within the 12 hour limit and if the mark price is within the 1.5% difference of the opening price, what profit exists should be able to be used to pay for any incurred fees from closing/decreasing the position instead of forfeiting all profit and still needing to pay all fees.
Examples:
Current State
Desired State
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.