@paulstinchcombe/gasless-nft-tx 0.11.3 → 0.12.1

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.
Files changed (20) hide show
  1. package/dist/KAMI-NFTs/KAMI1155CUpgradeable.sol +1069 -0
  2. package/dist/KAMI-NFTs/KAMI721ACUpgradable.sol +949 -0
  3. package/dist/KAMI-NFTs/KAMI721CUpgradeable.sol +691 -0
  4. package/dist/KAMI-NFTs/ProxyAdmin.sol +12 -0
  5. package/dist/KAMI-NFTs/TransparentUpgradeableProxy.sol +15 -0
  6. package/dist/KAMI-NFTs/artifacts/contracts/KAMI1155CUpgradeable.sol/KAMI1155CUpgradeable.dbg.json +4 -0
  7. package/dist/KAMI-NFTs/artifacts/contracts/KAMI1155CUpgradeable.sol/KAMI1155CUpgradeable.json +2207 -0
  8. package/dist/KAMI-NFTs/artifacts/contracts/KAMI721ACUpgradable.sol/KAMI721ACUpgradable.dbg.json +4 -0
  9. package/dist/KAMI-NFTs/artifacts/contracts/KAMI721ACUpgradable.sol/KAMI721ACUpgradable.json +2210 -0
  10. package/dist/KAMI-NFTs/artifacts/contracts/KAMI721CUpgradeable.sol/KAMI721CUpgradeable.dbg.json +4 -0
  11. package/dist/KAMI-NFTs/artifacts/contracts/KAMI721CUpgradeable.sol/KAMI721CUpgradeable.json +1823 -0
  12. package/dist/KAMI-NFTs/artifacts/contracts/ProxyAdmin.sol/KAMIProxyAdmin.dbg.json +4 -0
  13. package/dist/KAMI-NFTs/artifacts/contracts/ProxyAdmin.sol/KAMIProxyAdmin.json +132 -0
  14. package/dist/KAMI-NFTs/artifacts/contracts/TransparentUpgradeableProxy.sol/KAMITransparentUpgradeableProxy.dbg.json +4 -0
  15. package/dist/KAMI-NFTs/artifacts/contracts/TransparentUpgradeableProxy.sol/KAMITransparentUpgradeableProxy.json +116 -0
  16. package/dist/kami-upgrade-manager.d.ts +65 -0
  17. package/dist/kami-upgrade-manager.d.ts.map +1 -0
  18. package/dist/kami-upgrade-manager.js +320 -0
  19. package/dist/kami-upgrade-manager.js.map +1 -0
  20. package/package.json +1 -1
@@ -0,0 +1,4 @@
1
+ {
2
+ "_format": "hh-sol-dbg-1",
3
+ "buildInfo": "../../build-info/c62ec9e1c41c71827acc3bed0f8e94e8.json"
4
+ }
@@ -0,0 +1,132 @@
1
+ {
2
+ "_format": "hh-sol-artifact-1",
3
+ "contractName": "KAMIProxyAdmin",
4
+ "sourceName": "contracts/ProxyAdmin.sol",
5
+ "abi": [
6
+ {
7
+ "inputs": [
8
+ {
9
+ "internalType": "address",
10
+ "name": "owner",
11
+ "type": "address"
12
+ }
13
+ ],
14
+ "stateMutability": "nonpayable",
15
+ "type": "constructor"
16
+ },
17
+ {
18
+ "inputs": [
19
+ {
20
+ "internalType": "address",
21
+ "name": "owner",
22
+ "type": "address"
23
+ }
24
+ ],
25
+ "name": "OwnableInvalidOwner",
26
+ "type": "error"
27
+ },
28
+ {
29
+ "inputs": [
30
+ {
31
+ "internalType": "address",
32
+ "name": "account",
33
+ "type": "address"
34
+ }
35
+ ],
36
+ "name": "OwnableUnauthorizedAccount",
37
+ "type": "error"
38
+ },
39
+ {
40
+ "anonymous": false,
41
+ "inputs": [
42
+ {
43
+ "indexed": true,
44
+ "internalType": "address",
45
+ "name": "previousOwner",
46
+ "type": "address"
47
+ },
48
+ {
49
+ "indexed": true,
50
+ "internalType": "address",
51
+ "name": "newOwner",
52
+ "type": "address"
53
+ }
54
+ ],
55
+ "name": "OwnershipTransferred",
56
+ "type": "event"
57
+ },
58
+ {
59
+ "inputs": [],
60
+ "name": "UPGRADE_INTERFACE_VERSION",
61
+ "outputs": [
62
+ {
63
+ "internalType": "string",
64
+ "name": "",
65
+ "type": "string"
66
+ }
67
+ ],
68
+ "stateMutability": "view",
69
+ "type": "function"
70
+ },
71
+ {
72
+ "inputs": [],
73
+ "name": "owner",
74
+ "outputs": [
75
+ {
76
+ "internalType": "address",
77
+ "name": "",
78
+ "type": "address"
79
+ }
80
+ ],
81
+ "stateMutability": "view",
82
+ "type": "function"
83
+ },
84
+ {
85
+ "inputs": [],
86
+ "name": "renounceOwnership",
87
+ "outputs": [],
88
+ "stateMutability": "nonpayable",
89
+ "type": "function"
90
+ },
91
+ {
92
+ "inputs": [
93
+ {
94
+ "internalType": "address",
95
+ "name": "newOwner",
96
+ "type": "address"
97
+ }
98
+ ],
99
+ "name": "transferOwnership",
100
+ "outputs": [],
101
+ "stateMutability": "nonpayable",
102
+ "type": "function"
103
+ },
104
+ {
105
+ "inputs": [
106
+ {
107
+ "internalType": "contract ITransparentUpgradeableProxy",
108
+ "name": "proxy",
109
+ "type": "address"
110
+ },
111
+ {
112
+ "internalType": "address",
113
+ "name": "implementation",
114
+ "type": "address"
115
+ },
116
+ {
117
+ "internalType": "bytes",
118
+ "name": "data",
119
+ "type": "bytes"
120
+ }
121
+ ],
122
+ "name": "upgradeAndCall",
123
+ "outputs": [],
124
+ "stateMutability": "payable",
125
+ "type": "function"
126
+ }
127
+ ],
128
+ "bytecode": "0x6080346100bb57601f61047738819003918201601f19168301916001600160401b038311848410176100c0578084926020946040528339810103126100bb57516001600160a01b0390818116908190036100bb5780156100a257600080546001600160a01b03198116831782556040519316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a36103a090816100d78239f35b604051631e4fbdf760e01b815260006004820152602490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe60406080815260048036101561001457600080fd5b600091823560e01c8063715018a6146102bf5780638da5cb5b146102935780639623609d1461014a578063ad3cb1cc146100d85763f2fde38b1461005757600080fd5b346100d45760203660031901126100d4576001600160a01b038235818116939192908490036100cf57610088610347565b83156100b95750506000548260018060a01b031982161760005516600080516020610374833981519152600080a380f35b51631e4fbdf760e01b8152908101849052602490fd5b600080fd5b8280fd5b508234610147578060031936011261014757508051908181016001600160401b038111838210176101325761012e9350815260058252640352e302e360dc1b602083015251918291602083526020830190610307565b0390f35b604184634e487b7160e01b6000525260246000fd5b80fd5b5060603660031901126100d4576001600160a01b03918035838116919082900361026357602491823594851680950361028f576001600160401b03906044359082821161028b573660238301121561028b578184013583811161027957865192601f8201601f19908116603f011684018581118582101761026757885281845289939291903682820189011161026357818592896020930183870137840101526101f2610347565b803b156100d45761022297875180998194829363278f794360e11b8452898401528a8a8401526044830190610307565b039134905af1801561025957610236578580f35b84116102485750505238808080808580f35b634e487b7160e01b85526041905283fd5b84513d88823e3d90fd5b8480fd5b634e487b7160e01b8b5260418752878bfd5b634e487b7160e01b8952604185528589fd5b8780fd5b8580fd5b8382346102bb57816003193601126102bb57905490516001600160a01b039091168152602090f35b5080fd5b83346101475780600319360112610147576102d8610347565b80546001600160a01b03198116825581906001600160a01b03166000805160206103748339815191528280a380f35b919082519283825260005b848110610333575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610312565b6000546001600160a01b0316330361035b57565b60405163118cdaa760e01b8152336004820152602490fdfe8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0a164736f6c6343000818000a",
129
+ "deployedBytecode": "0x60406080815260048036101561001457600080fd5b600091823560e01c8063715018a6146102bf5780638da5cb5b146102935780639623609d1461014a578063ad3cb1cc146100d85763f2fde38b1461005757600080fd5b346100d45760203660031901126100d4576001600160a01b038235818116939192908490036100cf57610088610347565b83156100b95750506000548260018060a01b031982161760005516600080516020610374833981519152600080a380f35b51631e4fbdf760e01b8152908101849052602490fd5b600080fd5b8280fd5b508234610147578060031936011261014757508051908181016001600160401b038111838210176101325761012e9350815260058252640352e302e360dc1b602083015251918291602083526020830190610307565b0390f35b604184634e487b7160e01b6000525260246000fd5b80fd5b5060603660031901126100d4576001600160a01b03918035838116919082900361026357602491823594851680950361028f576001600160401b03906044359082821161028b573660238301121561028b578184013583811161027957865192601f8201601f19908116603f011684018581118582101761026757885281845289939291903682820189011161026357818592896020930183870137840101526101f2610347565b803b156100d45761022297875180998194829363278f794360e11b8452898401528a8a8401526044830190610307565b039134905af1801561025957610236578580f35b84116102485750505238808080808580f35b634e487b7160e01b85526041905283fd5b84513d88823e3d90fd5b8480fd5b634e487b7160e01b8b5260418752878bfd5b634e487b7160e01b8952604185528589fd5b8780fd5b8580fd5b8382346102bb57816003193601126102bb57905490516001600160a01b039091168152602090f35b5080fd5b83346101475780600319360112610147576102d8610347565b80546001600160a01b03198116825581906001600160a01b03166000805160206103748339815191528280a380f35b919082519283825260005b848110610333575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610312565b6000546001600160a01b0316330361035b57565b60405163118cdaa760e01b8152336004820152602490fdfe8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0a164736f6c6343000818000a",
130
+ "linkReferences": {},
131
+ "deployedLinkReferences": {}
132
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "_format": "hh-sol-dbg-1",
3
+ "buildInfo": "../../build-info/c62ec9e1c41c71827acc3bed0f8e94e8.json"
4
+ }
@@ -0,0 +1,116 @@
1
+ {
2
+ "_format": "hh-sol-artifact-1",
3
+ "contractName": "KAMITransparentUpgradeableProxy",
4
+ "sourceName": "contracts/TransparentUpgradeableProxy.sol",
5
+ "abi": [
6
+ {
7
+ "inputs": [
8
+ {
9
+ "internalType": "address",
10
+ "name": "_logic",
11
+ "type": "address"
12
+ },
13
+ {
14
+ "internalType": "address",
15
+ "name": "admin_",
16
+ "type": "address"
17
+ },
18
+ {
19
+ "internalType": "bytes",
20
+ "name": "_data",
21
+ "type": "bytes"
22
+ }
23
+ ],
24
+ "stateMutability": "nonpayable",
25
+ "type": "constructor"
26
+ },
27
+ {
28
+ "inputs": [
29
+ {
30
+ "internalType": "address",
31
+ "name": "target",
32
+ "type": "address"
33
+ }
34
+ ],
35
+ "name": "AddressEmptyCode",
36
+ "type": "error"
37
+ },
38
+ {
39
+ "inputs": [
40
+ {
41
+ "internalType": "address",
42
+ "name": "admin",
43
+ "type": "address"
44
+ }
45
+ ],
46
+ "name": "ERC1967InvalidAdmin",
47
+ "type": "error"
48
+ },
49
+ {
50
+ "inputs": [
51
+ {
52
+ "internalType": "address",
53
+ "name": "implementation",
54
+ "type": "address"
55
+ }
56
+ ],
57
+ "name": "ERC1967InvalidImplementation",
58
+ "type": "error"
59
+ },
60
+ {
61
+ "inputs": [],
62
+ "name": "ERC1967NonPayable",
63
+ "type": "error"
64
+ },
65
+ {
66
+ "inputs": [],
67
+ "name": "FailedCall",
68
+ "type": "error"
69
+ },
70
+ {
71
+ "inputs": [],
72
+ "name": "ProxyDeniedAdminAccess",
73
+ "type": "error"
74
+ },
75
+ {
76
+ "anonymous": false,
77
+ "inputs": [
78
+ {
79
+ "indexed": false,
80
+ "internalType": "address",
81
+ "name": "previousAdmin",
82
+ "type": "address"
83
+ },
84
+ {
85
+ "indexed": false,
86
+ "internalType": "address",
87
+ "name": "newAdmin",
88
+ "type": "address"
89
+ }
90
+ ],
91
+ "name": "AdminChanged",
92
+ "type": "event"
93
+ },
94
+ {
95
+ "anonymous": false,
96
+ "inputs": [
97
+ {
98
+ "indexed": true,
99
+ "internalType": "address",
100
+ "name": "implementation",
101
+ "type": "address"
102
+ }
103
+ ],
104
+ "name": "Upgraded",
105
+ "type": "event"
106
+ },
107
+ {
108
+ "stateMutability": "payable",
109
+ "type": "fallback"
110
+ }
111
+ ],
112
+ "bytecode": "0x604060a081523461026d57610a978038038061001a81610272565b92833981019060608183031261026d5761003381610297565b602091610041838201610297565b8582015190916001600160401b03919082821161026d570185601f8201121561026d57805190610078610073836102ab565b610272565b9682885286838301011161026d57859060005b83811061025957505060009187010152823b15610239577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b038581166001600160a01b0319928316811790935596909490917fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2815191869083156102305761014693600092839201845af43d15610228573d91610137610073846102ab565b9283523d60008985013e6102c6565b505b855191610477918284019081118482101761021257868492879461062085391681520301906000f0801561020757831691826080527f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f857fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103958587549483519286168352820152a182156101ef5716179055516102f6908161032a823960805181600f0152f35b8451633173bdd160e11b815260006004820152602490fd5b84513d6000823e3d90fd5b634e487b7160e01b600052604160045260246000fd5b6060916102c6565b50505050610148565b8551634c9c8ce360e01b81526001600160a01b0384166004820152602490fd5b81810183015189820184015287920161008b565b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761021257604052565b51906001600160a01b038216820361026d57565b6001600160401b03811161021257601f01601f191660200190565b906102ed57508051156102db57602081519101fd5b60405163d6bda27560e01b8152600490fd5b81511580610320575b6102fe575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b156102f656fe60806040526001600160a01b03337f000000000000000000000000000000000000000000000000000000000000000082160361006b576000356001600160e01b03191663278f794360e11b14610061576040516334ad5dbb60e21b8152600490fd5b6100696100f6565b005b6000805160206102ca83398151915254166000808092368280378136915af43d82803e15610097573d90f35b3d90fd5b634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f191682016001600160401b038111838210176100d657604052565b61009b565b6001600160401b0381116100d657601f01601f191660200190565b3660041161017f57604036600319011261017f576004356001600160a01b0381169081900361017f57602435906001600160401b03821161017f573660238301121561017f5781600401359061015361014e836100db565b6100b1565b91808352366024828601011161017f57602081600092602461017d97018387013784010152610184565b565b600080fd5b90813b1561020a576000805160206102ca83398151915280546001600160a01b0319166001600160a01b0384169081179091557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28051156101ef576101ec9161022b565b50565b5050346101f857565b60405163b398979f60e01b8152600490fd5b604051634c9c8ce360e01b81526001600160a01b0383166004820152602490fd5b60008061025f93602081519101845af43d15610262573d9161024f61014e846100db565b9283523d6000602085013e610266565b90565b6060915b9061028d575080511561027b57602081519101fd5b60405163d6bda27560e01b8152600490fd5b815115806102c0575b61029e575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b1561029656fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca164736f6c6343000818000a6080346100bb57601f61047738819003918201601f19168301916001600160401b038311848410176100c0578084926020946040528339810103126100bb57516001600160a01b0390818116908190036100bb5780156100a257600080546001600160a01b03198116831782556040519316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a36103a090816100d78239f35b604051631e4fbdf760e01b815260006004820152602490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe60406080815260048036101561001457600080fd5b600091823560e01c8063715018a6146102bf5780638da5cb5b146102935780639623609d1461014a578063ad3cb1cc146100d85763f2fde38b1461005757600080fd5b346100d45760203660031901126100d4576001600160a01b038235818116939192908490036100cf57610088610347565b83156100b95750506000548260018060a01b031982161760005516600080516020610374833981519152600080a380f35b51631e4fbdf760e01b8152908101849052602490fd5b600080fd5b8280fd5b508234610147578060031936011261014757508051908181016001600160401b038111838210176101325761012e9350815260058252640352e302e360dc1b602083015251918291602083526020830190610307565b0390f35b604184634e487b7160e01b6000525260246000fd5b80fd5b5060603660031901126100d4576001600160a01b03918035838116919082900361026357602491823594851680950361028f576001600160401b03906044359082821161028b573660238301121561028b578184013583811161027957865192601f8201601f19908116603f011684018581118582101761026757885281845289939291903682820189011161026357818592896020930183870137840101526101f2610347565b803b156100d45761022297875180998194829363278f794360e11b8452898401528a8a8401526044830190610307565b039134905af1801561025957610236578580f35b84116102485750505238808080808580f35b634e487b7160e01b85526041905283fd5b84513d88823e3d90fd5b8480fd5b634e487b7160e01b8b5260418752878bfd5b634e487b7160e01b8952604185528589fd5b8780fd5b8580fd5b8382346102bb57816003193601126102bb57905490516001600160a01b039091168152602090f35b5080fd5b83346101475780600319360112610147576102d8610347565b80546001600160a01b03198116825581906001600160a01b03166000805160206103748339815191528280a380f35b919082519283825260005b848110610333575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201610312565b6000546001600160a01b0316330361035b57565b60405163118cdaa760e01b8152336004820152602490fdfe8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0a164736f6c6343000818000a",
113
+ "deployedBytecode": "0x60806040526001600160a01b03337f000000000000000000000000000000000000000000000000000000000000000082160361006b576000356001600160e01b03191663278f794360e11b14610061576040516334ad5dbb60e21b8152600490fd5b6100696100f6565b005b6000805160206102ca83398151915254166000808092368280378136915af43d82803e15610097573d90f35b3d90fd5b634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f191682016001600160401b038111838210176100d657604052565b61009b565b6001600160401b0381116100d657601f01601f191660200190565b3660041161017f57604036600319011261017f576004356001600160a01b0381169081900361017f57602435906001600160401b03821161017f573660238301121561017f5781600401359061015361014e836100db565b6100b1565b91808352366024828601011161017f57602081600092602461017d97018387013784010152610184565b565b600080fd5b90813b1561020a576000805160206102ca83398151915280546001600160a01b0319166001600160a01b0384169081179091557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28051156101ef576101ec9161022b565b50565b5050346101f857565b60405163b398979f60e01b8152600490fd5b604051634c9c8ce360e01b81526001600160a01b0383166004820152602490fd5b60008061025f93602081519101845af43d15610262573d9161024f61014e846100db565b9283523d6000602085013e610266565b90565b6060915b9061028d575080511561027b57602081519101fd5b60405163d6bda27560e01b8152600490fd5b815115806102c0575b61029e575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b1561029656fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca164736f6c6343000818000a",
114
+ "linkReferences": {},
115
+ "deployedLinkReferences": {}
116
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @file KAMI Upgrade Manager
3
+ * @description Manages upgrades for upgradeable KAMI NFT contracts
4
+ */
5
+ import { Address, Hex } from 'viem';
6
+ import { UpgradeResult, ProxyInfo } from './kami-types';
7
+ /**
8
+ * Configuration for upgrade manager
9
+ */
10
+ export interface UpgradeManagerConfig {
11
+ rpcUrl: string;
12
+ platformPrivateKey: `0x${string}`;
13
+ platformSimpleAccountAddress: Address;
14
+ contractDeployerAddress: Address;
15
+ chain?: any;
16
+ }
17
+ /**
18
+ * KAMI Upgrade Manager
19
+ * Handles upgrades for upgradeable KAMI NFT contracts
20
+ */
21
+ export declare class KamiUpgradeManager {
22
+ private publicClient;
23
+ private walletClient;
24
+ private config;
25
+ private platformAccount;
26
+ constructor(config: UpgradeManagerConfig);
27
+ /**
28
+ * Get current implementation address for a proxy
29
+ */
30
+ getImplementation(proxyAddress: Address): Promise<Address | null>;
31
+ /**
32
+ * Get ProxyAdmin address for a proxy (if available)
33
+ * Note: TransparentUpgradeableProxy doesn't expose admin() directly
34
+ * This should be tracked during deployment
35
+ */
36
+ getProxyAdmin(proxyAddress: Address): Promise<Address | null>;
37
+ /**
38
+ * Get proxy information
39
+ */
40
+ getProxyInfo(proxyAddress: Address): Promise<ProxyInfo | null>;
41
+ /**
42
+ * Deploy new implementation contract
43
+ */
44
+ deployNewImplementation(contractName: 'KAMI721CUpgradeable' | 'KAMI721ACUpgradable' | 'KAMI1155CUpgradeable'): Promise<Address | null>;
45
+ /**
46
+ * Upgrade a proxy to a new implementation
47
+ */
48
+ upgradeProxy(proxyAddress: Address, proxyAdminAddress: Address, newImplementationAddress: Address, upgradeCallData?: Hex): Promise<UpgradeResult>;
49
+ /**
50
+ * Prepare and execute upgrade in one step
51
+ */
52
+ prepareAndUpgrade(proxyAddress: Address, proxyAdminAddress: Address, contractName: 'KAMI721CUpgradeable' | 'KAMI721ACUpgradable' | 'KAMI1155CUpgradeable', upgradeCallData?: Hex): Promise<UpgradeResult>;
53
+ /**
54
+ * Verify upgrade compatibility (basic checks)
55
+ */
56
+ verifyUpgrade(proxyAddress: Address, newImplementationAddress: Address): Promise<{
57
+ compatible: boolean;
58
+ error?: string;
59
+ }>;
60
+ /**
61
+ * Extract contract address from transaction receipt
62
+ */
63
+ private extractContractAddress;
64
+ }
65
+ //# sourceMappingURL=kami-upgrade-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kami-upgrade-manager.d.ts","sourceRoot":"","sources":["../src/kami-upgrade-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAKN,OAAO,EAEP,GAAG,EAEH,MAAM,MAAM,CAAC;AAKd,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,KAAK,MAAM,EAAE,CAAC;IAClC,4BAA4B,EAAE,OAAO,CAAC;IACtC,uBAAuB,EAAE,OAAO,CAAC;IACjC,KAAK,CAAC,EAAE,GAAG,CAAC;CACZ;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,eAAe,CAAoB;gBAE/B,MAAM,EAAE,oBAAoB;IAgBxC;;OAEG;IACG,iBAAiB,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAsBvE;;;;OAIG;IACG,aAAa,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAgBnE;;OAEG;IACG,YAAY,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAepE;;OAEG;IACG,uBAAuB,CAC5B,YAAY,EAAE,qBAAqB,GAAG,qBAAqB,GAAG,sBAAsB,GAClF,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAgE1B;;OAEG;IACG,YAAY,CACjB,YAAY,EAAE,OAAO,EACrB,iBAAiB,EAAE,OAAO,EAC1B,wBAAwB,EAAE,OAAO,EACjC,eAAe,CAAC,EAAE,GAAG,GACnB,OAAO,CAAC,aAAa,CAAC;IAiGzB;;OAEG;IACG,iBAAiB,CACtB,YAAY,EAAE,OAAO,EACrB,iBAAiB,EAAE,OAAO,EAC1B,YAAY,EAAE,qBAAqB,GAAG,qBAAqB,GAAG,sBAAsB,EACpF,eAAe,CAAC,EAAE,GAAG,GACnB,OAAO,CAAC,aAAa,CAAC;IAczB;;OAEG;IACG,aAAa,CAClB,YAAY,EAAE,OAAO,EACrB,wBAAwB,EAAE,OAAO,GAC/B,OAAO,CAAC;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IA4BnD;;OAEG;IACH,OAAO,CAAC,sBAAsB;CA8B9B"}
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ /**
3
+ * @file KAMI Upgrade Manager
4
+ * @description Manages upgrades for upgradeable KAMI NFT contracts
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.KamiUpgradeManager = void 0;
8
+ const viem_1 = require("viem");
9
+ const accounts_1 = require("viem/accounts");
10
+ const chains_1 = require("viem/chains");
11
+ const nextjs_artifact_loader_1 = require("./nextjs-artifact-loader");
12
+ const ContractDeployer_1 = require("./SmartContractWallet/ContractDeployer");
13
+ /**
14
+ * KAMI Upgrade Manager
15
+ * Handles upgrades for upgradeable KAMI NFT contracts
16
+ */
17
+ class KamiUpgradeManager {
18
+ publicClient;
19
+ walletClient;
20
+ config;
21
+ platformAccount;
22
+ constructor(config) {
23
+ this.config = config;
24
+ this.platformAccount = (0, accounts_1.privateKeyToAccount)(config.platformPrivateKey);
25
+ this.publicClient = (0, viem_1.createPublicClient)({
26
+ transport: (0, viem_1.http)(config.rpcUrl),
27
+ chain: config.chain || chains_1.baseSepolia,
28
+ });
29
+ this.walletClient = (0, viem_1.createWalletClient)({
30
+ account: this.platformAccount,
31
+ transport: (0, viem_1.http)(config.rpcUrl),
32
+ chain: config.chain || chains_1.baseSepolia,
33
+ });
34
+ }
35
+ /**
36
+ * Get current implementation address for a proxy
37
+ */
38
+ async getImplementation(proxyAddress) {
39
+ try {
40
+ const result = await this.publicClient.readContract({
41
+ address: proxyAddress,
42
+ abi: [
43
+ {
44
+ inputs: [],
45
+ name: 'implementation',
46
+ outputs: [{ name: '', type: 'address' }],
47
+ stateMutability: 'view',
48
+ type: 'function',
49
+ },
50
+ ],
51
+ functionName: 'implementation',
52
+ });
53
+ return result;
54
+ }
55
+ catch (error) {
56
+ console.error('Failed to get implementation address:', error);
57
+ return null;
58
+ }
59
+ }
60
+ /**
61
+ * Get ProxyAdmin address for a proxy (if available)
62
+ * Note: TransparentUpgradeableProxy doesn't expose admin() directly
63
+ * This should be tracked during deployment
64
+ */
65
+ async getProxyAdmin(proxyAddress) {
66
+ try {
67
+ // Try calling getProxyAdmin on ContractDeployer
68
+ const result = await this.publicClient.readContract({
69
+ address: this.config.contractDeployerAddress,
70
+ abi: ContractDeployer_1.CONTRACT_DEPLOYER_ABI,
71
+ functionName: 'getProxyAdmin',
72
+ args: [proxyAddress],
73
+ });
74
+ return result;
75
+ }
76
+ catch (error) {
77
+ console.warn('Failed to get ProxyAdmin address:', error);
78
+ return null;
79
+ }
80
+ }
81
+ /**
82
+ * Get proxy information
83
+ */
84
+ async getProxyInfo(proxyAddress) {
85
+ const implementationAddress = await this.getImplementation(proxyAddress);
86
+ if (!implementationAddress) {
87
+ return null;
88
+ }
89
+ const proxyAdminAddress = await this.getProxyAdmin(proxyAddress);
90
+ return {
91
+ proxyAddress,
92
+ implementationAddress,
93
+ proxyAdminAddress: proxyAdminAddress || undefined,
94
+ };
95
+ }
96
+ /**
97
+ * Deploy new implementation contract
98
+ */
99
+ async deployNewImplementation(contractName) {
100
+ try {
101
+ console.log(`📦 Deploying new ${contractName} implementation...`);
102
+ const artifact = (0, nextjs_artifact_loader_1.loadArtifactForNextJS)(contractName);
103
+ if (!artifact) {
104
+ console.error(`❌ ${contractName} artifact not found`);
105
+ return null;
106
+ }
107
+ const implementationBytecode = artifact.bytecode;
108
+ // Deploy implementation via ContractDeployer
109
+ const deployCalldata = (0, viem_1.encodeFunctionData)({
110
+ abi: ContractDeployer_1.CONTRACT_DEPLOYER_ABI,
111
+ functionName: 'deployImplementation',
112
+ args: [implementationBytecode],
113
+ });
114
+ const executeCalldata = (0, viem_1.encodeFunctionData)({
115
+ abi: [
116
+ {
117
+ type: 'function',
118
+ name: 'execute',
119
+ inputs: [
120
+ { name: 'dest', type: 'address' },
121
+ { name: 'value', type: 'uint256' },
122
+ { name: 'func', type: 'bytes' },
123
+ ],
124
+ outputs: [],
125
+ },
126
+ ],
127
+ functionName: 'execute',
128
+ args: [this.config.contractDeployerAddress, 0n, deployCalldata],
129
+ });
130
+ const txHash = await this.walletClient.sendTransaction({
131
+ account: this.platformAccount,
132
+ to: this.config.platformSimpleAccountAddress,
133
+ data: executeCalldata,
134
+ gas: 5000000n,
135
+ });
136
+ const receipt = await this.publicClient.waitForTransactionReceipt({ hash: txHash });
137
+ if (receipt.status !== 'success') {
138
+ console.error('❌ Implementation deployment failed');
139
+ return null;
140
+ }
141
+ // Extract implementation address from logs
142
+ const implementationAddress = this.extractContractAddress(receipt);
143
+ if (!implementationAddress) {
144
+ console.error('❌ Failed to extract implementation address');
145
+ return null;
146
+ }
147
+ console.log(`✅ New implementation deployed at: ${implementationAddress}`);
148
+ return implementationAddress;
149
+ }
150
+ catch (error) {
151
+ console.error('❌ Failed to deploy new implementation:', error);
152
+ return null;
153
+ }
154
+ }
155
+ /**
156
+ * Upgrade a proxy to a new implementation
157
+ */
158
+ async upgradeProxy(proxyAddress, proxyAdminAddress, newImplementationAddress, upgradeCallData) {
159
+ try {
160
+ console.log(`🔄 Upgrading proxy ${proxyAddress}...`);
161
+ console.log(` Old implementation: ${await this.getImplementation(proxyAddress)}`);
162
+ console.log(` New implementation: ${newImplementationAddress}`);
163
+ // Get old implementation address
164
+ const oldImplementationAddress = await this.getImplementation(proxyAddress);
165
+ if (!oldImplementationAddress) {
166
+ return {
167
+ success: false,
168
+ error: 'Failed to get current implementation address',
169
+ };
170
+ }
171
+ // Encode upgrade call
172
+ const upgradeCalldata = (0, viem_1.encodeFunctionData)({
173
+ abi: [
174
+ {
175
+ inputs: [
176
+ { name: 'proxy', type: 'address' },
177
+ { name: 'implementation', type: 'address' },
178
+ { name: 'data', type: 'bytes' },
179
+ ],
180
+ name: 'upgradeAndCall',
181
+ outputs: [],
182
+ stateMutability: 'nonpayable',
183
+ type: 'function',
184
+ },
185
+ ],
186
+ functionName: 'upgradeAndCall',
187
+ args: [proxyAddress, newImplementationAddress, upgradeCallData || '0x'],
188
+ });
189
+ // Execute upgrade via ProxyAdmin
190
+ const executeCalldata = (0, viem_1.encodeFunctionData)({
191
+ abi: [
192
+ {
193
+ type: 'function',
194
+ name: 'execute',
195
+ inputs: [
196
+ { name: 'dest', type: 'address' },
197
+ { name: 'value', type: 'uint256' },
198
+ { name: 'func', type: 'bytes' },
199
+ ],
200
+ outputs: [],
201
+ },
202
+ ],
203
+ functionName: 'execute',
204
+ args: [proxyAdminAddress, 0n, upgradeCalldata],
205
+ });
206
+ const txHash = await this.walletClient.sendTransaction({
207
+ account: this.platformAccount,
208
+ to: this.config.platformSimpleAccountAddress,
209
+ data: executeCalldata,
210
+ gas: 5000000n,
211
+ });
212
+ const receipt = await this.publicClient.waitForTransactionReceipt({ hash: txHash });
213
+ if (receipt.status !== 'success') {
214
+ return {
215
+ success: false,
216
+ error: 'Upgrade transaction failed',
217
+ transactionHash: txHash,
218
+ };
219
+ }
220
+ // Verify upgrade succeeded
221
+ const newImplAddress = await this.getImplementation(proxyAddress);
222
+ if (newImplAddress?.toLowerCase() !== newImplementationAddress.toLowerCase()) {
223
+ return {
224
+ success: false,
225
+ error: 'Upgrade verification failed - implementation address mismatch',
226
+ transactionHash: txHash,
227
+ };
228
+ }
229
+ console.log(`✅ Upgrade successful!`);
230
+ console.log(` New implementation: ${newImplAddress}`);
231
+ return {
232
+ success: true,
233
+ proxyAddress,
234
+ oldImplementationAddress,
235
+ newImplementationAddress: newImplAddress,
236
+ transactionHash: txHash,
237
+ };
238
+ }
239
+ catch (error) {
240
+ console.error('❌ Upgrade failed:', error);
241
+ return {
242
+ success: false,
243
+ error: error.message || 'Unknown upgrade error',
244
+ };
245
+ }
246
+ }
247
+ /**
248
+ * Prepare and execute upgrade in one step
249
+ */
250
+ async prepareAndUpgrade(proxyAddress, proxyAdminAddress, contractName, upgradeCallData) {
251
+ // Deploy new implementation
252
+ const newImplementationAddress = await this.deployNewImplementation(contractName);
253
+ if (!newImplementationAddress) {
254
+ return {
255
+ success: false,
256
+ error: 'Failed to deploy new implementation',
257
+ };
258
+ }
259
+ // Execute upgrade
260
+ return await this.upgradeProxy(proxyAddress, proxyAdminAddress, newImplementationAddress, upgradeCallData);
261
+ }
262
+ /**
263
+ * Verify upgrade compatibility (basic checks)
264
+ */
265
+ async verifyUpgrade(proxyAddress, newImplementationAddress) {
266
+ try {
267
+ // Get current implementation
268
+ const currentImpl = await this.getImplementation(proxyAddress);
269
+ if (!currentImpl) {
270
+ return { compatible: false, error: 'Failed to get current implementation' };
271
+ }
272
+ // Basic verification: check that new implementation is different
273
+ if (currentImpl.toLowerCase() === newImplementationAddress.toLowerCase()) {
274
+ return { compatible: false, error: 'New implementation is the same as current implementation' };
275
+ }
276
+ // Check that new implementation has code
277
+ const code = await this.publicClient.getBytecode({ address: newImplementationAddress });
278
+ if (!code || code === '0x') {
279
+ return { compatible: false, error: 'New implementation has no code' };
280
+ }
281
+ // Note: More comprehensive checks (storage layout, function signatures) should be done
282
+ // using OpenZeppelin's upgrade plugins or similar tools
283
+ return { compatible: true };
284
+ }
285
+ catch (error) {
286
+ return { compatible: false, error: error.message || 'Verification failed' };
287
+ }
288
+ }
289
+ /**
290
+ * Extract contract address from transaction receipt
291
+ */
292
+ extractContractAddress(receipt) {
293
+ // Look for ContractDeployed event
294
+ // Event signature: ContractDeployed(address indexed deployedAddress, address indexed deployer)
295
+ const eventSignature = (0, viem_1.keccak256)(Buffer.from('ContractDeployed(address,address)'));
296
+ for (const log of receipt.logs || []) {
297
+ if (log.topics && log.topics[0] === eventSignature && log.topics[1]) {
298
+ const deployedAddress = '0x' + log.topics[1].slice(-40);
299
+ return deployedAddress;
300
+ }
301
+ }
302
+ // Fallback: use contractAddress from receipt
303
+ if (receipt.contractAddress) {
304
+ return receipt.contractAddress;
305
+ }
306
+ // Fallback: find unique new address in logs
307
+ const uniqueAddresses = new Set();
308
+ for (const log of receipt.logs || []) {
309
+ if (log.address && log.address.toLowerCase() !== this.config.platformSimpleAccountAddress.toLowerCase()) {
310
+ uniqueAddresses.add(log.address);
311
+ }
312
+ }
313
+ if (uniqueAddresses.size === 1) {
314
+ return Array.from(uniqueAddresses)[0];
315
+ }
316
+ return null;
317
+ }
318
+ }
319
+ exports.KamiUpgradeManager = KamiUpgradeManager;
320
+ //# sourceMappingURL=kami-upgrade-manager.js.map