Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: saber-hq/saber-common
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.13.16
Choose a base ref
...
head repository: saber-hq/saber-common
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.13.17
Choose a head ref
  • 6 commits
  • 31 files changed
  • 2 contributors

Commits on May 25, 2022

  1. Copy the full SHA
    4a07fd9 View commit details
  2. Copy the full SHA
    7a87784 View commit details
  3. Copy the full SHA
    c2e5959 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0780b24 View commit details

Commits on May 26, 2022

  1. Use wallet for transaction broadcasting (#601)

    * adds broadcast ability within wallet adapter
    
    * add support for native transaction sending
    
    * attempt to fix glow wallet
    
    * remove unused
    macalinao authored May 26, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    61e2c4d View commit details
  2. Release v1.13.17

    github-actions[bot] committed May 26, 2022
    Copy the full SHA
    9b53bfd View commit details
Showing with 830 additions and 310 deletions.
  1. +1 −1 .yarn/sdks/typescript/package.json
  2. +6 −6 package.json
  3. +4 −4 packages/anchor-contrib/package.json
  4. +1 −1 packages/browserslist-config/package.json
  5. +6 −6 packages/chai-solana/package.json
  6. +6 −3 packages/chai-solana/src/printInstructionLogs.ts
  7. +28 −36 packages/chai-solana/src/utils.ts
  8. +2 −2 packages/eslint-config-react/package.json
  9. +3 −3 packages/eslint-config/package.json
  10. +3 −3 packages/solana-contrib/package.json
  11. +36 −2 packages/solana-contrib/src/interfaces.ts
  12. +45 −7 packages/solana-contrib/src/provider.ts
  13. +37 −0 packages/solana-contrib/src/transaction/TransactionReceipt.ts
  14. +17 −0 packages/solana-contrib/src/utils/misc.ts
  15. +8 −15 packages/solana-contrib/src/utils/simulateTransactionWithCommitment.ts
  16. +5 −5 packages/stableswap-sdk/package.json
  17. +4 −4 packages/token-utils/package.json
  18. +1 −1 packages/tsconfig/package.json
  19. +4 −4 packages/use-solana/package.json
  20. +22 −2 packages/use-solana/src/adapters/ledger/{index.tsx → index.ts}
  21. +18 −1 packages/use-solana/src/adapters/readonly/index.tsx
  22. +28 −3 packages/use-solana/src/adapters/secret-key/index.tsx
  23. +140 −0 packages/use-solana/src/adapters/solana.ts
  24. +0 −56 packages/use-solana/src/adapters/solana.tsx
  25. +39 −4 packages/use-solana/src/adapters/types.ts
  26. +1 −0 packages/use-solana/src/index.tsx
  27. +7 −6 packages/use-solana/src/providers.tsx
  28. +23 −2 packages/use-solana/src/typings/window.d.ts
  29. +114 −0 packages/use-solana/src/utils/provider.ts
  30. +16 −4 packages/use-solana/src/utils/useProviderInternal.ts
  31. +205 −129 yarn.lock
2 changes: 1 addition & 1 deletion .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript",
"version": "4.6.4-sdk",
"version": "4.7.2-sdk",
"main": "./lib/typescript.js",
"type": "commonjs"
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
"*.{md,js,json,yml,yaml,css,md}": "prettier --write"
},
"devDependencies": {
"@babel/core": "^7.18.0",
"@babel/preset-env": "^7.18.0",
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@project-serum/anchor": "^0.24.2",
"@rushstack/eslint-patch": "^1.1.3",
@@ -29,20 +29,20 @@
"@types/react": "^18.0.9",
"@types/source-map-support": "^0.5.4",
"@yarnpkg/doctor": "^3.1.3",
"bn.js": "^5.2.0",
"bn.js": "^5.2.1",
"buffer": "^6.0.3",
"eslint": "^8.16.0",
"husky": "^8.0.1",
"jest": "^28.1.0",
"jsbi": "^4.3.0",
"lint-staged": "^12.4.1",
"lint-staged": "^12.4.2",
"prettier": "^2.6.2",
"react": "^18.1.0",
"size-limit": "^7.0.8",
"source-map-support": "^0.5.21",
"ts-node": "^10.8.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"typescript": "^4.7.2"
},
"resolutions": {
"@solana/web3.js": "^1.42"
@@ -62,6 +62,6 @@
"test": "jest **/*.test.ts",
"doctor:packages": "yarn doctor packages/"
},
"version": "1.13.16",
"version": "1.13.17",
"packageManager": "yarn@3.2.1"
}
8 changes: 4 additions & 4 deletions packages/anchor-contrib/package.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
},
"homepage": "https://saber.so",
"description": "TypeScript client for Anchor programs.",
"version": "1.13.16",
"version": "1.13.17",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"author": "Ian Macalinao <ian@saber.so>",
@@ -26,11 +26,11 @@
"@solana/web3.js": "^1.43.1",
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.mapvalues": "^4.6.7",
"bn.js": "^5.2.0",
"typescript": "^4.6.4"
"bn.js": "^5.2.1",
"typescript": "^4.7.2"
},
"dependencies": {
"@saberhq/solana-contrib": "^1.13.16",
"@saberhq/solana-contrib": "^1.13.17",
"eventemitter3": "^4.0.7",
"lodash.camelcase": "^4.3.0",
"lodash.mapvalues": "^4.6.0",
2 changes: 1 addition & 1 deletion packages/browserslist-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saberhq/browserslist-config",
"version": "1.13.16",
"version": "1.13.17",
"homepage": "https://saber.so",
"description": "Saber shareable config for Browserslist.",
"repository": "git@github.com:saber-hq/saber-common.git",
12 changes: 6 additions & 6 deletions packages/chai-solana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saberhq/chai-solana",
"version": "1.13.16",
"version": "1.13.17",
"description": "Solana Chai helpers",
"author": "Ian Macalinao <ian@saber.so>",
"homepage": "https://github.com/saber-hq/saber-common#readme",
@@ -24,9 +24,9 @@
"src/"
],
"dependencies": {
"@saberhq/anchor-contrib": "^1.13.16",
"@saberhq/solana-contrib": "^1.13.16",
"@saberhq/token-utils": "^1.13.16",
"@saberhq/anchor-contrib": "^1.13.17",
"@saberhq/solana-contrib": "^1.13.17",
"@saberhq/token-utils": "^1.13.17",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/promise-retry": "^1.1.3",
@@ -49,8 +49,8 @@
"devDependencies": {
"@project-serum/anchor": "^0.24.2",
"@solana/web3.js": "^1.43.1",
"bn.js": "^5.2.0",
"bn.js": "^5.2.1",
"jsbi": "^4.3.0",
"typescript": "^4.6.4"
"typescript": "^4.7.2"
}
}
9 changes: 6 additions & 3 deletions packages/chai-solana/src/printInstructionLogs.ts
Original file line number Diff line number Diff line change
@@ -44,9 +44,12 @@ export const formatInstructionLogsForConsole = (
export const printSendTransactionError = (err: SendTransactionError) => {
try {
const parsed = parseTransactionLogs(err.logs ?? null, err);
console.error(formatInstructionLogsForConsole(parsed));
console.log(formatInstructionLogsForConsole(parsed));
} catch (e) {
console.error(`Could not parse transaction error`, e);
console.error("SendTransactionError", err);
console.warn(
colors.yellow("Could not print logs due to error. Printing raw logs"),
e
);
console.log(err.logs?.join("\n"));
}
};
64 changes: 28 additions & 36 deletions packages/chai-solana/src/utils.ts
Original file line number Diff line number Diff line change
@@ -2,42 +2,23 @@ import "chai-as-promised";

import type { Idl } from "@project-serum/anchor";
import type {
TransactionEnvelope,
PromiseOrValue,
TransactionLike,
TransactionReceipt,
} from "@saberhq/solana-contrib";
import { PendingTransaction } from "@saberhq/solana-contrib";
import type { SendTransactionError } from "@solana/web3.js";
import { confirmTransactionLike } from "@saberhq/solana-contrib";
import { assert, expect } from "chai";

import { printSendTransactionError } from "./printInstructionLogs";

const processTX = async (
tx: TransactionEnvelope | PendingTransaction | null
): Promise<TransactionReceipt> => {
if (tx instanceof PendingTransaction) {
return await tx.wait();
} else if (tx) {
try {
const pending = await tx.send({ printLogs: false });
return await pending.wait();
} catch (err) {
if (err && err instanceof Error && "logs" in err) {
printSendTransactionError(err as SendTransactionError);
}
throw err;
}
} else {
throw new Error("tx is null");
}
};

/**
* Processes a transaction, expecting rejection or fulfillment.
*
* @param tx
* @param msg
* @param cb
* @returns
*/
export const expectTX = (
tx:
| TransactionEnvelope
| null
| Promise<TransactionEnvelope | null>
| PendingTransaction
| Promise<PendingTransaction>,
tx: PromiseOrValue<TransactionLike | null>,
msg?: string,
cb?: (receipt: TransactionReceipt) => Promise<void>
): Chai.PromisedAssertion => {
@@ -47,12 +28,23 @@ export const expectTX = (
};

if (tx && "then" in tx) {
return expect(tx.then(processTX).then(handleReceipt), msg).eventually;
}
if (tx instanceof PendingTransaction) {
return expect(tx.wait().then(handleReceipt), msg).eventually;
return expect(
tx
.then(async (v) => {
if (v === null) {
throw new Error("transaction is null");
}
return await confirmTransactionLike(v);
})
.then(handleReceipt),
msg
).eventually;
} else if (tx) {
return expect(confirmTransactionLike(tx).then(handleReceipt), msg)
.eventually;
} else {
return expect(processTX(tx).then(handleReceipt), msg).eventually;
return expect(Promise.reject(new Error("transaction is null")), msg)
.eventually;
}
};

4 changes: 2 additions & 2 deletions packages/eslint-config-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saberhq/eslint-config-react",
"version": "1.13.16",
"version": "1.13.17",
"description": "Saber base React ESLint config",
"keywords": [
"eslint",
@@ -28,7 +28,7 @@
"eslint": ">=7"
},
"dependencies": {
"@saberhq/eslint-config": "^1.13.16",
"@saberhq/eslint-config": "^1.13.17",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0"
6 changes: 3 additions & 3 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saberhq/eslint-config",
"version": "1.13.16",
"version": "1.13.17",
"description": "Saber base ESLint config",
"keywords": [
"eslint",
@@ -27,8 +27,8 @@
"eslint": ">=7"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-plugin-import": "^2.26.0",
6 changes: 3 additions & 3 deletions packages/solana-contrib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saberhq/solana-contrib",
"version": "1.13.16",
"version": "1.13.17",
"description": "Common types and libraries for Solana",
"author": "Ian Macalinao <ian@saber.so>",
"homepage": "https://github.com/saber-hq/saber-common#readme",
@@ -37,8 +37,8 @@
"@types/bn.js": "^5.1.0",
"@types/jest": "^27.5.1",
"@types/node": "^17.0.35",
"bn.js": "^5.2.0",
"typescript": "^4.6.4"
"bn.js": "^5.2.1",
"typescript": "^4.7.2"
},
"peerDependencies": {
"@solana/web3.js": "^1.42",
38 changes: 36 additions & 2 deletions packages/solana-contrib/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import type {
Transaction,
} from "@solana/web3.js";

import type { PendingTransaction } from ".";
import type { BroadcastOptions, PendingTransaction } from ".";

/**
* Wallet interface for objects that can be used to sign provider transactions.
@@ -103,7 +103,7 @@ export interface Broadcaster {
*/
broadcast: (
tx: Transaction,
opts?: ConfirmOptions
opts?: BroadcastOptions
) => Promise<PendingTransaction>;

/**
@@ -121,12 +121,34 @@ export interface Broadcaster {
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
}

/**
* Sign and broadcast options.
*/
export type SignAndBroadcastOptions = BroadcastOptions & {
/**
* Additional signers
*/
signers?: Signer[];
};

/**
* An interface that can sign transactions.
*/
export interface TransactionSigner {
publicKey: PublicKey;

/**
* Signs and broadcasts a transaction.
*
* @param transaction
* @param broadcaster
* @param options
*/
signAndBroadcastTransaction(
transaction: Transaction,
opts?: SignAndBroadcastOptions
): Promise<PendingTransaction>;

/**
* Signs the given transaction, paid for and signed by the provider's wallet.
*
@@ -204,6 +226,18 @@ export interface Provider extends ReadonlyProvider {
opts?: ConfirmOptions
) => Promise<PendingTransaction[]>;

/**
* Signs and broadcasts a transaction.
*
* @param transaction
* @param broadcaster
* @param options
*/
signAndBroadcastTransaction(
transaction: Transaction,
opts?: SignAndBroadcastOptions
): Promise<PendingTransaction>;

/**
* Simulates the given transaction, returning emitted logs from execution.
*
Loading