@mento-protocol/mento-sdk 0.1.3 → 0.1.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.
- package/dist/cjs/mento.d.ts +6 -6
- package/dist/cjs/mento.js +21 -15
- package/dist/cjs/utils.d.ts +3 -3
- package/dist/cjs/utils.js +5 -3
- package/dist/esm/mento.d.ts +6 -6
- package/dist/esm/mento.js +21 -15
- package/dist/esm/utils.d.ts +3 -3
- package/dist/esm/utils.js +5 -3
- package/package.json +2 -2
package/dist/cjs/mento.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBroker } from '@mento-protocol/mento-core-ts';
|
|
2
|
-
import { BigNumber, providers, Signer } from 'ethers';
|
|
2
|
+
import { BigNumber, BigNumberish, providers, Signer } from 'ethers';
|
|
3
3
|
import { Address } from './types';
|
|
4
4
|
export interface Exchange {
|
|
5
5
|
providerAddr: Address;
|
|
@@ -56,7 +56,7 @@ export declare class Mento {
|
|
|
56
56
|
* @param amountOut the amount of tokenOut to be bought
|
|
57
57
|
* @returns the amount of tokenIn to be sold
|
|
58
58
|
*/
|
|
59
|
-
getAmountIn(tokenIn: Address, tokenOut: Address, amountOut:
|
|
59
|
+
getAmountIn(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish): Promise<BigNumber>;
|
|
60
60
|
/**
|
|
61
61
|
* Returns the amount of tokenOut to be bought by selling amountIn of tokenIn
|
|
62
62
|
* @param tokenIn the token to be sold
|
|
@@ -64,14 +64,14 @@ export declare class Mento {
|
|
|
64
64
|
* @param amountIn the amount of tokenIn to be sold
|
|
65
65
|
* @returns the amount of tokenOut to be bought
|
|
66
66
|
*/
|
|
67
|
-
getAmountOut(tokenIn: Address, tokenOut: Address, amountIn:
|
|
67
|
+
getAmountOut(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish): Promise<BigNumber>;
|
|
68
68
|
/**
|
|
69
69
|
* Increases the broker's trading allowance for the given token
|
|
70
70
|
* @param token the token to increase the allowance for
|
|
71
71
|
* @param amount the amount to increase the allowance by
|
|
72
72
|
* @returns the populated TransactionRequest object
|
|
73
73
|
*/
|
|
74
|
-
increaseTradingAllowance(token: Address, amount:
|
|
74
|
+
increaseTradingAllowance(token: Address, amount: BigNumberish): Promise<providers.TransactionRequest>;
|
|
75
75
|
/**
|
|
76
76
|
* Returns a token swap populated tx object with a fixed amount of tokenIn and a minimum amount of tokenOut
|
|
77
77
|
* Submitting the transaction to execute the swap is left to the consumer
|
|
@@ -81,7 +81,7 @@ export declare class Mento {
|
|
|
81
81
|
* @param amountOutMin the minimum amount of tokenOut to be bought
|
|
82
82
|
* @returns the populated TransactionRequest object
|
|
83
83
|
*/
|
|
84
|
-
swapIn(tokenIn: Address, tokenOut: Address, amountIn:
|
|
84
|
+
swapIn(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish, amountOutMin: BigNumberish): Promise<providers.TransactionRequest>;
|
|
85
85
|
/**
|
|
86
86
|
* Returns a token swap populated tx object with a maximum amount of tokenIn and a fixed amount of tokenOut
|
|
87
87
|
* Submitting the transaction to execute the swap is left to the consumer
|
|
@@ -91,7 +91,7 @@ export declare class Mento {
|
|
|
91
91
|
* @param amountInMax the maximum amount of tokenIn to be sold
|
|
92
92
|
* @returns the populated TransactionRequest object
|
|
93
93
|
*/
|
|
94
|
-
swapOut(tokenIn: Address, tokenOut: Address, amountOut:
|
|
94
|
+
swapOut(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish, amountInMax: BigNumberish): Promise<providers.TransactionRequest>;
|
|
95
95
|
/**
|
|
96
96
|
* Returns the mento instance's broker contract
|
|
97
97
|
* @returns broker contract
|
package/dist/cjs/mento.js
CHANGED
|
@@ -117,13 +117,15 @@ class Mento {
|
|
|
117
117
|
*/
|
|
118
118
|
increaseTradingAllowance(token, amount) {
|
|
119
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
121
|
-
throw new Error('A signer is required to populate the increaseAllowance tx object');
|
|
122
|
-
}
|
|
123
120
|
const spender = this.broker.address;
|
|
124
121
|
const tx = yield (0, utils_1.increaseAllowance)(token, spender, amount, this.signerOrProvider);
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
123
|
+
// The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
|
|
124
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return tx;
|
|
128
|
+
}
|
|
127
129
|
});
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
@@ -137,13 +139,15 @@ class Mento {
|
|
|
137
139
|
*/
|
|
138
140
|
swapIn(tokenIn, tokenOut, amountIn, amountOutMin) {
|
|
139
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
141
|
-
throw new Error('A signer is required to populate the swapIn tx object');
|
|
142
|
-
}
|
|
143
142
|
const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
|
|
144
143
|
const tx = yield this.broker.populateTransaction.swapIn(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountIn, amountOutMin);
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
145
|
+
// The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
|
|
146
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return tx;
|
|
150
|
+
}
|
|
147
151
|
});
|
|
148
152
|
}
|
|
149
153
|
/**
|
|
@@ -157,13 +161,15 @@ class Mento {
|
|
|
157
161
|
*/
|
|
158
162
|
swapOut(tokenIn, tokenOut, amountOut, amountInMax) {
|
|
159
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
161
|
-
throw new Error('A signer is required to populate the swapOut tx object');
|
|
162
|
-
}
|
|
163
164
|
const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
|
|
164
165
|
const tx = yield this.broker.populateTransaction.swapOut(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountOut, amountInMax);
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
if (ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
167
|
+
// The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
|
|
168
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
return tx;
|
|
172
|
+
}
|
|
167
173
|
});
|
|
168
174
|
}
|
|
169
175
|
/**
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumberish, providers, Signer } from 'ethers';
|
|
2
2
|
import { Address } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Ensures that given signer is truly a a connected signer
|
|
@@ -30,7 +30,7 @@ export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrPr
|
|
|
30
30
|
* @param tokenAddr the address of the erc20 token
|
|
31
31
|
* @param spender the address of the spender
|
|
32
32
|
* @param amount the amount to increase the allowance by
|
|
33
|
-
* @param
|
|
33
|
+
* @param signerOrProvider an ethers signer or provider
|
|
34
34
|
* @returns the populated TransactionRequest object
|
|
35
35
|
*/
|
|
36
|
-
export declare function increaseAllowance(tokenAddr: string, spender: string, amount:
|
|
36
|
+
export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -81,15 +81,17 @@ exports.getSymbolFromTokenAddress = getSymbolFromTokenAddress;
|
|
|
81
81
|
* @param tokenAddr the address of the erc20 token
|
|
82
82
|
* @param spender the address of the spender
|
|
83
83
|
* @param amount the amount to increase the allowance by
|
|
84
|
-
* @param
|
|
84
|
+
* @param signerOrProvider an ethers signer or provider
|
|
85
85
|
* @returns the populated TransactionRequest object
|
|
86
86
|
*/
|
|
87
|
-
function increaseAllowance(tokenAddr, spender, amount,
|
|
87
|
+
function increaseAllowance(tokenAddr, spender, amount, signerOrProvider) {
|
|
88
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
89
|
const abi = [
|
|
90
90
|
'function increaseAllowance(address spender, uint256 value) external returns (bool)',
|
|
91
91
|
];
|
|
92
|
-
|
|
92
|
+
// TODO, not all ERC-20 contracts support increaseAllowance
|
|
93
|
+
// Add a check for that here
|
|
94
|
+
const contract = new ethers_1.Contract(tokenAddr, abi, signerOrProvider);
|
|
93
95
|
return yield contract.populateTransaction.increaseAllowance(spender, amount);
|
|
94
96
|
});
|
|
95
97
|
}
|
package/dist/esm/mento.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBroker } from '@mento-protocol/mento-core-ts';
|
|
2
|
-
import { BigNumber, providers, Signer } from 'ethers';
|
|
2
|
+
import { BigNumber, BigNumberish, providers, Signer } from 'ethers';
|
|
3
3
|
import { Address } from './types';
|
|
4
4
|
export interface Exchange {
|
|
5
5
|
providerAddr: Address;
|
|
@@ -56,7 +56,7 @@ export declare class Mento {
|
|
|
56
56
|
* @param amountOut the amount of tokenOut to be bought
|
|
57
57
|
* @returns the amount of tokenIn to be sold
|
|
58
58
|
*/
|
|
59
|
-
getAmountIn(tokenIn: Address, tokenOut: Address, amountOut:
|
|
59
|
+
getAmountIn(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish): Promise<BigNumber>;
|
|
60
60
|
/**
|
|
61
61
|
* Returns the amount of tokenOut to be bought by selling amountIn of tokenIn
|
|
62
62
|
* @param tokenIn the token to be sold
|
|
@@ -64,14 +64,14 @@ export declare class Mento {
|
|
|
64
64
|
* @param amountIn the amount of tokenIn to be sold
|
|
65
65
|
* @returns the amount of tokenOut to be bought
|
|
66
66
|
*/
|
|
67
|
-
getAmountOut(tokenIn: Address, tokenOut: Address, amountIn:
|
|
67
|
+
getAmountOut(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish): Promise<BigNumber>;
|
|
68
68
|
/**
|
|
69
69
|
* Increases the broker's trading allowance for the given token
|
|
70
70
|
* @param token the token to increase the allowance for
|
|
71
71
|
* @param amount the amount to increase the allowance by
|
|
72
72
|
* @returns the populated TransactionRequest object
|
|
73
73
|
*/
|
|
74
|
-
increaseTradingAllowance(token: Address, amount:
|
|
74
|
+
increaseTradingAllowance(token: Address, amount: BigNumberish): Promise<providers.TransactionRequest>;
|
|
75
75
|
/**
|
|
76
76
|
* Returns a token swap populated tx object with a fixed amount of tokenIn and a minimum amount of tokenOut
|
|
77
77
|
* Submitting the transaction to execute the swap is left to the consumer
|
|
@@ -81,7 +81,7 @@ export declare class Mento {
|
|
|
81
81
|
* @param amountOutMin the minimum amount of tokenOut to be bought
|
|
82
82
|
* @returns the populated TransactionRequest object
|
|
83
83
|
*/
|
|
84
|
-
swapIn(tokenIn: Address, tokenOut: Address, amountIn:
|
|
84
|
+
swapIn(tokenIn: Address, tokenOut: Address, amountIn: BigNumberish, amountOutMin: BigNumberish): Promise<providers.TransactionRequest>;
|
|
85
85
|
/**
|
|
86
86
|
* Returns a token swap populated tx object with a maximum amount of tokenIn and a fixed amount of tokenOut
|
|
87
87
|
* Submitting the transaction to execute the swap is left to the consumer
|
|
@@ -91,7 +91,7 @@ export declare class Mento {
|
|
|
91
91
|
* @param amountInMax the maximum amount of tokenIn to be sold
|
|
92
92
|
* @returns the populated TransactionRequest object
|
|
93
93
|
*/
|
|
94
|
-
swapOut(tokenIn: Address, tokenOut: Address, amountOut:
|
|
94
|
+
swapOut(tokenIn: Address, tokenOut: Address, amountOut: BigNumberish, amountInMax: BigNumberish): Promise<providers.TransactionRequest>;
|
|
95
95
|
/**
|
|
96
96
|
* Returns the mento instance's broker contract
|
|
97
97
|
* @returns broker contract
|
package/dist/esm/mento.js
CHANGED
|
@@ -114,13 +114,15 @@ export class Mento {
|
|
|
114
114
|
*/
|
|
115
115
|
increaseTradingAllowance(token, amount) {
|
|
116
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
if (!Signer.isSigner(this.signerOrProvider)) {
|
|
118
|
-
throw new Error('A signer is required to populate the increaseAllowance tx object');
|
|
119
|
-
}
|
|
120
117
|
const spender = this.broker.address;
|
|
121
118
|
const tx = yield increaseAllowance(token, spender, amount, this.signerOrProvider);
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
if (Signer.isSigner(this.signerOrProvider)) {
|
|
120
|
+
// The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
|
|
121
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return tx;
|
|
125
|
+
}
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
128
|
/**
|
|
@@ -134,13 +136,15 @@ export class Mento {
|
|
|
134
136
|
*/
|
|
135
137
|
swapIn(tokenIn, tokenOut, amountIn, amountOutMin) {
|
|
136
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
if (!Signer.isSigner(this.signerOrProvider)) {
|
|
138
|
-
throw new Error('A signer is required to populate the swapIn tx object');
|
|
139
|
-
}
|
|
140
139
|
const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
|
|
141
140
|
const tx = yield this.broker.populateTransaction.swapIn(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountIn, amountOutMin);
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
if (Signer.isSigner(this.signerOrProvider)) {
|
|
142
|
+
// The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
|
|
143
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return tx;
|
|
147
|
+
}
|
|
144
148
|
});
|
|
145
149
|
}
|
|
146
150
|
/**
|
|
@@ -154,13 +158,15 @@ export class Mento {
|
|
|
154
158
|
*/
|
|
155
159
|
swapOut(tokenIn, tokenOut, amountOut, amountInMax) {
|
|
156
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
if (!Signer.isSigner(this.signerOrProvider)) {
|
|
158
|
-
throw new Error('A signer is required to populate the swapOut tx object');
|
|
159
|
-
}
|
|
160
161
|
const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
|
|
161
162
|
const tx = yield this.broker.populateTransaction.swapOut(exchange.providerAddr, exchange.id, tokenIn, tokenOut, amountOut, amountInMax);
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
if (Signer.isSigner(this.signerOrProvider)) {
|
|
164
|
+
// The contract call doesn't populate all of the signer fields, so we need an extra call for the signer
|
|
165
|
+
return this.signerOrProvider.populateTransaction(tx);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return tx;
|
|
169
|
+
}
|
|
164
170
|
});
|
|
165
171
|
}
|
|
166
172
|
/**
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumberish, providers, Signer } from 'ethers';
|
|
2
2
|
import { Address } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Ensures that given signer is truly a a connected signer
|
|
@@ -30,7 +30,7 @@ export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrPr
|
|
|
30
30
|
* @param tokenAddr the address of the erc20 token
|
|
31
31
|
* @param spender the address of the spender
|
|
32
32
|
* @param amount the amount to increase the allowance by
|
|
33
|
-
* @param
|
|
33
|
+
* @param signerOrProvider an ethers signer or provider
|
|
34
34
|
* @returns the populated TransactionRequest object
|
|
35
35
|
*/
|
|
36
|
-
export declare function increaseAllowance(tokenAddr: string, spender: string, amount:
|
|
36
|
+
export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
|
package/dist/esm/utils.js
CHANGED
|
@@ -74,15 +74,17 @@ export function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
|
|
|
74
74
|
* @param tokenAddr the address of the erc20 token
|
|
75
75
|
* @param spender the address of the spender
|
|
76
76
|
* @param amount the amount to increase the allowance by
|
|
77
|
-
* @param
|
|
77
|
+
* @param signerOrProvider an ethers signer or provider
|
|
78
78
|
* @returns the populated TransactionRequest object
|
|
79
79
|
*/
|
|
80
|
-
export function increaseAllowance(tokenAddr, spender, amount,
|
|
80
|
+
export function increaseAllowance(tokenAddr, spender, amount, signerOrProvider) {
|
|
81
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
82
|
const abi = [
|
|
83
83
|
'function increaseAllowance(address spender, uint256 value) external returns (bool)',
|
|
84
84
|
];
|
|
85
|
-
|
|
85
|
+
// TODO, not all ERC-20 contracts support increaseAllowance
|
|
86
|
+
// Add a check for that here
|
|
87
|
+
const contract = new Contract(tokenAddr, abi, signerOrProvider);
|
|
86
88
|
return yield contract.populateTransaction.increaseAllowance(spender, amount);
|
|
87
89
|
});
|
|
88
90
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mento-protocol/mento-sdk",
|
|
3
3
|
"description": "Official SDK for interacting with the Mento Protocol",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mento Labs",
|
|
7
7
|
"keywords": [
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@mento-protocol/mento-core-ts": "^0.1.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"ethers": "^5.7
|
|
83
|
+
"ethers": "^5.7"
|
|
84
84
|
},
|
|
85
85
|
"packageManager": "yarn@3.3.1"
|
|
86
86
|
}
|