diff --git a/pkg/innerring/invoke/balance.go b/pkg/innerring/invoke/balance.go index 9c531388..41465a83 100644 --- a/pkg/innerring/invoke/balance.go +++ b/pkg/innerring/invoke/balance.go @@ -22,11 +22,20 @@ type ( Amount int64 // in Fixed16 Until uint64 // epochs } + + // MintBurnParams for Mint and Burn invocations. + MintBurnParams struct { + ScriptHash []byte + Amount int64 // in Fixed16 + Comment []byte + } ) const ( transferXMethod = "transferX" lockMethod = "lock" + mintMethod = "mint" + burnMethod = "burn" ) // TransferBalanceX invokes transferX method. @@ -43,6 +52,32 @@ func TransferBalanceX(cli *client.Client, con util.Uint160, p *TransferXParams) ) } +// Mint assets in contract. +func Mint(cli *client.Client, con util.Uint160, p *MintBurnParams) error { + if cli == nil { + return client.ErrNilClient + } + + return cli.Invoke(con, extraFee, mintMethod, + p.ScriptHash, + p.Amount, + p.Comment, + ) +} + +// Burn minted assets. +func Burn(cli *client.Client, con util.Uint160, p *MintBurnParams) error { + if cli == nil { + return client.ErrNilClient + } + + return cli.Invoke(con, extraFee, burnMethod, + p.ScriptHash, + p.Amount, + p.Comment, + ) +} + // LockAsset invokes Lock method. func LockAsset(cli *client.Client, con util.Uint160, p *LockParams) error { if cli == nil { diff --git a/pkg/innerring/processors/neofs/process_assets.go b/pkg/innerring/processors/neofs/process_assets.go index 5a126604..52e43da4 100644 --- a/pkg/innerring/processors/neofs/process_assets.go +++ b/pkg/innerring/processors/neofs/process_assets.go @@ -15,11 +15,6 @@ const ( lockAccountLifetime uint64 = 20 ) -var ( - // fedReserveAddr is a special account in balance contract. - fedReserveAddr = []byte{0x0F, 0xED} -) - // Process deposit event by invoking balance contract and sending native // gas in morph chain. func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) { @@ -29,12 +24,11 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) { } // send transferX to balance contract - err := invoke.TransferBalanceX(np.morphClient, np.balanceContract, - &invoke.TransferXParams{ - Sender: fedReserveAddr, - Receiver: deposit.To().BytesBE(), - Amount: deposit.Amount() * 1_0000_0000, // from Fixed8 to Fixed16 - Comment: append([]byte(txLogPrefix), deposit.ID()...), + err := invoke.Mint(np.morphClient, np.balanceContract, + &invoke.MintBurnParams{ + ScriptHash: deposit.To().BytesBE(), + Amount: deposit.Amount() * 1_0000_0000, // from Fixed8 to Fixed16 + Comment: append([]byte(txLogPrefix), deposit.ID()...), }) if err != nil { np.log.Error("can't transfer assets to balance contract", zap.Error(err)) @@ -91,12 +85,11 @@ func (np *Processor) processCheque(cheque *neofsEvent.Cheque) { return } - err := invoke.TransferBalanceX(np.morphClient, np.balanceContract, - &invoke.TransferXParams{ - Sender: cheque.LockAccount().BytesBE(), - Receiver: fedReserveAddr, - Amount: cheque.Amount() * 1_0000_0000, // from Fixed8 to Fixed16 - Comment: append([]byte(txLogPrefix), cheque.ID()...), + err := invoke.Burn(np.morphClient, np.balanceContract, + &invoke.MintBurnParams{ + ScriptHash: cheque.LockAccount().BytesBE(), + Amount: cheque.Amount() * 1_0000_0000, // from Fixed8 to Fixed16 + Comment: append([]byte(txLogPrefix), cheque.ID()...), }) if err != nil { np.log.Error("can't transfer assets to fed contract", zap.Error(err))