-
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.
feat: refactor parameter governance support to allow for Invitations (#…
…4121) Invitations didn't fit the old model, so turned it into more polymorphic objects. I didn't get as much type-checking advantage as I expected. Moved parameter governance support into a subdirectory, which touched a bunch of files lightly. Added separate types for Amounts and Ratios whose Brands must match. vaults weren't using the params passed to them, so they were dropped. get parameters by type Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
cdf58e6
commit 159596b
Showing
39 changed files
with
1,183 additions
and
749 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// @ts-check | ||
|
||
import { isRemotable } from '@agoric/marshal'; | ||
import { assertIsRatio } from '@agoric/zoe/src/contractSupport/ratio.js'; | ||
|
||
const { details: X } = assert; | ||
|
||
const makeLooksLikeBrand = name => { | ||
return brand => { | ||
assert( | ||
// @ts-ignore value is undifferentiated to this point | ||
isRemotable(brand), | ||
X`value for ${name} must be a brand, was ${brand}`, | ||
); | ||
}; | ||
}; | ||
harden(makeLooksLikeBrand); | ||
|
||
const makeAssertInstallation = name => { | ||
return installation => { | ||
// TODO(3344): add a better assertion once Zoe validates installations | ||
assert( | ||
typeof installation === 'object' && | ||
Object.getOwnPropertyNames(installation).length === 1, | ||
X`value for ${name} must be an Installation, was ${installation}`, | ||
); | ||
}; | ||
}; | ||
harden(makeAssertInstallation); | ||
|
||
const makeAssertInstance = name => { | ||
return instance => { | ||
// TODO(3344): add a better assertion once Zoe validates instances | ||
assert( | ||
typeof instance === 'object' && | ||
Object.getOwnPropertyNames(instance).length === 0, | ||
X`value for ${name} must be an Instance, was ${instance}`, | ||
); | ||
}; | ||
}; | ||
harden(makeAssertInstance); | ||
|
||
const makeAssertBrandedRatio = (name, modelRatio) => { | ||
return ratio => { | ||
assertIsRatio(ratio); | ||
assert( | ||
ratio.numerator.brand === modelRatio.numerator.brand, | ||
X`Numerator brand for ${name} must be ${modelRatio.numerator.brand}`, | ||
); | ||
assert( | ||
ratio.denominator.brand === modelRatio.denominator.brand, | ||
X`Denominator brand for ${name} must be ${modelRatio.denominator.brand}`, | ||
); | ||
return true; | ||
}; | ||
}; | ||
harden(makeAssertBrandedRatio); | ||
|
||
export { | ||
makeLooksLikeBrand, | ||
makeAssertInstallation, | ||
makeAssertInstance, | ||
makeAssertBrandedRatio, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// ts-check | ||
|
||
import { ParamType } from './paramManager.js'; | ||
|
||
const makeGovernedNat = value => { | ||
return harden({ type: ParamType.NAT, value }); | ||
}; | ||
|
||
const makeGovernedAmount = value => { | ||
return harden({ type: ParamType.AMOUNT, value }); | ||
}; | ||
|
||
const makeGovernedRatio = value => { | ||
return harden({ type: ParamType.RATIO, value }); | ||
}; | ||
|
||
const makeGovernedBrand = value => { | ||
return harden({ type: ParamType.BRAND, value }); | ||
}; | ||
|
||
const makeGovernedInstance = value => { | ||
return harden({ type: ParamType.INSTANCE, value }); | ||
}; | ||
|
||
const makeGovernedInstallation = value => { | ||
return harden({ type: ParamType.INSTALLATION, value }); | ||
}; | ||
|
||
// value is an invitation amount, not an invitation | ||
const makeGovernedInvitation = value => { | ||
return harden({ type: ParamType.INVITATION, value }); | ||
}; | ||
|
||
const makeGovernedString = value => { | ||
return harden({ type: ParamType.STRING, value }); | ||
}; | ||
|
||
const makeGovernedUnknown = value => { | ||
return harden({ type: ParamType.UNKNOWN, value }); | ||
}; | ||
|
||
harden(makeGovernedAmount); | ||
harden(makeGovernedBrand); | ||
harden(makeGovernedInstallation); | ||
harden(makeGovernedInstance); | ||
harden(makeGovernedInvitation); | ||
harden(makeGovernedNat); | ||
harden(makeGovernedRatio); | ||
harden(makeGovernedString); | ||
harden(makeGovernedUnknown); | ||
|
||
export { | ||
makeGovernedAmount, | ||
makeGovernedBrand, | ||
makeGovernedInstallation, | ||
makeGovernedInstance, | ||
makeGovernedInvitation, | ||
makeGovernedNat, | ||
makeGovernedRatio, | ||
makeGovernedString, | ||
makeGovernedUnknown, | ||
}; |
Oops, something went wrong.