Skip to content

Commit

Permalink
Merge pull request #347 from multiversx/integrated-released-price-agg…
Browse files Browse the repository at this point in the history
…regator-contract

Integrated the released version of the price aggregator contract
  • Loading branch information
iulianpascalau authored Oct 2, 2024
2 parents 63f6ca4 + 7e48630 commit 680d586
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 9 deletions.
23 changes: 23 additions & 0 deletions integrationTests/relayers/slowTests/framework/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package framework
import (
"bytes"
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
"encoding/pem"
"fmt"
Expand Down Expand Up @@ -33,6 +34,7 @@ type KeysHolder struct {
type KeysStore struct {
testing.TB
RelayersKeys []KeysHolder
OraclesKeys []KeysHolder
SCExecutorKeys KeysHolder
OwnerKeys KeysHolder
DepositorKeys KeysHolder
Expand All @@ -51,6 +53,7 @@ func NewKeysStore(
tb testing.TB,
workingDir string,
numRelayers int,
numOracles int,
) *KeysStore {
keysStore := &KeysStore{
TB: tb,
Expand All @@ -60,6 +63,7 @@ func NewKeysStore(
}

keysStore.generateRelayersKeys(numRelayers)
keysStore.OraclesKeys = keysStore.generateKeys(numOracles, "generated oracle")
keysStore.SCExecutorKeys = keysStore.generateKey("")
keysStore.OwnerKeys = keysStore.generateKey(ethOwnerSK)
log.Info("generated owner",
Expand Down Expand Up @@ -92,6 +96,24 @@ func (keyStore *KeysStore) generateRelayersKeys(numKeys int) {
}
}

func (keyStore *KeysStore) generateKeys(numKeys int, message string) []KeysHolder {
keys := make([]KeysHolder, 0, numKeys)

for i := 0; i < numKeys; i++ {
ethPrivateKeyBytes := make([]byte, 32)
_, _ = rand.Read(ethPrivateKeyBytes)

key := keyStore.generateKey(hex.EncodeToString(ethPrivateKeyBytes))
log.Info(message, "index", i,
"MvX address", key.MvxAddress.Bech32(),
"Eth address", key.EthAddress.String())

keys = append(keys, key)
}

return keys
}

func (keyStore *KeysStore) generateKey(ethSkHex string) KeysHolder {
var err error

Expand All @@ -112,6 +134,7 @@ func (keyStore *KeysStore) generateKey(ethSkHex string) KeysHolder {
func (keyStore *KeysStore) getAllKeys() []KeysHolder {
allKeys := make([]KeysHolder, 0, len(keyStore.RelayersKeys)+10)
allKeys = append(allKeys, keyStore.RelayersKeys...)
allKeys = append(allKeys, keyStore.OraclesKeys...)
allKeys = append(allKeys, keyStore.SCExecutorKeys, keyStore.OwnerKeys, keyStore.DepositorKeys, keyStore.TestKeys)

return allKeys
Expand Down
26 changes: 18 additions & 8 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
createDepositGasLimit = 20000000 // 20 million
gasLimitPerDataByte = 1500

aggregatorContractPath = "testdata/contracts/mvx/aggregator.wasm"
aggregatorContractPath = "testdata/contracts/mvx/multiversx-price-aggregator-sc.wasm"
wrapperContractPath = "testdata/contracts/mvx/bridged-tokens-wrapper.wasm"
multiTransferContractPath = "testdata/contracts/mvx/multi-transfer-esdt.wasm"
safeContractPath = "testdata/contracts/mvx/esdt-safe.wasm"
Expand Down Expand Up @@ -139,9 +139,12 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
hex.EncodeToString([]byte("EGLD")),
hex.EncodeToString(stakeValue.Bytes()),
"01",
"01",
"01",
handler.OwnerKeys.MvxAddress.Hex(),
"03",
"03",
}

for _, oracleKey := range handler.OraclesKeys {
aggregatorDeployParams = append(aggregatorDeployParams, oracleKey.MvxAddress.Hex())
}

hash := ""
Expand All @@ -153,7 +156,7 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
aggregatorDeployParams,
)
require.NotEqual(handler, emptyAddress, handler.AggregatorAddress)
log.Info("Deploy: aggregator contract", "address", handler.AggregatorAddress, "transaction hash", hash)
log.Info("Deploy: aggregator contract", "address", handler.AggregatorAddress, "transaction hash", hash, "num oracles", len(handler.OraclesKeys))

// deploy wrapper
handler.WrapperAddress, hash, _ = handler.ChainSimulator.DeploySC(
Expand Down Expand Up @@ -425,7 +428,7 @@ func (handler *MultiversxHandler) finishSettings(ctx context.Context) {
handler.stakeAddressesOnContract(ctx, handler.MultisigAddress, handler.RelayersKeys)

// stake relayers on price aggregator
handler.stakeAddressesOnContract(ctx, handler.AggregatorAddress, []KeysHolder{handler.OwnerKeys})
handler.stakeAddressesOnContract(ctx, handler.AggregatorAddress, handler.OraclesKeys)

// unpause multisig
hash, txResult = handler.callContractNoParams(ctx, handler.MultisigAddress, unpauseFunction)
Expand Down Expand Up @@ -807,14 +810,20 @@ func (handler *MultiversxHandler) getTokenNameFromResult(txResult data.Transacti

// SubmitAggregatorBatch will submit the aggregator batch
func (handler *MultiversxHandler) SubmitAggregatorBatch(ctx context.Context, params IssueTokenParams) {
for _, key := range handler.OraclesKeys {
handler.submitAggregatorBatchForKey(ctx, key, params)
}
}

func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Context, key KeysHolder, params IssueTokenParams) {
timestamp := handler.ChainSimulator.GetBlockchainTimeStamp(ctx)
require.Greater(handler, timestamp, uint64(0), "something went wrong and the chain simulator returned 0 for the current timestamp")

timestampAsBigInt := big.NewInt(0).SetUint64(timestamp)

hash, txResult := handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.MvxSk,
key.MvxSk,
handler.AggregatorAddress,
zeroStringValue,
setCallsGasLimit,
Expand All @@ -825,7 +834,8 @@ func (handler *MultiversxHandler) SubmitAggregatorBatch(ctx context.Context, par
hex.EncodeToString(timestampAsBigInt.Bytes()),
hex.EncodeToString(feeInt.Bytes()),
fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific)})
log.Info("submit aggregator batch tx executed", "hash", hash, "submitter", handler.OwnerKeys.MvxAddress, "status", txResult.Status)

log.Info("submit aggregator batch tx executed", "transaction hash", hash, "submitter", key.MvxAddress.Bech32(), "status", txResult.Status)
}

// CreateDepositsOnMultiversxForToken will send the deposit transactions on MultiversX returning how many tokens should be minted on Ethereum
Expand Down
3 changes: 2 additions & 1 deletion integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
proxyCacherExpirationSeconds = 600
proxyMaxNoncesDelta = 7
NumRelayers = 3
NumOracles = 4
quorum = "03"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func NewTestSetup(tb testing.TB) *TestSetup {
esdtBalanceForSafe: make(map[string]*big.Int),
ethBalanceTestAddress: make(map[string]*big.Int),
}
setup.KeysStore = NewKeysStore(tb, setup.WorkingDir, NumRelayers)
setup.KeysStore = NewKeysStore(tb, setup.WorkingDir, NumRelayers, NumOracles)

// create a test context
setup.Ctx, setup.ctxCancel = context.WithCancel(context.Background())
Expand Down
Binary file not shown.
Loading

0 comments on commit 680d586

Please sign in to comment.