Skip to content

Commit

Permalink
bitgo optimizations (#10)
Browse files Browse the repository at this point in the history
* first pass

* most likely final pass
  • Loading branch information
emmanueldenloye authored Feb 5, 2021
1 parent 10d3eda commit 37b7e82
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
7 changes: 5 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ import qualified Tezos.Address as Tezos
import qualified Tezos.Core as Core (parseTimestamp)
import Lorentz (Timestamp, ToT, IsoValue)
import qualified Lorentz as L
import Lorentz.Run
import Util.IO (hSetTranslit, writeFileUtf8)
import Universum.Print
import Universum.String
import Universum.Lifted
import Universum.Exception

import Michelson.Printer
import Michelson.TypeCheck
import Michelson.Typed.Instr (FullContract(..))
import Michelson.Typed.Scope
Expand Down Expand Up @@ -315,9 +317,11 @@ main = do
fa12ContractAddr'
PrintSpecializedAnyFA12 centralWalletAddr' mOutput forceOneline ->
writeFunc mOutput $
L.printLorentzContract
printTypedFullContract
forceOneline $
compileLorentzContractWithOptions (CompilationOptions { coDisableInitialCast = True }) $
Specialized.specializedAnyForwarderContract centralWalletAddr'
--
PrintSpecializedAnyTezFA12 centralWalletAddr' mOutput forceOneline ->
writeFunc mOutput $
L.printLorentzContract
Expand All @@ -332,4 +336,3 @@ main = do
writeFunc mOutput $
L.printLorentzValue True $
Specialized.mkParameter amountToFlush tokenContract

27 changes: 13 additions & 14 deletions src/Lorentz/Contracts/Forwarder/Specialized/FlushAny.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import Lorentz.Base (SomeContract(..))
import Michelson.Analyzer (AnalyzerRes)
import Michelson.Typed.EntryPoints

import Lorentz.Contracts.Spec.AbstractLedgerInterface (TransferParams)
import qualified Lorentz.Contracts.Spec.AbstractLedgerInterface as AL
import qualified Lorentz.Contracts.Forwarder.Specialized as Specialized

Expand All @@ -39,6 +38,7 @@ import Prelude (Show(..), Enum(..), Eq(..), ($), String, show)

import Michelson.Typed.Value.Orphans ()

type TransferParams = (Address,Address,Natural)

-- | The number of sub-tokens to forward and the typed contract address of the
-- token to forward it on
Expand Down Expand Up @@ -104,26 +104,25 @@ toTransferParameter = do
pair
forcedCoerce_ @(Address, (Address, Natural)) @TransferParams

-- | Run a transfer to the given central wallet `Address`, given the token
-- contract `Address` and the number of tokens to transfer
runSpecializedAnyTransfer :: Address -> (Natural & ContractRef TransferParams & s) :-> (Operation & s)
runSpecializedAnyTransfer centralWalletAddr' = do
push centralWalletAddr'
toTransferParameter
dip . push $ toEnum @Mutez 0
transferTokens

-- | Forwarder contract: forwards the given number of sub-tokens
-- from its own address to the central wallet.
specializedAnyForwarderContract :: Address -> ContractCode Parameter Storage
specializedAnyForwarderContract centralWalletAddr' = do
car
unParameter
unpair
runSpecializedAnyTransfer centralWalletAddr'
dip nil
dup
car
dip $ do
cdr
push $ toEnum @Mutez 0
push centralWalletAddr'
toTransferParameter
transferTokens @TransferParams
nil
swap
cons
dip unit
unit
swap
pair

-- | `analyzeLorentz` specialized to the `specializedAnyForwarderContract`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ runSpecializedAnyTezTransfer centralWalletAddr' = do
ifNone nil $ do
dip dup
FlushAny.unParameter
unpair
dup
car
dip cdr
dig @2
FlushAny.toTransferParameter
dip . push $ toEnum @Mutez 0
Expand Down Expand Up @@ -128,4 +130,3 @@ verifyForwarderContract centralWalletAddr' (SomeContract (contract' :: ContractC
forceOneline
(specializedAnyFA12ForwarderContract
centralWalletAddr')

7 changes: 4 additions & 3 deletions src/Lorentz/Contracts/Forwarder/Specialized/FlushAny/Tez.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import Lorentz.Base (SomeContract(..))
import Michelson.Analyzer (AnalyzerRes)
import Michelson.Text

import Lorentz.Contracts.Spec.AbstractLedgerInterface (TransferParams)
import Lorentz.Contracts.Forwarder.Specialized.FlushAny (Parameter(..))
import qualified Lorentz.Contracts.Forwarder.Specialized as Specialized
import Lorentz.Contracts.Forwarder.Specialized.FlushAny (TransferParams)
import qualified Lorentz.Contracts.Forwarder.Specialized.FlushAny as FlushAny

import Data.Type.Equality
Expand Down Expand Up @@ -81,7 +81,9 @@ specializedAnyTezForwarderContract :: Address -> ContractCode Parameter Storage
specializedAnyTezForwarderContract centralWalletAddr' = do
car
FlushAny.unParameter
unpair
dup
car
dip cdr
runSpecializedAnyTezTransfer centralWalletAddr'
dip unit
pair
Expand Down Expand Up @@ -115,4 +117,3 @@ verifyForwarderContract centralWalletAddr' (SomeContract (contract' :: ContractC
forceOneline
(specializedAnyTezForwarderContract
centralWalletAddr')

0 comments on commit 37b7e82

Please sign in to comment.