-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefifaHTMLTokenUriResolver.sol
318 lines (275 loc) · 16.9 KB
/
DefifaHTMLTokenUriResolver.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import "lib/base64/base64.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {IJB721TokenUriResolver} from "@jbx-protocol/juice-721-delegate/contracts/interfaces/IJB721TokenUriResolver.sol";
import {JBIpfsDecoder} from "@jbx-protocol/juice-721-delegate/contracts/libraries/JBIpfsDecoder.sol";
import {IDefifaDelegate} from "./interfaces/IDefifaDelegate.sol";
import {IDefifaTokenUriResolver} from "./interfaces/IDefifaTokenUriResolver.sol";
import {DefifaFontImporter} from "./libraries/DefifaFontImporter.sol";
import {
IScriptyBuilder,
InlineScriptRequest,
WrappedScriptRequest
} from "scripty.sol/contracts/scripty/IScriptyBuilder.sol";
/**
* @title
* DefifaDelegate
*
* @notice
* Defifa default 721 token URI resolver.
*
* @dev
* Adheres to -
* IDefifaTokenUriResolver: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
* IJB721TokenUriResolver: Interface to ensure compatibility with 721Delegates.
*/
// contract DefifaHTMLTokenUriResolver is IDefifaTokenUriResolver, IJB721TokenUriResolver {
// using Strings for uint256;
// //*********************************************************************//
// // -------------------- private constant properties ------------------ //
// //*********************************************************************//
// /**
// * @notice
// * The fidelity of the decimal returned in the NFT image.
// */
// uint256 private constant _IMG_DECIMAL_FIDELITY = 4;
// //*********************************************************************//
// // -------------------- Scripty.sol Kmac hacks ------------------ //
// //*********************************************************************//
// /**
// * @notice
// * somebody that knows more than me should fix this
// */
// address private constant _SCRIPTY_STORAGE_ADDRESS = 0x096451F43800f207FC32B4FF86F286EdaF736eE3;
// address private constant _SCRIPTY_BUILDER_ADDRESS = 0x16b727a2Fc9322C724F4Bc562910c99a5edA5084;
// address private constant _ETHFS_FILESTORAGE_ADDRESS = 0xFc7453dA7bF4d0c739C1c53da57b3636dAb0e11e;
// uint256 public constant BUFFER_SIZE = 1000000;
// //*********************************************************************//
// // --------------------- private stored properties ------------------- //
// //*********************************************************************//
// /**
// * @notice
// * The names of each tier.
// *
// * @dev _tierId The ID of the tier to get a name for.
// */
// mapping(uint256 => string) private _tierNameOf;
// //*********************************************************************//
// // --------------- public immutable stored properties ---------------- //
// //*********************************************************************//
// /**
// * @notice
// * The address of the origin 'DefifaGovernor', used to check in the init if the contract is the original or not
// */
// address public immutable override codeOrigin;
// //*********************************************************************//
// // -------------------- public stored properties --------------------- //
// //*********************************************************************//
// IDefifaDelegate public override delegate;
// ITypeface public override typeface;
// //*********************************************************************//
// // ------------------------- external views -------------------------- //
// //*********************************************************************//
// /**
// * @notice
// * The name of the tier with the specified ID.
// *
// * @param _tierId The ID of the tier to get the name of.
// *
// * @return The tier's name.
// */
// function tierNameOf(uint256 _tierId) external view override returns (string memory) {
// return _tierNameOf[_tierId];
// }
// /**
// * @notice
// * Helper functions for parsing tokenUri to get image ipfs hash. Currently unused.
// *
// * @dev TODO If parsing in sol js must be changed too
// */
// function parseIpfsPath(string memory ipfsPath) internal pure returns (string memory image) {
// bytes memory decoded = bytes(ipfsPath);
// // Extract the name, description, image, and external URL
// image = extractString(bytes(ipfsPath), 64, 96);
// }
// function extractString(bytes memory data, uint256 start, uint256 end) internal pure returns (string memory) {
// bytes memory result = new bytes(end - start);
// for (uint256 i = start; i < end; i++) {
// result[i - start] = data[i];
// }
// return string(result);
// }
// //*********************************************************************//
// // -------------------------- constructor ---------------------------- //
// //*********************************************************************//
// constructor(ITypeface _typeface) {
// codeOrigin = address(this);
// typeface = _typeface;
// }
// //*********************************************************************//
// // ---------------------- external transactions ---------------------- //
// //*********************************************************************//
// /**
// * @notice
// * Initializes the contract.
// *
// * @param _delegate The Defifa delegate contract that this contract is Governing.
// */
// function initialize(IDefifaDelegate _delegate, string[] memory _tierNames) public virtual override {
// // Make the original un-initializable.
// if (address(this) == codeOrigin) revert();
// // Stop re-initialization.
// if (address(delegate) != address(0)) revert();
// delegate = _delegate;
// // Keep a reference to the number of tier names.
// uint256 _numberOfTierNames = _tierNames.length;
// // Set the name for each tier.
// for (uint256 _i; _i < _numberOfTierNames;) {
// // Set the tier name.
// _tierNameOf[_i + 1] = _tierNames[_i];
// unchecked {
// ++_i;
// }
// }
// }
// /**
// * @notice
// * The metadata URI of the provided token ID.
// *
// * @dev
// * Defer to the token's tier IPFS URI if set.
// *
// * @param _tokenId The ID of the token to get the tier URI for.
// *
// * @return The token URI corresponding with the tier.
// */
// function getUri(uint256 _tokenId) external view override returns (string memory) {
// // Keep a reference to the delegate.
// IDefifaDelegate _delegate = delegate;
// // Get a reference to the tier.
// JB721Tier memory _tier = _delegate.store().tierOfTokenId(address(_delegate), _tokenId, false);
// // Scripty builder
// WrappedScriptRequest[] memory requests = new WrappedScriptRequest[](3);
// requests[0].name = "p5-v1.5.0.min.js.gz";
// requests[0].wrapType = 2; // <script type="text/javascript+gzip" src="data:text/javascript;base64,[script]"></script>
// requests[0].contractAddress = _ETHFS_FILESTORAGE_ADDRESS;
// requests[1].name = "gunzipScripts-0.0.1.js";
// requests[1].wrapType = 1; // <script src="data:text/javascript;base64,[script]"></script>
// requests[1].contractAddress = _ETHFS_FILESTORAGE_ADDRESS;
// // Set 'global' variables and add prior to script written in p5.js
// string memory _titleFontSize;
// string memory _title = _delegate.name();
// string memory _team = _tierNameOf[_tier.id];
// if (bytes(_title).length < 35) _titleFontSize = "20";
// else _titleFontSize = "16";
// string memory _fontSize;
// if (bytes(_team).length < 3) _fontSize = "40";
// else if (bytes(_team).length < 5) _fontSize = "40";
// else if (bytes(_team).length < 8) _fontSize = "40";
// else if (bytes(_team).length < 10) _fontSize = "40";
// else if (bytes(_team).length < 12) _fontSize = "40";
// else if (bytes(_team).length < 16) _fontSize = "40";
// else if (bytes(_team).length < 23) _fontSize = "40";
// else if (bytes(_team).length < 30) _fontSize = "30";
// else if (bytes(_team).length < 35) _fontSize = "20";
// else _fontSize = "16";
// // Get the current game phase.
// uint256 _gamePhase = _delegate.fundingCycleStore().currentOf(delegate.projectId()).number;
// string memory _gamePhaseText;
// {
// if (_gamePhase == 0) {
// _gamePhaseText = "Minting starts soon.";
// } else if (_gamePhase == 1) {
// _gamePhaseText = "Starting soon, minting and refunds are open.";
// } else if (_gamePhase == 2) {
// _gamePhaseText = "Starts soon. Last chance for refund.";
// } else if (_gamePhase == 3) {
// _gamePhaseText = "Game in progress.";
// } else if (_gamePhase == 4 && _delegate.redemptionWeightIsSet()) {
// _gamePhaseText = "Scorecard awaiting approval.";
// } else {
// _gamePhaseText = string.concat("Redeem for 0% of the pot.");
// }
// }
// string memory _rarityText;
// {
// uint256 _totalMinted = _tier.initialQuantity - _tier.remainingQuantity;
// if (_gamePhase == 1) {
// _rarityText = string(abi.encodePacked(_totalMinted.toString(), " minted so far"));
// } else {
// _rarityText = string(abi.encodePacked(_totalMinted.toString(), " in existence"));
// }
// }
// bytes32 _encodedTierIPFSUri = _delegate.store().encodedTierIPFSUriOf(address(_delegate), _tokenId);
// string memory artWorkIPFS = _encodedTierIPFSUri.length != 0
// ? JBIpfsDecoder.decode(_delegate.baseURI(), _encodedTierIPFSUri)
// : "QmP5eWnXTsRCWBeDrHboLtFeuhjVLNEHb6np7DiYN7uZyx"; // 404 ipfs img.
// // TODO @dev can we remove this and put into create flow?
// string memory scoreCardIPFS = "QmeB47KfbHetHPpQrPgmD9CxCDb9e2U9j9fxLr1FM3vzMo";
// string memory buttonImageIPFS = "QmdpL1xN4cAHQw4P1FZzw9P3oQofA8h45PfuTTbpV4BbJV";
// bytes memory controllerScript = abi.encodePacked(
// 'let artWorkSource ="',
// artWorkIPFS,
// '";',
// 'let scoreCardIPFS ="',
// scoreCardIPFS,
// '";',
// 'let buttonImageIPFS ="',
// buttonImageIPFS,
// '";',
// 'let txt_1 ="',
// _title,
// '".toUpperCase();let txt_1Size =',
// _titleFontSize,
// ';let txt_1Color = "#17e4f1";let txt_1_x = 40;let txt_1_y = 80;',
// 'let txt_2 ="GAME PHASE ',
// _gamePhase.toString(),
// " of 4",
// '";let txt_2Size = 20;let txt_2Color = "#17e4f1";let txt_2_x = 40;let txt_2_y = 220;',
// 'let txt_3 ="',
// _gamePhaseText,
// '";let txt_3Size = 20;let txt_3Color = "#fea282";let txt_3_x = 40;let txt_3_y = 250;',
// 'let txt_4 ="',
// _team,
// '";let txt_4Size =',
// _fontSize,
// ';let txt_4Color = "#fea282";let txt_4_x = 40;let txt_4_y = 130;',
// 'let txt_5 ="TOKEN ID: ',
// _tokenId.toString(),
// '";let txt_5Size = 16;let txt_5Color = "#FFFFFF";let txt_5_x = 40;let txt_5_y = 370;',
// 'let txt_6 ="RARITY: ',
// _rarityText,
// '";let txt_6Size = 16;let txt_6Color = "#FFFFFF";let txt_6_x = 40;let txt_6_y = 400;',
// 'let font = "data:font/truetype;charset=utf-8;base64,',
// DefifaFontImporter.getSkinnyFontSource(typeface),
// '";',
// // TODO remove line below and put file on chain eg ethfs.xyz, calc buffer size
// 'let page,camLoc,buttL,buttR,timer,buttonImg,pages=[],numOfPages=2,movingRight=!1,movingLeft=!1,isPaused=!1,artWorkPanel="https://jbm.infura-ipfs.io/ipfs/",scoreCardPanel="https://jbm.infura-ipfs.io/ipfs/"+scoreCardIPFS,buttonImage="https://jbm.infura-ipfs.io/ipfs/"+buttonImageIPFS,defifaBlue=[19,228,240],txt1=[[txt_1,txt_1Color,txt_1Size]],txt2=[[txt_2,txt_2Color,txt_2Size]],txt3=[[txt_3,txt_3Color,txt_3Size]],txt4=[[txt_4,txt_4Color,txt_4Size]],txt5=[[txt_5,txt_5Color,txt_5Size]],txt6=[[txt_6,txt_6Color,txt_6Size]],pageImg=[];function preload(){async function a(a){let c=await fetch("https://jbm.infura-ipfs.io/ipfs/"+a);console.log(b);const d=c.headers.get("content-type");console.log(d),d&&-1!==d.indexOf("application/json")?(b=await c.json(),pageImg[0]=loadImage(b.image)):(artWorkPanel="https://jbm.infura-ipfs.io/ipfs/"+a,pageImg[0]=loadImage(artWorkPanel),console.log(artWorkPanel))}let b;a(artWorkSource),pageImg[1]=loadImage(scoreCardPanel),buttonImg=loadImage(buttonImage)}function setup(){myFont=loadFont(font),createCanvas(500,500),camLoc=createVector(0,0);for(let a=0;a<numOfPages;a++)pages[a]=new Page(canvas.width/2*a,0,a,pageImg[a]);timer=canvas.width/2,buttL=new Button(canvas.width/2-90,5,75,75,buttonImg),buttR=new Button(canvas.width/2-90,5,75,75,buttonImg)}function draw(){background(220),slide(),push(),translate(camLoc.x,camLoc.y);for(let a=0;a<numOfPages;a++)pages[a].run();pop(),buttL.run(),buttR.run()}function goRight(){movingLeft||isPaused||(movingRight=!0)}function goLeft(){movingRight||isPaused||(movingLeft=!0)}function slide(){movingRight&&!movingLeft&&0<=timer&&(camLoc.x-=20,timer-=20),movingLeft&&!movingRight&&0<=timer&&(camLoc.x+=20,timer-=20),0==timer&&(movingRight=!1,movingLeft=!1,timer=canvas.width/2),0>=-camLoc.x?(camLoc.x=0,buttL.loc.x=-100):buttL.loc.x=canvas.height/2-75,-camLoc.x>=pages[pages.length-1].loc.x?(timer=canvas.width/2,movingRight=!1,movingLeft=!1,camLoc.x=-pages[pages.length-1].loc.x,buttR.loc.x=-100):buttR.loc.x=canvas.height/2-75}function drawtext(a,b,d){for(var e=a,f=0;f<d.length;++f){var g=d[f],h=g[0],j=g[1],c=g[2],k=textWidth(h);fill(j),textSize(c),text(h,e,b),e+=k}}function mousePressed(){mouseX>buttL.loc.x&&mouseX<buttL.loc.x+buttL.w&&mouseY>buttL.loc.y&&mouseY<buttL.loc.y+buttL.h&&goLeft(),mouseX>buttR.loc.x&&mouseX<buttR.loc.x+buttR.w&&mouseY>buttR.loc.y&&mouseY<buttR.loc.y+buttR.h&&goRight()}class Page{constructor(a,b,c,d){this.loc=createVector(a,b),this.w=canvas.width/2,this.h=canvas.height/2,this.pageNum=c+1,this.img=d}run(){image(this.img,this.loc.x,this.loc.y,500,500),textAlign(LEFT),textFont(myFont),2==this.pageNum&&(drawtext(this.loc.x+txt_1_x,this.loc.y+txt_1_y,txt1),drawtext(this.loc.x+txt_2_x,this.loc.y+txt_2_y,txt2),drawtext(this.loc.x+txt_3_x,this.loc.y+txt_3_y,txt3),drawtext(this.loc.x+txt_4_x,this.loc.y+txt_4_y,txt4),drawtext(this.loc.x+txt_5_x,this.loc.y+txt_5_y,txt5),drawtext(this.loc.x+txt_6_x,this.loc.y+txt_6_y,txt6));3==this.pageNum,line(this.loc.x,this.loc.y,this.loc.x+this.w,this.loc.y),line(this.loc.x,this.loc.y,this.loc.x,this.loc.y+this.h),line(this.loc.x,this.loc.y+this.h,this.loc.x+this.w,this.loc.y+this.h),line(this.loc.x+this.w,this.loc.y,this.loc.x+this.w,this.h)}}class Button{constructor(a,b,c,d,e){this.loc=new createVector(a,b),this.w=c,this.h=d,this.clr="white",this.img=e}run(){this.render(),this.checkMouse()}render(){fill(this.clr),stroke(20),strokeWeight(0),fill("black"),noStroke(),textSize(15),image(this.img,this.loc.x,this.loc.y,this.w,this.h)}checkMouse(){this.clr=mouseX>this.loc.x&&mouseX<this.loc.x+this.w&&mouseY>this.loc.y&&mouseY<this.loc.y+this.h?"gray":"white"}}'
// );
// requests[2].scriptContent = controllerScript;
// //requests[3].name = 'defifa_scorecard_min.0.0.1.js';
// //requests[3].contractAddress = _ETHFS_FILESTORAGE_ADDRESS;
// //requests[3].wrapType = 1;
// // For easier testing, bufferSize for statically stored scripts
// // is injected in the constructor. Then controller script's length
// // is added to that to find the final buffer size.
// uint256 finalBufferSize = BUFFER_SIZE + controllerScript.length;
// // For easier testing, bufferSize is injected in the constructor
// // of this contract.
// bytes memory base64EncodedHTMLDataURI =
// IScriptyBuilder(_SCRIPTY_BUILDER_ADDRESS).getEncodedHTMLWrapped(requests, finalBufferSize);
// bytes memory metadata = abi.encodePacked(
// '{"name":"',
// _title,
// '","description":"Team: ',
// _team,
// ", ID: ",
// _tier.id.toString(),
// '","animation_url":"',
// base64EncodedHTMLDataURI,
// '"}'
// );
// return string(abi.encodePacked("data:application/json;base64,", Base64.encode(metadata)));
// }
// }