@show-karma/karma-gap-sdk 0.3.33 → 0.3.35
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/core/class/GrantProgramRegistry/Allo.d.ts +7 -6
- package/core/class/GrantProgramRegistry/Allo.js +23 -8
- package/core/class/GrantProgramRegistry/AlloRegistry.d.ts +5 -4
- package/core/class/GrantProgramRegistry/AlloRegistry.js +15 -6
- package/core/class/remote-storage/IpfsStorage.d.ts +5 -2
- package/core/class/remote-storage/IpfsStorage.js +21 -4
- package/package.json +1 -2
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
import pinataSDK from "@pinata/sdk";
|
|
3
2
|
export declare class AlloBase {
|
|
4
3
|
private signer;
|
|
5
4
|
private contract;
|
|
6
|
-
private static ipfsClient;
|
|
7
5
|
private allo;
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
private pinataJWTToken;
|
|
7
|
+
constructor(signer: ethers.Signer, pinataJWTToken: string, chainId: number);
|
|
8
|
+
saveAndGetCID(data: any, pinataMetadata?: {
|
|
9
|
+
name: string;
|
|
10
|
+
}): Promise<any>;
|
|
10
11
|
encodeStrategyInitData(applicationStart: number, applicationEnd: number, roundStart: number, roundEnd: number, payoutToken: string): Promise<string>;
|
|
11
|
-
createGrant(args: any): Promise<{
|
|
12
|
+
createGrant(args: any, callback?: Function): Promise<{
|
|
12
13
|
poolId: string;
|
|
13
14
|
txHash: string;
|
|
14
15
|
}>;
|
|
15
|
-
updatePoolMetadata(poolId: string, poolMetadata: any): Promise<any>;
|
|
16
|
+
updatePoolMetadata(poolId: string, poolMetadata: any, callback?: Function): Promise<any>;
|
|
16
17
|
}
|
|
@@ -9,20 +9,29 @@ const Allo_json_1 = __importDefault(require("../../abi/Allo.json"));
|
|
|
9
9
|
const consts_1 = require("../../consts");
|
|
10
10
|
const ethers_2 = require("ethers");
|
|
11
11
|
const allo_v2_sdk_1 = require("@allo-team/allo-v2-sdk/");
|
|
12
|
+
const axios_1 = __importDefault(require("axios"));
|
|
12
13
|
class AlloBase {
|
|
13
|
-
constructor(signer,
|
|
14
|
+
constructor(signer, pinataJWTToken, chainId) {
|
|
14
15
|
this.signer = signer;
|
|
15
16
|
this.contract = new ethers_1.ethers.Contract(consts_1.AlloContracts.alloProxy, Allo_json_1.default, signer);
|
|
16
17
|
this.allo = new allo_v2_sdk_1.Allo({ chain: chainId });
|
|
17
|
-
|
|
18
|
+
this.pinataJWTToken = pinataJWTToken;
|
|
18
19
|
}
|
|
19
|
-
async saveAndGetCID(data) {
|
|
20
|
+
async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
|
|
20
21
|
try {
|
|
21
|
-
const res = await
|
|
22
|
-
|
|
22
|
+
const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
23
|
+
pinataContent: data,
|
|
24
|
+
pinataMetadata: pinataMetadata,
|
|
25
|
+
}, {
|
|
26
|
+
headers: {
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
Authorization: `Bearer ${this.pinataJWTToken}`,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
return res.data.IpfsHash;
|
|
23
32
|
}
|
|
24
33
|
catch (error) {
|
|
25
|
-
|
|
34
|
+
console.log(error);
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
async encodeStrategyInitData(applicationStart, applicationEnd, roundStart, roundEnd, payoutToken) {
|
|
@@ -38,7 +47,7 @@ class AlloBase {
|
|
|
38
47
|
]);
|
|
39
48
|
return initStrategyData;
|
|
40
49
|
}
|
|
41
|
-
async createGrant(args) {
|
|
50
|
+
async createGrant(args, callback) {
|
|
42
51
|
console.log("Creating grant...");
|
|
43
52
|
const walletBalance = await this.signer.provider.getBalance(await this.signer.getAddress());
|
|
44
53
|
console.log("Wallet balance:", (0, ethers_1.formatEther)(walletBalance.toString()), " ETH");
|
|
@@ -61,13 +70,16 @@ class AlloBase {
|
|
|
61
70
|
metadata: metadata,
|
|
62
71
|
managers: args.managers,
|
|
63
72
|
};
|
|
73
|
+
callback?.("preparing");
|
|
64
74
|
const txData = this.allo.createPool(createPoolArgs);
|
|
65
75
|
const tx = await this.signer.sendTransaction({
|
|
66
76
|
data: txData.data,
|
|
67
77
|
to: txData.to,
|
|
68
78
|
value: BigInt(txData.value),
|
|
69
79
|
});
|
|
80
|
+
callback?.("pending");
|
|
70
81
|
const receipt = await tx.wait();
|
|
82
|
+
callback?.("confirmed");
|
|
71
83
|
// Get ProfileCreated event
|
|
72
84
|
const poolId = receipt.logs[receipt.logs.length - 1].topics[0];
|
|
73
85
|
return {
|
|
@@ -79,15 +91,18 @@ class AlloBase {
|
|
|
79
91
|
console.error(`Failed to create pool: ${error}`);
|
|
80
92
|
}
|
|
81
93
|
}
|
|
82
|
-
async updatePoolMetadata(poolId, poolMetadata) {
|
|
94
|
+
async updatePoolMetadata(poolId, poolMetadata, callback) {
|
|
83
95
|
try {
|
|
96
|
+
callback?.("preparing");
|
|
84
97
|
const metadata_cid = await this.saveAndGetCID(poolMetadata);
|
|
85
98
|
const metadata = {
|
|
86
99
|
protocol: 1,
|
|
87
100
|
pointer: metadata_cid,
|
|
88
101
|
};
|
|
89
102
|
const tx = await this.contract.updatePoolMetadata(poolId, metadata);
|
|
103
|
+
callback?.("pending");
|
|
90
104
|
const receipt = await tx.wait();
|
|
105
|
+
callback?.("confirmed");
|
|
91
106
|
return receipt;
|
|
92
107
|
}
|
|
93
108
|
catch (error) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { ProfileMetadata } from "../types/allo";
|
|
3
|
-
import pinataSDK from "@pinata/sdk";
|
|
4
3
|
export declare class AlloRegistry {
|
|
5
4
|
private contract;
|
|
6
|
-
private
|
|
7
|
-
constructor(signer: ethers.Signer,
|
|
8
|
-
saveAndGetCID(data: any
|
|
5
|
+
private pinataJWTToken;
|
|
6
|
+
constructor(signer: ethers.Signer, pinataJWTToken: string);
|
|
7
|
+
saveAndGetCID(data: any, pinataMetadata?: {
|
|
8
|
+
name: string;
|
|
9
|
+
}): Promise<any>;
|
|
9
10
|
createProgram(nonce: number, name: string, profileMetadata: ProfileMetadata, owner: string, members: string[]): Promise<{
|
|
10
11
|
profileId: any;
|
|
11
12
|
txHash: any;
|
|
@@ -7,18 +7,27 @@ exports.AlloRegistry = void 0;
|
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const AlloRegistry_json_1 = __importDefault(require("../../abi/AlloRegistry.json"));
|
|
9
9
|
const consts_1 = require("../../consts");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
11
|
class AlloRegistry {
|
|
11
|
-
constructor(signer,
|
|
12
|
+
constructor(signer, pinataJWTToken) {
|
|
12
13
|
this.contract = new ethers_1.ethers.Contract(consts_1.AlloContracts.registry, AlloRegistry_json_1.default, signer);
|
|
13
|
-
|
|
14
|
+
this.pinataJWTToken = pinataJWTToken;
|
|
14
15
|
}
|
|
15
|
-
async saveAndGetCID(data) {
|
|
16
|
+
async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
|
|
16
17
|
try {
|
|
17
|
-
const res = await
|
|
18
|
-
|
|
18
|
+
const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
19
|
+
pinataContent: data,
|
|
20
|
+
pinataMetadata: pinataMetadata,
|
|
21
|
+
}, {
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
Authorization: `Bearer ${this.pinataJWTToken}`,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return res.data.IpfsHash;
|
|
19
28
|
}
|
|
20
29
|
catch (error) {
|
|
21
|
-
|
|
30
|
+
console.log(error);
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
33
|
async createProgram(nonce, name, profileMetadata, owner, members) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import pinataSDK from "@pinata/sdk";
|
|
2
1
|
import { RemoteStorage } from "./RemoteStorage";
|
|
3
2
|
import { TRemoteStorageOutput } from "core/types";
|
|
4
3
|
export interface IpfsStorageOptions {
|
|
5
4
|
token: string;
|
|
6
5
|
}
|
|
7
|
-
export declare class IpfsStorage extends RemoteStorage
|
|
6
|
+
export declare class IpfsStorage extends RemoteStorage {
|
|
7
|
+
private pinataJWTToken;
|
|
8
8
|
constructor(opts: IpfsStorageOptions,
|
|
9
9
|
/**
|
|
10
10
|
* If set, will send request to another server instead of
|
|
@@ -17,4 +17,7 @@ export declare class IpfsStorage extends RemoteStorage<pinataSDK> {
|
|
|
17
17
|
get<T = unknown>(args: {
|
|
18
18
|
cid: string;
|
|
19
19
|
}): Promise<T>;
|
|
20
|
+
saveAndGetCID(data: any, pinataMetadata?: {
|
|
21
|
+
name: string;
|
|
22
|
+
}): Promise<any>;
|
|
20
23
|
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.IpfsStorage = void 0;
|
|
7
|
-
const sdk_1 = __importDefault(require("@pinata/sdk"));
|
|
8
7
|
const RemoteStorage_1 = require("./RemoteStorage");
|
|
9
8
|
const SchemaError_1 = require("../SchemaError");
|
|
10
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
11
|
class IpfsStorage extends RemoteStorage_1.RemoteStorage {
|
|
12
12
|
constructor(opts,
|
|
13
13
|
/**
|
|
@@ -17,13 +17,13 @@ class IpfsStorage extends RemoteStorage_1.RemoteStorage {
|
|
|
17
17
|
sponsor) {
|
|
18
18
|
super(0 /* STORAGE_TYPE.IPFS */, sponsor);
|
|
19
19
|
this.assert(opts);
|
|
20
|
-
this.
|
|
20
|
+
this.pinataJWTToken = opts.token;
|
|
21
21
|
}
|
|
22
22
|
assert(opts) { }
|
|
23
23
|
async save(data) {
|
|
24
24
|
try {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
25
|
+
const cid = await this.saveAndGetCID(data);
|
|
26
|
+
return cid;
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
29
|
throw new SchemaError_1.RemoteStorageError("REMOTE_STORAGE_UPLOAD", `Error adding data to IPFS`);
|
|
@@ -35,5 +35,22 @@ class IpfsStorage extends RemoteStorage_1.RemoteStorage {
|
|
|
35
35
|
async get(args) {
|
|
36
36
|
return (0, utils_1.getIPFSData)(args.cid);
|
|
37
37
|
}
|
|
38
|
+
async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
|
|
39
|
+
try {
|
|
40
|
+
const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
41
|
+
pinataContent: data,
|
|
42
|
+
pinataMetadata: pinataMetadata,
|
|
43
|
+
}, {
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Authorization: `Bearer ${this.pinataJWTToken}`,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return res.data.IpfsHash;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.log(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
38
55
|
}
|
|
39
56
|
exports.IpfsStorage = IpfsStorage;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.35",
|
|
7
7
|
"description": "Simple and easy interface between EAS and Karma GAP.",
|
|
8
8
|
"main": "./index.js",
|
|
9
9
|
"author": "KarmaHQ",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"@allo-team/allo-v2-sdk": "^1.0.63",
|
|
23
23
|
"@ethereum-attestation-service/eas-sdk": "1.4.2",
|
|
24
24
|
"@gelatonetwork/relay-sdk": "^5.2.0",
|
|
25
|
-
"@pinata/sdk": "^2.1.0",
|
|
26
25
|
"@types/sha256": "^0.2.0",
|
|
27
26
|
"axios": "^1.4.0",
|
|
28
27
|
"ethers": "6.11.0",
|