1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| package gmxv2
import ( "context" "fmt" "math/big" "reflect" "strings"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" )
var ( ReaderAddr = common.HexToAddress("0xf60becbba223EEA9495Da3f606753867eC10d139") DataStoreAddr = common.HexToAddress("0xFD70de6b91282D8017aA4E741e9Ae325CAb992d8") EventEmitter = common.HexToAddress("0xC8ee91A54287DB53897056e12D9819156D3822Fb") )
const readerABI = `[ { "name": "getMarket", "type": "function", "stateMutability": "view", "inputs": [ {"name": "dataStore", "type": "address"}, {"name": "key", "type": "address"} ], "outputs": [ { "name": "", "type": "tuple", "components": [ {"name": "marketToken", "type": "address"}, {"name": "indexToken", "type": "address"}, {"name": "longToken", "type": "address"}, {"name": "shortToken", "type": "address"} ] } ] }, { // NOTE: 简化版 ABI, 实际 GMX v2 Reader.getPosition 返回嵌套结构: // Position.Addresses (account, market, collateralToken) // Position.Numbers (sizeInUsd, sizeInTokens, collateralAmount, ...) // Position.Flags (isLong) // 如需 abigen 或 reflect 解码, 请使用完整嵌套 ABI "name": "getPosition", "type": "function", "stateMutability": "view", "inputs": [ {"name": "dataStore", "type": "address"}, {"name": "key", "type": "bytes32"} ], "outputs": [ { "name": "", "type": "tuple", "components": [ {"name": "sizeInUsd", "type": "uint256"}, {"name": "sizeInTokens", "type": "uint256"}, {"name": "collateralAmount", "type": "uint256"}, {"name": "borrowingFactor", "type": "uint256"}, {"name": "fundingFeeAmountPerSize", "type": "uint256"}, {"name": "longTokenClaimableFundingAmountPerSize", "type": "uint256"}, {"name": "shortTokenClaimableFundingAmountPerSize", "type": "uint256"}, {"name": "increasedAtBlock", "type": "uint256"}, {"name": "decreasedAtBlock", "type": "uint256"}, {"name": "isLong", "type": "bool"} ] } ] }, { "name": "getOpenInterestWithPnl", "type": "function", "stateMutability": "view", "inputs": [ {"name": "dataStore", "type": "address"}, {"name": "market", "type": "tuple", "components": [ {"name": "marketToken", "type": "address"}, {"name": "indexToken", "type": "address"}, {"name": "longToken", "type": "address"}, {"name": "shortToken", "type": "address"} ]}, {"name": "indexTokenPrice", "type": "tuple", "components": [ {"name": "min", "type": "uint256"}, {"name": "max", "type": "uint256"} ]}, {"name": "isLong", "type": "bool"}, {"name": "maximize", "type": "bool"} ], "outputs": [ {"name": "", "type": "int256"} ] } ]`
|