@kynesyslabs/demosdk 1.0.28 → 1.0.29
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/build/multichain/core/solana.d.ts +12 -4
- package/build/multichain/core/solana.js +96 -3
- package/build/multichain/core/solana.js.map +1 -1
- package/build/multichain/core/types/defaultChain.d.ts +18 -2
- package/build/multichain/core/types/defaultChain.js +3 -3
- package/build/multichain/core/types/defaultChain.js.map +1 -1
- package/build/multichain/core/types/interfaces.d.ts +80 -2
- package/package.json +4 -2
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Address, Idl } from "@project-serum/anchor";
|
|
3
|
+
import { Connection, Keypair, VersionedTransaction } from "@solana/web3.js";
|
|
4
|
+
import { DefaultChain, SolanaDefaultChain } from "./types/defaultChain";
|
|
5
|
+
import { IPayOptions, SolanaReadAccountDataOptions, SolanaRunRawProgramParams, SolanarunProgramParams } from "./types/interfaces";
|
|
4
6
|
interface SignTxOptions {
|
|
5
7
|
/**
|
|
6
8
|
* The private key to sign the transaction with, instead of the connected wallet.
|
|
7
9
|
*/
|
|
8
10
|
privateKey?: string;
|
|
9
11
|
}
|
|
10
|
-
export declare class SOLANA extends DefaultChain {
|
|
12
|
+
export declare class SOLANA extends DefaultChain implements SolanaDefaultChain {
|
|
11
13
|
private static instance;
|
|
12
14
|
wallet: Keypair;
|
|
13
15
|
provider: Connection;
|
|
@@ -29,6 +31,12 @@ export declare class SOLANA extends DefaultChain {
|
|
|
29
31
|
preparePays(payments: IPayOptions[], options?: SignTxOptions): Promise<Uint8Array[]>;
|
|
30
32
|
prepareTransfer(receiver: string, amount: string, options?: SignTxOptions): Promise<Uint8Array>;
|
|
31
33
|
prepareTransfers(transfers: IPayOptions[], options?: SignTxOptions): Promise<Uint8Array[]>;
|
|
34
|
+
getProgramIdl(programId: Address): Promise<Idl>;
|
|
35
|
+
fetchAccount(address: Address, options: SolanaReadAccountDataOptions): Promise<{
|
|
36
|
+
[x: string]: any;
|
|
37
|
+
}>;
|
|
38
|
+
runAnchorProgram(programId: string, params: SolanarunProgramParams): Promise<Buffer>;
|
|
39
|
+
runRawProgram(programId: Address, params: SolanaRunRawProgramParams): Promise<Buffer>;
|
|
32
40
|
static getInstance(): SOLANA | boolean;
|
|
33
41
|
static createInstance(rpc_url: string): SOLANA;
|
|
34
42
|
}
|
|
@@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SOLANA = void 0;
|
|
7
|
-
const
|
|
7
|
+
const anchor_1 = require("@project-serum/anchor");
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
-
const
|
|
9
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
10
10
|
const defaultChain_1 = require("./types/defaultChain");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const buffer_layout_1 = require("@solana/buffer-layout");
|
|
11
13
|
class SOLANA extends defaultChain_1.DefaultChain {
|
|
12
14
|
constructor(rpc_url) {
|
|
13
15
|
super(rpc_url);
|
|
@@ -15,7 +17,7 @@ class SOLANA extends defaultChain_1.DefaultChain {
|
|
|
15
17
|
}
|
|
16
18
|
async connect() {
|
|
17
19
|
this.provider = new web3_js_1.Connection(this.rpc_url, {
|
|
18
|
-
confirmTransactionInitialTimeout:
|
|
20
|
+
confirmTransactionInitialTimeout: 15000,
|
|
19
21
|
});
|
|
20
22
|
const version = await this.provider.getVersion();
|
|
21
23
|
this.connected = Number.isInteger(version["feature-set"]);
|
|
@@ -108,6 +110,97 @@ class SOLANA extends defaultChain_1.DefaultChain {
|
|
|
108
110
|
async prepareTransfers(transfers, options) {
|
|
109
111
|
return await this.preparePays(transfers, options);
|
|
110
112
|
}
|
|
113
|
+
// SECTION: Programs
|
|
114
|
+
async getProgramIdl(programId) {
|
|
115
|
+
const provider = {
|
|
116
|
+
connection: this.provider,
|
|
117
|
+
};
|
|
118
|
+
return await anchor_1.Program.fetchIdl(programId, provider);
|
|
119
|
+
}
|
|
120
|
+
async fetchAccount(address, options) {
|
|
121
|
+
let programId = options.programId;
|
|
122
|
+
let idl = options.idl;
|
|
123
|
+
if (!programId) {
|
|
124
|
+
// INFO: Fetch the program ID from the account
|
|
125
|
+
const accInfo = await this.provider.getAccountInfo(new web3_js_1.PublicKey(address));
|
|
126
|
+
programId = accInfo.owner;
|
|
127
|
+
}
|
|
128
|
+
if (!idl) {
|
|
129
|
+
// INFO: Fetch the IDL from the network
|
|
130
|
+
idl = await this.getProgramIdl(options.programId);
|
|
131
|
+
}
|
|
132
|
+
const program = new anchor_1.Program(idl, programId, {
|
|
133
|
+
connection: this.provider,
|
|
134
|
+
});
|
|
135
|
+
return await program.account[options.name].fetch(address);
|
|
136
|
+
}
|
|
137
|
+
async runAnchorProgram(programId, params) {
|
|
138
|
+
// REVIEW: Do we need to connect our wallet with the anchor provider?
|
|
139
|
+
const wallet = new anchor_1.Wallet(this.wallet);
|
|
140
|
+
const pid = new web3_js_1.PublicKey(programId);
|
|
141
|
+
const anchorProvider = new anchor_1.AnchorProvider(this.provider, wallet, {});
|
|
142
|
+
let idl = params.idl;
|
|
143
|
+
if (!idl) {
|
|
144
|
+
// INFO: If not using manual IDL, fetch it from the network
|
|
145
|
+
idl = await this.getProgramIdl(programId);
|
|
146
|
+
}
|
|
147
|
+
if (!idl) {
|
|
148
|
+
// INFO: If no IDL is found, throw an error
|
|
149
|
+
throw new Error("No IDL found for this program");
|
|
150
|
+
}
|
|
151
|
+
// INFO: Get the IDL and create program interface
|
|
152
|
+
const program = new anchor_1.Program(idl, pid, anchorProvider);
|
|
153
|
+
// INFO: construct the transaction
|
|
154
|
+
const ix = program.methods[params.instruction];
|
|
155
|
+
// calling the method with undefined throws an error, so prevent it
|
|
156
|
+
const _ix = params.args ? ix(params.args) : ix();
|
|
157
|
+
const tx = await _ix
|
|
158
|
+
.accounts(params.accounts)
|
|
159
|
+
// .signers(params.signers)
|
|
160
|
+
.transaction();
|
|
161
|
+
// INFO: Add fee payer and validity data
|
|
162
|
+
tx.feePayer = params.feePayer;
|
|
163
|
+
const block = await this.provider.getLatestBlockhash();
|
|
164
|
+
tx.recentBlockhash = block.blockhash;
|
|
165
|
+
tx.lastValidBlockHeight = block.lastValidBlockHeight;
|
|
166
|
+
// INFO: Sign and return the tx
|
|
167
|
+
tx.sign(...params.signers);
|
|
168
|
+
return tx.serialize();
|
|
169
|
+
}
|
|
170
|
+
async runRawProgram(programId, params) {
|
|
171
|
+
// INFO: Set fee payer
|
|
172
|
+
const tx = new web3_js_1.Transaction({
|
|
173
|
+
feePayer: params.feePayer,
|
|
174
|
+
});
|
|
175
|
+
// INFO: Locate the instruction
|
|
176
|
+
const ix = {
|
|
177
|
+
index: params.instructionIndex,
|
|
178
|
+
// @ts-expect-error
|
|
179
|
+
layout: (0, buffer_layout_1.struct)([(0, buffer_layout_1.u32)("instruction"), (0, buffer_layout_1.ns64)(params.instructionName)]),
|
|
180
|
+
};
|
|
181
|
+
// INFO: Encode the instruction and its parameters
|
|
182
|
+
// Create an empty buffer
|
|
183
|
+
let data = Buffer.alloc(ix.layout.span);
|
|
184
|
+
let layoutFields = Object.assign({
|
|
185
|
+
instruction: ix.index,
|
|
186
|
+
}, params.params);
|
|
187
|
+
// Write the data to the buffer
|
|
188
|
+
ix.layout.encode(layoutFields, data);
|
|
189
|
+
// INFO: Add the instruction to the transaction
|
|
190
|
+
tx.add(new web3_js_1.TransactionInstruction({
|
|
191
|
+
keys: params.keys,
|
|
192
|
+
programId: new web3_js_1.PublicKey(programId),
|
|
193
|
+
data: data,
|
|
194
|
+
}));
|
|
195
|
+
// INFO: Add validity information
|
|
196
|
+
const block = await this.provider.getLatestBlockhash();
|
|
197
|
+
tx.recentBlockhash = block.blockhash;
|
|
198
|
+
tx.lastValidBlockHeight = block.lastValidBlockHeight;
|
|
199
|
+
// INFO: Sign and return the transaction
|
|
200
|
+
tx.sign(...params.signers);
|
|
201
|
+
return tx.serialize();
|
|
202
|
+
}
|
|
203
|
+
// SECTION: Singleton methods
|
|
111
204
|
static getInstance() {
|
|
112
205
|
if (!SOLANA.instance) {
|
|
113
206
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solana.js","sourceRoot":"","sources":["../../../../src/multichain/core/solana.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAyB;
|
|
1
|
+
{"version":3,"file":"solana.js","sourceRoot":"","sources":["../../../../src/multichain/core/solana.ts"],"names":[],"mappings":";;;;;;AAAA,kDAM8B;AAC9B,6CAUwB;AACxB,gDAAyB;AAEzB,uDAAuE;AAOvE,mCAAkC;AAClC,yDAAyD;AAuBzD,MAAa,MAAO,SAAQ,2BAAY;IAMpC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,OAAO;QACT,IAAI,CAAC,QAAQ,GAAG,IAAI,oBAAU,CAAC,IAAI,CAAC,OAAO,EAAE;YACzC,gCAAgC,EAAE,KAAK;SAC1C,CAAC,CAAA;QAEF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;QAChD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;QAEzD,OAAO,IAAI,CAAC,SAAS,CAAA;IACzB,CAAC;IAED,KAAK,CAAC,UAAU;QACZ,IAAI,CAAC,aAAa,EAAE,CAAA;QACpB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK,CAAC,YAAY;QACd,MAAM,OAAO,GAAG,iBAAO,CAAC,QAAQ,EAAE,CAAA;QAElC,OAAO;YACH,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC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Q,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAA;QACzC,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,CAAA;IAC1B,CAAC;CACJ;AA3RD,wBA2RC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Address, Idl } from "@project-serum/anchor";
|
|
2
|
+
import { Contract, TransactionReceipt } from "ethers";
|
|
3
|
+
import { IBCConnectWalletOptions, IPayOptions, SolanaReadAccountDataOptions, XmTransactionResponse } from "./interfaces";
|
|
3
4
|
export declare abstract class DefaultChain {
|
|
4
5
|
provider: any;
|
|
5
6
|
name: string;
|
|
@@ -151,3 +152,18 @@ export interface IBCDefaultChain extends DefaultChain {
|
|
|
151
152
|
connectWallet(privateKey: string, options: IBCConnectWalletOptions): Promise<any>;
|
|
152
153
|
ibcSend: () => Promise<any>;
|
|
153
154
|
}
|
|
155
|
+
export interface SolanaDefaultChain extends DefaultChain {
|
|
156
|
+
/**
|
|
157
|
+
* Fetch the IDL from the network
|
|
158
|
+
* @param programId The program address
|
|
159
|
+
* @returns The IDL of the program
|
|
160
|
+
*/
|
|
161
|
+
getProgramIdl: (programId: string) => Promise<Idl>;
|
|
162
|
+
/**
|
|
163
|
+
* Fetch the deserialized account from the network
|
|
164
|
+
* @param address The program address
|
|
165
|
+
* @param options Options
|
|
166
|
+
* @returns The account data
|
|
167
|
+
*/
|
|
168
|
+
fetchAccount: (address: Address, options: SolanaReadAccountDataOptions) => Promise<any>;
|
|
169
|
+
}
|
|
@@ -8,10 +8,10 @@ class DefaultChain {
|
|
|
8
8
|
// as we cannot use await in the constructor
|
|
9
9
|
constructor(rpc_url) {
|
|
10
10
|
this.provider = null;
|
|
11
|
-
this.name =
|
|
11
|
+
this.name = "";
|
|
12
12
|
this.signer = null;
|
|
13
13
|
this.wallet = null;
|
|
14
|
-
this.rpc_url =
|
|
14
|
+
this.rpc_url = "";
|
|
15
15
|
this.connected = false;
|
|
16
16
|
this.setRpc(rpc_url);
|
|
17
17
|
}
|
|
@@ -27,7 +27,7 @@ class DefaultChain {
|
|
|
27
27
|
* @param rpc_url The RPC URL
|
|
28
28
|
* @returns The sdk instance connected to the RPC provider
|
|
29
29
|
*/
|
|
30
|
-
static async create(rpc_url =
|
|
30
|
+
static async create(rpc_url = "") {
|
|
31
31
|
const instance = new this(rpc_url);
|
|
32
32
|
instance.setRpc(rpc_url);
|
|
33
33
|
if (rpc_url) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultChain.js","sourceRoot":"","sources":["../../../../../src/multichain/core/types/defaultChain.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"defaultChain.js","sourceRoot":"","sources":["../../../../../src/multichain/core/types/defaultChain.ts"],"names":[],"mappings":";;;AASA,MAAsB,YAAY;IAQ9B,sDAAsD;IACtD,6DAA6D;IAC7D,wDAAwD;IACxD,4CAA4C;IAC5C,YAAY,OAAe;QAX3B,aAAQ,GAAQ,IAAI,CAAA;QACpB,SAAI,GAAW,EAAE,CAAA;QACjB,WAAM,GAAQ,IAAI,CAAA;QAClB,WAAM,GAAQ,IAAI,CAAA;QAClB,YAAO,GAAW,EAAE,CAAA;QACpB,cAAS,GAAY,KAAK,CAAA;QAOtB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACxB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAe;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAEf,UAAkB,EAAE;QAEpB,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAA;QAClC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAExB,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAA;QAC5B,CAAC;QAED,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED;;OAEG;IACO,aAAa;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;IAC1B,CAAC;CA6GJ;AAhKD,oCAgKC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { MsgSendEncodeObject, StdFee } from
|
|
1
|
+
import { MsgSendEncodeObject, StdFee } from "@cosmjs/stargate";
|
|
2
|
+
import { Address, Idl } from "@project-serum/anchor";
|
|
3
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
2
4
|
/**
|
|
3
5
|
* `preparePay` parameters
|
|
4
6
|
*/
|
|
@@ -13,7 +15,7 @@ export interface XmTransactionResponse {
|
|
|
13
15
|
/**
|
|
14
16
|
* Whether the transaction was successful or not
|
|
15
17
|
*/
|
|
16
|
-
result:
|
|
18
|
+
result: "success" | "error";
|
|
17
19
|
/**
|
|
18
20
|
* The hash of the transaction if the tx was successful
|
|
19
21
|
*/
|
|
@@ -80,3 +82,79 @@ export interface IBCSignTxOptions extends IBCConnectWalletOptions {
|
|
|
80
82
|
*/
|
|
81
83
|
privateKey?: string;
|
|
82
84
|
}
|
|
85
|
+
export interface SolanarunProgramParams {
|
|
86
|
+
/**
|
|
87
|
+
* The IDL of the program to call. If not provided, the IDL will be fetched from the network.
|
|
88
|
+
*/
|
|
89
|
+
idl?: Idl | {
|
|
90
|
+
[key: string]: any;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The name of the instruction to call.
|
|
94
|
+
*/
|
|
95
|
+
instruction: string;
|
|
96
|
+
/**
|
|
97
|
+
* The arguments to pass to the instruction.
|
|
98
|
+
*/
|
|
99
|
+
args?: any;
|
|
100
|
+
/**
|
|
101
|
+
* The accounts to pass to the instruction.
|
|
102
|
+
*/
|
|
103
|
+
accounts?: {
|
|
104
|
+
[key: string]: PublicKey | string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* The fee payer of the transaction.
|
|
108
|
+
*/
|
|
109
|
+
feePayer: PublicKey;
|
|
110
|
+
/**
|
|
111
|
+
* Private keys to sign this transaction.
|
|
112
|
+
*/
|
|
113
|
+
signers?: Keypair[];
|
|
114
|
+
}
|
|
115
|
+
export interface SolanaReadAccountDataOptions {
|
|
116
|
+
/**
|
|
117
|
+
* The IDL of the program to read from. If not provided, the IDL will be fetched from the network.
|
|
118
|
+
*/
|
|
119
|
+
idl?: Idl | {
|
|
120
|
+
[key: string]: any;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* The name of the account to read from the program IDL.
|
|
124
|
+
*/
|
|
125
|
+
name: string;
|
|
126
|
+
/**
|
|
127
|
+
* The account's assigned program Id. If not provided, the account's owner will be fetched from the network.
|
|
128
|
+
*/
|
|
129
|
+
programId?: Address;
|
|
130
|
+
}
|
|
131
|
+
export interface SolanaRunRawProgramParams {
|
|
132
|
+
/**
|
|
133
|
+
* The instruction to call.
|
|
134
|
+
*/
|
|
135
|
+
instructionName: string;
|
|
136
|
+
/**
|
|
137
|
+
* The index of the instruction on the program definition
|
|
138
|
+
*/
|
|
139
|
+
instructionIndex: number;
|
|
140
|
+
/**
|
|
141
|
+
* The accounts required for this instruction
|
|
142
|
+
*/
|
|
143
|
+
keys?: {
|
|
144
|
+
pubkey: PublicKey;
|
|
145
|
+
isSigner: boolean;
|
|
146
|
+
isWritable: boolean;
|
|
147
|
+
}[];
|
|
148
|
+
/**
|
|
149
|
+
* The parameters required by the instruction
|
|
150
|
+
*/
|
|
151
|
+
params?: any;
|
|
152
|
+
/**
|
|
153
|
+
* Private keys to sign this transaction.
|
|
154
|
+
*/
|
|
155
|
+
signers: Keypair[];
|
|
156
|
+
/**
|
|
157
|
+
* The fee payer of the transaction
|
|
158
|
+
*/
|
|
159
|
+
feePayer: PublicKey;
|
|
160
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kynesyslabs/demosdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "build/index.d.ts",
|
|
6
6
|
"author": "Kynesys Labs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "rm -rf build && tsc --skipLibCheck && resolve-tspaths && mv build/src/* build/ && rm -rf build/src",
|
|
21
21
|
"publish": "yarn npm publish",
|
|
22
|
-
"test:multichain": "rm -rf build && jest --testMatch '**/tests
|
|
22
|
+
"test:multichain": "rm -rf build && jest --testMatch '**/tests/**/sol*.ts' --testPathIgnorePatterns **/tests/**/chainProvider* **/tests/utils/* **/tests/**/template* --verbose"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@cosmjs/proto-signing": "^0.32.3",
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"@multiversx/sdk-extension-provider": "^3.0.0",
|
|
29
29
|
"@multiversx/sdk-network-providers": "^2.4.3",
|
|
30
30
|
"@multiversx/sdk-wallet": "^4.4.0",
|
|
31
|
+
"@project-serum/anchor": "^0.26.0",
|
|
32
|
+
"@solana/buffer-layout": "^4.0.1",
|
|
31
33
|
"@solana/web3.js": "^1.91.7",
|
|
32
34
|
"@types/rijndael-js": "^1.0.2",
|
|
33
35
|
"@types/terminal-kit": "^2.5.6",
|