Skip to content

Commit

Permalink
Handle delayedEncode intent
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Oct 30, 2023
1 parent 8c74e7a commit a1bd2de
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 0 additions & 2 deletions intents/packets/delayed_abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/0xsequence/ethkit/ethcoder"
"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/davecgh/go-spew/spew"
)

type delayedEncodeType struct {
Expand Down Expand Up @@ -54,7 +53,6 @@ func EncodeDelayedABI(data *delayedEncodeType) (string, error) {
}

default:
spew.Dump(arg)
return "", fmt.Errorf("invalid arg type")
}
}
Expand Down
35 changes: 35 additions & 0 deletions intents/packets/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,41 @@ func (p *SendTransactionsPacket) ExpectedValuesFor(subpacket *json.RawMessage) (
Value: big.NewInt(0),
Data: encodedData,
}, nil

case "delayedEncode":
var subpacketDelayedEncodeType struct {
To string `json:"to"`
Value string `json:"value"`
Data json.RawMessage `json:"data"`
}

err := json.Unmarshal(*subpacket, &subpacketDelayedEncodeType)
if err != nil {
return nil, err
}

nst := &delayedEncodeType{}
err = json.Unmarshal(subpacketDelayedEncodeType.Data, nst)
if err != nil {
return nil, err
}

encoded, err := EncodeDelayedABI(nst)
if err != nil {
return nil, err
}

to := common.HexToAddress(subpacketDelayedEncodeType.To)
value, ok := sequence.ParseHexOrDec(subpacketDelayedEncodeType.Value)
if !ok {
return nil, fmt.Errorf("invalid value '%s'", subpacketDelayedEncodeType.Value)
}

return &ExpectedValuesForTransaction{
To: &to,
Value: value,
Data: common.FromHex(encoded),
}, nil
default:
return nil, fmt.Errorf("invalid subpacket type '%s'", subpacketType.Type)
}
Expand Down
35 changes: 33 additions & 2 deletions intents/packets/send_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,35 @@ func TestRecoverTransactionIntent(t *testing.T) {
}
],
"data": "0x223344"
},
{
"type": "delayedEncode",
"to": "0x140d72763D1ce39Ad4E2e73EC6e8FC53E5b73B64",
"value": "0",
"data": {
"abi": "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_orderId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_maxCost\",\"type\":\"uint256\"},{\"internalType\":\"address[]\",\"name\":\"_fees\",\"type\":\"address[]\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"fillOrKillOrder\",\"outputs\":[],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_val\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"_data\",\"type\":\"string\"}],\"name\":\"notExpired\",\"outputs\":[],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"otherMethods\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
"func": "fillOrKillOrder",
"args": [
"48774435471364917511246724398022004900255301025912680232738918790354204737320",
"1000000000000000000",
"[\"0x8541D65829f98f7D71A4655cCD7B2bB8494673bF\"]",
{
"abi": "notExpired(uint256,string)",
"func": "notExpired",
"args": [
"1600000000",
"Nov 1st, 2020"
]
}
]
}
}
]
},
"signatures": [
{
"session": "0x1111BD4F3233e7a7f552AdAf32C910fD30de598B",
"signature": "0x71a0d20a974e8a7cc3643c9ab0cf6f52bbeda20bf486449a6287c09c5f6c7d0a478a5ed8d0747f83c9a8851d9b87c05c1c74e28a0a3a428aef7b067c4bcbb1bb1b"
"signature": "0xfaf2c6af7a18344c4055d61c3475a6e2f43425961fa59bb6309a846ab582b0781016ec62d264eaa732136f9ad371a8da7e638105e1d1c3a9798f45da0807f9801c"
}
]
}`
Expand All @@ -74,7 +96,7 @@ func TestRecoverTransactionIntent(t *testing.T) {

hash, err := intent.Hash()
assert.Nil(t, err)
assert.Equal(t, common.Bytes2Hex(hash), "f7bbc2ad0d74cccdc1d6a8eae95f39f6f3f7d29f571e8ced744f626168913a00")
assert.Equal(t, common.Bytes2Hex(hash), "437629d2d86800f7d568ce8f1575cbcb6ec9b30cb3d661bc245fefc6a5f8cf7a")

signers := intent.Signers()
assert.Equal(t, 1, len(signers))
Expand Down Expand Up @@ -127,6 +149,15 @@ func TestRecoverTransactionIntent(t *testing.T) {
Data: common.FromHex("0x2eb2c2d6000000000000000000000000d67fc48b298b09ed3d03403d930769c527186c4e00000000000000000000000091e8ac543c5fedf9f3ef8b9da1500db84305681f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000032233440000000000000000000000000000000000000000000000000000000000"),
})

transactions = append(transactions, &sequence.Transaction{
DelegateCall: false,
RevertOnError: true,
GasLimit: big.NewInt(0),
To: common.HexToAddress("0x140d72763D1ce39Ad4E2e73EC6e8FC53E5b73B64"),
Value: big.NewInt(0),
Data: common.FromHex("0x6365f1646bd55a2877890bd58871eefe886770a7734077a74981910a75d7b1f044b5bf280000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008541d65829f98f7d71a4655ccd7b2bb8494673bf000000000000000000000000000000000000000000000000000000000000008446c421fa000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000d4e6f76203173742c20323032300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
})

bundle := sequence.Transaction{
Transactions: transactions,
Nonce: nonce,
Expand Down

0 comments on commit a1bd2de

Please sign in to comment.