Skip to content

Commit

Permalink
Add set interaction for taker traits 1inch limit order
Browse files Browse the repository at this point in the history
  • Loading branch information
hiepnv90 committed Nov 19, 2024
1 parent 42b43ce commit 0c93086
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/oneinch/limitorder/taker_traits.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (t *TakerTraits) SetExtension(ext Extension) *TakerTraits {
return t
}

// SetInteraction sets interaction, target should implement `ITakerInteraction` interface.
func (t *TakerTraits) SetInteraction(interaction Interaction) *TakerTraits {
t.interaction = &interaction
return t
}

func (t *TakerTraits) Encode() (*big.Int, []byte) {
var extension, interaction []byte
if t.extension != nil {
Expand Down
9 changes: 7 additions & 2 deletions pkg/oneinch/limitorder/taker_traits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ func TestEncodeTakerTraits(t *testing.T) {
PostInteraction: []byte{0x08},
CustomData: []byte{0xff},
}
interaction := Interaction{
Target: common.HexToAddress("0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"),
Data: hexutil.MustDecode("0xe21fd0e90000000000000000000000000000000000000000000000000000000000000020000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000005c00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000007a35a5dda7f50f471edfab96666a6b70a15440300000000000000000000000000000000000000000000000000000000673c4d6600000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040593611990000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000d4a11d5eeaac28ec3f61d100daf4d40471f1852000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000000000000000000000000000000b1a2bc2ec50000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000009b0000000000000000000000000947a2ff000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000007a35a5dda7f50f471edfab96666a6b70a15440300000000000000000000000000000000000000000000000000b1a2bc2ec50000000000000000000000000000000000000000000000000000000000000947662e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002297b22536f75726365223a226b7962657273776170222c22416d6f756e74496e555344223a223135362e3035373537303939333931353032222c22416d6f756e744f7574555344223a223135362e3035393237383337303335363235222c22526566657272616c223a22222c22466c616773223a302c22416d6f756e744f7574223a22313535363839373237222c2254696d657374616d70223a313733323030343032322c22496e74656772697479496e666f223a7b224b65794944223a2231222c225369676e6174757265223a22595841794f7670796a5569454847554e453139384d6d766f736d55673547525a462f7736546e4b5167666d503541696e5654484c5650495547533138437565436333736d4258766967574c656c39703258657a556a6a6f564c796866654263314e684b4465644848475558734e576d6a7673554f32496d4d50446a6446473835734b456869493243646b76342f6932626e4a72642f68394535654939716c30504f7076576d5753354f3344797a6a354c4e5a39436d7734696c783576652f304f7170593234384e70735a4d443243477374732f566c52493055514153344152386f30695a42626d546b47526554492f3643706d41712b4667324b33766f756e38666e3354734a557070656c67696f6442636469334865366c4a7a6e7538316247714647666a736a6f464346657264645874353632445a7a6154434139533030566572625a466470622b6f7a573378754b6a55316f71413d3d227d7d0000000000000000000000000000000000000000000000"),
}

takerTraits := NewDefaultTakerTraits()
takerTraits.SetExtension(extension).SetAmountMode(AmountModeMaker).SetAmountThreshold(big.NewInt(1))
takerTraits.SetInteraction(interaction)

encodedTakerTraits, args := takerTraits.Encode()
assert.Equal(t, common.HexToHash("0x8000002900000000000000000000000000000000000000000000000000000001").Big(), encodedTakerTraits)
assert.Equal(t, hexutil.Encode(extension.Encode()), hexutil.Encode(args))
assert.Equal(t, "0x8000002900085800000000000000000000000000000000000000000000000001", hexutil.Encode(encodedTakerTraits.Bytes()))
assert.Equal(t, hexutil.Encode(append(extension.Encode(), interaction.Encode()...)), hexutil.Encode(args))
}

0 comments on commit 0c93086

Please sign in to comment.