@show-karma/karma-gap-sdk 0.1.34 → 0.1.37
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/Fetcher.d.ts +11 -5
- package/core/class/GraphQL/GapEasClient.d.ts +1 -0
- package/core/class/GraphQL/GapEasClient.js +4 -0
- package/core/class/karma-indexer/GapIndexerClient.d.ts +7 -6
- package/core/class/karma-indexer/GapIndexerClient.js +19 -14
- package/core/utils/gelato/send-gelato-txn.d.ts +8 -7
- package/core/utils/gelato/send-gelato-txn.js +8 -7
- package/core/utils/gelato/watch-gelato-txn.d.ts +1 -1
- package/core/utils/gelato/watch-gelato-txn.js +32 -24
- package/package.json +1 -1
package/core/class/Fetcher.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Hex, IAttestation, TSchemaName } from
|
|
2
|
-
import { Attestation } from
|
|
3
|
-
import { Community, Grant, MemberOf, Milestone, Project } from
|
|
4
|
-
import { Grantee } from
|
|
5
|
-
import { AxiosGQL } from
|
|
1
|
+
import { Hex, IAttestation, TSchemaName } from 'core/types';
|
|
2
|
+
import { Attestation } from './Attestation';
|
|
3
|
+
import { Community, Grant, MemberOf, Milestone, Project } from './entities';
|
|
4
|
+
import { Grantee } from './types/attestations';
|
|
5
|
+
import { AxiosGQL } from './GraphQL/AxiosGQL';
|
|
6
6
|
export declare abstract class Fetcher extends AxiosGQL {
|
|
7
7
|
/**
|
|
8
8
|
* Fetch a single attestation by its UID.
|
|
@@ -129,4 +129,10 @@ export declare abstract class Fetcher extends AxiosGQL {
|
|
|
129
129
|
* @returns
|
|
130
130
|
*/
|
|
131
131
|
abstract slugExists(slug: string): Promise<boolean>;
|
|
132
|
+
/**
|
|
133
|
+
* Get grants for a project by an external uid
|
|
134
|
+
* > Works only for the indexed projects
|
|
135
|
+
* @param projectExtId
|
|
136
|
+
*/
|
|
137
|
+
abstract grantsForExtProject(projectExtId: string): Promise<Grant[]>;
|
|
132
138
|
}
|
|
@@ -416,5 +416,9 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
416
416
|
String.raw `\\\\\"${field}\\\\\": \\\\\"${value}\\\\\"`,
|
|
417
417
|
];
|
|
418
418
|
}
|
|
419
|
+
async grantsForExtProject(projectExtId) {
|
|
420
|
+
console.error(new Error('Grants for external project is only supported by a custom indexer. Check https://github.com/show-karma/karma-gap-sdk for more information.'));
|
|
421
|
+
return [];
|
|
422
|
+
}
|
|
419
423
|
}
|
|
420
424
|
exports.GapEasClient = GapEasClient;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { TSchemaName, IAttestation } from
|
|
2
|
-
import { Attestation } from
|
|
3
|
-
import { GapSchema } from
|
|
4
|
-
import { Fetcher } from
|
|
5
|
-
import { Community, Project, Grant, Milestone, MemberOf } from
|
|
6
|
-
import { Grantee } from
|
|
1
|
+
import { TSchemaName, IAttestation } from 'core/types';
|
|
2
|
+
import { Attestation } from '../Attestation';
|
|
3
|
+
import { GapSchema } from '../GapSchema';
|
|
4
|
+
import { Fetcher } from '../Fetcher';
|
|
5
|
+
import { Community, Project, Grant, Milestone, MemberOf } from '../entities';
|
|
6
|
+
import { Grantee } from '../types/attestations';
|
|
7
7
|
export declare class GapIndexerClient extends Fetcher {
|
|
8
8
|
attestation<T = unknown>(uid: `0x${string}`): Promise<Attestation<T, GapSchema>>;
|
|
9
9
|
attestations(schemaName: TSchemaName, search?: string): Promise<IAttestation[]>;
|
|
@@ -21,6 +21,7 @@ export declare class GapIndexerClient extends Fetcher {
|
|
|
21
21
|
grantees(): Promise<Grantee[]>;
|
|
22
22
|
grantsOf(grantee: `0x${string}`, withCommunity?: boolean): Promise<Grant[]>;
|
|
23
23
|
grantsFor(projects: Project[], withCommunity?: boolean): Promise<Grant[]>;
|
|
24
|
+
grantsForExtProject(projectExtId: string): Promise<Grant[]>;
|
|
24
25
|
grantsByCommunity(uid: `0x${string}`): Promise<Grant[]>;
|
|
25
26
|
milestonesOf(grants: Grant[]): Promise<Milestone[]>;
|
|
26
27
|
membersOf(projects: Project[]): Promise<MemberOf[]>;
|
|
@@ -7,26 +7,27 @@ const Fetcher_1 = require("../Fetcher");
|
|
|
7
7
|
const entities_1 = require("../entities");
|
|
8
8
|
const Endpoints = {
|
|
9
9
|
attestations: {
|
|
10
|
-
all: () =>
|
|
10
|
+
all: () => '/attestations',
|
|
11
11
|
byUid: (uid) => `/attestations/${uid}`,
|
|
12
12
|
},
|
|
13
13
|
communities: {
|
|
14
|
-
all: () =>
|
|
14
|
+
all: () => '/communities',
|
|
15
15
|
byUidOrSlug: (uidOrSlug) => `/communities/${uidOrSlug}`,
|
|
16
16
|
grants: (uidOrSlug) => `/communities/${uidOrSlug}/grants`,
|
|
17
17
|
},
|
|
18
18
|
grantees: {
|
|
19
|
-
all: () =>
|
|
19
|
+
all: () => '/grantees',
|
|
20
20
|
byAddress: (address) => `/grantees/${address}`,
|
|
21
21
|
grants: (address) => `/grantees/${address}/grants`,
|
|
22
22
|
projects: (address) => `/grantees/${address}/projects`,
|
|
23
23
|
},
|
|
24
24
|
grants: {
|
|
25
|
-
all: () =>
|
|
25
|
+
all: () => '/grants',
|
|
26
26
|
byUid: (uid) => `/grants/${uid}`,
|
|
27
|
+
byExternalId: (id) => `/grants/external-id/${id}`,
|
|
27
28
|
},
|
|
28
29
|
project: {
|
|
29
|
-
all: () =>
|
|
30
|
+
all: () => '/projects',
|
|
30
31
|
byUidOrSlug: (uidOrSlug) => `/projects/${uidOrSlug}`,
|
|
31
32
|
grants: (uidOrSlug) => `/projects/${uidOrSlug}/grants`,
|
|
32
33
|
milestones: (uidOrSlug) => `/projects/${uidOrSlug}/milestones`,
|
|
@@ -36,14 +37,14 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
|
|
|
36
37
|
async attestation(uid) {
|
|
37
38
|
const { data } = await this.client.get(Endpoints.attestations.byUid(uid));
|
|
38
39
|
if (!data)
|
|
39
|
-
throw new Error(
|
|
40
|
+
throw new Error('Attestation not found');
|
|
40
41
|
return Attestation_1.Attestation.fromInterface([data])[0];
|
|
41
42
|
}
|
|
42
43
|
async attestations(schemaName, search) {
|
|
43
44
|
const { data } = await this.client.get(Endpoints.attestations.all(), {
|
|
44
45
|
params: {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
'filter[schemaUID]': GapSchema_1.GapSchema.get(schemaName).uid,
|
|
47
|
+
'filter[data]': search,
|
|
47
48
|
},
|
|
48
49
|
});
|
|
49
50
|
return data || [];
|
|
@@ -51,8 +52,8 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
|
|
|
51
52
|
async attestationsOf(schemaName, attester) {
|
|
52
53
|
const { data } = await this.client.get(Endpoints.attestations.all(), {
|
|
53
54
|
params: {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
'filter[schemaUID]': GapSchema_1.GapSchema.get(schemaName).uid,
|
|
56
|
+
'filter[recipient]': attester,
|
|
56
57
|
},
|
|
57
58
|
});
|
|
58
59
|
return data || [];
|
|
@@ -63,13 +64,13 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
|
|
|
63
64
|
async communities(search) {
|
|
64
65
|
const { data } = await this.client.get(Endpoints.communities.all(), {
|
|
65
66
|
params: {
|
|
66
|
-
|
|
67
|
+
'filter[name]': search,
|
|
67
68
|
},
|
|
68
69
|
});
|
|
69
70
|
return entities_1.Community.from(data);
|
|
70
71
|
}
|
|
71
72
|
communitiesByIds(uids) {
|
|
72
|
-
throw new Error(
|
|
73
|
+
throw new Error('Method not implemented.');
|
|
73
74
|
}
|
|
74
75
|
async communityBySlug(slug) {
|
|
75
76
|
const { data } = await this.client.get(Endpoints.communities.byUidOrSlug(slug));
|
|
@@ -88,7 +89,7 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
|
|
|
88
89
|
async projects(name) {
|
|
89
90
|
const { data } = await this.client.get(Endpoints.project.all(), {
|
|
90
91
|
params: {
|
|
91
|
-
|
|
92
|
+
'filter[title]': name,
|
|
92
93
|
},
|
|
93
94
|
});
|
|
94
95
|
return entities_1.Project.from(data);
|
|
@@ -113,6 +114,10 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
|
|
|
113
114
|
const { data } = await this.client.get(Endpoints.project.grants(projects[0].uid));
|
|
114
115
|
return entities_1.Grant.from(data);
|
|
115
116
|
}
|
|
117
|
+
async grantsForExtProject(projectExtId) {
|
|
118
|
+
const { data } = await this.client.get(Endpoints.grants.byExternalId(projectExtId));
|
|
119
|
+
return entities_1.Grant.from(data);
|
|
120
|
+
}
|
|
116
121
|
async grantsByCommunity(uid) {
|
|
117
122
|
const { data } = await this.client.get(Endpoints.communities.grants(uid));
|
|
118
123
|
return entities_1.Grant.from(data);
|
|
@@ -122,7 +127,7 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
|
|
|
122
127
|
return entities_1.Milestone.from(data);
|
|
123
128
|
}
|
|
124
129
|
async membersOf(projects) {
|
|
125
|
-
throw new Error(
|
|
130
|
+
throw new Error('Method not implemented.');
|
|
126
131
|
}
|
|
127
132
|
async slugExists(slug) {
|
|
128
133
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GelatoRelay } from
|
|
2
|
-
import { Hex } from
|
|
3
|
-
declare function sendByUrl(...params: Parameters<GelatoRelay[
|
|
1
|
+
import { GelatoRelay } from '@gelatonetwork/relay-sdk';
|
|
2
|
+
import { Hex } from '../../types';
|
|
3
|
+
declare function sendByUrl(...params: Parameters<GelatoRelay['sponsoredCall']>): Promise<string>;
|
|
4
4
|
/**
|
|
5
5
|
* Send gelato using an explicit api key.
|
|
6
6
|
*
|
|
@@ -9,20 +9,21 @@ declare function sendByUrl(...params: Parameters<GelatoRelay["sponsoredCall"]>):
|
|
|
9
9
|
* @param params
|
|
10
10
|
* @returns Gelato's task id and a wait function.
|
|
11
11
|
*/
|
|
12
|
-
declare function sendByApiKey(...params: Parameters<GelatoRelay[
|
|
12
|
+
declare function sendByApiKey(...params: Parameters<GelatoRelay['sponsoredCall']>): Promise<{
|
|
13
13
|
taskId: string;
|
|
14
14
|
/**
|
|
15
15
|
* Waits for the transaction to be confirmed by Gelato.
|
|
16
|
+
* @param ttl interval between checks in ms
|
|
16
17
|
* @returns Txn id
|
|
17
18
|
*/
|
|
18
|
-
wait: () => Promise<string>;
|
|
19
|
+
wait: (ttl?: number) => Promise<string>;
|
|
19
20
|
}>;
|
|
20
21
|
/**
|
|
21
22
|
* Sends a sponsored call using GelatoRelay
|
|
22
23
|
* @param payload
|
|
23
24
|
* @returns txn hash
|
|
24
25
|
*/
|
|
25
|
-
declare function sendGelatoTxn(...params: Parameters<GelatoRelay[
|
|
26
|
+
declare function sendGelatoTxn(...params: Parameters<GelatoRelay['sponsoredCall']>): Promise<string>;
|
|
26
27
|
/**
|
|
27
28
|
* Builds the arguments for a sponsored call using GelatoRelay
|
|
28
29
|
* @param data Populated contract call.
|
|
@@ -45,7 +46,7 @@ declare function buildArgs(
|
|
|
45
46
|
/**
|
|
46
47
|
* Populated transaction data.
|
|
47
48
|
*/
|
|
48
|
-
data: string, chainId: bigint, target: Hex): Parameters<GelatoRelay[
|
|
49
|
+
data: string, chainId: bigint, target: Hex): Parameters<GelatoRelay['sponsoredCall']>;
|
|
49
50
|
declare const Gelato: {
|
|
50
51
|
sendByApiKey: typeof sendByApiKey;
|
|
51
52
|
sendByUrl: typeof sendByUrl;
|
|
@@ -22,9 +22,9 @@ async function sendByUrl(...params) {
|
|
|
22
22
|
*/
|
|
23
23
|
async function sendByApiKey(...params) {
|
|
24
24
|
const { apiKey } = GAP_1.GAP?.gelatoOpts || {};
|
|
25
|
-
if (!apiKey && params[1] ===
|
|
26
|
-
throw new Error(
|
|
27
|
-
if (apiKey && params[1] ===
|
|
25
|
+
if (!apiKey && params[1] === '{apiKey}')
|
|
26
|
+
throw new Error('No api key provided.');
|
|
27
|
+
if (apiKey && params[1] === '{apiKey}')
|
|
28
28
|
params[1] = apiKey;
|
|
29
29
|
const client = new relay_sdk_1.GelatoRelay();
|
|
30
30
|
const relayResponse = await client.sponsoredCall(...params);
|
|
@@ -32,9 +32,10 @@ async function sendByApiKey(...params) {
|
|
|
32
32
|
taskId: relayResponse.taskId,
|
|
33
33
|
/**
|
|
34
34
|
* Waits for the transaction to be confirmed by Gelato.
|
|
35
|
+
* @param ttl interval between checks in ms
|
|
35
36
|
* @returns Txn id
|
|
36
37
|
*/
|
|
37
|
-
wait: () => (0, watch_gelato_txn_1.watchGelatoTxn)(relayResponse.taskId),
|
|
38
|
+
wait: (ttl) => (0, watch_gelato_txn_1.watchGelatoTxn)(relayResponse.taskId, ttl),
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
@@ -44,10 +45,10 @@ async function sendByApiKey(...params) {
|
|
|
44
45
|
*/
|
|
45
46
|
async function sendGelatoTxn(...params) {
|
|
46
47
|
if (!GAP_1.GAP.gelatoOpts)
|
|
47
|
-
throw new Error(
|
|
48
|
+
throw new Error('Gelato opts not set.');
|
|
48
49
|
const { env_gelatoApiKey, sponsorUrl, useGasless, contained } = GAP_1.GAP.gelatoOpts;
|
|
49
50
|
if (!useGasless)
|
|
50
|
-
throw new Error(
|
|
51
|
+
throw new Error('Gasless is not enabled.');
|
|
51
52
|
if ((sponsorUrl && contained && env_gelatoApiKey) ||
|
|
52
53
|
(sponsorUrl && !contained)) {
|
|
53
54
|
return sendByUrl(...params);
|
|
@@ -85,7 +86,7 @@ data, chainId, target) {
|
|
|
85
86
|
chainId,
|
|
86
87
|
target,
|
|
87
88
|
},
|
|
88
|
-
|
|
89
|
+
'{apiKey}',
|
|
89
90
|
{
|
|
90
91
|
retries: 3,
|
|
91
92
|
},
|
|
@@ -18,35 +18,43 @@ var TaskState;
|
|
|
18
18
|
* @param taskId
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
|
-
async function watchGelatoTxn(taskId) {
|
|
21
|
+
async function watchGelatoTxn(taskId, ttl = 500) {
|
|
22
22
|
const client = new relay_sdk_1.GelatoRelay();
|
|
23
23
|
return new Promise((resolve, reject) => {
|
|
24
24
|
const loop = async () => {
|
|
25
25
|
const oneSecond = 1;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
try {
|
|
27
|
+
while (oneSecond) {
|
|
28
|
+
const status = await client.getTaskStatus(taskId);
|
|
29
|
+
// print status :D so we can debug this for now
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.log(status);
|
|
32
|
+
if (!status) {
|
|
33
|
+
reject(new Error('Transaction goes wrong.'));
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (status && status.taskState === TaskState.ExecSuccess) {
|
|
37
|
+
resolve(status.transactionHash || '');
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
else if ([
|
|
41
|
+
TaskState.Cancelled,
|
|
42
|
+
TaskState.ExecReverted,
|
|
43
|
+
TaskState.Blacklisted,
|
|
44
|
+
].includes(status?.taskState)) {
|
|
45
|
+
reject(new Error(status.lastCheckMessage
|
|
46
|
+
?.split(/(RegisterDelegate)|(Execution error): /)
|
|
47
|
+
.at(-1) || ''));
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
await new Promise((r) => setTimeout(r, ttl));
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
TaskState.ExecReverted,
|
|
42
|
-
TaskState.Blacklisted,
|
|
43
|
-
].includes(status?.taskState)) {
|
|
44
|
-
reject(new Error(status.lastCheckMessage
|
|
45
|
-
?.split(/(RegisterDelegate)|(Execution error): /)
|
|
46
|
-
.at(-1) || ""));
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// gelato may throw 429 error, so we need to retry
|
|
55
|
+
// Increase ttl to avoid too deadlocking
|
|
56
|
+
// Max ttl is 30s
|
|
57
|
+
ttl += Math.max(30000, ttl + 1000);
|
|
50
58
|
}
|
|
51
59
|
};
|
|
52
60
|
loop();
|