Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 13 commits into
base: dc-starter
Choose a base branch
from
Draft

Conversation

dckc
Copy link
Collaborator

@dckc dckc commented Jan 2, 2024

@dckc dckc force-pushed the dc-launchpad branch 2 times, most recently from 39319ac to 657f685 Compare January 12, 2024 04:45
@dckc dckc changed the base branch from main to dc-arb-asset-naming January 13, 2024 16:43
@dckc dckc force-pushed the dc-launchpad branch 3 times, most recently from 28f316e to 67332ee Compare January 14, 2024 23:42
@dckc dckc changed the base branch from dc-arb-asset-naming to dc-starter January 15, 2024 05:23
@dckc
Copy link
Collaborator Author

dckc commented Jan 15, 2024

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.

* @param {string} kw
*/
const makeZcfIssuerKit = async (zcf, kw) => {
const mint = await zcf.makeZCFMint(kw);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to throw, than to prepend with KW. Is ^[A-Z]/ something that could/should be supported by @endo/patterns?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah; that's clearly a KLUDGE

endo/patterns avoids regex stuff.

The core issue is: makeZCFMint conflates issuerName with keyword. I want the brand to print as BRD, but keywords are more naturally for a role played by a brand in the contract; in this case, Minted. IOU an agoric-sdk issue on this.

@dckc
Copy link
Collaborator Author

dckc commented Jan 15, 2024

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.

{ want: { Shares: ShapeAmt.Share } },
),
Withdraw: M.splitRecord({
want: { Deposit: ShapeAmt.Deposit },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has different bracing than the previous lines. That seems more like a bug than a difference.

},
};
// export these from a client interface module?
const Shape = harden({
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a subtle difference between M.splitRecord({ give: X, want: Y}) and M.splitRecord({ give: X }, { want: Y })

merits a comment

ack: @dtribble

*/
export const start = async (zcf, _privateArgs, _baggage) => {
const { name, supplyQty, displayInfo = {}, brands } = zcf.getTerms();
mustMatch(brands, M.splitRecord({ Deposit: BrandShape }));
Copy link
Contributor

@0xpatrickdev 0xpatrickdev Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why M.splitRecord(...) instead of harden({ Deposit: BrandShape })? Are we expecting brands to be keyed with anything else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time, I only needed this brand to exist for the code I was writing to be correct.

Stepping back and looking at the whole thing now, no, I don't think there are any others.

@dckc
Copy link
Collaborator Author

dckc commented Jan 21, 2024

start launchIt with contractStarter on a local chain

  • 2024-01-20 23:11 a0bdf5c feat(offer-tool): start launchIt with contractStarter
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,
  },
}

@dckc dckc force-pushed the dc-starter branch 4 times, most recently from c79876c to 2e8dd66 Compare January 21, 2024 23:11
@dckc dckc force-pushed the dc-launchpad branch 3 times, most recently from 9d5a04c to f08702b Compare January 22, 2024 04:56
 - use zoe exit for deadline
 - test-launchIt: start with contractStarter
 - larry returns instance so others can subscribe / deposit
 - Larry's wallet needs to know about MNY
   (recall upcoming HACK to add stuff to agoricNames)
 - NEEDSTEST: withdraw
 - NEEDSTEST: unhappy paths, esp timing
 - test: prune albert dead code

tests:
  ✔ boot, walletFactory, contractStarter
  ✔ start launchIt instance to launch token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

launchpad with price discovery
4 participants