diff --git a/coins/common.go b/coins/common.go index 0df2234c..10aec4c2 100644 --- a/coins/common.go +++ b/coins/common.go @@ -22,10 +22,10 @@ const ( MaxCoinPrecision = 100 ) -// RelayerFeeWei and RelayerFeeETH are the fixed 0.009 ETH fee for using a swap +// RelayerFeeWei and RelayerFeeETH are the fixed 0.01 ETH fee for using a swap // relayer to claim. var ( - RelayerFeeWei = big.NewInt(9e15) + RelayerFeeWei = big.NewInt(1e16) RelayerFeeETH = NewWeiAmount(RelayerFeeWei).AsEther() ) diff --git a/common/types/offer_test.go b/common/types/offer_test.go index d5834584..16fe1046 100644 --- a/common/types/offer_test.go +++ b/common/types/offer_test.go @@ -176,9 +176,9 @@ func TestOffer_UnmarshalJSON_BadAmountsOrRate(t *testing.T) { errContains: `"minAmount" cannot be negative`, }, { - // 0.009 relayer fee is 0.09 XMR with exchange rate of 0.1 - jsonData: fmt.Sprintf(offerJSON, `"0.09"`, `"10"`, `"0.1"`), - errContains: `min amount must be greater than 0.009 ETH when converted (0.09 XMR)`, + // 0.01 relayer fee is 0.1 XMR with exchange rate of 0.1 + jsonData: fmt.Sprintf(offerJSON, `"0.01"`, `"10"`, `"0.1"`), + errContains: `min amount must be greater than 0.01 ETH when converted (0.1 XMR)`, }, // Max Amount checks { diff --git a/docs/mainnet.md b/docs/mainnet.md index 378ea3c9..074428a2 100644 --- a/docs/mainnet.md +++ b/docs/mainnet.md @@ -80,7 +80,7 @@ To run a node as a relayer, pass the `--relayer` flag to `swapd`: ./bin/swapd --env stagenet --eth-endpoint MAINNET_ENDPOINT --relayer ``` -**Note:** the current fee sent to relayers is 0.009 ETH per swap. Subtract the gas cost from this to determine how much profit will be made. The gas required to do a relayer-claim transaction is `102048` gas. Multiply this by the transaction gas price for the gas cost. The gas price is set via oracle unless you manually set it with the `personal_setGasPrice` RPC call. +**Note:** the current fee sent to relayers is 0.01 ETH per swap. Subtract the gas cost from this to determine how much profit will be made. The gas required to do a relayer-claim transaction is `85040` gas. Multiply this by the transaction gas price for the gas cost. The gas price is set via oracle unless you manually set it with the `personal_setGasPrice` RPC call. ## swapcli commands diff --git a/docs/rpc.md b/docs/rpc.md index 97959295..cd67e5db 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -183,7 +183,7 @@ Parameters: - `relayerEndpoint`: (optional) RPC endpoint of the relayer to use for submitting claim transactions. - `relayerFee`: (optional) Fee in ETH that the relayer receives for - submitting the claim transaction. If `relayerEndpoint` is set and this is not set, it defaults to 0.009 ETH. + submitting the claim transaction. If `relayerEndpoint` is set and this is not set, it defaults to 0.01 ETH. Returns: - `offerID`: ID of the swap offer. diff --git a/relayer/submit_transaction_test.go b/relayer/submit_transaction_test.go index 8261122c..e0479ec4 100644 --- a/relayer/submit_transaction_test.go +++ b/relayer/submit_transaction_test.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" + "github.com/athanorlabs/atomic-swap/coins" "github.com/athanorlabs/atomic-swap/common/types" "github.com/athanorlabs/atomic-swap/dleq" contracts "github.com/athanorlabs/atomic-swap/ethereum" @@ -118,7 +119,7 @@ func Test_ValidateAndSendTransaction(t *testing.T) { Swap: swap, SwapCreator: swapCreatorAddr, RelayerHash: relayerHash, - Fee: big.NewInt(1), + Fee: coins.RelayerFeeWei, } req, err := CreateRelayClaimRequest(claimerSk, relaySwap, secret) diff --git a/relayer/validate.go b/relayer/validate.go index cd6ee620..b01aa3cd 100644 --- a/relayer/validate.go +++ b/relayer/validate.go @@ -38,6 +38,7 @@ func validateClaimRequest( // 2. the swap is for ETH and not an ERC20 token // 3. the swap value is strictly greater than the relayer fee // 4. the claim request's relayer hash matches keccak256(ourAddress || salt) +// 5. the relayer fee is greater than or equal the expected relayer fee func validateClaimValues( ctx context.Context, request *message.RelayClaimRequest, @@ -80,6 +81,14 @@ func validateClaimValues( ) } + // the relayer fee must be greater than or equal the expected relayer fee + if coins.RelayerFeeWei.Cmp(request.RelaySwap.Fee) > 0 { + return fmt.Errorf("relayer fee of %s ETH is less than expected %s ETH", + coins.FmtWeiAsETH(request.RelaySwap.Fee), + coins.RelayerFeeETH.Text('f'), + ) + } + return nil } diff --git a/relayer/validate_test.go b/relayer/validate_test.go index 12550d98..b368bbf1 100644 --- a/relayer/validate_test.go +++ b/relayer/validate_test.go @@ -41,12 +41,12 @@ func TestValidateRelayerFee(t *testing.T) { { description: "swap value equal to relayer fee", value: coins.RelayerFeeWei, - expectErr: "swap value of 0.009 ETH is too low to support 0.009 ETH relayer fee", + expectErr: "swap value of 0.01 ETH is too low to support 0.01 ETH relayer fee", }, { description: "swap value less than relayer fee", value: new(big.Int).Sub(coins.RelayerFeeWei, big.NewInt(1e15)), - expectErr: "swap value of 0.008 ETH is too low to support 0.009 ETH relayer fee", + expectErr: "swap value of 0.009 ETH is too low to support 0.01 ETH relayer fee", }, { description: "swap value larger than min fee", @@ -70,7 +70,7 @@ func TestValidateRelayerFee(t *testing.T) { request := &message.RelayClaimRequest{ RelaySwap: &contracts.SwapCreatorRelaySwap{ Swap: swap, - Fee: big.NewInt(1), + Fee: coins.RelayerFeeWei, SwapCreator: swapCreatorAddr, RelayerHash: relayerHash, }, @@ -172,7 +172,7 @@ func Test_validateClaimRequest(t *testing.T) { SwapCreator: swapCreatorAddr, Swap: *swap, RelayerHash: relayerHash, - Fee: big.NewInt(1), + Fee: coins.RelayerFeeWei, } req, err := CreateRelayClaimRequest(ethKey, relaySwap, secret) diff --git a/tests/integration_test.go b/tests/integration_test.go index a6fc6301..1cbacb15 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -187,7 +187,7 @@ func (s *IntegrationTestSuite) testSuccessOneSwap(asset types.EthAsset, useRelay defer cancel() bwsc := s.newSwapdWSClient(ctx, defaultXMRMakerSwapdWSEndpoint) - min := coins.StrToDecimal("0.2") + min := coins.StrToDecimal("0.21") offerResp, statusCh, err := bwsc.MakeOfferAndSubscribe(min, xmrmakerProvideAmount, exchangeRate, asset, useRelayer) require.NoError(s.T(), err) @@ -529,7 +529,7 @@ func (s *IntegrationTestSuite) testAbortXMRTakerCancels(asset types.EthAsset) { bwsc := s.newSwapdWSClient(ctx, defaultXMRMakerSwapdWSEndpoint) - min := coins.StrToDecimal("0.2") + min := coins.StrToDecimal("0.21") offerResp, statusCh, err := bwsc.MakeOfferAndSubscribe(min, xmrmakerProvideAmount, exchangeRate, asset, false) require.NoError(s.T(), err)