Git Product home page Git Product logo

Comments (5)

maschad avatar maschad commented on July 19, 2024 1

yarn start --task=initPool is used to manually initialize variables, but the problem now is that the variables are not initialized when they are defined.

My bad thanks for the clarification, the issue is that you weren't passing the storageSlots as an option when you were deploying the pool contract in the createPool task. (See https://docs.fuel.network/docs/fuels-ts/contracts/storage-slots/#storage-slots for more info)

I've applied the fix here and it works for me. See the code snippet below:

export const deploy_pool_contract = async (wallet: Account, assetIdA: string, assetIdB: string) => {

    const bytecodeDir = join(__dirname, '../../AMM/exchange-contract/out/debug/exchange-contract.bin')

	// Get the storage slot directory
    const storageSlotsDir = join(__dirname, '../../AMM/exchange-contract/out/debug/exchange-contract-storage_slots.json')

    const bytecode = readFileSync(bytecodeDir)
	
    // Parse the Storage slot JSON object
    const storageSlots = JSON.parse(readFileSync(storageSlotsDir, 'utf-8'))

    const factory = new ContractFactory(bytecode, ExchangeContractAbi__factory.abi, wallet)

    // Ensure it's passed to the deployContract function call
    let contractAbi = await factory.deployContract({ storageSlots })

    return contractAbi as ExchangeContractAbi
}

Does this solve your issue?

from fuels-ts.

maschad avatar maschad commented on July 19, 2024

Hey @cherideal I suspect this may be because the pool was not initialized, after running

yarn start --task=initPool

then running

yarn start --task=test1

I got the following output

fuel19ztwgeul8yzffsr0df0me8kk8vtr5xpnwlkup79aksv8m47m9h0qdxlfru
0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07 1929679
test1 done
0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781 test USD tUSD 6
0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d test BTC tBTC 10
{
  tokenContract: '0xf1ea11be20f8d6d7a30ff69f21bffc1a95910e0459b03fbdd5c5070f4f48f82d',
  tokens: [
    {
      assetId: '0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781',
      subId: '0x0000000000000000000000000000000000000000000000000000000000000000',
      name: 'test USD',
      symbol: 'tUSD',
      decimals: 6
    },
    {
      assetId: '0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d',
      subId: '0x0000000000000000000000000000000000000000000000000000000000000001',
      name: 'test BTC',
      symbol: 'tBTC',
      decimals: 10
    }
  ],
  ammContract: '0xe00f7e7f0508ef31649b828bdfc1518c38e1b9ae09e04cb9681cfe6ba66a66de',
  pools: {
    '0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781': {
      '0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d': '0x5600472e368e0934a39d5c2c25db0b56152939265a9181e6a91bf8fc3d68d04a'
    },
    '0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d': {
      '0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781': '0x5600472e368e0934a39d5c2c25db0b56152939265a9181e6a91bf8fc3d68d04a'
    }
  }
}
✨  Done in 4.89s.

and then

yarn start --task=test2
yarn start --task=test2
yarn run v1.22.19
warning ../../../package.json: No license field
$ ts-node src/index.ts --task=test2
The Fuel Node that you are trying to connect to is using fuel-core version 0.29.0,
which is not supported by the version of the TS SDK that you are using.
Things may not work as expected.
Supported fuel-core version: 0.27.0.
fuel19ztwgeul8yzffsr0df0me8kk8vtr5xpnwlkup79aksv8m47m9h0qdxlfru
0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07 1929679
test2 done
0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781 test USD tUSD 6
0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d test BTC tBTC 10
{
  tokenContract: '0xf1ea11be20f8d6d7a30ff69f21bffc1a95910e0459b03fbdd5c5070f4f48f82d',
  tokens: [
    {
      assetId: '0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781',
      subId: '0x0000000000000000000000000000000000000000000000000000000000000000',
      name: 'test USD',
      symbol: 'tUSD',
      decimals: 6
    },
    {
      assetId: '0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d',
      subId: '0x0000000000000000000000000000000000000000000000000000000000000001',
      name: 'test BTC',
      symbol: 'tBTC',
      decimals: 10
    }
  ],
  ammContract: '0xe00f7e7f0508ef31649b828bdfc1518c38e1b9ae09e04cb9681cfe6ba66a66de',
  pools: {
    '0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781': {
      '0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d': '0x5600472e368e0934a39d5c2c25db0b56152939265a9181e6a91bf8fc3d68d04a'
    },
    '0x299ea939953a56ab887dc663140b7b65da4be47851eb5f216d5201290cdae30d': {
      '0x580085ecb00ce878a662d19582a5d40cbe4417184f2514ed427c937ce4f50781': '0x5600472e368e0934a39d5c2c25db0b56152939265a9181e6a91bf8fc3d68d04a'
    }
  }
}

Could you retry the commands and then let me know if this solves your issue?

from fuels-ts.

cherideal avatar cherideal commented on July 19, 2024

yarn start --task=initPool is used to manually initialize variables, but the problem now is that the variables are not initialized when they are defined.

from fuels-ts.

cherideal avatar cherideal commented on July 19, 2024

This solves my problem, but what is the purpose of the initialization here?
storage {
liquidity_pool_supply: u64 = 0
}

from fuels-ts.

maschad avatar maschad commented on July 19, 2024

This solves my problem, but what is the purpose of the initialization here? storage { liquidity_pool_supply: u64 = 0 }

Those said values that where initialized in a storage slot also need to be deployed with the smart contract in order for the VM to allocate the storage blocks. That's the purpose of the custom storage slots. You can read more about storage here

I'm going to close this issue since the initial problem has been addressed. Feel free to open a discussion or forum post if you have any more questions about storage.

from fuels-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.