@tatumio/flow 2.0.1-alpha.237

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flowTxTemplates = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const dedent_js_1 = (0, tslib_1.__importDefault)(require("dedent-js"));
6
+ const flow_tx_1 = require("./flow.tx");
7
+ const flowTxTemplates = () => {
8
+ return {
9
+ deployNftTokenTypeWithMinterTxTemplate: (testnet) => (0, dedent_js_1.default) `
10
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
11
+ transaction(type: String) {
12
+ // local variable for storing the minter reference
13
+ let minter: &TatumMultiNFT.AdminMinter
14
+ let newMinter: AuthAccount;
15
+ prepare(adminMinter: AuthAccount, newMinter: AuthAccount) {
16
+ // borrow a reference to the NFTMinter resource in storage
17
+ self.minter = adminMinter.borrow<&TatumMultiNFT.AdminMinter>(from: TatumMultiNFT.AdminMinterStoragePath)
18
+ ?? panic("Could not borrow a reference to the NFT minter")
19
+ self.newMinter = newMinter;
20
+ }
21
+ execute {
22
+ // add new minter for specific token type
23
+ self.minter.addMinter(minterAccount: self.newMinter, type: type)
24
+ }
25
+ }
26
+ `,
27
+ metadataNftTokenScript: (testnet) => (0, dedent_js_1.default) `
28
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
29
+ pub fun main(account: Address, id: UInt64, type: String): String {
30
+ let collectionRef = getAccount(account)
31
+ .getCapability(TatumMultiNFT.CollectionPublicPath)
32
+ .borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>()
33
+ ?? panic("Could not borrow capability from public collection")
34
+ let ref = collectionRef.borrowTatumNFT(id: id, type: type)
35
+ if ref != nil {
36
+ return ref.metadata
37
+ } else {
38
+ return panic("No such token");
39
+ }
40
+ }`,
41
+ tokenByAddressNftTokenScript: (testnet) => (0, dedent_js_1.default) `
42
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
43
+ pub fun main(address: Address, type: String): [UInt64] {
44
+ let collectionRef = getAccount(address)
45
+ .getCapability(TatumMultiNFT.CollectionPublicPath)
46
+ .borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>()
47
+ ?? panic("Could not borrow capability from public collection")
48
+ return collectionRef.getIDsByType(type: type)
49
+ }`,
50
+ mintNftTokenTxTemplate: (testnet) => (0, dedent_js_1.default) `
51
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
52
+ transaction(recipient: Address, url: String, type: String) {
53
+ // local variable for storing the minter reference
54
+ let minter: &TatumMultiNFT.NFTMinter
55
+ prepare(signer: AuthAccount) {
56
+ // borrow a reference to the NFTMinter resource in storage
57
+ self.minter = signer.borrow<&TatumMultiNFT.NFTMinter>(from: TatumMultiNFT.MinterStoragePath)
58
+ ?? panic("Could not borrow a reference to the NFT minter")
59
+ }
60
+ execute {
61
+ // get the public account object for the recipient
62
+ let recipientAccount = getAccount(recipient)
63
+ // borrow the recipient's public NFT collection reference
64
+ let receiver = recipientAccount
65
+ .getCapability(TatumMultiNFT.CollectionPublicPath)
66
+ .borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>()
67
+ ?? panic("Could not get receiver reference to the NFT Collection")
68
+ // mint the NFT and deposit it to the recipient's collection
69
+ self.minter.mintNFT(recipient: receiver, type: type, url: url, address: recipient)
70
+ }
71
+ }`,
72
+ mintMultipleNftTokenTxTemplate: (testnet) => (0, dedent_js_1.default) `
73
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
74
+ transaction(recipient: [Address], url: [String], type: String) {
75
+ // local variable for storing the minter reference
76
+ let minter: &TatumMultiNFT.NFTMinter
77
+ prepare(signer: AuthAccount) {
78
+ // borrow a reference to the NFTMinter resource in storage
79
+ self.minter = signer.borrow<&TatumMultiNFT.NFTMinter>(from: TatumMultiNFT.MinterStoragePath)
80
+ ?? panic("Could not borrow a reference to the NFT minter")
81
+ }
82
+ execute {
83
+ var a = 0;
84
+ while a < url.length {
85
+ // get the public account object for the recipient
86
+ let recipientAccount = getAccount(recipient[a])
87
+ // borrow the recipient's public NFT collection reference
88
+ let receiver = recipientAccount
89
+ .getCapability(TatumMultiNFT.CollectionPublicPath)
90
+ .borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>()
91
+ ?? panic("Could not get receiver reference to the NFT Collection")
92
+ // mint the NFT and deposit it to the recipient's collection
93
+ self.minter.mintNFT(recipient: receiver, type: type, url: url[a], address: recipient[a])
94
+ a = a + 1
95
+ }
96
+ }
97
+ }`,
98
+ burnNftTokenTxTemplate: (testnet) => (0, dedent_js_1.default) `
99
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
100
+ transaction(withdrawID: UInt64, type: String) {
101
+ // local variable for storing the minter reference
102
+ let senderCollection: &{TatumMultiNFT.TatumMultiNftCollectionPublic}
103
+ prepare(signer: AuthAccount) {
104
+ // borrow a reference to the signer's NFT collection
105
+ self.senderCollection = signer.borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>(from: TatumMultiNFT.CollectionStoragePath)
106
+ ?? panic("Could not borrow a reference to the owner's collection")
107
+ // check if token has correct type
108
+ self.senderCollection.borrowTatumNFT(id: withdrawID, type: type)
109
+ }
110
+ execute {
111
+ // withdraw the NFT from the owner's collection
112
+ let nft <- self.senderCollection.withdraw(withdrawID: withdrawID)
113
+ // Destroy the nft
114
+ destroy nft
115
+ }
116
+ }`,
117
+ transferNftTokenTxTemplate: (testnet) => (0, dedent_js_1.default) `
118
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
119
+ transaction(recipient: Address, withdrawID: UInt64) {
120
+ // local variable for storing the minter reference
121
+ let senderCollection: &{TatumMultiNFT.TatumMultiNftCollectionPublic}
122
+ prepare(signer: AuthAccount) {
123
+ // borrow a reference to the signer's NFT collection
124
+ self.senderCollection = signer.borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>(from: TatumMultiNFT.CollectionStoragePath)
125
+ ?? panic("Could not borrow a reference to the owner's collection")
126
+ }
127
+ execute {
128
+ // get the recipients public account object
129
+ let recipient = getAccount(recipient)
130
+ // borrow a public reference to the receivers collection
131
+ let depositRef = recipient.getCapability(TatumMultiNFT.CollectionPublicPath).borrow<&{TatumMultiNFT.TatumMultiNftCollectionPublic}>()!
132
+ // withdraw the NFT from the owner's collection
133
+ let nft <- self.senderCollection.withdraw(withdrawID: withdrawID)
134
+ // Deposit the NFT in the recipient's collection
135
+ depositRef.deposit(token: <-nft)
136
+ }
137
+ }`,
138
+ prepareAddPublicKeyToAccountTxTemplate: () => (0, dedent_js_1.default) `transaction(publicKey: String) {
139
+ prepare(signer: AuthAccount) {
140
+ signer.addPublicKey(publicKey.decodeHex())
141
+ }
142
+ }`,
143
+ prepareTransferTxTemplate: (testnet, tokenAddress, tokenName, tokenStorage) => (0, dedent_js_1.default) `import FungibleToken from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.FungibleToken : flow_tx_1.FLOW_MAINNET_ADDRESSES.FungibleToken}
144
+ import ${tokenName} from ${tokenAddress}
145
+ transaction(amount: UFix64, recipient: Address) {
146
+ let sentVault: @FungibleToken.Vault
147
+ prepare(signer: AuthAccount) {
148
+ let vaultRef = signer.borrow<&${tokenName}.Vault>(from: /storage/${tokenStorage}Vault)
149
+ ?? panic("failed to borrow reference to sender vault")
150
+ self.sentVault <- vaultRef.withdraw(amount: amount)
151
+ }
152
+ execute {
153
+ let receiverRef = getAccount(recipient)
154
+ .getCapability(/public/${tokenStorage}Receiver)
155
+ .borrow<&{FungibleToken.Receiver}>()
156
+ ?? panic("failed to borrow reference to recipient vault")
157
+ receiverRef.deposit(from: <-self.sentVault)
158
+ }
159
+ }`,
160
+ prepareCreateAccountWithFUSDFromPublicKeyTxTemplate: (testnet) => (0, dedent_js_1.default) `import FungibleToken from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.FungibleToken : flow_tx_1.FLOW_MAINNET_ADDRESSES.FungibleToken}
161
+ import FUSD from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.FUSD : flow_tx_1.FLOW_MAINNET_ADDRESSES.FUSD}
162
+ import TatumMultiNFT from ${testnet ? flow_tx_1.FLOW_TESTNET_ADDRESSES.TatumMultiNFT : flow_tx_1.FLOW_MAINNET_ADDRESSES.TatumMultiNFT}
163
+ transaction(publicKey: String) {
164
+ let account: AuthAccount
165
+ prepare(signer: AuthAccount) {
166
+ self.account = AuthAccount(payer: signer)
167
+ }
168
+ execute {
169
+ self.account.addPublicKey(publicKey.decodeHex())
170
+ if self.account.borrow<&TatumMultiNFT.Collection>(from: TatumMultiNFT.CollectionStoragePath) == nil {
171
+ // create a new empty collection
172
+ let collection <- TatumMultiNFT.createEmptyCollection()
173
+ // save it to the account
174
+ self.account.save(<-collection, to: TatumMultiNFT.CollectionStoragePath)
175
+ // create a public capability for the collection
176
+ self.account.link<&TatumMultiNFT.Collection>(TatumMultiNFT.CollectionPublicPath, target: TatumMultiNFT.CollectionStoragePath)
177
+ }
178
+ // Add FUSD vault
179
+ self.account.save(<-FUSD.createEmptyVault(), to: /storage/fusdVault)
180
+ self.account.link<&FUSD.Vault{FungibleToken.Receiver}>(
181
+ /public/fusdReceiver,
182
+ target: /storage/fusdVault
183
+ )
184
+ self.account.link<&FUSD.Vault{FungibleToken.Balance}>(
185
+ /public/fusdBalance,
186
+ target: /storage/fusdVault
187
+ )
188
+ }
189
+ }
190
+ `,
191
+ };
192
+ };
193
+ exports.flowTxTemplates = flowTxTemplates;
194
+ //# sourceMappingURL=flow.tx.templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.tx.templates.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/flow/src/lib/services/flow.tx.templates.ts"],"names":[],"mappings":";;;;AAAA,uEAA8B;AAC9B,uCAA0E;AAEnE,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,OAAO;QACL,sCAAsC,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAA,mBAAM,EAAA;4BAElE,OAAO,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAAa,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAC1E;;;;;;;;;;;;;;;;CAgBH;QACG,sBAAsB,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAA,mBAAM,EAAA;4BAElD,OAAO,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAAa,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAC1E;;;;;;;;;;;;EAYF;QACE,4BAA4B,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAA,mBAAM,EAAA;4BAExD,OAAO,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAAa,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAC1E;;;;;;;EAOF;QACE,sBAAsB,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAA,mBAAM,EAAA;4BAElD,OAAO,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAAa,CAAC,CAAC,CAAC,gCAAsB,CAAC,aAC1E;;;;;;;;;;;;;;;;;;;;EAoBF;QACE,8BAA8B,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAA,mBAAM,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