From 13c07a56375a943200b761d2d2c349b686f9ec2d Mon Sep 17 00:00:00 2001 From: PeterHeng666 Date: Sun, 27 Oct 2024 17:30:00 +0800 Subject: [PATCH 1/3] add lock taiko --- abi/loopring.json | 1 + adapters/contracts/loopring/loopring.go | 17 +++++ adapters/projects/loopring/lock.go | 96 +++++++++++++++++++++++++ adapters/projects/loopring/lock_test.go | 41 +++++++++++ cmd/adapter.go | 2 + cmd/cmd.go | 7 ++ whitelist/protocols.json | 3 +- 7 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 abi/loopring.json create mode 100644 adapters/contracts/loopring/loopring.go create mode 100644 adapters/projects/loopring/lock.go create mode 100644 adapters/projects/loopring/lock_test.go diff --git a/abi/loopring.json b/abi/loopring.json new file mode 100644 index 0000000..2678607 --- /dev/null +++ b/abi/loopring.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"_exchange","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint96","name":"amount","type":"uint96"},{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"}],"name":"Deposited","type":"event"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint96","name":"amount","type":"uint96"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"exchange","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}] diff --git a/adapters/contracts/loopring/loopring.go b/adapters/contracts/loopring/loopring.go new file mode 100644 index 0000000..2e228b5 --- /dev/null +++ b/adapters/contracts/loopring/loopring.go @@ -0,0 +1,17 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package loopring + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" +) + + +// LoopringMetaData contains all meta data concerning the Drips contract. +var LoopringMetaData = &bind.MetaData{ + ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_exchange\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint96\",\"name\":\"amount\",\"type\":\"uint96\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"}],\"name\":\"Deposited\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenAddress\",\"type\":\"address\"},{\"internalType\":\"uint96\",\"name\":\"amount\",\"type\":\"uint96\"},{\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"extraData\",\"type\":\"bytes\"}],\"name\":\"deposit\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"exchange\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", +} + +// LoopringABI is the input ABI used to generate the binding from. +var LoopringABI = LoopringMetaData.ABI diff --git a/adapters/projects/loopring/lock.go b/adapters/projects/loopring/lock.go new file mode 100644 index 0000000..815a5a6 --- /dev/null +++ b/adapters/projects/loopring/lock.go @@ -0,0 +1,96 @@ +package loopring + +import ( + "context" + "math/big" + "strings" + + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/taikoxyz/trailblazer-adapters/adapters" + "github.com/taikoxyz/trailblazer-adapters/adapters/contracts/loopring" +) + +const ( + // https://taikoscan.io/address/0xaD32A362645Ac9139CFb5Ba3A2A46fC4c378812B + LockAddress string = "0xaD32A362645Ac9139CFb5Ba3A2A46fC4c378812B" + + logDepositWithDurationSignature string = "Deposited(address,address,address,uint96,uint256)" +) + +type LockIndexer struct { + client *ethclient.Client + addresses []common.Address +} + +func NewLockIndexer(client *ethclient.Client, addresses []common.Address) *LockIndexer { + return &LockIndexer{ + client: client, + addresses: addresses, + } +} + +var _ adapters.LogIndexer[adapters.Lock] = &LockIndexer{} + +func (indexer *LockIndexer) Addresses() []common.Address { + return indexer.addresses +} + +func (indexer *LockIndexer) Index(ctx context.Context, logs ...types.Log) ([]adapters.Lock, error) { + var locks []adapters.Lock + + for _, l := range logs { + if !indexer.isDepositWithDuration(l) { + continue + } + + var depositWithDurationEvent struct { + From common.Address + To common.Address + Token common.Address + Amount *big.Int + Duration *big.Int + } + + loopringABI, err := abi.JSON(strings.NewReader(loopring.LoopringABI)) + if err != nil { + return nil, err + } + + err = loopringABI.UnpackIntoInterface(&depositWithDurationEvent, "Deposited", l.Data) + if err != nil { + return nil, err + } + + if depositWithDurationEvent.Token != common.HexToAddress(adapters.TaikoTokenAddress) { + continue + } + + block, err := indexer.client.BlockByNumber(ctx, big.NewInt(int64(l.BlockNumber))) + if err != nil { + return nil, err + } + + lock := &adapters.Lock{ + User: depositWithDurationEvent.To, + TokenAmount: depositWithDurationEvent.Amount, + TokenDecimals: adapters.TaikoTokenDecimals, + Token: common.HexToAddress(adapters.TaikoTokenAddress), + Duration: depositWithDurationEvent.Duration.Uint64(), + BlockTime: block.Time(), + BlockNumber: block.NumberU64(), + TxHash: l.TxHash, + } + + locks = append(locks, *lock) + } + + return locks, nil +} + +func (indexer *LockIndexer) isDepositWithDuration(l types.Log) bool { + return l.Topics[0].Hex() == crypto.Keccak256Hash([]byte(logDepositWithDurationSignature)).Hex() +} diff --git a/adapters/projects/loopring/lock_test.go b/adapters/projects/loopring/lock_test.go new file mode 100644 index 0000000..4afc787 --- /dev/null +++ b/adapters/projects/loopring/lock_test.go @@ -0,0 +1,41 @@ +package loopring_test + +import ( + "context" + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/taikoxyz/trailblazer-adapters/adapters" + "github.com/taikoxyz/trailblazer-adapters/adapters/projects/loopring" +) + +func TestLockIndexer(t *testing.T) { + taikoRPC := "https://rpc.taiko.xyz" + blocknumber := int64(496553) + + ctx := context.Background() + + client, err := ethclient.Dial(taikoRPC) + require.NoError(t, err) + + indexer := loopring.NewLockIndexer(client, []common.Address{common.HexToAddress(loopring.LockAddress)}) + + logs, err := adapters.GetLogs(ctx, client, indexer.Addresses(), blocknumber) + require.NoError(t, err) + + locks, err := indexer.Index(ctx, logs...) + assert.NoError(t, err) + assert.Len(t, locks, 1) + assert.Equal(t, common.HexToAddress("0x6b1029C9AE8Aa5EEA9e045E8ba3C93d380D5BDDa"), locks[0].User) + assert.Equal(t, big.NewInt(1000000000000000000), locks[0].TokenAmount) + assert.Equal(t, adapters.TaikoTokenDecimals, locks[0].TokenDecimals) + assert.Equal(t, common.HexToAddress(adapters.TaikoTokenAddress), locks[0].Token) + assert.Equal(t, uint64(1730112839), locks[0].BlockTime) + assert.Equal(t, uint64(259200), locks[0].Duration) + assert.Equal(t, uint64(blocknumber), locks[0].BlockNumber) + assert.Equal(t, common.HexToHash("0x604cc9466718ffd00787cbe7b0aefaa3b9ab5da030e59b60e6dec4fa31922ad9"), locks[0].TxHash) +} diff --git a/cmd/adapter.go b/cmd/adapter.go index 432d291..372e7bf 100644 --- a/cmd/adapter.go +++ b/cmd/adapter.go @@ -21,6 +21,7 @@ const ( DripsLock adapter = "DripsLock" SymmetricLock adapter = "SymmetricLock" RobinosPrediction adapter = "RobinosPrediction" + LoopringLock adapter = "LoopringLock" ) func adapterz() []adapter { @@ -39,5 +40,6 @@ func adapterz() []adapter { DripsLock, SymmetricLock, RobinosPrediction, + LoopringLock, } } diff --git a/cmd/cmd.go b/cmd/cmd.go index 93b8355..c8ef979 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -25,6 +25,7 @@ import ( "github.com/taikoxyz/trailblazer-adapters/adapters/projects/ritsu" "github.com/taikoxyz/trailblazer-adapters/adapters/projects/symmetric" "github.com/taikoxyz/trailblazer-adapters/adapters/projects/robinos" + "github.com/taikoxyz/trailblazer-adapters/adapters/projects/loopring" transactionsender "github.com/taikoxyz/trailblazer-adapters/adapters/transaction_sender" ) @@ -187,6 +188,12 @@ func executeCommand(p prompt) error { robinos.SelectedMultiplierEvents, ) return processLog(ctx, client, indexer, p.Blocknumber) + case LoopringLock: + indexer := loopring.NewLockIndexer( + client, + []common.Address{common.HexToAddress(loopring.LockAddress)}, + ) + return processLog(ctx, client, indexer, p.Blocknumber) default: return fmt.Errorf("adapter %s is not supported", p.Adapter) diff --git a/whitelist/protocols.json b/whitelist/protocols.json index 800bbc5..59bff3c 100644 --- a/whitelist/protocols.json +++ b/whitelist/protocols.json @@ -736,7 +736,8 @@ "logo": "loopring_logo.png", "contracts": [ "0xbD787F374198d29E2F8Fa228c778FE39e1a5d3a9", - "0x3e71a41325e1d6B450307b6535EC48627ac4DaCC" + "0x3e71a41325e1d6B450307b6535EC48627ac4DaCC", + "0xaD32A362645Ac9139CFb5Ba3A2A46fC4c378812B" ] }, { From 6fc49839131cf3761d3f7d07a900c012e68eaa7a Mon Sep 17 00:00:00 2001 From: PeterHeng666 Date: Tue, 29 Oct 2024 08:28:18 +0800 Subject: [PATCH 2/3] format --- cmd/adapter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/adapter.go b/cmd/adapter.go index 372e7bf..3b6fee3 100644 --- a/cmd/adapter.go +++ b/cmd/adapter.go @@ -21,7 +21,7 @@ const ( DripsLock adapter = "DripsLock" SymmetricLock adapter = "SymmetricLock" RobinosPrediction adapter = "RobinosPrediction" - LoopringLock adapter = "LoopringLock" + LoopringLock adapter = "LoopringLock" ) func adapterz() []adapter { From 20d701d1c79506d8f38c73b50096947fc4bfc542 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 29 Oct 2024 09:23:54 +0000 Subject: [PATCH 3/3] add gen abi --- abigen.sh | 2 +- adapters/contracts/loopring/loopring.go | 356 +++++++++++++++++++++++- 2 files changed, 356 insertions(+), 2 deletions(-) diff --git a/abigen.sh b/abigen.sh index 9b782aa..13980e9 100755 --- a/abigen.sh +++ b/abigen.sh @@ -1,6 +1,6 @@ #/bin/sh -names=("erc20" "ritsu" "izumi" "iziPool" "drips" "symmetric" "balancer_vault" "balancer_token" "robinos") +names=("erc20" "ritsu" "izumi" "iziPool" "drips" "symmetric" "balancer_vault" "balancer_token" "robinos" "loopring") for (( i = 0; i < ${#names[@]}; ++i )); do diff --git a/adapters/contracts/loopring/loopring.go b/adapters/contracts/loopring/loopring.go index 2e228b5..1adcb2d 100644 --- a/adapters/contracts/loopring/loopring.go +++ b/adapters/contracts/loopring/loopring.go @@ -4,14 +4,368 @@ package loopring 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 +) -// LoopringMetaData contains all meta data concerning the Drips contract. +// LoopringMetaData contains all meta data concerning the Loopring contract. var LoopringMetaData = &bind.MetaData{ ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_exchange\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint96\",\"name\":\"amount\",\"type\":\"uint96\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"}],\"name\":\"Deposited\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenAddress\",\"type\":\"address\"},{\"internalType\":\"uint96\",\"name\":\"amount\",\"type\":\"uint96\"},{\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"extraData\",\"type\":\"bytes\"}],\"name\":\"deposit\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"exchange\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", } // LoopringABI is the input ABI used to generate the binding from. +// Deprecated: Use LoopringMetaData.ABI instead. var LoopringABI = LoopringMetaData.ABI + +// Loopring is an auto generated Go binding around an Ethereum contract. +type Loopring struct { + LoopringCaller // Read-only binding to the contract + LoopringTransactor // Write-only binding to the contract + LoopringFilterer // Log filterer for contract events +} + +// LoopringCaller is an auto generated read-only Go binding around an Ethereum contract. +type LoopringCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// LoopringTransactor is an auto generated write-only Go binding around an Ethereum contract. +type LoopringTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// LoopringFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type LoopringFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// LoopringSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type LoopringSession struct { + Contract *Loopring // 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 +} + +// LoopringCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type LoopringCallerSession struct { + Contract *LoopringCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// LoopringTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type LoopringTransactorSession struct { + Contract *LoopringTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// LoopringRaw is an auto generated low-level Go binding around an Ethereum contract. +type LoopringRaw struct { + Contract *Loopring // Generic contract binding to access the raw methods on +} + +// LoopringCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type LoopringCallerRaw struct { + Contract *LoopringCaller // Generic read-only contract binding to access the raw methods on +} + +// LoopringTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type LoopringTransactorRaw struct { + Contract *LoopringTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewLoopring creates a new instance of Loopring, bound to a specific deployed contract. +func NewLoopring(address common.Address, backend bind.ContractBackend) (*Loopring, error) { + contract, err := bindLoopring(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Loopring{LoopringCaller: LoopringCaller{contract: contract}, LoopringTransactor: LoopringTransactor{contract: contract}, LoopringFilterer: LoopringFilterer{contract: contract}}, nil +} + +// NewLoopringCaller creates a new read-only instance of Loopring, bound to a specific deployed contract. +func NewLoopringCaller(address common.Address, caller bind.ContractCaller) (*LoopringCaller, error) { + contract, err := bindLoopring(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &LoopringCaller{contract: contract}, nil +} + +// NewLoopringTransactor creates a new write-only instance of Loopring, bound to a specific deployed contract. +func NewLoopringTransactor(address common.Address, transactor bind.ContractTransactor) (*LoopringTransactor, error) { + contract, err := bindLoopring(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &LoopringTransactor{contract: contract}, nil +} + +// NewLoopringFilterer creates a new log filterer instance of Loopring, bound to a specific deployed contract. +func NewLoopringFilterer(address common.Address, filterer bind.ContractFilterer) (*LoopringFilterer, error) { + contract, err := bindLoopring(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &LoopringFilterer{contract: contract}, nil +} + +// bindLoopring binds a generic wrapper to an already deployed contract. +func bindLoopring(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := LoopringMetaData.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 (_Loopring *LoopringRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Loopring.Contract.LoopringCaller.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 (_Loopring *LoopringRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Loopring.Contract.LoopringTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Loopring *LoopringRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Loopring.Contract.LoopringTransactor.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 (_Loopring *LoopringCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _Loopring.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 (_Loopring *LoopringTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _Loopring.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Loopring *LoopringTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _Loopring.Contract.contract.Transact(opts, method, params...) +} + +// Exchange is a free data retrieval call binding the contract method 0xd2f7265a. +// +// Solidity: function exchange() view returns(address) +func (_Loopring *LoopringCaller) Exchange(opts *bind.CallOpts) (common.Address, error) { + var out []interface{} + err := _Loopring.contract.Call(opts, &out, "exchange") + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// Exchange is a free data retrieval call binding the contract method 0xd2f7265a. +// +// Solidity: function exchange() view returns(address) +func (_Loopring *LoopringSession) Exchange() (common.Address, error) { + return _Loopring.Contract.Exchange(&_Loopring.CallOpts) +} + +// Exchange is a free data retrieval call binding the contract method 0xd2f7265a. +// +// Solidity: function exchange() view returns(address) +func (_Loopring *LoopringCallerSession) Exchange() (common.Address, error) { + return _Loopring.Contract.Exchange(&_Loopring.CallOpts) +} + +// Deposit is a paid mutator transaction binding the contract method 0x8742da3a. +// +// Solidity: function deposit(address from, address to, address tokenAddress, uint96 amount, uint256 duration, bytes extraData) payable returns() +func (_Loopring *LoopringTransactor) Deposit(opts *bind.TransactOpts, from common.Address, to common.Address, tokenAddress common.Address, amount *big.Int, duration *big.Int, extraData []byte) (*types.Transaction, error) { + return _Loopring.contract.Transact(opts, "deposit", from, to, tokenAddress, amount, duration, extraData) +} + +// Deposit is a paid mutator transaction binding the contract method 0x8742da3a. +// +// Solidity: function deposit(address from, address to, address tokenAddress, uint96 amount, uint256 duration, bytes extraData) payable returns() +func (_Loopring *LoopringSession) Deposit(from common.Address, to common.Address, tokenAddress common.Address, amount *big.Int, duration *big.Int, extraData []byte) (*types.Transaction, error) { + return _Loopring.Contract.Deposit(&_Loopring.TransactOpts, from, to, tokenAddress, amount, duration, extraData) +} + +// Deposit is a paid mutator transaction binding the contract method 0x8742da3a. +// +// Solidity: function deposit(address from, address to, address tokenAddress, uint96 amount, uint256 duration, bytes extraData) payable returns() +func (_Loopring *LoopringTransactorSession) Deposit(from common.Address, to common.Address, tokenAddress common.Address, amount *big.Int, duration *big.Int, extraData []byte) (*types.Transaction, error) { + return _Loopring.Contract.Deposit(&_Loopring.TransactOpts, from, to, tokenAddress, amount, duration, extraData) +} + +// LoopringDepositedIterator is returned from FilterDeposited and is used to iterate over the raw logs and unpacked data for Deposited events raised by the Loopring contract. +type LoopringDepositedIterator struct { + Event *LoopringDeposited // 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 *LoopringDepositedIterator) 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(LoopringDeposited) + 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(LoopringDeposited) + 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 *LoopringDepositedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *LoopringDepositedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// LoopringDeposited represents a Deposited event raised by the Loopring contract. +type LoopringDeposited struct { + From common.Address + To common.Address + Token common.Address + Amount *big.Int + Duration *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterDeposited is a free log retrieval operation binding the contract event 0xe3683a3633d7c4dea824891208cc5661856f1c9441073cd1a0b999e189c8bb41. +// +// Solidity: event Deposited(address from, address to, address token, uint96 amount, uint256 duration) +func (_Loopring *LoopringFilterer) FilterDeposited(opts *bind.FilterOpts) (*LoopringDepositedIterator, error) { + + logs, sub, err := _Loopring.contract.FilterLogs(opts, "Deposited") + if err != nil { + return nil, err + } + return &LoopringDepositedIterator{contract: _Loopring.contract, event: "Deposited", logs: logs, sub: sub}, nil +} + +// WatchDeposited is a free log subscription operation binding the contract event 0xe3683a3633d7c4dea824891208cc5661856f1c9441073cd1a0b999e189c8bb41. +// +// Solidity: event Deposited(address from, address to, address token, uint96 amount, uint256 duration) +func (_Loopring *LoopringFilterer) WatchDeposited(opts *bind.WatchOpts, sink chan<- *LoopringDeposited) (event.Subscription, error) { + + logs, sub, err := _Loopring.contract.WatchLogs(opts, "Deposited") + 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(LoopringDeposited) + if err := _Loopring.contract.UnpackLog(event, "Deposited", 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 +} + +// ParseDeposited is a log parse operation binding the contract event 0xe3683a3633d7c4dea824891208cc5661856f1c9441073cd1a0b999e189c8bb41. +// +// Solidity: event Deposited(address from, address to, address token, uint96 amount, uint256 duration) +func (_Loopring *LoopringFilterer) ParseDeposited(log types.Log) (*LoopringDeposited, error) { + event := new(LoopringDeposited) + if err := _Loopring.contract.UnpackLog(event, "Deposited", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +}