@dorafactory/maci-sdk 0.1.2-pre.0 → 0.1.2-pre.2
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 +79 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -0
- package/dist/index.mjs.map +1 -1
- package/dist/libs/contract/contract.d.ts +8 -0
- package/package.json +1 -1
- package/src/libs/contract/contract.ts +91 -0
|
@@ -58,6 +58,14 @@ export declare class Contract {
|
|
|
58
58
|
gasStation?: boolean;
|
|
59
59
|
fee?: StdFee | 'auto' | number;
|
|
60
60
|
}): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
|
|
61
|
+
saasGrantToVoter({ signer, baseAmount, contractAddress, grantee, gasStation, fee, }: {
|
|
62
|
+
signer: OfflineSigner;
|
|
63
|
+
baseAmount: string;
|
|
64
|
+
contractAddress: string;
|
|
65
|
+
grantee: string;
|
|
66
|
+
gasStation?: boolean;
|
|
67
|
+
fee?: StdFee | 'auto' | number;
|
|
68
|
+
}): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
|
|
61
69
|
addSaasOperator({ signer, operator, gasStation, fee, }: {
|
|
62
70
|
signer: OfflineSigner;
|
|
63
71
|
operator: string;
|
package/package.json
CHANGED
|
@@ -508,6 +508,97 @@ export class Contract {
|
|
|
508
508
|
);
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
+
async saasGrantToVoter({
|
|
512
|
+
signer,
|
|
513
|
+
baseAmount,
|
|
514
|
+
contractAddress,
|
|
515
|
+
grantee,
|
|
516
|
+
gasStation = false,
|
|
517
|
+
fee = 1.8,
|
|
518
|
+
}: {
|
|
519
|
+
signer: OfflineSigner;
|
|
520
|
+
baseAmount: string;
|
|
521
|
+
contractAddress: string;
|
|
522
|
+
grantee: string;
|
|
523
|
+
gasStation?: boolean;
|
|
524
|
+
fee?: StdFee | 'auto' | number;
|
|
525
|
+
}) {
|
|
526
|
+
const client = await createSaasClientBy({
|
|
527
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
528
|
+
wallet: signer,
|
|
529
|
+
contractAddress: this.saasAddress,
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
if (gasStation && typeof fee !== 'object') {
|
|
533
|
+
// When gasStation is true and fee is not StdFee, we need to simulate first then add granter
|
|
534
|
+
const [{ address }] = await signer.getAccounts();
|
|
535
|
+
const contractClient = await this.contractClient({ signer });
|
|
536
|
+
const msg = {
|
|
537
|
+
grant_to_voter: {
|
|
538
|
+
base_amount: baseAmount,
|
|
539
|
+
contract_addr: contractAddress,
|
|
540
|
+
grantee,
|
|
541
|
+
},
|
|
542
|
+
};
|
|
543
|
+
const gasEstimation = await contractClient.simulate(
|
|
544
|
+
address,
|
|
545
|
+
[
|
|
546
|
+
{
|
|
547
|
+
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
|
548
|
+
value: {
|
|
549
|
+
sender: address,
|
|
550
|
+
contract: this.saasAddress,
|
|
551
|
+
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
''
|
|
556
|
+
);
|
|
557
|
+
const multiplier = typeof fee === 'number' ? fee : 1.8;
|
|
558
|
+
const gasPrice = GasPrice.fromString('10000000000peaka');
|
|
559
|
+
const calculatedFee = calculateFee(
|
|
560
|
+
Math.round(gasEstimation * multiplier),
|
|
561
|
+
gasPrice
|
|
562
|
+
);
|
|
563
|
+
const grantFee: StdFee = {
|
|
564
|
+
amount: calculatedFee.amount,
|
|
565
|
+
gas: calculatedFee.gas,
|
|
566
|
+
granter: this.saasAddress,
|
|
567
|
+
};
|
|
568
|
+
return client.grantToVoter(
|
|
569
|
+
{
|
|
570
|
+
baseAmount,
|
|
571
|
+
contractAddr: contractAddress,
|
|
572
|
+
grantee,
|
|
573
|
+
},
|
|
574
|
+
grantFee
|
|
575
|
+
);
|
|
576
|
+
} else if (gasStation && typeof fee === 'object') {
|
|
577
|
+
// When gasStation is true and fee is StdFee, add granter
|
|
578
|
+
const grantFee: StdFee = {
|
|
579
|
+
...fee,
|
|
580
|
+
granter: this.saasAddress,
|
|
581
|
+
};
|
|
582
|
+
return client.grantToVoter(
|
|
583
|
+
{
|
|
584
|
+
baseAmount,
|
|
585
|
+
contractAddr: contractAddress,
|
|
586
|
+
grantee,
|
|
587
|
+
},
|
|
588
|
+
grantFee
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return client.grantToVoter(
|
|
593
|
+
{
|
|
594
|
+
baseAmount,
|
|
595
|
+
contractAddr: contractAddress,
|
|
596
|
+
grantee,
|
|
597
|
+
},
|
|
598
|
+
fee
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
511
602
|
async addSaasOperator({
|
|
512
603
|
signer,
|
|
513
604
|
operator,
|