From cac6701732fe59ee27acebb7e3122bb446fcf21f Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Wed, 22 Jun 2022 14:35:38 -0400 Subject: [PATCH 1/3] Upgrade NPM dependencies --- .yarn/sdks/eslint/package.json | 2 +- .yarn/sdks/typescript/lib/tsserver.js | 39 +++++++++++++++++--- .yarn/sdks/typescript/lib/tsserverlibrary.js | 39 +++++++++++++++++--- .yarn/sdks/typescript/package.json | 2 +- package.json | 1 + src/wrappers/lockup.ts | 21 +++++------ yarn.lock | 1 + 7 files changed, 80 insertions(+), 25 deletions(-) diff --git a/.yarn/sdks/eslint/package.json b/.yarn/sdks/eslint/package.json index c1f5a51..1e1bcd8 100644 --- a/.yarn/sdks/eslint/package.json +++ b/.yarn/sdks/eslint/package.json @@ -1,6 +1,6 @@ { "name": "eslint", - "version": "8.15.0-sdk", + "version": "8.17.0-sdk", "main": "./lib/api.js", "type": "commonjs" } diff --git a/.yarn/sdks/typescript/lib/tsserver.js b/.yarn/sdks/typescript/lib/tsserver.js index a82ef79..9f9f4d6 100644 --- a/.yarn/sdks/typescript/lib/tsserver.js +++ b/.yarn/sdks/typescript/lib/tsserver.js @@ -61,14 +61,30 @@ const moduleWrapper = tsserver => { // // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 // - // Update Oct 8 2021: VSCode changed their format in 1.61. + // 2021-10-08: VSCode changed the format in 1.61. // Before | ^zip:/c:/foo/bar.zip/package.json // After | ^/zip//c:/foo/bar.zip/package.json // + // 2022-04-06: VSCode changed the format in 1.66. + // Before | ^/zip//c:/foo/bar.zip/package.json + // After | ^/zip/c:/foo/bar.zip/package.json + // + // 2022-05-06: VSCode changed the format in 1.68 + // Before | ^/zip/c:/foo/bar.zip/package.json + // After | ^/zip//c:/foo/bar.zip/package.json + // case `vscode <1.61`: { str = `^zip:${str}`; } break; + case `vscode <1.66`: { + str = `^/zip/${str}`; + } break; + + case `vscode <1.68`: { + str = `^/zip${str}`; + } break; + case `vscode`: { str = `^/zip/${str}`; } break; @@ -119,9 +135,7 @@ const moduleWrapper = tsserver => { case `vscode`: default: { - return process.platform === `win32` - ? str.replace(/^\^?(zip:|\/zip)\/+/, ``) - : str.replace(/^\^?(zip:|\/zip)\/+/, `/`); + return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`) } break; } } @@ -160,8 +174,21 @@ const moduleWrapper = tsserver => { typeof parsedMessage.arguments.hostInfo === `string` ) { hostInfo = parsedMessage.arguments.hostInfo; - if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) { - hostInfo += ` <1.61`; + if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { + const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match( + // The RegExp from https://semver.org/ but without the caret at the start + /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + ) ?? []).map(Number) + + if (major === 1) { + if (minor < 61) { + hostInfo += ` <1.61`; + } else if (minor < 66) { + hostInfo += ` <1.66`; + } else if (minor < 68) { + hostInfo += ` <1.68`; + } + } } } diff --git a/.yarn/sdks/typescript/lib/tsserverlibrary.js b/.yarn/sdks/typescript/lib/tsserverlibrary.js index 0d70146..878b119 100644 --- a/.yarn/sdks/typescript/lib/tsserverlibrary.js +++ b/.yarn/sdks/typescript/lib/tsserverlibrary.js @@ -61,14 +61,30 @@ const moduleWrapper = tsserver => { // // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910 // - // Update Oct 8 2021: VSCode changed their format in 1.61. + // 2021-10-08: VSCode changed the format in 1.61. // Before | ^zip:/c:/foo/bar.zip/package.json // After | ^/zip//c:/foo/bar.zip/package.json // + // 2022-04-06: VSCode changed the format in 1.66. + // Before | ^/zip//c:/foo/bar.zip/package.json + // After | ^/zip/c:/foo/bar.zip/package.json + // + // 2022-05-06: VSCode changed the format in 1.68 + // Before | ^/zip/c:/foo/bar.zip/package.json + // After | ^/zip//c:/foo/bar.zip/package.json + // case `vscode <1.61`: { str = `^zip:${str}`; } break; + case `vscode <1.66`: { + str = `^/zip/${str}`; + } break; + + case `vscode <1.68`: { + str = `^/zip${str}`; + } break; + case `vscode`: { str = `^/zip/${str}`; } break; @@ -119,9 +135,7 @@ const moduleWrapper = tsserver => { case `vscode`: default: { - return process.platform === `win32` - ? str.replace(/^\^?(zip:|\/zip)\/+/, ``) - : str.replace(/^\^?(zip:|\/zip)\/+/, `/`); + return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`) } break; } } @@ -160,8 +174,21 @@ const moduleWrapper = tsserver => { typeof parsedMessage.arguments.hostInfo === `string` ) { hostInfo = parsedMessage.arguments.hostInfo; - if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) { - hostInfo += ` <1.61`; + if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { + const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match( + // The RegExp from https://semver.org/ but without the caret at the start + /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + ) ?? []).map(Number) + + if (major === 1) { + if (minor < 61) { + hostInfo += ` <1.61`; + } else if (minor < 66) { + hostInfo += ` <1.66`; + } else if (minor < 68) { + hostInfo += ` <1.68`; + } + } } } diff --git a/.yarn/sdks/typescript/package.json b/.yarn/sdks/typescript/package.json index b23cc3d..7f51207 100644 --- a/.yarn/sdks/typescript/package.json +++ b/.yarn/sdks/typescript/package.json @@ -1,6 +1,6 @@ { "name": "typescript", - "version": "4.6.4-sdk", + "version": "4.7.3-sdk", "main": "./lib/typescript.js", "type": "commonjs" } diff --git a/package.json b/package.json index 8447733..e4880f4 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "@types/bn.js": "^5" }, "peerDependencies": { + "@project-serum/anchor": "^0.24.2", "@saberhq/anchor-contrib": "^1.13", "@saberhq/solana-contrib": "^1.13", "@saberhq/stableswap-sdk": "^1.13", diff --git a/src/wrappers/lockup.ts b/src/wrappers/lockup.ts index af981f9..c2da55c 100644 --- a/src/wrappers/lockup.ts +++ b/src/wrappers/lockup.ts @@ -1,14 +1,13 @@ -import type * as anchor from "@project-serum/anchor"; import type { TransactionEnvelope } from "@saberhq/solana-contrib"; import type { u64 } from "@saberhq/token-utils"; import { getOrCreateATA, TOKEN_PROGRAM_ID } from "@saberhq/token-utils"; -import type { PublicKey } from "@solana/web3.js"; +import type { PublicKey, TransactionInstruction } from "@solana/web3.js"; import { SystemProgram, SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY, } from "@solana/web3.js"; -import { BN } from "bn.js"; +import BN from "bn.js"; import type { LockupProgram, ReleaseData } from "../programs/lockup"; import type { Saber } from "../sdk"; @@ -16,7 +15,7 @@ import type { Saber } from "../sdk"; const ZERO = new BN(0); export interface PendingRelease { - release: anchor.web3.PublicKey; + release: PublicKey; tx: TransactionEnvelope; } @@ -55,9 +54,9 @@ export class LockupWrapper { minterInfo, mint, }: { - amount: anchor.BN; - startTs: anchor.BN; - endTs: anchor.BN; + amount: BN; + startTs: BN; + endTs: BN; beneficiary: PublicKey; release: PublicKey; minterInfo: PublicKey; @@ -107,9 +106,9 @@ export class LockupWrapper { endTs, beneficiary, }: { - amount: anchor.BN; - startTs: anchor.BN; - endTs: anchor.BN; + amount: BN; + startTs: BN; + endTs: BN; beneficiary: PublicKey; }): Promise { const release = await this.releaseAddress(beneficiary); @@ -139,7 +138,7 @@ export class LockupWrapper { const mintProxyStateAddress = this.saber.mintProxy.program.state.address(); const mintProxyState = await this.saber.mintProxy.program.state.fetch(); - const instructions: anchor.web3.TransactionInstruction[] = []; + const instructions: TransactionInstruction[] = []; const { address, instruction } = await getOrCreateATA({ provider: this.saber.provider, mint: mintProxyState.tokenMint, diff --git a/yarn.lock b/yarn.lock index fc352d5..280230f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -451,6 +451,7 @@ __metadata: typedoc: ^0.22.17 typescript: ^4.7.3 peerDependencies: + "@project-serum/anchor": ^0.24.2 "@saberhq/anchor-contrib": ^1.13 "@saberhq/solana-contrib": ^1.13 "@saberhq/stableswap-sdk": ^1.13 From aee0c3676fe3af337426938ff5b8732b937e2b4d Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Wed, 22 Jun 2022 14:38:37 -0400 Subject: [PATCH 2/3] remove an async function --- src/wrappers/mint-proxy/index.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/wrappers/mint-proxy/index.ts b/src/wrappers/mint-proxy/index.ts index 27536a3..039971a 100644 --- a/src/wrappers/mint-proxy/index.ts +++ b/src/wrappers/mint-proxy/index.ts @@ -1,6 +1,7 @@ import type { Address } from "@project-serum/anchor"; import { translateAddress, utils } from "@project-serum/anchor"; import type { TransactionEnvelope } from "@saberhq/solana-contrib"; +import { getProgramAddress } from "@saberhq/solana-contrib"; import type { u64 } from "@saberhq/token-utils"; import { ChainId, @@ -22,30 +23,37 @@ import type { MinterInfo, MintProxyProgram } from "../../programs"; import type { Saber } from "../../sdk"; import type { PendingMintAndProxy, PendingMintProxy } from "./types"; -async function associated( +const associated = ( programId: Address, ...args: Array
-): Promise { +): PublicKey => { const seeds = [Buffer.from([97, 110, 99, 104, 111, 114])]; // b"anchor". args.forEach((arg) => { seeds.push(arg instanceof Buffer ? arg : translateAddress(arg).toBuffer()); }); - const [assoc] = await PublicKey.findProgramAddress( - seeds, - translateAddress(programId) - ); - return assoc; -} + return getProgramAddress(seeds, translateAddress(programId)); +}; /** * Finds the address of a minter. * @param minter + * + * @deprecated use {@link getMinterInfoAddress} * @returns */ export const findMinterInfoAddress = async ( minter: PublicKey ): Promise => { - return await associated(SABER_ADDRESSES.MintProxy, minter); + return Promise.resolve(getMinterInfoAddress(minter)); +}; + +/** + * Finds the address of a minter. + * @param minter + * @returns + */ +export const getMinterInfoAddress = (minter: PublicKey): PublicKey => { + return associated(SABER_ADDRESSES.MintProxy, minter); }; export class MintProxyWrapper { From f26e44d205f9b0fc59995ca15b5fc6519fb906fe Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Wed, 22 Jun 2022 14:40:02 -0400 Subject: [PATCH 3/3] import cleanup --- src/redeemer/pda.ts | 18 ++++++++++++++++++ src/wrappers/mint-proxy/index.ts | 11 +++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/redeemer/pda.ts b/src/redeemer/pda.ts index 8e7290c..ec071d1 100644 --- a/src/redeemer/pda.ts +++ b/src/redeemer/pda.ts @@ -1,4 +1,5 @@ import { utils } from "@project-serum/anchor"; +import { getProgramAddress } from "@saberhq/solana-contrib"; import { PublicKey } from "@solana/web3.js"; import { SABER_ADDRESSES } from "../constants"; @@ -19,3 +20,20 @@ export const findRedeemerKey = async ({ SABER_ADDRESSES.Redeemer ); }; + +export const getRedeemerKey = ({ + iouMint, + redemptionMint, +}: { + iouMint: PublicKey; + redemptionMint: PublicKey; +}): PublicKey => { + return getProgramAddress( + [ + utils.bytes.utf8.encode("Redeemer"), + iouMint.toBytes(), + redemptionMint.toBytes(), + ], + SABER_ADDRESSES.Redeemer + ); +}; diff --git a/src/wrappers/mint-proxy/index.ts b/src/wrappers/mint-proxy/index.ts index 039971a..86e9ef5 100644 --- a/src/wrappers/mint-proxy/index.ts +++ b/src/wrappers/mint-proxy/index.ts @@ -1,5 +1,4 @@ -import type { Address } from "@project-serum/anchor"; -import { translateAddress, utils } from "@project-serum/anchor"; +import { utils } from "@project-serum/anchor"; import type { TransactionEnvelope } from "@saberhq/solana-contrib"; import { getProgramAddress } from "@saberhq/solana-contrib"; import type { u64 } from "@saberhq/token-utils"; @@ -24,14 +23,14 @@ import type { Saber } from "../../sdk"; import type { PendingMintAndProxy, PendingMintProxy } from "./types"; const associated = ( - programId: Address, - ...args: Array
+ programId: PublicKey, + ...args: Array ): PublicKey => { const seeds = [Buffer.from([97, 110, 99, 104, 111, 114])]; // b"anchor". args.forEach((arg) => { - seeds.push(arg instanceof Buffer ? arg : translateAddress(arg).toBuffer()); + seeds.push(arg instanceof Buffer ? arg : arg.toBuffer()); }); - return getProgramAddress(seeds, translateAddress(programId)); + return getProgramAddress(seeds, programId); }; /**