Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script to register asset #724

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@
],
"testTimeout": 30000
}
}
}
133 changes: 133 additions & 0 deletions scripts/register-asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* eslint @typescript-eslint/no-var-requires: "off" */
import { createSubstrateAPI } from "../src/factory";
import { ApiPromise } from "@polkadot/api";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import { printDiscordProposal } from "./util";

main().catch((err) => {
console.log("Error thrown by script:");
console.log(err);
});

const NEW_ASSET = {
metadata: {
decimals: 6,
name: "USD Coin",
symbol: "USDC",
existentialDeposit: 0,
location: {
V3: {
parents: 1,
interior: {
X3: [
{
Parachain: 1000
},
{
PalletInstance: 50
},
{
GeneralIndex: 1337
}
]
}
}
},
additional: { feePerSecond: 11888560, coingeckoId: "usd-coin" }
},
pools: [
{
token1: { Token: "INTR" },
dexFees: 15,
},
],
market: {
collateralFactor: 630000,
liquidationThreshold: 670000,
reserveFactor: 200000,
closeFactor: 500000,
liquidateIncentive: "1100000000000000000",
liquidateIncentiveReservedFactor: 25000,
rateModel: {
Jump: {
baseRate: 0,
jumpRate: "50000000000000000",
fullRate: "500000000000000000",
jumpUtilization: 900000
}
},
state: "Pending",
supplyCap: "10000000000",
borrowCap: "10000000000",
lendTokenId: { LendToken: 5 }, // NOTE: make sure this is free
supplyIncentivesPerBlock: 0
},
vaultParams: {
wrappedCurrency: { Token: "IBTC" },
liquidationCollateral: "1450000000000000000",
premiumRedeem: "1650000000000000000",
secureCollateral: "1800000000000000000",
minimumCollateral: "20000000000000",
systemCollateralCeiling: "38000000000000000",
}
};

function vaultRegistryCalls(
api: ApiPromise,
collateralCurrency: { ForeignAsset: number },
) {
const {
wrappedCurrency,
liquidationCollateral,
premiumRedeem,
secureCollateral,
minimumCollateral,
systemCollateralCeiling
} = NEW_ASSET.vaultParams;
const currencyPair = {
collateral: collateralCurrency,
wrapped: wrappedCurrency,
};
return [
api.tx.vaultRegistry.setLiquidationCollateralThreshold(currencyPair, liquidationCollateral),
api.tx.vaultRegistry.setPremiumRedeemThreshold(currencyPair, premiumRedeem),
api.tx.vaultRegistry.setSecureCollateralThreshold(currencyPair, secureCollateral),
api.tx.vaultRegistry.setMinimumCollateral(currencyPair.collateral, minimumCollateral),
api.tx.vaultRegistry.setSystemCollateralCeiling(currencyPair, systemCollateralCeiling),
];
}

async function main(): Promise<void> {
await cryptoWaitReady();

const parachainEndpoint = "wss://api.interlay.io/parachain";
const paraApi = await createSubstrateAPI(parachainEndpoint);

const lastAssetId = await paraApi.query.assetRegistry.lastAssetId();
const nextAssetId = lastAssetId.toNumber() + 1;
const currencyId = { ForeignAsset: nextAssetId };

const allCalls = [
paraApi.tx.assetRegistry.registerAsset(NEW_ASSET.metadata, nextAssetId)
];

allCalls.push(...NEW_ASSET.pools.map(pool =>
paraApi.tx.dexGeneral.createPair(currencyId, pool.token1, pool.dexFees)
))

allCalls.push(
...[
paraApi.tx.loans.addMarket(currencyId, NEW_ASSET.market),
paraApi.tx.loans.activateMarket(currencyId)
]
);

allCalls.push(...vaultRegistryCalls(paraApi, currencyId));

const batched = paraApi.tx.utility.batchAll(allCalls);

const title = `Register ${NEW_ASSET.metadata.symbol}`;
printDiscordProposal(title, batched, parachainEndpoint, paraApi);

await paraApi.disconnect();
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig-base.json",
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"outDir": "build/esm",
"module": "CommonJS",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not cause issues for the ui? Fwiw I had this

--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,8 +1,15 @@
 {
     "extends": "./tsconfig-base.json",
+    "ts-node": {
+        // these options are overrides used only by ts-node
+        // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable
+        "compilerOptions": {
+          "module": "commonjs"
+        }
+      },

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See pr description

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my version is mergable but yea I guess we don't want the register-asset script

}
}
}
Loading