Created
May 11, 2023 00:05
-
-
Save erights/7b5ed0f47bf610ead613b197a7f4c203 to your computer and use it in GitHub Desktop.
Another example loss of horizontal whitespace by bundling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let M,mustMatch,prepareExoClass,prepareExo,swapExact,InvitationShape,isAfterDeadlineExitRule,OfferHandlerI;$h_imports([["@agoric/store", [["M", [$h_a => (M = $h_a)]],["mustMatch", [$h_a => (mustMatch = $h_a)]]]],["../../../exported.js", []],["@agoric/vat-data", [["prepareExoClass", [$h_a => (prepareExoClass = $h_a)]],["prepareExo", [$h_a => (prepareExo = $h_a)]]]],["../../../src/contractSupport/index.js", [["swapExact", [$h_a => (swapExact = $h_a)]]]],["../../../src/typeGuards.js", [["InvitationShape", [$h_a => (InvitationShape = $h_a)]],["isAfterDeadlineExitRule", [$h_a => (isAfterDeadlineExitRule = $h_a)]],["OfferHandlerI", [$h_a => (OfferHandlerI = $h_a)]]]]]); | |
const{details:X}=assert; | |
const sellSeatExpiredMsg='The covered call option is expired.'; | |
/** | |
* @see original version in .../zoe/src/contracts/coveredCall.js and upgradeable | |
* version in contracts/coveredCall-durable.js. | |
* | |
* This variant has minor changes to the returned strings that make it | |
* identifiable, to demonstrate that upgrade has occurred. | |
* | |
* @param {ZCF} zcf | |
* @param {unknown} _privateArgs | |
* @param {Ximport('@agoric/vat-data').Baggage} instanceBaggage | |
*/ | |
const prepare=async(zcf,_privateArgs,instanceBaggage)=>{ | |
debugger; | |
const firstTime=!instanceBaggage.has('DidStart'); | |
if(firstTime){ | |
instanceBaggage.init('DidStart',true); | |
} | |
const upgraded=firstTime?'V3 ':'V3 upgraded '; | |
/* TODO the exerciseOption offer handler that this makes is an object rather*/ | |
/* than a function for now only because we do not yet support durable*/ | |
/* functions.*/ | |
const makeExerciser=prepareExoClass( | |
instanceBaggage, | |
'makeExerciserKindHandle', | |
OfferHandlerI, | |
(sellSeat)=>({sellSeat}), | |
{ | |
handle(buySeat){ | |
const{state}=this; | |
assert(!state.sellSeat.hasExited(),sellSeatExpiredMsg); | |
try{ | |
swapExact(zcf,state.sellSeat,buySeat); | |
}catch(err){ | |
console.log( | |
`Swap ${upgraded}failed. Please make sure your offer has the same underlyingAssets and strikePrice as specified in the invitation details. The keywords should not matter.`, | |
err); | |
throw err; | |
} | |
zcf.shutdown( `Swap ${upgraded}completed.`); | |
return `The ${upgraded}option was exercised. Please collect the assets in your payout.`; | |
}}); | |
/** @type {OfferHandler} */ | |
const makeOption=(sellSeat)=>{ | |
mustMatch( | |
sellSeat.getProposal(), | |
M.split({exit:{afterDeadline:M.any()}})); | |
const sellSeatExitRule=sellSeat.getProposal().exit; | |
if(!isAfterDeadlineExitRule(sellSeatExitRule)){ | |
/* TypeScript confused about `||` control flow so use `if` instead*/ | |
/* https://github.com/microsoft/TypeScript/issues/50739*/ | |
assert.fail( | |
X `the seller must have an afterDeadline exitRule, but instead had ${sellSeatExitRule}`); | |
} | |
const exerciseOption=makeExerciser(sellSeat); | |
const customDetails=harden({ | |
expirationDate:sellSeatExitRule.afterDeadline.deadline, | |
timeAuthority:sellSeatExitRule.afterDeadline.timer, | |
underlyingAssets:sellSeat.getProposal().give, | |
strikePrice:sellSeat.getProposal().want}); | |
return zcf.makeInvitation(exerciseOption,'exerciseOption',customDetails); | |
}; | |
const CCallCreatorI=M.interface('CCallCreator',{ | |
makeInvitation:M.call().returns(M.eref(InvitationShape))}); | |
const creatorFacet=prepareExo( | |
instanceBaggage, | |
'creatorFacet', | |
CCallCreatorI, | |
{ | |
makeInvitation(){ | |
return zcf.makeInvitation(makeOption,'makeCallOption'); | |
}}); | |
return harden({creatorFacet}); | |
};$h_once.prepare(prepare); | |
harden(prepare); | |
}) | |
//# sourceURL=.../zoe/test/swingsetTests/upgradeCoveredCall/coveredCall-durable-V3.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { M, mustMatch } from '@agoric/store'; | |
import '../../../exported.js'; | |
import { prepareExoClass, prepareExo } from '@agoric/vat-data'; | |
import { swapExact } from '../../../src/contractSupport/index.js'; | |
import { | |
InvitationShape, | |
isAfterDeadlineExitRule, | |
OfferHandlerI, | |
} from '../../../src/typeGuards.js'; | |
const { details: X } = assert; | |
const sellSeatExpiredMsg = 'The covered call option is expired.'; | |
/** | |
* @see original version in .../zoe/src/contracts/coveredCall.js and upgradeable | |
* version in contracts/coveredCall-durable.js. | |
* | |
* This variant has minor changes to the returned strings that make it | |
* identifiable, to demonstrate that upgrade has occurred. | |
* | |
* @param {ZCF} zcf | |
* @param {unknown} _privateArgs | |
* @param {import('@agoric/vat-data').Baggage} instanceBaggage | |
*/ | |
const prepare = async (zcf, _privateArgs, instanceBaggage) => { | |
debugger; | |
const firstTime = !instanceBaggage.has('DidStart'); | |
if (firstTime) { | |
instanceBaggage.init('DidStart', true); | |
} | |
const upgraded = firstTime ? 'V3 ' : 'V3 upgraded '; | |
// TODO the exerciseOption offer handler that this makes is an object rather | |
// than a function for now only because we do not yet support durable | |
// functions. | |
const makeExerciser = prepareExoClass( | |
instanceBaggage, | |
'makeExerciserKindHandle', | |
OfferHandlerI, | |
sellSeat => ({ sellSeat }), | |
{ | |
handle(buySeat) { | |
const { state } = this; | |
assert(!state.sellSeat.hasExited(), sellSeatExpiredMsg); | |
try { | |
swapExact(zcf, state.sellSeat, buySeat); | |
} catch (err) { | |
console.log( | |
`Swap ${upgraded}failed. Please make sure your offer has the same underlyingAssets and strikePrice as specified in the invitation details. The keywords should not matter.`, | |
err, | |
); | |
throw err; | |
} | |
zcf.shutdown(`Swap ${upgraded}completed.`); | |
return `The ${upgraded}option was exercised. Please collect the assets in your payout.`; | |
}, | |
}, | |
); | |
/** @type {OfferHandler} */ | |
const makeOption = sellSeat => { | |
mustMatch( | |
sellSeat.getProposal(), | |
M.split({ exit: { afterDeadline: M.any() } }), | |
); | |
const sellSeatExitRule = sellSeat.getProposal().exit; | |
if (!isAfterDeadlineExitRule(sellSeatExitRule)) { | |
// TypeScript confused about `||` control flow so use `if` instead | |
// https://github.com/microsoft/TypeScript/issues/50739 | |
assert.fail( | |
X`the seller must have an afterDeadline exitRule, but instead had ${sellSeatExitRule}`, | |
); | |
} | |
const exerciseOption = makeExerciser(sellSeat); | |
const customDetails = harden({ | |
expirationDate: sellSeatExitRule.afterDeadline.deadline, | |
timeAuthority: sellSeatExitRule.afterDeadline.timer, | |
underlyingAssets: sellSeat.getProposal().give, | |
strikePrice: sellSeat.getProposal().want, | |
}); | |
return zcf.makeInvitation(exerciseOption, 'exerciseOption', customDetails); | |
}; | |
const CCallCreatorI = M.interface('CCallCreator', { | |
makeInvitation: M.call().returns(M.eref(InvitationShape)), | |
}); | |
const creatorFacet = prepareExo( | |
instanceBaggage, | |
'creatorFacet', | |
CCallCreatorI, | |
{ | |
makeInvitation() { | |
return zcf.makeInvitation(makeOption, 'makeCallOption'); | |
}, | |
}, | |
); | |
return harden({ creatorFacet }); | |
}; | |
harden(prepare); | |
export { prepare }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment