@streamflow/distributor 6.3.8 → 7.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{solana → cjs/solana}/generated/instructions/clawback.js +2 -1
- package/dist/{solana → cjs/solana}/generated/instructions/closeClaim.js +2 -1
- package/dist/{solana → cjs/solana}/generated/instructions/newDistributor.js +4 -3
- package/dist/{solana → cjs/solana}/generated/instructions/setAdmin.js +2 -1
- package/dist/{solana → cjs/solana}/generated/instructions/setClawbackReceiver.js +2 -1
- package/dist/{solana → cjs/solana}/utils.js +5 -4
- package/dist/esm/index.js +1 -0
- package/dist/esm/solana/client.js +188 -0
- package/dist/esm/solana/constants.js +8 -0
- package/dist/esm/solana/generated/accounts/ClaimStatus.js +113 -0
- package/dist/esm/solana/generated/accounts/MerkleDistributor.js +190 -0
- package/dist/esm/solana/generated/accounts/index.js +2 -0
- package/dist/esm/solana/generated/errors/anchor.js +707 -0
- package/dist/esm/solana/generated/errors/custom.js +252 -0
- package/dist/esm/solana/generated/errors/index.js +37 -0
- package/dist/esm/solana/generated/instructions/claimLocked.js +19 -0
- package/dist/esm/solana/generated/instructions/clawback.js +18 -0
- package/dist/esm/solana/generated/instructions/closeClaim.js +18 -0
- package/dist/esm/solana/generated/instructions/index.js +7 -0
- package/dist/esm/solana/generated/instructions/newClaim.js +32 -0
- package/dist/esm/solana/generated/instructions/newDistributor.js +67 -0
- package/dist/esm/solana/generated/instructions/setAdmin.js +14 -0
- package/dist/esm/solana/generated/instructions/setClawbackReceiver.js +14 -0
- package/dist/esm/solana/generated/programId.js +5 -0
- package/dist/esm/solana/index.js +7 -0
- package/dist/esm/solana/types.js +156 -0
- package/dist/esm/solana/utils.js +60 -0
- package/package.json +20 -19
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{solana → cjs/solana}/client.js +0 -0
- /package/dist/{solana → cjs/solana}/constants.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/accounts/ClaimStatus.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/accounts/MerkleDistributor.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/accounts/index.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/errors/anchor.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/errors/custom.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/errors/index.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/instructions/claimLocked.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/instructions/index.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/instructions/newClaim.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/programId.js +0 -0
- /package/dist/{solana → cjs/solana}/index.js +0 -0
- /package/dist/{solana → cjs/solana}/types.js +0 -0
- /package/dist/{index.d.ts → esm/index.d.ts} +0 -0
- /package/dist/{solana → esm/solana}/client.d.ts +0 -0
- /package/dist/{solana → esm/solana}/constants.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/accounts/ClaimStatus.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/accounts/MerkleDistributor.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/accounts/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/errors/anchor.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/errors/custom.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/errors/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/claimLocked.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/clawback.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/closeClaim.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/newClaim.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/newDistributor.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/setAdmin.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/setClawbackReceiver.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/programId.d.ts +0 -0
- /package/dist/{solana → esm/solana}/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/types.d.ts +0 -0
- /package/dist/{solana → esm/solana}/utils.d.ts +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Buffer } from "buffer";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { ContractError } from "@streamflow/common";
|
|
4
|
+
import { signAndExecuteTransaction } from "@streamflow/common/solana";
|
|
5
|
+
import { fromTxError } from "./generated/errors";
|
|
6
|
+
import { ONE_IN_BASIS_POINTS } from "./constants";
|
|
7
|
+
export const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
|
|
8
|
+
export function getDistributorPda(programId, mint, version) {
|
|
9
|
+
// Constructing the seed for the PDA
|
|
10
|
+
const seeds = [
|
|
11
|
+
Buffer.from("MerkleDistributor"),
|
|
12
|
+
mint.toBuffer(),
|
|
13
|
+
Buffer.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer)),
|
|
14
|
+
];
|
|
15
|
+
// Finding the PDA
|
|
16
|
+
return PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
17
|
+
}
|
|
18
|
+
export function getClaimantStatusPda(programId, distributor, claimant) {
|
|
19
|
+
// Constructing the seed for the PDA
|
|
20
|
+
const seeds = [Buffer.from("ClaimStatus"), claimant.toBuffer(), distributor.toBuffer()];
|
|
21
|
+
// Finding the PDA
|
|
22
|
+
return PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
23
|
+
}
|
|
24
|
+
export function getEventAuthorityPda(programId) {
|
|
25
|
+
// Constructing the seed for the PDA
|
|
26
|
+
const seeds = [Buffer.from("__event_authority")];
|
|
27
|
+
// Finding the PDA
|
|
28
|
+
return PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
29
|
+
}
|
|
30
|
+
export async function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
|
|
31
|
+
try {
|
|
32
|
+
return await signAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof Error) {
|
|
36
|
+
const parsed = fromTxError(err);
|
|
37
|
+
if (parsed) {
|
|
38
|
+
throw new ContractError(err, parsed.name, parsed.msg);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
|
|
45
|
+
const epoch = await connection.getEpochInfo();
|
|
46
|
+
const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
|
|
47
|
+
? transferFeeConfig.newerTransferFee
|
|
48
|
+
: transferFeeConfig.olderTransferFee;
|
|
49
|
+
const transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
|
|
50
|
+
let feeCharged = BigInt(0);
|
|
51
|
+
if (transferFeeBasisPoints !== BigInt(0)) {
|
|
52
|
+
const numerator = transferAmount * ONE_IN_BASIS_POINTS;
|
|
53
|
+
const denominator = ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
|
|
54
|
+
const rawPreFeeAmount = divCeilN(numerator, denominator);
|
|
55
|
+
const fee = rawPreFeeAmount - transferAmount;
|
|
56
|
+
transferAmount = rawPreFeeAmount;
|
|
57
|
+
feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
|
|
58
|
+
}
|
|
59
|
+
return { transferAmount, feeCharged };
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/distributor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"types": "./dist/esm/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./solana": {
|
|
16
|
+
"import": "./dist/esm/solana/index.js",
|
|
17
|
+
"require": "./dist/cjs/solana/index.js",
|
|
18
|
+
"types": "./dist/esm/solana/index.d.ts"
|
|
17
19
|
}
|
|
18
20
|
},
|
|
19
21
|
"scripts": {
|
|
20
|
-
"build": "rm -rf dist; tsc -p tsconfig.json",
|
|
22
|
+
"build:cjs": "rm -rf dist/cjs; tsc -p tsconfig.cjs.json",
|
|
23
|
+
"build:esm": "rm -rf dist/esm; tsc -p tsconfig.esm.json",
|
|
24
|
+
"build": "rm -rf dist; pnpm run build:cjs && pnpm run build:esm",
|
|
21
25
|
"pack": "pnpm build && pnpm pack",
|
|
22
26
|
"lint": "eslint --fix .",
|
|
23
27
|
"prepublishOnly": "npm run lint && npm run build"
|
|
24
28
|
},
|
|
25
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "8b2be143ac1bfeaca3bcecc11eb5fa1e81f2ffb7",
|
|
26
30
|
"devDependencies": {
|
|
27
|
-
"@streamflow/eslint-config": "
|
|
31
|
+
"@streamflow/eslint-config": "7.0.0-alpha.1",
|
|
28
32
|
"@types/bn.js": "5.1.1",
|
|
29
|
-
"@types/jest": "29.2.4",
|
|
30
33
|
"date-fns": "2.28.0",
|
|
31
|
-
"jest": "29.3.1",
|
|
32
|
-
"ts-jest": "29.0.3",
|
|
33
34
|
"typescript": "^4.9.5"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
@@ -38,10 +39,10 @@
|
|
|
38
39
|
"@solana/spl-token": "0.3.6",
|
|
39
40
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
40
41
|
"@solana/web3.js": "1.70.1",
|
|
41
|
-
"@streamflow/common": "
|
|
42
|
+
"@streamflow/common": "7.0.0-alpha.1",
|
|
42
43
|
"bn.js": "5.2.1",
|
|
43
44
|
"borsh": "^2.0.0",
|
|
44
45
|
"bs58": "5.0.0",
|
|
45
|
-
"p-queue": "^
|
|
46
|
+
"p-queue": "^8.0.1"
|
|
46
47
|
}
|
|
47
48
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|