-
Notifications
You must be signed in to change notification settings - Fork 225
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
wallet misc #6191
wallet misc #6191
Changes from all commits
2e7e93f
0718500
69bf74e
c14aca6
c6ef58c
b241df1
2d47690
aa97747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
#!/bin/sh | ||
|
||
export AGORIC_NET=ollinet | ||
if [ -z "$AGORIC_NET" ]; then | ||
echo "AGORIC_NET env not set" | ||
echo | ||
echo "e.g. AGORIC_NET=ollinet (or export to save typing it each time)" | ||
echo | ||
echo "To test locally, AGORIC_NET=local and have the following running: | ||
# freshen sdk | ||
cd agoric-sdk | ||
yarn install && yarn build | ||
|
||
# (new tab) | ||
# Start the chain | ||
cd packages/cosmic-swingset | ||
make scenario2-setup scenario2-run-chain-psm | ||
|
||
# (new tab) | ||
# Fund the pool (addr is a magic string) | ||
make SOLO_COINS=1234000000ibc/usdc1234 ACCT_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346 fund-acct | ||
# Provision your wallet | ||
cd packages/cosmic-swingset | ||
# Copy the agoric address from your keplr wallet or 'agd keys list', starts with 'agoric1' | ||
WALLET_ADDR=<yours> | ||
make ACCT_ADDR=$WALLET_ADDR AGORIC_POWERS=SMART_WALLET fund-acct provision-acct | ||
# verify | ||
agoric wallet list | ||
agoric wallet show --from $WALLET_ADDR | ||
" | ||
exit 1 | ||
fi | ||
|
||
KEY=$1 | ||
|
||
if [ -z "$KEY" ] | ||
then | ||
echo "USAGE: $0 key" | ||
echo "You can reference by name: agd keys list" | ||
echo "Make sure it has been provisioned by the faucet: https://$AGORIC_NET.faucet.agoric.net/" | ||
exit 1 | ||
if [ -z "$KEY" ]; then | ||
echo "USAGE: $0 key" | ||
echo "You can reference by name: agd keys list" | ||
echo "Make sure it has been provisioned by the faucet: https://$AGORIC_NET.faucet.agoric.net/" | ||
exit 1 | ||
fi | ||
|
||
set -x | ||
|
||
# NB: fee percentages must be at least the governed param values | ||
|
||
# perf test wantMinted | ||
OFFER=$(mktemp -t agops) | ||
bin/agops psm swap --wantMinted 0.01 --feePct 0.01 >| "$OFFER" | ||
OFFER=$(mktemp -t agops.XXX) | ||
bin/agops psm swap --wantMinted 0.01 --feePct 0.01 >|"$OFFER" | ||
time bin/agops perf satisfaction --executeOffer "$OFFER" --from "$KEY" | ||
|
||
# perf test giveMinted | ||
OFFER=$(mktemp -t agops) | ||
bin/agops psm swap --giveMinted 0.01 --feePct 0.01 >| "$OFFER" | ||
OFFER=$(mktemp -t agops.XXX) | ||
bin/agops psm swap --giveMinted 0.01 --feePct 0.03 >|"$OFFER" | ||
time bin/agops perf satisfaction --executeOffer "$OFFER" --from "$KEY" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /usr/bin/env node | ||
import '@endo/init'; | ||
import { createBundles } from '@agoric/deploy-script-support'; | ||
import url from 'url'; | ||
|
||
const dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
const sourceToBundle = [ | ||
[ | ||
`@agoric/smart-wallet/src/walletFactory.js`, | ||
`../bundles/bundle-walletFactory.js`, | ||
], | ||
]; | ||
|
||
await createBundles(sourceToBundle, dirname); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ export const UNPUBLISHED_RESULT = 'UNPUBLISHED'; | |
* @param {{ receive: (payment: *) => Promise<Amount> }} opts.depositFacet | ||
* @param {object} opts.powers | ||
* @param {import('./types').Cell<number>} opts.powers.lastOfferId | ||
* @param {Pick<Console, 'info'| 'error'>} opts.powers.logger | ||
* @param {(spec: import('./invitations').InvitationSpec) => ERef<Invitation>} opts.powers.invitationFromSpec | ||
* @param {(brand: Brand) => import('./types').RemotePurse} opts.powers.purseForBrand | ||
* @param {(status: OfferStatus) => void} opts.onStatusChange | ||
|
@@ -43,7 +44,7 @@ export const makeOfferExecutor = ({ | |
onStatusChange, | ||
onNewContinuingOffer, | ||
}) => { | ||
const { invitationFromSpec, lastOfferId, purseForBrand } = powers; | ||
const { invitationFromSpec, lastOfferId, logger, purseForBrand } = powers; | ||
|
||
return { | ||
/** | ||
|
@@ -54,6 +55,8 @@ export const makeOfferExecutor = ({ | |
* @throws if any parts of the offer can be determined synchronously to be invalid | ||
*/ | ||
async executeOffer(offerSpec) { | ||
logger.info('starting executeOffer', offerSpec.id); | ||
|
||
const paymentsManager = makePaymentsHelper(purseForBrand, depositFacet); | ||
|
||
/** @type {OfferStatus} */ | ||
|
@@ -71,7 +74,7 @@ export const makeOfferExecutor = ({ | |
* @param {Error} err | ||
*/ | ||
const handleError = err => { | ||
console.error('OFFER ERROR:', err); | ||
logger.error('OFFER ERROR:', err); | ||
updateStatus({ error: err.toString() }); | ||
paymentsManager.tryReclaimingWithdrawnPayments().then(result => { | ||
if (result) { | ||
|
@@ -104,23 +107,32 @@ export const makeOfferExecutor = ({ | |
paymentKeywordRecord, | ||
offerArgs, | ||
); | ||
// ??? should we notify of being seated? | ||
logger.info(id, 'seated'); | ||
|
||
// publish 'result' | ||
E.when( | ||
E(seatRef).getOfferResult(), | ||
result => { | ||
const passStyle = passStyleOf(result); | ||
console.log('offerResult', passStyle, result); | ||
logger.info(id, 'offerResult', passStyle, result); | ||
// someday can we get TS to type narrow based on the passStyleOf result match? | ||
switch (passStyle) { | ||
case 'bigint': | ||
case 'boolean': | ||
case 'null': | ||
case 'number': | ||
case 'string': | ||
case 'symbol': | ||
case 'undefined': | ||
updateStatus({ result }); | ||
break; | ||
case 'copyRecord': | ||
if ('invitationMakers' in result) { | ||
// save for continuing invitation offer | ||
onNewContinuingOffer(id, result.invitationMakers); | ||
} | ||
// ??? are all copyRecord types valid to publish? | ||
updateStatus({ result }); | ||
// copyRecord is valid to publish but not safe as it may have private info | ||
updateStatus({ result: UNPUBLISHED_RESULT }); | ||
break; | ||
default: | ||
// drop the result | ||
|
@@ -131,14 +143,19 @@ export const makeOfferExecutor = ({ | |
); | ||
|
||
// publish 'numWantsSatisfied' | ||
E.when(E(seatRef).numWantsSatisfied(), numSatisfied => { | ||
if (numSatisfied === 0) { | ||
updateStatus({ numWantsSatisfied: 0 }); | ||
} | ||
updateStatus({ | ||
numWantsSatisfied: numSatisfied, | ||
}); | ||
}); | ||
E.when( | ||
E(seatRef).numWantsSatisfied(), | ||
numSatisfied => { | ||
logger.info(id, 'numSatisfied', numSatisfied); | ||
if (numSatisfied === 0) { | ||
updateStatus({ numWantsSatisfied: 0 }); | ||
} | ||
updateStatus({ | ||
numWantsSatisfied: numSatisfied, | ||
}); | ||
}, | ||
handleError, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commit message doesn't mention this. (not critical) |
||
); | ||
|
||
// publish 'payouts' | ||
// This will block until all payouts succeed, but user will be updated | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,7 +343,9 @@ const behavior = { | |
*/ | ||
async executeOffer(offerSpec) { | ||
const { facets, state } = this; | ||
/** @type {State} */ | ||
const { | ||
address, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm. I missed something somewhere. A wallet knows the address it's associated with? Is that necessary? It sets off my ACL spidey-sense... it feels vagely like caller or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I had the same tingle. It's not strictly necessary. We could take it out by passing two other things in instead:
But it has to persist through init and there may be some churn with durability, so I'll punt until then: #5894 |
||
zoe, | ||
brandPurses, | ||
invitationBrand, | ||
|
@@ -353,6 +355,11 @@ const behavior = { | |
updatePublishKit, | ||
} = this.state; | ||
|
||
const logger = { | ||
info: (...args) => console.info('wallet', address, ...args), | ||
error: (...args) => console.log('wallet', address, ...args), | ||
}; | ||
|
||
const executor = makeOfferExecutor({ | ||
zoe, | ||
depositFacet: facets.deposit, | ||
|
@@ -375,12 +382,15 @@ const behavior = { | |
state.lastOfferId = id; | ||
}, | ||
}, | ||
logger, | ||
}, | ||
onStatusChange: offerStatus => | ||
onStatusChange: offerStatus => { | ||
logger.info('offerStatus', offerStatus); | ||
updatePublishKit.publisher.publish({ | ||
updated: 'offerStatus', | ||
status: offerStatus, | ||
}), | ||
}); | ||
}, | ||
onNewContinuingOffer: (offerId, invitationMakers) => | ||
offerToInvitationMakers.init(offerId, invitationMakers), | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 ocap-happy logging