Skip to content

Commit fec111b

Browse files
committed
chore(script): add supply to loan markets
1 parent cdbc5d8 commit fec111b

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

scripts/init-testnet.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ main().catch((err) => {
4040
console.log(err);
4141
});
4242

43+
type Currency = { Token: any } | { ForeignAsset: any } | { LendToken: any };
44+
type LoansMarket = { collateralFactor?: any; liquidationThreshold?: any; reserveFactor?: any; closeFactor?: any; liquidateIncentive?: any; liquidateIncentiveReservedFactor?: any; rateModel?: any; state?: any; supplyCap?: any; borrowCap?: any; lendTokenId?: any };
45+
4346
function constructLendingSetup(api: ApiPromise) {
44-
const addMarkets = [
45-
api.tx.loans.addMarket(
47+
const markets: [Currency, LoansMarket][] = [
48+
[
4649
{
4750
Token: 'KBTC'
4851
},
@@ -66,7 +69,7 @@ function constructLendingSetup(api: ApiPromise) {
6669
borrowCap: "2000000000",
6770
lendTokenId: { LendToken: 1 }
6871
}
69-
), api.tx.loans.addMarket(
72+
], [
7073
{
7174
Token: 'KSM'
7275
},
@@ -90,7 +93,7 @@ function constructLendingSetup(api: ApiPromise) {
9093
borrowCap: "30000000000000000",
9194
lendTokenId: { LendToken: 2 }
9295
}
93-
), api.tx.loans.addMarket(
96+
], [
9497
{
9598
ForeignAsset: 1 // usdt
9699
},
@@ -114,7 +117,7 @@ function constructLendingSetup(api: ApiPromise) {
114117
borrowCap: "80000000000",
115118
lendTokenId: { LendToken: 3 }
116119
}
117-
), api.tx.loans.addMarket(
120+
], [
118121
{
119122
ForeignAsset: 2 // movr
120123
},
@@ -138,30 +141,35 @@ function constructLendingSetup(api: ApiPromise) {
138141
borrowCap: "20000000000000000000000",
139142
lendTokenId: { LendToken: 4 }
140143
}
141-
)
144+
],
142145
];
143146

144-
const underlyingTokens = [
145-
{ Token: "KBTC" },
146-
{ Token: "KSM" },
147-
{ ForeignAsset: 1 }, // USDT
148-
{ ForeignAsset: 2 }, // MOVR
149-
];
147+
const addMarkets = markets.map(([token, market]) => {
148+
return api.tx.loans.addMarket(token, market);
149+
});
150150

151-
let addRewards = [
151+
const addRewards = [
152152
api.tx.utility.dispatchAs(
153153
{ system: { Signed: treasuryAccount } },
154154
api.tx.loans.addReward("100000000000000000000")
155155
)
156156
];
157-
let activateMarketWithRewards = underlyingTokens.map((token) => {
157+
158+
const activateMarketWithRewards = markets.map(([token, _]) => {
158159
return [
159160
api.tx.loans.activateMarket(token),
160161
api.tx.loans.updateMarketRewardSpeed(token, 10, 10),
161162
]
162-
}).reduce((x, y) => { return x.concat(y); });
163+
}).flat();
164+
165+
const addSupply = markets.map(([token, market]) => {
166+
return api.tx.utility.dispatchAs(
167+
{ system: { Signed: treasuryAccount } },
168+
api.tx.loans.mint(token, new BN(market.supplyCap).divn(10))
169+
)
170+
}).flat();
163171

164-
return addMarkets.concat(addRewards).concat(activateMarketWithRewards);
172+
return [addMarkets, addRewards, activateMarketWithRewards, addSupply].flat()
165173
}
166174

167175
function constructFundingSetup(api: ApiPromise) {
@@ -303,7 +311,7 @@ async function constructAmmSetup(api: ApiPromise) {
303311
),
304312
)
305313
];
306-
}).reduce((x, y) => { return x.concat(y); });
314+
}).flat();
307315

308316
// note: this is before the batch is executed
309317
const basePoolId = (await api.query.zenlinkStableAmm.nextPoolId() as any).toNumber();
@@ -510,7 +518,7 @@ async function setupParachain() {
510518
constructVaultRegistrySetup(paraApi),
511519
constructAnnuitySetup(paraApi),
512520
await constructAmmSetup(paraApi),
513-
].reduce((x, y) => { return x.concat(y); });
521+
].flat();
514522

515523
const batched = paraApi.tx.utility.batchAll(calls);
516524
const sudo = paraApi.tx.sudo.sudo(batched.method.toHex());

0 commit comments

Comments
 (0)