llama-pay-sdk 3.1.0 → 3.1.1
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/lib/crypto.d.ts +3 -4
- package/lib/crypto.d.ts.map +1 -1
- package/lib/crypto.js +9 -23
- package/lib/crypto.js.map +1 -1
- package/lib/erc20Abi.d.ts +39 -0
- package/lib/erc20Abi.d.ts.map +1 -0
- package/lib/erc20Abi.js +226 -0
- package/lib/erc20Abi.js.map +1 -0
- package/package.json +1 -1
- package/src/crypto.ts +10 -27
- package/src/{erc20.abi.json → erc20Abi.ts} +1 -1
package/lib/crypto.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { ethers, TransactionResponse } from 'ethers';
|
|
|
2
2
|
import { SimpleMultisigTransactionData } from './models/SimpleMultisigTransactionData';
|
|
3
3
|
export type TransactionRequest = ethers.TransactionRequest;
|
|
4
4
|
export declare function getPublicAddress(privateKey: string): string;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
5
|
+
export declare function sendNative(privateKey: string, tx: TransactionRequest, rpcUrl?: string): Promise<TransactionResponse>;
|
|
6
|
+
export declare function sendERC20(privateKey: string, tx: TransactionRequest & {
|
|
7
7
|
tokenAddress: string;
|
|
8
|
-
}, rpcUrl?: string): Promise<
|
|
8
|
+
}, rpcUrl?: string): Promise<TransactionResponse>;
|
|
9
9
|
export declare function signTypedData(privateKey: string, txData: SimpleMultisigTransactionData, rpcUrl?: string): Promise<string>;
|
|
10
|
-
export declare function broadcastTx(signedTx: string, rpcUrl: string): Promise<TransactionResponse>;
|
|
11
10
|
//# sourceMappingURL=crypto.d.ts.map
|
package/lib/crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAA;
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAA;AAGtF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAA;AAE1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,UAElD;AAoBD,wBAAsB,UAAU,CAC5B,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAK9B;AAED,wBAAsB,SAAS,CAC3B,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,kBAAkB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,EACjD,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAS9B;AAED,wBAAsB,aAAa,CAC/B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,6BAA6B,EACrC,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAkBjB"}
|
package/lib/crypto.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPublicAddress = getPublicAddress;
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
4
|
+
exports.sendNative = sendNative;
|
|
5
|
+
exports.sendERC20 = sendERC20;
|
|
6
6
|
exports.signTypedData = signTypedData;
|
|
7
|
-
exports.broadcastTx = broadcastTx;
|
|
8
7
|
const ethers_1 = require("ethers");
|
|
9
|
-
const
|
|
8
|
+
const erc20Abi_1 = require("./erc20Abi");
|
|
10
9
|
function getPublicAddress(privateKey) {
|
|
11
10
|
return new ethers_1.ethers.Wallet(privateKey).address;
|
|
12
11
|
}
|
|
13
12
|
function buildERC20TransactionData(params) {
|
|
14
|
-
const token = new ethers_1.ethers.Interface(
|
|
13
|
+
const token = new ethers_1.ethers.Interface(erc20Abi_1.ERC20_ABI);
|
|
15
14
|
const data = token.encodeFunctionData('transfer', [params.to, params.value]);
|
|
16
15
|
return {
|
|
17
16
|
to: params.tokenAddress,
|
|
@@ -20,30 +19,21 @@ function buildERC20TransactionData(params) {
|
|
|
20
19
|
from: params.from
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
|
-
async function
|
|
22
|
+
async function sendNative(privateKey, tx, rpcUrl) {
|
|
24
23
|
let txReq = { ...tx };
|
|
25
24
|
const provider = rpcUrl ? new ethers_1.ethers.JsonRpcProvider(rpcUrl) : null;
|
|
26
25
|
const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
27
|
-
|
|
28
|
-
return wallet.signTransaction(populated);
|
|
26
|
+
return wallet.sendTransaction(txReq);
|
|
29
27
|
}
|
|
30
|
-
async function
|
|
31
|
-
if (!tx.from)
|
|
32
|
-
throw new Error('Missing from');
|
|
28
|
+
async function sendERC20(privateKey, tx, rpcUrl) {
|
|
33
29
|
if (!tx.to)
|
|
34
30
|
throw new Error('Missing to');
|
|
35
31
|
if (tx.value == null)
|
|
36
32
|
throw new Error('Missing value');
|
|
37
|
-
const txReq = buildERC20TransactionData({
|
|
38
|
-
from: tx.from,
|
|
39
|
-
to: tx.to,
|
|
40
|
-
value: tx.value,
|
|
41
|
-
tokenAddress: tx.tokenAddress
|
|
42
|
-
});
|
|
43
33
|
const provider = rpcUrl ? new ethers_1.ethers.JsonRpcProvider(rpcUrl) : null;
|
|
44
34
|
const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
45
|
-
const
|
|
46
|
-
return
|
|
35
|
+
const token = new ethers_1.ethers.Contract(tx.tokenAddress, erc20Abi_1.ERC20_ABI, wallet);
|
|
36
|
+
return token.transfer(tx.to, tx.value);
|
|
47
37
|
}
|
|
48
38
|
async function signTypedData(privateKey, txData, rpcUrl) {
|
|
49
39
|
const provider = rpcUrl ? new ethers_1.ethers.JsonRpcProvider(rpcUrl) : null;
|
|
@@ -57,8 +47,4 @@ async function signTypedData(privateKey, txData, rpcUrl) {
|
|
|
57
47
|
});
|
|
58
48
|
return signature;
|
|
59
49
|
}
|
|
60
|
-
async function broadcastTx(signedTx, rpcUrl) {
|
|
61
|
-
const provider = new ethers_1.ethers.JsonRpcProvider(rpcUrl);
|
|
62
|
-
return provider.broadcastTransaction(signedTx);
|
|
63
|
-
}
|
|
64
50
|
//# sourceMappingURL=crypto.js.map
|
package/lib/crypto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":";;AAMA,4CAEC;AAoBD,gCASC;AAED,8BAaC;AAED,sCAsBC;AA5ED,mCAAoD;AAEpD,yCAAsC;AAItC,SAAgB,gBAAgB,CAAC,UAAkB;IAC/C,OAAO,IAAI,eAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAA;AAChD,CAAC;AAED,SAAS,yBAAyB,CAAC,MAKlC;IACG,MAAM,KAAK,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,oBAAS,CAAC,CAAA;IAE7C,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAE5E,OAAO;QACH,EAAE,EAAE,MAAM,CAAC,YAAY;QACvB,IAAI;QACJ,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,MAAM,CAAC,IAAI;KACpB,CAAA;AACL,CAAC;AAEM,KAAK,UAAU,UAAU,CAC5B,UAAkB,EAClB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CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAEtD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CACxC,MAAM,CAAC,MAAM,EACb,EAAE,mBAAmB,EAAE,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EACzD;QACI,GAAG,MAAM,CAAC,OAAO;QACjB,KAAK,EACD,MAAM,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI;YACzB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACX,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QACtC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,KAAY,CAAC;KAC/C,CACJ,CAAA;IAED,OAAO,SAAS,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const ERC20_ABI: ({
|
|
2
|
+
constant: boolean;
|
|
3
|
+
inputs: {
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}[];
|
|
7
|
+
name: string;
|
|
8
|
+
outputs: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}[];
|
|
12
|
+
payable: boolean;
|
|
13
|
+
stateMutability: string;
|
|
14
|
+
type: string;
|
|
15
|
+
anonymous?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
payable: boolean;
|
|
18
|
+
stateMutability: string;
|
|
19
|
+
type: string;
|
|
20
|
+
constant?: undefined;
|
|
21
|
+
inputs?: undefined;
|
|
22
|
+
name?: undefined;
|
|
23
|
+
outputs?: undefined;
|
|
24
|
+
anonymous?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
anonymous: boolean;
|
|
27
|
+
inputs: {
|
|
28
|
+
indexed: boolean;
|
|
29
|
+
name: string;
|
|
30
|
+
type: string;
|
|
31
|
+
}[];
|
|
32
|
+
name: string;
|
|
33
|
+
type: string;
|
|
34
|
+
constant?: undefined;
|
|
35
|
+
outputs?: undefined;
|
|
36
|
+
payable?: undefined;
|
|
37
|
+
stateMutability?: undefined;
|
|
38
|
+
})[];
|
|
39
|
+
//# sourceMappingURL=erc20Abi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc20Abi.d.ts","sourceRoot":"","sources":["../src/erc20Abi.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6NrB,CAAA"}
|
package/lib/erc20Abi.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC20_ABI = void 0;
|
|
4
|
+
exports.ERC20_ABI = [
|
|
5
|
+
{
|
|
6
|
+
"constant": true,
|
|
7
|
+
"inputs": [],
|
|
8
|
+
"name": "name",
|
|
9
|
+
"outputs": [
|
|
10
|
+
{
|
|
11
|
+
"name": "",
|
|
12
|
+
"type": "string"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"payable": false,
|
|
16
|
+
"stateMutability": "view",
|
|
17
|
+
"type": "function"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"constant": false,
|
|
21
|
+
"inputs": [
|
|
22
|
+
{
|
|
23
|
+
"name": "_spender",
|
|
24
|
+
"type": "address"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "_value",
|
|
28
|
+
"type": "uint256"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"name": "approve",
|
|
32
|
+
"outputs": [
|
|
33
|
+
{
|
|
34
|
+
"name": "",
|
|
35
|
+
"type": "bool"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"payable": false,
|
|
39
|
+
"stateMutability": "nonpayable",
|
|
40
|
+
"type": "function"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"constant": true,
|
|
44
|
+
"inputs": [],
|
|
45
|
+
"name": "totalSupply",
|
|
46
|
+
"outputs": [
|
|
47
|
+
{
|
|
48
|
+
"name": "",
|
|
49
|
+
"type": "uint256"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"payable": false,
|
|
53
|
+
"stateMutability": "view",
|
|
54
|
+
"type": "function"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"constant": false,
|
|
58
|
+
"inputs": [
|
|
59
|
+
{
|
|
60
|
+
"name": "_from",
|
|
61
|
+
"type": "address"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "_to",
|
|
65
|
+
"type": "address"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "_value",
|
|
69
|
+
"type": "uint256"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"name": "transferFrom",
|
|
73
|
+
"outputs": [
|
|
74
|
+
{
|
|
75
|
+
"name": "",
|
|
76
|
+
"type": "bool"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"payable": false,
|
|
80
|
+
"stateMutability": "nonpayable",
|
|
81
|
+
"type": "function"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"constant": true,
|
|
85
|
+
"inputs": [],
|
|
86
|
+
"name": "decimals",
|
|
87
|
+
"outputs": [
|
|
88
|
+
{
|
|
89
|
+
"name": "",
|
|
90
|
+
"type": "uint8"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"payable": false,
|
|
94
|
+
"stateMutability": "view",
|
|
95
|
+
"type": "function"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"constant": true,
|
|
99
|
+
"inputs": [
|
|
100
|
+
{
|
|
101
|
+
"name": "_owner",
|
|
102
|
+
"type": "address"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"name": "balanceOf",
|
|
106
|
+
"outputs": [
|
|
107
|
+
{
|
|
108
|
+
"name": "balance",
|
|
109
|
+
"type": "uint256"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"payable": false,
|
|
113
|
+
"stateMutability": "view",
|
|
114
|
+
"type": "function"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"constant": true,
|
|
118
|
+
"inputs": [],
|
|
119
|
+
"name": "symbol",
|
|
120
|
+
"outputs": [
|
|
121
|
+
{
|
|
122
|
+
"name": "",
|
|
123
|
+
"type": "string"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"payable": false,
|
|
127
|
+
"stateMutability": "view",
|
|
128
|
+
"type": "function"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"constant": false,
|
|
132
|
+
"inputs": [
|
|
133
|
+
{
|
|
134
|
+
"name": "_to",
|
|
135
|
+
"type": "address"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name": "_value",
|
|
139
|
+
"type": "uint256"
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"name": "transfer",
|
|
143
|
+
"outputs": [
|
|
144
|
+
{
|
|
145
|
+
"name": "",
|
|
146
|
+
"type": "bool"
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"payable": false,
|
|
150
|
+
"stateMutability": "nonpayable",
|
|
151
|
+
"type": "function"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"constant": true,
|
|
155
|
+
"inputs": [
|
|
156
|
+
{
|
|
157
|
+
"name": "_owner",
|
|
158
|
+
"type": "address"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "_spender",
|
|
162
|
+
"type": "address"
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"name": "allowance",
|
|
166
|
+
"outputs": [
|
|
167
|
+
{
|
|
168
|
+
"name": "",
|
|
169
|
+
"type": "uint256"
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
"payable": false,
|
|
173
|
+
"stateMutability": "view",
|
|
174
|
+
"type": "function"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"payable": true,
|
|
178
|
+
"stateMutability": "payable",
|
|
179
|
+
"type": "fallback"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"anonymous": false,
|
|
183
|
+
"inputs": [
|
|
184
|
+
{
|
|
185
|
+
"indexed": true,
|
|
186
|
+
"name": "owner",
|
|
187
|
+
"type": "address"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"indexed": true,
|
|
191
|
+
"name": "spender",
|
|
192
|
+
"type": "address"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"indexed": false,
|
|
196
|
+
"name": "value",
|
|
197
|
+
"type": "uint256"
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"name": "Approval",
|
|
201
|
+
"type": "event"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"anonymous": false,
|
|
205
|
+
"inputs": [
|
|
206
|
+
{
|
|
207
|
+
"indexed": true,
|
|
208
|
+
"name": "from",
|
|
209
|
+
"type": "address"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"indexed": true,
|
|
213
|
+
"name": "to",
|
|
214
|
+
"type": "address"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"indexed": false,
|
|
218
|
+
"name": "value",
|
|
219
|
+
"type": "uint256"
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"name": "Transfer",
|
|
223
|
+
"type": "event"
|
|
224
|
+
}
|
|
225
|
+
];
|
|
226
|
+
//# sourceMappingURL=erc20Abi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc20Abi.js","sourceRoot":"","sources":["../src/erc20Abi.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB;QACE,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,MAAM;QACd,SAAS,EAAE;YACT;gBACE,MAAM,EAAE,EAAE;gBACV,MAAM,EA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gBACE,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE,SAAS;aAClB;SACF;QACD,SAAS,EAAE,KAAK;QAChB,iBAAiB,EAAE,MAAM;QACzB,MAAM,EAAE,UAAU;KACnB;IACD;QACE,SAAS,EAAE,IAAI;QACf,iBAAiB,EAAE,SAAS;QAC5B,MAAM,EAAE,UAAU;KACnB;IACD;QACE,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE;YACR;gBACE,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,SAAS,EAAE,KAAK;gBAChB,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,SAAS;aAClB;SACF;QACD,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,OAAO;KAChB;IACD;QACE,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE;YACR;gBACE,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,SAAS;aAClB;YACD;gBACE,SAAS,EAAE,KAAK;gBAChB,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,SAAS;aAClB;SACF;QACD,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,OAAO;KAChB;CACF,CAAA"}
|
package/package.json
CHANGED
package/src/crypto.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ethers, TransactionResponse } from 'ethers'
|
|
2
2
|
import { SimpleMultisigTransactionData } from './models/SimpleMultisigTransactionData'
|
|
3
|
-
|
|
4
|
-
const erc20Abi = require('./erc20.abi.json')
|
|
3
|
+
import { ERC20_ABI } from './erc20Abi'
|
|
5
4
|
|
|
6
5
|
export type TransactionRequest = ethers.TransactionRequest
|
|
7
6
|
|
|
@@ -15,7 +14,7 @@ function buildERC20TransactionData(params: {
|
|
|
15
14
|
value: ethers.BigNumberish
|
|
16
15
|
tokenAddress: string
|
|
17
16
|
}): ethers.TransactionRequest {
|
|
18
|
-
const token = new ethers.Interface(
|
|
17
|
+
const token = new ethers.Interface(ERC20_ABI)
|
|
19
18
|
|
|
20
19
|
const data = token.encodeFunctionData('transfer', [params.to, params.value])
|
|
21
20
|
|
|
@@ -27,37 +26,30 @@ function buildERC20TransactionData(params: {
|
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
export async function
|
|
29
|
+
export async function sendNative(
|
|
31
30
|
privateKey: string,
|
|
32
31
|
tx: TransactionRequest,
|
|
33
32
|
rpcUrl?: string
|
|
34
|
-
): Promise<
|
|
33
|
+
): Promise<TransactionResponse> {
|
|
35
34
|
let txReq = { ...tx }
|
|
36
35
|
const provider = rpcUrl ? new ethers.JsonRpcProvider(rpcUrl) : null
|
|
37
36
|
const wallet = new ethers.Wallet(privateKey, provider)
|
|
38
|
-
|
|
39
|
-
return wallet.signTransaction(populated)
|
|
37
|
+
return wallet.sendTransaction(txReq)
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
export async function
|
|
40
|
+
export async function sendERC20(
|
|
43
41
|
privateKey: string,
|
|
44
42
|
tx: TransactionRequest & { tokenAddress: string },
|
|
45
43
|
rpcUrl?: string
|
|
46
|
-
): Promise<
|
|
47
|
-
if (!tx.from) throw new Error('Missing from')
|
|
44
|
+
): Promise<TransactionResponse> {
|
|
48
45
|
if (!tx.to) throw new Error('Missing to')
|
|
49
46
|
if (tx.value == null) throw new Error('Missing value')
|
|
50
47
|
|
|
51
|
-
const txReq = buildERC20TransactionData({
|
|
52
|
-
from: tx.from,
|
|
53
|
-
to: tx.to,
|
|
54
|
-
value: tx.value,
|
|
55
|
-
tokenAddress: tx.tokenAddress
|
|
56
|
-
})
|
|
57
48
|
const provider = rpcUrl ? new ethers.JsonRpcProvider(rpcUrl) : null
|
|
58
49
|
const wallet = new ethers.Wallet(privateKey, provider)
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
|
|
51
|
+
const token = new ethers.Contract(tx.tokenAddress, ERC20_ABI, wallet)
|
|
52
|
+
return token.transfer(tx.to, tx.value)
|
|
61
53
|
}
|
|
62
54
|
|
|
63
55
|
export async function signTypedData(
|
|
@@ -83,12 +75,3 @@ export async function signTypedData(
|
|
|
83
75
|
|
|
84
76
|
return signature
|
|
85
77
|
}
|
|
86
|
-
|
|
87
|
-
export async function broadcastTx(
|
|
88
|
-
signedTx: string,
|
|
89
|
-
rpcUrl: string
|
|
90
|
-
): Promise<TransactionResponse> {
|
|
91
|
-
const provider = new ethers.JsonRpcProvider(rpcUrl)
|
|
92
|
-
|
|
93
|
-
return provider.broadcastTransaction(signedTx)
|
|
94
|
-
}
|