@xyo-network/chain-sdk 1.1.7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs +1 -5
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index-node.mjs +1 -5
- package/dist/node/index-node.mjs.map +1 -1
- package/dist/types/test/evm/stakingContractUtils.d.ts.map +1 -1
- package/package.json +30 -30
- package/src/test/evm/stakingContractUtils.ts +4 -7
- package/babel.config.json +0 -6
package/dist/neutral/index.mjs
CHANGED
|
@@ -159,14 +159,10 @@ var createTestGenesisBlock = /* @__PURE__ */ __name(async (blockProducerAccounts
|
|
|
159
159
|
exp: Number.MAX_SAFE_INTEGER,
|
|
160
160
|
nbf: 0,
|
|
161
161
|
intent: "producer"
|
|
162
|
-
}).meta({
|
|
163
|
-
$opCodes: [
|
|
164
|
-
"elevate"
|
|
165
|
-
]
|
|
166
162
|
}).build();
|
|
167
163
|
const signedStakedBlockProducerIntent = await buildTransaction(randomChainId, [
|
|
168
164
|
stakeIntent
|
|
169
|
-
], blockProducerAccount, 0, 1e3
|
|
165
|
+
], [], blockProducerAccount, 0, 1e3);
|
|
170
166
|
return signedStakedBlockProducerIntent;
|
|
171
167
|
}));
|
|
172
168
|
const intents = signedStakedBlockProducerIntents.map((intent) => intent[0]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/index-shared.ts","../../src/test/evm/runGanache.ts","../../src/test/evm/stakingContractUtils.ts"],"sourcesContent":["export * from './index-shared.ts'\nexport * from './test/index.ts'\n","export * from '@xyo-network/chain-ethereum'\nexport * from '@xyo-network/chain-modules'\nexport * from '@xyo-network/chain-orchestration'\nexport * from '@xyo-network/chain-protocol'\nexport * from '@xyo-network/chain-services'\nexport * from '@xyo-network/chain-utils'\nexport * from '@xyo-network/chain-validation'\nexport * from '@xyo-network/xl1-model'\n","import type { ChildProcess } from 'node:child_process'\nimport { spawn } from 'node:child_process'\n\nimport { delay } from '@xylabs/delay'\nimport { JsonRpcProvider } from 'ethers/providers'\n\nasync function isGanacheRunning(url: string) {\n try {\n const provider = new JsonRpcProvider(url)\n await provider.getBlockNumber() // Try to fetch the latest block number\n return true // If this succeeds, the server is running\n } catch {\n return false // If this fails, the server is not running\n }\n}\n\nexport async function startGanache(port: number, mnemonic: string) {\n console.log('Starting Ganache CLI...')\n\n // Start Ganache CLI\n const ganacheProcess = spawn(\n 'yarn',\n ['ganache', '--port', `${port}`, '--chain.chainId', '1337', '--mnemonic', mnemonic],\n { stdio: 'inherit' },\n )\n\n // Wait for Ganache to be ready\n while (!await isGanacheRunning(`http://127.0.0.1:${port}`)) {\n await delay(500)\n }\n\n return ganacheProcess\n}\n\nexport function stopGanache(process: ChildProcess) {\n console.log('Stopping Ganache CLI...')\n\n if (process) {\n process.kill('SIGTERM')\n console.log('Ganache CLI stopped.')\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Address } from '@xylabs/hex'\nimport { asAddress } from '@xylabs/hex'\nimport type { AccountInstance, WalletInstance } from '@xyo-network/account'\nimport { Account } from '@xyo-network/account'\nimport { createChain } from '@xyo-network/chain-ethereum'\nimport { buildBlock, buildTransaction } from '@xyo-network/chain-protocol'\nimport { XYO_ZERO_ADDRESS } from '@xyo-network/chain-utils'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\nimport { BurnableErc20__factory as Erc20Factory } from '@xyo-network/typechain'\nimport type {\n ChainStakeIntent, Elevated, HydratedBlock,\n} from '@xyo-network/xl1-model'\nimport { ChainStakeIntentSchema } from '@xyo-network/xl1-model'\nimport { getAddress } from 'ethers/address'\nimport { JsonRpcProvider } from 'ethers/providers'\nimport { parseUnits } from 'ethers/utils'\nimport { Wallet } from 'ethers/wallet'\n\nconst gasConfig = () => {\n return {\n gasLimit: 2_000_000, // Set the gas limit\n gasPrice: parseUnits('100', 'gwei'),\n }\n}\n\nexport const createTestErc20 = async (ganachePort: number, testPhrase: string, contractCreator: WalletInstance): Promise<Address> => {\n const provider = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWallet = new Wallet(contractCreator.privateKey, provider)\n const erc20 = new Erc20Factory(ethWallet)\n const totalSupply = parseUnits('1000000', 18)\n const erc20Contract = await (await erc20.deploy('Test Token', 'TST', totalSupply, gasConfig())).waitForDeployment()\n const erc20Address = await erc20Contract.getAddress()\n const erc20ContractPerson0 = Erc20Factory.connect(erc20Address, ethWallet)\n const balance = await erc20ContractPerson0.balanceOf(ethWallet.address)\n assertEx(balance === totalSupply, () => 'Balance does not match total supply')\n return assertEx(asAddress(erc20Address), () => 'Invalid ERC20 contract address')\n}\n\nexport const transferTestTokens = async (ganachePort: number, erc20Address: Address, account0: WalletInstance, account1: WalletInstance) => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson0 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson0)\n const transferAmount = parseUnits('1000', 18)\n await (await erc20ContractPerson0.transfer(ethWalletPerson1.address, transferAmount, gasConfig())).wait()\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n const balance = await erc20ContractPerson1.balanceOf(ethWalletPerson1.address)\n assertEx(balance === transferAmount, () => 'Balance does not match transfer amount')\n}\n\nexport const createTestChainContract = async (\n ganachePort: number,\n erc20Address: Address,\n account0: WalletInstance,\n initialProducer: AccountInstance,\n): Promise<Address> => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const [xyoChainContractAddress] = await createChain(\n ethWalletPerson0,\n erc20Address,\n initialProducer,\n XYO_ZERO_ADDRESS,\n 0n,\n XYO_ZERO_ADDRESS,\n 50_000n,\n gasConfig(),\n )\n return assertEx(asAddress(xyoChainContractAddress), () => 'Invalid staking contract address')\n}\n\nexport const approveTestStakeChainAddress = async (ganachePort: number, erc20Address: Address, xyoChainContractAddress: Address, account1: WalletInstance) => {\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n\n const _approveResultTx = await (await erc20ContractPerson1.approve(getAddress(xyoChainContractAddress), parseUnits('100', 18), gasConfig())).wait()\n}\n\nexport const createTestGenesisBlock = async (\n blockProducerAccounts: WalletInstance[],\n): Promise<HydratedBlock> => {\n const randomChainId = (await Account.random()).address\n // Create staked intents for all the block producers declaring their intent to produce blocks\n const signedStakedBlockProducerIntents = await Promise.all(blockProducerAccounts.map(async (blockProducerAccount) => {\n const stakeIntent = new PayloadBuilder<Elevated<ChainStakeIntent>>({ schema: ChainStakeIntentSchema }).fields({\n from: blockProducerAccount.address,\n exp: Number.MAX_SAFE_INTEGER,\n nbf: 0,\n intent: 'producer',\n })\n .meta({ $opCodes: ['elevate'] })\n .build()\n\n const signedStakedBlockProducerIntent = await buildTransaction(\n randomChainId,\n [stakeIntent],\n blockProducerAccount,\n 0,\n 1000,\n [],\n )\n return signedStakedBlockProducerIntent\n }))\n const intents = signedStakedBlockProducerIntents.map(intent => intent[0])\n const payloads = signedStakedBlockProducerIntents.flatMap(intent => intent[1]) as Elevated<WithStorageMeta<ChainStakeIntent>>[]\n return await buildBlock(randomChainId, signedStakedBlockProducerIntents, [...intents, ...payloads], blockProducerAccounts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,qCAAc;AACd,oCAAc;AACd,0CAAc;AACd,qCAAc;AACd,qC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ACQ;OACDD,sBACA,GACA,KACA,CAAA,CAAE;AAEJ,WAAOe;EACT,CAAA,CAAA;AACA,QAAME,UAAUrB,iCAAiCG,IAAIY,CAAAA,WAAUA,OAAO,CAAA,CAAE;AACxE,QAAMO,WAAWtB,iCAAiCuB,QAAQR,CAAAA,WAAUA,OAAO,CAAA,CAAE;AAC7E,SAAO,MAAMS,WAAW3B,eAAeG,kCAAkC;OAAIqB;OAAYC;KAAW1B,qBAAAA;AACtG,GA5BsC;","names":["spawn","delay","JsonRpcProvider","isGanacheRunning","url","provider","JsonRpcProvider","getBlockNumber","startGanache","port","mnemonic","console","log","ganacheProcess","spawn","stdio","delay","stopGanache","process","kill","assertEx","asAddress","Account","createChain","buildBlock","buildTransaction","XYO_ZERO_ADDRESS","PayloadBuilder","BurnableErc20__factory","Erc20Factory","ChainStakeIntentSchema","getAddress","JsonRpcProvider","parseUnits","Wallet","gasConfig","gasLimit","gasPrice","parseUnits","createTestErc20","ganachePort","testPhrase","contractCreator","provider","JsonRpcProvider","ethWallet","Wallet","privateKey","erc20","Erc20Factory","totalSupply","erc20Contract","deploy","waitForDeployment","erc20Address","getAddress","erc20ContractPerson0","connect","balance","balanceOf","address","assertEx","asAddress","transferTestTokens","account0","account1","provider0","ethWalletPerson0","provider1","ethWalletPerson1","transferAmount","transfer","wait","erc20ContractPerson1","createTestChainContract","initialProducer","xyoChainContractAddress","createChain","XYO_ZERO_ADDRESS","approveTestStakeChainAddress","_approveResultTx","approve","createTestGenesisBlock","blockProducerAccounts","randomChainId","Account","random","signedStakedBlockProducerIntents","Promise","all","map","blockProducerAccount","stakeIntent","PayloadBuilder","schema","ChainStakeIntentSchema","fields","from","exp","Number","MAX_SAFE_INTEGER","nbf","intent","meta","$opCodes","build","signedStakedBlockProducerIntent","buildTransaction","intents","payloads","flatMap","buildBlock"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/index-shared.ts","../../src/test/evm/runGanache.ts","../../src/test/evm/stakingContractUtils.ts"],"sourcesContent":["export * from './index-shared.ts'\nexport * from './test/index.ts'\n","export * from '@xyo-network/chain-ethereum'\nexport * from '@xyo-network/chain-modules'\nexport * from '@xyo-network/chain-orchestration'\nexport * from '@xyo-network/chain-protocol'\nexport * from '@xyo-network/chain-services'\nexport * from '@xyo-network/chain-utils'\nexport * from '@xyo-network/chain-validation'\nexport * from '@xyo-network/xl1-model'\n","import type { ChildProcess } from 'node:child_process'\nimport { spawn } from 'node:child_process'\n\nimport { delay } from '@xylabs/delay'\nimport { JsonRpcProvider } from 'ethers/providers'\n\nasync function isGanacheRunning(url: string) {\n try {\n const provider = new JsonRpcProvider(url)\n await provider.getBlockNumber() // Try to fetch the latest block number\n return true // If this succeeds, the server is running\n } catch {\n return false // If this fails, the server is not running\n }\n}\n\nexport async function startGanache(port: number, mnemonic: string) {\n console.log('Starting Ganache CLI...')\n\n // Start Ganache CLI\n const ganacheProcess = spawn(\n 'yarn',\n ['ganache', '--port', `${port}`, '--chain.chainId', '1337', '--mnemonic', mnemonic],\n { stdio: 'inherit' },\n )\n\n // Wait for Ganache to be ready\n while (!await isGanacheRunning(`http://127.0.0.1:${port}`)) {\n await delay(500)\n }\n\n return ganacheProcess\n}\n\nexport function stopGanache(process: ChildProcess) {\n console.log('Stopping Ganache CLI...')\n\n if (process) {\n process.kill('SIGTERM')\n console.log('Ganache CLI stopped.')\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Address } from '@xylabs/hex'\nimport { asAddress } from '@xylabs/hex'\nimport type { AccountInstance, WalletInstance } from '@xyo-network/account'\nimport { Account } from '@xyo-network/account'\nimport { createChain } from '@xyo-network/chain-ethereum'\nimport { buildBlock, buildTransaction } from '@xyo-network/chain-protocol'\nimport { XYO_ZERO_ADDRESS } from '@xyo-network/chain-utils'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\nimport { BurnableErc20__factory as Erc20Factory } from '@xyo-network/typechain'\nimport type { ChainStakeIntent, HydratedBlock } from '@xyo-network/xl1-model'\nimport { ChainStakeIntentSchema } from '@xyo-network/xl1-model'\nimport { getAddress } from 'ethers/address'\nimport { JsonRpcProvider } from 'ethers/providers'\nimport { parseUnits } from 'ethers/utils'\nimport { Wallet } from 'ethers/wallet'\n\nconst gasConfig = () => {\n return {\n gasLimit: 2_000_000, // Set the gas limit\n gasPrice: parseUnits('100', 'gwei'),\n }\n}\n\nexport const createTestErc20 = async (ganachePort: number, testPhrase: string, contractCreator: WalletInstance): Promise<Address> => {\n const provider = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWallet = new Wallet(contractCreator.privateKey, provider)\n const erc20 = new Erc20Factory(ethWallet)\n const totalSupply = parseUnits('1000000', 18)\n const erc20Contract = await (await erc20.deploy('Test Token', 'TST', totalSupply, gasConfig())).waitForDeployment()\n const erc20Address = await erc20Contract.getAddress()\n const erc20ContractPerson0 = Erc20Factory.connect(erc20Address, ethWallet)\n const balance = await erc20ContractPerson0.balanceOf(ethWallet.address)\n assertEx(balance === totalSupply, () => 'Balance does not match total supply')\n return assertEx(asAddress(erc20Address), () => 'Invalid ERC20 contract address')\n}\n\nexport const transferTestTokens = async (ganachePort: number, erc20Address: Address, account0: WalletInstance, account1: WalletInstance) => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson0 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson0)\n const transferAmount = parseUnits('1000', 18)\n await (await erc20ContractPerson0.transfer(ethWalletPerson1.address, transferAmount, gasConfig())).wait()\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n const balance = await erc20ContractPerson1.balanceOf(ethWalletPerson1.address)\n assertEx(balance === transferAmount, () => 'Balance does not match transfer amount')\n}\n\nexport const createTestChainContract = async (\n ganachePort: number,\n erc20Address: Address,\n account0: WalletInstance,\n initialProducer: AccountInstance,\n): Promise<Address> => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const [xyoChainContractAddress] = await createChain(\n ethWalletPerson0,\n erc20Address,\n initialProducer,\n XYO_ZERO_ADDRESS,\n 0n,\n XYO_ZERO_ADDRESS,\n 50_000n,\n gasConfig(),\n )\n return assertEx(asAddress(xyoChainContractAddress), () => 'Invalid staking contract address')\n}\n\nexport const approveTestStakeChainAddress = async (ganachePort: number, erc20Address: Address, xyoChainContractAddress: Address, account1: WalletInstance) => {\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n\n const _approveResultTx = await (await erc20ContractPerson1.approve(getAddress(xyoChainContractAddress), parseUnits('100', 18), gasConfig())).wait()\n}\n\nexport const createTestGenesisBlock = async (\n blockProducerAccounts: WalletInstance[],\n): Promise<HydratedBlock> => {\n const randomChainId = (await Account.random()).address\n // Create staked intents for all the block producers declaring their intent to produce blocks\n const signedStakedBlockProducerIntents = await Promise.all(blockProducerAccounts.map(async (blockProducerAccount) => {\n const stakeIntent = new PayloadBuilder<ChainStakeIntent>({ schema: ChainStakeIntentSchema }).fields({\n from: blockProducerAccount.address,\n exp: Number.MAX_SAFE_INTEGER,\n nbf: 0,\n intent: 'producer',\n })\n .build()\n\n const signedStakedBlockProducerIntent = await buildTransaction(\n randomChainId,\n [stakeIntent],\n [],\n blockProducerAccount,\n 0,\n 1000,\n )\n return signedStakedBlockProducerIntent\n }))\n const intents = signedStakedBlockProducerIntents.map(intent => intent[0])\n const payloads = signedStakedBlockProducerIntents.flatMap(intent => intent[1]) as WithStorageMeta<ChainStakeIntent>[]\n return await buildBlock(randomChainId, signedStakedBlockProducerIntents, [...intents, ...payloads], blockProducerAccounts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,qCAAc;AACd,oCAAc;AACd,0CAAc;AACd,qCAAc;AACd,qCAAc;AACd,kCAAc;AACd,uCAAc;AACd,gCAAc;;;ADPd,0BAAc;;;AECd,SAASA,aAAa;AAEtB,SAASC,aAAa;AACtB,SAASC,uBAAuB;AAEhC,eAAeC,iBAAiBC,KAAW;AACzC,MAAI;AACF,UAAMC,WAAW,IAAIC,gBAAgBF,GAAAA;AACrC,UAAMC,SAASE,eAAc;AAC7B,WAAO;EACT,QAAQ;AACN,WAAO;EACT;AACF;AAReJ;AAUf,eAAsBK,aAAaC,MAAcC,UAAgB;AAC/DC,UAAQC,IAAI,yBAAA;AAGZ,QAAMC,iBAAiBC,MACrB,QACA;IAAC;IAAW;IAAU,GAAGL,IAAAA;IAAQ;IAAmB;IAAQ;IAAcC;KAC1E;IAAEK,OAAO;EAAU,CAAA;AAIrB,SAAO,CAAC,MAAMZ,iBAAiB,oBAAoBM,IAAAA,EAAM,GAAG;AAC1D,UAAMO,MAAM,GAAA;EACd;AAEA,SAAOH;AACT;AAhBsBL;AAkBf,SAASS,YAAYC,SAAqB;AAC/CP,UAAQC,IAAI,yBAAA;AAEZ,MAAIM,SAAS;AACXA,YAAQC,KAAK,SAAA;AACbR,YAAQC,IAAI,sBAAA;EACd;AACF;AAPgBK;;;AClChB,SAASG,gBAAgB;AAEzB,SAASC,iBAAiB;AAE1B,SAASC,eAAe;AACxB,SAASC,mBAAmB;AAC5B,SAASC,YAAYC,wBAAwB;AAC7C,SAASC,wBAAwB;AACjC,SAASC,sBAAsB;AAE/B,SAASC,0BAA0BC,oBAAoB;AAEvD,SAASC,8BAA8B;AACvC,SAASC,kBAAkB;AAC3B,SAASC,mBAAAA,wBAAuB;AAChC,SA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AQC;IAAuB,CAAA,EAAGC,OAAO;MAClGC,MAAMN,qBAAqB/B;MAC3BsC,KAAKC,OAAOC;MACZC,KAAK;MACLC,QAAQ;IACV,CAAA,EACGC,MAAK;AAER,UAAMC,kCAAkC,MAAMC,iBAC5CrB,eACA;MAACQ;OACD,CAAA,GACAD,sBACA,GACA,GAAA;AAEF,WAAOa;EACT,CAAA,CAAA;AACA,QAAME,UAAUnB,iCAAiCG,IAAIY,CAAAA,WAAUA,OAAO,CAAA,CAAE;AACxE,QAAMK,WAAWpB,iCAAiCqB,QAAQN,CAAAA,WAAUA,OAAO,CAAA,CAAE;AAC7E,SAAO,MAAMO,WAAWzB,eAAeG,kCAAkC;OAAImB;OAAYC;KAAWxB,qBAAAA;AACtG,GA3BsC;","names":["spawn","delay","JsonRpcProvider","isGanacheRunning","url","provider","JsonRpcProvider","getBlockNumber","startGanache","port","mnemonic","console","log","ganacheProcess","spawn","stdio","delay","stopGanache","process","kill","assertEx","asAddress","Account","createChain","buildBlock","buildTransaction","XYO_ZERO_ADDRESS","PayloadBuilder","BurnableErc20__factory","Erc20Factory","ChainStakeIntentSchema","getAddress","JsonRpcProvider","parseUnits","Wallet","gasConfig","gasLimit","gasPrice","parseUnits","createTestErc20","ganachePort","testPhrase","contractCreator","provider","JsonRpcProvider","ethWallet","Wallet","privateKey","erc20","Erc20Factory","totalSupply","erc20Contract","deploy","waitForDeployment","erc20Address","getAddress","erc20ContractPerson0","connect","balance","balanceOf","address","assertEx","asAddress","transferTestTokens","account0","account1","provider0","ethWalletPerson0","provider1","ethWalletPerson1","transferAmount","transfer","wait","erc20ContractPerson1","createTestChainContract","initialProducer","xyoChainContractAddress","createChain","XYO_ZERO_ADDRESS","approveTestStakeChainAddress","_approveResultTx","approve","createTestGenesisBlock","blockProducerAccounts","randomChainId","Account","random","signedStakedBlockProducerIntents","Promise","all","map","blockProducerAccount","stakeIntent","PayloadBuilder","schema","ChainStakeIntentSchema","fields","from","exp","Number","MAX_SAFE_INTEGER","nbf","intent","build","signedStakedBlockProducerIntent","buildTransaction","intents","payloads","flatMap","buildBlock"]}
|
package/dist/node/index-node.mjs
CHANGED
|
@@ -171,14 +171,10 @@ var createTestGenesisBlock = /* @__PURE__ */ __name(async (blockProducerAccounts
|
|
|
171
171
|
exp: Number.MAX_SAFE_INTEGER,
|
|
172
172
|
nbf: 0,
|
|
173
173
|
intent: "producer"
|
|
174
|
-
}).meta({
|
|
175
|
-
$opCodes: [
|
|
176
|
-
"elevate"
|
|
177
|
-
]
|
|
178
174
|
}).build();
|
|
179
175
|
const signedStakedBlockProducerIntent = await buildTransaction(randomChainId, [
|
|
180
176
|
stakeIntent
|
|
181
|
-
], blockProducerAccount, 0, 1e3
|
|
177
|
+
], [], blockProducerAccount, 0, 1e3);
|
|
182
178
|
return signedStakedBlockProducerIntent;
|
|
183
179
|
}));
|
|
184
180
|
const intents = signedStakedBlockProducerIntents.map((intent) => intent[0]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index-node.ts","../../src/index.ts","../../src/index-shared.ts","../../src/test/evm/runGanache.ts","../../src/test/evm/stakingContractUtils.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nexport * from './index.ts'\n","export * from './index-shared.ts'\nexport * from './test/index.ts'\n","export * from '@xyo-network/chain-ethereum'\nexport * from '@xyo-network/chain-modules'\nexport * from '@xyo-network/chain-orchestration'\nexport * from '@xyo-network/chain-protocol'\nexport * from '@xyo-network/chain-services'\nexport * from '@xyo-network/chain-utils'\nexport * from '@xyo-network/chain-validation'\nexport * from '@xyo-network/xl1-model'\n","import type { ChildProcess } from 'node:child_process'\nimport { spawn } from 'node:child_process'\n\nimport { delay } from '@xylabs/delay'\nimport { JsonRpcProvider } from 'ethers/providers'\n\nasync function isGanacheRunning(url: string) {\n try {\n const provider = new JsonRpcProvider(url)\n await provider.getBlockNumber() // Try to fetch the latest block number\n return true // If this succeeds, the server is running\n } catch {\n return false // If this fails, the server is not running\n }\n}\n\nexport async function startGanache(port: number, mnemonic: string) {\n console.log('Starting Ganache CLI...')\n\n // Start Ganache CLI\n const ganacheProcess = spawn(\n 'yarn',\n ['ganache', '--port', `${port}`, '--chain.chainId', '1337', '--mnemonic', mnemonic],\n { stdio: 'inherit' },\n )\n\n // Wait for Ganache to be ready\n while (!await isGanacheRunning(`http://127.0.0.1:${port}`)) {\n await delay(500)\n }\n\n return ganacheProcess\n}\n\nexport function stopGanache(process: ChildProcess) {\n console.log('Stopping Ganache CLI...')\n\n if (process) {\n process.kill('SIGTERM')\n console.log('Ganache CLI stopped.')\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Address } from '@xylabs/hex'\nimport { asAddress } from '@xylabs/hex'\nimport type { AccountInstance, WalletInstance } from '@xyo-network/account'\nimport { Account } from '@xyo-network/account'\nimport { createChain } from '@xyo-network/chain-ethereum'\nimport { buildBlock, buildTransaction } from '@xyo-network/chain-protocol'\nimport { XYO_ZERO_ADDRESS } from '@xyo-network/chain-utils'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\nimport { BurnableErc20__factory as Erc20Factory } from '@xyo-network/typechain'\nimport type {\n ChainStakeIntent, Elevated, HydratedBlock,\n} from '@xyo-network/xl1-model'\nimport { ChainStakeIntentSchema } from '@xyo-network/xl1-model'\nimport { getAddress } from 'ethers/address'\nimport { JsonRpcProvider } from 'ethers/providers'\nimport { parseUnits } from 'ethers/utils'\nimport { Wallet } from 'ethers/wallet'\n\nconst gasConfig = () => {\n return {\n gasLimit: 2_000_000, // Set the gas limit\n gasPrice: parseUnits('100', 'gwei'),\n }\n}\n\nexport const createTestErc20 = async (ganachePort: number, testPhrase: string, contractCreator: WalletInstance): Promise<Address> => {\n const provider = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWallet = new Wallet(contractCreator.privateKey, provider)\n const erc20 = new Erc20Factory(ethWallet)\n const totalSupply = parseUnits('1000000', 18)\n const erc20Contract = await (await erc20.deploy('Test Token', 'TST', totalSupply, gasConfig())).waitForDeployment()\n const erc20Address = await erc20Contract.getAddress()\n const erc20ContractPerson0 = Erc20Factory.connect(erc20Address, ethWallet)\n const balance = await erc20ContractPerson0.balanceOf(ethWallet.address)\n assertEx(balance === totalSupply, () => 'Balance does not match total supply')\n return assertEx(asAddress(erc20Address), () => 'Invalid ERC20 contract address')\n}\n\nexport const transferTestTokens = async (ganachePort: number, erc20Address: Address, account0: WalletInstance, account1: WalletInstance) => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson0 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson0)\n const transferAmount = parseUnits('1000', 18)\n await (await erc20ContractPerson0.transfer(ethWalletPerson1.address, transferAmount, gasConfig())).wait()\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n const balance = await erc20ContractPerson1.balanceOf(ethWalletPerson1.address)\n assertEx(balance === transferAmount, () => 'Balance does not match transfer amount')\n}\n\nexport const createTestChainContract = async (\n ganachePort: number,\n erc20Address: Address,\n account0: WalletInstance,\n initialProducer: AccountInstance,\n): Promise<Address> => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const [xyoChainContractAddress] = await createChain(\n ethWalletPerson0,\n erc20Address,\n initialProducer,\n XYO_ZERO_ADDRESS,\n 0n,\n XYO_ZERO_ADDRESS,\n 50_000n,\n gasConfig(),\n )\n return assertEx(asAddress(xyoChainContractAddress), () => 'Invalid staking contract address')\n}\n\nexport const approveTestStakeChainAddress = async (ganachePort: number, erc20Address: Address, xyoChainContractAddress: Address, account1: WalletInstance) => {\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n\n const _approveResultTx = await (await erc20ContractPerson1.approve(getAddress(xyoChainContractAddress), parseUnits('100', 18), gasConfig())).wait()\n}\n\nexport const createTestGenesisBlock = async (\n blockProducerAccounts: WalletInstance[],\n): Promise<HydratedBlock> => {\n const randomChainId = (await Account.random()).address\n // Create staked intents for all the block producers declaring their intent to produce blocks\n const signedStakedBlockProducerIntents = await Promise.all(blockProducerAccounts.map(async (blockProducerAccount) => {\n const stakeIntent = new PayloadBuilder<Elevated<ChainStakeIntent>>({ schema: ChainStakeIntentSchema }).fields({\n from: blockProducerAccount.address,\n exp: Number.MAX_SAFE_INTEGER,\n nbf: 0,\n intent: 'producer',\n })\n .meta({ $opCodes: ['elevate'] })\n .build()\n\n const signedStakedBlockProducerIntent = await buildTransaction(\n randomChainId,\n [stakeIntent],\n blockProducerAccount,\n 0,\n 1000,\n [],\n )\n return signedStakedBlockProducerIntent\n }))\n const intents = signedStakedBlockProducerIntents.map(intent => intent[0])\n const payloads = signedStakedBlockProducerIntents.flatMap(intent => intent[1]) as Elevated<WithStorageMeta<ChainStakeIntent>>[]\n return await buildBlock(randomChainId, signedStakedBlockProducerIntents, [...intents, ...payloads], blockProducerAccounts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA;;;;;;;;;;;;ACAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,qCAAc;AACd,oCAAc;AACd,0CAAc;AACd,qCAAc;AACd,qCAAc;AACd,kCAAc;AACd,uCAAc;AACd,gCAAc;;;ADPd,0BAAc;;;AECd,SAASA,aAAa;AAEtB,SAASC,aAAa;AACtB,SAASC,uBAAuB;AAEhC,eAAeC,iBAAiBC,KAAW;AACzC,MAAI;AACF,UAAMC,WAAW,IAAIC,gBAAg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UA,OAAO,CAAA,CAAE;AAC7E,SAAO,MAAMS,WAAW3B,eAAeG,kCAAkC;OAAIqB;OAAYC;KAAW1B,qBAAAA;AACtG,GA5BsC;;;AJjFtC,+BAAc;","names":["spawn","delay","JsonRpcProvider","isGanacheRunning","url","provider","JsonRpcProvider","getBlockNumber","startGanache","port","mnemonic","console","log","ganacheProcess","spawn","stdio","delay","stopGanache","process","kill","assertEx","asAddress","Account","createChain","buildBlock","buildTransaction","XYO_ZERO_ADDRESS","PayloadBuilder","BurnableErc20__factory","Erc20Factory","ChainStakeIntentSchema","getAddress","JsonRpcProvider","parseUnits","Wallet","gasConfig","gasLimit","gasPrice","parseUnits","createTestErc20","ganachePort","testPhrase","contractCreator","provider","JsonRpcProvider","ethWallet","Wallet","privateKey","erc20","Erc20Factory","totalSupply","erc20Contract","deploy","waitForDeployment","erc20Address","getAddress","erc20ContractPerson0","connect","balance","balanceOf","address","assertEx","asAddress","transferTestTokens","account0","account1","provider0","ethWalletPerson0","provider1","ethWalletPerson1","transferAmount","transfer","wait","erc20ContractPerson1","createTestChainContract","initialProducer","xyoChainContractAddress","createChain","XYO_ZERO_ADDRESS","approveTestStakeChainAddress","_approveResultTx","approve","createTestGenesisBlock","blockProducerAccounts","randomChainId","Account","random","signedStakedBlockProducerIntents","Promise","all","map","blockProducerAccount","stakeIntent","PayloadBuilder","schema","ChainStakeIntentSchema","fields","from","exp","Number","MAX_SAFE_INTEGER","nbf","intent","meta","$opCodes","build","signedStakedBlockProducerIntent","buildTransaction","intents","payloads","flatMap","buildBlock"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index-node.ts","../../src/index.ts","../../src/index-shared.ts","../../src/test/evm/runGanache.ts","../../src/test/evm/stakingContractUtils.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nexport * from './index.ts'\n","export * from './index-shared.ts'\nexport * from './test/index.ts'\n","export * from '@xyo-network/chain-ethereum'\nexport * from '@xyo-network/chain-modules'\nexport * from '@xyo-network/chain-orchestration'\nexport * from '@xyo-network/chain-protocol'\nexport * from '@xyo-network/chain-services'\nexport * from '@xyo-network/chain-utils'\nexport * from '@xyo-network/chain-validation'\nexport * from '@xyo-network/xl1-model'\n","import type { ChildProcess } from 'node:child_process'\nimport { spawn } from 'node:child_process'\n\nimport { delay } from '@xylabs/delay'\nimport { JsonRpcProvider } from 'ethers/providers'\n\nasync function isGanacheRunning(url: string) {\n try {\n const provider = new JsonRpcProvider(url)\n await provider.getBlockNumber() // Try to fetch the latest block number\n return true // If this succeeds, the server is running\n } catch {\n return false // If this fails, the server is not running\n }\n}\n\nexport async function startGanache(port: number, mnemonic: string) {\n console.log('Starting Ganache CLI...')\n\n // Start Ganache CLI\n const ganacheProcess = spawn(\n 'yarn',\n ['ganache', '--port', `${port}`, '--chain.chainId', '1337', '--mnemonic', mnemonic],\n { stdio: 'inherit' },\n )\n\n // Wait for Ganache to be ready\n while (!await isGanacheRunning(`http://127.0.0.1:${port}`)) {\n await delay(500)\n }\n\n return ganacheProcess\n}\n\nexport function stopGanache(process: ChildProcess) {\n console.log('Stopping Ganache CLI...')\n\n if (process) {\n process.kill('SIGTERM')\n console.log('Ganache CLI stopped.')\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Address } from '@xylabs/hex'\nimport { asAddress } from '@xylabs/hex'\nimport type { AccountInstance, WalletInstance } from '@xyo-network/account'\nimport { Account } from '@xyo-network/account'\nimport { createChain } from '@xyo-network/chain-ethereum'\nimport { buildBlock, buildTransaction } from '@xyo-network/chain-protocol'\nimport { XYO_ZERO_ADDRESS } from '@xyo-network/chain-utils'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\nimport { BurnableErc20__factory as Erc20Factory } from '@xyo-network/typechain'\nimport type { ChainStakeIntent, HydratedBlock } from '@xyo-network/xl1-model'\nimport { ChainStakeIntentSchema } from '@xyo-network/xl1-model'\nimport { getAddress } from 'ethers/address'\nimport { JsonRpcProvider } from 'ethers/providers'\nimport { parseUnits } from 'ethers/utils'\nimport { Wallet } from 'ethers/wallet'\n\nconst gasConfig = () => {\n return {\n gasLimit: 2_000_000, // Set the gas limit\n gasPrice: parseUnits('100', 'gwei'),\n }\n}\n\nexport const createTestErc20 = async (ganachePort: number, testPhrase: string, contractCreator: WalletInstance): Promise<Address> => {\n const provider = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWallet = new Wallet(contractCreator.privateKey, provider)\n const erc20 = new Erc20Factory(ethWallet)\n const totalSupply = parseUnits('1000000', 18)\n const erc20Contract = await (await erc20.deploy('Test Token', 'TST', totalSupply, gasConfig())).waitForDeployment()\n const erc20Address = await erc20Contract.getAddress()\n const erc20ContractPerson0 = Erc20Factory.connect(erc20Address, ethWallet)\n const balance = await erc20ContractPerson0.balanceOf(ethWallet.address)\n assertEx(balance === totalSupply, () => 'Balance does not match total supply')\n return assertEx(asAddress(erc20Address), () => 'Invalid ERC20 contract address')\n}\n\nexport const transferTestTokens = async (ganachePort: number, erc20Address: Address, account0: WalletInstance, account1: WalletInstance) => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson0 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson0)\n const transferAmount = parseUnits('1000', 18)\n await (await erc20ContractPerson0.transfer(ethWalletPerson1.address, transferAmount, gasConfig())).wait()\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n const balance = await erc20ContractPerson1.balanceOf(ethWalletPerson1.address)\n assertEx(balance === transferAmount, () => 'Balance does not match transfer amount')\n}\n\nexport const createTestChainContract = async (\n ganachePort: number,\n erc20Address: Address,\n account0: WalletInstance,\n initialProducer: AccountInstance,\n): Promise<Address> => {\n const provider0 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson0 = new Wallet(account0.privateKey, provider0)\n const [xyoChainContractAddress] = await createChain(\n ethWalletPerson0,\n erc20Address,\n initialProducer,\n XYO_ZERO_ADDRESS,\n 0n,\n XYO_ZERO_ADDRESS,\n 50_000n,\n gasConfig(),\n )\n return assertEx(asAddress(xyoChainContractAddress), () => 'Invalid staking contract address')\n}\n\nexport const approveTestStakeChainAddress = async (ganachePort: number, erc20Address: Address, xyoChainContractAddress: Address, account1: WalletInstance) => {\n const provider1 = new JsonRpcProvider(`http://127.0.0.1:${ganachePort}`, 1337)\n const ethWalletPerson1 = new Wallet(account1.privateKey, provider1)\n const erc20ContractPerson1 = Erc20Factory.connect(getAddress(erc20Address), ethWalletPerson1)\n\n const _approveResultTx = await (await erc20ContractPerson1.approve(getAddress(xyoChainContractAddress), parseUnits('100', 18), gasConfig())).wait()\n}\n\nexport const createTestGenesisBlock = async (\n blockProducerAccounts: WalletInstance[],\n): Promise<HydratedBlock> => {\n const randomChainId = (await Account.random()).address\n // Create staked intents for all the block producers declaring their intent to produce blocks\n const signedStakedBlockProducerIntents = await Promise.all(blockProducerAccounts.map(async (blockProducerAccount) => {\n const stakeIntent = new PayloadBuilder<ChainStakeIntent>({ schema: ChainStakeIntentSchema }).fields({\n from: blockProducerAccount.address,\n exp: Number.MAX_SAFE_INTEGER,\n nbf: 0,\n intent: 'producer',\n })\n .build()\n\n const signedStakedBlockProducerIntent = await buildTransaction(\n randomChainId,\n [stakeIntent],\n [],\n blockProducerAccount,\n 0,\n 1000,\n )\n return signedStakedBlockProducerIntent\n }))\n const intents = signedStakedBlockProducerIntents.map(intent => intent[0])\n const payloads = signedStakedBlockProducerIntents.flatMap(intent => intent[1]) as WithStorageMeta<ChainStakeIntent>[]\n return await buildBlock(randomChainId, signedStakedBlockProducerIntents, [...intents, ...payloads], blockProducerAccounts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;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,QAAQ;IACV,CAAA,EACGC,MAAK;AAER,UAAMC,kCAAkC,MAAMC,iBAC5CrB,eACA;MAACQ;OACD,CAAA,GACAD,sBACA,GACA,GAAA;AAEF,WAAOa;EACT,CAAA,CAAA;AACA,QAAME,UAAUnB,iCAAiCG,IAAIY,CAAAA,WAAUA,OAAO,CAAA,CAAE;AACxE,QAAMK,WAAWpB,iCAAiCqB,QAAQN,CAAAA,WAAUA,OAAO,CAAA,CAAE;AAC7E,SAAO,MAAMO,WAAWzB,eAAeG,kCAAkC;OAAImB;OAAYC;KAAWxB,qBAAAA;AACtG,GA3BsC;;;AJ/EtC,+BAAc;","names":["spawn","delay","JsonRpcProvider","isGanacheRunning","url","provider","JsonRpcProvider","getBlockNumber","startGanache","port","mnemonic","console","log","ganacheProcess","spawn","stdio","delay","stopGanache","process","kill","assertEx","asAddress","Account","createChain","buildBlock","buildTransaction","XYO_ZERO_ADDRESS","PayloadBuilder","BurnableErc20__factory","Erc20Factory","ChainStakeIntentSchema","getAddress","JsonRpcProvider","parseUnits","Wallet","gasConfig","gasLimit","gasPrice","parseUnits","createTestErc20","ganachePort","testPhrase","contractCreator","provider","JsonRpcProvider","ethWallet","Wallet","privateKey","erc20","Erc20Factory","totalSupply","erc20Contract","deploy","waitForDeployment","erc20Address","getAddress","erc20ContractPerson0","connect","balance","balanceOf","address","assertEx","asAddress","transferTestTokens","account0","account1","provider0","ethWalletPerson0","provider1","ethWalletPerson1","transferAmount","transfer","wait","erc20ContractPerson1","createTestChainContract","initialProducer","xyoChainContractAddress","createChain","XYO_ZERO_ADDRESS","approveTestStakeChainAddress","_approveResultTx","approve","createTestGenesisBlock","blockProducerAccounts","randomChainId","Account","random","signedStakedBlockProducerIntents","Promise","all","map","blockProducerAccount","stakeIntent","PayloadBuilder","schema","ChainStakeIntentSchema","fields","from","exp","Number","MAX_SAFE_INTEGER","nbf","intent","build","signedStakedBlockProducerIntent","buildTransaction","intents","payloads","flatMap","buildBlock"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stakingContractUtils.d.ts","sourceRoot":"","sources":["../../../../src/test/evm/stakingContractUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQ3E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"stakingContractUtils.d.ts","sourceRoot":"","sources":["../../../../src/test/evm/stakingContractUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQ3E,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAc7E,eAAO,MAAM,eAAe,GAAU,aAAa,MAAM,EAAE,YAAY,MAAM,EAAE,iBAAiB,cAAc,KAAG,OAAO,CAAC,OAAO,CAW/H,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAU,aAAa,MAAM,EAAE,cAAc,OAAO,EAAE,UAAU,cAAc,EAAE,UAAU,cAAc,kBAWtI,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,aAAa,MAAM,EACnB,cAAc,OAAO,EACrB,UAAU,cAAc,EACxB,iBAAiB,eAAe,KAC/B,OAAO,CAAC,OAAO,CAcjB,CAAA;AAED,eAAO,MAAM,4BAA4B,GAAU,aAAa,MAAM,EAAE,cAAc,OAAO,EAAE,yBAAyB,OAAO,EAAE,UAAU,cAAc,kBAMxJ,CAAA;AAED,eAAO,MAAM,sBAAsB,GACjC,uBAAuB,cAAc,EAAE,KACtC,OAAO,CAAC,aAAa,CAyBvB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/chain-sdk",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"description": "XYO Layer One SDK",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -46,42 +46,42 @@
|
|
|
46
46
|
"deploy3": "echo Deploy3 not allowed!"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@xylabs/assert": "^4.8.
|
|
50
|
-
"@xylabs/delay": "^4.8.
|
|
51
|
-
"@xylabs/hex": "^4.8.
|
|
52
|
-
"@xyo-network/account": "^3.12.
|
|
53
|
-
"@xyo-network/archivist-model": "^3.12.
|
|
54
|
-
"@xyo-network/bridge-http": "^3.12.
|
|
55
|
-
"@xyo-network/bridge-model": "^3.12.
|
|
56
|
-
"@xyo-network/chain-ethereum": "^1.
|
|
57
|
-
"@xyo-network/chain-modules": "^1.
|
|
58
|
-
"@xyo-network/chain-orchestration": "^1.
|
|
59
|
-
"@xyo-network/chain-protocol": "^1.
|
|
60
|
-
"@xyo-network/chain-services": "^1.
|
|
61
|
-
"@xyo-network/chain-utils": "^1.
|
|
62
|
-
"@xyo-network/chain-validation": "^1.
|
|
63
|
-
"@xyo-network/diviner-model": "^3.12.
|
|
64
|
-
"@xyo-network/module-model": "^3.12.
|
|
65
|
-
"@xyo-network/node-memory": "^3.12.
|
|
66
|
-
"@xyo-network/payload-builder": "^3.12.
|
|
67
|
-
"@xyo-network/payload-model": "^3.12.
|
|
68
|
-
"@xyo-network/sentinel-memory": "^3.12.
|
|
69
|
-
"@xyo-network/sentinel-model": "^3.12.
|
|
49
|
+
"@xylabs/assert": "^4.8.4",
|
|
50
|
+
"@xylabs/delay": "^4.8.4",
|
|
51
|
+
"@xylabs/hex": "^4.8.4",
|
|
52
|
+
"@xyo-network/account": "^3.12.2",
|
|
53
|
+
"@xyo-network/archivist-model": "^3.12.2",
|
|
54
|
+
"@xyo-network/bridge-http": "^3.12.2",
|
|
55
|
+
"@xyo-network/bridge-model": "^3.12.2",
|
|
56
|
+
"@xyo-network/chain-ethereum": "^1.2.0",
|
|
57
|
+
"@xyo-network/chain-modules": "^1.2.0",
|
|
58
|
+
"@xyo-network/chain-orchestration": "^1.2.0",
|
|
59
|
+
"@xyo-network/chain-protocol": "^1.2.0",
|
|
60
|
+
"@xyo-network/chain-services": "^1.2.0",
|
|
61
|
+
"@xyo-network/chain-utils": "^1.2.0",
|
|
62
|
+
"@xyo-network/chain-validation": "^1.2.0",
|
|
63
|
+
"@xyo-network/diviner-model": "^3.12.2",
|
|
64
|
+
"@xyo-network/module-model": "^3.12.2",
|
|
65
|
+
"@xyo-network/node-memory": "^3.12.2",
|
|
66
|
+
"@xyo-network/payload-builder": "^3.12.2",
|
|
67
|
+
"@xyo-network/payload-model": "^3.12.2",
|
|
68
|
+
"@xyo-network/sentinel-memory": "^3.12.2",
|
|
69
|
+
"@xyo-network/sentinel-model": "^3.12.2",
|
|
70
70
|
"@xyo-network/typechain": "^3.5.1",
|
|
71
|
-
"@xyo-network/xl1-model": "^1.
|
|
71
|
+
"@xyo-network/xl1-model": "^1.2.0",
|
|
72
72
|
"ethers": "6.13.6"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/node": "^22.14.0",
|
|
76
|
-
"@xylabs/decimal-precision": "^4.8.
|
|
77
|
-
"@xylabs/delay": "^4.8.
|
|
76
|
+
"@xylabs/decimal-precision": "^4.8.4",
|
|
77
|
+
"@xylabs/delay": "^4.8.4",
|
|
78
78
|
"@xylabs/ts-scripts-yarn3": "^6.2.1",
|
|
79
79
|
"@xylabs/tsconfig": "^6.2.1",
|
|
80
|
-
"@xyo-network/account": "^3.12.
|
|
81
|
-
"@xyo-network/account-model": "^3.12.
|
|
82
|
-
"@xyo-network/archivist-memory": "^3.12.
|
|
83
|
-
"@xyo-network/boundwitness-builder": "^3.12.
|
|
84
|
-
"@xyo-network/payload-model": "^3.12.
|
|
80
|
+
"@xyo-network/account": "^3.12.2",
|
|
81
|
+
"@xyo-network/account-model": "^3.12.2",
|
|
82
|
+
"@xyo-network/archivist-memory": "^3.12.2",
|
|
83
|
+
"@xyo-network/boundwitness-builder": "^3.12.2",
|
|
84
|
+
"@xyo-network/payload-model": "^3.12.2",
|
|
85
85
|
"eslint": "^9.24.0",
|
|
86
86
|
"typescript": "^5.8.3",
|
|
87
87
|
"vitest": "^3.1.1"
|
|
@@ -9,9 +9,7 @@ import { XYO_ZERO_ADDRESS } from '@xyo-network/chain-utils'
|
|
|
9
9
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
10
10
|
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
11
11
|
import { BurnableErc20__factory as Erc20Factory } from '@xyo-network/typechain'
|
|
12
|
-
import type {
|
|
13
|
-
ChainStakeIntent, Elevated, HydratedBlock,
|
|
14
|
-
} from '@xyo-network/xl1-model'
|
|
12
|
+
import type { ChainStakeIntent, HydratedBlock } from '@xyo-network/xl1-model'
|
|
15
13
|
import { ChainStakeIntentSchema } from '@xyo-network/xl1-model'
|
|
16
14
|
import { getAddress } from 'ethers/address'
|
|
17
15
|
import { JsonRpcProvider } from 'ethers/providers'
|
|
@@ -86,26 +84,25 @@ export const createTestGenesisBlock = async (
|
|
|
86
84
|
const randomChainId = (await Account.random()).address
|
|
87
85
|
// Create staked intents for all the block producers declaring their intent to produce blocks
|
|
88
86
|
const signedStakedBlockProducerIntents = await Promise.all(blockProducerAccounts.map(async (blockProducerAccount) => {
|
|
89
|
-
const stakeIntent = new PayloadBuilder<
|
|
87
|
+
const stakeIntent = new PayloadBuilder<ChainStakeIntent>({ schema: ChainStakeIntentSchema }).fields({
|
|
90
88
|
from: blockProducerAccount.address,
|
|
91
89
|
exp: Number.MAX_SAFE_INTEGER,
|
|
92
90
|
nbf: 0,
|
|
93
91
|
intent: 'producer',
|
|
94
92
|
})
|
|
95
|
-
.meta({ $opCodes: ['elevate'] })
|
|
96
93
|
.build()
|
|
97
94
|
|
|
98
95
|
const signedStakedBlockProducerIntent = await buildTransaction(
|
|
99
96
|
randomChainId,
|
|
100
97
|
[stakeIntent],
|
|
98
|
+
[],
|
|
101
99
|
blockProducerAccount,
|
|
102
100
|
0,
|
|
103
101
|
1000,
|
|
104
|
-
[],
|
|
105
102
|
)
|
|
106
103
|
return signedStakedBlockProducerIntent
|
|
107
104
|
}))
|
|
108
105
|
const intents = signedStakedBlockProducerIntents.map(intent => intent[0])
|
|
109
|
-
const payloads = signedStakedBlockProducerIntents.flatMap(intent => intent[1]) as
|
|
106
|
+
const payloads = signedStakedBlockProducerIntents.flatMap(intent => intent[1]) as WithStorageMeta<ChainStakeIntent>[]
|
|
110
107
|
return await buildBlock(randomChainId, signedStakedBlockProducerIntents, [...intents, ...payloads], blockProducerAccounts)
|
|
111
108
|
}
|