forked from watsonwanda/oracle-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abi.go
85 lines (70 loc) · 3.39 KB
/
abi.go
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
package origin
import (
"github.com/defiweb/go-eth/abi"
"github.com/defiweb/go-eth/types"
)
// [Balancer V2]
var getLatest = abi.MustParseMethod("getLatest(uint8)(uint256)")
var getPriceRateCache = abi.MustParseMethod("getPriceRateCache(address)(uint256,uint256,uint256)")
var getPoolID = abi.MustParseMethod("getPoolId()(bytes32)")
var getVault = abi.MustParseMethod("getVault()(address)")
var getPoolTokens = abi.MustParseMethod("getPoolTokens(bytes32)(address[] memory tokens,uint256[] memory balances,uint256 lastChangeBlock)")
var getSwapFeePercentage = abi.MustParseMethod("getSwapFeePercentage()(uint256)")
var getScalingFactors = abi.MustParseMethod("getScalingFactors()(uint256[] memory)")
var getNormalizedWeights = abi.MustParseMethod("getNormalizedWeights()(uint256[] memory)")
var getBptIndex = abi.MustParseMethod("getBptIndex()(uint256)")
// [Balancer V2 - ComposableStablePool]
var getAmplificationParameter = abi.MustParseMethod("getAmplificationParameter()(uint256 value,bool isUpdating,uint256 precision)")
var getTotalSupply = abi.MustParseMethod("totalSupply()(uint256)")
// [Curve]
// Since curve has `stableswap` pool and `cryptoswap` pool, and their smart contracts have pretty similar interface
// `stableswap` pool is using `int128` in `get_dy`, `get_dx` ...,
// while `cryptoswap` pool is using `uint256` in `get_dy`, `get_dx`, ...
var getDy1 = abi.MustParseMethod("get_dy(int128,int128,uint256)(uint256)")
var getDy2 = abi.MustParseMethod("get_dy(uint256,uint256,uint256)(uint256)")
var coins = abi.MustParseMethod("coins(uint256)(address)")
// [dsr]
var dsr = abi.MustParseMethod("dsr()(uint256)")
// [Lido-Liquid Staking Token]
var tokenRebased = abi.MustParseEvent("TokenRebased(uint256 indexed reportTimestamp," +
"uint256 timeElapsed," +
"uint256 preTotalShares," +
"uint256 preTotalEther," +
"uint256 postTotalShares," +
"uint256 postTotalEther," +
"uint256 sharesMintedAsFees)")
// [RocketPool]
var getExchangeRate = abi.MustParseMethod("getExchangeRate()(uint256)")
// [sDAI]
var previewRedeem = abi.MustParseMethod("previewRedeem(uint256)(uint256)")
// [Sushiswap]
var getReserves = abi.MustParseMethod("getReserves()(uint112 _reserve0,uint112 _reserve1,uint32 _blockTimestampLast)")
var token0Abi = abi.MustParseMethod("token0()(address)")
var token1Abi = abi.MustParseMethod("token1()(address)")
// [Uniswap v3]
var slot0 = abi.MustParseMethod("slot0()(uint160,int24,uint16,uint16,uint16,uint8,bool)")
// var token0Abi = abi.MustParseMethod("token0()(address)")
// var token1Abi = abi.MustParseMethod("token1()(address)")
// [Uniswap v2]
// var getReserves =
// abi.MustParseMethod("getReserves()(uint112 _reserve0,uint112 _reserve1,uint32 _blockTimestampLast)")
// var token0Abi = abi.MustParseMethod("token0()(address)")
// var token1Abi = abi.MustParseMethod("token1()(address)")
// [wstETH]
var stEthPerToken = abi.MustParseMethod("stEthPerToken()(uint256)")
type requestFunc[T any] func(fromBlock, toBlock *types.BlockNumber) ([]T, error)
func requestWithBlockStep[T any](fromBlock, toBlock, step uint64, callback requestFunc[T]) ([]T, error) {
var result []T
for ; fromBlock <= toBlock; fromBlock = toBlock + 1 {
to := fromBlock + step
if to > toBlock {
to = toBlock
}
nextResult, err := callback(types.BlockNumberFromUint64Ptr(fromBlock), types.BlockNumberFromUint64Ptr(to))
if err != nil {
return nil, err
}
result = append(result, nextResult...)
}
return result, nil
}