@silvana-one/token 0.1.1 → 0.1.3
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/node/bid.js +17 -16
- package/dist/node/bid.js.map +1 -1
- package/dist/node/div.d.ts +62 -0
- package/dist/node/div.js +39 -0
- package/dist/node/div.js.map +1 -0
- package/dist/node/index.cjs +348 -304
- package/dist/node/offer.js +7 -6
- package/dist/node/offer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/bid.js +17 -16
- package/dist/web/bid.js.map +1 -1
- package/dist/web/div.d.ts +62 -0
- package/dist/web/div.js +39 -0
- package/dist/web/div.js.map +1 -0
- package/dist/web/offer.js +7 -6
- package/dist/web/offer.js.map +1 -1
- package/package.json +6 -6
- package/src/bid.ts +16 -24
- package/src/div.ts +44 -0
- package/src/offer.ts +6 -8
package/dist/node/index.cjs
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
48
48
|
|
|
49
49
|
// dist/node/bid.js
|
|
50
50
|
var import_tslib4 = require("tslib");
|
|
51
|
-
var
|
|
51
|
+
var import_o1js5 = require("o1js");
|
|
52
52
|
var import_storage2 = require("@silvana-one/storage");
|
|
53
53
|
|
|
54
54
|
// dist/node/FungibleTokenContract.js
|
|
@@ -633,19 +633,55 @@ var FungibleTokenAdvancedAdmin = class extends import_o1js3.TokenContract {
|
|
|
633
633
|
var FungibleToken = FungibleTokenContract(FungibleTokenAdmin);
|
|
634
634
|
var AdvancedFungibleToken = FungibleTokenContract(FungibleTokenAdvancedAdmin);
|
|
635
635
|
|
|
636
|
+
// dist/node/div.js
|
|
637
|
+
var import_o1js4 = require("o1js");
|
|
638
|
+
var MulDivResult = class extends (0, import_o1js4.Struct)({
|
|
639
|
+
result: import_o1js4.UInt64,
|
|
640
|
+
remainder: import_o1js4.UInt64
|
|
641
|
+
}) {
|
|
642
|
+
};
|
|
643
|
+
var MulDivResultInternal = class extends (0, import_o1js4.Struct)({
|
|
644
|
+
result: import_o1js4.Field,
|
|
645
|
+
remainder: import_o1js4.Field
|
|
646
|
+
}) {
|
|
647
|
+
};
|
|
648
|
+
function mulDiv(params) {
|
|
649
|
+
const { value, multiplier, denominator } = params;
|
|
650
|
+
denominator.equals(import_o1js4.UInt64.zero).assertFalse("division by zero");
|
|
651
|
+
const fields = import_o1js4.Provable.witness(MulDivResultInternal, () => {
|
|
652
|
+
const valueBigInt = value.toBigInt();
|
|
653
|
+
const multiplierBigInt = multiplier.toBigInt();
|
|
654
|
+
const denominatorBigInt = denominator.toBigInt();
|
|
655
|
+
if (denominatorBigInt === 0n) {
|
|
656
|
+
return { result: import_o1js4.Field.from(0n), remainder: import_o1js4.Field.from(0n) };
|
|
657
|
+
}
|
|
658
|
+
const result = valueBigInt * multiplierBigInt / denominatorBigInt;
|
|
659
|
+
const remainder = valueBigInt * multiplierBigInt - result * denominatorBigInt;
|
|
660
|
+
return { result: import_o1js4.Field.from(result), remainder: import_o1js4.Field.from(remainder) };
|
|
661
|
+
});
|
|
662
|
+
import_o1js4.Gadgets.rangeCheck64(fields.result);
|
|
663
|
+
import_o1js4.Gadgets.rangeCheck64(fields.remainder);
|
|
664
|
+
fields.remainder.assertLessThan(denominator.value);
|
|
665
|
+
fields.result.mul(denominator.value).add(fields.remainder).assertEquals(value.value.mul(multiplier.value));
|
|
666
|
+
return {
|
|
667
|
+
result: import_o1js4.UInt64.Unsafe.fromField(fields.result),
|
|
668
|
+
remainder: import_o1js4.UInt64.Unsafe.fromField(fields.remainder)
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
|
|
636
672
|
// dist/node/bid.js
|
|
637
|
-
var BidEvent = class extends (0,
|
|
638
|
-
amount:
|
|
639
|
-
address:
|
|
673
|
+
var BidEvent = class extends (0, import_o1js5.Struct)({
|
|
674
|
+
amount: import_o1js5.UInt64,
|
|
675
|
+
address: import_o1js5.PublicKey
|
|
640
676
|
}) {
|
|
641
677
|
};
|
|
642
|
-
var FungibleTokenBidContract = class extends
|
|
678
|
+
var FungibleTokenBidContract = class extends import_o1js5.SmartContract {
|
|
643
679
|
constructor() {
|
|
644
680
|
super(...arguments);
|
|
645
|
-
this.price = (0,
|
|
646
|
-
this.buyer = (0,
|
|
647
|
-
this.token = (0,
|
|
648
|
-
this.whitelist = (0,
|
|
681
|
+
this.price = (0, import_o1js5.State)();
|
|
682
|
+
this.buyer = (0, import_o1js5.State)();
|
|
683
|
+
this.token = (0, import_o1js5.State)();
|
|
684
|
+
this.whitelist = (0, import_o1js5.State)();
|
|
649
685
|
this.events = {
|
|
650
686
|
bid: BidEvent,
|
|
651
687
|
withdraw: BidEvent,
|
|
@@ -657,72 +693,78 @@ var FungibleTokenBidContract = class extends import_o1js4.SmartContract {
|
|
|
657
693
|
await super.deploy(args);
|
|
658
694
|
this.whitelist.set(args.whitelist);
|
|
659
695
|
this.account.permissions.set({
|
|
660
|
-
...
|
|
661
|
-
send:
|
|
662
|
-
setVerificationKey:
|
|
663
|
-
setPermissions:
|
|
696
|
+
...import_o1js5.Permissions.default(),
|
|
697
|
+
send: import_o1js5.Permissions.proof(),
|
|
698
|
+
setVerificationKey: import_o1js5.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
699
|
+
setPermissions: import_o1js5.Permissions.impossible()
|
|
664
700
|
});
|
|
665
701
|
}
|
|
666
702
|
async initialize(token, amount, price) {
|
|
667
|
-
this.account.provedState.requireEquals((0,
|
|
668
|
-
amount.equals(
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
|
|
703
|
+
this.account.provedState.requireEquals((0, import_o1js5.Bool)(false));
|
|
704
|
+
amount.equals(import_o1js5.UInt64.from(0)).assertFalse();
|
|
705
|
+
const totalPrice = mulDiv({
|
|
706
|
+
value: price,
|
|
707
|
+
multiplier: amount,
|
|
708
|
+
denominator: import_o1js5.UInt64.from(1e9)
|
|
709
|
+
}).result;
|
|
672
710
|
const buyer = this.sender.getUnconstrained();
|
|
673
|
-
const buyerUpdate =
|
|
711
|
+
const buyerUpdate = import_o1js5.AccountUpdate.createSigned(buyer);
|
|
674
712
|
buyerUpdate.send({ to: this.address, amount: totalPrice });
|
|
675
|
-
buyerUpdate.body.useFullCommitment = (0,
|
|
713
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
676
714
|
this.buyer.set(buyer);
|
|
677
715
|
this.price.set(price);
|
|
678
716
|
this.token.set(token);
|
|
679
717
|
this.emitEvent("bid", { amount, address: buyer });
|
|
680
718
|
}
|
|
681
719
|
async bid(amount, price) {
|
|
682
|
-
amount.equals(
|
|
720
|
+
amount.equals(import_o1js5.UInt64.from(0)).assertFalse();
|
|
683
721
|
const balance = this.account.balance.getAndRequireEquals();
|
|
684
722
|
const oldPrice = this.price.getAndRequireEquals();
|
|
685
|
-
price.equals(oldPrice).or(balance.equals(
|
|
723
|
+
price.equals(oldPrice).or(balance.equals(import_o1js5.UInt64.from(0))).assertTrue();
|
|
686
724
|
this.price.set(price);
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
725
|
+
const totalPrice = mulDiv({
|
|
726
|
+
value: price,
|
|
727
|
+
multiplier: amount,
|
|
728
|
+
denominator: import_o1js5.UInt64.from(1e9)
|
|
729
|
+
}).result;
|
|
690
730
|
const sender = this.sender.getUnconstrained();
|
|
691
731
|
const buyer = this.buyer.getAndRequireEquals();
|
|
692
732
|
sender.assertEquals(buyer);
|
|
693
|
-
const buyerUpdate =
|
|
733
|
+
const buyerUpdate = import_o1js5.AccountUpdate.createSigned(buyer);
|
|
694
734
|
buyerUpdate.send({ to: this.address, amount: totalPrice });
|
|
695
|
-
buyerUpdate.body.useFullCommitment = (0,
|
|
735
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
696
736
|
this.price.set(price);
|
|
697
737
|
this.emitEvent("bid", { amount, address: buyer });
|
|
698
738
|
}
|
|
699
739
|
async withdraw(amountInMina) {
|
|
700
|
-
amountInMina.equals(
|
|
701
|
-
this.account.balance.requireBetween(amountInMina,
|
|
740
|
+
amountInMina.equals(import_o1js5.UInt64.from(0)).assertFalse();
|
|
741
|
+
this.account.balance.requireBetween(amountInMina, import_o1js5.UInt64.MAXINT());
|
|
702
742
|
const buyer = this.buyer.getAndRequireEquals();
|
|
703
743
|
const sender = this.sender.getUnconstrained();
|
|
704
|
-
const senderUpdate =
|
|
705
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
744
|
+
const senderUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
745
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
706
746
|
sender.assertEquals(buyer);
|
|
707
747
|
let bidUpdate = this.send({ to: senderUpdate, amount: amountInMina });
|
|
708
|
-
bidUpdate.body.useFullCommitment = (0,
|
|
748
|
+
bidUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
709
749
|
this.emitEvent("withdraw", {
|
|
710
750
|
amount: amountInMina,
|
|
711
751
|
address: buyer
|
|
712
752
|
});
|
|
713
753
|
}
|
|
714
754
|
async sell(amount) {
|
|
715
|
-
amount.equals(
|
|
755
|
+
amount.equals(import_o1js5.UInt64.from(0)).assertFalse();
|
|
716
756
|
const price = this.price.getAndRequireEquals();
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
757
|
+
const totalPrice = mulDiv({
|
|
758
|
+
value: price,
|
|
759
|
+
multiplier: amount,
|
|
760
|
+
denominator: import_o1js5.UInt64.from(1e9)
|
|
761
|
+
}).result;
|
|
762
|
+
this.account.balance.requireBetween(totalPrice, import_o1js5.UInt64.MAXINT());
|
|
721
763
|
const buyer = this.buyer.getAndRequireEquals();
|
|
722
764
|
const token = this.token.getAndRequireEquals();
|
|
723
765
|
const seller = this.sender.getUnconstrained();
|
|
724
766
|
const sellerUpdate = this.send({ to: seller, amount: totalPrice });
|
|
725
|
-
sellerUpdate.body.useFullCommitment = (0,
|
|
767
|
+
sellerUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
726
768
|
sellerUpdate.requireSignature();
|
|
727
769
|
const tokenContract = new FungibleToken(token);
|
|
728
770
|
await tokenContract.transfer(seller, buyer, amount);
|
|
@@ -734,55 +776,55 @@ var FungibleTokenBidContract = class extends import_o1js4.SmartContract {
|
|
|
734
776
|
async updateWhitelist(whitelist) {
|
|
735
777
|
const buyer = this.buyer.getAndRequireEquals();
|
|
736
778
|
const sender = this.sender.getUnconstrained();
|
|
737
|
-
const senderUpdate =
|
|
738
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
779
|
+
const senderUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
780
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
739
781
|
sender.assertEquals(buyer);
|
|
740
782
|
this.whitelist.set(whitelist);
|
|
741
783
|
this.emitEvent("updateWhitelist", whitelist);
|
|
742
784
|
}
|
|
743
785
|
};
|
|
744
786
|
(0, import_tslib4.__decorate)([
|
|
745
|
-
(0,
|
|
787
|
+
(0, import_o1js5.state)(import_o1js5.UInt64),
|
|
746
788
|
(0, import_tslib4.__metadata)("design:type", Object)
|
|
747
789
|
], FungibleTokenBidContract.prototype, "price", void 0);
|
|
748
790
|
(0, import_tslib4.__decorate)([
|
|
749
|
-
(0,
|
|
791
|
+
(0, import_o1js5.state)(import_o1js5.PublicKey),
|
|
750
792
|
(0, import_tslib4.__metadata)("design:type", Object)
|
|
751
793
|
], FungibleTokenBidContract.prototype, "buyer", void 0);
|
|
752
794
|
(0, import_tslib4.__decorate)([
|
|
753
|
-
(0,
|
|
795
|
+
(0, import_o1js5.state)(import_o1js5.PublicKey),
|
|
754
796
|
(0, import_tslib4.__metadata)("design:type", Object)
|
|
755
797
|
], FungibleTokenBidContract.prototype, "token", void 0);
|
|
756
798
|
(0, import_tslib4.__decorate)([
|
|
757
|
-
(0,
|
|
799
|
+
(0, import_o1js5.state)(import_storage2.Whitelist),
|
|
758
800
|
(0, import_tslib4.__metadata)("design:type", Object)
|
|
759
801
|
], FungibleTokenBidContract.prototype, "whitelist", void 0);
|
|
760
802
|
(0, import_tslib4.__decorate)([
|
|
761
|
-
|
|
803
|
+
import_o1js5.method,
|
|
762
804
|
(0, import_tslib4.__metadata)("design:type", Function),
|
|
763
|
-
(0, import_tslib4.__metadata)("design:paramtypes", [
|
|
805
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js5.PublicKey, import_o1js5.UInt64, import_o1js5.UInt64]),
|
|
764
806
|
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
765
807
|
], FungibleTokenBidContract.prototype, "initialize", null);
|
|
766
808
|
(0, import_tslib4.__decorate)([
|
|
767
|
-
|
|
809
|
+
import_o1js5.method,
|
|
768
810
|
(0, import_tslib4.__metadata)("design:type", Function),
|
|
769
|
-
(0, import_tslib4.__metadata)("design:paramtypes", [
|
|
811
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js5.UInt64, import_o1js5.UInt64]),
|
|
770
812
|
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
771
813
|
], FungibleTokenBidContract.prototype, "bid", null);
|
|
772
814
|
(0, import_tslib4.__decorate)([
|
|
773
|
-
|
|
815
|
+
import_o1js5.method,
|
|
774
816
|
(0, import_tslib4.__metadata)("design:type", Function),
|
|
775
|
-
(0, import_tslib4.__metadata)("design:paramtypes", [
|
|
817
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js5.UInt64]),
|
|
776
818
|
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
777
819
|
], FungibleTokenBidContract.prototype, "withdraw", null);
|
|
778
820
|
(0, import_tslib4.__decorate)([
|
|
779
|
-
|
|
821
|
+
import_o1js5.method,
|
|
780
822
|
(0, import_tslib4.__metadata)("design:type", Function),
|
|
781
|
-
(0, import_tslib4.__metadata)("design:paramtypes", [
|
|
823
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js5.UInt64]),
|
|
782
824
|
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
783
825
|
], FungibleTokenBidContract.prototype, "sell", null);
|
|
784
826
|
(0, import_tslib4.__decorate)([
|
|
785
|
-
|
|
827
|
+
import_o1js5.method,
|
|
786
828
|
(0, import_tslib4.__metadata)("design:type", Function),
|
|
787
829
|
(0, import_tslib4.__metadata)("design:paramtypes", [import_storage2.Whitelist]),
|
|
788
830
|
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
@@ -790,20 +832,20 @@ var FungibleTokenBidContract = class extends import_o1js4.SmartContract {
|
|
|
790
832
|
|
|
791
833
|
// dist/node/claim.js
|
|
792
834
|
var import_tslib5 = require("tslib");
|
|
793
|
-
var
|
|
835
|
+
var import_o1js6 = require("o1js");
|
|
794
836
|
var import_storage3 = require("@silvana-one/storage");
|
|
795
|
-
var ClaimEvent = class extends (0,
|
|
796
|
-
amount:
|
|
797
|
-
address:
|
|
837
|
+
var ClaimEvent = class extends (0, import_o1js6.Struct)({
|
|
838
|
+
amount: import_o1js6.UInt64,
|
|
839
|
+
address: import_o1js6.PublicKey
|
|
798
840
|
}) {
|
|
799
841
|
};
|
|
800
|
-
var FungibleTokenClaimContract = class extends
|
|
842
|
+
var FungibleTokenClaimContract = class extends import_o1js6.SmartContract {
|
|
801
843
|
constructor() {
|
|
802
844
|
super(...arguments);
|
|
803
|
-
this.owner = (0,
|
|
804
|
-
this.token = (0,
|
|
805
|
-
this.whitelist = (0,
|
|
806
|
-
this.maxAmount = (0,
|
|
845
|
+
this.owner = (0, import_o1js6.State)();
|
|
846
|
+
this.token = (0, import_o1js6.State)();
|
|
847
|
+
this.whitelist = (0, import_o1js6.State)();
|
|
848
|
+
this.maxAmount = (0, import_o1js6.State)();
|
|
807
849
|
this.events = {
|
|
808
850
|
offer: ClaimEvent,
|
|
809
851
|
withdraw: ClaimEvent,
|
|
@@ -814,16 +856,16 @@ var FungibleTokenClaimContract = class extends import_o1js5.SmartContract {
|
|
|
814
856
|
async deploy(args) {
|
|
815
857
|
await super.deploy(args);
|
|
816
858
|
this.whitelist.set(args.whitelist);
|
|
817
|
-
this.maxAmount.set(args.maxAmount ??
|
|
859
|
+
this.maxAmount.set(args.maxAmount ?? import_o1js6.UInt64.MAXINT());
|
|
818
860
|
this.account.permissions.set({
|
|
819
|
-
...
|
|
820
|
-
send:
|
|
821
|
-
setVerificationKey:
|
|
822
|
-
setPermissions:
|
|
861
|
+
...import_o1js6.Permissions.default(),
|
|
862
|
+
send: import_o1js6.Permissions.proof(),
|
|
863
|
+
setVerificationKey: import_o1js6.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
864
|
+
setPermissions: import_o1js6.Permissions.impossible()
|
|
823
865
|
});
|
|
824
866
|
}
|
|
825
867
|
async initialize(owner, token, amount) {
|
|
826
|
-
this.account.provedState.requireEquals((0,
|
|
868
|
+
this.account.provedState.requireEquals((0, import_o1js6.Bool)(false));
|
|
827
869
|
const tokenContract = new FungibleToken(token);
|
|
828
870
|
const tokenId = tokenContract.deriveTokenId();
|
|
829
871
|
tokenId.assertEquals(this.tokenId);
|
|
@@ -839,27 +881,27 @@ var FungibleTokenClaimContract = class extends import_o1js5.SmartContract {
|
|
|
839
881
|
const tokenId = tokenContract.deriveTokenId();
|
|
840
882
|
tokenId.assertEquals(this.tokenId);
|
|
841
883
|
const sender = this.sender.getUnconstrained();
|
|
842
|
-
const senderUpdate =
|
|
843
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
884
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender);
|
|
885
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
844
886
|
sender.assertEquals(owner);
|
|
845
887
|
await tokenContract.transfer(sender, this.address, amount);
|
|
846
888
|
this.emitEvent("offer", { amount, address: sender });
|
|
847
889
|
}
|
|
848
890
|
async withdraw(amount) {
|
|
849
|
-
amount.equals(
|
|
850
|
-
this.account.balance.requireBetween(amount,
|
|
891
|
+
amount.equals(import_o1js6.UInt64.from(0)).assertFalse();
|
|
892
|
+
this.account.balance.requireBetween(amount, import_o1js6.UInt64.MAXINT());
|
|
851
893
|
const owner = this.owner.getAndRequireEquals();
|
|
852
894
|
const token = this.token.getAndRequireEquals();
|
|
853
895
|
const tokenContract = new FungibleToken(token);
|
|
854
896
|
const tokenId = tokenContract.deriveTokenId();
|
|
855
897
|
tokenId.assertEquals(this.tokenId);
|
|
856
898
|
const sender = this.sender.getUnconstrained();
|
|
857
|
-
const senderUpdate =
|
|
858
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
899
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender, tokenId);
|
|
900
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
859
901
|
sender.assertEquals(owner);
|
|
860
902
|
let offerUpdate = this.send({ to: senderUpdate, amount });
|
|
861
|
-
offerUpdate.body.mayUseToken =
|
|
862
|
-
offerUpdate.body.useFullCommitment = (0,
|
|
903
|
+
offerUpdate.body.mayUseToken = import_o1js6.AccountUpdate.MayUseToken.InheritFromParent;
|
|
904
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
863
905
|
this.emitEvent("withdraw", { amount, address: sender });
|
|
864
906
|
}
|
|
865
907
|
async claim(amount) {
|
|
@@ -869,16 +911,16 @@ var FungibleTokenClaimContract = class extends import_o1js5.SmartContract {
|
|
|
869
911
|
const tokenId = tokenContract.deriveTokenId();
|
|
870
912
|
tokenId.assertEquals(this.tokenId);
|
|
871
913
|
const sender = this.sender.getUnconstrained();
|
|
872
|
-
const senderUpdate =
|
|
873
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
914
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender, tokenId);
|
|
915
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
874
916
|
const whitelist = this.whitelist.getAndRequireEquals();
|
|
875
917
|
const whiteListedAmount = await whitelist.getWhitelistedAmount(sender);
|
|
876
|
-
const maxClaimAmount =
|
|
918
|
+
const maxClaimAmount = import_o1js6.Provable.if(whitelist.isSome(), whiteListedAmount.assertSome("No tokens to claim"), maxAmount);
|
|
877
919
|
amount.assertLessThanOrEqual(maxClaimAmount);
|
|
878
|
-
this.account.balance.requireBetween(amount,
|
|
920
|
+
this.account.balance.requireBetween(amount, import_o1js6.UInt64.MAXINT());
|
|
879
921
|
let offerUpdate = this.send({ to: senderUpdate, amount });
|
|
880
|
-
offerUpdate.body.mayUseToken =
|
|
881
|
-
offerUpdate.body.useFullCommitment = (0,
|
|
922
|
+
offerUpdate.body.mayUseToken = import_o1js6.AccountUpdate.MayUseToken.InheritFromParent;
|
|
923
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
882
924
|
this.emitEvent("claim", {
|
|
883
925
|
amount,
|
|
884
926
|
address: sender
|
|
@@ -887,59 +929,59 @@ var FungibleTokenClaimContract = class extends import_o1js5.SmartContract {
|
|
|
887
929
|
async updateWhitelist(whitelist) {
|
|
888
930
|
const owner = this.owner.getAndRequireEquals();
|
|
889
931
|
const sender = this.sender.getUnconstrained();
|
|
890
|
-
const senderUpdate =
|
|
891
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
932
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender);
|
|
933
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
892
934
|
sender.assertEquals(owner);
|
|
893
935
|
this.whitelist.set(whitelist);
|
|
894
936
|
this.emitEvent("updateWhitelist", whitelist);
|
|
895
937
|
}
|
|
896
938
|
};
|
|
897
939
|
(0, import_tslib5.__decorate)([
|
|
898
|
-
(0,
|
|
940
|
+
(0, import_o1js6.state)(import_o1js6.PublicKey),
|
|
899
941
|
(0, import_tslib5.__metadata)("design:type", Object)
|
|
900
942
|
], FungibleTokenClaimContract.prototype, "owner", void 0);
|
|
901
943
|
(0, import_tslib5.__decorate)([
|
|
902
|
-
(0,
|
|
944
|
+
(0, import_o1js6.state)(import_o1js6.PublicKey),
|
|
903
945
|
(0, import_tslib5.__metadata)("design:type", Object)
|
|
904
946
|
], FungibleTokenClaimContract.prototype, "token", void 0);
|
|
905
947
|
(0, import_tslib5.__decorate)([
|
|
906
|
-
(0,
|
|
948
|
+
(0, import_o1js6.state)(import_storage3.Whitelist),
|
|
907
949
|
(0, import_tslib5.__metadata)("design:type", Object)
|
|
908
950
|
], FungibleTokenClaimContract.prototype, "whitelist", void 0);
|
|
909
951
|
(0, import_tslib5.__decorate)([
|
|
910
|
-
(0,
|
|
952
|
+
(0, import_o1js6.state)(import_o1js6.UInt64),
|
|
911
953
|
(0, import_tslib5.__metadata)("design:type", Object)
|
|
912
954
|
], FungibleTokenClaimContract.prototype, "maxAmount", void 0);
|
|
913
955
|
(0, import_tslib5.__decorate)([
|
|
914
|
-
|
|
956
|
+
import_o1js6.method,
|
|
915
957
|
(0, import_tslib5.__metadata)("design:type", Function),
|
|
916
958
|
(0, import_tslib5.__metadata)("design:paramtypes", [
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
959
|
+
import_o1js6.PublicKey,
|
|
960
|
+
import_o1js6.PublicKey,
|
|
961
|
+
import_o1js6.UInt64
|
|
920
962
|
]),
|
|
921
963
|
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
922
964
|
], FungibleTokenClaimContract.prototype, "initialize", null);
|
|
923
965
|
(0, import_tslib5.__decorate)([
|
|
924
|
-
|
|
966
|
+
import_o1js6.method,
|
|
925
967
|
(0, import_tslib5.__metadata)("design:type", Function),
|
|
926
|
-
(0, import_tslib5.__metadata)("design:paramtypes", [
|
|
968
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_o1js6.UInt64]),
|
|
927
969
|
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
928
970
|
], FungibleTokenClaimContract.prototype, "offer", null);
|
|
929
971
|
(0, import_tslib5.__decorate)([
|
|
930
|
-
|
|
972
|
+
import_o1js6.method,
|
|
931
973
|
(0, import_tslib5.__metadata)("design:type", Function),
|
|
932
|
-
(0, import_tslib5.__metadata)("design:paramtypes", [
|
|
974
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_o1js6.UInt64]),
|
|
933
975
|
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
934
976
|
], FungibleTokenClaimContract.prototype, "withdraw", null);
|
|
935
977
|
(0, import_tslib5.__decorate)([
|
|
936
|
-
|
|
978
|
+
import_o1js6.method,
|
|
937
979
|
(0, import_tslib5.__metadata)("design:type", Function),
|
|
938
|
-
(0, import_tslib5.__metadata)("design:paramtypes", [
|
|
980
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_o1js6.UInt64]),
|
|
939
981
|
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
940
982
|
], FungibleTokenClaimContract.prototype, "claim", null);
|
|
941
983
|
(0, import_tslib5.__decorate)([
|
|
942
|
-
|
|
984
|
+
import_o1js6.method,
|
|
943
985
|
(0, import_tslib5.__metadata)("design:type", Function),
|
|
944
986
|
(0, import_tslib5.__metadata)("design:paramtypes", [import_storage3.Whitelist]),
|
|
945
987
|
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
@@ -947,20 +989,20 @@ var FungibleTokenClaimContract = class extends import_o1js5.SmartContract {
|
|
|
947
989
|
|
|
948
990
|
// dist/node/offer.js
|
|
949
991
|
var import_tslib6 = require("tslib");
|
|
950
|
-
var
|
|
992
|
+
var import_o1js7 = require("o1js");
|
|
951
993
|
var import_storage4 = require("@silvana-one/storage");
|
|
952
|
-
var OfferEvent = class extends (0,
|
|
953
|
-
amount:
|
|
954
|
-
address:
|
|
994
|
+
var OfferEvent = class extends (0, import_o1js7.Struct)({
|
|
995
|
+
amount: import_o1js7.UInt64,
|
|
996
|
+
address: import_o1js7.PublicKey
|
|
955
997
|
}) {
|
|
956
998
|
};
|
|
957
|
-
var FungibleTokenOfferContract = class extends
|
|
999
|
+
var FungibleTokenOfferContract = class extends import_o1js7.SmartContract {
|
|
958
1000
|
constructor() {
|
|
959
1001
|
super(...arguments);
|
|
960
|
-
this.price = (0,
|
|
961
|
-
this.seller = (0,
|
|
962
|
-
this.token = (0,
|
|
963
|
-
this.whitelist = (0,
|
|
1002
|
+
this.price = (0, import_o1js7.State)();
|
|
1003
|
+
this.seller = (0, import_o1js7.State)();
|
|
1004
|
+
this.token = (0, import_o1js7.State)();
|
|
1005
|
+
this.whitelist = (0, import_o1js7.State)();
|
|
964
1006
|
this.events = {
|
|
965
1007
|
offer: OfferEvent,
|
|
966
1008
|
withdraw: OfferEvent,
|
|
@@ -972,14 +1014,14 @@ var FungibleTokenOfferContract = class extends import_o1js6.SmartContract {
|
|
|
972
1014
|
await super.deploy(args);
|
|
973
1015
|
this.whitelist.set(args.whitelist);
|
|
974
1016
|
this.account.permissions.set({
|
|
975
|
-
...
|
|
976
|
-
send:
|
|
977
|
-
setVerificationKey:
|
|
978
|
-
setPermissions:
|
|
1017
|
+
...import_o1js7.Permissions.default(),
|
|
1018
|
+
send: import_o1js7.Permissions.proof(),
|
|
1019
|
+
setVerificationKey: import_o1js7.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
1020
|
+
setPermissions: import_o1js7.Permissions.impossible()
|
|
979
1021
|
});
|
|
980
1022
|
}
|
|
981
1023
|
async initialize(seller, token, amount, price) {
|
|
982
|
-
this.account.provedState.requireEquals((0,
|
|
1024
|
+
this.account.provedState.requireEquals((0, import_o1js7.Bool)(false));
|
|
983
1025
|
const tokenContract = new FungibleToken(token);
|
|
984
1026
|
const tokenId = tokenContract.deriveTokenId();
|
|
985
1027
|
tokenId.assertEquals(this.tokenId);
|
|
@@ -997,51 +1039,53 @@ var FungibleTokenOfferContract = class extends import_o1js6.SmartContract {
|
|
|
997
1039
|
tokenId.assertEquals(this.tokenId);
|
|
998
1040
|
const balance = this.account.balance.getAndRequireEquals();
|
|
999
1041
|
const oldPrice = this.price.getAndRequireEquals();
|
|
1000
|
-
price.equals(oldPrice).or(balance.equals(
|
|
1042
|
+
price.equals(oldPrice).or(balance.equals(import_o1js7.UInt64.from(0))).assertTrue();
|
|
1001
1043
|
this.price.set(price);
|
|
1002
1044
|
const sender = this.sender.getUnconstrained();
|
|
1003
|
-
const senderUpdate =
|
|
1004
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
1045
|
+
const senderUpdate = import_o1js7.AccountUpdate.createSigned(sender);
|
|
1046
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1005
1047
|
sender.assertEquals(seller);
|
|
1006
1048
|
await tokenContract.transfer(sender, this.address, amount);
|
|
1007
1049
|
this.emitEvent("offer", { amount, address: sender });
|
|
1008
1050
|
}
|
|
1009
1051
|
async withdraw(amount) {
|
|
1010
|
-
amount.equals(
|
|
1011
|
-
this.account.balance.requireBetween(amount,
|
|
1052
|
+
amount.equals(import_o1js7.UInt64.from(0)).assertFalse();
|
|
1053
|
+
this.account.balance.requireBetween(amount, import_o1js7.UInt64.MAXINT());
|
|
1012
1054
|
const seller = this.seller.getAndRequireEquals();
|
|
1013
1055
|
const token = this.token.getAndRequireEquals();
|
|
1014
1056
|
const tokenContract = new FungibleToken(token);
|
|
1015
1057
|
const tokenId = tokenContract.deriveTokenId();
|
|
1016
1058
|
tokenId.assertEquals(this.tokenId);
|
|
1017
1059
|
const sender = this.sender.getUnconstrained();
|
|
1018
|
-
const senderUpdate =
|
|
1019
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
1060
|
+
const senderUpdate = import_o1js7.AccountUpdate.createSigned(sender, tokenId);
|
|
1061
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1020
1062
|
sender.assertEquals(seller);
|
|
1021
1063
|
let offerUpdate = this.send({ to: senderUpdate, amount });
|
|
1022
|
-
offerUpdate.body.mayUseToken =
|
|
1023
|
-
offerUpdate.body.useFullCommitment = (0,
|
|
1064
|
+
offerUpdate.body.mayUseToken = import_o1js7.AccountUpdate.MayUseToken.InheritFromParent;
|
|
1065
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1024
1066
|
this.emitEvent("withdraw", { amount, address: sender });
|
|
1025
1067
|
}
|
|
1026
1068
|
async buy(amount) {
|
|
1027
|
-
amount.equals(
|
|
1028
|
-
this.account.balance.requireBetween(amount,
|
|
1069
|
+
amount.equals(import_o1js7.UInt64.from(0)).assertFalse();
|
|
1070
|
+
this.account.balance.requireBetween(amount, import_o1js7.UInt64.MAXINT());
|
|
1029
1071
|
const seller = this.seller.getAndRequireEquals();
|
|
1030
1072
|
const token = this.token.getAndRequireEquals();
|
|
1031
1073
|
const tokenContract = new FungibleToken(token);
|
|
1032
1074
|
const tokenId = tokenContract.deriveTokenId();
|
|
1033
1075
|
tokenId.assertEquals(this.tokenId);
|
|
1034
1076
|
const price = this.price.getAndRequireEquals();
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1077
|
+
const totalPrice = mulDiv({
|
|
1078
|
+
value: price,
|
|
1079
|
+
multiplier: amount,
|
|
1080
|
+
denominator: import_o1js7.UInt64.from(1e9)
|
|
1081
|
+
}).result;
|
|
1038
1082
|
const buyer = this.sender.getUnconstrained();
|
|
1039
|
-
const buyerUpdate =
|
|
1083
|
+
const buyerUpdate = import_o1js7.AccountUpdate.createSigned(buyer);
|
|
1040
1084
|
buyerUpdate.send({ to: seller, amount: totalPrice });
|
|
1041
|
-
buyerUpdate.body.useFullCommitment = (0,
|
|
1085
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1042
1086
|
let offerUpdate = this.send({ to: buyer, amount });
|
|
1043
|
-
offerUpdate.body.mayUseToken =
|
|
1044
|
-
offerUpdate.body.useFullCommitment = (0,
|
|
1087
|
+
offerUpdate.body.mayUseToken = import_o1js7.AccountUpdate.MayUseToken.InheritFromParent;
|
|
1088
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1045
1089
|
const whitelist = this.whitelist.getAndRequireEquals();
|
|
1046
1090
|
const whitelistedAmount = await whitelist.getWhitelistedAmount(buyer);
|
|
1047
1091
|
amount.assertLessThanOrEqual(whitelistedAmount.assertSome("Cannot buy more than whitelisted amount"));
|
|
@@ -1050,60 +1094,60 @@ var FungibleTokenOfferContract = class extends import_o1js6.SmartContract {
|
|
|
1050
1094
|
async updateWhitelist(whitelist) {
|
|
1051
1095
|
const seller = this.seller.getAndRequireEquals();
|
|
1052
1096
|
const sender = this.sender.getUnconstrained();
|
|
1053
|
-
const senderUpdate =
|
|
1054
|
-
senderUpdate.body.useFullCommitment = (0,
|
|
1097
|
+
const senderUpdate = import_o1js7.AccountUpdate.createSigned(sender);
|
|
1098
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1055
1099
|
sender.assertEquals(seller);
|
|
1056
1100
|
this.whitelist.set(whitelist);
|
|
1057
1101
|
this.emitEvent("updateWhitelist", whitelist);
|
|
1058
1102
|
}
|
|
1059
1103
|
};
|
|
1060
1104
|
(0, import_tslib6.__decorate)([
|
|
1061
|
-
(0,
|
|
1105
|
+
(0, import_o1js7.state)(import_o1js7.UInt64),
|
|
1062
1106
|
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1063
1107
|
], FungibleTokenOfferContract.prototype, "price", void 0);
|
|
1064
1108
|
(0, import_tslib6.__decorate)([
|
|
1065
|
-
(0,
|
|
1109
|
+
(0, import_o1js7.state)(import_o1js7.PublicKey),
|
|
1066
1110
|
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1067
1111
|
], FungibleTokenOfferContract.prototype, "seller", void 0);
|
|
1068
1112
|
(0, import_tslib6.__decorate)([
|
|
1069
|
-
(0,
|
|
1113
|
+
(0, import_o1js7.state)(import_o1js7.PublicKey),
|
|
1070
1114
|
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1071
1115
|
], FungibleTokenOfferContract.prototype, "token", void 0);
|
|
1072
1116
|
(0, import_tslib6.__decorate)([
|
|
1073
|
-
(0,
|
|
1117
|
+
(0, import_o1js7.state)(import_storage4.Whitelist),
|
|
1074
1118
|
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1075
1119
|
], FungibleTokenOfferContract.prototype, "whitelist", void 0);
|
|
1076
1120
|
(0, import_tslib6.__decorate)([
|
|
1077
|
-
|
|
1121
|
+
import_o1js7.method,
|
|
1078
1122
|
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1079
1123
|
(0, import_tslib6.__metadata)("design:paramtypes", [
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1124
|
+
import_o1js7.PublicKey,
|
|
1125
|
+
import_o1js7.PublicKey,
|
|
1126
|
+
import_o1js7.UInt64,
|
|
1127
|
+
import_o1js7.UInt64
|
|
1084
1128
|
]),
|
|
1085
1129
|
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1086
1130
|
], FungibleTokenOfferContract.prototype, "initialize", null);
|
|
1087
1131
|
(0, import_tslib6.__decorate)([
|
|
1088
|
-
|
|
1132
|
+
import_o1js7.method,
|
|
1089
1133
|
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1090
|
-
(0, import_tslib6.__metadata)("design:paramtypes", [
|
|
1134
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_o1js7.UInt64, import_o1js7.UInt64]),
|
|
1091
1135
|
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1092
1136
|
], FungibleTokenOfferContract.prototype, "offer", null);
|
|
1093
1137
|
(0, import_tslib6.__decorate)([
|
|
1094
|
-
|
|
1138
|
+
import_o1js7.method,
|
|
1095
1139
|
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1096
|
-
(0, import_tslib6.__metadata)("design:paramtypes", [
|
|
1140
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_o1js7.UInt64]),
|
|
1097
1141
|
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1098
1142
|
], FungibleTokenOfferContract.prototype, "withdraw", null);
|
|
1099
1143
|
(0, import_tslib6.__decorate)([
|
|
1100
|
-
|
|
1144
|
+
import_o1js7.method,
|
|
1101
1145
|
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1102
|
-
(0, import_tslib6.__metadata)("design:paramtypes", [
|
|
1146
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_o1js7.UInt64]),
|
|
1103
1147
|
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1104
1148
|
], FungibleTokenOfferContract.prototype, "buy", null);
|
|
1105
1149
|
(0, import_tslib6.__decorate)([
|
|
1106
|
-
|
|
1150
|
+
import_o1js7.method,
|
|
1107
1151
|
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1108
1152
|
(0, import_tslib6.__metadata)("design:paramtypes", [import_storage4.Whitelist]),
|
|
1109
1153
|
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
@@ -1111,17 +1155,17 @@ var FungibleTokenOfferContract = class extends import_o1js6.SmartContract {
|
|
|
1111
1155
|
|
|
1112
1156
|
// dist/node/BondingCurveAdmin.js
|
|
1113
1157
|
var import_tslib7 = require("tslib");
|
|
1114
|
-
var
|
|
1158
|
+
var import_o1js8 = require("o1js");
|
|
1115
1159
|
var import_token = require("@silvana-one/token");
|
|
1116
|
-
var BondingCurveParams = class _BondingCurveParams extends (0,
|
|
1117
|
-
startPrice:
|
|
1118
|
-
curveK:
|
|
1119
|
-
fee:
|
|
1160
|
+
var BondingCurveParams = class _BondingCurveParams extends (0, import_o1js8.Struct)({
|
|
1161
|
+
startPrice: import_o1js8.UInt64,
|
|
1162
|
+
curveK: import_o1js8.UInt64,
|
|
1163
|
+
fee: import_o1js8.UInt32,
|
|
1120
1164
|
// 1000 = 1%
|
|
1121
|
-
mintingIsAllowed:
|
|
1165
|
+
mintingIsAllowed: import_o1js8.Bool
|
|
1122
1166
|
}) {
|
|
1123
1167
|
pack() {
|
|
1124
|
-
return
|
|
1168
|
+
return import_o1js8.Field.fromBits([
|
|
1125
1169
|
...this.startPrice.value.toBits(64),
|
|
1126
1170
|
...this.curveK.value.toBits(64),
|
|
1127
1171
|
...this.fee.value.toBits(32),
|
|
@@ -1130,9 +1174,9 @@ var BondingCurveParams = class _BondingCurveParams extends (0, import_o1js7.Stru
|
|
|
1130
1174
|
}
|
|
1131
1175
|
static unpack(field) {
|
|
1132
1176
|
const bits = field.toBits(64 + 64 + 32 + 1);
|
|
1133
|
-
const startPrice =
|
|
1134
|
-
const curveK =
|
|
1135
|
-
const fee =
|
|
1177
|
+
const startPrice = import_o1js8.UInt64.Unsafe.fromField(import_o1js8.Field.fromBits(bits.slice(0, 64)));
|
|
1178
|
+
const curveK = import_o1js8.UInt64.Unsafe.fromField(import_o1js8.Field.fromBits(bits.slice(64, 64 + 64)));
|
|
1179
|
+
const fee = import_o1js8.UInt32.Unsafe.fromField(import_o1js8.Field.fromBits(bits.slice(64 + 64, 64 + 64 + 32)));
|
|
1136
1180
|
const mintingIsAllowed = bits[64 + 64 + 32];
|
|
1137
1181
|
return new _BondingCurveParams({
|
|
1138
1182
|
startPrice,
|
|
@@ -1142,42 +1186,42 @@ var BondingCurveParams = class _BondingCurveParams extends (0, import_o1js7.Stru
|
|
|
1142
1186
|
});
|
|
1143
1187
|
}
|
|
1144
1188
|
};
|
|
1145
|
-
var BondingMintEvent = class extends (0,
|
|
1146
|
-
to:
|
|
1147
|
-
amount:
|
|
1148
|
-
price:
|
|
1149
|
-
payment:
|
|
1150
|
-
fee:
|
|
1189
|
+
var BondingMintEvent = class extends (0, import_o1js8.Struct)({
|
|
1190
|
+
to: import_o1js8.PublicKey,
|
|
1191
|
+
amount: import_o1js8.UInt64,
|
|
1192
|
+
price: import_o1js8.UInt64,
|
|
1193
|
+
payment: import_o1js8.UInt64,
|
|
1194
|
+
fee: import_o1js8.UInt64
|
|
1151
1195
|
}) {
|
|
1152
1196
|
};
|
|
1153
|
-
var BondingRedeemEvent = class extends (0,
|
|
1154
|
-
seller:
|
|
1155
|
-
amount:
|
|
1156
|
-
payment:
|
|
1157
|
-
minBalance:
|
|
1158
|
-
maxSupply:
|
|
1159
|
-
fee:
|
|
1197
|
+
var BondingRedeemEvent = class extends (0, import_o1js8.Struct)({
|
|
1198
|
+
seller: import_o1js8.PublicKey,
|
|
1199
|
+
amount: import_o1js8.UInt64,
|
|
1200
|
+
payment: import_o1js8.UInt64,
|
|
1201
|
+
minBalance: import_o1js8.UInt64,
|
|
1202
|
+
maxSupply: import_o1js8.UInt64,
|
|
1203
|
+
fee: import_o1js8.UInt64
|
|
1160
1204
|
}) {
|
|
1161
1205
|
};
|
|
1162
|
-
var BondingCurveAdminInitializeProps = class extends (0,
|
|
1163
|
-
tokenAddress:
|
|
1164
|
-
startPrice:
|
|
1165
|
-
curveK:
|
|
1166
|
-
feeMaster:
|
|
1167
|
-
fee:
|
|
1206
|
+
var BondingCurveAdminInitializeProps = class extends (0, import_o1js8.Struct)({
|
|
1207
|
+
tokenAddress: import_o1js8.PublicKey,
|
|
1208
|
+
startPrice: import_o1js8.UInt64,
|
|
1209
|
+
curveK: import_o1js8.UInt64,
|
|
1210
|
+
feeMaster: import_o1js8.PublicKey,
|
|
1211
|
+
fee: import_o1js8.UInt32,
|
|
1168
1212
|
// 1000 = 1%
|
|
1169
|
-
launchFee:
|
|
1170
|
-
numberOfNewAccounts:
|
|
1213
|
+
launchFee: import_o1js8.UInt64,
|
|
1214
|
+
numberOfNewAccounts: import_o1js8.UInt64
|
|
1171
1215
|
}) {
|
|
1172
1216
|
};
|
|
1173
|
-
var FungibleTokenBondingCurveAdmin = class extends
|
|
1217
|
+
var FungibleTokenBondingCurveAdmin = class extends import_o1js8.TokenContract {
|
|
1174
1218
|
constructor() {
|
|
1175
1219
|
super(...arguments);
|
|
1176
|
-
this.owner = (0,
|
|
1177
|
-
this.token = (0,
|
|
1178
|
-
this.feeMaster = (0,
|
|
1179
|
-
this.curve = (0,
|
|
1180
|
-
this.insideMint = (0,
|
|
1220
|
+
this.owner = (0, import_o1js8.State)(import_o1js8.PublicKey.empty());
|
|
1221
|
+
this.token = (0, import_o1js8.State)(import_o1js8.PublicKey.empty());
|
|
1222
|
+
this.feeMaster = (0, import_o1js8.State)(import_o1js8.PublicKey.empty());
|
|
1223
|
+
this.curve = (0, import_o1js8.State)();
|
|
1224
|
+
this.insideMint = (0, import_o1js8.State)((0, import_o1js8.Bool)(false));
|
|
1181
1225
|
this.events = {
|
|
1182
1226
|
mint: BondingMintEvent,
|
|
1183
1227
|
redeem: BondingRedeemEvent
|
|
@@ -1186,16 +1230,16 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1186
1230
|
async deploy(props) {
|
|
1187
1231
|
await super.deploy(props);
|
|
1188
1232
|
this.curve.set(new BondingCurveParams({
|
|
1189
|
-
startPrice:
|
|
1190
|
-
curveK:
|
|
1191
|
-
fee:
|
|
1192
|
-
mintingIsAllowed: (0,
|
|
1233
|
+
startPrice: import_o1js8.UInt64.from(1e4),
|
|
1234
|
+
curveK: import_o1js8.UInt64.from(1e4),
|
|
1235
|
+
fee: import_o1js8.UInt32.from(1e3),
|
|
1236
|
+
mintingIsAllowed: (0, import_o1js8.Bool)(false)
|
|
1193
1237
|
}).pack());
|
|
1194
1238
|
this.account.permissions.set({
|
|
1195
|
-
...
|
|
1196
|
-
setVerificationKey:
|
|
1197
|
-
setPermissions:
|
|
1198
|
-
send:
|
|
1239
|
+
...import_o1js8.Permissions.default(),
|
|
1240
|
+
setVerificationKey: import_o1js8.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
1241
|
+
setPermissions: import_o1js8.Permissions.impossible(),
|
|
1242
|
+
send: import_o1js8.Permissions.proof()
|
|
1199
1243
|
});
|
|
1200
1244
|
}
|
|
1201
1245
|
async approveBase(forest) {
|
|
@@ -1203,41 +1247,41 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1203
1247
|
}
|
|
1204
1248
|
async initialize(props) {
|
|
1205
1249
|
const { tokenAddress, feeMaster, startPrice, curveK, fee, launchFee, numberOfNewAccounts } = props;
|
|
1206
|
-
this.account.provedState.requireEquals((0,
|
|
1250
|
+
this.account.provedState.requireEquals((0, import_o1js8.Bool)(false));
|
|
1207
1251
|
this.token.set(tokenAddress);
|
|
1208
1252
|
this.feeMaster.set(feeMaster);
|
|
1209
1253
|
this.curve.set(new BondingCurveParams({
|
|
1210
1254
|
startPrice,
|
|
1211
1255
|
curveK,
|
|
1212
1256
|
fee,
|
|
1213
|
-
mintingIsAllowed: (0,
|
|
1257
|
+
mintingIsAllowed: (0, import_o1js8.Bool)(false)
|
|
1214
1258
|
}).pack());
|
|
1215
|
-
const supplyUpdate =
|
|
1216
|
-
let permissions =
|
|
1217
|
-
permissions.send =
|
|
1218
|
-
permissions.setPermissions =
|
|
1259
|
+
const supplyUpdate = import_o1js8.AccountUpdate.createSigned(this.address, this.deriveTokenId());
|
|
1260
|
+
let permissions = import_o1js8.Permissions.default();
|
|
1261
|
+
permissions.send = import_o1js8.Permissions.none();
|
|
1262
|
+
permissions.setPermissions = import_o1js8.Permissions.impossible();
|
|
1219
1263
|
supplyUpdate.account.permissions.set(permissions);
|
|
1220
|
-
const payment = launchFee.add(numberOfNewAccounts.mul(
|
|
1264
|
+
const payment = launchFee.add(numberOfNewAccounts.mul(import_o1js8.UInt64.from(1e9)));
|
|
1221
1265
|
const owner = this.sender.getUnconstrained();
|
|
1222
|
-
const ownerUpdate =
|
|
1266
|
+
const ownerUpdate = import_o1js8.AccountUpdate.create(owner);
|
|
1223
1267
|
ownerUpdate.requireSignature();
|
|
1224
1268
|
this.owner.set(owner);
|
|
1225
|
-
ownerUpdate.body.useFullCommitment = (0,
|
|
1226
|
-
ownerUpdate.account.balance.requireBetween(payment,
|
|
1269
|
+
ownerUpdate.body.useFullCommitment = (0, import_o1js8.Bool)(true);
|
|
1270
|
+
ownerUpdate.account.balance.requireBetween(payment, import_o1js8.UInt64.MAXINT());
|
|
1227
1271
|
ownerUpdate.balance.subInPlace(payment);
|
|
1228
|
-
const feeUpdate =
|
|
1272
|
+
const feeUpdate = import_o1js8.AccountUpdate.create(feeMaster);
|
|
1229
1273
|
feeUpdate.balance.addInPlace(launchFee);
|
|
1230
1274
|
}
|
|
1231
1275
|
async mint(to, amount, price) {
|
|
1232
|
-
this.insideMint.getAndRequireEquals().assertEquals((0,
|
|
1233
|
-
this.insideMint.set((0,
|
|
1276
|
+
this.insideMint.getAndRequireEquals().assertEquals((0, import_o1js8.Bool)(false));
|
|
1277
|
+
this.insideMint.set((0, import_o1js8.Bool)(true));
|
|
1234
1278
|
const tokenAddress = this.token.getAndRequireEquals();
|
|
1235
1279
|
const token = new BondingCurveFungibleToken(tokenAddress);
|
|
1236
1280
|
const { startPrice, curveK, fee, mintingIsAllowed } = BondingCurveParams.unpack(this.curve.getAndRequireEquals());
|
|
1237
1281
|
const buyer = this.sender.getUnconstrained();
|
|
1238
|
-
const buyerUpdate =
|
|
1282
|
+
const buyerUpdate = import_o1js8.AccountUpdate.create(buyer);
|
|
1239
1283
|
buyerUpdate.requireSignature();
|
|
1240
|
-
buyerUpdate.body.useFullCommitment = (0,
|
|
1284
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js8.Bool)(true);
|
|
1241
1285
|
const owner = this.owner.getAndRequireEquals();
|
|
1242
1286
|
const isOwner = owner.equals(buyer);
|
|
1243
1287
|
const canMint = isOwner.or(mintingIsAllowed);
|
|
@@ -1246,22 +1290,22 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1246
1290
|
startPrice,
|
|
1247
1291
|
curveK,
|
|
1248
1292
|
fee,
|
|
1249
|
-
mintingIsAllowed: (0,
|
|
1293
|
+
mintingIsAllowed: (0, import_o1js8.Bool)(true)
|
|
1250
1294
|
}).pack());
|
|
1251
|
-
const maximumSupplyField =
|
|
1295
|
+
const maximumSupplyField = import_o1js8.Provable.witness(import_o1js8.Field, () => {
|
|
1252
1296
|
if (price.toBigInt() < startPrice.toBigInt()) {
|
|
1253
1297
|
throw Error("Price must be greater than or equal to the start price");
|
|
1254
1298
|
}
|
|
1255
|
-
return
|
|
1299
|
+
return import_o1js8.Field.from((price.toBigInt() - startPrice.toBigInt()) * 10n ** 14n / curveK.toBigInt());
|
|
1256
1300
|
});
|
|
1257
|
-
maximumSupplyField.mul(curveK.value).add(startPrice.value.mul(
|
|
1258
|
-
maximumSupplyField.assertLessThan(
|
|
1259
|
-
const maximumSupply =
|
|
1260
|
-
const supplyUpdate =
|
|
1261
|
-
supplyUpdate.account.balance.requireBetween(
|
|
1262
|
-
amount.assertLessThanOrEqual(
|
|
1263
|
-
supplyUpdate.balanceChange =
|
|
1264
|
-
const paymentField =
|
|
1301
|
+
maximumSupplyField.mul(curveK.value).add(startPrice.value.mul(import_o1js8.Field.from(10 ** 14))).assertLessThanOrEqual(price.value.mul(import_o1js8.Field.from(10 ** 14)));
|
|
1302
|
+
maximumSupplyField.assertLessThan(import_o1js8.UInt64.MAXINT().value);
|
|
1303
|
+
const maximumSupply = import_o1js8.UInt64.Unsafe.fromField(maximumSupplyField);
|
|
1304
|
+
const supplyUpdate = import_o1js8.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
1305
|
+
supplyUpdate.account.balance.requireBetween(import_o1js8.UInt64.zero, maximumSupply);
|
|
1306
|
+
amount.assertLessThanOrEqual(import_o1js8.UInt64.from(2n ** 62n));
|
|
1307
|
+
supplyUpdate.balanceChange = import_o1js8.Int64.fromUnsigned(amount);
|
|
1308
|
+
const paymentField = import_o1js8.Provable.witness(import_o1js8.Field, () => {
|
|
1265
1309
|
let payment2 = price.toBigInt() * amount.toBigInt() / 10n ** 9n;
|
|
1266
1310
|
if (payment2 * 10n ** 9n !== price.toBigInt() * amount.toBigInt()) {
|
|
1267
1311
|
payment2++;
|
|
@@ -1269,12 +1313,12 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1269
1313
|
if (payment2 * 10n ** 9n < price.toBigInt() * amount.toBigInt()) {
|
|
1270
1314
|
throw Error("Payment calculation failed");
|
|
1271
1315
|
}
|
|
1272
|
-
return
|
|
1316
|
+
return import_o1js8.Field.from(payment2);
|
|
1273
1317
|
});
|
|
1274
|
-
paymentField.mul(
|
|
1275
|
-
paymentField.assertLessThan(
|
|
1276
|
-
const payment =
|
|
1277
|
-
const feePaymentField =
|
|
1318
|
+
paymentField.mul(import_o1js8.Field.from(10 ** 9)).assertGreaterThanOrEqual(price.value.mul(amount.value));
|
|
1319
|
+
paymentField.assertLessThan(import_o1js8.UInt64.MAXINT().value);
|
|
1320
|
+
const payment = import_o1js8.UInt64.Unsafe.fromField(paymentField);
|
|
1321
|
+
const feePaymentField = import_o1js8.Provable.witness(import_o1js8.Field, () => {
|
|
1278
1322
|
let feePayment2 = payment.toBigInt() * fee.toBigint() / 100000n;
|
|
1279
1323
|
if (feePayment2 * 100000n !== payment.toBigInt() * fee.toBigint()) {
|
|
1280
1324
|
feePayment2++;
|
|
@@ -1282,20 +1326,20 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1282
1326
|
if (feePayment2 * 100000n < payment.toBigInt() * fee.toBigint()) {
|
|
1283
1327
|
throw Error("Fee calculation failed");
|
|
1284
1328
|
}
|
|
1285
|
-
return
|
|
1329
|
+
return import_o1js8.Field.from(feePayment2);
|
|
1286
1330
|
});
|
|
1287
|
-
feePaymentField.mul(
|
|
1288
|
-
feePaymentField.assertLessThan(
|
|
1289
|
-
let feePayment =
|
|
1290
|
-
feePayment =
|
|
1331
|
+
feePaymentField.mul(import_o1js8.Field.from(1e5)).assertGreaterThanOrEqual(payment.value.mul(fee.value));
|
|
1332
|
+
feePaymentField.assertLessThan(import_o1js8.UInt64.MAXINT().value);
|
|
1333
|
+
let feePayment = import_o1js8.UInt64.Unsafe.fromField(feePaymentField);
|
|
1334
|
+
feePayment = import_o1js8.Provable.if(feePayment.lessThan(import_o1js8.UInt64.from(1e8)), import_o1js8.UInt64.from(1e8), feePayment);
|
|
1291
1335
|
const tokenUpdate = await token.mint(to, amount);
|
|
1292
1336
|
const isNew = tokenUpdate.account.isNew.get();
|
|
1293
|
-
const totalPayment = payment.add(feePayment).add(
|
|
1294
|
-
buyerUpdate.account.balance.requireBetween(totalPayment,
|
|
1337
|
+
const totalPayment = payment.add(feePayment).add(import_o1js8.Provable.if(isNew, import_o1js8.UInt64.from(1e9), import_o1js8.UInt64.zero));
|
|
1338
|
+
buyerUpdate.account.balance.requireBetween(totalPayment, import_o1js8.UInt64.MAXINT());
|
|
1295
1339
|
buyerUpdate.balance.subInPlace(totalPayment);
|
|
1296
1340
|
this.balance.addInPlace(payment);
|
|
1297
|
-
const feeUpdate =
|
|
1298
|
-
feeUpdate.body.useFullCommitment = (0,
|
|
1341
|
+
const feeUpdate = import_o1js8.AccountUpdate.create(this.feeMaster.getAndRequireEquals());
|
|
1342
|
+
feeUpdate.body.useFullCommitment = (0, import_o1js8.Bool)(true);
|
|
1299
1343
|
feeUpdate.balance.addInPlace(feePayment);
|
|
1300
1344
|
this.emitEvent("mint", new BondingMintEvent({
|
|
1301
1345
|
to,
|
|
@@ -1313,17 +1357,17 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1313
1357
|
async redeem(amount, minPrice, slippage) {
|
|
1314
1358
|
const tokenAddress = this.token.getAndRequireEquals();
|
|
1315
1359
|
const token = new BondingCurveFungibleToken(tokenAddress);
|
|
1316
|
-
const balance = await
|
|
1317
|
-
await (0,
|
|
1360
|
+
const balance = await import_o1js8.Provable.witnessAsync(import_o1js8.UInt64, async () => {
|
|
1361
|
+
await (0, import_o1js8.fetchAccount)({
|
|
1318
1362
|
publicKey: this.address,
|
|
1319
1363
|
tokenId: this.tokenId
|
|
1320
1364
|
});
|
|
1321
|
-
const balance2 =
|
|
1365
|
+
const balance2 = import_o1js8.Mina.getAccount(this.address, this.tokenId).balance;
|
|
1322
1366
|
console.log("redeem: balance", balance2.toBigInt());
|
|
1323
1367
|
return balance2;
|
|
1324
1368
|
});
|
|
1325
|
-
slippage.assertLessThan(
|
|
1326
|
-
const minBalanceField =
|
|
1369
|
+
slippage.assertLessThan(import_o1js8.UInt32.from(1e3));
|
|
1370
|
+
const minBalanceField = import_o1js8.Provable.witness(import_o1js8.Field, () => {
|
|
1327
1371
|
let minBalance2 = balance.toBigInt() * (1000n - slippage.toBigint()) / 1000n;
|
|
1328
1372
|
if (minBalance2 * 1000n !== balance.toBigInt() * (1000n - slippage.toBigint())) {
|
|
1329
1373
|
minBalance2++;
|
|
@@ -1331,38 +1375,38 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1331
1375
|
if (minBalance2 * 1000n < balance.toBigInt() * (1000n - slippage.toBigint())) {
|
|
1332
1376
|
throw Error("Min balance calculation failed");
|
|
1333
1377
|
}
|
|
1334
|
-
return
|
|
1378
|
+
return import_o1js8.Field.from(minBalance2);
|
|
1335
1379
|
});
|
|
1336
|
-
minBalanceField.mul(
|
|
1337
|
-
minBalanceField.assertLessThan(
|
|
1338
|
-
const minBalance =
|
|
1339
|
-
this.account.balance.requireBetween(minBalance,
|
|
1340
|
-
const supply = await
|
|
1341
|
-
await (0,
|
|
1380
|
+
minBalanceField.mul(import_o1js8.Field.from(1e3)).add(balance.value.mul(slippage.value)).assertGreaterThanOrEqual(balance.value.mul(import_o1js8.Field.from(1e3)));
|
|
1381
|
+
minBalanceField.assertLessThan(import_o1js8.UInt64.MAXINT().value);
|
|
1382
|
+
const minBalance = import_o1js8.UInt64.Unsafe.fromField(minBalanceField);
|
|
1383
|
+
this.account.balance.requireBetween(minBalance, import_o1js8.UInt64.MAXINT());
|
|
1384
|
+
const supply = await import_o1js8.Provable.witnessAsync(import_o1js8.UInt64, async () => {
|
|
1385
|
+
await (0, import_o1js8.fetchAccount)({
|
|
1342
1386
|
publicKey: this.address,
|
|
1343
1387
|
tokenId: this.deriveTokenId()
|
|
1344
1388
|
});
|
|
1345
|
-
const balance2 =
|
|
1389
|
+
const balance2 = import_o1js8.Mina.getAccount(this.address, this.deriveTokenId()).balance;
|
|
1346
1390
|
console.log("redeem: supply", balance2.toBigInt());
|
|
1347
1391
|
return balance2;
|
|
1348
1392
|
});
|
|
1349
1393
|
supply.assertGreaterThanOrEqual(amount);
|
|
1350
|
-
supply.assertGreaterThan(
|
|
1351
|
-
const maxSupplyField =
|
|
1352
|
-
maxSupplyField.mul(
|
|
1353
|
-
maxSupplyField.assertLessThan(
|
|
1354
|
-
const maxSupply =
|
|
1355
|
-
const supplyUpdate =
|
|
1356
|
-
supplyUpdate.account.balance.requireBetween(
|
|
1357
|
-
supplyUpdate.balanceChange =
|
|
1358
|
-
const paymentField =
|
|
1394
|
+
supply.assertGreaterThan(import_o1js8.UInt64.zero);
|
|
1395
|
+
const maxSupplyField = import_o1js8.Provable.witness(import_o1js8.Field, () => import_o1js8.Field.from(supply.toBigInt() * (1000n + slippage.toBigint()) / 1000n));
|
|
1396
|
+
maxSupplyField.mul(import_o1js8.Field.from(1e3)).assertLessThanOrEqual(supply.value.mul(import_o1js8.Field.from(1e3).add(slippage.value)));
|
|
1397
|
+
maxSupplyField.assertLessThan(import_o1js8.UInt64.MAXINT().value);
|
|
1398
|
+
const maxSupply = import_o1js8.UInt64.Unsafe.fromField(maxSupplyField);
|
|
1399
|
+
const supplyUpdate = import_o1js8.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
1400
|
+
supplyUpdate.account.balance.requireBetween(import_o1js8.UInt64.zero, maxSupply);
|
|
1401
|
+
supplyUpdate.balanceChange = import_o1js8.Int64.fromUnsigned(amount).neg();
|
|
1402
|
+
const paymentField = import_o1js8.Provable.witness(import_o1js8.Field, () => import_o1js8.Field.from(minBalance.toBigInt() * amount.toBigInt() / maxSupply.toBigInt()));
|
|
1359
1403
|
paymentField.mul(maxSupply.value).assertLessThanOrEqual(minBalance.value.mul(amount.value));
|
|
1360
|
-
paymentField.assertLessThan(
|
|
1361
|
-
amount.value.mul(minPrice.value).assertLessThanOrEqual(paymentField.mul(
|
|
1362
|
-
const payment =
|
|
1404
|
+
paymentField.assertLessThan(import_o1js8.Field.from(2n ** 62n));
|
|
1405
|
+
amount.value.mul(minPrice.value).assertLessThanOrEqual(paymentField.mul(import_o1js8.Field.from(10 ** 9)));
|
|
1406
|
+
const payment = import_o1js8.UInt64.Unsafe.fromField(paymentField);
|
|
1363
1407
|
const { fee, mintingIsAllowed } = BondingCurveParams.unpack(this.curve.getAndRequireEquals());
|
|
1364
1408
|
mintingIsAllowed.assertTrue("Minting is disabled for this token, nothing to redeem");
|
|
1365
|
-
let feePayment =
|
|
1409
|
+
let feePayment = import_o1js8.Provable.witness(import_o1js8.UInt64, () => {
|
|
1366
1410
|
let feePayment2 = payment.toBigInt() * fee.toBigint() / 100000n;
|
|
1367
1411
|
if (feePayment2 * 100000n !== payment.toBigInt() * fee.toBigint()) {
|
|
1368
1412
|
feePayment2++;
|
|
@@ -1370,23 +1414,23 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1370
1414
|
if (feePayment2 * 100000n < payment.toBigInt() * fee.toBigint()) {
|
|
1371
1415
|
throw Error("Fee calculation failed");
|
|
1372
1416
|
}
|
|
1373
|
-
return
|
|
1417
|
+
return import_o1js8.UInt64.from(feePayment2);
|
|
1374
1418
|
});
|
|
1375
|
-
feePayment =
|
|
1419
|
+
feePayment = import_o1js8.Provable.if(feePayment.lessThan(import_o1js8.UInt64.from(1e8)), import_o1js8.UInt64.from(1e8), feePayment);
|
|
1376
1420
|
const seller = this.sender.getUnconstrained();
|
|
1377
|
-
const sellerUpdate =
|
|
1378
|
-
const isNew = await
|
|
1379
|
-
const sellerAccount = await (0,
|
|
1421
|
+
const sellerUpdate = import_o1js8.AccountUpdate.create(seller);
|
|
1422
|
+
const isNew = await import_o1js8.Provable.witnessAsync(import_o1js8.Bool, async () => {
|
|
1423
|
+
const sellerAccount = await (0, import_o1js8.fetchAccount)({
|
|
1380
1424
|
publicKey: seller
|
|
1381
1425
|
});
|
|
1382
|
-
return (0,
|
|
1426
|
+
return (0, import_o1js8.Bool)(sellerAccount.account === void 0);
|
|
1383
1427
|
});
|
|
1384
1428
|
sellerUpdate.account.isNew.requireEquals(isNew);
|
|
1385
|
-
const accountCreationFee =
|
|
1429
|
+
const accountCreationFee = import_o1js8.Provable.if(isNew, import_o1js8.UInt64.from(1e9), import_o1js8.UInt64.zero);
|
|
1386
1430
|
payment.assertGreaterThan(feePayment.add(accountCreationFee));
|
|
1387
1431
|
sellerUpdate.requireSignature();
|
|
1388
|
-
sellerUpdate.body.useFullCommitment = (0,
|
|
1389
|
-
const totalPayment =
|
|
1432
|
+
sellerUpdate.body.useFullCommitment = (0, import_o1js8.Bool)(true);
|
|
1433
|
+
const totalPayment = import_o1js8.Provable.witness(import_o1js8.UInt64, () => {
|
|
1390
1434
|
if (payment.toBigInt() < feePayment.toBigInt() + accountCreationFee.toBigInt()) {
|
|
1391
1435
|
console.error(`The redeem amount ${Number(payment.toBigInt() / 10n ** 6n) / 1e3} MINA is too low to cover the fee ${Number(feePayment.toBigInt() / 10n ** 6n) / 1e3} MINA and account creation fee ${Number(accountCreationFee.toBigInt() / 10n ** 6n) / 1e3} MINA for the account ${seller.toBase58()}`, {
|
|
1392
1436
|
payment: payment.toBigInt(),
|
|
@@ -1403,12 +1447,12 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1403
1447
|
});
|
|
1404
1448
|
throw Error(`The redeem amount ${Number(payment.toBigInt() / 10n ** 6n) / 1e3} MINA is too low to cover the fee ${Number(feePayment.toBigInt() / 10n ** 6n) / 1e3} MINA and account creation fee ${Number(accountCreationFee.toBigInt() / 10n ** 6n) / 1e3} MINA for the account ${seller.toBase58()}`);
|
|
1405
1449
|
}
|
|
1406
|
-
return
|
|
1450
|
+
return import_o1js8.UInt64.from(payment.toBigInt() - feePayment.toBigInt() - accountCreationFee.toBigInt());
|
|
1407
1451
|
});
|
|
1408
1452
|
totalPayment.add(feePayment).add(accountCreationFee).assertEquals(payment);
|
|
1409
1453
|
sellerUpdate.balance.addInPlace(totalPayment);
|
|
1410
|
-
const feeUpdate =
|
|
1411
|
-
feeUpdate.body.useFullCommitment = (0,
|
|
1454
|
+
const feeUpdate = import_o1js8.AccountUpdate.create(this.feeMaster.getAndRequireEquals());
|
|
1455
|
+
feeUpdate.body.useFullCommitment = (0, import_o1js8.Bool)(true);
|
|
1412
1456
|
feeUpdate.balance.addInPlace(feePayment);
|
|
1413
1457
|
this.balance.subInPlace(payment);
|
|
1414
1458
|
await token.burn(seller, amount);
|
|
@@ -1428,10 +1472,10 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1428
1472
|
async sync() {
|
|
1429
1473
|
const tokenAddress = this.token.getAndRequireEquals();
|
|
1430
1474
|
const token = new BondingCurveFungibleToken(tokenAddress);
|
|
1431
|
-
const supplyUpdate =
|
|
1475
|
+
const supplyUpdate = import_o1js8.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
1432
1476
|
const circulatingSupply = await token.getBalanceOf(tokenAddress);
|
|
1433
1477
|
const totalSupply = supplyUpdate.account.balance.getAndRequireEquals();
|
|
1434
|
-
supplyUpdate.balanceChange =
|
|
1478
|
+
supplyUpdate.balanceChange = import_o1js8.Int64.fromUnsigned(totalSupply.sub(circulatingSupply)).neg();
|
|
1435
1479
|
}
|
|
1436
1480
|
/** Update the verification key.
|
|
1437
1481
|
* Note that because we have set the permissions for setting the verification key to `impossibleDuringCurrentVersion()`, this will only be possible in case of a protocol update that requires an update.
|
|
@@ -1441,110 +1485,110 @@ var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
|
1441
1485
|
}
|
|
1442
1486
|
ensureOwnerSignature() {
|
|
1443
1487
|
const owner = this.owner.getAndRequireEquals();
|
|
1444
|
-
const update =
|
|
1445
|
-
update.body.useFullCommitment = (0,
|
|
1488
|
+
const update = import_o1js8.AccountUpdate.createSigned(owner);
|
|
1489
|
+
update.body.useFullCommitment = (0, import_o1js8.Bool)(true);
|
|
1446
1490
|
return update;
|
|
1447
1491
|
}
|
|
1448
1492
|
async canMint(_accountUpdate) {
|
|
1449
|
-
this.insideMint.requireEquals((0,
|
|
1450
|
-
this.insideMint.set((0,
|
|
1451
|
-
return (0,
|
|
1493
|
+
this.insideMint.requireEquals((0, import_o1js8.Bool)(true));
|
|
1494
|
+
this.insideMint.set((0, import_o1js8.Bool)(false));
|
|
1495
|
+
return (0, import_o1js8.Bool)(true);
|
|
1452
1496
|
}
|
|
1453
1497
|
async canChangeAdmin(_admin) {
|
|
1454
1498
|
this.ensureOwnerSignature();
|
|
1455
|
-
return (0,
|
|
1499
|
+
return (0, import_o1js8.Bool)(true);
|
|
1456
1500
|
}
|
|
1457
1501
|
async canPause() {
|
|
1458
1502
|
this.ensureOwnerSignature();
|
|
1459
|
-
return (0,
|
|
1503
|
+
return (0, import_o1js8.Bool)(true);
|
|
1460
1504
|
}
|
|
1461
1505
|
async canResume() {
|
|
1462
1506
|
this.ensureOwnerSignature();
|
|
1463
|
-
return (0,
|
|
1507
|
+
return (0, import_o1js8.Bool)(true);
|
|
1464
1508
|
}
|
|
1465
1509
|
async canChangeVerificationKey(_vk) {
|
|
1466
1510
|
this.ensureOwnerSignature();
|
|
1467
|
-
return (0,
|
|
1511
|
+
return (0, import_o1js8.Bool)(true);
|
|
1468
1512
|
}
|
|
1469
1513
|
};
|
|
1470
1514
|
(0, import_tslib7.__decorate)([
|
|
1471
|
-
(0,
|
|
1515
|
+
(0, import_o1js8.state)(import_o1js8.PublicKey),
|
|
1472
1516
|
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1473
1517
|
], FungibleTokenBondingCurveAdmin.prototype, "owner", void 0);
|
|
1474
1518
|
(0, import_tslib7.__decorate)([
|
|
1475
|
-
(0,
|
|
1519
|
+
(0, import_o1js8.state)(import_o1js8.PublicKey),
|
|
1476
1520
|
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1477
1521
|
], FungibleTokenBondingCurveAdmin.prototype, "token", void 0);
|
|
1478
1522
|
(0, import_tslib7.__decorate)([
|
|
1479
|
-
(0,
|
|
1523
|
+
(0, import_o1js8.state)(import_o1js8.PublicKey),
|
|
1480
1524
|
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1481
1525
|
], FungibleTokenBondingCurveAdmin.prototype, "feeMaster", void 0);
|
|
1482
1526
|
(0, import_tslib7.__decorate)([
|
|
1483
|
-
(0,
|
|
1527
|
+
(0, import_o1js8.state)(import_o1js8.Field),
|
|
1484
1528
|
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1485
1529
|
], FungibleTokenBondingCurveAdmin.prototype, "curve", void 0);
|
|
1486
1530
|
(0, import_tslib7.__decorate)([
|
|
1487
|
-
(0,
|
|
1531
|
+
(0, import_o1js8.state)(import_o1js8.Bool),
|
|
1488
1532
|
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1489
1533
|
], FungibleTokenBondingCurveAdmin.prototype, "insideMint", void 0);
|
|
1490
1534
|
(0, import_tslib7.__decorate)([
|
|
1491
|
-
|
|
1535
|
+
import_o1js8.method,
|
|
1492
1536
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1493
1537
|
(0, import_tslib7.__metadata)("design:paramtypes", [BondingCurveAdminInitializeProps]),
|
|
1494
1538
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1495
1539
|
], FungibleTokenBondingCurveAdmin.prototype, "initialize", null);
|
|
1496
1540
|
(0, import_tslib7.__decorate)([
|
|
1497
|
-
|
|
1541
|
+
import_o1js8.method,
|
|
1498
1542
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1499
|
-
(0, import_tslib7.__metadata)("design:paramtypes", [
|
|
1543
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js8.PublicKey, import_o1js8.UInt64, import_o1js8.UInt64]),
|
|
1500
1544
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1501
1545
|
], FungibleTokenBondingCurveAdmin.prototype, "mint", null);
|
|
1502
1546
|
(0, import_tslib7.__decorate)([
|
|
1503
|
-
|
|
1547
|
+
import_o1js8.method,
|
|
1504
1548
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1505
|
-
(0, import_tslib7.__metadata)("design:paramtypes", [
|
|
1549
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js8.UInt64, import_o1js8.UInt64, import_o1js8.UInt32]),
|
|
1506
1550
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1507
1551
|
], FungibleTokenBondingCurveAdmin.prototype, "redeem", null);
|
|
1508
1552
|
(0, import_tslib7.__decorate)([
|
|
1509
|
-
|
|
1553
|
+
import_o1js8.method,
|
|
1510
1554
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1511
1555
|
(0, import_tslib7.__metadata)("design:paramtypes", []),
|
|
1512
1556
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1513
1557
|
], FungibleTokenBondingCurveAdmin.prototype, "sync", null);
|
|
1514
1558
|
(0, import_tslib7.__decorate)([
|
|
1515
|
-
|
|
1559
|
+
import_o1js8.method,
|
|
1516
1560
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1517
|
-
(0, import_tslib7.__metadata)("design:paramtypes", [
|
|
1561
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js8.VerificationKey]),
|
|
1518
1562
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1519
1563
|
], FungibleTokenBondingCurveAdmin.prototype, "updateVerificationKey", null);
|
|
1520
1564
|
(0, import_tslib7.__decorate)([
|
|
1521
|
-
|
|
1565
|
+
import_o1js8.method.returns(import_o1js8.Bool),
|
|
1522
1566
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1523
|
-
(0, import_tslib7.__metadata)("design:paramtypes", [
|
|
1567
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js8.AccountUpdate]),
|
|
1524
1568
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1525
1569
|
], FungibleTokenBondingCurveAdmin.prototype, "canMint", null);
|
|
1526
1570
|
(0, import_tslib7.__decorate)([
|
|
1527
|
-
|
|
1571
|
+
import_o1js8.method.returns(import_o1js8.Bool),
|
|
1528
1572
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1529
|
-
(0, import_tslib7.__metadata)("design:paramtypes", [
|
|
1573
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js8.PublicKey]),
|
|
1530
1574
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1531
1575
|
], FungibleTokenBondingCurveAdmin.prototype, "canChangeAdmin", null);
|
|
1532
1576
|
(0, import_tslib7.__decorate)([
|
|
1533
|
-
|
|
1577
|
+
import_o1js8.method.returns(import_o1js8.Bool),
|
|
1534
1578
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1535
1579
|
(0, import_tslib7.__metadata)("design:paramtypes", []),
|
|
1536
1580
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1537
1581
|
], FungibleTokenBondingCurveAdmin.prototype, "canPause", null);
|
|
1538
1582
|
(0, import_tslib7.__decorate)([
|
|
1539
|
-
|
|
1583
|
+
import_o1js8.method.returns(import_o1js8.Bool),
|
|
1540
1584
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1541
1585
|
(0, import_tslib7.__metadata)("design:paramtypes", []),
|
|
1542
1586
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1543
1587
|
], FungibleTokenBondingCurveAdmin.prototype, "canResume", null);
|
|
1544
1588
|
(0, import_tslib7.__decorate)([
|
|
1545
|
-
|
|
1589
|
+
import_o1js8.method.returns(import_o1js8.Bool),
|
|
1546
1590
|
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1547
|
-
(0, import_tslib7.__metadata)("design:paramtypes", [
|
|
1591
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js8.VerificationKey]),
|
|
1548
1592
|
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1549
1593
|
], FungibleTokenBondingCurveAdmin.prototype, "canChangeVerificationKey", null);
|
|
1550
1594
|
var BondingCurveFungibleToken = (0, import_token.FungibleTokenContract)(FungibleTokenBondingCurveAdmin);
|