@dorafactory/maci-sdk 0.1.1 → 0.1.2-pre.0
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/index.js +992 -140
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +992 -140
- package/dist/index.mjs.map +1 -1
- package/dist/libs/const.d.ts +3 -0
- package/dist/libs/contract/config.d.ts +6 -0
- package/dist/libs/contract/contract.d.ts +65 -3
- package/dist/libs/contract/ts/Saas.client.d.ts +150 -0
- package/dist/libs/contract/ts/Saas.types.d.ts +128 -0
- package/dist/libs/contract/types.d.ts +10 -0
- package/dist/libs/maci/maci.d.ts +8 -6
- package/dist/maci.d.ts +13 -2
- package/dist/types/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/libs/const.ts +12 -1
- package/src/libs/contract/config.ts +19 -1
- package/src/libs/contract/contract.ts +553 -2
- package/src/libs/contract/ts/Saas.client.ts +567 -0
- package/src/libs/contract/ts/Saas.types.ts +147 -0
- package/src/libs/contract/types.ts +11 -2
- package/src/libs/maci/maci.ts +176 -88
- package/src/maci.ts +16 -0
- package/src/types/index.ts +4 -0
package/src/libs/maci/maci.ts
CHANGED
|
@@ -473,7 +473,7 @@ export class MACI {
|
|
|
473
473
|
signature: string;
|
|
474
474
|
};
|
|
475
475
|
gasStation?: boolean;
|
|
476
|
-
fee?: StdFee;
|
|
476
|
+
fee?: StdFee | 'auto' | number;
|
|
477
477
|
}) {
|
|
478
478
|
try {
|
|
479
479
|
if (!address) {
|
|
@@ -561,6 +561,7 @@ export class MACI {
|
|
|
561
561
|
operatorCoordPubKey,
|
|
562
562
|
maciKeypair,
|
|
563
563
|
gasStation = false,
|
|
564
|
+
fee = 1.8,
|
|
564
565
|
}: {
|
|
565
566
|
signer: OfflineSigner;
|
|
566
567
|
address?: string;
|
|
@@ -572,6 +573,7 @@ export class MACI {
|
|
|
572
573
|
operatorCoordPubKey: PubKey;
|
|
573
574
|
maciKeypair?: Keypair;
|
|
574
575
|
gasStation?: boolean;
|
|
576
|
+
fee?: StdFee | 'auto' | number;
|
|
575
577
|
}) {
|
|
576
578
|
if (maciKeypair === undefined) {
|
|
577
579
|
maciKeypair = this.maciKeypair;
|
|
@@ -664,6 +666,7 @@ export class MACI {
|
|
|
664
666
|
payload,
|
|
665
667
|
contractAddress,
|
|
666
668
|
gasStation,
|
|
669
|
+
fee,
|
|
667
670
|
});
|
|
668
671
|
} catch (error) {
|
|
669
672
|
throw Error(`Vote failed! ${error}`);
|
|
@@ -676,6 +679,7 @@ export class MACI {
|
|
|
676
679
|
payload,
|
|
677
680
|
contractAddress,
|
|
678
681
|
gasStation,
|
|
682
|
+
fee = 1.8,
|
|
679
683
|
}: {
|
|
680
684
|
client: SigningCosmWasmClient;
|
|
681
685
|
address: string;
|
|
@@ -685,6 +689,7 @@ export class MACI {
|
|
|
685
689
|
}[];
|
|
686
690
|
contractAddress: string;
|
|
687
691
|
gasStation: boolean;
|
|
692
|
+
fee?: StdFee | 'auto' | number;
|
|
688
693
|
}) {
|
|
689
694
|
const msgs: MsgExecuteContractEncodeObject[] = payload.map(
|
|
690
695
|
({ msg, encPubkeys }) => ({
|
|
@@ -711,17 +716,30 @@ export class MACI {
|
|
|
711
716
|
})
|
|
712
717
|
);
|
|
713
718
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
719
|
+
if (gasStation && typeof fee !== 'object') {
|
|
720
|
+
// When gasStation is true and fee is not StdFee, we need to simulate first then add granter
|
|
721
|
+
const gasEstimation = await client.simulate(address, msgs, '');
|
|
722
|
+
const multiplier = typeof fee === 'number' ? fee : 1.8;
|
|
723
|
+
const gasPrice = GasPrice.fromString('10000000000peaka');
|
|
724
|
+
const calculatedFee = calculateFee(
|
|
725
|
+
Math.round(gasEstimation * multiplier),
|
|
726
|
+
gasPrice
|
|
727
|
+
);
|
|
728
|
+
const grantFee: StdFee = {
|
|
729
|
+
amount: calculatedFee.amount,
|
|
730
|
+
gas: calculatedFee.gas,
|
|
731
|
+
granter: contractAddress,
|
|
732
|
+
};
|
|
733
|
+
return client.signAndBroadcast(address, msgs, grantFee);
|
|
734
|
+
} else if (gasStation && typeof fee === 'object') {
|
|
735
|
+
// When gasStation is true and fee is StdFee, add granter
|
|
718
736
|
const grantFee: StdFee = {
|
|
719
|
-
|
|
720
|
-
gas: fee.gas,
|
|
737
|
+
...fee,
|
|
721
738
|
granter: contractAddress,
|
|
722
739
|
};
|
|
723
740
|
return client.signAndBroadcast(address, msgs, grantFee);
|
|
724
741
|
}
|
|
742
|
+
|
|
725
743
|
return client.signAndBroadcast(address, msgs, fee);
|
|
726
744
|
}
|
|
727
745
|
|
|
@@ -731,52 +749,62 @@ export class MACI {
|
|
|
731
749
|
pubKey,
|
|
732
750
|
contractAddress,
|
|
733
751
|
gasStation,
|
|
734
|
-
fee,
|
|
752
|
+
fee = 1.8,
|
|
735
753
|
}: {
|
|
736
754
|
client: SigningCosmWasmClient;
|
|
737
755
|
address: string;
|
|
738
756
|
pubKey: PubKey;
|
|
739
757
|
contractAddress: string;
|
|
740
758
|
gasStation?: boolean;
|
|
741
|
-
fee?: StdFee;
|
|
759
|
+
fee?: StdFee | 'auto' | number;
|
|
742
760
|
}) {
|
|
743
|
-
const
|
|
744
|
-
|
|
761
|
+
const msg = {
|
|
762
|
+
sign_up: {
|
|
763
|
+
pubkey: {
|
|
764
|
+
x: pubKey[0].toString(),
|
|
765
|
+
y: pubKey[1].toString(),
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
};
|
|
745
769
|
|
|
746
|
-
if (gasStation === true) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
gas: fee.gas,
|
|
750
|
-
granter: contractAddress,
|
|
751
|
-
};
|
|
752
|
-
return client.execute(
|
|
770
|
+
if (gasStation === true && typeof fee !== 'object') {
|
|
771
|
+
// When gasStation is true and fee is not StdFee, we need to simulate first then add granter
|
|
772
|
+
const gasEstimation = await client.simulate(
|
|
753
773
|
address,
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
774
|
+
[
|
|
775
|
+
{
|
|
776
|
+
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
|
777
|
+
value: {
|
|
778
|
+
sender: address,
|
|
779
|
+
contract: contractAddress,
|
|
780
|
+
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
760
781
|
},
|
|
761
782
|
},
|
|
762
|
-
|
|
763
|
-
|
|
783
|
+
],
|
|
784
|
+
''
|
|
785
|
+
);
|
|
786
|
+
const multiplier = typeof fee === 'number' ? fee : 1.8;
|
|
787
|
+
const gasPrice = GasPrice.fromString('10000000000peaka');
|
|
788
|
+
const calculatedFee = calculateFee(
|
|
789
|
+
Math.round(gasEstimation * multiplier),
|
|
790
|
+
gasPrice
|
|
764
791
|
);
|
|
792
|
+
const grantFee: StdFee = {
|
|
793
|
+
amount: calculatedFee.amount,
|
|
794
|
+
gas: calculatedFee.gas,
|
|
795
|
+
granter: contractAddress,
|
|
796
|
+
};
|
|
797
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
798
|
+
} else if (gasStation === true && typeof fee === 'object') {
|
|
799
|
+
// When gasStation is true and fee is StdFee, add granter
|
|
800
|
+
const grantFee: StdFee = {
|
|
801
|
+
...fee,
|
|
802
|
+
granter: contractAddress,
|
|
803
|
+
};
|
|
804
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
765
805
|
}
|
|
766
806
|
|
|
767
|
-
return client.execute(
|
|
768
|
-
address,
|
|
769
|
-
contractAddress,
|
|
770
|
-
{
|
|
771
|
-
sign_up: {
|
|
772
|
-
pubkey: {
|
|
773
|
-
x: pubKey[0].toString(),
|
|
774
|
-
y: pubKey[1].toString(),
|
|
775
|
-
},
|
|
776
|
-
},
|
|
777
|
-
},
|
|
778
|
-
fee
|
|
779
|
-
);
|
|
807
|
+
return client.execute(address, contractAddress, msg, fee);
|
|
780
808
|
}
|
|
781
809
|
|
|
782
810
|
async signupOracle({
|
|
@@ -786,7 +814,7 @@ export class MACI {
|
|
|
786
814
|
contractAddress,
|
|
787
815
|
oracleCertificate,
|
|
788
816
|
gasStation,
|
|
789
|
-
fee,
|
|
817
|
+
fee = 1.8,
|
|
790
818
|
}: {
|
|
791
819
|
client: SigningCosmWasmClient;
|
|
792
820
|
address: string;
|
|
@@ -797,32 +825,57 @@ export class MACI {
|
|
|
797
825
|
signature: string;
|
|
798
826
|
};
|
|
799
827
|
gasStation?: boolean;
|
|
800
|
-
fee?: StdFee;
|
|
828
|
+
fee?: StdFee | 'auto' | number;
|
|
801
829
|
}) {
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
contractAddress,
|
|
808
|
-
{
|
|
809
|
-
sign_up: {
|
|
810
|
-
pubkey: {
|
|
811
|
-
x: pubKey[0].toString(),
|
|
812
|
-
y: pubKey[1].toString(),
|
|
813
|
-
},
|
|
814
|
-
amount: oracleCertificate.amount,
|
|
815
|
-
certificate: oracleCertificate.signature,
|
|
830
|
+
const msg = {
|
|
831
|
+
sign_up: {
|
|
832
|
+
pubkey: {
|
|
833
|
+
x: pubKey[0].toString(),
|
|
834
|
+
y: pubKey[1].toString(),
|
|
816
835
|
},
|
|
836
|
+
amount: oracleCertificate.amount,
|
|
837
|
+
certificate: oracleCertificate.signature,
|
|
817
838
|
},
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
if (gasStation === true && typeof fee !== 'object') {
|
|
842
|
+
// When gasStation is true and fee is not StdFee, we need to simulate first then add granter
|
|
843
|
+
const gasEstimation = await client.simulate(
|
|
844
|
+
address,
|
|
845
|
+
[
|
|
846
|
+
{
|
|
847
|
+
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
|
848
|
+
value: {
|
|
849
|
+
sender: address,
|
|
850
|
+
contract: contractAddress,
|
|
851
|
+
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
852
|
+
},
|
|
853
|
+
},
|
|
854
|
+
],
|
|
855
|
+
''
|
|
856
|
+
);
|
|
857
|
+
const multiplier = typeof fee === 'number' ? fee : 1.8;
|
|
858
|
+
const gasPrice = GasPrice.fromString('10000000000peaka');
|
|
859
|
+
const calculatedFee = calculateFee(
|
|
860
|
+
Math.round(gasEstimation * multiplier),
|
|
861
|
+
gasPrice
|
|
862
|
+
);
|
|
863
|
+
const grantFee: StdFee = {
|
|
864
|
+
amount: calculatedFee.amount,
|
|
865
|
+
gas: calculatedFee.gas,
|
|
866
|
+
granter: contractAddress,
|
|
867
|
+
};
|
|
868
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
869
|
+
} else if (gasStation === true && typeof fee === 'object') {
|
|
870
|
+
// When gasStation is true and fee is StdFee, add granter
|
|
871
|
+
const grantFee: StdFee = {
|
|
872
|
+
...fee,
|
|
873
|
+
granter: contractAddress,
|
|
874
|
+
};
|
|
875
|
+
return client.execute(address, contractAddress, msg, grantFee);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
return client.execute(address, contractAddress, msg, fee);
|
|
826
879
|
}
|
|
827
880
|
|
|
828
881
|
async deactivate({
|
|
@@ -831,14 +884,14 @@ export class MACI {
|
|
|
831
884
|
maciKeypair,
|
|
832
885
|
contractAddress,
|
|
833
886
|
gasStation,
|
|
834
|
-
fee,
|
|
887
|
+
fee = 1.8,
|
|
835
888
|
}: {
|
|
836
889
|
signer: OfflineSigner;
|
|
837
890
|
address?: string;
|
|
838
891
|
maciKeypair?: Keypair;
|
|
839
892
|
contractAddress: string;
|
|
840
893
|
gasStation?: boolean;
|
|
841
|
-
fee?: StdFee;
|
|
894
|
+
fee?: StdFee | 'auto' | number;
|
|
842
895
|
}) {
|
|
843
896
|
try {
|
|
844
897
|
address = address || (await signer.getAccounts())[0].address;
|
|
@@ -873,31 +926,66 @@ export class MACI {
|
|
|
873
926
|
|
|
874
927
|
const { msg, encPubkeys } = payload[0];
|
|
875
928
|
|
|
876
|
-
const
|
|
877
|
-
|
|
929
|
+
const deactivateMsg = stringizing({
|
|
930
|
+
publish_deactivate_message: {
|
|
931
|
+
enc_pub_key: {
|
|
932
|
+
x: encPubkeys[0],
|
|
933
|
+
y: encPubkeys[1],
|
|
934
|
+
},
|
|
935
|
+
message: {
|
|
936
|
+
data: msg,
|
|
937
|
+
},
|
|
938
|
+
},
|
|
939
|
+
});
|
|
878
940
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
941
|
+
if (gasStation === true && typeof fee !== 'object') {
|
|
942
|
+
// When gasStation is true and fee is not StdFee, we need to simulate first then add granter
|
|
943
|
+
const gasEstimation = await client.simulate(
|
|
944
|
+
address,
|
|
945
|
+
[
|
|
946
|
+
{
|
|
947
|
+
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
|
948
|
+
value: {
|
|
949
|
+
sender: address,
|
|
950
|
+
contract: contractAddress,
|
|
951
|
+
msg: new TextEncoder().encode(JSON.stringify(deactivateMsg)),
|
|
952
|
+
},
|
|
890
953
|
},
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
954
|
+
],
|
|
955
|
+
''
|
|
956
|
+
);
|
|
957
|
+
const multiplier = typeof fee === 'number' ? fee : 1.8;
|
|
958
|
+
const gasPrice = GasPrice.fromString('10000000000peaka');
|
|
959
|
+
const calculatedFee = calculateFee(
|
|
960
|
+
Math.round(gasEstimation * multiplier),
|
|
961
|
+
gasPrice
|
|
962
|
+
);
|
|
963
|
+
const grantFee: StdFee = {
|
|
964
|
+
amount: calculatedFee.amount,
|
|
965
|
+
gas: calculatedFee.gas,
|
|
966
|
+
granter: contractAddress,
|
|
967
|
+
};
|
|
968
|
+
return client.execute(
|
|
969
|
+
address,
|
|
970
|
+
contractAddress,
|
|
971
|
+
deactivateMsg,
|
|
972
|
+
grantFee
|
|
973
|
+
);
|
|
974
|
+
} else if (gasStation === true && typeof fee === 'object') {
|
|
975
|
+
// When gasStation is true and fee is StdFee, add granter
|
|
976
|
+
const grantFee: StdFee = {
|
|
977
|
+
...fee,
|
|
978
|
+
granter: contractAddress,
|
|
979
|
+
};
|
|
980
|
+
return client.execute(
|
|
981
|
+
address,
|
|
982
|
+
contractAddress,
|
|
983
|
+
deactivateMsg,
|
|
984
|
+
grantFee
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
return client.execute(address, contractAddress, deactivateMsg, fee);
|
|
901
989
|
} catch (error) {
|
|
902
990
|
throw Error(`Submit deactivate failed! ${error}`);
|
|
903
991
|
}
|
package/src/maci.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
CreateAMaciRoundParams,
|
|
6
6
|
CreateMaciRoundParams,
|
|
7
7
|
CreateOracleMaciRoundParams,
|
|
8
|
+
CreateSaasOracleMaciRoundParams,
|
|
8
9
|
} from './libs/contract/types';
|
|
9
10
|
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
10
11
|
import {
|
|
@@ -33,8 +34,10 @@ export class MaciClient {
|
|
|
33
34
|
public certificateApiEndpoint: string;
|
|
34
35
|
|
|
35
36
|
public registryAddress: string;
|
|
37
|
+
public saasAddress: string;
|
|
36
38
|
public maciCodeId: number;
|
|
37
39
|
public oracleCodeId: number;
|
|
40
|
+
public saasOracleCodeId: number;
|
|
38
41
|
public feegrantOperator: string;
|
|
39
42
|
public whitelistBackendPubkey: string;
|
|
40
43
|
|
|
@@ -58,8 +61,10 @@ export class MaciClient {
|
|
|
58
61
|
restEndpoint,
|
|
59
62
|
apiEndpoint,
|
|
60
63
|
registryAddress,
|
|
64
|
+
saasAddress,
|
|
61
65
|
maciCodeId,
|
|
62
66
|
oracleCodeId,
|
|
67
|
+
saasOracleCodeId,
|
|
63
68
|
customFetch,
|
|
64
69
|
defaultOptions,
|
|
65
70
|
feegrantOperator,
|
|
@@ -77,8 +82,10 @@ export class MaciClient {
|
|
|
77
82
|
this.certificateApiEndpoint =
|
|
78
83
|
certificateApiEndpoint || defaultParams.certificateApiEndpoint;
|
|
79
84
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
85
|
+
this.saasAddress = saasAddress || defaultParams.saasAddress;
|
|
80
86
|
this.maciCodeId = maciCodeId || defaultParams.maciCodeId;
|
|
81
87
|
this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
|
|
88
|
+
this.saasOracleCodeId = saasOracleCodeId || defaultParams.saasCodeId;
|
|
82
89
|
this.feegrantOperator =
|
|
83
90
|
feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
84
91
|
this.whitelistBackendPubkey =
|
|
@@ -101,8 +108,10 @@ export class MaciClient {
|
|
|
101
108
|
network: this.network,
|
|
102
109
|
rpcEndpoint: this.rpcEndpoint,
|
|
103
110
|
registryAddress: this.registryAddress,
|
|
111
|
+
saasAddress: this.saasAddress,
|
|
104
112
|
maciCodeId: this.maciCodeId,
|
|
105
113
|
oracleCodeId: this.oracleCodeId,
|
|
114
|
+
saasOracleCodeId: this.saasOracleCodeId,
|
|
106
115
|
feegrantOperator: this.feegrantOperator,
|
|
107
116
|
whitelistBackendPubkey: this.whitelistBackendPubkey,
|
|
108
117
|
});
|
|
@@ -217,6 +226,13 @@ export class MaciClient {
|
|
|
217
226
|
});
|
|
218
227
|
}
|
|
219
228
|
|
|
229
|
+
async createSaasOracleMaciRound(params: CreateSaasOracleMaciRoundParams) {
|
|
230
|
+
return await this.contract.createSaasOracleMaciRound({
|
|
231
|
+
signer: this.getSigner(params.signer),
|
|
232
|
+
...params,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
220
236
|
async genKeypairFromSign({
|
|
221
237
|
signer,
|
|
222
238
|
address,
|
package/src/types/index.ts
CHANGED
|
@@ -30,8 +30,10 @@ export type ClientParams = {
|
|
|
30
30
|
apiEndpoint?: string;
|
|
31
31
|
certificateApiEndpoint?: string;
|
|
32
32
|
registryAddress?: string;
|
|
33
|
+
saasAddress?: string;
|
|
33
34
|
maciCodeId?: number;
|
|
34
35
|
oracleCodeId?: number;
|
|
36
|
+
saasOracleCodeId?: number;
|
|
35
37
|
customFetch?: typeof fetch;
|
|
36
38
|
defaultOptions?: FetchOptions;
|
|
37
39
|
feegrantOperator?: string;
|
|
@@ -45,8 +47,10 @@ export type ContractParams = {
|
|
|
45
47
|
network: 'mainnet' | 'testnet';
|
|
46
48
|
rpcEndpoint: string;
|
|
47
49
|
registryAddress: string;
|
|
50
|
+
saasAddress: string;
|
|
48
51
|
maciCodeId: number;
|
|
49
52
|
oracleCodeId: number;
|
|
53
|
+
saasOracleCodeId: number;
|
|
50
54
|
whitelistBackendPubkey: string;
|
|
51
55
|
feegrantOperator: string;
|
|
52
56
|
};
|