-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: virtualize pool with vpool facet
- Loading branch information
Showing
9 changed files
with
328 additions
and
249 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
// @ts-check | ||
|
||
import { Far } from '@endo/marshal'; | ||
import { defineKind } from '@agoric/swingset-vat/src/storeModule.js'; | ||
|
||
/** | ||
* @template {AssetKind} K | ||
* @param {string} allegedName | ||
* @param {Brand<K>} brand | ||
* @returns {Payment<K>} | ||
* @returns {() => Payment<K>} | ||
*/ | ||
export const makePayment = (allegedName, brand) => { | ||
return Far(`${allegedName} payment`, { | ||
getAllegedBrand: () => brand, | ||
}); | ||
export const makePaymentMaker = (allegedName, brand) => { | ||
const makePayment = defineKind( | ||
`${allegedName} payment`, | ||
() => ({}), | ||
() => ({ | ||
getAllegedBrand: () => brand, | ||
}), | ||
); | ||
return makePayment; | ||
}; | ||
harden(makePaymentMaker); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,60 @@ | ||
import { makeNotifierKit } from '@agoric/notifier'; | ||
import { Far } from '@endo/marshal'; | ||
import { defineKind } from '@agoric/swingset-vat/src/storeModule.js'; | ||
import { AmountMath } from './amountMath.js'; | ||
|
||
export const makePurse = (allegedName, assetKind, brand, purseMethods) => { | ||
let currentBalance = AmountMath.makeEmpty(brand, assetKind); | ||
export const makePurseMaker = (allegedName, assetKind, brand, purseMethods) => { | ||
const makePurseKit = defineKind( | ||
allegedName, | ||
() => { | ||
const currentBalance = AmountMath.makeEmpty(brand, assetKind); | ||
|
||
/** @type {NotifierRecord<Amount>} */ | ||
const { notifier: balanceNotifier, updater: balanceUpdater } = | ||
makeNotifierKit(currentBalance); | ||
/** @type {NotifierRecord<Amount>} */ | ||
const { notifier: balanceNotifier, updater: balanceUpdater } = | ||
makeNotifierKit(currentBalance); | ||
|
||
const updatePurseBalance = newPurseBalance => { | ||
currentBalance = newPurseBalance; | ||
balanceUpdater.updateState(currentBalance); | ||
}; | ||
|
||
/** @type {Purse} */ | ||
const purse = Far(`${allegedName} purse`, { | ||
deposit: (srcPayment, optAmountShape = undefined) => { | ||
// Note COMMIT POINT within deposit. | ||
return purseMethods.deposit( | ||
return { | ||
currentBalance, | ||
updatePurseBalance, | ||
srcPayment, | ||
optAmountShape, | ||
); | ||
balanceNotifier, | ||
balanceUpdater, | ||
}; | ||
}, | ||
withdraw: amount => | ||
// Note COMMIT POINT within withdraw. | ||
purseMethods.withdraw(currentBalance, updatePurseBalance, amount), | ||
getCurrentAmount: () => currentBalance, | ||
getCurrentAmountNotifier: () => balanceNotifier, | ||
getAllegedBrand: () => brand, | ||
// eslint-disable-next-line no-use-before-define | ||
getDepositFacet: () => depositFacet, | ||
}); | ||
|
||
const depositFacet = Far(`${allegedName} depositFacet`, { | ||
receive: purse.deposit, | ||
}); | ||
state => { | ||
const { balanceNotifier, balanceUpdater } = state; | ||
const updatePurseBalance = newPurseBalance => { | ||
state.currentBalance = newPurseBalance; | ||
balanceUpdater.updateState(state.currentBalance); | ||
}; | ||
|
||
return purse; | ||
/** @type {Purse} */ | ||
const purse = { | ||
deposit: (srcPayment, optAmountShape = undefined) => { | ||
// Note COMMIT POINT within deposit. | ||
return purseMethods.deposit( | ||
state.currentBalance, | ||
updatePurseBalance, | ||
srcPayment, | ||
optAmountShape, | ||
); | ||
}, | ||
withdraw: amount => | ||
// Note COMMIT POINT within withdraw. | ||
purseMethods.withdraw( | ||
state.currentBalance, | ||
updatePurseBalance, | ||
amount, | ||
), | ||
getCurrentAmount: () => state.currentBalance, | ||
getCurrentAmountNotifier: () => balanceNotifier, | ||
getAllegedBrand: () => brand, | ||
// eslint-disable-next-line no-use-before-define | ||
getDepositFacet: () => depositFacet, | ||
}; | ||
const depositFacet = { | ||
receive: purse.deposit, | ||
}; | ||
return { purse, depositFacet }; | ||
}, | ||
); | ||
return () => makePurseKit().purse; | ||
}; | ||
harden(makePurseMaker); |
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
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
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
Oops, something went wrong.