Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating new contracts #389

Merged
merged 12 commits into from
Dec 19, 2024
2 changes: 1 addition & 1 deletion cmd/bridge/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ProposeStatusBase = 10000000
ProposeStatusForEach = 7000000
PerformActionBase = 40000000
PerformActionForEach = 5500000
PerformActionForEach = 7000000
ScCallPerByte = 100000 # 1500 tx data field + the rest for the actual storage in the contract
ScCallPerformForEach = 10000000

Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
chain-simulator:
image: multiversx/chainsimulator:v1.7.13-patch2
image: multiversx/chainsimulator:v1.7.13-patch2-fix1
ports:
- 8085:8085
volumes:
Expand Down
5 changes: 4 additions & 1 deletion integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,5 +797,8 @@ func createScCallData(function string, gasLimit uint64, args ...string) []byte {
Arguments: args,
}

return codec.EncodeCallDataStrict(callData)
buff := codec.EncodeCallDataStrict(callData)
log.Info("working with SC call data", "buff", buff)

return buff
}
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,12 @@ func processCalledDataParams(buff []byte) (uint64, string) {
valBuff := buff[:8]
value := binary.BigEndian.Uint64(valBuff)

buff = buff[8+32+4:] // trim the nonce, address and length of the token
token := string(buff)
buff = buff[8+32:] // trim the nonce and the address
tokenLenBuff := buff[:4]
tokenLen := binary.BigEndian.Uint32(tokenLenBuff)
buff = buff[4:] // trim the length of the token string

token := string(buff[:tokenLen])

return value, token
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewBridgeComponents(
ProposeStatusBase: 10000000,
ProposeStatusForEach: 7000000,
PerformActionBase: 40000000,
PerformActionForEach: 5500000,
PerformActionForEach: 7000000,
ScCallPerByte: 100000,
ScCallPerformForEach: 10000000,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
generateBlocksUntilTxProcessedEndpoint = "simulator/generate-blocks-until-transaction-processed/%s"
numProbeRetries = 10
networkConfigEndpointTemplate = "network/status/%d"
codeMetadata = "0502"
esdtSupplyEndpointTemplate = "network/esdt/supply/%s"
)

Expand Down Expand Up @@ -130,7 +131,7 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat
require.Nil(instance.TB, err)

scCode := wasm.GetSCCode(wasmFilePath)
params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex}
params := []string{scCode, wasm.VMTypeHex, codeMetadata}
params = append(params, parameters...)
txData := strings.Join(params, "@")

Expand Down
192 changes: 53 additions & 139 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ const (
bridgeProxyContractPath = "testdata/contracts/mvx/bridge-proxy.wasm"
testCallerContractPath = "testdata/contracts/mvx/test-caller.wasm"

setBridgeProxyContractAddressFunction = "setBridgeProxyContractAddress"
setWrappingContractAddressFunction = "setWrappingContractAddress"
changeOwnerAddressFunction = "ChangeOwnerAddress"
setEsdtSafeOnMultiTransferFunction = "setEsdtSafeOnMultiTransfer"
setEsdtSafeAddressFunction = "setEsdtSafeAddress"
moveRefundBatchToSafeFromChildContractFunction = "moveRefundBatchToSafeFromChildContract"
getCurrentRefundBatchFunction = "getCurrentRefundBatch"
stakeFunction = "stake"
Expand All @@ -71,8 +67,6 @@ const (
submitBatchFunction = "submitBatch"
unwrapTokenCreateTransactionFunction = "unwrapTokenCreateTransaction"
createTransactionFunction = "createTransaction"
setBridgedTokensWrapperAddressFunction = "setBridgedTokensWrapperAddress"
setMultiTransferAddressFunction = "setMultiTransferAddress"
withdrawRefundFeesForEthereumFunction = "withdrawRefundFeesForEthereum"
getRefundFeesForEthereumFunction = "getRefundFeesForEthereum"
withdrawTransactionFeesFunction = "withdrawTransactionFees"
Expand All @@ -83,6 +77,8 @@ const (
getBurnBalancesFunction = "getBurnBalances"
getTotalBalancesFunction = "getTotalBalances"
getTokenLiquidityFunction = "getTokenLiquidity"
getRefundTransactions = "getRefundTransactions"
executeRefundTransaction = "executeRefundTransaction"
)

var (
Expand Down Expand Up @@ -138,10 +134,6 @@ func NewMultiversxHandler(
func (handler *MultiversxHandler) DeployAndSetContracts(ctx context.Context) {
handler.deployContracts(ctx)

handler.wireMultiTransfer(ctx)
handler.wireSCProxy(ctx)
handler.wireSafe(ctx)

handler.changeOwners(ctx)
handler.finishSettings(ctx)
}
Expand Down Expand Up @@ -201,8 +193,6 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
handler.OwnerKeys.MvxSk,
deployGasLimit,
[]string{
handler.AggregatorAddress.Hex(),
handler.MultiTransferAddress.Hex(),
"01",
},
)
Expand All @@ -215,9 +205,7 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
bridgeProxyContractPath,
handler.OwnerKeys.MvxSk,
deployGasLimit,
[]string{
handler.MultiTransferAddress.Hex(),
},
make([]string, 0),
)
require.NotEqual(handler, emptyAddress, handler.ScProxyAddress)
log.Info("Deploy: SC proxy contract", "address", handler.ScProxyAddress, "transaction hash", hash)
Expand All @@ -229,6 +217,8 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
handler.SafeAddress.Hex(),
handler.MultiTransferAddress.Hex(),
handler.ScProxyAddress.Hex(),
handler.WrapperAddress.Hex(),
handler.AggregatorAddress.Hex(),
minRelayerStakeHex,
slashAmount,
handler.Quorum}
Expand Down Expand Up @@ -257,117 +247,6 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) {
log.Info("Deploy: test-caller contract", "address", handler.CalleeScAddress, "transaction hash", hash)
}

func (handler *MultiversxHandler) wireMultiTransfer(ctx context.Context) {
// setBridgeProxyContractAddress
params := []string{
handler.ScProxyAddress.Hex(),
}
hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.MultiTransferAddress,
zeroStringValue,
setCallsGasLimit,
setBridgeProxyContractAddressFunction,
params)

log.Info("Set in multi-transfer contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status)

// setWrappingContractAddress
params = []string{
handler.WrapperAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.MultiTransferAddress,
zeroStringValue,
setCallsGasLimit,
setWrappingContractAddressFunction,
params)

log.Info("Set in multi-transfer contract the wrapper contract", "transaction hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) wireSCProxy(ctx context.Context) {
// setBridgedTokensWrapper in SC bridge proxy
params := []string{
handler.WrapperAddress.Hex(),
}
hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ScProxyAddress,
zeroStringValue,
setCallsGasLimit,
setBridgedTokensWrapperAddressFunction,
params)

log.Info("Set in SC proxy contract the wrapper contract", "transaction hash", hash, "status", txResult.Status)

// setMultiTransferAddress in SC bridge proxy
params = []string{
handler.MultiTransferAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ScProxyAddress,
zeroStringValue,
setCallsGasLimit,
setMultiTransferAddressFunction,
params)

log.Info("Set in SC proxy contract the multi-transfer contract", "transaction hash", hash, "status", txResult.Status)

// setEsdtSafeAddress on bridge proxy
params = []string{
handler.SafeAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.ScProxyAddress,
zeroStringValue,
setCallsGasLimit,
setEsdtSafeAddressFunction,
params)

log.Info("Set in SC proxy contract the safe contract", "transaction hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) wireSafe(ctx context.Context) {
// setBridgedTokensWrapperAddress
params := []string{
handler.WrapperAddress.Hex(),
}
hash, txResult := handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.SafeAddress,
zeroStringValue,
setCallsGasLimit,
setBridgedTokensWrapperAddressFunction,
params)

log.Info("Set in safe contract the wrapper contract", "transaction hash", hash, "status", txResult.Status)

//setBridgeProxyContractAddress
params = []string{
handler.ScProxyAddress.Hex(),
}
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.SafeAddress,
zeroStringValue,
setCallsGasLimit,
setBridgeProxyContractAddressFunction,
params)

log.Info("Set in safe contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status)
}

func (handler *MultiversxHandler) changeOwners(ctx context.Context) {
// ChangeOwnerAddress for safe
params := []string{
Expand Down Expand Up @@ -420,18 +299,6 @@ func (handler *MultiversxHandler) finishSettings(ctx context.Context) {
hash, txResult := handler.callContractNoParams(ctx, handler.MultisigAddress, unpauseProxyFunction)
log.Info("Un-paused SC proxy contract", "transaction hash", hash, "status", txResult.Status)

// setEsdtSafeOnMultiTransfer
hash, txResult = handler.scCallAndCheckTx(
ctx,
handler.OwnerKeys,
handler.MultisigAddress,
zeroStringValue,
setCallsGasLimit,
setEsdtSafeOnMultiTransferFunction,
[]string{})

log.Info("Set in multisig contract the safe contract (automatically)", "transaction hash", hash, "status", txResult.Status)

// stake relayers on multisig
handler.stakeAddressesOnContract(ctx, handler.MultisigAddress, handler.RelayersKeys)

Expand Down Expand Up @@ -566,9 +433,9 @@ func (handler *MultiversxHandler) issueAndWhitelistTokensWithChainSpecific(ctx c
return
}
handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params)
handler.transferChainSpecificTokenToSCs(ctx, params)
handler.addUniversalTokenToWrapper(ctx, params)
handler.whitelistTokenOnWrapper(ctx, params)
handler.transferChainSpecificTokenToSCs(ctx, params)
handler.setRolesForSpecificTokenOnSafe(ctx, params)
handler.addMappingInMultisig(ctx, params)
handler.whitelistTokenOnMultisig(ctx, params)
Expand Down Expand Up @@ -1251,6 +1118,53 @@ func (handler *MultiversxHandler) scCallAndCheckTx(
return hash, txResult
}

// RefundAllFromScBridgeProxy will refund transactions from the bridge proxy, if existing
func (handler *MultiversxHandler) RefundAllFromScBridgeProxy(ctx context.Context) {
refundIDs := handler.getAllRefundIDsFromScBridgeProxy(ctx)
if len(refundIDs) == 0 {
return
}

for _, refundID := range refundIDs {
handler.refundTransactionInScBridgeProxy(ctx, refundID)
}
}

func (handler *MultiversxHandler) getAllRefundIDsFromScBridgeProxy(ctx context.Context) []uint64 {
responseBytes := handler.ChainSimulator.ExecuteVMQuery(
ctx,
handler.ScProxyAddress,
getRefundTransactions,
make([]string, 0),
)

numResponseLines := len(responseBytes)
require.Equal(handler, 0, numResponseLines%2, "expected an even number on response")

refundIDs := make([]uint64, 0, numResponseLines/2)
for i := 0; i < numResponseLines; i += 2 {
refundID := big.NewInt(0).SetBytes(responseBytes[i])
refundIDs = append(refundIDs, refundID.Uint64())
}

return refundIDs
}

func (handler *MultiversxHandler) refundTransactionInScBridgeProxy(ctx context.Context, refundID uint64) {
log.Info("sending refund transaction in SC bridge proxy", "refund ID", refundID)
handler.scCallAndCheckTx(
ctx,
handler.SCExecutorKeys, // anyone can call this, for example, the sc executor
handler.ScProxyAddress,
"0",
generalSCCallGasLimit,
executeRefundTransaction,
[]string{
hex.EncodeToString(big.NewInt(0).SetUint64(refundID).Bytes()),
},
)
}

func getHexBool(input bool) string {
if input {
return hexTrue
Expand Down
Loading
Loading