Socket
Socket
Sign inDemoInstall

@iai-skunks/ml-registry-solana

Package Overview
Dependencies
106
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.1 to 0.5.0

6

dist/bindings.d.ts

@@ -17,3 +17,3 @@ import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";

*/
export declare function createModelRegistry(connection: Connection, programId: PublicKey, payerKey: PublicKey, modelName: string, linkFunc: string, coeffs: number[], space: number, usageFee: number, feeAccountKey: PublicKey, intercept?: number, lamports?: number): Promise<[TransactionInstruction, PublicKey]>;
export declare function createModelRegistry(connection: Connection, programId: PublicKey, payerKey: PublicKey, modelName: string, linkFunc: string, coeffs: number[], space: number, usageFee: number, feeAccountKey: PublicKey, serviceFeeAmount: number, tokenProgram: PublicKey, sourceTokenAccount: PublicKey, mlServiceUtilityKey: PublicKey, intercept?: number, lamports?: number): Promise<[TransactionInstruction, PublicKey]>;
/**

@@ -30,5 +30,5 @@ * Creates a predict with specified model instruction

* @param mlServiceKey The wallet to where all proportion of fees to service are deposited
* @param mlServiceCharge The percentage cut the service earns per prediction fee
* @param mlServiceFeePctg The percentage cut the service earns per prediction fee
* @param lamports The budget to be set for the name account. If not specified, it'll be the minimum for rent exemption
*/
export declare function predictWithModel(connection: Connection, programId: PublicKey, payerKey: PublicKey, modelName: string, scoreAccountName: string, indVars: number[], space: number, mlServiceKey: PublicKey, mlServiceCharge: number, lamports?: number): Promise<[TransactionInstruction, PublicKey]>;
export declare function predictWithModel(connection: Connection, programId: PublicKey, payerKey: PublicKey, modelName: string, scoreAccountName: string, indVars: number[], space: number, mlServiceKey: PublicKey, mlServiceFeePctg: number, serviceFeeAmount: number, tokenProgram: PublicKey, sourceTokenAccount: PublicKey, mlServiceUtilityKey: PublicKey, lamports?: number): Promise<[TransactionInstruction, PublicKey]>;

@@ -36,3 +36,3 @@ "use strict";

*/
function createModelRegistry(connection, programId, payerKey, modelName, linkFunc, coeffs, space, usageFee, feeAccountKey, intercept, lamports) {
function createModelRegistry(connection, programId, payerKey, modelName, linkFunc, coeffs, space, usageFee, feeAccountKey, serviceFeeAmount, tokenProgram, sourceTokenAccount, mlServiceUtilityKey, intercept, lamports) {
return __awaiter(this, void 0, void 0, function* () {

@@ -51,3 +51,3 @@ const hashedName = yield (0, utils_1.getHashedName)(modelName);

}
const instruction = (0, instructions_1.createInstruction)(programId, web3_js_1.SystemProgram.programId, payerKey, modelAccountPubkey, hashedName, coeffs, finalIntercept, linkFunc, new custom_types_1.Numberu64(balance), new custom_types_1.Numberu32(space), new custom_types_1.Numberu64(usageFee), feeAccountKey);
const instruction = (0, instructions_1.createInstruction)(programId, web3_js_1.SystemProgram.programId, payerKey, modelAccountPubkey, hashedName, coeffs, finalIntercept, linkFunc, new custom_types_1.Numberu64(balance), new custom_types_1.Numberu32(space), new custom_types_1.Numberu64(usageFee), feeAccountKey, new custom_types_1.Numberu64(serviceFeeAmount), tokenProgram, sourceTokenAccount, mlServiceUtilityKey);
return [instruction, modelAccountPubkey];

@@ -68,6 +68,6 @@ });

* @param mlServiceKey The wallet to where all proportion of fees to service are deposited
* @param mlServiceCharge The percentage cut the service earns per prediction fee
* @param mlServiceFeePctg The percentage cut the service earns per prediction fee
* @param lamports The budget to be set for the name account. If not specified, it'll be the minimum for rent exemption
*/
function predictWithModel(connection, programId, payerKey, modelName, scoreAccountName, indVars, space, mlServiceKey, mlServiceCharge, lamports) {
function predictWithModel(connection, programId, payerKey, modelName, scoreAccountName, indVars, space, mlServiceKey, mlServiceFeePctg, serviceFeeAmount, tokenProgram, sourceTokenAccount, mlServiceUtilityKey, lamports) {
return __awaiter(this, void 0, void 0, function* () {

@@ -87,3 +87,3 @@ const balance = lamports

const modelState = yield states_1.ModelState.retrieve(connection, modelAccountPubkey);
const instruction = (0, instructions_1.createPredictInstruction)(web3_js_1.SystemProgram.programId, programId, payerKey, modelAccountPubkey, modelHashedName, scoreAccountPubkey, scoreHashedName, indVars, new custom_types_1.Numberu64(balance), new custom_types_1.Numberu32(space), modelState.feeAccountKey, mlServiceKey, mlServiceCharge);
const instruction = (0, instructions_1.createPredictInstruction)(web3_js_1.SystemProgram.programId, programId, payerKey, modelAccountPubkey, modelHashedName, scoreAccountPubkey, scoreHashedName, indVars, new custom_types_1.Numberu64(balance), new custom_types_1.Numberu32(space), modelState.feeAccountKey, mlServiceKey, mlServiceFeePctg, new custom_types_1.Numberu64(serviceFeeAmount), tokenProgram, sourceTokenAccount, mlServiceUtilityKey);
return [instruction, scoreAccountPubkey];

@@ -90,0 +90,0 @@ });

/// <reference types="node" />
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { Numberu32, Numberu64 } from "./custom_types";
export declare function createInstruction(mlProgramId: PublicKey, systemProgramId: PublicKey, payerKey: PublicKey, modelAccountKey: PublicKey, hashedName: Buffer, coeffs: number[], intercept: number, linkFunc: string, lamports: Numberu64, space: Numberu32, usageFee: Numberu64, feeAccountKey: PublicKey): TransactionInstruction;
export declare function createPredictInstruction(systemProgramId: PublicKey, mlProgramId: PublicKey, payerKey: PublicKey, modelAccountKey: PublicKey, modelHashedName: Buffer, scoreAccountKey: PublicKey, scoreHashedName: Buffer, indVars: number[], lamports: Numberu64, space: Numberu32, feeAccountKey: PublicKey, mlServiceKey: PublicKey, mlServiceCharge: number): TransactionInstruction;
export declare function createInstruction(mlProgramId: PublicKey, systemProgramId: PublicKey, payerKey: PublicKey, modelAccountKey: PublicKey, hashedName: Buffer, coeffs: number[], intercept: number, linkFunc: string, lamports: Numberu64, space: Numberu32, usageFee: Numberu64, feeAccountKey: PublicKey, serviceFeeAmount: Numberu64, tokenProgram: PublicKey, sourceTokenAccount: PublicKey, mlServiceUtilityKey: PublicKey): TransactionInstruction;
export declare function createPredictInstruction(systemProgramId: PublicKey, mlProgramId: PublicKey, payerKey: PublicKey, modelAccountKey: PublicKey, modelHashedName: Buffer, scoreAccountKey: PublicKey, scoreHashedName: Buffer, indVars: number[], lamports: Numberu64, space: Numberu32, feeAccountKey: PublicKey, mlServiceKey: PublicKey, mlServiceFeePctg: number, serviceFeeAmount: Numberu64, tokenProgram: PublicKey, sourceTokenAccount: PublicKey, mlServiceUtilityKey: PublicKey): TransactionInstruction;

@@ -6,3 +6,3 @@ "use strict";

const custom_types_1 = require("./custom_types");
function createInstruction(mlProgramId, systemProgramId, payerKey, modelAccountKey, hashedName, coeffs, intercept, linkFunc, lamports, space, usageFee, feeAccountKey) {
function createInstruction(mlProgramId, systemProgramId, payerKey, modelAccountKey, hashedName, coeffs, intercept, linkFunc, lamports, space, usageFee, feeAccountKey, serviceFeeAmount, tokenProgram, sourceTokenAccount, mlServiceUtilityKey) {
const buffers = [

@@ -21,2 +21,3 @@ Buffer.from(Int8Array.from([0])),

feeAccountKey.toBuffer(),
serviceFeeAmount.toBuffer(),
];

@@ -40,2 +41,17 @@ const data = Buffer.concat(buffers);

},
{
pubkey: tokenProgram,
isSigner: false,
isWritable: false,
},
{
pubkey: sourceTokenAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: mlServiceUtilityKey,
isSigner: false,
isWritable: true,
},
];

@@ -49,3 +65,3 @@ return new web3_js_1.TransactionInstruction({

exports.createInstruction = createInstruction;
function createPredictInstruction(systemProgramId, mlProgramId, payerKey, modelAccountKey, modelHashedName, scoreAccountKey, scoreHashedName, indVars, lamports, space, feeAccountKey, mlServiceKey, mlServiceCharge) {
function createPredictInstruction(systemProgramId, mlProgramId, payerKey, modelAccountKey, modelHashedName, scoreAccountKey, scoreHashedName, indVars, lamports, space, feeAccountKey, mlServiceKey, mlServiceFeePctg, serviceFeeAmount, tokenProgram, sourceTokenAccount, mlServiceUtilityKey) {
const buffers = [

@@ -61,3 +77,4 @@ Buffer.from(Int8Array.from([1])),

space.toBuffer(),
new custom_types_1.Float32(mlServiceCharge).toBuffer(),
new custom_types_1.Float32(mlServiceFeePctg).toBuffer(),
serviceFeeAmount.toBuffer()
];

@@ -96,2 +113,17 @@ const data = Buffer.concat(buffers);

},
{
pubkey: tokenProgram,
isSigner: false,
isWritable: false,
},
{
pubkey: sourceTokenAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: mlServiceUtilityKey,
isSigner: false,
isWritable: true,
},
];

@@ -98,0 +130,0 @@ return new web3_js_1.TransactionInstruction({

{
"name": "@iai-skunks/ml-registry-solana",
"version": "0.4.1",
"version": "0.5.0",
"description": "SPL ML Model Registry/Inference JavaScript API",

@@ -21,2 +21,3 @@ "main": "dist/index.js",

"dependencies": {
"@solana/spl-token": "^0.2.0",
"@solana/web3.js": "^1.37.0",

@@ -28,7 +29,5 @@ "bn.js": "^5.2.0",

"devDependencies": {
"yaml": "^1.10.2",
"mz": "^2.7.0",
"@types/node": "^17.0.23",
"@types/bn.js": "^5.1.0",
"@types/mz": "^2.7.4",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.18.0",

@@ -41,2 +40,3 @@ "@typescript-eslint/parser": "^5.18.0",

"eslint-plugin-node": "^11.1.0",
"mz": "^2.7.0",
"prettier": "^2.6.2",

@@ -46,4 +46,5 @@ "ts-loader": "^9.2.8",

"typedoc": "^0.22.14",
"typescript": "^4.6.3"
"typescript": "^4.6.3",
"yaml": "^1.10.2"
}
}

@@ -0,1 +1,4 @@

## v0.5.0
- update bindings to allow for service charges paid with a token program
## v0.4.1

@@ -2,0 +5,0 @@ - fix improper import of ModelState in bindings.ts

@@ -43,2 +43,6 @@ import {

feeAccountKey: PublicKey,
serviceFeeAmount: number,
tokenProgram: PublicKey,
sourceTokenAccount: PublicKey,
mlServiceUtilityKey: PublicKey,
intercept?: number,

@@ -85,3 +89,7 @@ lamports?: number

new Numberu64(usageFee),
feeAccountKey
feeAccountKey,
new Numberu64(serviceFeeAmount),
tokenProgram,
sourceTokenAccount,
mlServiceUtilityKey
);

@@ -103,3 +111,3 @@

* @param mlServiceKey The wallet to where all proportion of fees to service are deposited
* @param mlServiceCharge The percentage cut the service earns per prediction fee
* @param mlServiceFeePctg The percentage cut the service earns per prediction fee
* @param lamports The budget to be set for the name account. If not specified, it'll be the minimum for rent exemption

@@ -116,3 +124,7 @@ */

mlServiceKey: PublicKey,
mlServiceCharge: number,
mlServiceFeePctg: number,
serviceFeeAmount: number,
tokenProgram: PublicKey,
sourceTokenAccount: PublicKey,
mlServiceUtilityKey: PublicKey,
lamports?: number

@@ -163,3 +175,7 @@ ): Promise<[TransactionInstruction, PublicKey]> {

mlServiceKey,
mlServiceCharge
mlServiceFeePctg,
new Numberu64(serviceFeeAmount),
tokenProgram,
sourceTokenAccount,
mlServiceUtilityKey
);

@@ -166,0 +182,0 @@

@@ -17,3 +17,7 @@ import { PublicKey, TransactionInstruction } from "@solana/web3.js";

usageFee: Numberu64,
feeAccountKey: PublicKey
feeAccountKey: PublicKey,
serviceFeeAmount: Numberu64,
tokenProgram: PublicKey,
sourceTokenAccount: PublicKey,
mlServiceUtilityKey: PublicKey
): TransactionInstruction {

@@ -33,2 +37,3 @@ const buffers = [

feeAccountKey.toBuffer(),
serviceFeeAmount.toBuffer(),
];

@@ -54,2 +59,17 @@

},
{
pubkey: tokenProgram,
isSigner: false,
isWritable: false,
},
{
pubkey: sourceTokenAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: mlServiceUtilityKey,
isSigner: false,
isWritable: true,
},
];

@@ -77,3 +97,7 @@

mlServiceKey: PublicKey,
mlServiceCharge: number
mlServiceFeePctg: number,
serviceFeeAmount: Numberu64,
tokenProgram: PublicKey,
sourceTokenAccount: PublicKey,
mlServiceUtilityKey: PublicKey
): TransactionInstruction {

@@ -90,3 +114,4 @@ const buffers = [

space.toBuffer(),
new Float32(mlServiceCharge).toBuffer(),
new Float32(mlServiceFeePctg).toBuffer(),
serviceFeeAmount.toBuffer()
];

@@ -127,2 +152,17 @@

},
{
pubkey: tokenProgram,
isSigner: false,
isWritable: false,
},
{
pubkey: sourceTokenAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: mlServiceUtilityKey,
isSigner: false,
isWritable: true,
},
];

@@ -129,0 +169,0 @@

@@ -6,2 +6,3 @@ import {

establishPayer,
establishAssociatedServiceAccount,
predict,

@@ -17,2 +18,3 @@ } from "./ml_predict";

await establishPayer();
await establishAssociatedServiceAccount();
await checkProgram();

@@ -27,12 +29,4 @@

);
const mlServiceKey = new PublicKey(
"AjXukoeGHeRacrmoV8hGFzYAqMh974uySrrji7Cid4jG"
);
const mlServiceCharge = 10.0;
// meta data size
let modelSpace =
coeffs.join(", ").toString().length + intercept.toString().length;
let predictSpace = indVars.join(", ").toString().length;
// normal test
await createModel(

@@ -42,8 +36,8 @@ coeffs,

"normal",
modelSpace,
usageFee,
feeAccountKey
);
await predict(indVars, predictSpace, mlServiceKey, mlServiceCharge);
await predict(indVars);
// log reg test
await createModel(

@@ -53,7 +47,6 @@ coeffs,

"logreg",
modelSpace,
usageFee,
feeAccountKey
);
await predict(indVars, predictSpace, mlServiceKey, mlServiceCharge);
await predict(indVars);

@@ -60,0 +53,0 @@ console.log("Success");

@@ -11,2 +11,3 @@ import path from "path";

} from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token";

@@ -23,5 +24,16 @@ import { createModelRegistry, predictWithModel } from "../src/bindings";

let modelKeyCopy: PublicKey;
let sourceTokenAccount: PublicKey;
let mlServiceUtilityKey: PublicKey;
const PROGRAM_PATH = path.resolve(__dirname, "../../program/dist/program");
const PROGRAM_KEYPAIR_PATH = path.join(PROGRAM_PATH, "ml_predict-keypair.json");
const UTILITY_TOKEN_MINT = new PublicKey(
"6LYebwvX39zn18XA4692s3h8UsbmBzmnLKmzz1CPm8Ta"
);
const ML_SERVICE_KEY = new PublicKey(
"435nNKzx9F9kDeX8rpuaufZLzKGAYPtAQMSuWPDf9sBC"
);
const ML_SERVICE_FEE_PCTG = 10.0;
const CREATE_SERVICE_FEE_AMOUNT = 10e9;
const PREDICT_SERVICE_FEE_AMOUNT = 1e9;

@@ -42,2 +54,7 @@ export async function establishConnection(): Promise<void> {

sourceTokenAccount = await getAssociatedTokenAddress(
UTILITY_TOKEN_MINT,
payer.publicKey
);
console.log(

@@ -51,2 +68,15 @@ "Payer account: ",

export async function establishAssociatedServiceAccount(): Promise<void> {
mlServiceUtilityKey = await getAssociatedTokenAddress(
UTILITY_TOKEN_MINT,
ML_SERVICE_KEY
);
console.log(
"ml service wallet: ",
ML_SERVICE_KEY.toString(),
"associated utility account: ",
mlServiceUtilityKey.toString()
);
}
export async function checkProgram(): Promise<void> {

@@ -78,3 +108,2 @@ // read program id from generated keypair file after deploy

linkFunc: string,
space: number,
usageFee: number,

@@ -88,2 +117,5 @@ feeAccountKey: PublicKey,

const modelSpace =
coeffs.join(", ").toString().length + intercept.toString().length;
const [instruction, modelAccountPubkey] = await createModelRegistry(

@@ -96,5 +128,9 @@ connection,

coeffs,
space,
modelSpace,
usageFee,
feeAccountKey,
CREATE_SERVICE_FEE_AMOUNT,
TOKEN_PROGRAM_ID,
sourceTokenAccount,
mlServiceUtilityKey,
intercept,

@@ -123,5 +159,2 @@ lamports

indVars: number[],
space: number,
mlServiceKey: PublicKey,
mlServiceCharge: number,
lamports?: number

@@ -132,2 +165,4 @@ ): Promise<void> {

const predictSpace = indVars.join(", ").toString().length;
const [instruction, scoreAccountPubkey] = await predictWithModel(

@@ -140,5 +175,9 @@ connection,

indVars,
space,
mlServiceKey,
mlServiceCharge,
predictSpace,
ML_SERVICE_KEY,
ML_SERVICE_FEE_PCTG,
PREDICT_SERVICE_FEE_AMOUNT,
TOKEN_PROGRAM_ID,
sourceTokenAccount,
mlServiceUtilityKey,
lamports

@@ -145,0 +184,0 @@ );

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc