Skip to content

Commit

Permalink
ts: upgrade anchor (#735)
Browse files Browse the repository at this point in the history
* ts: upgrade anchor

Signed-off-by: microwavedcola1 <[email protected]>

* Fixes from review

Signed-off-by: microwavedcola1 <[email protected]>

---------

Signed-off-by: microwavedcola1 <[email protected]>
(cherry picked from commit e0b4bd1)
  • Loading branch information
microwavedcola1 authored and ckamm committed Nov 2, 2023
1 parent 9edcff1 commit a41a82e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 55 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/[email protected]",
"**/cross-fetch/node-fetch": "npm:@blockworks-foundation/[email protected]"
},
Expand Down
2 changes: 1 addition & 1 deletion ts/client/scripts/mm/market-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) >
Expand Down
23 changes: 16 additions & 7 deletions ts/client/src/accounts/mangoAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1776,15 +1776,24 @@ export class PerpOoDto {
) {}
}

export class TokenConditionalSwapDisplayPriceStyle {
static sellTokenPerBuyToken = { sellTokenPerBuyToken: {} };
static buyTokenPerSellToken = { buyTokenPerSellToken: {} };
export type TokenConditionalSwapDisplayPriceStyle =
| { sellTokenPerBuyToken: Record<string, never> }
| { buyTokenPerSellToken: Record<string, never> };
// 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<string, never> }
| { stopLoss: Record<string, never> }
| { takeProfit: Record<string, never> };
// 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(
Expand Down
59 changes: 38 additions & 21 deletions ts/client/src/accounts/perp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,7 @@ export class BookSide {
* iterates over all orders
*/
public *items(): Generator<PerpOrder> {
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
Expand Down Expand Up @@ -833,10 +829,15 @@ export class BookSide {
}
}

export class BookSideType {
static bids = { bids: {} };
static asks = { asks: {} };
export type BookSideType =
| { bids: Record<string, never> }
| { asks: Record<string, never> };
// 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;
Expand Down Expand Up @@ -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<string, never> }
| { cancelProvide: Record<string, never> }
| { abortTransaction: Record<string, never> };
// 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<string, never> }
| { ask: Record<string, never> };
// 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<string, never> }
| { immediateOrCancel: Record<string, never> }
| { postOnly: Record<string, never> }
| { market: Record<string, never> }
| { postOnlySlide: Record<string, never> };
// 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 {
Expand Down
36 changes: 25 additions & 11 deletions ts/client/src/accounts/serum3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,35 @@ export class Serum3Market {
}
}

export class Serum3SelfTradeBehavior {
static decrementTake = { decrementTake: {} };
static cancelProvide = { cancelProvide: {} };
static abortTransaction = { abortTransaction: {} };
export type Serum3OrderType =
| { limit: Record<string, never> }
| { immediateOrCancel: Record<string, never> }
| { postOnly: Record<string, never> };
// 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<string, never> }
| { cancelProvide: Record<string, never> }
| { abortTransaction: Record<string, never> };
// 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<string, never> }
| { ask: Record<string, never> };
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Serum3Side {
export const bid = { bid: {} };
export const ask = { ask: {} };
}

export async function generateSerum3MarketExternalVaultSignerAddress(
Expand Down
10 changes: 7 additions & 3 deletions ts/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ export class FlashLoanWithdraw {
static amount: BN;
}

export class FlashLoanType {
static unknown = { unknown: {} };
static swap = { swap: {} };
export type FlashLoanType =
| { unknown: Record<string, never> }
| { swap: Record<string, never> };
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace FlashLoanType {
export const unknown = { unknown: {} };
export const swap = { swap: {} };
}

export class InterestRateParams {
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit a41a82e

Please sign in to comment.