3land_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. package/README.md +352 -0
  2. package/assets/3land_rebrand.gif +0 -0
  3. package/assets/battle_sol.gif +0 -0
  4. package/assets/ds.jpeg +0 -0
  5. package/assets/future.webp +0 -0
  6. package/assets/music.mp3 +0 -0
  7. package/assets/niicl.gif +0 -0
  8. package/assets/og.png +0 -0
  9. package/assets/phone.glb +0 -0
  10. package/assets/testvid.mp4 +0 -0
  11. package/idl.json +7652 -0
  12. package/package.json +35 -0
  13. package/src/index.ts +89 -0
  14. package/src/library/Irys/irys.ts +412 -0
  15. package/src/library/Store.ts +613 -0
  16. package/src/library/implementation/storeImplementation.ts +385 -0
  17. package/src/library/instructions/store/buySingleEdition.ts +227 -0
  18. package/src/library/instructions/store/createSingleEdition.ts +49 -0
  19. package/src/library/instructions/store/createStore.ts +19 -0
  20. package/src/library/instructions/store/idl.ts +7622 -0
  21. package/src/library/instructions/store/uploadFilesIryis.ts +133 -0
  22. package/src/types/accounts/ArchiveDeposit.ts +207 -0
  23. package/src/types/accounts/Authority.ts +73 -0
  24. package/src/types/accounts/BurnDeposit.ts +111 -0
  25. package/src/types/accounts/BurnProgress.ts +97 -0
  26. package/src/types/accounts/BuyHistory.ts +121 -0
  27. package/src/types/accounts/BuyTrack.ts +94 -0
  28. package/src/types/accounts/Card.ts +185 -0
  29. package/src/types/accounts/CollectionRegistry.ts +145 -0
  30. package/src/types/accounts/CollectorRegistry.ts +145 -0
  31. package/src/types/accounts/CreatorRegistry.ts +153 -0
  32. package/src/types/accounts/CurrencyArtistProof.ts +113 -0
  33. package/src/types/accounts/GenericUser.ts +185 -0
  34. package/src/types/accounts/ItemArchive.ts +223 -0
  35. package/src/types/accounts/ItemReserveList.ts +87 -0
  36. package/src/types/accounts/ItemReserveList2.ts +73 -0
  37. package/src/types/accounts/LutVault.ts +97 -0
  38. package/src/types/accounts/Pack.ts +367 -0
  39. package/src/types/accounts/PackContent.ts +97 -0
  40. package/src/types/accounts/PackOpenHolder.ts +141 -0
  41. package/src/types/accounts/PackReceipt.ts +145 -0
  42. package/src/types/accounts/PackTraits.ts +101 -0
  43. package/src/types/accounts/Payment.ts +97 -0
  44. package/src/types/accounts/PoolVault.ts +177 -0
  45. package/src/types/accounts/RevealForMe.ts +139 -0
  46. package/src/types/accounts/SecureHolder.ts +97 -0
  47. package/src/types/accounts/Single.ts +301 -0
  48. package/src/types/accounts/Store.ts +180 -0
  49. package/src/types/accounts/StoresHolder.ts +131 -0
  50. package/src/types/accounts/ThreeId.ts +189 -0
  51. package/src/types/accounts/TokenManager.ts +217 -0
  52. package/src/types/accounts/ZeroCard.ts +73 -0
  53. package/src/types/accounts/ZeroContent.ts +89 -0
  54. package/src/types/accounts/ZeroOpenHolder.ts +183 -0
  55. package/src/types/accounts/index.ts +84 -0
  56. package/src/types/errors/anchor.ts +773 -0
  57. package/src/types/errors/index.ts +59 -0
  58. package/src/types/implementation/implementationTypes.ts +27 -0
  59. package/src/types/instructions/addBurn.ts +56 -0
  60. package/src/types/instructions/adjustDepositBurn.ts +33 -0
  61. package/src/types/instructions/archiveItem.ts +60 -0
  62. package/src/types/instructions/assignPackDelegate.ts +30 -0
  63. package/src/types/instructions/burnPay.ts +55 -0
  64. package/src/types/instructions/buyPack.ts +69 -0
  65. package/src/types/instructions/buyPay.ts +71 -0
  66. package/src/types/instructions/buyToken.ts +64 -0
  67. package/src/types/instructions/claimZeroCard.ts +106 -0
  68. package/src/types/instructions/closeDepositBurn.ts +47 -0
  69. package/src/types/instructions/closeRegisterTraits.ts +28 -0
  70. package/src/types/instructions/createCard.ts +56 -0
  71. package/src/types/instructions/createCollection.ts +68 -0
  72. package/src/types/instructions/createPack.ts +71 -0
  73. package/src/types/instructions/createSingle.ts +71 -0
  74. package/src/types/instructions/createStore.ts +50 -0
  75. package/src/types/instructions/createTokenLauncher.ts +82 -0
  76. package/src/types/instructions/createZeroCard.ts +76 -0
  77. package/src/types/instructions/deleteCard.ts +32 -0
  78. package/src/types/instructions/deletePack.ts +40 -0
  79. package/src/types/instructions/deleteSingle.ts +36 -0
  80. package/src/types/instructions/deleteTokenLauncher.ts +38 -0
  81. package/src/types/instructions/depositBurn.ts +55 -0
  82. package/src/types/instructions/donateUser.ts +84 -0
  83. package/src/types/instructions/feedPool.ts +61 -0
  84. package/src/types/instructions/feedTraits.ts +44 -0
  85. package/src/types/instructions/feedTree.ts +63 -0
  86. package/src/types/instructions/flagPack.ts +50 -0
  87. package/src/types/instructions/flagSingle.ts +47 -0
  88. package/src/types/instructions/gatePay.ts +59 -0
  89. package/src/types/instructions/index.ts +140 -0
  90. package/src/types/instructions/initialize.ts +46 -0
  91. package/src/types/instructions/openPack.ts +79 -0
  92. package/src/types/instructions/prepareCreator.ts +30 -0
  93. package/src/types/instructions/preparePack.ts +51 -0
  94. package/src/types/instructions/prepareTraits.ts +28 -0
  95. package/src/types/instructions/printPack.ts +95 -0
  96. package/src/types/instructions/printSingle.ts +108 -0
  97. package/src/types/instructions/recoverDepositBurn.ts +80 -0
  98. package/src/types/instructions/registerActivity.ts +43 -0
  99. package/src/types/instructions/registerCollector.ts +63 -0
  100. package/src/types/instructions/registerCreator.ts +48 -0
  101. package/src/types/instructions/registerGenericUser.ts +94 -0
  102. package/src/types/instructions/registerPackUploads.ts +44 -0
  103. package/src/types/instructions/registerTraits.ts +42 -0
  104. package/src/types/instructions/registerUser.ts +50 -0
  105. package/src/types/instructions/storeLutFor.ts +44 -0
  106. package/src/types/instructions/unwrapAndDestroy.ts +56 -0
  107. package/src/types/instructions/updateCard.ts +54 -0
  108. package/src/types/instructions/updatePack.ts +71 -0
  109. package/src/types/instructions/updateSingle.ts +64 -0
  110. package/src/types/instructions/updateStore.ts +47 -0
  111. package/src/types/instructions/withdrawFromStore.ts +26 -0
  112. package/src/types/programId.ts +42 -0
  113. package/src/types/types/AccountClass.ts +868 -0
  114. package/src/types/types/AccountHasher.ts +89 -0
  115. package/src/types/types/ActionAfter.ts +202 -0
  116. package/src/types/types/AllowedCurrencyArgs.ts +53 -0
  117. package/src/types/types/AuthorityGateTypes.ts +90 -0
  118. package/src/types/types/BurnCount.ts +60 -0
  119. package/src/types/types/BurnState.ts +88 -0
  120. package/src/types/types/BurnTrack.ts +64 -0
  121. package/src/types/types/BurnType.ts +118 -0
  122. package/src/types/types/BurnTypeBurn.ts +56 -0
  123. package/src/types/types/BuyHistoryClass.ts +90 -0
  124. package/src/types/types/CardClass.ts +56 -0
  125. package/src/types/types/CardState.ts +238 -0
  126. package/src/types/types/CardTrack.ts +76 -0
  127. package/src/types/types/Category.ts +72 -0
  128. package/src/types/types/CnftData.ts +85 -0
  129. package/src/types/types/CollectTrack.ts +61 -0
  130. package/src/types/types/Collection.ts +64 -0
  131. package/src/types/types/CompactCnftData.ts +76 -0
  132. package/src/types/types/CoolTimePerAmountArgs.ts +72 -0
  133. package/src/types/types/Creator.ts +72 -0
  134. package/src/types/types/CreatorGateArgs.ts +53 -0
  135. package/src/types/types/CurrencyArtistProof.ts +85 -0
  136. package/src/types/types/CurrencyType.ts +259 -0
  137. package/src/types/types/DateTraitInit.ts +61 -0
  138. package/src/types/types/DateTraitInitMap.ts +72 -0
  139. package/src/types/types/Deposit.ts +85 -0
  140. package/src/types/types/DepositFormat.ts +90 -0
  141. package/src/types/types/DepositState.ts +88 -0
  142. package/src/types/types/DepositSubtype.ts +90 -0
  143. package/src/types/types/DepositTrack.ts +69 -0
  144. package/src/types/types/DepositTrackType.ts +120 -0
  145. package/src/types/types/DepositType.ts +245 -0
  146. package/src/types/types/Earnings.ts +37 -0
  147. package/src/types/types/EditionStoreType.ts +120 -0
  148. package/src/types/types/EncryptedPayload.ts +61 -0
  149. package/src/types/types/ExtraParameter.ts +117 -0
  150. package/src/types/types/FakeBurnCount.ts +64 -0
  151. package/src/types/types/FakeDeposit.ts +64 -0
  152. package/src/types/types/FakeTraitPair.ts +61 -0
  153. package/src/types/types/FakeTraitValue.ts +61 -0
  154. package/src/types/types/FakeVolumeTrack.ts +64 -0
  155. package/src/types/types/FeeType.ts +118 -0
  156. package/src/types/types/FeedingTraits.ts +57 -0
  157. package/src/types/types/Filter.ts +64 -0
  158. package/src/types/types/FilterType.ts +56 -0
  159. package/src/types/types/GeneralStore.ts +56 -0
  160. package/src/types/types/GenericStore.ts +64 -0
  161. package/src/types/types/GenericValue.ts +172 -0
  162. package/src/types/types/GlobalFee.ts +85 -0
  163. package/src/types/types/GlobalState.ts +148 -0
  164. package/src/types/types/IndexDate.ts +94 -0
  165. package/src/types/types/IndexDates.ts +64 -0
  166. package/src/types/types/Item.ts +53 -0
  167. package/src/types/types/ItemClass.ts +88 -0
  168. package/src/types/types/ItemState.ts +298 -0
  169. package/src/types/types/ItemTrack.ts +76 -0
  170. package/src/types/types/ListingPerWalletArgs.ts +53 -0
  171. package/src/types/types/MemeVaultProof.ts +64 -0
  172. package/src/types/types/MetadataArgs.ts +207 -0
  173. package/src/types/types/NonFungibleTraitInit.ts +64 -0
  174. package/src/types/types/NonFungibleTraitInitMap.ts +84 -0
  175. package/src/types/types/OnlyBetweenTimesArgs.ts +76 -0
  176. package/src/types/types/OnlyTheseDOWArgs.ts +53 -0
  177. package/src/types/types/PackConfig.ts +98 -0
  178. package/src/types/types/PackOpenHolderState.ts +120 -0
  179. package/src/types/types/PackRule.ts +85 -0
  180. package/src/types/types/PackState.ts +118 -0
  181. package/src/types/types/PackType.ts +118 -0
  182. package/src/types/types/PaymentClass.ts +118 -0
  183. package/src/types/types/PoolAccess.ts +88 -0
  184. package/src/types/types/PoolState.ts +88 -0
  185. package/src/types/types/PoolType.ts +88 -0
  186. package/src/types/types/Popularity.ts +76 -0
  187. package/src/types/types/PopularityState.ts +630 -0
  188. package/src/types/types/PreviousDonationRecord.ts +76 -0
  189. package/src/types/types/Price.ts +64 -0
  190. package/src/types/types/PriceRule.ts +216 -0
  191. package/src/types/types/RecoverDeposit.ts +56 -0
  192. package/src/types/types/Rule.ts +199 -0
  193. package/src/types/types/SaleConfig.ts +102 -0
  194. package/src/types/types/SaleTrack.ts +85 -0
  195. package/src/types/types/SaleType.ts +148 -0
  196. package/src/types/types/Seed.ts +61 -0
  197. package/src/types/types/SelectedCard.ts +61 -0
  198. package/src/types/types/SelectedZeroCard.ts +61 -0
  199. package/src/types/types/SemiFungibleTraitInit.ts +61 -0
  200. package/src/types/types/SemiFungibleTraitInitMap.ts +72 -0
  201. package/src/types/types/ShortCreator.ts +64 -0
  202. package/src/types/types/ShortMetadata.ts +145 -0
  203. package/src/types/types/ShortMetadataArgs.ts +111 -0
  204. package/src/types/types/StoreConfig.ts +98 -0
  205. package/src/types/types/StoreRule.ts +145 -0
  206. package/src/types/types/SuperCategory.ts +61 -0
  207. package/src/types/types/TightCardMetadata.ts +120 -0
  208. package/src/types/types/TimeRangeType.ts +120 -0
  209. package/src/types/types/TimedPerWalletArgs.ts +53 -0
  210. package/src/types/types/TokenMetadata.ts +72 -0
  211. package/src/types/types/TokenProgramVersion.ts +90 -0
  212. package/src/types/types/TokenStandard.ts +150 -0
  213. package/src/types/types/TokenState.ts +88 -0
  214. package/src/types/types/TokenType.ts +88 -0
  215. package/src/types/types/TotalPerTimeArgs.ts +85 -0
  216. package/src/types/types/TotalPerTimeWalletArgs.ts +61 -0
  217. package/src/types/types/TrackRegistry.ts +90 -0
  218. package/src/types/types/TraitInit.ts +210 -0
  219. package/src/types/types/TraitPass.ts +60 -0
  220. package/src/types/types/TraitPassType.ts +225 -0
  221. package/src/types/types/TraitType.ts +267 -0
  222. package/src/types/types/TraitValue.ts +72 -0
  223. package/src/types/types/UnlocksAfter.ts +172 -0
  224. package/src/types/types/UnwrapMetadata.ts +156 -0
  225. package/src/types/types/UseMethod.ts +118 -0
  226. package/src/types/types/Uses.ts +76 -0
  227. package/src/types/types/VerifyCollectionMetadata.ts +109 -0
  228. package/src/types/types/VolumeTrack.ts +61 -0
  229. package/src/types/types/WrappedSource.ts +85 -0
  230. package/src/types/types/ZeroConfig.ts +85 -0
  231. package/src/types/types/index.ts +798 -0
  232. package/src/utility/Connection.ts +9 -0
  233. package/src/utility/Holders.ts +8 -0
  234. package/src/utility/PdaManager.ts +230 -0
  235. package/src/utility/config.ts +32 -0
  236. package/src/utility/utils.ts +191 -0
  237. package/src/utility/validation.ts +229 -0
  238. package/tsconfig.json +12 -0
@@ -0,0 +1,180 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface StoreFields {
8
+ class: types.AccountClassKind
9
+ holder: PublicKey
10
+ creator: PublicKey
11
+ page: BN
12
+ count: BN
13
+ live: BN
14
+ name: string
15
+ config: types.StoreConfigFields
16
+ storeId: number
17
+ globalFee: types.GlobalFeeFields | null
18
+ globalDeposit: BN
19
+ cacheHolder: Array<number>
20
+ }
21
+
22
+ export interface StoreJSON {
23
+ class: types.AccountClassJSON
24
+ holder: string
25
+ creator: string
26
+ page: string
27
+ count: string
28
+ live: string
29
+ name: string
30
+ config: types.StoreConfigJSON
31
+ storeId: number
32
+ globalFee: types.GlobalFeeJSON | null
33
+ globalDeposit: string
34
+ cacheHolder: Array<number>
35
+ }
36
+
37
+ export class Store {
38
+ readonly class: types.AccountClassKind
39
+ readonly holder: PublicKey
40
+ readonly creator: PublicKey
41
+ readonly page: BN
42
+ readonly count: BN
43
+ readonly live: BN
44
+ readonly name: string
45
+ readonly config: types.StoreConfig
46
+ readonly storeId: number
47
+ readonly globalFee: types.GlobalFee | null
48
+ readonly globalDeposit: BN
49
+ readonly cacheHolder: Array<number>
50
+
51
+ static readonly discriminator = Buffer.from([
52
+ 130, 48, 247, 244, 182, 191, 30, 26,
53
+ ])
54
+
55
+ static readonly layout = borsh.struct([
56
+ types.AccountClass.layout("class"),
57
+ borsh.publicKey("holder"),
58
+ borsh.publicKey("creator"),
59
+ borsh.u64("page"),
60
+ borsh.u64("count"),
61
+ borsh.u64("live"),
62
+ borsh.str("name"),
63
+ types.StoreConfig.layout("config"),
64
+ borsh.u16("storeId"),
65
+ borsh.option(types.GlobalFee.layout(), "globalFee"),
66
+ borsh.u64("globalDeposit"),
67
+ borsh.array(borsh.u8(), 128, "cacheHolder"),
68
+ ])
69
+
70
+ constructor(fields: StoreFields) {
71
+ this.class = fields.class
72
+ this.holder = fields.holder
73
+ this.creator = fields.creator
74
+ this.page = fields.page
75
+ this.count = fields.count
76
+ this.live = fields.live
77
+ this.name = fields.name
78
+ this.config = new types.StoreConfig({ ...fields.config })
79
+ this.storeId = fields.storeId
80
+ this.globalFee =
81
+ (fields.globalFee && new types.GlobalFee({ ...fields.globalFee })) || null
82
+ this.globalDeposit = fields.globalDeposit
83
+ this.cacheHolder = fields.cacheHolder
84
+ }
85
+
86
+ static async fetch(
87
+ c: Connection,
88
+ address: PublicKey,
89
+ programId: PublicKey = PROGRAM_ID
90
+ ): Promise<Store | null> {
91
+ const info = await c.getAccountInfo(address)
92
+
93
+ if (info === null) {
94
+ return null
95
+ }
96
+ if (!info.owner.equals(programId)) {
97
+ throw new Error("account doesn't belong to this program")
98
+ }
99
+
100
+ return this.decode(info.data)
101
+ }
102
+
103
+ static async fetchMultiple(
104
+ c: Connection,
105
+ addresses: PublicKey[],
106
+ programId: PublicKey = PROGRAM_ID
107
+ ): Promise<Array<Store | null>> {
108
+ const infos = await c.getMultipleAccountsInfo(addresses)
109
+
110
+ return infos.map((info) => {
111
+ if (info === null) {
112
+ return null
113
+ }
114
+ if (!info.owner.equals(programId)) {
115
+ throw new Error("account doesn't belong to this program")
116
+ }
117
+
118
+ return this.decode(info.data)
119
+ })
120
+ }
121
+
122
+ static decode(data: Buffer): Store {
123
+ if (!data.slice(0, 8).equals(Store.discriminator)) {
124
+ throw new Error("invalid account discriminator")
125
+ }
126
+
127
+ const dec = Store.layout.decode(data.slice(8))
128
+
129
+ return new Store({
130
+ class: types.AccountClass.fromDecoded(dec.class),
131
+ holder: dec.holder,
132
+ creator: dec.creator,
133
+ page: dec.page,
134
+ count: dec.count,
135
+ live: dec.live,
136
+ name: dec.name,
137
+ config: types.StoreConfig.fromDecoded(dec.config),
138
+ storeId: dec.storeId,
139
+ globalFee:
140
+ (dec.globalFee && types.GlobalFee.fromDecoded(dec.globalFee)) || null,
141
+ globalDeposit: dec.globalDeposit,
142
+ cacheHolder: dec.cacheHolder,
143
+ })
144
+ }
145
+
146
+ toJSON(): StoreJSON {
147
+ return {
148
+ class: this.class.toJSON(),
149
+ holder: this.holder.toString(),
150
+ creator: this.creator.toString(),
151
+ page: this.page.toString(),
152
+ count: this.count.toString(),
153
+ live: this.live.toString(),
154
+ name: this.name,
155
+ config: this.config.toJSON(),
156
+ storeId: this.storeId,
157
+ globalFee: (this.globalFee && this.globalFee.toJSON()) || null,
158
+ globalDeposit: this.globalDeposit.toString(),
159
+ cacheHolder: this.cacheHolder,
160
+ }
161
+ }
162
+
163
+ static fromJSON(obj: StoreJSON): Store {
164
+ return new Store({
165
+ class: types.AccountClass.fromJSON(obj.class),
166
+ holder: new PublicKey(obj.holder),
167
+ creator: new PublicKey(obj.creator),
168
+ page: new BN(obj.page),
169
+ count: new BN(obj.count),
170
+ live: new BN(obj.live),
171
+ name: obj.name,
172
+ config: types.StoreConfig.fromJSON(obj.config),
173
+ storeId: obj.storeId,
174
+ globalFee:
175
+ (obj.globalFee && types.GlobalFee.fromJSON(obj.globalFee)) || null,
176
+ globalDeposit: new BN(obj.globalDeposit),
177
+ cacheHolder: obj.cacheHolder,
178
+ })
179
+ }
180
+ }
@@ -0,0 +1,131 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface StoresHolderFields {
8
+ class: types.AccountClassKind
9
+ slot: BN
10
+ creator: PublicKey
11
+ count: BN
12
+ defaultGlobalFee: types.GlobalFeeFields | null
13
+ }
14
+
15
+ export interface StoresHolderJSON {
16
+ class: types.AccountClassJSON
17
+ slot: string
18
+ creator: string
19
+ count: string
20
+ defaultGlobalFee: types.GlobalFeeJSON | null
21
+ }
22
+
23
+ export class StoresHolder {
24
+ readonly class: types.AccountClassKind
25
+ readonly slot: BN
26
+ readonly creator: PublicKey
27
+ readonly count: BN
28
+ readonly defaultGlobalFee: types.GlobalFee | null
29
+
30
+ static readonly discriminator = Buffer.from([
31
+ 237, 16, 131, 248, 150, 182, 165, 234,
32
+ ])
33
+
34
+ static readonly layout = borsh.struct([
35
+ types.AccountClass.layout("class"),
36
+ borsh.u64("slot"),
37
+ borsh.publicKey("creator"),
38
+ borsh.u64("count"),
39
+ borsh.option(types.GlobalFee.layout(), "defaultGlobalFee"),
40
+ ])
41
+
42
+ constructor(fields: StoresHolderFields) {
43
+ this.class = fields.class
44
+ this.slot = fields.slot
45
+ this.creator = fields.creator
46
+ this.count = fields.count
47
+ this.defaultGlobalFee =
48
+ (fields.defaultGlobalFee &&
49
+ new types.GlobalFee({ ...fields.defaultGlobalFee })) ||
50
+ null
51
+ }
52
+
53
+ static async fetch(
54
+ c: Connection,
55
+ address: PublicKey,
56
+ programId: PublicKey = PROGRAM_ID
57
+ ): Promise<StoresHolder | null> {
58
+ const info = await c.getAccountInfo(address)
59
+
60
+ if (info === null) {
61
+ return null
62
+ }
63
+ if (!info.owner.equals(programId)) {
64
+ throw new Error("account doesn't belong to this program")
65
+ }
66
+
67
+ return this.decode(info.data)
68
+ }
69
+
70
+ static async fetchMultiple(
71
+ c: Connection,
72
+ addresses: PublicKey[],
73
+ programId: PublicKey = PROGRAM_ID
74
+ ): Promise<Array<StoresHolder | null>> {
75
+ const infos = await c.getMultipleAccountsInfo(addresses)
76
+
77
+ return infos.map((info) => {
78
+ if (info === null) {
79
+ return null
80
+ }
81
+ if (!info.owner.equals(programId)) {
82
+ throw new Error("account doesn't belong to this program")
83
+ }
84
+
85
+ return this.decode(info.data)
86
+ })
87
+ }
88
+
89
+ static decode(data: Buffer): StoresHolder {
90
+ if (!data.slice(0, 8).equals(StoresHolder.discriminator)) {
91
+ throw new Error("invalid account discriminator")
92
+ }
93
+
94
+ const dec = StoresHolder.layout.decode(data.slice(8))
95
+
96
+ return new StoresHolder({
97
+ class: types.AccountClass.fromDecoded(dec.class),
98
+ slot: dec.slot,
99
+ creator: dec.creator,
100
+ count: dec.count,
101
+ defaultGlobalFee:
102
+ (dec.defaultGlobalFee &&
103
+ types.GlobalFee.fromDecoded(dec.defaultGlobalFee)) ||
104
+ null,
105
+ })
106
+ }
107
+
108
+ toJSON(): StoresHolderJSON {
109
+ return {
110
+ class: this.class.toJSON(),
111
+ slot: this.slot.toString(),
112
+ creator: this.creator.toString(),
113
+ count: this.count.toString(),
114
+ defaultGlobalFee:
115
+ (this.defaultGlobalFee && this.defaultGlobalFee.toJSON()) || null,
116
+ }
117
+ }
118
+
119
+ static fromJSON(obj: StoresHolderJSON): StoresHolder {
120
+ return new StoresHolder({
121
+ class: types.AccountClass.fromJSON(obj.class),
122
+ slot: new BN(obj.slot),
123
+ creator: new PublicKey(obj.creator),
124
+ count: new BN(obj.count),
125
+ defaultGlobalFee:
126
+ (obj.defaultGlobalFee &&
127
+ types.GlobalFee.fromJSON(obj.defaultGlobalFee)) ||
128
+ null,
129
+ })
130
+ }
131
+ }
@@ -0,0 +1,189 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface ThreeIdFields {
8
+ class: types.AccountClassKind
9
+ holderHash: BN
10
+ creator: PublicKey
11
+ lutAccount: PublicKey
12
+ points1: BN
13
+ points2: BN
14
+ coin1: number
15
+ coin2: number
16
+ settings: Array<number>
17
+ subwallets: Array<PublicKey>
18
+ username: string
19
+ generalStore: Array<types.GeneralStoreKind>
20
+ extra: Array<number>
21
+ }
22
+
23
+ export interface ThreeIdJSON {
24
+ class: types.AccountClassJSON
25
+ holderHash: string
26
+ creator: string
27
+ lutAccount: string
28
+ points1: string
29
+ points2: string
30
+ coin1: number
31
+ coin2: number
32
+ settings: Array<number>
33
+ subwallets: Array<string>
34
+ username: string
35
+ generalStore: Array<types.GeneralStoreJSON>
36
+ extra: Array<number>
37
+ }
38
+
39
+ export class ThreeId {
40
+ readonly class: types.AccountClassKind
41
+ readonly holderHash: BN
42
+ readonly creator: PublicKey
43
+ readonly lutAccount: PublicKey
44
+ readonly points1: BN
45
+ readonly points2: BN
46
+ readonly coin1: number
47
+ readonly coin2: number
48
+ readonly settings: Array<number>
49
+ readonly subwallets: Array<PublicKey>
50
+ readonly username: string
51
+ readonly generalStore: Array<types.GeneralStoreKind>
52
+ readonly extra: Array<number>
53
+
54
+ static readonly discriminator = Buffer.from([123, 56, 150, 21, 8, 4, 144, 81])
55
+
56
+ static readonly layout = borsh.struct([
57
+ types.AccountClass.layout("class"),
58
+ borsh.u64("holderHash"),
59
+ borsh.publicKey("creator"),
60
+ borsh.publicKey("lutAccount"),
61
+ borsh.u64("points1"),
62
+ borsh.u64("points2"),
63
+ borsh.u32("coin1"),
64
+ borsh.u32("coin2"),
65
+ borsh.array(borsh.u8(), 8, "settings"),
66
+ borsh.vec(borsh.publicKey(), "subwallets"),
67
+ borsh.str("username"),
68
+ borsh.vec(types.GeneralStore.layout(), "generalStore"),
69
+ borsh.array(borsh.u8(), 32, "extra"),
70
+ ])
71
+
72
+ constructor(fields: ThreeIdFields) {
73
+ this.class = fields.class
74
+ this.holderHash = fields.holderHash
75
+ this.creator = fields.creator
76
+ this.lutAccount = fields.lutAccount
77
+ this.points1 = fields.points1
78
+ this.points2 = fields.points2
79
+ this.coin1 = fields.coin1
80
+ this.coin2 = fields.coin2
81
+ this.settings = fields.settings
82
+ this.subwallets = fields.subwallets
83
+ this.username = fields.username
84
+ this.generalStore = fields.generalStore
85
+ this.extra = fields.extra
86
+ }
87
+
88
+ static async fetch(
89
+ c: Connection,
90
+ address: PublicKey,
91
+ programId: PublicKey = PROGRAM_ID
92
+ ): Promise<ThreeId | null> {
93
+ const info = await c.getAccountInfo(address)
94
+
95
+ if (info === null) {
96
+ return null
97
+ }
98
+ if (!info.owner.equals(programId)) {
99
+ throw new Error("account doesn't belong to this program")
100
+ }
101
+
102
+ return this.decode(info.data)
103
+ }
104
+
105
+ static async fetchMultiple(
106
+ c: Connection,
107
+ addresses: PublicKey[],
108
+ programId: PublicKey = PROGRAM_ID
109
+ ): Promise<Array<ThreeId | null>> {
110
+ const infos = await c.getMultipleAccountsInfo(addresses)
111
+
112
+ return infos.map((info) => {
113
+ if (info === null) {
114
+ return null
115
+ }
116
+ if (!info.owner.equals(programId)) {
117
+ throw new Error("account doesn't belong to this program")
118
+ }
119
+
120
+ return this.decode(info.data)
121
+ })
122
+ }
123
+
124
+ static decode(data: Buffer): ThreeId {
125
+ if (!data.slice(0, 8).equals(ThreeId.discriminator)) {
126
+ throw new Error("invalid account discriminator")
127
+ }
128
+
129
+ const dec = ThreeId.layout.decode(data.slice(8))
130
+
131
+ return new ThreeId({
132
+ class: types.AccountClass.fromDecoded(dec.class),
133
+ holderHash: dec.holderHash,
134
+ creator: dec.creator,
135
+ lutAccount: dec.lutAccount,
136
+ points1: dec.points1,
137
+ points2: dec.points2,
138
+ coin1: dec.coin1,
139
+ coin2: dec.coin2,
140
+ settings: dec.settings,
141
+ subwallets: dec.subwallets,
142
+ username: dec.username,
143
+ generalStore: dec.generalStore.map(
144
+ (
145
+ item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */
146
+ ) => types.GeneralStore.fromDecoded(item)
147
+ ),
148
+ extra: dec.extra,
149
+ })
150
+ }
151
+
152
+ toJSON(): ThreeIdJSON {
153
+ return {
154
+ class: this.class.toJSON(),
155
+ holderHash: this.holderHash.toString(),
156
+ creator: this.creator.toString(),
157
+ lutAccount: this.lutAccount.toString(),
158
+ points1: this.points1.toString(),
159
+ points2: this.points2.toString(),
160
+ coin1: this.coin1,
161
+ coin2: this.coin2,
162
+ settings: this.settings,
163
+ subwallets: this.subwallets.map((item) => item.toString()),
164
+ username: this.username,
165
+ generalStore: this.generalStore.map((item) => item.toJSON()),
166
+ extra: this.extra,
167
+ }
168
+ }
169
+
170
+ static fromJSON(obj: ThreeIdJSON): ThreeId {
171
+ return new ThreeId({
172
+ class: types.AccountClass.fromJSON(obj.class),
173
+ holderHash: new BN(obj.holderHash),
174
+ creator: new PublicKey(obj.creator),
175
+ lutAccount: new PublicKey(obj.lutAccount),
176
+ points1: new BN(obj.points1),
177
+ points2: new BN(obj.points2),
178
+ coin1: obj.coin1,
179
+ coin2: obj.coin2,
180
+ settings: obj.settings,
181
+ subwallets: obj.subwallets.map((item) => new PublicKey(item)),
182
+ username: obj.username,
183
+ generalStore: obj.generalStore.map((item) =>
184
+ types.GeneralStore.fromJSON(item)
185
+ ),
186
+ extra: obj.extra,
187
+ })
188
+ }
189
+ }
@@ -0,0 +1,217 @@
1
+ import { PublicKey, Connection } from "@solana/web3.js"
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from "../programId"
6
+
7
+ export interface TokenManagerFields {
8
+ class: types.AccountClassKind
9
+ storeHash: BN
10
+ tokenType: types.TokenTypeKind
11
+ state: types.TokenStateKind
12
+ currency: PublicKey
13
+ creator: PublicKey
14
+ communityShare: number
15
+ name: string
16
+ base: BN
17
+ price: BN
18
+ supply: BN
19
+ created: BN
20
+ pool: BN
21
+ pending: BN
22
+ taxes: Array<number>
23
+ options: Array<number>
24
+ extra: Array<number>
25
+ }
26
+
27
+ export interface TokenManagerJSON {
28
+ class: types.AccountClassJSON
29
+ storeHash: string
30
+ tokenType: types.TokenTypeJSON
31
+ state: types.TokenStateJSON
32
+ currency: string
33
+ creator: string
34
+ communityShare: number
35
+ name: string
36
+ base: string
37
+ price: string
38
+ supply: string
39
+ created: string
40
+ pool: string
41
+ pending: string
42
+ taxes: Array<number>
43
+ options: Array<number>
44
+ extra: Array<number>
45
+ }
46
+
47
+ export class TokenManager {
48
+ readonly class: types.AccountClassKind
49
+ readonly storeHash: BN
50
+ readonly tokenType: types.TokenTypeKind
51
+ readonly state: types.TokenStateKind
52
+ readonly currency: PublicKey
53
+ readonly creator: PublicKey
54
+ readonly communityShare: number
55
+ readonly name: string
56
+ readonly base: BN
57
+ readonly price: BN
58
+ readonly supply: BN
59
+ readonly created: BN
60
+ readonly pool: BN
61
+ readonly pending: BN
62
+ readonly taxes: Array<number>
63
+ readonly options: Array<number>
64
+ readonly extra: Array<number>
65
+
66
+ static readonly discriminator = Buffer.from([
67
+ 185, 97, 124, 231, 70, 75, 228, 47,
68
+ ])
69
+
70
+ static readonly layout = borsh.struct([
71
+ types.AccountClass.layout("class"),
72
+ borsh.u64("storeHash"),
73
+ types.TokenType.layout("tokenType"),
74
+ types.TokenState.layout("state"),
75
+ borsh.publicKey("currency"),
76
+ borsh.publicKey("creator"),
77
+ borsh.u16("communityShare"),
78
+ borsh.str("name"),
79
+ borsh.u64("base"),
80
+ borsh.u64("price"),
81
+ borsh.u64("supply"),
82
+ borsh.u64("created"),
83
+ borsh.u64("pool"),
84
+ borsh.u64("pending"),
85
+ borsh.array(borsh.u16(), 4, "taxes"),
86
+ borsh.array(borsh.u8(), 8, "options"),
87
+ borsh.array(borsh.u8(), 64, "extra"),
88
+ ])
89
+
90
+ constructor(fields: TokenManagerFields) {
91
+ this.class = fields.class
92
+ this.storeHash = fields.storeHash
93
+ this.tokenType = fields.tokenType
94
+ this.state = fields.state
95
+ this.currency = fields.currency
96
+ this.creator = fields.creator
97
+ this.communityShare = fields.communityShare
98
+ this.name = fields.name
99
+ this.base = fields.base
100
+ this.price = fields.price
101
+ this.supply = fields.supply
102
+ this.created = fields.created
103
+ this.pool = fields.pool
104
+ this.pending = fields.pending
105
+ this.taxes = fields.taxes
106
+ this.options = fields.options
107
+ this.extra = fields.extra
108
+ }
109
+
110
+ static async fetch(
111
+ c: Connection,
112
+ address: PublicKey,
113
+ programId: PublicKey = PROGRAM_ID
114
+ ): Promise<TokenManager | null> {
115
+ const info = await c.getAccountInfo(address)
116
+
117
+ if (info === null) {
118
+ return null
119
+ }
120
+ if (!info.owner.equals(programId)) {
121
+ throw new Error("account doesn't belong to this program")
122
+ }
123
+
124
+ return this.decode(info.data)
125
+ }
126
+
127
+ static async fetchMultiple(
128
+ c: Connection,
129
+ addresses: PublicKey[],
130
+ programId: PublicKey = PROGRAM_ID
131
+ ): Promise<Array<TokenManager | null>> {
132
+ const infos = await c.getMultipleAccountsInfo(addresses)
133
+
134
+ return infos.map((info) => {
135
+ if (info === null) {
136
+ return null
137
+ }
138
+ if (!info.owner.equals(programId)) {
139
+ throw new Error("account doesn't belong to this program")
140
+ }
141
+
142
+ return this.decode(info.data)
143
+ })
144
+ }
145
+
146
+ static decode(data: Buffer): TokenManager {
147
+ if (!data.slice(0, 8).equals(TokenManager.discriminator)) {
148
+ throw new Error("invalid account discriminator")
149
+ }
150
+
151
+ const dec = TokenManager.layout.decode(data.slice(8))
152
+
153
+ return new TokenManager({
154
+ class: types.AccountClass.fromDecoded(dec.class),
155
+ storeHash: dec.storeHash,
156
+ tokenType: types.TokenType.fromDecoded(dec.tokenType),
157
+ state: types.TokenState.fromDecoded(dec.state),
158
+ currency: dec.currency,
159
+ creator: dec.creator,
160
+ communityShare: dec.communityShare,
161
+ name: dec.name,
162
+ base: dec.base,
163
+ price: dec.price,
164
+ supply: dec.supply,
165
+ created: dec.created,
166
+ pool: dec.pool,
167
+ pending: dec.pending,
168
+ taxes: dec.taxes,
169
+ options: dec.options,
170
+ extra: dec.extra,
171
+ })
172
+ }
173
+
174
+ toJSON(): TokenManagerJSON {
175
+ return {
176
+ class: this.class.toJSON(),
177
+ storeHash: this.storeHash.toString(),
178
+ tokenType: this.tokenType.toJSON(),
179
+ state: this.state.toJSON(),
180
+ currency: this.currency.toString(),
181
+ creator: this.creator.toString(),
182
+ communityShare: this.communityShare,
183
+ name: this.name,
184
+ base: this.base.toString(),
185
+ price: this.price.toString(),
186
+ supply: this.supply.toString(),
187
+ created: this.created.toString(),
188
+ pool: this.pool.toString(),
189
+ pending: this.pending.toString(),
190
+ taxes: this.taxes,
191
+ options: this.options,
192
+ extra: this.extra,
193
+ }
194
+ }
195
+
196
+ static fromJSON(obj: TokenManagerJSON): TokenManager {
197
+ return new TokenManager({
198
+ class: types.AccountClass.fromJSON(obj.class),
199
+ storeHash: new BN(obj.storeHash),
200
+ tokenType: types.TokenType.fromJSON(obj.tokenType),
201
+ state: types.TokenState.fromJSON(obj.state),
202
+ currency: new PublicKey(obj.currency),
203
+ creator: new PublicKey(obj.creator),
204
+ communityShare: obj.communityShare,
205
+ name: obj.name,
206
+ base: new BN(obj.base),
207
+ price: new BN(obj.price),
208
+ supply: new BN(obj.supply),
209
+ created: new BN(obj.created),
210
+ pool: new BN(obj.pool),
211
+ pending: new BN(obj.pending),
212
+ taxes: obj.taxes,
213
+ options: obj.options,
214
+ extra: obj.extra,
215
+ })
216
+ }
217
+ }