@zebec-network/zebec-stream-sdk 1.7.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifacts/zebec_stream.d.ts +1 -498
- package/dist/artifacts/zebec_stream.json +324 -761
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +4 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/pda.d.ts +0 -2
- package/dist/pda.js +0 -10
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/services/streamService.d.ts +0 -1
- package/dist/services/streamService.js +0 -1
- package/package.json +29 -29
- package/dist/services/zTokenService.d.ts +0 -66
- package/dist/services/zTokenService.js +0 -290
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const STREAM_NAME_BUFFER_SIZE = 128;
|
|
2
2
|
export type Network = "mainnet-beta" | "devnet";
|
|
3
3
|
export declare const STREAM_PROGRAM_ID: Record<Network, string>;
|
|
4
|
-
export declare const ZTOKEN_PROGRAM_ID: Record<Network, string>;
|
|
5
4
|
export declare const STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS: Record<Network, string>;
|
package/dist/constants.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS = exports.
|
|
3
|
+
exports.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS = exports.STREAM_PROGRAM_ID = exports.STREAM_NAME_BUFFER_SIZE = void 0;
|
|
4
4
|
exports.STREAM_NAME_BUFFER_SIZE = 128;
|
|
5
5
|
exports.STREAM_PROGRAM_ID = {
|
|
6
|
-
"mainnet-beta": "
|
|
7
|
-
devnet: "
|
|
8
|
-
};
|
|
9
|
-
exports.ZTOKEN_PROGRAM_ID = {
|
|
10
|
-
"mainnet-beta": "GoqwQ8CeFB3KEQgVQtnJzUAMz6zHMpCdeG785PD459W6",
|
|
11
|
-
devnet: "GoqwQ8CeFB3KEQgVQtnJzUAMz6zHMpCdeG785PD459W6",
|
|
6
|
+
"mainnet-beta": "zSTRMmYcFF8SPdHmsAmAUjBnx4zDHvnqqGz2mPcc5QC",
|
|
7
|
+
devnet: "zSTRMmYcFF8SPdHmsAmAUjBnx4zDHvnqqGz2mPcc5QC",
|
|
12
8
|
};
|
|
13
9
|
exports.STREAM_PROGRAM_LOOKUP_TABLE_ADDRESS = {
|
|
14
10
|
devnet: "HJmEzSXzJrtSdgBZSaedQ51WaD4LkT1r5zR2yT1QERqv",
|
|
15
|
-
"mainnet-beta": "",
|
|
11
|
+
"mainnet-beta": "43N5otEu7k7TzkKsdhkwiYGrdKjBejetWQbF9cJPtY6i",
|
|
16
12
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,11 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.STREAM_TOKEN_PROGRAM_ID = void 0;
|
|
18
17
|
__exportStar(require("./artifacts"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
19
|
__exportStar(require("./services"), exports);
|
|
20
20
|
__exportStar(require("./pda"), exports);
|
|
21
21
|
__exportStar(require("./providers"), exports);
|
|
22
22
|
__exportStar(require("./types"), exports);
|
|
23
|
-
var constants_1 = require("./constants");
|
|
24
|
-
Object.defineProperty(exports, "STREAM_TOKEN_PROGRAM_ID", { enumerable: true, get: function () { return constants_1.STREAM_PROGRAM_ID; } });
|
package/dist/pda.d.ts
CHANGED
|
@@ -2,5 +2,3 @@ import { Address } from "@coral-xyz/anchor";
|
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
export declare function deriveStreamConfigPda(programId: Address): [PublicKey, number];
|
|
4
4
|
export declare function deriveStreamVaultPda(metatadata: Address, programId: Address): [PublicKey, number];
|
|
5
|
-
export declare function deriveZTokenConfigPda(programId: Address): [PublicKey, number];
|
|
6
|
-
export declare function deriveMintAuthoritPda(programId: Address): [PublicKey, number];
|
package/dist/pda.js
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deriveStreamConfigPda = deriveStreamConfigPda;
|
|
4
4
|
exports.deriveStreamVaultPda = deriveStreamVaultPda;
|
|
5
|
-
exports.deriveZTokenConfigPda = deriveZTokenConfigPda;
|
|
6
|
-
exports.deriveMintAuthoritPda = deriveMintAuthoritPda;
|
|
7
5
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
6
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
7
|
const SEEDS = {
|
|
10
8
|
STREAM_CONFIG: anchor_1.utils.bytes.utf8.encode("config"),
|
|
11
|
-
ZTOKEN_CONFIG: anchor_1.utils.bytes.utf8.encode("ztoken_config"),
|
|
12
|
-
MINT_AUTHORITY: anchor_1.utils.bytes.utf8.encode("ztoken_minter"),
|
|
13
9
|
};
|
|
14
10
|
function deriveStreamConfigPda(programId) {
|
|
15
11
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(SEEDS.STREAM_CONFIG)], (0, anchor_1.translateAddress)(programId));
|
|
@@ -17,9 +13,3 @@ function deriveStreamConfigPda(programId) {
|
|
|
17
13
|
function deriveStreamVaultPda(metatadata, programId) {
|
|
18
14
|
return web3_js_1.PublicKey.findProgramAddressSync([(0, anchor_1.translateAddress)(metatadata).toBuffer()], (0, anchor_1.translateAddress)(programId));
|
|
19
15
|
}
|
|
20
|
-
function deriveZTokenConfigPda(programId) {
|
|
21
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(SEEDS.ZTOKEN_CONFIG)], (0, anchor_1.translateAddress)(programId));
|
|
22
|
-
}
|
|
23
|
-
function deriveMintAuthoritPda(programId) {
|
|
24
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(SEEDS.MINT_AUTHORITY)], (0, anchor_1.translateAddress)(programId));
|
|
25
|
-
}
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./zTokenService"), exports);
|
|
18
17
|
__exportStar(require("./streamService"), exports);
|
|
@@ -40,7 +40,6 @@ export declare class ZebecStreamService {
|
|
|
40
40
|
streamName: Uint8Array | Buffer;
|
|
41
41
|
transferableByRecipient: boolean;
|
|
42
42
|
transferableBySender: boolean;
|
|
43
|
-
numberOfWithdrawls: BN;
|
|
44
43
|
}): Promise<TransactionInstruction>;
|
|
45
44
|
getPauseResumeStreamInstruction(streamMetadata: PublicKey, user: PublicKey): Promise<TransactionInstruction>;
|
|
46
45
|
getCancelStreamInstruction(feePayer: PublicKey, otherParty: PublicKey, otherPartyAta: PublicKey, signer: PublicKey, signerAta: PublicKey, streamMetadata: PublicKey, streamToken: PublicKey, streamVault: PublicKey, streamVaultAta: PublicKey): Promise<TransactionInstruction>;
|
|
@@ -244,7 +244,6 @@ class ZebecStreamService {
|
|
|
244
244
|
cliffPercentage,
|
|
245
245
|
duration: new anchor_1.BN(params.duration),
|
|
246
246
|
isPausable: params.isPausable,
|
|
247
|
-
numberOfWithdrawls: new anchor_1.BN(params.duration / params.autoWithdrawFrequency),
|
|
248
247
|
rateUpdatable: params.rateUpdatable,
|
|
249
248
|
startNow: params.startNow,
|
|
250
249
|
startTime: new anchor_1.BN(params.startTime),
|
package/package.json
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@zebec-network/zebec-stream-sdk",
|
|
3
|
-
"version": "1.7.4",
|
|
4
|
-
"description": "This is an SDK for interacting with ZEBEC Stream Program in solana",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
2
|
"author": "Ashish Sapkota",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@coral-xyz/anchor": "^0.31.1",
|
|
5
|
+
"@metaplex-foundation/mpl-token-metadata": "^3.4.0",
|
|
6
|
+
"@metaplex-foundation/umi": "^1.4.1",
|
|
7
|
+
"@metaplex-foundation/umi-bundle-defaults": "^1.4.1",
|
|
8
|
+
"@metaplex-foundation/umi-web3js-adapters": "^1.4.1",
|
|
9
|
+
"@solana/spl-token": "^0.4.14",
|
|
10
|
+
"@solana/web3.js": "^1.98.2",
|
|
11
|
+
"@zebec-network/core-utils": "^1.1.1",
|
|
12
|
+
"@zebec-network/solana-common": "^2.3.1",
|
|
13
|
+
"bignumber.js": "^9.3.1"
|
|
19
14
|
},
|
|
15
|
+
"description": "This is an SDK for interacting with ZEBEC Stream Program in solana",
|
|
20
16
|
"devDependencies": {
|
|
21
17
|
"@types/bn.js": "^5.2.0",
|
|
22
18
|
"@types/mocha": "^10.0.10",
|
|
@@ -29,16 +25,20 @@
|
|
|
29
25
|
"ts-node": "^10.9.2",
|
|
30
26
|
"typescript": "^5.9.2"
|
|
31
27
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"main": "dist/index.js",
|
|
33
|
+
"name": "@zebec-network/zebec-stream-sdk",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "npm run clean && tsc",
|
|
36
|
+
"clean": "rimraf ./dist",
|
|
37
|
+
"format": "prettier --write .",
|
|
38
|
+
"start": "ts-node src/index.ts",
|
|
39
|
+
"test": "ts-mocha -p ./tsconfig.json -t 1000000000 test/**/*.test.ts",
|
|
40
|
+
"test:single": "ts-mocha -p ./tsconfig.json -t 1000000000"
|
|
41
|
+
},
|
|
42
|
+
"types": "dist/index.d.ts",
|
|
43
|
+
"version": "2.1.0"
|
|
44
|
+
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
-
import { Commitment, Keypair, PublicKey } from "@solana/web3.js";
|
|
3
|
-
import { TransactionPayload } from "@zebec-network/solana-common";
|
|
4
|
-
import { ZebecStreamIdl as ZTokenIdl } from "../artifacts";
|
|
5
|
-
import { Numeric } from "../types";
|
|
6
|
-
export declare class ZTokenService {
|
|
7
|
-
readonly provider: anchor.Provider;
|
|
8
|
-
readonly program: anchor.Program<ZTokenIdl>;
|
|
9
|
-
constructor(provider: anchor.Provider, program: anchor.Program<ZTokenIdl>);
|
|
10
|
-
static create(provider: anchor.Provider, network: "mainnet-beta" | "devnet"): ZTokenService;
|
|
11
|
-
get programId(): PublicKey;
|
|
12
|
-
get connection(): anchor.web3.Connection;
|
|
13
|
-
private _createPayload;
|
|
14
|
-
getInitZTOkenConfigInstruction(admin: PublicKey, feeVault: PublicKey, feeBps: number, minAmount: anchor.BN): Promise<anchor.web3.TransactionInstruction>;
|
|
15
|
-
getMintZTokenInstruction(admin: PublicKey, destination: PublicKey, mint: PublicKey, amount: anchor.BN, hash: number[]): Promise<anchor.web3.TransactionInstruction>;
|
|
16
|
-
getBurnZTokenInstruction(mint: PublicKey, source: PublicKey, sourceAta: PublicKey, amount: anchor.BN, receiver: string): Promise<anchor.web3.TransactionInstruction>;
|
|
17
|
-
getSetMintableTokensInstruction(admin: PublicKey, tokens: PublicKey[]): Promise<anchor.web3.TransactionInstruction>;
|
|
18
|
-
getUpdateZTokenConfigInstruction(admin: PublicKey, feeVault: PublicKey, feeBps: number, minAmount: anchor.BN): Promise<anchor.web3.TransactionInstruction>;
|
|
19
|
-
getEmergencyPauseInstruction(admin: PublicKey): Promise<anchor.web3.TransactionInstruction>;
|
|
20
|
-
createToken(params: {
|
|
21
|
-
admin: anchor.Address;
|
|
22
|
-
tokenInfo: {
|
|
23
|
-
tokenName: string;
|
|
24
|
-
symbol: string;
|
|
25
|
-
metadataUri: string;
|
|
26
|
-
decimals: number;
|
|
27
|
-
mintKeypair?: Keypair;
|
|
28
|
-
};
|
|
29
|
-
}): Promise<TransactionPayload>;
|
|
30
|
-
initZTOkenConfig(params: {
|
|
31
|
-
admin: anchor.Address;
|
|
32
|
-
feeVault: anchor.Address;
|
|
33
|
-
minAmount: Numeric;
|
|
34
|
-
feePercent: number;
|
|
35
|
-
}): Promise<TransactionPayload>;
|
|
36
|
-
mintZToken(params: {
|
|
37
|
-
admin: anchor.Address;
|
|
38
|
-
destination: anchor.Address;
|
|
39
|
-
mint: anchor.Address;
|
|
40
|
-
amount: Numeric;
|
|
41
|
-
hash: number[] | Buffer | Uint8Array;
|
|
42
|
-
}): Promise<TransactionPayload>;
|
|
43
|
-
burnZToken(params: {
|
|
44
|
-
mint: anchor.Address;
|
|
45
|
-
source: anchor.Address;
|
|
46
|
-
receiver: string;
|
|
47
|
-
amount: Numeric;
|
|
48
|
-
}): Promise<TransactionPayload>;
|
|
49
|
-
updateZTOkenConfig(params: {
|
|
50
|
-
admin: anchor.Address;
|
|
51
|
-
feeVault: anchor.Address;
|
|
52
|
-
minAmount: Numeric;
|
|
53
|
-
feePercent: number;
|
|
54
|
-
}): Promise<TransactionPayload>;
|
|
55
|
-
emergencyPause(params: {
|
|
56
|
-
admin: anchor.Address;
|
|
57
|
-
}): Promise<TransactionPayload>;
|
|
58
|
-
getZTokenConfigInfo(commitment?: Commitment): Promise<{
|
|
59
|
-
fee: number;
|
|
60
|
-
admin: anchor.web3.PublicKey;
|
|
61
|
-
emergencyPause: boolean;
|
|
62
|
-
feeVault: anchor.web3.PublicKey;
|
|
63
|
-
minAmount: string;
|
|
64
|
-
minttableTokens: anchor.web3.PublicKey[];
|
|
65
|
-
}>;
|
|
66
|
-
}
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ZTokenService = void 0;
|
|
40
|
-
const assert_1 = __importDefault(require("assert"));
|
|
41
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
42
|
-
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
43
|
-
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
|
|
44
|
-
const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
|
|
45
|
-
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
|
46
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
47
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
48
|
-
const core_utils_1 = require("@zebec-network/core-utils");
|
|
49
|
-
const solana_common_1 = require("@zebec-network/solana-common");
|
|
50
|
-
const artifacts_1 = require("../artifacts");
|
|
51
|
-
const pda_1 = require("../pda");
|
|
52
|
-
class ZTokenService {
|
|
53
|
-
provider;
|
|
54
|
-
program;
|
|
55
|
-
constructor(provider, program) {
|
|
56
|
-
this.provider = provider;
|
|
57
|
-
this.program = program;
|
|
58
|
-
}
|
|
59
|
-
static create(provider, network) {
|
|
60
|
-
const connection = provider.connection;
|
|
61
|
-
const rpcEndpoint = connection.rpcEndpoint;
|
|
62
|
-
const connNetwork = rpcEndpoint.includes("devnet")
|
|
63
|
-
? "devnet"
|
|
64
|
-
: rpcEndpoint.includes("testnet")
|
|
65
|
-
? "testnet"
|
|
66
|
-
: "mainnet-beta";
|
|
67
|
-
if (connNetwork === "testnet") {
|
|
68
|
-
throw new Error("InvalidOperation: Testnet is not supported. Please use connection with devnet or mainnet-beta network.");
|
|
69
|
-
}
|
|
70
|
-
if (network !== connNetwork) {
|
|
71
|
-
throw new Error(`InvalidOperation: Network mismatch. network and connection network should be same. network: ${network}, connection: ${connNetwork}`);
|
|
72
|
-
}
|
|
73
|
-
const program = new anchor.Program(artifacts_1.ZEBEC_STREAM_IDL, provider);
|
|
74
|
-
return new ZTokenService(provider, program);
|
|
75
|
-
}
|
|
76
|
-
get programId() {
|
|
77
|
-
return this.program.programId;
|
|
78
|
-
}
|
|
79
|
-
get connection() {
|
|
80
|
-
return this.provider.connection;
|
|
81
|
-
}
|
|
82
|
-
async _createPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
|
|
83
|
-
const errorMap = new Map();
|
|
84
|
-
let signTransaction = undefined;
|
|
85
|
-
const provider = this.provider;
|
|
86
|
-
if (provider instanceof anchor.AnchorProvider) {
|
|
87
|
-
signTransaction = async (tx) => {
|
|
88
|
-
return provider.wallet.signTransaction(tx);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return new solana_common_1.TransactionPayload(this.connection, errorMap, { instructions, feePayer: payerKey, signers, addressLookupTableAccounts }, signTransaction);
|
|
92
|
-
}
|
|
93
|
-
async getInitZTOkenConfigInstruction(admin, feeVault, feeBps, minAmount) {
|
|
94
|
-
return this.program.methods
|
|
95
|
-
.initZtokenConfig({
|
|
96
|
-
fee: feeBps,
|
|
97
|
-
minAmount,
|
|
98
|
-
})
|
|
99
|
-
.accounts({
|
|
100
|
-
feeVault,
|
|
101
|
-
admin,
|
|
102
|
-
})
|
|
103
|
-
.instruction();
|
|
104
|
-
}
|
|
105
|
-
async getMintZTokenInstruction(admin, destination, mint, amount, hash) {
|
|
106
|
-
return this.program.methods
|
|
107
|
-
.mintZtoken({
|
|
108
|
-
amount,
|
|
109
|
-
hash,
|
|
110
|
-
})
|
|
111
|
-
.accounts({
|
|
112
|
-
destination,
|
|
113
|
-
mint,
|
|
114
|
-
admin,
|
|
115
|
-
})
|
|
116
|
-
.instruction();
|
|
117
|
-
}
|
|
118
|
-
async getBurnZTokenInstruction(mint, source, sourceAta, amount, receiver) {
|
|
119
|
-
return this.program.methods
|
|
120
|
-
.burnZtoken({
|
|
121
|
-
amount,
|
|
122
|
-
receiver,
|
|
123
|
-
})
|
|
124
|
-
.accounts({
|
|
125
|
-
mint,
|
|
126
|
-
sourceAta,
|
|
127
|
-
source,
|
|
128
|
-
})
|
|
129
|
-
.instruction();
|
|
130
|
-
}
|
|
131
|
-
async getSetMintableTokensInstruction(admin, tokens) {
|
|
132
|
-
return this.program.methods
|
|
133
|
-
.setMintableTokens({
|
|
134
|
-
tokens,
|
|
135
|
-
})
|
|
136
|
-
.accounts({
|
|
137
|
-
admin,
|
|
138
|
-
})
|
|
139
|
-
.instruction();
|
|
140
|
-
}
|
|
141
|
-
async getUpdateZTokenConfigInstruction(admin, feeVault, feeBps, minAmount) {
|
|
142
|
-
return this.program.methods
|
|
143
|
-
.updateZtokenConfig({
|
|
144
|
-
fee: feeBps,
|
|
145
|
-
feeVault,
|
|
146
|
-
minAmount,
|
|
147
|
-
})
|
|
148
|
-
.accounts({
|
|
149
|
-
admin,
|
|
150
|
-
})
|
|
151
|
-
.instruction();
|
|
152
|
-
}
|
|
153
|
-
async getEmergencyPauseInstruction(admin) {
|
|
154
|
-
return this.program.methods
|
|
155
|
-
.emergencyPause()
|
|
156
|
-
.accounts({
|
|
157
|
-
admin,
|
|
158
|
-
})
|
|
159
|
-
.instruction();
|
|
160
|
-
}
|
|
161
|
-
async createToken(params) {
|
|
162
|
-
const { tokenInfo } = params;
|
|
163
|
-
const connection = new web3_js_1.Connection(this.connection.rpcEndpoint, this.connection.commitment);
|
|
164
|
-
const lamports = await (0, spl_token_1.getMinimumBalanceForRentExemptMint)(connection);
|
|
165
|
-
const mintKeypair = tokenInfo.mintKeypair ?? web3_js_1.Keypair.generate();
|
|
166
|
-
const mint = mintKeypair.publicKey;
|
|
167
|
-
const admin = anchor.translateAddress(params.admin);
|
|
168
|
-
const mintAuthority = admin;
|
|
169
|
-
const updateAuthority = admin;
|
|
170
|
-
const [newMintAuthority] = (0, pda_1.deriveMintAuthoritPda)(this.programId);
|
|
171
|
-
const umi = (0, umi_bundle_defaults_1.createUmi)(this.connection.rpcEndpoint);
|
|
172
|
-
const mplProgramId = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(mpl_token_metadata_1.MPL_TOKEN_METADATA_PROGRAM_ID);
|
|
173
|
-
const [metadata] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), mplProgramId.toBytes(), mint.toBytes()], mplProgramId);
|
|
174
|
-
const args = {
|
|
175
|
-
data: {
|
|
176
|
-
name: tokenInfo.tokenName,
|
|
177
|
-
symbol: tokenInfo.symbol,
|
|
178
|
-
uri: tokenInfo.metadataUri,
|
|
179
|
-
sellerFeeBasisPoints: 0,
|
|
180
|
-
collection: null,
|
|
181
|
-
creators: null,
|
|
182
|
-
uses: null,
|
|
183
|
-
},
|
|
184
|
-
isMutable: true,
|
|
185
|
-
collectionDetails: null,
|
|
186
|
-
};
|
|
187
|
-
// just a work around to create a umi signer from web3Js PublicKey
|
|
188
|
-
// as umi expects a Signer object. only publicKey is used, so others are null.
|
|
189
|
-
const mintAuthoritySigner = {
|
|
190
|
-
publicKey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(mintAuthority),
|
|
191
|
-
signTransaction: null,
|
|
192
|
-
signMessage: null,
|
|
193
|
-
signAllTransactions: null,
|
|
194
|
-
};
|
|
195
|
-
const accounts = {
|
|
196
|
-
metadata: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(metadata),
|
|
197
|
-
mint: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(mint),
|
|
198
|
-
payer: mintAuthoritySigner,
|
|
199
|
-
mintAuthority: mintAuthoritySigner,
|
|
200
|
-
updateAuthority: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(updateAuthority),
|
|
201
|
-
};
|
|
202
|
-
const metadataBuilder = (0, mpl_token_metadata_1.createMetadataAccountV3)(umi, {
|
|
203
|
-
...accounts,
|
|
204
|
-
...args,
|
|
205
|
-
});
|
|
206
|
-
const ix = metadataBuilder.getInstructions()[0];
|
|
207
|
-
const createMetadataInstruction = {
|
|
208
|
-
keys: ix.keys.map((key) => {
|
|
209
|
-
return {
|
|
210
|
-
...key,
|
|
211
|
-
pubkey: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(key.pubkey),
|
|
212
|
-
};
|
|
213
|
-
}),
|
|
214
|
-
data: Buffer.from(ix.data),
|
|
215
|
-
programId: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(ix.programId),
|
|
216
|
-
};
|
|
217
|
-
const setMintableTokenIx = await this.getSetMintableTokensInstruction(admin, [mint]);
|
|
218
|
-
const ixs = [
|
|
219
|
-
web3_js_1.SystemProgram.createAccount({
|
|
220
|
-
fromPubkey: mintAuthority,
|
|
221
|
-
newAccountPubkey: mint,
|
|
222
|
-
space: spl_token_1.MINT_SIZE,
|
|
223
|
-
lamports: lamports,
|
|
224
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
225
|
-
}),
|
|
226
|
-
(0, spl_token_1.createInitializeMintInstruction)(mint, tokenInfo.decimals, mintAuthority, null, spl_token_1.TOKEN_PROGRAM_ID),
|
|
227
|
-
createMetadataInstruction,
|
|
228
|
-
(0, spl_token_1.createSetAuthorityInstruction)(mint, mintAuthority, spl_token_1.AuthorityType.MintTokens, // authority type
|
|
229
|
-
newMintAuthority),
|
|
230
|
-
setMintableTokenIx,
|
|
231
|
-
];
|
|
232
|
-
return this._createPayload(admin, ixs, [mintKeypair]);
|
|
233
|
-
}
|
|
234
|
-
async initZTOkenConfig(params) {
|
|
235
|
-
const admin = anchor.translateAddress(params.admin);
|
|
236
|
-
const feeVault = anchor.translateAddress(params.feeVault);
|
|
237
|
-
const feeBps = Number((0, core_utils_1.percentToBps)(params.feePercent));
|
|
238
|
-
const minAmount = new anchor.BN(params.minAmount);
|
|
239
|
-
const ix = await this.getInitZTOkenConfigInstruction(admin, feeVault, feeBps, minAmount);
|
|
240
|
-
return this._createPayload(admin, [ix]);
|
|
241
|
-
}
|
|
242
|
-
async mintZToken(params) {
|
|
243
|
-
const [config] = (0, pda_1.deriveZTokenConfigPda)(this.programId);
|
|
244
|
-
const configAccount = await this.program.account.ztoken.fetch(config);
|
|
245
|
-
const admin = anchor.translateAddress(params.admin);
|
|
246
|
-
(0, assert_1.default)(admin.equals(configAccount.admin), "Invalid admin address");
|
|
247
|
-
const destination = anchor.translateAddress(params.destination);
|
|
248
|
-
const mint = anchor.translateAddress(params.mint);
|
|
249
|
-
(0, assert_1.default)(params.hash.length == 32, "Invalid hash provided. Required 32 byte hash buffer");
|
|
250
|
-
const mintDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, mint);
|
|
251
|
-
const amount = new anchor.BN((0, bignumber_js_1.BigNumber)(params.amount).times(solana_common_1.TEN_BIGNUM.pow(mintDecimals)).toFixed());
|
|
252
|
-
const ix = await this.getMintZTokenInstruction(admin, destination, mint, amount, Array.from(params.hash));
|
|
253
|
-
return this._createPayload(admin, [ix]);
|
|
254
|
-
}
|
|
255
|
-
async burnZToken(params) {
|
|
256
|
-
const mint = anchor.translateAddress(params.mint);
|
|
257
|
-
const source = anchor.translateAddress(params.source);
|
|
258
|
-
const sourceAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, source, true);
|
|
259
|
-
const mintDecimals = await (0, solana_common_1.getMintDecimals)(this.connection, mint);
|
|
260
|
-
const amount = new anchor.BN((0, bignumber_js_1.BigNumber)(params.amount).times(solana_common_1.TEN_BIGNUM.pow(mintDecimals)).toFixed(0));
|
|
261
|
-
const ix = await this.getBurnZTokenInstruction(mint, source, sourceAta, amount, params.receiver);
|
|
262
|
-
return this._createPayload(source, [ix]);
|
|
263
|
-
}
|
|
264
|
-
async updateZTOkenConfig(params) {
|
|
265
|
-
const admin = anchor.translateAddress(params.admin);
|
|
266
|
-
const feeVault = anchor.translateAddress(params.feeVault);
|
|
267
|
-
const feeBps = Number((0, core_utils_1.percentToBps)(params.feePercent));
|
|
268
|
-
const minAmount = new anchor.BN(params.minAmount);
|
|
269
|
-
const ix = await this.getUpdateZTokenConfigInstruction(admin, feeVault, feeBps, minAmount);
|
|
270
|
-
return this._createPayload(admin, [ix]);
|
|
271
|
-
}
|
|
272
|
-
async emergencyPause(params) {
|
|
273
|
-
const admin = anchor.translateAddress(params.admin);
|
|
274
|
-
const ix = await this.getEmergencyPauseInstruction(admin);
|
|
275
|
-
return this._createPayload(admin, [ix]);
|
|
276
|
-
}
|
|
277
|
-
async getZTokenConfigInfo(commitment) {
|
|
278
|
-
const [config] = (0, pda_1.deriveZTokenConfigPda)(this.programId);
|
|
279
|
-
const configAccount = await this.program.account.ztoken.fetch(config, commitment ?? this.connection.commitment);
|
|
280
|
-
return {
|
|
281
|
-
fee: Number((0, core_utils_1.bpsToPercent)(configAccount.fee)),
|
|
282
|
-
admin: configAccount.admin,
|
|
283
|
-
emergencyPause: configAccount.emergencyPause,
|
|
284
|
-
feeVault: configAccount.feeVault,
|
|
285
|
-
minAmount: configAccount.minAmount.toString(),
|
|
286
|
-
minttableTokens: configAccount.mintableTokens,
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
exports.ZTokenService = ZTokenService;
|