Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Added support to specify MSP program ID
Browse files Browse the repository at this point in the history
  • Loading branch information
8dell committed Sep 1, 2022
1 parent 19f9a55 commit 117dd93
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mean-dao/msp",
"version": "2.8.2",
"version": "2.8.4-alpha.1",
"description": "MSP Typescript SDK",
"private": false,
"main": "lib/index.js",
Expand Down
6 changes: 5 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { PublicKey } from '@solana/web3.js';
* Constants
*/
export class Constants {
static MSP = new PublicKey('MSPCUMbLfy2MeT6geLMMzrUkv1Tx88XRApaVRdyxTuu');
// DEVNET MSP program address: MSPdQo5ZdrPh6rU1LsvUv5nRhAnj1mj6YQEqBUq8YwZ
// MAINNET MSP program address: MSPCUMbLfy2MeT6geLMMzrUkv1Tx88XRApaVRdyxTuu
static FEE_TREASURY = new PublicKey(
'3TD6SWY9M1mLY2kZWJNavPLhwXvcRsWdnZLRaMzERJBw',
);
Expand All @@ -15,6 +16,9 @@ export class Constants {
static MAX_TX_SIZE = 1200;
// This is an internal convention to identify the intention to use NATIVE sol and not SPL wSOL
static SOL_MINT = new PublicKey('11111111111111111111111111111111');
static READONLY_PUBKEY = new PublicKey(
'3KmMEv7A8R3MMhScQceXBQe69qLmnFfxSM3q8HyzkrSx',
);
}

export const LATEST_IDL_FILE_VERSION = 4;
Expand Down
27 changes: 4 additions & 23 deletions src/msp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class MSP {
private connection: Connection;
private program: Program<Msp>;
private commitment: Commitment | ConnectionConfig | undefined;
private customProgramId: PublicKey | undefined;

/**
* Create a Streaming API object
Expand All @@ -76,31 +75,19 @@ export class MSP {
*/
constructor(
rpcUrl: string,
walletAddress: string,
programId: string,
commitment: Commitment | string = 'finalized',
_customProgramId?: PublicKey,
) {
this.commitment = commitment as Commitment;
this.connection = new Connection(
rpcUrl,
(this.commitment as Commitment) || 'finalized',
);
this.customProgramId = _customProgramId;
this.program = createProgram(
this.connection,
walletAddress,
_customProgramId,
);
this.program = createProgram(this.connection, programId);
}

public async getStream(id: PublicKey, friendly = true): Promise<any> {
const program = createProgram(
this.connection,
Constants.FEE_TREASURY.toBase58(),
this.customProgramId,
);

return getStream(program, id, friendly);
return getStream(this.program, id, friendly);
}

public async refreshStream(
Expand All @@ -111,18 +98,12 @@ export class MSP {
const copyStreamInfo = Object.assign({}, streamInfo);

if (hardUpdate) {
const program = createProgram(
this.connection,
Constants.FEE_TREASURY.toBase58(),
this.customProgramId,
);

const streamId =
typeof copyStreamInfo.id === 'string'
? new PublicKey(copyStreamInfo.id)
: (copyStreamInfo.id as PublicKey);

return await getStream(program, streamId);
return await getStream(this.program, streamId);
}

return getStreamCached(copyStreamInfo, friendly);
Expand Down
8 changes: 3 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,22 @@ const defaultStreamActivity: StreamActivity = {

export const createProgram = (
connection: Connection,
walletAddress: string,
_customProgramId?: PublicKey,
programId: string,
): Program<Msp> => {
const opts: ConfirmOptions = {
preflightCommitment: 'finalized',
commitment: 'finalized',
};

const wallet: Wallet = {
publicKey: new PublicKey(walletAddress),
publicKey: Constants.READONLY_PUBKEY,
signAllTransactions: async txs => txs,
signTransaction: async tx => tx,
};

const provider = new AnchorProvider(connection, wallet, opts);

if (_customProgramId) return new Program(IDL, _customProgramId, provider);
return new Program(IDL, Constants.MSP, provider);
return new Program(IDL, programId, provider);
};

export const getStream = async (
Expand Down
10 changes: 6 additions & 4 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ describe('Tests creating a vesting treasury\n', async () => {
lamports: 1000 * LAMPORTS_PER_SOL,
toPubkey: new PublicKey("3TD6SWY9M1mLY2kZWJNavPLhwXvcRsWdnZLRaMzERJBw")
}));
tx.add(SystemProgram.transfer({
fromPubkey: root.publicKey,
lamports: 1000 * LAMPORTS_PER_SOL,
toPubkey: Constants.READONLY_PUBKEY
}));
await sendAndConfirmTransaction(connection, tx, [root], { commitment: 'confirmed' });
console.log("Balance user1: : ", await connection.getBalance(user1Wallet.publicKey, 'confirmed'));
console.log("Balance user2: : ", await connection.getBalance(user2Wallet.publicKey, 'confirmed'));

msp = new MSP(endpoint, user1Wallet.publicKey.toBase58(), 'confirmed',
// comment out to avoid error 'Attempt to load a program that does not exist'
new PublicKey("2nZ8KDGdPBexJwWznPZosioWJzNBSM3doUXUYdo37ndN")
);
msp = new MSP(endpoint, "MSPdQo5ZdrPh6rU1LsvUv5nRhAnj1mj6YQEqBUq8YwZ", 'confirmed');
});

it('Creates a vesting treasury and vesting stream\n', async () => {
Expand Down

0 comments on commit 117dd93

Please sign in to comment.