Skip to content

Commit 832ebe7

Browse files
committed
Merge branch 'tilen/get_feeds' into 'main'
Updating get feeds functionality See merge request flarenetwork/ftso/fast-updates!33
2 parents 0ca9daa + 0fdd4d6 commit 832ebe7

File tree

111 files changed

+2622
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2622
-218
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ nul
9292
# other files
9393
go-client/sig.out
9494
go-client/keys.out
95+
96+
# contracts
97+
*.bin
98+
*.abi

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
[submodule "flare-smart-contracts-v2"]
2-
path = flare-smart-contracts-v2
3-
url = [email protected]:flare-foundation/flare-smart-contracts-v2.git
4-
branch = main

flare-smart-contracts-v2

Lines changed: 0 additions & 1 deletion
This file was deleted.

go-client/Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FLARE_SMART_CONTRACTS_V2 = ../flare-smart-contracts-v2
2-
GO_CLIENT_RELATIVE = ../go-client
1+
FLARE_SMART_CONTRACTS_V2 = ../../flare-smart-contracts-v2
2+
GO_CLIENT_RELATIVE = ../fast-updates/go-client
33
SOLC_OPTIONS = @openzeppelin/=node_modules/@openzeppelin/ flare-smart-contracts/=node_modules/flare-smart-contracts/ --evm-version london --optimize --optimize-runs 200
44
CONTRACTS_FOLDER = contracts-interface
55

66
compile: compile-solc compile-abigen
77

88
compile-solc: compile-solc-base compile-solc-mock
9-
compile-solc-base: compile-solc-fast_updater-abi compile-solc-fast_updater-bin compile-solc-fast_updates-configuration-abi compile-solc-fast_updates-configuration-bin compile-solc-fast_update-incentive-abi compile-solc-fast_update-incentive-bin compile-solc-submission-abi
9+
compile-solc-base: compile-solc-fast_updater-abi compile-solc-fast_updater-bin compile-solc-fast_updates-configuration-abi compile-solc-fast_updates-configuration-bin compile-solc-fast_update-incentive-abi compile-solc-fast_update-incentive-bin compile-solc-submission-abi compile-solc-fee_calculator-abi compile-solc-fee_calculator-bin
1010
compile-solc-mock: compile-solc-mock-abi compile-solc-mock-bin
1111

1212
compile-solc-fast_updater-abi:
@@ -36,8 +36,13 @@ compile-solc-mock-abi:
3636
compile-solc-mock-bin:
3737
cd $(FLARE_SMART_CONTRACTS_V2); solc $(SOLC_OPTIONS) --bin contracts/fastUpdates/mock/FlareSystemMock.sol -o $(GO_CLIENT_RELATIVE)/$(CONTRACTS_FOLDER) --overwrite
3838

39+
compile-solc-fee_calculator-abi:
40+
cd $(FLARE_SMART_CONTRACTS_V2); solc $(SOLC_OPTIONS) --abi contracts/fastUpdates/implementation/FeeCalculator.sol -o $(GO_CLIENT_RELATIVE)/$(CONTRACTS_FOLDER) --overwrite
3941

40-
compile-abigen: compile-abigen-flare_system_manager compile-abigen-flare_mock compile-abigen-voter_registry compile-abigen-fast_updater compile-abigen-fast_update-configuration compile-abigen-fast_update-incentive compile-abigen-submission
42+
compile-solc-fee_calculator-bin:
43+
cd $(FLARE_SMART_CONTRACTS_V2); solc $(SOLC_OPTIONS) --bin contracts/fastUpdates/implementation/FeeCalculator.sol -o $(GO_CLIENT_RELATIVE)/$(CONTRACTS_FOLDER) --overwrite
44+
45+
compile-abigen: compile-abigen-flare_system_manager compile-abigen-flare_mock compile-abigen-voter_registry compile-abigen-fast_updater compile-abigen-fast_update-configuration compile-abigen-fast_update-incentive compile-abigen-submission compile-abigen-fee_calculator
4146

4247
compile-abigen-flare_system_manager:
4348
cd $(CONTRACTS_FOLDER); abigen --abi=IFlareSystemsManager.abi --pkg=system_manager --out=system_manager/FlareSystemManager.go
@@ -59,3 +64,6 @@ compile-abigen-fast_update-incentive:
5964

6065
compile-abigen-submission:
6166
cd $(CONTRACTS_FOLDER); abigen --abi=Submission.abi --pkg=submission --out=submission/Submission.go
67+
68+
compile-abigen-fee_calculator:
69+
cd $(CONTRACTS_FOLDER); abigen --bin=FeeCalculator.bin --abi=FeeCalculator.abi --pkg=fee_calculator --out=fee_calculator/FeeCalculator.go

go-client/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ flare_system_manager = "0x919b4b4B561C72c990DC868F751328eF127c45F4"
5050
incentive_manager_address = "0x919b4b4B561C72c990DC868F751328eF127c45F4"
5151
# parameter defining when a fast update can be submitted
5252
submission_window = 10
53-
# url of the off-chain data provider
53+
# url of the off-chain data provider
5454
value_provider_url = "http://127.0.0.1:3101/feed-values/0"
55+
# (optional) when (off-chain) fetching feeds values, an address with sufficient
56+
# balance should be provided, even though the transactions never happen;
57+
# the below address is the default one, which on flare chains has enough balance
58+
fetch_current_feeds_address = "0x000000000000000000000000000000000000dEaD"
59+
fetch_current_feeds_value = "1000000000000000000000000"
5560

5661
[transactions]
5762
gas_limit = 8000000
@@ -156,6 +161,7 @@ where the key value needs to be replaced by the generated private key and the ad
156161
to be replaced by the actual _entity_ address.
157162

158163
In case you forgot your public key, but saved the private one, you can run the following for outputting the key:
164+
159165
```bash
160166
go run keygen/keygen.go --key 0x1512de600a10a0aac01580dbfc080965b89ed2329a7b2bf538f4c7e09e34aa1
161167
```
@@ -231,10 +237,8 @@ in the protocol.
231237

232238
The Fast Updates Go client uses an interface to the contracts that was compiled using `solc` compiler and `abigen` tool. In the case
233239
that the contracts are changed, the interface needs to be changed as well. Use the provided
234-
`Makefile` to compile the new interfaces with
240+
`Makefile` to compile the new interfaces. In the makefile set the destination of the `flare-smart-contracts-v2` repo and run
235241

236242
```bash
237243
make compile
238244
```
239-
240-
assuming the submodule repository `flare-smart-contracts-v2` is up to date.

go-client/client/client.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"math/big"
77
"time"
88

9+
"github.com/ethereum/go-ethereum/accounts/abi"
910
"github.com/ethereum/go-ethereum/common"
1011
"github.com/ethereum/go-ethereum/crypto"
1112
"github.com/ethereum/go-ethereum/ethclient"
@@ -23,23 +24,26 @@ import (
2324
)
2425

2526
type FastUpdatesClient struct {
26-
params config.FastUpdateClientConfig
27-
chainClient *ethclient.Client
28-
valuesProvider provider.ValuesProvider
29-
signingAccount *Account
30-
transactionAccounts []*Account
31-
fastUpdater *fast_updater.FastUpdater
32-
fastUpdatesConfig *fast_updates_configuration.FastUpdatesConfiguration
33-
submission *submission.Submission
34-
flareSystemMock *mock.Mock
35-
flareSystemManager *system_manager.SystemManager
36-
IncentiveManager *incentive.Incentive
37-
key *sortition.Key
38-
registeredEpochs map[int64]bool
39-
transactionQueue *TransactionQueue
40-
allFeeds []provider.FeedId
41-
loggingParams config.LoggerConfig
42-
Stats UpdatesStats
27+
params config.FastUpdateClientConfig
28+
chainClient *ethclient.Client
29+
valuesProvider provider.ValuesProvider
30+
signingAccount *Account
31+
transactionAccounts []*Account
32+
fastUpdater *fast_updater.FastUpdater
33+
fastUpdaterABI *abi.ABI
34+
fastUpdatesConfig *fast_updates_configuration.FastUpdatesConfiguration
35+
submission *submission.Submission
36+
flareSystemMock *mock.Mock
37+
flareSystemManager *system_manager.SystemManager
38+
IncentiveManager *incentive.Incentive
39+
key *sortition.Key
40+
registeredEpochs map[int64]bool
41+
transactionQueue *TransactionQueue
42+
allFeeds []provider.FeedId
43+
loggingParams config.LoggerConfig
44+
Stats UpdatesStats
45+
FetchCurrentFeedsValue *big.Int
46+
FetchCurrentFeedsAddress common.Address
4347
}
4448

4549
type Account struct {
@@ -113,6 +117,10 @@ func CreateFastUpdatesClient(cfg *config.Config, valuesProvider provider.ValuesP
113117
return nil, fmt.Errorf("CreateFastUpdatesClient: NewFastUpdater: %w", err)
114118
}
115119
}
120+
fastUpdatesClient.fastUpdaterABI, err = fast_updater.FastUpdaterMetaData.GetAbi()
121+
if err != nil {
122+
return nil, fmt.Errorf("CreateFastUpdatesClient: GetAbi: %w", err)
123+
}
116124

117125
fastUpdatesClient.IncentiveManager, err = incentive.NewIncentive(
118126
common.HexToAddress(cfg.Client.IncentiveManagerAddress), fastUpdatesClient.chainClient,
@@ -177,6 +185,17 @@ func CreateFastUpdatesClient(cfg *config.Config, valuesProvider provider.ValuesP
177185
if fastUpdatesClient.params.MaxWeight == 0 {
178186
fastUpdatesClient.params.MaxWeight = 4096
179187
}
188+
if cfg.Client.FetchCurrentFeedsAddress != "" {
189+
fastUpdatesClient.FetchCurrentFeedsAddress = common.HexToAddress(cfg.Client.FetchCurrentFeedsAddress)
190+
var check bool
191+
fastUpdatesClient.FetchCurrentFeedsValue, check = new(big.Int).SetString(cfg.Client.FetchCurrentFeedsValue, 10)
192+
if !check {
193+
return nil, fmt.Errorf("CreateFastUpdatesClient: failed reading fetch_current_feeds_value: %s", cfg.Client.FetchCurrentFeedsValue)
194+
}
195+
} else {
196+
fastUpdatesClient.FetchCurrentFeedsAddress = common.HexToAddress("0x000000000000000000000000000000000000dEaD")
197+
fastUpdatesClient.FetchCurrentFeedsValue, _ = new(big.Int).SetString("1000000000000000000000000", 10)
198+
}
180199

181200
return &fastUpdatesClient, nil
182201
}

go-client/client/client_requests.go

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"strings"
88
"time"
99

10+
"github.com/ethereum/go-ethereum"
11+
"github.com/ethereum/go-ethereum/accounts/abi"
1012
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1113
"github.com/ethereum/go-ethereum/common"
1214
"github.com/ethereum/go-ethereum/core/types"
@@ -20,6 +22,8 @@ import (
2022
"fast-updates-client/updates"
2123
)
2224

25+
const fetchCurrentFeedsMethod = "fetchCurrentFeeds"
26+
2327
func (client *FastUpdatesClient) CurrentBlockNumber() (uint64, error) {
2428
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Duration(config.CallTimeoutMillisDefault)*time.Millisecond)
2529
currentBlockNum, err := client.chainClient.BlockNumber(ctx)
@@ -97,19 +101,54 @@ func (client *FastUpdatesClient) GetMyWeight() (uint64, error) {
97101
return weight.Uint64(), nil
98102
}
99103

100-
func (client *FastUpdatesClient) GetFeeds(feedIndexes []int) ([]float64, uint64, error) {
101-
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Duration(config.CallTimeoutMillisDefault)*time.Millisecond)
102-
ops := &bind.CallOpts{Context: ctx}
104+
func (client *FastUpdatesClient) callContractFetchCurrentFeeds(ctx context.Context, feedIndexes []*big.Int) (*provider.ValuesDecimals, error) {
105+
fastUpdatesAddress := common.HexToAddress(client.params.FastUpdaterAddress)
106+
107+
input, err := client.fastUpdaterABI.Pack(fetchCurrentFeedsMethod, feedIndexes)
108+
if err != nil {
109+
return nil, err
110+
}
111+
112+
msg := ethereum.CallMsg{
113+
To: &fastUpdatesAddress,
114+
Data: input,
115+
Value: client.FetchCurrentFeedsValue,
116+
From: client.FetchCurrentFeedsAddress,
117+
}
118+
outputBytes, err := client.chainClient.CallContract(ctx, msg, nil)
119+
if err != nil {
120+
return nil, err
121+
}
103122

123+
res, err := client.fastUpdaterABI.Unpack(fetchCurrentFeedsMethod, outputBytes)
124+
if err != nil {
125+
return nil, err
126+
}
127+
if len(res) != 3 {
128+
return nil, fmt.Errorf("ABI unpack error, length of response %d", len(res))
129+
}
130+
131+
return &provider.ValuesDecimals{
132+
Feeds: *abi.ConvertType(res[0], new([]*big.Int)).(*[]*big.Int),
133+
Decimals: *abi.ConvertType(res[1], new([]int8)).(*[]int8),
134+
Timestamp: *abi.ConvertType(res[2], new(uint64)).(*uint64),
135+
}, nil
136+
}
137+
138+
func (client *FastUpdatesClient) GetFeeds(feedIndexes []int) ([]float64, uint64, error) {
104139
feedIndexesBigInt := make([]*big.Int, len(feedIndexes))
105140
for i, index := range feedIndexes {
106141
feedIndexesBigInt[i] = big.NewInt(int64(index))
107142
}
108143

109-
feedValues, err := client.fastUpdater.FetchCurrentFeeds(ops, feedIndexesBigInt)
144+
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Duration(config.CallTimeoutMillisDefault)*time.Millisecond)
145+
feedValues, err := client.callContractFetchCurrentFeeds(ctx, feedIndexesBigInt)
110146
cancelFunc()
147+
if err != nil {
148+
return nil, 0, err
149+
}
111150

112-
floatValues := RawChainValuesToFloats(feedValues)
151+
floatValues := RawChainValuesToFloats(*feedValues)
113152
return floatValues, feedValues.Timestamp, err
114153
}
115154

go-client/client/client_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ func TestClient(t *testing.T) {
5454

5555
// set configuration parameters
5656
cfgClient := config.FastUpdateClientConfig{
57-
SigningPrivateKey: "0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",
58-
SortitionPrivateKey: "0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",
59-
SubmissionWindow: 4,
60-
MaxWeight: 1024,
57+
SigningPrivateKey: "0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",
58+
SortitionPrivateKey: "0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",
59+
SubmissionWindow: 4,
60+
MaxWeight: 1024,
61+
FetchCurrentFeedsAddress: "0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4",
62+
FetchCurrentFeedsValue: "10000",
6163
}
6264
cfgTransactions := config.TransactionsConfig{
6365
Accounts: []string{"0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",

go-client/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type FastUpdateClientConfig struct {
5858
SubmissionWindow int `toml:"submission_window"`
5959
MaxWeight int `toml:"max_weight"`
6060
ValueProviderUrl string `toml:"value_provider_url"`
61+
FetchCurrentFeedsValue string `toml:"fetch_current_feeds_value"`
62+
FetchCurrentFeedsAddress string `toml:"fetch_current_feeds_address"`
6163
}
6264

6365
type TransactionsConfig struct {

go-client/contracts-interface/AddressUpdatable.abi

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)