agoric-labs / ag-power-tools

Agoric Power Tools: Contracts to Partition System Authorities
Apache License 2.0
1 stars 1 forks source link

feat(launchIt): launch a token (WIP) #7

Open dckc opened 10 months ago

dckc commented 10 months ago

goal: fixes #15

DRAFT until:

dckc commented 9 months ago

separate contract for each launch, using contractStarter

13 tests are passing as of 2029597. The launcher Larry, story, so far, is:

$ yarn test test/test-launchIt.js 
  ✔ boot, walletFactory, contractStarter (337ms)
...
  ✔ start launchIt instance to launch token (340ms)
    ℹ sam gives {
        brand: Object @Alleged: ZDEFAULT brand {},
        value: 0n,
      } to install launchIt
    ℹ sam install paid {
        Fee: {
          brand: Object @Alleged: ZDEFAULT brand {},
          value: 0n,
        },
        Handles: {
          brand: Object @Alleged: Zoe Invitation brand {},
          value: [
            Object { … },
          ],
        },
      }
    ℹ Larry prepares to launch {
        name: 'CDOG',
        supplyQty: 1000000n,
      }
    ℹ Larry pays {
        brand: Object @Alleged: ZDEFAULT brand {},
        value: 0n,
      } to start CDOG-launch
    ℹ larry launch result UNPUBLISHED
    ℹ larry launch instance Object @Alleged: InstanceHandle {}
    ℹ Larry opens pool thru {
        absValue: 10n,
        timerBrand: Object @Alleged: timerBrand {},
      }
    ℹ TODO: pool is open for contributions: Object @Alleged: InstanceHandle {}
    ℹ TODO: boostrap time is up. swap contributions
    ℹ TODO: 1,000,000 CDOG tokens are distributed to subscribers
    ℹ TODO Larry withdraws proceeds
  ─

  2 tests passed
Done in 1.56s.
dckc commented 9 months ago

working in 1 case: Larry launches BRD; market discovers price

Larry minted 1_000_000 BRD. A dozen fans bought shares and the market discovered a price of 0.000379 MNY/BRD.

2024-01-15 15:35 9d88719 test-launchIt: basic scenario complete

yarn test test/test-launchIt.js ``` $ yarn test test/test-launchIt.js bundles/ add: launchIt from /home/connolly/projects/ag-power-tools/contract/src/launchIt.js bundles/ bundle-contractStarter.js valid: 131 files bundled at 2024-01-15T05:37:02.747Z ✔ boot, walletFactory, contractStarter (1.6s) ... ✔ start launchIt instance to launch token (768ms) ℹ sam gives { brand: Object @Alleged: ZDEFAULT brand {}, value: 0n, } to install launchIt ℹ sam install paid { Fee: { brand: Object @Alleged: ZDEFAULT brand {}, value: 0n, }, Handles: { brand: Object @Alleged: Zoe Invitation brand {}, value: [ Object { … }, ], }, } ℹ Larry prepares to launch { name: 'BRD', supplyQty: 1000000n, } ℹ Larry pays { brand: Object @Alleged: ZDEFAULT brand {}, value: 0n, } to start BRD-launch ℹ larry launch result UNPUBLISHED ℹ larry launch instance Object @Alleged: InstanceHandle {} ℹ Larry opens pool thru { absValue: 10n, timerBrand: Object @Alleged: timerBrand {}, } ℹ 0 fan got { brand: Object @Alleged: Share brand {}, value: 3n, } ℹ 1 fan got { brand: Object @Alleged: Share brand {}, value: 26n, } ℹ 2 fan got { brand: Object @Alleged: Share brand {}, value: 49n, } ℹ 3 fan got { brand: Object @Alleged: Share brand {}, value: 25n, } ℹ 4 fan got { brand: Object @Alleged: Share brand {}, value: 48n, } ℹ 5 fan got { brand: Object @Alleged: Share brand {}, value: 24n, } ℹ 6 fan got { brand: Object @Alleged: Share brand {}, value: 47n, } ℹ 7 fan got { brand: Object @Alleged: Share brand {}, value: 23n, } ℹ 8 fan got { brand: Object @Alleged: Share brand {}, value: 46n, } ℹ 9 fan got { brand: Object @Alleged: Share brand {}, value: 22n, } ℹ 10 fan got { brand: Object @Alleged: Share brand {}, value: 45n, } ℹ 11 fan got { brand: Object @Alleged: Share brand {}, value: 21n, } ℹ time passed... to 11n ℹ TODO: should fan figure out his share of the proceeds? ℹ Larry collects proceeds { absValue: 10n, timerBrand: Object @Alleged: timerBrand {}, } ℹ result 379n ℹ @@proceeds { Deposit: { brand: Object @Alleged: MNY brand {}, value: 379n, }, } ℹ 0 fan got { brand: Object @Alleged: BRD brand {}, value: 7915n, } ℹ 1 fan got { brand: Object @Alleged: BRD brand {}, value: 68601n, } ℹ 2 fan got { brand: Object @Alleged: BRD brand {}, value: 129287n, } ℹ 3 fan got { brand: Object @Alleged: BRD brand {}, value: 65963n, } ℹ 4 fan got { brand: Object @Alleged: BRD brand {}, value: 126649n, } ℹ 5 fan got { brand: Object @Alleged: BRD brand {}, value: 63324n, } ℹ 6 fan got { brand: Object @Alleged: BRD brand {}, value: 124010n, } ℹ 7 fan got { brand: Object @Alleged: BRD brand {}, value: 60686n, } ℹ 8 fan got { brand: Object @Alleged: BRD brand {}, value: 121372n, } ℹ 9 fan got { brand: Object @Alleged: BRD brand {}, value: 58047n, } ℹ 10 fan got { brand: Object @Alleged: BRD brand {}, value: 118733n, } ℹ 11 fan got { brand: Object @Alleged: BRD brand {}, value: 55408n, } ─ 2 tests passed Done in 3.33s. ```
dckc commented 9 months ago

start launchIt with contractStarter on a local chain

deploy contract starter: yarn docker:make deploy-contract ``` $ yarn start:docker ... wait for logs to show steady blocks as usual $ yarn docker:make lower-bundle-cost $ yarn docker:make fund-acct mint100 $ yarn docker:make deploy-contract yarn run v1.22.19 $ docker compose exec agd make -C /workspace/contract deploy-contract make: Entering directory '/workspace/contract' yarn rollup -c rollup.config.mjs src/start-contractStarter.js yarn run v1.22.21 $ /workspace/node_modules/.bin/rollup -c rollup.config.mjs src/start-contractStarter.js Removing intrinsics.Symbol.dispose Removing intrinsics.Symbol.asyncDispose src/start-contractStarter.js → bundles/deploy-starter.js... bundles add: contractStarter from ./src/contractStarter.js bundles bundled 131 files in bundle-contractStarter.js at 2024-01-21T05:16:24.135Z @@@emit permit created bundles/deploy-starter.js in 1.2s Done in 1.55s. yarn --silent bundle-source --cache-json bundles/ src/contractStarter.js contractStarter Removing intrinsics.Symbol.dispose Removing intrinsics.Symbol.asyncDispose bundles/ add: contractStarter from src/contractStarter.js bundles/ bundled 131 files in bundle-contractStarter.json at 2024-01-21T05:16:25.803Z ls -sh bundles/bundle-contractStarter.json 1.2M bundles/bundle-contractStarter.json agd tx swingset install-bundle --compress "@bundles/bundle-contractStarter.json" \ -o json \ --from agoric1xe269y3fhye8nrlduf826wgn499y6wmnv32tw5 \ --keyring-backend=test --chain-id=agoriclocal --gas=auto --gas-adjustment=1.2 --yes -b block >bundles/bundle-contractStarter.json.installed || rm bundles/bundle-contractStarter.json.installed gas estimate: 45271506 TODO: try agoric publish to better track outcome jq '{bundleID: ("b1-" + .endoZipBase64Sha512)}' bundles/bundle-contractStarter.json { "bundleID": "b1-f3a9e5724d176bd950d6c45e313ab68a6a3009accbb5e4ec1ec59fae669a3c7d95611ee050d88ba3f65b24e07dd9a1913566008ac447e3a4c9305f347fab0e95" } jq '{code: .code, height: .height}' bundles/bundle-contractStarter.json.installed { "code": 0, "height": "1138" } SCRIPT=bundles/deploy-starter.js PERMIT=bundles/deploy-starter-permit.json TITLE="Deploy Starter Contract" \ ./scripts/propose-start-contract.sh + cd /workspace/contract + SCRIPT=bundles/deploy-starter.js + PERMIT=bundles/deploy-starter-permit.json + ls -sh bundles/deploy-starter.js bundles/deploy-starter-permit.json 4.0K bundles/deploy-starter-permit.json 8.0K bundles/deploy-starter.js ++ agd query gov proposals --output json ++ jq -c '.proposals | length | .+1' + PROPOSAL=10 + make fund-acct make[1]: Entering directory '/workspace/contract' agd tx bank send validator agoric1xe269y3fhye8nrlduf826wgn499y6wmnv32tw5 321000000ubld \ --keyring-backend=test --chain-id=agoriclocal --gas=auto --gas-adjustment=1.2 --yes -b block \ -o json >,tx.json gas estimate: 76761 jq '{code: .code, height: .height}' ,tx.json { "code": 0, "height": "1139" } make[1]: Leaving directory '/workspace/contract' + TITLE='Deploy Starter Contract' + FROM=user1 + CHAIN_ID=agoriclocal + agd tx gov submit-proposal swingset-core-eval bundles/deploy-starter-permit.json bundles/deploy-starter.js '--title=Deploy Starter Contract' '--description=Evaluate bundles/deploy-starter.js' --deposit=10000000ubld --gas=auto --gas-adjustment=1.2 --from user1 --chain-id agoriclocal --keyring-backend=test --yes -b block gas estimate: 1358548 code: 0 codespace: "" data: 0A2B0A252F636F736D6F732E676F762E763162657461312E4D73675375626D697450726F706F73616C1202080A ... type: submit_proposal gas_used: "1129104" gas_wanted: "1358548" height: "1140" info: "" logs: ... txhash: 0DA07CC7F2F29872BC93C61CAE678592A0384C882161BCACD698001E9EB6A889 waiting for block... txhash: 91880F99C56EECDE63A5B5757363C277CD6119779B16DA1533E4C727D485D77C waiting for block... ... txhash: E0E04358046C6A8861CF2A98E96DF208ECB78AB1AA4167FBA6C27F2DC0DE821D waiting for block... 1 block produced done Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) Waiting for proposal to pass (status=PROPOSAL_STATUS_VOTING_PERIOD) make: Leaving directory '/workspace/contract' Done in 17.91s. # agoric follow -lF :published.agoricNames.instance [ ... [ "walletFactory", slotToVal("board06366","Alleged: InstanceHandle"), ], [ "contractStarter", slotToVal("board00694","Alleged: InstanceHandle"), ], ] # agoric follow -lF :published.boardAux.board00694 { terms: { agoricNames: slotToVal("board04395","Alleged: NameHubKit nameHub"), board: slotToVal("board05396","Alleged: Board board"), brands: { Fee: slotToVal("board0257","Alleged: IST brand"), Invitation: slotToVal("board0074","Alleged: Zoe Invitation brand"), }, issuers: { Fee: slotToVal("board0223","Alleged: IST issuer"), Invitation: slotToVal("board0371","Alleged: Zoe Invitation issuer"), }, namesByAddress: slotToVal("board02897","Alleged: Hub work-around"), priceAuthority: slotToVal("board01998","Alleged: composite price authority"), prices: { installBundleID: { brand: slotToVal("board0257"), value: 0n, }, startInstance: { brand: slotToVal("board0257"), value: 0n, }, storageNode: { brand: slotToVal("board0257"), value: 0n, }, timerService: { brand: slotToVal("board0257"), value: 0n, }, }, }, } ```
yarn docker:make install-launchIt ``` $ yarn docker:make install-launchIt yarn run v1.22.19 $ docker compose exec agd make -C /workspace/contract install-launchIt make: Entering directory '/workspace/contract' yarn --silent bundle-source --cache-json bundles/ src/launchIt.js launchIt Removing intrinsics.Symbol.dispose Removing intrinsics.Symbol.asyncDispose bundles/ add: launchIt from src/launchIt.js (Error#1) Error#1: ENOENT: no such file or directory, stat '/workspace/node_modules/@agoric/zoe/src/contractSupport/ratio' bundles/ bundled 144 files in bundle-launchIt.json at 2024-01-21T05:21:16.350Z ls -sh bundles/bundle-launchIt.json 1.2M bundles/bundle-launchIt.json agd tx swingset install-bundle --compress "@bundles/bundle-launchIt.json" \ -o json \ --from agoric1xe269y3fhye8nrlduf826wgn499y6wmnv32tw5 \ --keyring-backend=test --chain-id=agoriclocal --gas=auto --gas-adjustment=1.2 --yes -b block >bundles/bundle-launchIt.json.installed || rm bundles/bundle-launchIt.json.installed gas estimate: 48815364 TODO: try agoric publish to better track outcome jq '{bundleID: ("b1-" + .endoZipBase64Sha512)}' bundles/bundle-launchIt.json { "bundleID": "b1-f36559a2de8d8611e431035f33a92a7473de08b2a56b2f2b790a7287182eb05e4e5a10fa87f680583b96dee43cfea5addecd637f64da72811b11f2aa16261fda" } jq '{code: .code, height: .height}' bundles/bundle-launchIt.json.installed { "code": 0, "height": "1425" } make: Leaving directory '/workspace/contract' Done in 2.66s. ```
start launchIt with contractStarter: offer-tool.js bundles/bundle-launchIt.json ``` $ yarn docker:bash ... user1: agoric1xe269y3fhye8nrlduf826wgn499y6wmnv32tw5 # cd /workspace/contract/ root@d54e832dc844:/workspace/contract# yarn node src/offer-tool.js bundles/bundle-launchIt.json yarn node v1.22.21 Removing intrinsics.Symbol.dispose Removing intrinsics.Symbol.asyncDispose XXX is sync IO essential? instance Object [Alleged: InstanceHandle#board00694] {} { offerId: 'start-1705814652985' } { offerId: 'start-1705814652985', height: '1599', txhash: '676E980D7E8603C88A7D7CB09CD98C7F476899E7F5755AC6DEE20904B1AA8F82', code: 0 } { offerId: 'start-1705814652985', height: '1599', txhash: '676E980D7E8603C88A7D7CB09CD98C7F476899E7F5755AC6DEE20904B1AA8F82', code: 0, result: 'UNPUBLISHED' } { offerId: 'start-1705814652985', height: '1599', txhash: '676E980D7E8603C88A7D7CB09CD98C7F476899E7F5755AC6DEE20904B1AA8F82', code: 0, payouts: { Fee: { brand: Object [Alleged: IST brand#board0257] {}, value: 0n }, Handles: { brand: Object [Alleged: Zoe Invitation brand#board0074] {}, value: [Array] } }, result: 'UNPUBLISHED' } { installation: Object [Alleged: BundleIDInstallation#null] {}, instance: Object [Alleged: InstanceHandle#board06299] {} } Done in 3.53s. # agoric follow -lF :published.boardAux.board06299 ... { terms: { brands: { BRD: slotToVal("board046100","Alleged: BRD brand"), Deposit: slotToVal("board0257","Alleged: IST brand"), Share: slotToVal("board003101","Alleged: Share brand"), }, issuers: { BRD: slotToVal("board029102","Alleged: BRD issuer"), Deposit: slotToVal("board0223","Alleged: IST issuer"), Share: slotToVal("board052103","Alleged: Share issuer"), }, name: "BRD", supplyQty: 1000000n, }, } ```