Skip to content

Commit bb461f8

Browse files
committed
Updating example to pull signature data from creator address endpoint
1 parent 17706d1 commit bb461f8

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

sdk-clients/orderbook/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (api *api) CreateOrder(ctx context.Context, params CreateOrderParams) (*Cre
5151
// TODO Reusing the same request/response objects until the openapi spec is updated to include the correct object definitions
5252

5353
// GetOrdersByCreatorAddress returns all orders created by a given address in the Limit Order Protocol
54-
func (api *api) GetOrdersByCreatorAddress(ctx context.Context, params GetOrdersByCreatorAddressParams) ([]OrderResponse, error) {
54+
func (api *api) GetOrdersByCreatorAddress(ctx context.Context, params GetOrdersByCreatorAddressParams) ([]*OrderResponse, error) {
5555
u := fmt.Sprintf("/orderbook/v4.0/%d/address/%s", api.chainId, params.CreatorAddress)
5656

5757
err := params.Validate()
@@ -65,7 +65,7 @@ func (api *api) GetOrdersByCreatorAddress(ctx context.Context, params GetOrdersB
6565
U: u,
6666
}
6767

68-
var ordersResponse []OrderResponse
68+
var ordersResponse []*OrderResponse
6969
err = api.httpExecutor.ExecuteRequest(ctx, payload, &ordersResponse)
7070
if err != nil {
7171
return nil, err

sdk-clients/orderbook/examples/create_and_fill_order/main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,19 @@ func main() {
9191
// Sleep to accommodate free-tier API keys
9292
time.Sleep(time.Second)
9393

94-
getOrderResponse, err := client.GetOrdersByCreatorAddress(ctx, orderbook.GetOrdersByCreatorAddressParams{
94+
ordersByCreatorResponse, err := client.GetOrdersByCreatorAddress(ctx, orderbook.GetOrdersByCreatorAddressParams{
9595
CreatorAddress: client.Wallet.Address().Hex(),
9696
})
9797

98-
fmt.Printf("Order created! \nOrder hash: %v\n", getOrderResponse[0].OrderHash)
98+
fmt.Printf("Order created! \nOrder hash: %v\n", ordersByCreatorResponse[0].OrderHash)
9999

100100
// Sleep to accommodate free-tier API keys
101101
time.Sleep(time.Second)
102102

103-
getOrderRresponse, err := client.GetOrder(ctx, orderbook.GetOrderParams{
104-
OrderHash: getOrderResponse[0].OrderHash,
105-
})
106-
107-
fillOrderData, err := client.GetFillOrderCalldata(getOrderRresponse, nil)
103+
fillOrderData, err := client.GetFillOrderCalldata(ordersByCreatorResponse[0], nil)
104+
if err != nil {
105+
log.Fatalf("Failed to get fill order calldata: %v", err)
106+
}
108107

109108
aggregationRouter, err := constants.Get1inchRouterFromChainId(chainId)
110109
if err != nil {

sdk-clients/orderbook/normalization.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,48 @@ func NormalizeGetOrderByHashResponse(resp *GetOrderByHashResponse) (*GetOrderByH
5050
}, nil
5151
}
5252

53+
func NormalizeOrderResponse(resp *OrderResponse) (*OrderResponseExtended, error) {
54+
saltBigInt, ok := new(big.Int).SetString(resp.Data.Salt, 10)
55+
if !ok {
56+
saltBigInt, ok = new(big.Int).SetString(resp.Data.Salt[2:], 16)
57+
if !ok {
58+
return nil, fmt.Errorf("invalid salt value")
59+
}
60+
}
61+
makingAmountBigInt, ok := new(big.Int).SetString(resp.Data.MakingAmount, 10)
62+
if !ok {
63+
return nil, fmt.Errorf("invalid making amount value")
64+
}
65+
takingAmountBigInt, ok := new(big.Int).SetString(resp.Data.TakingAmount, 10)
66+
if !ok {
67+
return nil, fmt.Errorf("invalid taking amount value")
68+
}
69+
70+
makerAssetBigInt := AddressStringToBigInt(resp.Data.MakerAsset)
71+
takerAssetBigInt := AddressStringToBigInt(resp.Data.TakerAsset)
72+
makerBigInt := AddressStringToBigInt(resp.Data.Maker)
73+
receiverBigInt := AddressStringToBigInt(resp.Data.Receiver)
74+
75+
makerTraits, err := hexutil.DecodeBig(resp.Data.MakerTraits)
76+
if err != nil {
77+
return nil, fmt.Errorf("invalid maker traits value")
78+
}
79+
80+
return &OrderResponseExtended{
81+
OrderResponse: *resp,
82+
LimitOrderDataNormalized: NormalizedLimitOrderData{
83+
Salt: saltBigInt,
84+
MakerAsset: makerAssetBigInt,
85+
TakerAsset: takerAssetBigInt,
86+
Maker: makerBigInt,
87+
Receiver: receiverBigInt,
88+
MakingAmount: makingAmountBigInt,
89+
TakingAmount: takingAmountBigInt,
90+
MakerTraits: makerTraits,
91+
},
92+
}, nil
93+
}
94+
5395
func AddressStringToBigInt(addressString string) *big.Int {
5496
address := common.HexToAddress(addressString)
5597
addressBytes := new(big.Int).SetBytes(address.Bytes())

sdk-clients/orderbook/orderbook_types_manual.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ type OrderResponse struct {
9292
OrderInvalidReason interface{} `json:"orderInvalidReason"`
9393
}
9494

95+
type OrderResponseExtended struct {
96+
OrderResponse
97+
LimitOrderDataNormalized NormalizedLimitOrderData
98+
}
99+
95100
type GetOrderByHashResponse struct {
96101
ID int `json:"id"`
97102
OrderHash string `json:"orderHash"`
@@ -101,7 +106,6 @@ type GetOrderByHashResponse struct {
101106
MakerAsset string `json:"makerAsset"`
102107
OrderMaker string `json:"orderMaker"`
103108
OrderStatus int `json:"orderStatus"`
104-
Signature string `json:"signature"`
105109
MakerAmount string `json:"makerAmount"`
106110
RemainingMakerAmount string `json:"remainingMakerAmount"`
107111
MakerBalance string `json:"makerBalance"`

sdk-clients/orderbook/web3data.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ func (c *Client) GetSeriesNonce(ctx context.Context, publicAddress gethCommon.Ad
3939
return nonce, nil
4040
}
4141

42-
func (c *Client) GetFillOrderCalldata(getOrderResponse *GetOrderByHashResponseExtended, takerTraits *TakerTraits) ([]byte, error) {
42+
func (c *Client) GetFillOrderCalldata(orderResponse *OrderResponse, takerTraits *TakerTraits) ([]byte, error) {
43+
44+
orderResponseExtended, err := NormalizeOrderResponse(orderResponse)
45+
if err != nil {
46+
return nil, err
47+
}
4348

4449
var function string
45-
if getOrderResponse.Data.Extension == "0x" {
50+
if orderResponseExtended.Data.Extension == "0x" {
4651
function = "fillOrder"
4752
} else {
4853
if takerTraits == nil {
@@ -52,7 +57,7 @@ func (c *Client) GetFillOrderCalldata(getOrderResponse *GetOrderByHashResponseEx
5257
function = "fillOrderArgs"
5358
}
5459

55-
compressedSignature, err := CompressSignature(getOrderResponse.Signature[2:])
60+
compressedSignature, err := CompressSignature(orderResponseExtended.Signature[2:])
5661
if err != nil {
5762
return nil, err
5863
}
@@ -71,13 +76,13 @@ func (c *Client) GetFillOrderCalldata(getOrderResponse *GetOrderByHashResponseEx
7176

7277
switch function {
7378
case "fillOrder":
74-
fillOrderData, err = c.AggregationRouterV6.Pack(function, getOrderResponse.LimitOrderDataNormalized, rCompressed, vsCompressed, getOrderResponse.LimitOrderDataNormalized.TakingAmount, big.NewInt(0))
79+
fillOrderData, err = c.AggregationRouterV6.Pack(function, orderResponseExtended.LimitOrderDataNormalized, rCompressed, vsCompressed, orderResponseExtended.LimitOrderDataNormalized.TakingAmount, big.NewInt(0))
7580
if err != nil {
7681
return nil, err
7782
}
7883
case "fillOrderArgs":
7984
takerTraitsEncoded := takerTraits.Encode()
80-
fillOrderData, err = c.AggregationRouterV6.Pack(function, getOrderResponse.LimitOrderDataNormalized, rCompressed, vsCompressed, getOrderResponse.LimitOrderDataNormalized.TakingAmount, takerTraitsEncoded.TraitFlags, takerTraitsEncoded.Args)
85+
fillOrderData, err = c.AggregationRouterV6.Pack(function, orderResponseExtended.LimitOrderDataNormalized, rCompressed, vsCompressed, orderResponseExtended.LimitOrderDataNormalized.TakingAmount, takerTraitsEncoded.TraitFlags, takerTraitsEncoded.Args)
8186
if err != nil {
8287
return nil, err
8388
}

0 commit comments

Comments
 (0)