@reflectmoney/stable.ts 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,13 @@ export declare abstract class Stablecoin<T extends Controller> {
53
53
  * Initialize the stablecoin by deriving the controller key
54
54
  */
55
55
  initializeKeys(): Promise<void>;
56
+ /**
57
+ * Loads the mint supply and decimals from the blockchain.
58
+ * This should be called after stablecoinMint is set (typically in the load() method).
59
+ *
60
+ * @throws Error if stablecoinMint is not set
61
+ */
62
+ loadMintSupply(): Promise<void>;
56
63
  getController(): T;
57
64
  getStablecoinMint(): Address;
58
65
  getLookupTable(): Address;
@@ -22,6 +22,7 @@ const getProgramAddress_1 = require("../utils/getProgramAddress");
22
22
  const axios_1 = __importDefault(require("axios"));
23
23
  const sdk_1 = require("@drift-labs/sdk");
24
24
  const web3_js_1 = require("@solana/web3.js");
25
+ const token_1 = require("@solana-program/token");
25
26
  // System Program and Rent Sysvar addresses
26
27
  const SYSTEM_PROGRAM = (0, kit_1.address)("11111111111111111111111111111111");
27
28
  const SYSVAR_RENT = (0, kit_1.address)("SysvarRent111111111111111111111111111111111");
@@ -48,6 +49,22 @@ class Stablecoin {
48
49
  this.controllerKey = yield PdaClient_1.PdaClient.deriveController(this.index, this.devnet, this.mock);
49
50
  });
50
51
  }
52
+ /**
53
+ * Loads the mint supply and decimals from the blockchain.
54
+ * This should be called after stablecoinMint is set (typically in the load() method).
55
+ *
56
+ * @throws Error if stablecoinMint is not set
57
+ */
58
+ loadMintSupply() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ if (!this.stablecoinMint) {
61
+ throw new Error("Stablecoin mint not set. Call load() first to set the mint address.");
62
+ }
63
+ const mintAccount = yield (0, token_1.fetchMint)(this.rpc, this.stablecoinMint);
64
+ this.stablecoinMintSupply = mintAccount.data.supply;
65
+ this.stablecoinMintDecimals = mintAccount.data.decimals;
66
+ });
67
+ }
51
68
  getController() {
52
69
  return this.controller;
53
70
  }
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USDT_PLUS_LOOKUP_TABLE = exports.USDC_PLUS_LOOKUP_TABLE = void 0;
4
4
  const kit_1 = require("@solana/kit");
5
- exports.USDC_PLUS_LOOKUP_TABLE = (0, kit_1.address)("23FkJhYpNQwizoD7mFLxL9oTPqaqTitHESUPLLKC5uJc");
5
+ exports.USDC_PLUS_LOOKUP_TABLE = (0, kit_1.address)("D1Zj28AJLEmRGPhHrk5aaAzechEx7VRLfhmSHzwC61FZ");
6
6
  exports.USDT_PLUS_LOOKUP_TABLE = (0, kit_1.address)("23FkJhYpNQwizoD7mFLxL9oTPqaqTitHESUPLLKC5uJc" // TODO: Replace with actual USDT+ lookup table
7
7
  );
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MOCK_PROGRAM_ADDRESS = void 0;
4
4
  const kit_1 = require("@solana/kit");
5
- exports.MOCK_PROGRAM_ADDRESS = (0, kit_1.address)("mockPXu7Ur54ab1Q2eiYQ6jDijQsq6wvh965pt7ktf4");
5
+ exports.MOCK_PROGRAM_ADDRESS = (0, kit_1.address)("mockQT6RCB813G9asyPoKj8rF2rx7haay8GeKNz2xgn");
@@ -115,6 +115,8 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
115
115
  }
116
116
  this.autoCompound = autoCompound;
117
117
  this.stablecoinMint = this.controller.base.mint;
118
+ // Load mint supply and decimals
119
+ yield this.loadMintSupply();
118
120
  });
119
121
  }
120
122
  /**
@@ -146,6 +148,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
146
148
  yield this.initializeKeys();
147
149
  const main = yield classes_1.PdaClient.deriveMain(this.devnet, this.mock);
148
150
  const adminPermissions = yield classes_1.PdaClient.derivePermissions(admin.address, this.devnet, this.mock);
151
+ const usdcMint = this.devnet ? constants_1.USDC_MINT_DEVNET : constants_1.USDC_MINT;
149
152
  const ix = (0, reflect_main_1.getInitDriftControllerS1Instruction)({
150
153
  admin,
151
154
  adminPermissions,
@@ -156,7 +159,13 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
156
159
  recipientAddresses,
157
160
  recipientCuts,
158
161
  }, { programAddress: this.programAddress });
159
- return [ix];
162
+ // The program requires the USDC mint as remaining_accounts[0] to validate it matches USDC_MINT
163
+ const remainingAccounts = [
164
+ { address: usdcMint, role: 0 }, // mint_info (readonly)
165
+ ];
166
+ // Create instruction with remaining accounts
167
+ const ixWithRemainingAccounts = Object.assign(Object.assign({}, ix), { accounts: [...ix.accounts, ...remainingAccounts] });
168
+ return [ixWithRemainingAccounts];
160
169
  });
161
170
  }
162
171
  /**
@@ -77,6 +77,8 @@ class UsdcPlusStablecoinLegacy extends Stablecoin_1.Stablecoin {
77
77
  const controllerAccount = yield (0, accounts_1.fetchDriftUsdcController)(this.rpc, this.controllerKey);
78
78
  this.controller = controllerAccount.data;
79
79
  this.stablecoinMint = this.controller.baseStrategy.mint;
80
+ // Load mint supply and decimals
81
+ yield this.loadMintSupply();
80
82
  });
81
83
  }
82
84
  /**
@@ -115,6 +115,8 @@ class UsdtPlusStablecoin extends Stablecoin_1.Stablecoin {
115
115
  }
116
116
  this.autoCompound = autoCompound;
117
117
  this.stablecoinMint = this.controller.base.mint;
118
+ // Load mint supply and decimals
119
+ yield this.loadMintSupply();
118
120
  });
119
121
  }
120
122
  /**
@@ -156,7 +158,13 @@ class UsdtPlusStablecoin extends Stablecoin_1.Stablecoin {
156
158
  recipientAddresses,
157
159
  recipientCuts,
158
160
  }, { programAddress: this.programAddress });
159
- return [ix];
161
+ // The program requires the USDT mint as remaining_accounts[0] to validate it matches USDT_MINT
162
+ const remainingAccounts = [
163
+ { address: constants_1.USDT_MINT, role: 0 }, // mint_info (readonly)
164
+ ];
165
+ // Create instruction with remaining accounts
166
+ const ixWithRemainingAccounts = Object.assign(Object.assign({}, ix), { accounts: [...ix.accounts, ...remainingAccounts] });
167
+ return [ixWithRemainingAccounts];
160
168
  });
161
169
  }
162
170
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/stable.ts",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "type": "commonjs",
5
5
  "author": "stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {