@kynesyslabs/demosdk 2.3.28 → 2.4.1
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/abstraction/Identities.d.ts +10 -1
- package/build/abstraction/Identities.js +34 -4
- package/build/abstraction/Identities.js.map +1 -1
- package/build/contracts/ContractDeployer.d.ts +34 -0
- package/build/contracts/ContractDeployer.js +196 -0
- package/build/contracts/ContractDeployer.js.map +1 -0
- package/build/contracts/ContractFactory.d.ts +52 -0
- package/build/contracts/ContractFactory.js +98 -0
- package/build/contracts/ContractFactory.js.map +1 -0
- package/build/contracts/ContractInstance.d.ts +51 -0
- package/build/contracts/ContractInstance.js +138 -0
- package/build/contracts/ContractInstance.js.map +1 -0
- package/build/contracts/ContractInteractor.d.ts +55 -0
- package/build/contracts/ContractInteractor.js +242 -0
- package/build/contracts/ContractInteractor.js.map +1 -0
- package/build/contracts/index.d.ts +9 -0
- package/build/contracts/index.js +16 -0
- package/build/contracts/index.js.map +1 -0
- package/build/contracts/templates/TemplateRegistry.d.ts +71 -0
- package/build/contracts/templates/TemplateRegistry.js +404 -0
- package/build/contracts/templates/TemplateRegistry.js.map +1 -0
- package/build/contracts/templates/TemplateValidator.d.ts +55 -0
- package/build/contracts/templates/TemplateValidator.js +202 -0
- package/build/contracts/templates/TemplateValidator.js.map +1 -0
- package/build/contracts/types/ContractABI.d.ts +111 -0
- package/build/contracts/types/ContractABI.js +6 -0
- package/build/contracts/types/ContractABI.js.map +1 -0
- package/build/contracts/types/TypedContract.d.ts +34 -0
- package/build/contracts/types/TypedContract.js +6 -0
- package/build/contracts/types/TypedContract.js.map +1 -0
- package/build/types/abstraction/index.d.ts +7 -1
- package/build/types/web2/discord.d.ts +8 -0
- package/build/types/web2/discord.js +3 -0
- package/build/types/web2/discord.js.map +1 -0
- package/build/websdk/DemosContracts.d.ts +140 -0
- package/build/websdk/DemosContracts.js +185 -0
- package/build/websdk/DemosContracts.js.map +1 -0
- package/build/websdk/demosclass.d.ts +6 -0
- package/build/websdk/demosclass.js +5 -0
- package/build/websdk/demosclass.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { XMCoreTargetIdentityPayload, Web2CoreTargetIdentityPayload, GithubProof, TwitterProof, InferFromSignaturePayload } from "../types/abstraction";
|
|
1
|
+
import { XMCoreTargetIdentityPayload, Web2CoreTargetIdentityPayload, GithubProof, TwitterProof, InferFromSignaturePayload, DiscordProof } from "../types/abstraction";
|
|
2
2
|
import { Demos } from "../websdk/demosclass";
|
|
3
3
|
import { PQCAlgorithm } from "../types/cryptography";
|
|
4
4
|
import { RPCResponseWithValidityData } from "../types";
|
|
@@ -7,6 +7,7 @@ export declare class Identities {
|
|
|
7
7
|
web2: {
|
|
8
8
|
github: string[];
|
|
9
9
|
twitter: string[];
|
|
10
|
+
discord: string[];
|
|
10
11
|
};
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
@@ -86,6 +87,14 @@ export declare class Identities {
|
|
|
86
87
|
* @returns The response from the RPC call.
|
|
87
88
|
*/
|
|
88
89
|
addTwitterIdentity(demos: Demos, payload: TwitterProof, referralCode?: string): Promise<RPCResponseWithValidityData>;
|
|
90
|
+
/**
|
|
91
|
+
* Add a discord identity to the GCR.
|
|
92
|
+
*
|
|
93
|
+
* @param demos A Demos instance to communicate with the RPC.
|
|
94
|
+
* @param payload The payload to add the identity to.
|
|
95
|
+
* @returns The response from the RPC call.
|
|
96
|
+
*/
|
|
97
|
+
addDiscordIdentity(demos: Demos, payload: DiscordProof, referralCode?: string): Promise<RPCResponseWithValidityData>;
|
|
89
98
|
bindPqcIdentity(demos: Demos, algorithms?: "all" | PQCAlgorithm[]): Promise<RPCResponseWithValidityData>;
|
|
90
99
|
removePqcIdentity(demos: Demos, algorithms?: "all" | PQCAlgorithm[]): Promise<RPCResponseWithValidityData>;
|
|
91
100
|
/**
|
|
@@ -19,6 +19,10 @@ class Identities {
|
|
|
19
19
|
"https://gist.githubusercontent.com",
|
|
20
20
|
],
|
|
21
21
|
twitter: ["https://x.com", "https://twitter.com"],
|
|
22
|
+
discord: [
|
|
23
|
+
"https://discord.com/channels",
|
|
24
|
+
"https://ptb.discord.com/channels",
|
|
25
|
+
],
|
|
22
26
|
},
|
|
23
27
|
};
|
|
24
28
|
}
|
|
@@ -110,7 +114,10 @@ class Identities {
|
|
|
110
114
|
* @returns The validity data of the identity transaction.
|
|
111
115
|
*/
|
|
112
116
|
async inferXmIdentity(demos, payload, referralCode) {
|
|
113
|
-
return await this.inferIdentity(demos, "xm", {
|
|
117
|
+
return await this.inferIdentity(demos, "xm", {
|
|
118
|
+
...payload,
|
|
119
|
+
referralCode: referralCode,
|
|
120
|
+
});
|
|
114
121
|
}
|
|
115
122
|
/**
|
|
116
123
|
* Infer a web2 identity from a proof payload.
|
|
@@ -189,6 +196,31 @@ class Identities {
|
|
|
189
196
|
};
|
|
190
197
|
return await this.inferIdentity(demos, "web2", twitterPayload);
|
|
191
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Add a discord identity to the GCR.
|
|
201
|
+
*
|
|
202
|
+
* @param demos A Demos instance to communicate with the RPC.
|
|
203
|
+
* @param payload The payload to add the identity to.
|
|
204
|
+
* @returns The response from the RPC call.
|
|
205
|
+
*/
|
|
206
|
+
async addDiscordIdentity(demos, payload, referralCode) {
|
|
207
|
+
const data = await demos.web2.getDiscordMessage(payload);
|
|
208
|
+
if (!data.success) {
|
|
209
|
+
throw new Error(data.error);
|
|
210
|
+
}
|
|
211
|
+
const msg = data.message;
|
|
212
|
+
if (!msg.authorId || !msg.authorUsername) {
|
|
213
|
+
throw new Error("Unable to get discord user info. Please try again.");
|
|
214
|
+
}
|
|
215
|
+
const discordPayload = {
|
|
216
|
+
context: "discord",
|
|
217
|
+
proof: payload,
|
|
218
|
+
username: msg.authorUsername,
|
|
219
|
+
userId: msg.authorId,
|
|
220
|
+
referralCode: referralCode,
|
|
221
|
+
};
|
|
222
|
+
return await this.inferIdentity(demos, "web2", discordPayload);
|
|
223
|
+
}
|
|
192
224
|
// SECTION: PQC Identities
|
|
193
225
|
async bindPqcIdentity(demos, algorithms = "all") {
|
|
194
226
|
let addressTypes = [];
|
|
@@ -337,9 +369,7 @@ class Identities {
|
|
|
337
369
|
}
|
|
338
370
|
const request = {
|
|
339
371
|
method: "gcr_routine",
|
|
340
|
-
params: [
|
|
341
|
-
{ method: "getReferralInfo", params: [address] },
|
|
342
|
-
],
|
|
372
|
+
params: [{ method: "getReferralInfo", params: [address] }],
|
|
343
373
|
};
|
|
344
374
|
return await demos.rpcCall(request, true);
|
|
345
375
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Identities.js","sourceRoot":"","sources":["../../../src/abstraction/Identities.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,8EAA8E;;;;;;AAE9E,kDAAyB;
|
|
1
|
+
{"version":3,"file":"Identities.js","sourceRoot":"","sources":["../../../src/abstraction/Identities.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,8EAA8E;;;;;;AAE9E,kDAAyB;AAiBzB,6CAA6D;AAC7D,qCAAmE;AAEnE,MAAa,UAAU;IAAvB;QACI,YAAO,GAAG;YACN,IAAI,EAAE;gBACF,MAAM,EAAE;oBACJ,yBAAyB;oBACzB,mCAAmC;oBACnC,oCAAoC;iBACvC;gBACD,OAAO,EAAE,CAAC,eAAe,EAAE,qBAAqB,CAAC;gBACjD,OAAO,EAAE;oBACL,8BAA8B;oBAC9B,kCAAkC;iBACrC;aACJ;SACJ,CAAA;IA0eL,CAAC;IAxeG;;;;;OAKG;IACH,KAAK,CAAC,sBAAsB,CAAC,KAAY;QACrC,MAAM,OAAO,GAAG,MAAM,CAAA;QACtB,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CACrC,KAAK,CAAC,SAAS,EACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CACpC,CAAA;QAED,OAAO,S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rB,MAAM,EAAE;gBACJ,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE;aAC7D;SACJ,CAAA;QAED,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,KAAY,EAAE,OAAgB;QAChD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,GAAG,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAA;QAC7C,CAAC;QAED,MAAM,OAAO,GAAG;YACZ,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;SAC7D,CAAA;QAED,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,2BAA2B,CAAC,KAAY,EAAE,QAAgB;QAC5D,MAAM,OAAO,GAAG;YACZ,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE;gBACJ,EAAE,MAAM,EAAE,6BAA6B,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE;aAChE;SACJ,CAAA;QAED,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;CACJ;AAxfD,gCAwfC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract deployment functionality for Demos SDK
|
|
3
|
+
*/
|
|
4
|
+
import { Demos } from '../websdk/demosclass';
|
|
5
|
+
import { ContractDeploymentResult, ContractDeployOptions } from './types/ContractABI';
|
|
6
|
+
import { ContractInstance } from './ContractInstance';
|
|
7
|
+
export declare class ContractDeployer {
|
|
8
|
+
private demos;
|
|
9
|
+
constructor(demos: Demos);
|
|
10
|
+
/**
|
|
11
|
+
* Deploy a new smart contract
|
|
12
|
+
* @param source TypeScript source code of the contract
|
|
13
|
+
* @param constructorArgs Arguments for the contract constructor
|
|
14
|
+
* @param options Deployment options
|
|
15
|
+
* @returns Deployment result with contract address
|
|
16
|
+
*/
|
|
17
|
+
deploy(source: string, constructorArgs?: any[], options?: ContractDeployOptions): Promise<ContractDeploymentResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Deploy a contract and return an instance wrapper
|
|
20
|
+
*/
|
|
21
|
+
deployAndWrap<T = any>(source: string, constructorArgs?: any[], options?: ContractDeployOptions): Promise<ContractInstance<T>>;
|
|
22
|
+
/**
|
|
23
|
+
* Validate contract source code
|
|
24
|
+
*/
|
|
25
|
+
private validateSourceCode;
|
|
26
|
+
/**
|
|
27
|
+
* Build deployment transaction
|
|
28
|
+
*/
|
|
29
|
+
private buildDeployTransaction;
|
|
30
|
+
/**
|
|
31
|
+
* Wait for contract deployment confirmation
|
|
32
|
+
*/
|
|
33
|
+
private waitForDeployment;
|
|
34
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Contract deployment functionality for Demos SDK
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ContractDeployer = void 0;
|
|
40
|
+
const ContractInstance_1 = require("./ContractInstance");
|
|
41
|
+
const unifiedCrypto_1 = require("../encryption/unifiedCrypto");
|
|
42
|
+
const skeletons = __importStar(require("../websdk/utils/skeletons"));
|
|
43
|
+
class ContractDeployer {
|
|
44
|
+
constructor(demos) {
|
|
45
|
+
this.demos = demos;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Deploy a new smart contract
|
|
49
|
+
* @param source TypeScript source code of the contract
|
|
50
|
+
* @param constructorArgs Arguments for the contract constructor
|
|
51
|
+
* @param options Deployment options
|
|
52
|
+
* @returns Deployment result with contract address
|
|
53
|
+
*/
|
|
54
|
+
async deploy(source, constructorArgs = [], options = {}) {
|
|
55
|
+
try {
|
|
56
|
+
// Validate wallet connection
|
|
57
|
+
if (!this.demos.walletConnected) {
|
|
58
|
+
throw new Error('Wallet not connected. Please connect a wallet first.');
|
|
59
|
+
}
|
|
60
|
+
// Validate source code
|
|
61
|
+
if (options.validateSource !== false) {
|
|
62
|
+
this.validateSourceCode(source);
|
|
63
|
+
}
|
|
64
|
+
// Prepare deployment payload
|
|
65
|
+
const deployPayload = {
|
|
66
|
+
source,
|
|
67
|
+
constructorArgs,
|
|
68
|
+
metadata: options.metadata
|
|
69
|
+
};
|
|
70
|
+
// Build the deployment transaction
|
|
71
|
+
const tx = await this.buildDeployTransaction(deployPayload, options);
|
|
72
|
+
// Send the transaction
|
|
73
|
+
const rpcResult = await this.demos.rpcCall({
|
|
74
|
+
method: 'sendTransaction',
|
|
75
|
+
params: [tx]
|
|
76
|
+
});
|
|
77
|
+
if (rpcResult.result !== 200) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
error: rpcResult.response?.error || 'Deployment failed'
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Wait for confirmation if requested
|
|
84
|
+
if (options.waitForConfirmation !== false) {
|
|
85
|
+
const confirmation = await this.waitForDeployment(rpcResult.response.transactionHash, options.confirmations || 1);
|
|
86
|
+
if (!confirmation.success) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: confirmation.error
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
contractAddress: confirmation.contractAddress,
|
|
95
|
+
deploymentTx: rpcResult.response.transactionHash,
|
|
96
|
+
gasUsed: confirmation.gasUsed,
|
|
97
|
+
blockHeight: confirmation.blockHeight
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
deploymentTx: rpcResult.response.transactionHash,
|
|
103
|
+
contractAddress: rpcResult.response.contractAddress
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
error: error.message || 'Contract deployment failed'
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Deploy a contract and return an instance wrapper
|
|
115
|
+
*/
|
|
116
|
+
async deployAndWrap(source, constructorArgs = [], options = {}) {
|
|
117
|
+
const result = await this.deploy(source, constructorArgs, options);
|
|
118
|
+
if (!result.success || !result.contractAddress) {
|
|
119
|
+
throw new Error(result.error || 'Deployment failed');
|
|
120
|
+
}
|
|
121
|
+
return new ContractInstance_1.ContractInstance(this.demos, result.contractAddress, options.metadata?.abi);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Validate contract source code
|
|
125
|
+
*/
|
|
126
|
+
validateSourceCode(source) {
|
|
127
|
+
// Check for basic contract structure
|
|
128
|
+
if (!source.includes('DemosContract')) {
|
|
129
|
+
throw new Error('Contract must extend DemosContract');
|
|
130
|
+
}
|
|
131
|
+
// Check for banned APIs
|
|
132
|
+
const bannedAPIs = [
|
|
133
|
+
'eval', 'Function', 'setTimeout', 'setInterval',
|
|
134
|
+
'XMLHttpRequest', 'fetch', 'WebSocket', 'Worker'
|
|
135
|
+
];
|
|
136
|
+
for (const api of bannedAPIs) {
|
|
137
|
+
if (source.includes(api)) {
|
|
138
|
+
throw new Error(`Banned API detected: ${api}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Check size limit (256KB)
|
|
142
|
+
const sizeInBytes = new TextEncoder().encode(source).length;
|
|
143
|
+
if (sizeInBytes > 256 * 1024) {
|
|
144
|
+
throw new Error(`Contract too large: ${sizeInBytes} bytes (max 256KB)`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build deployment transaction
|
|
149
|
+
*/
|
|
150
|
+
async buildDeployTransaction(payload, options) {
|
|
151
|
+
const { publicKey } = await this.demos.crypto.getIdentity('ed25519');
|
|
152
|
+
const publicKeyHex = (0, unifiedCrypto_1.uint8ArrayToHex)(publicKey);
|
|
153
|
+
const nonce = await this.demos.getAddressNonce(publicKeyHex);
|
|
154
|
+
const tx = structuredClone(skeletons.transaction);
|
|
155
|
+
tx.content.type = 'contractDeploy';
|
|
156
|
+
tx.content.data = ['contractDeploy', payload];
|
|
157
|
+
tx.content.nonce = options.nonce || nonce;
|
|
158
|
+
tx.content.from = publicKeyHex;
|
|
159
|
+
tx.content.timestamp = Date.now();
|
|
160
|
+
tx.content.amount = Number(options.value || 0);
|
|
161
|
+
// Sign the transaction
|
|
162
|
+
return await this.demos.sign(tx);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Wait for contract deployment confirmation
|
|
166
|
+
*/
|
|
167
|
+
async waitForDeployment(txHash, confirmations) {
|
|
168
|
+
const maxAttempts = 30; // 30 seconds timeout
|
|
169
|
+
let attempts = 0;
|
|
170
|
+
while (attempts < maxAttempts) {
|
|
171
|
+
const result = await this.demos.rpcCall({
|
|
172
|
+
method: 'getTransactionReceipt',
|
|
173
|
+
params: [txHash]
|
|
174
|
+
});
|
|
175
|
+
if (result.result === 200 && result.response) {
|
|
176
|
+
const receipt = result.response;
|
|
177
|
+
if (receipt.confirmations >= confirmations) {
|
|
178
|
+
return {
|
|
179
|
+
success: true,
|
|
180
|
+
contractAddress: receipt.contractAddress,
|
|
181
|
+
gasUsed: receipt.gasUsed,
|
|
182
|
+
blockHeight: receipt.blockHeight
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
187
|
+
attempts++;
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
error: 'Deployment confirmation timeout'
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.ContractDeployer = ContractDeployer;
|
|
196
|
+
//# sourceMappingURL=ContractDeployer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractDeployer.js","sourceRoot":"","sources":["../../../src/contracts/ContractDeployer.ts"],"names":[],"mappings":";AAAA;;GAEG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AAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;YACvD,QAAQ,EAAE,CAAA;QACd,CAAC;QAED,OAAO;YACH,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,iCAAiC;SAC3C,CAAA;IACL,CAAC;CACJ;AAnMD,4CAmMC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating contract instances
|
|
3
|
+
*/
|
|
4
|
+
import { Demos } from '../websdk/demosclass';
|
|
5
|
+
import { ContractDeployer } from './ContractDeployer';
|
|
6
|
+
import { ContractInteractor } from './ContractInteractor';
|
|
7
|
+
import { ContractInstance } from './ContractInstance';
|
|
8
|
+
import { ContractABI, ContractDeployOptions } from './types/ContractABI';
|
|
9
|
+
export declare class ContractFactory {
|
|
10
|
+
private demos;
|
|
11
|
+
private deployer;
|
|
12
|
+
private interactor;
|
|
13
|
+
constructor(demos: Demos);
|
|
14
|
+
/**
|
|
15
|
+
* Deploy a new contract
|
|
16
|
+
*/
|
|
17
|
+
deploy(source: string, constructorArgs?: any[], options?: ContractDeployOptions): Promise<ContractInstance>;
|
|
18
|
+
/**
|
|
19
|
+
* Get an instance of an existing contract
|
|
20
|
+
*/
|
|
21
|
+
at<T = any>(address: string, abi?: ContractABI): Promise<ContractInstance<T>>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a batch operation builder
|
|
24
|
+
*/
|
|
25
|
+
batch(): BatchBuilder;
|
|
26
|
+
/**
|
|
27
|
+
* Estimate gas for a contract call
|
|
28
|
+
*/
|
|
29
|
+
estimateGas(contractAddress: string, method: string, args?: any[]): Promise<bigint>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Batch operation builder
|
|
33
|
+
*/
|
|
34
|
+
export declare class BatchBuilder {
|
|
35
|
+
private demos;
|
|
36
|
+
private deployer;
|
|
37
|
+
private interactor;
|
|
38
|
+
private operations;
|
|
39
|
+
constructor(demos: Demos, deployer: ContractDeployer, interactor: ContractInteractor);
|
|
40
|
+
/**
|
|
41
|
+
* Add a deployment to the batch
|
|
42
|
+
*/
|
|
43
|
+
deploy(source: string, constructorArgs?: any[], options?: ContractDeployOptions): BatchBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Add a contract call to the batch
|
|
46
|
+
*/
|
|
47
|
+
call(contractAddress: string, method: string, args?: any[]): BatchBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Execute all operations in the batch
|
|
50
|
+
*/
|
|
51
|
+
execute(): Promise<any[]>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for creating contract instances
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BatchBuilder = exports.ContractFactory = void 0;
|
|
7
|
+
const ContractDeployer_1 = require("./ContractDeployer");
|
|
8
|
+
const ContractInteractor_1 = require("./ContractInteractor");
|
|
9
|
+
const ContractInstance_1 = require("./ContractInstance");
|
|
10
|
+
class ContractFactory {
|
|
11
|
+
constructor(demos) {
|
|
12
|
+
this.demos = demos;
|
|
13
|
+
this.deployer = new ContractDeployer_1.ContractDeployer(demos);
|
|
14
|
+
this.interactor = new ContractInteractor_1.ContractInteractor(demos);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Deploy a new contract
|
|
18
|
+
*/
|
|
19
|
+
async deploy(source, constructorArgs = [], options = {}) {
|
|
20
|
+
return await this.deployer.deployAndWrap(source, constructorArgs, options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get an instance of an existing contract
|
|
24
|
+
*/
|
|
25
|
+
async at(address, abi) {
|
|
26
|
+
return new ContractInstance_1.ContractInstance(this.demos, address, abi);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a batch operation builder
|
|
30
|
+
*/
|
|
31
|
+
batch() {
|
|
32
|
+
return new BatchBuilder(this.demos, this.deployer, this.interactor);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Estimate gas for a contract call
|
|
36
|
+
*/
|
|
37
|
+
async estimateGas(contractAddress, method, args = []) {
|
|
38
|
+
const result = await this.demos.rpcCall({
|
|
39
|
+
method: 'estimateGas',
|
|
40
|
+
params: [{
|
|
41
|
+
contractAddress,
|
|
42
|
+
method,
|
|
43
|
+
args
|
|
44
|
+
}]
|
|
45
|
+
});
|
|
46
|
+
if (result.result === 200) {
|
|
47
|
+
return BigInt(result.response.gasEstimate || 0);
|
|
48
|
+
}
|
|
49
|
+
throw new Error('Failed to estimate gas');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.ContractFactory = ContractFactory;
|
|
53
|
+
/**
|
|
54
|
+
* Batch operation builder
|
|
55
|
+
*/
|
|
56
|
+
class BatchBuilder {
|
|
57
|
+
constructor(demos, deployer, interactor) {
|
|
58
|
+
this.demos = demos;
|
|
59
|
+
this.deployer = deployer;
|
|
60
|
+
this.interactor = interactor;
|
|
61
|
+
this.operations = [];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Add a deployment to the batch
|
|
65
|
+
*/
|
|
66
|
+
deploy(source, constructorArgs = [], options = {}) {
|
|
67
|
+
this.operations.push(async () => await this.deployer.deploy(source, constructorArgs, options));
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Add a contract call to the batch
|
|
72
|
+
*/
|
|
73
|
+
call(contractAddress, method, args = []) {
|
|
74
|
+
this.operations.push(async () => await this.interactor.call(contractAddress, method, args));
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Execute all operations in the batch
|
|
79
|
+
*/
|
|
80
|
+
async execute() {
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const operation of this.operations) {
|
|
83
|
+
try {
|
|
84
|
+
const result = await operation();
|
|
85
|
+
results.push(result);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
results.push({
|
|
89
|
+
success: false,
|
|
90
|
+
error: error.message
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.BatchBuilder = BatchBuilder;
|
|
98
|
+
//# sourceMappingURL=ContractFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractFactory.js","sourceRoot":"","sources":["../../../src/contracts/ContractFactory.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,yDAAqD;AACrD,6DAAyD;AACzD,yDAAqD;AAGrD,MAAa,eAAe;IAIxB,YAAoB,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,mCAAgB,CAAC,KAAK,CAAC,CAAA;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,uCAAkB,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,MAAc,EACd,kBAAyB,EAAE,EAC3B,UAAiC,EAAE;QAEnC,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,CAAC,CAAA;IAC9E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,EAAE,CACJ,OAAe,EACf,GAAiB;QAEjB,OAAO,IAAI,mCAAgB,CAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;IAC5D,CAAC;IAED;;OAEG;IACH,KAAK;QACD,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IACvE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CACb,eAAuB,EACvB,MAAc,EACd,OAAc,EAAE;QAEhB,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AM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACtC,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAA;gBAChC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC;oBACT,OAAO,EAAE,KAAK;oBACd,KAAK,EAAG,KAAe,CAAC,OAAO;iBAClC,CAAC,CAAA;YACN,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ;AAvDD,oCAuDC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract instance wrapper for easy interaction
|
|
3
|
+
*/
|
|
4
|
+
import { Demos } from '../websdk/demosclass';
|
|
5
|
+
import { ContractCallResult, ContractCallOptions, ContractABI } from './types/ContractABI';
|
|
6
|
+
import { ContractInstance as IContractInstance } from './types/TypedContract';
|
|
7
|
+
export declare class ContractInstance<T = any> implements IContractInstance<T> {
|
|
8
|
+
private demos;
|
|
9
|
+
address: string;
|
|
10
|
+
abi?: ContractABI;
|
|
11
|
+
private interactor;
|
|
12
|
+
methods: T;
|
|
13
|
+
constructor(demos: Demos, address: string, abi?: ContractABI);
|
|
14
|
+
/**
|
|
15
|
+
* Call a contract method
|
|
16
|
+
*/
|
|
17
|
+
call<R = any>(method: string, args?: any[], options?: ContractCallOptions): Promise<ContractCallResult<R>>;
|
|
18
|
+
/**
|
|
19
|
+
* Send DEM with a contract call
|
|
20
|
+
*/
|
|
21
|
+
callWithValue<R = any>(method: string, args: any[], value: bigint | number, options?: ContractCallOptions): Promise<ContractCallResult<R>>;
|
|
22
|
+
/**
|
|
23
|
+
* Get contract state (if accessible)
|
|
24
|
+
*/
|
|
25
|
+
getState(key?: string): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Get contract metadata
|
|
28
|
+
*/
|
|
29
|
+
getMetadata(): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Get contract events
|
|
32
|
+
*/
|
|
33
|
+
getEvents(params?: {
|
|
34
|
+
eventName?: string;
|
|
35
|
+
fromBlock?: number;
|
|
36
|
+
toBlock?: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
}): Promise<any[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Setup method proxies based on ABI
|
|
41
|
+
*/
|
|
42
|
+
private setupMethodProxies;
|
|
43
|
+
/**
|
|
44
|
+
* Create a typed instance from ABI
|
|
45
|
+
*/
|
|
46
|
+
static fromABI<T>(demos: Demos, address: string, abi: ContractABI): ContractInstance<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Wait for contract to be deployed at address
|
|
49
|
+
*/
|
|
50
|
+
static waitForDeployment(demos: Demos, address: string, timeout?: number): Promise<boolean>;
|
|
51
|
+
}
|