@streamflow/distributor 7.0.0-alpha.2 → 7.0.0-alpha.20
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 +19 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/solana/clients/BaseDistributorClient.js +222 -0
- package/dist/cjs/solana/clients/SolanaAlignedDistributorClient.js +104 -0
- package/dist/cjs/solana/clients/SolanaDistributorClient.js +17 -0
- package/dist/cjs/solana/clients/index.js +10 -0
- package/dist/cjs/solana/constants.js +22 -9
- package/dist/cjs/solana/descriptor/aligned_distributor.js +2 -0
- package/dist/cjs/solana/descriptor/idl/aligned_distributor.json +1242 -0
- package/dist/cjs/solana/generated/accounts/ClaimStatus.js +56 -114
- package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +96 -129
- 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 +17 -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/index.js +8 -12
- package/dist/cjs/solana/utils.js +46 -94
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/solana/clients/BaseDistributorClient.d.ts +39 -0
- package/dist/esm/solana/{client.js → clients/BaseDistributorClient.js} +97 -66
- package/dist/esm/solana/clients/SolanaAlignedDistributorClient.d.ts +14 -0
- package/dist/esm/solana/clients/SolanaAlignedDistributorClient.js +99 -0
- package/dist/esm/solana/clients/SolanaDistributorClient.d.ts +8 -0
- package/dist/esm/solana/clients/SolanaDistributorClient.js +11 -0
- package/dist/esm/solana/clients/index.d.ts +2 -0
- package/dist/esm/solana/clients/index.js +2 -0
- package/dist/esm/solana/constants.d.ts +15 -0
- package/dist/esm/solana/constants.js +14 -0
- package/dist/esm/solana/descriptor/aligned_distributor.d.ts +918 -0
- package/dist/esm/solana/descriptor/aligned_distributor.js +1 -0
- package/dist/esm/solana/descriptor/idl/aligned_distributor.json +1242 -0
- package/dist/esm/solana/generated/accounts/ClaimStatus.d.ts +17 -17
- package/dist/esm/solana/generated/accounts/ClaimStatus.js +13 -13
- package/dist/esm/solana/generated/accounts/MerkleDistributor.d.ts +55 -25
- package/dist/esm/solana/generated/accounts/MerkleDistributor.js +53 -18
- package/dist/esm/solana/generated/instructions/newClaim.d.ts +3 -3
- package/dist/esm/solana/generated/instructions/newDistributor.d.ts +8 -8
- package/dist/esm/solana/generated/instructions/newDistributor.js +6 -0
- package/dist/esm/solana/index.d.ts +7 -7
- package/dist/esm/solana/index.js +7 -7
- package/dist/esm/solana/types.d.ts +49 -4
- package/dist/esm/solana/utils.d.ts +2 -1
- package/dist/esm/solana/utils.js +11 -6
- package/package.json +9 -7
- package/dist/cjs/solana/client.js +0 -365
- package/dist/esm/solana/client.d.ts +0 -36
|
@@ -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"),
|
|
@@ -38,6 +38,9 @@ exports.layout = borsh.struct([
|
|
|
38
38
|
borsh.u64("endVestingTs"),
|
|
39
39
|
borsh.u64("clawbackStartTs"),
|
|
40
40
|
borsh.bool("claimsClosable"),
|
|
41
|
+
borsh.option(borsh.bool(), "canUpdateDuration"),
|
|
42
|
+
borsh.option(borsh.u64(), "totalAmountUnlocked"),
|
|
43
|
+
borsh.option(borsh.u64(), "totalAmountLocked"),
|
|
41
44
|
]);
|
|
42
45
|
/**
|
|
43
46
|
* READ THE FOLLOWING:
|
|
@@ -59,9 +62,8 @@ exports.layout = borsh.struct([
|
|
|
59
62
|
* assert the parameters are what you expect, most importantly the clawback_receiver and admin.
|
|
60
63
|
* - If your transaction fails, double check the value on-chain matches what you expect.
|
|
61
64
|
*/
|
|
62
|
-
function newDistributor(args, accounts, programId) {
|
|
63
|
-
|
|
64
|
-
var keys = [
|
|
65
|
+
function newDistributor(args, accounts, programId = programId_1.PROGRAM_ID) {
|
|
66
|
+
const keys = [
|
|
65
67
|
{ pubkey: accounts.distributor, isSigner: false, isWritable: true },
|
|
66
68
|
{ pubkey: accounts.clawbackReceiver, isSigner: false, isWritable: true },
|
|
67
69
|
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
@@ -75,9 +77,9 @@ function newDistributor(args, accounts, programId) {
|
|
|
75
77
|
},
|
|
76
78
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
77
79
|
];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
const identifier = buffer_1.Buffer.from([32, 139, 112, 171, 0, 2, 225, 155]);
|
|
81
|
+
const buffer = buffer_1.Buffer.alloc(1000);
|
|
82
|
+
const len = exports.layout.encode({
|
|
81
83
|
version: args.version,
|
|
82
84
|
root: args.root,
|
|
83
85
|
maxTotalClaim: args.maxTotalClaim,
|
|
@@ -87,9 +89,12 @@ function newDistributor(args, accounts, programId) {
|
|
|
87
89
|
endVestingTs: args.endVestingTs,
|
|
88
90
|
clawbackStartTs: args.clawbackStartTs,
|
|
89
91
|
claimsClosable: args.claimsClosable,
|
|
92
|
+
canUpdateDuration: null,
|
|
93
|
+
totalAmountUnlocked: null,
|
|
94
|
+
totalAmountLocked: null,
|
|
90
95
|
}, buffer);
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
const data = buffer_1.Buffer.concat([identifier, buffer]).slice(0, 8 + len);
|
|
97
|
+
const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
93
98
|
return ix;
|
|
94
99
|
}
|
|
95
100
|
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/index.js
CHANGED
|
@@ -25,16 +25,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
__setModuleDefault(result, mod);
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.constants =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
__exportStar(require("./generated/
|
|
36
|
-
__exportStar(require("./generated/
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./
|
|
39
|
-
|
|
40
|
-
exports.constants = __importStar(require("./constants"));
|
|
29
|
+
exports.constants = void 0;
|
|
30
|
+
__exportStar(require("./clients/index.js"), exports);
|
|
31
|
+
__exportStar(require("./generated/accounts/index.js"), exports);
|
|
32
|
+
__exportStar(require("./generated/errors/index.js"), exports);
|
|
33
|
+
__exportStar(require("./generated/instructions/index.js"), exports);
|
|
34
|
+
__exportStar(require("./utils.js"), exports);
|
|
35
|
+
__exportStar(require("./types.js"), exports);
|
|
36
|
+
exports.constants = __importStar(require("./constants.js"));
|
package/dist/cjs/solana/utils.js
CHANGED
|
@@ -1,54 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateAmountWithTransferFees = exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = exports.getTestOraclePda = exports.getAlignedDistributorPda = void 0;
|
|
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 index_js_1 = require("./generated/errors/index.js");
|
|
9
|
+
const constants_js_1 = require("./constants.js");
|
|
10
|
+
const getAlignedDistributorPda = (programId, distributor) => {
|
|
11
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_js_1.ALIGNED_DISTRIBUTOR_PREFIX, distributor.toBuffer()], programId)[0];
|
|
10
12
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
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
|
-
}
|
|
13
|
+
exports.getAlignedDistributorPda = getAlignedDistributorPda;
|
|
14
|
+
const getTestOraclePda = (programId, mint, creator) => {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_js_1.TEST_ORACLE_PREFIX, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
37
16
|
};
|
|
38
|
-
|
|
39
|
-
exports.calculateAmountWithTransferFees = exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = exports.divCeilN = void 0;
|
|
40
|
-
var buffer_1 = require("buffer");
|
|
41
|
-
var web3_js_1 = require("@solana/web3.js");
|
|
42
|
-
var common_1 = require("@streamflow/common");
|
|
43
|
-
var solana_1 = require("@streamflow/common/solana");
|
|
44
|
-
var errors_1 = require("./generated/errors");
|
|
45
|
-
var constants_1 = require("./constants");
|
|
46
|
-
var divCeilN = function (n, d) { return n / d + (n % d ? BigInt(1) : BigInt(0)); };
|
|
47
|
-
exports.divCeilN = divCeilN;
|
|
17
|
+
exports.getTestOraclePda = getTestOraclePda;
|
|
48
18
|
function getDistributorPda(programId, mint, version) {
|
|
49
19
|
// Constructing the seed for the PDA
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
const seeds = [
|
|
21
|
+
constants_js_1.DISTRIBUTOR_PREFIX,
|
|
52
22
|
mint.toBuffer(),
|
|
53
23
|
buffer_1.Buffer.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer)),
|
|
54
24
|
];
|
|
@@ -58,66 +28,48 @@ function getDistributorPda(programId, mint, version) {
|
|
|
58
28
|
exports.getDistributorPda = getDistributorPda;
|
|
59
29
|
function getClaimantStatusPda(programId, distributor, claimant) {
|
|
60
30
|
// Constructing the seed for the PDA
|
|
61
|
-
|
|
31
|
+
const seeds = [constants_js_1.CLAIM_STATUS_PREFIX, claimant.toBuffer(), distributor.toBuffer()];
|
|
62
32
|
// Finding the PDA
|
|
63
33
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
64
34
|
}
|
|
65
35
|
exports.getClaimantStatusPda = getClaimantStatusPda;
|
|
66
36
|
function getEventAuthorityPda(programId) {
|
|
67
37
|
// Constructing the seed for the PDA
|
|
68
|
-
|
|
38
|
+
const seeds = [buffer_1.Buffer.from("__event_authority")];
|
|
69
39
|
// Finding the PDA
|
|
70
40
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
71
41
|
}
|
|
72
42
|
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*/];
|
|
43
|
+
async function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
|
|
44
|
+
try {
|
|
45
|
+
return await (0, solana_1.signAndExecuteTransaction)(connection, invoker, tx, confirmationParams, throttleParams);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err instanceof Error) {
|
|
49
|
+
const parsed = (0, index_js_1.fromTxError)(err);
|
|
50
|
+
if (parsed) {
|
|
51
|
+
throw new common_1.ContractError(err, parsed.name, parsed.msg);
|
|
92
52
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
95
56
|
}
|
|
96
57
|
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
|
-
});
|
|
58
|
+
async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
|
|
59
|
+
const epoch = await connection.getEpochInfo();
|
|
60
|
+
const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
|
|
61
|
+
? transferFeeConfig.newerTransferFee
|
|
62
|
+
: transferFeeConfig.olderTransferFee;
|
|
63
|
+
const transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
|
|
64
|
+
let feeCharged = BigInt(0);
|
|
65
|
+
if (transferFeeBasisPoints !== BigInt(0)) {
|
|
66
|
+
const numerator = transferAmount * constants_js_1.ONE_IN_BASIS_POINTS;
|
|
67
|
+
const denominator = constants_js_1.ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
|
|
68
|
+
const rawPreFeeAmount = (0, common_1.divCeilN)(numerator, denominator);
|
|
69
|
+
const fee = rawPreFeeAmount - transferAmount;
|
|
70
|
+
transferAmount = rawPreFeeAmount;
|
|
71
|
+
feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
|
|
72
|
+
}
|
|
73
|
+
return { transferAmount, feeCharged };
|
|
122
74
|
}
|
|
123
75
|
exports.calculateAmountWithTransferFees = calculateAmountWithTransferFees;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as StreamflowDistributorSolana from "./solana";
|
|
1
|
+
export * as StreamflowDistributorSolana from "./solana/index.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as StreamflowDistributorSolana from "./solana";
|
|
1
|
+
export * as StreamflowDistributorSolana from "./solana/index.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import PQueue from "p-queue";
|
|
2
|
+
import { Connection, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
|
|
3
|
+
import { ICluster, ITransactionResult } from "@streamflow/common";
|
|
4
|
+
import { IProgramAccount } from "@streamflow/common/solana";
|
|
5
|
+
import { IClaimData, IClawbackData, ICreateDistributorResult, IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt, ICreateDistributorData, ICreateAlignedDistributorData, ISearchDistributors } from "../types";
|
|
6
|
+
import { ClawbackAccounts, NewDistributorAccounts, NewDistributorArgs } from "../generated/instructions";
|
|
7
|
+
import { ClaimStatus, MerkleDistributor } from "../generated/accounts";
|
|
8
|
+
export interface IInitOptions {
|
|
9
|
+
clusterUrl: string;
|
|
10
|
+
cluster?: ICluster;
|
|
11
|
+
commitment?: Commitment | ConnectionConfig;
|
|
12
|
+
programId?: string;
|
|
13
|
+
sendRate?: number;
|
|
14
|
+
sendThrottler?: PQueue;
|
|
15
|
+
}
|
|
16
|
+
export default abstract class BaseDistributorClient {
|
|
17
|
+
protected connection: Connection;
|
|
18
|
+
protected programId: PublicKey;
|
|
19
|
+
protected commitment: Commitment | ConnectionConfig;
|
|
20
|
+
protected sendThrottler: PQueue;
|
|
21
|
+
constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler, }: IInitOptions);
|
|
22
|
+
protected abstract getNewDistributorInstruction(data: ICreateDistributorData | ICreateAlignedDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
|
|
23
|
+
protected abstract getClawbackInstruction(account: ClawbackAccounts): Promise<TransactionInstruction>;
|
|
24
|
+
getCommitment(): Commitment | undefined;
|
|
25
|
+
getDistributorProgramId(): PublicKey;
|
|
26
|
+
prepareCreateInstructions(data: ICreateDistributorData | ICreateAlignedDistributorData, extParams: ICreateSolanaExt): Promise<{
|
|
27
|
+
distributorPublicKey: PublicKey;
|
|
28
|
+
ixs: TransactionInstruction[];
|
|
29
|
+
}>;
|
|
30
|
+
create(data: ICreateDistributorData | ICreateAlignedDistributorData, extParams: ICreateSolanaExt): Promise<ICreateDistributorResult>;
|
|
31
|
+
claim(data: IClaimData, extParams: IInteractSolanaExt): Promise<ITransactionResult>;
|
|
32
|
+
prepareClaimInstructions(data: IClaimData, extParams: IInteractSolanaExt): Promise<TransactionInstruction[]>;
|
|
33
|
+
prepareClawbackInstructions(data: IClawbackData, extParams: IInteractSolanaExt): Promise<TransactionInstruction[]>;
|
|
34
|
+
clawback(data: IClawbackData, extParams: IInteractSolanaExt): Promise<ITransactionResult>;
|
|
35
|
+
getClaims(data: IGetClaimData[]): Promise<(ClaimStatus | null)[]>;
|
|
36
|
+
getDistributors(data: IGetDistributors): Promise<(MerkleDistributor | null)[]>;
|
|
37
|
+
searchDistributors(data: ISearchDistributors): Promise<IProgramAccount<MerkleDistributor>[]>;
|
|
38
|
+
protected getNewDistributorArgs(data: ICreateDistributorData): NewDistributorArgs;
|
|
39
|
+
}
|