feat: create v2-prep branch with comprehensive planning
Restructured project for V2 refactor: **Structure Changes:** - Moved all V1 code to orig/ folder (preserved with git mv) - Created docs/planning/ directory - Added orig/README_V1.md explaining V1 preservation **Planning Documents:** - 00_V2_MASTER_PLAN.md: Complete architecture overview - Executive summary of critical V1 issues - High-level component architecture diagrams - 5-phase implementation roadmap - Success metrics and risk mitigation - 07_TASK_BREAKDOWN.md: Atomic task breakdown - 99+ hours of detailed tasks - Every task < 2 hours (atomic) - Clear dependencies and success criteria - Organized by implementation phase **V2 Key Improvements:** - Per-exchange parsers (factory pattern) - Multi-layer strict validation - Multi-index pool cache - Background validation pipeline - Comprehensive observability **Critical Issues Addressed:** - Zero address tokens (strict validation + cache enrichment) - Parsing accuracy (protocol-specific parsers) - No audit trail (background validation channel) - Inefficient lookups (multi-index cache) - Stats disconnection (event-driven metrics) Next Steps: 1. Review planning documents 2. Begin Phase 1: Foundation (P1-001 through P1-010) 3. Implement parsers in Phase 2 4. Build cache system in Phase 3 5. Add validation pipeline in Phase 4 6. Migrate and test in Phase 5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
439
orig/pkg/contracts/executor.go
Normal file
439
orig/pkg/contracts/executor.go
Normal file
@@ -0,0 +1,439 @@
|
||||
// Package contracts provides integration with MEV smart contracts for arbitrage execution
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
etypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
|
||||
"github.com/fraktal/mev-beta/bindings/contracts"
|
||||
"github.com/fraktal/mev-beta/bindings/flashswap"
|
||||
"github.com/fraktal/mev-beta/internal/config"
|
||||
"github.com/fraktal/mev-beta/internal/logger"
|
||||
"github.com/fraktal/mev-beta/pkg/security"
|
||||
stypes "github.com/fraktal/mev-beta/pkg/types"
|
||||
)
|
||||
|
||||
// ContractExecutor handles execution of arbitrage opportunities through smart contracts
|
||||
type ContractExecutor struct {
|
||||
config *config.BotConfig
|
||||
logger *logger.Logger
|
||||
client *ethclient.Client
|
||||
keyManager *security.KeyManager
|
||||
arbitrage *contracts.ArbitrageExecutor
|
||||
flashSwapper *flashswap.BaseFlashSwapper
|
||||
privateKey string
|
||||
accountAddress common.Address
|
||||
chainID *big.Int
|
||||
gasPrice *big.Int
|
||||
pendingNonce uint64
|
||||
lastNonceUpdate time.Time
|
||||
}
|
||||
|
||||
// NewContractExecutor creates a new contract executor
|
||||
func NewContractExecutor(
|
||||
cfg *config.Config,
|
||||
logger *logger.Logger,
|
||||
keyManager *security.KeyManager,
|
||||
) (*ContractExecutor, error) {
|
||||
// Connect to Ethereum client
|
||||
client, err := ethclient.Dial(cfg.Arbitrum.RPCEndpoint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to Ethereum node: %w", err)
|
||||
}
|
||||
|
||||
// Parse contract addresses from config
|
||||
arbitrageAddr := common.HexToAddress(cfg.Contracts.ArbitrageExecutor)
|
||||
flashSwapperAddr := common.HexToAddress(cfg.Contracts.FlashSwapper)
|
||||
|
||||
// Create contract instances
|
||||
arbitrageContract, err := contracts.NewArbitrageExecutor(arbitrageAddr, client)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to instantiate arbitrage contract: %w", err)
|
||||
}
|
||||
|
||||
flashSwapperContract, err := flashswap.NewBaseFlashSwapper(flashSwapperAddr, client)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to instantiate flash swapper contract: %w", err)
|
||||
}
|
||||
|
||||
// Get chain ID
|
||||
chainID, err := client.ChainID(context.Background())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get chain ID: %w", err)
|
||||
}
|
||||
|
||||
executor := &ContractExecutor{
|
||||
config: &cfg.Bot,
|
||||
logger: logger,
|
||||
client: client,
|
||||
keyManager: keyManager,
|
||||
arbitrage: arbitrageContract,
|
||||
flashSwapper: flashSwapperContract,
|
||||
privateKey: "", // Will be retrieved from keyManager when needed
|
||||
accountAddress: common.Address{}, // Will be retrieved from keyManager when needed
|
||||
chainID: chainID,
|
||||
gasPrice: big.NewInt(0),
|
||||
pendingNonce: 0,
|
||||
}
|
||||
|
||||
// Initialize gas price
|
||||
if err := executor.updateGasPrice(); err != nil {
|
||||
logger.Warn(fmt.Sprintf("Failed to initialize gas price: %v", err))
|
||||
}
|
||||
|
||||
logger.Info("Contract executor initialized successfully")
|
||||
return executor, nil
|
||||
}
|
||||
|
||||
// ExecuteArbitrage executes a standard arbitrage opportunity
|
||||
func (ce *ContractExecutor) ExecuteArbitrage(ctx context.Context, opportunity stypes.ArbitrageOpportunity) (*etypes.Transaction, error) {
|
||||
ce.logger.Info(fmt.Sprintf("Executing arbitrage opportunity: %+v", opportunity))
|
||||
|
||||
// Convert opportunity to contract parameters
|
||||
params := ce.convertToArbitrageParams(opportunity)
|
||||
|
||||
// Prepare transaction options
|
||||
opts, err := ce.prepareTransactionOpts(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to prepare transaction options: %w", err)
|
||||
}
|
||||
|
||||
// Execute arbitrage through contract - convert interface types using correct field names
|
||||
arbitrageParams := contracts.IArbitrageArbitrageParams{
|
||||
Tokens: params.Tokens,
|
||||
Pools: params.Pools,
|
||||
Amounts: params.Amounts,
|
||||
SwapData: params.SwapData,
|
||||
MinProfit: params.MinProfit,
|
||||
}
|
||||
tx, err := ce.arbitrage.ExecuteArbitrage(opts, arbitrageParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to execute arbitrage: %w", err)
|
||||
}
|
||||
|
||||
ce.logger.Info(fmt.Sprintf("Arbitrage transaction submitted: %s", tx.Hash().Hex()))
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// ExecuteTriangularArbitrage executes a triangular arbitrage opportunity
|
||||
func (ce *ContractExecutor) ExecuteTriangularArbitrage(ctx context.Context, opportunity stypes.ArbitrageOpportunity) (*etypes.Transaction, error) {
|
||||
ce.logger.Info(fmt.Sprintf("Executing triangular arbitrage opportunity: %+v", opportunity))
|
||||
|
||||
// Convert opportunity to contract parameters
|
||||
params := ce.convertToTriangularArbitrageParams(opportunity)
|
||||
|
||||
// Prepare transaction options
|
||||
opts, err := ce.prepareTransactionOpts(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to prepare transaction options: %w", err)
|
||||
}
|
||||
|
||||
// Execute triangular arbitrage through contract - convert interface types
|
||||
triangularParams := contracts.IArbitrageTriangularArbitrageParams{
|
||||
TokenA: params.TokenA,
|
||||
TokenB: params.TokenB,
|
||||
TokenC: params.TokenC,
|
||||
PoolAB: params.PoolAB,
|
||||
PoolBC: params.PoolBC,
|
||||
PoolCA: params.PoolCA,
|
||||
AmountIn: params.AmountIn,
|
||||
MinProfit: params.MinProfit,
|
||||
SwapDataAB: params.SwapDataAB,
|
||||
SwapDataBC: params.SwapDataBC,
|
||||
SwapDataCA: params.SwapDataCA,
|
||||
}
|
||||
tx, err := ce.arbitrage.ExecuteTriangularArbitrage(opts, triangularParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to execute triangular arbitrage: %w", err)
|
||||
}
|
||||
|
||||
ce.logger.Info(fmt.Sprintf("Triangular arbitrage transaction submitted: %s", tx.Hash().Hex()))
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// convertToArbitrageParams converts a scanner opportunity to contract parameters
|
||||
func (ce *ContractExecutor) convertToArbitrageParams(opportunity stypes.ArbitrageOpportunity) contracts.IArbitrageArbitrageParams {
|
||||
// Convert token addresses
|
||||
tokens := make([]common.Address, len(opportunity.Path))
|
||||
for i, token := range opportunity.Path {
|
||||
tokens[i] = common.HexToAddress(token)
|
||||
}
|
||||
|
||||
// Convert pool addresses
|
||||
pools := make([]common.Address, len(opportunity.Pools))
|
||||
for i, pool := range opportunity.Pools {
|
||||
pools[i] = common.HexToAddress(pool)
|
||||
}
|
||||
|
||||
// Convert amounts (simplified for now)
|
||||
amounts := make([]*big.Int, len(pools))
|
||||
for i := range amounts {
|
||||
// Use a default amount for now - in practice this should be calculated based on optimal trade size
|
||||
amounts[i] = big.NewInt(1000000000000000000) // 1 ETH equivalent
|
||||
}
|
||||
|
||||
// Convert swap data (empty for now - in practice this would contain encoded swap parameters)
|
||||
swapData := make([][]byte, len(pools))
|
||||
for i := range swapData {
|
||||
swapData[i] = []byte{}
|
||||
}
|
||||
|
||||
// Create parameters struct
|
||||
params := contracts.IArbitrageArbitrageParams{
|
||||
Tokens: tokens,
|
||||
Pools: pools,
|
||||
Amounts: amounts,
|
||||
SwapData: swapData,
|
||||
MinProfit: opportunity.Profit, // Use estimated profit as minimum required profit
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
// convertToTriangularArbitrageParams converts a scanner opportunity to triangular arbitrage parameters
|
||||
func (ce *ContractExecutor) convertToTriangularArbitrageParams(opportunity stypes.ArbitrageOpportunity) contracts.IArbitrageTriangularArbitrageParams {
|
||||
// For triangular arbitrage, we expect exactly 3 tokens forming a triangle
|
||||
if len(opportunity.Path) < 3 {
|
||||
ce.logger.Error("Invalid triangular arbitrage path - insufficient tokens")
|
||||
return contracts.IArbitrageTriangularArbitrageParams{}
|
||||
}
|
||||
|
||||
// Extract the three tokens
|
||||
tokenA := common.HexToAddress(opportunity.Path[0])
|
||||
tokenB := common.HexToAddress(opportunity.Path[1])
|
||||
tokenC := common.HexToAddress(opportunity.Path[2])
|
||||
|
||||
// Extract pools (should be 3 for triangular arbitrage)
|
||||
if len(opportunity.Pools) < 3 {
|
||||
ce.logger.Error("Invalid triangular arbitrage pools - insufficient pools")
|
||||
return contracts.IArbitrageTriangularArbitrageParams{}
|
||||
}
|
||||
|
||||
poolAB := common.HexToAddress(opportunity.Pools[0])
|
||||
poolBC := common.HexToAddress(opportunity.Pools[1])
|
||||
poolCA := common.HexToAddress(opportunity.Pools[2])
|
||||
|
||||
// Create parameters struct
|
||||
// Calculate optimal input amount based on opportunity size
|
||||
amountIn := opportunity.AmountIn
|
||||
if amountIn == nil || amountIn.Sign() == 0 {
|
||||
// Use 10% of estimated profit as input amount for triangular arbitrage
|
||||
amountIn = new(big.Int).Div(opportunity.Profit, big.NewInt(10))
|
||||
if amountIn.Cmp(big.NewInt(1000000000000000)) < 0 { // Minimum 0.001 ETH
|
||||
amountIn = big.NewInt(1000000000000000)
|
||||
}
|
||||
}
|
||||
|
||||
// Generate swap data for each leg of the triangular arbitrage
|
||||
swapDataAB, err := ce.generateSwapData(tokenA, tokenB, poolAB)
|
||||
if err != nil {
|
||||
ce.logger.Warn(fmt.Sprintf("Failed to generate swap data AB: %v", err))
|
||||
swapDataAB = []byte{} // Fallback to empty data
|
||||
}
|
||||
|
||||
swapDataBC, err := ce.generateSwapData(tokenB, tokenC, poolBC)
|
||||
if err != nil {
|
||||
ce.logger.Warn(fmt.Sprintf("Failed to generate swap data BC: %v", err))
|
||||
swapDataBC = []byte{} // Fallback to empty data
|
||||
}
|
||||
|
||||
swapDataCA, err := ce.generateSwapData(tokenC, tokenA, poolCA)
|
||||
if err != nil {
|
||||
ce.logger.Warn(fmt.Sprintf("Failed to generate swap data CA: %v", err))
|
||||
swapDataCA = []byte{} // Fallback to empty data
|
||||
}
|
||||
|
||||
params := contracts.IArbitrageTriangularArbitrageParams{
|
||||
TokenA: tokenA,
|
||||
TokenB: tokenB,
|
||||
TokenC: tokenC,
|
||||
PoolAB: poolAB,
|
||||
PoolBC: poolBC,
|
||||
PoolCA: poolCA,
|
||||
AmountIn: amountIn,
|
||||
MinProfit: opportunity.Profit,
|
||||
SwapDataAB: swapDataAB,
|
||||
SwapDataBC: swapDataBC,
|
||||
SwapDataCA: swapDataCA,
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
// generateSwapData generates the appropriate swap data based on the pool type
|
||||
func (ce *ContractExecutor) generateSwapData(tokenIn, tokenOut, pool common.Address) ([]byte, error) {
|
||||
// Check if this is a Uniswap V3 pool by trying to call the fee function
|
||||
if fee, err := ce.getUniswapV3Fee(pool); err == nil {
|
||||
// This is a Uniswap V3 pool - generate V3 swap data
|
||||
return ce.generateUniswapV3SwapData(tokenIn, tokenOut, fee)
|
||||
}
|
||||
|
||||
// Check if this is a Uniswap V2 pool by trying to call getReserves
|
||||
if err := ce.checkUniswapV2Pool(pool); err == nil {
|
||||
// This is a Uniswap V2 pool - generate V2 swap data
|
||||
return ce.generateUniswapV2SwapData(tokenIn, tokenOut)
|
||||
}
|
||||
|
||||
// Unknown pool type - return empty data
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
// generateUniswapV3SwapData generates swap data for Uniswap V3 pools
|
||||
func (ce *ContractExecutor) generateUniswapV3SwapData(tokenIn, tokenOut common.Address, fee uint32) ([]byte, error) {
|
||||
// Encode the recipient and deadline for the swap
|
||||
// This is a simplified implementation - production would include more parameters
|
||||
_ = struct {
|
||||
TokenIn common.Address
|
||||
TokenOut common.Address
|
||||
Fee uint32
|
||||
Recipient common.Address
|
||||
Deadline *big.Int
|
||||
AmountOutMinimum *big.Int
|
||||
SqrtPriceLimitX96 *big.Int
|
||||
}{
|
||||
TokenIn: tokenIn,
|
||||
TokenOut: tokenOut,
|
||||
Fee: fee,
|
||||
Recipient: common.Address{}, // Will be set by contract
|
||||
Deadline: big.NewInt(time.Now().Add(10 * time.Minute).Unix()),
|
||||
AmountOutMinimum: big.NewInt(1), // Accept any amount for now
|
||||
SqrtPriceLimitX96: big.NewInt(0), // No price limit
|
||||
}
|
||||
|
||||
// In production, this would use proper ABI encoding
|
||||
// For now, return a simple encoding
|
||||
return []byte(fmt.Sprintf("v3:%s:%s:%d", tokenIn.Hex(), tokenOut.Hex(), fee)), nil
|
||||
}
|
||||
|
||||
// generateUniswapV2SwapData generates swap data for Uniswap V2 pools
|
||||
func (ce *ContractExecutor) generateUniswapV2SwapData(tokenIn, tokenOut common.Address) ([]byte, error) {
|
||||
// V2 swaps are simpler - just need token addresses and path
|
||||
_ = struct {
|
||||
TokenIn common.Address
|
||||
TokenOut common.Address
|
||||
To common.Address
|
||||
Deadline *big.Int
|
||||
}{
|
||||
TokenIn: tokenIn,
|
||||
TokenOut: tokenOut,
|
||||
To: common.Address{}, // Will be set by contract
|
||||
Deadline: big.NewInt(time.Now().Add(10 * time.Minute).Unix()),
|
||||
}
|
||||
|
||||
// Simple encoding for V2 swaps
|
||||
return []byte(fmt.Sprintf("v2:%s:%s", tokenIn.Hex(), tokenOut.Hex())), nil
|
||||
}
|
||||
|
||||
// getUniswapV3Fee tries to get the fee from a Uniswap V3 pool
|
||||
func (ce *ContractExecutor) getUniswapV3Fee(pool common.Address) (uint32, error) {
|
||||
// In production, this would call the fee() function on the pool contract
|
||||
// For now, return a default fee
|
||||
return 3000, nil // 0.3% fee
|
||||
}
|
||||
|
||||
// checkUniswapV2Pool checks if an address is a Uniswap V2 pool
|
||||
func (ce *ContractExecutor) checkUniswapV2Pool(pool common.Address) error {
|
||||
// In production, this would call getReserves() to verify it's a V2 pool
|
||||
// For now, just return success
|
||||
return nil
|
||||
}
|
||||
|
||||
// prepareTransactionOpts prepares transaction options with proper gas pricing and nonce
|
||||
func (ce *ContractExecutor) prepareTransactionOpts(ctx context.Context) (*bind.TransactOpts, error) {
|
||||
// Update gas price if needed
|
||||
if err := ce.updateGasPrice(); err != nil {
|
||||
ce.logger.Warn(fmt.Sprintf("Failed to update gas price: %v", err))
|
||||
}
|
||||
|
||||
// Get current nonce
|
||||
nonce, err := ce.client.PendingNonceAt(ctx, ce.accountAddress)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get account nonce: %w", err)
|
||||
}
|
||||
|
||||
// Check nonce safely before creating transaction options
|
||||
nonceInt64, err := security.SafeUint64ToInt64(nonce)
|
||||
if err != nil {
|
||||
ce.logger.Error("Nonce exceeds int64 maximum", "nonce", nonce, "error", err)
|
||||
return nil, fmt.Errorf("nonce value exceeds maximum: %w", err)
|
||||
}
|
||||
|
||||
// Create transaction options
|
||||
opts := &bind.TransactOpts{
|
||||
From: ce.accountAddress,
|
||||
Nonce: big.NewInt(nonceInt64),
|
||||
Signer: ce.signTransaction, // Custom signer function
|
||||
Value: big.NewInt(0), // No ETH value for arbitrage transactions
|
||||
GasPrice: ce.gasPrice,
|
||||
GasLimit: 0, // Let the node estimate gas limit
|
||||
Context: ctx,
|
||||
NoSend: false,
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// updateGasPrice updates the gas price estimate
|
||||
func (ce *ContractExecutor) updateGasPrice() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Get suggested gas price from node
|
||||
gasPrice, err := ce.client.SuggestGasPrice(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to suggest gas price: %w", err)
|
||||
}
|
||||
|
||||
// Use the suggested gas price directly (no multiplier from config)
|
||||
ce.gasPrice = gasPrice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// signTransaction signs a transaction with the configured private key
|
||||
func (ce *ContractExecutor) signTransaction(address common.Address, tx *etypes.Transaction) (*etypes.Transaction, error) {
|
||||
// Get the private key from the key manager
|
||||
privateKey, err := ce.keyManager.GetActivePrivateKey()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get private key: %w", err)
|
||||
}
|
||||
|
||||
// Get the chain ID for proper signing
|
||||
chainID, err := ce.client.NetworkID(context.Background())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get chain ID: %w", err)
|
||||
}
|
||||
|
||||
ce.logger.Debug(fmt.Sprintf("Signing transaction with chain ID %s", chainID.String()))
|
||||
|
||||
// Create EIP-155 signer for the current chain
|
||||
signer := etypes.NewEIP155Signer(chainID)
|
||||
|
||||
// Sign the transaction
|
||||
signedTx, err := etypes.SignTx(tx, signer, privateKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to sign transaction: %w", err)
|
||||
}
|
||||
|
||||
ce.logger.Debug(fmt.Sprintf("Transaction signed successfully: %s", signedTx.Hash().Hex()))
|
||||
return signedTx, nil
|
||||
}
|
||||
|
||||
// GetClient returns the ethereum client for external use
|
||||
func (ce *ContractExecutor) GetClient() *ethclient.Client {
|
||||
return ce.client
|
||||
}
|
||||
|
||||
// Close closes the contract executor and releases resources
|
||||
func (ce *ContractExecutor) Close() {
|
||||
if ce.client != nil {
|
||||
ce.client.Close()
|
||||
}
|
||||
}
|
||||
175
orig/pkg/contracts/flashloan_executor.go
Normal file
175
orig/pkg/contracts/flashloan_executor.go
Normal file
@@ -0,0 +1,175 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
)
|
||||
|
||||
// FlashLoanExecutorConfig holds configuration for flash loan execution
|
||||
type FlashLoanExecutorConfig struct {
|
||||
ContractAddress common.Address
|
||||
BalancerVault common.Address
|
||||
MaxSlippageBps *big.Int
|
||||
MaxPathLength *big.Int
|
||||
MinProfitWei *big.Int
|
||||
OwnerPrivateKey string
|
||||
RPCEndpoint string
|
||||
}
|
||||
|
||||
// FlashLoanExecutor manages flash loan arbitrage execution
|
||||
type FlashLoanExecutor struct {
|
||||
config *FlashLoanExecutorConfig
|
||||
client *ethclient.Client
|
||||
contract *FlashLoanReceiverSecure
|
||||
auth *bind.TransactOpts
|
||||
}
|
||||
|
||||
// NewFlashLoanExecutor creates a new flash loan executor
|
||||
func NewFlashLoanExecutor(config *FlashLoanExecutorConfig) (*FlashLoanExecutor, error) {
|
||||
client, err := ethclient.Dial(config.RPCEndpoint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to RPC: %w", err)
|
||||
}
|
||||
|
||||
contract, err := NewFlashLoanReceiverSecure(config.ContractAddress, client)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to instantiate contract: %w", err)
|
||||
}
|
||||
|
||||
return &FlashLoanExecutor{
|
||||
config: config,
|
||||
client: client,
|
||||
contract: contract,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ExecuteArbitrage executes a flash loan arbitrage opportunity
|
||||
func (e *FlashLoanExecutor) ExecuteArbitrage(
|
||||
ctx context.Context,
|
||||
tokens []common.Address,
|
||||
amounts []*big.Int,
|
||||
path ArbitragePath,
|
||||
) (*FlashLoanResult, error) {
|
||||
// Encode the arbitrage path
|
||||
userData, err := e.encodeArbitragePath(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode path: %w", err)
|
||||
}
|
||||
|
||||
// Execute the flash loan arbitrage
|
||||
tx, err := e.contract.ExecuteArbitrage(
|
||||
e.auth,
|
||||
convertToIERC20Array(tokens),
|
||||
amounts,
|
||||
userData,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("flash loan execution failed: %w", err)
|
||||
}
|
||||
|
||||
// Wait for transaction confirmation
|
||||
receipt, err := bind.WaitMined(ctx, e.client, tx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("transaction mining failed: %w", err)
|
||||
}
|
||||
|
||||
return &FlashLoanResult{
|
||||
TxHash: tx.Hash(),
|
||||
Success: receipt.Status == 1,
|
||||
GasUsed: receipt.GasUsed,
|
||||
BlockNum: receipt.BlockNumber.Uint64(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawProfit withdraws accumulated profits from the contract
|
||||
func (e *FlashLoanExecutor) WithdrawProfit(
|
||||
ctx context.Context,
|
||||
token common.Address,
|
||||
amount *big.Int,
|
||||
) error {
|
||||
tx, err := e.contract.WithdrawProfit(e.auth, token, amount)
|
||||
if err != nil {
|
||||
return fmt.Errorf("withdraw failed: %w", err)
|
||||
}
|
||||
|
||||
_, err = bind.WaitMined(ctx, e.client, tx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("withdraw transaction mining failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EmergencyWithdraw withdraws all funds from the contract
|
||||
func (e *FlashLoanExecutor) EmergencyWithdraw(
|
||||
ctx context.Context,
|
||||
token common.Address,
|
||||
) error {
|
||||
tx, err := e.contract.EmergencyWithdraw(e.auth, token)
|
||||
if err != nil {
|
||||
return fmt.Errorf("emergency withdraw failed: %w", err)
|
||||
}
|
||||
|
||||
_, err = bind.WaitMined(ctx, e.client, tx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("emergency withdraw transaction mining failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBalance retrieves the balance of a token in the contract
|
||||
func (e *FlashLoanExecutor) GetBalance(
|
||||
ctx context.Context,
|
||||
token common.Address,
|
||||
) (*big.Int, error) {
|
||||
opts := &bind.CallOpts{Context: ctx}
|
||||
balance, err := e.contract.GetBalance(opts, token)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get balance: %w", err)
|
||||
}
|
||||
|
||||
return balance, nil
|
||||
}
|
||||
|
||||
// ArbitragePath represents a multi-hop arbitrage path
|
||||
type ArbitragePath struct {
|
||||
Tokens []common.Address
|
||||
Exchanges []common.Address
|
||||
Fees []*big.Int
|
||||
IsV3 []bool
|
||||
MinProfit *big.Int
|
||||
SlippageBps *big.Int
|
||||
}
|
||||
|
||||
// FlashLoanResult contains the result of a flash loan execution
|
||||
type FlashLoanResult struct {
|
||||
TxHash common.Hash
|
||||
Success bool
|
||||
GasUsed uint64
|
||||
BlockNum uint64
|
||||
}
|
||||
|
||||
// encodeArbitragePath encodes the arbitrage path into bytes for the contract
|
||||
func (e *FlashLoanExecutor) encodeArbitragePath(path ArbitragePath) ([]byte, error) {
|
||||
// TODO: Implement proper ABI encoding for the userData parameter
|
||||
// This will encode: tokens, exchanges, fees, isV3, minProfit, slippageBps
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
// convertToIERC20Array converts address array to IERC20 array for contract call
|
||||
func convertToIERC20Array(addrs []common.Address) []common.Address {
|
||||
return addrs
|
||||
}
|
||||
|
||||
// Close closes the RPC client connection
|
||||
func (e *FlashLoanExecutor) Close() {
|
||||
if e.client != nil {
|
||||
e.client.Close()
|
||||
}
|
||||
}
|
||||
919
orig/pkg/contracts/flashloan_receiver_secure.go
Normal file
919
orig/pkg/contracts/flashloan_receiver_secure.go
Normal file
@@ -0,0 +1,919 @@
|
||||
// Code generated - DO NOT EDIT.
|
||||
// This file is a generated binding and any manual changes will be lost.
|
||||
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
ethereum "github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var (
|
||||
_ = errors.New
|
||||
_ = big.NewInt
|
||||
_ = strings.NewReader
|
||||
_ = ethereum.NotFound
|
||||
_ = bind.Bind
|
||||
_ = common.Big1
|
||||
_ = types.BloomLookup
|
||||
_ = event.NewSubscription
|
||||
_ = abi.ConvertType
|
||||
)
|
||||
|
||||
// FlashLoanReceiverSecureMetaData contains all meta data concerning the FlashLoanReceiverSecure contract.
|
||||
var FlashLoanReceiverSecureMetaData = &bind.MetaData{
|
||||
ABI: "[{\"type\":\"constructor\",\"inputs\":[{\"name\":\"_vault\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"receive\",\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"BASIS_POINTS\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"MAX_PATH_LENGTH\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"MAX_SLIPPAGE_BPS\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"emergencyWithdraw\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"executeArbitrage\",\"inputs\":[{\"name\":\"tokens\",\"type\":\"address[]\",\"internalType\":\"contractIERC20[]\"},{\"name\":\"amounts\",\"type\":\"uint256[]\",\"internalType\":\"uint256[]\"},{\"name\":\"path\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"getBalance\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"owner\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"receiveFlashLoan\",\"inputs\":[{\"name\":\"tokens\",\"type\":\"address[]\",\"internalType\":\"contractIERC20[]\"},{\"name\":\"amounts\",\"type\":\"uint256[]\",\"internalType\":\"uint256[]\"},{\"name\":\"feeAmounts\",\"type\":\"uint256[]\",\"internalType\":\"uint256[]\"},{\"name\":\"userData\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"transferOwnership\",\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"vault\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"contractIBalancerVault\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"withdrawProfit\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"ArbitrageExecuted\",\"inputs\":[{\"name\":\"initiator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"profit\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"pathLength\",\"type\":\"uint8\",\"indexed\":false,\"internalType\":\"uint8\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"FlashLoanInitiated\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"SlippageProtectionTriggered\",\"inputs\":[{\"name\":\"expectedMin\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"},{\"name\":\"actualReceived\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"ReentrancyGuardReentrantCall\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"SafeERC20FailedOperation\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"}]}]",
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureABI is the input ABI used to generate the binding from.
|
||||
// Deprecated: Use FlashLoanReceiverSecureMetaData.ABI instead.
|
||||
var FlashLoanReceiverSecureABI = FlashLoanReceiverSecureMetaData.ABI
|
||||
|
||||
// FlashLoanReceiverSecure is an auto generated Go binding around an Ethereum contract.
|
||||
type FlashLoanReceiverSecure struct {
|
||||
FlashLoanReceiverSecureCaller // Read-only binding to the contract
|
||||
FlashLoanReceiverSecureTransactor // Write-only binding to the contract
|
||||
FlashLoanReceiverSecureFilterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureCaller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type FlashLoanReceiverSecureCaller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type FlashLoanReceiverSecureTransactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type FlashLoanReceiverSecureFilterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureSession is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type FlashLoanReceiverSecureSession struct {
|
||||
Contract *FlashLoanReceiverSecure // Generic contract binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type FlashLoanReceiverSecureCallerSession struct {
|
||||
Contract *FlashLoanReceiverSecureCaller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type FlashLoanReceiverSecureTransactorSession struct {
|
||||
Contract *FlashLoanReceiverSecureTransactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureRaw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type FlashLoanReceiverSecureRaw struct {
|
||||
Contract *FlashLoanReceiverSecure // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type FlashLoanReceiverSecureCallerRaw struct {
|
||||
Contract *FlashLoanReceiverSecureCaller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type FlashLoanReceiverSecureTransactorRaw struct {
|
||||
Contract *FlashLoanReceiverSecureTransactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewFlashLoanReceiverSecure creates a new instance of FlashLoanReceiverSecure, bound to a specific deployed contract.
|
||||
func NewFlashLoanReceiverSecure(address common.Address, backend bind.ContractBackend) (*FlashLoanReceiverSecure, error) {
|
||||
contract, err := bindFlashLoanReceiverSecure(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecure{FlashLoanReceiverSecureCaller: FlashLoanReceiverSecureCaller{contract: contract}, FlashLoanReceiverSecureTransactor: FlashLoanReceiverSecureTransactor{contract: contract}, FlashLoanReceiverSecureFilterer: FlashLoanReceiverSecureFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewFlashLoanReceiverSecureCaller creates a new read-only instance of FlashLoanReceiverSecure, bound to a specific deployed contract.
|
||||
func NewFlashLoanReceiverSecureCaller(address common.Address, caller bind.ContractCaller) (*FlashLoanReceiverSecureCaller, error) {
|
||||
contract, err := bindFlashLoanReceiverSecure(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecureCaller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewFlashLoanReceiverSecureTransactor creates a new write-only instance of FlashLoanReceiverSecure, bound to a specific deployed contract.
|
||||
func NewFlashLoanReceiverSecureTransactor(address common.Address, transactor bind.ContractTransactor) (*FlashLoanReceiverSecureTransactor, error) {
|
||||
contract, err := bindFlashLoanReceiverSecure(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecureTransactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewFlashLoanReceiverSecureFilterer creates a new log filterer instance of FlashLoanReceiverSecure, bound to a specific deployed contract.
|
||||
func NewFlashLoanReceiverSecureFilterer(address common.Address, filterer bind.ContractFilterer) (*FlashLoanReceiverSecureFilterer, error) {
|
||||
contract, err := bindFlashLoanReceiverSecure(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecureFilterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindFlashLoanReceiverSecure binds a generic wrapper to an already deployed contract.
|
||||
func bindFlashLoanReceiverSecure(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := FlashLoanReceiverSecureMetaData.GetAbi()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, *parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// Call invokes the (constant) contract method with params as input values and
|
||||
// sets the output to result. The result type might be a single field for simple
|
||||
// returns, a slice of interfaces for anonymous returns and a struct for named
|
||||
// returns.
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _FlashLoanReceiverSecure.Contract.FlashLoanReceiverSecureCaller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.FlashLoanReceiverSecureTransactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.FlashLoanReceiverSecureTransactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// Call invokes the (constant) contract method with params as input values and
|
||||
// sets the output to result. The result type might be a single field for simple
|
||||
// returns, a slice of interfaces for anonymous returns and a struct for named
|
||||
// returns.
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _FlashLoanReceiverSecure.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// BASISPOINTS is a free data retrieval call binding the contract method 0xe1f1c4a7.
|
||||
//
|
||||
// Solidity: function BASIS_POINTS() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCaller) BASISPOINTS(opts *bind.CallOpts) (*big.Int, error) {
|
||||
var out []interface{}
|
||||
err := _FlashLoanReceiverSecure.contract.Call(opts, &out, "BASIS_POINTS")
|
||||
|
||||
if err != nil {
|
||||
return *new(*big.Int), err
|
||||
}
|
||||
|
||||
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
|
||||
|
||||
return out0, err
|
||||
|
||||
}
|
||||
|
||||
// BASISPOINTS is a free data retrieval call binding the contract method 0xe1f1c4a7.
|
||||
//
|
||||
// Solidity: function BASIS_POINTS() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) BASISPOINTS() (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.BASISPOINTS(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// BASISPOINTS is a free data retrieval call binding the contract method 0xe1f1c4a7.
|
||||
//
|
||||
// Solidity: function BASIS_POINTS() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerSession) BASISPOINTS() (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.BASISPOINTS(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// MAXPATHLENGTH is a free data retrieval call binding the contract method 0xec52303b.
|
||||
//
|
||||
// Solidity: function MAX_PATH_LENGTH() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCaller) MAXPATHLENGTH(opts *bind.CallOpts) (*big.Int, error) {
|
||||
var out []interface{}
|
||||
err := _FlashLoanReceiverSecure.contract.Call(opts, &out, "MAX_PATH_LENGTH")
|
||||
|
||||
if err != nil {
|
||||
return *new(*big.Int), err
|
||||
}
|
||||
|
||||
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
|
||||
|
||||
return out0, err
|
||||
|
||||
}
|
||||
|
||||
// MAXPATHLENGTH is a free data retrieval call binding the contract method 0xec52303b.
|
||||
//
|
||||
// Solidity: function MAX_PATH_LENGTH() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) MAXPATHLENGTH() (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.MAXPATHLENGTH(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// MAXPATHLENGTH is a free data retrieval call binding the contract method 0xec52303b.
|
||||
//
|
||||
// Solidity: function MAX_PATH_LENGTH() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerSession) MAXPATHLENGTH() (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.MAXPATHLENGTH(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// MAXSLIPPAGEBPS is a free data retrieval call binding the contract method 0xe229cd76.
|
||||
//
|
||||
// Solidity: function MAX_SLIPPAGE_BPS() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCaller) MAXSLIPPAGEBPS(opts *bind.CallOpts) (*big.Int, error) {
|
||||
var out []interface{}
|
||||
err := _FlashLoanReceiverSecure.contract.Call(opts, &out, "MAX_SLIPPAGE_BPS")
|
||||
|
||||
if err != nil {
|
||||
return *new(*big.Int), err
|
||||
}
|
||||
|
||||
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
|
||||
|
||||
return out0, err
|
||||
|
||||
}
|
||||
|
||||
// MAXSLIPPAGEBPS is a free data retrieval call binding the contract method 0xe229cd76.
|
||||
//
|
||||
// Solidity: function MAX_SLIPPAGE_BPS() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) MAXSLIPPAGEBPS() (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.MAXSLIPPAGEBPS(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// MAXSLIPPAGEBPS is a free data retrieval call binding the contract method 0xe229cd76.
|
||||
//
|
||||
// Solidity: function MAX_SLIPPAGE_BPS() view returns(uint256)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerSession) MAXSLIPPAGEBPS() (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.MAXSLIPPAGEBPS(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// GetBalance is a free data retrieval call binding the contract method 0xf8b2cb4f.
|
||||
//
|
||||
// Solidity: function getBalance(address token) view returns(uint256 balance)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCaller) GetBalance(opts *bind.CallOpts, token common.Address) (*big.Int, error) {
|
||||
var out []interface{}
|
||||
err := _FlashLoanReceiverSecure.contract.Call(opts, &out, "getBalance", token)
|
||||
|
||||
if err != nil {
|
||||
return *new(*big.Int), err
|
||||
}
|
||||
|
||||
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
|
||||
|
||||
return out0, err
|
||||
|
||||
}
|
||||
|
||||
// GetBalance is a free data retrieval call binding the contract method 0xf8b2cb4f.
|
||||
//
|
||||
// Solidity: function getBalance(address token) view returns(uint256 balance)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) GetBalance(token common.Address) (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.GetBalance(&_FlashLoanReceiverSecure.CallOpts, token)
|
||||
}
|
||||
|
||||
// GetBalance is a free data retrieval call binding the contract method 0xf8b2cb4f.
|
||||
//
|
||||
// Solidity: function getBalance(address token) view returns(uint256 balance)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerSession) GetBalance(token common.Address) (*big.Int, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.GetBalance(&_FlashLoanReceiverSecure.CallOpts, token)
|
||||
}
|
||||
|
||||
// Owner is a free data retrieval call binding the contract method 0x8da5cb5b.
|
||||
//
|
||||
// Solidity: function owner() view returns(address)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCaller) Owner(opts *bind.CallOpts) (common.Address, error) {
|
||||
var out []interface{}
|
||||
err := _FlashLoanReceiverSecure.contract.Call(opts, &out, "owner")
|
||||
|
||||
if err != nil {
|
||||
return *new(common.Address), err
|
||||
}
|
||||
|
||||
out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
|
||||
|
||||
return out0, err
|
||||
|
||||
}
|
||||
|
||||
// Owner is a free data retrieval call binding the contract method 0x8da5cb5b.
|
||||
//
|
||||
// Solidity: function owner() view returns(address)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) Owner() (common.Address, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.Owner(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// Owner is a free data retrieval call binding the contract method 0x8da5cb5b.
|
||||
//
|
||||
// Solidity: function owner() view returns(address)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerSession) Owner() (common.Address, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.Owner(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// Vault is a free data retrieval call binding the contract method 0xfbfa77cf.
|
||||
//
|
||||
// Solidity: function vault() view returns(address)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCaller) Vault(opts *bind.CallOpts) (common.Address, error) {
|
||||
var out []interface{}
|
||||
err := _FlashLoanReceiverSecure.contract.Call(opts, &out, "vault")
|
||||
|
||||
if err != nil {
|
||||
return *new(common.Address), err
|
||||
}
|
||||
|
||||
out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
|
||||
|
||||
return out0, err
|
||||
|
||||
}
|
||||
|
||||
// Vault is a free data retrieval call binding the contract method 0xfbfa77cf.
|
||||
//
|
||||
// Solidity: function vault() view returns(address)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) Vault() (common.Address, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.Vault(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// Vault is a free data retrieval call binding the contract method 0xfbfa77cf.
|
||||
//
|
||||
// Solidity: function vault() view returns(address)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureCallerSession) Vault() (common.Address, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.Vault(&_FlashLoanReceiverSecure.CallOpts)
|
||||
}
|
||||
|
||||
// EmergencyWithdraw is a paid mutator transaction binding the contract method 0x6ff1c9bc.
|
||||
//
|
||||
// Solidity: function emergencyWithdraw(address token) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactor) EmergencyWithdraw(opts *bind.TransactOpts, token common.Address) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.contract.Transact(opts, "emergencyWithdraw", token)
|
||||
}
|
||||
|
||||
// EmergencyWithdraw is a paid mutator transaction binding the contract method 0x6ff1c9bc.
|
||||
//
|
||||
// Solidity: function emergencyWithdraw(address token) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) EmergencyWithdraw(token common.Address) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.EmergencyWithdraw(&_FlashLoanReceiverSecure.TransactOpts, token)
|
||||
}
|
||||
|
||||
// EmergencyWithdraw is a paid mutator transaction binding the contract method 0x6ff1c9bc.
|
||||
//
|
||||
// Solidity: function emergencyWithdraw(address token) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorSession) EmergencyWithdraw(token common.Address) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.EmergencyWithdraw(&_FlashLoanReceiverSecure.TransactOpts, token)
|
||||
}
|
||||
|
||||
// ExecuteArbitrage is a paid mutator transaction binding the contract method 0x176243c4.
|
||||
//
|
||||
// Solidity: function executeArbitrage(address[] tokens, uint256[] amounts, bytes path) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactor) ExecuteArbitrage(opts *bind.TransactOpts, tokens []common.Address, amounts []*big.Int, path []byte) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.contract.Transact(opts, "executeArbitrage", tokens, amounts, path)
|
||||
}
|
||||
|
||||
// ExecuteArbitrage is a paid mutator transaction binding the contract method 0x176243c4.
|
||||
//
|
||||
// Solidity: function executeArbitrage(address[] tokens, uint256[] amounts, bytes path) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) ExecuteArbitrage(tokens []common.Address, amounts []*big.Int, path []byte) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.ExecuteArbitrage(&_FlashLoanReceiverSecure.TransactOpts, tokens, amounts, path)
|
||||
}
|
||||
|
||||
// ExecuteArbitrage is a paid mutator transaction binding the contract method 0x176243c4.
|
||||
//
|
||||
// Solidity: function executeArbitrage(address[] tokens, uint256[] amounts, bytes path) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorSession) ExecuteArbitrage(tokens []common.Address, amounts []*big.Int, path []byte) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.ExecuteArbitrage(&_FlashLoanReceiverSecure.TransactOpts, tokens, amounts, path)
|
||||
}
|
||||
|
||||
// ReceiveFlashLoan is a paid mutator transaction binding the contract method 0xf04f2707.
|
||||
//
|
||||
// Solidity: function receiveFlashLoan(address[] tokens, uint256[] amounts, uint256[] feeAmounts, bytes userData) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactor) ReceiveFlashLoan(opts *bind.TransactOpts, tokens []common.Address, amounts []*big.Int, feeAmounts []*big.Int, userData []byte) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.contract.Transact(opts, "receiveFlashLoan", tokens, amounts, feeAmounts, userData)
|
||||
}
|
||||
|
||||
// ReceiveFlashLoan is a paid mutator transaction binding the contract method 0xf04f2707.
|
||||
//
|
||||
// Solidity: function receiveFlashLoan(address[] tokens, uint256[] amounts, uint256[] feeAmounts, bytes userData) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) ReceiveFlashLoan(tokens []common.Address, amounts []*big.Int, feeAmounts []*big.Int, userData []byte) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.ReceiveFlashLoan(&_FlashLoanReceiverSecure.TransactOpts, tokens, amounts, feeAmounts, userData)
|
||||
}
|
||||
|
||||
// ReceiveFlashLoan is a paid mutator transaction binding the contract method 0xf04f2707.
|
||||
//
|
||||
// Solidity: function receiveFlashLoan(address[] tokens, uint256[] amounts, uint256[] feeAmounts, bytes userData) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorSession) ReceiveFlashLoan(tokens []common.Address, amounts []*big.Int, feeAmounts []*big.Int, userData []byte) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.ReceiveFlashLoan(&_FlashLoanReceiverSecure.TransactOpts, tokens, amounts, feeAmounts, userData)
|
||||
}
|
||||
|
||||
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
|
||||
//
|
||||
// Solidity: function transferOwnership(address newOwner) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactor) TransferOwnership(opts *bind.TransactOpts, newOwner common.Address) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.contract.Transact(opts, "transferOwnership", newOwner)
|
||||
}
|
||||
|
||||
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
|
||||
//
|
||||
// Solidity: function transferOwnership(address newOwner) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) TransferOwnership(newOwner common.Address) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.TransferOwnership(&_FlashLoanReceiverSecure.TransactOpts, newOwner)
|
||||
}
|
||||
|
||||
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
|
||||
//
|
||||
// Solidity: function transferOwnership(address newOwner) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorSession) TransferOwnership(newOwner common.Address) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.TransferOwnership(&_FlashLoanReceiverSecure.TransactOpts, newOwner)
|
||||
}
|
||||
|
||||
// WithdrawProfit is a paid mutator transaction binding the contract method 0xd35c9a07.
|
||||
//
|
||||
// Solidity: function withdrawProfit(address token, uint256 amount) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactor) WithdrawProfit(opts *bind.TransactOpts, token common.Address, amount *big.Int) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.contract.Transact(opts, "withdrawProfit", token, amount)
|
||||
}
|
||||
|
||||
// WithdrawProfit is a paid mutator transaction binding the contract method 0xd35c9a07.
|
||||
//
|
||||
// Solidity: function withdrawProfit(address token, uint256 amount) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) WithdrawProfit(token common.Address, amount *big.Int) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.WithdrawProfit(&_FlashLoanReceiverSecure.TransactOpts, token, amount)
|
||||
}
|
||||
|
||||
// WithdrawProfit is a paid mutator transaction binding the contract method 0xd35c9a07.
|
||||
//
|
||||
// Solidity: function withdrawProfit(address token, uint256 amount) returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorSession) WithdrawProfit(token common.Address, amount *big.Int) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.WithdrawProfit(&_FlashLoanReceiverSecure.TransactOpts, token, amount)
|
||||
}
|
||||
|
||||
// Receive is a paid mutator transaction binding the contract receive function.
|
||||
//
|
||||
// Solidity: receive() payable returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactor) Receive(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.contract.RawTransact(opts, nil) // calldata is disallowed for receive function
|
||||
}
|
||||
|
||||
// Receive is a paid mutator transaction binding the contract receive function.
|
||||
//
|
||||
// Solidity: receive() payable returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureSession) Receive() (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.Receive(&_FlashLoanReceiverSecure.TransactOpts)
|
||||
}
|
||||
|
||||
// Receive is a paid mutator transaction binding the contract receive function.
|
||||
//
|
||||
// Solidity: receive() payable returns()
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureTransactorSession) Receive() (*types.Transaction, error) {
|
||||
return _FlashLoanReceiverSecure.Contract.Receive(&_FlashLoanReceiverSecure.TransactOpts)
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureArbitrageExecutedIterator is returned from FilterArbitrageExecuted and is used to iterate over the raw logs and unpacked data for ArbitrageExecuted events raised by the FlashLoanReceiverSecure contract.
|
||||
type FlashLoanReceiverSecureArbitrageExecutedIterator struct {
|
||||
Event *FlashLoanReceiverSecureArbitrageExecuted // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// Next advances the iterator to the subsequent event, returning whether there
|
||||
// are any more events found. In case of a retrieval or parsing error, false is
|
||||
// returned and Error() can be queried for the exact failure.
|
||||
func (it *FlashLoanReceiverSecureArbitrageExecutedIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(FlashLoanReceiverSecureArbitrageExecuted)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(FlashLoanReceiverSecureArbitrageExecuted)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *FlashLoanReceiverSecureArbitrageExecutedIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *FlashLoanReceiverSecureArbitrageExecutedIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureArbitrageExecuted represents a ArbitrageExecuted event raised by the FlashLoanReceiverSecure contract.
|
||||
type FlashLoanReceiverSecureArbitrageExecuted struct {
|
||||
Initiator common.Address
|
||||
Profit *big.Int
|
||||
PathLength uint8
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterArbitrageExecuted is a free log retrieval operation binding the contract event 0xfac37cdddfd7f291801e7d8107a709cf227f494d3c10c42194ad1fdfb2d9ef6e.
|
||||
//
|
||||
// Solidity: event ArbitrageExecuted(address indexed initiator, uint256 profit, uint8 pathLength)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) FilterArbitrageExecuted(opts *bind.FilterOpts, initiator []common.Address) (*FlashLoanReceiverSecureArbitrageExecutedIterator, error) {
|
||||
|
||||
var initiatorRule []interface{}
|
||||
for _, initiatorItem := range initiator {
|
||||
initiatorRule = append(initiatorRule, initiatorItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _FlashLoanReceiverSecure.contract.FilterLogs(opts, "ArbitrageExecuted", initiatorRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecureArbitrageExecutedIterator{contract: _FlashLoanReceiverSecure.contract, event: "ArbitrageExecuted", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchArbitrageExecuted is a free log subscription operation binding the contract event 0xfac37cdddfd7f291801e7d8107a709cf227f494d3c10c42194ad1fdfb2d9ef6e.
|
||||
//
|
||||
// Solidity: event ArbitrageExecuted(address indexed initiator, uint256 profit, uint8 pathLength)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) WatchArbitrageExecuted(opts *bind.WatchOpts, sink chan<- *FlashLoanReceiverSecureArbitrageExecuted, initiator []common.Address) (event.Subscription, error) {
|
||||
|
||||
var initiatorRule []interface{}
|
||||
for _, initiatorItem := range initiator {
|
||||
initiatorRule = append(initiatorRule, initiatorItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _FlashLoanReceiverSecure.contract.WatchLogs(opts, "ArbitrageExecuted", initiatorRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(FlashLoanReceiverSecureArbitrageExecuted)
|
||||
if err := _FlashLoanReceiverSecure.contract.UnpackLog(event, "ArbitrageExecuted", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// ParseArbitrageExecuted is a log parse operation binding the contract event 0xfac37cdddfd7f291801e7d8107a709cf227f494d3c10c42194ad1fdfb2d9ef6e.
|
||||
//
|
||||
// Solidity: event ArbitrageExecuted(address indexed initiator, uint256 profit, uint8 pathLength)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) ParseArbitrageExecuted(log types.Log) (*FlashLoanReceiverSecureArbitrageExecuted, error) {
|
||||
event := new(FlashLoanReceiverSecureArbitrageExecuted)
|
||||
if err := _FlashLoanReceiverSecure.contract.UnpackLog(event, "ArbitrageExecuted", log); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
event.Raw = log
|
||||
return event, nil
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureFlashLoanInitiatedIterator is returned from FilterFlashLoanInitiated and is used to iterate over the raw logs and unpacked data for FlashLoanInitiated events raised by the FlashLoanReceiverSecure contract.
|
||||
type FlashLoanReceiverSecureFlashLoanInitiatedIterator struct {
|
||||
Event *FlashLoanReceiverSecureFlashLoanInitiated // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// Next advances the iterator to the subsequent event, returning whether there
|
||||
// are any more events found. In case of a retrieval or parsing error, false is
|
||||
// returned and Error() can be queried for the exact failure.
|
||||
func (it *FlashLoanReceiverSecureFlashLoanInitiatedIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(FlashLoanReceiverSecureFlashLoanInitiated)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(FlashLoanReceiverSecureFlashLoanInitiated)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *FlashLoanReceiverSecureFlashLoanInitiatedIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *FlashLoanReceiverSecureFlashLoanInitiatedIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureFlashLoanInitiated represents a FlashLoanInitiated event raised by the FlashLoanReceiverSecure contract.
|
||||
type FlashLoanReceiverSecureFlashLoanInitiated struct {
|
||||
Token common.Address
|
||||
Amount *big.Int
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterFlashLoanInitiated is a free log retrieval operation binding the contract event 0x591ad3206c771ad9f89e5fce3ba3fd39fe164da7093471fce70eaf468c495f3c.
|
||||
//
|
||||
// Solidity: event FlashLoanInitiated(address indexed token, uint256 amount)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) FilterFlashLoanInitiated(opts *bind.FilterOpts, token []common.Address) (*FlashLoanReceiverSecureFlashLoanInitiatedIterator, error) {
|
||||
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _FlashLoanReceiverSecure.contract.FilterLogs(opts, "FlashLoanInitiated", tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecureFlashLoanInitiatedIterator{contract: _FlashLoanReceiverSecure.contract, event: "FlashLoanInitiated", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchFlashLoanInitiated is a free log subscription operation binding the contract event 0x591ad3206c771ad9f89e5fce3ba3fd39fe164da7093471fce70eaf468c495f3c.
|
||||
//
|
||||
// Solidity: event FlashLoanInitiated(address indexed token, uint256 amount)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) WatchFlashLoanInitiated(opts *bind.WatchOpts, sink chan<- *FlashLoanReceiverSecureFlashLoanInitiated, token []common.Address) (event.Subscription, error) {
|
||||
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _FlashLoanReceiverSecure.contract.WatchLogs(opts, "FlashLoanInitiated", tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(FlashLoanReceiverSecureFlashLoanInitiated)
|
||||
if err := _FlashLoanReceiverSecure.contract.UnpackLog(event, "FlashLoanInitiated", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// ParseFlashLoanInitiated is a log parse operation binding the contract event 0x591ad3206c771ad9f89e5fce3ba3fd39fe164da7093471fce70eaf468c495f3c.
|
||||
//
|
||||
// Solidity: event FlashLoanInitiated(address indexed token, uint256 amount)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) ParseFlashLoanInitiated(log types.Log) (*FlashLoanReceiverSecureFlashLoanInitiated, error) {
|
||||
event := new(FlashLoanReceiverSecureFlashLoanInitiated)
|
||||
if err := _FlashLoanReceiverSecure.contract.UnpackLog(event, "FlashLoanInitiated", log); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
event.Raw = log
|
||||
return event, nil
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureSlippageProtectionTriggeredIterator is returned from FilterSlippageProtectionTriggered and is used to iterate over the raw logs and unpacked data for SlippageProtectionTriggered events raised by the FlashLoanReceiverSecure contract.
|
||||
type FlashLoanReceiverSecureSlippageProtectionTriggeredIterator struct {
|
||||
Event *FlashLoanReceiverSecureSlippageProtectionTriggered // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// Next advances the iterator to the subsequent event, returning whether there
|
||||
// are any more events found. In case of a retrieval or parsing error, false is
|
||||
// returned and Error() can be queried for the exact failure.
|
||||
func (it *FlashLoanReceiverSecureSlippageProtectionTriggeredIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(FlashLoanReceiverSecureSlippageProtectionTriggered)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(FlashLoanReceiverSecureSlippageProtectionTriggered)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *FlashLoanReceiverSecureSlippageProtectionTriggeredIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *FlashLoanReceiverSecureSlippageProtectionTriggeredIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FlashLoanReceiverSecureSlippageProtectionTriggered represents a SlippageProtectionTriggered event raised by the FlashLoanReceiverSecure contract.
|
||||
type FlashLoanReceiverSecureSlippageProtectionTriggered struct {
|
||||
ExpectedMin *big.Int
|
||||
ActualReceived *big.Int
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterSlippageProtectionTriggered is a free log retrieval operation binding the contract event 0xb6094abf4e604ae0f85e37ab40510f093f6857d01c802ec39d20a3d67ec8f44d.
|
||||
//
|
||||
// Solidity: event SlippageProtectionTriggered(uint256 expectedMin, uint256 actualReceived)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) FilterSlippageProtectionTriggered(opts *bind.FilterOpts) (*FlashLoanReceiverSecureSlippageProtectionTriggeredIterator, error) {
|
||||
|
||||
logs, sub, err := _FlashLoanReceiverSecure.contract.FilterLogs(opts, "SlippageProtectionTriggered")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FlashLoanReceiverSecureSlippageProtectionTriggeredIterator{contract: _FlashLoanReceiverSecure.contract, event: "SlippageProtectionTriggered", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchSlippageProtectionTriggered is a free log subscription operation binding the contract event 0xb6094abf4e604ae0f85e37ab40510f093f6857d01c802ec39d20a3d67ec8f44d.
|
||||
//
|
||||
// Solidity: event SlippageProtectionTriggered(uint256 expectedMin, uint256 actualReceived)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) WatchSlippageProtectionTriggered(opts *bind.WatchOpts, sink chan<- *FlashLoanReceiverSecureSlippageProtectionTriggered) (event.Subscription, error) {
|
||||
|
||||
logs, sub, err := _FlashLoanReceiverSecure.contract.WatchLogs(opts, "SlippageProtectionTriggered")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(FlashLoanReceiverSecureSlippageProtectionTriggered)
|
||||
if err := _FlashLoanReceiverSecure.contract.UnpackLog(event, "SlippageProtectionTriggered", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// ParseSlippageProtectionTriggered is a log parse operation binding the contract event 0xb6094abf4e604ae0f85e37ab40510f093f6857d01c802ec39d20a3d67ec8f44d.
|
||||
//
|
||||
// Solidity: event SlippageProtectionTriggered(uint256 expectedMin, uint256 actualReceived)
|
||||
func (_FlashLoanReceiverSecure *FlashLoanReceiverSecureFilterer) ParseSlippageProtectionTriggered(log types.Log) (*FlashLoanReceiverSecureSlippageProtectionTriggered, error) {
|
||||
event := new(FlashLoanReceiverSecureSlippageProtectionTriggered)
|
||||
if err := _FlashLoanReceiverSecure.contract.UnpackLog(event, "SlippageProtectionTriggered", log); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
event.Raw = log
|
||||
return event, nil
|
||||
}
|
||||
57
orig/pkg/contracts/key_manager.go
Normal file
57
orig/pkg/contracts/key_manager.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
type KeyManager struct {
|
||||
privateKey *ecdsa.PrivateKey
|
||||
}
|
||||
|
||||
// NewKeyManager creates a new key manager from environment
|
||||
func NewKeyManager() (*KeyManager, error) {
|
||||
privateKeyStr := os.Getenv("PRIVATE_KEY")
|
||||
if privateKeyStr == "" {
|
||||
return nil, fmt.Errorf("PRIVATE_KEY environment variable not set")
|
||||
}
|
||||
|
||||
// Remove 0x prefix if present
|
||||
if len(privateKeyStr) > 2 && privateKeyStr[:2] == "0x" {
|
||||
privateKeyStr = privateKeyStr[2:]
|
||||
}
|
||||
|
||||
privateKeyBytes, err := hex.DecodeString(privateKeyStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid private key: %v", err)
|
||||
}
|
||||
|
||||
privateKey, err := crypto.ToECDSA(privateKeyBytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid private key format: %v", err)
|
||||
}
|
||||
|
||||
return &KeyManager{
|
||||
privateKey: privateKey,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetPrivateKey returns the private key
|
||||
func (km *KeyManager) GetPrivateKey() (*ecdsa.PrivateKey, error) {
|
||||
if km.privateKey == nil {
|
||||
return nil, fmt.Errorf("private key not initialized")
|
||||
}
|
||||
return km.privateKey, nil
|
||||
}
|
||||
|
||||
// GetAddress returns the Ethereum address
|
||||
func (km *KeyManager) GetAddress() string {
|
||||
if km.privateKey == nil {
|
||||
return ""
|
||||
}
|
||||
return crypto.PubkeyToAddress(km.privateKey.PublicKey).Hex()
|
||||
}
|
||||
Reference in New Issue
Block a user