@silvana-one/token 0.1.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/README.md +1 -0
- package/dist/node/BondingCurveAdmin.d.ts +690 -0
- package/dist/node/BondingCurveAdmin.js +504 -0
- package/dist/node/BondingCurveAdmin.js.map +1 -0
- package/dist/node/FungibleToken.d.ts +414 -0
- package/dist/node/FungibleToken.js +7 -0
- package/dist/node/FungibleToken.js.map +1 -0
- package/dist/node/FungibleTokenAdvancedAdmin.d.ts +124 -0
- package/dist/node/FungibleTokenAdvancedAdmin.js +226 -0
- package/dist/node/FungibleTokenAdvancedAdmin.js.map +1 -0
- package/dist/node/FungibleTokenContract.d.ts +526 -0
- package/dist/node/FungibleTokenContract.js +295 -0
- package/dist/node/FungibleTokenContract.js.map +1 -0
- package/dist/node/FungibleTokenStandardAdmin.d.ts +27 -0
- package/dist/node/FungibleTokenStandardAdmin.js +101 -0
- package/dist/node/FungibleTokenStandardAdmin.js.map +1 -0
- package/dist/node/bid.d.ts +86 -0
- package/dist/node/bid.js +168 -0
- package/dist/node/bid.js.map +1 -0
- package/dist/node/claim.d.ts +89 -0
- package/dist/node/claim.js +156 -0
- package/dist/node/claim.js.map +1 -0
- package/dist/node/index.cjs +1576 -0
- package/dist/node/index.d.ts +8 -0
- package/dist/node/index.js +9 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/offer.d.ts +87 -0
- package/dist/node/offer.js +169 -0
- package/dist/node/offer.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsconfig.web.tsbuildinfo +1 -0
- package/dist/web/BondingCurveAdmin.d.ts +690 -0
- package/dist/web/BondingCurveAdmin.js +504 -0
- package/dist/web/BondingCurveAdmin.js.map +1 -0
- package/dist/web/FungibleToken.d.ts +414 -0
- package/dist/web/FungibleToken.js +7 -0
- package/dist/web/FungibleToken.js.map +1 -0
- package/dist/web/FungibleTokenAdvancedAdmin.d.ts +124 -0
- package/dist/web/FungibleTokenAdvancedAdmin.js +226 -0
- package/dist/web/FungibleTokenAdvancedAdmin.js.map +1 -0
- package/dist/web/FungibleTokenContract.d.ts +526 -0
- package/dist/web/FungibleTokenContract.js +295 -0
- package/dist/web/FungibleTokenContract.js.map +1 -0
- package/dist/web/FungibleTokenStandardAdmin.d.ts +27 -0
- package/dist/web/FungibleTokenStandardAdmin.js +101 -0
- package/dist/web/FungibleTokenStandardAdmin.js.map +1 -0
- package/dist/web/bid.d.ts +86 -0
- package/dist/web/bid.js +168 -0
- package/dist/web/bid.js.map +1 -0
- package/dist/web/claim.d.ts +89 -0
- package/dist/web/claim.js +156 -0
- package/dist/web/claim.js.map +1 -0
- package/dist/web/index.d.ts +8 -0
- package/dist/web/index.js +9 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/offer.d.ts +87 -0
- package/dist/web/offer.js +169 -0
- package/dist/web/offer.js.map +1 -0
- package/package.json +64 -0
- package/src/BondingCurveAdmin.ts +590 -0
- package/src/FungibleToken.ts +11 -0
- package/src/FungibleTokenAdvancedAdmin.ts +260 -0
- package/src/FungibleTokenContract.ts +337 -0
- package/src/FungibleTokenStandardAdmin.ts +95 -0
- package/src/bid.ts +170 -0
- package/src/claim.ts +151 -0
- package/src/index.ts +8 -0
- package/src/offer.ts +164 -0
|
@@ -0,0 +1,1576 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// dist/node/index.js
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AdvancedAdminData: () => AdvancedAdminData,
|
|
24
|
+
AdvancedFungibleToken: () => AdvancedFungibleToken,
|
|
25
|
+
BalanceChangeEvent: () => BalanceChangeEvent,
|
|
26
|
+
BidEvent: () => BidEvent,
|
|
27
|
+
BondingCurveAdminInitializeProps: () => BondingCurveAdminInitializeProps,
|
|
28
|
+
BondingCurveFungibleToken: () => BondingCurveFungibleToken,
|
|
29
|
+
BondingCurveParams: () => BondingCurveParams,
|
|
30
|
+
BondingMintEvent: () => BondingMintEvent,
|
|
31
|
+
BondingRedeemEvent: () => BondingRedeemEvent,
|
|
32
|
+
BurnEvent: () => BurnEvent,
|
|
33
|
+
FungibleToken: () => FungibleToken,
|
|
34
|
+
FungibleTokenAdmin: () => FungibleTokenAdmin,
|
|
35
|
+
FungibleTokenAdvancedAdmin: () => FungibleTokenAdvancedAdmin,
|
|
36
|
+
FungibleTokenBidContract: () => FungibleTokenBidContract,
|
|
37
|
+
FungibleTokenBondingCurveAdmin: () => FungibleTokenBondingCurveAdmin,
|
|
38
|
+
FungibleTokenClaimContract: () => FungibleTokenClaimContract,
|
|
39
|
+
FungibleTokenContract: () => FungibleTokenContract,
|
|
40
|
+
FungibleTokenErrors: () => FungibleTokenErrors,
|
|
41
|
+
FungibleTokenOfferContract: () => FungibleTokenOfferContract,
|
|
42
|
+
MintEvent: () => MintEvent,
|
|
43
|
+
OfferEvent: () => OfferEvent,
|
|
44
|
+
PauseEvent: () => PauseEvent,
|
|
45
|
+
SetAdminEvent: () => SetAdminEvent
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(index_exports);
|
|
48
|
+
|
|
49
|
+
// dist/node/bid.js
|
|
50
|
+
var import_tslib4 = require("tslib");
|
|
51
|
+
var import_o1js4 = require("o1js");
|
|
52
|
+
var import_storage2 = require("@silvana-one/storage");
|
|
53
|
+
|
|
54
|
+
// dist/node/FungibleTokenContract.js
|
|
55
|
+
var import_tslib = require("tslib");
|
|
56
|
+
var import_o1js = require("o1js");
|
|
57
|
+
var FungibleTokenErrors = {
|
|
58
|
+
noAdminKey: "could not fetch admin contract key",
|
|
59
|
+
noPermissionToChangeAdmin: "Not allowed to change admin contract",
|
|
60
|
+
tokenPaused: "Token is currently paused",
|
|
61
|
+
noPermissionToMint: "Not allowed to mint tokens",
|
|
62
|
+
noPermissionToPause: "Not allowed to pause token",
|
|
63
|
+
noPermissionToResume: "Not allowed to resume token",
|
|
64
|
+
noTransferFromCirculation: "Can't transfer to/from the circulation account",
|
|
65
|
+
noPermissionChangeAllowed: "Can't change permissions for access or receive on token accounts",
|
|
66
|
+
flashMinting: "Flash-minting or unbalanced transaction detected. Please make sure that your transaction is balanced, and that your `AccountUpdate`s are ordered properly, so that tokens are not received before they are sent.",
|
|
67
|
+
unbalancedTransaction: "Transaction is unbalanced"
|
|
68
|
+
};
|
|
69
|
+
function FungibleTokenContract(adminContract) {
|
|
70
|
+
class FungibleToken2 extends import_o1js.TokenContract {
|
|
71
|
+
constructor() {
|
|
72
|
+
super(...arguments);
|
|
73
|
+
this.decimals = (0, import_o1js.State)();
|
|
74
|
+
this.admin = (0, import_o1js.State)();
|
|
75
|
+
this.paused = (0, import_o1js.State)();
|
|
76
|
+
this.events = {
|
|
77
|
+
SetAdmin: SetAdminEvent,
|
|
78
|
+
Pause: PauseEvent,
|
|
79
|
+
Mint: MintEvent,
|
|
80
|
+
Burn: BurnEvent,
|
|
81
|
+
BalanceChange: BalanceChangeEvent
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async deploy(props) {
|
|
85
|
+
await super.deploy(props);
|
|
86
|
+
this.paused.set((0, import_o1js.Bool)(true));
|
|
87
|
+
this.account.zkappUri.set(props.src);
|
|
88
|
+
this.account.tokenSymbol.set(props.symbol);
|
|
89
|
+
this.account.permissions.set({
|
|
90
|
+
...import_o1js.Permissions.default(),
|
|
91
|
+
setVerificationKey: props.allowUpdates ? import_o1js.Permissions.VerificationKey.proofDuringCurrentVersion() : import_o1js.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
92
|
+
setPermissions: import_o1js.Permissions.impossible(),
|
|
93
|
+
access: import_o1js.Permissions.proof()
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Update the verification key.
|
|
97
|
+
* This will only work when `allowUpdates` has been set to `true` during deployment.
|
|
98
|
+
*/
|
|
99
|
+
async updateVerificationKey(vk) {
|
|
100
|
+
const adminContract2 = await this.getAdminContract();
|
|
101
|
+
const canChangeVerificationKey = await adminContract2.canChangeVerificationKey(vk);
|
|
102
|
+
canChangeVerificationKey.assertTrue(FungibleTokenErrors.noPermissionToChangeAdmin);
|
|
103
|
+
this.account.verificationKey.set(vk);
|
|
104
|
+
}
|
|
105
|
+
/** Initializes the account for tracking total circulation.
|
|
106
|
+
* @argument {PublicKey} admin - public key where the admin contract is deployed
|
|
107
|
+
* @argument {UInt8} decimals - number of decimals for the token
|
|
108
|
+
* @argument {Bool} startPaused - if set to `Bool(true), the contract will start in a mode where token minting and transfers are paused. This should be used for non-atomic deployments
|
|
109
|
+
*/
|
|
110
|
+
async initialize(admin, decimals, startPaused) {
|
|
111
|
+
this.account.provedState.requireEquals((0, import_o1js.Bool)(false));
|
|
112
|
+
this.admin.set(admin);
|
|
113
|
+
this.decimals.set(decimals);
|
|
114
|
+
this.paused.set((0, import_o1js.Bool)(false));
|
|
115
|
+
this.paused.set(startPaused);
|
|
116
|
+
const accountUpdate = import_o1js.AccountUpdate.createSigned(this.address, this.deriveTokenId());
|
|
117
|
+
let permissions = import_o1js.Permissions.default();
|
|
118
|
+
permissions.send = import_o1js.Permissions.none();
|
|
119
|
+
permissions.setPermissions = import_o1js.Permissions.impossible();
|
|
120
|
+
accountUpdate.account.permissions.set(permissions);
|
|
121
|
+
}
|
|
122
|
+
async getAdminContract() {
|
|
123
|
+
const admin = await import_o1js.Provable.witnessAsync(import_o1js.PublicKey, async () => {
|
|
124
|
+
let pk = await this.admin.fetch();
|
|
125
|
+
(0, import_o1js.assert)(pk !== void 0, FungibleTokenErrors.noAdminKey);
|
|
126
|
+
return pk;
|
|
127
|
+
});
|
|
128
|
+
this.admin.requireEquals(admin);
|
|
129
|
+
return new adminContract(admin);
|
|
130
|
+
}
|
|
131
|
+
async setAdmin(admin) {
|
|
132
|
+
const adminContract2 = await this.getAdminContract();
|
|
133
|
+
const canChangeAdmin = await adminContract2.canChangeAdmin(admin);
|
|
134
|
+
canChangeAdmin.assertTrue(FungibleTokenErrors.noPermissionToChangeAdmin);
|
|
135
|
+
this.admin.set(admin);
|
|
136
|
+
this.emitEvent("SetAdmin", new SetAdminEvent({ adminKey: admin }));
|
|
137
|
+
}
|
|
138
|
+
async mint(recipient, amount) {
|
|
139
|
+
this.paused.getAndRequireEquals().assertFalse(FungibleTokenErrors.tokenPaused);
|
|
140
|
+
const accountUpdate = this.internal.mint({ address: recipient, amount });
|
|
141
|
+
const adminContract2 = await this.getAdminContract();
|
|
142
|
+
const canMint = await adminContract2.canMint(accountUpdate);
|
|
143
|
+
canMint.assertTrue(FungibleTokenErrors.noPermissionToMint);
|
|
144
|
+
recipient.equals(this.address).assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
|
145
|
+
this.approve(accountUpdate);
|
|
146
|
+
this.emitEvent("Mint", new MintEvent({ recipient, amount }));
|
|
147
|
+
const circulationUpdate = import_o1js.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
148
|
+
circulationUpdate.balanceChange = import_o1js.Int64.fromUnsigned(amount);
|
|
149
|
+
return accountUpdate;
|
|
150
|
+
}
|
|
151
|
+
async burn(from, amount) {
|
|
152
|
+
this.paused.getAndRequireEquals().assertFalse(FungibleTokenErrors.tokenPaused);
|
|
153
|
+
const accountUpdate = this.internal.burn({ address: from, amount });
|
|
154
|
+
const circulationUpdate = import_o1js.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
155
|
+
from.equals(this.address).assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
|
156
|
+
circulationUpdate.balanceChange = import_o1js.Int64.fromUnsigned(amount).neg();
|
|
157
|
+
this.emitEvent("Burn", new BurnEvent({ from, amount }));
|
|
158
|
+
return accountUpdate;
|
|
159
|
+
}
|
|
160
|
+
async pause() {
|
|
161
|
+
const adminContract2 = await this.getAdminContract();
|
|
162
|
+
const canPause = await adminContract2.canPause();
|
|
163
|
+
canPause.assertTrue(FungibleTokenErrors.noPermissionToPause);
|
|
164
|
+
this.paused.set((0, import_o1js.Bool)(true));
|
|
165
|
+
this.emitEvent("Pause", new PauseEvent({ isPaused: (0, import_o1js.Bool)(true) }));
|
|
166
|
+
}
|
|
167
|
+
async resume() {
|
|
168
|
+
const adminContract2 = await this.getAdminContract();
|
|
169
|
+
const canResume = await adminContract2.canResume();
|
|
170
|
+
canResume.assertTrue(FungibleTokenErrors.noPermissionToResume);
|
|
171
|
+
this.paused.set((0, import_o1js.Bool)(false));
|
|
172
|
+
this.emitEvent("Pause", new PauseEvent({ isPaused: (0, import_o1js.Bool)(false) }));
|
|
173
|
+
}
|
|
174
|
+
async transfer(from, to, amount) {
|
|
175
|
+
this.paused.getAndRequireEquals().assertFalse(FungibleTokenErrors.tokenPaused);
|
|
176
|
+
from.equals(this.address).assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
|
177
|
+
to.equals(this.address).assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
|
178
|
+
this.internal.send({ from, to, amount });
|
|
179
|
+
}
|
|
180
|
+
checkPermissionsUpdate(update) {
|
|
181
|
+
let permissions = update.update.permissions;
|
|
182
|
+
let { access, receive } = permissions.value;
|
|
183
|
+
let accessIsNone = import_o1js.Provable.equal(import_o1js.Types.AuthRequired, access, import_o1js.Permissions.none());
|
|
184
|
+
let receiveIsNone = import_o1js.Provable.equal(import_o1js.Types.AuthRequired, receive, import_o1js.Permissions.none());
|
|
185
|
+
let updateAllowed = accessIsNone.and(receiveIsNone);
|
|
186
|
+
(0, import_o1js.assert)(updateAllowed.or(permissions.isSome.not()), FungibleTokenErrors.noPermissionChangeAllowed);
|
|
187
|
+
}
|
|
188
|
+
/** Approve `AccountUpdate`s that have been created outside of the token contract.
|
|
189
|
+
*
|
|
190
|
+
* @argument {AccountUpdateForest} updates - The `AccountUpdate`s to approve. Note that the forest size is limited by the base token contract, @see TokenContract.MAX_ACCOUNT_UPDATES The current limit is 9.
|
|
191
|
+
*/
|
|
192
|
+
async approveBase(updates) {
|
|
193
|
+
this.paused.getAndRequireEquals().assertFalse(FungibleTokenErrors.tokenPaused);
|
|
194
|
+
let totalBalance = import_o1js.Int64.from(0);
|
|
195
|
+
this.forEachUpdate(updates, (update, usesToken) => {
|
|
196
|
+
this.checkPermissionsUpdate(update);
|
|
197
|
+
this.emitEventIf(usesToken, "BalanceChange", new BalanceChangeEvent({
|
|
198
|
+
address: update.publicKey,
|
|
199
|
+
amount: update.balanceChange
|
|
200
|
+
}));
|
|
201
|
+
update.publicKey.equals(this.address).and(usesToken).assertFalse(FungibleTokenErrors.noTransferFromCirculation);
|
|
202
|
+
totalBalance = import_o1js.Provable.if(usesToken, totalBalance.add(update.balanceChange), totalBalance);
|
|
203
|
+
totalBalance.isPositive().assertFalse(FungibleTokenErrors.flashMinting);
|
|
204
|
+
});
|
|
205
|
+
totalBalance.assertEquals(import_o1js.Int64.zero, FungibleTokenErrors.unbalancedTransaction);
|
|
206
|
+
}
|
|
207
|
+
async getBalanceOf(address) {
|
|
208
|
+
const account = import_o1js.AccountUpdate.create(address, this.deriveTokenId()).account;
|
|
209
|
+
const balance = account.balance.get();
|
|
210
|
+
account.balance.requireEquals(balance);
|
|
211
|
+
return balance;
|
|
212
|
+
}
|
|
213
|
+
/** Reports the current circulating supply
|
|
214
|
+
* This does take into account currently unreduced actions.
|
|
215
|
+
*/
|
|
216
|
+
async getCirculating() {
|
|
217
|
+
let circulating = await this.getBalanceOf(this.address);
|
|
218
|
+
return circulating;
|
|
219
|
+
}
|
|
220
|
+
async getDecimals() {
|
|
221
|
+
return this.decimals.getAndRequireEquals();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
(0, import_tslib.__decorate)([
|
|
225
|
+
(0, import_o1js.state)(import_o1js.UInt8),
|
|
226
|
+
(0, import_tslib.__metadata)("design:type", Object)
|
|
227
|
+
], FungibleToken2.prototype, "decimals", void 0);
|
|
228
|
+
(0, import_tslib.__decorate)([
|
|
229
|
+
(0, import_o1js.state)(import_o1js.PublicKey),
|
|
230
|
+
(0, import_tslib.__metadata)("design:type", Object)
|
|
231
|
+
], FungibleToken2.prototype, "admin", void 0);
|
|
232
|
+
(0, import_tslib.__decorate)([
|
|
233
|
+
(0, import_o1js.state)(import_o1js.Bool),
|
|
234
|
+
(0, import_tslib.__metadata)("design:type", Object)
|
|
235
|
+
], FungibleToken2.prototype, "paused", void 0);
|
|
236
|
+
(0, import_tslib.__decorate)([
|
|
237
|
+
import_o1js.method,
|
|
238
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
239
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.VerificationKey]),
|
|
240
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
241
|
+
], FungibleToken2.prototype, "updateVerificationKey", null);
|
|
242
|
+
(0, import_tslib.__decorate)([
|
|
243
|
+
import_o1js.method,
|
|
244
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
245
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.PublicKey, import_o1js.UInt8, import_o1js.Bool]),
|
|
246
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
247
|
+
], FungibleToken2.prototype, "initialize", null);
|
|
248
|
+
(0, import_tslib.__decorate)([
|
|
249
|
+
import_o1js.method,
|
|
250
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
251
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.PublicKey]),
|
|
252
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
253
|
+
], FungibleToken2.prototype, "setAdmin", null);
|
|
254
|
+
(0, import_tslib.__decorate)([
|
|
255
|
+
import_o1js.method.returns(import_o1js.AccountUpdate),
|
|
256
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
257
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.PublicKey, import_o1js.UInt64]),
|
|
258
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
259
|
+
], FungibleToken2.prototype, "mint", null);
|
|
260
|
+
(0, import_tslib.__decorate)([
|
|
261
|
+
import_o1js.method.returns(import_o1js.AccountUpdate),
|
|
262
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
263
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.PublicKey, import_o1js.UInt64]),
|
|
264
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
265
|
+
], FungibleToken2.prototype, "burn", null);
|
|
266
|
+
(0, import_tslib.__decorate)([
|
|
267
|
+
import_o1js.method,
|
|
268
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
269
|
+
(0, import_tslib.__metadata)("design:paramtypes", []),
|
|
270
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
271
|
+
], FungibleToken2.prototype, "pause", null);
|
|
272
|
+
(0, import_tslib.__decorate)([
|
|
273
|
+
import_o1js.method,
|
|
274
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
275
|
+
(0, import_tslib.__metadata)("design:paramtypes", []),
|
|
276
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
277
|
+
], FungibleToken2.prototype, "resume", null);
|
|
278
|
+
(0, import_tslib.__decorate)([
|
|
279
|
+
import_o1js.method,
|
|
280
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
281
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.PublicKey, import_o1js.PublicKey, import_o1js.UInt64]),
|
|
282
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
283
|
+
], FungibleToken2.prototype, "transfer", null);
|
|
284
|
+
(0, import_tslib.__decorate)([
|
|
285
|
+
import_o1js.method,
|
|
286
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
287
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.AccountUpdateForest]),
|
|
288
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
289
|
+
], FungibleToken2.prototype, "approveBase", null);
|
|
290
|
+
(0, import_tslib.__decorate)([
|
|
291
|
+
import_o1js.method.returns(import_o1js.UInt64),
|
|
292
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
293
|
+
(0, import_tslib.__metadata)("design:paramtypes", [import_o1js.PublicKey]),
|
|
294
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
295
|
+
], FungibleToken2.prototype, "getBalanceOf", null);
|
|
296
|
+
(0, import_tslib.__decorate)([
|
|
297
|
+
import_o1js.method.returns(import_o1js.UInt8),
|
|
298
|
+
(0, import_tslib.__metadata)("design:type", Function),
|
|
299
|
+
(0, import_tslib.__metadata)("design:paramtypes", []),
|
|
300
|
+
(0, import_tslib.__metadata)("design:returntype", Promise)
|
|
301
|
+
], FungibleToken2.prototype, "getDecimals", null);
|
|
302
|
+
return FungibleToken2;
|
|
303
|
+
}
|
|
304
|
+
var SetAdminEvent = class extends (0, import_o1js.Struct)({
|
|
305
|
+
adminKey: import_o1js.PublicKey
|
|
306
|
+
}) {
|
|
307
|
+
};
|
|
308
|
+
var PauseEvent = class extends (0, import_o1js.Struct)({
|
|
309
|
+
isPaused: import_o1js.Bool
|
|
310
|
+
}) {
|
|
311
|
+
};
|
|
312
|
+
var MintEvent = class extends (0, import_o1js.Struct)({
|
|
313
|
+
recipient: import_o1js.PublicKey,
|
|
314
|
+
amount: import_o1js.UInt64
|
|
315
|
+
}) {
|
|
316
|
+
};
|
|
317
|
+
var BurnEvent = class extends (0, import_o1js.Struct)({
|
|
318
|
+
from: import_o1js.PublicKey,
|
|
319
|
+
amount: import_o1js.UInt64
|
|
320
|
+
}) {
|
|
321
|
+
};
|
|
322
|
+
var BalanceChangeEvent = class extends (0, import_o1js.Struct)({
|
|
323
|
+
address: import_o1js.PublicKey,
|
|
324
|
+
amount: import_o1js.Int64
|
|
325
|
+
}) {
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// dist/node/FungibleTokenStandardAdmin.js
|
|
329
|
+
var import_tslib2 = require("tslib");
|
|
330
|
+
var import_o1js2 = require("o1js");
|
|
331
|
+
var FungibleTokenAdmin = class extends import_o1js2.SmartContract {
|
|
332
|
+
constructor() {
|
|
333
|
+
super(...arguments);
|
|
334
|
+
this.adminPublicKey = (0, import_o1js2.State)();
|
|
335
|
+
}
|
|
336
|
+
async deploy(props) {
|
|
337
|
+
await super.deploy(props);
|
|
338
|
+
this.adminPublicKey.set(props.adminPublicKey);
|
|
339
|
+
this.account.permissions.set({
|
|
340
|
+
...import_o1js2.Permissions.default(),
|
|
341
|
+
setVerificationKey: import_o1js2.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
342
|
+
setPermissions: import_o1js2.Permissions.impossible()
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
/** Update the verification key.
|
|
346
|
+
* 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.
|
|
347
|
+
*/
|
|
348
|
+
async updateVerificationKey(vk) {
|
|
349
|
+
this.account.verificationKey.set(vk);
|
|
350
|
+
}
|
|
351
|
+
async ensureAdminSignature() {
|
|
352
|
+
const admin = await import_o1js2.Provable.witnessAsync(import_o1js2.PublicKey, async () => {
|
|
353
|
+
let pk = await this.adminPublicKey.fetch();
|
|
354
|
+
(0, import_o1js2.assert)(pk !== void 0, "could not fetch admin public key");
|
|
355
|
+
return pk;
|
|
356
|
+
});
|
|
357
|
+
this.adminPublicKey.requireEquals(admin);
|
|
358
|
+
return import_o1js2.AccountUpdate.createSigned(admin);
|
|
359
|
+
}
|
|
360
|
+
async canMint(_accountUpdate) {
|
|
361
|
+
await this.ensureAdminSignature();
|
|
362
|
+
return (0, import_o1js2.Bool)(true);
|
|
363
|
+
}
|
|
364
|
+
async canChangeAdmin(_admin) {
|
|
365
|
+
await this.ensureAdminSignature();
|
|
366
|
+
return (0, import_o1js2.Bool)(true);
|
|
367
|
+
}
|
|
368
|
+
async canPause() {
|
|
369
|
+
await this.ensureAdminSignature();
|
|
370
|
+
return (0, import_o1js2.Bool)(true);
|
|
371
|
+
}
|
|
372
|
+
async canResume() {
|
|
373
|
+
await this.ensureAdminSignature();
|
|
374
|
+
return (0, import_o1js2.Bool)(true);
|
|
375
|
+
}
|
|
376
|
+
async canChangeVerificationKey(_vk) {
|
|
377
|
+
await this.ensureAdminSignature();
|
|
378
|
+
return (0, import_o1js2.Bool)(true);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
(0, import_tslib2.__decorate)([
|
|
382
|
+
(0, import_o1js2.state)(import_o1js2.PublicKey),
|
|
383
|
+
(0, import_tslib2.__metadata)("design:type", Object)
|
|
384
|
+
], FungibleTokenAdmin.prototype, "adminPublicKey", void 0);
|
|
385
|
+
(0, import_tslib2.__decorate)([
|
|
386
|
+
import_o1js2.method,
|
|
387
|
+
(0, import_tslib2.__metadata)("design:type", Function),
|
|
388
|
+
(0, import_tslib2.__metadata)("design:paramtypes", [import_o1js2.VerificationKey]),
|
|
389
|
+
(0, import_tslib2.__metadata)("design:returntype", Promise)
|
|
390
|
+
], FungibleTokenAdmin.prototype, "updateVerificationKey", null);
|
|
391
|
+
(0, import_tslib2.__decorate)([
|
|
392
|
+
import_o1js2.method.returns(import_o1js2.Bool),
|
|
393
|
+
(0, import_tslib2.__metadata)("design:type", Function),
|
|
394
|
+
(0, import_tslib2.__metadata)("design:paramtypes", [import_o1js2.AccountUpdate]),
|
|
395
|
+
(0, import_tslib2.__metadata)("design:returntype", Promise)
|
|
396
|
+
], FungibleTokenAdmin.prototype, "canMint", null);
|
|
397
|
+
(0, import_tslib2.__decorate)([
|
|
398
|
+
import_o1js2.method.returns(import_o1js2.Bool),
|
|
399
|
+
(0, import_tslib2.__metadata)("design:type", Function),
|
|
400
|
+
(0, import_tslib2.__metadata)("design:paramtypes", [import_o1js2.PublicKey]),
|
|
401
|
+
(0, import_tslib2.__metadata)("design:returntype", Promise)
|
|
402
|
+
], FungibleTokenAdmin.prototype, "canChangeAdmin", null);
|
|
403
|
+
(0, import_tslib2.__decorate)([
|
|
404
|
+
import_o1js2.method.returns(import_o1js2.Bool),
|
|
405
|
+
(0, import_tslib2.__metadata)("design:type", Function),
|
|
406
|
+
(0, import_tslib2.__metadata)("design:paramtypes", []),
|
|
407
|
+
(0, import_tslib2.__metadata)("design:returntype", Promise)
|
|
408
|
+
], FungibleTokenAdmin.prototype, "canPause", null);
|
|
409
|
+
(0, import_tslib2.__decorate)([
|
|
410
|
+
import_o1js2.method.returns(import_o1js2.Bool),
|
|
411
|
+
(0, import_tslib2.__metadata)("design:type", Function),
|
|
412
|
+
(0, import_tslib2.__metadata)("design:paramtypes", []),
|
|
413
|
+
(0, import_tslib2.__metadata)("design:returntype", Promise)
|
|
414
|
+
], FungibleTokenAdmin.prototype, "canResume", null);
|
|
415
|
+
(0, import_tslib2.__decorate)([
|
|
416
|
+
import_o1js2.method.returns(import_o1js2.Bool),
|
|
417
|
+
(0, import_tslib2.__metadata)("design:type", Function),
|
|
418
|
+
(0, import_tslib2.__metadata)("design:paramtypes", [import_o1js2.VerificationKey]),
|
|
419
|
+
(0, import_tslib2.__metadata)("design:returntype", Promise)
|
|
420
|
+
], FungibleTokenAdmin.prototype, "canChangeVerificationKey", null);
|
|
421
|
+
|
|
422
|
+
// dist/node/FungibleTokenAdvancedAdmin.js
|
|
423
|
+
var import_tslib3 = require("tslib");
|
|
424
|
+
var import_o1js3 = require("o1js");
|
|
425
|
+
var import_storage = require("@silvana-one/storage");
|
|
426
|
+
var AdvancedAdminData = class _AdvancedAdminData extends (0, import_o1js3.Struct)({
|
|
427
|
+
totalSupply: import_o1js3.UInt64,
|
|
428
|
+
requireAdminSignatureForMint: import_o1js3.Bool,
|
|
429
|
+
anyoneCanMint: import_o1js3.Bool
|
|
430
|
+
}) {
|
|
431
|
+
static new(params = {}) {
|
|
432
|
+
const { totalSupply, requireAdminSignatureForMint, anyoneCanMint } = params;
|
|
433
|
+
return new _AdvancedAdminData({
|
|
434
|
+
totalSupply: import_o1js3.UInt64.from(totalSupply ?? 0),
|
|
435
|
+
requireAdminSignatureForMint: (0, import_o1js3.Bool)(requireAdminSignatureForMint ?? false),
|
|
436
|
+
anyoneCanMint: (0, import_o1js3.Bool)(anyoneCanMint ?? false)
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
pack() {
|
|
440
|
+
const totalSupplyBits = this.totalSupply.value.toBits(64);
|
|
441
|
+
return import_o1js3.Field.fromBits([
|
|
442
|
+
...totalSupplyBits,
|
|
443
|
+
this.requireAdminSignatureForMint,
|
|
444
|
+
this.anyoneCanMint
|
|
445
|
+
]);
|
|
446
|
+
}
|
|
447
|
+
static unpack(packed) {
|
|
448
|
+
const bits = packed.toBits(64 + 1 + 1);
|
|
449
|
+
const totalSupply = import_o1js3.UInt64.Unsafe.fromField(import_o1js3.Field.fromBits(bits.slice(0, 64)));
|
|
450
|
+
const requireAdminSignatureForMint = bits[64];
|
|
451
|
+
const anyoneCanMint = bits[64 + 1];
|
|
452
|
+
return new _AdvancedAdminData({
|
|
453
|
+
totalSupply,
|
|
454
|
+
requireAdminSignatureForMint,
|
|
455
|
+
anyoneCanMint
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
var FungibleTokenAdvancedAdmin = class extends import_o1js3.TokenContract {
|
|
460
|
+
constructor() {
|
|
461
|
+
super(...arguments);
|
|
462
|
+
this.adminPublicKey = (0, import_o1js3.State)();
|
|
463
|
+
this.tokenContract = (0, import_o1js3.State)();
|
|
464
|
+
this.whitelist = (0, import_o1js3.State)();
|
|
465
|
+
this.adminData = (0, import_o1js3.State)();
|
|
466
|
+
this.events = { updateWhitelist: import_storage.Whitelist };
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Overrides the approveBase method to prevent transfers of tokens.
|
|
470
|
+
*
|
|
471
|
+
* @param forest - The account update forest.
|
|
472
|
+
*/
|
|
473
|
+
async approveBase(forest) {
|
|
474
|
+
throw Error("Transfer not allowed");
|
|
475
|
+
}
|
|
476
|
+
async deploy(props) {
|
|
477
|
+
await super.deploy(props);
|
|
478
|
+
this.adminPublicKey.set(props.adminPublicKey);
|
|
479
|
+
this.tokenContract.set(props.tokenContract);
|
|
480
|
+
this.adminData.set(new AdvancedAdminData({
|
|
481
|
+
totalSupply: props.totalSupply,
|
|
482
|
+
requireAdminSignatureForMint: props.requireAdminSignatureForMint,
|
|
483
|
+
anyoneCanMint: props.anyoneCanMint
|
|
484
|
+
}).pack());
|
|
485
|
+
this.whitelist.set(props.whitelist);
|
|
486
|
+
this.account.permissions.set({
|
|
487
|
+
...import_o1js3.Permissions.default(),
|
|
488
|
+
setVerificationKey: import_o1js3.Permissions.VerificationKey.proofDuringCurrentVersion(),
|
|
489
|
+
setPermissions: import_o1js3.Permissions.impossible()
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
/** Update the verification key.
|
|
493
|
+
* Note that because we have set the permissions for setting
|
|
494
|
+
* the verification key to `impossibleDuringCurrentVersion()`,
|
|
495
|
+
* this will only be possible in case of a protocol update that requires an update.
|
|
496
|
+
*/
|
|
497
|
+
async updateVerificationKey(vk) {
|
|
498
|
+
await this.ensureAdminSignature();
|
|
499
|
+
this.account.verificationKey.set(vk);
|
|
500
|
+
}
|
|
501
|
+
async ensureAdminSignature() {
|
|
502
|
+
const admin = this.adminPublicKey.getAndRequireEquals();
|
|
503
|
+
const adminUpdate = import_o1js3.AccountUpdate.createSigned(admin);
|
|
504
|
+
adminUpdate.body.useFullCommitment = (0, import_o1js3.Bool)(true);
|
|
505
|
+
return adminUpdate;
|
|
506
|
+
}
|
|
507
|
+
async canMint(_accountUpdate) {
|
|
508
|
+
const address = _accountUpdate.body.publicKey;
|
|
509
|
+
const balanceChange = _accountUpdate.body.balanceChange;
|
|
510
|
+
balanceChange.isPositive().assertTrue();
|
|
511
|
+
const amount = balanceChange.magnitude;
|
|
512
|
+
const adminData = AdvancedAdminData.unpack(this.adminData.getAndRequireEquals());
|
|
513
|
+
amount.assertLessThanOrEqual(adminData.totalSupply);
|
|
514
|
+
const tokenContract = this.tokenContract.getAndRequireEquals();
|
|
515
|
+
const tokenId = import_o1js3.TokenId.derive(tokenContract);
|
|
516
|
+
const adminTokenId = this.deriveTokenId();
|
|
517
|
+
_accountUpdate.body.tokenId.assertEquals(tokenId);
|
|
518
|
+
const maxAdditionalSupply = adminData.totalSupply.sub(amount);
|
|
519
|
+
const tokenUpdate = import_o1js3.AccountUpdate.createIf(adminData.totalSupply.equals(import_o1js3.UInt64.MAXINT()).not(), this.address, adminTokenId);
|
|
520
|
+
tokenUpdate.account.balance.requireBetween(import_o1js3.UInt64.zero, maxAdditionalSupply);
|
|
521
|
+
tokenUpdate.balance.addInPlace(amount);
|
|
522
|
+
this.self.approve(tokenUpdate);
|
|
523
|
+
const whitelist = this.whitelist.getAndRequireEquals();
|
|
524
|
+
const whitelistedAmount = await whitelist.getWhitelistedAmount(address);
|
|
525
|
+
whitelistedAmount.isSome.or(adminData.anyoneCanMint).assertTrue("Cannot mint to non-whitelisted address");
|
|
526
|
+
const maxMintAmount = import_o1js3.Provable.if(
|
|
527
|
+
adminData.anyoneCanMint,
|
|
528
|
+
import_o1js3.Provable.if(whitelistedAmount.isSome, whitelistedAmount.value, import_o1js3.UInt64.MAXINT()),
|
|
529
|
+
// blacklist
|
|
530
|
+
whitelistedAmount.value
|
|
531
|
+
);
|
|
532
|
+
amount.assertLessThanOrEqual(maxMintAmount);
|
|
533
|
+
const trackMintUpdate = import_o1js3.AccountUpdate.createIf(
|
|
534
|
+
whitelist.isSome(),
|
|
535
|
+
// we do not track minting if the whitelist is empty
|
|
536
|
+
address,
|
|
537
|
+
adminTokenId
|
|
538
|
+
);
|
|
539
|
+
trackMintUpdate.account.balance.requireBetween(import_o1js3.UInt64.zero, maxMintAmount.sub(amount));
|
|
540
|
+
trackMintUpdate.balance.addInPlace(amount);
|
|
541
|
+
this.self.approve(trackMintUpdate);
|
|
542
|
+
const adminSignatureUpdate = import_o1js3.AccountUpdate.createIf(adminData.requireAdminSignatureForMint, this.adminPublicKey.getAndRequireEquals());
|
|
543
|
+
adminSignatureUpdate.requireSignature();
|
|
544
|
+
adminSignatureUpdate.body.useFullCommitment = (0, import_o1js3.Bool)(true);
|
|
545
|
+
return (0, import_o1js3.Bool)(true);
|
|
546
|
+
}
|
|
547
|
+
async canChangeAdmin(_admin) {
|
|
548
|
+
await this.ensureAdminSignature();
|
|
549
|
+
return (0, import_o1js3.Bool)(true);
|
|
550
|
+
}
|
|
551
|
+
async canPause() {
|
|
552
|
+
await this.ensureAdminSignature();
|
|
553
|
+
return (0, import_o1js3.Bool)(true);
|
|
554
|
+
}
|
|
555
|
+
async canResume() {
|
|
556
|
+
await this.ensureAdminSignature();
|
|
557
|
+
return (0, import_o1js3.Bool)(true);
|
|
558
|
+
}
|
|
559
|
+
async updateWhitelist(whitelist) {
|
|
560
|
+
const admin = this.adminPublicKey.getAndRequireEquals();
|
|
561
|
+
const sender = this.sender.getUnconstrained();
|
|
562
|
+
const senderUpdate = import_o1js3.AccountUpdate.createSigned(sender);
|
|
563
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js3.Bool)(true);
|
|
564
|
+
admin.assertEquals(sender);
|
|
565
|
+
this.whitelist.set(whitelist);
|
|
566
|
+
this.emitEvent("updateWhitelist", whitelist);
|
|
567
|
+
}
|
|
568
|
+
async canChangeVerificationKey(_vk) {
|
|
569
|
+
await this.ensureAdminSignature();
|
|
570
|
+
return (0, import_o1js3.Bool)(true);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
(0, import_tslib3.__decorate)([
|
|
574
|
+
(0, import_o1js3.state)(import_o1js3.PublicKey),
|
|
575
|
+
(0, import_tslib3.__metadata)("design:type", Object)
|
|
576
|
+
], FungibleTokenAdvancedAdmin.prototype, "adminPublicKey", void 0);
|
|
577
|
+
(0, import_tslib3.__decorate)([
|
|
578
|
+
(0, import_o1js3.state)(import_o1js3.PublicKey),
|
|
579
|
+
(0, import_tslib3.__metadata)("design:type", Object)
|
|
580
|
+
], FungibleTokenAdvancedAdmin.prototype, "tokenContract", void 0);
|
|
581
|
+
(0, import_tslib3.__decorate)([
|
|
582
|
+
(0, import_o1js3.state)(import_storage.Whitelist),
|
|
583
|
+
(0, import_tslib3.__metadata)("design:type", Object)
|
|
584
|
+
], FungibleTokenAdvancedAdmin.prototype, "whitelist", void 0);
|
|
585
|
+
(0, import_tslib3.__decorate)([
|
|
586
|
+
(0, import_o1js3.state)(import_o1js3.Field),
|
|
587
|
+
(0, import_tslib3.__metadata)("design:type", Object)
|
|
588
|
+
], FungibleTokenAdvancedAdmin.prototype, "adminData", void 0);
|
|
589
|
+
(0, import_tslib3.__decorate)([
|
|
590
|
+
import_o1js3.method,
|
|
591
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
592
|
+
(0, import_tslib3.__metadata)("design:paramtypes", [import_o1js3.VerificationKey]),
|
|
593
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
594
|
+
], FungibleTokenAdvancedAdmin.prototype, "updateVerificationKey", null);
|
|
595
|
+
(0, import_tslib3.__decorate)([
|
|
596
|
+
import_o1js3.method.returns(import_o1js3.Bool),
|
|
597
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
598
|
+
(0, import_tslib3.__metadata)("design:paramtypes", [import_o1js3.AccountUpdate]),
|
|
599
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
600
|
+
], FungibleTokenAdvancedAdmin.prototype, "canMint", null);
|
|
601
|
+
(0, import_tslib3.__decorate)([
|
|
602
|
+
import_o1js3.method.returns(import_o1js3.Bool),
|
|
603
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
604
|
+
(0, import_tslib3.__metadata)("design:paramtypes", [import_o1js3.PublicKey]),
|
|
605
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
606
|
+
], FungibleTokenAdvancedAdmin.prototype, "canChangeAdmin", null);
|
|
607
|
+
(0, import_tslib3.__decorate)([
|
|
608
|
+
import_o1js3.method.returns(import_o1js3.Bool),
|
|
609
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
610
|
+
(0, import_tslib3.__metadata)("design:paramtypes", []),
|
|
611
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
612
|
+
], FungibleTokenAdvancedAdmin.prototype, "canPause", null);
|
|
613
|
+
(0, import_tslib3.__decorate)([
|
|
614
|
+
import_o1js3.method.returns(import_o1js3.Bool),
|
|
615
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
616
|
+
(0, import_tslib3.__metadata)("design:paramtypes", []),
|
|
617
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
618
|
+
], FungibleTokenAdvancedAdmin.prototype, "canResume", null);
|
|
619
|
+
(0, import_tslib3.__decorate)([
|
|
620
|
+
import_o1js3.method,
|
|
621
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
622
|
+
(0, import_tslib3.__metadata)("design:paramtypes", [import_storage.Whitelist]),
|
|
623
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
624
|
+
], FungibleTokenAdvancedAdmin.prototype, "updateWhitelist", null);
|
|
625
|
+
(0, import_tslib3.__decorate)([
|
|
626
|
+
import_o1js3.method.returns(import_o1js3.Bool),
|
|
627
|
+
(0, import_tslib3.__metadata)("design:type", Function),
|
|
628
|
+
(0, import_tslib3.__metadata)("design:paramtypes", [import_o1js3.VerificationKey]),
|
|
629
|
+
(0, import_tslib3.__metadata)("design:returntype", Promise)
|
|
630
|
+
], FungibleTokenAdvancedAdmin.prototype, "canChangeVerificationKey", null);
|
|
631
|
+
|
|
632
|
+
// dist/node/FungibleToken.js
|
|
633
|
+
var FungibleToken = FungibleTokenContract(FungibleTokenAdmin);
|
|
634
|
+
var AdvancedFungibleToken = FungibleTokenContract(FungibleTokenAdvancedAdmin);
|
|
635
|
+
|
|
636
|
+
// dist/node/bid.js
|
|
637
|
+
var BidEvent = class extends (0, import_o1js4.Struct)({
|
|
638
|
+
amount: import_o1js4.UInt64,
|
|
639
|
+
address: import_o1js4.PublicKey
|
|
640
|
+
}) {
|
|
641
|
+
};
|
|
642
|
+
var FungibleTokenBidContract = class extends import_o1js4.SmartContract {
|
|
643
|
+
constructor() {
|
|
644
|
+
super(...arguments);
|
|
645
|
+
this.price = (0, import_o1js4.State)();
|
|
646
|
+
this.buyer = (0, import_o1js4.State)();
|
|
647
|
+
this.token = (0, import_o1js4.State)();
|
|
648
|
+
this.whitelist = (0, import_o1js4.State)();
|
|
649
|
+
this.events = {
|
|
650
|
+
bid: BidEvent,
|
|
651
|
+
withdraw: BidEvent,
|
|
652
|
+
sell: BidEvent,
|
|
653
|
+
updateWhitelist: import_storage2.Whitelist
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
async deploy(args) {
|
|
657
|
+
await super.deploy(args);
|
|
658
|
+
this.whitelist.set(args.whitelist);
|
|
659
|
+
this.account.permissions.set({
|
|
660
|
+
...import_o1js4.Permissions.default(),
|
|
661
|
+
send: import_o1js4.Permissions.proof(),
|
|
662
|
+
setVerificationKey: import_o1js4.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
663
|
+
setPermissions: import_o1js4.Permissions.impossible()
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
async initialize(token, amount, price) {
|
|
667
|
+
this.account.provedState.requireEquals((0, import_o1js4.Bool)(false));
|
|
668
|
+
amount.equals(import_o1js4.UInt64.from(0)).assertFalse();
|
|
669
|
+
const totalPriceField = price.value.mul(amount.value).div((0, import_o1js4.Field)(1e9));
|
|
670
|
+
totalPriceField.assertLessThan(import_o1js4.UInt64.MAXINT().value, "totalPrice overflow");
|
|
671
|
+
const totalPrice = import_o1js4.UInt64.Unsafe.fromField(totalPriceField);
|
|
672
|
+
const buyer = this.sender.getUnconstrained();
|
|
673
|
+
const buyerUpdate = import_o1js4.AccountUpdate.createSigned(buyer);
|
|
674
|
+
buyerUpdate.send({ to: this.address, amount: totalPrice });
|
|
675
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js4.Bool)(true);
|
|
676
|
+
this.buyer.set(buyer);
|
|
677
|
+
this.price.set(price);
|
|
678
|
+
this.token.set(token);
|
|
679
|
+
this.emitEvent("bid", { amount, address: buyer });
|
|
680
|
+
}
|
|
681
|
+
async bid(amount, price) {
|
|
682
|
+
amount.equals(import_o1js4.UInt64.from(0)).assertFalse();
|
|
683
|
+
const balance = this.account.balance.getAndRequireEquals();
|
|
684
|
+
const oldPrice = this.price.getAndRequireEquals();
|
|
685
|
+
price.equals(oldPrice).or(balance.equals(import_o1js4.UInt64.from(0))).assertTrue();
|
|
686
|
+
this.price.set(price);
|
|
687
|
+
const totalPriceField = price.value.mul(amount.value).div((0, import_o1js4.Field)(1e9));
|
|
688
|
+
totalPriceField.assertLessThan(import_o1js4.UInt64.MAXINT().value, "totalPrice overflow");
|
|
689
|
+
const totalPrice = import_o1js4.UInt64.Unsafe.fromField(totalPriceField);
|
|
690
|
+
const sender = this.sender.getUnconstrained();
|
|
691
|
+
const buyer = this.buyer.getAndRequireEquals();
|
|
692
|
+
sender.assertEquals(buyer);
|
|
693
|
+
const buyerUpdate = import_o1js4.AccountUpdate.createSigned(buyer);
|
|
694
|
+
buyerUpdate.send({ to: this.address, amount: totalPrice });
|
|
695
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js4.Bool)(true);
|
|
696
|
+
this.price.set(price);
|
|
697
|
+
this.emitEvent("bid", { amount, address: buyer });
|
|
698
|
+
}
|
|
699
|
+
async withdraw(amountInMina) {
|
|
700
|
+
amountInMina.equals(import_o1js4.UInt64.from(0)).assertFalse();
|
|
701
|
+
this.account.balance.requireBetween(amountInMina, import_o1js4.UInt64.MAXINT());
|
|
702
|
+
const buyer = this.buyer.getAndRequireEquals();
|
|
703
|
+
const sender = this.sender.getUnconstrained();
|
|
704
|
+
const senderUpdate = import_o1js4.AccountUpdate.createSigned(sender);
|
|
705
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js4.Bool)(true);
|
|
706
|
+
sender.assertEquals(buyer);
|
|
707
|
+
let bidUpdate = this.send({ to: senderUpdate, amount: amountInMina });
|
|
708
|
+
bidUpdate.body.useFullCommitment = (0, import_o1js4.Bool)(true);
|
|
709
|
+
this.emitEvent("withdraw", {
|
|
710
|
+
amount: amountInMina,
|
|
711
|
+
address: buyer
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
async sell(amount) {
|
|
715
|
+
amount.equals(import_o1js4.UInt64.from(0)).assertFalse();
|
|
716
|
+
const price = this.price.getAndRequireEquals();
|
|
717
|
+
const totalPriceField = price.value.mul(amount.value).div((0, import_o1js4.Field)(1e9));
|
|
718
|
+
totalPriceField.assertLessThan(import_o1js4.UInt64.MAXINT().value, "totalPrice overflow");
|
|
719
|
+
const totalPrice = import_o1js4.UInt64.Unsafe.fromField(totalPriceField);
|
|
720
|
+
this.account.balance.requireBetween(totalPrice, import_o1js4.UInt64.MAXINT());
|
|
721
|
+
const buyer = this.buyer.getAndRequireEquals();
|
|
722
|
+
const token = this.token.getAndRequireEquals();
|
|
723
|
+
const seller = this.sender.getUnconstrained();
|
|
724
|
+
const sellerUpdate = this.send({ to: seller, amount: totalPrice });
|
|
725
|
+
sellerUpdate.body.useFullCommitment = (0, import_o1js4.Bool)(true);
|
|
726
|
+
sellerUpdate.requireSignature();
|
|
727
|
+
const tokenContract = new FungibleToken(token);
|
|
728
|
+
await tokenContract.transfer(seller, buyer, amount);
|
|
729
|
+
const whitelist = this.whitelist.getAndRequireEquals();
|
|
730
|
+
const whitelistedAmount = await whitelist.getWhitelistedAmount(seller);
|
|
731
|
+
amount.assertLessThanOrEqual(whitelistedAmount.assertSome("Cannot sell more than whitelisted amount"));
|
|
732
|
+
this.emitEvent("sell", { amount, address: seller });
|
|
733
|
+
}
|
|
734
|
+
async updateWhitelist(whitelist) {
|
|
735
|
+
const buyer = this.buyer.getAndRequireEquals();
|
|
736
|
+
const sender = this.sender.getUnconstrained();
|
|
737
|
+
const senderUpdate = import_o1js4.AccountUpdate.createSigned(sender);
|
|
738
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js4.Bool)(true);
|
|
739
|
+
sender.assertEquals(buyer);
|
|
740
|
+
this.whitelist.set(whitelist);
|
|
741
|
+
this.emitEvent("updateWhitelist", whitelist);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
(0, import_tslib4.__decorate)([
|
|
745
|
+
(0, import_o1js4.state)(import_o1js4.UInt64),
|
|
746
|
+
(0, import_tslib4.__metadata)("design:type", Object)
|
|
747
|
+
], FungibleTokenBidContract.prototype, "price", void 0);
|
|
748
|
+
(0, import_tslib4.__decorate)([
|
|
749
|
+
(0, import_o1js4.state)(import_o1js4.PublicKey),
|
|
750
|
+
(0, import_tslib4.__metadata)("design:type", Object)
|
|
751
|
+
], FungibleTokenBidContract.prototype, "buyer", void 0);
|
|
752
|
+
(0, import_tslib4.__decorate)([
|
|
753
|
+
(0, import_o1js4.state)(import_o1js4.PublicKey),
|
|
754
|
+
(0, import_tslib4.__metadata)("design:type", Object)
|
|
755
|
+
], FungibleTokenBidContract.prototype, "token", void 0);
|
|
756
|
+
(0, import_tslib4.__decorate)([
|
|
757
|
+
(0, import_o1js4.state)(import_storage2.Whitelist),
|
|
758
|
+
(0, import_tslib4.__metadata)("design:type", Object)
|
|
759
|
+
], FungibleTokenBidContract.prototype, "whitelist", void 0);
|
|
760
|
+
(0, import_tslib4.__decorate)([
|
|
761
|
+
import_o1js4.method,
|
|
762
|
+
(0, import_tslib4.__metadata)("design:type", Function),
|
|
763
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js4.PublicKey, import_o1js4.UInt64, import_o1js4.UInt64]),
|
|
764
|
+
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
765
|
+
], FungibleTokenBidContract.prototype, "initialize", null);
|
|
766
|
+
(0, import_tslib4.__decorate)([
|
|
767
|
+
import_o1js4.method,
|
|
768
|
+
(0, import_tslib4.__metadata)("design:type", Function),
|
|
769
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js4.UInt64, import_o1js4.UInt64]),
|
|
770
|
+
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
771
|
+
], FungibleTokenBidContract.prototype, "bid", null);
|
|
772
|
+
(0, import_tslib4.__decorate)([
|
|
773
|
+
import_o1js4.method,
|
|
774
|
+
(0, import_tslib4.__metadata)("design:type", Function),
|
|
775
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js4.UInt64]),
|
|
776
|
+
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
777
|
+
], FungibleTokenBidContract.prototype, "withdraw", null);
|
|
778
|
+
(0, import_tslib4.__decorate)([
|
|
779
|
+
import_o1js4.method,
|
|
780
|
+
(0, import_tslib4.__metadata)("design:type", Function),
|
|
781
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_o1js4.UInt64]),
|
|
782
|
+
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
783
|
+
], FungibleTokenBidContract.prototype, "sell", null);
|
|
784
|
+
(0, import_tslib4.__decorate)([
|
|
785
|
+
import_o1js4.method,
|
|
786
|
+
(0, import_tslib4.__metadata)("design:type", Function),
|
|
787
|
+
(0, import_tslib4.__metadata)("design:paramtypes", [import_storage2.Whitelist]),
|
|
788
|
+
(0, import_tslib4.__metadata)("design:returntype", Promise)
|
|
789
|
+
], FungibleTokenBidContract.prototype, "updateWhitelist", null);
|
|
790
|
+
|
|
791
|
+
// dist/node/claim.js
|
|
792
|
+
var import_tslib5 = require("tslib");
|
|
793
|
+
var import_o1js5 = require("o1js");
|
|
794
|
+
var import_storage3 = require("@silvana-one/storage");
|
|
795
|
+
var ClaimEvent = class extends (0, import_o1js5.Struct)({
|
|
796
|
+
amount: import_o1js5.UInt64,
|
|
797
|
+
address: import_o1js5.PublicKey
|
|
798
|
+
}) {
|
|
799
|
+
};
|
|
800
|
+
var FungibleTokenClaimContract = class extends import_o1js5.SmartContract {
|
|
801
|
+
constructor() {
|
|
802
|
+
super(...arguments);
|
|
803
|
+
this.owner = (0, import_o1js5.State)();
|
|
804
|
+
this.token = (0, import_o1js5.State)();
|
|
805
|
+
this.whitelist = (0, import_o1js5.State)();
|
|
806
|
+
this.maxAmount = (0, import_o1js5.State)();
|
|
807
|
+
this.events = {
|
|
808
|
+
offer: ClaimEvent,
|
|
809
|
+
withdraw: ClaimEvent,
|
|
810
|
+
claim: ClaimEvent,
|
|
811
|
+
updateWhitelist: import_storage3.Whitelist
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
async deploy(args) {
|
|
815
|
+
await super.deploy(args);
|
|
816
|
+
this.whitelist.set(args.whitelist);
|
|
817
|
+
this.maxAmount.set(args.maxAmount ?? import_o1js5.UInt64.MAXINT());
|
|
818
|
+
this.account.permissions.set({
|
|
819
|
+
...import_o1js5.Permissions.default(),
|
|
820
|
+
send: import_o1js5.Permissions.proof(),
|
|
821
|
+
setVerificationKey: import_o1js5.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
822
|
+
setPermissions: import_o1js5.Permissions.impossible()
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
async initialize(owner, token, amount) {
|
|
826
|
+
this.account.provedState.requireEquals((0, import_o1js5.Bool)(false));
|
|
827
|
+
const tokenContract = new FungibleToken(token);
|
|
828
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
829
|
+
tokenId.assertEquals(this.tokenId);
|
|
830
|
+
await tokenContract.transfer(owner, this.address, amount);
|
|
831
|
+
this.owner.set(owner);
|
|
832
|
+
this.token.set(token);
|
|
833
|
+
this.emitEvent("offer", { amount, address: owner });
|
|
834
|
+
}
|
|
835
|
+
async offer(amount) {
|
|
836
|
+
const owner = this.owner.getAndRequireEquals();
|
|
837
|
+
const token = this.token.getAndRequireEquals();
|
|
838
|
+
const tokenContract = new FungibleToken(token);
|
|
839
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
840
|
+
tokenId.assertEquals(this.tokenId);
|
|
841
|
+
const sender = this.sender.getUnconstrained();
|
|
842
|
+
const senderUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
843
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
844
|
+
sender.assertEquals(owner);
|
|
845
|
+
await tokenContract.transfer(sender, this.address, amount);
|
|
846
|
+
this.emitEvent("offer", { amount, address: sender });
|
|
847
|
+
}
|
|
848
|
+
async withdraw(amount) {
|
|
849
|
+
amount.equals(import_o1js5.UInt64.from(0)).assertFalse();
|
|
850
|
+
this.account.balance.requireBetween(amount, import_o1js5.UInt64.MAXINT());
|
|
851
|
+
const owner = this.owner.getAndRequireEquals();
|
|
852
|
+
const token = this.token.getAndRequireEquals();
|
|
853
|
+
const tokenContract = new FungibleToken(token);
|
|
854
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
855
|
+
tokenId.assertEquals(this.tokenId);
|
|
856
|
+
const sender = this.sender.getUnconstrained();
|
|
857
|
+
const senderUpdate = import_o1js5.AccountUpdate.createSigned(sender, tokenId);
|
|
858
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
859
|
+
sender.assertEquals(owner);
|
|
860
|
+
let offerUpdate = this.send({ to: senderUpdate, amount });
|
|
861
|
+
offerUpdate.body.mayUseToken = import_o1js5.AccountUpdate.MayUseToken.InheritFromParent;
|
|
862
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
863
|
+
this.emitEvent("withdraw", { amount, address: sender });
|
|
864
|
+
}
|
|
865
|
+
async claim(amount) {
|
|
866
|
+
const maxAmount = this.maxAmount.getAndRequireEquals();
|
|
867
|
+
const token = this.token.getAndRequireEquals();
|
|
868
|
+
const tokenContract = new FungibleToken(token);
|
|
869
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
870
|
+
tokenId.assertEquals(this.tokenId);
|
|
871
|
+
const sender = this.sender.getUnconstrained();
|
|
872
|
+
const senderUpdate = import_o1js5.AccountUpdate.createSigned(sender, tokenId);
|
|
873
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
874
|
+
const whitelist = this.whitelist.getAndRequireEquals();
|
|
875
|
+
const whiteListedAmount = await whitelist.getWhitelistedAmount(sender);
|
|
876
|
+
const maxClaimAmount = import_o1js5.Provable.if(whitelist.isSome(), whiteListedAmount.assertSome("No tokens to claim"), maxAmount);
|
|
877
|
+
amount.assertLessThanOrEqual(maxClaimAmount);
|
|
878
|
+
this.account.balance.requireBetween(amount, import_o1js5.UInt64.MAXINT());
|
|
879
|
+
let offerUpdate = this.send({ to: senderUpdate, amount });
|
|
880
|
+
offerUpdate.body.mayUseToken = import_o1js5.AccountUpdate.MayUseToken.InheritFromParent;
|
|
881
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
882
|
+
this.emitEvent("claim", {
|
|
883
|
+
amount,
|
|
884
|
+
address: sender
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
async updateWhitelist(whitelist) {
|
|
888
|
+
const owner = this.owner.getAndRequireEquals();
|
|
889
|
+
const sender = this.sender.getUnconstrained();
|
|
890
|
+
const senderUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
891
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js5.Bool)(true);
|
|
892
|
+
sender.assertEquals(owner);
|
|
893
|
+
this.whitelist.set(whitelist);
|
|
894
|
+
this.emitEvent("updateWhitelist", whitelist);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
(0, import_tslib5.__decorate)([
|
|
898
|
+
(0, import_o1js5.state)(import_o1js5.PublicKey),
|
|
899
|
+
(0, import_tslib5.__metadata)("design:type", Object)
|
|
900
|
+
], FungibleTokenClaimContract.prototype, "owner", void 0);
|
|
901
|
+
(0, import_tslib5.__decorate)([
|
|
902
|
+
(0, import_o1js5.state)(import_o1js5.PublicKey),
|
|
903
|
+
(0, import_tslib5.__metadata)("design:type", Object)
|
|
904
|
+
], FungibleTokenClaimContract.prototype, "token", void 0);
|
|
905
|
+
(0, import_tslib5.__decorate)([
|
|
906
|
+
(0, import_o1js5.state)(import_storage3.Whitelist),
|
|
907
|
+
(0, import_tslib5.__metadata)("design:type", Object)
|
|
908
|
+
], FungibleTokenClaimContract.prototype, "whitelist", void 0);
|
|
909
|
+
(0, import_tslib5.__decorate)([
|
|
910
|
+
(0, import_o1js5.state)(import_o1js5.UInt64),
|
|
911
|
+
(0, import_tslib5.__metadata)("design:type", Object)
|
|
912
|
+
], FungibleTokenClaimContract.prototype, "maxAmount", void 0);
|
|
913
|
+
(0, import_tslib5.__decorate)([
|
|
914
|
+
import_o1js5.method,
|
|
915
|
+
(0, import_tslib5.__metadata)("design:type", Function),
|
|
916
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [
|
|
917
|
+
import_o1js5.PublicKey,
|
|
918
|
+
import_o1js5.PublicKey,
|
|
919
|
+
import_o1js5.UInt64
|
|
920
|
+
]),
|
|
921
|
+
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
922
|
+
], FungibleTokenClaimContract.prototype, "initialize", null);
|
|
923
|
+
(0, import_tslib5.__decorate)([
|
|
924
|
+
import_o1js5.method,
|
|
925
|
+
(0, import_tslib5.__metadata)("design:type", Function),
|
|
926
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_o1js5.UInt64]),
|
|
927
|
+
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
928
|
+
], FungibleTokenClaimContract.prototype, "offer", null);
|
|
929
|
+
(0, import_tslib5.__decorate)([
|
|
930
|
+
import_o1js5.method,
|
|
931
|
+
(0, import_tslib5.__metadata)("design:type", Function),
|
|
932
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_o1js5.UInt64]),
|
|
933
|
+
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
934
|
+
], FungibleTokenClaimContract.prototype, "withdraw", null);
|
|
935
|
+
(0, import_tslib5.__decorate)([
|
|
936
|
+
import_o1js5.method,
|
|
937
|
+
(0, import_tslib5.__metadata)("design:type", Function),
|
|
938
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_o1js5.UInt64]),
|
|
939
|
+
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
940
|
+
], FungibleTokenClaimContract.prototype, "claim", null);
|
|
941
|
+
(0, import_tslib5.__decorate)([
|
|
942
|
+
import_o1js5.method,
|
|
943
|
+
(0, import_tslib5.__metadata)("design:type", Function),
|
|
944
|
+
(0, import_tslib5.__metadata)("design:paramtypes", [import_storage3.Whitelist]),
|
|
945
|
+
(0, import_tslib5.__metadata)("design:returntype", Promise)
|
|
946
|
+
], FungibleTokenClaimContract.prototype, "updateWhitelist", null);
|
|
947
|
+
|
|
948
|
+
// dist/node/offer.js
|
|
949
|
+
var import_tslib6 = require("tslib");
|
|
950
|
+
var import_o1js6 = require("o1js");
|
|
951
|
+
var import_storage4 = require("@silvana-one/storage");
|
|
952
|
+
var OfferEvent = class extends (0, import_o1js6.Struct)({
|
|
953
|
+
amount: import_o1js6.UInt64,
|
|
954
|
+
address: import_o1js6.PublicKey
|
|
955
|
+
}) {
|
|
956
|
+
};
|
|
957
|
+
var FungibleTokenOfferContract = class extends import_o1js6.SmartContract {
|
|
958
|
+
constructor() {
|
|
959
|
+
super(...arguments);
|
|
960
|
+
this.price = (0, import_o1js6.State)();
|
|
961
|
+
this.seller = (0, import_o1js6.State)();
|
|
962
|
+
this.token = (0, import_o1js6.State)();
|
|
963
|
+
this.whitelist = (0, import_o1js6.State)();
|
|
964
|
+
this.events = {
|
|
965
|
+
offer: OfferEvent,
|
|
966
|
+
withdraw: OfferEvent,
|
|
967
|
+
buy: OfferEvent,
|
|
968
|
+
updateWhitelist: import_storage4.Whitelist
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
async deploy(args) {
|
|
972
|
+
await super.deploy(args);
|
|
973
|
+
this.whitelist.set(args.whitelist);
|
|
974
|
+
this.account.permissions.set({
|
|
975
|
+
...import_o1js6.Permissions.default(),
|
|
976
|
+
send: import_o1js6.Permissions.proof(),
|
|
977
|
+
setVerificationKey: import_o1js6.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
978
|
+
setPermissions: import_o1js6.Permissions.impossible()
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
async initialize(seller, token, amount, price) {
|
|
982
|
+
this.account.provedState.requireEquals((0, import_o1js6.Bool)(false));
|
|
983
|
+
const tokenContract = new FungibleToken(token);
|
|
984
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
985
|
+
tokenId.assertEquals(this.tokenId);
|
|
986
|
+
await tokenContract.transfer(seller, this.address, amount);
|
|
987
|
+
this.seller.set(seller);
|
|
988
|
+
this.price.set(price);
|
|
989
|
+
this.token.set(token);
|
|
990
|
+
this.emitEvent("offer", { amount, address: seller });
|
|
991
|
+
}
|
|
992
|
+
async offer(amount, price) {
|
|
993
|
+
const seller = this.seller.getAndRequireEquals();
|
|
994
|
+
const token = this.token.getAndRequireEquals();
|
|
995
|
+
const tokenContract = new FungibleToken(token);
|
|
996
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
997
|
+
tokenId.assertEquals(this.tokenId);
|
|
998
|
+
const balance = this.account.balance.getAndRequireEquals();
|
|
999
|
+
const oldPrice = this.price.getAndRequireEquals();
|
|
1000
|
+
price.equals(oldPrice).or(balance.equals(import_o1js6.UInt64.from(0))).assertTrue();
|
|
1001
|
+
this.price.set(price);
|
|
1002
|
+
const sender = this.sender.getUnconstrained();
|
|
1003
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender);
|
|
1004
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
1005
|
+
sender.assertEquals(seller);
|
|
1006
|
+
await tokenContract.transfer(sender, this.address, amount);
|
|
1007
|
+
this.emitEvent("offer", { amount, address: sender });
|
|
1008
|
+
}
|
|
1009
|
+
async withdraw(amount) {
|
|
1010
|
+
amount.equals(import_o1js6.UInt64.from(0)).assertFalse();
|
|
1011
|
+
this.account.balance.requireBetween(amount, import_o1js6.UInt64.MAXINT());
|
|
1012
|
+
const seller = this.seller.getAndRequireEquals();
|
|
1013
|
+
const token = this.token.getAndRequireEquals();
|
|
1014
|
+
const tokenContract = new FungibleToken(token);
|
|
1015
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
1016
|
+
tokenId.assertEquals(this.tokenId);
|
|
1017
|
+
const sender = this.sender.getUnconstrained();
|
|
1018
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender, tokenId);
|
|
1019
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
1020
|
+
sender.assertEquals(seller);
|
|
1021
|
+
let offerUpdate = this.send({ to: senderUpdate, amount });
|
|
1022
|
+
offerUpdate.body.mayUseToken = import_o1js6.AccountUpdate.MayUseToken.InheritFromParent;
|
|
1023
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
1024
|
+
this.emitEvent("withdraw", { amount, address: sender });
|
|
1025
|
+
}
|
|
1026
|
+
async buy(amount) {
|
|
1027
|
+
amount.equals(import_o1js6.UInt64.from(0)).assertFalse();
|
|
1028
|
+
this.account.balance.requireBetween(amount, import_o1js6.UInt64.MAXINT());
|
|
1029
|
+
const seller = this.seller.getAndRequireEquals();
|
|
1030
|
+
const token = this.token.getAndRequireEquals();
|
|
1031
|
+
const tokenContract = new FungibleToken(token);
|
|
1032
|
+
const tokenId = tokenContract.deriveTokenId();
|
|
1033
|
+
tokenId.assertEquals(this.tokenId);
|
|
1034
|
+
const price = this.price.getAndRequireEquals();
|
|
1035
|
+
const totalPriceField = price.value.mul(amount.value).div((0, import_o1js6.Field)(1e9));
|
|
1036
|
+
totalPriceField.assertLessThan(import_o1js6.UInt64.MAXINT().value, "totalPrice overflow");
|
|
1037
|
+
const totalPrice = import_o1js6.UInt64.Unsafe.fromField(totalPriceField);
|
|
1038
|
+
const buyer = this.sender.getUnconstrained();
|
|
1039
|
+
const buyerUpdate = import_o1js6.AccountUpdate.createSigned(buyer);
|
|
1040
|
+
buyerUpdate.send({ to: seller, amount: totalPrice });
|
|
1041
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
1042
|
+
let offerUpdate = this.send({ to: buyer, amount });
|
|
1043
|
+
offerUpdate.body.mayUseToken = import_o1js6.AccountUpdate.MayUseToken.InheritFromParent;
|
|
1044
|
+
offerUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
1045
|
+
const whitelist = this.whitelist.getAndRequireEquals();
|
|
1046
|
+
const whitelistedAmount = await whitelist.getWhitelistedAmount(buyer);
|
|
1047
|
+
amount.assertLessThanOrEqual(whitelistedAmount.assertSome("Cannot buy more than whitelisted amount"));
|
|
1048
|
+
this.emitEvent("buy", { amount, address: buyer });
|
|
1049
|
+
}
|
|
1050
|
+
async updateWhitelist(whitelist) {
|
|
1051
|
+
const seller = this.seller.getAndRequireEquals();
|
|
1052
|
+
const sender = this.sender.getUnconstrained();
|
|
1053
|
+
const senderUpdate = import_o1js6.AccountUpdate.createSigned(sender);
|
|
1054
|
+
senderUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true);
|
|
1055
|
+
sender.assertEquals(seller);
|
|
1056
|
+
this.whitelist.set(whitelist);
|
|
1057
|
+
this.emitEvent("updateWhitelist", whitelist);
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
(0, import_tslib6.__decorate)([
|
|
1061
|
+
(0, import_o1js6.state)(import_o1js6.UInt64),
|
|
1062
|
+
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1063
|
+
], FungibleTokenOfferContract.prototype, "price", void 0);
|
|
1064
|
+
(0, import_tslib6.__decorate)([
|
|
1065
|
+
(0, import_o1js6.state)(import_o1js6.PublicKey),
|
|
1066
|
+
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1067
|
+
], FungibleTokenOfferContract.prototype, "seller", void 0);
|
|
1068
|
+
(0, import_tslib6.__decorate)([
|
|
1069
|
+
(0, import_o1js6.state)(import_o1js6.PublicKey),
|
|
1070
|
+
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1071
|
+
], FungibleTokenOfferContract.prototype, "token", void 0);
|
|
1072
|
+
(0, import_tslib6.__decorate)([
|
|
1073
|
+
(0, import_o1js6.state)(import_storage4.Whitelist),
|
|
1074
|
+
(0, import_tslib6.__metadata)("design:type", Object)
|
|
1075
|
+
], FungibleTokenOfferContract.prototype, "whitelist", void 0);
|
|
1076
|
+
(0, import_tslib6.__decorate)([
|
|
1077
|
+
import_o1js6.method,
|
|
1078
|
+
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1079
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [
|
|
1080
|
+
import_o1js6.PublicKey,
|
|
1081
|
+
import_o1js6.PublicKey,
|
|
1082
|
+
import_o1js6.UInt64,
|
|
1083
|
+
import_o1js6.UInt64
|
|
1084
|
+
]),
|
|
1085
|
+
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1086
|
+
], FungibleTokenOfferContract.prototype, "initialize", null);
|
|
1087
|
+
(0, import_tslib6.__decorate)([
|
|
1088
|
+
import_o1js6.method,
|
|
1089
|
+
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1090
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_o1js6.UInt64, import_o1js6.UInt64]),
|
|
1091
|
+
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1092
|
+
], FungibleTokenOfferContract.prototype, "offer", null);
|
|
1093
|
+
(0, import_tslib6.__decorate)([
|
|
1094
|
+
import_o1js6.method,
|
|
1095
|
+
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1096
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_o1js6.UInt64]),
|
|
1097
|
+
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1098
|
+
], FungibleTokenOfferContract.prototype, "withdraw", null);
|
|
1099
|
+
(0, import_tslib6.__decorate)([
|
|
1100
|
+
import_o1js6.method,
|
|
1101
|
+
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1102
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_o1js6.UInt64]),
|
|
1103
|
+
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1104
|
+
], FungibleTokenOfferContract.prototype, "buy", null);
|
|
1105
|
+
(0, import_tslib6.__decorate)([
|
|
1106
|
+
import_o1js6.method,
|
|
1107
|
+
(0, import_tslib6.__metadata)("design:type", Function),
|
|
1108
|
+
(0, import_tslib6.__metadata)("design:paramtypes", [import_storage4.Whitelist]),
|
|
1109
|
+
(0, import_tslib6.__metadata)("design:returntype", Promise)
|
|
1110
|
+
], FungibleTokenOfferContract.prototype, "updateWhitelist", null);
|
|
1111
|
+
|
|
1112
|
+
// dist/node/BondingCurveAdmin.js
|
|
1113
|
+
var import_tslib7 = require("tslib");
|
|
1114
|
+
var import_o1js7 = require("o1js");
|
|
1115
|
+
var import_token = require("@silvana-one/token");
|
|
1116
|
+
var BondingCurveParams = class _BondingCurveParams extends (0, import_o1js7.Struct)({
|
|
1117
|
+
startPrice: import_o1js7.UInt64,
|
|
1118
|
+
curveK: import_o1js7.UInt64,
|
|
1119
|
+
fee: import_o1js7.UInt32,
|
|
1120
|
+
// 1000 = 1%
|
|
1121
|
+
mintingIsAllowed: import_o1js7.Bool
|
|
1122
|
+
}) {
|
|
1123
|
+
pack() {
|
|
1124
|
+
return import_o1js7.Field.fromBits([
|
|
1125
|
+
...this.startPrice.value.toBits(64),
|
|
1126
|
+
...this.curveK.value.toBits(64),
|
|
1127
|
+
...this.fee.value.toBits(32),
|
|
1128
|
+
this.mintingIsAllowed
|
|
1129
|
+
]);
|
|
1130
|
+
}
|
|
1131
|
+
static unpack(field) {
|
|
1132
|
+
const bits = field.toBits(64 + 64 + 32 + 1);
|
|
1133
|
+
const startPrice = import_o1js7.UInt64.Unsafe.fromField(import_o1js7.Field.fromBits(bits.slice(0, 64)));
|
|
1134
|
+
const curveK = import_o1js7.UInt64.Unsafe.fromField(import_o1js7.Field.fromBits(bits.slice(64, 64 + 64)));
|
|
1135
|
+
const fee = import_o1js7.UInt32.Unsafe.fromField(import_o1js7.Field.fromBits(bits.slice(64 + 64, 64 + 64 + 32)));
|
|
1136
|
+
const mintingIsAllowed = bits[64 + 64 + 32];
|
|
1137
|
+
return new _BondingCurveParams({
|
|
1138
|
+
startPrice,
|
|
1139
|
+
curveK,
|
|
1140
|
+
fee,
|
|
1141
|
+
mintingIsAllowed
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
var BondingMintEvent = class extends (0, import_o1js7.Struct)({
|
|
1146
|
+
to: import_o1js7.PublicKey,
|
|
1147
|
+
amount: import_o1js7.UInt64,
|
|
1148
|
+
price: import_o1js7.UInt64,
|
|
1149
|
+
payment: import_o1js7.UInt64,
|
|
1150
|
+
fee: import_o1js7.UInt64
|
|
1151
|
+
}) {
|
|
1152
|
+
};
|
|
1153
|
+
var BondingRedeemEvent = class extends (0, import_o1js7.Struct)({
|
|
1154
|
+
seller: import_o1js7.PublicKey,
|
|
1155
|
+
amount: import_o1js7.UInt64,
|
|
1156
|
+
payment: import_o1js7.UInt64,
|
|
1157
|
+
minBalance: import_o1js7.UInt64,
|
|
1158
|
+
maxSupply: import_o1js7.UInt64,
|
|
1159
|
+
fee: import_o1js7.UInt64
|
|
1160
|
+
}) {
|
|
1161
|
+
};
|
|
1162
|
+
var BondingCurveAdminInitializeProps = class extends (0, import_o1js7.Struct)({
|
|
1163
|
+
tokenAddress: import_o1js7.PublicKey,
|
|
1164
|
+
startPrice: import_o1js7.UInt64,
|
|
1165
|
+
curveK: import_o1js7.UInt64,
|
|
1166
|
+
feeMaster: import_o1js7.PublicKey,
|
|
1167
|
+
fee: import_o1js7.UInt32,
|
|
1168
|
+
// 1000 = 1%
|
|
1169
|
+
launchFee: import_o1js7.UInt64,
|
|
1170
|
+
numberOfNewAccounts: import_o1js7.UInt64
|
|
1171
|
+
}) {
|
|
1172
|
+
};
|
|
1173
|
+
var FungibleTokenBondingCurveAdmin = class extends import_o1js7.TokenContract {
|
|
1174
|
+
constructor() {
|
|
1175
|
+
super(...arguments);
|
|
1176
|
+
this.owner = (0, import_o1js7.State)(import_o1js7.PublicKey.empty());
|
|
1177
|
+
this.token = (0, import_o1js7.State)(import_o1js7.PublicKey.empty());
|
|
1178
|
+
this.feeMaster = (0, import_o1js7.State)(import_o1js7.PublicKey.empty());
|
|
1179
|
+
this.curve = (0, import_o1js7.State)();
|
|
1180
|
+
this.insideMint = (0, import_o1js7.State)((0, import_o1js7.Bool)(false));
|
|
1181
|
+
this.events = {
|
|
1182
|
+
mint: BondingMintEvent,
|
|
1183
|
+
redeem: BondingRedeemEvent
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
async deploy(props) {
|
|
1187
|
+
await super.deploy(props);
|
|
1188
|
+
this.curve.set(new BondingCurveParams({
|
|
1189
|
+
startPrice: import_o1js7.UInt64.from(1e4),
|
|
1190
|
+
curveK: import_o1js7.UInt64.from(1e4),
|
|
1191
|
+
fee: import_o1js7.UInt32.from(1e3),
|
|
1192
|
+
mintingIsAllowed: (0, import_o1js7.Bool)(false)
|
|
1193
|
+
}).pack());
|
|
1194
|
+
this.account.permissions.set({
|
|
1195
|
+
...import_o1js7.Permissions.default(),
|
|
1196
|
+
setVerificationKey: import_o1js7.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
|
1197
|
+
setPermissions: import_o1js7.Permissions.impossible(),
|
|
1198
|
+
send: import_o1js7.Permissions.proof()
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
async approveBase(forest) {
|
|
1202
|
+
throw Error("Transfer not allowed");
|
|
1203
|
+
}
|
|
1204
|
+
async initialize(props) {
|
|
1205
|
+
const { tokenAddress, feeMaster, startPrice, curveK, fee, launchFee, numberOfNewAccounts } = props;
|
|
1206
|
+
this.account.provedState.requireEquals((0, import_o1js7.Bool)(false));
|
|
1207
|
+
this.token.set(tokenAddress);
|
|
1208
|
+
this.feeMaster.set(feeMaster);
|
|
1209
|
+
this.curve.set(new BondingCurveParams({
|
|
1210
|
+
startPrice,
|
|
1211
|
+
curveK,
|
|
1212
|
+
fee,
|
|
1213
|
+
mintingIsAllowed: (0, import_o1js7.Bool)(false)
|
|
1214
|
+
}).pack());
|
|
1215
|
+
const supplyUpdate = import_o1js7.AccountUpdate.createSigned(this.address, this.deriveTokenId());
|
|
1216
|
+
let permissions = import_o1js7.Permissions.default();
|
|
1217
|
+
permissions.send = import_o1js7.Permissions.none();
|
|
1218
|
+
permissions.setPermissions = import_o1js7.Permissions.impossible();
|
|
1219
|
+
supplyUpdate.account.permissions.set(permissions);
|
|
1220
|
+
const payment = launchFee.add(numberOfNewAccounts.mul(import_o1js7.UInt64.from(1e9)));
|
|
1221
|
+
const owner = this.sender.getUnconstrained();
|
|
1222
|
+
const ownerUpdate = import_o1js7.AccountUpdate.create(owner);
|
|
1223
|
+
ownerUpdate.requireSignature();
|
|
1224
|
+
this.owner.set(owner);
|
|
1225
|
+
ownerUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1226
|
+
ownerUpdate.account.balance.requireBetween(payment, import_o1js7.UInt64.MAXINT());
|
|
1227
|
+
ownerUpdate.balance.subInPlace(payment);
|
|
1228
|
+
const feeUpdate = import_o1js7.AccountUpdate.create(feeMaster);
|
|
1229
|
+
feeUpdate.balance.addInPlace(launchFee);
|
|
1230
|
+
}
|
|
1231
|
+
async mint(to, amount, price) {
|
|
1232
|
+
this.insideMint.getAndRequireEquals().assertEquals((0, import_o1js7.Bool)(false));
|
|
1233
|
+
this.insideMint.set((0, import_o1js7.Bool)(true));
|
|
1234
|
+
const tokenAddress = this.token.getAndRequireEquals();
|
|
1235
|
+
const token = new BondingCurveFungibleToken(tokenAddress);
|
|
1236
|
+
const { startPrice, curveK, fee, mintingIsAllowed } = BondingCurveParams.unpack(this.curve.getAndRequireEquals());
|
|
1237
|
+
const buyer = this.sender.getUnconstrained();
|
|
1238
|
+
const buyerUpdate = import_o1js7.AccountUpdate.create(buyer);
|
|
1239
|
+
buyerUpdate.requireSignature();
|
|
1240
|
+
buyerUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1241
|
+
const owner = this.owner.getAndRequireEquals();
|
|
1242
|
+
const isOwner = owner.equals(buyer);
|
|
1243
|
+
const canMint = isOwner.or(mintingIsAllowed);
|
|
1244
|
+
canMint.assertTrue("Minting is disabled for this token");
|
|
1245
|
+
this.curve.set(new BondingCurveParams({
|
|
1246
|
+
startPrice,
|
|
1247
|
+
curveK,
|
|
1248
|
+
fee,
|
|
1249
|
+
mintingIsAllowed: (0, import_o1js7.Bool)(true)
|
|
1250
|
+
}).pack());
|
|
1251
|
+
const maximumSupplyField = import_o1js7.Provable.witness(import_o1js7.Field, () => {
|
|
1252
|
+
if (price.toBigInt() < startPrice.toBigInt()) {
|
|
1253
|
+
throw Error("Price must be greater than or equal to the start price");
|
|
1254
|
+
}
|
|
1255
|
+
return import_o1js7.Field.from((price.toBigInt() - startPrice.toBigInt()) * 10n ** 14n / curveK.toBigInt());
|
|
1256
|
+
});
|
|
1257
|
+
maximumSupplyField.mul(curveK.value).add(startPrice.value.mul(import_o1js7.Field.from(10 ** 14))).assertLessThanOrEqual(price.value.mul(import_o1js7.Field.from(10 ** 14)));
|
|
1258
|
+
maximumSupplyField.assertLessThan(import_o1js7.UInt64.MAXINT().value);
|
|
1259
|
+
const maximumSupply = import_o1js7.UInt64.Unsafe.fromField(maximumSupplyField);
|
|
1260
|
+
const supplyUpdate = import_o1js7.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
1261
|
+
supplyUpdate.account.balance.requireBetween(import_o1js7.UInt64.zero, maximumSupply);
|
|
1262
|
+
amount.assertLessThanOrEqual(import_o1js7.UInt64.from(2n ** 62n));
|
|
1263
|
+
supplyUpdate.balanceChange = import_o1js7.Int64.fromUnsigned(amount);
|
|
1264
|
+
const paymentField = import_o1js7.Provable.witness(import_o1js7.Field, () => {
|
|
1265
|
+
let payment2 = price.toBigInt() * amount.toBigInt() / 10n ** 9n;
|
|
1266
|
+
if (payment2 * 10n ** 9n !== price.toBigInt() * amount.toBigInt()) {
|
|
1267
|
+
payment2++;
|
|
1268
|
+
}
|
|
1269
|
+
if (payment2 * 10n ** 9n < price.toBigInt() * amount.toBigInt()) {
|
|
1270
|
+
throw Error("Payment calculation failed");
|
|
1271
|
+
}
|
|
1272
|
+
return import_o1js7.Field.from(payment2);
|
|
1273
|
+
});
|
|
1274
|
+
paymentField.mul(import_o1js7.Field.from(10 ** 9)).assertGreaterThanOrEqual(price.value.mul(amount.value));
|
|
1275
|
+
paymentField.assertLessThan(import_o1js7.UInt64.MAXINT().value);
|
|
1276
|
+
const payment = import_o1js7.UInt64.Unsafe.fromField(paymentField);
|
|
1277
|
+
const feePaymentField = import_o1js7.Provable.witness(import_o1js7.Field, () => {
|
|
1278
|
+
let feePayment2 = payment.toBigInt() * fee.toBigint() / 100000n;
|
|
1279
|
+
if (feePayment2 * 100000n !== payment.toBigInt() * fee.toBigint()) {
|
|
1280
|
+
feePayment2++;
|
|
1281
|
+
}
|
|
1282
|
+
if (feePayment2 * 100000n < payment.toBigInt() * fee.toBigint()) {
|
|
1283
|
+
throw Error("Fee calculation failed");
|
|
1284
|
+
}
|
|
1285
|
+
return import_o1js7.Field.from(feePayment2);
|
|
1286
|
+
});
|
|
1287
|
+
feePaymentField.mul(import_o1js7.Field.from(1e5)).assertGreaterThanOrEqual(payment.value.mul(fee.value));
|
|
1288
|
+
feePaymentField.assertLessThan(import_o1js7.UInt64.MAXINT().value);
|
|
1289
|
+
let feePayment = import_o1js7.UInt64.Unsafe.fromField(feePaymentField);
|
|
1290
|
+
feePayment = import_o1js7.Provable.if(feePayment.lessThan(import_o1js7.UInt64.from(1e8)), import_o1js7.UInt64.from(1e8), feePayment);
|
|
1291
|
+
const tokenUpdate = await token.mint(to, amount);
|
|
1292
|
+
const isNew = tokenUpdate.account.isNew.get();
|
|
1293
|
+
const totalPayment = payment.add(feePayment).add(import_o1js7.Provable.if(isNew, import_o1js7.UInt64.from(1e9), import_o1js7.UInt64.zero));
|
|
1294
|
+
buyerUpdate.account.balance.requireBetween(totalPayment, import_o1js7.UInt64.MAXINT());
|
|
1295
|
+
buyerUpdate.balance.subInPlace(totalPayment);
|
|
1296
|
+
this.balance.addInPlace(payment);
|
|
1297
|
+
const feeUpdate = import_o1js7.AccountUpdate.create(this.feeMaster.getAndRequireEquals());
|
|
1298
|
+
feeUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1299
|
+
feeUpdate.balance.addInPlace(feePayment);
|
|
1300
|
+
this.emitEvent("mint", new BondingMintEvent({
|
|
1301
|
+
to,
|
|
1302
|
+
amount,
|
|
1303
|
+
price,
|
|
1304
|
+
payment,
|
|
1305
|
+
fee: feePayment
|
|
1306
|
+
}));
|
|
1307
|
+
}
|
|
1308
|
+
/*
|
|
1309
|
+
In case of other txs being included in the same block, the balance and supply may change.
|
|
1310
|
+
We need to ensure that the balance is at least minBalance and the supply is at most maxSupply.
|
|
1311
|
+
It is recommended to put 5% buffer for minBalance and 5% buffer for maxSupply for tx to succeed.
|
|
1312
|
+
*/
|
|
1313
|
+
async redeem(amount, minPrice, slippage) {
|
|
1314
|
+
const tokenAddress = this.token.getAndRequireEquals();
|
|
1315
|
+
const token = new BondingCurveFungibleToken(tokenAddress);
|
|
1316
|
+
const balance = await import_o1js7.Provable.witnessAsync(import_o1js7.UInt64, async () => {
|
|
1317
|
+
await (0, import_o1js7.fetchAccount)({
|
|
1318
|
+
publicKey: this.address,
|
|
1319
|
+
tokenId: this.tokenId
|
|
1320
|
+
});
|
|
1321
|
+
const balance2 = import_o1js7.Mina.getAccount(this.address, this.tokenId).balance;
|
|
1322
|
+
console.log("redeem: balance", balance2.toBigInt());
|
|
1323
|
+
return balance2;
|
|
1324
|
+
});
|
|
1325
|
+
slippage.assertLessThan(import_o1js7.UInt32.from(1e3));
|
|
1326
|
+
const minBalanceField = import_o1js7.Provable.witness(import_o1js7.Field, () => {
|
|
1327
|
+
let minBalance2 = balance.toBigInt() * (1000n - slippage.toBigint()) / 1000n;
|
|
1328
|
+
if (minBalance2 * 1000n !== balance.toBigInt() * (1000n - slippage.toBigint())) {
|
|
1329
|
+
minBalance2++;
|
|
1330
|
+
}
|
|
1331
|
+
if (minBalance2 * 1000n < balance.toBigInt() * (1000n - slippage.toBigint())) {
|
|
1332
|
+
throw Error("Min balance calculation failed");
|
|
1333
|
+
}
|
|
1334
|
+
return import_o1js7.Field.from(minBalance2);
|
|
1335
|
+
});
|
|
1336
|
+
minBalanceField.mul(import_o1js7.Field.from(1e3)).add(balance.value.mul(slippage.value)).assertGreaterThanOrEqual(balance.value.mul(import_o1js7.Field.from(1e3)));
|
|
1337
|
+
minBalanceField.assertLessThan(import_o1js7.UInt64.MAXINT().value);
|
|
1338
|
+
const minBalance = import_o1js7.UInt64.Unsafe.fromField(minBalanceField);
|
|
1339
|
+
this.account.balance.requireBetween(minBalance, import_o1js7.UInt64.MAXINT());
|
|
1340
|
+
const supply = await import_o1js7.Provable.witnessAsync(import_o1js7.UInt64, async () => {
|
|
1341
|
+
await (0, import_o1js7.fetchAccount)({
|
|
1342
|
+
publicKey: this.address,
|
|
1343
|
+
tokenId: this.deriveTokenId()
|
|
1344
|
+
});
|
|
1345
|
+
const balance2 = import_o1js7.Mina.getAccount(this.address, this.deriveTokenId()).balance;
|
|
1346
|
+
console.log("redeem: supply", balance2.toBigInt());
|
|
1347
|
+
return balance2;
|
|
1348
|
+
});
|
|
1349
|
+
supply.assertGreaterThanOrEqual(amount);
|
|
1350
|
+
supply.assertGreaterThan(import_o1js7.UInt64.zero);
|
|
1351
|
+
const maxSupplyField = import_o1js7.Provable.witness(import_o1js7.Field, () => import_o1js7.Field.from(supply.toBigInt() * (1000n + slippage.toBigint()) / 1000n));
|
|
1352
|
+
maxSupplyField.mul(import_o1js7.Field.from(1e3)).assertLessThanOrEqual(supply.value.mul(import_o1js7.Field.from(1e3).add(slippage.value)));
|
|
1353
|
+
maxSupplyField.assertLessThan(import_o1js7.UInt64.MAXINT().value);
|
|
1354
|
+
const maxSupply = import_o1js7.UInt64.Unsafe.fromField(maxSupplyField);
|
|
1355
|
+
const supplyUpdate = import_o1js7.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
1356
|
+
supplyUpdate.account.balance.requireBetween(import_o1js7.UInt64.zero, maxSupply);
|
|
1357
|
+
supplyUpdate.balanceChange = import_o1js7.Int64.fromUnsigned(amount).neg();
|
|
1358
|
+
const paymentField = import_o1js7.Provable.witness(import_o1js7.Field, () => import_o1js7.Field.from(minBalance.toBigInt() * amount.toBigInt() / maxSupply.toBigInt()));
|
|
1359
|
+
paymentField.mul(maxSupply.value).assertLessThanOrEqual(minBalance.value.mul(amount.value));
|
|
1360
|
+
paymentField.assertLessThan(import_o1js7.Field.from(2n ** 62n));
|
|
1361
|
+
amount.value.mul(minPrice.value).assertLessThanOrEqual(paymentField.mul(import_o1js7.Field.from(10 ** 9)));
|
|
1362
|
+
const payment = import_o1js7.UInt64.Unsafe.fromField(paymentField);
|
|
1363
|
+
const { fee, mintingIsAllowed } = BondingCurveParams.unpack(this.curve.getAndRequireEquals());
|
|
1364
|
+
mintingIsAllowed.assertTrue("Minting is disabled for this token, nothing to redeem");
|
|
1365
|
+
let feePayment = import_o1js7.Provable.witness(import_o1js7.UInt64, () => {
|
|
1366
|
+
let feePayment2 = payment.toBigInt() * fee.toBigint() / 100000n;
|
|
1367
|
+
if (feePayment2 * 100000n !== payment.toBigInt() * fee.toBigint()) {
|
|
1368
|
+
feePayment2++;
|
|
1369
|
+
}
|
|
1370
|
+
if (feePayment2 * 100000n < payment.toBigInt() * fee.toBigint()) {
|
|
1371
|
+
throw Error("Fee calculation failed");
|
|
1372
|
+
}
|
|
1373
|
+
return import_o1js7.UInt64.from(feePayment2);
|
|
1374
|
+
});
|
|
1375
|
+
feePayment = import_o1js7.Provable.if(feePayment.lessThan(import_o1js7.UInt64.from(1e8)), import_o1js7.UInt64.from(1e8), feePayment);
|
|
1376
|
+
const seller = this.sender.getUnconstrained();
|
|
1377
|
+
const sellerUpdate = import_o1js7.AccountUpdate.create(seller);
|
|
1378
|
+
const isNew = await import_o1js7.Provable.witnessAsync(import_o1js7.Bool, async () => {
|
|
1379
|
+
const sellerAccount = await (0, import_o1js7.fetchAccount)({
|
|
1380
|
+
publicKey: seller
|
|
1381
|
+
});
|
|
1382
|
+
return (0, import_o1js7.Bool)(sellerAccount.account === void 0);
|
|
1383
|
+
});
|
|
1384
|
+
sellerUpdate.account.isNew.requireEquals(isNew);
|
|
1385
|
+
const accountCreationFee = import_o1js7.Provable.if(isNew, import_o1js7.UInt64.from(1e9), import_o1js7.UInt64.zero);
|
|
1386
|
+
payment.assertGreaterThan(feePayment.add(accountCreationFee));
|
|
1387
|
+
sellerUpdate.requireSignature();
|
|
1388
|
+
sellerUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1389
|
+
const totalPayment = import_o1js7.Provable.witness(import_o1js7.UInt64, () => {
|
|
1390
|
+
if (payment.toBigInt() < feePayment.toBigInt() + accountCreationFee.toBigInt()) {
|
|
1391
|
+
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
|
+
payment: payment.toBigInt(),
|
|
1393
|
+
feePayment: feePayment.toBigInt(),
|
|
1394
|
+
accountCreationFee: accountCreationFee.toBigInt(),
|
|
1395
|
+
minBalance: minBalance.toBigInt(),
|
|
1396
|
+
maxSupply: maxSupply.toBigInt(),
|
|
1397
|
+
supply: supply.toBigInt(),
|
|
1398
|
+
amount: amount.toBigInt(),
|
|
1399
|
+
balance: balance.toBigInt(),
|
|
1400
|
+
tokenAddress: tokenAddress.toBase58(),
|
|
1401
|
+
seller: seller.toBase58(),
|
|
1402
|
+
isNew: isNew.toBoolean()
|
|
1403
|
+
});
|
|
1404
|
+
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
|
+
}
|
|
1406
|
+
return import_o1js7.UInt64.from(payment.toBigInt() - feePayment.toBigInt() - accountCreationFee.toBigInt());
|
|
1407
|
+
});
|
|
1408
|
+
totalPayment.add(feePayment).add(accountCreationFee).assertEquals(payment);
|
|
1409
|
+
sellerUpdate.balance.addInPlace(totalPayment);
|
|
1410
|
+
const feeUpdate = import_o1js7.AccountUpdate.create(this.feeMaster.getAndRequireEquals());
|
|
1411
|
+
feeUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1412
|
+
feeUpdate.balance.addInPlace(feePayment);
|
|
1413
|
+
this.balance.subInPlace(payment);
|
|
1414
|
+
await token.burn(seller, amount);
|
|
1415
|
+
this.emitEvent("redeem", new BondingRedeemEvent({
|
|
1416
|
+
seller,
|
|
1417
|
+
amount,
|
|
1418
|
+
payment,
|
|
1419
|
+
minBalance,
|
|
1420
|
+
maxSupply,
|
|
1421
|
+
fee: feePayment
|
|
1422
|
+
}));
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* In case the user burned tokens without calling the redeem method,
|
|
1426
|
+
* we need to sync the supply to the actual circulated supply
|
|
1427
|
+
*/
|
|
1428
|
+
async sync() {
|
|
1429
|
+
const tokenAddress = this.token.getAndRequireEquals();
|
|
1430
|
+
const token = new BondingCurveFungibleToken(tokenAddress);
|
|
1431
|
+
const supplyUpdate = import_o1js7.AccountUpdate.create(this.address, this.deriveTokenId());
|
|
1432
|
+
const circulatingSupply = await token.getBalanceOf(tokenAddress);
|
|
1433
|
+
const totalSupply = supplyUpdate.account.balance.getAndRequireEquals();
|
|
1434
|
+
supplyUpdate.balanceChange = import_o1js7.Int64.fromUnsigned(totalSupply.sub(circulatingSupply)).neg();
|
|
1435
|
+
}
|
|
1436
|
+
/** Update the verification key.
|
|
1437
|
+
* 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.
|
|
1438
|
+
*/
|
|
1439
|
+
async updateVerificationKey(vk) {
|
|
1440
|
+
this.account.verificationKey.set(vk);
|
|
1441
|
+
}
|
|
1442
|
+
ensureOwnerSignature() {
|
|
1443
|
+
const owner = this.owner.getAndRequireEquals();
|
|
1444
|
+
const update = import_o1js7.AccountUpdate.createSigned(owner);
|
|
1445
|
+
update.body.useFullCommitment = (0, import_o1js7.Bool)(true);
|
|
1446
|
+
return update;
|
|
1447
|
+
}
|
|
1448
|
+
async canMint(_accountUpdate) {
|
|
1449
|
+
this.insideMint.requireEquals((0, import_o1js7.Bool)(true));
|
|
1450
|
+
this.insideMint.set((0, import_o1js7.Bool)(false));
|
|
1451
|
+
return (0, import_o1js7.Bool)(true);
|
|
1452
|
+
}
|
|
1453
|
+
async canChangeAdmin(_admin) {
|
|
1454
|
+
this.ensureOwnerSignature();
|
|
1455
|
+
return (0, import_o1js7.Bool)(true);
|
|
1456
|
+
}
|
|
1457
|
+
async canPause() {
|
|
1458
|
+
this.ensureOwnerSignature();
|
|
1459
|
+
return (0, import_o1js7.Bool)(true);
|
|
1460
|
+
}
|
|
1461
|
+
async canResume() {
|
|
1462
|
+
this.ensureOwnerSignature();
|
|
1463
|
+
return (0, import_o1js7.Bool)(true);
|
|
1464
|
+
}
|
|
1465
|
+
async canChangeVerificationKey(_vk) {
|
|
1466
|
+
this.ensureOwnerSignature();
|
|
1467
|
+
return (0, import_o1js7.Bool)(true);
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
(0, import_tslib7.__decorate)([
|
|
1471
|
+
(0, import_o1js7.state)(import_o1js7.PublicKey),
|
|
1472
|
+
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1473
|
+
], FungibleTokenBondingCurveAdmin.prototype, "owner", void 0);
|
|
1474
|
+
(0, import_tslib7.__decorate)([
|
|
1475
|
+
(0, import_o1js7.state)(import_o1js7.PublicKey),
|
|
1476
|
+
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1477
|
+
], FungibleTokenBondingCurveAdmin.prototype, "token", void 0);
|
|
1478
|
+
(0, import_tslib7.__decorate)([
|
|
1479
|
+
(0, import_o1js7.state)(import_o1js7.PublicKey),
|
|
1480
|
+
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1481
|
+
], FungibleTokenBondingCurveAdmin.prototype, "feeMaster", void 0);
|
|
1482
|
+
(0, import_tslib7.__decorate)([
|
|
1483
|
+
(0, import_o1js7.state)(import_o1js7.Field),
|
|
1484
|
+
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1485
|
+
], FungibleTokenBondingCurveAdmin.prototype, "curve", void 0);
|
|
1486
|
+
(0, import_tslib7.__decorate)([
|
|
1487
|
+
(0, import_o1js7.state)(import_o1js7.Bool),
|
|
1488
|
+
(0, import_tslib7.__metadata)("design:type", Object)
|
|
1489
|
+
], FungibleTokenBondingCurveAdmin.prototype, "insideMint", void 0);
|
|
1490
|
+
(0, import_tslib7.__decorate)([
|
|
1491
|
+
import_o1js7.method,
|
|
1492
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1493
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [BondingCurveAdminInitializeProps]),
|
|
1494
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1495
|
+
], FungibleTokenBondingCurveAdmin.prototype, "initialize", null);
|
|
1496
|
+
(0, import_tslib7.__decorate)([
|
|
1497
|
+
import_o1js7.method,
|
|
1498
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1499
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js7.PublicKey, import_o1js7.UInt64, import_o1js7.UInt64]),
|
|
1500
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1501
|
+
], FungibleTokenBondingCurveAdmin.prototype, "mint", null);
|
|
1502
|
+
(0, import_tslib7.__decorate)([
|
|
1503
|
+
import_o1js7.method,
|
|
1504
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1505
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js7.UInt64, import_o1js7.UInt64, import_o1js7.UInt32]),
|
|
1506
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1507
|
+
], FungibleTokenBondingCurveAdmin.prototype, "redeem", null);
|
|
1508
|
+
(0, import_tslib7.__decorate)([
|
|
1509
|
+
import_o1js7.method,
|
|
1510
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1511
|
+
(0, import_tslib7.__metadata)("design:paramtypes", []),
|
|
1512
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1513
|
+
], FungibleTokenBondingCurveAdmin.prototype, "sync", null);
|
|
1514
|
+
(0, import_tslib7.__decorate)([
|
|
1515
|
+
import_o1js7.method,
|
|
1516
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1517
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js7.VerificationKey]),
|
|
1518
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1519
|
+
], FungibleTokenBondingCurveAdmin.prototype, "updateVerificationKey", null);
|
|
1520
|
+
(0, import_tslib7.__decorate)([
|
|
1521
|
+
import_o1js7.method.returns(import_o1js7.Bool),
|
|
1522
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1523
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js7.AccountUpdate]),
|
|
1524
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1525
|
+
], FungibleTokenBondingCurveAdmin.prototype, "canMint", null);
|
|
1526
|
+
(0, import_tslib7.__decorate)([
|
|
1527
|
+
import_o1js7.method.returns(import_o1js7.Bool),
|
|
1528
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1529
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js7.PublicKey]),
|
|
1530
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1531
|
+
], FungibleTokenBondingCurveAdmin.prototype, "canChangeAdmin", null);
|
|
1532
|
+
(0, import_tslib7.__decorate)([
|
|
1533
|
+
import_o1js7.method.returns(import_o1js7.Bool),
|
|
1534
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1535
|
+
(0, import_tslib7.__metadata)("design:paramtypes", []),
|
|
1536
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1537
|
+
], FungibleTokenBondingCurveAdmin.prototype, "canPause", null);
|
|
1538
|
+
(0, import_tslib7.__decorate)([
|
|
1539
|
+
import_o1js7.method.returns(import_o1js7.Bool),
|
|
1540
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1541
|
+
(0, import_tslib7.__metadata)("design:paramtypes", []),
|
|
1542
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1543
|
+
], FungibleTokenBondingCurveAdmin.prototype, "canResume", null);
|
|
1544
|
+
(0, import_tslib7.__decorate)([
|
|
1545
|
+
import_o1js7.method.returns(import_o1js7.Bool),
|
|
1546
|
+
(0, import_tslib7.__metadata)("design:type", Function),
|
|
1547
|
+
(0, import_tslib7.__metadata)("design:paramtypes", [import_o1js7.VerificationKey]),
|
|
1548
|
+
(0, import_tslib7.__metadata)("design:returntype", Promise)
|
|
1549
|
+
], FungibleTokenBondingCurveAdmin.prototype, "canChangeVerificationKey", null);
|
|
1550
|
+
var BondingCurveFungibleToken = (0, import_token.FungibleTokenContract)(FungibleTokenBondingCurveAdmin);
|
|
1551
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1552
|
+
0 && (module.exports = {
|
|
1553
|
+
AdvancedAdminData,
|
|
1554
|
+
AdvancedFungibleToken,
|
|
1555
|
+
BalanceChangeEvent,
|
|
1556
|
+
BidEvent,
|
|
1557
|
+
BondingCurveAdminInitializeProps,
|
|
1558
|
+
BondingCurveFungibleToken,
|
|
1559
|
+
BondingCurveParams,
|
|
1560
|
+
BondingMintEvent,
|
|
1561
|
+
BondingRedeemEvent,
|
|
1562
|
+
BurnEvent,
|
|
1563
|
+
FungibleToken,
|
|
1564
|
+
FungibleTokenAdmin,
|
|
1565
|
+
FungibleTokenAdvancedAdmin,
|
|
1566
|
+
FungibleTokenBidContract,
|
|
1567
|
+
FungibleTokenBondingCurveAdmin,
|
|
1568
|
+
FungibleTokenClaimContract,
|
|
1569
|
+
FungibleTokenContract,
|
|
1570
|
+
FungibleTokenErrors,
|
|
1571
|
+
FungibleTokenOfferContract,
|
|
1572
|
+
MintEvent,
|
|
1573
|
+
OfferEvent,
|
|
1574
|
+
PauseEvent,
|
|
1575
|
+
SetAdminEvent
|
|
1576
|
+
});
|