@autonomys/auto-consensus 0.1.3-alpha.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/README.md +31 -0
- package/dist/address.d.ts +2 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +6 -0
- package/dist/balances.d.ts +10 -0
- package/dist/balances.d.ts.map +1 -0
- package/dist/balances.js +38 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/info.d.ts +2 -0
- package/dist/info.d.ts.map +1 -0
- package/dist/info.js +21 -0
- package/dist/staking.d.ts +50 -0
- package/dist/staking.d.ts.map +1 -0
- package/dist/staking.js +133 -0
- package/dist/transfer.d.ts +4 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +24 -0
- package/dist/types/events.d.ts +4 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/transaction.d.ts +12 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/transaction.js +2 -0
- package/dist/utils/detectTxSuccess.d.ts +3 -0
- package/dist/utils/detectTxSuccess.d.ts.map +1 -0
- package/dist/utils/detectTxSuccess.js +12 -0
- package/dist/utils/events.d.ts +31 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +93 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/signAndSendTx.d.ts +6 -0
- package/dist/utils/signAndSendTx.d.ts.map +1 -0
- package/dist/utils/signAndSendTx.js +51 -0
- package/dist/utils/sudo.d.ts +6 -0
- package/dist/utils/sudo.d.ts.map +1 -0
- package/dist/utils/sudo.js +16 -0
- package/dist/utils/validateEvents.d.ts +5 -0
- package/dist/utils/validateEvents.d.ts.map +1 -0
- package/dist/utils/validateEvents.js +23 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Autonomys Auto Consensus SDK
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Autonomys Auto Consensus SDK provides functionalities for blockchain consensus interactions, including address management, balance retrieval, staking, and transfers.
|
|
6
|
+
|
|
7
|
+
## Address Management
|
|
8
|
+
|
|
9
|
+
- `generateAddress(input: MnemonicOrURI): string`: Generates a new address.
|
|
10
|
+
|
|
11
|
+
## Balances
|
|
12
|
+
|
|
13
|
+
- `getBalance(address: string): Promise<Balance>`: Retrieves the balance of an address.
|
|
14
|
+
|
|
15
|
+
## Staking
|
|
16
|
+
|
|
17
|
+
- `stake(address: string, amount: number): Promise<void>`: Stakes an amount from an address.
|
|
18
|
+
|
|
19
|
+
## Transfers
|
|
20
|
+
|
|
21
|
+
- `transfer(from: string, to: string, amount: number): Promise<void>`: Transfers an amount from one address to another.
|
|
22
|
+
|
|
23
|
+
## Info
|
|
24
|
+
|
|
25
|
+
- `getInfo(): Promise<Info>`: Retrieves blockchain information.
|
|
26
|
+
|
|
27
|
+
## Import Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { generateAddress, getBalance, stake, transfer, getInfo } from '@autonomys/auto-consensus'
|
|
31
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,YAAa,MAAM,GAAG,UAAU,KAAG,MAAsC,CAAA"}
|
package/dist/address.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiPromise } from '@polkadot/api';
|
|
2
|
+
type BalanceData = {
|
|
3
|
+
free: bigint;
|
|
4
|
+
reserved: bigint;
|
|
5
|
+
frozen: bigint;
|
|
6
|
+
};
|
|
7
|
+
export declare const totalIssuance: (networkId?: string) => Promise<import("@polkadot/types-codec/types").Codec>;
|
|
8
|
+
export declare const balance: (api: ApiPromise, address: string) => Promise<BalanceData>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=balances.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balances.d.ts","sourceRoot":"","sources":["../src/balances.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAS/C,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,aAAa,eAAsB,MAAM,yDAQrD,CAAA;AAED,eAAO,MAAM,OAAO,QAAe,UAAU,WAAW,MAAM,KAAG,QAAQ,WAAW,CAgBnF,CAAA"}
|
package/dist/balances.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.balance = exports.totalIssuance = void 0;
|
|
13
|
+
const auto_utils_1 = require("@autonomys/auto-utils");
|
|
14
|
+
const totalIssuance = (networkId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
// Get the api instance for the network
|
|
16
|
+
const api = yield (0, auto_utils_1.activate)({ networkId });
|
|
17
|
+
// Get the current total token issuance
|
|
18
|
+
const totalIssuance = yield api.query.balances.totalIssuance();
|
|
19
|
+
return totalIssuance;
|
|
20
|
+
});
|
|
21
|
+
exports.totalIssuance = totalIssuance;
|
|
22
|
+
const balance = (api, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
// Query the balance of the address and parse the data
|
|
24
|
+
try {
|
|
25
|
+
const rawBalance = yield api.query.system.account(address);
|
|
26
|
+
const { data } = rawBalance;
|
|
27
|
+
return {
|
|
28
|
+
free: BigInt(data.free.toString()),
|
|
29
|
+
reserved: BigInt(data.reserved.toString()),
|
|
30
|
+
frozen: BigInt(data.frozen.toString()),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.log('error', error);
|
|
35
|
+
throw new Error('Error getting balance' + error);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
exports.balance = balance;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAE1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./address"), exports);
|
|
18
|
+
__exportStar(require("./balances"), exports);
|
|
19
|
+
__exportStar(require("./info"), exports);
|
|
20
|
+
__exportStar(require("./staking"), exports);
|
|
21
|
+
__exportStar(require("./transfer"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./utils"), exports);
|
package/dist/info.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../src/info.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,eAAsB,MAAM,yDAQxD,CAAA"}
|
package/dist/info.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.networkTimestamp = void 0;
|
|
13
|
+
const auto_utils_1 = require("@autonomys/auto-utils");
|
|
14
|
+
const networkTimestamp = (networkId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
// Get the api instance for the network
|
|
16
|
+
const api = yield (0, auto_utils_1.activate)({ networkId });
|
|
17
|
+
// Get the current timestamp
|
|
18
|
+
const timestamp = yield api.query.timestamp.now();
|
|
19
|
+
return timestamp;
|
|
20
|
+
});
|
|
21
|
+
exports.networkTimestamp = networkTimestamp;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import type { KeyringPair } from '@polkadot/keyring/types';
|
|
3
|
+
export type OperatorDetails = {
|
|
4
|
+
signingKey: string;
|
|
5
|
+
currentDomainId: bigint;
|
|
6
|
+
nextDomainId: bigint;
|
|
7
|
+
minimumNominatorStake: bigint;
|
|
8
|
+
nominationTax: number;
|
|
9
|
+
currentTotalStake: bigint;
|
|
10
|
+
currentEpochRewards: bigint;
|
|
11
|
+
currentTotalShares: bigint;
|
|
12
|
+
status: object[];
|
|
13
|
+
depositsInEpoch: bigint;
|
|
14
|
+
withdrawalsInEpoch: bigint;
|
|
15
|
+
totalStorageFeeDeposit: bigint;
|
|
16
|
+
};
|
|
17
|
+
export type Operator = {
|
|
18
|
+
operatorId: bigint;
|
|
19
|
+
operatorDetails: OperatorDetails;
|
|
20
|
+
};
|
|
21
|
+
type StringNumberOrBigInt = string | number | bigint;
|
|
22
|
+
export type RegisterOperatorInput = {
|
|
23
|
+
api: ApiPromise;
|
|
24
|
+
senderAddress: string;
|
|
25
|
+
Operator: KeyringPair;
|
|
26
|
+
domainId: StringNumberOrBigInt;
|
|
27
|
+
amountToStake: StringNumberOrBigInt;
|
|
28
|
+
minimumNominatorStake: StringNumberOrBigInt;
|
|
29
|
+
nominationTax: StringNumberOrBigInt;
|
|
30
|
+
};
|
|
31
|
+
export type StakingInput = {
|
|
32
|
+
api: ApiPromise;
|
|
33
|
+
operatorId: StringNumberOrBigInt;
|
|
34
|
+
};
|
|
35
|
+
export interface WithdrawStakeInput extends StakingInput {
|
|
36
|
+
shares: StringNumberOrBigInt;
|
|
37
|
+
}
|
|
38
|
+
export interface NominateOperatorInput extends StakingInput {
|
|
39
|
+
amountToStake: StringNumberOrBigInt;
|
|
40
|
+
}
|
|
41
|
+
export declare const operators: (api: ApiPromise) => Promise<Operator[]>;
|
|
42
|
+
export declare const operator: (api: ApiPromise, operatorId: StringNumberOrBigInt) => Promise<OperatorDetails>;
|
|
43
|
+
export declare const registerOperator: (input: RegisterOperatorInput) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
44
|
+
export declare const nominateOperator: (input: NominateOperatorInput) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
45
|
+
export declare const withdrawStake: (input: WithdrawStakeInput) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
46
|
+
export declare const deregisterOperator: (input: StakingInput) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
47
|
+
export declare const unlockFunds: (input: StakingInput) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
48
|
+
export declare const unlockNominator: (input: StakingInput) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=staking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAqB1D,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,sBAAsB,EAAE,MAAM,CAAA;CAC/B,CAAA;AACD,MAAM,MAAM,QAAQ,GAAG;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,eAAe,CAAA;CACjC,CAAA;AAED,KAAK,oBAAoB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAEpD,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,UAAU,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,oBAAoB,CAAA;IAC9B,aAAa,EAAE,oBAAoB,CAAA;IACnC,qBAAqB,EAAE,oBAAoB,CAAA;IAC3C,aAAa,EAAE,oBAAoB,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,UAAU,CAAA;IACf,UAAU,EAAE,oBAAoB,CAAA;CACjC,CAAA;AAED,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,MAAM,EAAE,oBAAoB,CAAA;CAC7B;AAED,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD,aAAa,EAAE,oBAAoB,CAAA;CACpC;AA8BD,eAAO,MAAM,SAAS,QAAe,UAAU,wBAQ9C,CAAA;AAED,eAAO,MAAM,QAAQ,QAAe,UAAU,cAAc,oBAAoB,6BAQ/E,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAiB,qBAAqB,oIA8BlE,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAiB,qBAAqB,oIAYlE,CAAA;AAED,eAAO,MAAM,aAAa,UAAiB,kBAAkB,oIAS5D,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAiB,YAAY,oIAS3D,CAAA;AAED,eAAO,MAAM,WAAW,UAAiB,YAAY,oIASpD,CAAA;AAED,eAAO,MAAM,eAAe,UAAiB,YAAY,oIASxD,CAAA"}
|
package/dist/staking.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.unlockNominator = exports.unlockFunds = exports.deregisterOperator = exports.withdrawStake = exports.nominateOperator = exports.registerOperator = exports.operator = exports.operators = void 0;
|
|
13
|
+
const types_1 = require("@polkadot/types");
|
|
14
|
+
const util_1 = require("@polkadot/util");
|
|
15
|
+
const parseOperatorDetails = (operatorDetails) => {
|
|
16
|
+
const rawOD = operatorDetails.toJSON();
|
|
17
|
+
return {
|
|
18
|
+
signingKey: rawOD.signingKey,
|
|
19
|
+
currentDomainId: BigInt(rawOD.currentDomainId),
|
|
20
|
+
nextDomainId: BigInt(rawOD.nextDomainId),
|
|
21
|
+
minimumNominatorStake: BigInt(rawOD.minimumNominatorStake),
|
|
22
|
+
nominationTax: rawOD.nominationTax,
|
|
23
|
+
currentTotalStake: BigInt(rawOD.currentTotalStake),
|
|
24
|
+
currentEpochRewards: BigInt(rawOD.currentEpochRewards),
|
|
25
|
+
currentTotalShares: BigInt(rawOD.currentTotalShares),
|
|
26
|
+
status: rawOD.status,
|
|
27
|
+
depositsInEpoch: BigInt(rawOD.depositsInEpoch),
|
|
28
|
+
withdrawalsInEpoch: BigInt(rawOD.withdrawalsInEpoch),
|
|
29
|
+
totalStorageFeeDeposit: BigInt(rawOD.totalStorageFeeDeposit),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const parseOperator = (operator) => {
|
|
33
|
+
return {
|
|
34
|
+
operatorId: BigInt(operator[0].toHuman()[0]),
|
|
35
|
+
operatorDetails: parseOperatorDetails(operator[1]),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const parseString = (operatorId) => typeof operatorId === 'string' ? operatorId : operatorId.toString();
|
|
39
|
+
const operators = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
const _operators = yield api.query.domains.operators.entries();
|
|
42
|
+
return _operators.map((o) => parseOperator(o));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error('error', error);
|
|
46
|
+
throw new Error('Error querying operators list.' + error);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
exports.operators = operators;
|
|
50
|
+
const operator = (api, operatorId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
try {
|
|
52
|
+
const _operator = yield api.query.domains.operators(parseString(operatorId));
|
|
53
|
+
return parseOperatorDetails(_operator);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('error', error);
|
|
57
|
+
throw new Error(`Error querying operatorId: ${operatorId} with error: ${error}`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
exports.operator = operator;
|
|
61
|
+
const registerOperator = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
try {
|
|
63
|
+
const { api, senderAddress, Operator, domainId, amountToStake, minimumNominatorStake, nominationTax, } = input;
|
|
64
|
+
const message = (0, types_1.createType)(api.registry, 'AccountId', senderAddress).toU8a();
|
|
65
|
+
const signingKey = (0, util_1.u8aToHex)(Operator.publicKey);
|
|
66
|
+
const signature = Operator.sign(message);
|
|
67
|
+
return yield api.tx.domains.registerOperator(parseString(domainId), parseString(amountToStake), {
|
|
68
|
+
signingKey,
|
|
69
|
+
minimumNominatorStake: parseString(minimumNominatorStake),
|
|
70
|
+
nominationTax: parseString(nominationTax),
|
|
71
|
+
}, signature);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error('error', error);
|
|
75
|
+
throw new Error('Error creating register operator tx.' + error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
exports.registerOperator = registerOperator;
|
|
79
|
+
const nominateOperator = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
const { api, operatorId, amountToStake } = input;
|
|
82
|
+
return yield api.tx.domains.nominateOperator(parseString(operatorId), parseString(amountToStake));
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('error', error);
|
|
86
|
+
throw new Error('Error creating nominate operator tx.' + error);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
exports.nominateOperator = nominateOperator;
|
|
90
|
+
const withdrawStake = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
try {
|
|
92
|
+
const { api, operatorId, shares } = input;
|
|
93
|
+
return yield api.tx.domains.withdrawStake(parseString(operatorId), parseString(shares));
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error('error', error);
|
|
97
|
+
throw new Error('Error creating withdraw stake tx.' + error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
exports.withdrawStake = withdrawStake;
|
|
101
|
+
const deregisterOperator = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
try {
|
|
103
|
+
const { api, operatorId } = input;
|
|
104
|
+
return yield api.tx.domains.deregisterOperator(parseString(operatorId));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error('error', error);
|
|
108
|
+
throw new Error('Error creating de-register operator tx.' + error);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
exports.deregisterOperator = deregisterOperator;
|
|
112
|
+
const unlockFunds = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
const { api, operatorId } = input;
|
|
115
|
+
return yield api.tx.domains.unlockFunds(parseString(operatorId));
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error('error', error);
|
|
119
|
+
throw new Error('Error creating unlock funds tx.' + error);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
exports.unlockFunds = unlockFunds;
|
|
123
|
+
const unlockNominator = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
try {
|
|
125
|
+
const { api, operatorId } = input;
|
|
126
|
+
return yield api.tx.domains.unlockNominator(parseString(operatorId));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error('error', error);
|
|
130
|
+
throw new Error('Error creating unlock nominator tx.' + error);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
exports.unlockNominator = unlockNominator;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ApiPromise } from '@polkadot/api';
|
|
2
|
+
export declare const transfer: (api: ApiPromise, receiver: string, amount: BigInt | number | string, allowDeath?: boolean) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
3
|
+
export declare const transferAll: (api: ApiPromise, receiver: string, keepAlive?: boolean) => Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
4
|
+
//# sourceMappingURL=transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,eAAO,MAAM,QAAQ,QACd,UAAU,YACL,MAAM,UACR,MAAM,GAAG,MAAM,GAAG,MAAM,eACnB,OAAO,oIAMrB,CAAA;AAED,eAAO,MAAM,WAAW,QACjB,UAAU,YACL,MAAM,cACL,OAAO,oIAInB,CAAA"}
|
package/dist/transfer.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.transferAll = exports.transfer = void 0;
|
|
13
|
+
const transfer = (api, receiver, amount, allowDeath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
// Transfer the tokens
|
|
15
|
+
return !allowDeath
|
|
16
|
+
? yield api.tx.balances.transferKeepAlive(receiver, amount)
|
|
17
|
+
: yield api.tx.balances.transferAllowDeath(receiver, amount);
|
|
18
|
+
});
|
|
19
|
+
exports.transfer = transfer;
|
|
20
|
+
const transferAll = (api_1, receiver_1, ...args_1) => __awaiter(void 0, [api_1, receiver_1, ...args_1], void 0, function* (api, receiver, keepAlive = false) {
|
|
21
|
+
// Transfer all the tokens
|
|
22
|
+
return yield api.tx.balances.transferAll(receiver, keepAlive);
|
|
23
|
+
});
|
|
24
|
+
exports.transferAll = transferAll;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type ActionEvents = string | string[];
|
|
2
|
+
export type Events = ActionEvents | ActionEvents[];
|
|
3
|
+
export type EventKeys = 'transfer' | 'operatorRegistered' | 'operatorNominated' | 'operatorDeregistered' | 'withdrawStake' | 'unlockFunds' | 'forceDomainEpochTransition';
|
|
4
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AAC5C,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,YAAY,EAAE,CAAA;AAGlD,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,oBAAoB,GACpB,mBAAmB,GACnB,sBAAsB,GACtB,eAAe,GACf,aAAa,GACb,4BAA4B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./events"), exports);
|
|
18
|
+
__exportStar(require("./transaction"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Events } from '../types/events';
|
|
2
|
+
export type EventsValidated = {
|
|
3
|
+
expected: Events;
|
|
4
|
+
found: Events;
|
|
5
|
+
};
|
|
6
|
+
export type TransactionSignedAndSend = {
|
|
7
|
+
success: boolean;
|
|
8
|
+
txHash: string | undefined;
|
|
9
|
+
blockHash: string | undefined;
|
|
10
|
+
events: EventsValidated;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/types/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,MAAM,EAAE,eAAe,CAAA;CACxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectTxSuccess.d.ts","sourceRoot":"","sources":["../../src/utils/detectTxSuccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAG7D,eAAO,MAAM,eAAe,WAAY,WAAW,EAAE,KAAG,OAMvD,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectTxSuccess = void 0;
|
|
4
|
+
const events_1 = require("./events");
|
|
5
|
+
const detectTxSuccess = (events) => {
|
|
6
|
+
events.forEach(({ event: { method, section } }) => {
|
|
7
|
+
if (events_1.expectSuccessfulTxEvent.indexOf(`${section}.${method}`) > -1)
|
|
8
|
+
return true;
|
|
9
|
+
});
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
exports.detectTxSuccess = detectTxSuccess;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ActionEvents, EventKeys } from '../types/events';
|
|
2
|
+
export declare const enum Type {
|
|
3
|
+
system = "system",
|
|
4
|
+
balances = "balances",
|
|
5
|
+
transactionPayment = "transactionPayment",
|
|
6
|
+
domains = "domains",
|
|
7
|
+
sudo = "sudo"
|
|
8
|
+
}
|
|
9
|
+
export declare const eventName: (type: Type, event: string) => string;
|
|
10
|
+
export declare const eventsGroup: {
|
|
11
|
+
system: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
14
|
+
balances: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
};
|
|
17
|
+
transactionPayment: {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
domains: {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
};
|
|
23
|
+
sudo: {
|
|
24
|
+
[key: string]: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare const expectSuccessfulTxEvent: string[];
|
|
28
|
+
export declare const events: {
|
|
29
|
+
[key in EventKeys]: ActionEvents;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG9D,0BAAkB,IAAI;IACpB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,kBAAkB,uBAAuB;IACzC,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAGD,eAAO,MAAM,SAAS,SAAU,IAAI,SAAS,MAAM,WAAuB,CAAA;AAkD1E,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;CAMvB,CAAA;AAGD,eAAO,MAAM,uBAAuB,UAAmB,CAAA;AAGvD,eAAO,MAAM,MAAM,EAAE;KAAG,GAAG,IAAI,SAAS,GAAG,YAAY;CA2CtD,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.events = exports.expectSuccessfulTxEvent = exports.eventsGroup = exports.eventName = void 0;
|
|
4
|
+
// Utility Function for Event Names
|
|
5
|
+
const eventName = (type, event) => `${type}.${event}`;
|
|
6
|
+
exports.eventName = eventName;
|
|
7
|
+
// System Events
|
|
8
|
+
const system = {
|
|
9
|
+
failure: (0, exports.eventName)("system" /* Type.system */, 'ExtrinsicFailed'),
|
|
10
|
+
newAccount: (0, exports.eventName)("system" /* Type.system */, 'NewAccount'),
|
|
11
|
+
success: (0, exports.eventName)("system" /* Type.system */, 'ExtrinsicSuccess'),
|
|
12
|
+
};
|
|
13
|
+
// Balances Events
|
|
14
|
+
const balances = {
|
|
15
|
+
deposit: (0, exports.eventName)("balances" /* Type.balances */, 'Deposit'),
|
|
16
|
+
endowed: (0, exports.eventName)("balances" /* Type.balances */, 'Endowed'),
|
|
17
|
+
transfer: (0, exports.eventName)("balances" /* Type.balances */, 'Transfer'),
|
|
18
|
+
withdraw: (0, exports.eventName)("balances" /* Type.balances */, 'Withdraw'),
|
|
19
|
+
};
|
|
20
|
+
// Transaction Payment Events
|
|
21
|
+
const transactionPayment = {
|
|
22
|
+
feePaid: (0, exports.eventName)("transactionPayment" /* Type.transactionPayment */, 'TransactionFeePaid'),
|
|
23
|
+
};
|
|
24
|
+
// Domains Events
|
|
25
|
+
const domains = {
|
|
26
|
+
forceDomainEpochTransition: (0, exports.eventName)("domains" /* Type.domains */, 'ForceDomainEpochTransition'),
|
|
27
|
+
fundsUnlocked: (0, exports.eventName)("domains" /* Type.domains */, 'FundsUnlocked'),
|
|
28
|
+
operatorDeregistered: (0, exports.eventName)("domains" /* Type.domains */, 'OperatorDeregistered'),
|
|
29
|
+
operatorNominated: (0, exports.eventName)("domains" /* Type.domains */, 'OperatorNominated'),
|
|
30
|
+
operatorRegistered: (0, exports.eventName)("domains" /* Type.domains */, 'OperatorRegistered'),
|
|
31
|
+
operatorUnlocked: (0, exports.eventName)("domains" /* Type.domains */, 'OperatorUnlocked'),
|
|
32
|
+
storageFeeDeposited: (0, exports.eventName)("domains" /* Type.domains */, 'StorageFeeDeposited'),
|
|
33
|
+
withdrawStake: (0, exports.eventName)("domains" /* Type.domains */, 'WithdrewStake'),
|
|
34
|
+
};
|
|
35
|
+
// Sudo Events
|
|
36
|
+
const sudo = {
|
|
37
|
+
sudid: (0, exports.eventName)("sudo" /* Type.sudo */, 'Sudid'),
|
|
38
|
+
};
|
|
39
|
+
// Group of Events
|
|
40
|
+
exports.eventsGroup = {
|
|
41
|
+
system,
|
|
42
|
+
balances,
|
|
43
|
+
transactionPayment,
|
|
44
|
+
domains,
|
|
45
|
+
sudo,
|
|
46
|
+
};
|
|
47
|
+
// Export a default success event
|
|
48
|
+
exports.expectSuccessfulTxEvent = [system.success];
|
|
49
|
+
// Events Mappings
|
|
50
|
+
exports.events = {
|
|
51
|
+
transfer: [balances.withdraw, balances.transfer, transactionPayment.feePaid, system.success],
|
|
52
|
+
operatorRegistered: [
|
|
53
|
+
balances.withdraw,
|
|
54
|
+
domains.storageFeeDeposited,
|
|
55
|
+
domains.operatorRegistered,
|
|
56
|
+
transactionPayment.feePaid,
|
|
57
|
+
system.success,
|
|
58
|
+
],
|
|
59
|
+
operatorNominated: [
|
|
60
|
+
balances.withdraw,
|
|
61
|
+
balances.transfer,
|
|
62
|
+
domains.storageFeeDeposited,
|
|
63
|
+
domains.operatorNominated,
|
|
64
|
+
transactionPayment.feePaid,
|
|
65
|
+
system.success,
|
|
66
|
+
],
|
|
67
|
+
operatorDeregistered: [
|
|
68
|
+
balances.withdraw,
|
|
69
|
+
domains.operatorDeregistered,
|
|
70
|
+
transactionPayment.feePaid,
|
|
71
|
+
system.success,
|
|
72
|
+
],
|
|
73
|
+
withdrawStake: [
|
|
74
|
+
balances.withdraw,
|
|
75
|
+
domains.withdrawStake,
|
|
76
|
+
transactionPayment.feePaid,
|
|
77
|
+
system.success,
|
|
78
|
+
],
|
|
79
|
+
unlockFunds: [
|
|
80
|
+
balances.withdraw,
|
|
81
|
+
domains.fundsUnlocked,
|
|
82
|
+
transactionPayment.feePaid,
|
|
83
|
+
system.success,
|
|
84
|
+
],
|
|
85
|
+
forceDomainEpochTransition: [
|
|
86
|
+
balances.withdraw,
|
|
87
|
+
domains.forceDomainEpochTransition,
|
|
88
|
+
sudo.sudid,
|
|
89
|
+
balances.deposit,
|
|
90
|
+
transactionPayment.feePaid,
|
|
91
|
+
system.success,
|
|
92
|
+
],
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,QAAQ,CAAA;AACtB,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./detectTxSuccess"), exports);
|
|
18
|
+
__exportStar(require("./events"), exports);
|
|
19
|
+
__exportStar(require("./signAndSendTx"), exports);
|
|
20
|
+
__exportStar(require("./sudo"), exports);
|
|
21
|
+
__exportStar(require("./validateEvents"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AddressOrPair, SubmittableExtrinsic } from '@polkadot/api/types';
|
|
2
|
+
import type { ISubmittableResult } from '@polkadot/types/types';
|
|
3
|
+
import type { Events } from '../types/events';
|
|
4
|
+
import type { TransactionSignedAndSend } from '../types/transaction';
|
|
5
|
+
export declare const signAndSendTx: (sender: AddressOrPair, tx: SubmittableExtrinsic<'promise', ISubmittableResult>, eventsExpected?: Events, log?: boolean) => Promise<TransactionSignedAndSend>;
|
|
6
|
+
//# sourceMappingURL=signAndSendTx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signAndSendTx.d.ts","sourceRoot":"","sources":["../../src/utils/signAndSendTx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAmB,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAKrF,eAAO,MAAM,aAAa,WAChB,aAAa,MACjB,qBAAqB,SAAS,EAAE,kBAAkB,CAAC,mBACvC,MAAM,QACjB,OAAO,KACX,QAAQ,wBAAwB,CAgClC,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.signAndSendTx = void 0;
|
|
13
|
+
const detectTxSuccess_1 = require("./detectTxSuccess");
|
|
14
|
+
const events_1 = require("./events");
|
|
15
|
+
const validateEvents_1 = require("./validateEvents");
|
|
16
|
+
const signAndSendTx = (sender_1, tx_1, ...args_1) => __awaiter(void 0, [sender_1, tx_1, ...args_1], void 0, function* (sender, tx, eventsExpected = events_1.expectSuccessfulTxEvent, log = false) {
|
|
17
|
+
let success = false;
|
|
18
|
+
let txHashHex = undefined;
|
|
19
|
+
let blockHash = undefined;
|
|
20
|
+
let eventsValidated = { expected: [], found: [] };
|
|
21
|
+
yield new Promise((resolve, reject) => {
|
|
22
|
+
tx.signAndSend(sender, ({ events, status, txHash }) => {
|
|
23
|
+
if (status.isInBlock) {
|
|
24
|
+
txHashHex = txHash.toHex();
|
|
25
|
+
blockHash = status.asInBlock.toHex();
|
|
26
|
+
if (log)
|
|
27
|
+
console.log('Successful tx', txHashHex, 'in block', blockHash);
|
|
28
|
+
success = (0, detectTxSuccess_1.detectTxSuccess)(events);
|
|
29
|
+
if (eventsExpected.length > 0) {
|
|
30
|
+
const _events = (0, validateEvents_1.validateEvents)(events, eventsExpected, txHashHex, blockHash, log);
|
|
31
|
+
if (_events.expected.length === 0)
|
|
32
|
+
resolve();
|
|
33
|
+
else
|
|
34
|
+
reject(new Error('Events not found'));
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
resolve();
|
|
38
|
+
}
|
|
39
|
+
else if (status.isRetracted ||
|
|
40
|
+
status.isFinalityTimeout ||
|
|
41
|
+
status.isDropped ||
|
|
42
|
+
status.isInvalid) {
|
|
43
|
+
if (log)
|
|
44
|
+
console.error('Transaction failed');
|
|
45
|
+
reject(new Error('Transaction failed'));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return { success, txHash: txHashHex, blockHash, events: eventsValidated };
|
|
50
|
+
});
|
|
51
|
+
exports.signAndSendTx = signAndSendTx;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import type { AddressOrPair, SubmittableExtrinsic } from '@polkadot/api/types';
|
|
3
|
+
import type { ISubmittableResult } from '@polkadot/types/types';
|
|
4
|
+
import type { Events } from '../types/events';
|
|
5
|
+
export declare const sudo: (api: ApiPromise, sender: AddressOrPair, tx: SubmittableExtrinsic<'promise', ISubmittableResult>, eventsExpected?: Events, log?: boolean) => Promise<import("..").TransactionSignedAndSend>;
|
|
6
|
+
//# sourceMappingURL=sudo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudo.d.ts","sourceRoot":"","sources":["../../src/utils/sudo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAI7C,eAAO,MAAM,IAAI,QACV,UAAU,UACP,aAAa,MACjB,qBAAqB,SAAS,EAAE,kBAAkB,CAAC,mBACvC,MAAM,QACjB,OAAO,mDAC6D,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.sudo = void 0;
|
|
13
|
+
const events_1 = require("./events");
|
|
14
|
+
const signAndSendTx_1 = require("./signAndSendTx");
|
|
15
|
+
const sudo = (api_1, sender_1, tx_1, ...args_1) => __awaiter(void 0, [api_1, sender_1, tx_1, ...args_1], void 0, function* (api, sender, tx, eventsExpected = events_1.expectSuccessfulTxEvent, log = true) { return yield (0, signAndSendTx_1.signAndSendTx)(sender, api.tx.sudo.sudo(tx), eventsExpected, log); });
|
|
16
|
+
exports.sudo = sudo;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EventRecord } from '@polkadot/types/interfaces';
|
|
2
|
+
import type { Events } from '../types/events';
|
|
3
|
+
import type { EventsValidated } from '../types/transaction';
|
|
4
|
+
export declare const validateEvents: (events: EventRecord[], eventsExpected: Events | undefined, tx: string, block: string, log?: boolean) => EventsValidated;
|
|
5
|
+
//# sourceMappingURL=validateEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateEvents.d.ts","sourceRoot":"","sources":["../../src/utils/validateEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAG3D,eAAO,MAAM,cAAc,WACjB,WAAW,EAAE,0CAEjB,MAAM,SACH,MAAM,QACR,OAAO,KACX,eAmBF,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateEvents = void 0;
|
|
4
|
+
const events_1 = require("./events");
|
|
5
|
+
const validateEvents = (events, eventsExpected = events_1.expectSuccessfulTxEvent, tx, block, log = false) => {
|
|
6
|
+
const _eventsExpected = typeof eventsExpected === 'string'
|
|
7
|
+
? [eventsExpected]
|
|
8
|
+
: eventsExpected.map((e) => (typeof e === 'string' ? [e] : e)).flat();
|
|
9
|
+
const found = [];
|
|
10
|
+
events.forEach(({ event: { data, method, section } }) => {
|
|
11
|
+
const index = _eventsExpected.indexOf(`${section}.${method}`);
|
|
12
|
+
if (index > -1) {
|
|
13
|
+
_eventsExpected.splice(index, 1);
|
|
14
|
+
found.push(`${section}.${method}`);
|
|
15
|
+
}
|
|
16
|
+
else if (log)
|
|
17
|
+
console.log('Event not expected', `${section}.${method}`, 'tx', tx, 'block', block);
|
|
18
|
+
});
|
|
19
|
+
if (_eventsExpected.length > 0)
|
|
20
|
+
console.log('Events not found', _eventsExpected, 'tx', tx, 'block', block);
|
|
21
|
+
return { expected: _eventsExpected, found };
|
|
22
|
+
};
|
|
23
|
+
exports.validateEvents = validateEvents;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autonomys/auto-consensus",
|
|
3
|
+
"version": "0.1.3-alpha.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc",
|
|
7
|
+
"clean": "rm -rf dist",
|
|
8
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
9
|
+
"test-local": "jest -i"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/subspace/auto-sdk"
|
|
18
|
+
},
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Autonomys",
|
|
21
|
+
"url": "https://www.autonomys.net"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@autonomys/auto-utils": "^0.1.3-alpha.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@polkadot/types-codec": "^11.2.1",
|
|
28
|
+
"@types/jest": "^29.5.12",
|
|
29
|
+
"eslint": "^8.57.0",
|
|
30
|
+
"jest": "^29.7.0",
|
|
31
|
+
"prettier": "^3.2.5",
|
|
32
|
+
"ts-jest": "^29.1.4",
|
|
33
|
+
"typescript": "^5.4.5"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "438f0fefdd77e291689a8a1233e28bc8792d5503"
|
|
36
|
+
}
|