@streamflow/distributor 6.0.0-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/LICENSE +674 -0
- package/README.md +127 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +27 -0
- package/dist/solana/client.d.ts +25 -0
- package/dist/solana/client.js +300 -0
- package/dist/solana/constants.d.ts +6 -0
- package/dist/solana/constants.js +11 -0
- package/dist/solana/generated/accounts/ClaimStatus.d.ts +72 -0
- package/dist/solana/generated/accounts/ClaimStatus.js +183 -0
- package/dist/solana/generated/accounts/MerkleDistributor.d.ts +138 -0
- package/dist/solana/generated/accounts/MerkleDistributor.js +238 -0
- package/dist/solana/generated/accounts/index.d.ts +4 -0
- package/dist/solana/generated/accounts/index.js +7 -0
- package/dist/solana/generated/errors/anchor.d.ts +434 -0
- package/dist/solana/generated/errors/anchor.js +889 -0
- package/dist/solana/generated/errors/custom.d.ts +162 -0
- package/dist/solana/generated/errors/custom.js +344 -0
- package/dist/solana/generated/errors/index.d.ts +5 -0
- package/dist/solana/generated/errors/index.js +104 -0
- package/dist/solana/generated/instructions/claimLocked.d.ts +21 -0
- package/dist/solana/generated/instructions/claimLocked.js +22 -0
- package/dist/solana/generated/instructions/clawback.d.ts +20 -0
- package/dist/solana/generated/instructions/clawback.js +22 -0
- package/dist/solana/generated/instructions/closeClaim.d.ts +13 -0
- package/dist/solana/generated/instructions/closeClaim.js +20 -0
- package/dist/solana/generated/instructions/index.d.ts +14 -0
- package/dist/solana/generated/instructions/index.js +17 -0
- package/dist/solana/generated/instructions/newClaim.d.ts +27 -0
- package/dist/solana/generated/instructions/newClaim.js +58 -0
- package/dist/solana/generated/instructions/newDistributor.d.ts +56 -0
- package/dist/solana/generated/instructions/newDistributor.js +94 -0
- package/dist/solana/generated/instructions/setAdmin.d.ts +10 -0
- package/dist/solana/generated/instructions/setAdmin.js +18 -0
- package/dist/solana/generated/instructions/setClawbackReceiver.d.ts +10 -0
- package/dist/solana/generated/instructions/setClawbackReceiver.js +18 -0
- package/dist/solana/generated/programId.d.ts +3 -0
- package/dist/solana/generated/programId.js +8 -0
- package/dist/solana/index.d.ts +4 -0
- package/dist/solana/index.js +37 -0
- package/dist/solana/types.d.ts +203 -0
- package/dist/solana/types.js +159 -0
- package/dist/solana/utils.d.ts +5 -0
- package/dist/solana/utils.js +87 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
## JS SDK to interact with Streamflow Airdrop.
|
|
2
|
+
|
|
3
|
+
This package allows you to `create`, `claim`, `clawback` a Token Distributor.
|
|
4
|
+
|
|
5
|
+
Token Distributor essentially that allows you to Airdrop tokens to multiple (thousands or even millions) of recipients with constant fees for the Sender. Recipient will pay gas fees when claiming tokens.
|
|
6
|
+
|
|
7
|
+
You can also use `getClaims` and `getDistributors` to fetch active claims and distributors respectively.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
`npm i -s @streamflow/common @streamflow/distributor`
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
`yarn add @streamflow/common @streamflow/distributor`
|
|
18
|
+
|
|
19
|
+
## Import SDK
|
|
20
|
+
|
|
21
|
+
Most common imports:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import { BN } from "bn.js";
|
|
25
|
+
import { ICluster } from "@streamflow/common";
|
|
26
|
+
import { SolanaDistributorClient } from "@streamflow/distributor/solana";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
_Check the SDK for other types and utility functions._
|
|
30
|
+
|
|
31
|
+
## Create DistributorClient instance
|
|
32
|
+
|
|
33
|
+
### Solana
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
const client = new SolanaDistributorClient({
|
|
37
|
+
clusterUrl: "https://api.mainnet-beta.solana.com",
|
|
38
|
+
cluster: ICluster.Mainnet,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Create an Airdrop (Distributor account)
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
const now = Math.floor(Date.now() / 1000);
|
|
46
|
+
|
|
47
|
+
const solanaParams = {
|
|
48
|
+
invoker: wallet, // SignerWalletAdapter or Keypair of Sender account
|
|
49
|
+
isNative: // [optional] [WILL CREATE A wSOL Airdrop] Needed only if you need to Airdrop Solana native token
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const res = await client.create(
|
|
53
|
+
{
|
|
54
|
+
mint: "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj", // mint
|
|
55
|
+
version: now, // version of the Airdrop, version will be used to generate unique address of the Distributor Account
|
|
56
|
+
root: [
|
|
57
|
+
54, 218, 49, 68, 131, 214, 250, 113, 37, 143, 167, 73, 17, 54, 233, 26, 141, 93, 28, 186, 137, 211, 251, 205,
|
|
58
|
+
240, 192, 134, 208, 108, 246, 0, 191,
|
|
59
|
+
], // Merkle root
|
|
60
|
+
maxNumNodes: new BN("4"), // Number of recipients
|
|
61
|
+
maxTotalClaim: new BN("4000000000"), // Total amount to distribute
|
|
62
|
+
unlockPeriod: 1, // Unlock period in seconds
|
|
63
|
+
startVestingTs: 0, // Timestamp when Airdrop starts
|
|
64
|
+
endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
|
|
65
|
+
clawbackStartTs: now + 5, // Timestamp after which Airdrop can be clawed back to the Sender address
|
|
66
|
+
claimsClosable: false, // Whether individual Claims can be closed by the Sender
|
|
67
|
+
},
|
|
68
|
+
solanaParams,
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Claim an Airdrop
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
const solanaParams = {
|
|
76
|
+
invoker: recipient, // SignerWalletAdapter or Keypair of Recipient account
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const claimRes = await client.claim(
|
|
80
|
+
{
|
|
81
|
+
id: res.metadataId, // address of the Distributor Account
|
|
82
|
+
proof: [
|
|
83
|
+
[
|
|
84
|
+
36, 11, 128, 61, 125, 228, 9, 50, 112, 51, 54, 201, 213, 81, 228, 216, 62, 191, 68, 63, 59, 125, 163, 77, 44,
|
|
85
|
+
88, 170, 65, 139, 25, 147, 145,
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
53, 101, 204, 14, 202, 64, 98, 238, 49, 6, 119, 208, 98, 195, 150, 81, 191, 55, 46, 103, 91, 245, 121, 195,
|
|
89
|
+
43, 104, 75, 183, 12, 38, 37, 153,
|
|
90
|
+
],
|
|
91
|
+
], // Merkle Proof used to verify claim
|
|
92
|
+
amountUnlocked: new BN("0"), // Total amount unlocked for a Recipient
|
|
93
|
+
amountLocked: new BN("1000000000"), // Total amount locked for a Recipient
|
|
94
|
+
},
|
|
95
|
+
solanaParams,
|
|
96
|
+
);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Clawback an Airdrop
|
|
100
|
+
|
|
101
|
+
Returns all funds to the original Sender.
|
|
102
|
+
- only Sender can clawback funds before Airdrop has ended;
|
|
103
|
+
- anyone can clawback funds a day after Airdrop has ended - funds will still go to the original Sender;
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const solanaParams = {
|
|
107
|
+
invoker: sender, // SignerWalletAdapter or Keypair of Invoker account
|
|
108
|
+
};
|
|
109
|
+
const clawbackRes = await client.clawback({ id: res.metadataId }, solanaParams);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Handling errors
|
|
113
|
+
|
|
114
|
+
`GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
|
|
115
|
+
- this class inherits original traceback
|
|
116
|
+
- error may optionally contain `contractErrorCode` property that can be further mapped to a specific **Contract** error
|
|
117
|
+
- for `createMultiple` method errors are wrapped individually for every recipient address
|
|
118
|
+
- please check documentation for enums `AnchorErrorCode` and `ContractErrorCode` at `solana/types.ts` to see short description for each error
|
|
119
|
+
|
|
120
|
+
## Additional notes
|
|
121
|
+
|
|
122
|
+
Streamflow Distributor protocol program IDs
|
|
123
|
+
|
|
124
|
+
| Solana | |
|
|
125
|
+
| ------- | -------------------------------------------- |
|
|
126
|
+
| Devet | MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N |
|
|
127
|
+
| Mainnet | |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as StreamflowDistributorSolana from "./solana";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.StreamflowDistributorSolana = void 0;
|
|
27
|
+
exports.StreamflowDistributorSolana = __importStar(require("./solana"));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
2
|
+
import { ICluster, ITransactionResult } from "@streamflow/common";
|
|
3
|
+
import { IClaimData, IClawbackData, ICreateDistributorData, ICreateDistributorResult, IGetClaimsData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt } from "./types";
|
|
4
|
+
import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
|
|
5
|
+
interface IInitOptions {
|
|
6
|
+
clusterUrl: string;
|
|
7
|
+
cluster?: ICluster;
|
|
8
|
+
commitment?: Commitment | ConnectionConfig;
|
|
9
|
+
programId?: string;
|
|
10
|
+
}
|
|
11
|
+
export default class SolanaDistributorClient {
|
|
12
|
+
private connection;
|
|
13
|
+
private programId;
|
|
14
|
+
private commitment;
|
|
15
|
+
/**
|
|
16
|
+
* Create Stream instance
|
|
17
|
+
*/
|
|
18
|
+
constructor({ clusterUrl, cluster, commitment, programId }: IInitOptions);
|
|
19
|
+
create(data: ICreateDistributorData, { invoker, isNative }: ICreateSolanaExt): Promise<ICreateDistributorResult>;
|
|
20
|
+
claim(data: IClaimData, { invoker }: IInteractSolanaExt): Promise<ITransactionResult>;
|
|
21
|
+
clawback(data: IClawbackData, { invoker }: IInteractSolanaExt): Promise<ITransactionResult>;
|
|
22
|
+
getClaims(data: IGetClaimsData): Promise<(ClaimStatus | null)[]>;
|
|
23
|
+
getDistributors(data: IGetDistributors): Promise<(MerkleDistributor | null)[]>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,300 @@
|
|
|
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
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
63
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
64
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
|
+
};
|
|
66
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
68
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
69
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
70
|
+
var common_1 = require("@streamflow/common");
|
|
71
|
+
var solana_1 = require("@streamflow/common/solana");
|
|
72
|
+
var constants_1 = require("./constants");
|
|
73
|
+
var instructions_1 = require("./generated/instructions");
|
|
74
|
+
var accounts_1 = require("./generated/accounts");
|
|
75
|
+
var utils_1 = require("./utils");
|
|
76
|
+
var SolanaDistributorClient = /** @class */ (function () {
|
|
77
|
+
/**
|
|
78
|
+
* Create Stream instance
|
|
79
|
+
*/
|
|
80
|
+
function SolanaDistributorClient(_a) {
|
|
81
|
+
var clusterUrl = _a.clusterUrl, _b = _a.cluster, cluster = _b === void 0 ? common_1.ICluster.Mainnet : _b, _c = _a.commitment, commitment = _c === void 0 ? "confirmed" : _c, _d = _a.programId, programId = _d === void 0 ? "" : _d;
|
|
82
|
+
this.commitment = commitment;
|
|
83
|
+
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
84
|
+
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.DISTRIBUTOR_PROGRAM_ID[cluster]);
|
|
85
|
+
}
|
|
86
|
+
SolanaDistributorClient.prototype.create = function (data, _a) {
|
|
87
|
+
var invoker = _a.invoker, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var ixs, mint, mintAccount, distributorPublicKey, tokenVault, senderTokens, args, accounts, _c, _d, _e, _f, commitment, hash, tx, signature;
|
|
90
|
+
var _g;
|
|
91
|
+
return __generator(this, function (_h) {
|
|
92
|
+
switch (_h.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!invoker.publicKey) {
|
|
95
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
96
|
+
}
|
|
97
|
+
ixs = [];
|
|
98
|
+
mint = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(data.mint);
|
|
99
|
+
return [4 /*yield*/, (0, spl_token_1.getMint)(this.connection, mint)];
|
|
100
|
+
case 1:
|
|
101
|
+
mintAccount = _h.sent();
|
|
102
|
+
distributorPublicKey = (0, utils_1.getDistributorPda)(this.programId, mint, data.version);
|
|
103
|
+
return [4 /*yield*/, (0, solana_1.ata)(mint, distributorPublicKey)];
|
|
104
|
+
case 2:
|
|
105
|
+
tokenVault = _h.sent();
|
|
106
|
+
return [4 /*yield*/, (0, solana_1.ata)(mint, invoker.publicKey)];
|
|
107
|
+
case 3:
|
|
108
|
+
senderTokens = _h.sent();
|
|
109
|
+
args = {
|
|
110
|
+
version: new bn_js_1.default(data.version, 10),
|
|
111
|
+
root: data.root,
|
|
112
|
+
maxTotalClaim: data.maxTotalClaim,
|
|
113
|
+
maxNumNodes: data.maxNumNodes,
|
|
114
|
+
unlockPeriod: new bn_js_1.default(data.unlockPeriod, 10),
|
|
115
|
+
startVestingTs: new bn_js_1.default(data.startVestingTs, 10),
|
|
116
|
+
endVestingTs: new bn_js_1.default(data.endVestingTs, 10),
|
|
117
|
+
clawbackStartTs: new bn_js_1.default(data.clawbackStartTs, 10),
|
|
118
|
+
claimsClosable: data.claimsClosable,
|
|
119
|
+
};
|
|
120
|
+
accounts = {
|
|
121
|
+
distributor: distributorPublicKey,
|
|
122
|
+
clawbackReceiver: senderTokens,
|
|
123
|
+
mint: mint,
|
|
124
|
+
tokenVault: tokenVault,
|
|
125
|
+
admin: invoker.publicKey,
|
|
126
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
127
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
128
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
129
|
+
};
|
|
130
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
131
|
+
_d = (_c = ixs.push).apply;
|
|
132
|
+
_e = [ixs];
|
|
133
|
+
_f = [[]];
|
|
134
|
+
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, data.maxTotalClaim)];
|
|
135
|
+
case 4:
|
|
136
|
+
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
137
|
+
_h.label = 5;
|
|
138
|
+
case 5:
|
|
139
|
+
ixs.push((0, instructions_1.newDistributor)(args, accounts, this.programId));
|
|
140
|
+
ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mint, tokenVault, invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals));
|
|
141
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
142
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
143
|
+
case 6:
|
|
144
|
+
hash = _h.sent();
|
|
145
|
+
tx = (_g = new web3_js_1.Transaction({
|
|
146
|
+
feePayer: invoker.publicKey,
|
|
147
|
+
blockhash: hash.blockhash,
|
|
148
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
149
|
+
})).add.apply(_g, __spreadArray([], __read(ixs), false));
|
|
150
|
+
return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
151
|
+
case 7:
|
|
152
|
+
signature = _h.sent();
|
|
153
|
+
return [2 /*return*/, {
|
|
154
|
+
ixs: ixs,
|
|
155
|
+
txId: signature,
|
|
156
|
+
metadataId: distributorPublicKey.toBase58(),
|
|
157
|
+
}];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
SolanaDistributorClient.prototype.claim = function (data, _a) {
|
|
163
|
+
var invoker = _a.invoker;
|
|
164
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
+
var distributorPublicKey, distributor, ixs, invokerTokens, claimStatusPublicKey, claimStatus, accounts, args, commitment, hash, tx, signature;
|
|
166
|
+
var _b;
|
|
167
|
+
return __generator(this, function (_c) {
|
|
168
|
+
switch (_c.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
if (!invoker.publicKey) {
|
|
171
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
172
|
+
}
|
|
173
|
+
distributorPublicKey = new web3_js_1.PublicKey(data.id);
|
|
174
|
+
return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
|
|
175
|
+
case 1:
|
|
176
|
+
distributor = _c.sent();
|
|
177
|
+
if (!distributor) {
|
|
178
|
+
throw new Error("Couldn't get account info");
|
|
179
|
+
}
|
|
180
|
+
return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [invoker.publicKey], distributor.mint, invoker)];
|
|
181
|
+
case 2:
|
|
182
|
+
ixs = _c.sent();
|
|
183
|
+
return [4 /*yield*/, (0, solana_1.ata)(distributor.mint, invoker.publicKey)];
|
|
184
|
+
case 3:
|
|
185
|
+
invokerTokens = _c.sent();
|
|
186
|
+
claimStatusPublicKey = (0, utils_1.getClaimantStatusPda)(this.programId, distributorPublicKey, invoker.publicKey);
|
|
187
|
+
return [4 /*yield*/, accounts_1.ClaimStatus.fetch(this.connection, claimStatusPublicKey)];
|
|
188
|
+
case 4:
|
|
189
|
+
claimStatus = _c.sent();
|
|
190
|
+
accounts = {
|
|
191
|
+
distributor: distributorPublicKey,
|
|
192
|
+
claimStatus: claimStatusPublicKey,
|
|
193
|
+
from: distributor.tokenVault,
|
|
194
|
+
to: invokerTokens,
|
|
195
|
+
claimant: invoker.publicKey,
|
|
196
|
+
mint: distributor.mint,
|
|
197
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
198
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
199
|
+
};
|
|
200
|
+
if (claimStatus) {
|
|
201
|
+
ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
args = {
|
|
205
|
+
amountLocked: data.amountLocked,
|
|
206
|
+
amountUnlocked: data.amountUnlocked,
|
|
207
|
+
proof: data.proof,
|
|
208
|
+
};
|
|
209
|
+
ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
|
|
210
|
+
}
|
|
211
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
212
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
213
|
+
case 5:
|
|
214
|
+
hash = _c.sent();
|
|
215
|
+
tx = (_b = new web3_js_1.Transaction({
|
|
216
|
+
feePayer: invoker.publicKey,
|
|
217
|
+
blockhash: hash.blockhash,
|
|
218
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
219
|
+
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
220
|
+
return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
221
|
+
case 6:
|
|
222
|
+
signature = _c.sent();
|
|
223
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
SolanaDistributorClient.prototype.clawback = function (data, _a) {
|
|
229
|
+
var invoker = _a.invoker;
|
|
230
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
+
var distributorPublicKey, distributor, ixs, accounts, commitment, hash, tx, signature;
|
|
232
|
+
var _b;
|
|
233
|
+
return __generator(this, function (_c) {
|
|
234
|
+
switch (_c.label) {
|
|
235
|
+
case 0:
|
|
236
|
+
if (!invoker.publicKey) {
|
|
237
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
238
|
+
}
|
|
239
|
+
distributorPublicKey = new web3_js_1.PublicKey(data.id);
|
|
240
|
+
return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
|
|
241
|
+
case 1:
|
|
242
|
+
distributor = _c.sent();
|
|
243
|
+
if (!distributor) {
|
|
244
|
+
throw new Error("Couldn't get account info");
|
|
245
|
+
}
|
|
246
|
+
return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [invoker.publicKey], distributor.mint, invoker)];
|
|
247
|
+
case 2:
|
|
248
|
+
ixs = _c.sent();
|
|
249
|
+
accounts = {
|
|
250
|
+
distributor: distributorPublicKey,
|
|
251
|
+
from: distributor.tokenVault,
|
|
252
|
+
to: distributor.clawbackReceiver,
|
|
253
|
+
claimant: invoker.publicKey,
|
|
254
|
+
mint: distributor.mint,
|
|
255
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
256
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
257
|
+
};
|
|
258
|
+
ixs.push((0, instructions_1.clawback)(accounts, this.programId));
|
|
259
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
260
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
261
|
+
case 3:
|
|
262
|
+
hash = _c.sent();
|
|
263
|
+
tx = (_b = new web3_js_1.Transaction({
|
|
264
|
+
feePayer: invoker.publicKey,
|
|
265
|
+
blockhash: hash.blockhash,
|
|
266
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
267
|
+
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
268
|
+
return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
269
|
+
case 4:
|
|
270
|
+
signature = _c.sent();
|
|
271
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
SolanaDistributorClient.prototype.getClaims = function (data) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
278
|
+
var distributorPublicKey, claimStatusPublicKeys;
|
|
279
|
+
var _this = this;
|
|
280
|
+
return __generator(this, function (_a) {
|
|
281
|
+
distributorPublicKey = new web3_js_1.PublicKey(data.id);
|
|
282
|
+
claimStatusPublicKeys = data.recipients.map(function (recipient) {
|
|
283
|
+
return (0, utils_1.getClaimantStatusPda)(_this.programId, distributorPublicKey, new web3_js_1.PublicKey(recipient));
|
|
284
|
+
});
|
|
285
|
+
return [2 /*return*/, accounts_1.ClaimStatus.fetchMultiple(this.connection, claimStatusPublicKeys, this.programId)];
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
SolanaDistributorClient.prototype.getDistributors = function (data) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
var distributorPublicKeys;
|
|
292
|
+
return __generator(this, function (_a) {
|
|
293
|
+
distributorPublicKeys = data.ids.map(function (distributorId) { return new web3_js_1.PublicKey(distributorId); });
|
|
294
|
+
return [2 /*return*/, accounts_1.MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId)];
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
return SolanaDistributorClient;
|
|
299
|
+
}());
|
|
300
|
+
exports.default = SolanaDistributorClient;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DISTRIBUTOR_PROGRAM_ID = void 0;
|
|
5
|
+
var common_1 = require("@streamflow/common");
|
|
6
|
+
exports.DISTRIBUTOR_PROGRAM_ID = (_a = {},
|
|
7
|
+
_a[common_1.ICluster.Devnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
8
|
+
_a[common_1.ICluster.Mainnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
9
|
+
_a[common_1.ICluster.Testnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
10
|
+
_a[common_1.ICluster.Local] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
11
|
+
_a);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PublicKey, Connection } from "@solana/web3.js";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
export interface ClaimStatusFields {
|
|
5
|
+
/** Authority that claimed the tokens. */
|
|
6
|
+
claimant: PublicKey;
|
|
7
|
+
/** Locked amount */
|
|
8
|
+
lockedAmount: BN;
|
|
9
|
+
/** Locked amount withdrawn */
|
|
10
|
+
lockedAmountWithdrawn: BN;
|
|
11
|
+
/** Unlocked amount */
|
|
12
|
+
unlockedAmount: BN;
|
|
13
|
+
/** Last claim time */
|
|
14
|
+
lastClaimTs: BN;
|
|
15
|
+
/** Track amount per unlock, can be useful for non-linear vesting */
|
|
16
|
+
lastAmountPerUnlock: BN;
|
|
17
|
+
/** Whether claim is closed */
|
|
18
|
+
closed: boolean;
|
|
19
|
+
/** Buffer for additional fields */
|
|
20
|
+
buffer1: Array<number>;
|
|
21
|
+
/** Buffer for additional fields */
|
|
22
|
+
buffer2: Array<number>;
|
|
23
|
+
}
|
|
24
|
+
export interface ClaimStatusJSON {
|
|
25
|
+
/** Authority that claimed the tokens. */
|
|
26
|
+
claimant: string;
|
|
27
|
+
/** Locked amount */
|
|
28
|
+
lockedAmount: string;
|
|
29
|
+
/** Locked amount withdrawn */
|
|
30
|
+
lockedAmountWithdrawn: string;
|
|
31
|
+
/** Unlocked amount */
|
|
32
|
+
unlockedAmount: string;
|
|
33
|
+
/** Last claim time */
|
|
34
|
+
lastClaimTs: string;
|
|
35
|
+
/** Track amount per unlock, can be useful for non-linear vesting */
|
|
36
|
+
lastAmountPerUnlock: string;
|
|
37
|
+
/** Whether claim is closed */
|
|
38
|
+
closed: boolean;
|
|
39
|
+
/** Buffer for additional fields */
|
|
40
|
+
buffer1: Array<number>;
|
|
41
|
+
/** Buffer for additional fields */
|
|
42
|
+
buffer2: Array<number>;
|
|
43
|
+
}
|
|
44
|
+
/** Holds whether or not a claimant has claimed tokens. */
|
|
45
|
+
export declare class ClaimStatus {
|
|
46
|
+
/** Authority that claimed the tokens. */
|
|
47
|
+
readonly claimant: PublicKey;
|
|
48
|
+
/** Locked amount */
|
|
49
|
+
readonly lockedAmount: BN;
|
|
50
|
+
/** Locked amount withdrawn */
|
|
51
|
+
readonly lockedAmountWithdrawn: BN;
|
|
52
|
+
/** Unlocked amount */
|
|
53
|
+
readonly unlockedAmount: BN;
|
|
54
|
+
/** Last claim time */
|
|
55
|
+
readonly lastClaimTs: BN;
|
|
56
|
+
/** Track amount per unlock, can be useful for non-linear vesting */
|
|
57
|
+
readonly lastAmountPerUnlock: BN;
|
|
58
|
+
/** Whether claim is closed */
|
|
59
|
+
readonly closed: boolean;
|
|
60
|
+
/** Buffer for additional fields */
|
|
61
|
+
readonly buffer1: Array<number>;
|
|
62
|
+
/** Buffer for additional fields */
|
|
63
|
+
readonly buffer2: Array<number>;
|
|
64
|
+
static readonly discriminator: Buffer;
|
|
65
|
+
static readonly layout: any;
|
|
66
|
+
constructor(fields: ClaimStatusFields);
|
|
67
|
+
static fetch(c: Connection, address: PublicKey, programId?: PublicKey): Promise<ClaimStatus | null>;
|
|
68
|
+
static fetchMultiple(c: Connection, addresses: PublicKey[], programId?: PublicKey): Promise<Array<ClaimStatus | null>>;
|
|
69
|
+
static decode(data: Buffer): ClaimStatus;
|
|
70
|
+
toJSON(): ClaimStatusJSON;
|
|
71
|
+
static fromJSON(obj: ClaimStatusJSON): ClaimStatus;
|
|
72
|
+
}
|