@dorafactory/maci-sdk 0.0.19 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorafactory/maci-sdk",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "SDK for interacting with maci",
5
5
  "keywords": [
6
6
  "maci",
@@ -116,11 +116,12 @@ export class Http {
116
116
  }
117
117
  }
118
118
 
119
- async fetchRest(path: string): Promise<any> {
119
+ async fetchRest(path: string, options?: any): Promise<any> {
120
120
  try {
121
121
  const fetchFn = this.getFetch();
122
122
  const response = await fetchFn(`${this.restEndpoint}${path}`, {
123
123
  ...this.defaultOptions,
124
+ ...options,
124
125
  });
125
126
 
126
127
  if (!response.ok) {
@@ -107,6 +107,28 @@ export class MACI {
107
107
  return response.data.signUpEvents[0].stateIdx;
108
108
  }
109
109
 
110
+ async feegrantAllowance({
111
+ address,
112
+ contractAddress,
113
+ }: {
114
+ address: string;
115
+ contractAddress: string;
116
+ }) {
117
+ try {
118
+ const response = await this.oracleCertificate.feegrantAllowance(
119
+ contractAddress,
120
+ address
121
+ );
122
+ return response;
123
+ } catch (error) {
124
+ return {
125
+ granter: contractAddress,
126
+ grantee: address,
127
+ spend_limit: [],
128
+ };
129
+ }
130
+ }
131
+
110
132
  // only for maci and oracle maci, amaci will set the voice credit when deploy the contract
111
133
  async queryWhitelistBalanceOf({
112
134
  signer,
@@ -3,6 +3,7 @@ import {
3
3
  OracleCertificateParams,
4
4
  SignatureRequest,
5
5
  SignatureResponse,
6
+ FeegrantAllowanceResponse,
6
7
  } from './types';
7
8
 
8
9
  export class OracleCertificate {
@@ -33,4 +34,19 @@ export class OracleCertificate {
33
34
 
34
35
  return signatureData;
35
36
  }
37
+
38
+ async feegrantAllowance(
39
+ granter: string,
40
+ grantee: string
41
+ ): Promise<FeegrantAllowanceResponse> {
42
+ const response = await this.http.fetchRest(
43
+ `/cosmos/feegrant/v1beta1/allowance/${granter}/${grantee}`
44
+ );
45
+
46
+ return {
47
+ granter,
48
+ grantee,
49
+ spend_limit: response.allowance.allowance.allowance.spend_limit,
50
+ };
51
+ }
36
52
  }
@@ -18,3 +18,12 @@ export type SignatureResponse = {
18
18
  amount: string;
19
19
  snapshotHeight: string;
20
20
  };
21
+
22
+ export type FeegrantAllowanceResponse = {
23
+ granter: string;
24
+ grantee: string;
25
+ spend_limit: {
26
+ denom: string;
27
+ amount: string;
28
+ }[];
29
+ };