Skip to content

Commit 7cbce9f

Browse files
committed
feat: add more collateral types, pivot to BLD/RUN and decimals
1 parent ac9049c commit 7cbce9f

File tree

4 files changed

+185
-76
lines changed

4 files changed

+185
-76
lines changed

packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js

+51-25
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ import { amountMath } from '@agoric/ertp';
1818
import { GCI } from './gci';
1919
import { makeBridgeManager } from './bridge';
2020
import { makeNameHubKit } from './nameHub';
21-
import { CENTRAL_ISSUER_NAME, fakeIssuerEntries } from './issuers';
21+
import {
22+
CENTRAL_ISSUER_NAME,
23+
fakeIssuerEntries,
24+
fromCosmosIssuerEntries,
25+
fromPegasusIssuerEntries,
26+
} from './issuers';
2227

2328
const NUM_IBC_PORTS = 3;
2429
const QUOTE_INTERVAL = 30;
2530

26-
const PERCENT_DENOM = 100n;
2731
const BASIS_POINTS_DENOM = 10000n;
2832

2933
console.debug(`loading bootstrap.js`);
@@ -115,28 +119,34 @@ export function buildRootObject(vatPowers, vatParameters) {
115119
// Now we can bootstrap the economy!
116120
const treasuryCreator = await installEconomy();
117121
const [centralIssuer, centralBrand] = await Promise.all(
118-
['issuer', 'brand'].map(hub => E(agoricNames).lookup(hub, 'MOE')),
122+
['issuer', 'brand'].map(hub => E(agoricNames).lookup(hub, 'RUN')),
119123
);
120124

125+
// [string, import('./issuers').IssuerInitializationRecord]
121126
const CENTRAL_ISSUER_ENTRY = [
122127
CENTRAL_ISSUER_NAME,
123128
{
124129
issuer: centralIssuer,
125-
mintValue: 0,
126-
pursePetname: 'Local currency',
127-
fakeTradesGivenCentral: [[1, 1]],
130+
defaultPurses: [['Agoric local currency', 0]],
131+
tradesGivenCentral: [[1, 1]],
128132
},
129133
];
130134

131135
/** @type {Store<string, import('./issuers').IssuerInitializationRecord>} */
132136
const issuerNameToRecord = makeStore();
137+
/** @type {Array<[string, import('./issuers').IssuerInitializationRecord]>} */
138+
const issuerEntries = [
139+
CENTRAL_ISSUER_ENTRY,
140+
...fromCosmosIssuerEntries,
141+
...fromPegasusIssuerEntries,
142+
];
133143
if (!noFakeCurrencies) {
134-
fakeIssuerEntries.map(entry => issuerNameToRecord.init(...entry));
144+
issuerEntries.push(...fakeIssuerEntries);
135145
}
136-
issuerNameToRecord.init(...CENTRAL_ISSUER_ENTRY);
146+
issuerEntries.forEach(entry => issuerNameToRecord.init(...entry));
137147

138148
const issuerNames = [...issuerNameToRecord.keys()];
139-
const issuers = await Promise.all(
149+
await Promise.all(
140150
issuerNames.map(async issuerName => {
141151
const record = issuerNameToRecord.get(issuerName);
142152
if (record.issuer !== undefined) {
@@ -188,20 +198,20 @@ export function buildRootObject(vatPowers, vatParameters) {
188198
console.debug(`Creating ${issuerName}-${CENTRAL_ISSUER_NAME}`);
189199
const record = issuerNameToRecord.get(issuerName);
190200
assert(record);
191-
const { fakeTradesGivenCentral, issuer } = record;
192-
if (!fakeTradesGivenCentral) {
201+
const { tradesGivenCentral, issuer } = record;
202+
if (!tradesGivenCentral) {
193203
return;
194204
}
195-
const fakeTradesGivenOther =
205+
const tradesGivenOther =
196206
centralIssuer !== issuer &&
197-
fakeTradesGivenCentral.map(([valueCentral, valueOther]) => [
207+
tradesGivenCentral.map(([valueCentral, valueOther]) => [
198208
valueOther,
199209
valueCentral,
200210
]);
201211
await Promise.all([
202-
makeFakePriceAuthority(centralIssuer, issuer, fakeTradesGivenCentral),
203-
fakeTradesGivenOther &&
204-
makeFakePriceAuthority(issuer, centralIssuer, fakeTradesGivenOther),
212+
makeFakePriceAuthority(centralIssuer, issuer, tradesGivenCentral),
213+
tradesGivenOther &&
214+
makeFakePriceAuthority(issuer, centralIssuer, tradesGivenOther),
205215
]);
206216
}),
207217
);
@@ -218,11 +228,14 @@ export function buildRootObject(vatPowers, vatParameters) {
218228
if (!config) {
219229
return undefined;
220230
}
231+
assert(record.tradesGivenCentral);
232+
const initialPrice = record.tradesGivenCentral[0];
233+
assert(initialPrice);
221234
const rates = {
222235
initialPrice: makeRatio(
223-
config.initialPricePercent,
236+
initialPrice[0],
224237
centralBrand,
225-
PERCENT_DENOM,
238+
initialPrice[1],
226239
record.brand,
227240
),
228241
initialMargin: makeRatio(config.initialMarginPercent, centralBrand),
@@ -304,18 +317,30 @@ export function buildRootObject(vatPowers, vatParameters) {
304317
additionalPowers.treasuryCreator = treasuryCreator;
305318
}
306319

320+
const mintNames = [];
321+
const mintPurses = [];
322+
const mintValues = [];
323+
issuerNames.forEach(issuerName => {
324+
const record = issuerNameToRecord.get(issuerName);
325+
if (!record.defaultPurses) {
326+
return;
327+
}
328+
record.defaultPurses.forEach(([purseName, value]) => {
329+
mintNames.push(issuerName);
330+
mintPurses.push(purseName);
331+
mintValues.push(value);
332+
});
333+
});
307334
const payments = await E(vats.mints).mintInitialPayments(
308-
issuerNames,
309-
issuerNames.map(
310-
issuerName => issuerNameToRecord.get(issuerName).mintValue,
311-
),
335+
mintNames,
336+
mintValues,
312337
);
313338

314-
const paymentInfo = issuerNames.map((issuerName, i) => ({
315-
issuer: issuers[i],
339+
const paymentInfo = mintNames.map((issuerName, i) => ({
340+
issuer: issuerNameToRecord.get(issuerName).issuer,
316341
issuerPetname: issuerName,
317342
payment: payments[i],
318-
pursePetname: issuerNameToRecord.get(issuerName).pursePetname,
343+
pursePetname: mintPurses[i],
319344
}));
320345

321346
const faucet = Far('faucet', {
@@ -600,6 +625,7 @@ export function buildRootObject(vatPowers, vatParameters) {
600625
return chainBundler.createUserBundle(nickname, 'demo', [
601626
'agoric.agoricNamesAdmin',
602627
'agoric.priceAuthorityAdmin',
628+
'agoric.treasuryCreator',
603629
'agoric.vattp',
604630
]);
605631
}

packages/cosmic-swingset/lib/ag-solo/vats/issuers.js

+127-44
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// @ts-check
22

3-
export const CENTRAL_ISSUER_NAME = 'MOE';
3+
export const CENTRAL_ISSUER_NAME = 'RUN';
44

55
/** @typedef {number | bigint} Bigish */
66

77
/**
88
* @typedef {Object} CollateralConfig
99
* @property {string} keyword
1010
* @property {Bigish} collateralValue
11-
* @property {bigint} initialPricePercent
1211
* @property {bigint} initialMarginPercent
1312
* @property {bigint} liquidationMarginPercent
1413
* @property {bigint} interestRateBasis
@@ -21,76 +20,160 @@ export const CENTRAL_ISSUER_NAME = 'MOE';
2120
* @property {Brand} [brand]
2221
* @property {Array<any>} [issuerArgs]
2322
* @property {CollateralConfig} [collateralConfig]
24-
* @property {string} pursePetname
25-
* @property {Bigish} mintValue
26-
* @property {Array<[Bigish, Bigish]>} [fakeTradesGivenCentral]
23+
* @property {Array<[string, Bigish]>} [defaultPurses]
24+
* @property {Array<[Bigish, Bigish]>} [tradesGivenCentral]
2725
*/
2826

27+
export const makeScaler = toDecimals => (n, fromDecimals = 0) => {
28+
if (typeof n === 'bigint') {
29+
return n * 10n ** BigInt(toDecimals);
30+
}
31+
return (
32+
BigInt(Math.floor(n * 10 ** fromDecimals)) *
33+
10n ** BigInt(toDecimals - fromDecimals)
34+
);
35+
};
36+
export const scaleMills = makeScaler(4);
37+
export const scaleMicro = makeScaler(6);
38+
export const scaleEth = makeScaler(18);
39+
export const scaleCentral = scaleMicro;
40+
2941
/** @type {Array<[string, IssuerInitializationRecord]>} */
30-
const fakeIssuerEntries = [
42+
const fromCosmosIssuerEntries = [
43+
[
44+
'BLD',
45+
{
46+
issuerArgs: [undefined, { decimalPlaces: 6 }],
47+
defaultPurses: [['Agoric staking token', scaleMicro(73)]],
48+
collateralConfig: {
49+
keyword: 'BLD',
50+
collateralValue: scaleMicro(1000000n),
51+
initialMarginPercent: 150n,
52+
liquidationMarginPercent: 125n,
53+
interestRateBasis: 250n,
54+
loanFeeBasis: 50n,
55+
},
56+
tradesGivenCentral: [
57+
[scaleCentral(27.9, 1), scaleMicro(1)],
58+
[scaleCentral(25.7, 1), scaleMicro(1)],
59+
[scaleCentral(26.8, 1), scaleMicro(1)],
60+
],
61+
},
62+
],
63+
];
64+
65+
harden(fromCosmosIssuerEntries);
66+
export { fromCosmosIssuerEntries };
67+
68+
/** @type {Array<[string, IssuerInitializationRecord]>} */
69+
const fromPegasusIssuerEntries = [
70+
[
71+
'ATOM',
72+
{
73+
issuerArgs: [undefined, { decimalPlaces: 6 }],
74+
defaultPurses: [['Cosmos Staking', scaleMicro(68)]],
75+
collateralConfig: {
76+
keyword: 'ATOM',
77+
collateralValue: scaleMicro(1000000n),
78+
initialMarginPercent: 150n,
79+
liquidationMarginPercent: 125n,
80+
interestRateBasis: 250n,
81+
loanFeeBasis: 50n,
82+
},
83+
tradesGivenCentral: [
84+
[scaleCentral(18.61, 2), scaleMicro(1)],
85+
[scaleCentral(19.97, 2), scaleMicro(1)],
86+
[scaleCentral(19.17, 2), scaleMicro(1)],
87+
],
88+
},
89+
],
90+
[
91+
'ETH',
92+
{
93+
issuerArgs: [undefined, { decimalPlaces: 18 }],
94+
collateralConfig: {
95+
keyword: 'ETH',
96+
collateralValue: scaleEth(1000000n),
97+
initialMarginPercent: 150n,
98+
liquidationMarginPercent: 125n,
99+
interestRateBasis: 250n,
100+
loanFeeBasis: 50n,
101+
},
102+
tradesGivenCentral: [
103+
[scaleCentral(1914.86, 2), scaleEth(1)],
104+
[scaleCentral(1489.87, 2), scaleEth(1)],
105+
[scaleCentral(1924.4, 2), scaleEth(1)],
106+
],
107+
},
108+
],
109+
// FIXME: Either of these entries (LINK or USDC) screw up the bootstrap process.
110+
// I'm not sure why.
111+
/*
31112
[
32113
'LINK',
33114
{
34115
issuerArgs: [undefined, { decimalPlaces: 18 }],
35-
mintValue: 51n * 10n ** 18n,
116+
defaultPurses: [['Oracle fee', scaleEth(51n)]],
36117
collateralConfig: {
37118
keyword: 'LINK',
38-
collateralValue: 1000000n * 10n ** 18n,
39-
initialPricePercent: 125n,
119+
collateralValue: scaleEth(1000000n),
40120
initialMarginPercent: 150n,
41121
liquidationMarginPercent: 125n,
42122
interestRateBasis: 250n,
43123
loanFeeBasis: 50n,
44124
},
45-
pursePetname: 'Oracle fee',
46-
fakeTradesGivenCentral: [
47-
[279000n, 10n ** 18n],
48-
[257000n, 10n ** 18n],
49-
[268000n, 10n ** 18n],
125+
tradesGivenCentral: [
126+
[scaleCentral(27.9, 2), scaleEth(1)],
127+
[scaleCentral(25.7, 2), scaleEth(1)],
128+
[scaleCentral(26.8, 2), scaleEth(1)],
50129
],
51130
},
52131
],
53132
[
54-
'moola',
133+
'USDC',
55134
{
56-
mintValue: 1900,
135+
issuerArgs: [undefined, { decimalPlaces: 18 }],
136+
defaultPurses: [['USD Coin', scaleEth(1323n)]],
57137
collateralConfig: {
58-
collateralValue: 7400000,
59-
keyword: 'Moola',
60-
initialPricePercent: 150n,
138+
keyword: 'USDC',
139+
collateralValue: scaleEth(1000000n),
61140
initialMarginPercent: 150n,
62-
liquidationMarginPercent: 120n,
63-
interestRateBasis: 200n,
64-
loanFeeBasis: 150n,
141+
liquidationMarginPercent: 125n,
142+
interestRateBasis: 250n,
143+
loanFeeBasis: 50n,
65144
},
66-
pursePetname: 'Fun budget',
67-
fakeTradesGivenCentral: [
68-
[10000, 1],
69-
[13000, 1],
70-
[12000, 1],
71-
[18000, 1],
72-
[15000, 1],
145+
tradesGivenCentral: [[scaleCentral(1), scaleEth(1)]],
146+
},
147+
],
148+
*/
149+
];
150+
151+
harden(fromPegasusIssuerEntries);
152+
export { fromPegasusIssuerEntries };
153+
154+
/** @type {Array<[string, IssuerInitializationRecord]>} */
155+
const fakeIssuerEntries = [
156+
[
157+
'moola',
158+
{
159+
defaultPurses: [['Fun budget', 1900]],
160+
tradesGivenCentral: [
161+
[scaleCentral(1), 1],
162+
[scaleCentral(1.3, 1), 1],
163+
[scaleCentral(1.2, 1), 1],
164+
[scaleCentral(1.8, 1), 1],
165+
[scaleCentral(1.5, 1), 1],
73166
],
74167
},
75168
],
76169
[
77170
'simolean',
78171
{
79-
mintValue: 970,
80-
collateralConfig: {
81-
collateralValue: 968000,
82-
keyword: 'Simolean',
83-
initialPricePercent: 110n,
84-
initialMarginPercent: 120n,
85-
liquidationMarginPercent: 105n,
86-
interestRateBasis: 100n,
87-
loanFeeBasis: 225n,
88-
},
89-
pursePetname: 'Nest egg',
90-
fakeTradesGivenCentral: [
91-
[213500, 1],
92-
[217200, 1],
93-
[212400, 1],
172+
defaultPurses: [['Nest egg', 970]],
173+
tradesGivenCentral: [
174+
[scaleCentral(21.35, 2), 1],
175+
[scaleCentral(21.72, 2), 1],
176+
[scaleCentral(21.24, 2), 1],
94177
],
95178
},
96179
],

0 commit comments

Comments
 (0)