2024-06-06 20:08:25 +00:00
package pathprocessor
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"
"github.com/status-im/status-go/services/wallet/token"
)
type PathProcessor interface {
2024-06-14 11:27:53 +00:00
// Name returns the name of the bridge
2024-06-06 20:08:25 +00:00
Name ( ) string
2024-06-14 11:27:53 +00:00
// AvailableFor checks if the bridge is available for the given networks/tokens
2024-06-06 20:08:25 +00:00
AvailableFor ( params ProcessorInputParams ) ( bool , error )
2024-06-14 11:27:53 +00:00
// CalculateFees calculates the fees for the bridge and returns the amount BonderFee and TokenFee (used for bridges)
2024-06-06 20:08:25 +00:00
CalculateFees ( params ProcessorInputParams ) ( * big . Int , * big . Int , error )
2024-06-14 11:27:53 +00:00
// PackTxInputData packs tx for sending
2024-06-10 12:52:47 +00:00
PackTxInputData ( params ProcessorInputParams ) ( [ ] byte , error )
2024-06-14 11:27:53 +00:00
// EstimateGas estimates the gas
2024-06-06 20:08:25 +00:00
EstimateGas ( params ProcessorInputParams ) ( uint64 , error )
2024-06-14 11:27:53 +00:00
// CalculateAmountOut calculates the amount out
2024-06-06 20:08:25 +00:00
CalculateAmountOut ( params ProcessorInputParams ) ( * big . Int , error )
2024-08-12 12:07:32 +00: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 11:27:53 +00:00
// GetContractAddress returns the contract address
2024-06-06 20:08:25 +00:00
GetContractAddress ( params ProcessorInputParams ) ( common . Address , error )
2024-08-12 12:07:32 +00: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-06-06 20:08:25 +00:00
}
2024-06-14 11:27:53 +00:00
type PathProcessorClearable interface {
// Clear clears the local cache
Clear ( )
}
2024-06-06 20:08:25 +00: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 20:14:30 +00:00
AmountOut * big . Int
2024-06-06 20:08:25 +00:00
// extra params
BonderFee * big . Int
Username string
PublicKey string
2024-06-11 08:00:17 +00:00
PackID * big . Int
2024-06-18 10:31:23 +00:00
// for testing purposes
TestsMode bool
2024-08-23 14:01:49 +00:00
TestEstimationMap map [ string ] Estimation // [bridge-name, estimation]
TestBonderFeeMap map [ string ] * big . Int // [token-symbol, bonder-fee]
2024-06-18 10:31:23 +00:00
TestApprovalGasEstimation uint64
TestApprovalL1Fee uint64
2024-06-06 20:08:25 +00:00
}
2024-08-23 14:01:49 +00:00
type Estimation struct {
Value uint64
Err error
}