@streamflow/distributor 7.0.0-alpha.3 → 7.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/solana/client.js +176 -350
- package/dist/cjs/solana/constants.js +7 -8
- package/dist/cjs/solana/generated/accounts/ClaimStatus.js +47 -105
- package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +58 -116
- package/dist/cjs/solana/generated/errors/anchor.js +540 -717
- package/dist/cjs/solana/generated/errors/custom.js +171 -243
- package/dist/cjs/solana/generated/errors/index.js +12 -51
- package/dist/cjs/solana/generated/instructions/claimLocked.js +7 -8
- package/dist/cjs/solana/generated/instructions/clawback.js +8 -9
- package/dist/cjs/solana/generated/instructions/closeClaim.js +8 -9
- package/dist/cjs/solana/generated/instructions/newClaim.js +10 -11
- package/dist/cjs/solana/generated/instructions/newDistributor.js +11 -12
- package/dist/cjs/solana/generated/instructions/setAdmin.js +8 -9
- package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +8 -9
- package/dist/cjs/solana/generated/programId.js +1 -1
- package/dist/cjs/solana/utils.js +38 -92
- package/package.json +4 -4
|
@@ -24,17 +24,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.newClaim = exports.layout = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
28
|
+
const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
|
+
const programId_1 = require("../programId");
|
|
30
30
|
exports.layout = borsh.struct([
|
|
31
31
|
borsh.u64("amountUnlocked"),
|
|
32
32
|
borsh.u64("amountLocked"),
|
|
33
33
|
borsh.vec(borsh.array(borsh.u8(), 32), "proof"),
|
|
34
34
|
]);
|
|
35
|
-
function newClaim(args, accounts, programId) {
|
|
36
|
-
|
|
37
|
-
var keys = [
|
|
35
|
+
function newClaim(args, accounts, programId = programId_1.PROGRAM_ID) {
|
|
36
|
+
const keys = [
|
|
38
37
|
{ pubkey: accounts.distributor, isSigner: false, isWritable: true },
|
|
39
38
|
{ pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
|
|
40
39
|
{ pubkey: accounts.from, isSigner: false, isWritable: true },
|
|
@@ -46,15 +45,15 @@ function newClaim(args, accounts, programId) {
|
|
|
46
45
|
{ pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
|
|
47
46
|
{ pubkey: accounts.program, isSigner: false, isWritable: false },
|
|
48
47
|
];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const identifier = Buffer.from([78, 177, 98, 123, 210, 21, 187, 83]);
|
|
49
|
+
const buffer = Buffer.alloc(1000);
|
|
50
|
+
const len = exports.layout.encode({
|
|
52
51
|
amountUnlocked: args.amountUnlocked,
|
|
53
52
|
amountLocked: args.amountLocked,
|
|
54
53
|
proof: args.proof,
|
|
55
54
|
}, buffer);
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
|
|
56
|
+
const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
58
57
|
return ix;
|
|
59
58
|
}
|
|
60
59
|
exports.newClaim = newClaim;
|
|
@@ -24,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.newDistributor = exports.layout = void 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
28
|
+
const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
|
+
const buffer_1 = require("buffer");
|
|
30
|
+
const programId_1 = require("../programId");
|
|
31
31
|
exports.layout = borsh.struct([
|
|
32
32
|
borsh.u64("version"),
|
|
33
33
|
borsh.array(borsh.u8(), 32, "root"),
|
|
@@ -59,9 +59,8 @@ exports.layout = borsh.struct([
|
|
|
59
59
|
* assert the parameters are what you expect, most importantly the clawback_receiver and admin.
|
|
60
60
|
* - If your transaction fails, double check the value on-chain matches what you expect.
|
|
61
61
|
*/
|
|
62
|
-
function newDistributor(args, accounts, programId) {
|
|
63
|
-
|
|
64
|
-
var keys = [
|
|
62
|
+
function newDistributor(args, accounts, programId = programId_1.PROGRAM_ID) {
|
|
63
|
+
const keys = [
|
|
65
64
|
{ pubkey: accounts.distributor, isSigner: false, isWritable: true },
|
|
66
65
|
{ pubkey: accounts.clawbackReceiver, isSigner: false, isWritable: true },
|
|
67
66
|
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
@@ -75,9 +74,9 @@ function newDistributor(args, accounts, programId) {
|
|
|
75
74
|
},
|
|
76
75
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
77
76
|
];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
const identifier = buffer_1.Buffer.from([32, 139, 112, 171, 0, 2, 225, 155]);
|
|
78
|
+
const buffer = buffer_1.Buffer.alloc(1000);
|
|
79
|
+
const len = exports.layout.encode({
|
|
81
80
|
version: args.version,
|
|
82
81
|
root: args.root,
|
|
83
82
|
maxTotalClaim: args.maxTotalClaim,
|
|
@@ -88,8 +87,8 @@ function newDistributor(args, accounts, programId) {
|
|
|
88
87
|
clawbackStartTs: args.clawbackStartTs,
|
|
89
88
|
claimsClosable: args.claimsClosable,
|
|
90
89
|
}, buffer);
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const data = buffer_1.Buffer.concat([identifier, buffer]).slice(0, 8 + len);
|
|
91
|
+
const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
93
92
|
return ix;
|
|
94
93
|
}
|
|
95
94
|
exports.newDistributor = newDistributor;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setAdmin = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function setAdmin(accounts, programId) {
|
|
8
|
-
|
|
9
|
-
var keys = [
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const programId_1 = require("../programId");
|
|
7
|
+
function setAdmin(accounts, programId = programId_1.PROGRAM_ID) {
|
|
8
|
+
const keys = [
|
|
10
9
|
{ pubkey: accounts.distributor, isSigner: false, isWritable: true },
|
|
11
10
|
{ pubkey: accounts.admin, isSigner: true, isWritable: true },
|
|
12
11
|
{ pubkey: accounts.newAdmin, isSigner: false, isWritable: true },
|
|
13
12
|
];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const identifier = buffer_1.Buffer.from([251, 163, 0, 52, 91, 194, 187, 92]);
|
|
14
|
+
const data = identifier;
|
|
15
|
+
const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
17
16
|
return ix;
|
|
18
17
|
}
|
|
19
18
|
exports.setAdmin = setAdmin;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setClawbackReceiver = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function setClawbackReceiver(accounts, programId) {
|
|
8
|
-
|
|
9
|
-
var keys = [
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const programId_1 = require("../programId");
|
|
7
|
+
function setClawbackReceiver(accounts, programId = programId_1.PROGRAM_ID) {
|
|
8
|
+
const keys = [
|
|
10
9
|
{ pubkey: accounts.distributor, isSigner: false, isWritable: true },
|
|
11
10
|
{ pubkey: accounts.newClawbackAccount, isSigner: false, isWritable: false },
|
|
12
11
|
{ pubkey: accounts.admin, isSigner: true, isWritable: true },
|
|
13
12
|
];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const identifier = buffer_1.Buffer.from([153, 217, 34, 20, 19, 29, 229, 75]);
|
|
14
|
+
const data = identifier;
|
|
15
|
+
const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
17
16
|
return ix;
|
|
18
17
|
}
|
|
19
18
|
exports.setClawbackReceiver = setClawbackReceiver;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROGRAM_ID = exports.PROGRAM_ID_CLI = void 0;
|
|
4
|
-
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
// Program ID passed with the cli --program-id flag when running the code generator. Do not edit, it will get overwritten.
|
|
6
6
|
exports.PROGRAM_ID_CLI = new web3_js_1.PublicKey("MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N");
|
|
7
7
|
// This constant will not get overwritten on subsequent code generations and it's safe to modify it's value.
|
package/dist/cjs/solana/utils.js
CHANGED
|
@@ -1,53 +1,17 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.calculateAmountWithTransferFees = exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = exports.divCeilN = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const common_1 = require("@streamflow/common");
|
|
7
|
+
const solana_1 = require("@streamflow/common/solana");
|
|
8
|
+
const errors_1 = require("./generated/errors");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
|
|
47
11
|
exports.divCeilN = divCeilN;
|
|
48
12
|
function getDistributorPda(programId, mint, version) {
|
|
49
13
|
// Constructing the seed for the PDA
|
|
50
|
-
|
|
14
|
+
const seeds = [
|
|
51
15
|
buffer_1.Buffer.from("MerkleDistributor"),
|
|
52
16
|
mint.toBuffer(),
|
|
53
17
|
buffer_1.Buffer.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer)),
|
|
@@ -58,66 +22,48 @@ function getDistributorPda(programId, mint, version) {
|
|
|
58
22
|
exports.getDistributorPda = getDistributorPda;
|
|
59
23
|
function getClaimantStatusPda(programId, distributor, claimant) {
|
|
60
24
|
// Constructing the seed for the PDA
|
|
61
|
-
|
|
25
|
+
const seeds = [buffer_1.Buffer.from("ClaimStatus"), claimant.toBuffer(), distributor.toBuffer()];
|
|
62
26
|
// Finding the PDA
|
|
63
27
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
64
28
|
}
|
|
65
29
|
exports.getClaimantStatusPda = getClaimantStatusPda;
|
|
66
30
|
function getEventAuthorityPda(programId) {
|
|
67
31
|
// Constructing the seed for the PDA
|
|
68
|
-
|
|
32
|
+
const seeds = [buffer_1.Buffer.from("__event_authority")];
|
|
69
33
|
// Finding the PDA
|
|
70
34
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
71
35
|
}
|
|
72
36
|
exports.getEventAuthorityPda = getEventAuthorityPda;
|
|
73
|
-
function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
case 2:
|
|
83
|
-
err_1 = _a.sent();
|
|
84
|
-
if (err_1 instanceof Error) {
|
|
85
|
-
parsed = (0, errors_1.fromTxError)(err_1);
|
|
86
|
-
if (parsed) {
|
|
87
|
-
throw new common_1.ContractError(err_1, parsed.name, parsed.msg);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
throw err_1;
|
|
91
|
-
case 3: return [2 /*return*/];
|
|
37
|
+
async function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
|
|
38
|
+
try {
|
|
39
|
+
return await (0, solana_1.signAndExecuteTransaction)(connection, invoker, tx, confirmationParams, throttleParams);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof Error) {
|
|
43
|
+
const parsed = (0, errors_1.fromTxError)(err);
|
|
44
|
+
if (parsed) {
|
|
45
|
+
throw new common_1.ContractError(err, parsed.name, parsed.msg);
|
|
92
46
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
95
50
|
}
|
|
96
51
|
exports.wrappedSignAndExecuteTransaction = wrappedSignAndExecuteTransaction;
|
|
97
|
-
function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
rawPreFeeAmount = (0, exports.divCeilN)(numerator, denominator);
|
|
114
|
-
fee = rawPreFeeAmount - transferAmount;
|
|
115
|
-
transferAmount = rawPreFeeAmount;
|
|
116
|
-
feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
|
|
117
|
-
}
|
|
118
|
-
return [2 /*return*/, { transferAmount: transferAmount, feeCharged: feeCharged }];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
52
|
+
async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
|
|
53
|
+
const epoch = await connection.getEpochInfo();
|
|
54
|
+
const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
|
|
55
|
+
? transferFeeConfig.newerTransferFee
|
|
56
|
+
: transferFeeConfig.olderTransferFee;
|
|
57
|
+
const transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
|
|
58
|
+
let feeCharged = BigInt(0);
|
|
59
|
+
if (transferFeeBasisPoints !== BigInt(0)) {
|
|
60
|
+
const numerator = transferAmount * constants_1.ONE_IN_BASIS_POINTS;
|
|
61
|
+
const denominator = constants_1.ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
|
|
62
|
+
const rawPreFeeAmount = (0, exports.divCeilN)(numerator, denominator);
|
|
63
|
+
const fee = rawPreFeeAmount - transferAmount;
|
|
64
|
+
transferAmount = rawPreFeeAmount;
|
|
65
|
+
feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
|
|
66
|
+
}
|
|
67
|
+
return { transferAmount, feeCharged };
|
|
122
68
|
}
|
|
123
69
|
exports.calculateAmountWithTransferFees = calculateAmountWithTransferFees;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/distributor",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.6",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"lint": "eslint --fix .",
|
|
27
27
|
"prepublishOnly": "npm run lint && npm run build"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "f789b5ddcc3d6fb9b84beb0b16f63c6348bd37ab",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@streamflow/eslint-config": "7.0.0-alpha.
|
|
31
|
+
"@streamflow/eslint-config": "7.0.0-alpha.6",
|
|
32
32
|
"date-fns": "2.28.0",
|
|
33
33
|
"typescript": "^4.9.5"
|
|
34
34
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@solana/spl-token": "0.3.6",
|
|
39
39
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
40
40
|
"@solana/web3.js": "1.70.1",
|
|
41
|
-
"@streamflow/common": "7.0.0-alpha.
|
|
41
|
+
"@streamflow/common": "7.0.0-alpha.6",
|
|
42
42
|
"bignumber.js": "^9.1.2",
|
|
43
43
|
"borsh": "^2.0.0",
|
|
44
44
|
"bs58": "5.0.0",
|