2024-06-06 22:08:25 +02:00
package pathprocessor
2024-10-03 20:59:44 +01:00
//go:generate mockgen -package=mock_pathprocessor -source=processor.go -destination=mock/processor.go
2024-06-06 22:08:25 +02:00
import (
"math/big"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/account"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/params"
2024-11-05 22:20:27 +01:00
"github.com/status-im/status-go/services/wallet/requests"
2024-06-06 22:08:25 +02:00
"github.com/status-im/status-go/services/wallet/token"
2024-09-23 09:16:03 +02:00
"github.com/status-im/status-go/transactions"
2024-06-06 22:08:25 +02:00
)
type PathProcessor interface {
2024-06-14 13:27:53 +02:00
// Name returns the name of the bridge
2024-06-06 22:08:25 +02:00
Name ( ) string
2024-06-14 13:27:53 +02:00
// AvailableFor checks if the bridge is available for the given networks/tokens
2024-06-06 22:08:25 +02:00
AvailableFor ( params ProcessorInputParams ) ( bool , error )
2024-06-14 13:27:53 +02:00
// CalculateFees calculates the fees for the bridge and returns the amount BonderFee and TokenFee (used for bridges)
2024-06-06 22:08:25 +02:00
CalculateFees ( params ProcessorInputParams ) ( * big . Int , * big . Int , error )
2024-06-14 13:27:53 +02:00
// PackTxInputData packs tx for sending
2024-06-10 14:52:47 +02:00
PackTxInputData ( params ProcessorInputParams ) ( [ ] byte , error )
2024-06-14 13:27:53 +02:00
// EstimateGas estimates the gas
2024-06-06 22:08:25 +02:00
EstimateGas ( params ProcessorInputParams ) ( uint64 , error )
2024-06-14 13:27:53 +02:00
// CalculateAmountOut calculates the amount out
2024-06-06 22:08:25 +02:00
CalculateAmountOut ( params ProcessorInputParams ) ( * big . Int , error )
2024-08-12 14:07:32 +02:00
// Send sends the tx, returns the hash and the used nonce (lastUsedNonce is -1 if it's the first tx)
Send ( sendArgs * MultipathProcessorTxArgs , lastUsedNonce int64 , verifiedAccount * account . SelectedExtKey ) ( types . Hash , uint64 , error )
2024-06-14 13:27:53 +02:00
// GetContractAddress returns the contract address
2024-06-06 22:08:25 +02:00
GetContractAddress ( params ProcessorInputParams ) ( common . Address , error )
2024-08-12 14:07:32 +02:00
// BuildTransaction builds the transaction based on MultipathProcessorTxArgs, returns the transaction and the used nonce (lastUsedNonce is -1 if it's the first tx)
BuildTransaction ( sendArgs * MultipathProcessorTxArgs , lastUsedNonce int64 ) ( * ethTypes . Transaction , uint64 , error )
2024-09-23 09:16:03 +02:00
// BuildTransactionV2 builds the transaction based on SendTxArgs, returns the transaction and the used nonce (lastUsedNonce is -1 if it's the first tx)
BuildTransactionV2 ( sendArgs * transactions . SendTxArgs , lastUsedNonce int64 ) ( * ethTypes . Transaction , uint64 , error )
2024-06-06 22:08:25 +02:00
}
2024-06-14 13:27:53 +02:00
type PathProcessorClearable interface {
// Clear clears the local cache
Clear ( )
}
2024-06-06 22:08:25 +02:00
type ProcessorInputParams struct {
FromChain * params . Network
ToChain * params . Network
FromAddr common . Address
ToAddr common . Address
FromToken * token . Token
ToToken * token . Token
AmountIn * big . Int
2024-06-12 22:14:30 +02:00
AmountOut * big . Int
2024-06-06 22:08:25 +02:00
// extra params
BonderFee * big . Int
Username string
PublicKey string
2024-06-11 10:00:17 +02:00
PackID * big . Int
2024-06-18 12:31:23 +02:00
// for testing purposes
TestsMode bool
2024-11-05 22:20:27 +01:00
TestEstimationMap map [ string ] requests . Estimation // [bridge-name, estimation]
TestBonderFeeMap map [ string ] * big . Int // [token-symbol, bonder-fee]
2024-06-18 12:31:23 +02:00
TestApprovalGasEstimation uint64
TestApprovalL1Fee uint64
2024-06-06 22:08:25 +02:00
}