@ripe-finance/sdk 1.7.1 → 1.8.2

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.
package/dist/index.js CHANGED
@@ -1,56 +1,20 @@
1
1
  import { iteratorQuery, query } from '@dappql/async';
2
2
  import { createPublicClient, http, zeroAddress } from 'viem';
3
- import { base, baseSepolia } from 'viem/chains';
3
+ import { base } from 'viem/chains';
4
4
  import * as CONTRACTS from './contracts/index.js';
5
5
  import createSdk from './contracts/sdk.js';
6
6
  export * from './contracts/index.js';
7
- const TESTNET_ADDRESSES = {
8
- GreenToken: '0xA986af04241b93131236AA5d7779DD348842F26A',
9
- RipeToken: '0x83E5b66864Ce2eecbd5BA9C0481214A559B5e84c',
10
- SavingsGreen: '0x5D94b2d65623Ce3C3E7668604CE34F8091307Bd1',
11
- RipeHq: '0x1Ea91ACf2FC876954A487Be300C703647d575C7E',
12
- Contributor: '0x3644727ef554127Cc1D17c7316c0EDce86B78065',
13
- TrainingWheels: '0xd1DCaD1D41F055c34155d3F9AfC07AC558E173B5',
14
- DefaultsBase: '0xd70e8CC0d18C629b8E7150Fe5DFAe1bCc9697743',
15
- Ledger: '0x126cE0208e82044D01695c1cebfE076B6F4BD394',
16
- MissionControl: '0x09c6Ee6d9c24eE24E7Da9d8610B93d0DAb11ba8B',
17
- Switchboard: '0xAa8e3B4318Db158467f5FA254627632c3E0Adb8f',
18
- SwitchboardAlpha: '0xAA0276945D94D3c742DdCcA92EfB0588CC17b3f6',
19
- SwitchboardBravo: '0xb4098645bD804bfce0A0cf57A3ACCC45eF59245f',
20
- SwitchboardCharlie: '0x5012f3509bf097fEAa30B462E000E3A9cc9dEb08',
21
- SwitchboardDelta: '0xC5ed897bE4Ab6b30B6e252249BaE2a4B86A08eDA',
22
- PriceDesk: '0x45c47b4fbD59b34e53996C782faa1aCc5E128872',
23
- ChainlinkPrices: '0xF59966c32A189110c0f1FA296Fd0Bb6D848824Ff',
24
- CurvePrices: '0xcc643965E8C8C88B9Ae764E75a0C836EcC8689e8',
25
- VaultBook: '0x835709c9Bb390503b863b2F36c16eF9ca5f958Ec',
26
- StabilityPool: '0xb7DE6844e97490DE6d7d98A9BE94Ca4809724b01',
27
- RipeGov: '0x9b2e0636125cDBdC473bC75DFd502b1642B68ab1',
28
- SimpleErc20: '0xfC743b1D29Bcd3861741474710eB2BB7CFfF1fd7',
29
- RebaseErc20: '0x7429B315c1d8Ac129a1266D9FA4Df23F4CcF5052',
30
- AuctionHouse: '0x8a639da50Bd5F7331acf35c63E04cCb093F7d6D1',
31
- AuctionHouseNFT: '0x6013566681612364f8d1250934E1a3a84e955EE2',
32
- Boardroom: '0xaB51f948c6B7676ADa865AB300B46Da4DF098c95',
33
- BondRoom: '0xA4113EA97c6a54F7D8A4B5534f648cAaBc733666',
34
- CreditEngine: '0x456B8581Aeb9F058e51B7AB404b7BCEaa91f2C26',
35
- Endaoment: '0x8A3C76767AdC47B06d94C86b807946c0558B441d',
36
- HumanResources: '0x0794699118ab39c823544c433aefa2151dBF190c',
37
- Lootbox: '0xeD34B590BA499a773b25DDA22e79FFeEB15bdFF4',
38
- Teller: '0x8Fb1C942aD0a69dBA2F172E9adaB605e652EC9D9',
39
- GreenPool: '0x3f6ACfa20824D71AA4aFd2e0fEd22ffBc456B0bA',
40
- RipePool: '0x0000000000000000000000000000000000000000',
41
- BondBooster: '0x0000000000000000000000000000000000000000',
42
- };
7
+ const WETH = '0x4200000000000000000000000000000000000006';
43
8
  class Ripe {
44
9
  constructor(config) {
45
10
  this.publicClient =
46
11
  config?.publicClient ||
47
12
  createPublicClient({
48
- chain: config?.isTestnet ? baseSepolia : base,
13
+ chain: base,
49
14
  transport: http(config?.rpcUrl),
50
15
  });
51
16
  this.walletClient = config?.walletClient;
52
17
  this.contracts = createSdk(this.publicClient, this.walletClient);
53
- this.isTestnet = config?.isTestnet ?? false;
54
18
  }
55
19
  setWalletClient(walletClient) {
56
20
  this.walletClient = walletClient;
@@ -61,248 +25,247 @@ class Ripe {
61
25
  this.contracts = createSdk(this.publicClient, this.walletClient);
62
26
  }
63
27
  get GreenToken() {
64
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.GreenToken : CONTRACTS.GreenToken.deployAddress;
28
+ const deployAddress = CONTRACTS.GreenToken.deployAddress;
65
29
  return {
66
30
  ...this.contracts.GreenToken,
67
31
  deployAddress,
68
32
  };
69
33
  }
70
34
  get RipeToken() {
71
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.RipeToken : CONTRACTS.RipeToken.deployAddress;
35
+ const deployAddress = CONTRACTS.RipeToken.deployAddress;
72
36
  return {
73
37
  ...this.contracts.RipeToken,
74
38
  deployAddress,
75
39
  };
76
40
  }
77
41
  get SavingsGreen() {
78
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.SavingsGreen : CONTRACTS.SavingsGreen.deployAddress;
42
+ const deployAddress = CONTRACTS.SavingsGreen.deployAddress;
79
43
  return {
80
44
  ...this.contracts.SavingsGreen,
81
45
  deployAddress,
82
46
  };
83
47
  }
84
48
  get RipeHq() {
85
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.RipeHq : CONTRACTS.RipeHq.deployAddress;
49
+ const deployAddress = CONTRACTS.RipeHq.deployAddress;
86
50
  return {
87
51
  ...this.contracts.RipeHq,
88
52
  deployAddress,
89
53
  };
90
54
  }
91
55
  get Contributor() {
92
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Contributor : CONTRACTS.Contributor.deployAddress;
56
+ const deployAddress = CONTRACTS.Contributor.deployAddress;
93
57
  return {
94
58
  ...this.contracts.Contributor,
95
59
  deployAddress,
96
60
  };
97
61
  }
98
62
  get TrainingWheels() {
99
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.TrainingWheels : CONTRACTS.TrainingWheels.deployAddress;
63
+ const deployAddress = CONTRACTS.TrainingWheels.deployAddress;
100
64
  return {
101
65
  ...this.contracts.TrainingWheels,
102
66
  deployAddress,
103
67
  };
104
68
  }
105
69
  get DefaultsBase() {
106
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.DefaultsBase : CONTRACTS.DefaultsBase.deployAddress;
70
+ const deployAddress = CONTRACTS.DefaultsBase.deployAddress;
107
71
  return {
108
72
  ...this.contracts.DefaultsBase,
109
73
  deployAddress,
110
74
  };
111
75
  }
112
76
  get Ledger() {
113
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Ledger : CONTRACTS.Ledger.deployAddress;
77
+ const deployAddress = CONTRACTS.Ledger.deployAddress;
114
78
  return {
115
79
  ...this.contracts.Ledger,
116
80
  deployAddress,
117
81
  };
118
82
  }
119
83
  get MissionControl() {
120
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.MissionControl : CONTRACTS.MissionControl.deployAddress;
84
+ const deployAddress = CONTRACTS.MissionControl.deployAddress;
121
85
  return {
122
86
  ...this.contracts.MissionControl,
123
87
  deployAddress,
124
88
  };
125
89
  }
126
90
  get Switchboard() {
127
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Switchboard : CONTRACTS.Switchboard.deployAddress;
91
+ const deployAddress = CONTRACTS.Switchboard.deployAddress;
128
92
  return {
129
93
  ...this.contracts.Switchboard,
130
94
  deployAddress,
131
95
  };
132
96
  }
133
97
  get SwitchboardAlpha() {
134
- const deployAddress = this.isTestnet
135
- ? TESTNET_ADDRESSES.SwitchboardAlpha
136
- : CONTRACTS.SwitchboardAlpha.deployAddress;
98
+ const deployAddress = CONTRACTS.SwitchboardAlpha.deployAddress;
137
99
  return {
138
100
  ...this.contracts.SwitchboardAlpha,
139
101
  deployAddress,
140
102
  };
141
103
  }
142
104
  get SwitchboardBravo() {
143
- const deployAddress = this.isTestnet
144
- ? TESTNET_ADDRESSES.SwitchboardBravo
145
- : CONTRACTS.SwitchboardBravo.deployAddress;
105
+ const deployAddress = CONTRACTS.SwitchboardBravo.deployAddress;
146
106
  return {
147
107
  ...this.contracts.SwitchboardBravo,
148
108
  deployAddress,
149
109
  };
150
110
  }
151
111
  get SwitchboardCharlie() {
152
- const deployAddress = this.isTestnet
153
- ? TESTNET_ADDRESSES.SwitchboardCharlie
154
- : CONTRACTS.SwitchboardCharlie.deployAddress;
112
+ const deployAddress = CONTRACTS.SwitchboardCharlie.deployAddress;
155
113
  return {
156
114
  ...this.contracts.SwitchboardCharlie,
157
115
  deployAddress,
158
116
  };
159
117
  }
160
118
  get SwitchboardDelta() {
161
- const deployAddress = this.isTestnet
162
- ? TESTNET_ADDRESSES.SwitchboardDelta
163
- : CONTRACTS.SwitchboardDelta.deployAddress;
119
+ const deployAddress = CONTRACTS.SwitchboardDelta.deployAddress;
164
120
  return {
165
121
  ...this.contracts.SwitchboardDelta,
166
122
  deployAddress,
167
123
  };
168
124
  }
169
125
  get PriceDesk() {
170
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.PriceDesk : CONTRACTS.PriceDesk.deployAddress;
126
+ const deployAddress = CONTRACTS.PriceDesk.deployAddress;
171
127
  return {
172
128
  ...this.contracts.PriceDesk,
173
129
  deployAddress,
174
130
  };
175
131
  }
176
132
  get ChainlinkPrices() {
177
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.ChainlinkPrices : CONTRACTS.ChainlinkPrices.deployAddress;
133
+ const deployAddress = CONTRACTS.ChainlinkPrices.deployAddress;
178
134
  return {
179
135
  ...this.contracts.ChainlinkPrices,
180
136
  deployAddress,
181
137
  };
182
138
  }
183
139
  get CurvePrices() {
184
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.CurvePrices : CONTRACTS.CurvePrices.deployAddress;
140
+ const deployAddress = CONTRACTS.CurvePrices.deployAddress;
185
141
  return {
186
142
  ...this.contracts.CurvePrices,
187
143
  deployAddress,
188
144
  };
189
145
  }
190
146
  get VaultBook() {
191
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.VaultBook : CONTRACTS.VaultBook.deployAddress;
147
+ const deployAddress = CONTRACTS.VaultBook.deployAddress;
192
148
  return {
193
149
  ...this.contracts.VaultBook,
194
150
  deployAddress,
195
151
  };
196
152
  }
197
153
  get StabilityPool() {
198
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.StabilityPool : CONTRACTS.StabilityPool.deployAddress;
154
+ const deployAddress = CONTRACTS.StabilityPool.deployAddress;
199
155
  return {
200
156
  ...this.contracts.StabilityPool,
201
157
  deployAddress,
202
158
  };
203
159
  }
204
160
  get RipeGov() {
205
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.RipeGov : CONTRACTS.RipeGov.deployAddress;
161
+ const deployAddress = CONTRACTS.RipeGov.deployAddress;
206
162
  return {
207
163
  ...this.contracts.RipeGov,
208
164
  deployAddress,
209
165
  };
210
166
  }
211
167
  get SimpleErc20() {
212
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.SimpleErc20 : CONTRACTS.SimpleErc20.deployAddress;
168
+ const deployAddress = CONTRACTS.SimpleErc20.deployAddress;
213
169
  return {
214
170
  ...this.contracts.SimpleErc20,
215
171
  deployAddress,
216
172
  };
217
173
  }
218
174
  get RebaseErc20() {
219
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.RebaseErc20 : CONTRACTS.RebaseErc20.deployAddress;
175
+ const deployAddress = CONTRACTS.RebaseErc20.deployAddress;
220
176
  return {
221
177
  ...this.contracts.RebaseErc20,
222
178
  deployAddress,
223
179
  };
224
180
  }
225
181
  get AuctionHouse() {
226
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.AuctionHouse : CONTRACTS.AuctionHouse.deployAddress;
182
+ const deployAddress = CONTRACTS.AuctionHouse.deployAddress;
227
183
  return {
228
184
  ...this.contracts.AuctionHouse,
229
185
  deployAddress,
230
186
  };
231
187
  }
232
188
  get AuctionHouseNFT() {
233
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.AuctionHouseNFT : CONTRACTS.AuctionHouseNFT.deployAddress;
189
+ const deployAddress = CONTRACTS.AuctionHouseNFT.deployAddress;
234
190
  return {
235
191
  ...this.contracts.AuctionHouseNFT,
236
192
  deployAddress,
237
193
  };
238
194
  }
239
195
  get Boardroom() {
240
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Boardroom : CONTRACTS.Boardroom.deployAddress;
196
+ const deployAddress = CONTRACTS.Boardroom.deployAddress;
241
197
  return {
242
198
  ...this.contracts.Boardroom,
243
199
  deployAddress,
244
200
  };
245
201
  }
246
202
  get BondRoom() {
247
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.BondRoom : CONTRACTS.BondRoom.deployAddress;
203
+ const deployAddress = CONTRACTS.BondRoom.deployAddress;
248
204
  return {
249
205
  ...this.contracts.BondRoom,
250
206
  deployAddress,
251
207
  };
252
208
  }
253
209
  get BondBooster() {
254
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.BondBooster : CONTRACTS.BondBooster.deployAddress;
210
+ const deployAddress = CONTRACTS.BondBooster.deployAddress;
255
211
  return {
256
212
  ...this.contracts.BondBooster,
257
213
  deployAddress,
258
214
  };
259
215
  }
260
216
  get CreditEngine() {
261
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.CreditEngine : CONTRACTS.CreditEngine.deployAddress;
217
+ const deployAddress = CONTRACTS.CreditEngine.deployAddress;
262
218
  return {
263
219
  ...this.contracts.CreditEngine,
264
220
  deployAddress,
265
221
  };
266
222
  }
267
223
  get Endaoment() {
268
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Endaoment : CONTRACTS.Endaoment.deployAddress;
224
+ const deployAddress = CONTRACTS.Endaoment.deployAddress;
269
225
  return {
270
226
  ...this.contracts.Endaoment,
271
227
  deployAddress,
272
228
  };
273
229
  }
274
230
  get HumanResources() {
275
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.HumanResources : CONTRACTS.HumanResources.deployAddress;
231
+ const deployAddress = CONTRACTS.HumanResources.deployAddress;
276
232
  return {
277
233
  ...this.contracts.HumanResources,
278
234
  deployAddress,
279
235
  };
280
236
  }
281
237
  get Lootbox() {
282
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Lootbox : CONTRACTS.Lootbox.deployAddress;
238
+ const deployAddress = CONTRACTS.Lootbox.deployAddress;
283
239
  return {
284
240
  ...this.contracts.Lootbox,
285
241
  deployAddress,
286
242
  };
287
243
  }
288
244
  get Teller() {
289
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.Teller : CONTRACTS.Teller.deployAddress;
245
+ const deployAddress = CONTRACTS.Teller.deployAddress;
290
246
  return {
291
247
  ...this.contracts.Teller,
292
248
  deployAddress,
293
249
  };
294
250
  }
295
251
  get GreenPool() {
296
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.GreenPool : CONTRACTS.GreenPool.deployAddress;
252
+ const deployAddress = CONTRACTS.GreenPool.deployAddress;
297
253
  return {
298
254
  ...this.contracts.GreenPool,
299
255
  deployAddress,
300
256
  };
301
257
  }
302
- get RipePool() {
303
- const deployAddress = this.isTestnet ? TESTNET_ADDRESSES.RipePool : CONTRACTS.RipePool.deployAddress;
258
+ get RipePoolCurve() {
259
+ const deployAddress = CONTRACTS.RipePoolCurve.deployAddress;
304
260
  return {
305
- ...this.contracts.RipePool,
261
+ ...this.contracts.RipePoolCurve,
262
+ deployAddress,
263
+ };
264
+ }
265
+ get RipePoolAero() {
266
+ const deployAddress = CONTRACTS.RipePoolAero.deployAddress;
267
+ return {
268
+ ...this.contracts.RipePoolAero,
306
269
  deployAddress,
307
270
  };
308
271
  }
@@ -311,13 +274,6 @@ class Ripe {
311
274
  }
312
275
  get addressResolver() {
313
276
  return (contractName) => {
314
- if (this.isTestnet) {
315
- const address = TESTNET_ADDRESSES[contractName];
316
- if (!address) {
317
- throw new Error(`Address for ${contractName} not found`);
318
- }
319
- return address;
320
- }
321
277
  return CONTRACTS[contractName].deployAddress;
322
278
  };
323
279
  }
@@ -330,8 +286,19 @@ class Ripe {
330
286
  return iteratorQuery(this.publicClient, total, getItem, options, this.addressResolver);
331
287
  }
332
288
  async getSupporttedTokens(options = {}) {
289
+ const ripeTokenAddress = this.addressResolver('RipeToken');
290
+ const ripePoolAeroAddress = this.addressResolver('RipePoolAero');
333
291
  const { walletAddress = zeroAddress, forceGreenPeg = false } = options;
334
- const { totalTokens } = await query(this.publicClient, { totalTokens: CONTRACTS.MissionControl.call.getNumAssets() }, options, this.addressResolver);
292
+ const { totalTokens, ripePoolReserves, ripePoolSupply, ripeTokenPrice, wethPrice } = await query(this.publicClient, {
293
+ totalTokens: CONTRACTS.MissionControl.call.getNumAssets(),
294
+ ripeTokenPrice: CONTRACTS.AeroClassicLego.call.getPriceUnsafe(ripePoolAeroAddress, ripeTokenAddress),
295
+ ripePoolReserves: CONTRACTS.RipePoolAero.call.getReserves(),
296
+ ripePoolSupply: CONTRACTS.RipePoolAero.call.totalSupply(),
297
+ wethPrice: CONTRACTS.PriceDesk.call.getPrice(WETH, false),
298
+ }, options, this.addressResolver);
299
+ const ripeLpPrice = ripePoolSupply === 0n
300
+ ? 0n
301
+ : (ripePoolReserves[0] * ripeTokenPrice + ripePoolReserves[1] * wethPrice) / ripePoolSupply;
335
302
  const supportedTokens = await iteratorQuery(this.publicClient, totalTokens, (index) => CONTRACTS.MissionControl.call.assets(index), {
336
303
  firstIndex: 1n,
337
304
  }, this.addressResolver);
@@ -342,6 +309,15 @@ class Ripe {
342
309
  allTokens.add(this.addressResolver('GreenPool'));
343
310
  const allTokensArray = Array.from(allTokens);
344
311
  const tokensQuery = allTokensArray.reduce((acc, token) => {
312
+ if ([ripeTokenAddress, ripePoolAeroAddress].includes(token)) {
313
+ return {
314
+ ...acc,
315
+ [`${token}-name`]: CONTRACTS.ERC20.call.name().at(token).defaultTo(''),
316
+ [`${token}-symbol`]: CONTRACTS.ERC20.call.symbol().at(token).defaultTo(''),
317
+ [`${token}-decimals`]: CONTRACTS.ERC20.call.decimals().at(token).defaultTo(18),
318
+ [`${token}-balance`]: CONTRACTS.ERC20.call.balanceOf(walletAddress).at(token).defaultTo(0n),
319
+ };
320
+ }
345
321
  return {
346
322
  ...acc,
347
323
  [`${token}-name`]: CONTRACTS.ERC20.call.name().at(token).defaultTo(''),
@@ -391,6 +367,12 @@ class Ripe {
391
367
  : supportedTokenInfo[`${this.addressResolver('GreenToken')}-price`];
392
368
  price = greenPrice;
393
369
  }
370
+ if (token === this.addressResolver('RipeToken')) {
371
+ price = ripeTokenPrice;
372
+ }
373
+ if (token === this.addressResolver('RipePoolAero')) {
374
+ price = ripeLpPrice;
375
+ }
394
376
  const config = assetConfig[token];
395
377
  return {
396
378
  address: token,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ripe-finance/sdk",
3
- "version": "1.7.1",
3
+ "version": "1.8.2",
4
4
  "description": "SDK for interacting with Ripe Finance Smart Contracts with TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@dappql/async": "^1.0.3",
33
- "dappql": "^2.0.29",
33
+ "dappql": "^2.0.30",
34
34
  "viem": "^2.23.7"
35
35
  }
36
36
  }