From a41a82e57ad7df90a8041f1b0070faf536e41eb8 Mon Sep 17 00:00:00 2001 From: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:05:56 +0200 Subject: [PATCH] ts: upgrade anchor (#735) * ts: upgrade anchor Signed-off-by: microwavedcola1 * Fixes from review Signed-off-by: microwavedcola1 --------- Signed-off-by: microwavedcola1 (cherry picked from commit e0b4bd12364b59d9eafbff67f10797a8d3281756) --- package.json | 5 ++- ts/client/scripts/mm/market-maker.ts | 2 +- ts/client/src/accounts/mangoAccount.ts | 23 +++++++--- ts/client/src/accounts/perp.ts | 59 +++++++++++++++++--------- ts/client/src/accounts/serum3.ts | 36 +++++++++++----- ts/client/src/types.ts | 10 +++-- yarn.lock | 20 ++++----- 7 files changed, 100 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index 675344e69..36fd6fce9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,8 @@ "trailingComma": "all" }, "dependencies": { - "@coral-xyz/anchor": "^0.27.0", + "@blockworks-foundation/mango-v4-settings": "^0.2.15", + "@coral-xyz/anchor": "^0.28.1-beta.2", "@project-serum/serum": "0.13.65", "@pythnetwork/client": "~2.14.0", "@solana/spl-token": "0.3.7", @@ -74,7 +75,7 @@ "node-kraken-api": "^2.2.2" }, "resolutions": { - "@coral-xyz/anchor": "^0.27.0", + "@coral-xyz/anchor": "^0.28.1-beta.2", "**/@solana/web3.js/node-fetch": "npm:@blockworks-foundation/node-fetch@2.6.11", "**/cross-fetch/node-fetch": "npm:@blockworks-foundation/node-fetch@2.6.11" }, diff --git a/ts/client/scripts/mm/market-maker.ts b/ts/client/scripts/mm/market-maker.ts index bcf2bb701..7b168c4c8 100644 --- a/ts/client/scripts/mm/market-maker.ts +++ b/ts/client/scripts/mm/market-maker.ts @@ -606,7 +606,7 @@ async function makeMarketUpdateInstructions( ); moveOrders = openOrders.length < 2 || openOrders.length > 2; for (const o of openOrders) { - const refPrice = o.side === 'buy' ? bookAdjBid : bookAdjAsk; + const refPrice = o.side === PerpOrderSide.bid ? bookAdjBid : bookAdjAsk; moveOrders = moveOrders || Math.abs(o.priceLots.toNumber() / refPrice.toNumber() - 1) > diff --git a/ts/client/src/accounts/mangoAccount.ts b/ts/client/src/accounts/mangoAccount.ts index 8c5727a32..80d797cc5 100644 --- a/ts/client/src/accounts/mangoAccount.ts +++ b/ts/client/src/accounts/mangoAccount.ts @@ -1776,15 +1776,24 @@ export class PerpOoDto { ) {} } -export class TokenConditionalSwapDisplayPriceStyle { - static sellTokenPerBuyToken = { sellTokenPerBuyToken: {} }; - static buyTokenPerSellToken = { buyTokenPerSellToken: {} }; +export type TokenConditionalSwapDisplayPriceStyle = + | { sellTokenPerBuyToken: Record } + | { buyTokenPerSellToken: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace TokenConditionalSwapDisplayPriceStyle { + export const sellTokenPerBuyToken = { sellTokenPerBuyToken: {} }; + export const buyTokenPerSellToken = { buyTokenPerSellToken: {} }; } -export class TokenConditionalSwapIntention { - static unknown = { unknown: {} }; - static stopLoss = { stopLoss: {} }; - static takeProfit = { takeProfit: {} }; +export type TokenConditionalSwapIntention = + | { unknown: Record } + | { stopLoss: Record } + | { takeProfit: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace TokenConditionalSwapIntention { + export const unknown = { unknown: {} }; + export const stopLoss = { stopLoss: {} }; + export const takeProfit = { takeProfit: {} }; } function tokenConditionalSwapIntentionFromDto( diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index 04e844e7e..eced1ce5f 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -646,11 +646,7 @@ export class BookSide { * iterates over all orders */ public *items(): Generator { - function isBetter( - type: PerpOrderSide, - a: PerpOrder, - b: PerpOrder, - ): boolean { + function isBetter(type: BookSideType, a: PerpOrder, b: PerpOrder): boolean { return a.priceLots.eq(b.priceLots) ? a.seqNum.lt(b.seqNum) // if prices are equal prefer perp orders in the order they are placed : type === BookSideType.bids // else compare the actual prices @@ -833,10 +829,15 @@ export class BookSide { } } -export class BookSideType { - static bids = { bids: {} }; - static asks = { asks: {} }; +export type BookSideType = + | { bids: Record } + | { asks: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace BookSideType { + export const bids = { bids: {} }; + export const asks = { asks: {} }; } + export class LeafNode { static from(obj: { ownerSlot: number; @@ -879,23 +880,39 @@ export class InnerNode { constructor(public children: [number]) {} } -export class PerpSelfTradeBehavior { - static decrementTake = { decrementTake: {} }; - static cancelProvide = { cancelProvide: {} }; - static abortTransaction = { abortTransaction: {} }; +export type PerpSelfTradeBehavior = + | { decrementTake: Record } + | { cancelProvide: Record } + | { abortTransaction: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace PerpSelfTradeBehavior { + export const decrementTake = { decrementTake: {} }; + export const cancelProvide = { cancelProvide: {} }; + export const abortTransaction = { abortTransaction: {} }; } -export class PerpOrderSide { - static bid = { bid: {} }; - static ask = { ask: {} }; +export type PerpOrderSide = + | { bid: Record } + | { ask: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace PerpOrderSide { + export const bid = { bid: {} }; + export const ask = { ask: {} }; } -export class PerpOrderType { - static limit = { limit: {} }; - static immediateOrCancel = { immediateOrCancel: {} }; - static postOnly = { postOnly: {} }; - static market = { market: {} }; - static postOnlySlide = { postOnlySlide: {} }; +export type PerpOrderType = + | { limit: Record } + | { immediateOrCancel: Record } + | { postOnly: Record } + | { market: Record } + | { postOnlySlide: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace PerpOrderType { + export const limit = { limit: {} }; + export const immediateOrCancel = { immediateOrCancel: {} }; + export const postOnly = { postOnly: {} }; + export const market = { market: {} }; + export const postOnlySlide = { postOnlySlide: {} }; } export class PerpOrder { diff --git a/ts/client/src/accounts/serum3.ts b/ts/client/src/accounts/serum3.ts index f888bc4fd..ef306589a 100644 --- a/ts/client/src/accounts/serum3.ts +++ b/ts/client/src/accounts/serum3.ts @@ -197,21 +197,35 @@ export class Serum3Market { } } -export class Serum3SelfTradeBehavior { - static decrementTake = { decrementTake: {} }; - static cancelProvide = { cancelProvide: {} }; - static abortTransaction = { abortTransaction: {} }; +export type Serum3OrderType = + | { limit: Record } + | { immediateOrCancel: Record } + | { postOnly: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace Serum3OrderType { + export const limit = { limit: {} }; + export const immediateOrCancel = { immediateOrCancel: {} }; + export const postOnly = { postOnly: {} }; } -export class Serum3OrderType { - static limit = { limit: {} }; - static immediateOrCancel = { immediateOrCancel: {} }; - static postOnly = { postOnly: {} }; +export type Serum3SelfTradeBehavior = + | { decrementTake: Record } + | { cancelProvide: Record } + | { abortTransaction: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace Serum3SelfTradeBehavior { + export const decrementTake = { decrementTake: {} }; + export const cancelProvide = { cancelProvide: {} }; + export const abortTransaction = { abortTransaction: {} }; } -export class Serum3Side { - static bid = { bid: {} }; - static ask = { ask: {} }; +export type Serum3Side = + | { bid: Record } + | { ask: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace Serum3Side { + export const bid = { bid: {} }; + export const ask = { ask: {} }; } export async function generateSerum3MarketExternalVaultSignerAddress( diff --git a/ts/client/src/types.ts b/ts/client/src/types.ts index f31b6d503..09d1b97f5 100644 --- a/ts/client/src/types.ts +++ b/ts/client/src/types.ts @@ -7,9 +7,13 @@ export class FlashLoanWithdraw { static amount: BN; } -export class FlashLoanType { - static unknown = { unknown: {} }; - static swap = { swap: {} }; +export type FlashLoanType = + | { unknown: Record } + | { swap: Record }; +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace FlashLoanType { + export const unknown = { unknown: {} }; + export const swap = { swap: {} }; } export class InterestRateParams { diff --git a/yarn.lock b/yarn.lock index 3655a61b3..108255f23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -35,12 +35,13 @@ resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ== -"@coral-xyz/anchor@^0.26.0", "@coral-xyz/anchor@^0.27.0": - version "0.27.0" - resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.27.0.tgz#621e5ef123d05811b97e49973b4ed7ede27c705c" - integrity sha512-+P/vPdORawvg3A9Wj02iquxb4T0C5m4P6aZBVYysKl4Amk+r6aMPZkUhilBkD6E4Nuxnoajv3CFykUfkGE0n5g== +"@coral-xyz/anchor@^0.26.0", "@coral-xyz/anchor@^0.28.1-beta.2": + version "0.28.1-beta.2" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.28.1-beta.2.tgz#4ddd4b2b66af04407be47cf9524147793ec514a0" + integrity sha512-xreUcOFF8+IQKWOBUrDKJbIw2ftpRVybFlEPVrbSlOBCbreCWrQ5754Gt9cHIcuBDAzearCDiBqzsGQdNgPJiw== dependencies: - "@coral-xyz/borsh" "^0.27.0" + "@coral-xyz/borsh" "^0.28.0" + "@noble/hashes" "^1.3.1" "@solana/web3.js" "^1.68.0" base64-js "^1.5.1" bn.js "^5.1.2" @@ -50,16 +51,15 @@ cross-fetch "^3.1.5" crypto-hash "^1.3.0" eventemitter3 "^4.0.7" - js-sha256 "^0.9.0" pako "^2.0.3" snake-case "^3.0.4" superstruct "^0.15.4" toml "^3.0.0" -"@coral-xyz/borsh@^0.27.0": - version "0.27.0" - resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.27.0.tgz#700c647ea5262b1488957ac7fb4e8acf72c72b63" - integrity sha512-tJKzhLukghTWPLy+n8K8iJKgBq1yLT/AxaNd10yJrX8mI56ao5+OFAKAqW/h0i79KCvb4BK0VGO5ECmmolFz9A== +"@coral-xyz/borsh@^0.28.0": + version "0.28.0" + resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.28.0.tgz#fa368a2f2475bbf6f828f4657f40a52102e02b6d" + integrity sha512-/u1VTzw7XooK7rqeD7JLUSwOyRSesPUk0U37BV9zK0axJc1q0nRbKFGFLYCQ16OtdOJTTwGfGp11Lx9B45bRCQ== dependencies: bn.js "^5.1.2" buffer-layout "^1.2.0"