Skip to content

Commit

Permalink
Typescript fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Dec 6, 2023
1 parent 4ddc1fb commit a8520f1
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 89 deletions.
2 changes: 1 addition & 1 deletion packages/sdks/common-marinade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/sdks/common-marinade/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}

2 changes: 1 addition & 1 deletion packages/sdks/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdks/common/src/BeamInterface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Keypair, type PublicKey, Transaction } from "@solana/web3.js";
import BN from "bn.js";
import { AnchorProvider, Program, Idl } from "@coral-xyz/anchor";
import { AnchorProvider, Program, type Idl } from "@coral-xyz/anchor";
/**
* Represents a common interface for sunrise beams that act as stake-pool proxies.
*/
Expand Down
9 changes: 7 additions & 2 deletions packages/sdks/common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { AnchorProvider } from "@coral-xyz/anchor";
import BN from "bn.js";
import {
ConfirmOptions,
type ConfirmOptions,
Connection,
PublicKey,
Signer,
type Signer,
Transaction,
} from "@solana/web3.js";
import { STAKE_PROGRAM_ID } from "./constants.js";

export type NonEmptyArray<T> = [T, ...T[]];

export const isNonEmptyArray = <T>(array: T[]): array is NonEmptyArray<T> =>
array.length > 0;

const enum Seeds {
VAULT_AUTHORITY = "vault-authority",
}
Expand Down
5 changes: 4 additions & 1 deletion packages/sdks/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}

2 changes: 1 addition & 1 deletion packages/sdks/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}

2 changes: 1 addition & 1 deletion packages/sdks/marinade-lp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/sdks/marinade-lp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}
2 changes: 1 addition & 1 deletion packages/sdks/marinade-sp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/sdks/marinade-sp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}

2 changes: 1 addition & 1 deletion packages/sdks/spl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/sdks/spl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}

2 changes: 1 addition & 1 deletion packages/sdks/sunrise-stake-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dist"
],
"scripts": {
"build": "rm -r dist; tsc --module es2015 --outDir dist/esm; tsc --module commonjs --outDir dist/cjs && yarn typedoc",
"build": "rm -r dist; tsc --outDir dist/esm; tsc --module commonjs --moduleResolution node --outDir dist/cjs && yarn typedoc",
"lint": "tsc --noEmit && eslint -c ../../../.eslintrc.yaml --ext .ts,.tsx src"
},
"dependencies": {
Expand Down
20 changes: 13 additions & 7 deletions packages/sdks/sunrise-stake-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { type AnchorProvider, Idl } from "@coral-xyz/anchor";
import { PublicKey, Transaction } from "@solana/web3.js";
import BN from "bn.js";
import { SunriseClient } from "@sunrisestake/beams-core";
import { BeamInterface, BeamState } from "@sunrisestake/beams-common";
import {
BeamInterface,
BeamState,
isNonEmptyArray,
NonEmptyArray,
} from "@sunrisestake/beams-common";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
Expand Down Expand Up @@ -75,7 +80,7 @@ export class SunriseStake {
recipient?: PublicKey,
): Promise<Transaction[]> {
const options = this.solDepositBeams();
if (options.length === 0) {
if (!isNonEmptyArray(options)) {
throw new Error("No available beam(s) for deposit");
}

Expand All @@ -92,24 +97,25 @@ export class SunriseStake {
/** Route a deposit through the beams required to complete it. */
private async splitDeposit(
lamports: BN,
options: BeamInterface<Idl, BeamState>[],
options: NonEmptyArray<BeamInterface<Idl, BeamState>>,
): Promise<[BeamInterface<Idl, BeamState>, BN][]> {
const { effectiveGsolSupply } = await this.fetchDetails();
// If effective Gsol supply equals 0, any beam can fully cover the deposit.
if (effectiveGsolSupply.eqn(0)) {
return [[options[0], lamports]];
const [firstOption] = options;
return [[firstOption, lamports]];
}

let unassigned = lamports;
const results = new Array<[BeamInterface<Idl, BeamState>, BN]>();

for (let i = 0; i < options.length; ++i) {
for (const item of options) {
if (unassigned.eqn(0)) {
break;
}

const allocation = this.sunriseClient.state.beams.find(
(a) => a.key === options[i].stateAddress,
(a) => a.key === item.stateAddress,
)?.allocation;

if (!allocation) throw new Error("Beam allocation not found");
Expand All @@ -122,7 +128,7 @@ export class SunriseStake {
);

unassigned = unassigned.sub(singleDeposit);
results.push([options[i], singleDeposit]);
results.push([item, singleDeposit]);
}

// Reachable if the client is initialized with some beams missing.
Expand Down
5 changes: 4 additions & 1 deletion packages/sdks/sunrise-stake-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
"rootDir": "src"
},
"include": [
"src/**/*"
]
}

5 changes: 3 additions & 2 deletions packages/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
},
"dependencies": {
"@solana/spl-token": "^0.3.8",
"@sunrisestake/beams-core": "*",
"@sunrisestake/beams-marinade-lp": "*",
"@sunrisestake/beams-marinade-sp": "*",
"@sunrisestake/beams-spl": "*",
"@sunrisestake/beams-core": "*",
"@types/chai": "^4.3.6",
"@types/chai-as-promised": "^7.1.6",
"@types/mocha": "^10.0.6",
Expand All @@ -23,6 +23,7 @@
"mocha": "^10.2.0",
"mochawesome": "^7.1.3",
"mochawesome-merge": "^4.3.0",
"ts-node": "^10.9.1"
"ts-node": "^10.9.1",
"tsx": "^4.6.2"
}
}
2 changes: 1 addition & 1 deletion packages/tests/run-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ done

yarn -s mochawesome-merge ../../mochawesome-report/mocha-reports/*.json > ../../mochawesome-report/mergedReport.json
yarn marge ../../mochawesome-report/mergedReport.json -o ../../mochawesome-report
yarn ts-node-esm src/analyseReport.ts
yarn tsx src/analyseReport.ts
9 changes: 5 additions & 4 deletions packages/tests/src/functional/beams/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Keypair, PublicKey } from "@solana/web3.js";
import {
createTokenAccount,
initializeTestMint,
log,
sendAndConfirmTransaction,
transferMintAuthority,
} from "../../utils.js";
Expand Down Expand Up @@ -68,8 +69,8 @@ describe("Sunrise core", () => {
client.gsolMintAuthority[0],
);

console.log("state address", client.stateAddress.toBase58());
console.log("gsol mint", client.state.gsolMint.toBase58());
log("state address", client.stateAddress.toBase58());
log("gsol mint", client.state.gsolMint.toBase58());
});

/**
Expand Down Expand Up @@ -214,8 +215,8 @@ describe("Sunrise core", () => {
.rpc();

await expect(shouldFail).to.be.rejectedWithAnchorError(
client.program.idl,
6007,
client.program.idl,
6007,
client.program.programId,
);
});
Expand Down
18 changes: 5 additions & 13 deletions packages/tests/src/functional/beams/marinade-lp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { SunriseClient } from "@sunrisestake/beams-core";
import { MarinadeLpClient } from "@sunrisestake/beams-marinade-lp";
import { Keypair, PublicKey } from "@solana/web3.js";
import { Keypair } from "@solana/web3.js";
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
import BN from "bn.js";
import { provider, sunriseStateKeypair } from "../setup.js";
Expand All @@ -16,15 +16,10 @@ import {
tokenAccountBalance,
} from "../../utils.js";
import { expect } from "chai";
import {MSOL_MINT, SUNRISE_CORE_STATE} from "../consts.js";
import { MSOL_MINT, SUNRISE_CORE_STATE } from "../consts.js";

describe("Marinade liquidity pool beam", () => {
let sunriseClient: SunriseClient;
let beamClient: MarinadeLpClient;

const mlpState = MarinadeLpClient.deriveStateAddress(
sunriseStateKeypair.publicKey,
)[0];
const staker = Keypair.generate();
const stakerIdentity = new AnchorProvider(
provider.connection,
Expand All @@ -46,16 +41,13 @@ describe("Marinade liquidity pool beam", () => {
// NOTE - when combined with the marinade-sp beam, this should be the msol token account
// associated with the marinade stake pool.
const msolTokenAccount = await createTokenAccount(
provider,
sunriseStateKeypair.publicKey,
MSOL_MINT,
);

sunriseClient = await SunriseClient.get(
provider,
sunriseStateKeypair.publicKey,
MSOL_MINT,
);

await SunriseClient.get(provider, sunriseStateKeypair.publicKey);

const treasury = Keypair.generate();
beamClient = await MarinadeLpClient.initialize(
provider,
Expand Down
Loading

0 comments on commit a8520f1

Please sign in to comment.