From ba015d78bc597c202fab3941f3c79beec53b2397 Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Tue, 13 Dec 2022 18:05:02 +1100 Subject: [PATCH 1/4] Fix for "readonly" bug when DLOB tries to update nodelist with new events --- sdk/src/dlob/DLOB.ts | 8 ++++++-- sdk/src/dlob/NodeList.ts | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sdk/src/dlob/DLOB.ts b/sdk/src/dlob/DLOB.ts index 97172ad27..0bbfd6313 100644 --- a/sdk/src/dlob/DLOB.ts +++ b/sdk/src/dlob/DLOB.ts @@ -270,8 +270,12 @@ export class DLOB { return; } - order.baseAssetAmountFilled = cumulativeBaseAssetAmountFilled; - this.getListForOrder(order)?.update(order, userAccount); + const newOrder = { + ...order, + baseAssetAmountFilled: cumulativeBaseAssetAmountFilled, + }; + + this.getListForOrder(order)?.update(newOrder, userAccount); if (onUpdate) { onUpdate(); diff --git a/sdk/src/dlob/NodeList.ts b/sdk/src/dlob/NodeList.ts index caef2fc18..3010d16e9 100644 --- a/sdk/src/dlob/NodeList.ts +++ b/sdk/src/dlob/NodeList.ts @@ -105,8 +105,14 @@ export class NodeList const orderId = getOrderSignature(order.orderId, userAccount); if (this.nodeMap.has(orderId)) { const node = this.nodeMap.get(orderId); - Object.assign(node.order, order); - node.haveFilled = false; + + const newNode = { + ...node, + ...order, + haveFilled: false, + }; + + this.nodeMap.set(orderId, newNode); } } From 0458c9655dfcc14f547b655ae0aff31d4cdfde88 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 13 Dec 2022 13:30:11 -0500 Subject: [PATCH 2/4] fix test --- sdk/src/dlob/NodeList.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sdk/src/dlob/NodeList.ts b/sdk/src/dlob/NodeList.ts index 3010d16e9..caef2fc18 100644 --- a/sdk/src/dlob/NodeList.ts +++ b/sdk/src/dlob/NodeList.ts @@ -105,14 +105,8 @@ export class NodeList const orderId = getOrderSignature(order.orderId, userAccount); if (this.nodeMap.has(orderId)) { const node = this.nodeMap.get(orderId); - - const newNode = { - ...node, - ...order, - haveFilled: false, - }; - - this.nodeMap.set(orderId, newNode); + Object.assign(node.order, order); + node.haveFilled = false; } } From 9139aa8df448202abd5aa23ca9b340effaaea1a1 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 13 Dec 2022 13:32:36 -0500 Subject: [PATCH 3/4] have updateOrder match other update order implementations --- sdk/src/dlob/DLOB.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/dlob/DLOB.ts b/sdk/src/dlob/DLOB.ts index 0bbfd6313..2a1de0701 100644 --- a/sdk/src/dlob/DLOB.ts +++ b/sdk/src/dlob/DLOB.ts @@ -272,8 +272,8 @@ export class DLOB { const newOrder = { ...order, - baseAssetAmountFilled: cumulativeBaseAssetAmountFilled, }; + newOrder.baseAssetAmountFilled = cumulativeBaseAssetAmountFilled; this.getListForOrder(order)?.update(newOrder, userAccount); From 6f2fa3c35ab597e344caf4520cf0ddcf6131f4d1 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 13 Dec 2022 13:35:59 -0500 Subject: [PATCH 4/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2cee2d7..614bdbe77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes +- ts-sdk: fix DLOB.updateOrder ([#290](https://github.com/drift-labs/protocol-v2/pull/290)) - ts-sdk: make calculateClaimablePnl mirror on-chain logic ([#291](https://github.com/drift-labs/protocol-v2/pull/291)) - ts-sdk: add margin trading toggle field to user accounts, update toggle margin trading function to add ability to toggle for any subaccount rather than just the active ([#285](https://github.com/drift-labs/protocol-v2/pull/285))