@@ -83,14 +83,30 @@ const (
8383)
8484
8585type BatchCompact struct {
86- Arbiter common.Address
87- Sponsor common.Address
88- Nonce * big.Int
89- Expires * big.Int
90- Commitments []Lock
86+ Arbiter common.Address
87+ Sponsor common.Address
88+ Nonce * big.Int
89+ Expires * big.Int
90+ IdsAndAmounts [][2 ]* big.Int
91+ Mandate Mandate
9192}
9293
93- const LOCK_TYPEHASH = "fb7744571d97aa61eb9c2bc3c67b9b1ba047ac9e95afb2ef02bc5b3d9e64fbe5"
94+ type Mandate struct {
95+ FillDeadline uint32
96+ LocalOracle common.Address
97+ OutputDescription []Output
98+ }
99+
100+ type Output struct {
101+ Oracle common.Hash
102+ Settler common.Hash
103+ ChainId * big.Int
104+ Token common.Hash
105+ Amount * big.Int
106+ Recipient common.Hash
107+ Call []byte
108+ Context []byte
109+ }
94110
95111// VerifyCompactSignature verifies that the signature over the compact digest was made by the signer
96112func VerifyCompactSignature (digest []byte , signature []byte , signer common.Address ) (bool , error ) {
@@ -121,17 +137,28 @@ func GenerateCompactDigest(chainId *big.Int, verifyingContract common.Address, o
121137 {Name : "chainId" , Type : "uint256" },
122138 {Name : "verifyingContract" , Type : "address" },
123139 },
124- "Lock" : []apitypes.Type {
125- {Name : "lockTag" , Type : "bytes12" },
126- {Name : "token" , Type : "address" },
140+ "OutputDescription" : []apitypes.Type {
141+ {Name : "oracle" , Type : "bytes32" },
142+ {Name : "settler" , Type : "bytes32" },
143+ {Name : "token" , Type : "bytes32" },
144+ {Name : "recipient" , Type : "bytes32" },
145+ {Name : "call" , Type : "bytes" },
146+ {Name : "context" , Type : "bytes" },
147+ {Name : "chainId" , Type : "uint256" },
127148 {Name : "amount" , Type : "uint256" },
128149 },
150+ "Mandate" : []apitypes.Type {
151+ {Name : "fillDeadline" , Type : "uint32" },
152+ {Name : "localOracle" , Type : "address" },
153+ {Name : "outputs" , Type : "OutputDescription[]" },
154+ },
129155 "BatchCompact" : []apitypes.Type {
130156 {Name : "arbiter" , Type : "address" },
131157 {Name : "sponsor" , Type : "address" },
132158 {Name : "nonce" , Type : "uint256" },
133159 {Name : "expires" , Type : "uint256" },
134- {Name : "commitments" , Type : "Lock[]" },
160+ {Name : "idsAndAmounts" , Type : "uint256[2][]" },
161+ {Name : "mandate" , Type : "Mandate" },
135162 },
136163 }
137164
@@ -163,48 +190,110 @@ func GenerateCompactDigest(chainId *big.Int, verifyingContract common.Address, o
163190}
164191
165192func batchCompactToMessage (b BatchCompact ) map [string ]interface {} {
166- commitments := make ([]map [string ]interface {}, len (b .Commitments ))
167- for i , lock := range b .Commitments {
168- commitments [i ] = lockToMap (lock )
193+ outputs := make ([]map [string ]interface {}, len (b .Mandate .OutputDescription ))
194+ for i , o := range b .Mandate .OutputDescription {
195+ outputs [i ] = outputToMap (o )
196+ }
197+
198+ mandate := map [string ]interface {}{
199+ "fillDeadline" : new (big.Int ).SetUint64 (uint64 (b .Mandate .FillDeadline )),
200+ "localOracle" : b .Mandate .LocalOracle .Hex (),
201+ "outputs" : outputs ,
169202 }
170203
171204 return map [string ]interface {}{
172- "arbiter" : b .Arbiter .Hex (),
173- "sponsor" : b .Sponsor .Hex (),
174- "nonce" : b .Nonce .String (),
175- "expires" : b .Expires .String (),
176- "commitments" : commitments ,
205+ "arbiter" : b .Arbiter .Hex (),
206+ "sponsor" : b .Sponsor .Hex (),
207+ "nonce" : b .Nonce .String (),
208+ "expires" : b .Expires .String (),
209+ "mandate" : mandate ,
210+ "idsAndAmounts" : idsAndAmountsToInterface (b .IdsAndAmounts ),
177211 }
178212}
179213
180- func lockToMap ( lock Lock ) map [string ]interface {} {
214+ func outputToMap ( output Output ) map [string ]interface {} {
181215 return map [string ]interface {}{
182- "lockTag" : "0x" + hex .EncodeToString (lock .LockTag [:]),
183- "token" : lock .Token .Hex (),
184- "amount" : lock .Amount .String (),
216+ "oracle" : output .Oracle .Hex (),
217+ "settler" : output .Oracle .Hex (),
218+ "token" : output .Token .Hex (),
219+ "recipient" : output .Recipient .Hex (),
220+ "call" : "0x" + hex .EncodeToString (output .Call ),
221+ "context" : "0x" + hex .EncodeToString (output .Context ),
222+ "chainId" : output .ChainId ,
223+ "amount" : output .Amount ,
185224 }
186225}
187226
227+ func idsAndAmountsToInterface (idsAndAmounts [][2 ]* big.Int ) []interface {} {
228+ ids := (make ([]interface {}, len (idsAndAmounts )))
229+ for i , amounts := range idsAndAmounts {
230+ ids [i ] = []interface {}{amounts [0 ], amounts [1 ]}
231+ }
232+ return ids
233+ }
234+
188235// convertLifiOrderToBatchCompact calculates the EIP712 BatchCompact from the lifi order
189236func convertLifiOrderToBatchCompact (lifiOrder LifiOrder ) (* BatchCompact , error ) {
190- commitments , err := extractCommitments (lifiOrder .Order .Inputs )
237+ idsAndAmounts := make ([][2 ]* big.Int , len (lifiOrder .Order .Inputs ))
238+ for i , idAndAmount := range lifiOrder .Order .Inputs {
239+ idsAndAmounts [i ][0 ] = idAndAmount [0 ].Int
240+ idsAndAmounts [i ][1 ] = idAndAmount [1 ].Int
241+
242+ }
243+
244+ outputs , err := extractOutputs (lifiOrder .Order .Outputs )
191245 if err != nil {
192246 return nil , err
193247 }
194248
195- sponsor := common .HexToAddress (lifiOrder .Order .User )
196- arbiter := common .HexToAddress (lifiOrder .Order .LocalOracle )
197-
198249 return & BatchCompact {
199- Arbiter : arbiter ,
200- Sponsor : sponsor ,
201- Nonce : lifiOrder .Order .Nonce .Int ,
202- Expires : big .NewInt (lifiOrder .Order .Expires ),
203- Commitments : commitments ,
250+ // TODO: arbiter
251+ Arbiter : common .HexToAddress (lifiOrder .Order .LocalOracle ),
252+ Sponsor : common .HexToAddress (lifiOrder .Order .User ),
253+ Nonce : lifiOrder .Order .Nonce .Int ,
254+ Expires : big .NewInt (lifiOrder .Order .Expires ),
255+ IdsAndAmounts : idsAndAmounts ,
256+ Mandate : Mandate {
257+ FillDeadline : uint32 (lifiOrder .Order .FillDeadline ),
258+ LocalOracle : common .HexToAddress (lifiOrder .Order .LocalOracle ),
259+ OutputDescription : outputs ,
260+ },
204261 }, nil
205262}
206263
207- func extractCommitments (idsAndAmounts [][2 ]* BigInt ) ([]Lock , error ) {
264+ func extractOutputs (mandateOutputs []MandateOutput ) ([]Output , error ) {
265+ outputs := make ([]Output , len (mandateOutputs ))
266+ for i , output := range mandateOutputs {
267+ chainID , ok := new (big.Int ).SetString (output .ChainID , 10 )
268+ if ! ok {
269+ return outputs , fmt .Errorf ("failed parsing chainID" )
270+ }
271+
272+ call , err := hex .DecodeString (output .Call [2 :])
273+ if err != nil {
274+ return outputs , err
275+ }
276+
277+ context , err := hex .DecodeString (output .Context [2 :])
278+ if err != nil {
279+ return outputs , err
280+ }
281+
282+ outputs [i ] = Output {
283+ Oracle : common .HexToHash (output .Oracle ),
284+ Settler : common .HexToHash (output .Settler ),
285+ ChainId : chainID ,
286+ Token : common .HexToHash (output .Token ),
287+ Amount : output .Amount .Int ,
288+ Recipient : common .HexToHash (output .Recipient ),
289+ Call : call ,
290+ Context : context ,
291+ }
292+ }
293+ return outputs , nil
294+ }
295+
296+ func ExtractLocks (idsAndAmounts [][2 ]* BigInt ) ([]Lock , error ) {
208297 locks := make ([]Lock , len (idsAndAmounts ))
209298
210299 for i , idsAndAmount := range idsAndAmounts {
0 commit comments